diff --git a/src/preferences/menu/ColorWindow.cpp b/src/preferences/menu/ColorWindow.cpp index cf7e69ec55..bb904838b5 100644 --- a/src/preferences/menu/ColorWindow.cpp +++ b/src/preferences/menu/ColorWindow.cpp @@ -9,6 +9,7 @@ #include "ColorWindow.h" +#include "MenuSettings.h" #include "msg.h" #include @@ -22,9 +23,9 @@ ColorWindow::ColorWindow(BMessenger owner) B_NOT_ZOOMABLE | B_NOT_RESIZABLE), fOwner(owner) { - // Set and collect the variables for revert - get_menu_info(&fInfo); - get_menu_info(&fRevertInfo); + fCurrentColor = MenuSettings::GetInstance()->BackgroundColor(); + fPreviousColor = MenuSettings::GetInstance()->PreviousBackgroundColor(); + fDefaultColor = MenuSettings::GetInstance()->DefaultBackgroundColor(); BView *topView = new BView(Bounds(), "topView", B_FOLLOW_ALL_SIDES, 0); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -32,7 +33,7 @@ ColorWindow::ColorWindow(BMessenger owner) fColorControl = new BColorControl(BPoint(10, 10), B_CELLS_32x8, 9, "COLOR", new BMessage(MENU_COLOR), true); - fColorControl->SetValue(fInfo.background_color); + fColorControl->SetValue(fCurrentColor); fColorControl->ResizeToPreferred(); topView->AddChild(fColorControl); @@ -44,7 +45,7 @@ ColorWindow::ColorWindow(BMessenger owner) new BMessage(MENU_COLOR_DEFAULT), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fDefaultButton->ResizeToPreferred(); - fDefaultButton->SetEnabled(false); + fDefaultButton->SetEnabled(fCurrentColor != fDefaultColor); topView->AddChild(fDefaultButton); rect.OffsetBy(fDefaultButton->Bounds().Width() + 10, 0); @@ -52,7 +53,7 @@ ColorWindow::ColorWindow(BMessenger owner) new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fRevertButton->ResizeToPreferred(); - fRevertButton->SetEnabled(false); + fRevertButton->SetEnabled(fCurrentColor != fPreviousColor); topView->AddChild(fRevertButton); ResizeTo(fColorControl->Bounds().Width() + 20, fRevertButton->Frame().bottom + 10); @@ -67,46 +68,42 @@ ColorWindow::Quit() } +void +ColorWindow::_UpdateAndPost() +{ + fDefaultButton->SetEnabled(fCurrentColor != fDefaultColor); + fRevertButton->SetEnabled(fCurrentColor != fPreviousColor); + + fCurrentColor = fColorControl->ValueAsColor(); + + menu_info info; + get_menu_info(&info); + info.background_color = fCurrentColor; + set_menu_info(&info); + + be_app->PostMessage(MENU_COLOR); +} + + void ColorWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case MENU_REVERT: - fColorControl->SetValue(fRevertInfo.background_color); - fInfo.background_color = fColorControl->ValueAsColor(); - set_menu_info(&fInfo); - be_app->PostMessage(UPDATE_WINDOW); - fRevertButton->SetEnabled(false); + fColorControl->SetValue(fPreviousColor); + _UpdateAndPost(); break; - case MENU_COLOR_DEFAULT: - // change to system color for system wide - // compatability - rgb_color color; - color.red = 216; - color.blue = 216; - color.green = 216; - color.alpha = 255; - fColorControl->SetValue(color); - fDefaultButton->SetEnabled(false); - get_menu_info(&fInfo); - fInfo.background_color = fColorControl->ValueAsColor(); - set_menu_info(&fInfo); - be_app->PostMessage(MENU_COLOR); + case MENU_COLOR_DEFAULT: + fColorControl->SetValue(fDefaultColor); + _UpdateAndPost(); break; case MENU_COLOR: - get_menu_info(&fInfo); - fRevertInfo.background_color = fInfo.background_color; - fInfo.background_color = fColorControl->ValueAsColor(); - set_menu_info(&fInfo); - be_app->PostMessage(MENU_COLOR); - fDefaultButton->SetEnabled(true); - fRevertButton->SetEnabled(true); + _UpdateAndPost(); break; default: - be_app->PostMessage(UPDATE_WINDOW); BWindow::MessageReceived(msg); break; } diff --git a/src/preferences/menu/ColorWindow.h b/src/preferences/menu/ColorWindow.h index 6528afbcb8..872e3e773f 100644 --- a/src/preferences/menu/ColorWindow.h +++ b/src/preferences/menu/ColorWindow.h @@ -27,12 +27,16 @@ class ColorWindow : public BWindow { virtual void Quit(); virtual void MessageReceived(BMessage* message); + private: + void _UpdateAndPost(); + private: - BColorControl* fColorControl; + BColorControl* fColorControl; BButton* fDefaultButton; - BButton* fRevertButton; - menu_info fRevertInfo; - menu_info fInfo; + BButton* fRevertButton; + rgb_color fCurrentColor; + rgb_color fPreviousColor; + rgb_color fDefaultColor; BMessenger fOwner; }; diff --git a/src/preferences/menu/MenuBar.cpp b/src/preferences/menu/MenuBar.cpp index 7b448bd342..c107a1fb2b 100644 --- a/src/preferences/menu/MenuBar.cpp +++ b/src/preferences/menu/MenuBar.cpp @@ -20,16 +20,12 @@ #include #include -#include -#include - MenuBar::MenuBar() : BMenuBar(BRect(40, 10, 10, 10), "menu", B_FOLLOW_TOP | B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true) { - _BuildMenu(); - UpdateMenu(); + _BuildMenu(); SetItemMargins(14.0, 2.0, 20.0, 0.0); } @@ -81,38 +77,19 @@ MenuBar::_BuildMenu() void -MenuBar::UpdateMenu() +MenuBar::Update() { menu_info info; MenuSettings::GetInstance()->Get(info); fAlwaysShowTriggersItem->SetMarked(info.triggers_always_shown); - key_map *keys; - char* chars; - get_key_map(&keys, &chars); - - bool altAsShortcut = (keys->left_command_key == 0x5d) - && (keys->right_command_key == 0x5f); - - free(chars); - free(keys); - + bool altAsShortcut = MenuSettings::GetInstance()->AltAsShortcut(); fAltAsShortcutItem->SetMarked(altAsShortcut); fControlAsShortcutItem->SetMarked(!altAsShortcut); -} - - -void -MenuBar::Update() -{ - UpdateMenu(); BFont font; if (LockLooper()) { - menu_info info; - MenuSettings::GetInstance()->Get(info); - font.SetFamilyAndStyle(info.f_family, info.f_style); font.SetSize(info.font_size); SetFont(&font); diff --git a/src/preferences/menu/MenuBar.h b/src/preferences/menu/MenuBar.h index 5b454b2e66..a4889b3f75 100644 --- a/src/preferences/menu/MenuBar.h +++ b/src/preferences/menu/MenuBar.h @@ -18,8 +18,7 @@ class MenuBar : public BMenuBar { MenuBar(); virtual void AttachedToWindow(); - - void UpdateMenu(); + void Update(); virtual void FrameResized(float width, float height); diff --git a/src/preferences/menu/MenuSettings.cpp b/src/preferences/menu/MenuSettings.cpp index 52f0787021..a13b6a85fd 100644 --- a/src/preferences/menu/MenuSettings.cpp +++ b/src/preferences/menu/MenuSettings.cpp @@ -9,6 +9,10 @@ #include "MenuSettings.h" +#include +#include +#include +#include MenuSettings::MenuSettings() @@ -17,15 +21,22 @@ MenuSettings::MenuSettings() // would provide and execute this information, as it does // for get_menu_info and set_menu_info (or is this information // coming from libbe.so? or else where?). - fDefaultSettings.font_size = 12; - //info.f_family = "test"; - //info.f_style = "test"; - fDefaultSettings.background_color = ui_color(B_MENU_BACKGROUND_COLOR); + fDefaultSettings.font_size = 12; + sprintf(fDefaultSettings.f_family,"%s","Bitstream Vera Sans"); + sprintf(fDefaultSettings.f_style,"%s","Roman"); + rgb_color color; + color.red = 216; + color.blue = 216; + color.green = 216; + color.alpha = 255; + fDefaultSettings.background_color = color;//ui_color(B_MENU_BACKGROUND_COLOR); fDefaultSettings.separator = 0; fDefaultSettings.click_to_open = true; fDefaultSettings.triggers_always_shown = false; - - fPreviousSettings = fDefaultSettings; + fDefaultAltAsShortcut = true; + + get_menu_info(&fPreviousSettings); + fPreviousAltAsShortcut = AltAsShortcut(); } @@ -55,23 +66,83 @@ MenuSettings::Get(menu_info &info) const void MenuSettings::Set(menu_info &info) { - get_menu_info(&fPreviousSettings); set_menu_info(&info); } +bool +MenuSettings::AltAsShortcut() const +{ + key_map *keys; + char* chars; + + get_key_map(&keys, &chars); + bool altAsShortcut = (keys->left_command_key == 0x5d) + && (keys->right_command_key == 0x5f); + + free(chars); + free(keys); + + return altAsShortcut; +} + + +void +MenuSettings::SetAltAsShortcut(bool altAsShortcut) +{ + if (altAsShortcut) { + // This might not be the same for all keyboards + set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); + set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); + set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c); + set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); + } else { + // This might not be the same for all keyboards + set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); + set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); + set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); + set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); + } + be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); +} + + void MenuSettings::Revert() { set_menu_info(&fPreviousSettings); + SetAltAsShortcut(fPreviousAltAsShortcut); } void MenuSettings::ResetToDefaults() { - get_menu_info(&fPreviousSettings); set_menu_info(&fDefaultSettings); + SetAltAsShortcut(fDefaultAltAsShortcut); +} + + +rgb_color +MenuSettings::BackgroundColor() const +{ + menu_info info; + get_menu_info(&info); + return info.background_color; +} + + +rgb_color +MenuSettings::PreviousBackgroundColor() const +{ + return fPreviousSettings.background_color; +} + + +rgb_color +MenuSettings::DefaultBackgroundColor() const +{ + return fDefaultSettings.background_color; } @@ -82,9 +153,29 @@ MenuSettings::IsDefaultable() get_menu_info(&info); return info.font_size != fDefaultSettings.font_size + || strcmp(info.f_family, fDefaultSettings.f_family) != 0 + || strcmp(info.f_style, fDefaultSettings.f_style) != 0 || info.background_color != fDefaultSettings.background_color || info.separator != fDefaultSettings.separator || info.click_to_open != fDefaultSettings.click_to_open - || info.triggers_always_shown != fDefaultSettings.triggers_always_shown; + || info.triggers_always_shown != fDefaultSettings.triggers_always_shown + || AltAsShortcut() != fDefaultAltAsShortcut; +} + + +bool +MenuSettings::IsRevertable() +{ + menu_info info; + get_menu_info(&info); + + return info.font_size != fPreviousSettings.font_size + || strcmp(info.f_family, fPreviousSettings.f_family) != 0 + || strcmp(info.f_style, fPreviousSettings.f_style) != 0 + || info.background_color != fPreviousSettings.background_color + || info.separator != fPreviousSettings.separator + || info.click_to_open != fPreviousSettings.click_to_open + || info.triggers_always_shown != fPreviousSettings.triggers_always_shown + || AltAsShortcut() != fPreviousAltAsShortcut; } diff --git a/src/preferences/menu/MenuSettings.h b/src/preferences/menu/MenuSettings.h index 0da789f8f7..7fbe227d12 100644 --- a/src/preferences/menu/MenuSettings.h +++ b/src/preferences/menu/MenuSettings.h @@ -18,17 +18,28 @@ class MenuSettings { void Get(menu_info &info) const; void Set(menu_info &info); + + bool AltAsShortcut() const; + void SetAltAsShortcut(bool altAsShortcut); + + rgb_color BackgroundColor() const; + rgb_color PreviousBackgroundColor() const; + rgb_color DefaultBackgroundColor() const; + void Revert(); void ResetToDefaults(); bool IsDefaultable(); - + bool IsRevertable(); + private: MenuSettings(); ~MenuSettings(); menu_info fPreviousSettings; - menu_info fDefaultSettings; + menu_info fDefaultSettings; + bool fPreviousAltAsShortcut; + bool fDefaultAltAsShortcut; }; #endif // MENU_SETTINGS_H diff --git a/src/preferences/menu/MenuWindow.cpp b/src/preferences/menu/MenuWindow.cpp index ddeea1ea6d..15724faba0 100644 --- a/src/preferences/menu/MenuWindow.cpp +++ b/src/preferences/menu/MenuWindow.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -31,6 +30,8 @@ MenuWindow::MenuWindow(BRect rect) B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { fColorWindow = NULL; + + fSettings = MenuSettings::GetInstance(); BView* topView = new BView(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW); @@ -60,34 +61,29 @@ MenuWindow::MenuWindow(BRect rect) topView->AddChild(fRevertButton); topView->MakeFocus(); - fMenuBar->Update(); + + _UpdateAll(); } void MenuWindow::MessageReceived(BMessage *msg) { - MenuSettings *settings = MenuSettings::GetInstance(); menu_info info; switch (msg->what) { case MENU_REVERT: - settings->Revert(); - - fRevertButton->SetEnabled(false); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + fSettings->Revert(); + _UpdateAll(); break; case MENU_DEFAULT: - settings->ResetToDefaults(); - - fDefaultsButton->SetEnabled(false); - fMenuBar->Update(); + fSettings->ResetToDefaults(); + _UpdateAll(); break; case UPDATE_WINDOW: - fMenuBar->Update(); + _UpdateAll(); break; case MENU_FONT_FAMILY: @@ -98,64 +94,39 @@ MenuWindow::MessageReceived(BMessage *msg) const font_style *style; msg->FindString("style", (const char **)&style); - settings->Get(info); + fSettings->Get(info); strlcpy(info.f_family, (const char *)family, B_FONT_FAMILY_LENGTH); strlcpy(info.f_style, (const char *)style, B_FONT_STYLE_LENGTH); - settings->Set(info); + fSettings->Set(info); - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + _UpdateAll(); break; } case MENU_FONT_SIZE: - settings->Get(info); + fSettings->Get(info); msg->FindFloat("size", &info.font_size); - settings->Set(info); + fSettings->Set(info); - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + _UpdateAll(); break; case ALLWAYS_TRIGGERS_MSG: - settings->Get(info); + fSettings->Get(info); info.triggers_always_shown = !info.triggers_always_shown; - settings->Set(info); + fSettings->Set(info); - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->UpdateMenu(); - fMenuBar->Update(); + _UpdateAll(); break; - case CTL_MARKED_MSG: - // This might not be the same for all keyboards - set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); - set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); - set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); - set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); - be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); - - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + case CTL_MARKED_MSG: + fSettings->SetAltAsShortcut(false); + _UpdateAll(); break; case ALT_MARKED_MSG: - - // This might not be the same for all keyboards - set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); - set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); - set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c); - set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); - - be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); - - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + fSettings->SetAltAsShortcut(true); + _UpdateAll(); break; case COLOR_SCHEME_OPEN_MSG: @@ -170,10 +141,8 @@ MenuWindow::MessageReceived(BMessage *msg) fColorWindow = NULL; break; - case MENU_COLOR: - fRevertButton->SetEnabled(true); - fDefaultsButton->SetEnabled(settings->IsDefaultable()); - fMenuBar->Update(); + case MENU_COLOR: + _UpdateAll(); break; default: @@ -183,6 +152,15 @@ MenuWindow::MessageReceived(BMessage *msg) } +void +MenuWindow::_UpdateAll() +{ + fRevertButton->SetEnabled(fSettings->IsRevertable()); + fDefaultsButton->SetEnabled(fSettings->IsDefaultable()); + fMenuBar->Update(); +} + + bool MenuWindow::QuitRequested() { diff --git a/src/preferences/menu/MenuWindow.h b/src/preferences/menu/MenuWindow.h index 3179dddc0d..9e71af1a18 100644 --- a/src/preferences/menu/MenuWindow.h +++ b/src/preferences/menu/MenuWindow.h @@ -10,7 +10,7 @@ #ifndef MENU_WINDOW_H #define MENU_WINDOW_H - +#include "MenuSettings.h" #include #include @@ -20,16 +20,20 @@ class BButton; class MenuBar; class MenuWindow : public BWindow { public: - MenuWindow(BRect frame); + MenuWindow(BRect frame); virtual void MessageReceived(BMessage *message); virtual bool QuitRequested(); - + + private: + void _UpdateAll(); + private: ColorWindow* fColorWindow; MenuBar* fMenuBar; BButton* fDefaultsButton; BButton* fRevertButton; + MenuSettings* fSettings; }; #endif // MENU_WINDOW_H