Removed the Update() methods. Created a new class AutoSettingsMenu from which every menu class inherits. It gets the new settings on AttachedToWindow() automatically

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17426 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-05-11 20:23:38 +00:00
parent d906e6a03e
commit fdd142c9ed
7 changed files with 75 additions and 76 deletions

View File

@ -0,0 +1,23 @@
#include "AutoSettingsMenu.h"
AutoSettingsMenu::AutoSettingsMenu(const char *name, menu_layout layout)
:
BMenu(name, layout)
{
}
void
AutoSettingsMenu::AttachedToWindow()
{
menu_info info;
get_menu_info(&info);
BFont font;
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
BMenu::AttachedToWindow();
}

View File

@ -0,0 +1,13 @@
#ifndef __AUTOSETTINGSMENU_H
#define __AUTOSETTINGSMENU_H
#include <Menu.h>
class AutoSettingsMenu : public BMenu {
public:
AutoSettingsMenu(const char *name, menu_layout layout);
virtual void AttachedToWindow();
};
#endif

View File

@ -7,13 +7,33 @@
#include <MenuItem.h>
FontMenu::FontMenu()
: BMenu("Font", B_ITEMS_IN_COLUMN)
: AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
SetRadioMode(true);
GetFonts();
}
void
FontMenu::AttachedToWindow()
{
AutoSettingsMenu::AttachedToWindow();
BFont font;
GetFont(&font);
// font style menus
for (int i = 0; i < CountItems(); i++)
ItemAt(i)->Submenu()->SetFont(&font);
ClearAllMarkedItems();
menu_info info;
get_menu_info(&info);
PlaceCheckMarkOnFont(info.f_family, info.f_style);
}
void
FontMenu::GetFonts()
{
@ -22,7 +42,7 @@ FontMenu::GetFonts()
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);
BMenu *fontStyleMenu = new BMenu(*family, B_ITEMS_IN_COLUMN);
fontStyleMenu->SetRadioMode(true);
int32 numStyles = count_font_styles(*family);
for ( int32 j = 0; j < numStyles; j++ ) {
@ -31,7 +51,7 @@ FontMenu::GetFonts()
BMessage *msg = new BMessage(MENU_FONT_STYLE);
msg->AddPointer("family", family);
msg->AddPointer("style", style);
fontStyleItem = new BMenuItem(*style, msg, 0, 0);
BMenuItem *fontStyleItem = new BMenuItem(*style, msg, 0, 0);
fontStyleMenu->AddItem(fontStyleItem);
}
}
@ -42,56 +62,25 @@ FontMenu::GetFonts()
// first style
if ( get_font_style(*family, 0, style, &flags) == B_OK )
msg->AddPointer("style", style);
fontFamily = new BMenuItem(fontStyleMenu, msg);
BMenuItem *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);
if (LockLooper()) {
SetFont(&font);
SetViewColor(info.background_color);
// font style menus
for (int i = 0; i < CountItems(); i++)
ItemAt(i)->Submenu()->SetFont(&font);
InvalidateLayout();
Invalidate();
UnlockLooper();
}
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)) {
BMenuItem *fontFamilyItem = FindItem(family);
if (fontFamilyItem != NULL && family != NULL) {
fontFamilyItem->SetMarked(true);
styleMenu = fontFamilyItem->Submenu();
BMenu *styleMenu = fontFamilyItem->Submenu();
if ((styleMenu != NULL) && (style != NULL)) {
fontStyleItem = styleMenu->FindItem(style);
if (styleMenu != NULL && style != NULL) {
BMenuItem *fontStyleItem = styleMenu->FindItem(style);
if (fontStyleItem != NULL)
fontStyleItem->SetMarked(true);

View File

@ -1,12 +1,11 @@
#ifndef __FONTMENU_H
#define __FONTMENU_H
#include <Menu.h>
#include "AutoSettingsMenu.h"
class FontSizeMenu : public BMenu {
class FontSizeMenu : public AutoSettingsMenu {
public:
FontSizeMenu();
virtual void Update();
private:
menu_info info;
@ -19,19 +18,16 @@ private:
};
class FontMenu : public BMenu {
class FontMenu : public AutoSettingsMenu {
public:
FontMenu();
virtual void GetFonts();
virtual void Update();
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
virtual void ClearAllMarkedItems();
virtual void AttachedToWindow();
void GetFonts();
status_t PlaceCheckMarkOnFont(font_family family, font_style style);
void ClearAllMarkedItems();
private:
menu_info info;
BMenuItem *fontFamily;
BMenu *fontStyleMenu;
BMenuItem *fontStyleItem;
};
#endif

View File

@ -6,7 +6,7 @@
#include <Window.h>
FontSizeMenu::FontSizeMenu()
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
:AutoSettingsMenu("Font Size", B_ITEMS_IN_COLUMN)
{
get_menu_info(&info);
@ -49,23 +49,3 @@ FontSizeMenu::FontSizeMenu()
SetTargetForItems(Window());
SetRadioMode(true);
}
void
FontSizeMenu::Update()
{
get_menu_info(&info);
BFont font;
if (LockLooper()) {
font.SetFamilyAndStyle(info.f_family, info.f_style);
font.SetSize(info.font_size);
SetFont(&font);
SetViewColor(info.background_color);
InvalidateLayout();
Invalidate();
UnlockLooper();
}
SetEnabled(true);
}

View File

@ -1,6 +1,7 @@
SubDir HAIKU_TOP src preferences menu ;
Preference Menu :
AutoSettingsMenu.cpp
BitmapMenuItem.cpp
ColorWindow.cpp
FontMenu.cpp

View File

@ -116,9 +116,6 @@ MenuBar::Update()
{
// get up-to-date menu info
get_menu_info(&info);
// update submenus
fontMenu->Update();
fontSizeMenu->Update();
// this needs to be updated in case the Defaults
// were requested.
if (info.separator == 0)