Author: danw
Date: 2005-02-27 20:47:06 -0500 (Sun, 27 Feb 2005)
New Revision: 41272

Modified:
   trunk/stetic/ChangeLog
   trunk/stetic/glue/value.c
   trunk/stetic/libstetic/GladeUtils.cs
   trunk/stetic/libstetic/wrapper/Label.cs
   trunk/stetic/libstetic/wrapper/RadioButton.cs
   trunk/stetic/libstetic/wrapper/Table.cs
   trunk/stetic/libstetic/wrapper/TextView.cs
   trunk/stetic/libstetic/wrapper/Widget.cs
   trunk/stetic/libstetic/wrapper/Window.cs
   trunk/stetic/stetic/GladeImport.cs
Log:
        * libstetic/GladeUtils.cs (ExtractProperty): utility to remove a
        property from the propNames/propVals lists.
        (HydrateProperties): add some debug messages here

        * libstetic/wrapper/Label.cs (GladeImport): simplify using
        ExtractProperty

        * libstetic/wrapper/RadioButton.cs (GladeImport): handle "group"

        * libstetic/wrapper/Table.cs (GladeImport): force a Sync after
        import
        (Sync): don't knock out conflicting sites if they're full (which
        will happen temporarily during glade import, since table.Add(foo)
        will always put it at 0,0).

        * libstetic/wrapper/TextView.cs (GladeImport): handle "text"

        * libstetic/wrapper/Widget.cs (GladeImport): extract "visible" and
        "has_default"; fake out "visible", hold off on setting
        "has_default" until the import is complete (since it requires a
        parent window).

        * libstetic/wrapper/Window.cs (Wrap): force TypeHint to "Normal"
        so the WM doesn't do annoying things to us 
        (GladeImport): extract "modal" and "type_hint"
        (TypeHint): add a shadow property for this
        
        * stetic/GladeImport.cs (CreateWidget, AddChildren): merge these
        together and reduce redundant code.


Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog      2005-02-28 00:11:58 UTC (rev 41271)
+++ trunk/stetic/ChangeLog      2005-02-28 01:47:06 UTC (rev 41272)
@@ -1,3 +1,35 @@
+2005-02-27  Dan Winship  <[EMAIL PROTECTED]>
+
+       * libstetic/GladeUtils.cs (ExtractProperty): utility to remove a
+       property from the propNames/propVals lists.
+       (HydrateProperties): add some debug messages here
+
+       * libstetic/wrapper/Label.cs (GladeImport): simplify using
+       ExtractProperty
+
+       * libstetic/wrapper/RadioButton.cs (GladeImport): handle "group"
+
+       * libstetic/wrapper/Table.cs (GladeImport): force a Sync after
+       import
+       (Sync): don't knock out conflicting sites if they're full (which
+       will happen temporarily during glade import, since table.Add(foo)
+       will always put it at 0,0).
+
+       * libstetic/wrapper/TextView.cs (GladeImport): handle "text"
+
+       * libstetic/wrapper/Widget.cs (GladeImport): extract "visible" and
+       "has_default"; fake out "visible", hold off on setting
+       "has_default" until the import is complete (since it requires a
+       parent window).
+
+       * libstetic/wrapper/Window.cs (Wrap): force TypeHint to "Normal"
+       so the WM doesn't do annoying things to us 
+       (GladeImport): extract "modal" and "type_hint"
+       (TypeHint): add a shadow property for this
+       
+       * stetic/GladeImport.cs (CreateWidget, AddChildren): merge these
+       together and reduce redundant code.
+
 2005-02-25  Dan Winship  <[EMAIL PROTECTED]>
 
        Reorganize the glade import code; put all the wacky exceptions

Modified: trunk/stetic/glue/value.c
===================================================================
--- trunk/stetic/glue/value.c   2005-02-28 00:11:58 UTC (rev 41271)
+++ trunk/stetic/glue/value.c   2005-02-28 01:47:06 UTC (rev 41272)
@@ -77,14 +77,31 @@
                break;
        default:
                if (G_TYPE_IS_ENUM (G_VALUE_TYPE (value))) {
-                       GEnumClass *enum_class = g_type_class_ref 
(G_VALUE_TYPE(value));
+                       GEnumClass *enum_class = g_type_class_ref (G_VALUE_TYPE 
(value));
                        GEnumValue *enum_value = g_enum_get_value_by_name 
(enum_class, data);
                        g_type_class_unref (enum_class);
                        if (enum_value) {
                                g_value_set_enum (value, enum_value->value);
                                return TRUE;
                        }
+               } else if (G_TYPE_IS_FLAGS (G_VALUE_TYPE (value))) {
+                       GFlagsClass *flags_class = g_type_class_ref 
(G_VALUE_TYPE (value));
+                       char **flags;
+                       guint i, fval = 0;
+
+                       flags = g_strsplit (data, "|", 0);
+                       for (i = 0; flags[i]; i++) {
+                               GFlagsValue *flags_value = 
g_flags_get_value_by_nick (flags_class, flags[i]);
+                               if (flags_value)
+                                       fval |= flags_value->value;
+                       }
+                       g_strfreev (flags);
+
+                       g_value_set_flags (value, fval);
+                       g_type_class_unref (flags_class);
+                       return TRUE;
                }
+
                return FALSE;
        }
 

Modified: trunk/stetic/libstetic/GladeUtils.cs
===================================================================
--- trunk/stetic/libstetic/GladeUtils.cs        2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/GladeUtils.cs        2005-02-28 01:47:06 UTC (rev 
41272)
@@ -6,11 +6,17 @@
 
        public static class GladeUtils {
 
-               [DllImport("libgobject-2.0-0.dll")]
-               static extern IntPtr g_type_from_name (string name);
+               public static string ExtractProperty (string name, ArrayList 
propNames, ArrayList propVals)
+               {
+                       int index = propNames.IndexOf (name);
+                       if (index == -1)
+                               return null;
 
-               [DllImport("glibsharpglue-2")]
-               static extern IntPtr gtksharp_get_type_id (IntPtr obj);
+                       string value = propVals[index] as string;
+                       propNames.RemoveAt (index);
+                       propVals.RemoveAt (index);
+                       return value;
+               }
 
                [DllImport("libsteticglue")]
                static extern bool stetic_g_value_init_for_property (ref 
GLib.Value value, IntPtr gtype, string propertyName);
@@ -38,16 +44,28 @@
                                else
                                        inited = 
stetic_g_value_init_for_property (ref value, gtype, name);
 
-                               if (!inited || !stetic_g_value_hydrate (ref 
value, strval)) {
+                               if (!inited) {
+                                       Console.WriteLine ("Unrecognized 
{0}property name '{1}'",
+                                                          childprops ? "child 
" : "", name);
                                        names.RemoveAt (i);
                                        strvals.RemoveAt (i);
-                               } else {
-                                       values.Add (value);
-                                       i++;
+                                       continue;
                                }
+                               if (!stetic_g_value_hydrate (ref value, 
strval)) {
+                                       Console.WriteLine ("Could not hydrate 
{0}property '{1}' with value '{2}'",
+                                                          childprops ? "child 
" : "", name, strval);
+                                       names.RemoveAt (i);
+                                       strvals.RemoveAt (i);
+                               }
+
+                               values.Add (value);
+                               i++;
                        }
                }
 
+               [DllImport("libgobject-2.0-0.dll")]
+               static extern IntPtr g_type_from_name (string name);
+
                [DllImport("glibsharpglue-2")]
                static extern IntPtr gtksharp_object_newv (IntPtr gtype, int 
n_params, string[] names, GLib.Value[] vals);
 
@@ -79,6 +97,9 @@
                        return widget;
                }
 
+               [DllImport("glibsharpglue-2")]
+               static extern IntPtr gtksharp_get_type_id (IntPtr obj);
+
                [DllImport("libgobject-2.0-0.dll")]
                static extern void g_object_set_property (IntPtr obj, string 
name, ref GLib.Value val);
 

Modified: trunk/stetic/libstetic/wrapper/Label.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Label.cs     2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/wrapper/Label.cs     2005-02-28 01:47:06 UTC (rev 
41272)
@@ -33,13 +33,9 @@
 
                protected override void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
                {
-                       int index = propNames.IndexOf ("mnemonic_widget");
-                       if (index != -1) {
-                               mnemonic_widget = propVals[index] as string;
-                               propNames.RemoveAt (index);
-                               propVals.RemoveAt (index);
+                       mnemonic_widget = GladeUtils.ExtractProperty 
("mnemonic_widget", propNames, propVals);
+                       if (mnemonic_widget != null)
                                stetic.GladeImportComplete += SetMnemonicWidget;
-                       }
                        base.GladeImport (className, id, propNames, propVals);
                }
 

Modified: trunk/stetic/libstetic/wrapper/RadioButton.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/RadioButton.cs       2005-02-28 00:11:58 UTC 
(rev 41271)
+++ trunk/stetic/libstetic/wrapper/RadioButton.cs       2005-02-28 01:47:06 UTC 
(rev 41272)
@@ -43,6 +43,32 @@
                        }
                }
 
+               string group;
+
+               protected override void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
+               {
+                       group = GladeUtils.ExtractProperty ("group", propNames, 
propVals);
+                       base.GladeImport (className, id, propNames, propVals);
+
+                       if (group != null)
+                               stetic.GladeImportComplete += SetGroup;
+                       else {
+                               GroupList.Add (((Gtk.Widget)Wrapped).Name);
+                               GroupLeaders.Add (Wrapped);
+                       }
+               }
+
+               void SetGroup ()
+               {
+                       Gtk.Widget leader = stetic.LookupWidgetById (group);
+                       if (leader != null) {
+                               int index = GroupLeaders.IndexOf (leader);
+                               if (index != -1)
+                                       Group = index;
+                       }
+                       stetic.GladeImportComplete -= SetGroup;
+               }
+
                [Editor (typeof (Stetic.Editor.GroupPicker))]
                [Description ("Group", "The name of the radio button group that 
this button belongs to")]
                public int Group {

Modified: trunk/stetic/libstetic/wrapper/Table.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Table.cs     2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/wrapper/Table.cs     2005-02-28 01:47:06 UTC (rev 
41272)
@@ -41,6 +41,18 @@
                        Sync ();
                }
 
+               protected override void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
+               {
+                       stetic.GladeImportComplete += DoSync;
+                       base.GladeImport (className, id, propNames, propVals);
+               }
+
+               void DoSync ()
+               {
+                       Sync ();
+                       stetic.GladeImportComplete -= DoSync;
+               }
+
                private Gtk.Table table {
                        get {
                                return (Gtk.Table)Wrapped;
@@ -96,10 +108,13 @@
                                        grid[top,left] = child as WidgetSite;
                                else
                                        table.Remove (child);
-                        }
+                       }
 
                        // Now fill in the real widgets, knocking out any 
placeholders
-                       // they overlap.
+                       // they overlap. (If there are real widgets that overlap
+                       // placeholders, neither will be knocked out, and the 
layout
+                       // will probably end up wrong as well. But this 
situation
+                       // happens at least temporarily during glade import.)
                         foreach (Gtk.Widget child in children) {
                                site = (WidgetSite) child;
                                if (!site.Occupied)
@@ -113,7 +128,8 @@
 
                                 for (row = top; row < bottom; row++) {
                                         for (col = left; col < right; col++) {
-                                               if (grid[row,col] != null)
+                                               site = grid[row,col];
+                                               if (site != null && 
!site.Occupied)
                                                        table.Remove 
(grid[row,col]);
                                                 grid[row,col] = child as 
WidgetSite;
                                         }

Modified: trunk/stetic/libstetic/wrapper/TextView.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/TextView.cs  2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/wrapper/TextView.cs  2005-02-28 01:47:06 UTC (rev 
41272)
@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 
 namespace Stetic.Wrapper {
 
@@ -32,6 +33,13 @@
                        ((Gtk.TextView)Wrapped).Buffer.Changed += 
Buffer_Changed;
                }
 
+               protected override void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
+               {
+                       string text = GladeUtils.ExtractProperty ("text", 
propNames, propVals);
+                       base.GladeImport (className, id, propNames, propVals);
+                       Text = text;
+               }
+
                [Editor (typeof (Stetic.Editor.Text))]
                [Description ("Text", "The initial text to display in the Text 
View")]
                public string Text {

Modified: trunk/stetic/libstetic/wrapper/Widget.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Widget.cs    2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/wrapper/Widget.cs    2005-02-28 01:47:06 UTC (rev 
41272)
@@ -44,11 +44,23 @@
 
                protected virtual void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
                {
+                       string visible = GladeUtils.ExtractProperty ("visible", 
propNames, propVals);
+                       string has_default = GladeUtils.ExtractProperty 
("has_default", propNames, propVals);
                        Gtk.Widget widget = GladeUtils.CreateWidget (className, 
propNames, propVals);
                        widget.Name = id;
                        Wrap (widget, true);
+
+                       Visible = (visible == "True");
+                       if (has_default == "True")
+                               stetic.GladeImportComplete += SetDefault;
                }
 
+               void SetDefault ()
+               {
+                       ((Gtk.Widget)Wrapped).HasDefault = true;
+                       stetic.GladeImportComplete -= SetDefault;
+               }
+
                public static new Widget Lookup (GLib.Object obj)
                {
                        return Stetic.ObjectWrapper.Lookup (obj) as 
Stetic.Wrapper.Widget;

Modified: trunk/stetic/libstetic/wrapper/Window.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Window.cs    2005-02-28 00:11:58 UTC (rev 
41271)
+++ trunk/stetic/libstetic/wrapper/Window.cs    2005-02-28 01:47:06 UTC (rev 
41272)
@@ -1,5 +1,6 @@
 using GLib;
 using System;
+using System.Collections;
 
 namespace Stetic.Wrapper {
 
@@ -43,9 +44,11 @@
 
                protected override void Wrap (object obj, bool initialized)
                {
+                       Gtk.Window window = (Gtk.Window)obj;
+
+                       window.TypeHint = Gdk.WindowTypeHint.Normal;
                        base.Wrap (obj, initialized);
 
-                       Gtk.Window window = (Gtk.Window)Wrapped;
                        if (!initialized) {
                                window.Title = window.Name;
 
@@ -58,6 +61,17 @@
                        window.DeleteEvent += DeleteEvent;
                }
 
+               protected override void GladeImport (string className, string 
id, ArrayList propNames, ArrayList propVals)
+               {
+                       string modal = GladeUtils.ExtractProperty ("modal", 
propNames, propVals);
+                       string type_hint = GladeUtils.ExtractProperty 
("type_hint", propNames, propVals);
+                       base.GladeImport (className, id, propNames, propVals);
+                       Modal = (modal == "True");
+
+                       if (type_hint != null && type_hint.StartsWith 
("GDK_WINDOW_TYPE_HINT_"))
+                               TypeHint = (Gdk.WindowTypeHint) Enum.Parse 
(typeof (Gdk.WindowTypeHint), type_hint.Substring (21), true);
+               }
+
                [ConnectBefore]
                void DeleteEvent (object obj, Gtk.DeleteEventArgs args)
                {
@@ -68,7 +82,7 @@
                public override bool HExpandable { get { return true; } }
                public override bool VExpandable { get { return true; } }
 
-               // We don't want to actually set the underlying "modal" 
property;
+               // We don't want to actually set the underlying properties for 
these;
                // that would be annoying to interact with.
                bool modal;
                public bool Modal {
@@ -76,8 +90,18 @@
                                return modal;
                        }
                        set {
-                               modal = Modal;
+                               modal = value;
                        }
                }
+
+               Gdk.WindowTypeHint typeHint;
+               public Gdk.WindowTypeHint TypeHint {
+                       get {
+                               return typeHint;
+                       }
+                       set {
+                               typeHint = value;
+                       }
+               }
        }
 }

Modified: trunk/stetic/stetic/GladeImport.cs
===================================================================
--- trunk/stetic/stetic/GladeImport.cs  2005-02-28 00:11:58 UTC (rev 41271)
+++ trunk/stetic/stetic/GladeImport.cs  2005-02-28 01:47:06 UTC (rev 41272)
@@ -46,7 +46,7 @@
 
                        project.BeginGladeImport ();
                        foreach (XmlNode toplevel in node.SelectNodes 
("widget")) {
-                               Widget w = CreateWidget (project, toplevel);
+                               Widget w = CreateWidget (project, null, null, 
toplevel);
                                if (w == null)
                                        continue;
                                project.AddWindow (w);
@@ -64,63 +64,50 @@
                [DllImport("libsteticglue")]
                static extern bool stetic_g_value_init_for_child_property (ref 
GLib.Value value, string className, string propertyName);
 
-               static Widget CreateWidget (Project project, XmlNode wnode)
+               static Widget CreateWidget (Project project, 
Stetic.Wrapper.Container parent, XmlNode thischild, XmlNode widget)
                {
-                       string className = wnode.Attributes["class"].Value;
-                       string id = wnode.Attributes["id"].Value;
+                       string className = widget.Attributes["class"].Value;
+                       string id = widget.Attributes["id"].Value;
 
                        ArrayList propNames, propVals;
-                       ExtractProperties (wnode.SelectNodes ("property"), out 
propNames, out propVals);
+                       ExtractProperties (widget.SelectNodes ("property"), out 
propNames, out propVals);
 
-                       ObjectWrapper wrapper = 
Stetic.ObjectWrapper.GladeImport (project, className, id, propNames, propVals);
+                       ObjectWrapper wrapper;
+                       if (thischild == null) {
+                               wrapper = Stetic.ObjectWrapper.GladeImport 
(project, className, id, propNames, propVals);
+                       } else if (thischild.Attributes["internal-child"] != 
null) {
+                               wrapper = parent.GladeSetInternalChild 
(thischild.Attributes["internal-child"].Value,
+                                                                       
className, id,
+                                                                       
propNames, propVals);
+                       } else {
+                               ArrayList packingNames, packingVals;
+                               ExtractProperties (thischild.SelectNodes 
("packing/property"),
+                                                  out packingNames, out 
packingVals);
+                               wrapper = parent.GladeImportChild (className, 
id,
+                                                                  propNames, 
propVals,
+                                                                  
packingNames, packingVals);
+                       }
+
                        if (wrapper == null) {
                                Console.WriteLine ("Could not create stetic 
wrapper for type {0}", className);
                                return null;
                        }
 
-                       if (wrapper is Stetic.Wrapper.Container) {
-                               AddChildren (project, 
(Stetic.Wrapper.Container)wrapper, wnode.SelectNodes ("child"));
+                       Stetic.Wrapper.Container container = wrapper as 
Stetic.Wrapper.Container;
+                       if (container != null) {
+                               foreach (XmlNode child in widget.SelectNodes 
("child")) {
+                                       widget = child.SelectSingleNode 
("widget");
+
+                                       if (widget == null)
+                                               container.AddPlaceholder ();
+                                       else
+                                               CreateWidget (project, 
container, child, widget);
+                               }
                        }
 
                        return (Gtk.Widget)wrapper.Wrapped;
                }
 
-               static void AddChildren (Project project, 
Stetic.Wrapper.Container wrapper, XmlNodeList children)
-               {
-                       foreach (XmlNode child in children) {
-                               XmlNode wnode = child.SelectSingleNode 
("widget");
-
-                               if (wnode == null) {
-                                       wrapper.AddPlaceholder ();
-                                       continue;
-                               }
-
-                               string className = 
wnode.Attributes["class"].Value;
-                               string id = wnode.Attributes["id"].Value;
-
-                               ArrayList propNames, propVals;
-                               ExtractProperties (wnode.SelectNodes 
("property"),
-                                                  out propNames, out propVals);
-
-                               ObjectWrapper childWrapper;
-                               if (child.Attributes["internal-child"] != null) 
{
-                                       childWrapper = 
wrapper.GladeSetInternalChild (child.Attributes["internal-child"].Value,
-                                                                               
      className, id,
-                                                                               
      propNames, propVals);
-                               } else {
-                                       ArrayList packingNames, packingVals;
-                                       ExtractProperties (child.SelectNodes 
("packing/property"),
-                                                          out packingNames, 
out packingVals);
-                                       childWrapper = wrapper.GladeImportChild 
(className, id,
-                                                                               
 propNames, propVals,
-                                                                               
 packingNames, packingVals);
-                               }
-
-                               if (childWrapper is Stetic.Wrapper.Container)
-                                       AddChildren (project, 
(Stetic.Wrapper.Container)childWrapper, wnode.SelectNodes ("child"));
-                       }
-               }
-
                static void ExtractProperties (XmlNodeList nodes, out ArrayList 
names, out ArrayList values)
                {
                        names = new ArrayList ();

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

Reply via email to