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:
@@ -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();
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -7,13 +7,33 @@
|
|||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
|
|
||||||
FontMenu::FontMenu()
|
FontMenu::FontMenu()
|
||||||
: BMenu("Font", B_ITEMS_IN_COLUMN)
|
: AutoSettingsMenu("Font", B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
SetRadioMode(true);
|
SetRadioMode(true);
|
||||||
GetFonts();
|
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
|
void
|
||||||
FontMenu::GetFonts()
|
FontMenu::GetFonts()
|
||||||
{
|
{
|
||||||
@@ -22,7 +42,7 @@ FontMenu::GetFonts()
|
|||||||
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);
|
BMenu *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++ ) {
|
||||||
@@ -31,7 +51,7 @@ FontMenu::GetFonts()
|
|||||||
BMessage *msg = new BMessage(MENU_FONT_STYLE);
|
BMessage *msg = new BMessage(MENU_FONT_STYLE);
|
||||||
msg->AddPointer("family", family);
|
msg->AddPointer("family", family);
|
||||||
msg->AddPointer("style", style);
|
msg->AddPointer("style", style);
|
||||||
fontStyleItem = new BMenuItem(*style, msg, 0, 0);
|
BMenuItem *fontStyleItem = new BMenuItem(*style, msg, 0, 0);
|
||||||
fontStyleMenu->AddItem(fontStyleItem);
|
fontStyleMenu->AddItem(fontStyleItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,56 +62,25 @@ FontMenu::GetFonts()
|
|||||||
// first style
|
// first style
|
||||||
if ( get_font_style(*family, 0, style, &flags) == B_OK )
|
if ( get_font_style(*family, 0, style, &flags) == B_OK )
|
||||||
msg->AddPointer("style", style);
|
msg->AddPointer("style", style);
|
||||||
fontFamily = new BMenuItem(fontStyleMenu, msg);
|
BMenuItem *fontFamily = new BMenuItem(fontStyleMenu, msg);
|
||||||
AddItem(fontFamily);
|
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
|
status_t
|
||||||
FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style)
|
FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style)
|
||||||
{
|
{
|
||||||
BMenuItem *fontFamilyItem;
|
BMenuItem *fontFamilyItem = FindItem(family);
|
||||||
BMenuItem *fontStyleItem;
|
if (fontFamilyItem != NULL && family != NULL) {
|
||||||
BMenu *styleMenu;
|
|
||||||
|
|
||||||
fontFamilyItem = FindItem(family);
|
|
||||||
if ((fontFamilyItem != NULL) && (family != NULL)) {
|
|
||||||
fontFamilyItem->SetMarked(true);
|
fontFamilyItem->SetMarked(true);
|
||||||
styleMenu = fontFamilyItem->Submenu();
|
BMenu *styleMenu = fontFamilyItem->Submenu();
|
||||||
|
|
||||||
if ((styleMenu != NULL) && (style != NULL)) {
|
if (styleMenu != NULL && style != NULL) {
|
||||||
fontStyleItem = styleMenu->FindItem(style);
|
BMenuItem *fontStyleItem = styleMenu->FindItem(style);
|
||||||
if (fontStyleItem != NULL)
|
if (fontStyleItem != NULL)
|
||||||
fontStyleItem->SetMarked(true);
|
fontStyleItem->SetMarked(true);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#ifndef __FONTMENU_H
|
#ifndef __FONTMENU_H
|
||||||
#define __FONTMENU_H
|
#define __FONTMENU_H
|
||||||
|
|
||||||
#include <Menu.h>
|
#include "AutoSettingsMenu.h"
|
||||||
|
|
||||||
class FontSizeMenu : public BMenu {
|
class FontSizeMenu : public AutoSettingsMenu {
|
||||||
public:
|
public:
|
||||||
FontSizeMenu();
|
FontSizeMenu();
|
||||||
virtual void Update();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
menu_info info;
|
menu_info info;
|
||||||
@@ -19,19 +18,16 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class FontMenu : public BMenu {
|
class FontMenu : public AutoSettingsMenu {
|
||||||
public:
|
public:
|
||||||
FontMenu();
|
FontMenu();
|
||||||
virtual void GetFonts();
|
virtual void AttachedToWindow();
|
||||||
virtual void Update();
|
void GetFonts();
|
||||||
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
|
|
||||||
virtual void ClearAllMarkedItems();
|
status_t PlaceCheckMarkOnFont(font_family family, font_style style);
|
||||||
|
void ClearAllMarkedItems();
|
||||||
private:
|
private:
|
||||||
menu_info info;
|
menu_info info;
|
||||||
BMenuItem *fontFamily;
|
|
||||||
BMenu *fontStyleMenu;
|
|
||||||
BMenuItem *fontStyleItem;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
FontSizeMenu::FontSizeMenu()
|
FontSizeMenu::FontSizeMenu()
|
||||||
:BMenu("Font Size", B_ITEMS_IN_COLUMN)
|
:AutoSettingsMenu("Font Size", B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
|
|
||||||
@@ -49,23 +49,3 @@ FontSizeMenu::FontSizeMenu()
|
|||||||
SetTargetForItems(Window());
|
SetTargetForItems(Window());
|
||||||
SetRadioMode(true);
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
SubDir HAIKU_TOP src preferences menu ;
|
SubDir HAIKU_TOP src preferences menu ;
|
||||||
|
|
||||||
Preference Menu :
|
Preference Menu :
|
||||||
|
AutoSettingsMenu.cpp
|
||||||
BitmapMenuItem.cpp
|
BitmapMenuItem.cpp
|
||||||
ColorWindow.cpp
|
ColorWindow.cpp
|
||||||
FontMenu.cpp
|
FontMenu.cpp
|
||||||
|
|||||||
@@ -116,9 +116,6 @@ MenuBar::Update()
|
|||||||
{
|
{
|
||||||
// get up-to-date menu info
|
// get up-to-date menu info
|
||||||
get_menu_info(&info);
|
get_menu_info(&info);
|
||||||
// update submenus
|
|
||||||
fontMenu->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)
|
||||||
|
|||||||
Reference in New Issue
Block a user