From b03deb09dbdb2968fecc5f128fd6ae4cf7b8169f Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 19 Apr 2006 20:04:19 +0000 Subject: [PATCH] Menu settings are now handled by the app_server. As a result, changing them does something, although they aren't saved to disk yet. 'click_to_open' is not checked anymore, because it was useless anyway, I'll remove it from the Menu preflet too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17174 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/InterfaceDefs.cpp | 22 +------------- src/kits/interface/Menu.cpp | 45 ++++++++++++++-------------- src/kits/interface/MenuBar.cpp | 6 +--- src/kits/interface/StringView.cpp | 3 +- src/servers/app/DesktopSettings.cpp | 16 +++++----- 5 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/kits/interface/InterfaceDefs.cpp b/src/kits/interface/InterfaceDefs.cpp index 40204953b5..91a2217bd2 100644 --- a/src/kits/interface/InterfaceDefs.cpp +++ b/src/kits/interface/InterfaceDefs.cpp @@ -785,26 +785,6 @@ shift_color(rgb_color color, float shift) } -static status_t -load_menu_settings(menu_info &into) -{ - // TODO: Load settings from the settings file, - // and only if it fails, fallback to the defaults - - // TODO: shouldn't the server handle the details? It could broadcast - // change messages to the applications, which could also relayout - // there menus and menu bars then (as soon as we have a layout management) - into.font_size = be_plain_font->Size(); - be_plain_font->GetFamilyAndStyle(&into.f_family, &into.f_style); - into.background_color = ui_color(B_MENU_BACKGROUND_COLOR); - into.separator = 0; - into.click_to_open = true; - into.triggers_always_shown = false; - - return B_OK; -} - - extern "C" status_t _init_interface_kit_() { @@ -818,7 +798,7 @@ _init_interface_kit_() _init_global_fonts_(); _menu_info_ptr_ = &BMenu::sMenuInfo; - status_t status = load_menu_settings(BMenu::sMenuInfo); + status_t status = get_menu_info(&BMenu::sMenuInfo); general_info.background_color = ui_color(B_PANEL_BACKGROUND_COLOR); general_info.mark_color.set_to(0, 0, 0); diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 7072ceec9a..f69e168db1 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -20,9 +20,11 @@ #include #include +#include #include #include #include +#include class _ExtraMenuData_ { @@ -973,8 +975,7 @@ BMenu::Track(bool sticky, BRect *clickToOpenRect) } // If sticky is false, pass 0 to the tracking function - // so the menu will stay in nonsticky mode, regardless - // of the "IsStickyPrefOn()" value + // so the menu will stay in nonsticky mode const bigtime_t trackTime = sticky ? system_time() : 0; int action; BMenuItem *menuItem = _track(&action, trackTime); @@ -1215,8 +1216,8 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) localAction = MENU_ACT_CLOSE; break; } else if (buttons == 0 && !IsStickyMode()) { - if (IsStickyPrefOn() && (system_time() < trackTime + 1000000 - || (fExtraRect != NULL && fExtraRect->Contains(location)))) + if (system_time() < trackTime + 1000000 + || (fExtraRect != NULL && fExtraRect->Contains(location))) SetStickyMode(true); else { localAction = MENU_ACT_CLOSE; @@ -1896,7 +1897,7 @@ BMenu::UpdateWindowViewSize(bool upWind) bool BMenu::IsStickyPrefOn() { - return sMenuInfo.click_to_open; + return true; } @@ -1991,29 +1992,24 @@ BMenu::DoCreateMsg(BMenuItem *ti, BMenu *tm, BMessage *m, } +// TODO: Maybe the following two methods would fit better into InterfaceDefs.cpp +// In R5, they do all the work client side, we let the app_server handle the details. status_t set_menu_info(menu_info *info) { if (!info) return B_BAD_VALUE; - - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - return B_OK; - - path.Append("menu_settings"); - - BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); - - if (file.InitCheck() != B_OK) - return B_OK; - - file.Write(info, sizeof(menu_info)); + BPrivate::AppServerLink link; + link.StartMessage(AS_SET_MENU_INFO); + link.Attach(*info); - BMenu::sMenuInfo = *info; + status_t status = B_ERROR; + if (link.FlushWithReply(status) == B_OK && status == B_OK) + BMenu::sMenuInfo = *info; + // Update also the local copy, in case anyone relies on it - return B_OK; + return status; } @@ -2023,7 +2019,12 @@ get_menu_info(menu_info *info) if (!info) return B_BAD_VALUE; - *info = BMenu::sMenuInfo; + BPrivate::AppServerLink link; + link.StartMessage(AS_GET_MENU_INFO); - return B_OK; + status_t status = B_ERROR; + if (link.FlushWithReply(status) == B_OK && status == B_OK) + link.Read(info); + + return status; } diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index d7abf693ba..12a8eab760 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -7,8 +7,6 @@ * Stefano Ceccherini (burton666@libero.it) */ -// TODO: Finish this class - #include #include #include @@ -443,10 +441,8 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) if (fSelected != NULL && fSelected->Submenu() == NULL) { resultItem = fSelected; break; - } else if (IsStickyPrefOn()) + } else SetStickyMode(true); - else - break; } if (snoozeAmount > 0) diff --git a/src/kits/interface/StringView.cpp b/src/kits/interface/StringView.cpp index 293cf091ff..8a910aa100 100644 --- a/src/kits/interface/StringView.cpp +++ b/src/kits/interface/StringView.cpp @@ -29,7 +29,8 @@ BStringView::BStringView(BRect frame, const char* name, const char* text, BStringView::BStringView(BMessage* data) - : BView(data) + : BView(data), + fText(NULL) { int32 align; if (data->FindInt32("_align", &align) == B_OK) diff --git a/src/servers/app/DesktopSettings.cpp b/src/servers/app/DesktopSettings.cpp index 3075a3325f..50ff4744e5 100644 --- a/src/servers/app/DesktopSettings.cpp +++ b/src/servers/app/DesktopSettings.cpp @@ -52,14 +52,16 @@ DesktopSettings::Private::_SetDefaults() fScrollBarInfo.min_knob_size = 15; // init menu info - fMenuInfo.font_size = 12.0; -// TODO: ... -// fMenuInfo.f_family; -// fMenuInfo.f_style; -// fMenuInfo.background_color = gColorSet->menu_background; - // look of the separator (R5: (0, 1, 2), default ?) + strlcpy(fMenuInfo.f_family, fPlainFont.Family(), B_FONT_FAMILY_LENGTH); + strlcpy(fMenuInfo.f_style, fPlainFont.Style(), B_FONT_STYLE_LENGTH); + fMenuInfo.font_size = fPlainFont.Size(); + // TODO: + fMenuInfo.background_color.set_to(216, 216, 216); //gColorSet->menu_background; + + // look of the separator (R5: (0, 1, 2), default 0) + // TODO: we could just choose a nice one and remove the others fMenuInfo.separator = 0; - fMenuInfo.click_to_open = true; + fMenuInfo.click_to_open = true; // always true fMenuInfo.triggers_always_shown = false; fWorkspacesCount = 4;