# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1573633539 -3600
#      Wed Nov 13 09:25:39 2019 +0100
# Node ID 96b790c9336434bc9fce4d5fd56716f94d28bae1
# Parent  748aea34aecdaf5eef25283daab3ca2a13b01e96
Hide __appdata__ internal property (bug #57211, bug #57212)

* graphics.in.h (base_graphics_object::__appdata__): New hidden any_property
  that defaults to an empty struct.
  (base_graphics_object::applicationdata): Alias for "__appdata__". 

* setappdata.m, getappadata.m, rmappdata.m, isappdata.m: Assume the
  "__appdata__" property exists.

diff -r 748aea34aecd -r 96b790c93364 libinterp/corefcn/graphics.in.h
--- a/libinterp/corefcn/graphics.in.h	Tue Nov 12 22:36:17 2019 +0100
+++ b/libinterp/corefcn/graphics.in.h	Wed Nov 13 09:25:39 2019 +0100
@@ -2295,6 +2295,10 @@
                              bool traverse,
                              std::list<graphics_object> &children_list) const;
 
+  octave_value get_applicationdata (void) const { return get___appdata__ (); }
+
+  void set_applicationdata (const octave_value& val) { set___appdata__ (val); }
+
   void set_modified (const octave_value& val) { set___modified__ (val); }
 
   void set___modified__ (const octave_value& val) { __modified__ = val; }
@@ -2385,6 +2389,8 @@
     bool_property visible u , "on"
 
     // Octave-specific properties
+    any_property __appdata__ h , octave_scalar_map ()
+    any_property applicationdata ghs , Matrix ()
     bool_property __modified__ hs , "on"
     graphics_handle __myhandle__ fhrs , mh
   END_PROPERTIES
diff -r 748aea34aecd -r 96b790c93364 scripts/gui/getappdata.m
--- a/scripts/gui/getappdata.m	Tue Nov 12 22:36:17 2019 +0100
+++ b/scripts/gui/getappdata.m	Wed Nov 13 09:25:39 2019 +0100
@@ -62,11 +62,7 @@
     if (numel (h) != 1)
       error ("getappdata: Only one handle H may be used when fetching appdata");
     endif
-    try
-      value = get (h, "__appdata__");
-    catch
-      value = struct ();
-    end_try_catch
+    value = get (h, "__appdata__");
   endif
 
 endfunction
diff -r 748aea34aecd -r 96b790c93364 scripts/gui/isappdata.m
--- a/scripts/gui/isappdata.m	Tue Nov 12 22:36:17 2019 +0100
+++ b/scripts/gui/isappdata.m	Wed Nov 13 09:25:39 2019 +0100
@@ -42,12 +42,10 @@
 
   valid = false (size (h));
   for i = 1:numel (h)
-    try
-      appdata = get (h(i), "__appdata__");
-      if (isfield (appdata, name))
-        valid(i) = true;
-      endif
-    end_try_catch
+    appdata = get (h(i), "__appdata__");
+    if (isfield (appdata, name))
+      valid(i) = true;
+    endif
   endfor
 
 endfunction
diff -r 748aea34aecd -r 96b790c93364 scripts/gui/rmappdata.m
--- a/scripts/gui/rmappdata.m	Tue Nov 12 22:36:17 2019 +0100
+++ b/scripts/gui/rmappdata.m	Wed Nov 13 09:25:39 2019 +0100
@@ -45,17 +45,15 @@
   endif
 
   for hg = h
-    if (isprop (hg, "__appdata__"))
-      appdata = get (hg, "__appdata__");
-      vld = isfield (appdata, varargin);
-      if (! all (vld))
-        ## FIXME: Should we bother to error out?  Or just silently continue?
-        missing = varargin{find (! vld, 1)};
-        error ("rmappdata: appdata '%s' is not present", missing);
-      endif
-      appdata = rmfield (appdata, varargin);
-      set (hg, "__appdata__", appdata);
+    appdata = get (hg, "__appdata__");
+    vld = isfield (appdata, varargin);
+    if (! all (vld))
+      ## FIXME: Should we bother to error out?  Or just silently continue?
+      missing = varargin{find (! vld, 1)};
+      error ("rmappdata: appdata '%s' is not present", missing);
     endif
+    appdata = rmfield (appdata, varargin);
+    set (hg, "__appdata__", appdata);
   endfor
 
 endfunction
diff -r 748aea34aecd -r 96b790c93364 scripts/gui/setappdata.m
--- a/scripts/gui/setappdata.m	Tue Nov 12 22:36:17 2019 +0100
+++ b/scripts/gui/setappdata.m	Wed Nov 13 09:25:39 2019 +0100
@@ -73,12 +73,7 @@
   endif
 
   for hg = h
-    try
-      appdata = get (hg, "__appdata__");
-    catch
-      appdata = struct ();
-      addproperty ("__appdata__", hg, "any", appdata);
-    end_try_catch
+    appdata = get (hg, "__appdata__");
 
     ## Slow, but not likely to be that many elements in loop
     for narg = 1:2:numel (varargin)
