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:
parent
fdd142c9ed
commit
a73a27510a
@ -1,4 +1,5 @@
|
||||
#include "AutoSettingsMenu.h"
|
||||
#include "MenuSettings.h"
|
||||
|
||||
AutoSettingsMenu::AutoSettingsMenu(const char *name, menu_layout layout)
|
||||
:
|
||||
@ -11,9 +12,9 @@ void
|
||||
AutoSettingsMenu::AttachedToWindow()
|
||||
{
|
||||
menu_info info;
|
||||
get_menu_info(&info);
|
||||
BFont font;
|
||||
|
||||
MenuSettings::GetInstance()->Get(info);
|
||||
|
||||
BFont font;
|
||||
font.SetFamilyAndStyle(info.f_family, info.f_style);
|
||||
font.SetSize(info.font_size);
|
||||
SetFont(&font);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "FontMenu.h"
|
||||
#include "MenuSettings.h"
|
||||
#include "msg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -9,7 +10,6 @@
|
||||
FontMenu::FontMenu()
|
||||
: AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN)
|
||||
{
|
||||
get_menu_info(&info);
|
||||
SetRadioMode(true);
|
||||
GetFonts();
|
||||
}
|
||||
@ -29,7 +29,7 @@ FontMenu::AttachedToWindow()
|
||||
|
||||
ClearAllMarkedItems();
|
||||
menu_info info;
|
||||
get_menu_info(&info);
|
||||
MenuSettings::GetInstance()->Get(info);
|
||||
PlaceCheckMarkOnFont(info.f_family, info.f_style);
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,6 @@
|
||||
class FontSizeMenu : public AutoSettingsMenu {
|
||||
public:
|
||||
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);
|
||||
void ClearAllMarkedItems();
|
||||
private:
|
||||
menu_info info;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "FontMenu.h"
|
||||
#include "MenuSettings.h"
|
||||
#include "msg.h"
|
||||
|
||||
#include <Message.h>
|
||||
@ -8,44 +9,50 @@
|
||||
FontSizeMenu::FontSizeMenu()
|
||||
: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);
|
||||
msg->AddFloat("size", 9);
|
||||
fontSizeNine = new BMenuItem("9", msg, 0, 0);
|
||||
AddItem(fontSizeNine);
|
||||
if(info.font_size == 9){fontSizeNine->SetMarked(true);}
|
||||
BMenuItem *item = new BMenuItem("9", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 9)
|
||||
item->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);}
|
||||
item = new BMenuItem("10", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 10)
|
||||
item->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);}
|
||||
item = new BMenuItem("11", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 11)
|
||||
item->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);}
|
||||
item = new BMenuItem("12", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 12)
|
||||
item->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);}
|
||||
item = new BMenuItem("14", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 14)
|
||||
item->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);}
|
||||
item = new BMenuItem("18", msg, 0, 0);
|
||||
AddItem(item);
|
||||
if (info.font_size == 18)
|
||||
item->SetMarked(true);
|
||||
|
||||
SetTargetForItems(Window());
|
||||
SetRadioMode(true);
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ Preference Menu :
|
||||
FontMenu.cpp
|
||||
FontSizeMenu.cpp
|
||||
MenuApp.cpp
|
||||
MenuBar.cpp
|
||||
MenuBar.cpp
|
||||
MenuSettings.cpp
|
||||
MenuWindow.cpp
|
||||
: libtranslation.so libbe.so
|
||||
: Menu.rdef
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "BitmapMenuItem.h"
|
||||
#include "FontMenu.h"
|
||||
#include "MenuBar.h"
|
||||
#include "MenuSettings.h"
|
||||
#include "msg.h"
|
||||
|
||||
#include <Application.h>
|
||||
@ -14,7 +15,6 @@
|
||||
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();
|
||||
SetItemMargins(14.0, 2.0, 20.0, 0.0);
|
||||
@ -88,8 +88,8 @@ MenuBar::set_menu()
|
||||
char *chars;
|
||||
bool altAsShortcut;
|
||||
|
||||
// get up-to-date menu info
|
||||
get_menu_info(&info);
|
||||
menu_info info;
|
||||
MenuSettings::GetInstance()->Get(info);
|
||||
|
||||
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
|
||||
|
||||
@ -114,8 +114,8 @@ MenuBar::set_menu()
|
||||
void
|
||||
MenuBar::Update()
|
||||
{
|
||||
// get up-to-date menu info
|
||||
get_menu_info(&info);
|
||||
menu_info info;
|
||||
MenuSettings::GetInstance()->Get(info);
|
||||
// this needs to be updated in case the Defaults
|
||||
// were requested.
|
||||
if (info.separator == 0)
|
||||
|
@ -13,12 +13,10 @@ public:
|
||||
virtual void AttachedToWindow();
|
||||
void set_menu();
|
||||
void build_menu();
|
||||
virtual void Update();
|
||||
void Update();
|
||||
virtual void FrameResized(float width, float height);
|
||||
|
||||
private:
|
||||
menu_info info;
|
||||
|
||||
//seperator submenu
|
||||
BMenu *separatorStyleMenu;
|
||||
BMenuItem *separatorStyleZero;
|
||||
|
66
src/preferences/menu/MenuSettings.cpp
Normal file
66
src/preferences/menu/MenuSettings.cpp
Normal file
@ -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);
|
||||
}
|
||||
|
25
src/preferences/menu/MenuSettings.h
Normal file
25
src/preferences/menu/MenuSettings.h
Normal file
@ -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 "MenuApp.h"
|
||||
#include "MenuBar.h"
|
||||
#include "MenuSettings.h"
|
||||
#include "MenuWindow.h"
|
||||
#include "msg.h"
|
||||
|
||||
@ -17,9 +18,6 @@ MenuWindow::MenuWindow(BRect rect)
|
||||
: BWindow(rect, "Menu", B_TITLED_WINDOW,
|
||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
get_menu_info(&revert_info);
|
||||
get_menu_info(&info);
|
||||
|
||||
revert = false;
|
||||
|
||||
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
|
||||
@ -54,15 +52,19 @@ MenuWindow::MenuWindow(BRect rect)
|
||||
void
|
||||
MenuWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
MenuSettings *settings = MenuSettings::GetInstance();
|
||||
menu_info info;
|
||||
switch(msg->what) {
|
||||
case MENU_REVERT:
|
||||
set_menu_info(&revert_info);
|
||||
revert = false;
|
||||
settings->Revert();
|
||||
Update();
|
||||
break;
|
||||
|
||||
case MENU_DEFAULT:
|
||||
Defaults();
|
||||
revert = true;
|
||||
settings->ResetToDefaults();
|
||||
Update();
|
||||
break;
|
||||
|
||||
case UPDATE_WINDOW:
|
||||
@ -72,42 +74,40 @@ MenuWindow::MessageReceived(BMessage *msg)
|
||||
case MENU_FONT_FAMILY:
|
||||
case MENU_FONT_STYLE:
|
||||
{
|
||||
revert = true;
|
||||
font_family *family;
|
||||
msg->FindPointer("family", (void**)&family);
|
||||
font_style *style;
|
||||
msg->FindPointer("style", (void**)&style);
|
||||
settings->Get(info);
|
||||
memcpy(info.f_family, family, sizeof(info.f_family));
|
||||
memcpy(info.f_style, style, sizeof(info.f_style));
|
||||
set_menu_info(&info);
|
||||
settings->Set(info);
|
||||
Update();
|
||||
break;
|
||||
}
|
||||
|
||||
case MENU_FONT_SIZE:
|
||||
revert = true;
|
||||
float fontSize;
|
||||
msg->FindFloat("size", &fontSize);
|
||||
info.font_size = fontSize;
|
||||
set_menu_info(&info);
|
||||
settings->Get(info);
|
||||
msg->FindFloat("size", &info.font_size);
|
||||
settings->Set(info);
|
||||
Update();
|
||||
break;
|
||||
|
||||
case MENU_SEP_TYPE:
|
||||
revert = true;
|
||||
int32 i;
|
||||
msg->FindInt32("sep", &i);
|
||||
info.separator = i;
|
||||
set_menu_info(&info);
|
||||
settings->Get(info);
|
||||
msg->FindInt32("sep", &info.separator);
|
||||
settings->Set(info);
|
||||
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);
|
||||
settings->Get(info);
|
||||
info.triggers_always_shown = !info.triggers_always_shown;
|
||||
settings->Set(info);
|
||||
menuBar->set_menu();
|
||||
Update();
|
||||
break;
|
||||
@ -141,7 +141,6 @@ MenuWindow::MessageReceived(BMessage *msg)
|
||||
break;
|
||||
|
||||
case MENU_COLOR:
|
||||
get_menu_info(&info);
|
||||
revert = true;
|
||||
Update();
|
||||
break;
|
||||
@ -161,30 +160,3 @@ MenuWindow::Update()
|
||||
// alert the rest of the application to 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;
|
||||
ColorWindow *colorWindow;
|
||||
BMenuItem *toggleItem;
|
||||
menu_info info;
|
||||
menu_info revert_info;
|
||||
BMenu *menu;
|
||||
MenuBar *menuBar;
|
||||
BBox *menuView;
|
||||
|
Loading…
Reference in New Issue
Block a user