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:
@@ -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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
ColorWindow::ColorWindow()
|
||||||
: BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
: 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
|
// 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);
|
||||||
|
|
||||||
|
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(&info);
|
||||||
get_menu_info(&revert_info);
|
info.background_color = colorPicker->ValueAsColor();
|
||||||
|
set_menu_info(&info);
|
||||||
|
be_app->PostMessage(UPDATE_WINDOW);
|
||||||
|
break;}
|
||||||
|
|
||||||
BView *colView = new BView(BRect(0,0,1000,100), "menuView",
|
default:
|
||||||
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
be_app->PostMessage(UPDATE_WINDOW);
|
||||||
|
BMessage(msg);
|
||||||
colorPicker = new ColorPicker();
|
break;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
@@ -1,122 +1,119 @@
|
|||||||
|
#include "FontMenu.h"
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
#include "MenuApp.h"
|
#include <stdlib.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
FontMenu::FontMenu()
|
#include <Message.h>
|
||||||
: BMenu("Font", B_ITEMS_IN_COLUMN)
|
#include <MenuItem.h>
|
||||||
{
|
|
||||||
get_menu_info(&info);
|
|
||||||
SetRadioMode(true);
|
|
||||||
GetFonts();
|
|
||||||
}
|
|
||||||
|
|
||||||
FontMenu::~FontMenu()
|
FontMenu::FontMenu()
|
||||||
{ /*nothing to clean up*/}
|
: BMenu("Font", B_ITEMS_IN_COLUMN)
|
||||||
|
{
|
||||||
|
get_menu_info(&info);
|
||||||
|
SetRadioMode(true);
|
||||||
|
GetFonts();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FontMenu::GetFonts()
|
FontMenu::GetFonts()
|
||||||
{
|
{
|
||||||
int32 numFamilies = count_font_families();
|
int32 numFamilies = count_font_families();
|
||||||
for ( int32 i = 0; i < numFamilies; i++ ) {
|
for ( int32 i = 0; i < numFamilies; i++ ) {
|
||||||
font_family *family = (font_family*)malloc(sizeof(font_family));
|
font_family *family = (font_family*)malloc(sizeof(font_family));
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
if ( get_font_family(i, family, &flags) == B_OK ) {
|
if ( get_font_family(i, family, &flags) == B_OK ) {
|
||||||
fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN);
|
fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN);
|
||||||
fontStyleMenu->SetRadioMode(true);
|
fontStyleMenu->SetRadioMode(true);
|
||||||
int32 numStyles = count_font_styles(*family);
|
int32 numStyles = count_font_styles(*family);
|
||||||
for ( int32 j = 0; j < numStyles; j++ ) {
|
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);
|
|
||||||
font_style *style = (font_style*)malloc(sizeof(font_style));
|
font_style *style = (font_style*)malloc(sizeof(font_style));
|
||||||
// if font family selected, we need to change style to
|
if ( get_font_style(*family, j, style, &flags) == B_OK ) {
|
||||||
// first style
|
BMessage *msg = new BMessage(MENU_FONT_STYLE);
|
||||||
if ( get_font_style(*family, 0, style, &flags) == B_OK )
|
msg->AddPointer("family", family);
|
||||||
msg->AddPointer("style", style);
|
msg->AddPointer("style", style);
|
||||||
fontFamily = new BMenuItem(fontStyleMenu, msg);
|
fontStyleItem = new BMenuItem(*style, msg, 0, 0);
|
||||||
AddItem(fontFamily);
|
fontStyleMenu->AddItem(fontStyleItem);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
if ((styleMenu != NULL) && (style != NULL))
|
|
||||||
{
|
|
||||||
fontStyleItem = styleMenu->FindItem(style);
|
|
||||||
|
|
||||||
if (fontStyleItem != NULL)
|
|
||||||
{
|
|
||||||
fontStyleItem->SetMarked(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
BMessage *msg = new BMessage(MENU_FONT_FAMILY);
|
||||||
return B_ERROR;
|
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();
|
||||||
|
|
||||||
|
if ((styleMenu != NULL) && (style != NULL))
|
||||||
|
{
|
||||||
|
fontStyleItem = styleMenu->FindItem(style);
|
||||||
|
if (fontStyleItem != NULL)
|
||||||
|
{
|
||||||
|
fontStyleItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
void
|
return B_OK;
|
||||||
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++) {
|
void
|
||||||
submenu->ItemAt(j)->SetMarked(false);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,69 +1,71 @@
|
|||||||
|
#include "FontMenu.h"
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
#include "MenuApp.h"
|
#include <Message.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
FontSizeMenu::FontSizeMenu()
|
FontSizeMenu::FontSizeMenu()
|
||||||
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
|
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
|
|
||||||
BMessage *msg = new BMessage(MENU_FONT_SIZE);
|
BMessage *msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 9);
|
msg->AddFloat("size", 9);
|
||||||
fontSizeNine = new BMenuItem("9", msg, 0, 0);
|
fontSizeNine = new BMenuItem("9", msg, 0, 0);
|
||||||
AddItem(fontSizeNine);
|
AddItem(fontSizeNine);
|
||||||
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
|
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
|
||||||
|
|
||||||
msg = new BMessage(MENU_FONT_SIZE);
|
msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 10);
|
msg->AddFloat("size", 10);
|
||||||
fontSizeTen = new BMenuItem("10", msg, 0, 0);
|
fontSizeTen = new BMenuItem("10", msg, 0, 0);
|
||||||
AddItem(fontSizeTen);
|
AddItem(fontSizeTen);
|
||||||
if(info.font_size == 10){fontSizeTen->SetMarked(true);}
|
if(info.font_size == 10){fontSizeTen->SetMarked(true);}
|
||||||
|
|
||||||
msg = new BMessage(MENU_FONT_SIZE);
|
msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 11);
|
msg->AddFloat("size", 11);
|
||||||
fontSizeEleven = new BMenuItem("11", msg, 0, 0);
|
fontSizeEleven = new BMenuItem("11", msg, 0, 0);
|
||||||
AddItem(fontSizeEleven);
|
AddItem(fontSizeEleven);
|
||||||
if(info.font_size == 11){fontSizeEleven->SetMarked(true);}
|
if(info.font_size == 11){fontSizeEleven->SetMarked(true);}
|
||||||
|
|
||||||
msg = new BMessage(MENU_FONT_SIZE);
|
msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 12);
|
msg->AddFloat("size", 12);
|
||||||
fontSizeTwelve = new BMenuItem("12", msg, 0, 0);
|
fontSizeTwelve = new BMenuItem("12", msg, 0, 0);
|
||||||
AddItem(fontSizeTwelve);
|
AddItem(fontSizeTwelve);
|
||||||
if(info.font_size == 12){fontSizeTwelve->SetMarked(true);}
|
if(info.font_size == 12){fontSizeTwelve->SetMarked(true);}
|
||||||
|
|
||||||
msg = new BMessage(MENU_FONT_SIZE);
|
msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 14);
|
msg->AddFloat("size", 14);
|
||||||
fontSizeFourteen = new BMenuItem("14", msg, 0, 0);
|
fontSizeFourteen = new BMenuItem("14", msg, 0, 0);
|
||||||
AddItem(fontSizeFourteen);
|
AddItem(fontSizeFourteen);
|
||||||
if(info.font_size == 14){fontSizeFourteen->SetMarked(true);}
|
if(info.font_size == 14){fontSizeFourteen->SetMarked(true);}
|
||||||
|
|
||||||
msg = new BMessage(MENU_FONT_SIZE);
|
msg = new BMessage(MENU_FONT_SIZE);
|
||||||
msg->AddFloat("size", 18);
|
msg->AddFloat("size", 18);
|
||||||
fontSizeEighteen = new BMenuItem("18", msg, 0, 0);
|
fontSizeEighteen = new BMenuItem("18", msg, 0, 0);
|
||||||
AddItem(fontSizeEighteen);
|
AddItem(fontSizeEighteen);
|
||||||
if(info.font_size == 18){fontSizeEighteen->SetMarked(true);}
|
if(info.font_size == 18){fontSizeEighteen->SetMarked(true);}
|
||||||
|
|
||||||
SetTargetForItems(Window());
|
SetTargetForItems(Window());
|
||||||
SetRadioMode(true);
|
SetRadioMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontSizeMenu::~FontSizeMenu()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FontSizeMenu::Update()
|
FontSizeMenu::Update()
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
Supermenu()->Window()->Lock();
|
Supermenu()->Window()->Lock();
|
||||||
font.SetFamilyAndStyle(info.f_family, info.f_style);
|
font.SetFamilyAndStyle(info.f_family, info.f_style);
|
||||||
font.SetSize(info.font_size);
|
font.SetSize(info.font_size);
|
||||||
SetFont(&font);
|
SetFont(&font);
|
||||||
SetViewColor(info.background_color);
|
SetViewColor(info.background_color);
|
||||||
Supermenu()->Window()->Unlock();
|
Supermenu()->Window()->Unlock();
|
||||||
set_menu_info(&info);
|
set_menu_info(&info);
|
||||||
|
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
SetEnabled(true);
|
SetEnabled(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ SubDir HAIKU_TOP src preferences menu ;
|
|||||||
|
|
||||||
Preference Menu :
|
Preference Menu :
|
||||||
BitmapMenuItem.cpp
|
BitmapMenuItem.cpp
|
||||||
ColorPicker.cpp
|
|
||||||
ColorWindow.cpp
|
ColorWindow.cpp
|
||||||
FontMenu.cpp
|
FontMenu.cpp
|
||||||
FontSizeMenu.cpp
|
FontSizeMenu.cpp
|
||||||
|
|||||||
@@ -1,41 +1,29 @@
|
|||||||
|
#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()
|
menuWindow = new MenuWindow();
|
||||||
: BApplication("application/x-vnd.Be-GGUI")
|
Update();
|
||||||
{
|
menuWindow->Show();
|
||||||
get_menu_info(&info);
|
}
|
||||||
|
|
||||||
menuWindow = new MenuWindow();
|
|
||||||
Update();
|
|
||||||
menuWindow->Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuApp::~MenuApp()
|
void
|
||||||
{/*nothing to clean up*/}
|
MenuApp::Update()
|
||||||
|
{
|
||||||
|
menuWindow->Update();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
MenuApp::QuitRequested()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MenuApp::Update()
|
MenuApp::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
menuWindow->Update();
|
switch(msg->what) {
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
new MenuApp();
|
|
||||||
be_app -> Run();
|
|
||||||
delete be_app;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
MenuApp::MessageReceived(BMessage *msg){
|
|
||||||
switch(msg->what) {
|
|
||||||
|
|
||||||
//others
|
//others
|
||||||
case UPDATE_WINDOW:
|
case UPDATE_WINDOW:
|
||||||
@@ -49,7 +37,16 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BMessage(msg);
|
BApplication::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
new MenuApp();
|
||||||
|
be_app->Run();
|
||||||
|
delete be_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-130
@@ -1,134 +1,21 @@
|
|||||||
#include <Application.h>
|
#ifndef __MENU_APP_H
|
||||||
#include <Button.h>
|
#define __MENU_APP_H
|
||||||
#include <ColorControl.h>
|
|
||||||
#include <Window.h>
|
|
||||||
#include <Box.h>
|
|
||||||
#include <Alert.h>
|
|
||||||
#include <Menu.h>
|
|
||||||
#include <MenuBar.h>
|
|
||||||
#include <MenuItem.h>
|
|
||||||
|
|
||||||
#include "BitmapMenuItem.h"
|
#include <Application.h>
|
||||||
|
#include <Menu.h>
|
||||||
|
|
||||||
#ifndef MENU_H
|
class MenuWindow;
|
||||||
#define MENU_H
|
class MenuApp : public BApplication {
|
||||||
|
public:
|
||||||
|
MenuApp();
|
||||||
|
virtual void Update();
|
||||||
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
|
||||||
#include "msg.h"
|
private:
|
||||||
|
MenuWindow *menuWindow;
|
||||||
|
BRect rect;
|
||||||
|
menu_info info;
|
||||||
|
BMenu *menu;
|
||||||
|
};
|
||||||
|
|
||||||
class FontSizeMenu : public BMenu {
|
#endif
|
||||||
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
|
|
||||||
|
|||||||
+117
-114
@@ -1,138 +1,141 @@
|
|||||||
#include "MenuApp.h"
|
#include "BitmapMenuItem.h"
|
||||||
|
#include "FontMenu.h"
|
||||||
|
#include "MenuBar.h"
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#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)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
build_menu();
|
build_menu();
|
||||||
set_menu();
|
set_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MenuBar::build_menu()
|
MenuBar::build_menu()
|
||||||
{
|
{
|
||||||
// font and font size menus
|
// font and font size menus
|
||||||
fontMenu = new FontMenu();
|
fontMenu = new FontMenu();
|
||||||
fontSizeMenu = new FontSizeMenu();
|
fontSizeMenu = new FontSizeMenu();
|
||||||
|
|
||||||
// create the menu items
|
// create the menu items
|
||||||
clickToOpenItem = new BMenuItem("Click To Open", new BMessage(CLICK_OPEN_MSG), 0, 0);
|
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);
|
alwaysShowTriggersItem = new BMenuItem("Always Show Triggers", new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0);
|
||||||
separatorStyleItem = new BMenuItem("Separator Style", new BMessage(DEFAULT_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_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);
|
||||||
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(" ", 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("", 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("", 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)
|
||||||
separatorStyleOne->SetMarked(true);
|
separatorStyleOne->SetMarked(true);
|
||||||
if (info.separator == 2)
|
if (info.separator == 2)
|
||||||
separatorStyleTwo->SetMarked(true);
|
separatorStyleTwo->SetMarked(true);
|
||||||
separatorStyleMenu->AddItem(separatorStyleZero);
|
separatorStyleMenu->AddItem(separatorStyleZero);
|
||||||
separatorStyleMenu->AddItem(separatorStyleOne);
|
separatorStyleMenu->AddItem(separatorStyleOne);
|
||||||
separatorStyleMenu->AddItem(separatorStyleTwo);
|
separatorStyleMenu->AddItem(separatorStyleTwo);
|
||||||
separatorStyleMenu->SetTargetForItems(Window());
|
separatorStyleMenu->SetTargetForItems(Window());
|
||||||
|
|
||||||
// Add items to menubar
|
// Add items to menubar
|
||||||
AddItem(fontMenu, 0);
|
AddItem(fontMenu, 0);
|
||||||
AddItem(fontSizeMenu, 1);
|
AddItem(fontSizeMenu, 1);
|
||||||
AddSeparatorItem();
|
AddSeparatorItem();
|
||||||
AddItem(clickToOpenItem);
|
AddItem(clickToOpenItem);
|
||||||
AddItem(alwaysShowTriggersItem);
|
AddItem(alwaysShowTriggersItem);
|
||||||
AddSeparatorItem();
|
AddSeparatorItem();
|
||||||
AddItem(colorSchemeItem);
|
AddItem(colorSchemeItem);
|
||||||
AddItem(separatorStyleMenu);
|
AddItem(separatorStyleMenu);
|
||||||
AddSeparatorItem();
|
AddSeparatorItem();
|
||||||
AddItem(ctlAsShortcutItem);
|
AddItem(ctlAsShortcutItem);
|
||||||
AddItem(altAsShortcutItem);
|
AddItem(altAsShortcutItem);
|
||||||
SetTargetForItems(Window());
|
SetTargetForItems(Window());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MenuBar::set_menu()
|
MenuBar::set_menu()
|
||||||
{
|
{
|
||||||
key_map *keys;
|
key_map *keys;
|
||||||
char *chars;
|
char *chars;
|
||||||
bool altAsShortcut;
|
bool altAsShortcut;
|
||||||
|
|
||||||
// get up-to-date menu info
|
// get up-to-date menu info
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
|
|
||||||
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
|
|
||||||
|
|
||||||
|
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
|
||||||
clickToOpenItem->SetMarked(info.click_to_open);
|
clickToOpenItem->SetMarked(info.click_to_open);
|
||||||
alwaysShowTriggersItem->SetEnabled(info.click_to_open);
|
alwaysShowTriggersItem->SetEnabled(info.click_to_open);
|
||||||
|
|
||||||
get_key_map(&keys, &chars);
|
get_key_map(&keys, &chars);
|
||||||
|
|
||||||
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
|
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
|
||||||
altAsShortcutItem->SetMarked(altAsShortcut);
|
altAsShortcutItem->SetMarked(altAsShortcut);
|
||||||
ctlAsShortcutItem->SetMarked(!altAsShortcut);
|
ctlAsShortcutItem->SetMarked(!altAsShortcut);
|
||||||
|
|
||||||
free(chars);
|
free(chars);
|
||||||
free(keys);
|
free(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
MenuBar::Update()
|
|
||||||
{
|
|
||||||
// get up-to-date menu info
|
|
||||||
get_menu_info(&info);
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuBar::Update()
|
||||||
|
{
|
||||||
|
// get up-to-date menu info
|
||||||
|
get_menu_info(&info);
|
||||||
// update submenus
|
// update submenus
|
||||||
fontMenu->Update();
|
fontMenu->Update();
|
||||||
fontSizeMenu->Update();
|
fontSizeMenu->Update();
|
||||||
|
|
||||||
// this needs to be updated in case the Defaults
|
// this needs to be updated in case the Defaults
|
||||||
// were requested.
|
// were requested.
|
||||||
if (info.separator == 0)
|
if (info.separator == 0)
|
||||||
separatorStyleZero->SetMarked(true);
|
separatorStyleZero->SetMarked(true);
|
||||||
else if (info.separator == 1)
|
else if (info.separator == 1)
|
||||||
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();
|
||||||
font.SetFamilyAndStyle(info.f_family, info.f_style);
|
font.SetFamilyAndStyle(info.f_family, info.f_style);
|
||||||
font.SetSize(info.font_size);
|
font.SetSize(info.font_size);
|
||||||
SetFont(&font);
|
SetFont(&font);
|
||||||
SetViewColor(info.background_color);
|
SetViewColor(info.background_color);
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
|
|
||||||
// force the menu to redraw
|
// force the menu to redraw
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuBar::FrameResized(float width, float height)
|
|
||||||
{
|
void
|
||||||
Window()->PostMessage(UPDATE_WINDOW);
|
MenuBar::FrameResized(float width, float height)
|
||||||
}
|
{
|
||||||
|
Window()->PostMessage(UPDATE_WINDOW);
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
+192
-183
@@ -1,200 +1,209 @@
|
|||||||
#include "MenuApp.h"
|
#include "ColorWindow.h"
|
||||||
#include <stdio.h>
|
#include "MenuApp.h"
|
||||||
#include <string.h>
|
#include "MenuBar.h"
|
||||||
#include <Roster.h>
|
#include "MenuWindow.h"
|
||||||
|
#include "msg.h"
|
||||||
|
|
||||||
MenuWindow::MenuWindow()
|
#include <stdio.h>
|
||||||
: BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
#include <string.h>
|
||||||
{
|
|
||||||
get_menu_info(&revert_info);
|
|
||||||
get_menu_info(&info);
|
|
||||||
|
|
||||||
revert = false;
|
#include <Alert.h>
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
|
||||||
MoveTo((rect.left += 100),(rect.top += 100));
|
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,
|
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",
|
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);
|
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",
|
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);
|
new BMessage(MENU_REVERT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
|
||||||
revertButton->SetEnabled(false);
|
revertButton->SetEnabled(false);
|
||||||
|
|
||||||
menuView->AddChild(defaultButton);
|
menuView->AddChild(defaultButton);
|
||||||
menuView->AddChild(revertButton);
|
menuView->AddChild(revertButton);
|
||||||
|
|
||||||
menuView->MakeFocus();
|
menuView->MakeFocus();
|
||||||
|
|
||||||
|
Update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuWindow::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch(msg->what) {
|
||||||
|
|
||||||
|
case MENU_REVERT:
|
||||||
|
set_menu_info(&revert_info);
|
||||||
|
revert = false;
|
||||||
Update();
|
Update();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case MENU_DEFAULT:
|
||||||
|
Defaults();
|
||||||
|
break;
|
||||||
|
|
||||||
MenuWindow::~MenuWindow()
|
case UPDATE_WINDOW:
|
||||||
{/*nothing to delete;*/}
|
Update();
|
||||||
|
break;
|
||||||
|
|
||||||
void
|
case MENU_FONT_FAMILY:
|
||||||
MenuWindow::MessageReceived(BMessage *msg)
|
case MENU_FONT_STYLE:
|
||||||
{
|
{
|
||||||
switch(msg->what) {
|
font_family *family;
|
||||||
|
msg->FindPointer("family", (void**)&family);
|
||||||
case MENU_REVERT:
|
font_style *style;
|
||||||
set_menu_info(&revert_info);
|
msg->FindPointer("style", (void**)&style);
|
||||||
revert = false;
|
memcpy(info.f_family, family, sizeof(info.f_family));
|
||||||
Update();
|
memcpy(info.f_style, style, sizeof(info.f_style));
|
||||||
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);
|
|
||||||
|
|
||||||
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 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;
|
|
||||||
set_menu_info(&info);
|
set_menu_info(&info);
|
||||||
Update();
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user