* 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
This commit is contained in:
Axel Dörfler
2006-11-17 08:52:01 +00:00
parent 61e693903c
commit da01893148
8 changed files with 213 additions and 90 deletions
+43 -15
View File
@@ -1,3 +1,13 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
* Vasilis Kaoutsis, [email protected]
*/
#include <Application.h> #include <Application.h>
#include <Button.h> #include <Button.h>
#include <ColorControl.h> #include <ColorControl.h>
@@ -6,13 +16,16 @@
#include "ColorWindow.h" #include "ColorWindow.h"
#include "msg.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 // Set and collect the variables for revert
get_menu_info(&info); get_menu_info(&info);
get_menu_info(&revert_info); get_menu_info(&revert_info);
BView *colView = new BView(BRect(0,0,1000,100), "menuView", BView *colView = new BView(BRect(0,0,1000,100), "menuView",
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); 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->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
colView->AddChild(colorPicker); colView->AddChild(colorPicker);
AddChild(colView); AddChild(colView);
ResizeTo(383,130); ResizeTo(383, 130);
// Create the buttons and add them to the view // Create the buttons and add them to the view
DefaultButton = new BButton(BRect(10,100,85,110), "Default", "Default", 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", 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(DefaultButton);
colView->AddChild(RevertButton); colView->AddChild(RevertButton);
DefaultButton->SetEnabled(false); DefaultButton->SetEnabled(false);
RevertButton->SetEnabled(false); RevertButton->SetEnabled(false);
} }
ColorWindow::~ColorWindow()
{
}
void
ColorWindow::Quit()
{
fOwner.SendMessage(COLOR_SCHEME_CLOSED_MSG);
BWindow::Quit();
}
void void
ColorWindow::MessageReceived(BMessage *msg) ColorWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch (msg->what) {
case MENU_REVERT: case MENU_REVERT:
colorPicker->SetValue(revert_info.background_color); colorPicker->SetValue(revert_info.background_color);
info.background_color = colorPicker->ValueAsColor(); info.background_color = colorPicker->ValueAsColor();
@@ -50,10 +78,10 @@ ColorWindow::MessageReceived(BMessage *msg)
be_app->PostMessage(UPDATE_WINDOW); be_app->PostMessage(UPDATE_WINDOW);
RevertButton->SetEnabled(false); RevertButton->SetEnabled(false);
break; break;
case MENU_COLOR_DEFAULT: case MENU_COLOR_DEFAULT:
// change to system color for system wide // change to system color for system wide
// compatability // compatability
rgb_color color; rgb_color color;
color.red = 216; color.red = 216;
color.blue = 216; color.blue = 216;
@@ -76,7 +104,7 @@ ColorWindow::MessageReceived(BMessage *msg)
DefaultButton->SetEnabled(true); DefaultButton->SetEnabled(true);
RevertButton->SetEnabled(true); RevertButton->SetEnabled(true);
break; break;
default: default:
be_app->PostMessage(UPDATE_WINDOW); be_app->PostMessage(UPDATE_WINDOW);
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
+27 -11
View File
@@ -1,22 +1,38 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
* Vasilis Kaoutsis, [email protected]
*/
#ifndef __COLORWINDOW_H #ifndef __COLORWINDOW_H
#define __COLORWINDOW_H #define __COLORWINDOW_H
#include <Menu.h> #include <Menu.h>
#include <Messenger.h>
#include <Window.h> #include <Window.h>
class BColorControl; class BColorControl;
class BButton; class BButton;
class ColorWindow : public BWindow {
public:
ColorWindow();
virtual void MessageReceived(BMessage *msg);
private:
BColorControl *colorPicker; class ColorWindow : public BWindow {
BButton *DefaultButton; public:
BButton *RevertButton; ColorWindow(BMessenger owner);
menu_info revert_info; ~ColorWindow();
menu_info info;
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
+3 -1
View File
@@ -1,5 +1,7 @@
SubDir HAIKU_TOP src preferences menu ; SubDir HAIKU_TOP src preferences menu ;
SetSubDirSupportedPlatformsBeOSCompatible ;
Preference Menu : Preference Menu :
AutoSettingsMenu.cpp AutoSettingsMenu.cpp
BitmapMenuItem.cpp BitmapMenuItem.cpp
@@ -10,7 +12,7 @@ Preference Menu :
MenuBar.cpp MenuBar.cpp
MenuSettings.cpp MenuSettings.cpp
MenuWindow.cpp MenuWindow.cpp
: libtranslation.so libbe.so : be translation
: Menu.rdef : Menu.rdef
; ;
+2 -1
View File
@@ -5,6 +5,7 @@
* Authors in chronological order: * Authors in chronological order:
* <unknown, please fill in who knows> * <unknown, please fill in who knows>
* Jack Burton * Jack Burton
* Vasilis Kaoutsis, [email protected]
*/ */
@@ -30,7 +31,7 @@ MenuApp::MessageReceived(BMessage *msg)
case ALLWAYS_TRIGGERS_MSG: case ALLWAYS_TRIGGERS_MSG:
case CTL_MARKED_MSG: case CTL_MARKED_MSG:
case ALT_MARKED_MSG: case ALT_MARKED_MSG:
case COLOR_SCHEME_MSG: case COLOR_SCHEME_OPEN_MSG:
case MENU_COLOR: case MENU_COLOR:
fMenuWindow->PostMessage(msg); fMenuWindow->PostMessage(msg);
break; break;
+18 -5
View File
@@ -1,3 +1,13 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
* Vasilis Kaoutsis, [email protected]
*/
#include "BitmapMenuItem.h" #include "BitmapMenuItem.h"
#include "FontMenu.h" #include "FontMenu.h"
#include "MenuBar.h" #include "MenuBar.h"
@@ -13,7 +23,8 @@
#include <stdlib.h> #include <stdlib.h>
MenuBar::MenuBar() 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(); build_menu();
set_menu(); set_menu();
@@ -37,15 +48,17 @@ MenuBar::build_menu()
fontSizeMenu = new FontSizeMenu(); fontSizeMenu = new FontSizeMenu();
// create the menu items // create the menu items
alwaysShowTriggersItem = new BMenuItem("Always Show Triggers", new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0); alwaysShowTriggersItem = new BMenuItem("Always Show Triggers",
separatorStyleItem = new BMenuItem("Separator Style", new BMessage(DEFAULT_MSG), 0, 0); new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0);
separatorStyleItem = new BMenuItem("Separator Style",
new BMessage(DEFAULT_MSG), 0, 0);
ctlAsShortcutItem = new BitmapMenuItem("as Shortcut Key", 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", altAsShortcutItem = new BitmapMenuItem("as Shortcut Key",
new BMessage(ALT_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT")); new BMessage(ALT_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT"));
// color menu // 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 // create the separator menu
separatorStyleMenu = new BMenu("Separator Style", B_ITEMS_IN_COLUMN); separatorStyleMenu = new BMenu("Separator Style", B_ITEMS_IN_COLUMN);
+71 -32
View File
@@ -1,3 +1,13 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
* Vasilis Kaoutsis, [email protected]
*/
#include "ColorWindow.h" #include "ColorWindow.h"
#include "MenuApp.h" #include "MenuApp.h"
#include "MenuBar.h" #include "MenuBar.h"
@@ -5,72 +15,81 @@
#include "MenuWindow.h" #include "MenuWindow.h"
#include "msg.h" #include "msg.h"
#include <stdio.h>
#include <string.h>
#include <Alert.h> #include <Alert.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Roster.h> #include <Roster.h>
#include <stdio.h>
#include <string.h>
MenuWindow::MenuWindow(BRect rect) MenuWindow::MenuWindow(BRect rect)
: BWindow(rect, "Menu", B_TITLED_WINDOW, : 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; revert = false;
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, 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); AddChild(menuView);
menuBar = new MenuBar(); menuBar = new MenuBar();
menuView->AddChild(menuBar); menuView->AddChild(menuBar);
// resize the window according to the size of menuBar // resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 40), (menuBar->Frame().bottom + 45)); ResizeTo((menuBar->Frame().right + 40), (menuBar->Frame().bottom + 45));
BRect menuBarFrame = menuBar->Frame(); 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), 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); menuView->AddChild(defaultButton);
buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0); buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0);
revertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT), 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); revertButton->SetEnabled(false);
menuView->AddChild(revertButton); menuView->AddChild(revertButton);
menuView->MakeFocus(); menuView->MakeFocus();
Update(); Update();
} }
MenuWindow::~MenuWindow()
{
}
void void
MenuWindow::MessageReceived(BMessage *msg) MenuWindow::MessageReceived(BMessage *msg)
{ {
MenuSettings *settings = MenuSettings::GetInstance(); MenuSettings *settings = MenuSettings::GetInstance();
menu_info info; menu_info info;
switch(msg->what) {
switch (msg->what) {
case MENU_REVERT: case MENU_REVERT:
revert = false; revert = false;
settings->Revert(); settings->Revert();
Update(); Update();
break; break;
case MENU_DEFAULT: case MENU_DEFAULT:
revert = true; revert = true;
settings->ResetToDefaults(); settings->ResetToDefaults();
Update(); Update();
break; break;
case UPDATE_WINDOW: case UPDATE_WINDOW:
Update(); Update();
break; break;
case MENU_FONT_FAMILY: case MENU_FONT_FAMILY:
case MENU_FONT_STYLE: case MENU_FONT_STYLE:
{ {
@@ -86,7 +105,7 @@ MenuWindow::MessageReceived(BMessage *msg)
Update(); Update();
break; break;
} }
case MENU_FONT_SIZE: case MENU_FONT_SIZE:
revert = true; revert = true;
settings->Get(info); settings->Get(info);
@@ -94,7 +113,7 @@ MenuWindow::MessageReceived(BMessage *msg)
settings->Set(info); settings->Set(info);
Update(); Update();
break; break;
case MENU_SEP_TYPE: case MENU_SEP_TYPE:
revert = true; revert = true;
settings->Get(info); settings->Get(info);
@@ -102,7 +121,7 @@ MenuWindow::MessageReceived(BMessage *msg)
settings->Set(info); settings->Set(info);
Update(); Update();
break; break;
case ALLWAYS_TRIGGERS_MSG: case ALLWAYS_TRIGGERS_MSG:
revert = true; revert = true;
settings->Get(info); settings->Get(info);
@@ -111,7 +130,7 @@ MenuWindow::MessageReceived(BMessage *msg)
menuBar->set_menu(); menuBar->set_menu();
Update(); Update();
break; break;
case CTL_MARKED_MSG: case CTL_MARKED_MSG:
revert = true; revert = true;
// This might not be the same for all keyboards // 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)); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));
Update(); Update();
break; break;
case ALT_MARKED_MSG: case ALT_MARKED_MSG:
revert = true; revert = true;
// This might not be the same for all keyboards // 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_RIGHT_COMMAND_KEY, 0x5f);
set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c); set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c);
set_modifier_key(B_RIGHT_OPTION_KEY, 0x60); set_modifier_key(B_RIGHT_OPTION_KEY, 0x60);
be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));
Update(); Update();
break; break;
case COLOR_SCHEME_MSG: case COLOR_SCHEME_OPEN_MSG:
colorWindow = new ColorWindow(); if (colorWindow == NULL) {
colorWindow->Show(); colorWindow = new ColorWindow(this);
colorWindow->Show();
} else
colorWindow->Activate();
break; break;
case COLOR_SCHEME_CLOSED_MSG:
colorWindow = NULL;
break;
case MENU_COLOR: case MENU_COLOR:
revert = true; revert = true;
Update(); Update();
break; break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@@ -152,11 +178,24 @@ MenuWindow::MessageReceived(BMessage *msg)
} }
bool
MenuWindow::QuitRequested()
{
if (colorWindow != NULL && colorWindow->Lock()) {
colorWindow->Quit();
colorWindow = NULL;
}
return true;
}
void void
MenuWindow::Update() MenuWindow::Update()
{ {
revertButton->SetEnabled(revert); revertButton->SetEnabled(revert);
// alert the rest of the application to update // alert the rest of the application to update
menuBar->Update(); menuBar->Update();
} }
+30 -16
View File
@@ -1,30 +1,44 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
*/
#ifndef __MENU_WINDOW_H #ifndef __MENU_WINDOW_H
#define __MENU_WINDOW_H #define __MENU_WINDOW_H
#include <Menu.h> #include <Menu.h>
#include <Window.h> #include <Window.h>
class ColorWindow; class ColorWindow;
class BMenuItem; class BMenuItem;
class BBox; class BBox;
class BButton; class BButton;
class MenuBar; class MenuBar;
class MenuWindow : public BWindow {
public:
MenuWindow(BRect frame);
virtual void MessageReceived(BMessage *msg);
virtual void Update();
void Defaults();
private: class MenuWindow : public BWindow {
bool revert; public:
ColorWindow *colorWindow; MenuWindow(BRect frame);
BMenuItem *toggleItem; virtual ~MenuWindow();
BMenu *menu;
MenuBar *menuBar; virtual void MessageReceived(BMessage *message);
BBox *menuView; virtual bool QuitRequested();
BButton *revertButton;
BButton *defaultButton; 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
+19 -9
View File
@@ -1,31 +1,41 @@
/*
* Copyright 2002-2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors in chronological order:
* <unknown, please fill in who knows>
* Vasilis Kaoutsis, [email protected]
*/
#ifndef __MESSAGES_H #ifndef __MESSAGES_H
#define __MESSAGES_H #define __MESSAGES_H
const uint32 MENU_BAR_ARCHIVE = 'mbar'; const uint32 MENU_BAR_ARCHIVE = 'mbar';
//default //default
const uint32 DEFAULT_MSG = 'dmsg'; const uint32 DEFAULT_MSG = 'dmsg';
const uint32 MENU_DEFAULT = 'mede'; const uint32 MENU_DEFAULT = 'mede';
const uint32 MENU_REVERT = 'mere'; const uint32 MENU_REVERT = 'mere';
//others //others
const uint32 UPDATE_WINDOW = 'uwin'; const uint32 UPDATE_WINDOW = 'uwin';
const uint32 ALLWAYS_TRIGGERS_MSG = 'alti'; 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 CTL_MARKED_MSG = 'ctms';
const uint32 ALT_MARKED_MSG = 'alms'; const uint32 ALT_MARKED_MSG = 'alms';
//color //color
const uint32 MENU_COLOR = 'meco'; const uint32 MENU_COLOR = 'meco';
const uint32 CLICK_OPEN_MSG = 'clop'; const uint32 CLICK_OPEN_MSG = 'clop';
const uint32 MENU_COLOR_DEFAULT = 'mcod'; const uint32 MENU_COLOR_DEFAULT = 'mcod';
//font //font
const uint32 MENU_FONT_FAMILY = 'mffm'; const uint32 MENU_FONT_FAMILY = 'mffm';
const uint32 MENU_FONT_STYLE = 'mfst'; const uint32 MENU_FONT_STYLE = 'mfst';
const uint32 MENU_FONT_SIZE = 'mfsz'; const uint32 MENU_FONT_SIZE = 'mfsz';
//seperator //seperator
const uint32 MENU_SEP_TYPE = 'mstp'; const uint32 MENU_SEP_TYPE = 'mstp';
#endif #endif // __MESSAGES_H