From 56d2b8765aca983c2e854cf7f2afcc0742bf3809 Mon Sep 17 00:00:00 2001 From: Li Linfeng Date: Sun, 25 Aug 2019 15:00:04 +0800 Subject: [PATCH] bring menu handler change to gtk/win --- src/celestia/gtk/main.cpp | 8 ++++---- src/celestia/gtk/menu-context.cpp | 10 ++++++---- src/celestia/gtk/menu-context.h | 11 ++++++----- src/celestia/win32/winmain.cpp | 17 ++++++++++------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/celestia/gtk/main.cpp b/src/celestia/gtk/main.cpp index 98481c08..77d3454f 100644 --- a/src/celestia/gtk/main.cpp +++ b/src/celestia/gtk/main.cpp @@ -472,11 +472,11 @@ int main(int argc, char* argv[]) /* Create the main menu bar */ createMainMenu(app->mainWindow, app); - /* Initialize the context menu */ - initContext(app); + /* Initialize the context menu handler */ + GTKContextMenuHandler *handler = new GTKContextMenuHandler(app); - /* Set context menu callback for the core */ - app->core->setContextMenuCallback(menuContext); + /* Set context menu handler for the core */ + app->core->setContextMenuHandler(handler); #ifdef GNOME /* Set window contents (GNOME) */ diff --git a/src/celestia/gtk/menu-context.cpp b/src/celestia/gtk/menu-context.cpp index 0297560e..91449e97 100644 --- a/src/celestia/gtk/menu-context.cpp +++ b/src/celestia/gtk/menu-context.cpp @@ -42,16 +42,18 @@ static GtkMenu* CreateAlternateSurfaceMenu(const vector& surfaces); static AppData* app; -/* Initializer. Sets the appData, since there is no way to pass it. */ -void initContext(AppData* a) +/* Initializer. Sets the appData */ +GTKContextMenuHandler::GTKContextMenuHandler(AppData* _app) : + CelestiaCore::ContextMenuHandler() { - app = a; + // FIXME: a workaround to have it referenced by any menu callback + app = _app; } /* ENTRY: Context menu (event handled by appCore) * Normally, float x and y, but unused, so removed. */ -void menuContext(float, float, Selection sel) +void GTKContextMenuHandler::requestContextMenu(float, float, Selection sel) { GtkWidget* popup = gtk_menu_new(); string name; diff --git a/src/celestia/gtk/menu-context.h b/src/celestia/gtk/menu-context.h index 7e621af7..05dca0f3 100644 --- a/src/celestia/gtk/menu-context.h +++ b/src/celestia/gtk/menu-context.h @@ -21,11 +21,12 @@ #include "common.h" +class GTKContextMenuHandler : public CelestiaCore::ContextMenuHandler +{ + public: + GTKContextMenuHandler(AppData* app); -/* Initializer Function */ -void initContext(AppData* a); - -/* Entry Function */ -void menuContext(float, float, Selection sel); + void requestContextMenu(float, float, Selection sel); +}; #endif /* GTK_MENU_CONTEXT_H */ diff --git a/src/celestia/win32/winmain.cpp b/src/celestia/win32/winmain.cpp index 2f63a94a..b3c4c985 100644 --- a/src/celestia/win32/winmain.cpp +++ b/src/celestia/win32/winmain.cpp @@ -1786,12 +1786,6 @@ void ShowWWWInfo(const Selection& sel) } -void ContextMenu(float x, float y, Selection sel) -{ - handlePopupMenu(mainWindow, x, y, sel); -} - - bool EnableFullScreen(const DEVMODE& dm) { DEVMODE devMode; @@ -2349,6 +2343,15 @@ public: } }; +class WinContextMenuHandler : public CelestiaCore::ContextMenuHandler +{ +public: + void requestContextMenu(float x, float y, Selection sel) + { + handlePopupMenu(mainWindow, x, y, sel); + } +}; + static bool InitJoystick(JOYCAPS& caps) { @@ -3524,7 +3527,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, BuildScriptsMenu(menuBar, ScriptsDirectory); syncMenusWithRendererState(); - appCore->setContextMenuCallback(ContextMenu); + appCore->setContextMenuHandler(new WinContextMenuHandler()); bReady = true;