Bind() static private method

static private Bind ( IProject proj, ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, bool initialized ) : void
proj IProject
klass ClassDescriptor
wrapper ObjectWrapper
wrapped object
initialized bool
return void
Esempio n. 1
0
        static public void Read(ObjectWrapper wrapper, XmlElement elem)
        {
            string className = elem.GetAttribute("class");

            if (className == null)
            {
                throw new GladeException("<widget> node with no class name");
            }

            ClassDescriptor klass = Registry.LookupClassByName(className);

            if (klass == null)
            {
                throw new GladeException("No stetic ClassDescriptor for " + className);
            }

            Gtk.Widget widget = (Gtk.Widget)wrapper.Wrapped;
            if (widget == null)
            {
                widget = (Gtk.Widget)klass.CreateInstance(wrapper.Project);
                ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true);
            }

            widget.Name = elem.GetAttribute("id");

            ReadMembers(klass, wrapper, widget, elem);

            if (!(widget is Gtk.Window))
            {
                widget.ShowAll();
            }
        }
        public object NewInstance(IProject proj, bool initialize)
        {
            object ob = CreateInstance(proj);

            string name = WrappedTypeName.ToLower() + (++counter).ToString();
            int    i    = name.LastIndexOf('.');

            if (i != -1)
            {
                if (i < name.Length)
                {
                    name = name.Substring(i + 1);
                }
                else
                {
                    name = name.Replace(".", "");
                }
            }

            ObjectWrapper ow = CreateWrapper();

            try
            {
                ow.Loading = true;
                ObjectWrapper.Bind(proj, this, ow, ob, !initialize);

                // Initialize the properties after creating the wrapper, since some properties
                // may be implemented in the wrapper

                foreach (ItemGroup group in groups)
                {
                    foreach (ItemDescriptor item in group)
                    {
                        PropertyDescriptor prop = item as PropertyDescriptor;
                        if (prop != null && prop.InitWithName)
                        {
                            prop.SetValue(ob, name);
                        }
                    }
                }
            }
            finally
            {
                ow.Loading = false;
            }

            return(ob);
        }
Esempio n. 3
0
        public object NewInstance(IProject proj, bool initialize)
        {
            object ob = CreateInstance(proj);

            string name = WrappedTypeName.ToLower() + (++counter).ToString();
            int    i    = name.LastIndexOf('.');

            if (i != -1)
            {
                if (i < name.Length)
                {
                    name = name.Substring(i + 1);
                }
                else
                {
                    name = name.Replace(".", "");
                }
            }

            foreach (ItemGroup group in groups)
            {
                foreach (ItemDescriptor item in group)
                {
                    PropertyDescriptor prop = item as PropertyDescriptor;
                    if (prop != null && prop.InitWithName)
                    {
                        prop.SetValue(ob, name);
                    }
                }
            }

            ObjectWrapper ow = CreateWrapper();

            ObjectWrapper.Bind(proj, this, ow, ob, !initialize);
            return(ob);
        }
Esempio n. 4
0
        static public void ImportWidget(ObjectWrapper wrapper, XmlElement elem)
        {
            string className = elem.GetAttribute("class");

            if (className == null)
            {
                throw new GladeException("<widget> node with no class name");
            }

            ClassDescriptor klassBase = Registry.LookupClassByCName(className);

            if (klassBase == null)
            {
                throw new GladeException("No stetic ClassDescriptor for " + className);
            }

            TypedClassDescriptor klass = klassBase as TypedClassDescriptor;

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

            ReadSignals(klass, wrapper, elem);

            Hashtable rawProps, overrideProps;

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

            string[]     propNames;
            GLib.Value[] propVals;
            ParseProperties(klass.WrappedType, false, rawProps.Values,
                            out propNames, out propVals);

            Gtk.Widget widget;

            if (wrapper.Wrapped == null)
            {
                if (className == "GtkWindow" || className == "GtkDialog")
                {
                    widget = (Gtk.Widget)klass.CreateInstance(wrapper.Project);
                    ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true);
                    SetProperties(klass, widget, propNames, propVals);
                }
                else
                {
                    IntPtr raw = gtksharp_object_newv(klass.GType.Val, propNames.Length, propNames, propVals);
                    if (raw == IntPtr.Zero)
                    {
                        throw new GladeException("Could not create widget", className);
                    }
                    widget = (Gtk.Widget)GLib.Object.GetObject(raw, true);
                    if (widget == null)
                    {
                        gtk_object_sink(raw);
                        throw new GladeException("Could not create gtk# wrapper", className);
                    }
                    ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true);
                }
            }
            else
            {
                widget = (Gtk.Widget)wrapper.Wrapped;
                for (int i = 0; i < propNames.Length; i++)
                {
                    g_object_set_property(widget.Handle, propNames[i], ref propVals[i]);
                }
            }
            MarkTranslatables(widget, rawProps);

            widget.Name = elem.GetAttribute("id");

            SetOverrideProperties(wrapper, overrideProps);
            MarkTranslatables(widget, overrideProps);
        }