Restyled Menu preflet, it's still very ugly but at least I can

understand where's things.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16611 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-03-06 17:15:16 +00:00
parent 9f6376a0c7
commit b820da1a25
13 changed files with 750 additions and 740 deletions
-20
View File
@@ -1,20 +0,0 @@
#include "MenuApp.h"
ColorPicker::ColorPicker()
:BColorControl(BPoint(10,10), B_CELLS_32x8,
9, "COLOR", new BMessage(MENU_COLOR), true)
{
menu_info info;
get_menu_info(&info);
SetValue(info.background_color);
}
ColorPicker::~ColorPicker()
{}
void
ColorPicker::MessageReceived(BMessage *msg){
switch(msg->what) {
}
}
+68 -63
View File
@@ -1,68 +1,73 @@
#include <Application.h>
#include <Button.h>
#include <ColorControl.h>
#include <Menu.h>
#include "MenuApp.h"
#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)
{
// 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);
ColorWindow::ColorWindow()
: BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{
// Set and collect the variables for revert
colorPicker = new BColorControl(BPoint(10,10), B_CELLS_32x8,
9, "COLOR", new BMessage(MENU_COLOR), true);
colorPicker->SetValue(info.background_color);
colView->SetViewColor(219,219,219,255);
colView->AddChild(colorPicker);
AddChild(colView);
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);
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);
colView->AddChild(DefaultButton);
colView->AddChild(RevertButton);
}
void
ColorWindow::MessageReceived(BMessage *msg)
{
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_COLOR_DEFAULT:
// change to system color for system wide
// compatability
rgb_color color;
color.red = 219;
color.blue = 219;
color.green = 219;
color.alpha = 255;
colorPicker->SetValue(color);
case MENU_COLOR:{
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);
colorPicker = new ColorPicker();
colView->SetViewColor(219,219,219,255);
colView->AddChild(colorPicker);
AddChild(colView);
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);
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);
colView->AddChild(DefaultButton);
colView->AddChild(RevertButton);
}
info.background_color = colorPicker->ValueAsColor();
set_menu_info(&info);
be_app->PostMessage(UPDATE_WINDOW);
break;}
ColorWindow::~ColorWindow()
{}
void
ColorWindow::MessageReceived(BMessage *msg)
{
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_COLOR_DEFAULT:
// change to system color for system wide
// compatability
rgb_color color;
color.red = 219;
color.blue = 219;
color.green = 219;
color.alpha = 255;
colorPicker->SetValue(color);
case MENU_COLOR:{
get_menu_info(&info);
info.background_color = colorPicker->ValueAsColor();
set_menu_info(&info);
be_app->PostMessage(UPDATE_WINDOW);
break;}
default:
be_app->PostMessage(UPDATE_WINDOW);
BMessage(msg);
break;
}
default:
be_app->PostMessage(UPDATE_WINDOW);
BMessage(msg);
break;
}
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef __COLORWINDOW_H
#define __COLORWINDOW_H
#include <Menu.h>
#include <Window.h>
class BColorControl;
class BButton;
class ColorWindow : public BWindow {
public:
ColorWindow();
virtual void MessageReceived(BMessage *msg);
BColorControl *colorPicker;
BButton *DefaultButton;
BButton *RevertButton;
menu_info revert_info;
menu_info info;
};
#endif
+103 -106
View File
@@ -1,122 +1,119 @@
#include "FontMenu.h"
#include "msg.h"
#include "MenuApp.h"
#include <stdlib.h>
#include <stdlib.h>
#include <Message.h>
#include <MenuItem.h>
FontMenu::FontMenu()
: BMenu("Font", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
SetRadioMode(true);
GetFonts();
}
FontMenu::FontMenu()
: BMenu("Font", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
SetRadioMode(true);
GetFonts();
}
FontMenu::~FontMenu()
{ /*nothing to clean up*/}
void
FontMenu::GetFonts()
{
int32 numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ ) {
font_family *family = (font_family*)malloc(sizeof(font_family));
uint32 flags;
if ( get_font_family(i, family, &flags) == B_OK ) {
fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN);
fontStyleMenu->SetRadioMode(true);
int32 numStyles = count_font_styles(*family);
for ( int32 j = 0; j < numStyles; j++ ) {
font_style *style = (font_style*)malloc(sizeof(font_style));
if ( get_font_style(*family, j, style, &flags) == B_OK ) {
BMessage *msg = new BMessage(MENU_FONT_STYLE);
msg->AddPointer("family", family);
msg->AddPointer("style", style);
fontStyleItem = new BMenuItem(*style, msg, 0, 0);
fontStyleMenu->AddItem(fontStyleItem);
}
}
BMessage *msg = new BMessage(MENU_FONT_FAMILY);
msg->AddPointer("family", family);
void
FontMenu::GetFonts()
{
int32 numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ ) {
font_family *family = (font_family*)malloc(sizeof(font_family));
uint32 flags;
if ( get_font_family(i, family, &flags) == B_OK ) {
fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN);
fontStyleMenu->SetRadioMode(true);
int32 numStyles = count_font_styles(*family);
for ( int32 j = 0; j < numStyles; j++ ) {
font_style *style = (font_style*)malloc(sizeof(font_style));
// if font family selected, we need to change style to
// first style
if ( get_font_style(*family, 0, style, &flags) == B_OK )
if ( get_font_style(*family, j, style, &flags) == B_OK ) {
BMessage *msg = new BMessage(MENU_FONT_STYLE);
msg->AddPointer("family", family);
msg->AddPointer("style", style);
fontFamily = new BMenuItem(fontStyleMenu, msg);
AddItem(fontFamily);
fontStyleItem = new BMenuItem(*style, msg, 0, 0);
fontStyleMenu->AddItem(fontStyleItem);
}
}
BMessage *msg = new BMessage(MENU_FONT_FAMILY);
msg->AddPointer("family", family);
font_style *style = (font_style*)malloc(sizeof(font_style));
// if font family selected, we need to change style to
// first style
if ( get_font_style(*family, 0, style, &flags) == B_OK )
msg->AddPointer("style", style);
fontFamily = new BMenuItem(fontStyleMenu, msg);
AddItem(fontFamily);
}
}
void
FontMenu::Update()
{
// it may be better to pull all menu prefs
// related stuff out of the FontMenu class
// so it can be easily reused in other apps
get_menu_info(&info);
// font menu
BFont font;
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
InvalidateLayout();
}
// font style menus
for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->Submenu()->SetFont(&font);
}
ClearAllMarkedItems();
PlaceCheckMarkOnFont(info.f_family, info.f_style);
}
status_t
FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style)
{
BMenuItem *fontFamilyItem;
BMenuItem *fontStyleItem;
BMenu *styleMenu;
fontFamilyItem = FindItem(family);
if ((fontFamilyItem != NULL) && (family != NULL))
{
fontFamilyItem->SetMarked(true);
styleMenu = fontFamilyItem->Submenu();
void
FontMenu::Update()
{
// it may be better to pull all menu prefs
// related stuff out of the FontMenu class
// so it can be easily reused in other apps
get_menu_info(&info);
if ((styleMenu != NULL) && (style != NULL))
{
fontStyleItem = styleMenu->FindItem(style);
// font menu
BFont font;
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
InvalidateLayout();
// font style menus
for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->Submenu()->SetFont(&font);
}
ClearAllMarkedItems();
PlaceCheckMarkOnFont(info.f_family, info.f_style);
}
if (fontStyleItem != NULL)
{
fontStyleItem->SetMarked(true);
}
status_t
FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style)
{
BMenuItem *fontFamilyItem;
BMenuItem *fontStyleItem;
BMenu *styleMenu;
fontFamilyItem = FindItem(family);
if ((fontFamilyItem != NULL) && (family != NULL))
{
fontFamilyItem->SetMarked(true);
styleMenu = fontFamilyItem->Submenu();
if ((styleMenu != NULL) && (style != NULL))
{
fontStyleItem = styleMenu->FindItem(style);
if (fontStyleItem != NULL)
{
fontStyleItem->SetMarked(true);
}
else
return B_ERROR;
}
else
return B_ERROR;
return B_OK;
}
void
FontMenu::ClearAllMarkedItems()
{
// we need to clear all menuitems and submenuitems
for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->SetMarked(false);
BMenu *submenu = ItemAt(i)->Submenu();
for (int j = 0; j < submenu->CountItems(); j++) {
submenu->ItemAt(j)->SetMarked(false);
}
}
else
return B_ERROR;
}
return B_OK;
}
void
FontMenu::ClearAllMarkedItems()
{
// we need to clear all menuitems and submenuitems
for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->SetMarked(false);
BMenu *submenu = ItemAt(i)->Submenu();
for (int j = 0; j < submenu->CountItems(); j++) {
submenu->ItemAt(j)->SetMarked(false);
}
}
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef __FONTMENU_H
#define __FONTMENU_H
#include <Menu.h>
class FontSizeMenu : public BMenu {
public:
FontSizeMenu();
virtual void Update();
private:
menu_info info;
BMenuItem *fontSizeNine;
BMenuItem *fontSizeTen;
BMenuItem *fontSizeEleven;
BMenuItem *fontSizeTwelve;
BMenuItem *fontSizeFourteen;
BMenuItem *fontSizeEighteen;
};
class FontMenu : public BMenu {
public:
FontMenu();
virtual void GetFonts();
virtual void Update();
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
virtual void ClearAllMarkedItems();
private:
menu_info info;
BMenuItem *fontFamily;
BMenu *fontStyleMenu;
BMenuItem *fontStyleItem;
};
#endif
+67 -65
View File
@@ -1,69 +1,71 @@
#include "FontMenu.h"
#include "msg.h"
#include "MenuApp.h"
#include <Message.h>
#include <MenuItem.h>
#include <Window.h>
FontSizeMenu::FontSizeMenu()
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
FontSizeMenu::FontSizeMenu()
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
BMessage *msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 9);
fontSizeNine = new BMenuItem("9", msg, 0, 0);
AddItem(fontSizeNine);
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 10);
fontSizeTen = new BMenuItem("10", msg, 0, 0);
AddItem(fontSizeTen);
if(info.font_size == 10){fontSizeTen->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 11);
fontSizeEleven = new BMenuItem("11", msg, 0, 0);
AddItem(fontSizeEleven);
if(info.font_size == 11){fontSizeEleven->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 12);
fontSizeTwelve = new BMenuItem("12", msg, 0, 0);
AddItem(fontSizeTwelve);
if(info.font_size == 12){fontSizeTwelve->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 14);
fontSizeFourteen = new BMenuItem("14", msg, 0, 0);
AddItem(fontSizeFourteen);
if(info.font_size == 14){fontSizeFourteen->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 18);
fontSizeEighteen = new BMenuItem("18", msg, 0, 0);
AddItem(fontSizeEighteen);
if(info.font_size == 18){fontSizeEighteen->SetMarked(true);}
SetTargetForItems(Window());
SetRadioMode(true);
}
BMessage *msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 9);
fontSizeNine = new BMenuItem("9", msg, 0, 0);
AddItem(fontSizeNine);
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
FontSizeMenu::~FontSizeMenu()
{ }
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 10);
fontSizeTen = new BMenuItem("10", msg, 0, 0);
AddItem(fontSizeTen);
if(info.font_size == 10){fontSizeTen->SetMarked(true);}
void
FontSizeMenu::Update()
{
get_menu_info(&info);
BFont font;
Supermenu()->Window()->Lock();
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
Supermenu()->Window()->Unlock();
set_menu_info(&info);
InvalidateLayout();
Invalidate();
SetEnabled(true);
}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 11);
fontSizeEleven = new BMenuItem("11", msg, 0, 0);
AddItem(fontSizeEleven);
if(info.font_size == 11){fontSizeEleven->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 12);
fontSizeTwelve = new BMenuItem("12", msg, 0, 0);
AddItem(fontSizeTwelve);
if(info.font_size == 12){fontSizeTwelve->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 14);
fontSizeFourteen = new BMenuItem("14", msg, 0, 0);
AddItem(fontSizeFourteen);
if(info.font_size == 14){fontSizeFourteen->SetMarked(true);}
msg = new BMessage(MENU_FONT_SIZE);
msg->AddFloat("size", 18);
fontSizeEighteen = new BMenuItem("18", msg, 0, 0);
AddItem(fontSizeEighteen);
if(info.font_size == 18){fontSizeEighteen->SetMarked(true);}
SetTargetForItems(Window());
SetRadioMode(true);
}
void
FontSizeMenu::Update()
{
get_menu_info(&info);
BFont font;
Supermenu()->Window()->Lock();
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
Supermenu()->Window()->Unlock();
set_menu_info(&info);
InvalidateLayout();
Invalidate();
SetEnabled(true);
}
-1
View File
@@ -2,7 +2,6 @@ SubDir HAIKU_TOP src preferences menu ;
Preference Menu :
BitmapMenuItem.cpp
ColorPicker.cpp
ColorWindow.cpp
FontMenu.cpp
FontSizeMenu.cpp
+34 -37
View File
@@ -1,42 +1,30 @@
#include "MenuApp.h"
#include "MenuWindow.h"
#include "msg.h"
#include "MenuApp.h"
MenuApp::MenuApp()
: BApplication("application/x-vnd.Be-GGUI")
{
get_menu_info(&info);
MenuApp::MenuApp()
: BApplication("application/x-vnd.Be-GGUI")
{
get_menu_info(&info);
menuWindow = new MenuWindow();
Update();
menuWindow->Show();
}
MenuApp::~MenuApp()
{/*nothing to clean up*/}
bool
MenuApp::QuitRequested()
{
return true;
}
menuWindow = new MenuWindow();
Update();
menuWindow->Show();
}
void
MenuApp::Update()
{
menuWindow->Update();
}
void
MenuApp::Update()
{
menuWindow->Update();
}
int main()
{
new MenuApp();
be_app -> Run();
delete be_app;
}
void
MenuApp::MessageReceived(BMessage *msg){
switch(msg->what) {
void
MenuApp::MessageReceived(BMessage *msg)
{
switch(msg->what) {
//others
case UPDATE_WINDOW:
case CLICK_OPEN_MSG:
@@ -47,9 +35,18 @@
case MENU_COLOR:
menuWindow->PostMessage(msg);
break;
default:
BMessage(msg);
BApplication::MessageReceived(msg);
break;
}
}
}
int main()
{
new MenuApp();
be_app->Run();
delete be_app;
}
+19 -132
View File
@@ -1,134 +1,21 @@
#include <Application.h>
#include <Button.h>
#include <ColorControl.h>
#include <Window.h>
#include <Box.h>
#include <Alert.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#ifndef __MENU_APP_H
#define __MENU_APP_H
#include <Application.h>
#include <Menu.h>
class MenuWindow;
class MenuApp : public BApplication {
public:
MenuApp();
virtual void Update();
virtual void MessageReceived(BMessage *msg);
#include "BitmapMenuItem.h"
private:
MenuWindow *menuWindow;
BRect rect;
menu_info info;
BMenu *menu;
};
#ifndef MENU_H
#define MENU_H
#include "msg.h"
class FontSizeMenu : public BMenu {
public:
FontSizeMenu();
virtual ~FontSizeMenu();
virtual void Update();
menu_info info;
BMenuItem *fontSizeNine;
BMenuItem *fontSizeTen;
BMenuItem *fontSizeEleven;
BMenuItem *fontSizeTwelve;
BMenuItem *fontSizeFourteen;
BMenuItem *fontSizeEighteen;
};
class FontMenu : public BMenu {
public:
FontMenu();
virtual ~FontMenu();
virtual void GetFonts();
virtual void Update();
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
virtual void ClearAllMarkedItems();
menu_info info;
BMenuItem *fontFamily;
BMenu *fontStyleMenu;
BMenuItem *fontStyleItem;
};
class MenuBar : public BMenuBar {
public:
MenuBar();
void set_menu();
void build_menu();
virtual void Update();
virtual void FrameResized(float width, float height);
BRect menu_rect;
BRect rect;
menu_info info;
//seperator submenu
BMenu *separatorStyleMenu;
BMenuItem *separatorStyleZero;
BMenuItem *separatorStyleOne;
BMenuItem *separatorStyleTwo;
//others
FontMenu *fontMenu;
FontSizeMenu *fontSizeMenu;
BMenuItem *clickToOpenItem;
BMenuItem *alwaysShowTriggersItem;
BMenuItem *colorSchemeItem;
BMenuItem *separatorStyleItem;
BMenuItem *ctlAsShortcutItem;
BMenuItem *altAsShortcutItem;
};
class ColorPicker : public BColorControl {
public:
ColorPicker();
virtual ~ColorPicker();
virtual void MessageReceived(BMessage *msg);
};
class ColorWindow : public BWindow {
public:
ColorWindow();
virtual ~ColorWindow();
virtual void MessageReceived(BMessage *msg);
ColorPicker *colorPicker;
BButton *DefaultButton;
BButton *RevertButton;
menu_info revert_info;
menu_info info;
};
class MenuWindow : public BWindow {
public:
MenuWindow();
virtual ~MenuWindow();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Update();
void Defaults();
bool revert;
ColorWindow *colorWindow;
BMenuItem *toggleItem;
menu_info info;
menu_info revert_info;
BRect rect;
BMenu *menu;
MenuBar *menuBar;
BBox *menuView;
BButton *revertButton;
BButton *defaultButton;
};
class MenuApp : public BApplication {
public:
MenuApp();
virtual ~MenuApp();
virtual void Update();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
//main
MenuWindow *menuWindow;
BRect rect;
menu_info info;
BMenu *menu;
};
#endif
#endif
+130 -127
View File
@@ -1,138 +1,141 @@
#include "MenuApp.h"
#include "BitmapMenuItem.h"
#include "FontMenu.h"
#include "MenuBar.h"
#include "msg.h"
#include <Application.h>
#include <Resources.h>
#include <TranslationUtils.h>
#include <Application.h>
#include <Resources.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
MenuBar::MenuBar()
:BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true)
{
get_menu_info(&info);
build_menu();
set_menu();
}
void
MenuBar::build_menu()
{
// font and font size menus
fontMenu = new FontMenu();
fontSizeMenu = new FontSizeMenu();
// create the menu items
clickToOpenItem = new BMenuItem("Click To Open", new BMessage(CLICK_OPEN_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"));
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);
// create the separator menu
separatorStyleMenu = new BMenu("Separator Style", B_ITEMS_IN_COLUMN);
separatorStyleMenu->SetRadioMode(true);
BMessage *msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 0);
separatorStyleZero = new BitmapMenuItem(" ", msg,
BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0"));
msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 1);
separatorStyleOne = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1"));
msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 2);
separatorStyleTwo = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2"));
if (info.separator == 0)
separatorStyleZero->SetMarked(true);
if (info.separator == 1)
separatorStyleOne->SetMarked(true);
if (info.separator == 2)
separatorStyleTwo->SetMarked(true);
separatorStyleMenu->AddItem(separatorStyleZero);
separatorStyleMenu->AddItem(separatorStyleOne);
separatorStyleMenu->AddItem(separatorStyleTwo);
separatorStyleMenu->SetTargetForItems(Window());
// Add items to menubar
AddItem(fontMenu, 0);
AddItem(fontSizeMenu, 1);
AddSeparatorItem();
AddItem(clickToOpenItem);
AddItem(alwaysShowTriggersItem);
AddSeparatorItem();
AddItem(colorSchemeItem);
AddItem(separatorStyleMenu);
AddSeparatorItem();
AddItem(ctlAsShortcutItem);
AddItem(altAsShortcutItem);
SetTargetForItems(Window());
}
void
MenuBar::set_menu()
{
key_map *keys;
char *chars;
bool altAsShortcut;
// get up-to-date menu info
get_menu_info(&info);
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
MenuBar::MenuBar()
:BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true)
{
get_menu_info(&info);
build_menu();
set_menu();
}
void
MenuBar::build_menu()
{
// font and font size menus
fontMenu = new FontMenu();
fontSizeMenu = new FontSizeMenu();
// create the menu items
clickToOpenItem = new BMenuItem("Click To Open", new BMessage(CLICK_OPEN_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"));
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);
// create the separator menu
separatorStyleMenu = new BMenu("Separator Style", B_ITEMS_IN_COLUMN);
separatorStyleMenu->SetRadioMode(true);
BMessage *msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 0);
separatorStyleZero = new BitmapMenuItem(" ", msg,
BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0"));
msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 1);
separatorStyleOne = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1"));
msg = new BMessage(MENU_SEP_TYPE);
msg->AddInt32("sep", 2);
separatorStyleTwo = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2"));
if (info.separator == 0)
separatorStyleZero->SetMarked(true);
if (info.separator == 1)
separatorStyleOne->SetMarked(true);
if (info.separator == 2)
separatorStyleTwo->SetMarked(true);
separatorStyleMenu->AddItem(separatorStyleZero);
separatorStyleMenu->AddItem(separatorStyleOne);
separatorStyleMenu->AddItem(separatorStyleTwo);
separatorStyleMenu->SetTargetForItems(Window());
// Add items to menubar
AddItem(fontMenu, 0);
AddItem(fontSizeMenu, 1);
AddSeparatorItem();
AddItem(clickToOpenItem);
AddItem(alwaysShowTriggersItem);
AddSeparatorItem();
AddItem(colorSchemeItem);
AddItem(separatorStyleMenu);
AddSeparatorItem();
AddItem(ctlAsShortcutItem);
AddItem(altAsShortcutItem);
SetTargetForItems(Window());
}
void
MenuBar::set_menu()
{
key_map *keys;
char *chars;
bool altAsShortcut;
// get up-to-date menu info
get_menu_info(&info);
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
clickToOpenItem->SetMarked(info.click_to_open);
alwaysShowTriggersItem->SetEnabled(info.click_to_open);
get_key_map(&keys, &chars);
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
altAsShortcutItem->SetMarked(altAsShortcut);
ctlAsShortcutItem->SetMarked(!altAsShortcut);
free(chars);
free(keys);
}
alwaysShowTriggersItem->SetEnabled(info.click_to_open);
void
MenuBar::Update()
{
// get up-to-date menu info
get_menu_info(&info);
get_key_map(&keys, &chars);
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
altAsShortcutItem->SetMarked(altAsShortcut);
ctlAsShortcutItem->SetMarked(!altAsShortcut);
free(chars);
free(keys);
}
void
MenuBar::Update()
{
// get up-to-date menu info
get_menu_info(&info);
// update submenus
fontMenu->Update();
fontSizeMenu->Update();
fontMenu->Update();
fontSizeMenu->Update();
// this needs to be updated in case the Defaults
// were requested.
if (info.separator == 0)
separatorStyleZero->SetMarked(true);
else if (info.separator == 1)
separatorStyleOne->SetMarked(true);
else if (info.separator == 2)
separatorStyleTwo->SetMarked(true);
// were requested.
if (info.separator == 0)
separatorStyleZero->SetMarked(true);
else if (info.separator == 1)
separatorStyleOne->SetMarked(true);
else if (info.separator == 2)
separatorStyleTwo->SetMarked(true);
set_menu();
BFont font;
Window()->Lock();
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
Window()->Unlock();
// force the menu to redraw
InvalidateLayout();
}
void MenuBar::FrameResized(float width, float height)
{
Window()->PostMessage(UPDATE_WINDOW);
}
BFont font;
Window()->Lock();
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
Window()->Unlock();
// force the menu to redraw
InvalidateLayout();
}
void
MenuBar::FrameResized(float width, float height)
{
Window()->PostMessage(UPDATE_WINDOW);
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef __BARMENU_H
#define __BARMENU_H
#include <MenuBar.h>
class BMenuItem;
class FontMenu;
class FontSizeMenu;
class MenuBar : public BMenuBar {
public:
MenuBar();
void set_menu();
void build_menu();
virtual void Update();
virtual void FrameResized(float width, float height);
BRect menu_rect;
BRect rect;
menu_info info;
//seperator submenu
BMenu *separatorStyleMenu;
BMenuItem *separatorStyleZero;
BMenuItem *separatorStyleOne;
BMenuItem *separatorStyleTwo;
//others
FontMenu *fontMenu;
FontSizeMenu *fontSizeMenu;
BMenuItem *clickToOpenItem;
BMenuItem *alwaysShowTriggersItem;
BMenuItem *colorSchemeItem;
BMenuItem *separatorStyleItem;
BMenuItem *ctlAsShortcutItem;
BMenuItem *altAsShortcutItem;
};
#endif
+198 -189
View File
@@ -1,200 +1,209 @@
#include "MenuApp.h"
#include <stdio.h>
#include <string.h>
#include <Roster.h>
MenuWindow::MenuWindow()
: BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{
get_menu_info(&revert_info);
get_menu_info(&info);
revert = false;
MoveTo((rect.left += 100),(rect.top += 100));
#include "ColorWindow.h"
#include "MenuApp.h"
#include "MenuBar.h"
#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>
MenuWindow::MenuWindow()
: BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{
get_menu_info(&revert_info);
get_menu_info(&info);
revert = false;
MoveTo((rect.left += 100),(rect.top += 100));
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
AddChild(menuView);
menuBar = new 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);
menuView->AddChild(defaultButton);
menuView->AddChild(revertButton);
menuView->MakeFocus();
Update();
}
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
AddChild(menuView);
MenuWindow::~MenuWindow()
{/*nothing to delete;*/}
menuBar = new 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);
void
MenuWindow::MessageReceived(BMessage *msg)
{
switch(msg->what) {
menuView->AddChild(defaultButton);
menuView->AddChild(revertButton);
menuView->MakeFocus();
case MENU_REVERT:
set_menu_info(&revert_info);
revert = false;
Update();
break;
case MENU_DEFAULT:
Defaults();
break;
case UPDATE_WINDOW:
Update();
break;
case MENU_FONT_FAMILY:
case MENU_FONT_STYLE:
{
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_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);
Update();
}
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;
}
}
void
MenuWindow::MessageReceived(BMessage *msg)
{
switch(msg->what) {
bool
MenuWindow::QuitRequested()
case MENU_REVERT:
set_menu_info(&revert_info);
revert = false;
Update();
break;
case MENU_DEFAULT:
Defaults();
break;
case UPDATE_WINDOW:
Update();
break;
case MENU_FONT_FAMILY:
case MENU_FONT_STYLE:
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
void
MenuWindow::Update()
{
revertButton->SetEnabled(revert);
// alert the rest of the application to update
menuBar->Update();
// resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45));
}
void
MenuWindow::Defaults()
{
// to set the default color. this should be changed
// to the system color for system wide compatability.
rgb_color color;
color.red = 219;
color.blue = 219;
color.green = 219;
color.alpha = 255;
// the default settings. possibly a call to the app_server
// would provide and execute this information, as it does
// for get_menu_info and set_menu_info (or is this information
// coming from libbe.so? or else where?).
info.font_size = 12;
//info.f_family = "test";
//info.f_style = "test";
info.background_color = color;
info.separator = 0;
info.click_to_open = true;
info.triggers_always_shown = false;
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_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();
}
void
MenuWindow::Update()
{
revertButton->SetEnabled(revert);
// alert the rest of the application to update
menuBar->Update();
// resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45));
}
void
MenuWindow::Defaults()
{
// to set the default color. this should be changed
// to the system color for system wide compatability.
rgb_color color;
color.red = 219;
color.blue = 219;
color.green = 219;
color.alpha = 255;
// the default settings. possibly a call to the app_server
// would provide and execute this information, as it does
// for get_menu_info and set_menu_info (or is this information
// coming from libbe.so? or else where?).
info.font_size = 12;
//info.f_family = "test";
//info.f_style = "test";
info.background_color = color;
info.separator = 0;
info.click_to_open = true;
info.triggers_always_shown = false;
set_menu_info(&info);
Update();
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef __MENU_WINDOW_H
#define __MENU_WINDOW_H
#include <Window.h>
class ColorWindow;
class BMenuItem;
class BMenu;
class BBox;
class BButton;
class MenuBar;
class MenuWindow : public BWindow {
public:
MenuWindow();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Update();
void Defaults();
private:
bool revert;
ColorWindow *colorWindow;
BMenuItem *toggleItem;
menu_info info;
menu_info revert_info;
BRect rect;
BMenu *menu;
MenuBar *menuBar;
BBox *menuView;
BButton *revertButton;
BButton *defaultButton;
};
#endif