hrev45037 adds 5 changesets to branch 'master' old head: 9a538a294cdef4c1517054b1a1e3aab8b6d63444 new head: defcf2ebc4c6cc54b82a6233897bef969a97deca overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=defcf2e+%5E9a538a2 ---------------------------------------------------------------------------- 31c0024: Add Deskbar clock settings to Time Preferences * Added a new Clock tab to the Time preflet. Added Clock related controls there. They all function by communicating with Deskbar. * Put controls in a BBox controlled by the Show clock checkbox. This more clearly shows that all the clock settings are dependent on the show clock setting since it doesn't matter what your clock settings are if you don't show the clock. * Make revert work. * Split clock settings into it's own file and struct. * Re-add the time zone setting. * Remove the clock settings from the Deskbar preference window, they are in Time now. * Make Locale preferences accepts B_LOCALE_CHANGED message, although not used. c5b556a: Rearrange Deskbar preferences to use a list view like Tracker Instead of showing all Deskbar preferences at once, show them one at a time using a list view to switch between them like Tracker preferences. 9fd9f94: Make prefs window height depend on content 37fb25e: On second thought, AddGlue to all 3 so the window stays the same height defcf2e: Add newline at the end of PreferencesWindow.cpp This completes the move of clock preferences from Deskbar to Time. This closes #7331. Also closing #8769 as invalid as it has been discussed to death and 12/24 hour setting seems to belong in Locale prefs only. Clock preferences have been moved into their own settings file as well so perhaps will be moved to their own replicant in the future. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 21 files changed, 667 insertions(+), 157 deletions(-) src/apps/deskbar/BarApp.cpp | 78 ++++++-- src/apps/deskbar/BarApp.h | 11 +- src/apps/deskbar/BarView.cpp | 5 + src/apps/deskbar/DeskbarMenu.cpp | 7 +- src/apps/deskbar/DeskbarMenu.h | 2 + src/apps/deskbar/PreferencesWindow.cpp | 151 +++++++++----- src/apps/deskbar/PreferencesWindow.h | 17 +- src/apps/deskbar/StatusView.cpp | 62 ++++-- src/apps/deskbar/TimeView.cpp | 80 ++++---- src/apps/deskbar/TimeView.h | 36 +++- src/preferences/locale/FormatSettingsView.cpp | 17 +- src/preferences/locale/LocalePreflet.cpp | 5 + src/preferences/locale/LocaleWindow.cpp | 7 +- src/preferences/time/ClockView.cpp | 227 ++++++++++++++++++++++ src/preferences/time/ClockView.h | 44 +++++ src/preferences/time/Jamfile | 1 + src/preferences/time/Time.cpp | 17 ++ src/preferences/time/Time.h | 3 + src/preferences/time/TimeMessages.h | 18 ++ src/preferences/time/TimeWindow.cpp | 26 ++- src/preferences/time/TimeWindow.h | 10 +- ############################################################################ Commit: 31c0024d1b271b0b671c77432cce0be483b366f0 URL: http://cgit.haiku-os.org/haiku/commit/?id=31c0024 Author: John Scipione <jscipione@xxxxxxxxx> Date: Thu Nov 8 05:43:14 2012 UTC Add Deskbar clock settings to Time Preferences * Added a new Clock tab to the Time preflet. Added Clock related controls there. They all function by communicating with Deskbar. * Put controls in a BBox controlled by the Show clock checkbox. This more clearly shows that all the clock settings are dependent on the show clock setting since it doesn't matter what your clock settings are if you don't show the clock. * Make revert work. * Split clock settings into it's own file and struct. * Re-add the time zone setting. * Remove the clock settings from the Deskbar preference window, they are in Time now. * Make Locale preferences accepts B_LOCALE_CHANGED message, although not used. ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 42160e0..563de4e 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -51,6 +51,8 @@ All rights reserved. #include <FindDirectory.h> #include <Locale.h> #include <Mime.h> +#include <Message.h> +#include <Messenger.h> #include <Path.h> #include <Roster.h> #include <RosterPrivate.h> @@ -74,9 +76,8 @@ BList TBarApp::sBarTeamInfoList; BList TBarApp::sSubscribers; -const uint32 kShowDeskbarMenu = 'BeMn'; -const uint32 kShowTeamMenu = 'TmMn'; - +const uint32 kShowDeskbarMenu = 'BeMn'; +const uint32 kShowTeamMenu = 'TmMn'; static const color_space kIconColorSpace = B_RGBA32; @@ -95,6 +96,7 @@ main() TBarApp::TBarApp() : BApplication(kDeskbarSignature), fSettingsFile(NULL), + fClockSettingsFile(NULL), fPreferencesWindow(NULL) { InitSettings(); @@ -159,8 +161,11 @@ TBarApp::~TBarApp() = static_cast<BMessenger*>(sSubscribers.ItemAt(i)); delete messenger; } + SaveSettings(); + delete fSettingsFile; + delete fClockSettingsFile; } @@ -204,9 +209,6 @@ TBarApp::SaveSettings() storedSettings.AddInt32("state", fSettings.state); storedSettings.AddFloat("width", fSettings.width); - storedSettings.AddBool("showSeconds", fSettings.showSeconds); - storedSettings.AddBool("showDayOfWeek", fSettings.showDayOfWeek); - storedSettings.AddPoint("switcherLoc", fSettings.switcherLoc); storedSettings.AddInt32("recentAppsCount", fSettings.recentAppsCount); storedSettings.AddInt32("recentDocsCount", fSettings.recentDocsCount); @@ -233,6 +235,20 @@ TBarApp::SaveSettings() storedSettings.Flatten(fSettingsFile); } + + if (fClockSettingsFile->InitCheck() == B_OK) { + fClockSettingsFile->Seek(0, SEEK_SET); + BMessage storedSettings; + + storedSettings.AddBool("showSeconds", + fClockSettings.showSeconds); + storedSettings.AddBool("showDayOfWeek", + fClockSettings.showDayOfWeek); + storedSettings.AddBool("showTimeZone", + fClockSettings.showTimeZone); + + storedSettings.Flatten(fClockSettingsFile); + } } @@ -243,8 +259,6 @@ TBarApp::InitSettings() settings.vertical = true; settings.left = false; settings.top = true; - settings.showSeconds = false; - settings.showDayOfWeek = false; settings.state = kExpandoState; settings.width = 0; settings.switcherLoc = BPoint(5000, 5000); @@ -266,13 +280,19 @@ TBarApp::InitSettings() settings.recentDocsEnabled = true; settings.recentFoldersEnabled = true; + clock_settings clock; + clock.showSeconds = false; + clock.showDayOfWeek = false; + clock.showTimeZone = false; + BPath dirPath; const char* settingsFileName = "Deskbar_settings"; + const char* clockSettingsFileName = "Deskbar_clock_settings"; find_directory(B_USER_DESKBAR_DIRECTORY, &dirPath, true); // just make it - if (find_directory (B_USER_SETTINGS_DIRECTORY, &dirPath, true) == B_OK) { + if (find_directory(B_USER_SETTINGS_DIRECTORY, &dirPath, true) == B_OK) { BPath filePath = dirPath; filePath.Append(settingsFileName); fSettingsFile = new BFile(filePath.Path(), O_RDWR); @@ -282,6 +302,13 @@ TBarApp::InitSettings() theDir.CreateFile(settingsFileName, fSettingsFile); } + fClockSettingsFile = new BFile(filePath.Path(), O_RDWR); + if (fClockSettingsFile->InitCheck() != B_OK) { + BDirectory theDir(dirPath.Path()); + if (theDir.InitCheck() == B_OK) + theDir.CreateFile(clockSettingsFileName, fClockSettingsFile); + } + BMessage storedSettings; if (fSettingsFile->InitCheck() == B_OK && storedSettings.Unflatten(fSettingsFile) == B_OK) { @@ -299,14 +326,6 @@ TBarApp::InitSettings() } if (storedSettings.FindFloat("width", &settings.width) != B_OK) settings.width = 0; - if (storedSettings.FindBool("showSeconds", &settings.showSeconds) - != B_OK) { - settings.showSeconds = false; - } - if (storedSettings.FindBool("showDayOfWeek", &settings.showDayOfWeek) - != B_OK) { - settings.showDayOfWeek = false; - } if (storedSettings.FindPoint("switcherLoc", &settings.switcherLoc) != B_OK) { settings.switcherLoc = BPoint(5000, 5000); @@ -378,9 +397,26 @@ TBarApp::InitSettings() settings.recentFoldersEnabled = true; } } + + if (fClockSettingsFile->InitCheck() == B_OK + && storedSettings.Unflatten(fClockSettingsFile) == B_OK) { + if (storedSettings.FindBool("showSeconds", &clock.showSeconds) + != B_OK) { + clock.showSeconds = false; + } + if (storedSettings.FindBool("showDayOfWeek", + &clock.showDayOfWeek) != B_OK) { + clock.showDayOfWeek = false; + } + if (storedSettings.FindBool("showTimeZone", + &clock.showTimeZone) != B_OK) { + clock.showDayOfWeek = false; + } + } } fSettings = settings; + fClockSettings = clock; } @@ -626,13 +662,19 @@ TBarApp::MessageReceived(BMessage* message) bool localize; if (message->FindBool("filesys", &localize) == B_OK) gLocalizedNamePreferred = localize; + } + // fall-through + case kShowHideTime: + case kShowSeconds: + case kShowDayOfWeek: + case kShowTimeZone: + case kGetClockSettings: fStatusViewMessenger.SendMessage(message); // Notify the replicant tray (through BarView) that the time // interval has changed and it should update the time view // and reflow the tray icons. break; - } default: BApplication::MessageReceived(message); diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 2c81757..0427150 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -75,8 +75,6 @@ struct desk_settings { bool vertical; bool left; bool top; - bool showSeconds; - bool showDayOfWeek; uint32 state; float width; BPoint switcherLoc; @@ -99,6 +97,12 @@ struct desk_settings { bool recentFoldersEnabled; }; +struct clock_settings { + bool showSeconds; + bool showDayOfWeek; + bool showTimeZone; +}; + class BFile; class BList; class BBitmap; @@ -132,6 +136,7 @@ class TBarApp : public BApplication { virtual void RefsReceived(BMessage* refs); desk_settings* Settings() { return &fSettings; } + clock_settings* ClockSettings() { return &fClockSettings; } TBarView* BarView() const { return fBarView; } TBarWindow* BarWindow() const { return fBarWindow; } @@ -156,7 +161,9 @@ class TBarApp : public BApplication { BMessenger fSwitcherMessenger; BMessenger fStatusViewMessenger; BFile* fSettingsFile; + BFile* fClockSettingsFile; desk_settings fSettings; + clock_settings fClockSettings; PreferencesWindow* fPreferencesWindow; diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 6f89271..2c0fb4f 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -223,6 +223,11 @@ TBarView::MessageReceived(BMessage* message) { switch (message->what) { case B_LOCALE_CHANGED: + case kShowHideTime: + case kShowSeconds: + case kShowDayOfWeek: + case kShowTimeZone: + case kGetClockSettings: fReplicantTray->MessageReceived(message); break; diff --git a/src/apps/deskbar/DeskbarMenu.cpp b/src/apps/deskbar/DeskbarMenu.cpp index 04d51fb..b85c082 100644 --- a/src/apps/deskbar/DeskbarMenu.cpp +++ b/src/apps/deskbar/DeskbarMenu.cpp @@ -388,13 +388,12 @@ TDeskbarMenu::ResetTargets() case kRebootSystem: case kSuspendSystem: case kShutdownSystem: - item->SetTarget(be_app); - break; - case kShowHideTime: case kShowSeconds: case kShowDayOfWeek: - item->SetTarget(fBarView->fReplicantTray); + case kShowTimeZone: + case kGetClockSettings: + item->SetTarget(be_app); break; } } diff --git a/src/apps/deskbar/DeskbarMenu.h b/src/apps/deskbar/DeskbarMenu.h index ce9b7a6..3737a32 100644 --- a/src/apps/deskbar/DeskbarMenu.h +++ b/src/apps/deskbar/DeskbarMenu.h @@ -37,6 +37,8 @@ All rights reserved. #include "NavMenu.h" +#include "PreferencesWindow.h" + // for message constants class TBarView; diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index 5a0da89..9826970 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -91,12 +91,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"), new BMessage(kAutoHide)); - // Clock controls - fShowSeconds = new BCheckBox(B_TRANSLATE("Show seconds"), - new BMessage(kShowSeconds)); - fShowDayOfWeek = new BCheckBox(B_TRANSLATE("Show day of week"), - new BMessage(kShowDayOfWeek)); - // Get settings from BarApp TBarApp* barApp = static_cast<TBarApp*>(be_app); desk_settings* settings = barApp->Settings(); @@ -156,16 +150,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAutoRaise->SetValue(settings->autoRaise); fWindowAutoHide->SetValue(settings->autoHide); - // Clock settings - TReplicantTray* replicantTray = barApp->BarView()->ReplicantTray(); - if (replicantTray->Time() != NULL) { - fShowSeconds->SetValue(replicantTray->Time()->ShowSeconds()); - fShowDayOfWeek->SetValue(replicantTray->Time()->ShowDayOfWeek()); - } else { - fShowSeconds->SetValue(settings->showSeconds); - fShowDayOfWeek->SetValue(settings->showDayOfWeek); - } - EnableDisableDependentItems(); // Targets @@ -179,19 +163,14 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAutoRaise->SetTarget(be_app); fWindowAutoHide->SetTarget(be_app); - fShowSeconds->SetTarget(replicantTray); - fShowDayOfWeek->SetTarget(replicantTray); - // Layout fMenuBox = new BBox("fMenuBox"); fAppsBox = new BBox("fAppsBox"); fWindowBox = new BBox("fWindowBox"); - fClockBox = new BBox("fClockBox"); fMenuBox->SetLabel(B_TRANSLATE("Menu")); fAppsBox->SetLabel(B_TRANSLATE("Applications")); fWindowBox->SetLabel(B_TRANSLATE("Window")); - fClockBox->SetLabel(B_TRANSLATE("Clock")); BView* view; view = BLayoutBuilder::Group<>() @@ -252,25 +231,12 @@ PreferencesWindow::PreferencesWindow(BRect frame) .View(); fWindowBox->AddChild(view); - view = BLayoutBuilder::Group<>() - .AddGroup(B_VERTICAL, 0) - .Add(fShowSeconds) - .Add(fShowDayOfWeek) - .AddGlue() - .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) - .End() - .View(); - fClockBox->AddChild(view); - BLayoutBuilder::Group<>(this) - .AddGrid(5, 5) - .Add(fMenuBox, 0, 0) - .Add(fWindowBox, 1, 0) - .Add(fAppsBox, 0, 1) - .Add(fClockBox, 1, 1) - .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) + .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING) + .Add(fMenuBox) + .Add(fAppsBox) + .Add(fWindowBox) + .SetInsets(B_USE_DEFAULT_SPACING) .End() .End(); diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h index 86fd9c2..d942165 100644 --- a/src/apps/deskbar/PreferencesWindow.h +++ b/src/apps/deskbar/PreferencesWindow.h @@ -23,11 +23,6 @@ const uint32 kResizeTeamIcons = 'RTIs'; const uint32 kAutoRaise = 'AtRs'; const uint32 kAutoHide = 'AtHd'; -const uint32 kShowHideTime = 'ShTm'; -const uint32 kShowSeconds = 'SwSc'; -const uint32 kShowDayOfWeek = 'SwDw'; - - class BBox; class BButton; class BCheckBox; @@ -51,7 +46,6 @@ public: private: BBox* fMenuBox; BBox* fAppsBox; - BBox* fClockBox; BBox* fWindowBox; BCheckBox* fMenuRecentDocuments; @@ -72,9 +66,6 @@ private: BCheckBox* fWindowAlwaysOnTop; BCheckBox* fWindowAutoRaise; BCheckBox* fWindowAutoHide; - - BCheckBox* fShowSeconds; - BCheckBox* fShowDayOfWeek; }; diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index fcea955..b9e6976 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -147,14 +147,8 @@ TReplicantTray::TReplicantTray(TBarView* parent, bool vertical) fMinimumTrayWidth = sMinimumWindowWidth - kGutter - kDragRegionWidth; } - BFormattingConventions conventions; - BLocale::Default()->GetFormattingConventions(&conventions); - bool use24HourClock = conventions.Use24HourClock(); - desk_settings* settings = ((TBarApp*)be_app)->Settings(); - // Create the time view - fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0, - use24HourClock, settings->showSeconds, settings->showDayOfWeek); + fTime = new TTimeView(fMinimumTrayWidth, kMaxReplicantHeight - 1.0); } @@ -180,6 +174,12 @@ TReplicantTray::AttachedToWindow() Window()->SetPulseRate(1000000); + // Set clock settings + clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); + fTime->SetShowSeconds(settings->showSeconds); + fTime->SetShowDayOfWeek(settings->showDayOfWeek); + fTime->SetShowTimeZone(settings->showTimeZone); + AddChild(fTime); fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - 1, 2); @@ -279,10 +279,7 @@ TReplicantTray::MessageReceived(BMessage* message) if (fTime == NULL) return; - // Locale may have updated 12/24 hour clock - BFormattingConventions conventions; - BLocale::Default()->GetFormattingConventions(&conventions); - fTime->SetUse24HourClock(conventions.Use24HourClock()); + fTime->Update(); // time string reformat -> realign RealignReplicants(); @@ -317,6 +314,36 @@ TReplicantTray::MessageReceived(BMessage* message) AdjustPlacement(); break; + case kShowTimeZone: + if (fTime == NULL) + return; + + fTime->SetShowTimeZone(!fTime->ShowTimeZone()); + + // time string reformat -> realign + RealignReplicants(); + AdjustPlacement(); + break; + + case kGetClockSettings: + { + if (fTime == NULL) + return; + + bool showClock = !fTime->IsHidden(); + bool showSeconds = fTime->ShowSeconds(); + bool showDayOfWeek = fTime->ShowDayOfWeek(); + bool showTimeZone = fTime->ShowTimeZone(); + + BMessage* reply = new BMessage(kGetClockSettings); + reply->AddBool("showClock", showClock); + reply->AddBool("showSeconds", showSeconds); + reply->AddBool("showDayOfWeek", showDayOfWeek); + reply->AddBool("showTimeZone", showTimeZone); + message->SendReply(reply); + break; + } + #ifdef DB_ADDONS case B_NODE_MONITOR: HandleEntryUpdate(message); @@ -375,12 +402,12 @@ TReplicantTray::ShowReplicantMenu(BPoint point) BPopUpMenu* menu = new BPopUpMenu("", false, false); menu->SetFont(be_plain_font); - // If clock is visible show the extended menu, otherwise show "Show time" + // If clock is visible show the extended menu, otherwise show "Show clock" if (!fTime->IsHidden()) fTime->ShowTimeOptions(ConvertToScreen(point)); else { - BMenuItem* item = new BMenuItem(B_TRANSLATE("Show time"), + BMenuItem* item = new BMenuItem(B_TRANSLATE("Show clock"), new BMessage(kShowHideTime)); menu->AddItem(item); menu->SetTargetForItems(this); @@ -411,6 +438,12 @@ TReplicantTray::ShowHideTime() RealignReplicants(); AdjustPlacement(); + + // message Time preferences to update it's show time setting + BMessenger messenger("application/x-vnd.Haiku-Time"); + BMessage* message = new BMessage(kShowHideTime); + message->AddBool("showClock", !fTime->IsHidden()); + messenger.SendMessage(message); } @@ -1235,9 +1268,10 @@ TReplicantTray::SaveTimeSettings() if (fTime == NULL) return; - desk_settings* settings = ((TBarApp*)be_app)->Settings(); + clock_settings* settings = ((TBarApp*)be_app)->ClockSettings(); settings->showSeconds = fTime->ShowSeconds(); settings->showDayOfWeek = fTime->ShowDayOfWeek(); + settings->showTimeZone = fTime->ShowTimeZone(); } diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index b0f86be..0c6d0c8 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -38,6 +38,7 @@ All rights reserved. #include <string.h> +#include <Application.h> #include <Catalog.h> #include <Debug.h> #include <Locale.h> @@ -55,20 +56,11 @@ static const char* const kMinString = "99:99 AM"; static const float kHMargin = 2.0; -enum { - kShowTime, - kChangeTime, - kHide, - kShowCalendar -}; - - #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "TimeView" -TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock, - bool showSeconds, bool showDayOfWeek) +TTimeView::TTimeView(float maxWidth, float height) : BView(BRect(-100, -100, -90, -90), "_deskbar_tv_", B_FOLLOW_RIGHT | B_FOLLOW_TOP, @@ -77,9 +69,9 @@ TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock, fMaxWidth(maxWidth), fHeight(height), fOrientation(true), - fUse24HourClock(use24HourClock), - fShowSeconds(showSeconds), - fShowDayOfWeek(showDayOfWeek) + fShowSeconds(false), + fShowDayOfWeek(false), + fShowTimeZone(false) { fCurrentTime = fLastTime = time(NULL); fSeconds = fMinute = fHour = 0; @@ -88,7 +80,6 @@ TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock, fLastTimeStr[0] = 0; fLastDateStr[0] = 0; fNeedToUpdate = true; - fLocale = *BLocale::Default(); } @@ -125,7 +116,10 @@ status_t TTimeView::Archive(BMessage* data, bool deep) const { BView::Archive(data, deep); - data->AddBool("seconds", fShowSeconds); + data->AddBool("showSeconds", fShowSeconds); + data->AddBool("showDayOfWeek", fShowDayOfWeek); + data->AddBool("showTimeZone", fShowTimeZone); + data->AddBool("orientation", fOrientation); data->AddInt32("deskbar:private_align", B_ALIGN_RIGHT); return B_OK; @@ -194,13 +188,21 @@ TTimeView::MessageReceived(BMessage* message) { switch (message->what) { case kChangeTime: + { // launch the time prefs app be_roster->Launch("application/x-vnd.Haiku-Time"); + // tell Time preflet to switch to the clock tab + BMessenger messenger("application/x-vnd.Haiku-Time"); + BMessage* switchToClock = new BMessage('SlCk'); + messenger.SendMessage(switchToClock); break; + } case kShowHideTime: - Window()->PostMessage(message, Parent()); + { + be_app->MessageReceived(message); break; + } case kShowCalendar: { @@ -303,46 +305,46 @@ TTimeView::SetOrientation(bool orientation) bool -TTimeView::Use24HourClock() const +TTimeView::ShowSeconds() const { - return fUse24HourClock; + return fShowSeconds; } void -TTimeView::SetUse24HourClock(bool use24HourClock) +TTimeView::SetShowSeconds(bool show) { - fUse24HourClock = use24HourClock; + fShowSeconds = show; Update(); } bool -TTimeView::ShowSeconds() const +TTimeView::ShowDayOfWeek() const { - return fShowSeconds; + return fShowDayOfWeek; } void -TTimeView::SetShowSeconds(bool show) +TTimeView::SetShowDayOfWeek(bool show) { - fShowSeconds = show; + fShowDayOfWeek = show; Update(); } bool -TTimeView::ShowDayOfWeek() const +TTimeView::ShowTimeZone() const { - return fShowDayOfWeek; + return fShowTimeZone; } void -TTimeView::SetShowDayOfWeek(bool show) +TTimeView::SetShowTimeZone(bool show) { - fShowDayOfWeek = show; + fShowTimeZone = show; Update(); } @@ -379,16 +381,17 @@ TTimeView::ShowCalendar(BPoint where) void TTimeView::GetCurrentTime() { - ssize_t offset = 0; + ssize_t offset_dow = 0; + ssize_t offset_time = 0; // ToDo: Check to see if we should write day of week after time for locale if (fShowDayOfWeek) { BString timeFormat("eee "); - offset = fLocale.FormatTime(fCurrentTimeStr, sizeof(fCurrentTimeStr), - fCurrentTime, timeFormat); + offset_dow = fLocale.FormatTime(fCurrentTimeStr, + sizeof(fCurrentTimeStr), fCurrentTime, timeFormat); - if (offset < 0) { + if (offset_dow < 0) { // error occured, attempt to overwrite with current time // (this should not ever happen) fLocale.FormatTime(fCurrentTimeStr, sizeof(fCurrentTimeStr), @@ -398,9 +401,16 @@ TTimeView::GetCurrentTime() } } - fLocale.FormatTime(fCurrentTimeStr + offset, - sizeof(fCurrentTimeStr) - offset, fCurrentTime, + offset_time = fLocale.FormatTime(fCurrentTimeStr + offset_dow, + sizeof(fCurrentTimeStr) - offset_dow, fCurrentTime, fShowSeconds ? B_MEDIUM_TIME_FORMAT : B_SHORT_TIME_FORMAT); + + if (fShowTimeZone) { + BString timeFormat(" V"); + ssize_t offset = offset_dow + offset_time; + fLocale.FormatTime(fCurrentTimeStr + offset, + sizeof(fCurrentTimeStr) - offset, fCurrentTime, timeFormat); + } } @@ -456,7 +466,7 @@ TTimeView::ShowTimeOptions(BPoint point) new BMessage(kChangeTime)); menu->AddItem(item); - item = new BMenuItem(B_TRANSLATE("Hide time"), + item = new BMenuItem(B_TRANSLATE("Hide clock"), new BMessage(kShowHideTime)); menu->AddItem(item); diff --git a/src/apps/deskbar/TimeView.h b/src/apps/deskbar/TimeView.h index f273a10..129b202 100644 --- a/src/apps/deskbar/TimeView.h +++ b/src/apps/deskbar/TimeView.h @@ -41,7 +41,28 @@ All rights reserved. #include <Messenger.h> #include <View.h> -#include "PreferencesWindow.h" // For message constants + +// open Time preferences +const uint32 kChangeTime = 'ChTm'; + +// pop the calendar +const uint32 kShowCalendar = 'ShCa'; + +// show or hide clock +const uint32 kShowHideTime = 'ShTm'; + +// show seconds +const uint32 kShowSeconds = 'SwSc'; + +// show day of week +const uint32 kShowDayOfWeek = 'SwDw'; + +// show time zone +const uint32 kShowTimeZone = 'SwTz'; + +// get clock settings to send to Time prefs +const uint32 kGetClockSettings = 'GCkS'; + class BCountry; @@ -53,9 +74,7 @@ class _EXPORT TTimeView; class TTimeView : public BView { public: - TTimeView(float maxWidth, float height, - bool use24HourClock, bool showSeconds, - bool showDayOfWeek); + TTimeView(float maxWidth, float height); TTimeView(BMessage* data); ~TTimeView(); @@ -77,15 +96,15 @@ public: bool Orientation() const; void SetOrientation(bool o); - bool Use24HourClock() const; - void SetUse24HourClock(bool use24HourClock); - bool ShowSeconds() const; void SetShowSeconds(bool show); bool ShowDayOfWeek() const; void SetShowDayOfWeek(bool show); + bool ShowTimeZone() const; + void SetShowTimeZone(bool show); + void ShowCalendar(BPoint where); private: @@ -116,9 +135,12 @@ private: float fHeight; bool fOrientation; // vertical = true + bool fOverrideLocale; bool fUse24HourClock; bool fShowSeconds; bool fShowDayOfWeek; + bool fShowTimeZone; + BString fTimeFormat; BPoint fTimeLocation; diff --git a/src/preferences/locale/FormatSettingsView.cpp b/src/preferences/locale/FormatSettingsView.cpp index 2ea8cd4..0dc5f6b 100644 --- a/src/preferences/locale/FormatSettingsView.cpp +++ b/src/preferences/locale/FormatSettingsView.cpp @@ -258,12 +258,27 @@ void FormatSettingsView::MessageReceived(BMessage* message) { switch (message->what) { + case B_LOCALE_CHANGED: + { + // Time updated 12/24 hour clock + BFormattingConventions conventions; + BLocale::Default()->GetFormattingConventions(&conventions); + if (conventions.Use24HourClock()) + f24HourRadioButton->SetValue(B_CONTROL_ON); + else + f12HourRadioButton->SetValue(B_CONTROL_ON); + + _UpdateExamples(); + Window()->PostMessage(kMsgSettingsChanged); + break; + } + case kClockFormatChange: { BFormattingConventions conventions; BLocale::Default()->GetFormattingConventions(&conventions); conventions.SetExplicitUse24HourClock( - f24HourRadioButton->Value() ? true : false); + f24HourRadioButton->Value() == B_CONTROL_ON); MutableLocaleRoster::Default()->SetDefaultFormattingConventions( conventions); diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index d71b26b..65eb300 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -65,6 +65,11 @@ void LocalePreflet::MessageReceived(BMessage* message) { switch (message->what) { + case B_LOCALE_CHANGED: + BLocaleRoster::Default()->Refresh(); + fLocaleWindow->PostMessage(message); + break; + case kMsgRestartTrackerAndDeskbar: if (message->FindInt32("which") == 1) { _RestartApp("application/x-vnd.Be-TRAK"); diff --git a/src/preferences/locale/LocaleWindow.cpp b/src/preferences/locale/LocaleWindow.cpp index 97933bd..2a6b4ef 100644 --- a/src/preferences/locale/LocaleWindow.cpp +++ b/src/preferences/locale/LocaleWindow.cpp @@ -295,6 +295,10 @@ void LocaleWindow::MessageReceived(BMessage* message) { switch (message->what) { + case B_LOCALE_CHANGED: + fFormatView->MessageReceived(message); + break; + case kMsgDefaults: _Defaults(); break; @@ -478,8 +482,7 @@ LocaleWindow::Show() void LocaleWindow::_SettingsChanged() { - bool haveAnythingToRevert = fFormatView->IsReversible() || _IsReversible(); - fRevertButton->SetEnabled(haveAnythingToRevert); + fRevertButton->SetEnabled(fFormatView->IsReversible() || _IsReversible()); } diff --git a/src/preferences/time/ClockView.cpp b/src/preferences/time/ClockView.cpp new file mode 100644 index 0000000..8c51c67 --- /dev/null +++ b/src/preferences/time/ClockView.cpp @@ -0,0 +1,227 @@ +/* + * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * John Scipione <jscipione@xxxxxxxxx> + */ + +#include "ClockView.h" + +#include <Alignment.h> +#include <Box.h> +#include <Catalog.h> +#include <CheckBox.h> +#include <ControlLook.h> +#include <LayoutBuilder.h> +#include <Locale.h> +#include <Message.h> +#include <Messenger.h> +#include <RadioButton.h> +#include <SpaceLayoutItem.h> +#include <Window.h> + +#include "TimeMessages.h" + + +static const char* kDeskbarSignature = "application/x-vnd.Be-TSKB"; + +static const float kIndentSpacing + = be_control_look->DefaultItemSpacing() * 2.3; + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "Time" + + +ClockView::ClockView(const char* name) + : + BView(name, 0), + fCachedShowClock(B_CONTROL_ON), + fCachedShowSeconds(B_CONTROL_OFF), + fCachedShowDayOfWeek(B_CONTROL_OFF), + fCachedShowTimeZone(B_CONTROL_OFF) +{ + fShowClock = new BCheckBox(B_TRANSLATE("Show clock in Deskbar"), + new BMessage(kShowHideTime)); + fShowSeconds = new BCheckBox(B_TRANSLATE("Display time with seconds"), + new BMessage(kShowSeconds)); + fShowDayOfWeek = new BCheckBox(B_TRANSLATE("Show day of week"), + new BMessage(kShowDayOfWeek)); + fShowTimeZone = new BCheckBox(B_TRANSLATE("Show time zone"), + new BMessage(kShowTimeZone)); + + BView* view = BLayoutBuilder::Group<>(B_VERTICAL, 0) + .Add(fShowSeconds) + .Add(fShowDayOfWeek) + .Add(fShowTimeZone) + .AddGlue() + .SetInsets(B_USE_DEFAULT_SPACING) + .View(); + + BBox* showClockBox = new BBox("show clock box"); + showClockBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); + showClockBox->SetLabel(fShowClock); + showClockBox->AddChild(view); + + BLayoutBuilder::Group<>(this) + .AddGroup(B_VERTICAL, 0) + .Add(showClockBox) + .End() + .SetInsets(B_USE_DEFAULT_SPACING); +} + + +ClockView::~ClockView() +{ +} + + +void +ClockView::AttachedToWindow() +{ + if (Parent()) + SetViewColor(Parent()->ViewColor()); + + fShowClock->SetTarget(this); + fShowSeconds->SetTarget(this); + fShowDayOfWeek->SetTarget(this); + fShowTimeZone->SetTarget(this); + + // Disable these controls initially, they'll be enabled + // when we get a response from Deskbar. + fShowClock->SetEnabled(false); + fShowSeconds->SetEnabled(false); + fShowDayOfWeek->SetEnabled(false); + fShowTimeZone->SetEnabled(false); + + // Ask Deskbar for current clock settings, it will reply + // asynchronously in MesssageReceived() below. + BMessenger* messenger = new BMessenger(kDeskbarSignature); + BMessenger replyMessenger(this); + BMessage* message = new BMessage(kGetClockSettings); + messenger->SendMessage(message, replyMessenger); +} + + +void +ClockView::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kGetClockSettings: + { + // Get current clock settings from Deskbar + bool showClock; + bool showSeconds; + bool showDayOfWeek; + bool showTimeZone; + + if (message->FindBool("showSeconds", &showSeconds) == B_OK) { + fCachedShowSeconds = showSeconds + ? B_CONTROL_ON : B_CONTROL_OFF; + fShowSeconds->SetValue(fCachedShowSeconds); + fShowSeconds->SetEnabled(true); + } + + if (message->FindBool("showDayOfWeek", &showDayOfWeek) == B_OK) { + fCachedShowDayOfWeek = showDayOfWeek + ? B_CONTROL_ON : B_CONTROL_OFF; + fShowDayOfWeek->SetValue(fCachedShowDayOfWeek); + fShowDayOfWeek->SetEnabled(true); + } + + if (message->FindBool("showTimeZone", &showTimeZone) == B_OK) { + fCachedShowTimeZone = showTimeZone + ? B_CONTROL_ON : B_CONTROL_OFF; + fShowTimeZone->SetValue(fCachedShowTimeZone); + fShowTimeZone->SetEnabled(true); + } + + // do this one last because it might disable the others + if (message->FindBool("showClock", &showClock) == B_OK) { + fCachedShowClock = showClock ? B_CONTROL_ON : B_CONTROL_OFF; + fShowClock->SetValue(fCachedShowClock); + fShowClock->SetEnabled(true); + fShowSeconds->SetEnabled(showClock); + fShowDayOfWeek->SetEnabled(showClock); + fShowTimeZone->SetEnabled(showClock); + } + break; + } + + case kShowHideTime: + { + bool showClock; + if (message->FindBool("showClock", &showClock) == B_OK) { + // message originated from Deskbar, handle special + fShowClock->SetValue(showClock ? B_CONTROL_ON : B_CONTROL_OFF); + fShowSeconds->SetEnabled(showClock); + fShowDayOfWeek->SetEnabled(showClock); + fShowTimeZone->SetEnabled(showClock); + + Window()->PostMessage(kMsgChange); + break; + // don't fall through + } + showClock = fShowClock->Value() == B_CONTROL_ON; + fShowSeconds->SetEnabled(showClock); + fShowDayOfWeek->SetEnabled(showClock); + fShowTimeZone->SetEnabled(showClock); + } + // fall-through + case kShowSeconds: + case kShowDayOfWeek: + case kShowTimeZone: + { + BMessenger* messenger = new BMessenger(kDeskbarSignature); + messenger->SendMessage(message); + + Window()->PostMessage(kMsgChange); + + break; + } + + case kMsgRevert: + _Revert(); + break; + + default: + BView::MessageReceived(message); + break; + } +} + + +bool +ClockView::CheckCanRevert() +{ + return fShowClock->Value() != fCachedShowClock + || fShowSeconds->Value() != fCachedShowSeconds + || fShowDayOfWeek->Value() != fCachedShowDayOfWeek + || fShowTimeZone->Value() != fCachedShowTimeZone; +} + + +void +ClockView::_Revert() +{ + if (fShowClock->Value() != fCachedShowClock) { + fShowClock->SetValue(fCachedShowClock); + fShowClock->Invoke(); + } + + if (fShowSeconds->Value() != fCachedShowSeconds) { + fShowSeconds->SetValue(fCachedShowSeconds); + fShowSeconds->Invoke(); + } + + if (fShowDayOfWeek->Value() != fCachedShowDayOfWeek) { + fShowDayOfWeek->SetValue(fCachedShowDayOfWeek); + fShowDayOfWeek->Invoke(); + } + + if (fShowTimeZone->Value() != fCachedShowTimeZone) { + fShowTimeZone->SetValue(fCachedShowTimeZone); + fShowTimeZone->Invoke(); + } +} diff --git a/src/preferences/time/ClockView.h b/src/preferences/time/ClockView.h new file mode 100644 index 0000000..d5a6e65 --- /dev/null +++ b/src/preferences/time/ClockView.h @@ -0,0 +1,44 @@ +/* + * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * John Scipione <jscipione@xxxxxxxxx> + */ +#ifndef _CLOCK_VIEW_H +#define _CLOCK_VIEW_H + + +#include <View.h> + + +class BCheckBox; +class BRadioButton; + + +class ClockView : public BView { +public: + ClockView(const char* name); + virtual ~ClockView(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + + bool CheckCanRevert(); + +private: + void _Revert(); + + BCheckBox* fShowClock; + BCheckBox* fShowSeconds; + BCheckBox* fShowDayOfWeek; + BCheckBox* fShowTimeZone; + + int32 fCachedShowClock; + int32 fCachedShowSeconds; + int32 fCachedShowDayOfWeek; + int32 fCachedShowTimeZone; +}; + + +#endif // _CLOCK_VIEW_H diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile index 43e27b0..aa7154f 100644 --- a/src/preferences/time/Jamfile +++ b/src/preferences/time/Jamfile @@ -9,6 +9,7 @@ local sources = AnalogClock.cpp BaseView.cpp Bitmaps.cpp + ClockView.cpp DateTimeEdit.cpp SectionEdit.cpp DateTimeView.cpp diff --git a/src/preferences/time/Time.cpp b/src/preferences/time/Time.cpp index 10c462d..21a65ea 100644 --- a/src/preferences/time/Time.cpp +++ b/src/preferences/time/Time.cpp @@ -20,6 +20,7 @@ #include <Catalog.h> #include "NetworkTimeView.h" +#include "TimeMessages.h" #include "TimeWindow.h" @@ -64,6 +65,22 @@ TimeApplication::AboutRequested() } +void +TimeApplication::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kSelectClockTab: + case kShowHideTime: + fWindow->PostMessage(message); + break; + + default: + BApplication::MessageReceived(message); + break; + } +} + + int main(int argc, char** argv) { diff --git a/src/preferences/time/Time.h b/src/preferences/time/Time.h index a0af8e0..99ab955 100644 --- a/src/preferences/time/Time.h +++ b/src/preferences/time/Time.h @@ -14,6 +14,7 @@ #include <Application.h> +class BMessage; class TTimeWindow; @@ -25,6 +26,8 @@ public: virtual void ReadyToRun(); virtual void AboutRequested(); + virtual void MessageReceived(BMessage* message); + private: TTimeWindow* fWindow; }; diff --git a/src/preferences/time/TimeMessages.h b/src/preferences/time/TimeMessages.h index 51a5440..73206cf 100644 --- a/src/preferences/time/TimeMessages.h +++ b/src/preferences/time/TimeMessages.h @@ -49,5 +49,23 @@ const uint32 kMsgChange = 'chng'; // change time finished const uint32 kChangeTimeFinished = 'tcfi'; +// show or hide Deskbar clock +const uint32 kShowHideTime = 'ShTm'; + +// show seconds +const uint32 kShowSeconds = 'SwSc'; + +// show day of week +const uint32 kShowDayOfWeek = 'SwDw'; + +// show time zone +const uint32 kShowTimeZone = 'SwTz'; + +// get clock settings from Deskbar +const uint32 kGetClockSettings = 'GCkS'; + +// bring the clock tab to front +const uint32 kSelectClockTab = 'SlCk'; + #endif // _TIME_MESSAGES_H diff --git a/src/preferences/time/TimeWindow.cpp b/src/preferences/time/TimeWindow.cpp index 2c7c6e4..8d2e641 100644 --- a/src/preferences/time/TimeWindow.cpp +++ b/src/preferences/time/TimeWindow.cpp @@ -19,6 +19,7 @@ #include <TabView.h> #include "BaseView.h" +#include "ClockView.h" #include "DateTimeView.h" #include "NetworkTimeView.h" #include "TimeMessages.h" @@ -79,6 +80,7 @@ TTimeWindow::MessageReceived(BMessage* message) fDateTimeView->MessageReceived(message); fTimeZoneView->MessageReceived(message); fNetworkTimeView->MessageReceived(message); + fClockView->MessageReceived(message); fRevertButton->SetEnabled(false); break; @@ -92,6 +94,15 @@ TTimeWindow::MessageReceived(BMessage* message) _SetRevertStatus(); break; + case kSelectClockTab: + // focus the clock tab (last one) + fTabView->Select(fTabView->CountTabs() - 1); + break; + + case kShowHideTime: + fClockView->MessageReceived(message); + break; + default: BWindow::MessageReceived(message); break; @@ -107,17 +118,19 @@ TTimeWindow::_InitWindow() fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time")); fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone")); fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time")); + fClockView = new ClockView(B_TRANSLATE("Clock")); fBaseView = new TTimeBaseView("baseView"); fBaseView->StartWatchingAll(fDateTimeView); fBaseView->StartWatchingAll(fTimeZoneView); - BTabView* tabView = new BTabView("tabView"); - tabView->AddTab(fDateTimeView); - tabView->AddTab(fTimeZoneView); - tabView->AddTab(fNetworkTimeView); + fTabView = new BTabView("tabView"); + fTabView->AddTab(fDateTimeView); + fTabView->AddTab(fTimeZoneView); + fTabView->AddTab(fNetworkTimeView); + fTabView->AddTab(fClockView); - fBaseView->AddChild(tabView); + fBaseView->AddChild(fTabView); fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); @@ -166,5 +179,6 @@ TTimeWindow::_SetRevertStatus() { fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert() || fTimeZoneView->CheckCanRevert() - || fNetworkTimeView->CheckCanRevert()); + || fNetworkTimeView->CheckCanRevert() + || fClockView->CheckCanRevert()); } diff --git a/src/preferences/time/TimeWindow.h b/src/preferences/time/TimeWindow.h index 55ef884..46af79e 100644 --- a/src/preferences/time/TimeWindow.h +++ b/src/preferences/time/TimeWindow.h @@ -14,10 +14,12 @@ class BMessage; +class BTabView; +class ClockView; class DateTimeView; -class TTimeBaseView; -class TimeZoneView; class NetworkTimeView; +class TimeZoneView; +class TTimeBaseView; class TTimeWindow : public BWindow { @@ -35,9 +37,13 @@ private: void _SetRevertStatus(); TTimeBaseView* fBaseView; + + BTabView* fTabView; DateTimeView* fDateTimeView; TimeZoneView* fTimeZoneView; NetworkTimeView* fNetworkTimeView; + ClockView* fClockView; + BButton* fRevertButton; }; ############################################################################ Commit: c5b556a080ae265a2d6bedafbd5833f116153bc0 URL: http://cgit.haiku-os.org/haiku/commit/?id=c5b556a Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Nov 24 02:23:38 2012 UTC Rearrange Deskbar preferences to use a list view like Tracker Instead of showing all Deskbar preferences at once, show them one at a time using a list view to switch between them like Tracker preferences. ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index 9826970..6f2615b 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -19,14 +19,16 @@ #include <ControlLook.h> #include <FormattingConventions.h> #include <GroupLayout.h> +#include <ListView.h> #include <Locale.h> #include <LayoutBuilder.h> #include <OpenWithTracker.h> #include <RadioButton.h> #include <Roster.h> +#include <ScrollView.h> #include <SeparatorView.h> #include <Slider.h> -#include <StringView.h> +#include <StringItem.h> #include <TextControl.h> #include <View.h> @@ -34,8 +36,32 @@ #include "StatusView.h" +namespace BPrivate { + +class SettingsItem : public BStringItem { + public: + SettingsItem(const char* label, BView* view) + : + BStringItem(label), + fSettingsView(view) + { + } + + BView* View() + { + return fSettingsView; + } + + private: + BView* fSettingsView; +}; + +} // namespace BPrivate + + static const float kIndentSpacing = be_control_look->DefaultItemSpacing() * 2.3; +static const uint32 kSettingsViewChanged = 'Svch'; #undef B_TRANSLATION_CONTEXT @@ -47,6 +73,15 @@ PreferencesWindow::PreferencesWindow(BRect frame) BWindow(frame, B_TRANSLATE("Deskbar preferences"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE) { + // Main view controls + fSettingsTypeListView = new BListView("List View", + B_SINGLE_SELECTION_LIST); + + BScrollView* scrollView = new BScrollView("scrollview", + fSettingsTypeListView, 0, false, true); + + fSettingsContainerBox = new BBox("SettingsContainerBox"); + // Menu controls fMenuRecentDocuments = new BCheckBox(B_TRANSLATE("Recent documents:"), new BMessage(kUpdateRecentCounts)); @@ -164,16 +199,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAutoHide->SetTarget(be_app); // Layout - fMenuBox = new BBox("fMenuBox"); - fAppsBox = new BBox("fAppsBox"); - fWindowBox = new BBox("fWindowBox"); - - fMenuBox->SetLabel(B_TRANSLATE("Menu")); - fAppsBox->SetLabel(B_TRANSLATE("Applications")); - fWindowBox->SetLabel(B_TRANSLATE("Window")); - - BView* view; - view = BLayoutBuilder::Group<>() + BView* menuSettingsView = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 0) .AddGroup(B_VERTICAL, 0) @@ -196,9 +222,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); - fMenuBox->AddChild(view); - view = BLayoutBuilder::Group<>() + BView* applicationSettingsView = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .Add(fAppsSort) .Add(fAppsSortTrackerFirst) @@ -217,9 +242,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); - fAppsBox->AddChild(view); - view = BLayoutBuilder::Group<>() + BView* windowSettingsView = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .Add(fWindowAlwaysOnTop) .Add(fWindowAutoRaise) @@ -229,17 +253,33 @@ PreferencesWindow::PreferencesWindow(BRect frame) B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); - fWindowBox->AddChild(view); BLayoutBuilder::Group<>(this) - .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING) - .Add(fMenuBox) - .Add(fAppsBox) - .Add(fWindowBox) - .SetInsets(B_USE_DEFAULT_SPACING) - .End() + .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) + .Add(scrollView) + .Add(fSettingsContainerBox) + .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, + B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End(); + fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Menu"), + menuSettingsView)); + fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Application"), + applicationSettingsView)); + fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Window"), + windowSettingsView)); + + // constraint the listview width so that the longest item fits + float width = 0; + fSettingsTypeListView->GetPreferredSize(&width, NULL); + width += B_V_SCROLL_BAR_WIDTH; + fSettingsTypeListView->SetExplicitMinSize(BSize(width, 0)); + fSettingsTypeListView->SetExplicitMaxSize(BSize(width, B_SIZE_UNLIMITED)); + + fSettingsTypeListView->SetSelectionMessage( + new BMessage(kSettingsViewChanged)); + fSettingsTypeListView->Select(0); + CenterOnScreen(); } @@ -272,6 +312,10 @@ PreferencesWindow::MessageReceived(BMessage* message) EnableDisableDependentItems(); break; + case kSettingsViewChanged: + _HandleChangedSettingsView(); + break; + default: BWindow::MessageReceived(message); break; @@ -333,3 +377,35 @@ PreferencesWindow::EnableDisableDependentItems() fWindowAutoRaise->SetEnabled( fWindowAlwaysOnTop->Value() == B_CONTROL_OFF); } + + +// #pragma mark - + + +void +PreferencesWindow::_HandleChangedSettingsView() +{ + int32 currentSelection = fSettingsTypeListView->CurrentSelection(); + if (currentSelection < 0) + return; + + BView* oldView = fSettingsContainerBox->ChildAt(0); + + if (oldView) + oldView->RemoveSelf(); + + SettingsItem* selectedItem = + dynamic_cast<SettingsItem*> + (fSettingsTypeListView->ItemAt(currentSelection)); + + if (selectedItem) { + fSettingsContainerBox->SetLabel(selectedItem->Text()); + + BView* view = selectedItem->View(); + view->SetViewColor(fSettingsContainerBox->ViewColor()); + view->Hide(); + fSettingsContainerBox->AddChild(view); + + view->Show(); + } +} \ No newline at end of file diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h index d942165..3be45d9 100644 --- a/src/apps/deskbar/PreferencesWindow.h +++ b/src/apps/deskbar/PreferencesWindow.h @@ -26,6 +26,7 @@ const uint32 kAutoHide = 'AtHd'; class BBox; class BButton; class BCheckBox; +class BListView; class BRadioButton; class BSlider; class BStringView; @@ -44,9 +45,10 @@ public: void EnableDisableDependentItems(); private: - BBox* fMenuBox; - BBox* fAppsBox; - BBox* fWindowBox; + void _HandleChangedSettingsView(); + + BListView* fSettingsTypeListView; + BBox* fSettingsContainerBox; BCheckBox* fMenuRecentDocuments; BCheckBox* fMenuRecentApplications; ############################################################################ Commit: 9fd9f94dcc4aa29a3f2ed10cbed86fbe16aacd7b URL: http://cgit.haiku-os.org/haiku/commit/?id=9fd9f94 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Nov 24 03:27:36 2012 UTC Make prefs window height depend on content ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index 6f2615b..ae42330 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -237,7 +237,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0) .Add(fAppsIconSizeSlider) .End() - .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() @@ -248,7 +247,6 @@ PreferencesWindow::PreferencesWindow(BRect frame) .Add(fWindowAlwaysOnTop) .Add(fWindowAutoRaise) .Add(fWindowAutoHide) - .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() @@ -398,7 +396,7 @@ PreferencesWindow::_HandleChangedSettingsView() dynamic_cast<SettingsItem*> (fSettingsTypeListView->ItemAt(currentSelection)); - if (selectedItem) { + if (selectedItem != NULL) { fSettingsContainerBox->SetLabel(selectedItem->Text()); BView* view = selectedItem->View(); ############################################################################ Commit: 37fb25e0f812923e7702e35aeac3b079335867ca URL: http://cgit.haiku-os.org/haiku/commit/?id=37fb25e Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Nov 24 03:41:51 2012 UTC On second thought, AddGlue to all 3 so the window stays the same height ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index ae42330..a168eb0 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -218,6 +218,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) .Add(new BButton(B_TRANSLATE("Edit menu" B_UTF8_ELLIPSIS), new BMessage(kEditMenuInTracker))) .End() + .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() @@ -237,6 +238,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0) .Add(fAppsIconSizeSlider) .End() + .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() @@ -247,6 +249,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) .Add(fWindowAlwaysOnTop) .Add(fWindowAutoRaise) .Add(fWindowAutoHide) + .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() ############################################################################ Revision: hrev45037 Commit: defcf2ebc4c6cc54b82a6233897bef969a97deca URL: http://cgit.haiku-os.org/haiku/commit/?id=defcf2e Author: John Scipione <jscipione@xxxxxxxxx> Date: Thu Dec 20 23:58:09 2012 UTC Ticket: https://dev.haiku-os.org/ticket/7331 Ticket: https://dev.haiku-os.org/ticket/8769 Add newline at the end of PreferencesWindow.cpp This completes the move of clock preferences from Deskbar to Time. This closes #7331. Also closing #8769 as invalid as it has been discussed to death and 12/24 hour setting seems to belong in Locale prefs only. Clock preferences have been moved into their own settings file as well so perhaps will be moved to their own replicant in the future. ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index a168eb0..4539170 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -409,4 +409,4 @@ PreferencesWindow::_HandleChangedSettingsView() view->Show(); } -} \ No newline at end of file +}