more cleanups. There is now a MenuSettings class which handles settings in a central way. More code simplification
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17427 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include "AutoSettingsMenu.h"
|
#include "AutoSettingsMenu.h"
|
||||||
|
#include "MenuSettings.h"
|
||||||
|
|
||||||
AutoSettingsMenu::AutoSettingsMenu(const char *name, menu_layout layout)
|
AutoSettingsMenu::AutoSettingsMenu(const char *name, menu_layout layout)
|
||||||
:
|
:
|
||||||
@@ -11,9 +12,9 @@ void
|
|||||||
AutoSettingsMenu::AttachedToWindow()
|
AutoSettingsMenu::AttachedToWindow()
|
||||||
{
|
{
|
||||||
menu_info info;
|
menu_info info;
|
||||||
get_menu_info(&info);
|
MenuSettings::GetInstance()->Get(info);
|
||||||
BFont font;
|
|
||||||
|
|
||||||
|
BFont font;
|
||||||
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);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "FontMenu.h"
|
#include "FontMenu.h"
|
||||||
|
#include "MenuSettings.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -9,7 +10,6 @@
|
|||||||
FontMenu::FontMenu()
|
FontMenu::FontMenu()
|
||||||
: AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN)
|
: AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
|
||||||
SetRadioMode(true);
|
SetRadioMode(true);
|
||||||
GetFonts();
|
GetFonts();
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ FontMenu::AttachedToWindow()
|
|||||||
|
|
||||||
ClearAllMarkedItems();
|
ClearAllMarkedItems();
|
||||||
menu_info info;
|
menu_info info;
|
||||||
get_menu_info(&info);
|
MenuSettings::GetInstance()->Get(info);
|
||||||
PlaceCheckMarkOnFont(info.f_family, info.f_style);
|
PlaceCheckMarkOnFont(info.f_family, info.f_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,6 @@
|
|||||||
class FontSizeMenu : public AutoSettingsMenu {
|
class FontSizeMenu : public AutoSettingsMenu {
|
||||||
public:
|
public:
|
||||||
FontSizeMenu();
|
FontSizeMenu();
|
||||||
|
|
||||||
private:
|
|
||||||
menu_info info;
|
|
||||||
BMenuItem *fontSizeNine;
|
|
||||||
BMenuItem *fontSizeTen;
|
|
||||||
BMenuItem *fontSizeEleven;
|
|
||||||
BMenuItem *fontSizeTwelve;
|
|
||||||
BMenuItem *fontSizeFourteen;
|
|
||||||
BMenuItem *fontSizeEighteen;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -26,8 +17,6 @@ public:
|
|||||||
|
|
||||||
status_t PlaceCheckMarkOnFont(font_family family, font_style style);
|
status_t PlaceCheckMarkOnFont(font_family family, font_style style);
|
||||||
void ClearAllMarkedItems();
|
void ClearAllMarkedItems();
|
||||||
private:
|
|
||||||
menu_info info;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "FontMenu.h"
|
#include "FontMenu.h"
|
||||||
|
#include "MenuSettings.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
@@ -8,44 +9,50 @@
|
|||||||
FontSizeMenu::FontSizeMenu()
|
FontSizeMenu::FontSizeMenu()
|
||||||
:AutoSettingsMenu("Font Size", B_ITEMS_IN_COLUMN)
|
:AutoSettingsMenu("Font Size", B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
menu_info info;
|
||||||
|
MenuSettings::GetInstance()->Get(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);
|
BMenuItem *item = new BMenuItem("9", msg, 0, 0);
|
||||||
AddItem(fontSizeNine);
|
AddItem(item);
|
||||||
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
|
if (info.font_size == 9)
|
||||||
|
item->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);
|
item = new BMenuItem("10", msg, 0, 0);
|
||||||
AddItem(fontSizeTen);
|
AddItem(item);
|
||||||
if(info.font_size == 10){fontSizeTen->SetMarked(true);}
|
if (info.font_size == 10)
|
||||||
|
item->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);
|
item = new BMenuItem("11", msg, 0, 0);
|
||||||
AddItem(fontSizeEleven);
|
AddItem(item);
|
||||||
if(info.font_size == 11){fontSizeEleven->SetMarked(true);}
|
if (info.font_size == 11)
|
||||||
|
item->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);
|
item = new BMenuItem("12", msg, 0, 0);
|
||||||
AddItem(fontSizeTwelve);
|
AddItem(item);
|
||||||
if(info.font_size == 12){fontSizeTwelve->SetMarked(true);}
|
if (info.font_size == 12)
|
||||||
|
item->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);
|
item = new BMenuItem("14", msg, 0, 0);
|
||||||
AddItem(fontSizeFourteen);
|
AddItem(item);
|
||||||
if(info.font_size == 14){fontSizeFourteen->SetMarked(true);}
|
if (info.font_size == 14)
|
||||||
|
item->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);
|
item = new BMenuItem("18", msg, 0, 0);
|
||||||
AddItem(fontSizeEighteen);
|
AddItem(item);
|
||||||
if(info.font_size == 18){fontSizeEighteen->SetMarked(true);}
|
if (info.font_size == 18)
|
||||||
|
item->SetMarked(true);
|
||||||
|
|
||||||
SetTargetForItems(Window());
|
|
||||||
SetRadioMode(true);
|
SetRadioMode(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Preference Menu :
|
|||||||
FontSizeMenu.cpp
|
FontSizeMenu.cpp
|
||||||
MenuApp.cpp
|
MenuApp.cpp
|
||||||
MenuBar.cpp
|
MenuBar.cpp
|
||||||
|
MenuSettings.cpp
|
||||||
MenuWindow.cpp
|
MenuWindow.cpp
|
||||||
: libtranslation.so libbe.so
|
: libtranslation.so libbe.so
|
||||||
: Menu.rdef
|
: Menu.rdef
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "BitmapMenuItem.h"
|
#include "BitmapMenuItem.h"
|
||||||
#include "FontMenu.h"
|
#include "FontMenu.h"
|
||||||
#include "MenuBar.h"
|
#include "MenuBar.h"
|
||||||
|
#include "MenuSettings.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
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);
|
|
||||||
build_menu();
|
build_menu();
|
||||||
set_menu();
|
set_menu();
|
||||||
SetItemMargins(14.0, 2.0, 20.0, 0.0);
|
SetItemMargins(14.0, 2.0, 20.0, 0.0);
|
||||||
@@ -88,8 +88,8 @@ MenuBar::set_menu()
|
|||||||
char *chars;
|
char *chars;
|
||||||
bool altAsShortcut;
|
bool altAsShortcut;
|
||||||
|
|
||||||
// get up-to-date menu info
|
menu_info info;
|
||||||
get_menu_info(&info);
|
MenuSettings::GetInstance()->Get(info);
|
||||||
|
|
||||||
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
|
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
|
||||||
|
|
||||||
@@ -114,8 +114,8 @@ MenuBar::set_menu()
|
|||||||
void
|
void
|
||||||
MenuBar::Update()
|
MenuBar::Update()
|
||||||
{
|
{
|
||||||
// get up-to-date menu info
|
menu_info info;
|
||||||
get_menu_info(&info);
|
MenuSettings::GetInstance()->Get(info);
|
||||||
// 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)
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ public:
|
|||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
void set_menu();
|
void set_menu();
|
||||||
void build_menu();
|
void build_menu();
|
||||||
virtual void Update();
|
void Update();
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
menu_info info;
|
|
||||||
|
|
||||||
//seperator submenu
|
//seperator submenu
|
||||||
BMenu *separatorStyleMenu;
|
BMenu *separatorStyleMenu;
|
||||||
BMenuItem *separatorStyleZero;
|
BMenuItem *separatorStyleZero;
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#include "MenuSettings.h"
|
||||||
|
|
||||||
|
|
||||||
|
MenuSettings::MenuSettings()
|
||||||
|
{
|
||||||
|
// 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?).
|
||||||
|
fDefaultSettings.font_size = 12;
|
||||||
|
//info.f_family = "test";
|
||||||
|
//info.f_style = "test";
|
||||||
|
fDefaultSettings.background_color = ui_color(B_MENU_BACKGROUND_COLOR);
|
||||||
|
fDefaultSettings.separator = 0;
|
||||||
|
fDefaultSettings.click_to_open = true;
|
||||||
|
fDefaultSettings.triggers_always_shown = false;
|
||||||
|
|
||||||
|
fPreviousSettings = fDefaultSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MenuSettings::~MenuSettings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
MenuSettings *
|
||||||
|
MenuSettings::GetInstance()
|
||||||
|
{
|
||||||
|
static MenuSettings *settings = NULL;
|
||||||
|
if (settings == NULL)
|
||||||
|
settings = new MenuSettings();
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuSettings::Get(menu_info &info) const
|
||||||
|
{
|
||||||
|
get_menu_info(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuSettings::Set(menu_info &info)
|
||||||
|
{
|
||||||
|
get_menu_info(&fPreviousSettings);
|
||||||
|
set_menu_info(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuSettings::Revert()
|
||||||
|
{
|
||||||
|
set_menu_info(&fPreviousSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MenuSettings::ResetToDefaults()
|
||||||
|
{
|
||||||
|
get_menu_info(&fPreviousSettings);
|
||||||
|
set_menu_info(&fDefaultSettings);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef __MENUSETTINGS_H
|
||||||
|
#define __MENUSETTINGS_H
|
||||||
|
|
||||||
|
#include <Menu.h>
|
||||||
|
|
||||||
|
class MenuSettings {
|
||||||
|
public:
|
||||||
|
static MenuSettings *GetInstance();
|
||||||
|
|
||||||
|
void Get(menu_info &info) const;
|
||||||
|
void Set(menu_info &info);
|
||||||
|
|
||||||
|
void Revert();
|
||||||
|
void ResetToDefaults();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MenuSettings();
|
||||||
|
~MenuSettings();
|
||||||
|
|
||||||
|
menu_info fPreviousSettings;
|
||||||
|
menu_info fDefaultSettings;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "ColorWindow.h"
|
#include "ColorWindow.h"
|
||||||
#include "MenuApp.h"
|
#include "MenuApp.h"
|
||||||
#include "MenuBar.h"
|
#include "MenuBar.h"
|
||||||
|
#include "MenuSettings.h"
|
||||||
#include "MenuWindow.h"
|
#include "MenuWindow.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
|
||||||
@@ -17,9 +18,6 @@ MenuWindow::MenuWindow(BRect rect)
|
|||||||
: BWindow(rect, "Menu", B_TITLED_WINDOW,
|
: BWindow(rect, "Menu", B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
||||||
{
|
{
|
||||||
get_menu_info(&revert_info);
|
|
||||||
get_menu_info(&info);
|
|
||||||
|
|
||||||
revert = false;
|
revert = false;
|
||||||
|
|
||||||
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
|
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
|
||||||
@@ -54,15 +52,19 @@ MenuWindow::MenuWindow(BRect rect)
|
|||||||
void
|
void
|
||||||
MenuWindow::MessageReceived(BMessage *msg)
|
MenuWindow::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
|
MenuSettings *settings = MenuSettings::GetInstance();
|
||||||
|
menu_info info;
|
||||||
switch(msg->what) {
|
switch(msg->what) {
|
||||||
case MENU_REVERT:
|
case MENU_REVERT:
|
||||||
set_menu_info(&revert_info);
|
|
||||||
revert = false;
|
revert = false;
|
||||||
|
settings->Revert();
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MENU_DEFAULT:
|
case MENU_DEFAULT:
|
||||||
Defaults();
|
revert = true;
|
||||||
|
settings->ResetToDefaults();
|
||||||
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_WINDOW:
|
case UPDATE_WINDOW:
|
||||||
@@ -72,42 +74,40 @@ MenuWindow::MessageReceived(BMessage *msg)
|
|||||||
case MENU_FONT_FAMILY:
|
case MENU_FONT_FAMILY:
|
||||||
case MENU_FONT_STYLE:
|
case MENU_FONT_STYLE:
|
||||||
{
|
{
|
||||||
|
revert = true;
|
||||||
font_family *family;
|
font_family *family;
|
||||||
msg->FindPointer("family", (void**)&family);
|
msg->FindPointer("family", (void**)&family);
|
||||||
font_style *style;
|
font_style *style;
|
||||||
msg->FindPointer("style", (void**)&style);
|
msg->FindPointer("style", (void**)&style);
|
||||||
|
settings->Get(info);
|
||||||
memcpy(info.f_family, family, sizeof(info.f_family));
|
memcpy(info.f_family, family, sizeof(info.f_family));
|
||||||
memcpy(info.f_style, style, sizeof(info.f_style));
|
memcpy(info.f_style, style, sizeof(info.f_style));
|
||||||
set_menu_info(&info);
|
settings->Set(info);
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MENU_FONT_SIZE:
|
case MENU_FONT_SIZE:
|
||||||
revert = true;
|
revert = true;
|
||||||
float fontSize;
|
settings->Get(info);
|
||||||
msg->FindFloat("size", &fontSize);
|
msg->FindFloat("size", &info.font_size);
|
||||||
info.font_size = fontSize;
|
settings->Set(info);
|
||||||
set_menu_info(&info);
|
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MENU_SEP_TYPE:
|
case MENU_SEP_TYPE:
|
||||||
revert = true;
|
revert = true;
|
||||||
int32 i;
|
settings->Get(info);
|
||||||
msg->FindInt32("sep", &i);
|
msg->FindInt32("sep", &info.separator);
|
||||||
info.separator = i;
|
settings->Set(info);
|
||||||
set_menu_info(&info);
|
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALLWAYS_TRIGGERS_MSG:
|
case ALLWAYS_TRIGGERS_MSG:
|
||||||
revert = true;
|
revert = true;
|
||||||
if (info.triggers_always_shown != true)
|
settings->Get(info);
|
||||||
info.triggers_always_shown = true;
|
info.triggers_always_shown = !info.triggers_always_shown;
|
||||||
else
|
settings->Set(info);
|
||||||
info.triggers_always_shown = false;
|
|
||||||
set_menu_info(&info);
|
|
||||||
menuBar->set_menu();
|
menuBar->set_menu();
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
@@ -141,7 +141,6 @@ MenuWindow::MessageReceived(BMessage *msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MENU_COLOR:
|
case MENU_COLOR:
|
||||||
get_menu_info(&info);
|
|
||||||
revert = true;
|
revert = true;
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
@@ -161,30 +160,3 @@ MenuWindow::Update()
|
|||||||
// alert the rest of the application to update
|
// alert the rest of the application to update
|
||||||
menuBar->Update();
|
menuBar->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ private:
|
|||||||
bool revert;
|
bool revert;
|
||||||
ColorWindow *colorWindow;
|
ColorWindow *colorWindow;
|
||||||
BMenuItem *toggleItem;
|
BMenuItem *toggleItem;
|
||||||
menu_info info;
|
|
||||||
menu_info revert_info;
|
|
||||||
BMenu *menu;
|
BMenu *menu;
|
||||||
MenuBar *menuBar;
|
MenuBar *menuBar;
|
||||||
BBox *menuView;
|
BBox *menuView;
|
||||||
|
|||||||
Reference in New Issue
Block a user