changeset 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 2ae0ca4ee36b
children f6d15ae003b8
files scripts/ChangeLog scripts/plot/figure.m scripts/plot/module.mk scripts/plot/private/__add_default_menu__.m
diffstat 4 files changed, 119 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Dec 13 10:50:20 2010 -0800
+++ b/scripts/ChangeLog	Mon Dec 13 20:17:24 2010 +0100
@@ -1,3 +1,9 @@
+2010-12-13  Kai Habel  <kai.habel@gmx.de>
+
+	* (plot/private/__add_default_menu__.m): New function.
+	* (plot/figure.m): Call __add_default_menu__ function.
+	* plot/module.mk: Add new file to list.
+
 2010-12-13  Rik  <octave@nomad.inbox5.com>
 
 	* optimization/sqp.m: Change docstring to refer to x0 as the initial
--- a/scripts/plot/figure.m	Mon Dec 13 10:50:20 2010 -0800
+++ b/scripts/plot/figure.m	Mon Dec 13 20:17:24 2010 +0100
@@ -73,6 +73,9 @@
     print_usage ();
   endif
 
+  cf = get (0, "currentfigure");
+  __add_default_menu__ (cf);
+
   if (nargout > 0)
     h = f;
   endif
--- a/scripts/plot/module.mk	Mon Dec 13 10:50:20 2010 -0800
+++ b/scripts/plot/module.mk	Mon Dec 13 20:17:24 2010 +0100
@@ -8,6 +8,7 @@
 plot_PRIVATE_FCN_FILES = \
   plot/private/__actual_axis_position__.m \
   plot/private/__add_datasource__.m \
+  plot/private/__add_default_menu__.m \
   plot/private/__axes_limits__.m \
   plot/private/__axis_label__.m \
   plot/private/__bar__.m \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/private/__add_default_menu__.m	Mon Dec 13 20:17:24 2010 +0100
@@ -0,0 +1,109 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {Function File} {} __add_default_menu__ (fig)
+## Adds default menu to figure. All uimenu handles have
+## set their property "handlevisibility" to "off".
+## @end deftypefn
+
+## Author: Kai Habel
+
+function __add_default_menu__ (fig)
+
+  if (isfigure (fig))
+    obj = findall (fig, "label", "&File", "tag", "__default_menu__");
+    if (length (obj) == 0)
+      __f = uimenu (fig, "label", "&File", "handlevisibility", "off", "tag", "__default_menu__");
+        sa = uimenu (__f, "label", "Save &As", "handlevisibility", "off",
+                          "callback", @save_cb);
+        sv = uimenu (__f, "label", "&Save", "handlevisibility", "off",
+                          "callback", @save_cb);
+        cl = uimenu (__f, "label", "&Close", "handlevisibility", "off",
+                          "callback", "close(gcf)");
+
+      __e = uimenu (fig, "label", "&Edit", "handlevisibility", "off");
+        gr = uimenu (__e, "label", "&Grid", "handlevisibility", "off",
+                          "callback", @grid_cb);
+        as = uimenu (__e, "label", "Auto&scale", "handlevisibility", "off",
+                          "callback", @autoscale_cb);
+        gm = uimenu (__e, "label", "GUI &Mode", "handlevisibility", "off");
+          gm2 = uimenu (gm, "label", "Pan+Zoom", "handlevisibility", "off",
+                            "callback", @guimode_cb);
+          gm3 = uimenu (gm, "label", "Rotate+Zoom", "handlevisibility", "off",
+                            "callback", @guimode_cb);
+          gmn = uimenu (gm, "label", "None", "handlevisibility", "off",
+                            "callback", @guimode_cb);
+      __h = uimenu (fig, "label", "&Help", "handlevisibility", "off");
+        ab = uimenu (__h, "label", "A&bout", "handlevisibility", "off", "enable", "off");
+    endif
+  else
+    error ("expecting figure handle", "handlevisibility", "off");
+  endif
+
+endfunction
+
+function grid_cb (h, e)
+  grid;
+  drawnow; # should not be required
+endfunction
+
+function save_cb (h, e)
+  lbl = get (gcbo, "label");
+  if (strcmp (lbl, "&Save"))
+    fname = get (gcbo, "userdata");
+    if (isempty (fname))
+      __save_as__ (gcbo);
+    else
+      saveas (gcbo, fname);
+    endif
+  elseif (strcmp (lbl, "Save &As"))
+    __save_as__ (gcbo);
+  endif
+endfunction
+
+function __save_as__ (caller)
+
+  [filename, filedir] = uiputfile ({"*.pdf;*.ps;*.gif;*.png;*.jpg","Supported Graphic Formats"},
+                                  "Save Figure",
+                                  pwd);
+  if (filename != 0)
+    fname = strcat (filedir, filesep, filename);
+    obj = findall ("label", "&Save");
+    if (length (obj) > 0)
+      set (obj(1), "userdata", fname);
+    endif
+    saveas (caller, fname);
+  endif
+endfunction
+
+function autoscale_cb (h, e)
+  axis ("auto");
+  drawnow; #should not be required
+endfunction
+
+function guimode_cb (h, e)
+  lbl = get(h, "label");
+  if (strncmp(lbl, "Pan+Zoom", 8))
+    fltk_gui_mode("2D");
+  elseif (strncmp(lbl, "Rotate+Zoom", 11))
+    fltk_gui_mode("3D");
+  elseif (strncmp(lbl, "None", 4))
+    fltk_gui_mode("None");
+  endif
+endfunction