* 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 <Button.h>
#include <ColorControl.h>
@@ -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);
+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
#define __COLORWINDOW_H
#include <Menu.h>
#include <Messenger.h>
#include <Window.h>
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
+3 -1
View File
@@ -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
;
+2 -1
View File
@@ -5,6 +5,7 @@
* Authors in chronological order:
* <unknown, please fill in who knows>
* Jack Burton
* Vasilis Kaoutsis, [email protected]
*/
@@ -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;
+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 "FontMenu.h"
#include "MenuBar.h"
@@ -13,7 +23,8 @@
#include <stdlib.h>
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);
+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 "MenuApp.h"
#include "MenuBar.h"
@@ -5,72 +15,81 @@
#include "MenuWindow.h"
#include "msg.h"
#include <stdio.h>
#include <string.h>
#include <Alert.h>
#include <Box.h>
#include <Button.h>
#include <MenuItem.h>
#include <Roster.h>
#include <stdio.h>
#include <string.h>
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();
}
+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
#define __MENU_WINDOW_H
#include <Menu.h>
#include <Window.h>
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
+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, 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