From b5b0ea5771f5eb1c6fef2dba998bb59c430a16b3 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 25 Feb 2015 10:35:03 +0100 Subject: [PATCH] Revert "Switch to FLTK's copy() method for menus" This reverts commit e95412569bd45ec3da43e1b9a244856e0408f6ab and commit 52a18150a7a8f2802000136c35005bc83b5b0855. The copy() method unfortunately has its own problems so it was not a good replacement. --- vncviewer/OptionsDialog.cxx | 14 +----- vncviewer/Viewport.cxx | 85 ++++++++++++------------------------- 2 files changed, 30 insertions(+), 69 deletions(-) diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx index f3678409..b9752aa1 100644 --- a/vncviewer/OptionsDialog.cxx +++ b/vncviewer/OptionsDialog.cxx @@ -724,19 +724,9 @@ void OptionsDialog::createInputPage(int tx, int ty, int tw, int th) menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu key"))); - Fl_Menu_Item items[getMenuKeySymbolCount() + 2]; - - memset(items, 0, sizeof(items)); - - items[0].text = strdup(_("None")); - items[0].flags = FL_MENU_DIVIDER; - + menuKeyChoice->add(_("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER); for (int i = 0; i < getMenuKeySymbolCount(); i++) - items[i+1].text = strdup(getMenuKeySymbols()[i].name); - - items[getMenuKeySymbolCount()+1].text = NULL; - - menuKeyChoice->copy(items); + menuKeyChoice->add(getMenuKeySymbols()[i].name, 0, NULL, 0, 0); ty += CHOICE_HEIGHT + TIGHT_MARGIN; diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 463523f5..33ba24fe 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -1061,69 +1060,41 @@ void Viewport::handleFLTKKeyPress(void) void Viewport::initContextMenu() { - size_t i; - Fl_Menu_Item items[] = { - { strdup(_("E&xit viewer")), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER }, + contextMenu->clear(); + + contextMenu->add(_("E&xit viewer"), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER); #ifdef HAVE_FLTK_FULLSCREEN - { strdup(_("&Full screen")), 0, NULL, (void*)ID_FULLSCREEN, FL_MENU_TOGGLE }, + contextMenu->add(_("&Full screen"), 0, NULL, (void*)ID_FULLSCREEN, + FL_MENU_TOGGLE | (window()->fullscreen_active()?FL_MENU_VALUE:0)); #endif - { strdup(_("Resize &window to session")), 0, NULL, (void*)ID_RESIZE, FL_MENU_DIVIDER }, - - { strdup(_("&Ctrl")), 0, NULL, (void*)ID_CTRL, FL_MENU_TOGGLE }, - { strdup(_("&Alt")), 0, NULL, (void*)ID_ALT, FL_MENU_TOGGLE }, - - { strdup("Menu key"), 0, NULL, (void*)ID_MENUKEY, 0 }, - { strdup("Secret shortcut menu key"), menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE }, - { strdup(_("Send Ctrl-Alt-&Del")), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER }, - - { strdup(_("&Refresh screen")), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER }, - - { strdup(_("&Options...")), 0, NULL, (void*)ID_OPTIONS, 0 }, - { strdup(_("Connection &info...")), 0, NULL, (void*)ID_INFO, 0 }, - { strdup(_("About &TigerVNC viewer...")), 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER }, - - { strdup(_("Dismiss &menu")), 0, NULL, (void*)ID_DISMISS, 0 }, - - {0} - }; - - // Update any state - for (i = 0;i < sizeof(items)/sizeof(items[0]);i++) { - switch ((intptr_t)items[i].user_data_) { + contextMenu->add(_("Resize &window to session"), 0, NULL, (void*)ID_RESIZE, #ifdef HAVE_FLTK_FULLSCREEN - case ID_FULLSCREEN: - if (window()->fullscreen_active()) - items[i].flags |= FL_MENU_VALUE; - break; - case ID_RESIZE: - if (window()->fullscreen_active()) - items[i].flags |= FL_MENU_INACTIVE; - break; + (window()->fullscreen_active()?FL_MENU_INACTIVE:0) | #endif - case ID_CTRL: - if (menuCtrlKey) - items[i].flags |= FL_MENU_VALUE; - break; - case ID_ALT: - if (menuAltKey) - items[i].flags |= FL_MENU_VALUE; - break; - case ID_MENUKEY: - // The menu key needs to have its fields updated, or the entries hidden - if (!menuKeySym) - items[i].flags |= FL_MENU_INACTIVE | FL_MENU_INVISIBLE; - else if (!(items[i].flags & FL_MENU_INVISIBLE)) { - char sendMenuKey[64]; - snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey); - free((void*)items[i].text); - items[i].text = strdup(sendMenuKey); - } - break; - } + FL_MENU_DIVIDER); + + contextMenu->add(_("&Ctrl"), 0, NULL, (void*)ID_CTRL, + FL_MENU_TOGGLE | (menuCtrlKey?FL_MENU_VALUE:0)); + contextMenu->add(_("&Alt"), 0, NULL, (void*)ID_ALT, + FL_MENU_TOGGLE | (menuAltKey?FL_MENU_VALUE:0)); + + if (menuKeySym) { + char sendMenuKey[64]; + snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey); + contextMenu->add(sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0); + contextMenu->add("Secret shortcut menu key", menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE); } - contextMenu->copy(items); + contextMenu->add(_("Send Ctrl-Alt-&Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER); + + contextMenu->add(_("&Refresh screen"), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER); + + contextMenu->add(_("&Options..."), 0, NULL, (void*)ID_OPTIONS, 0); + contextMenu->add(_("Connection &info..."), 0, NULL, (void*)ID_INFO, 0); + contextMenu->add(_("About &TigerVNC viewer..."), 0, NULL, (void*)ID_ABOUT, FL_MENU_DIVIDER); + + contextMenu->add(_("Dismiss &menu"), 0, NULL, (void*)ID_DISMISS, 0); } -- 2.39.5