示例#1
0
 public static IntPtr GetClassPtr(GType type)
 {
     IntPtr klass = g_type_class_peek (type.Val);
         if (klass == IntPtr.Zero)
             klass = g_type_class_ref (type.Val);
         return klass;
 }
示例#2
0
        public FlagsInfo(GLib.GType gtype)
        {
            if (!IsFlagsType(gtype))
            {
                throw new ArgumentException();
            }

            IntPtr class_ptr = g_type_class_ref(gtype.Val);

            if (class_ptr == IntPtr.Zero)
            {
                throw new Exception();
            }

            GFlagsClass klass = (GFlagsClass)Marshal.PtrToStructure(class_ptr, typeof(GFlagsClass));

            this.mask = klass.mask;

            values = new FlagsValue[klass.n_values];
            int unmanaged_struct_size = Marshal.SizeOf(typeof(GFlagsValue));

            for (int i = 0; i < klass.n_values; i++)
            {
                GFlagsValue gv = (GFlagsValue)Marshal.PtrToStructure(new IntPtr(klass.values.ToInt64() + i * unmanaged_struct_size), typeof(GFlagsValue));
                values[i].value      = gv.value;
                values[i].value_name = GLib.Marshaller.Utf8PtrToString(gv.value_name);
                values[i].value_nick = GLib.Marshaller.Utf8PtrToString(gv.value_nick);
            }

            g_type_class_unref(class_ptr);
        }
示例#3
0
 public static void CheckInstanceIsA(IntPtr pointer, GLib.GType type)
 {
     if (!GObjectInterop.g_type_check_instance_is_a(new TypeInstance(pointer, checkType: false), type))
     {
         GType.ThrowInvalidCast(null, null);
     }
 }
示例#4
0
		public static void Register (GType native_type, System.Type type)
		{
			if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType)
				types[native_type.Val] = type;
			if (type != null)
				gtypes[type] = native_type;
		}
示例#5
0
		static void OverrideNewWindowPolicyDecisionRequested (GType gtype)
		{
			if (EtoWebView.NewWindowPolicyDecisionRequestedVMCallback == null) {
				EtoWebView.NewWindowPolicyDecisionRequestedVMCallback = new EtoWebView.NewWindowPolicyDecisionRequestedVMDelegate (EtoWebView.newwindowpolicydecisionrequested_cb);
			}
			GLib.Object.OverrideVirtualMethod (gtype, "new-window-policy-decision-requested", EtoWebView.NewWindowPolicyDecisionRequestedVMCallback);
		}
示例#6
0
        public override string ToString()
        {
            GParamSpec spec      = (GParamSpec)Marshal.PtrToStructure(Handle, typeof(GParamSpec));
            GType      valtype   = new GType(spec.value_type);
            GType      ownertype = new GType(spec.owner_type);

            return("ParamSpec: name=" + Marshaller.Utf8PtrToString(spec.name) + " value_type=" + valtype.ToString() + " owner_type=" + ownertype.ToString());
        }
示例#7
0
 public static GType GetBaseType(GType type)
 {
     IntPtr parent = g_type_parent (type.Val);
     if (parent == IntPtr.Zero)
         return GType.None;
     else
         return new GType (parent);
 }
示例#8
0
 private static void OverrideError(GLib.GType gtype)
 {
     if (ErrorVMCallback == null)
     {
         ErrorVMCallback = new ErrorVMDelegate(error_cb);
     }
     OverrideVirtualMethod(gtype, "error", ErrorVMCallback);
 }
示例#9
0
 private static void OverrideMediaInfo(GLib.GType gtype)
 {
     if (MediaInfoVMCallback == null)
     {
         MediaInfoVMCallback = new MediaInfoVMDelegate(media_info_cb);
     }
     OverrideVirtualMethod(gtype, "media-info", MediaInfoVMCallback);
 }
示例#10
0
 public Value(Opaque val, string type_name)
 {
     type = IntPtr.Zero;
     pad1 = new Padding();
     pad2 = new Padding();
     g_value_init(ref this, GType.FromName(type_name).Val);
     g_value_set_boxed(ref this, val.Handle);
 }
示例#11
0
 private static void OverrideEos(GLib.GType gtype)
 {
     if (EosVMCallback == null)
     {
         EosVMCallback = new EosVMDelegate(eos_cb);
     }
     OverrideVirtualMethod(gtype, "eos", EosVMCallback);
 }
示例#12
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);
        }
示例#13
0
 private static void OverrideDeviceChange(GLib.GType gtype)
 {
     if (DeviceChangeVMCallback == null)
     {
         DeviceChangeVMCallback = new DeviceChangeVMDelegate(device_change_cb);
     }
     OverrideVirtualMethod(gtype, "device_change", DeviceChangeVMCallback);
 }
示例#14
0
 private static void OverrideReadyToCapture(GLib.GType gtype)
 {
     if (ReadyToCaptureVMCallback == null)
     {
         ReadyToCaptureVMCallback = new ReadyToCaptureVMDelegate(ready_to_capture_cb);
     }
     OverrideVirtualMethod(gtype, "ready-to-capture", ReadyToCaptureVMCallback);
 }
示例#15
0
 public static GType GetThresholdType(GType type)
 {
     GLib.GType curr_type = type;
     while (curr_type.ToString ().StartsWith ("__gtksharp_")) {
         curr_type = GetBaseType (curr_type);
     }
     return curr_type;
 }
示例#16
0
        internal static void OverrideDefaultHandler(GType gtype, string name, Delegate cb)
        {
            IntPtr closure = g_cclosure_new(cb, IntPtr.Zero, IntPtr.Zero);

            gtype.EnsureClass();
            uint id = GetSignalId(name, gtype.Val);

            g_signal_override_class_closure(id, gtype.Val, closure);
        }
示例#17
0
 public static GType GetThresholdType(GType type)
 {
     GLib.GType curr_type = type;
     while (curr_type.ToString().StartsWith("__gtksharp_"))
     {
         curr_type = GetBaseType(curr_type);
     }
     return(curr_type);
 }
示例#18
0
        public ParamSpec(string name, string nick, string blurb, GType type, bool readable, bool writable)
        {
            ParamFlags pflags = ParamFlags.None;
            if (readable) pflags |= ParamFlags.Readable;
            if (writable) pflags |= ParamFlags.Writable;
            int flags = (int) pflags;

            IntPtr p_name = GLib.Marshaller.StringToPtrGStrdup (name);
            IntPtr p_nick = GLib.Marshaller.StringToPtrGStrdup (nick);
            IntPtr p_blurb = GLib.Marshaller.StringToPtrGStrdup (blurb);

            if (type == GType.Char)
                handle = g_param_spec_char (p_name, p_nick, p_blurb, SByte.MinValue, SByte.MaxValue, 0, flags);
            else if (type == GType.UChar)
                handle = g_param_spec_uchar (p_name, p_nick, p_blurb, Byte.MinValue, Byte.MaxValue, 0, flags);
            else if (type == GType.Boolean)
                handle = g_param_spec_boolean (p_name, p_nick, p_blurb, false, flags);
            else if (type == GType.Int)
                handle = g_param_spec_int (p_name, p_nick, p_blurb, Int32.MinValue, Int32.MaxValue, 0, flags);
            else if (type == GType.UInt)
                handle = g_param_spec_uint (p_name, p_nick, p_blurb, 0, UInt32.MaxValue, 0, flags);
            else if (type == GType.Long)
                handle = g_param_spec_long (p_name, p_nick, p_blurb, IntPtr.Zero, IntPtr.Size == 4 ? new IntPtr (Int32.MaxValue) : new IntPtr (Int64.MaxValue), IntPtr.Zero, flags);
            else if (type == GType.ULong)
                handle = g_param_spec_ulong (p_name, p_nick, p_blurb, UIntPtr.Zero, UIntPtr.Size == 4 ? new UIntPtr (UInt32.MaxValue) : new UIntPtr (UInt64.MaxValue), UIntPtr.Zero, flags);
            else if (type == GType.Int64)
                handle = g_param_spec_int64 (p_name, p_nick, p_blurb, Int64.MinValue, Int64.MaxValue, 0, flags);
            else if (type == GType.UInt64)
                handle = g_param_spec_uint64 (p_name, p_nick, p_blurb, 0, UInt64.MaxValue, 0, flags);
            /*
            else if (type == GType.Enum)
            else if (type == GType.Flags)
            * TODO:
            * Both g_param_spec_enum and g_param_spec_flags expect default property values and the members of the enum seemingly cannot be enumerated
            */
            else if (type == GType.Float)
                handle = g_param_spec_float (p_name, p_nick, p_blurb, Single.MinValue, Single.MaxValue, 0.0f, flags);
            else if (type == GType.Double)
                handle = g_param_spec_double (p_name, p_nick, p_blurb, Double.MinValue, Double.MaxValue, 0.0, flags);
            else if (type == GType.String)
                handle = g_param_spec_string (p_name, p_nick, p_blurb, IntPtr.Zero, flags);
            else if (type == GType.Pointer)
                handle = g_param_spec_pointer (p_name, p_nick, p_blurb, flags);
            else if (type.Val == g_gtype_get_type ())
                handle = g_param_spec_gtype (p_name, p_nick, p_blurb, GType.None.Val, flags);
            else if (g_type_is_a (type.Val, GType.Boxed.Val))
                handle = g_param_spec_boxed (p_name, p_nick, p_blurb, type.Val, flags);
            else if (g_type_is_a (type.Val, GType.Object.Val))
                handle = g_param_spec_object (p_name, p_nick, p_blurb, type.Val, flags);
            else
                throw new ArgumentException ("type");

            GLib.Marshaller.Free (p_name);
            GLib.Marshaller.Free (p_nick);
            GLib.Marshaller.Free (p_blurb);
        }
示例#19
0
        public GType GetThresholdType()
        {
            GType curr_type = this;

            while (IsManaged(curr_type))
            {
                curr_type = curr_type.GetBaseType();
            }
            return(curr_type);
        }
示例#20
0
        public Value(object obj)
        {
            type = IntPtr.Zero;
            pad1 = pad2 = 0;

            GType gtype = (GType)obj.GetType();

            g_value_init(ref this, gtype.Val);
            Val = obj;
        }
示例#21
0
文件: GType.cs 项目: shana/gtk-sharp
        public GType GetThresholdType()
        {
            GType curr_type = this;

            while (curr_type.ToString().StartsWith("__gtksharp_"))
            {
                curr_type = curr_type.GetBaseType();
            }
            return(curr_type);
        }
示例#22
0
        static void AddInterfaces(GType gtype, Type t, ref bool handlers_overridden)
        {
            foreach (Type iface in t.GetInterfaces())
            {
                if (!iface.IsDefined(typeof(GInterfaceAttribute), true))
                {
                    continue;
                }

                GInterfaceAttribute attr    = iface.GetCustomAttributes(typeof(GInterfaceAttribute), false) [0] as GInterfaceAttribute;
                GInterfaceAdapter   adapter = Activator.CreateInstance(attr.AdapterType, null) as GInterfaceAdapter;
                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;
                }

                if (!iface.IsAssignableFrom(t.BaseType))
                {
                    GInterfaceInfo info = adapter.Info;
                    info.Data = gtype.GetClassPtr();
                    //FIXME:  overiding prop is done inside the init of interface adapter
                    // not sure that it is the good solution but
                    // it is the only one I found without exception or loop
                    g_type_add_interface_static(gtype.Val, adapter.GType.Val, ref info);
                }
                foreach (PropertyInfo p in iface.GetProperties())
                {
                    PropertyAttribute[] attrs = p.GetCustomAttributes(typeof(PropertyAttribute), true) as PropertyAttribute [];
                    if (attrs.Length == 0)
                    {
                        continue;
                    }
                    PropertyAttribute property_attr = attrs [0];
                    PropertyInfo      declared_prop = t.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance);
                    if (declared_prop == null)
                    {
                        continue;
                    }
                    IntPtr param_spec = FindInterfaceProperty(adapter.GType, property_attr.Name);

                    Dictionary <IntPtr, PropertyInfo> props;
                    if (!Properties.TryGetValue(t, out props))
                    {
                        props          = new Dictionary <IntPtr, PropertyInfo> ();
                        Properties [t] = props;
                    }
                    props [param_spec] = declared_prop;
                }
            }
        }
示例#23
0
        static System.Type ResolveManagedType(GType gtype)
        {
            // First check typedict
            if (TypeDict.TryGetValue(gtype.typeid, out Type type))
            {
                return(type);
            }

            // If not
            throw new NotImplementedException("Type lookup not implemented");

            //return type;
        }
示例#24
0
 public static void Register(GType native_type, System.Type type)
 {
     lock (types) {
         if (native_type != GType.Pointer && native_type != GType.Boxed && native_type != ManagedValue.GType)
         {
             types[native_type.Val] = type;
         }
         if (type != null)
         {
             gtypes[type] = native_type;
         }
     }
 }
示例#25
0
        static IntPtr FindInterfaceProperty(GType type, string name)
        {
            IntPtr g_iface     = type.GetDefaultInterfacePtr();
            IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);

            try
            {
                return(g_object_interface_find_property(g_iface, native_name));
            }
            finally
            {
                GLib.Marshaller.Free(native_name);
            }
        }
示例#26
0
        // sets the column count.  beware, it clears
        // use this if you are going to load each column and row yourself
        // instead of using DataBind() or DataLoad()
        public void SetColumnCount(int columnCount)
        {
            Clear();
            dataMember = "";
            dataSource = null;

            GLib.GType[] theTypes = new GLib.GType[columnCount];
            gridColumns = new ArrayList();
            for (int col = 0; col < columnCount; col++)
            {
                theTypes[col] = GLib.GType.String;
                gridColumns.Add(new DataGridColumn());
            }
            store.ColumnTypes = theTypes;
        }
示例#27
0
 public Value(EnumWrapper wrap, string type_name)
 {
     type = IntPtr.Zero;
     pad1 = new Padding();
     pad2 = new Padding();
     g_value_init(ref this, GType.FromName(type_name).Val);
     if (wrap.flags)
     {
         g_value_set_flags(ref this, (uint)(int)wrap);
     }
     else
     {
         g_value_set_enum(ref this, (int)wrap);
     }
 }
示例#28
0
        private static void InvokeTypeInitializers(GType gtype, System.Type t)
        {
            object[] parms = { gtype, t };

            BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;

            foreach (TypeInitializerAttribute tia in t.GetCustomAttributes(typeof(TypeInitializerAttribute), true))
            {
                MethodInfo m = tia.Type.GetMethod(tia.MethodName, flags);
                if (m != null)
                {
                    m.Invoke(null, parms);
                }
            }
        }
示例#29
0
        protected static GType RegisterGType(System.Type t)
        {
            GType  parent_gtype = LookupGType(t.BaseType);
            string name         = BuildEscapedName(t);
            IntPtr native_name  = GLib.Marshaller.StringToPtrGStrdup(name);
            GType  gtype        = new GType(gtksharp_register_type(native_name, parent_gtype.Val));

            GLib.Marshaller.Free(native_name);
            GLib.GType.Register(gtype, t);
            AddProperties(gtype, t);
            ConnectDefaultHandlers(gtype, t);
            InvokeClassInitializers(gtype, t);
            AddInterfaces(gtype, t);
            g_types[t] = gtype;
            return(gtype);
        }
示例#30
0
        static void AddInterfaces(GType gtype, Type t)
        {
            foreach (Type iface in t.GetInterfaces())
            {
                if (!iface.IsDefined(typeof(GInterfaceAttribute), true) || iface.IsAssignableFrom(t.BaseType))
                {
                    continue;
                }

                GInterfaceAttribute attr    = iface.GetCustomAttributes(typeof(GInterfaceAttribute), false) [0] as GInterfaceAttribute;
                GInterfaceAdapter   adapter = Activator.CreateInstance(attr.AdapterType, null) as GInterfaceAdapter;

                GInterfaceInfo info = adapter.Info;
                g_type_add_interface_static(gtype.Val, adapter.GType.Val, ref info);
            }
        }
        object ToBoxed()
        {
            IntPtr boxed_ptr = g_value_get_boxed(ref this);
            Type   t         = GType.LookupType(type);

            if (t == null)
            {
                throw new Exception("Unknown type " + new GType(type).ToString());
            }
            else if (t.IsSubclassOf(typeof(GLib.Opaque)))
            {
                return((GLib.Opaque) this);
            }

            return(FastActivator.CreateBoxed(boxed_ptr, t));
        }
示例#32
0
        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);
        }
示例#33
0
 internal void Update(object val)
 {
     if (GType.Is(type, GType.Boxed) && !(val is IWrapper))
     {
         MethodInfo mi        = val.GetType().GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance);
         IntPtr     boxed_ptr = g_value_get_boxed(ref this);
         if (mi == null)
         {
             Marshal.StructureToPtr(val, boxed_ptr, false);
         }
         else
         {
             mi.Invoke(val, null);
         }
     }
 }
示例#34
0
        public PropertyInfo(IntPtr pspec_ptr)
        {
            GParamSpec pspec = (GParamSpec)Marshal.PtrToStructure(pspec_ptr, typeof(GParamSpec));
            IntPtr     name  = g_param_spec_get_name(pspec_ptr);
            IntPtr     nick  = g_param_spec_get_nick(pspec_ptr);
            IntPtr     blurb = g_param_spec_get_blurb(pspec_ptr);

            this.name  = GLib.Marshaller.Utf8PtrToString(name);
            this.nick  = GLib.Marshaller.Utf8PtrToString(nick);
            this.blurb = GLib.Marshaller.Utf8PtrToString(blurb);

            this.readable     = ((pspec.Flags & (1 << 0)) != 0);
            this.writeable    = ((pspec.Flags & (1 << 1)) != 0);
            this.controllable = ((pspec.Flags & (1 << 9)) != 0);
            /* TODO: Add more flags later, like the mutable flags */

            this.gtype = new GLib.GType(pspec.ValueType);
            this.type  = (System.Type) this.gtype;

            this.dflt = this.min = this.max = null;

            try {
                GLib.Value v = new GLib.Value(new GLib.GType(pspec.ValueType));
                g_param_value_set_default(pspec_ptr, ref v);
                this.dflt = v.Val;
                v.Dispose();

                if (EnumInfo.IsEnumType(this.gtype))
                {
                    EnumInfo ei = new EnumInfo(this.gtype);
                    this.min = ei.Min;
                    this.max = ei.Max;
                }
                else
                {
                    GLib.Value min = new GLib.Value(new GLib.GType(pspec.ValueType));
                    GLib.Value max = new GLib.Value(new GLib.GType(pspec.ValueType));
                    if (gstsharp_g_param_spec_get_range(pspec_ptr, ref min, ref max))
                    {
                        this.min = (object)min.Val;
                        this.max = (object)max.Val;
                    }
                    min.Dispose();
                    max.Dispose();
                }
            } catch (Exception) {}
        }
示例#35
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);
                        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));
                    }
                }
            }
        }
示例#36
0
    private static void ConnectDefaultHandlers(GType gtype, System.Type t)
    {
        foreach (MethodInfo minfo in t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly)) {
            MethodInfo baseinfo = minfo.GetBaseDefinition ();
            if (baseinfo == minfo)
                continue;

            foreach (object attr in baseinfo.GetCustomAttributes (typeof (DefaultSignalHandlerAttribute), false)) {
                DefaultSignalHandlerAttribute sigattr = attr as DefaultSignalHandlerAttribute;
                MethodInfo connector = sigattr.Type.GetMethod (sigattr.ConnectionMethod, BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof (GType) }, new ParameterModifier [0]);
                object[] parms = new object [1];
                parms [0] = gtype;
                connector.Invoke (null, parms);
                break;
            }
        }
    }
        static Type GetTypeOrParent(IntPtr obj)
        {
            IntPtr typeid = gtksharp_get_type_id(obj);

            Type result = GType.LookupType(typeid);

            while (result == null)
            {
                typeid = g_type_parent(typeid);
                if (typeid == IntPtr.Zero)
                {
                    return(null);
                }
                result = GType.LookupType(typeid);
            }
            return(result);
        }
示例#38
0
        public PropertyInfo(IntPtr pspec_ptr)
        {
            GParamSpec pspec = (GParamSpec) Marshal.PtrToStructure (pspec_ptr, typeof (GParamSpec));
              IntPtr name = g_param_spec_get_name (pspec_ptr);
              IntPtr nick = g_param_spec_get_nick (pspec_ptr);
              IntPtr blurb = g_param_spec_get_blurb (pspec_ptr);

              this.name = GLib.Marshaller.Utf8PtrToString (name);
              this.nick = GLib.Marshaller.Utf8PtrToString (nick);
              this.blurb = GLib.Marshaller.Utf8PtrToString (blurb);

              this.readable = ( (pspec.Flags & (1 << 0)) != 0);
              this.writeable = ( (pspec.Flags & (1 << 1)) != 0);
              this.controllable = ( (pspec.Flags & (1 << 9)) != 0);
              /* TODO: Add more flags later, like the mutable flags */

              this.gtype = new GLib.GType (pspec.ValueType);
              this.type = (System.Type) this.gtype;

              this.dflt = this.min = this.max = null;

              try {
            GLib.Value v = new GLib.Value (new GLib.GType (pspec.ValueType));
            g_param_value_set_default (pspec_ptr, ref v);
            this.dflt = v.Val;
            v.Dispose ();

            if (EnumInfo.IsEnumType (this.gtype)) {
              EnumInfo ei = new EnumInfo (this.gtype);
              this.min = ei.Min;
              this.max = ei.Max;
            } else {
              GLib.Value min = new GLib.Value (new GLib.GType (pspec.ValueType));
              GLib.Value max = new GLib.Value (new GLib.GType (pspec.ValueType));
              if (gstsharp_g_param_spec_get_range (pspec_ptr, ref min, ref max)) {
            this.min = (object) min.Val;
            this.max = (object) max.Val;
              }
              min.Dispose ();
              max.Dispose ();
            }
              } catch (Exception) {}
        }
示例#39
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));
                    }
                }
            }
        }
示例#40
0
        static void AddInterfaces(GType gtype, Type t, ref bool handlers_overridden)
        {
            foreach (Type iface in t.GetInterfaces ()) {
                if (!iface.IsDefined (typeof (GInterfaceAttribute), true))
                    continue;

                GInterfaceAttribute attr = iface.GetCustomAttributes (typeof (GInterfaceAttribute), false) [0] as GInterfaceAttribute;
                GInterfaceAdapter adapter = Activator.CreateInstance (attr.AdapterType, null) as GInterfaceAdapter;
                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;
                }

                if (!iface.IsAssignableFrom (t.BaseType)) {
                    GInterfaceInfo info = adapter.Info;
                    info.Data = gtype.GetClassPtr ();
                    //FIXME:  overiding prop is done inside the init of interface adapter
                    // not sure that it is the good solution but
                    // it is the only one I found without exception or loop
                    g_type_add_interface_static (gtype.Val, adapter.GType.Val, ref info);
                }
                foreach (PropertyInfo p in iface.GetProperties ()) {
                    PropertyAttribute[] attrs = p.GetCustomAttributes (typeof (PropertyAttribute), true) as PropertyAttribute [];
                    if (attrs.Length == 0)
                        continue;
                    PropertyAttribute property_attr = attrs [0];
                    PropertyInfo declared_prop = t.GetProperty (p.Name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
                    if (declared_prop == null)
                        continue;
                    IntPtr param_spec = FindInterfaceProperty (adapter.GType, property_attr.Name);

                    Properties [param_spec] = declared_prop;
                }
            }
        }
示例#41
0
文件: Object.cs 项目: shana/gtk-sharp
        static void AddInterfaces(GType gtype, Type t)
        {
            foreach (Type iface in t.GetInterfaces ()) {
                if (!iface.IsDefined (typeof (GInterfaceAttribute), true) || iface.IsAssignableFrom (t.BaseType))
                    continue;

                GInterfaceAttribute attr = iface.GetCustomAttributes (typeof (GInterfaceAttribute), false) [0] as GInterfaceAttribute;
                GInterfaceAdapter adapter = Activator.CreateInstance (attr.AdapterType, null) as GInterfaceAdapter;

                GInterfaceInfo info = adapter.Info;
                g_type_add_interface_static (gtype.Val, adapter.GType.Val, ref info);
            }
        }
示例#42
0
 public ParamSpec(string name, string nick, string blurb, GType type, bool readable, bool writable)
     : this(name, nick, blurb, type, (readable ? ParamFlags.Readable : ParamFlags.None) | (writable ? ParamFlags.Writable : ParamFlags.None))
 {
 }
示例#43
0
 internal static GType RegisterGObjectType(System.Type t)
 {
     GType parent_gtype = LookupGObjectType (t.BaseType);
     string name = BuildEscapedName (t);
     IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
     GTypeQuery query;
     g_type_query (parent_gtype.Val, out query);
     GTypeInfo info = new GTypeInfo ();
     info.class_size = (ushort) query.class_size;
     info.instance_size = (ushort) query.instance_size;
     GType gtype = new GType (g_type_register_static (parent_gtype.Val, native_name, ref info, 0));
     GLib.Marshaller.Free (native_name);
     Register (gtype, t);
     return gtype;
 }
示例#44
0
 protected static void OverrideVirtualMethod(GType gtype, string name, Delegate cb)
 {
     Signal.OverrideDefaultHandler (gtype, name, cb);
 }
示例#45
0
 protected TreeStore(GType gtype)
     : base(gtype)
 {
 }
示例#46
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;
        }
示例#47
0
 public static bool IsInstance(GType type, IntPtr raw)
 {
     return Is (ValFromInstancePtr (raw), type);
 }
示例#48
0
 public static bool Is(IntPtr type, GType is_a_type)
 {
     return g_type_is_a (type, is_a_type.Val);
 }
示例#49
0
 public static uint GetClassSize(GType type)
 {
     GTypeQuery query;
     g_type_query (type.Val, out query);
     return query.class_size;
 }
示例#50
0
 public GTypeSignalKey(GType type, string name)
 {
     this.type = type;
     signal_name = name;
 }
示例#51
0
        private static void InvokeTypeInitializers(GType gtype, System.Type t)
        {
            object[] parms = {gtype, t};

            BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;

            foreach (TypeInitializerAttribute tia in t.GetCustomAttributes (typeof (TypeInitializerAttribute), true)) {
                MethodInfo m = tia.Type.GetMethod (tia.MethodName, flags);
                if (m != null)
                    m.Invoke (null, parms);
            }
        }
示例#52
0
文件: Value.cs 项目: saraa/fishtastic
 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);
 }
示例#53
0
文件: Value.cs 项目: knocte/gtk-sharp
		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);
		}
示例#54
0
 public static void RegisterType(GType native_type, System.Type type)
 {
     GType.Register (native_type, type);
 }
示例#55
0
 public int AddValueMapping(GType store_type, GetStoreValueCallback callback)
 {
     store_types.Add(store_type);
     callbacks.Add(callback);
     return callbacks.Count;
 }
示例#56
0
 public override string ToString()
 {
     GParamSpec spec = (GParamSpec) Marshal.PtrToStructure (Handle, typeof (GParamSpec));
     GType valtype= new GType (spec.value_type);
     GType ownertype= new GType (spec.owner_type);
     return "ParamSpec: name=" +  Marshaller.Utf8PtrToString (spec.name) + " value_type=" + valtype.ToString() + " owner_type=" + ownertype.ToString();
 }
示例#57
0
 static IntPtr FindInterfaceProperty(GType type, string name)
 {
     IntPtr g_iface = type.GetDefaultInterfacePtr ();
     IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
     return g_object_interface_find_property (g_iface, native_name);
 }
		public void DataBind () 
		{
			Clear ();

			System.Object o = null;
			o = GetResolvedDataSource (DataSource, DataMember);
			IEnumerable ie = (IEnumerable) o;
			ITypedList tlist = (ITypedList) o;

			// FIXME: does not belong in this base method
			Gtk.TreeIter iter = new Gtk.TreeIter ();
									
			PropertyDescriptorCollection pdc = tlist.GetItemProperties (new PropertyDescriptor[0]);

			// FIXME: does not belong in this base method
			gridColumns = new DataGridColumn[pdc.Count];

			// FIXME: does not belong in base method
			// define the columns in the treeview store
			// based on the schema of the result
			/*
			uint[] theTypes = new uint[pdc.Count];
			for (int col = 0; col < pdc.Count; col++) {
				theTypes[col] = (int) TypeFundamentals.TypeString;
			}
			*/
			GType [] theTypes = new GType[pdc.Count];
			for ( int col=0; col<pdc.Count; col++ ) {
				theTypes[col] = (GType)GType.String;
			}
			store.ColumnTypes = theTypes;

			// FIXME: does not belong in this base method
			int colndx = -1;
			foreach (PropertyDescriptor pd in pdc) {
				colndx ++;
				gridColumns[colndx] = new DataGridColumn ();
				gridColumns[colndx].ColumnName = pd.Name;				
			}

			foreach (System.Object obj in ie) {
				ICustomTypeDescriptor custom = (ICustomTypeDescriptor) obj;
				PropertyDescriptorCollection properties;
				properties = custom.GetProperties ();
				
				iter = NewRow ();
				int cv = 0;
				foreach (PropertyDescriptor property in properties) {
					object oPropValue = property.GetValue (obj);
					string sPropValue = oPropValue.ToString ();
					
					// FIXME: does not belong in this base method
					SetColumnValue (iter, cv, sPropValue);

					cv++;
				}
			}

			// FIXME: does not belong in this base method
			treeView.Model = store;
			AutoCreateTreeViewColumns ( treeView );
		}
示例#59
0
 internal ClassInitializer(Type type)
 {
     ClassInitManagedDelegate = this.ClassInit;
     Type = type;
     gtype = GType.RegisterGObjectType (this);
     is_first_subclass = gtype.GetBaseType () == gtype.GetThresholdType ();
 }
示例#60
0
文件: GType.cs 项目: Zekom/gtk-sharp
        internal static GType RegisterGObjectType(Object.ClassInitializer gobject_class_initializer)
        {
            GType parent_gtype = LookupGObjectType (gobject_class_initializer.Type.BaseType);
            string name = BuildEscapedName (gobject_class_initializer.Type);

            IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
            GTypeQuery query;
            g_type_query (parent_gtype.Val, out query);
            GTypeInfo info = new GTypeInfo ();
            info.class_size = (ushort) query.class_size;
            info.instance_size = (ushort) query.instance_size;
            info.class_init = gobject_class_initializer.ClassInitManagedDelegate;

            GType gtype = new GType (g_type_register_static (parent_gtype.Val, native_name, ref info, 0));
            GLib.Marshaller.Free (native_name);
            Register (gtype, gobject_class_initializer.Type);

            return gtype;
        }