Author: danw
Date: 2005-05-24 15:27:21 -0400 (Tue, 24 May 2005)
New Revision: 44939

Modified:
   trunk/stetic/ChangeLog
   trunk/stetic/libstetic/GladeUtils.cs
   trunk/stetic/libstetic/PropertyDescriptor.cs
   trunk/stetic/libstetic/RadioGroupManager.cs
   trunk/stetic/libstetic/editor/GroupPicker.cs
   trunk/stetic/libstetic/wrapper/Button.cs
   trunk/stetic/libstetic/wrapper/Calendar.cs
   trunk/stetic/libstetic/wrapper/Container.cs
   trunk/stetic/libstetic/wrapper/Custom.cs
   trunk/stetic/libstetic/wrapper/MenuItem.cs
   trunk/stetic/libstetic/wrapper/OptionMenu.cs
   trunk/stetic/libstetic/wrapper/RadioButton.cs
   trunk/stetic/libstetic/wrapper/RadioMenuItem.cs
   trunk/stetic/libstetic/wrapper/RadioToolButton.cs
   trunk/stetic/libstetic/wrapper/Widget.cs
   trunk/stetic/stetic/Glade.cs
Log:
        * libstetic/GladeUtils.cs: Fix up the parsing/unparsing to be
        based on C# types rather than ParamSpec GTypes, so that it can be
        used for C# wrapper properties. Update for PropertyDescriptor
        GladeProperty changes.

        * libstetic/PropertyDescriptor.cs (PropertyDescriptor): Allow the
        "Foo" in a "Foo/Bar" property to be a wrapper property. Copy the
        ParamSpec and GladeAttribute from a property to its glade proxy.
        (GladeProperty): don't return null; if the property has no
        GladeProperty proxy, return the property itself.
        (GladeName): don't peek into GladeProperty. (Make the caller do
        it).
        (GladeGetValue, GladeSetValue): gone; just use GetValue/SetValue
        on the GladeProperty.

        * libstetic/RadioGroupManager.cs (GladeGroupName): return the
        glade "group" property value for a radio group item.

        * libstetic/editor/GroupPicker.cs (Dispose): Changed from
        OnDestroyed() to work around a gtk# refcounting bug at the moment.

        * libstetic/wrapper/Button.cs (ConstructChild): build Unselectable
        wrappers for the contents, so they can be glade-serialized
        correctly.
        (GladeChildren): include or skip the child wrappers as
        appropriate.
        (HasResponseId): fix

        * libstetic/wrapper/Calendar.cs (DisplayOptions): proxies
        Gtk.Calendar.DisplayOptions, with a GladeProperty attribute.
        (Register): Change properties to, "DisplayOptions/ShowHeading",
        etc, so that DisplayOptions is treated as the glade property.
        (GladeImport): no longer needed

        * libstetic/wrapper/Container.cs (GladeChildren): new virtual
        property to get a list of children for glade export purposes

        * libstetic/wrapper/Custom.cs:
        s/ObjectManager.RegisterType/GType.Register/
        (Int1, Int2): make these ints now that GladeUtils can deal with
        that.

        * libstetic/wrapper/MenuItem.cs (Label): store the label text
        separately from the Label itself, since OptionMenu will steal the
        Label of the selected MenuItem, so our Label will sometimes be
        unexpectedly null.
        (UseUnderline): remove glade proxy now that GladeUtils can
        directly deal with the property being a bool.

        * libstetic/wrapper/OptionMenu.cs (Items, FlattenMenu): Remove.
        Make the contents be a menu, not just a list of labels.
        (Wrap): mark the menu wrapper with the InternalChildId "menu"
        (GladeImport): don't need FlattenMenu any more, but have to set
        Active property after the menu is built.
        (GladeChildren): return the menu.

        * libstetic/wrapper/RadioButton.cs:
        * libstetic/wrapper/RadioMenuItem.cs: 
        * libstetic/wrapper/RadioToolButton.cs (GladeImport): Re-set
        "Active" after setting the group.
        (GladeExport): Use GroupManager.GladeGroupName() to get the right
        group

        * libstetic/wrapper/Widget.cs (Unselectable): new property.
        (FindWrapper): skip wrappers marked Unselectable.

        * stetic/Glade.cs (ExportWidget): use GladeChildren rather than
        RealChildren.


Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog      2005-05-24 19:17:54 UTC (rev 44938)
+++ trunk/stetic/ChangeLog      2005-05-24 19:27:21 UTC (rev 44939)
@@ -1,3 +1,74 @@
+2005-05-24  Dan Winship  <[EMAIL PROTECTED]>
+
+       * libstetic/GladeUtils.cs: Fix up the parsing/unparsing to be
+       based on C# types rather than ParamSpec GTypes, so that it can be
+       used for C# wrapper properties. Update for PropertyDescriptor
+       GladeProperty changes.
+
+       * libstetic/PropertyDescriptor.cs (PropertyDescriptor): Allow the
+       "Foo" in a "Foo/Bar" property to be a wrapper property. Copy the
+       ParamSpec and GladeAttribute from a property to its glade proxy.
+       (GladeProperty): don't return null; if the property has no
+       GladeProperty proxy, return the property itself.
+       (GladeName): don't peek into GladeProperty. (Make the caller do
+       it).
+       (GladeGetValue, GladeSetValue): gone; just use GetValue/SetValue
+       on the GladeProperty.
+
+       * libstetic/RadioGroupManager.cs (GladeGroupName): return the
+       glade "group" property value for a radio group item.
+
+       * libstetic/editor/GroupPicker.cs (Dispose): Changed from
+       OnDestroyed() to work around a gtk# refcounting bug at the moment.
+
+       * libstetic/wrapper/Button.cs (ConstructChild): build Unselectable
+       wrappers for the contents, so they can be glade-serialized
+       correctly.
+       (GladeChildren): include or skip the child wrappers as
+       appropriate.
+       (HasResponseId): fix
+
+       * libstetic/wrapper/Calendar.cs (DisplayOptions): proxies
+       Gtk.Calendar.DisplayOptions, with a GladeProperty attribute.
+       (Register): Change properties to, "DisplayOptions/ShowHeading",
+       etc, so that DisplayOptions is treated as the glade property.
+       (GladeImport): no longer needed
+
+       * libstetic/wrapper/Container.cs (GladeChildren): new virtual
+       property to get a list of children for glade export purposes
+
+       * libstetic/wrapper/Custom.cs:
+       s/ObjectManager.RegisterType/GType.Register/
+       (Int1, Int2): make these ints now that GladeUtils can deal with
+       that.
+
+       * libstetic/wrapper/MenuItem.cs (Label): store the label text
+       separately from the Label itself, since OptionMenu will steal the
+       Label of the selected MenuItem, so our Label will sometimes be
+       unexpectedly null.
+       (UseUnderline): remove glade proxy now that GladeUtils can
+       directly deal with the property being a bool.
+
+       * libstetic/wrapper/OptionMenu.cs (Items, FlattenMenu): Remove.
+       Make the contents be a menu, not just a list of labels.
+       (Wrap): mark the menu wrapper with the InternalChildId "menu"
+       (GladeImport): don't need FlattenMenu any more, but have to set
+       Active property after the menu is built.
+       (GladeChildren): return the menu.
+
+       * libstetic/wrapper/RadioButton.cs:
+       * libstetic/wrapper/RadioMenuItem.cs: 
+       * libstetic/wrapper/RadioToolButton.cs (GladeImport): Re-set
+       "Active" after setting the group.
+       (GladeExport): Use GroupManager.GladeGroupName() to get the right
+       group
+
+       * libstetic/wrapper/Widget.cs (Unselectable): new property.
+       (FindWrapper): skip wrappers marked Unselectable.
+
+       * stetic/Glade.cs (ExportWidget): use GladeChildren rather than
+       RealChildren.
+
 2005-05-04  Dan Winship  <[EMAIL PROTECTED]>
 
        * configure.in: require gtk-sharp 2.5

Modified: trunk/stetic/libstetic/GladeUtils.cs
===================================================================
--- trunk/stetic/libstetic/GladeUtils.cs        2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/GladeUtils.cs        2005-05-24 19:27:21 UTC (rev 
44939)
@@ -22,8 +22,11 @@
                        foreach (ItemGroup group in wrapper.ItemGroups) {
                                foreach (ItemDescriptor item in group.Items) {
                                        PropertyDescriptor prop = item as 
PropertyDescriptor;
-                                       if (prop == null || prop.GladeName == 
null)
+                                       if (prop == null)
                                                continue;
+                                       prop = prop.GladeProperty;
+                                       if (prop.GladeName == null)
+                                               continue;
                                        if (prop.GladeFlags == 0 ||
                                            (prop.GladeFlags & 
GladeProperty.UseUnderlying) != 0)
                                                continue;
@@ -38,102 +41,129 @@
                        }
                }
 
-               static void ParseProperty (Type type, bool childprop, string 
name, string strval, out GLib.Value value)
+               static GLib.Value ParseBasicType (GLib.TypeFundamentals type, 
string strval)
                {
-                       if (name == "adjustment") {
-                               try {
-                                       string[] vals = strval.Split (' ');
-                                       double deflt, min, max, step, page_inc, 
page_size;
-
-                                       deflt = Double.Parse (vals[0]);
-                                       min = Double.Parse (vals[1]);
-                                       max = Double.Parse (vals[2]);
-                                       step = Double.Parse (vals[3]);
-                                       page_inc = Double.Parse (vals[4]);
-                                       page_size = Double.Parse (vals[5]);
-
-                                       value = new GLib.Value (new 
Gtk.Adjustment (deflt, min, max, step, page_inc, page_size));
-                                       return;
-                               } catch {
-                                       ;
-                               }
-                       }
-
-                       ParamSpec pspec;
-
-                       if (childprop)
-                               pspec = ParamSpec.LookupChildProperty (type, 
name);
-                       else
-                               pspec = ParamSpec.LookupObjectProperty (type, 
name);
-                       if (pspec == null)
-                               throw new GladeException ("Unknown property", 
type.ToString (), childprop, name, strval);
-
-                       GLib.GType gtype = new GLib.GType (g_type_fundamental 
(pspec.ValueType));
-                       switch ((GLib.TypeFundamentals)(int)gtype.Val) {
+                       switch (type) {
                        case GLib.TypeFundamentals.TypeChar:
-                               value = new GLib.Value (SByte.Parse (strval));
-                               break;
+                               return new GLib.Value (SByte.Parse (strval));
                        case GLib.TypeFundamentals.TypeUChar:
-                               value = new GLib.Value (Byte.Parse (strval));
-                               break;
+                               return new GLib.Value (Byte.Parse (strval));
                        case GLib.TypeFundamentals.TypeBoolean:
-                               value = new GLib.Value (strval == "True");
-                               break;
+                               return new GLib.Value (strval == "True");
                        case GLib.TypeFundamentals.TypeInt:
-                               value = new GLib.Value (Int32.Parse (strval));
-                               break;
+                               return new GLib.Value (Int32.Parse (strval));
                        case GLib.TypeFundamentals.TypeUInt:
-                               value = new GLib.Value (UInt32.Parse (strval));
-                               break;
+                               return new GLib.Value (UInt32.Parse (strval));
                        case GLib.TypeFundamentals.TypeInt64:
-                               value = new GLib.Value (Int64.Parse (strval));
-                               break;
+                               return new GLib.Value (Int64.Parse (strval));
                        case GLib.TypeFundamentals.TypeUInt64:
-                               value = new GLib.Value (UInt64.Parse (strval));
-                               break;
+                               return new GLib.Value (UInt64.Parse (strval));
                        case GLib.TypeFundamentals.TypeFloat:
-                               value = new GLib.Value (Single.Parse (strval));
-                               break;
+                               return new GLib.Value (Single.Parse (strval));
                        case GLib.TypeFundamentals.TypeDouble:
-                               value = new GLib.Value (Double.Parse (strval));
-                               break;
+                               return new GLib.Value (Double.Parse (strval));
                        case GLib.TypeFundamentals.TypeString:
-                               value = new GLib.Value (strval);
-                               break;
+                               return new GLib.Value (strval);
+                       default:
+                               throw new GladeException ("Could not parse");
+                       }
+               }
 
-                       case GLib.TypeFundamentals.TypeEnum:
-                               IntPtr enum_class = g_type_class_ref 
(pspec.ValueType);
+               static GLib.Value ParseEnum (IntPtr gtype, string strval)
+               {
+                       IntPtr enum_class = g_type_class_ref (gtype);
+                       try {
                                IntPtr enum_value = g_enum_get_value_by_name 
(enum_class, strval);
                                if (enum_value == IntPtr.Zero)
-                                       goto default;
+                                       throw new GladeException ("Could not 
parse");
 
                                IntPtr eval = Marshal.ReadIntPtr (enum_value);
-                               string ename = GLib.Marshaller.Utf8PtrToString 
(g_type_name_from_class (enum_class));
-                               value = new GLib.Value (new GLib.EnumWrapper 
((int)eval, false), ename);
+
+                               string typeName = 
GLib.Marshaller.Utf8PtrToString (g_type_name (gtype));
+                               return new GLib.Value (new GLib.EnumWrapper 
((int)eval, false), typeName);
+                       } finally {
                                g_type_class_unref (enum_class);
-                               break;
+                       }
+               }
 
-                       case GLib.TypeFundamentals.TypeFlags:
-                               IntPtr flags_class = g_type_class_ref 
(pspec.ValueType);
-                               uint fval = 0;
+               static GLib.Value ParseFlags (IntPtr gtype, string strval)
+               {
+                       IntPtr flags_class = g_type_class_ref (gtype);
+                       uint fval = 0;
 
+                       try {
+                               // The Trim() is needed for Widget.Events.
+                               // The get_value_by_nick() is for 
BoxChild.[XY]Options
                                foreach (string flag in strval.Split ('|')) {
                                        if (flag == "")
                                                continue;
-                                       IntPtr flags_value = 
g_flags_get_value_by_nick (flags_class, flag);
+                                       IntPtr flags_value = 
g_flags_get_value_by_name (flags_class, flag.Trim ());
                                        if (flags_value == IntPtr.Zero)
-                                               goto default;
+                                               flags_value = 
g_flags_get_value_by_nick (flags_class, flag);
+                                       if (flags_value == IntPtr.Zero)
+                                               throw new GladeException 
("Could not parse");
 
                                        IntPtr bits = Marshal.ReadIntPtr 
(flags_value);
                                        fval |= (uint)bits;
                                }
 
-                               string fname = GLib.Marshaller.Utf8PtrToString 
(g_type_name_from_class (flags_class));
-                               value = new GLib.Value (new GLib.EnumWrapper 
((int)fval, true), fname);
+                               string typeName = 
GLib.Marshaller.Utf8PtrToString (g_type_name (gtype));
+                               return new GLib.Value (new GLib.EnumWrapper 
((int)fval, true), typeName);
+                       } finally {
                                g_type_class_unref (flags_class);
-                               break;
+                       }
+               }
 
-                       default:
+               static GLib.Value ParseAdjustment (string strval)
+               {
+                       string[] vals = strval.Split (' ');
+                       double deflt, min, max, step, page_inc, page_size;
+
+                       deflt = Double.Parse (vals[0]);
+                       min = Double.Parse (vals[1]);
+                       max = Double.Parse (vals[2]);
+                       step = Double.Parse (vals[3]);
+                       page_inc = Double.Parse (vals[4]);
+                       page_size = Double.Parse (vals[5]);
+                       return new GLib.Value (new Gtk.Adjustment (deflt, min, 
max, step, page_inc, page_size));
+               }
+
+               static GLib.Value ParseProperty (ParamSpec pspec, Type 
propType, string strval)
+               {
+                       IntPtr gtype;
+                       if (propType != null)
+                               gtype = ((GLib.GType)propType).Val;
+                       else if (pspec != null)
+                               gtype = pspec.ValueType;
+                       else
+                               throw new GladeException ("Bad type");
+
+                       GLib.TypeFundamentals typef = 
(GLib.TypeFundamentals)(int)g_type_fundamental (gtype);
+
+                       if (gtype == Gtk.Adjustment.GType.Val)
+                               return ParseAdjustment (strval);
+                       else if (typef == GLib.TypeFundamentals.TypeEnum)
+                               return ParseEnum (gtype, strval);
+                       else if (typef == GLib.TypeFundamentals.TypeFlags)
+                               return ParseFlags (gtype, strval);
+                       else
+                               return ParseBasicType (typef, strval);
+               }
+
+               static GLib.Value ParseProperty (Type type, bool childprop, 
string name, string strval)
+               {
+                       ParamSpec pspec;
+
+                       if (childprop)
+                               pspec = ParamSpec.LookupChildProperty (type, 
name);
+                       else
+                               pspec = ParamSpec.LookupObjectProperty (type, 
name);
+                       if (pspec == null)
+                               throw new GladeException ("Unknown property", 
type.ToString (), childprop, name, strval);
+
+                       try {
+                               return ParseProperty (pspec, null, strval);
+                       } catch {
                                throw new GladeException ("Could not parse 
property", type.ToString (), childprop, name, strval);
                        }
                }
@@ -149,7 +179,7 @@
 
                                GLib.Value value;
                                try {
-                                       ParseProperty (type, childprops, name, 
strval, out value);
+                                       value = ParseProperty (type, 
childprops, name, strval);
                                        names.Add (name);
                                        values.Add (value);
                                } catch (GladeException ge) {
@@ -250,18 +280,15 @@
                static void ParseGladeProperty (ObjectWrapper wrapper, bool 
childprop,
                                                PropertyDescriptor prop, string 
strval)
                {
-                       if (((prop.GladeFlags & GladeProperty.Proxied) != 0) ||
-                           prop.PropertyType == typeof (string))
-                               prop.GladeSetValue (wrapper, strval);
-                       else {
-                               GLib.Value value;
-                               ParseProperty (ObjectWrapper.WrappedType 
(wrapper.GetType ()),
-                                              childprop, prop.GladeName, 
strval, out value);
+                       try {
+                               GLib.Value value = ParseProperty 
(prop.ParamSpec, prop.PropertyType, strval);
                                if (prop.PropertyType.IsEnum) {
-                                       GLib.EnumWrapper wrap = 
(GLib.EnumWrapper)value;
-                                       prop.GladeSetValue (wrapper, 
Enum.ToObject (prop.PropertyType, (int)wrap));
+                                       GLib.EnumWrapper ewrap = 
(GLib.EnumWrapper)value;
+                                       prop.SetValue (wrapper, Enum.ToObject 
(prop.PropertyType, (int)ewrap));
                                } else
-                                       prop.GladeSetValue (wrapper, value.Val);
+                                       prop.SetValue (wrapper, value.Val);
+                       } catch (Exception e) {
+                               throw new GladeException ("Could not parse 
property", wrapper.GetType ().ToString (), childprop, prop.GladeName, strval);
                        }
                }
 
@@ -278,12 +305,6 @@
 
                static string PropToString (ObjectWrapper wrapper, 
PropertyDescriptor prop)
                {
-                       // If this is a stetic-only property, skip it
-                       if (prop.GladeName == null && prop.GladeFlags == 0)
-                               return null;
-
-                       // Get the value, either from the underlying property 
or from
-                       // the wrapper
                        object value;
 
                        if ((prop.GladeFlags & GladeProperty.UseUnderlying) != 
0) {
@@ -301,13 +322,10 @@
                                }
                                value = gval.Val;
                        } else
-                               value = prop.GladeGetValue (wrapper);
+                               value = prop.GetValue (wrapper);
                        if (value == null)
                                return null;
 
-                       if (prop.GladeProperty != null)
-                               prop = prop.GladeProperty;
-
                        // If the property has its default value, we don't need 
to write it
                        if (prop.ParamSpec != null && value.Equals 
(prop.ParamSpec.Default))
                                return null;
@@ -376,12 +394,15 @@
                        foreach (ItemGroup group in wrapper.ItemGroups) {
                                foreach (ItemDescriptor item in group.Items) {
                                        PropertyDescriptor prop = item as 
PropertyDescriptor;
-                                       if (prop == null || prop.GladeName == 
null)
+                                       if (prop == null)
                                                continue;
+                                       prop = prop.GladeProperty;
+                                       if (prop.GladeName == null)
+                                               continue;
                                        if (!prop.VisibleFor (wrapper))
                                                continue;
 
-                                       string val = PropToString (wrapper, 
prop);
+                                       string val = PropToString (wrapper, 
prop.GladeProperty);
                                        if (val != null)
                                                props[prop.GladeName] = val;
                                }
@@ -392,10 +413,10 @@
                static extern IntPtr g_type_fundamental (IntPtr gtype);
 
                [DllImport("libgobject-2.0-0.dll")]
-               static extern IntPtr g_type_name_from_class (IntPtr klass);
+               static extern IntPtr g_type_from_name (string name);
 
                [DllImport("libgobject-2.0-0.dll")]
-               static extern IntPtr g_type_from_name (string name);
+               static extern IntPtr g_type_name (IntPtr gtype);
 
                [DllImport("libgobject-2.0-0.dll")]
                static extern IntPtr g_type_class_ref (IntPtr gtype);
@@ -428,6 +449,9 @@
                static extern IntPtr g_flags_get_value_by_nick (IntPtr 
flags_class, string nick);
 
                [DllImport("libgobject-2.0-0.dll")]
+               static extern IntPtr g_flags_get_value_by_name (IntPtr 
flags_class, string nick);
+
+               [DllImport("libgobject-2.0-0.dll")]
                static extern IntPtr g_flags_get_first_value (IntPtr 
flags_class, uint val);
        }
 }

Modified: trunk/stetic/libstetic/PropertyDescriptor.cs
===================================================================
--- trunk/stetic/libstetic/PropertyDescriptor.cs        2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/PropertyDescriptor.cs        2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -34,7 +34,7 @@
                                // Split-up property (eg, "XOptions/XExpand")
                                gladeProperty = new PropertyDescriptor 
(wrapperType, objectType, propertyName.Substring (0, slash));
                                propertyInfo = FindProperty (wrapperType, 
objectType, propertyName.Substring (slash + 1));
-                               isWrapperProperty = true;
+                               isWrapperProperty = 
propertyInfo.DeclaringType.IsSubclassOf (typeof (ObjectWrapper));
                        } else {
                                // Basic simple property
                                propertyInfo = FindProperty (wrapperType, 
objectType, propertyName);
@@ -76,8 +76,13 @@
 
                                if (attr is Stetic.GladePropertyAttribute) {
                                        gladeAttribute = 
(GladePropertyAttribute)attr;
-                                       if (gladeAttribute.Proxy != null)
+                                       if (gladeAttribute.Proxy != null) {
                                                gladeProperty = new 
PropertyDescriptor (wrapperType, objectType, gladeAttribute.Proxy);
+                                               if (gladeProperty.pspec == null)
+                                                       gladeProperty.pspec = 
pspec;
+                                               if 
(gladeProperty.gladeAttribute == null)
+                                                       
gladeProperty.gladeAttribute = gladeAttribute;
+                                       }
                                }
                        }
                }
@@ -209,13 +214,19 @@
 
                public GladeProperty GladeFlags {
                        get {
-                               return gladeAttribute != null ? 
gladeAttribute.Flags : 0;
+                               if (gladeAttribute != null)
+                                       return gladeAttribute.Flags;
+                               else
+                                       return 0;
                        }
                }
 
                public PropertyDescriptor GladeProperty {
                        get {
-                               return gladeProperty;
+                               if (gladeProperty != null)
+                                       return gladeProperty;
+                               else
+                                       return this;
                        }
                }
 
@@ -223,39 +234,11 @@
                        get {
                                if (gladeAttribute != null && 
gladeAttribute.Name != null)
                                        return gladeAttribute.Name;
-                               else if (gladeProperty != null && 
gladeProperty.GladeName != null)
-                                       return gladeProperty.GladeName;
                                else if (pspec != null)
                                        return pspec.Name.Replace ('-', '_');
                                else
                                        return null;
                        }
                }
-
-               public object GladeGetValue (ObjectWrapper wrapper)
-               {
-                       if (gladeProperty != null)
-                               return gladeProperty.GetValue (wrapper);
-                       else {
-                               object obj = isWrapperProperty ? wrapper : 
wrapper.Wrapped;
-                               if (memberInfo != null)
-                                       return memberInfo.GetValue (obj, null);
-                               else
-                                       return propertyInfo.GetValue (obj, 
null);
-                       }
-               }
-
-               public void GladeSetValue (ObjectWrapper wrapper, object value)
-               {
-                       if (gladeProperty != null)
-                               gladeProperty.SetValue (wrapper, value);
-                       else {
-                               object obj = isWrapperProperty ? wrapper : 
wrapper.Wrapped;
-                               if (memberInfo != null)
-                                       memberInfo.SetValue (obj, value, null);
-                               else
-                                       propertyInfo.SetValue (obj, value, 
null);
-                       }
-               }
        }
 }

Modified: trunk/stetic/libstetic/RadioGroupManager.cs
===================================================================
--- trunk/stetic/libstetic/RadioGroupManager.cs 2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/RadioGroupManager.cs 2005-05-24 19:27:21 UTC (rev 
44939)
@@ -2,23 +2,28 @@
 using System.Collections;
 using System.Reflection;
 
-// The external (UI/glade file) representation of "radio widget"
-// (Gtk.RadioButton, Gtk.RadioToolButton, and Gtk.RadioMenuItem) groups
-// is that the groups have names, and each widget's "group" property stores
-// the name of its group.
+// The stetic representation of "radio widget" (Gtk.RadioButton,
+// Gtk.RadioToolButton, and Gtk.RadioMenuItem) groups is that the
+// groups have names, and each widget's "Group" property stores the
+// name of its group. The glade representation is similar, except that
+// the group names aren't arbitrary; they have to be the name of the
+// first widget in the group. (On disk, the "group leader" has no
+// "group" property, and the other widgets have the leader's name as
+// their group property.)
 //
-// The internal (Gtk) representation of groups is that each radio widget
-// has a GLib.SList "Group" property. The content of the list is essentially
-// opaque. (For Gtk.RadioButton, the list contains all of the RadioButtons
-// in the group. But for Gtk.ToolRadioButton it contains pointers to internal
-// widgets, not the ToolRadioButtons themselves.) The only thing we can do
-// with them then is to read one widget's group and then immediately assign
-// it to another widget. We can't look into the list, or assume that a
-// widget's Group property will keep the same value if any other widget's
-// Group changes.
+// The internal gtk representation of groups is that each radio widget
+// has a GLib.SList "Group" property. The content of the list is
+// essentially opaque. (For Gtk.RadioButton, the list contains all of
+// the RadioButtons in the group. But for Gtk.ToolRadioButton it
+// contains pointers to internal widgets, not the ToolRadioButtons
+// themselves.) The only thing we can do with them then is to read one
+// widget's group and then immediately assign it to another widget. We
+// can't look into the list, or assume that a widget's Group property
+// will keep the same value if any other widget's Group changes.
 //
-// Each radio widget type wrapper class keeps a static RadioGroupManager to
-// handle this string<->GLib.SList translation for it.
+// Each radio widget type wrapper class keeps a static
+// RadioGroupManager to handle this string<->GLib.SList translation
+// for it.
 
 namespace Stetic {
 
@@ -154,5 +159,15 @@
                                widgets[radio] = newGroup;
                        }
                }
+
+               public string GladeGroupName (Gtk.Widget radio)
+               {
+                       RadioGroup group = widgets[radio] as RadioGroup;
+                       if (group == null || group.Widgets.Count == 0)
+                               return null;
+
+                       Gtk.Widget leader = (Gtk.Widget)group.Widgets[0];
+                       return leader.Name;
+               }
        }
 }

Modified: trunk/stetic/libstetic/editor/GroupPicker.cs
===================================================================
--- trunk/stetic/libstetic/editor/GroupPicker.cs        2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/editor/GroupPicker.cs        2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -29,9 +29,10 @@
                        GroupsChanged ();
                }
 
-               protected override void OnDestroyed ()
+               public override void Dispose ()
                {
                        manager.GroupsChanged -= GroupsChanged;
+                       base.Dispose ();
                }
 
                void GroupsChanged ()

Modified: trunk/stetic/libstetic/wrapper/Button.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Button.cs    2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/Button.cs    2005-05-24 19:27:21 UTC (rev 
44939)
@@ -116,6 +116,30 @@
                        hasLabel = true;
                }
 
+               public override void GladeExport (out string className, out 
string id, out Hashtable props)
+               {
+                       base.GladeExport (out className, out id, out props);
+                       props["use_stock"] = IsStock ? "True" : "False";
+               }
+
+               public override IEnumerable RealChildren {
+                       get {
+                               if (HasLabel)
+                                       return new Gtk.Widget[0];
+                               else
+                                       return base.RealChildren;
+                       }
+               }
+
+               public override IEnumerable GladeChildren {
+                       get {
+                               if (Icon == null || IsStock)
+                                       return new Gtk.Widget[0];
+                               else
+                                       return base.RealChildren;
+                       }
+               }
+
                private Gtk.Button button {
                        get {
                                return (Gtk.Button)Wrapped;
@@ -210,8 +234,28 @@
                        alignment.ShowAll ();
 
                        button.Add (alignment);
+
+                       Widget wrapper;
+                       wrapper = (Widget)ObjectWrapper.Create (stetic, typeof 
(Stetic.Wrapper.Label), labelWidget);
+                       wrapper.Unselectable = true;
+                       wrapper = (Widget)ObjectWrapper.Create (stetic, typeof 
(Stetic.Wrapper.Image), iconWidget);
+                       wrapper.Unselectable = true;
+                       wrapper = (Widget)ObjectWrapper.Create (stetic, typeof 
(Stetic.Wrapper.HBox), box);
+                       wrapper.Unselectable = true;
+                       wrapper = (Widget)ObjectWrapper.Create (stetic, typeof 
(Stetic.Wrapper.Alignment), alignment);
+                       wrapper.Unselectable = true;
                }
 
+               bool IsStock {
+                       get {
+                               if (icon == null || !icon.StartsWith ("stock:"))
+                                       return false;
+
+                               Gtk.StockItem item = Gtk.Stock.Lookup 
(icon.Substring (6));
+                               return item.Label != null && label == 
item.Label;
+                       }
+               }
+
                [Editor (typeof (Stetic.Editor.Image))]
                [Description ("Icon", "The icon to display in the button")]
                public string Icon {
@@ -257,9 +301,6 @@
                                Stetic.Wrapper.Widget pwrap = ParentWrapper;
                                if (pwrap == null)
                                        return false;
-                               pwrap = pwrap.ParentWrapper;
-                               if (pwrap == null)
-                                       return false;
                                return pwrap.InternalChildId == "action_area";
                        }
                }

Modified: trunk/stetic/libstetic/wrapper/Calendar.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Calendar.cs  2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/Calendar.cs  2005-05-24 19:27:21 UTC (rev 
44939)
@@ -11,33 +11,26 @@
                internal static new void Register (Type type)
                {
                        AddItemGroup (type, "Calendar Properties",
-                                     "ShowHeading",
-                                     "ShowDayNames",
-                                     "ShowWeekNumbers",
-                                     "NoMonthChange");
+                                     "DisplayOptions/ShowHeading",
+                                     "DisplayOptions/ShowDayNames",
+                                     "DisplayOptions/ShowWeekNumbers",
+                                     "DisplayOptions/NoMonthChange");
                }
 
-               protected override void GladeImport (string className, string 
id, Hashtable props)
-               {
-                       string display_options = GladeUtils.ExtractProperty 
("display_options", props);
-                       base.GladeImport (className, id, props);
+               Gtk.Calendar calendar {
+                       get {
+                               return (Gtk.Calendar)wrapped;
+                       }
+               }
 
-                       if (display_options != null) {
-                               Gtk.CalendarDisplayOptions options = 0;
-
-                               if (display_options.IndexOf ("SHOW_HEADING") != 
-1)
-                                       options |= 
Gtk.CalendarDisplayOptions.ShowHeading;
-                               if (display_options.IndexOf ("SHOW_DAY_NAMES") 
!= -1)
-                                       options |= 
Gtk.CalendarDisplayOptions.ShowDayNames;
-                               if (display_options.IndexOf ("NO_MONTH_CHANGE") 
!= -1)
-                                       options |= 
Gtk.CalendarDisplayOptions.NoMonthChange;
-                               if (display_options.IndexOf 
("SHOW_WEEK_NUMBERS") != -1)
-                                       options |= 
Gtk.CalendarDisplayOptions.ShowWeekNumbers;
-                               if (display_options.IndexOf 
("WEEK_START_MONDAY") != -1)
-                                       options |= 
Gtk.CalendarDisplayOptions.WeekStartMonday;
-
-                               ((Gtk.Calendar)Wrapped).DisplayOptions = 
options;
+               [GladeProperty (Name = "display_options")]
+               public Gtk.CalendarDisplayOptions DisplayOptions {
+                       get {
+                               return calendar.DisplayOptions;
                        }
+                       set {
+                               calendar.DisplayOptions = value;
+                       }
                }
        }
 }

Modified: trunk/stetic/libstetic/wrapper/Container.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Container.cs 2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/Container.cs 2005-05-24 19:27:21 UTC (rev 
44939)
@@ -246,6 +246,12 @@
                        }
                }
 
+               public virtual IEnumerable GladeChildren {
+                       get {
+                               return RealChildren;
+                       }
+               }
+
                protected virtual void ReplaceChild (Gtk.Widget oldChild, 
Gtk.Widget newChild)
                {
                        Gtk.Container.ContainerChild cc;

Modified: trunk/stetic/libstetic/wrapper/Custom.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Custom.cs    2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/Custom.cs    2005-05-24 19:27:21 UTC (rev 
44939)
@@ -6,7 +6,7 @@
        public class Custom : Gtk.DrawingArea {
                static Custom ()
                {
-                       GLib.ObjectManager.RegisterType (GType, typeof 
(Stetic.Custom));
+                       GLib.GType.Register (GType, typeof (Stetic.Custom));
                }
 
                public Custom (IntPtr raw) : base(raw) {}
@@ -49,7 +49,8 @@
                                      "Int2");
                }
 
-               string creationFunction, string1, string2, int1 = "0", int2 = 
"0";
+               string creationFunction, string1, string2;
+               int int1, int2;
 
                [GladeProperty (Name = "creation_function")]
                public string CreationFunction {
@@ -81,35 +82,23 @@
                        }
                }
 
-               // This is sort of lame. But the properties were actually 
int-valued,
-               // they would need GladeProxies. We should move all of these 
into
-               // custom.c anyway.
-
                [GladeProperty (Name = "int1")]
-               public string Int1 {
+               public int Int1 {
                        get {
                                return int1;
                        }
                        set {
-                               try {
-                                       int1 = Int32.Parse (value).ToString ();
-                               } catch {
-                                       int1 = "0";
-                               }
+                               int1 = value;
                        }
                }
 
                [GladeProperty (Name = "int2")]
-               public string Int2 {
+               public int Int2 {
                        get {
                                return int2;
                        }
                        set {
-                               try {
-                                       int2 = Int32.Parse (value).ToString ();
-                               } catch {
-                                       int2 = "0";
-                               }
+                               int2 = value;
                        }
                }
        }

Modified: trunk/stetic/libstetic/wrapper/MenuItem.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/MenuItem.cs  2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/MenuItem.cs  2005-05-24 19:27:21 UTC (rev 
44939)
@@ -81,19 +81,21 @@
                        }
                }
 
+               string labelText;
+
                [GladeProperty (Name = "label")]
                [Description ("Label", "The text of the menu item")]
                public string Label {
                        get {
-                               return label.LabelProp;
+                               return labelText;
                        }
                        set {
-                               label.LabelProp = value;
+                               label.LabelProp = labelText = value;
                                EmitNotify ("Label");
                        }
                }
 
-               [GladeProperty (Name = "use_underline", Proxy = 
"GladeUseUnderline")]
+               [GladeProperty (Name = "use_underline")]
                [Description ("Use Underline", "If set, an underline in the 
text indicates the next character should be used for the mnemonic accelerator 
key")]
                public bool UseUnderline {
                        get {
@@ -105,15 +107,6 @@
                        }
                }
 
-               internal string GladeUseUnderline {
-                       get {
-                               return UseUnderline ? "True" : "False";
-                       }
-                       set {
-                               UseUnderline = (value == "True");
-                       }
-               }
-
                Gtk.AccelGroup accelGroup;
                string accelerator;
 

Modified: trunk/stetic/libstetic/wrapper/OptionMenu.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/OptionMenu.cs        2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/wrapper/OptionMenu.cs        2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -14,7 +14,6 @@
                internal static new void Register (Type type)
                {
                        AddItemGroup (type, "Option Menu Properties",
-                                     "Items",
                                      "Active");
                }
 
@@ -27,14 +26,20 @@
                                menu.Show ();
                                optionmenu.Menu = menu;
                        }
-                       ObjectWrapper.Create (stetic, typeof 
(Stetic.Wrapper.Menu), optionmenu.Menu);
+                       Widget menuWrapper = (Widget)ObjectWrapper.Create 
(stetic, typeof (Stetic.Wrapper.Menu), optionmenu.Menu);
+                       menuWrapper.InternalChildId = "menu";
                }
 
                protected override void GladeImport (string className, string 
id, Hashtable props)
                {
-                       GladeUtils.ExtractProperty ("history", props);
+                       string history = GladeUtils.ExtractProperty ("history", 
props);
                        base.GladeImport (className, id, props);
-                       stetic.GladeImportComplete += FlattenMenu;
+                       stetic.GladeImportComplete += delegate () {
+                               if (history != null)
+                                       Active = Int32.Parse (history);
+                               else
+                                       Active = 0;
+                       };
                }
 
                public override Widget GladeSetInternalChild (string childId, 
string className, string id, Hashtable props)
@@ -47,22 +52,10 @@
                        return wrapper;
                }
 
-               void FlattenMenu ()
-               {
-                       Gtk.Menu menu = optionmenu.Menu as Gtk.Menu;
-                       System.Text.StringBuilder sb = new 
System.Text.StringBuilder ();
-
-                       foreach (Gtk.Widget w in menu) {
-                               Gtk.MenuItem item = w as Gtk.MenuItem;
-                               if (item == null)
-                                       continue;
-                               Gtk.Label label = item.Child as Gtk.Label;
-                               if (label != null)
-                                       sb.Append (label.LabelProp);
-                               sb.Append ("\n");
+               public override IEnumerable GladeChildren {
+                       get {
+                               return new Gtk.Widget[] { optionmenu.Menu };
                        }
-
-                       Items = sb.ToString ();
                }
 
                Gtk.OptionMenu optionmenu {
@@ -71,45 +64,7 @@
                        }
                }
 
-               string items = "";
-               string[] item = new string[0];
-
-               [Editor (typeof (Stetic.Editor.Text))]
-               [Description ("Items", "The items to display in the Option 
Menu, one per line")]
-               public string Items {
-                       get {
-                               return items;
-                       }
-                       set {
-                               int active = optionmenu.History;
-                               Gtk.Menu menu = new Gtk.Menu ();
-
-                               items = value;
-                               while (items.EndsWith ("\n"))
-                                       items = items.Substring (0, 
items.Length - 1);
-                               item = items.Split ('\n');
-
-                               for (int i = 0; i < item.Length; i++) {
-                                       Gtk.MenuItem mitem;
-                                       if (item[i] == "")
-                                               mitem = new 
Gtk.SeparatorMenuItem ();
-                                       else
-                                               mitem = new Gtk.MenuItem 
(item[i]);
-                                       mitem.Show ();
-                                       mitem.Activated += delegate (object 
obj, EventArgs args) {
-                                               EmitNotify ("Active");
-                                       };
-                                       menu.Add (mitem);
-                               }
-
-                               menu.Show ();
-                               optionmenu.Menu = menu;
-                               optionmenu.SetHistory ((uint)active);
-
-                               EmitNotify ("Items");
-                       }
-               }
-
+               [GladeProperty (Name = "history")]
                [Description ("Active", "The active menu item")]
                [Range (0, System.Int32.MaxValue)]
                public int Active {

Modified: trunk/stetic/libstetic/wrapper/RadioButton.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/RadioButton.cs       2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/wrapper/RadioButton.cs       2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -35,14 +35,25 @@
                protected override void GladeImport (string className, string 
id, Hashtable props)
                {
                        string group = GladeUtils.ExtractProperty ("group", 
props);
+                       string active = GladeUtils.ExtractProperty ("active", 
props);
                        base.GladeImport (className, id, props);
 
                        if (group != null)
                                Group = group;
                        else
                                Group = Wrapped.Name;
+                       if (active == "True")
+                               ((Gtk.RadioButton)Wrapped).Active = true;
                }
 
+               public override void GladeExport (out string className, out 
string id, out Hashtable props)
+               {
+                       base.GladeExport (out className, out id, out props);
+                       string group = GroupManager.GladeGroupName (Wrapped);
+                       if (group != id)
+                               props["group"] = group;
+               }
+
                [Editor (typeof (Stetic.Editor.GroupPicker))]
                [Description ("Group", "The name of the radio button group that 
this button belongs to")]
                public string Group {

Modified: trunk/stetic/libstetic/wrapper/RadioMenuItem.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/RadioMenuItem.cs     2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/wrapper/RadioMenuItem.cs     2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -36,14 +36,25 @@
                protected override void GladeImport (string className, string 
id, Hashtable props)
                {
                        string group = GladeUtils.ExtractProperty ("group", 
props);
+                       string active = GladeUtils.ExtractProperty ("active", 
props);
                        base.GladeImport (className, id, props);
 
                        if (group != null)
                                Group = group;
                        else
                                Group = Wrapped.Name;
+                       if (active == "True")
+                               ((Gtk.RadioMenuItem)Wrapped).Active = true;
                }
 
+               public override void GladeExport (out string className, out 
string id, out Hashtable props)
+               {
+                       base.GladeExport (out className, out id, out props);
+                       string group = GroupManager.GladeGroupName (Wrapped);
+                       if (group != id)
+                               props["group"] = group;
+               }
+
                [Editor (typeof (Stetic.Editor.GroupPicker))]
                [Description ("Group", "The name of the radio button group that 
this menu item belongs to")]
                public string Group {

Modified: trunk/stetic/libstetic/wrapper/RadioToolButton.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/RadioToolButton.cs   2005-05-24 19:17:54 UTC 
(rev 44938)
+++ trunk/stetic/libstetic/wrapper/RadioToolButton.cs   2005-05-24 19:27:21 UTC 
(rev 44939)
@@ -39,14 +39,25 @@
                protected override void GladeImport (string className, string 
id, Hashtable props)
                {
                        string group = GladeUtils.ExtractProperty ("group", 
props);
+                       string active = GladeUtils.ExtractProperty ("active", 
props);
                        base.GladeImport (className, id, props);
 
                        if (group != null)
                                Group = group;
                        else
                                Group = Wrapped.Name;
+                       if (active == "True")
+                               ((Gtk.RadioToolButton)Wrapped).Active = true;
                }
 
+               public override void GladeExport (out string className, out 
string id, out Hashtable props)
+               {
+                       base.GladeExport (out className, out id, out props);
+                       string group = GroupManager.GladeGroupName (Wrapped);
+                       if (group != id)
+                               props["group"] = group;
+               }
+
                [Editor (typeof (Stetic.Editor.GroupPicker))]
                [Description ("Group", "The name of the radio button group that 
this button belongs to")]
                public string Group {

Modified: trunk/stetic/libstetic/wrapper/Widget.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Widget.cs    2005-05-24 19:17:54 UTC (rev 
44938)
+++ trunk/stetic/libstetic/wrapper/Widget.cs    2005-05-24 19:27:21 UTC (rev 
44939)
@@ -108,26 +108,30 @@
 
                Widget FindWrapper (Gtk.Widget top, int x, int y)
                {
+                       Widget wrapper;
+
                        Gtk.Container container = top as Gtk.Container;
-                       if (container == null)
-                               return Lookup (top);
+                       if (container != null) {
+                               foreach (Gtk.Widget child in 
container.AllChildren) {
+                                       if (!child.IsDrawable)
+                                               continue;
 
-                       foreach (Gtk.Widget child in container.AllChildren) {
-                               if (!child.IsDrawable)
-                                       continue;
-
-                               Gdk.Rectangle alloc = child.Allocation;
-                               if (alloc.Contains (x, y)) {
-                                       Widget wrapper;
-                                       if (child.GdkWindow == top.GdkWindow)
-                                               wrapper = FindWrapper (child, 
x, y);
-                                       else
-                                               wrapper = FindWrapper (child, x 
- alloc.X, y - alloc.Y);
-                                       if (wrapper != null)
-                                               return wrapper;
+                                       Gdk.Rectangle alloc = child.Allocation;
+                                       if (alloc.Contains (x, y)) {
+                                               if (child.GdkWindow == 
top.GdkWindow)
+                                                       wrapper = FindWrapper 
(child, x, y);
+                                               else
+                                                       wrapper = FindWrapper 
(child, x - alloc.X, y - alloc.Y);
+                                               if (wrapper != null)
+                                                       return wrapper;
+                                       }
                                }
                        }
 
+                       wrapper = Lookup (top);
+                       if (wrapper != null && wrapper.Unselectable)
+                               return null;
+
                        return Lookup (top);
                }
 
@@ -195,6 +199,8 @@
                public virtual bool HExpandable { get { return false; } }
                public virtual bool VExpandable { get { return false; } }
 
+               public bool Unselectable;
+
                bool window_visible;
                [GladeProperty]
                public bool Visible {

Modified: trunk/stetic/stetic/Glade.cs
===================================================================
--- trunk/stetic/stetic/Glade.cs        2005-05-24 19:17:54 UTC (rev 44938)
+++ trunk/stetic/stetic/Glade.cs        2005-05-24 19:27:21 UTC (rev 44939)
@@ -161,7 +161,7 @@
                        if (container != null) {
                                XmlElement elt;
 
-                               foreach (Gtk.Widget child in 
container.RealChildren) {
+                               foreach (Gtk.Widget child in 
container.GladeChildren) {
 #if FIXME
                                        if (!site.Occupied) {
                                                child = doc.CreateElement 
("child");

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

Reply via email to