Ticket #254: menu.diff
File menu.diff, 16.0 KB (added by , 17 years ago) |
---|
-
src/preferences/menu/ColorWindow.cpp
9 9 10 10 11 11 #include "ColorWindow.h" 12 #include "MenuSettings.h" 12 13 #include "msg.h" 13 14 14 15 #include <Application.h> … … 22 23 B_NOT_ZOOMABLE | B_NOT_RESIZABLE), 23 24 fOwner(owner) 24 25 { 25 // Set and collect the variables for revert26 get_menu_info(&fInfo);27 get_menu_info(&fRevertInfo);26 fCurrentColor = MenuSettings::GetInstance()->BackgroundColor(); 27 fPreviousColor = MenuSettings::GetInstance()->PreviousBackgroundColor(); 28 fDefaultColor = MenuSettings::GetInstance()->DefaultBackgroundColor(); 28 29 29 30 BView *topView = new BView(Bounds(), "topView", B_FOLLOW_ALL_SIDES, 0); 30 31 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); … … 32 33 33 34 fColorControl = new BColorControl(BPoint(10, 10), B_CELLS_32x8, 34 35 9, "COLOR", new BMessage(MENU_COLOR), true); 35 fColorControl->SetValue(f Info.background_color);36 fColorControl->SetValue(fCurrentColor); 36 37 fColorControl->ResizeToPreferred(); 37 38 topView->AddChild(fColorControl); 38 39 … … 44 45 new BMessage(MENU_COLOR_DEFAULT), B_FOLLOW_LEFT | B_FOLLOW_TOP, 45 46 B_WILL_DRAW | B_NAVIGABLE); 46 47 fDefaultButton->ResizeToPreferred(); 47 fDefaultButton->SetEnabled(f alse);48 fDefaultButton->SetEnabled(fCurrentColor != fDefaultColor); 48 49 topView->AddChild(fDefaultButton); 49 50 50 51 rect.OffsetBy(fDefaultButton->Bounds().Width() + 10, 0); … … 52 53 new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_TOP, 53 54 B_WILL_DRAW | B_NAVIGABLE); 54 55 fRevertButton->ResizeToPreferred(); 55 fRevertButton->SetEnabled(f alse);56 fRevertButton->SetEnabled(fCurrentColor != fPreviousColor); 56 57 topView->AddChild(fRevertButton); 57 58 58 59 ResizeTo(fColorControl->Bounds().Width() + 20, fRevertButton->Frame().bottom + 10); … … 68 69 69 70 70 71 void 72 ColorWindow::_UpdateAndPost() 73 { 74 fDefaultButton->SetEnabled(fCurrentColor != fDefaultColor); 75 fRevertButton->SetEnabled(fCurrentColor != fPreviousColor); 76 77 fCurrentColor = fColorControl->ValueAsColor(); 78 79 menu_info info; 80 get_menu_info(&info); 81 info.background_color = fCurrentColor; 82 set_menu_info(&info); 83 84 be_app->PostMessage(MENU_COLOR); 85 } 86 87 88 void 71 89 ColorWindow::MessageReceived(BMessage *msg) 72 90 { 73 91 switch (msg->what) { 74 92 case MENU_REVERT: 75 fColorControl->SetValue(fRevertInfo.background_color); 76 fInfo.background_color = fColorControl->ValueAsColor(); 77 set_menu_info(&fInfo); 78 be_app->PostMessage(UPDATE_WINDOW); 79 fRevertButton->SetEnabled(false); 93 fColorControl->SetValue(fPreviousColor); 94 _UpdateAndPost(); 80 95 break; 81 96 82 case MENU_COLOR_DEFAULT: 83 // change to system color for system wide 84 // compatability 85 rgb_color color; 86 color.red = 216; 87 color.blue = 216; 88 color.green = 216; 89 color.alpha = 255; 90 fColorControl->SetValue(color); 91 fDefaultButton->SetEnabled(false); 92 get_menu_info(&fInfo); 93 fInfo.background_color = fColorControl->ValueAsColor(); 94 set_menu_info(&fInfo); 95 be_app->PostMessage(MENU_COLOR); 97 case MENU_COLOR_DEFAULT: 98 fColorControl->SetValue(fDefaultColor); 99 _UpdateAndPost(); 96 100 break; 97 101 98 102 case MENU_COLOR: 99 get_menu_info(&fInfo); 100 fRevertInfo.background_color = fInfo.background_color; 101 fInfo.background_color = fColorControl->ValueAsColor(); 102 set_menu_info(&fInfo); 103 be_app->PostMessage(MENU_COLOR); 104 fDefaultButton->SetEnabled(true); 105 fRevertButton->SetEnabled(true); 103 _UpdateAndPost(); 106 104 break; 107 105 108 106 default: 109 be_app->PostMessage(UPDATE_WINDOW);110 107 BWindow::MessageReceived(msg); 111 108 break; 112 109 } -
src/preferences/menu/ColorWindow.h
27 27 virtual void Quit(); 28 28 virtual void MessageReceived(BMessage* message); 29 29 30 private: 31 void _UpdateAndPost(); 32 30 33 private: 31 BColorControl* 34 BColorControl* fColorControl; 32 35 BButton* fDefaultButton; 33 BButton* fRevertButton; 34 menu_info fRevertInfo; 35 menu_info fInfo; 36 BButton* fRevertButton; 37 rgb_color fCurrentColor; 38 rgb_color fPreviousColor; 39 rgb_color fDefaultColor; 36 40 BMessenger fOwner; 37 41 }; 38 42 -
src/preferences/menu/MenuBar.cpp
20 20 #include <TranslationUtils.h> 21 21 #include <Window.h> 22 22 23 #include <stdio.h>24 #include <stdlib.h>25 23 26 27 24 MenuBar::MenuBar() 28 25 : BMenuBar(BRect(40, 10, 10, 10), "menu", B_FOLLOW_TOP | B_FRAME_EVENTS, 29 26 B_ITEMS_IN_COLUMN, true) 30 27 { 31 _BuildMenu(); 32 UpdateMenu(); 28 _BuildMenu(); 33 29 SetItemMargins(14.0, 2.0, 20.0, 0.0); 34 30 } 35 31 … … 81 77 82 78 83 79 void 84 MenuBar::Update Menu()80 MenuBar::Update() 85 81 { 86 82 menu_info info; 87 83 MenuSettings::GetInstance()->Get(info); 88 84 89 85 fAlwaysShowTriggersItem->SetMarked(info.triggers_always_shown); 90 86 91 key_map *keys; 92 char* chars; 93 get_key_map(&keys, &chars); 94 95 bool altAsShortcut = (keys->left_command_key == 0x5d) 96 && (keys->right_command_key == 0x5f); 97 98 free(chars); 99 free(keys); 100 87 bool altAsShortcut = MenuSettings::GetInstance()->AltAsShortcut(); 101 88 fAltAsShortcutItem->SetMarked(altAsShortcut); 102 89 fControlAsShortcutItem->SetMarked(!altAsShortcut); 103 }104 90 105 106 void107 MenuBar::Update()108 {109 UpdateMenu();110 111 91 BFont font; 112 92 if (LockLooper()) { 113 menu_info info;114 MenuSettings::GetInstance()->Get(info);115 116 93 font.SetFamilyAndStyle(info.f_family, info.f_style); 117 94 font.SetSize(info.font_size); 118 95 SetFont(&font); -
src/preferences/menu/MenuBar.h
18 18 MenuBar(); 19 19 20 20 virtual void AttachedToWindow(); 21 22 void UpdateMenu(); 21 23 22 void Update(); 24 23 virtual void FrameResized(float width, float height); 25 24 -
src/preferences/menu/MenuSettings.cpp
9 9 10 10 11 11 #include "MenuSettings.h" 12 #include <Roster.h> 13 #include <Errors.h> 14 #include <stdio.h> 15 #include <stdlib.h> 12 16 13 17 14 18 MenuSettings::MenuSettings() … … 17 21 // would provide and execute this information, as it does 18 22 // for get_menu_info and set_menu_info (or is this information 19 23 // coming from libbe.so? or else where?). 20 fDefaultSettings.font_size = 12; 21 //info.f_family = "test"; 22 //info.f_style = "test"; 23 fDefaultSettings.background_color = ui_color(B_MENU_BACKGROUND_COLOR); 24 fDefaultSettings.font_size = 12; 25 sprintf(fDefaultSettings.f_family,"%s","Bitstream Vera Sans"); 26 sprintf(fDefaultSettings.f_style,"%s","Roman"); 27 rgb_color color; 28 color.red = 216; 29 color.blue = 216; 30 color.green = 216; 31 color.alpha = 255; 32 fDefaultSettings.background_color = color;//ui_color(B_MENU_BACKGROUND_COLOR); 24 33 fDefaultSettings.separator = 0; 25 34 fDefaultSettings.click_to_open = true; 26 35 fDefaultSettings.triggers_always_shown = false; 27 28 fPreviousSettings = fDefaultSettings; 36 fDefaultAltAsShortcut = true; 37 38 get_menu_info(&fPreviousSettings); 39 fPreviousAltAsShortcut = AltAsShortcut(); 29 40 } 30 41 31 42 … … 55 66 void 56 67 MenuSettings::Set(menu_info &info) 57 68 { 58 get_menu_info(&fPreviousSettings);59 69 set_menu_info(&info); 60 70 } 61 71 62 72 73 bool 74 MenuSettings::AltAsShortcut() const 75 { 76 key_map *keys; 77 char* chars; 78 79 get_key_map(&keys, &chars); 80 bool altAsShortcut = (keys->left_command_key == 0x5d) 81 && (keys->right_command_key == 0x5f); 82 83 free(chars); 84 free(keys); 85 86 return altAsShortcut; 87 } 88 89 63 90 void 91 MenuSettings::SetAltAsShortcut(bool altAsShortcut) 92 { 93 if (altAsShortcut) { 94 // This might not be the same for all keyboards 95 set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); 96 set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); 97 set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c); 98 set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); 99 } else { 100 // This might not be the same for all keyboards 101 set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); 102 set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); 103 set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); 104 set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); 105 } 106 be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); 107 } 108 109 110 void 64 111 MenuSettings::Revert() 65 112 { 66 113 set_menu_info(&fPreviousSettings); 114 SetAltAsShortcut(fPreviousAltAsShortcut); 67 115 } 68 116 69 117 70 118 void 71 119 MenuSettings::ResetToDefaults() 72 120 { 73 get_menu_info(&fPreviousSettings);74 121 set_menu_info(&fDefaultSettings); 122 SetAltAsShortcut(fDefaultAltAsShortcut); 75 123 } 76 124 77 125 126 rgb_color 127 MenuSettings::BackgroundColor() const 128 { 129 menu_info info; 130 get_menu_info(&info); 131 return info.background_color; 132 } 133 134 135 rgb_color 136 MenuSettings::PreviousBackgroundColor() const 137 { 138 return fPreviousSettings.background_color; 139 } 140 141 142 rgb_color 143 MenuSettings::DefaultBackgroundColor() const 144 { 145 return fDefaultSettings.background_color; 146 } 147 148 78 149 bool 79 150 MenuSettings::IsDefaultable() 80 151 { … … 82 153 get_menu_info(&info); 83 154 84 155 return info.font_size != fDefaultSettings.font_size 156 || strcmp(info.f_family, fDefaultSettings.f_family) != 0 157 || strcmp(info.f_style, fDefaultSettings.f_style) != 0 85 158 || info.background_color != fDefaultSettings.background_color 86 159 || info.separator != fDefaultSettings.separator 87 160 || info.click_to_open != fDefaultSettings.click_to_open 88 || info.triggers_always_shown != fDefaultSettings.triggers_always_shown; 161 || info.triggers_always_shown != fDefaultSettings.triggers_always_shown 162 || AltAsShortcut() != fDefaultAltAsShortcut; 89 163 } 90 164 165 166 bool 167 MenuSettings::IsRevertable() 168 { 169 menu_info info; 170 get_menu_info(&info); 171 172 return info.font_size != fPreviousSettings.font_size 173 || strcmp(info.f_family, fPreviousSettings.f_family) != 0 174 || strcmp(info.f_style, fPreviousSettings.f_style) != 0 175 || info.background_color != fPreviousSettings.background_color 176 || info.separator != fPreviousSettings.separator 177 || info.click_to_open != fPreviousSettings.click_to_open 178 || info.triggers_always_shown != fPreviousSettings.triggers_always_shown 179 || AltAsShortcut() != fPreviousAltAsShortcut; 180 } 181 -
src/preferences/menu/MenuSettings.h
18 18 19 19 void Get(menu_info &info) const; 20 20 void Set(menu_info &info); 21 22 bool AltAsShortcut() const; 23 void SetAltAsShortcut(bool altAsShortcut); 24 25 rgb_color BackgroundColor() const; 26 rgb_color PreviousBackgroundColor() const; 27 rgb_color DefaultBackgroundColor() const; 28 21 29 22 30 void Revert(); 23 31 void ResetToDefaults(); 24 32 bool IsDefaultable(); 25 33 bool IsRevertable(); 34 26 35 private: 27 36 MenuSettings(); 28 37 ~MenuSettings(); 29 38 30 39 menu_info fPreviousSettings; 31 menu_info fDefaultSettings; 40 menu_info fDefaultSettings; 41 bool fPreviousAltAsShortcut; 42 bool fDefaultAltAsShortcut; 32 43 }; 33 44 34 45 #endif // MENU_SETTINGS_H -
src/preferences/menu/MenuWindow.cpp
20 20 #include <Box.h> 21 21 #include <Button.h> 22 22 #include <MenuItem.h> 23 #include <Roster.h>24 23 25 24 #include <stdio.h> 26 25 #include <string.h> … … 31 30 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) 32 31 { 33 32 fColorWindow = NULL; 33 34 fSettings = MenuSettings::GetInstance(); 34 35 35 36 BView* topView = new BView(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, 36 37 B_WILL_DRAW); … … 60 61 topView->AddChild(fRevertButton); 61 62 62 63 topView->MakeFocus(); 63 fMenuBar->Update(); 64 65 _UpdateAll(); 64 66 } 65 67 66 68 67 69 void 68 70 MenuWindow::MessageReceived(BMessage *msg) 69 71 { 70 MenuSettings *settings = MenuSettings::GetInstance();71 72 menu_info info; 72 73 73 74 switch (msg->what) { 74 75 case MENU_REVERT: 75 settings->Revert(); 76 77 fRevertButton->SetEnabled(false); 78 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 79 fMenuBar->Update(); 76 fSettings->Revert(); 77 _UpdateAll(); 80 78 break; 81 79 82 80 case MENU_DEFAULT: 83 settings->ResetToDefaults(); 84 85 fDefaultsButton->SetEnabled(false); 86 fMenuBar->Update(); 81 fSettings->ResetToDefaults(); 82 _UpdateAll(); 87 83 break; 88 84 89 85 case UPDATE_WINDOW: 90 fMenuBar->Update();86 _UpdateAll(); 91 87 break; 92 88 93 89 case MENU_FONT_FAMILY: … … 98 94 const font_style *style; 99 95 msg->FindString("style", (const char **)&style); 100 96 101 settings->Get(info);97 fSettings->Get(info); 102 98 strlcpy(info.f_family, (const char *)family, B_FONT_FAMILY_LENGTH); 103 99 strlcpy(info.f_style, (const char *)style, B_FONT_STYLE_LENGTH); 104 settings->Set(info);100 fSettings->Set(info); 105 101 106 fRevertButton->SetEnabled(true); 107 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 108 fMenuBar->Update(); 102 _UpdateAll(); 109 103 break; 110 104 } 111 105 112 106 case MENU_FONT_SIZE: 113 settings->Get(info);107 fSettings->Get(info); 114 108 msg->FindFloat("size", &info.font_size); 115 settings->Set(info);109 fSettings->Set(info); 116 110 117 fRevertButton->SetEnabled(true); 118 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 119 fMenuBar->Update(); 111 _UpdateAll(); 120 112 break; 121 113 122 114 case ALLWAYS_TRIGGERS_MSG: 123 settings->Get(info);115 fSettings->Get(info); 124 116 info.triggers_always_shown = !info.triggers_always_shown; 125 settings->Set(info);117 fSettings->Set(info); 126 118 127 fRevertButton->SetEnabled(true); 128 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 129 fMenuBar->UpdateMenu(); 130 fMenuBar->Update(); 119 _UpdateAll(); 131 120 break; 132 121 133 case CTL_MARKED_MSG: 134 // This might not be the same for all keyboards 135 set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c); 136 set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); 137 set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); 138 set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); 139 be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); 140 141 fRevertButton->SetEnabled(true); 142 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 143 fMenuBar->Update(); 122 case CTL_MARKED_MSG: 123 fSettings->SetAltAsShortcut(false); 124 _UpdateAll(); 144 125 break; 145 126 146 127 case ALT_MARKED_MSG: 147 148 // This might not be the same for all keyboards 149 set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d); 150 set_modifier_key(B_RIGHT_COMMAND_KEY, 0x5f); 151 set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c); 152 set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); 153 154 be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); 155 156 fRevertButton->SetEnabled(true); 157 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 158 fMenuBar->Update(); 128 fSettings->SetAltAsShortcut(true); 129 _UpdateAll(); 159 130 break; 160 131 161 132 case COLOR_SCHEME_OPEN_MSG: … … 170 141 fColorWindow = NULL; 171 142 break; 172 143 173 case MENU_COLOR: 174 fRevertButton->SetEnabled(true); 175 fDefaultsButton->SetEnabled(settings->IsDefaultable()); 176 fMenuBar->Update(); 144 case MENU_COLOR: 145 _UpdateAll(); 177 146 break; 178 147 179 148 default: … … 183 152 } 184 153 185 154 155 void 156 MenuWindow::_UpdateAll() 157 { 158 fRevertButton->SetEnabled(fSettings->IsRevertable()); 159 fDefaultsButton->SetEnabled(fSettings->IsDefaultable()); 160 fMenuBar->Update(); 161 } 162 163 186 164 bool 187 165 MenuWindow::QuitRequested() 188 166 { -
src/preferences/menu/MenuWindow.h
10 10 #ifndef MENU_WINDOW_H 11 11 #define MENU_WINDOW_H 12 12 13 13 #include "MenuSettings.h" 14 14 #include <Menu.h> 15 15 #include <Window.h> 16 16 … … 20 20 class MenuBar; 21 21 class MenuWindow : public BWindow { 22 22 public: 23 MenuWindow(BRect frame); 23 MenuWindow(BRect frame); 24 24 25 25 virtual void MessageReceived(BMessage *message); 26 26 virtual bool QuitRequested(); 27 27 28 private: 29 void _UpdateAll(); 30 28 31 private: 29 32 ColorWindow* fColorWindow; 30 33 MenuBar* fMenuBar; 31 34 BButton* fDefaultsButton; 32 35 BButton* fRevertButton; 36 MenuSettings* fSettings; 33 37 }; 34 38 35 39 #endif // MENU_WINDOW_H