# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1544281623 -3600
#      Sat Dec 08 16:07:03 2018 +0100
# Node ID 4107ff474dcc7249b74543acae90cbcc6aa61b51
# Parent  55564fdb3e4d3b9ced44143223d4847ec06f1fa4
Implement "SizeChangedFcn" for uipanel and uibuttongroup (bug #55085).

* graphics.in.h (uibuttongroup::properties, uipanel::properties): Add set method
  to position property.

* graphics.cc (uibuttongroup::properties::set_position,
  uipanel::properties::set_position): Add new functions that call the resizefcn
  handle and the sizechangedfcn handle when the size changes.

diff -r 55564fdb3e4d -r 4107ff474dcc libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc	Sat Dec 08 12:49:39 2018 +0100
+++ b/libinterp/corefcn/graphics.cc	Sat Dec 08 16:07:03 2018 +0100
@@ -10633,6 +10633,37 @@
 }
 
 void
+uibuttongroup::properties::set_position (const octave_value& v)
+{
+  Matrix old_bb, new_bb;
+  bool modified = false;
+
+  old_bb = get_boundingbox (true);
+  modified = position.set (v, false);
+  new_bb = get_boundingbox (true);
+
+  if (old_bb != new_bb)
+    {
+      if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3))
+        {
+          if (! get_resizefcn ().isempty ())
+            gh_manager::post_callback (__myhandle__, "resizefcn");
+
+          if (! get_sizechangedfcn ().isempty ())
+            gh_manager::post_callback (__myhandle__, "sizechangedfcn");
+
+          update_boundingbox ();
+        }
+    }
+
+  if (modified)
+    {
+      position.run_listeners (POSTSET);
+      mark_modified ();
+    }
+}
+
+void
 uibuttongroup::properties::set_units (const octave_value& val)
 {
   caseless_str old_units = get_units ();
@@ -10804,6 +10835,38 @@
 }
 
 void
+uipanel::properties::set_position (const octave_value& v)
+{
+  Matrix old_bb, new_bb;
+  bool modified = false;
+
+  old_bb = get_boundingbox (true);
+  modified = position.set (v, false);
+  new_bb = get_boundingbox (true);
+
+  if (old_bb != new_bb)
+    {
+      if (old_bb(2) != new_bb(2) || old_bb(3) != new_bb(3))
+        {
+          if (! get_resizefcn ().isempty ())
+            gh_manager::post_callback (__myhandle__, "resizefcn");
+
+          if (! get_sizechangedfcn ().isempty ())
+            gh_manager::post_callback (__myhandle__, "sizechangedfcn");
+
+          update_boundingbox ();
+        }
+    }
+
+  if (modified)
+    {
+      position.run_listeners (POSTSET);
+      mark_modified ();
+    }
+}
+
+
+void
 uipanel::properties::set_units (const octave_value& val)
 {
   caseless_str old_units = get_units ();
@@ -11571,8 +11634,11 @@
       if (cname.compare ("deletefcn")
           || cname.compare ("createfcn")
           || (go.isa ("figure")
-              && (cname.compare ("closerequestfcn")
-                  || cname.compare ("resizefcn")
+              && cname.compare ("closerequestfcn"))
+          || ((go.isa ("figure")
+               || go.isa ("uipanel")
+               || go.isa ("uibuttongroup"))
+              && (cname.compare ("resizefcn")
                   || cname.compare ("sizechangedfcn"))))
         busyaction = base_graphics_event::INTERRUPT;
       else if (go.get_properties ().get_busyaction () == "cancel")
diff -r 55564fdb3e4d -r 4107ff474dcc libinterp/corefcn/graphics.in.h
--- a/libinterp/corefcn/graphics.in.h	Sat Dec 08 12:49:39 2018 +0100
+++ b/libinterp/corefcn/graphics.in.h	Sat Dec 08 16:07:03 2018 +0100
@@ -5577,7 +5577,7 @@
       radio_property fontweight u , "light|{normal}|demi|bold"
       color_property foregroundcolor , color_values (0, 0, 0)
       color_property highlightcolor , color_values (1, 1, 1)
-      array_property position , default_panel_position ()
+      array_property position S , default_panel_position ()
       // FIXME: "resizefcn" is no longer recommended by Matlab,
       //        and has been replaced with "sizechangedfcn"
       //        Eventually this will need to be hidden, and then removed.
@@ -5677,7 +5677,7 @@
       radio_property fontweight u , "light|{normal}|demi|bold"
       color_property foregroundcolor , color_values (0, 0, 0)
       color_property highlightcolor , color_values (1, 1, 1)
-      array_property position , default_panel_position ()
+      array_property position S , default_panel_position ()
       // FIXME: "resizefcn" is no longer recommended by Matlab,
       //        and has been replaced with "sizechangedfcn"
       //        Eventually this will need to be hidden, and then removed.
