6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
39 #include <ControlLook.h>
40 #include <LayoutBuilder.h>
43 #include <WindowPrivate.h>
46 #include "ContainerWindow.h"
49 #include "SelectionWindow.h"
52 const uint32 kSelectButtonPressed
= 'sbpr';
55 // #pragma mark - SelectionWindow
58 #undef B_TRANSLATION_CONTEXT
59 #define B_TRANSLATION_CONTEXT "SelectionWindow"
62 SelectionWindow::SelectionWindow(BContainerWindow
* window
)
64 BWindow(BRect(0, 0, 270, 0), B_TRANSLATE("Select"), B_TITLED_WINDOW
,
65 B_NOT_ZOOMABLE
| B_NOT_MINIMIZABLE
| B_NOT_V_RESIZABLE
66 | B_NO_WORKSPACE_ACTIVATION
| B_ASYNCHRONOUS_CONTROLS
67 | B_NOT_ANCHORED_ON_ACTIVATE
| B_AUTO_UPDATE_SIZE_LIMITS
71 if (window
->Feel() & kDesktopWindowFeel
) {
72 // The window will not show up if we have
73 // B_FLOATING_SUBSET_WINDOW_FEEL and use it with the desktop window
74 // since it's never in front.
75 SetFeel(B_NORMAL_WINDOW_FEEL
);
78 AddToSubset(fParentWindow
);
80 BMenu
* menu
= new BPopUpMenu("popup");
81 menu
->AddItem(new BMenuItem(B_TRANSLATE("starts with"), NULL
));
82 menu
->AddItem(new BMenuItem(B_TRANSLATE("ends with"), NULL
));
83 menu
->AddItem(new BMenuItem(B_TRANSLATE("contains"), NULL
));
84 menu
->AddItem(new BMenuItem(B_TRANSLATE("matches wildcard expression"),
86 menu
->AddItem(new BMenuItem(B_TRANSLATE("matches regular expression"),
89 menu
->SetLabelFromMarked(true);
90 menu
->ItemAt(3)->SetMarked(true);
91 // Set wildcard matching to default.
93 // Set up the menu field
94 fMatchingTypeMenuField
= new BMenuField("name", B_TRANSLATE("Name"), menu
);
96 // Set up the expression text control
97 fExpressionTextControl
= new BTextControl("expression", NULL
, "", NULL
);
99 // Set up the Invert checkbox
100 fInverseCheckBox
= new BCheckBox("inverse", B_TRANSLATE("Invert"), NULL
);
101 fInverseCheckBox
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, B_SIZE_UNSET
));
103 // Set up the Ignore Case checkbox
104 fIgnoreCaseCheckBox
= new BCheckBox(
105 "ignore", B_TRANSLATE("Ignore case"), NULL
);
106 fIgnoreCaseCheckBox
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, B_SIZE_UNSET
));
107 fIgnoreCaseCheckBox
->SetValue(1);
109 // Set up the Select button
110 fSelectButton
= new BButton("select", B_TRANSLATE("Select"),
111 new BMessage(kSelectButtonPressed
));
112 fSelectButton
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, B_SIZE_UNSET
));
113 fSelectButton
->MakeDefault(true);
115 BLayoutBuilder::Group
<>(this, B_VERTICAL
, B_USE_HALF_ITEM_SPACING
)
116 .SetInsets(B_USE_WINDOW_SPACING
)
117 .Add(fMatchingTypeMenuField
)
118 .Add(fExpressionTextControl
)
119 .AddGroup(B_HORIZONTAL
)
120 .Add(fInverseCheckBox
)
121 .Add(fIgnoreCaseCheckBox
)
131 fExpressionTextControl
->MakeFocus(true);
137 SelectionWindow::MessageReceived(BMessage
* message
)
139 switch (message
->what
) {
140 case kSelectButtonPressed
:
143 // Order of posting and hiding important
144 // since we want to activate the target
145 // window when the message arrives.
146 // (Hide is synhcronous, while PostMessage is not.)
147 // See PoseView::SelectMatchingEntries().
149 BMessage
* selectionInfo
= new BMessage(kSelectMatchingEntries
);
150 selectionInfo
->AddInt32("ExpressionType", ExpressionType());
152 Expression(expression
);
153 selectionInfo
->AddString("Expression", expression
.String());
154 selectionInfo
->AddBool("InvertSelection", Invert());
155 selectionInfo
->AddBool("IgnoreCase", IgnoreCase());
156 fParentWindow
->PostMessage(selectionInfo
);
161 _inherited::MessageReceived(message
);
168 SelectionWindow::QuitRequested()
176 SelectionWindow::MoveCloseToMouse()
179 BPoint mousePosition
;
181 ChildAt((int32
)0)->GetMouse(&mousePosition
, &buttons
);
182 ConvertToScreen(&mousePosition
);
184 // Position the window centered around the mouse...
185 BPoint windowPosition
= BPoint(mousePosition
.x
- Frame().Width() / 2,
186 mousePosition
.y
- Frame().Height() / 2);
188 // ... unless that's outside of the current screen size:
191 = MAX(20, MIN(screen
.Frame().right
- 20 - Frame().Width(),
193 windowPosition
.y
= MAX(20,
194 MIN(screen
.Frame().bottom
- 20 - Frame().Height(), windowPosition
.y
));
196 MoveTo(windowPosition
);
197 SetWorkspaces(1UL << current_workspace());
201 TrackerStringExpressionType
202 SelectionWindow::ExpressionType() const
204 if (!fMatchingTypeMenuField
->LockLooper())
207 BMenuItem
* item
= fMatchingTypeMenuField
->Menu()->FindMarked();
209 fMatchingTypeMenuField
->UnlockLooper();
213 int32 index
= fMatchingTypeMenuField
->Menu()->IndexOf(item
);
215 fMatchingTypeMenuField
->UnlockLooper();
217 if (index
< kStartsWith
|| index
> kRegexpMatch
)
220 TrackerStringExpressionType typeArray
[] = { kStartsWith
, kEndsWith
,
221 kContains
, kGlobMatch
, kRegexpMatch
};
223 return typeArray
[index
];
228 SelectionWindow::Expression(BString
&result
) const
230 if (!fExpressionTextControl
->LockLooper())
233 result
= fExpressionTextControl
->Text();
235 fExpressionTextControl
->UnlockLooper();
240 SelectionWindow::IgnoreCase() const
242 if (!fIgnoreCaseCheckBox
->LockLooper()) {
247 bool ignore
= fIgnoreCaseCheckBox
->Value() != 0;
249 fIgnoreCaseCheckBox
->UnlockLooper();
256 SelectionWindow::Invert() const
258 if (!fInverseCheckBox
->LockLooper()) {
263 bool inverse
= fInverseCheckBox
->Value() != 0;
265 fInverseCheckBox
->UnlockLooper();