diff --git a/src/preferences/menu/AutoSettingsMenu.cpp b/src/preferences/menu/AutoSettingsMenu.cpp new file mode 100644 index 0000000000..c225856a78 --- /dev/null +++ b/src/preferences/menu/AutoSettingsMenu.cpp @@ -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(); +} diff --git a/src/preferences/menu/AutoSettingsMenu.h b/src/preferences/menu/AutoSettingsMenu.h new file mode 100644 index 0000000000..16ac958c3b --- /dev/null +++ b/src/preferences/menu/AutoSettingsMenu.h @@ -0,0 +1,13 @@ +#ifndef __AUTOSETTINGSMENU_H +#define __AUTOSETTINGSMENU_H + +#include + +class AutoSettingsMenu : public BMenu { +public: + AutoSettingsMenu(const char *name, menu_layout layout); + virtual void AttachedToWindow(); +}; + + +#endif diff --git a/src/preferences/menu/FontMenu.cpp b/src/preferences/menu/FontMenu.cpp index 33b2c59c89..0c1f415b4d 100644 --- a/src/preferences/menu/FontMenu.cpp +++ b/src/preferences/menu/FontMenu.cpp @@ -7,13 +7,33 @@ #include 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); diff --git a/src/preferences/menu/FontMenu.h b/src/preferences/menu/FontMenu.h index f4930e9224..a569062ea5 100644 --- a/src/preferences/menu/FontMenu.h +++ b/src/preferences/menu/FontMenu.h @@ -1,12 +1,11 @@ #ifndef __FONTMENU_H #define __FONTMENU_H -#include +#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 diff --git a/src/preferences/menu/FontSizeMenu.cpp b/src/preferences/menu/FontSizeMenu.cpp index 7c2f4b5060..9b35a6442e 100644 --- a/src/preferences/menu/FontSizeMenu.cpp +++ b/src/preferences/menu/FontSizeMenu.cpp @@ -6,7 +6,7 @@ #include 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); -} diff --git a/src/preferences/menu/Jamfile b/src/preferences/menu/Jamfile index 7f959fce1e..cbc8460c7b 100644 --- a/src/preferences/menu/Jamfile +++ b/src/preferences/menu/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src preferences menu ; Preference Menu : + AutoSettingsMenu.cpp BitmapMenuItem.cpp ColorWindow.cpp FontMenu.cpp diff --git a/src/preferences/menu/MenuBar.cpp b/src/preferences/menu/MenuBar.cpp index a97b825eb8..c09618ec6e 100644 --- a/src/preferences/menu/MenuBar.cpp +++ b/src/preferences/menu/MenuBar.cpp @@ -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)