Author: lluis
Date: 2006-04-18 08:17:45 -0400 (Tue, 18 Apr 2006)
New Revision: 59587

Modified:
   trunk/stetic/ChangeLog
   trunk/stetic/libstetic/wrapper/Container.cs
   trunk/stetic/libstetic/wrapper/Expander.cs
   trunk/stetic/libstetic/wrapper/Frame.cs
   trunk/stetic/libstetic/wrapper/Widget.cs
Log:
2006-04-18  Lluis Sanchez Gual  <[EMAIL PROTECTED]>

        * libstetic/wrapper/Widget.cs:
        * libstetic/wrapper/Container.cs: When adding a widget to a container,
          make sure the identifiers are not duplicated.
        * libstetic/wrapper/Frame.cs: Fixed code generation for
          the label widget.
        * libstetic/wrapper/Expander.cs: Fix code generation. Fixes bug #78090.



Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog      2006-04-18 11:30:50 UTC (rev 59586)
+++ trunk/stetic/ChangeLog      2006-04-18 12:17:45 UTC (rev 59587)
@@ -1,3 +1,12 @@
+2006-04-18  Lluis Sanchez Gual  <[EMAIL PROTECTED]>
+
+       * libstetic/wrapper/Widget.cs:
+       * libstetic/wrapper/Container.cs: When adding a widget to a container,
+         make sure the identifiers are not duplicated.
+       * libstetic/wrapper/Frame.cs: Fixed code generation for
+         the label widget.
+       * libstetic/wrapper/Expander.cs: Fix code generation. Fixes bug #78090.
+
 2006-04-10  Lluis Sanchez Gual  <[EMAIL PROTECTED]> 
 
        * libstetic/editor/Boolean.cs: Fix nullref in some themes.

Modified: trunk/stetic/libstetic/wrapper/Container.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Container.cs 2006-04-18 11:30:50 UTC (rev 
59586)
+++ trunk/stetic/libstetic/wrapper/Container.cs 2006-04-18 12:17:45 UTC (rev 
59587)
@@ -31,13 +31,23 @@
 
                        container.Removed += ChildRemoved;
                        container.SizeAllocated += SizeAllocated;
+                       container.ParentSet += OnParentSet;
 
                        if (Wrapped.GetType ().ToString ()[0] == 'H')
                                ContainerOrientation = 
Gtk.Orientation.Horizontal;
                        else
                                ContainerOrientation = Gtk.Orientation.Vertical;
+                       
+                       ValidateChildNames ();
                }
                
+               void OnParentSet (object o, Gtk.ParentSetArgs args)
+               {
+                       // Make sure children's IDs don't conflict with other 
widgets
+                       // in the parent container.
+                       ValidateChildNames ();
+               }
+               
                Gtk.Container container {
                        get {
                                return (Gtk.Container)Wrapped;
@@ -738,7 +748,106 @@
                                return (ContainerOrientation == 
Gtk.Orientation.Horizontal);
                        }
                }
+               
+               void ValidateChildNames ()
+               {
+                       if (!IsTopLevel) {
+                               ParentWrapper.ValidateChildNames ();
+                               return;
+                       }
+                               
+                       Hashtable names = new Hashtable ();
+                       ValidateChildNames (names, container);
+               }
 
+               void ValidateChildNames (Hashtable names, Gtk.Container parent)
+               {
+                       foreach (Gtk.Widget w in parent.AllChildren) {
+                               if (names.Contains (w.Name)) {
+                                       // There is a widget with the same 
name. If the widget
+                                       // has a numeric suffix, just increase 
it.
+                                       string name; int idx;
+                                       ParseWidgetName (w.Name, out name, out 
idx);
+                                       
+                                       string compName = idx != 0 ? name + idx 
: name;
+                                       while (names.Contains (compName)) {
+                                               idx++;
+                                               compName = name + idx;
+                                       }
+                                       w.Name = compName;
+                               }
+                               names [w.Name] = w;
+                               
+                               if (w is Gtk.Container) {
+                                       ValidateChildNames (names, 
(Gtk.Container)w);
+                               }
+                       }
+               }
+               
+               void ParseWidgetName (string name, out string baseName, out int 
idx)
+               {
+                       // Extract a numeric sufix from the name
+                       
+                       int n;
+                       for (n = name.Length - 1; n >= 0 && char.IsDigit (name 
[n]); n--)
+                               ;
+                               
+                       if (n < name.Length - 1) {
+                               baseName = name.Substring (0, n + 1);
+                               idx = int.Parse (name.Substring (n + 1));
+                       } else {
+                               baseName = name;
+                               idx = 0;
+                       }
+               }
+
+               internal string GetValidWidgetName (Gtk.Widget widget)
+               {
+                       // Get a valid name for a widget (a name that doesn't
+                       // exist in the parent container.
+
+                       if (!IsTopLevel)
+                               return ParentWrapper.GetValidWidgetName 
(widget);
+
+                       string name;
+                       int idx;
+
+                       ParseWidgetName (widget.Name, out name, out idx);
+                       
+                       string compName = idx != 0 ? name + idx : name;
+                       
+                       Gtk.Widget fw = FindWidget (compName, widget);
+                       while (fw != null) {
+                               idx++;
+                               compName = name + idx;
+                               fw = FindWidget (compName, widget);
+                       }
+                       
+                       return compName;
+               }
+               
+               Gtk.Widget FindWidget (string name, Gtk.Widget skipwidget)
+               {
+                       if (Wrapped != skipwidget && Wrapped.Name == name)
+                               return Wrapped;
+                       else
+                               return FindWidget ((Gtk.Container)Wrapped, 
name, skipwidget);
+               }
+               
+               Gtk.Widget FindWidget (Gtk.Container parent, string name, 
Gtk.Widget skipwidget)
+               {
+                       foreach (Gtk.Widget w in parent.AllChildren) {
+                               if (w.Name == name && w != skipwidget)
+                                       return w;
+                               if (w is Gtk.Container) {
+                                       Gtk.Widget res = FindWidget 
((Gtk.Container)w, name, skipwidget);
+                                       if (res != null)
+                                               return res;
+                               }
+                       }
+                       return null;
+               }
+               
                public class ContainerChild : Stetic.ObjectWrapper {
 
                        internal static void Register ()

Modified: trunk/stetic/libstetic/wrapper/Expander.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Expander.cs  2006-04-18 11:30:50 UTC (rev 
59586)
+++ trunk/stetic/libstetic/wrapper/Expander.cs  2006-04-18 12:17:45 UTC (rev 
59587)
@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Xml;
+using System.CodeDom;
 
 namespace Stetic.Wrapper {
 
@@ -53,5 +54,26 @@
                        else
                                base.ReplaceChild (oldChild, newChild);
                }
+               
+               internal protected override CodeExpression 
GenerateWidgetCreation (GeneratorContext ctx)
+               {
+                       return new CodeObjectCreateExpression 
(ClassDescriptor.WrappedTypeName, new CodePrimitiveExpression (null));
+               }
+
+               protected override void GenerateChildBuildCode 
(GeneratorContext ctx, string parentVar, Widget wrapper)
+               {
+                       if (wrapper.Wrapped == expander.LabelWidget) {
+                               string varName = ctx.GenerateCreationCode 
(wrapper);
+                               CodeAssignStatement assign = new 
CodeAssignStatement (
+                                       new CodePropertyReferenceExpression (
+                                               new 
CodeVariableReferenceExpression (parentVar),
+                                               "LabelWidget"
+                                       ),
+                                       new CodeVariableReferenceExpression 
(varName)
+                               );
+                               ctx.Statements.Add (assign);
+                       } else
+                               base.GenerateChildBuildCode (ctx, parentVar, 
wrapper);
+               }
        }
 }

Modified: trunk/stetic/libstetic/wrapper/Frame.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Frame.cs     2006-04-18 11:30:50 UTC (rev 
59586)
+++ trunk/stetic/libstetic/wrapper/Frame.cs     2006-04-18 12:17:45 UTC (rev 
59587)
@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Xml;
+using System.CodeDom;
 
 namespace Stetic.Wrapper {
 
@@ -55,6 +56,22 @@
                        return child_elem;
                }
 
+               protected override void GenerateChildBuildCode 
(GeneratorContext ctx, string parentVar, Widget wrapper)
+               {
+                       if (wrapper.Wrapped == frame.LabelWidget) {
+                               string varName = ctx.GenerateCreationCode 
(wrapper);
+                               CodeAssignStatement assign = new 
CodeAssignStatement (
+                                       new CodePropertyReferenceExpression (
+                                               new 
CodeVariableReferenceExpression (parentVar),
+                                               "LabelWidget"
+                                       ),
+                                       new CodeVariableReferenceExpression 
(varName)
+                               );
+                               ctx.Statements.Add (assign);
+                       } else
+                               base.GenerateChildBuildCode (ctx, parentVar, 
wrapper);
+               }
+               
                public override void ReplaceChild (Gtk.Widget oldChild, 
Gtk.Widget newChild)
                {
                        if (oldChild == frame.LabelWidget)

Modified: trunk/stetic/libstetic/wrapper/Widget.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Widget.cs    2006-04-18 11:30:50 UTC (rev 
59586)
+++ trunk/stetic/libstetic/wrapper/Widget.cs    2006-04-18 12:17:45 UTC (rev 
59587)
@@ -45,10 +45,18 @@
                        
                        Wrapped.PopupMenu += PopupMenu;
                        Wrapped.FocusInEvent += OnFocusIn;
+                       Wrapped.ParentSet += OnParentSet;
                        InterceptClicks (Wrapped);
 
                        hexpandable = this.ClassDescriptor.HExpandable;
                        vexpandable = this.ClassDescriptor.VExpandable;
+                       
+                       if (ParentWrapper != null) {
+                               // Make sure the widget's name is not already 
being used.
+                               string nn = ParentWrapper.GetValidWidgetName 
(Wrapped);
+                               if (nn != Wrapped.Name)
+                                       Wrapped.Name = nn;
+                       }
                }
                
                void OnFocusIn (object s, Gtk.FocusInEventArgs a)
@@ -61,6 +69,16 @@
                        else if (ParentWrapper != null)
                                ParentWrapper.Select ();
                }
+               
+               void OnParentSet (object o, Gtk.ParentSetArgs args)
+               {
+                       if (ParentWrapper != null) {
+                               // Make sure the widget's name is not already 
being used.
+                               string nn = ParentWrapper.GetValidWidgetName 
(Wrapped);
+                               if (nn != Wrapped.Name)
+                                       Wrapped.Name = nn;
+                       }
+               }
 
                void InterceptClicks (Gtk.Widget widget)
                {
@@ -96,6 +114,14 @@
                        get { return signals; }
                }
                
+               public Container GetTopLevel ()
+               {
+                       Widget c = this;
+                       while (!c.IsTopLevel)
+                               c = c.ParentWrapper;
+                       return c as Container;
+               }
+               
                [GLib.ConnectBefore]
                void WidgetEvent (object obj, Gtk.WidgetEventArgs args)
                {
@@ -222,12 +248,14 @@
                {
                        PropertyDescriptor prop = ClassDescriptor ["Visible"] 
as PropertyDescriptor;
                        if (prop != null && prop.PropertyType == typeof(bool) 
&& (bool) prop.GetValue (Wrapped)) {
-                               ctx.Statements.Add (
-                                       new CodeMethodInvokeExpression (
-                                               new 
CodeVariableReferenceExpression (varName), 
-                                               "Show"
-                                       )
-                               );
+                               if ((bool) prop.GetValue (Wrapped)) {
+                                       ctx.Statements.Add (
+                                               new CodeMethodInvokeExpression (
+                                                       new 
CodeVariableReferenceExpression (varName), 
+                                                       "Show"
+                                               )
+                                       );
+                               }
                        }
                }
                
@@ -382,6 +410,14 @@
                        
                        if (propertyName == "Name") {
                                if (Wrapped.Name != oldName) {
+                                       if (ParentWrapper != null) {
+                                               string nn = 
ParentWrapper.GetValidWidgetName (Wrapped);
+                                               if (nn != Wrapped.Name) {
+                                                       Wrapped.Name = nn;
+                                                       return;
+                                               }
+                                       }
+                                       
                                        string on = oldName;
                                        oldName = Wrapped.Name;
                                        OnNameChanged (new 
WidgetNameChangedArgs (this, on, Wrapped.Name));

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to