Пример #1
0
        static IntPtr ConstructorCallback(IntPtr gtypeval, uint n_construct_properties, IntPtr construct_properties)
        {
            GType        gtype            = new GLib.GType(gtypeval);
            GObjectClass threshold_class  = (GObjectClass)Marshal.PtrToStructure(gtype.GetThresholdType().GetClassPtr(), typeof(GObjectClass));
            IntPtr       raw              = threshold_class.constructor_cb(gtypeval, n_construct_properties, construct_properties);
            bool         construct_needed = true;

            for (int i = 0; i < n_construct_properties; i++)
            {
                IntPtr p = new IntPtr(construct_properties.ToInt64() + i * 2 * IntPtr.Size);

                string prop_name = Marshaller.Utf8PtrToString(g_param_spec_get_name(Marshal.ReadIntPtr(p)));
                if (prop_name != "gtk-sharp-managed-instance")
                {
                    continue;
                }

                Value val = (Value)Marshal.PtrToStructure(Marshal.ReadIntPtr(p, IntPtr.Size), typeof(Value));
                if ((IntPtr)val.Val != IntPtr.Zero)
                {
                    GCHandle gch = (GCHandle)(IntPtr)val.Val;
                    Object   o   = (GLib.Object)gch.Target;
                    o.Raw            = raw;
                    construct_needed = false;
                    break;
                }
            }

            if (construct_needed)
            {
                GetObject(raw, false);
            }

            return(raw);
        }
Пример #2
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());
        }
Пример #3
0
        public GException(IntPtr errptr)
        {
            var err = (GError)Marshal.PtrToStructure(errptr, typeof(GError));

            Domain = err.Domain;
            Code   = err.Code;
            msg    = Marshaller.Utf8PtrToString(err.Msg);
            g_clear_error(ref errptr);
        }
Пример #4
0
        internal object DataMarshal(IntPtr data)
        {
            object ret = null;

            if (element_type != null)
            {
                if (element_type == typeof(string))
                {
                    ret = Marshaller.Utf8PtrToString(data);
                }
                else if (element_type == typeof(FilenameString))
                {
                    ret = Marshaller.FilenamePtrToString(data);
                }
                else if (element_type == typeof(IntPtr))
                {
                    ret = data;
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Object)))
                {
                    ret = GLib.Object.GetObject(data, false);
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Opaque)))
                {
                    ret = GLib.Opaque.GetOpaque(data, element_type, elements_owned);
                }
                else if (element_type == typeof(int))
                {
                    ret = (int)data;
                }
                else if (element_type.IsValueType)
                {
                    ret = Marshal.PtrToStructure(data, element_type);
                }
                else if (element_type.IsInterface)
                {
                    Type adapter_type = element_type.Assembly.GetType(InterfaceToAdapterTypeName(element_type));
                    System.Reflection.MethodInfo method = adapter_type.GetMethod("GetObject", new Type[] { typeof(IntPtr), typeof(bool) });
                    ret = method.Invoke(null, new object[] { data, false });
                }
                else
                {
                    ret = Activator.CreateInstance(element_type, new object[] { data });
                }
            }
            else if (Object.IsObject(data))
            {
                ret = GLib.Object.GetObject(data, false);
            }

            return(ret);
        }
Пример #5
0
        public string[] GetArgs(int argc)
        {
            int count = add_progname ? argc - 1 : argc;
            int idx   = add_progname ? 1 : 0;

            string[] result = new string [count];

            for (int i = 0; i < count; i++, idx++)
            {
                result [i] = Marshaller.Utf8PtrToString(Marshal.ReadIntPtr(handle, idx * IntPtr.Size));
            }

            return(result);
        }
Пример #6
0
        static void NativeCallback(IntPtr log_domain_native, LogLevelFlags flags, IntPtr message_native, IntPtr user_data)
        {
            if (user_data == IntPtr.Zero)
            {
                return;
            }
            string   log_domain = Marshaller.Utf8PtrToString(log_domain_native);
            string   message    = Marshaller.Utf8PtrToString(message_native);
            GCHandle gch        = (GCHandle)user_data;
            LogFunc  func       = gch.Target as LogFunc;

            if (func != null)
            {
                func(log_domain, flags, message);
            }
        }
Пример #7
0
        static IntPtr ConstructorCallback(IntPtr gtypeval, uint n_construct_properties, IntPtr construct_properties)
        {
            GType        gtype           = new GLib.GType(gtypeval);
            GObjectClass threshold_class = (GObjectClass)Marshal.PtrToStructure(gtype.GetThresholdType().GetClassPtr(), typeof(GObjectClass));
            IntPtr       raw             = threshold_class.constructor_cb(gtypeval, n_construct_properties, construct_properties);
            Dictionary <IntPtr, GLib.Value> deferred;

            GLib.Object obj = null;
            for (int i = 0; i < n_construct_properties; i++)
            {
                IntPtr p = new IntPtr(construct_properties.ToInt64() + i * 2 * IntPtr.Size);

                string prop_name = Marshaller.Utf8PtrToString(g_param_spec_get_name(Marshal.ReadIntPtr(p)));
                if (prop_name != "gtk-sharp-managed-instance")
                {
                    continue;
                }

                Value val = (Value)Marshal.PtrToStructure(Marshal.ReadIntPtr(p, IntPtr.Size), typeof(Value));
                if ((IntPtr)val.Val != IntPtr.Zero)
                {
                    GCHandle gch = (GCHandle)(IntPtr)val.Val;
                    obj     = (GLib.Object)gch.Target;
                    obj.Raw = raw;
                    break;
                }
            }

            if (obj == null)
            {
                obj = GetObject(raw, false);
            }

            if (PropertiesToSet.TryGetValue(raw, out deferred))
            {
                foreach (var item in deferred)
                {
                    SetDeferredProperty(obj, item.Value, item.Key);
                }
                PropertiesToSet.Remove(raw);
            }
            return(raw);
        }
Пример #8
0
        internal object DataMarshal(IntPtr data)
        {
            object ret = null;

            if (element_type != null)
            {
                if (element_type == typeof(string))
                {
                    ret = Marshaller.Utf8PtrToString(data);
                }
                else if (element_type == typeof(IntPtr))
                {
                    ret = data;
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Object)))
                {
                    ret = GLib.Object.GetObject(data, false);
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Opaque)))
                {
                    ret = GLib.Opaque.GetOpaque(data, element_type, elements_owned);
                }
                else if (element_type == typeof(int))
                {
                    ret = (int)data;
                }
                else if (element_type.IsValueType)
                {
                    ret = Marshal.PtrToStructure(data, element_type);
                }
                else
                {
                    ret = Activator.CreateInstance(element_type, new object[] { data });
                }
            }
            else if (Object.IsObject(data))
            {
                ret = GLib.Object.GetObject(data, false);
            }

            return(ret);
        }
Пример #9
0
        public static string GetFileContents(string filename)
        {
            int    length;
            IntPtr contents, error;
            IntPtr native_filename = Marshaller.StringToPtrGStrdup(filename);

            if (Global.IsWindowsPlatform)
            {
                if (!g_file_get_contents_utf8(native_filename, out contents, out length, out error))
                {
                    throw new GException(error);
                }
            }
            else
            {
                if (!g_file_get_contents(native_filename, out contents, out length, out error))
                {
                    throw new GException(error);
                }
            }

            Marshaller.Free(native_filename);
            return(Marshaller.Utf8PtrToString(contents));
        }
Пример #10
0
 public static string PtrToString(IntPtr ptr)
 {
     return(Marshaller.Utf8PtrToString(ptr));
 }
Пример #11
0
            void Callback(IntPtr nmessage)
            {
                string message = Marshaller.Utf8PtrToString(nmessage);

                managed(message);
            }
Пример #12
0
 public override string ToString()
 {
     return(Marshaller.Utf8PtrToString(g_type_name(val)));
 }
Пример #13
0
        public static Type LookupType(IntPtr typeid)
        {
            Type result;

            if (types.TryGetValue(typeid, out result))
            {
                return(result);
            }

            string native_name = Marshaller.Utf8PtrToString(g_type_name(typeid));
            string type_name   = GetQualifiedName(native_name);

            Assembly[] assemblies = (Assembly[])AppDomain.CurrentDomain.GetAssemblies().Clone();
            foreach (Assembly asm in assemblies)
            {
                result = asm.GetType(type_name);
                if (result != null)
                {
                    break;
                }
            }

            if (result == null)
            {
                // Because of lazy loading of references, it's possible the type's assembly
                // needs to be loaded.  We will look for it by name in the references of
                // the currently loaded assemblies.  Hopefully a recursive traversal is
                // not needed. We avoid one for now because of problems experienced
                // in a patch from bug #400595, and a desire to keep memory usage low
                // by avoiding a complete loading of all dependent assemblies.
                string ns       = type_name.Substring(0, type_name.LastIndexOf('.'));
                string asm_name = ns.ToLower().Replace('.', '-') + "-sharp";
                foreach (Assembly asm in assemblies)
                {
                    foreach (AssemblyName ref_name in asm.GetReferencedAssemblies())
                    {
                        if (ref_name.Name != asm_name)
                        {
                            continue;
                        }
                        try {
                            string   asm_dir = Path.GetDirectoryName(asm.Location);
                            Assembly ref_asm;
                            if (File.Exists(Path.Combine(asm_dir, ref_name.Name + ".dll")))
                            {
                                ref_asm = Assembly.LoadFrom(Path.Combine(asm_dir, ref_name.Name + ".dll"));
                            }
                            else
                            {
                                ref_asm = Assembly.Load(ref_name);
                            }
                            result = ref_asm.GetType(type_name);
                            if (result != null)
                            {
                                break;
                            }
                        } catch (Exception) {
                            /* Failure to load a referenced assembly is not an error */
                        }
                    }
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            Register(new GType(typeid), result);
            return(result);
        }
Пример #14
0
 public override string ToString()
 {
     return(Marshaller.Utf8PtrToString(g_variant_type_peek_string(Handle)));
 }