1 ## Copyright (C) 2010-2012 Kai Habel
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} uimenu (@var{property}, @var{value}, @dots{})
21 ## @deftypefnx {Function File} {} uimenu (@var{h}, @var{property}, @var{value}, @dots{})
22 ## Create a uimenu object and return a handle to it. If @var{h} is ommited
23 ## then a top-level menu for the current figure is created. If @var{h}
24 ## is given then a submenu relative to @var{h} is created.
26 ## uimenu objects have the following specific properties:
29 ## @item "accelerator"
30 ## A string containing the key combination together with CTRL to execute this
31 ## menu entry (e.g., "x" for CTRL+x).
34 ## Is the function called when this menu entry is executed. It can be either a
35 ## function string (e.g., "myfun"), a function handle (e.g., @@myfun) or a cell
36 ## array containing the function handle and arguments for the callback
37 ## function (e.g., @{@@myfun, arg1, arg2@}).
40 ## Can be set "on" or "off". Sets a mark at this menu entry.
43 ## Can be set "on" or "off". If disabled the menu entry cannot be selected
44 ## and it is grayed out.
46 ## @item "foregroundcolor"
47 ## A color value setting the text color for this menu entry.
50 ## A string containing the label for this menu entry. A "&"-symbol can be
51 ## used to mark the "accelerator" character (e.g., @nospell{"E&xit"})
54 ## An scalar value containing the relative menu position. The entry with the
55 ## lowest value is at the first position starting from left or top.
58 ## Can be set "on" or "off". If enabled it draws a separator line above the
59 ## current position. It is ignored for top level entries.
67 ## f = uimenu ("label", "&File", "accelerator", "f");
68 ## e = uimenu ("label", "&Edit", "accelerator", "e");
69 ## uimenu (f, "label", "Close", "accelerator", "q", ...
70 ## "callback", "close (gcf)");
71 ## uimenu (e, "label", "Toggle &Grid", "accelerator", "g", ...
72 ## "callback", "grid (gca)");
80 function hui = uimenu (varargin)
82 [h, args] = __uiobject_split_args__ ("uimenu", varargin, {"figure", "uicontextmenu", "uimenu"});
84 tmp = __go_uimenu__ (h, args{:});
97 %! shading ("interp");
98 %! f = uimenu ("label", "&File", "accelerator", "f");
99 %! e = uimenu ("label", "&Edit", "accelerator", "e");
100 %! uimenu (f, "label", "Close", "accelerator", "q", "callback", "close (gcf)");
101 %! uimenu (e, "label", "Toggle &Grid", "accelerator", "g", "callback", "grid (gca)");
104 %! toolkit = graphics_toolkit ();
105 %! graphics_toolkit ("fltk");
106 %! hf = figure ("visible", "off");
108 %! ui = uimenu ("label", "mylabel");
109 %! assert (findobj (hf, "type", "uimenu"), ui);
110 %! assert (get (ui, "label"), "mylabel");
111 %! assert (get (ui, "checked"), "off");
112 %! assert (get (ui, "separator"), "off");
113 %! assert (get (ui, "enable"), "on");
114 %! assert (get (ui, "position"), 9);
115 %! unwind_protect_cleanup
117 %! graphics_toolkit (toolkit);
118 %! end_unwind_protect
120 %% check for top level menus file, edit, and help
122 %! toolkit = graphics_toolkit ();
123 %! graphics_toolkit ("fltk");
124 %! hf = figure ("visible", "off");
126 %! uif = findall (hf, "label", "&file");
127 %! assert (ishghandle (uif))
128 %! uie = findall (hf, "label", "&edit");
129 %! assert (ishghandle (uie))
130 %! uih = findall (hf, "label", "&help");
131 %! assert (ishghandle (uih))
132 %! unwind_protect_cleanup
134 %! graphics_toolkit (toolkit);
135 %! end_unwind_protect
138 %! toolkit = graphics_toolkit ();
139 %! graphics_toolkit ("fltk");
140 %! hf = figure ("visible", "off");
142 %! uie = findall (hf, "label", "&edit");
143 %! myui = uimenu (uie, "label", "mylabel");
144 %! assert (ancestor (myui, "uimenu", "toplevel"), uie)
145 %! unwind_protect_cleanup
147 %! graphics_toolkit (toolkit);
148 %! end_unwind_protect