Ejemplo n.º 1
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 = GObject.Marshaller.StringToPtrGStrdup (name);
            IntPtr p_nick = GObject.Marshaller.StringToPtrGStrdup (nick);
            IntPtr p_blurb = GObject.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");

            GObject.Marshaller.Free (p_name);
            GObject.Marshaller.Free (p_nick);
            GObject.Marshaller.Free (p_blurb);
        }
Ejemplo n.º 2
0
 internal static GType RegisterGObjectType(System.Type t)
 {
     GType parent_gtype = LookupGObjectType (t.BaseType);
     string name = BuildEscapedName (t);
     IntPtr native_name = GObject.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));
     GObject.Marshaller.Free (native_name);
     Register (gtype, t);
     return gtype;
 }
Ejemplo n.º 3
0
 internal static bool Is(IntPtr type, GType is_a_type)
 {
     return g_type_is_a (type, is_a_type.Val);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 public static void RegisterType(GType native_type, System.Type type)
 {
     GType.Register (native_type, type);
 }
Ejemplo n.º 7
0
 protected InitiallyUnowned(GType gtype)
     : base(gtype)
 {
 }
Ejemplo n.º 8
0
 protected Object(GType gtype)
 {
     Raw = g_object_new (gtype.Val, IntPtr.Zero);
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
0
 static void OverridePropertyHandlers(GType gtype, GetPropertyDelegate get_cb, SetPropertyDelegate set_cb)
 {
     IntPtr class_ptr = gtype.ClassPtr;
     GObjectClass klass = (GObjectClass) Marshal.PtrToStructure (class_ptr, typeof (GObjectClass));
     klass.get_prop_cb = get_cb;
     klass.set_prop_cb = set_cb;
     Marshal.StructureToPtr (klass, class_ptr, false);
 }
Ejemplo n.º 11
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.ClassPtr;
            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;
        }
Ejemplo n.º 12
0
        private static void InvokeClassInitializers(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);
            }

            for (Type curr = t; curr != typeof(GObject.Object); curr = curr.BaseType) {

                if (curr.Assembly.IsDefined (typeof (IgnoreClassInitializersAttribute), false))
                    continue;

                foreach (MethodInfo minfo in curr.GetMethods(flags))
                    if (minfo.IsDefined (typeof (ClassInitializerAttribute), true))
                        minfo.Invoke (null, parms);
            }
        }
Ejemplo n.º 13
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);
                    object[] parms = new object [1];
                    parms [0] = gtype;
                    connector.Invoke (null, parms);
                    break;
                }
            }
        }
Ejemplo n.º 14
0
        static void AddProperties(GType gtype, System.Type t)
        {
            uint idx = 1;

            bool handlers_overridden = false;
            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("GObject.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName)));

                    PropertyAttribute property_attr = attr as PropertyAttribute;
                    if (!handlers_overridden) {
                        OverridePropertyHandlers (gtype, GetPropertyHandler, SetPropertyHandler);
                        handlers_overridden = true;
                    }

                    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 ("GObject.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName));
                    }
                }
            }
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
 protected static void OverrideVirtualMethod(GType gtype, string name, Delegate cb)
 {
     Signal.OverrideDefaultHandler (gtype, name, cb);
 }