From da0189314899a54828f1c1e4a628a9222bdd7d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 17 Nov 2006 08:52:01 +0000 Subject: [PATCH] * A new color window was opened every time you clicked on "Color Scheme..." - patch provided by Vasilis Kaoutsis. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19309 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/menu/ColorWindow.cpp | 58 +++++++++++---- src/preferences/menu/ColorWindow.h | 38 +++++++--- src/preferences/menu/Jamfile | 4 +- src/preferences/menu/MenuApp.cpp | 3 +- src/preferences/menu/MenuBar.cpp | 23 ++++-- src/preferences/menu/MenuWindow.cpp | 103 ++++++++++++++++++--------- src/preferences/menu/MenuWindow.h | 46 +++++++----- src/preferences/menu/msg.h | 28 +++++--- 8 files changed, 213 insertions(+), 90 deletions(-) diff --git a/src/preferences/menu/ColorWindow.cpp b/src/preferences/menu/ColorWindow.cpp index f96a95dc93..89e675b724 100644 --- a/src/preferences/menu/ColorWindow.cpp +++ b/src/preferences/menu/ColorWindow.cpp @@ -1,3 +1,13 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + * Vasilis Kaoutsis, kaoutsis@sch.gr + */ + + #include #include #include @@ -6,13 +16,16 @@ #include "ColorWindow.h" #include "msg.h" -ColorWindow::ColorWindow() - : BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) + +ColorWindow::ColorWindow(BMessenger owner) + : BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE), + fOwner(owner) { // Set and collect the variables for revert get_menu_info(&info); get_menu_info(&revert_info); - + BView *colView = new BView(BRect(0,0,1000,100), "menuView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); @@ -22,27 +35,42 @@ ColorWindow::ColorWindow() colView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); colView->AddChild(colorPicker); AddChild(colView); - - ResizeTo(383,130); - + + ResizeTo(383, 130); + // Create the buttons and add them to the view DefaultButton = new BButton(BRect(10,100,85,110), "Default", "Default", - new BMessage(MENU_COLOR_DEFAULT), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); + new BMessage(MENU_COLOR_DEFAULT), B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE); RevertButton = new BButton(BRect(95,100,175,20), "REVERT", "Revert", - new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); - + new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, + B_WILL_DRAW | B_NAVIGABLE); + colView->AddChild(DefaultButton); colView->AddChild(RevertButton); - + DefaultButton->SetEnabled(false); RevertButton->SetEnabled(false); } +ColorWindow::~ColorWindow() +{ +} + + +void +ColorWindow::Quit() +{ + fOwner.SendMessage(COLOR_SCHEME_CLOSED_MSG); + BWindow::Quit(); +} + + void ColorWindow::MessageReceived(BMessage *msg) { - switch(msg->what) { + switch (msg->what) { case MENU_REVERT: colorPicker->SetValue(revert_info.background_color); info.background_color = colorPicker->ValueAsColor(); @@ -50,10 +78,10 @@ ColorWindow::MessageReceived(BMessage *msg) be_app->PostMessage(UPDATE_WINDOW); RevertButton->SetEnabled(false); break; - + case MENU_COLOR_DEFAULT: - // change to system color for system wide - // compatability + // change to system color for system wide + // compatability rgb_color color; color.red = 216; color.blue = 216; @@ -76,7 +104,7 @@ ColorWindow::MessageReceived(BMessage *msg) DefaultButton->SetEnabled(true); RevertButton->SetEnabled(true); break; - + default: be_app->PostMessage(UPDATE_WINDOW); BWindow::MessageReceived(msg); diff --git a/src/preferences/menu/ColorWindow.h b/src/preferences/menu/ColorWindow.h index 8d7b1c4ca7..9552e62e52 100644 --- a/src/preferences/menu/ColorWindow.h +++ b/src/preferences/menu/ColorWindow.h @@ -1,22 +1,38 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + * Vasilis Kaoutsis, kaoutsis@sch.gr + */ #ifndef __COLORWINDOW_H #define __COLORWINDOW_H + #include +#include #include class BColorControl; class BButton; -class ColorWindow : public BWindow { -public: - ColorWindow(); - virtual void MessageReceived(BMessage *msg); -private: - BColorControl *colorPicker; - BButton *DefaultButton; - BButton *RevertButton; - menu_info revert_info; - menu_info info; + +class ColorWindow : public BWindow { + public: + ColorWindow(BMessenger owner); + ~ColorWindow(); + + virtual void Quit(); + virtual void MessageReceived(BMessage* message); + + private: + BColorControl *colorPicker; + BButton *DefaultButton; + BButton *RevertButton; + menu_info revert_info; + menu_info info; + BMessenger fOwner; }; -#endif +#endif // __COLORWINDOW_H diff --git a/src/preferences/menu/Jamfile b/src/preferences/menu/Jamfile index 388ec84d53..9a7c974650 100644 --- a/src/preferences/menu/Jamfile +++ b/src/preferences/menu/Jamfile @@ -1,5 +1,7 @@ SubDir HAIKU_TOP src preferences menu ; +SetSubDirSupportedPlatformsBeOSCompatible ; + Preference Menu : AutoSettingsMenu.cpp BitmapMenuItem.cpp @@ -10,7 +12,7 @@ Preference Menu : MenuBar.cpp MenuSettings.cpp MenuWindow.cpp - : libtranslation.so libbe.so + : be translation : Menu.rdef ; diff --git a/src/preferences/menu/MenuApp.cpp b/src/preferences/menu/MenuApp.cpp index 97b862b0e2..eee13ab667 100644 --- a/src/preferences/menu/MenuApp.cpp +++ b/src/preferences/menu/MenuApp.cpp @@ -5,6 +5,7 @@ * Authors in chronological order: * * Jack Burton + * Vasilis Kaoutsis, kaoutsis@sch.gr */ @@ -30,7 +31,7 @@ MenuApp::MessageReceived(BMessage *msg) case ALLWAYS_TRIGGERS_MSG: case CTL_MARKED_MSG: case ALT_MARKED_MSG: - case COLOR_SCHEME_MSG: + case COLOR_SCHEME_OPEN_MSG: case MENU_COLOR: fMenuWindow->PostMessage(msg); break; diff --git a/src/preferences/menu/MenuBar.cpp b/src/preferences/menu/MenuBar.cpp index a33fe49f56..489ca9d05a 100644 --- a/src/preferences/menu/MenuBar.cpp +++ b/src/preferences/menu/MenuBar.cpp @@ -1,3 +1,13 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + * Vasilis Kaoutsis, kaoutsis@sch.gr + */ + + #include "BitmapMenuItem.h" #include "FontMenu.h" #include "MenuBar.h" @@ -13,7 +23,8 @@ #include MenuBar::MenuBar() - :BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true) + :BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, + B_ITEMS_IN_COLUMN, true) { build_menu(); set_menu(); @@ -37,15 +48,17 @@ MenuBar::build_menu() fontSizeMenu = new FontSizeMenu(); // create the menu items - alwaysShowTriggersItem = new BMenuItem("Always Show Triggers", new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0); - separatorStyleItem = new BMenuItem("Separator Style", new BMessage(DEFAULT_MSG), 0, 0); + alwaysShowTriggersItem = new BMenuItem("Always Show Triggers", + new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0); + separatorStyleItem = new BMenuItem("Separator Style", + new BMessage(DEFAULT_MSG), 0, 0); ctlAsShortcutItem = new BitmapMenuItem("as Shortcut Key", - new BMessage(CTL_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "CTL")); + new BMessage(CTL_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "CTL")); altAsShortcutItem = new BitmapMenuItem("as Shortcut Key", new BMessage(ALT_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT")); // color menu - colorSchemeItem = new BMenuItem("Color Scheme...", new BMessage(COLOR_SCHEME_MSG), 0, 0); + colorSchemeItem = new BMenuItem("Color Scheme...", new BMessage(COLOR_SCHEME_OPEN_MSG), 0, 0); // create the separator menu separatorStyleMenu = new BMenu("Separator Style", B_ITEMS_IN_COLUMN); diff --git a/src/preferences/menu/MenuWindow.cpp b/src/preferences/menu/MenuWindow.cpp index 3fb4d89ff5..d8d998ae22 100644 --- a/src/preferences/menu/MenuWindow.cpp +++ b/src/preferences/menu/MenuWindow.cpp @@ -1,3 +1,13 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + * Vasilis Kaoutsis, kaoutsis@sch.gr + */ + + #include "ColorWindow.h" #include "MenuApp.h" #include "MenuBar.h" @@ -5,72 +15,81 @@ #include "MenuWindow.h" #include "msg.h" -#include -#include - #include #include #include #include #include + +#include +#include + MenuWindow::MenuWindow(BRect rect) : BWindow(rect, "Menu", B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) + B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { + colorWindow = NULL; revert = false; - + menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(menuView); - + menuBar = new MenuBar(); menuView->AddChild(menuBar); - + // resize the window according to the size of menuBar ResizeTo((menuBar->Frame().right + 40), (menuBar->Frame().bottom + 45)); - + BRect menuBarFrame = menuBar->Frame(); - BRect buttonFrame(menuBarFrame.left, menuBarFrame.bottom + 10, menuBarFrame.left + 75, menuBarFrame.bottom + 30); - + BRect buttonFrame(menuBarFrame.left, menuBarFrame.bottom + 10, + menuBarFrame.left + 75, menuBarFrame.bottom + 30); + defaultButton = new BButton(buttonFrame, "Default", "Defaults", new BMessage(MENU_DEFAULT), - B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); + B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); menuView->AddChild(defaultButton); buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0); revertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT), - B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); + B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); revertButton->SetEnabled(false); menuView->AddChild(revertButton); - + menuView->MakeFocus(); - + Update(); } +MenuWindow::~MenuWindow() +{ +} + + void MenuWindow::MessageReceived(BMessage *msg) { MenuSettings *settings = MenuSettings::GetInstance(); menu_info info; - switch(msg->what) { + + switch (msg->what) { case MENU_REVERT: revert = false; settings->Revert(); Update(); break; - + case MENU_DEFAULT: revert = true; settings->ResetToDefaults(); Update(); break; - + case UPDATE_WINDOW: Update(); break; - + case MENU_FONT_FAMILY: case MENU_FONT_STYLE: { @@ -86,7 +105,7 @@ MenuWindow::MessageReceived(BMessage *msg) Update(); break; } - + case MENU_FONT_SIZE: revert = true; settings->Get(info); @@ -94,7 +113,7 @@ MenuWindow::MessageReceived(BMessage *msg) settings->Set(info); Update(); break; - + case MENU_SEP_TYPE: revert = true; settings->Get(info); @@ -102,7 +121,7 @@ MenuWindow::MessageReceived(BMessage *msg) settings->Set(info); Update(); break; - + case ALLWAYS_TRIGGERS_MSG: revert = true; settings->Get(info); @@ -111,7 +130,7 @@ MenuWindow::MessageReceived(BMessage *msg) menuBar->set_menu(); Update(); break; - + case CTL_MARKED_MSG: revert = true; // This might not be the same for all keyboards @@ -122,7 +141,7 @@ MenuWindow::MessageReceived(BMessage *msg) be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); Update(); break; - + case ALT_MARKED_MSG: revert = true; // This might not be the same for all keyboards @@ -130,21 +149,28 @@ MenuWindow::MessageReceived(BMessage *msg) 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)); Update(); break; - - case COLOR_SCHEME_MSG: - colorWindow = new ColorWindow(); - colorWindow->Show(); + + case COLOR_SCHEME_OPEN_MSG: + if (colorWindow == NULL) { + colorWindow = new ColorWindow(this); + colorWindow->Show(); + } else + colorWindow->Activate(); break; - + + case COLOR_SCHEME_CLOSED_MSG: + colorWindow = NULL; + break; + case MENU_COLOR: revert = true; Update(); break; - + default: BWindow::MessageReceived(msg); break; @@ -152,11 +178,24 @@ MenuWindow::MessageReceived(BMessage *msg) } +bool +MenuWindow::QuitRequested() +{ + if (colorWindow != NULL && colorWindow->Lock()) { + colorWindow->Quit(); + colorWindow = NULL; + } + + return true; +} + + void MenuWindow::Update() { revertButton->SetEnabled(revert); - + // alert the rest of the application to update menuBar->Update(); } + diff --git a/src/preferences/menu/MenuWindow.h b/src/preferences/menu/MenuWindow.h index 0433287e0d..611b884a1e 100644 --- a/src/preferences/menu/MenuWindow.h +++ b/src/preferences/menu/MenuWindow.h @@ -1,30 +1,44 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + */ #ifndef __MENU_WINDOW_H #define __MENU_WINDOW_H + #include #include + class ColorWindow; class BMenuItem; class BBox; class BButton; class MenuBar; -class MenuWindow : public BWindow { -public: - MenuWindow(BRect frame); - virtual void MessageReceived(BMessage *msg); - virtual void Update(); - void Defaults(); -private: - bool revert; - ColorWindow *colorWindow; - BMenuItem *toggleItem; - BMenu *menu; - MenuBar *menuBar; - BBox *menuView; - BButton *revertButton; - BButton *defaultButton; +class MenuWindow : public BWindow { + public: + MenuWindow(BRect frame); + virtual ~MenuWindow(); + + virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + + void Update(); + void Defaults(); + + private: + bool revert; + ColorWindow *colorWindow; + BMenuItem *toggleItem; + BMenu *menu; + MenuBar *menuBar; + BBox *menuView; + BButton *revertButton; + BButton *defaultButton; }; -#endif +#endif // __MENU_WINDOW_H diff --git a/src/preferences/menu/msg.h b/src/preferences/menu/msg.h index 432f3d4adc..8ca3f41f9d 100644 --- a/src/preferences/menu/msg.h +++ b/src/preferences/menu/msg.h @@ -1,31 +1,41 @@ +/* + * Copyright 2002-2006, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors in chronological order: + * + * Vasilis Kaoutsis, kaoutsis@sch.gr + */ #ifndef __MESSAGES_H #define __MESSAGES_H + const uint32 MENU_BAR_ARCHIVE = 'mbar'; //default -const uint32 DEFAULT_MSG = 'dmsg'; -const uint32 MENU_DEFAULT = 'mede'; -const uint32 MENU_REVERT = 'mere'; +const uint32 DEFAULT_MSG = 'dmsg'; +const uint32 MENU_DEFAULT = 'mede'; +const uint32 MENU_REVERT = 'mere'; //others -const uint32 UPDATE_WINDOW = 'uwin'; +const uint32 UPDATE_WINDOW = 'uwin'; const uint32 ALLWAYS_TRIGGERS_MSG = 'alti'; -const uint32 COLOR_SCHEME_MSG = 'cosc'; +const uint32 COLOR_SCHEME_OPEN_MSG = 'coso'; +const uint32 COLOR_SCHEME_CLOSED_MSG = 'cosc'; const uint32 CTL_MARKED_MSG = 'ctms'; const uint32 ALT_MARKED_MSG = 'alms'; //color -const uint32 MENU_COLOR = 'meco'; +const uint32 MENU_COLOR = 'meco'; const uint32 CLICK_OPEN_MSG = 'clop'; const uint32 MENU_COLOR_DEFAULT = 'mcod'; //font const uint32 MENU_FONT_FAMILY = 'mffm'; const uint32 MENU_FONT_STYLE = 'mfst'; -const uint32 MENU_FONT_SIZE = 'mfsz'; +const uint32 MENU_FONT_SIZE = 'mfsz'; //seperator -const uint32 MENU_SEP_TYPE = 'mstp'; +const uint32 MENU_SEP_TYPE = 'mstp'; -#endif +#endif // __MESSAGES_H