From 74c38cab401171fe519f3cf5608e9da2e84df826 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 16 Jun 2019 23:33:00 -0400 Subject: [PATCH] BMenuBar & Deskbar: Make the hack to call ShowMenuBar a lot less ugly. The previous hack, which as the comment (and __MWERKS__) implies dates all the way back to the Be era, finally broke: int32 is "int" on non-x86, not "long", and so this generated an undefined symbol error on ARM. The best solution seems to be to make StartMenuBar merely protected, and then make a subclass where it is fully public to call it. This is a lot less fragile (and much less ugly.) Change-Id: I0519d0d9eeb1cc4523d0c6dd4fdfe8688ed1092c Reviewed-on: https://review.haiku-os.org/c/1516 Reviewed-by: Adrien Destugues --- headers/os/interface/MenuBar.h | 11 +++++------ src/apps/deskbar/BarWindow.cpp | 34 ++++++++++++---------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/headers/os/interface/MenuBar.h b/headers/os/interface/MenuBar.h index 76c5f0b176..b48c91aed9 100644 --- a/headers/os/interface/MenuBar.h +++ b/headers/os/interface/MenuBar.h @@ -79,6 +79,11 @@ public: virtual status_t Perform(perform_code code, void* data); +protected: + void StartMenuBar(int32 menuIndex, + bool sticky = true, bool showMenu = false, + BRect* special_rect = NULL); + private: friend class BWindow; friend class BMenuField; @@ -91,12 +96,6 @@ private: BMenuBar &operator=(const BMenuBar &); - // TODO: Tracker uses this function so we can't change - // its signature without breaking it - void StartMenuBar(int32 menuIndex, - bool sticky = true, bool showMenu = false, - BRect* special_rect = NULL); - static int32 _TrackTask(void *arg); BMenuItem* _Track(int32 *action, int32 startIndex = -1, bool showMenu = false); diff --git a/src/apps/deskbar/BarWindow.cpp b/src/apps/deskbar/BarWindow.cpp index 1207eef98c..9469479bfb 100644 --- a/src/apps/deskbar/BarWindow.cpp +++ b/src/apps/deskbar/BarWindow.cpp @@ -68,24 +68,14 @@ All rights reserved. #define B_TRANSLATION_CONTEXT "MainWindow" -// This is a very ugly hack to be able to call the private -// BMenuBar::StartMenuBar() method from the TBarWindow::ShowBeMenu() method. -// Don't do this at home -- but why the hell is this method private? -#if __MWERKS__ - #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarFlbbP5BRect -#elif __GNUC__ <= 2 - #define BMenuBar_StartMenuBar_Hack StartMenuBar__8BMenuBarlbT2P5BRect -#elif __GNUC__ > 2 - #if B_HAIKU_64_BIT - #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarEibbP5BRect - #else - #define BMenuBar_StartMenuBar_Hack _ZN8BMenuBar12StartMenuBarElbbP5BRect - #endif -#else -# error "You may want to port this ugly hack to your compiler ABI" -#endif -extern "C" void - BMenuBar_StartMenuBar_Hack(BMenuBar*, int32, bool, bool, BRect*); +// This is a bit of a hack to be able to call BMenuBar::StartMenuBar(), which +// is private. Don't do this at home! +class TStartableMenuBar : public BMenuBar { +public: + void StartMenuBar(int32 menuIndex, bool sticky = true, bool showMenu = false, + BRect* special_rect = NULL) { BMenuBar::StartMenuBar(menuIndex, sticky, showMenu, + special_rect); } +}; TDeskbarMenu* TBarWindow::sDeskbarMenu = NULL; @@ -323,14 +313,14 @@ TBarWindow::DeskbarMenu() void TBarWindow::ShowDeskbarMenu() { - BMenuBar* menuBar = fBarView->BarMenuBar(); + TStartableMenuBar* menuBar = (TStartableMenuBar*)fBarView->BarMenuBar(); if (menuBar == NULL) - menuBar = KeyMenuBar(); + menuBar = (TStartableMenuBar*)KeyMenuBar(); if (menuBar == NULL) return; - BMenuBar_StartMenuBar_Hack(menuBar, 0, true, true, NULL); + menuBar->StartMenuBar(0, true, true, NULL); } @@ -344,7 +334,7 @@ TBarWindow::ShowTeamMenu() if (KeyMenuBar() == NULL) return; - BMenuBar_StartMenuBar_Hack(KeyMenuBar(), index, true, true, NULL); + ((TStartableMenuBar*)KeyMenuBar())->StartMenuBar(index, true, true, NULL); }