Patch by Vasilis Kaoutsis:

* Use a BMessenger instead of a BWindow pointer
* Removed an useless SetTitle() call
* Lock the window before quitting it
* Style changes and cleanups


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20326 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-03-04 21:06:51 +00:00
parent aa46234e72
commit bb11b61bee
3 changed files with 91 additions and 147 deletions
+53 -85
View File
@@ -1,68 +1,30 @@
/* /*
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright 2007, Haiku, Inc.
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * Copyright 2003-2004 Kian Duffy, [email protected]
* * Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
* Permission is hereby granted, free of charge, to any person obtaining * All rights reserved. Distributed under the terms of the MIT license.
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/ */
#include <Window.h>
#include <Rect.h>
#include <TextControl.h>
#include <Box.h>
#include <CheckBox.h>
#include <Button.h>
#include <RadioButton.h>
#include <Message.h>
#include <stdio.h>
#include <File.h>
#include <String.h>
#include "TermWindow.h"
#include "FindDlg.h" #include "FindDlg.h"
#include "TermApp.h"
#include "MenuUtil.h"
#include "PrefHandler.h"
// message define #include <Box.h>
#include <Button.h>
#include <CheckBox.h>
#include <RadioButton.h>
#include <String.h>
#include <TextControl.h>
const uint32 MSG_FIND_HIDE = 'Fhid'; const uint32 MSG_FIND_HIDE = 'Fhid';
//////////////////////////////////////////////////////////////////////////////
// FindDlg
// Constructer
//////////////////////////////////////////////////////////////////////////////
FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
bool findselection, bool matchword, bool matchcase, bool forwardsearch)
: BWindow(frame, "Find",
B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
{
fWindow = win;
SetTitle("Find");
AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage (MSG_FIND_HIDE)); FindDlg::FindDlg (BRect frame, BMessenger messenger , BString &str,
bool findSelection, bool matchWord, bool matchCase, bool forwardSearch)
: BWindow(frame, "Find", B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE),
fFindDlgMessenger(messenger)
{
AddShortcut((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage(MSG_FIND_HIDE));
//Build up view //Build up view
fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW); fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
@@ -75,12 +37,12 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
//These labels are from the bottom up //These labels are from the bottom up
float buttonsTop = frame.Height() - 19 - lineHeight; float buttonsTop = frame.Height() - 19 - lineHeight;
float matchwordBottom = buttonsTop - 4; float matchWordBottom = buttonsTop - 4;
float matchwordTop = matchwordBottom - lineHeight - 8; float matchWordTop = matchWordBottom - lineHeight - 8;
float matchcaseBottom = matchwordTop - 4; float matchCaseBottom = matchWordTop - 4;
float matchcaseTop = matchcaseBottom - lineHeight - 8; float matchCaseTop = matchCaseBottom - lineHeight - 8;
float forwardsearchBottom = matchcaseTop - 4; float forwardSearchBottom = matchCaseTop - 4;
float forwardsearchTop = forwardsearchBottom - lineHeight - 8; float forwardSearchTop = forwardSearchBottom - lineHeight - 8;
//These things are calculated from the top //These things are calculated from the top
float textRadioTop = 12; float textRadioTop = 12;
@@ -90,11 +52,11 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
float selectionRadioBottom = selectionRadioTop + lineHeight + 8; float selectionRadioBottom = selectionRadioTop + lineHeight + 8;
//Divider //Divider
float dividerHeight = (selectionRadioBottom + forwardsearchTop) / 2; float dividerHeight = (selectionRadioBottom + forwardSearchTop) / 2;
//Button Coordinates //Button Coordinates
float searchbuttonLeft = (frame.Width() - fFindView->StringWidth("Find") - 60) / 2; float searchButtonLeft = (frame.Width() - fFindView->StringWidth("Find") - 60) / 2;
float searchbuttonRight = searchbuttonLeft + fFindView->StringWidth("Find") + 60; float searchButtonRight = searchButtonLeft + fFindView->StringWidth("Find") + 60;
//Build the Views //Build the Views
fTextRadio = new BRadioButton(BRect(14, textRadioTop, textRadioRight, textRadioBottom), fTextRadio = new BRadioButton(BRect(14, textRadioTop, textRadioRight, textRadioBottom),
@@ -105,7 +67,7 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
"fFindLabel", "", "", NULL); "fFindLabel", "", "", NULL);
fFindLabel->SetDivider(0); fFindLabel->SetDivider(0);
fFindView->AddChild(fFindLabel); fFindView->AddChild(fFindLabel);
if (!findselection) if (!findSelection)
fFindLabel->SetText(str.String()); fFindLabel->SetText(str.String());
fFindLabel->MakeFocus(true); fFindLabel->MakeFocus(true);
@@ -113,7 +75,7 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
"fSelectionRadio", "Use Selection", NULL); "fSelectionRadio", "Use Selection", NULL);
fFindView->AddChild(fSelectionRadio); fFindView->AddChild(fSelectionRadio);
if (findselection) if (findSelection)
fSelectionRadio->SetValue(B_CONTROL_ON); fSelectionRadio->SetValue(B_CONTROL_ON);
else else
fTextRadio->SetValue(B_CONTROL_ON); fTextRadio->SetValue(B_CONTROL_ON);
@@ -121,25 +83,25 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
fSeparator = new BBox(BRect(6, dividerHeight, frame.Width() - 6, dividerHeight + 1)); fSeparator = new BBox(BRect(6, dividerHeight, frame.Width() - 6, dividerHeight + 1));
fFindView->AddChild(fSeparator); fFindView->AddChild(fSeparator);
fForwardSearchBox = new BCheckBox(BRect(14, forwardsearchTop, frame.Width() - 14, forwardsearchBottom), fForwardSearchBox = new BCheckBox(BRect(14, forwardSearchTop, frame.Width() - 14, forwardSearchBottom),
"fForwardSearchBox", "Search Forward", NULL); "fForwardSearchBox", "Search Forward", NULL);
fFindView->AddChild(fForwardSearchBox); fFindView->AddChild(fForwardSearchBox);
if (forwardsearch) if (forwardSearch)
fForwardSearchBox->SetValue(B_CONTROL_ON); fForwardSearchBox->SetValue(B_CONTROL_ON);
fMatchCaseBox = new BCheckBox(BRect(14, matchcaseTop, frame.Width() - 14, matchcaseBottom), fMatchCaseBox = new BCheckBox(BRect(14, matchCaseTop, frame.Width() - 14, matchCaseBottom),
"fMatchCaseBox", "Match Case", NULL); "fMatchCaseBox", "Match Case", NULL);
fFindView->AddChild(fMatchCaseBox); fFindView->AddChild(fMatchCaseBox);
if (matchcase) if (matchCase)
fMatchCaseBox->SetValue(B_CONTROL_ON); fMatchCaseBox->SetValue(B_CONTROL_ON);
fMatchWordBox = new BCheckBox(BRect(14, matchwordTop, frame.Width() - 14, matchwordBottom), fMatchWordBox = new BCheckBox(BRect(14, matchWordTop, frame.Width() - 14, matchWordBottom),
"fMatchWordBox", "Match Word", NULL); "fMatchWordBox", "Match Word", NULL);
fFindView->AddChild(fMatchWordBox); fFindView->AddChild(fMatchWordBox);
if (matchword) if (matchWord)
fMatchWordBox->SetValue(B_CONTROL_ON); fMatchWordBox->SetValue(B_CONTROL_ON);
fFindButton = new BButton(BRect(searchbuttonLeft, buttonsTop, searchbuttonRight, frame.Height() - 14), fFindButton = new BButton(BRect(searchButtonLeft, buttonsTop, searchButtonRight, frame.Height() - 14),
"fFindButton", "Find", new BMessage(MSG_FIND)); "fFindButton", "Find", new BMessage(MSG_FIND));
fFindButton->MakeDefault(true); fFindButton->MakeDefault(true);
fFindView->AddChild(fFindButton); fFindView->AddChild(fFindButton);
@@ -147,39 +109,45 @@ FindDlg::FindDlg (BRect frame, TermWindow *win , BString &str,
Show(); Show();
} }
FindDlg::~FindDlg (void)
{
FindDlg::~FindDlg()
{
} }
void void
FindDlg::MessageReceived (BMessage *msg) FindDlg::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_QUIT_REQUESTED: case B_QUIT_REQUESTED:
Quit(); Quit();
break; break;
case MSG_FIND: case MSG_FIND:
SendFindMessage(); _SendFindMessage();
break; break;
case MSG_FIND_HIDE: case MSG_FIND_HIDE:
Quit(); Quit();
break; break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
} }
} }
void
FindDlg::Quit (void)
{
fWindow->PostMessage(MSG_FIND_CLOSED);
BWindow::Quit ();
}
void void
FindDlg::SendFindMessage (void) FindDlg::Quit()
{
fFindDlgMessenger.SendMessage(MSG_FIND_CLOSED);
BWindow::Quit();
}
void
FindDlg::_SendFindMessage()
{ {
BMessage message(MSG_FIND); BMessage message(MSG_FIND);
@@ -195,5 +163,5 @@ FindDlg::SendFindMessage (void)
message.AddBool("matchcase", fMatchCaseBox->Value() == B_CONTROL_ON); message.AddBool("matchcase", fMatchCaseBox->Value() == B_CONTROL_ON);
message.AddBool("matchword", fMatchWordBox->Value() == B_CONTROL_ON); message.AddBool("matchword", fMatchWordBox->Value() == B_CONTROL_ON);
fWindow->PostMessage(&message); fFindDlgMessenger.SendMessage(&message);
} }
+19 -48
View File
@@ -1,63 +1,35 @@
/* /*
* Copyright (c) 2003-4 Kian Duffy <[email protected]> * Copyright 2007, Haiku, Inc.
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * Copyright 2003-2004 Kian Duffy, [email protected]
* * Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
* Permission is hereby granted, free of charge, to any person obtaining * All rights reserved. Distributed under the terms of the MIT license.
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/ */
#ifndef FINDDLG_H_INCLUDED #ifndef FINDDLG_H_INCLUDED
#define FINDDLG_H_INCLUDED #define FINDDLG_H_INCLUDED
#include <Messenger.h>
#include <Window.h> #include <Window.h>
#include <TextView.h>
const ulong MSG_FIND = 'msgf'; const ulong MSG_FIND = 'msgf';
const ulong MSG_FIND_START = 'msac'; const ulong MSG_FIND_START = 'msac';
const ulong MSG_FIND_CLOSED = 'mfcl'; const ulong MSG_FIND_CLOSED = 'mfcl';
class BRect;
class BBitmap;
class BMessage;
class TermWindow;
class BTextControl;
class BRadioButton;
class BCheckBox;
class FindDlg : public BWindow class FindDlg : public BWindow {
{ public:
public: FindDlg (BRect frame, BMessenger messenger, BString &str,
FindDlg (BRect frame, TermWindow *win, BString &str, bool findSelection, bool matchWord, bool matchCase, bool forwardSearch);
bool findselection, bool matchword, bool matchcase, bool forwardsearch); virtual ~FindDlg();
~FindDlg ();
private: virtual void Quit();
virtual void Quit (void); virtual void MessageReceived(BMessage *msg);
void MessageReceived (BMessage *msg);
void SendFindMessage (void); private:
void _SendFindMessage();
private:
BView *fFindView; BView *fFindView;
BTextControl *fFindLabel; BTextControl *fFindLabel;
BRadioButton *fTextRadio; BRadioButton *fTextRadio;
@@ -69,8 +41,7 @@ private:
BButton *fFindButton; BButton *fFindButton;
BString *fFindString; BString *fFindString;
TermWindow *fWindow; BMessenger fFindDlgMessenger;
}; };
#endif // FINDDLG_H_INCLUDED
#endif /* FINDDLG_H_INCLUDED */
+9 -4
View File
@@ -603,14 +603,19 @@ TermWindow::WindowActivated (bool )
void void
TermWindow::Quit(void) TermWindow::Quit()
{ {
delete fTermParse; delete fTermParse;
delete fCodeConv; delete fCodeConv;
if (fPrefWindow) fPrefWindow->PostMessage (B_QUIT_REQUESTED); if (fPrefWindow)
if (fFindPanel) fFindPanel->PostMessage(B_QUIT_REQUESTED); fPrefWindow->PostMessage(B_QUIT_REQUESTED);
be_app->PostMessage (B_QUIT_REQUESTED, be_app); if (fFindPanel && fFindPanel->Lock()) {
fFindPanel->Quit();
fFindPanel = NULL;
}
be_app->PostMessage(B_QUIT_REQUESTED, be_app);
BWindow::Quit (); BWindow::Quit ();
} }