comparison scripts/plot/private/__add_default_menu__.m @ 11349:4a3258b1448f

Add default menu for fltk backend figures
author Kai Habel <kai.habel@gmx.de>
date Mon, 13 Dec 2010 20:17:24 +0100
parents
children 1740012184f9
comparison
equal deleted inserted replaced
11348:2ae0ca4ee36b 11349:4a3258b1448f
1 ## Copyright (C) 2010 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} {} __add_default_menu__ (fig)
21 ## Adds default menu to figure. All uimenu handles have
22 ## set their property "handlevisibility" to "off".
23 ## @end deftypefn
24
25 ## Author: Kai Habel
26
27 function __add_default_menu__ (fig)
28
29 if (isfigure (fig))
30 obj = findall (fig, "label", "&File", "tag", "__default_menu__");
31 if (length (obj) == 0)
32 __f = uimenu (fig, "label", "&File", "handlevisibility", "off", "tag", "__default_menu__");
33 sa = uimenu (__f, "label", "Save &As", "handlevisibility", "off",
34 "callback", @save_cb);
35 sv = uimenu (__f, "label", "&Save", "handlevisibility", "off",
36 "callback", @save_cb);
37 cl = uimenu (__f, "label", "&Close", "handlevisibility", "off",
38 "callback", "close(gcf)");
39
40 __e = uimenu (fig, "label", "&Edit", "handlevisibility", "off");
41 gr = uimenu (__e, "label", "&Grid", "handlevisibility", "off",
42 "callback", @grid_cb);
43 as = uimenu (__e, "label", "Auto&scale", "handlevisibility", "off",
44 "callback", @autoscale_cb);
45 gm = uimenu (__e, "label", "GUI &Mode", "handlevisibility", "off");
46 gm2 = uimenu (gm, "label", "Pan+Zoom", "handlevisibility", "off",
47 "callback", @guimode_cb);
48 gm3 = uimenu (gm, "label", "Rotate+Zoom", "handlevisibility", "off",
49 "callback", @guimode_cb);
50 gmn = uimenu (gm, "label", "None", "handlevisibility", "off",
51 "callback", @guimode_cb);
52 __h = uimenu (fig, "label", "&Help", "handlevisibility", "off");
53 ab = uimenu (__h, "label", "A&bout", "handlevisibility", "off", "enable", "off");
54 endif
55 else
56 error ("expecting figure handle", "handlevisibility", "off");
57 endif
58
59 endfunction
60
61 function grid_cb (h, e)
62 grid;
63 drawnow; # should not be required
64 endfunction
65
66 function save_cb (h, e)
67 lbl = get (gcbo, "label");
68 if (strcmp (lbl, "&Save"))
69 fname = get (gcbo, "userdata");
70 if (isempty (fname))
71 __save_as__ (gcbo);
72 else
73 saveas (gcbo, fname);
74 endif
75 elseif (strcmp (lbl, "Save &As"))
76 __save_as__ (gcbo);
77 endif
78 endfunction
79
80 function __save_as__ (caller)
81
82 [filename, filedir] = uiputfile ({"*.pdf;*.ps;*.gif;*.png;*.jpg","Supported Graphic Formats"},
83 "Save Figure",
84 pwd);
85 if (filename != 0)
86 fname = strcat (filedir, filesep, filename);
87 obj = findall ("label", "&Save");
88 if (length (obj) > 0)
89 set (obj(1), "userdata", fname);
90 endif
91 saveas (caller, fname);
92 endif
93 endfunction
94
95 function autoscale_cb (h, e)
96 axis ("auto");
97 drawnow; #should not be required
98 endfunction
99
100 function guimode_cb (h, e)
101 lbl = get(h, "label");
102 if (strncmp(lbl, "Pan+Zoom", 8))
103 fltk_gui_mode("2D");
104 elseif (strncmp(lbl, "Rotate+Zoom", 11))
105 fltk_gui_mode("3D");
106 elseif (strncmp(lbl, "None", 4))
107 fltk_gui_mode("None");
108 endif
109 endfunction