static void SetPropertyCallback(IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) { // FIXME: Here is a big quick hack to avoid race condition when trying to set up adjustment with contructor // Because Raw is set too late if (param_spec != IntPtr.Zero) { ParamSpec foo = new ParamSpec(param_spec); if (foo.Name == "gtk-sharp-managed-instance") { GCHandle gch = (GCHandle)(IntPtr)value.Val; Object o = (GLib.Object)gch.Target; o.Raw = handle; } } GLib.Object obj = GLib.Object.GetObject(handle, false); var type = (Type)obj.LookupGType(); Dictionary <IntPtr, PropertyInfo> props; if (!Properties.TryGetValue(type, out props)) { return; } PropertyInfo prop; if (!props.TryGetValue(param_spec, out prop)) { return; } prop.SetValue(obj, value.Val, new object [0]); }
static IntPtr RegisterProperty(GType type, string name, string nick, string blurb, uint property_id, GType property_type, bool can_read, bool can_write) { IntPtr declaring_class = type.GetClassPtr(); ParamSpec pspec = new ParamSpec(name, nick, blurb, property_type, can_read, can_write); g_object_class_install_property(declaring_class, property_id, pspec.Handle); return(pspec.Handle); }
void InitForProperty(GType gtype, string name) { IntPtr p_name = Marshaller.StringToPtrGStrdup(name); IntPtr spec_ptr = g_object_class_find_property(gtype.GetClassPtr(), p_name); Marshaller.Free(p_name); if (spec_ptr == IntPtr.Zero) { throw new Exception(String.Format("No property with name '{0}' in type '{1}'", name, gtype.ToString())); } ParamSpec spec = new ParamSpec(spec_ptr); g_value_init(ref this, spec.ValueType.Val); }
static void AddProperties(GType gtype, System.Type t, bool register_instance_prop, ref bool handlers_overridden) { if (register_instance_prop) { IntPtr declaring_class = gtype.GetClassPtr(); ParamSpec pspec = new ParamSpec("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly); g_object_class_install_property(declaring_class, idx, pspec.Handle); idx++; } foreach (PropertyInfo pinfo in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false)) { if (pinfo.GetIndexParameters().Length > 0) { throw(new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName))); } if (!handlers_overridden) { IntPtr class_ptr = gtype.GetClassPtr(); GObjectClass gobject_class = (GObjectClass)Marshal.PtrToStructure(class_ptr, typeof(GObjectClass)); gobject_class.get_prop_cb = GetPropertyHandler; gobject_class.set_prop_cb = SetPropertyHandler; Marshal.StructureToPtr(gobject_class, class_ptr, false); handlers_overridden = true; } PropertyAttribute property_attr = attr as PropertyAttribute; try { IntPtr param_spec = RegisterProperty(gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType)pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite); Type type = (Type)gtype; Dictionary <IntPtr, PropertyInfo> gtype_properties; if (!Properties.TryGetValue(type, out gtype_properties)) { gtype_properties = new Dictionary <IntPtr, PropertyInfo> (); Properties [type] = gtype_properties; } gtype_properties.Add(param_spec, pinfo); idx++; } catch (ArgumentException) { throw new InvalidOperationException(String.Format("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName)); } } } }
void AddProperties() { if (is_first_subclass) { IntPtr declaring_class = gtype.GetClassPtr(); ParamSpec pspec = new ParamSpec("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly); g_object_class_install_property(declaring_class, idx, pspec.Handle); idx++; } foreach (PropertyInfo pinfo in Type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { foreach (object attr in pinfo.GetCustomAttributes(typeof(PropertyAttribute), false)) { if (pinfo.GetIndexParameters().Length > 0) { throw new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, Type.FullName)); } OverrideHandlers(false, true); PropertyAttribute property_attr = attr as PropertyAttribute; try { IntPtr param_spec = RegisterProperty(gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType)pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite); Type type = (Type)gtype; Dictionary <IntPtr, PropertyInfo> gtype_properties; if (!Properties.TryGetValue(type, out gtype_properties)) { gtype_properties = new Dictionary <IntPtr, PropertyInfo> (); Properties [type] = gtype_properties; } gtype_properties.Add(param_spec, pinfo); idx++; } catch (ArgumentException) { throw new InvalidOperationException(String.Format("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, Type.FullName)); } } } }
void AddProperties() { if (is_first_subclass) { IntPtr declaring_class = gtype.GetClassPtr (); ParamSpec pspec = new ParamSpec ("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly); g_object_class_install_property (declaring_class, idx, pspec.Handle); idx++; } foreach (PropertyInfo pinfo in Type.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { foreach (object attr in pinfo.GetCustomAttributes (typeof (PropertyAttribute), false)) { if (pinfo.GetIndexParameters ().Length > 0) throw new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, Type.FullName)); OverrideHandlers (false, true); PropertyAttribute property_attr = attr as PropertyAttribute; try { IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite); Type type = (Type)gtype; Dictionary<IntPtr, PropertyInfo> gtype_properties; if (!Properties.TryGetValue (type, out gtype_properties)) { gtype_properties = new Dictionary<IntPtr, PropertyInfo> (); Properties [type] = gtype_properties; } gtype_properties.Add (param_spec, pinfo); idx++; } catch (ArgumentException) { throw new InvalidOperationException (String.Format ("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, Type.FullName)); } } } }
static void SetPropertyCallback(IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) { // FIXME: Here is a big quick hack to avoid race condition when trying to set up adjustment with contructor // Because Raw is set too late if (param_spec != IntPtr.Zero) { ParamSpec foo = new ParamSpec(param_spec); if (foo.Name == "gtk-sharp-managed-instance") { GCHandle gch = (GCHandle) (IntPtr) value.Val; Object o = (GLib.Object) gch.Target; o.Raw = handle; } } GLib.Object obj = GLib.Object.GetObject (handle, false); var type = (Type)obj.LookupGType (); Dictionary<IntPtr, PropertyInfo> props; if (!Properties.TryGetValue (type, out props)) return; PropertyInfo prop; if (!props.TryGetValue (param_spec, out prop)) return; prop.SetValue (obj, value.Val, new object [0]); }
static IntPtr RegisterProperty(GType type, string name, string nick, string blurb, uint property_id, GType property_type, bool can_read, bool can_write) { IntPtr declaring_class = type.GetClassPtr (); ParamSpec pspec = new ParamSpec (name, nick, blurb, property_type, can_read, can_write); g_object_class_install_property (declaring_class, property_id, pspec.Handle); return pspec.Handle; }
static void SetPropertyCallback(IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) { // FIXME: Here is a big quick hack to avoid race condition when trying to set up adjustment with contructor // Because Raw is set too late if (param_spec != IntPtr.Zero) { ParamSpec foo = new ParamSpec(param_spec); if (foo.Name == "gtk-sharp-managed-instance") { GCHandle gch = (GCHandle) (IntPtr) value.Val; Object o = (GLib.Object) gch.Target; o.Raw = handle; } } if (!Properties.ContainsKey (param_spec)) return; GLib.Object obj = GLib.Object.GetObject (handle, false); Properties [param_spec].SetValue (obj, value.Val, new object [0]); }
static void AddProperties(GType gtype, System.Type t, bool register_instance_prop, ref bool handlers_overridden) { if (register_instance_prop) { IntPtr declaring_class = gtype.GetClassPtr (); ParamSpec pspec = new ParamSpec ("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly); g_object_class_install_property (declaring_class, idx, pspec.Handle); idx++; } foreach (PropertyInfo pinfo in t.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { foreach (object attr in pinfo.GetCustomAttributes (typeof (PropertyAttribute), false)) { if(pinfo.GetIndexParameters().Length > 0) throw(new InvalidOperationException(String.Format("GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName))); if (!handlers_overridden) { IntPtr class_ptr = gtype.GetClassPtr (); GObjectClass gobject_class = (GObjectClass) Marshal.PtrToStructure (class_ptr, typeof (GObjectClass)); gobject_class.get_prop_cb = GetPropertyHandler; gobject_class.set_prop_cb = SetPropertyHandler; Marshal.StructureToPtr (gobject_class, class_ptr, false); handlers_overridden = true; } PropertyAttribute property_attr = attr as PropertyAttribute; try { IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite); Properties.Add (param_spec, pinfo); idx++; } catch (ArgumentException) { throw new InvalidOperationException (String.Format ("GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName)); } } } }
void InitForProperty(GType gtype, string name) { IntPtr p_name = Marshaller.StringToPtrGStrdup (name); ParamSpec spec = new ParamSpec (g_object_class_find_property (gtype.ClassPtr, p_name)); Marshaller.Free (p_name); g_value_init (ref this, spec.ValueType.Val); }
void InitForProperty (GType gtype, string name) { IntPtr p_name = Marshaller.StringToPtrGStrdup (name); IntPtr spec_ptr = g_object_class_find_property (gtype.GetClassPtr (), p_name); Marshaller.Free (p_name); if (spec_ptr == IntPtr.Zero) throw new Exception (String.Format ("No property with name '{0}' in type '{1}'", name, gtype.ToString())); ParamSpec spec = new ParamSpec (spec_ptr); g_value_init (ref this, spec.ValueType.Val); }