changeset 30999:fef2957c38ec

Deprecate uimenu properties "label" and "callback" (bug #62443) Replace "label" property with "text". Replace "callback" property with "menuselectedfcn". Both old properties are hidden, but continue to exist and work as before to support old code. * NEWS.8.md: Announce deprecation. * graphics.in.h (uimenu::BEGIN_PROPERTIES): Mark "callback" property with "hgs" for hidden, get, set routines. Mark "label" property with "hgs". * graphics.in.h (uimenu::get_callback, uimenu::set_callback): New functions which simply relay calls to "get_menuselectedfcn" and "set_menuselectedfcn". * Menu.cc (Menu::actionTriggered, Menu::actionHovered): Replace "callback" with "menuselectedfcn" in gh_callback_event calls. * __init_fltk__.cc (script_cb): Rename "execute_callback" to "execute_menuselectedfcn". * __init_fltk__.cc (update_menuselectedfcn): Rename function from "update_callback". Rename "get_callback" to "get_menuselectedfcn". * __init_fltk__.cc (add_to_uimenu): Rename "update_callback" to "update_menuselectedfcn". * __init_fltk__.cc (uimenu_update): Rename "ID_CALLBACK" to "ID_MENUSELECTEDFCN". * uimenu.m: Update documentation to use "menuselectedfcn" and "text". Update demos and BIST tests to use new property names. * __add_default_menu__.m: Update code to use "menuselectedfcn" and "text".
author Rik <rik@octave.org>
date Sat, 14 May 2022 19:06:56 -0700
parents 1bf26f913b9c
children d2c09591eb11
files etc/NEWS.8.md libgui/graphics/Menu.cc libinterp/corefcn/graphics.in.h libinterp/dldfcn/__init_fltk__.cc scripts/gui/uimenu.m scripts/plot/util/private/__add_default_menu__.m
diffstat 6 files changed, 133 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS.8.md	Sat May 14 18:03:35 2022 -0700
+++ b/etc/NEWS.8.md	Sat May 14 19:06:56 2022 -0700
@@ -65,6 +65,17 @@
   storage.  This setting was `false` by default for compatibility with
   Matlab.  Now you must manually convert to full storage when desired.
 
+
+- Properties
+
+  The following property names are discouraged, but there is no fixed
+  date for their removal.
+
+  Object           | Property    | Replacement
+  -----------------|-------------|------------
+  `uimenu`         | `label`     | `text`
+  `uimenu`         | `callback`  | `menuselectedfcn`
+
 The following functions were deprecated in Octave 6 and have been removed
 from Octave 8.
 
--- a/libgui/graphics/Menu.cc	Sat May 14 18:03:35 2022 -0700
+++ b/libgui/graphics/Menu.cc	Sat May 14 19:06:56 2022 -0700
@@ -294,13 +294,13 @@
 
     if (action->isCheckable ())
       action->setChecked (! action->isChecked ());
-    emit gh_callback_event (m_handle, "callback");
+    emit gh_callback_event (m_handle, "menuselectedfcn");
   }
 
   void
   Menu::actionHovered (void)
   {
-    emit gh_callback_event (m_handle, "callback");
+    emit gh_callback_event (m_handle, "menuselectedfcn");
   }
 
   void
--- a/libinterp/corefcn/graphics.in.h	Sat May 14 18:03:35 2022 -0700
+++ b/libinterp/corefcn/graphics.in.h	Sat May 14 19:06:56 2022 -0700
@@ -5793,11 +5793,16 @@
 
     BEGIN_PROPERTIES (uimenu)
       string_property accelerator , ""
-      callback_property callback , Matrix ()
+      // Deprecated in R2017b (replaced by "MenuSelectedFcn")
+      callback_property callback hgs , Matrix ()
       bool_property checked , "off"
       bool_property enable , "on"
       color_property foregroundcolor , color_values (0, 0, 0)
-      string_property label gs , ""
+      // Deprecated in R2017b (replaced by "Text")
+      string_property label hgs , ""
+      callback_property menuselectedfcn , Matrix ()
+      // Deprecated in R2017b, but replacement of re-ordering "children"
+      // property of parent does not work yet in Octave.
       double_property position , 0
       bool_property separator , "off"
       string_property text , ""
@@ -5807,7 +5812,7 @@
       any_property __object__ h , Matrix ()
     END_PROPERTIES
 
-    // Redirect calls from "Label" to "Text".
+    // Make "Label" an alias for "Text".
     std::string get_label (void) const
     {
       return get_text ();
@@ -5818,6 +5823,17 @@
       set_text (val);
     }
 
+    // Make "Callback" an alias for "MenuSelectedFcn".
+    octave_value get_callback (void) const
+    {
+      return get_menuselectedfcn ();
+    }
+
+    void set_callback (const octave_value& val)
+    {
+      set_menuselectedfcn (val);
+    }
+
   protected:
     void init (void)
     {
--- a/libinterp/dldfcn/__init_fltk__.cc	Sat May 14 18:03:35 2022 -0700
+++ b/libinterp/dldfcn/__init_fltk__.cc	Sat May 14 19:06:56 2022 -0700
@@ -297,7 +297,7 @@
 
 static void script_cb (Fl_Widget *, void *data)
 {
-  static_cast<uimenu::properties *> (data)->execute_callback ();
+  static_cast<uimenu::properties *> (data)->execute_menuselectedfcn ();
 }
 
 class fltk_uimenu
@@ -463,7 +463,7 @@
       }
   }
 
-  void update_callback (uimenu::properties& uimenup)
+  void update_menuselectedfcn (uimenu::properties& uimenup)
   {
     std::string fltk_label = uimenup.get___fltk_label__ ();
     if (! fltk_label.empty ())
@@ -472,7 +472,7 @@
           = const_cast<Fl_Menu_Item *> (m_menubar->find_item (fltk_label.c_str ()));
         if (item)
           {
-            if (! uimenup.get_callback ().isempty ())
+            if (! uimenup.get_menuselectedfcn ().isempty ())
               item->callback (static_cast<Fl_Callback *> (script_cb),
                               static_cast<void *> (&uimenup));
             else
@@ -635,7 +635,7 @@
 
     add_entry (uimenup);
     update_foregroundcolor (uimenup);
-    update_callback (uimenup);
+    update_menuselectedfcn (uimenup);
     update_accelerator (uimenup);
     update_enable (uimenup);
     update_visible (uimenup);
@@ -962,8 +962,8 @@
             m_uimenu->update_accelerator (uimenup);
             break;
 
-          case uimenu::properties::ID_CALLBACK:
-            m_uimenu->update_callback (uimenup);
+          case uimenu::properties::ID_MENUSELECTEDFCN:
+            m_uimenu->update_menuselectedfcn (uimenup);
             break;
 
           case uimenu::properties::ID_CHECKED:
--- a/scripts/gui/uimenu.m	Sat May 14 18:03:35 2022 -0700
+++ b/scripts/gui/uimenu.m	Sat May 14 19:06:56 2022 -0700
@@ -35,37 +35,39 @@
 ##
 ## @table @asis
 ## @item @qcode{"accelerator"}
-## A string containing the key combination together with CTRL to execute this
+## A string containing the key, together with CTRL, to execute this
 ## menu entry (e.g., @qcode{"x"} for CTRL+x).
 ##
-## @item @qcode{"callback"}
-## Is the function called when this menu entry is executed.  It can be either a
-## function string (e.g., @qcode{"myfcn"}), a function handle (e.g., @@myfcn)
-## or a cell array containing the function handle and arguments for the
-## callback function (e.g., @{@@myfcn, arg1, arg2@}).
-##
 ## @item @qcode{"checked"}
 ## Can be set @qcode{"on"} or @qcode{"off"}.  Sets a mark at this menu entry.
 ##
 ## @item @qcode{"enable"}
-## Can be set @qcode{"on"} or @qcode{"off"}.  If disabled the menu entry
-## cannot be selected and it is grayed out.
+## Can be set @qcode{"on"} or @qcode{"off"}.  If disabled then the menu entry
+## cannot be selected and is grayed out.
 ##
 ## @item @qcode{"foregroundcolor"}
-## A color value setting the text color for this menu entry.
+## A color value for the text of the menu entry.
 ##
-## @item @qcode{"label"}
-## A string containing the label for this menu entry.  A @qcode{"&"}-symbol
-## can be used to mark the @qcode{"accelerator"} character (e.g.,
-## @nospell{@qcode{"E&xit"}})
+## @item @qcode{"menuselectedfcn"}
+## The function called when this menu entry is executed.  It can be either a
+## function string (e.g., @qcode{"myfcn"}), a function handle (e.g., @@myfcn)
+## or a cell array containing the function handle and arguments for the
+## callback function (e.g., @{@@myfcn, arg1, arg2@}).
 ##
 ## @item @qcode{"position"}
-## An scalar value containing the relative menu position.  The entry with the
-## lowest value is at the first position starting from left or top.
+## A scalar value containing the relative menu position.  The first position
+## has value 1 and will be either the left or top depending on the orientation
+## of the uimenu.
 ##
 ## @item @qcode{"separator"}
-## Can be set @qcode{"on"} or @qcode{"off"}.  If enabled it draws a separator
-## line above the current position.  It is ignored for top level entries.
+## Can be set @qcode{"on"} or @qcode{"off"}.  If enabled, a separator
+## line is drawn above the current position.  This property is ignored for
+## top-level entries.
+##
+## @item @qcode{"text"}
+## A string containing the text for this menu entry.  A @qcode{"&"}-symbol
+## can be used to mark the @qcode{"accelerator"} character (e.g.,
+## @nospell{@qcode{"E&xit"}}).
 ##
 ## @end table
 ##
@@ -75,12 +77,12 @@
 ##
 ## @example
 ## @group
-## f = uimenu ("label", "&File", "accelerator", "f");
-## e = uimenu ("label", "&Edit", "accelerator", "e");
-## uimenu (f, "label", "Close", "accelerator", "q", ...
-##            "callback", "close (gcf)");
-## uimenu (e, "label", "Toggle &Grid", "accelerator", "g", ...
-##            "callback", "grid (gca)");
+## f = uimenu ("text", "&File", "accelerator", "f");
+## e = uimenu ("text", "&Edit", "accelerator", "e");
+## uimenu (f, "text", "Close", "accelerator", "q", ...
+##            "menuselectedfcn", "close (gcf)");
+## uimenu (e, "text", "Toggle &Grid", "accelerator", "g", ...
+##            "menuselectedfcn", "grid (gca)");
 ## @end group
 ## @end example
 ## @seealso{figure}
@@ -91,10 +93,10 @@
   [h, args] = __uiobject_split_args__ ("uimenu", varargin,
                                        {"figure", "uicontextmenu", "uimenu"});
 
-  tmp = __go_uimenu__ (h, args{:});
+  htmp = __go_uimenu__ (h, args{:});
 
   if (nargout > 0)
-    hui = tmp;
+    hui = htmp;
   endif
 
 endfunction
@@ -105,18 +107,20 @@
 %! surfl (peaks);
 %! colormap (copper (64));
 %! shading ('interp');
-%! f = uimenu ('label', '&File', 'accelerator', 'f');
-%! e = uimenu ('label', '&Edit', 'accelerator', 'e');
-%! uimenu (f, 'label', 'Close', 'accelerator', 'q', 'callback', 'close (gcf)');
-%! uimenu (e, 'label', 'Toggle &Grid', 'accelerator', 'g', 'callback', 'grid (gca)');
+%! f = uimenu ('text', '&File', 'accelerator', 'f');
+%! e = uimenu ('text', '&Edit', 'accelerator', 'e');
+%! uimenu (f, 'text', 'Close', 'accelerator', 'q', ...
+%!            'menuselectedfcn', 'close (gcf)');
+%! uimenu (e, 'text', 'Toggle &Grid', 'accelerator', 'g', ...
+%!            'menuselectedfcn', 'grid (gca)');
 
 %!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", available_graphics_toolkits ()))
 %! toolkit = graphics_toolkit ("qt");
 %! hf = figure ("visible", "off");
 %! unwind_protect
-%!   ui = uimenu ("label", "mylabel");
+%!   ui = uimenu ("text", "mytext");
 %!   assert (findobj (hf, "type", "uimenu"), ui);
-%!   assert (get (ui, "label"), "mylabel");
+%!   assert (get (ui, "text"), "mytext");
 %!   assert (get (ui, "checked"), "off");
 %!   assert (get (ui, "separator"), "off");
 %!   assert (get (ui, "enable"), "on");
@@ -131,9 +135,9 @@
 %! toolkit = graphics_toolkit ("qt");
 %! hf = figure ("visible", "off");
 %! unwind_protect
-%!   uif = findall (hf, "label", "&file");
+%!   uif = findall (hf, "text", "&file");
 %!   assert (ishghandle (uif));
-%!   uie = findall (hf, "label", "&edit");
+%!   uie = findall (hf, "text", "&edit");
 %!   assert (ishghandle (uie));
 %! unwind_protect_cleanup
 %!   close (hf);
@@ -144,8 +148,8 @@
 %! toolkit = graphics_toolkit ("qt");
 %! hf = figure ("visible", "off");
 %! unwind_protect
-%!   uie = findall (hf, "label", "&edit");
-%!   myui = uimenu (uie, "label", "mylabel");
+%!   uie = findall (hf, "text", "&edit");
+%!   myui = uimenu (uie, "text", "mytext");
 %!   assert (ancestor (myui, "uimenu", "toplevel"), uie);
 %! unwind_protect_cleanup
 %!   close (hf);
--- a/scripts/plot/util/private/__add_default_menu__.m	Sat May 14 18:03:35 2022 -0700
+++ b/scripts/plot/util/private/__add_default_menu__.m	Sat May 14 19:06:56 2022 -0700
@@ -49,104 +49,108 @@
     ## File menu
     hui = uimenu (hf, "label", "&File", "tag", "__default_menu__File", ...
                       "handlevisibility", "off");
-    uimenu (hui, "label", "&Open...", "callback", @open_cb, ...
-            "accelerator", "o");
-    uimenu (hui, "label", "&Save", "callback", {@save_cb, "save"}, ...
-            "accelerator", "s");
-    uimenu (hui, "label", "Save &As...", "callback", {@save_cb, "saveas"}, ...
-            "accelerator", "S");
-    uimenu (hui, "label", "&Close", "callback", @close_cb, ...
-            "accelerator", "w", "separator", "on");
+    uimenu (hui, "label", "&Open...", "menuselectedfcn", @open_cb, ...
+                 "accelerator", "o");
+    uimenu (hui, "label", "&Save", "menuselectedfcn", {@save_cb, "save"}, ...
+                 "accelerator", "s");
+    uimenu (hui, "label", "Save &As...", ...
+                 "menuselectedfcn", {@save_cb, "saveas"}, ...
+                 "accelerator", "S");
+    uimenu (hui, "label", "&Close", "menuselectedfcn", @close_cb, ...
+                 "accelerator", "w", "separator", "on");
     hmenu(1) = hui;
 
     ## Edit menu
     hui = uimenu (hf, "label", "&Edit", "handlevisibility", "off", ...
-                  "tag", "__default_menu__Edit");
-    uimenu (hui, "label", "&New Figure", "callback", "figure ();", ...
-            "accelerator", "n");
+                      "tag", "__default_menu__Edit");
+    uimenu (hui, "label", "&New Figure", "menuselectedfcn", "figure ();", ...
+                 "accelerator", "n");
     uimenu (hui, "label", "&Duplicate Figure",
-            "callback", "copyobj (gcbf (), groot ());", ...
-            "accelerator", "d");
+                 "menuselectedfcn", "copyobj (gcbf (), groot ());", ...
+                 "accelerator", "d");
     uimenu (hui, "label", "Clea&r Figure",
-            "callback", "clf (gcbf ());");
+                 "menuselectedfcn", "clf (gcbf ());");
     uimenu (hui, "label", "Reset Figure",
-            "callback", "reset (gcbf ());");
+                 "menuselectedfcn", "reset (gcbf ());");
     uimenu (hui, "label", "Copy Figure to Clipboard", ...
-            "callback", @clipboard_cb, "separator", "on", ...
-            "accelerator", "c");
+                 "menuselectedfcn", @clipboard_cb, "separator", "on", ...
+                 "accelerator", "c");
     hmenu(2) = hui;
 
     ## Tools menu
     hui = uimenu (hf, "label", "&Tools", "handlevisibility", "off", ...
-                  "tag", "__default_menu__Tools");
+                      "tag", "__default_menu__Tools");
     uimenu (hui, "label", "Toggle &grid on all axes", "tag", "toggle", ...
-            "callback", @grid_cb);
+                 "menuselectedfcn", @grid_cb);
     uimenu (hui, "label", "Show grid on all axes", "tag", "on", ...
-            "callback", @grid_cb);
+                 "menuselectedfcn", @grid_cb);
     uimenu (hui, "label", "Hide grid on all axes", "tag", "off", ...
-            "callback", @grid_cb);
-    uimenu (hui, "label", "Auto&scale all axes", "callback", @autoscale_cb);
+                 "menuselectedfcn", @grid_cb);
+    uimenu (hui, "label", "Auto&scale all axes",
+                 "menuselectedfcn", @autoscale_cb);
 
     hui2 = uimenu (hui, "label", "GUI &Mode (on all axes)");
     uimenu (hui2, "label", "Pan x and y", "tag", "pan_on", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Pan x only", "tag", "pan_xon", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Pan y only", "tag", "pan_yon", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Disable pan and rotate", "tag", ...
-            "no_pan_rotate", "callback", @guimode_cb);
+                  "no_pan_rotate", "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Rotate on", "tag", "rotate3d", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Enable mousezoom", "tag", "zoom_on", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     uimenu (hui2, "label", "Disable mousezoom", "tag", "zoom_off", ...
-            "callback", @guimode_cb);
+                  "menuselectedfcn", @guimode_cb);
     hmenu(3) = hui;
 
     ## Default toolbar
     init_mouse_tools (hf);
     htb = uitoolbar (hf, "tag", "__default_toolbar__", ...
-                     "handlevisibility", "off", "visible", "off");
+                         "handlevisibility", "off", "visible", "off");
 
     ht(1) = uitoggletool (htb, "tooltipstring", "Pan", ...
-                          "tag", "__default_button_pan__", ...
-                          "__named_icon__", "figure-pan");
+                               "tag", "__default_button_pan__", ...
+                               "__named_icon__", "figure-pan");
     ht(2) = uitoggletool (htb, "tooltipstring", "Rotate", ...
-                          "tag", "__default_button_rotate__", ...
-                          "__named_icon__", "figure-rotate");
+                               "tag", "__default_button_rotate__", ...
+                               "__named_icon__", "figure-rotate");
 
     ht(3) = uitoggletool (htb, "tooltipstring", "Zoom In", ...
-                          "tag", "__default_button_zoomin__", ...
-                          "__named_icon__", "figure-zoom-in", ...
-                          "separator", "on");
+                               "tag", "__default_button_zoomin__", ...
+                               "__named_icon__", "figure-zoom-in", ...
+                               "separator", "on");
     ht(4) = uitoggletool (htb, "tooltipstring", "Zoom Out", ...
-                          "tag", "__default_button_zoomout__", ...
-                          "__named_icon__", "figure-zoom-out");
+                               "tag", "__default_button_zoomout__", ...
+                               "__named_icon__", "figure-zoom-out");
     uipushtool (htb, "tooltipstring", "Automatic limits for current axes", ...
-                "clickedcallback", @auto_cb, ...
-                "__named_icon__", "figure-zoom-original");
+                     "clickedcallback", @auto_cb, ...
+                     "__named_icon__", "figure-zoom-original");
 
     ht(5) = uitoggletool (htb, "tooltipstring", "Insert Text", ...
-                          "tag", "__default_button_text__", ...
-                          "separator", "on", "__named_icon__", "figure-text");
+                               "tag", "__default_button_text__", ...
+                               "separator", "on", ...
+                               "__named_icon__", "figure-text");
 
     uipushtool (htb, "tooltipstring", "Toggle current axes visibility", ...
-                "clickedcallback", @axes_cb, "separator", "on", ...
-                "__named_icon__", "figure-axes");
+                     "clickedcallback", @axes_cb, "separator", "on", ...
+                     "__named_icon__", "figure-axes");
     uipushtool (htb, "tooltipstring", "Toggle current axes grid visibility", ...
-                "clickedcallback", @grid_cb,  "__named_icon__", "figure-grid");
+                     "clickedcallback", @grid_cb, ...
+                     "__named_icon__", "figure-grid");
 
     set (ht(1), "oncallback", {@mouse_tools_cb, ht, "pan"}, ...
-         "offcallback", {@mouse_tools_cb, ht, "pan"});
+                "offcallback", {@mouse_tools_cb, ht, "pan"});
     set (ht(2), "oncallback", {@mouse_tools_cb, ht, "rotate"}, ...
-         "offcallback", {@mouse_tools_cb, ht, "rotate"});
+                "offcallback", {@mouse_tools_cb, ht, "rotate"});
     set (ht(3), "oncallback", {@mouse_tools_cb, ht, "zoomin"}, ...
-         "offcallback", {@mouse_tools_cb, ht, "zoomin"});
+                "offcallback", {@mouse_tools_cb, ht, "zoomin"});
     set (ht(4), "oncallback", {@mouse_tools_cb, ht, "zoomout"}, ...
-         "offcallback", {@mouse_tools_cb, ht, "zoomout"});
+                "offcallback", {@mouse_tools_cb, ht, "zoomout"});
     set (ht(5), "oncallback", {@mouse_tools_cb, ht, "text"}, ...
-         "offcallback", {@mouse_tools_cb, ht, "text"});
+                "offcallback", {@mouse_tools_cb, ht, "text"});
   endif
 
   if (! exist ("ht", "var"))