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.
37 #include <ControlLook.h>
38 #include <InterfaceDefs.h>
39 #include <LayoutBuilder.h>
41 #include <ScrollView.h>
43 #include "TrackerSettings.h"
44 #include "TrackerSettingsWindow.h"
49 class SettingsItem
: public BStringItem
{
51 SettingsItem(const char* label
, SettingsView
* view
);
53 void DrawItem(BView
* owner
, BRect rect
, bool drawEverything
);
58 SettingsView
* fSettingsView
;
61 } // namespace BPrivate
64 const uint32 kSettingsViewChanged
= 'Svch';
65 const uint32 kDefaultsButtonPressed
= 'Apbp';
66 const uint32 kRevertButtonPressed
= 'Rebp';
69 #undef B_TRANSLATION_CONTEXT
70 #define B_TRANSLATION_CONTEXT "TrackerSettingsWindow"
73 // #pragma mark - TrackerSettingsWindow
76 TrackerSettingsWindow::TrackerSettingsWindow()
78 BWindow(BRect(80, 80, 450, 350), B_TRANSLATE("Tracker preferences"),
79 B_TITLED_WINDOW
, B_NOT_MINIMIZABLE
| B_NOT_RESIZABLE
80 | B_ASYNCHRONOUS_CONTROLS
| B_NOT_ZOOMABLE
81 | B_AUTO_UPDATE_SIZE_LIMITS
)
83 fSettingsTypeListView
= new BListView("List View",
84 B_SINGLE_SELECTION_LIST
);
86 BScrollView
* scrollView
= new BScrollView("scrollview",
87 fSettingsTypeListView
, B_FRAME_EVENTS
| B_WILL_DRAW
, false, true);
89 fDefaultsButton
= new BButton("Defaults", B_TRANSLATE("Defaults"),
90 new BMessage(kDefaultsButtonPressed
));
91 fDefaultsButton
->SetEnabled(false);
93 fRevertButton
= new BButton("Revert", B_TRANSLATE("Revert"),
94 new BMessage(kRevertButtonPressed
));
95 fRevertButton
->SetEnabled(false);
97 fSettingsContainerBox
= new BBox("SettingsContainerBox");
99 // const float spacing = be_control_look->DefaultItemSpacing();
101 BLayoutBuilder::Group
<>(this)
102 .AddGroup(B_HORIZONTAL
, B_USE_DEFAULT_SPACING
)
104 .AddGroup(B_VERTICAL
, B_USE_DEFAULT_SPACING
)
105 .Add(fSettingsContainerBox
)
106 .AddGroup(B_HORIZONTAL
, B_USE_DEFAULT_SPACING
)
107 .Add(fDefaultsButton
)
112 .SetInsets(B_USE_WINDOW_SPACING
)
115 fSettingsTypeListView
->AddItem(new SettingsItem(B_TRANSLATE("Desktop"),
116 new DesktopSettingsView()), kDesktopSettings
);
117 fSettingsTypeListView
->AddItem(new SettingsItem(B_TRANSLATE("Windows"),
118 new WindowsSettingsView()), kWindowsSettings
);
119 fSettingsTypeListView
->AddItem(new SettingsItem(
120 B_TRANSLATE("Volume icons"), new SpaceBarSettingsView()),
122 fSettingsTypeListView
->AddItem(new SettingsItem(
123 B_TRANSLATE("Disk mount"), new AutomountSettingsPanel()),
126 // constraint the listview width so that the longest item fits
128 fSettingsTypeListView
->GetPreferredSize(&width
, NULL
);
129 width
+= B_V_SCROLL_BAR_WIDTH
;
130 fSettingsTypeListView
->SetExplicitMinSize(BSize(width
, 0));
131 fSettingsTypeListView
->SetExplicitMaxSize(BSize(width
, B_SIZE_UNLIMITED
));
133 fSettingsTypeListView
->SetSelectionMessage(
134 new BMessage(kSettingsViewChanged
));
135 fSettingsTypeListView
->Select(0);
140 TrackerSettingsWindow::QuitRequested()
151 TrackerSettingsWindow::MessageReceived(BMessage
* message
)
153 switch (message
->what
) {
154 case kSettingsContentsModified
:
155 _HandleChangedContents();
158 case kDefaultsButtonPressed
:
159 _HandlePressedDefaultsButton();
162 case kRevertButtonPressed
:
163 _HandlePressedRevertButton();
166 case kSettingsViewChanged
:
167 _HandleChangedSettingsView();
171 _inherited::MessageReceived(message
);
178 TrackerSettingsWindow::Show()
181 int32 itemCount
= fSettingsTypeListView
->CountItems();
183 for (int32 i
= 0; i
< itemCount
; i
++) {
184 _ViewAt(i
)->RecordRevertSettings();
185 _ViewAt(i
)->ShowCurrentSettings();
188 fSettingsTypeListView
->Invalidate();
196 // move to current workspace
197 SetWorkspaces(B_CURRENT_WORKSPACE
);
205 TrackerSettingsWindow::ShowPage(SettingsPage page
)
207 fSettingsTypeListView
->Select(page
);
212 TrackerSettingsWindow::_ViewAt(int32 i
)
217 SettingsItem
* item
= dynamic_cast<SettingsItem
*>(
218 fSettingsTypeListView
->ItemAt(i
));
222 return item
!= NULL
? item
->View() : NULL
;
227 TrackerSettingsWindow::_HandleChangedContents()
229 fSettingsTypeListView
->Invalidate();
232 TrackerSettings().SaveSettings(false);
237 TrackerSettingsWindow::_UpdateButtons()
239 int32 itemCount
= fSettingsTypeListView
->CountItems();
241 bool defaultable
= false;
242 bool revertable
= false;
244 for (int32 i
= 0; i
< itemCount
; i
++) {
245 defaultable
|= _ViewAt(i
)->IsDefaultable();
246 revertable
|= _ViewAt(i
)->IsRevertable();
249 fDefaultsButton
->SetEnabled(defaultable
);
250 fRevertButton
->SetEnabled(revertable
);
255 TrackerSettingsWindow::_HandlePressedDefaultsButton()
257 int32 itemCount
= fSettingsTypeListView
->CountItems();
259 for (int32 i
= 0; i
< itemCount
; i
++) {
260 if (_ViewAt(i
)->IsDefaultable())
261 _ViewAt(i
)->SetDefaults();
264 _HandleChangedContents();
269 TrackerSettingsWindow::_HandlePressedRevertButton()
271 int32 itemCount
= fSettingsTypeListView
->CountItems();
273 for (int32 i
= 0; i
< itemCount
; i
++) {
274 if (_ViewAt(i
)->IsRevertable())
275 _ViewAt(i
)->Revert();
278 _HandleChangedContents();
283 TrackerSettingsWindow::_HandleChangedSettingsView()
285 int32 currentSelection
= fSettingsTypeListView
->CurrentSelection();
286 if (currentSelection
< 0)
289 BView
* oldView
= fSettingsContainerBox
->ChildAt(0);
292 oldView
->RemoveSelf();
294 SettingsItem
* selectedItem
= dynamic_cast<SettingsItem
*>(
295 fSettingsTypeListView
->ItemAt(currentSelection
));
296 if (selectedItem
!= NULL
) {
297 fSettingsContainerBox
->SetLabel(selectedItem
->Text());
299 BView
* view
= selectedItem
->View();
300 float tint
= B_NO_TINT
;
301 view
->SetViewUIColor(fSettingsContainerBox
->ViewUIColor(&tint
), tint
);
303 fSettingsContainerBox
->AddChild(view
);
310 // #pragma mark - SettingsItem
313 SettingsItem::SettingsItem(const char* label
, SettingsView
* view
)
322 SettingsItem::DrawItem(BView
* owner
, BRect rect
, bool drawEverything
)
325 bool isRevertable
= fSettingsView
->IsRevertable();
326 bool isSelected
= IsSelected();
328 if (isSelected
|| drawEverything
) {
331 color
= ui_color(B_LIST_SELECTED_BACKGROUND_COLOR
);
333 color
= owner
->ViewColor();
335 owner
->SetHighColor(color
);
336 owner
->SetLowColor(color
);
337 owner
->FillRect(rect
);
341 owner
->SetFont(be_bold_font
);
343 owner
->SetFont(be_plain_font
);
346 owner
->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR
));
348 owner
->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR
));
351 owner
->GetFontHeight(&fheight
);
353 owner
->DrawString(Text(),
354 BPoint(rect
.left
+ be_control_look
->DefaultLabelSpacing(),
355 rect
.top
+ fheight
.ascent
+ 2 + floorf(fheight
.leading
/ 2)));
357 owner
->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR
));
358 owner
->SetLowColor(owner
->ViewColor());
366 return fSettingsView
;