From 90dbf0c77dee3370fa878cfc67c681e2675fb2a7 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 21 Mar 2021 01:58:54 +0100 Subject: [PATCH] Fix menu-with-images example w/o using exit() Use window->hide() in quit callback instead. --- examples/howto-menu-with-images.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/howto-menu-with-images.cxx b/examples/howto-menu-with-images.cxx index 1262ffd38..e0be5cad4 100644 --- a/examples/howto-menu-with-images.cxx +++ b/examples/howto-menu-with-images.cxx @@ -4,7 +4,7 @@ // How to use Fl_Multi_Label to make menu items with images and labels. // // Copyright 2017 Greg Ercolano. -// Copyright 1998-2017 by Bill Spitzak and others. +// Copyright 1998-2021 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -16,6 +16,7 @@ // // https://www.fltk.org/bugs.php // + #include #include #include @@ -90,13 +91,13 @@ static Fl_Pixmap L_redx_pixmap(L_redx_xpm); void Menu_CB(Fl_Widget *w, void* data) { const char *itemname = (const char*)data; // "New", "Open", etc if ( strcmp(itemname, "Quit") == 0 ) { // handle Quit - exit(0); + w->window()->hide(); } else { // just show a message for other items fl_message("'%s' would happen here", itemname); } } -// ADD AN IMAGE IN FRONT OF ITEM'S TEXT +// Add an image in front of item's text int AddItemToMenu(Fl_Menu_ *menu, // menu to add item to const char *labeltext, // label text int shortcut, // shortcut (e.g. FL_COMMAND+'a') @@ -137,7 +138,7 @@ int AddItemToMenu(Fl_Menu_ *menu, // menu to add item to // void CreateMenuItems(Fl_Menu_* menu) { - // Add items with LABLES AND IMAGES using Fl_Multi_Label.. + // Add items with LABELS AND IMAGES using Fl_Multi_Label.. AddItemToMenu(menu, "File/New", FL_COMMAND+'n', Menu_CB, (void*)"New", &L_document_pixmap); AddItemToMenu(menu, "File/Open", FL_COMMAND+'o', Menu_CB, (void*)"Open", &L_folder_pixmap, FL_MENU_DIVIDER); AddItemToMenu(menu, "File/Quit", FL_COMMAND+'q', Menu_CB, (void*)"Quit", &L_redx_pixmap);