예제 #1
0
        public static T qobject_cast <T>(QObject obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }
            Type t = typeof(T);

            try {
                return((T)(object)obj);
            } catch {}
            if (!SmokeMarshallers.IsSmokeClass(t))
            {
                return(null);
            }
            string className = SmokeMarshallers.SmokeClassName(t);
            IntPtr ret       = qyoto_qt_metacast((IntPtr)GCHandle.Alloc(obj),className);

            if (ret == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                GCHandle handle = (GCHandle)ret;
                object   target = handle.Target;
                handle.SynchronizedFree();
                return((T)target);
            }
        }
        public override QSizeF DocumentSize()
        {
            GCHandle ret = (GCHandle)QAbstractTextDocumentLayoutDocumentSize((IntPtr)GCHandle.Alloc(this));
            QSizeF   s   = (QSizeF)ret.Target;

            ret.SynchronizedFree();
            return(s);
        }
예제 #3
0
        public override QRect VisualRect(QModelIndex index)
        {
            GCHandle ret = (GCHandle)QAbstractItemViewVisualRect((IntPtr)GCHandle.Alloc(this),
                                                                 (IntPtr)GCHandle.Alloc(index));
            QRect r = (QRect)ret.Target;

            ret.SynchronizedFree();
            return(r);
        }
예제 #4
0
        public override QModelIndex IndexAt(QPoint point)
        {
            GCHandle ret = (GCHandle)QAbstractItemViewIndexAt((IntPtr)GCHandle.Alloc(this),
                                                              (IntPtr)GCHandle.Alloc(point));
            QModelIndex i = (QModelIndex)ret.Target;

            ret.SynchronizedFree();
            return(i);
        }
        public override QModelIndex MapToSource(QModelIndex proxyIndex)
        {
            GCHandle ret = (GCHandle)QAbstractProxyModelMapToSource((IntPtr)GCHandle.Alloc(this),
                                                                    (IntPtr)GCHandle.Alloc(proxyIndex));
            QModelIndex ix = (QModelIndex)ret.Target;

            ret.SynchronizedFree();
            return(ix);
        }
        public override QModelIndex Index(int row, int column, QModelIndex parent)
        {
            GCHandle ret = (GCHandle)QAbstractItemModelIndex((IntPtr)GCHandle.Alloc(this), row, column,
                                                             (IntPtr)GCHandle.Alloc(parent));
            QModelIndex ix = (QModelIndex)ret.Target;

            ret.SynchronizedFree();
            return(ix);
        }
        public override QModelIndex Parent(QModelIndex child)
        {
            GCHandle ret = (GCHandle)QAbstractItemModelParent((IntPtr)GCHandle.Alloc(this),
                                                              (IntPtr)GCHandle.Alloc(child));
            QModelIndex ix = (QModelIndex)ret.Target;

            ret.SynchronizedFree();
            return(ix);
        }
        public override QRectF FrameBoundingRect(QTextFrame frame)
        {
            GCHandle ret = (GCHandle)QAbstractTextDocumentLayoutFrameBoundingRect((IntPtr)GCHandle.Alloc(this),
                                                                                  (IntPtr)GCHandle.Alloc(frame));
            QRectF r = (QRectF)ret.Target;

            ret.SynchronizedFree();
            return(r);
        }
예제 #9
0
        public override QVariant Data(QModelIndex index, int role)
        {
            GCHandle ret = (GCHandle)QAbstractItemModelData((IntPtr)GCHandle.Alloc(this),
                                                            (IntPtr)GCHandle.Alloc(index), role);
            QVariant v = (QVariant)ret.Target;

            ret.SynchronizedFree();
            return(v);
        }
예제 #10
0
        // A variant of Invoke() for use in method calls with 'ref' argument types.
        // The caller is responsible for setting up the stack, and copying items
        // back from the stack to the arguments after Invoke() has been called.
        public void Invoke(string mungedName, string signature, StackItem[] stack)
        {
#if DEBUG
            if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0)
            {
                Console.WriteLine("ENTER SmokeInvocation.Invoke1() MethodName: {0}.{1}",
                                  className,
                                  signature);
            }
#endif

            ModuleIndex methodId;
            methodId.smoke = IntPtr.Zero;
            methodId.index = -1;
            if (!methodIdCache.TryGetValue(signature, out methodId))
            {
                methodId = FindMethodId(className, mungedName, signature);

                if (methodId.index == -1)
                {
                    Console.Error.WriteLine("LEAVE Invoke() ** Missing method ** {0}.{1}",
                                            className,
                                            signature);
                    return;
                }

                methodIdCache[signature] = methodId;
            }

            unsafe
            {
                fixed(StackItem *stackPtr = stack)
                {
                    if (instance == null)
                    {
                        CallSmokeMethod(methodId.smoke, (int)methodId.index, (IntPtr)0, (IntPtr)stackPtr, stack.Length);
                    }
                    else
                    {
#if DEBUG
                        GCHandle instanceHandle = DebugGCHandle.Alloc(instance);
#else
                        GCHandle instanceHandle = GCHandle.Alloc(instance);
#endif
                        CallSmokeMethod(methodId.smoke, methodId.index, (IntPtr)instanceHandle, (IntPtr)stackPtr, stack.Length);
#if DEBUG
                        DebugGCHandle.Free(instanceHandle);
#else
                        instanceHandle.SynchronizedFree();
#endif
                    }
                }
            }

            return;
        }
예제 #11
0
        public override QSize SizeHint(QStyleOptionViewItem option, QModelIndex index)
        {
            GCHandle ret = (GCHandle)QAbstractItemDelegateSizeHint((IntPtr)GCHandle.Alloc(this),
                                                                   (IntPtr)GCHandle.Alloc(option),
                                                                   (IntPtr)GCHandle.Alloc(index));
            QSize s = (QSize)ret.Target;

            ret.SynchronizedFree();
            return(s);
        }
예제 #12
0
        public static void Free(GCHandle handle)
        {
            if (QDebug.debugLevel >= DebugLevel.High &&
                (QDebug.DebugChannel() & QtDebugChannel.QTDB_GC) != 0)
            {
                Console.WriteLine("GCHandle.Free 0x{0:x8} -> {1}", (IntPtr)handle, handle.Target);
            }

            handle.SynchronizedFree();
        }
예제 #13
0
        public object Invoke(string mungedName, string signature, Type returnType, params object[] args)
        {
#if DEBUG
            if ((QDebug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0)
            {
                Console.WriteLine("ENTER SmokeInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}",
                                  className,
                                  signature,
                                  returnType,
                                  args.Length / 2);
            }
#endif

            if (signature.StartsWith("operator=="))
            {
                if (args[1] == null && args[3] == null)
                {
                    return(true);
                }
                else if (args[1] == null || args[3] == null)
                {
                    return(false);
                }
            }
            ModuleIndex methodId;
            methodId.smoke = IntPtr.Zero;
            methodId.index = -1;
            if (!methodIdCache.TryGetValue(signature, out methodId))
            {
                methodId = FindMethodId(className, mungedName, signature);

                if (methodId.index == -1)
                {
                    Console.Error.WriteLine("LEAVE Invoke() ** Missing method ** {0}.{1}",
                                            className,
                                            signature);
                    return(null);
                }

                methodIdCache[signature] = methodId;
            }

            StackItem[] stack = new StackItem[(args.Length / 2) + 1];

            for (int i = 0, k = 1; i < args.Length; i += 2, k++)
            {
                if (args[i + 1] == null)
                {
                    unsafe {
                        stack[k].s_class = IntPtr.Zero;
                    }
                }
                else if (args[i] == typeof(int) || ((Type)args[i]).IsEnum)
                {
                    stack[k].s_int = (int)args[i + 1];
                }
                else if (args[i] == typeof(bool))
                {
                    stack[k].s_bool = (bool)args[i + 1];
                }
                else if (args[i] == typeof(short))
                {
                    stack[k].s_short = (short)args[i + 1];
                }
                else if (args[i] == typeof(float))
                {
                    stack[k].s_float = (float)args[i + 1];
                }
                else if (args[i] == typeof(double))
                {
                    stack[k].s_double = (double)args[i + 1];
                }
                else if (args[i] == typeof(long))
                {
                    stack[k].s_long = (long)args[i + 1];
                }
                else if (args[i] == typeof(ushort))
                {
                    stack[k].s_ushort = (ushort)args[i + 1];
                }
                else if (args[i] == typeof(uint))
                {
                    stack[k].s_uint = (uint)args[i + 1];
                }
                else if (args[i] == typeof(ulong))
                {
                    stack[k].s_ulong = (ulong)args[i + 1];
                }
                else if (args[i] == typeof(sbyte))
                {
                    stack[k].s_char = (sbyte)args[i + 1];
                }
                else if (args[i] == typeof(byte))
                {
                    stack[k].s_uchar = (byte)args[i + 1];
                }
                else if (args[i] == typeof(char))
                {
                    stack[k].s_uchar = (byte)(char)args[i + 1];
                }
                else
                {
#if DEBUG
                    stack[k].s_class = (IntPtr)DebugGCHandle.Alloc(args[i + 1]);
#else
                    stack[k].s_class = (IntPtr)GCHandle.Alloc(args[i + 1]);
#endif
                }
            }

            object returnValue = null;

            unsafe
            {
                fixed(StackItem *stackPtr = stack)
                {
                    if (instance == null)
                    {
                        CallSmokeMethod(methodId.smoke, (int)methodId.index, (IntPtr)0, (IntPtr)stackPtr, args.Length / 2);
                    }
                    else
                    {
#if DEBUG
                        GCHandle instanceHandle = DebugGCHandle.Alloc(instance);
#else
                        GCHandle instanceHandle = GCHandle.Alloc(instance);
#endif
                        CallSmokeMethod(methodId.smoke, methodId.index, (IntPtr)instanceHandle, (IntPtr)stackPtr, args.Length / 2);
#if DEBUG
                        DebugGCHandle.Free(instanceHandle);
#else
                        instanceHandle.SynchronizedFree();
#endif
                    }

                    if (returnType == typeof(void))
                    {
                        ;
                    }
                    else if (returnType == typeof(int))
                    {
                        returnValue = stack[0].s_int;
                    }
                    else if (returnType == typeof(bool))
                    {
                        returnValue = stack[0].s_bool;
                    }
                    else if (returnType == typeof(short))
                    {
                        returnValue = stack[0].s_short;
                    }
                    else if (returnType == typeof(float))
                    {
                        returnValue = stack[0].s_float;
                    }
                    else if (returnType == typeof(double))
                    {
                        returnValue = stack[0].s_double;
                    }
                    else if (returnType == typeof(long))
                    {
                        // s_long will contain the wrong value on 32 bit platforms
                        // (i.e. where a native C++ 'long' isn't at least 64 bit)
                        returnValue = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stack[0].s_int : stack[0].s_long;
                    }
                    else if (returnType == typeof(ushort))
                    {
                        returnValue = stack[0].s_ushort;
                    }
                    else if (returnType == typeof(uint))
                    {
                        returnValue = stack[0].s_uint;
                    }
                    else if (returnType.IsEnum)
                    {
                        returnValue = Enum.ToObject(returnType, stack[0].s_int);
                    }
                    else if (returnType == typeof(ulong))
                    {
                        returnValue = (SmokeMarshallers.SizeOfNativeLong < sizeof(long))? stack[0].s_uint : stack[0].s_ulong;
                    }
                    else if (returnType == typeof(sbyte))
                    {
                        returnValue = stack[0].s_char;
                    }
                    else if (returnType == typeof(byte))
                    {
                        returnValue = stack[0].s_uchar;
                    }
                    else if (returnType == typeof(char))
                    {
                        returnValue = (char)stack[0].s_char;
                    }
                    else
                    {
                        if (((IntPtr)stack[0].s_class) == IntPtr.Zero)
                        {
                            returnValue = null;
                        }
                        else
                        {
                            returnValue = ((GCHandle)stack[0].s_class).Target;
#if DEBUG
                            DebugGCHandle.Free((GCHandle)stack[0].s_class);
#else
                            ((GCHandle)stack[0].s_class).SynchronizedFree();
#endif
                        }
                    }
                }
            }

            return(returnValue);
        }
예제 #14
0
        static public QVariant FromValue(object value, Type valueType)
        {
            if (valueType == typeof(bool))
            {
                return(new QVariant((bool)value));
            }
            else if (valueType == typeof(double))
            {
                return(new QVariant((double)value));
            }
            else if (valueType == typeof(QBitArray))
            {
                return(new QVariant((QBitArray)value));
            }
            else if (valueType == typeof(QByteArray))
            {
                return(new QVariant((QByteArray)value));
            }
            else if (valueType == typeof(char))
            {
                return(new QVariant(new QChar((char)value)));
            }
            else if (valueType == typeof(QDate))
            {
                return(new QVariant((QDate)value));
            }
            else if (valueType == typeof(QDateTime))
            {
                return(new QVariant((QDateTime)value));
            }
            else if (valueType == typeof(int))
            {
                return(new QVariant((int)value));
            }
            else if (valueType == typeof(QLine))
            {
                return(new QVariant((QLine)value));
            }
            else if (valueType == typeof(QLineF))
            {
                return(new QVariant((QLineF)value));
            }
            else if (valueType == typeof(QLocale))
            {
                return(new QVariant((QLocale)value));
            }
            else if (valueType == typeof(QPoint))
            {
                return(new QVariant((QPoint)value));
            }
            else if (valueType == typeof(QPointF))
            {
                return(new QVariant((QPointF)value));
            }
            else if (valueType == typeof(QRect))
            {
                return(new QVariant((QRect)value));
            }
            else if (valueType == typeof(QRectF))
            {
                return(new QVariant((QRectF)value));
            }
            else if (valueType == typeof(QRegExp))
            {
                return(new QVariant((QRegExp)value));
            }
            else if (valueType == typeof(QSize))
            {
                return(new QVariant((QSize)value));
            }
            else if (valueType == typeof(QSizeF))
            {
                return(new QVariant((QSizeF)value));
            }
            else if (valueType == typeof(string))
            {
                return(new QVariant((string)value));
            }
            else if (valueType == typeof(List <string>))
            {
                return(new QVariant((List <string>)value));
            }
            else if (valueType == typeof(List <QVariant>))
            {
                return(new QVariant((List <QVariant>)value));
            }
            else if (valueType == typeof(Dictionary <string, QVariant>))
            {
                return(new QVariant((Dictionary <string, QVariant>)value));
            }
            else if (valueType == typeof(QTime))
            {
                return(new QVariant((QTime)value));
            }
            else if (valueType == typeof(uint))
            {
                return(new QVariant((uint)value));
            }
            else if (valueType == typeof(QUrl))
            {
                return(new QVariant((QUrl)value));
            }
            else if (valueType == typeof(QVariant))
            {
                return(new QVariant((QVariant)value));
            }
            else if (valueType.IsEnum)
            {
                return(new QVariant((int)value));
            }
            else
            {
                string typeName;
                if (SmokeMarshallers.IsSmokeClass(valueType))
                {
                    typeName = SmokeMarshallers.SmokeClassName(valueType);
                }
                else
                {
                    typeName = valueType.ToString();
                }
                TypeOf type = NameToType(typeName);
                if (type == TypeOf.Invalid)
                {
                    throw new Exception(string.Format("Type {0} not registered!", valueType.ToString()));
                }
                else if (type > TypeOf.LastCoreType)
                {
                    IntPtr valueHandle = IntPtr.Zero;
                    if (value != null)
                    {
                        valueHandle = (IntPtr)GCHandle.Alloc(value);
                    }
                    GCHandle handle = (GCHandle)QVariantFromValue(QMetaType.type(typeName), valueHandle);
                    QVariant v      = (QVariant)handle.Target;
                    handle.SynchronizedFree();
                    return(v);
                }

                return(new QVariant());
            }
        }