Example #1
0
        static public void SetPacking(Stetic.Wrapper.Container.ContainerChild wrapper, XmlElement child_elem)
        {
            XmlElement packing = child_elem["packing"];

            if (packing == null)
            {
                return;
            }

            Gtk.Container.ContainerChild cc = wrapper.Wrapped as Gtk.Container.ContainerChild;
            ClassDescriptor klass           = wrapper.ClassDescriptor;

            ReadMembers(klass, wrapper, cc, packing);
        }
Example #2
0
        static public void SetPacking(Stetic.Wrapper.Container.ContainerChild wrapper, XmlElement child_elem)
        {
            XmlElement packing = child_elem["packing"];

            if (packing == null)
            {
                return;
            }

            Gtk.Container.ContainerChild cc = wrapper.Wrapped as Gtk.Container.ContainerChild;

            TypedClassDescriptor klass = wrapper.ClassDescriptor as TypedClassDescriptor;

            if (klass == null)
            {
                throw new GladeException("The widget class " + cc.GetType() + " is not supported by Glade");
            }

            Hashtable rawProps, overrideProps;

            ExtractProperties(klass, packing, out rawProps, out overrideProps);

            string[]     propNames;
            GLib.Value[] propVals;
            ParseProperties(cc.Parent.GetType(), true, rawProps.Values,
                            out propNames, out propVals);

            for (int i = 0; i < propNames.Length; i++)
            {
                cc.Parent.ChildSetProperty(cc.Child, propNames[i], propVals[i]);
            }
            MarkTranslatables(cc, rawProps);

            SetOverrideProperties(wrapper, overrideProps);
            MarkTranslatables(cc, overrideProps);
        }
Example #3
0
        static string PropToString(ObjectWrapper wrapper, TypedPropertyDescriptor prop)
        {
            object value;

            if (!prop.GladeOverride)
            {
                Stetic.Wrapper.Container.ContainerChild ccwrap = wrapper as Stetic.Wrapper.Container.ContainerChild;
                GLib.Value gval;

                if (ccwrap != null)
                {
                    Gtk.Container.ContainerChild cc = (Gtk.Container.ContainerChild)ccwrap.Wrapped;
                    gval = new GLib.Value((GLib.GType)prop.PropertyType);
                    gtk_container_child_get_property(cc.Parent.Handle, cc.Child.Handle, prop.GladeName, ref gval);
                }
                else
                {
                    Gtk.Widget widget = wrapper.Wrapped as Gtk.Widget;
                    gval = new GLib.Value(widget, prop.GladeName);
                    g_object_get_property(widget.Handle, prop.GladeName, ref gval);
                }
                value = gval.Val;
            }
            else
            {
                value = prop.GetValue(wrapper.Wrapped);
            }
            if (value == null)
            {
                return(null);
            }

            // If the property has its default value, we don't need to write it
            if (prop.HasDefault && prop.ParamSpec.IsDefaultValue(value))
            {
                return(null);
            }

            if (value is Gtk.Adjustment)
            {
                Gtk.Adjustment adj = value as Gtk.Adjustment;
                return(String.Format("{0:G} {1:G} {2:G} {3:G} {4:G} {5:G}",
                                     adj.Value, adj.Lower, adj.Upper,
                                     adj.StepIncrement, adj.PageIncrement,
                                     adj.PageSize));
            }
            else if (value is Enum && prop.ParamSpec != null)
            {
                IntPtr klass = g_type_class_ref(((GLib.GType)prop.PropertyType).Val);

                if (prop.PropertyType.IsDefined(typeof(FlagsAttribute), false))
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    uint val = (uint)System.Convert.ChangeType(value, typeof(uint));

                    while (val != 0)
                    {
                        IntPtr flags_value = g_flags_get_first_value(klass, val);
                        if (flags_value == IntPtr.Zero)
                        {
                            break;
                        }
                        IntPtr fval = Marshal.ReadIntPtr(flags_value);
                        val &= ~(uint)fval;

                        IntPtr name = Marshal.ReadIntPtr(flags_value, Marshal.SizeOf(typeof(IntPtr)));
                        if (name != IntPtr.Zero)
                        {
                            if (sb.Length != 0)
                            {
                                sb.Append('|');
                            }
                            sb.Append(GLib.Marshaller.Utf8PtrToString(name));
                        }
                    }

                    g_type_class_unref(klass);
                    return(sb.ToString());
                }
                else
                {
                    int    val        = (int)System.Convert.ChangeType(value, typeof(int));
                    IntPtr enum_value = g_enum_get_value(klass, val);
                    g_type_class_unref(klass);

                    IntPtr name = Marshal.ReadIntPtr(enum_value, Marshal.SizeOf(typeof(IntPtr)));
                    return(GLib.Marshaller.Utf8PtrToString(name));
                }
            }
            else if (value is bool)
            {
                return((bool)value ? "True" : "False");
            }
            else
            {
                return(value.ToString());
            }
        }