]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/uimenu.m
update packages
[CreaPhase.git] / octave_packages / m / plot / uimenu.m
1 ## Copyright (C) 2010-2012 Kai Habel
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
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.
25 ##
26 ## uimenu objects have the following specific properties:
27 ##
28 ## @table @asis
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).
32 ##
33 ## @item "callback"
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@}).
38 ##
39 ## @item "checked"
40 ## Can be set "on" or "off".  Sets a mark at this menu entry.
41 ##
42 ## @item "enable"
43 ## Can be set "on" or "off".  If disabled the menu entry cannot be selected
44 ## and it is grayed out.
45 ##
46 ## @item "foregroundcolor"
47 ## A color value setting the text color for this menu entry.
48 ##
49 ## @item "label"
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"})
52 ##
53 ## @item "position"
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.
56 ##
57 ## @item "separator"
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.
60 ##
61 ## @end table
62 ##
63 ## Examples:
64 ##
65 ## @example
66 ## @group
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)");
73 ## @end group
74 ## @end example
75 ## @seealso{figure}
76 ## @end deftypefn
77
78 ## Author: Kai Habel
79
80 function hui = uimenu (varargin)
81
82   [h, args] = __uiobject_split_args__ ("uimenu", varargin, {"figure", "uicontextmenu", "uimenu"});
83
84   tmp = __go_uimenu__ (h, args{:});
85
86   if (nargout > 0)
87     hui = tmp;
88   endif
89
90 endfunction
91
92
93 %!demo
94 %! clf
95 %! surfl (peaks);
96 %! colormap (copper);
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)");
102
103 %!testif HAVE_FLTK
104 %! toolkit = graphics_toolkit ();
105 %! graphics_toolkit ("fltk");
106 %! hf = figure ("visible", "off");
107 %! unwind_protect
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
116 %!   close (hf);
117 %!   graphics_toolkit (toolkit);
118 %! end_unwind_protect
119
120 %% check for top level menus file, edit, and help
121 %!testif HAVE_FLTK
122 %! toolkit = graphics_toolkit ();
123 %! graphics_toolkit ("fltk");
124 %! hf = figure ("visible", "off");
125 %! unwind_protect
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
133 %!   close (hf);
134 %!   graphics_toolkit (toolkit);
135 %! end_unwind_protect
136
137 %!testif HAVE_FLTK
138 %! toolkit = graphics_toolkit ();
139 %! graphics_toolkit ("fltk");
140 %! hf = figure ("visible", "off");
141 %! unwind_protect
142 %!   uie = findall (hf, "label", "&edit");
143 %!   myui = uimenu (uie, "label", "mylabel");
144 %!   assert (ancestor (myui, "uimenu", "toplevel"), uie)
145 %! unwind_protect_cleanup
146 %!   close (hf);
147 %!   graphics_toolkit (toolkit);
148 %! end_unwind_protect
149