libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / stylededit / FindWindow.cpp
bloba8f4fc7d5bb4975fa6c3bc10548d2288f0700f63
1 /*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Mattias Sundblad
7 * Andrew Bachmann
8 */
11 #include "Constants.h"
12 #include "FindWindow.h"
14 #include <Button.h>
15 #include <Catalog.h>
16 #include <CheckBox.h>
17 #include <GroupLayoutBuilder.h>
18 #include <GridLayoutBuilder.h>
19 #include <Locale.h>
20 #include <LayoutBuilder.h>
21 #include <String.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)
52 .Add(fWrapBox, 1, 2)
53 .Add(fBackSearchBox, 1, 3)
55 .AddGroup(B_HORIZONTAL, 10)
56 .AddGlue()
57 .Add(fCancelButton)
58 .Add(fSearchButton)
59 .End()
60 .SetInsets(10, 10, 10, 10)
63 fSearchButton->MakeDefault(true);
64 fHandler = _handler;
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);
77 void
78 FindWindow::MessageReceived(BMessage* msg)
80 switch (msg->what) {
81 case MSG_HIDE_WINDOW:
82 if (!IsHidden())
83 Hide();
84 break;
85 case MSG_SEARCH:
86 _SendMessage();
87 break;
89 default:
90 BWindow::MessageReceived(msg);
91 break;
96 void
97 FindWindow::DispatchMessage(BMessage* message, BHandler* handler)
99 if (message->what == B_KEY_DOWN) {
100 int8 key;
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);
113 bool
114 FindWindow::QuitRequested()
116 BMessenger messenger(fHandler);
117 messenger.SendMessage(MSG_FIND_WINDOW_QUIT);
119 return true;
123 void
124 FindWindow::Show()
126 fSearchString->TextView()->SelectAll();
127 BWindow::Show();
131 void
132 FindWindow::_SendMessage()
134 BMessage message(MSG_SEARCH);
136 // Add the string
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);