Inheritance: ClassDescriptor
        public TypedSignalDescriptor(XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base(elem, group, klass)
        {
            Load(elem);

            EventInfo  eventInfo = FindEvent(klass.WrapperType, klass.WrappedType, name);
            MethodInfo handler   = eventInfo.EventHandlerType.GetMethod("Invoke");

            if (elem.HasAttribute("glade-name"))
            {
                gladeName = elem.GetAttribute("glade-name");
            }
            else
            {
                object[] att = eventInfo.GetCustomAttributes(typeof(GLib.SignalAttribute), true);
                if (att.Length > 0)
                {
                    gladeName = ((GLib.SignalAttribute)att[0]).CName;
                }
            }

            handlerTypeName       = eventInfo.EventHandlerType.FullName;
            handlerReturnTypeName = handler.ReturnType.FullName;

            ParameterInfo[] pars = handler.GetParameters();
            handlerParameters = new ParameterDescriptor [pars.Length];
            for (int n = 0; n < pars.Length; n++)
            {
                handlerParameters [n] = new ParameterDescriptor(pars[n].Name, pars [n].ParameterType.FullName);
            }
        }
Example #2
0
        static void ReadSignals(TypedClassDescriptor klass, ObjectWrapper wrapper, XmlElement elem)
        {
            Stetic.Wrapper.Widget ob = wrapper as Stetic.Wrapper.Widget;
            if (ob == null)
            {
                return;
            }

            foreach (ItemGroup group in klass.SignalGroups)
            {
                foreach (TypedSignalDescriptor signal in group)
                {
                    if (signal.GladeName == null)
                    {
                        continue;
                    }

                    XmlElement signal_elem = elem.SelectSingleNode("signal[@name='" + signal.GladeName + "']") as XmlElement;
                    if (signal_elem == null)
                    {
                        continue;
                    }

                    string handler = signal_elem.GetAttribute("handler");
                    bool   after   = signal_elem.GetAttribute("after") == "yes";
                    ob.Signals.Add(new Signal(signal, handler, after));
                }
            }
        }
 public override void ResetValue(object instance)
 {
     // This is a hack because there is no managed way of getting
     // the default value of a GObject property. The call to LoadDefaultValues
     // will guess the default values from a dummy instance
     if (!defaultSet)
     {
         ObjectWrapper        ww = ObjectWrapper.Lookup(instance);
         TypedClassDescriptor td = ww.ClassDescriptor as TypedClassDescriptor;
         if (td != null)
         {
             td.LoadDefaultValues();
         }
         defaultSet = true;
     }
     base.ResetValue(instance);
 }
Example #4
0
 static void SetProperties(TypedClassDescriptor klass, Gtk.Widget widget, string[] propNames, GLib.Value[] propVals)
 {
     for (int n = 0; n < propNames.Length; n++)
     {
         foreach (ItemGroup grp in klass.ItemGroups)
         {
             foreach (ItemDescriptor it in grp)
             {
                 if (it is TypedPropertyDescriptor)
                 {
                     TypedPropertyDescriptor prop = (TypedPropertyDescriptor)it;
                     if (prop.GladeName == propNames[n])
                     {
                         prop.SetValue(widget, propVals[n].Val);
                     }
                 }
             }
         }
     }
 }
		public TypedSignalDescriptor (XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base (elem, group, klass)
		{
			Load (elem);

			EventInfo eventInfo = FindEvent (klass.WrapperType, klass.WrappedType, name);
			MethodInfo handler = eventInfo.EventHandlerType.GetMethod ("Invoke");
			
			if (elem.HasAttribute ("glade-name"))
				gladeName = elem.GetAttribute ("glade-name");
			else {
				object[] att = eventInfo.GetCustomAttributes (typeof(GLib.SignalAttribute), true);
				if (att.Length > 0)
					gladeName = ((GLib.SignalAttribute)att[0]).CName;
			}
			
			handlerTypeName = eventInfo.EventHandlerType.FullName;
			handlerReturnTypeName = handler.ReturnType.FullName;
			
			ParameterInfo[] pars = handler.GetParameters ();
			handlerParameters = new ParameterDescriptor [pars.Length];
			for (int n=0; n<pars.Length; n++)
				handlerParameters [n] = new ParameterDescriptor (pars[n].Name, pars [n].ParameterType.FullName);
		}
Example #6
0
        static void ExtractProperties(TypedClassDescriptor klass, XmlElement elem,
                                      out Hashtable rawProps, out Hashtable overrideProps)
        {
            rawProps      = new Hashtable();
            overrideProps = new Hashtable();
            foreach (ItemGroup group in klass.ItemGroups)
            {
                foreach (ItemDescriptor item in group)
                {
                    TypedPropertyDescriptor prop = item as TypedPropertyDescriptor;
                    if (prop == null)
                    {
                        continue;
                    }
                    prop = prop.GladeProperty;
                    if (prop.GladeName == null)
                    {
                        continue;
                    }

                    XmlNode prop_node = elem.SelectSingleNode("property[@name='" + prop.GladeName + "']");
                    if (prop_node == null)
                    {
                        continue;
                    }

                    if (prop.GladeOverride)
                    {
                        overrideProps[prop] = prop_node;
                    }
                    else
                    {
                        rawProps[prop] = prop_node;
                    }
                }
            }
        }
Example #7
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 #8
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);
        }
        public TypedClassDescriptor(Assembly assembly, XmlElement elem)
        {
            bool inheritedWrapper = false;

            wrapped = Registry.GetType(elem.GetAttribute("type"), true);
            if (wrapped != null)
            {
                ConstructorInfo[] cInfos = wrapped.GetConstructors();
                foreach (ConstructorInfo ci in cInfos)
                {
                    if (ci.GetParameters().Length == 0)
                    {
                        cinfoNoParams = ci;
                        break;
                    }
                }
            }

            if (elem.HasAttribute("wrapper"))
            {
                wrapper = Registry.GetType(elem.GetAttribute("wrapper"), true);
            }
            else
            {
                inheritedWrapper = true;
                string baseClass = elem.GetAttribute("base-type");
                if (baseClass.Length > 0)
                {
                    // If a base type is specified, use the wrapper of that base type
                    TypedClassDescriptor parent = Registry.LookupClassByName(baseClass) as TypedClassDescriptor;
                    if (parent != null)
                    {
                        wrapper = parent.WrapperType;
                    }
                }
                else
                {
                    for (Type type = wrapped.BaseType; type != null; type = type.BaseType)
                    {
                        TypedClassDescriptor parent = Registry.LookupClassByName(type.FullName) as TypedClassDescriptor;
                        if (parent != null)
                        {
                            wrapper = parent.WrapperType;
                            break;
                        }
                    }
                }
                if (wrapper == null)
                {
                    throw new ArgumentException(string.Format("No wrapper type for class {0}", wrapped.FullName));
                }
            }

            gtype = (GLib.GType)wrapped;
            cname = gtype.ToString();

            string iconname = elem.GetAttribute("icon");

            if (iconname.Length > 0)
            {
                try {
                    // Using the pixbuf resource constructor generates a gdk warning.
                    Gdk.PixbufLoader loader = new Gdk.PixbufLoader(assembly, iconname);
                    icon = loader.Pixbuf;
                } catch {
                    Console.WriteLine("Could not load icon: " + iconname);
                    icon = GetDefaultIcon();
                }
            }
            else
            {
                icon = GetDefaultIcon();
            }

            BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;

            // If the wrapper is inherited from a base class, ignore the CreateInstance method
            // since it is going to create an instance of the base class.
            if (!inheritedWrapper)
            {
                ctorMethodInfoWithClass = wrapper.GetMethod("CreateInstance", flags, null, new Type[] { typeof(ClassDescriptor) }, null);
                if (ctorMethodInfoWithClass == null)
                {
                    ctorMethodInfo = wrapper.GetMethod("CreateInstance", flags, null, Type.EmptyTypes, null);
                }
            }

            // Look for a constructor even if a CreateInstance method was
            // found, since it may return null.
            cinfo = wrapped.GetConstructor(Type.EmptyTypes);
            if (cinfo == null)
            {
                useGTypeCtor = true;
                cinfo        = wrapped.GetConstructor(new Type[] { typeof(IntPtr) });
            }

            Load(elem);
        }
        public TypedPropertyDescriptor(XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base(elem, group, klass)
        {
            this.klass = klass;
            string propertyName = elem.GetAttribute("name");
            int    dot          = propertyName.IndexOf('.');

            if (dot != -1)
            {
                // Sub-property (eg, "Alignment.Value")
                memberInfo        = FindProperty(klass.WrapperType, klass.WrappedType, propertyName.Substring(0, dot));
                isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
                gladeProperty     = new TypedPropertyDescriptor(isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name);
                propertyInfo      = FindProperty(memberInfo.PropertyType, propertyName.Substring(dot + 1));
            }
            else
            {
                // Basic simple property
                propertyInfo      = FindProperty(klass.WrapperType, klass.WrappedType, propertyName);
                isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper));
            }

            // Wrapper properties that override widgets properties (using the same name)
            // must be considered runtime properties (will be available at run-time).
            if (!isWrapperProperty || klass.WrappedType.GetProperty(propertyName) != null)
            {
                isRuntimeProperty = true;
            }

            if (!IsInternal && propertyInfo.PropertyType.IsEnum &&
                Registry.LookupEnum(propertyInfo.PropertyType.FullName) == null)
            {
                throw new ArgumentException("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")");
            }

            pspec = FindPSpec(propertyInfo);

            if (isWrapperProperty && pspec == null)
            {
                PropertyInfo pinfo = klass.WrappedType.GetProperty(propertyInfo.Name, flags);
                if (pinfo != null)
                {
                    pspec = FindPSpec(pinfo);
                }
            }

            if (pspec != null)
            {
                // This information will be overridden by what's specified in the xml file
                description = pspec.Blurb;
                minimum     = pspec.Minimum;
                maximum     = pspec.Maximum;
                label       = propertyName;
                if (!elem.HasAttribute("ignore-default"))
                {
                    hasDefault = Type.GetTypeCode(PropertyType) != TypeCode.Object || PropertyType.IsEnum;
                }
            }
            else
            {
                label         = propertyInfo.Name;
                gladeOverride = true;
            }

            string typeName = elem.GetAttribute("editor");

            if (typeName.Length > 0)
            {
                editorType = Registry.GetType(typeName, false);
            }

            // Look for a default value attribute

            object[] ats = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true);
            if (ats.Length > 0)
            {
                DefaultValueAttribute at = (DefaultValueAttribute)ats [0];
                defaultValue = at.Value;
            }

            // Load default data
            Load(elem);
        }
		static void SetProperties (TypedClassDescriptor klass, Gtk.Widget widget, string[] propNames, GLib.Value[] propVals)
		{
			for (int n=0; n<propNames.Length; n++) {
				foreach (ItemGroup grp in klass.ItemGroups) {
					foreach (ItemDescriptor it in grp) {
						if (it is TypedPropertyDescriptor) {
							TypedPropertyDescriptor prop = (TypedPropertyDescriptor)it;
							if (prop.GladeName == propNames[n]) {
								prop.SetValue (widget, propVals[n].Val);
							}
						}
					}
				}
			}
		}
		static void ReadSignals (TypedClassDescriptor klass, ObjectWrapper wrapper, XmlElement elem)
		{
			Stetic.Wrapper.Widget ob = wrapper as Stetic.Wrapper.Widget;
			if (ob == null) return;
			
			foreach (ItemGroup group in klass.SignalGroups) {
				foreach (TypedSignalDescriptor signal in group) {
					if (signal.GladeName == null)
						continue;

					XmlElement signal_elem = elem.SelectSingleNode ("signal[@name='" + signal.GladeName + "']") as XmlElement;
					if (signal_elem == null)
						continue;
					
					string handler = signal_elem.GetAttribute ("handler");
					bool after = signal_elem.GetAttribute ("after") == "yes";
					ob.Signals.Add (new Signal (signal, handler, after));
				}
			}
		}
		static void ExtractProperties (TypedClassDescriptor klass, XmlElement elem,
					       out Hashtable rawProps, out Hashtable overrideProps)
		{
			rawProps = new Hashtable ();
			overrideProps = new Hashtable ();
			foreach (ItemGroup group in klass.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					TypedPropertyDescriptor prop = item as TypedPropertyDescriptor;
					if (prop == null)
						continue;
					prop = prop.GladeProperty;
					if (prop.GladeName == null)
						continue;

					XmlNode prop_node = elem.SelectSingleNode ("property[@name='" + prop.GladeName + "']");
					if (prop_node == null)
						continue;

					if (prop.GladeOverride)
						overrideProps[prop] = prop_node;
					else
						rawProps[prop] = prop_node;
				}
			}
		}
		public TypedPropertyDescriptor (XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base (elem, group, klass)
		{
			this.klass = klass;
			string propertyName = elem.GetAttribute ("name");
			int dot = propertyName.IndexOf ('.');

			if (dot != -1) {
				// Sub-property (eg, "Alignment.Value")
				memberInfo = FindProperty (klass.WrapperType, klass.WrappedType, propertyName.Substring (0, dot));
				isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf (typeof (ObjectWrapper));
				gladeProperty = new TypedPropertyDescriptor (isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name);
				propertyInfo = FindProperty (memberInfo.PropertyType, propertyName.Substring (dot + 1));
			} else {
				// Basic simple property
				propertyInfo = FindProperty (klass.WrapperType, klass.WrappedType, propertyName);
				isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf (typeof (ObjectWrapper));
			}
			
			// Wrapper properties that override widgets properties (using the same name)
			// must be considered runtime properties (will be available at run-time).
			if (!isWrapperProperty || klass.WrappedType.GetProperty (propertyName) != null)
				isRuntimeProperty = true;
			
			if (!IsInternal && propertyInfo.PropertyType.IsEnum &&
			    Registry.LookupEnum (propertyInfo.PropertyType.FullName) == null)
				throw new ArgumentException ("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")");

			pspec = FindPSpec (propertyInfo);
			
			if (isWrapperProperty && pspec == null) {
				PropertyInfo pinfo = klass.WrappedType.GetProperty (propertyInfo.Name, flags);
				if (pinfo != null)
					pspec = FindPSpec (pinfo);
			}

			if (pspec != null) {
				// This information will be overridden by what's specified in the xml file
				description = pspec.Blurb;
				minimum = pspec.Minimum;
				maximum = pspec.Maximum;
				label = propertyName;
				if (!elem.HasAttribute ("ignore-default"))
					hasDefault = Type.GetTypeCode (PropertyType) != TypeCode.Object || PropertyType.IsEnum;
			} else {
				label = propertyInfo.Name;
				gladeOverride = true;
			}

			string typeName = elem.GetAttribute ("editor");
			if (typeName.Length > 0)
				editorType = Registry.GetType (typeName, false);
			
			// Look for a default value attribute
			
			object[] ats = propertyInfo.GetCustomAttributes (typeof(DefaultValueAttribute), true);
			if (ats.Length > 0) {
				DefaultValueAttribute at = (DefaultValueAttribute) ats [0];
				defaultValue = at.Value;
			}
			
			// Load default data
			Load (elem);
		}