From fa29a27fd8ace3ec2e90ab58f03cce7d56464998 Mon Sep 17 00:00:00 2001 From: Janus Date: Tue, 15 Nov 2016 18:06:48 +0100 Subject: [PATCH] Magnify: MenuField and PopUpMenu are synchronized, Follow menu convetion * MenuField and PopUpMenu are updated as expected. * Follow menu convention as reported in #11259. * Fixes #13080. --- src/apps/magnify/Magnify.cpp | 110 +++++++++++++++++++++++------------ src/apps/magnify/Magnify.h | 2 + 2 files changed, 76 insertions(+), 36 deletions(-) diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp index 18fa5105d3..d6208b8c76 100644 --- a/src/apps/magnify/Magnify.cpp +++ b/src/apps/magnify/Magnify.cpp @@ -146,7 +146,7 @@ BuildInfoMenu(BMenu *menu) menu->AddItem(menuItem); menu->AddSeparatorItem(); - menuItem = new BMenuItem(B_TRANSLATE("Hide/Show info"), + menuItem = new BMenuItem(B_TRANSLATE("Show info"), new BMessage(msg_show_info), 'T'); menu->AddItem(menuItem); menuItem = new BMenuItem(B_TRANSLATE("Add a crosshair"), @@ -155,12 +155,12 @@ BuildInfoMenu(BMenu *menu) menuItem = new BMenuItem(B_TRANSLATE("Remove a crosshair"), new BMessage(msg_remove_cross_hair), 'H', B_SHIFT_KEY); menu->AddItem(menuItem); - menuItem = new BMenuItem(B_TRANSLATE("Hide/Show grid"), + menuItem = new BMenuItem(B_TRANSLATE("Show grid"), new BMessage(msg_toggle_grid), 'G'); menu->AddItem(menuItem); menu->AddSeparatorItem(); - menuItem = new BMenuItem(B_TRANSLATE("Freeze/Unfreeze image"), + menuItem = new BMenuItem(B_TRANSLATE("Freeze image"), new BMessage(msg_freeze), 'F'); menu->AddItem(menuItem); menuItem = new BMenuItem(B_TRANSLATE("Stick coordinates"), @@ -185,6 +185,59 @@ BuildInfoMenu(BMenu *menu) menu->AddItem(menuItem); } +static void +UpdateInfoMenu(BMenu *menu, TWindow *window) +{ + bool state = true; + bool showGrid = true; + bool infoBarIsVisible = true; + bool stickCordinates = true; + if (window) { + state = window->IsActive(); + showGrid = window->ShowGrid(); + infoBarIsVisible = window->InfoBarIsVisible(); + stickCordinates = window->IsSticked(); + } + BMenuItem* menuItem = menu->FindItem(B_TRANSLATE("Show info")); + if (menuItem) { + menuItem->SetEnabled(state); + menuItem->SetMarked(infoBarIsVisible); + } + menuItem = menu->FindItem(B_TRANSLATE("Add a crosshair")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Remove a crosshair")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Show grid")); + if (menuItem) { + menuItem->SetEnabled(state); + menuItem->SetMarked(showGrid); + } + menuItem = menu->FindItem(B_TRANSLATE("Freeze image")); + if (menuItem) { + menuItem->SetMarked(!state); + } + menuItem = menu->FindItem(B_TRANSLATE("Stick coordinates")); + if (menuItem) { + menuItem->SetMarked(stickCordinates); + } + menuItem = menu->FindItem(B_TRANSLATE("Make square")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Decrease window size")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Increase window size")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Decrease pixel size")); + if (menuItem) + menuItem->SetEnabled(state); + menuItem = menu->FindItem(B_TRANSLATE("Increase pixel size")); + if (menuItem) + menuItem->SetEnabled(state); +} // #pragma mark - @@ -655,6 +708,13 @@ TWindow::InfoIsShowing() } +bool +TWindow::InfoBarIsVisible() +{ + return fInfoBarState; +} + + void TWindow::UpdateInfo() { @@ -779,6 +839,13 @@ TWindow::IsActive() } +bool +TWindow::IsSticked() +{ + return fFatBits->Sticked(); +} + + // #pragma mark - @@ -965,37 +1032,7 @@ TMenu::~TMenu() void TMenu::AttachedToWindow() { - bool state = true; - if (fMainWindow) - state = fMainWindow->IsActive(); - - BMenuItem* menuItem = FindItem(B_TRANSLATE("Hide/Show info")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Add a crosshair")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Remove a crosshair")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Hide/Show grid")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Make square")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Decrease window size")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Increase window size")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Decrease pixel size")); - if (menuItem) - menuItem->SetEnabled(state); - menuItem = FindItem(B_TRANSLATE("Increase pixel size")); - if (menuItem) - menuItem->SetEnabled(state); + UpdateInfoMenu(this, fMainWindow); BMenu::AttachedToWindow(); } @@ -1228,10 +1265,11 @@ TMagnify::MouseDown(BPoint where) if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers & B_CONTROL_KEY)) { // secondary button was clicked or control key was down, show menu and return - BPopUpMenu *menu = new BPopUpMenu(B_TRANSLATE("Info")); + BPopUpMenu *menu = new BPopUpMenu(B_TRANSLATE("Info"), false, false); menu->SetFont(be_plain_font); BuildInfoMenu(menu); - + UpdateInfoMenu(menu, dynamic_cast(Window())); +MakeFocus(); BMenuItem *selected = menu->Go(ConvertToScreen(where)); if (selected) Window()->PostMessage(selected->Message()->what); diff --git a/src/apps/magnify/Magnify.h b/src/apps/magnify/Magnify.h index c75b4d1504..35cfa836ba 100644 --- a/src/apps/magnify/Magnify.h +++ b/src/apps/magnify/Magnify.h @@ -221,6 +221,7 @@ class TWindow : public BWindow { void ShowInfo(bool); bool InfoIsShowing(); + bool InfoBarIsVisible(); void UpdateInfo(); void UpdateInfoBarOnResize(); @@ -235,6 +236,7 @@ class TWindow : public BWindow { int32 PixelSize(); bool IsActive(); + bool IsSticked(); private: float fInfoHeight;