2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
11 #include "Constants.h"
12 #include "FindWindow.h"
17 #include <GroupLayoutBuilder.h>
18 #include <GridLayoutBuilder.h>
20 #include <LayoutBuilder.h>
22 #include <TextControl.h>
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "FindandReplaceWindow"
29 FindWindow::FindWindow(BRect frame
, BHandler
* _handler
, BString
* searchString
,
30 bool caseState
, bool wrapState
, bool backState
)
31 : BWindow(frame
, B_TRANSLATE("Find"), B_FLOATING_WINDOW
,
32 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_ASYNCHRONOUS_CONTROLS
33 | B_AUTO_UPDATE_SIZE_LIMITS
, B_CURRENT_WORKSPACE
)
35 AddShortcut('W', B_COMMAND_KEY
, new BMessage(MSG_HIDE_WINDOW
));
37 fSearchString
= new BTextControl("", B_TRANSLATE("Find:"), NULL
, NULL
);
38 fCaseSensBox
= new BCheckBox("", B_TRANSLATE("Case-sensitive"), NULL
);
39 fWrapBox
= new BCheckBox("", B_TRANSLATE("Wrap-around search"), NULL
);
40 fBackSearchBox
= new BCheckBox("", B_TRANSLATE("Search backwards"), NULL
);
41 fCancelButton
= new BButton("", B_TRANSLATE("Cancel"),
42 new BMessage(MSG_HIDE_WINDOW
));
43 fSearchButton
= new BButton("", B_TRANSLATE("Find"),
44 new BMessage(MSG_SEARCH
));
46 SetLayout(new BGroupLayout(B_HORIZONTAL
));
47 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 4)
48 .Add(BGridLayoutBuilder(6, 2)
49 .Add(fSearchString
->CreateLabelLayoutItem(), 0, 0)
50 .Add(fSearchString
->CreateTextViewLayoutItem(), 1, 0)
51 .Add(fCaseSensBox
, 1, 1)
53 .Add(fBackSearchBox
, 1, 3)
55 .AddGroup(B_HORIZONTAL
, 10)
60 .SetInsets(10, 10, 10, 10)
63 fSearchButton
->MakeDefault(true);
66 const char* text
= searchString
->String();
68 fSearchString
->SetText(text
);
69 fSearchString
->MakeFocus(true);
71 fCaseSensBox
->SetValue(caseState
? B_CONTROL_ON
: B_CONTROL_OFF
);
72 fWrapBox
->SetValue(wrapState
? B_CONTROL_ON
: B_CONTROL_OFF
);
73 fBackSearchBox
->SetValue(backState
? B_CONTROL_ON
: B_CONTROL_OFF
);
78 FindWindow::MessageReceived(BMessage
* msg
)
90 BWindow::MessageReceived(msg
);
97 FindWindow::DispatchMessage(BMessage
* message
, BHandler
* handler
)
99 if (message
->what
== B_KEY_DOWN
) {
101 if (message
->FindInt8("byte", 0, &key
) == B_OK
) {
102 if (key
== B_ESCAPE
) {
103 message
->MakeEmpty();
104 message
->what
= MSG_HIDE_WINDOW
;
109 BWindow::DispatchMessage(message
, handler
);
114 FindWindow::QuitRequested()
116 BMessenger
messenger(fHandler
);
117 messenger
.SendMessage(MSG_FIND_WINDOW_QUIT
);
126 fSearchString
->TextView()->SelectAll();
132 FindWindow::_SendMessage()
134 BMessage
message(MSG_SEARCH
);
137 message
.AddString("findtext", fSearchString
->Text());
139 // Add searchparameters from checkboxes
140 message
.AddBool("casesens", fCaseSensBox
->Value() == B_CONTROL_ON
);
141 message
.AddBool("wrap", fWrapBox
->Value() == B_CONTROL_ON
);
142 message
.AddBool("backsearch", fBackSearchBox
->Value() == B_CONTROL_ON
);
144 fHandler
->Looper()->PostMessage(&message
, fHandler
);
146 PostMessage(MSG_HIDE_WINDOW
);