The menu window's rect was never initialized, it worked by pure luck if launched from the terminal. Fixes bug 263. Other changes. Not yet finished

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16634 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-03-07 20:11:13 +00:00
parent 33cec98da1
commit 8edede9f83
8 changed files with 167 additions and 191 deletions
-2
View File
@@ -5,8 +5,6 @@
#include <String.h> #include <String.h>
class BBitmap; class BBitmap;
// MBitmapMenuItem class declaration
class BitmapMenuItem : public BMenuItem { class BitmapMenuItem : public BMenuItem {
public: public:
BitmapMenuItem(const char* name, BMessage* message, BBitmap* bmp, BitmapMenuItem(const char* name, BMessage* message, BBitmap* bmp,
+25 -26
View File
@@ -40,34 +40,33 @@ void
ColorWindow::MessageReceived(BMessage *msg) ColorWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
case MENU_REVERT:
colorPicker->SetValue(revert_info.background_color);
info.background_color = colorPicker->ValueAsColor();
set_menu_info(&info);
be_app->PostMessage(UPDATE_WINDOW);
break;
case MENU_REVERT: case MENU_COLOR_DEFAULT:
colorPicker->SetValue(revert_info.background_color); // change to system color for system wide
info.background_color = colorPicker->ValueAsColor(); // compatability
set_menu_info(&info); rgb_color color;
be_app->PostMessage(UPDATE_WINDOW); color.red = 219;
break; color.blue = 219;
color.green = 219;
color.alpha = 255;
colorPicker->SetValue(color);
case MENU_COLOR_DEFAULT: case MENU_COLOR:
// change to system color for system wide get_menu_info(&info);
// compatability info.background_color = colorPicker->ValueAsColor();
rgb_color color; set_menu_info(&info);
color.red = 219; be_app->PostMessage(UPDATE_WINDOW);
color.blue = 219; break;
color.green = 219;
color.alpha = 255;
colorPicker->SetValue(color);
case MENU_COLOR:{ default:
get_menu_info(&info); be_app->PostMessage(UPDATE_WINDOW);
info.background_color = colorPicker->ValueAsColor(); BWindow::MessageReceived(msg);
set_menu_info(&info); break;
be_app->PostMessage(UPDATE_WINDOW);
break;}
default:
be_app->PostMessage(UPDATE_WINDOW);
BMessage(msg);
break;
} }
} }
+2 -1
View File
@@ -7,10 +7,11 @@
class BColorControl; class BColorControl;
class BButton; class BButton;
class ColorWindow : public BWindow { class ColorWindow : public BWindow {
public: public:
ColorWindow(); ColorWindow();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
private:
BColorControl *colorPicker; BColorControl *colorPicker;
BButton *DefaultButton; BButton *DefaultButton;
BButton *RevertButton; BButton *RevertButton;
+3 -14
View File
@@ -5,18 +5,8 @@
MenuApp::MenuApp() MenuApp::MenuApp()
: BApplication("application/x-vnd.Be-GGUI") : BApplication("application/x-vnd.Be-GGUI")
{ {
get_menu_info(&info); fMenuWindow = new MenuWindow(BRect(100, 100, 400, 300));
fMenuWindow->Show();
menuWindow = new MenuWindow();
Update();
menuWindow->Show();
}
void
MenuApp::Update()
{
menuWindow->Update();
} }
@@ -24,7 +14,6 @@ void
MenuApp::MessageReceived(BMessage *msg) MenuApp::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
//others //others
case UPDATE_WINDOW: case UPDATE_WINDOW:
case CLICK_OPEN_MSG: case CLICK_OPEN_MSG:
@@ -33,7 +22,7 @@ MenuApp::MessageReceived(BMessage *msg)
case ALT_MARKED_MSG: case ALT_MARKED_MSG:
case COLOR_SCHEME_MSG: case COLOR_SCHEME_MSG:
case MENU_COLOR: case MENU_COLOR:
menuWindow->PostMessage(msg); fMenuWindow->PostMessage(msg);
break; break;
default: default:
+1 -6
View File
@@ -2,20 +2,15 @@
#define __MENU_APP_H #define __MENU_APP_H
#include <Application.h> #include <Application.h>
#include <Menu.h>
class MenuWindow; class MenuWindow;
class MenuApp : public BApplication { class MenuApp : public BApplication {
public: public:
MenuApp(); MenuApp();
virtual void Update();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
private: private:
MenuWindow *menuWindow; MenuWindow *fMenuWindow;
BRect rect;
menu_info info;
BMenu *menu;
}; };
#endif #endif
+5 -4
View File
@@ -44,14 +44,14 @@ MenuBar::build_menu()
separatorStyleMenu->SetRadioMode(true); separatorStyleMenu->SetRadioMode(true);
BMessage *msg = new BMessage(MENU_SEP_TYPE); BMessage *msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 0); msg->AddInt32("sep", 0);
separatorStyleZero = new BitmapMenuItem(" ", msg, separatorStyleZero = new BitmapMenuItem("separator0", msg,
BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0")); BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0"));
msg = new BMessage(MENU_SEP_TYPE); msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 1); msg->AddInt32("sep", 1);
separatorStyleOne = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1")); separatorStyleOne = new BitmapMenuItem("separator1", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1"));
msg = new BMessage(MENU_SEP_TYPE); msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 2); msg->AddInt32("sep", 2);
separatorStyleTwo = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2")); separatorStyleTwo = new BitmapMenuItem("separator2", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2"));
if (info.separator == 0) if (info.separator == 0)
separatorStyleZero->SetMarked(true); separatorStyleZero->SetMarked(true);
if (info.separator == 1) if (info.separator == 1)
@@ -119,7 +119,8 @@ MenuBar::Update()
separatorStyleOne->SetMarked(true); separatorStyleOne->SetMarked(true);
else if (info.separator == 2) else if (info.separator == 2)
separatorStyleTwo->SetMarked(true); separatorStyleTwo->SetMarked(true);
set_menu();
set_menu();
BFont font; BFont font;
Window()->Lock(); Window()->Lock();
+122 -127
View File
@@ -13,34 +13,41 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <Roster.h> #include <Roster.h>
MenuWindow::MenuWindow() MenuWindow::MenuWindow(BRect rect)
: BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) : BWindow(rect, "Menu", B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
{ {
get_menu_info(&revert_info); get_menu_info(&revert_info);
get_menu_info(&info); get_menu_info(&info);
revert = false; revert = false;
MoveTo((rect.left += 100),(rect.top += 100)); 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);
defaultButton = new BButton(BRect(10,0,85,20), "Default", "Defaults",
new BMessage(MENU_DEFAULT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
revertButton = new BButton(BRect(95,0,175,20), "Revert", "Revert",
new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
revertButton->SetEnabled(false);
// resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45));
BRect menuBarFrame = menuBar->Frame();
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_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
menuView->AddChild(defaultButton); menuView->AddChild(defaultButton);
buttonFrame.OffsetBy(buttonFrame.Width() + 20, 0);
revertButton = new BButton(buttonFrame, "Revert", "Revert", new BMessage(MENU_REVERT),
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
revertButton->SetEnabled(false);
menuView->AddChild(revertButton); menuView->AddChild(revertButton);
menuView->MakeFocus(); menuView->MakeFocus();
Update(); Update();
} }
@@ -48,124 +55,115 @@ void
MenuWindow::MessageReceived(BMessage *msg) MenuWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
case MENU_REVERT:
set_menu_info(&revert_info);
revert = false;
Update();
break;
case MENU_REVERT: case MENU_DEFAULT:
set_menu_info(&revert_info); Defaults();
revert = false; break;
Update();
break;
case MENU_DEFAULT: case UPDATE_WINDOW:
Defaults(); Update();
break; break;
case UPDATE_WINDOW: case MENU_FONT_FAMILY:
Update(); case MENU_FONT_STYLE:
break; {
font_family *family;
msg->FindPointer("family", (void**)&family);
font_style *style;
msg->FindPointer("style", (void**)&style);
memcpy(info.f_family, family, sizeof(info.f_family));
memcpy(info.f_style, style, sizeof(info.f_style));
set_menu_info(&info);
Update();
break;
}
case MENU_FONT_FAMILY: case MENU_FONT_SIZE:
case MENU_FONT_STYLE: revert = true;
{ float fontSize;
font_family *family; msg->FindFloat("size", &fontSize);
msg->FindPointer("family", (void**)&family); info.font_size = fontSize;
font_style *style; set_menu_info(&info);
msg->FindPointer("style", (void**)&style); Update();
memcpy(info.f_family, family, sizeof(info.f_family)); break;
memcpy(info.f_style, style, sizeof(info.f_style));
set_menu_info(&info); case MENU_SEP_TYPE:
Update(); revert = true;
break; int32 i;
msg->FindInt32("sep", &i);
info.separator = i;
set_menu_info(&info);
Update();
break;
case CLICK_OPEN_MSG:
revert = true;
if (info.click_to_open != true)
info.click_to_open = true;
else
info.click_to_open = false;
set_menu_info(&info);
menuBar->set_menu();
Update();
break;
case ALLWAYS_TRIGGERS_MSG:
revert = true;
if (info.triggers_always_shown != true)
info.triggers_always_shown = true;
else
info.triggers_always_shown = false;
set_menu_info(&info);
menuBar->set_menu();
Update();
break;
case CTL_MARKED_MSG:
revert = true;
menuBar->ctlAsShortcutItem->SetMarked(true);
menuBar->altAsShortcutItem->SetMarked(false);
// 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));
Update();
break;
case ALT_MARKED_MSG:
revert = true;
menuBar->altAsShortcutItem->SetMarked(true);
menuBar->ctlAsShortcutItem->SetMarked(false);
// 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));
Update();
break;
case COLOR_SCHEME_MSG:
colorWindow = new ColorWindow();
colorWindow->Show();
break;
case MENU_COLOR:
set_menu_info(&info);
(new BAlert("test","we made it","cool"))->Go();
break;
default:
BWindow::MessageReceived(msg);
break;
} }
case MENU_FONT_SIZE:
revert = true;
float f;
msg->FindFloat("size", &f);
info.font_size = f;
set_menu_info(&info);
Update();
break;
case MENU_SEP_TYPE:
revert = true;
int32 i;
msg->FindInt32("sep", &i);
info.separator = i;
set_menu_info(&info);
Update();
break;
case CLICK_OPEN_MSG:
revert = true;
if (info.click_to_open != true)
info.click_to_open = true;
else
info.click_to_open = false;
set_menu_info(&info);
menuBar->set_menu();
Update();
break;
case ALLWAYS_TRIGGERS_MSG:
revert = true;
if (info.triggers_always_shown != true)
info.triggers_always_shown = true;
else
info.triggers_always_shown = false;
set_menu_info(&info);
menuBar->set_menu();
Update();
break;
case CTL_MARKED_MSG:
revert = true;
menuBar->ctlAsShortcutItem->SetMarked(true);
menuBar->altAsShortcutItem->SetMarked(false);
// 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));
Update();
break;
case ALT_MARKED_MSG:
revert = true;
menuBar->altAsShortcutItem->SetMarked(true);
menuBar->ctlAsShortcutItem->SetMarked(false);
// 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));
Update();
break;
case COLOR_SCHEME_MSG:
colorWindow = new ColorWindow();
colorWindow->Show();
break;
case MENU_COLOR:
set_menu_info(&info);
(new BAlert("test","we made it","cool"))->Go();
break;
default:
BMessage(msg);
break;
}
}
bool
MenuWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return BWindow::QuitRequested();
} }
@@ -176,9 +174,6 @@ MenuWindow::Update()
// alert the rest of the application to update // alert the rest of the application to update
menuBar->Update(); menuBar->Update();
// resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45));
} }
+2 -4
View File
@@ -1,19 +1,18 @@
#ifndef __MENU_WINDOW_H #ifndef __MENU_WINDOW_H
#define __MENU_WINDOW_H #define __MENU_WINDOW_H
#include <Menu.h>
#include <Window.h> #include <Window.h>
class ColorWindow; class ColorWindow;
class BMenuItem; class BMenuItem;
class BMenu;
class BBox; class BBox;
class BButton; class BButton;
class MenuBar; class MenuBar;
class MenuWindow : public BWindow { class MenuWindow : public BWindow {
public: public:
MenuWindow(); MenuWindow(BRect frame);
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Update(); virtual void Update();
void Defaults(); void Defaults();
@@ -23,7 +22,6 @@ private:
BMenuItem *toggleItem; BMenuItem *toggleItem;
menu_info info; menu_info info;
menu_info revert_info; menu_info revert_info;
BRect rect;
BMenu *menu; BMenu *menu;
MenuBar *menuBar; MenuBar *menuBar;
BBox *menuView; BBox *menuView;