public static ParamSpec LookupChildProperty(Type type, string name) { string key = type.FullName + ":" + name; if (childProps[key] != null) { return((ParamSpec)childProps[key]); } IntPtr klass = ParamSpecTypeHack.LookupGTypeClass(type); if (klass == IntPtr.Zero) { return(null); } IntPtr pspec_raw = gtk_container_class_find_child_property(klass, name); if (pspec_raw == IntPtr.Zero) { return(null); } ParamSpec pspec = new ParamSpec(pspec_raw); childProps[key] = pspec; return(pspec); }
static GLib.Value ParseProperty(Type type, bool childprop, string name, string strval) { ParamSpec pspec; // FIXME: this can be removed when GParamSpec supports ValueType. PropertyInfo pi = FindClrProperty(type, name, childprop); if (pi == null) { throw new GladeException("Unknown property", type.ToString(), childprop, name, strval); } 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, pi.PropertyType, strval)); } catch { throw new GladeException("Could not parse property", type.ToString(), childprop, name, strval); } }
ParamSpec FindPSpec(PropertyInfo pinfo) { foreach (object attr in pinfo.GetCustomAttributes(false)) { if (attr is GLib.PropertyAttribute) { GLib.PropertyAttribute pattr = (GLib.PropertyAttribute)attr; return(ParamSpec.LookupObjectProperty(pinfo.DeclaringType, pattr.Name)); } if (attr is Gtk.ChildPropertyAttribute) { Gtk.ChildPropertyAttribute cpattr = (Gtk.ChildPropertyAttribute)attr; return(ParamSpec.LookupChildProperty(pinfo.DeclaringType.DeclaringType, cpattr.Name)); } } return(null); }
TypedPropertyDescriptor(Type objectType, string propertyName) { propertyInfo = FindProperty(objectType, propertyName); isWrapperProperty = false; pspec = FindPSpec(propertyInfo); if (pspec != null) { label = propertyName; description = pspec.Blurb; minimum = pspec.Minimum; maximum = pspec.Maximum; hasDefault = Type.GetTypeCode(PropertyType) != TypeCode.Object || PropertyType.IsEnum; } else { label = propertyInfo.Name; } }
/* static GLib.Value ParseUnichar (string strval) * { * return new GLib.Value (strval.Length == 1 ? (uint)strval[0] : 0U); * }*/ static GLib.Value ParseProperty(ParamSpec pspec, Type propType, string strval) { IntPtr gtype; if (propType != null) { gtype = ((GLib.GType)propType).Val; } /* * FIXME: ValueType is not supported right now * * 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)); } // FIXME: Enable when ParamSpec.IsUnichar is implemented. // else if (pspec != null && pspec.IsUnichar) // return ParseUnichar (strval); else { return(ParseBasicType(typef, strval)); } }
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 GLib.Value ParseUnichar (string strval) { return new GLib.Value (strval.Length == 1 ? (uint)strval[0] : 0U); }*/ static GLib.Value ParseProperty (ParamSpec pspec, Type propType, string strval) { IntPtr gtype; if (propType != null) gtype = ((GLib.GType)propType).Val; /* FIXME: ValueType is not supported right now 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); // FIXME: Enable when ParamSpec.IsUnichar is implemented. // else if (pspec != null && pspec.IsUnichar) // return ParseUnichar (strval); else return ParseBasicType (typef, strval); }
TypedPropertyDescriptor (Type objectType, string propertyName) { propertyInfo = FindProperty (objectType, propertyName); isWrapperProperty = false; pspec = FindPSpec (propertyInfo); if (pspec != null) { label = propertyName; description = pspec.Blurb; minimum = pspec.Minimum; maximum = pspec.Maximum; hasDefault = Type.GetTypeCode (PropertyType) != TypeCode.Object || PropertyType.IsEnum; } else label = propertyInfo.Name; }
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); }