2005-05-23 04:58:42 +04:00
|
|
|
/*
|
|
|
|
Open Tracker License
|
|
|
|
|
|
|
|
Terms and Conditions
|
|
|
|
|
|
|
|
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice applies to all licensees
|
|
|
|
and shall be included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
BE INCORPORATED 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.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of Be Incorporated shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings in
|
|
|
|
this Software without prior written authorization from Be Incorporated.
|
|
|
|
|
|
|
|
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
|
|
|
|
of Be Incorporated in the United States and other countries. Other brand product
|
|
|
|
names are registered trademarks or trademarks of their respective holders.
|
|
|
|
All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
#include "SettingsViews.h"
|
|
|
|
#include "TrackerSettings.h"
|
|
|
|
#include "TrackerSettingsWindow.h"
|
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
//#include <CheckBox.h>
|
|
|
|
#include <ScrollView.h>
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
namespace BPrivate {
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
class SettingsItem : public BStringItem {
|
|
|
|
public:
|
|
|
|
SettingsItem(const char *label, SettingsView *view);
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
void DrawItem(BView *owner, BRect rect, bool drawEverything);
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
SettingsView *View();
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
private:
|
|
|
|
SettingsView *fSettingsView;
|
|
|
|
};
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
} // namespace BPrivate
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
const uint32 kSettingsViewChanged = 'Svch';
|
|
|
|
const uint32 kDefaultsButtonPressed = 'Apbp';
|
|
|
|
const uint32 kRevertButtonPressed = 'Rebp';
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::TrackerSettingsWindow()
|
2007-01-21 23:50:14 +03:00
|
|
|
: BWindow(BRect(80, 80, 450, 350), "Tracker Preferences", B_TITLED_WINDOW,
|
2006-06-25 14:46:00 +04:00
|
|
|
B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_NO_WORKSPACE_ACTIVATION
|
|
|
|
| B_NOT_ANCHORED_ON_ACTIVATE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
|
|
|
{
|
|
|
|
BRect rect = Bounds();
|
|
|
|
BView *topView = new BView(rect, "Background", B_FOLLOW_ALL, 0);
|
|
|
|
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
|
|
AddChild(topView);
|
|
|
|
|
|
|
|
rect.InsetBy(10, 10);
|
|
|
|
rect.right = rect.left + be_plain_font->StringWidth("Volume Icons")
|
2006-08-11 17:23:10 +04:00
|
|
|
+ (float)B_V_SCROLL_BAR_WIDTH + 40.0f;
|
2006-06-25 14:46:00 +04:00
|
|
|
fSettingsTypeListView = new BListView(rect, "List View", B_SINGLE_SELECTION_LIST,
|
|
|
|
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
|
|
|
|
BScrollView* scrollView = new BScrollView("scrollview", fSettingsTypeListView,
|
|
|
|
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
|
|
|
|
topView->AddChild(scrollView);
|
|
|
|
|
|
|
|
rect = scrollView->Frame();
|
|
|
|
rect.left = rect.right + 10;
|
|
|
|
rect.top = rect.bottom;
|
|
|
|
fDefaultsButton = new BButton(rect, "Defaults", "Defaults",
|
|
|
|
new BMessage(kDefaultsButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
2005-05-23 04:58:42 +04:00
|
|
|
fDefaultsButton->ResizeToPreferred();
|
2007-08-24 05:17:18 +04:00
|
|
|
fDefaultsButton->SetEnabled(false);
|
2006-06-25 14:46:00 +04:00
|
|
|
fDefaultsButton->MoveBy(0, -fDefaultsButton->Bounds().Height());
|
|
|
|
topView->AddChild(fDefaultsButton);
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
rect = fDefaultsButton->Frame();
|
|
|
|
rect.left = rect.right + 10;
|
|
|
|
fRevertButton = new BButton(rect, "Revert", "Revert",
|
|
|
|
new BMessage(kRevertButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
2005-05-23 04:58:42 +04:00
|
|
|
fRevertButton->SetEnabled(false);
|
|
|
|
fRevertButton->ResizeToPreferred();
|
2006-06-25 14:46:00 +04:00
|
|
|
topView->AddChild(fRevertButton);
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
rect = scrollView->Frame();
|
|
|
|
rect.left = rect.right + 10;
|
|
|
|
rect.right = Bounds().right - 10;
|
|
|
|
rect.bottom = fDefaultsButton->Frame().top - 10;
|
|
|
|
fSettingsContainerBox = new BBox(rect, NULL, B_FOLLOW_ALL);
|
|
|
|
topView->AddChild(fSettingsContainerBox);
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
rect = _SettingsFrame();
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
fSettingsTypeListView->AddItem(new SettingsItem("Desktop",
|
2006-06-25 14:46:00 +04:00
|
|
|
new DesktopSettingsView(rect)));
|
2005-05-23 04:58:42 +04:00
|
|
|
fSettingsTypeListView->AddItem(new SettingsItem("Windows",
|
2006-06-25 14:46:00 +04:00
|
|
|
new WindowsSettingsView(rect)));
|
2007-01-21 23:50:14 +03:00
|
|
|
fSettingsTypeListView->AddItem(new SettingsItem("Date and Time",
|
2006-06-25 14:46:00 +04:00
|
|
|
new TimeFormatSettingsView(rect)));
|
2005-05-23 04:58:42 +04:00
|
|
|
fSettingsTypeListView->AddItem(new SettingsItem("Trash",
|
2006-06-25 14:46:00 +04:00
|
|
|
new TrashSettingsView(rect)));
|
2005-05-23 04:58:42 +04:00
|
|
|
fSettingsTypeListView->AddItem(new SettingsItem("Volume Icons",
|
2006-06-25 14:46:00 +04:00
|
|
|
new SpaceBarSettingsView(rect)));
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
// compute preferred view size
|
|
|
|
|
|
|
|
float minWidth = 0, minHeight = 0;
|
|
|
|
|
|
|
|
for (int32 i = 0; i < fSettingsTypeListView->CountItems(); i++) {
|
|
|
|
SettingsView* view = ((SettingsItem *)fSettingsTypeListView->ItemAt(i))->View();
|
|
|
|
|
|
|
|
float width, height;
|
|
|
|
view->GetPreferredSize(&width, &height);
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
if (minWidth < width)
|
|
|
|
minWidth = width;
|
|
|
|
if (minHeight < height)
|
|
|
|
minHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeBy(max_c(minWidth - rect.Width(), 0), max_c(minHeight - rect.Height(), 0));
|
|
|
|
// make sure window is large enough to contain all views
|
|
|
|
|
|
|
|
fSettingsTypeListView->SetSelectionMessage(new BMessage(kSettingsViewChanged));
|
2005-05-23 04:58:42 +04:00
|
|
|
fSettingsTypeListView->Select(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TrackerSettingsWindow::QuitRequested()
|
|
|
|
{
|
|
|
|
bool isHidden = false;
|
|
|
|
|
|
|
|
if (Lock()) {
|
|
|
|
isHidden = IsHidden();
|
|
|
|
Unlock();
|
|
|
|
} else
|
|
|
|
return true;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (isHidden)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackerSettingsWindow::MessageReceived(BMessage *message)
|
|
|
|
{
|
|
|
|
switch (message->what) {
|
|
|
|
case kSettingsContentsModified:
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandleChangedContents();
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
case kDefaultsButtonPressed:
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandlePressedDefaultsButton();
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
case kRevertButtonPressed:
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandlePressedRevertButton();
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kSettingsViewChanged:
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandleChangedSettingsView();
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
default:
|
|
|
|
_inherited::MessageReceived(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackerSettingsWindow::Show()
|
|
|
|
{
|
|
|
|
if (Lock()) {
|
|
|
|
int32 itemCount = fSettingsTypeListView->CountItems();
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
for (int32 i = 0; i < itemCount; i++) {
|
2006-06-25 14:46:00 +04:00
|
|
|
_ViewAt(i)->RecordRevertSettings();
|
|
|
|
_ViewAt(i)->ShowCurrentSettings();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fSettingsTypeListView->Invalidate();
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2008-02-18 21:08:48 +03:00
|
|
|
_UpdateButtons();
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
_inherited::Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SettingsView *
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::_ViewAt(int32 i)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
if (!Lock())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SettingsItem *item = dynamic_cast<SettingsItem*>(fSettingsTypeListView->ItemAt(i));
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
|
|
|
|
return item->View();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
BRect
|
|
|
|
TrackerSettingsWindow::_SettingsFrame()
|
|
|
|
{
|
|
|
|
font_height fontHeight;
|
|
|
|
be_bold_font->GetHeight(&fontHeight);
|
|
|
|
|
|
|
|
BRect rect = fSettingsContainerBox->Bounds().InsetByCopy(8, 8);
|
|
|
|
rect.top += ceilf(fontHeight.ascent + fontHeight.descent);
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
void
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::_HandleChangedContents()
|
2008-02-18 21:08:48 +03:00
|
|
|
{
|
|
|
|
fSettingsTypeListView->Invalidate();
|
|
|
|
_UpdateButtons();
|
|
|
|
|
|
|
|
TrackerSettings().SaveSettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackerSettingsWindow::_UpdateButtons()
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
int32 itemCount = fSettingsTypeListView->CountItems();
|
|
|
|
|
2007-08-24 05:17:18 +04:00
|
|
|
bool defaultable = false;
|
2005-05-23 04:58:42 +04:00
|
|
|
bool revertable = false;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
for (int32 i = 0; i < itemCount; i++) {
|
2007-08-24 05:17:18 +04:00
|
|
|
defaultable |= _ViewAt(i)->IsDefaultable();
|
2006-06-25 14:46:00 +04:00
|
|
|
revertable |= _ViewAt(i)->IsRevertable();
|
2006-06-01 14:47:12 +04:00
|
|
|
}
|
2008-02-18 21:08:48 +03:00
|
|
|
|
2007-08-24 05:17:18 +04:00
|
|
|
fDefaultsButton->SetEnabled(defaultable);
|
2005-05-23 04:58:42 +04:00
|
|
|
fRevertButton->SetEnabled(revertable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::_HandlePressedDefaultsButton()
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
int32 itemCount = fSettingsTypeListView->CountItems();
|
|
|
|
|
2007-08-24 05:17:18 +04:00
|
|
|
for (int32 i = 0; i < itemCount; i++) {
|
|
|
|
if (_ViewAt(i)->IsDefaultable())
|
|
|
|
_ViewAt(i)->SetDefaults();
|
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandleChangedContents();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::_HandlePressedRevertButton()
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
int32 itemCount = fSettingsTypeListView->CountItems();
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
for (int32 i = 0; i < itemCount; i++) {
|
2006-06-25 14:46:00 +04:00
|
|
|
if (_ViewAt(i)->IsRevertable())
|
|
|
|
_ViewAt(i)->Revert();
|
2006-06-01 14:47:12 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2006-06-25 14:46:00 +04:00
|
|
|
_HandleChangedContents();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
void
|
2006-06-25 14:46:00 +04:00
|
|
|
TrackerSettingsWindow::_HandleChangedSettingsView()
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
int32 currentSelection = fSettingsTypeListView->CurrentSelection();
|
|
|
|
if (currentSelection < 0)
|
|
|
|
return;
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
BView *oldView = fSettingsContainerBox->ChildAt(0);
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (oldView)
|
|
|
|
oldView->RemoveSelf();
|
|
|
|
|
|
|
|
SettingsItem *selectedItem =
|
|
|
|
dynamic_cast<SettingsItem*>(fSettingsTypeListView->ItemAt(currentSelection));
|
|
|
|
|
|
|
|
if (selectedItem) {
|
|
|
|
fSettingsContainerBox->SetLabel(selectedItem->Text());
|
2006-06-25 14:46:00 +04:00
|
|
|
|
|
|
|
BView *view = selectedItem->View();
|
|
|
|
view->SetViewColor(fSettingsContainerBox->ViewColor());
|
|
|
|
view->Hide();
|
|
|
|
fSettingsContainerBox->AddChild(view);
|
|
|
|
|
|
|
|
// Resize view after it has been attached to the window, so that
|
|
|
|
// it's resizing modes are respected
|
|
|
|
BRect rect = _SettingsFrame();
|
|
|
|
view->ResizeTo(rect.Width(), rect.Height());
|
|
|
|
view->Show();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
SettingsItem::SettingsItem(const char *label, SettingsView *view)
|
2006-06-01 14:47:12 +04:00
|
|
|
: BStringItem(label),
|
|
|
|
fSettingsView(view)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
SettingsItem::DrawItem(BView *owner, BRect rect, bool drawEverything)
|
|
|
|
{
|
|
|
|
const rgb_color kModifiedColor = {0, 0, 255, 0};
|
|
|
|
const rgb_color kBlack = {0, 0, 0, 0};
|
|
|
|
const rgb_color kSelectedColor = {140, 140, 140, 0};
|
|
|
|
|
|
|
|
if (fSettingsView) {
|
2006-06-01 14:47:12 +04:00
|
|
|
bool isRevertable = fSettingsView->IsRevertable();
|
2005-05-23 04:58:42 +04:00
|
|
|
bool isSelected = IsSelected();
|
|
|
|
|
|
|
|
if (isSelected || drawEverything) {
|
|
|
|
rgb_color color;
|
|
|
|
if (isSelected)
|
|
|
|
color = kSelectedColor;
|
|
|
|
else
|
|
|
|
color = owner->ViewColor();
|
|
|
|
|
|
|
|
owner->SetHighColor(color);
|
|
|
|
owner->SetLowColor(color);
|
|
|
|
owner->FillRect(rect);
|
|
|
|
}
|
2006-06-01 14:47:12 +04:00
|
|
|
|
|
|
|
if (isRevertable)
|
2005-05-23 04:58:42 +04:00
|
|
|
owner->SetHighColor(kModifiedColor);
|
|
|
|
else
|
|
|
|
owner->SetHighColor(kBlack);
|
|
|
|
|
2009-01-25 22:12:58 +03:00
|
|
|
font_height fheight;
|
|
|
|
owner->GetFontHeight(&fheight);
|
|
|
|
owner->MovePenTo(rect.left + 4, rect.top + fheight.ascent + 2 + floorf(fheight.leading / 2));
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
owner->DrawString(Text());
|
|
|
|
|
|
|
|
owner->SetHighColor(kBlack);
|
|
|
|
owner->SetLowColor(owner->ViewColor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-01 14:47:12 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
SettingsView *
|
|
|
|
SettingsItem::View()
|
|
|
|
{
|
|
|
|
return fSettingsView;
|
|
|
|
}
|