[Kde-bindings] KDE/kdebindings/csharp/kimono

Arno Rehn kde at arnorehn.de
Fri Jan 9 01:14:10 UTC 2009


SVN commit 907979 by arnorehn:

* Special case KPluginFactory.Create() for now until we
  fix the 'bug' in Smoke.

CCMAIL: kde-bindings at kde.org



 M  +20 -1     kde/KPluginFactoryExtras.cs  
 M  +46 -0     src/kimono.cpp  


--- trunk/KDE/kdebindings/csharp/kimono/kde/KPluginFactoryExtras.cs #907978:907979
@@ -1,9 +1,13 @@
 namespace Kimono {
 	using System;
 	using System.Collections.Generic;
+	using System.Runtime.InteropServices;
 	using Qyoto;
 
 	public partial class KPluginFactory : QObject, IDisposable {
+		[DllImport("kimono", CharSet=CharSet.Ansi)]
+		static extern IntPtr KPluginFactory_Create(IntPtr self, string classname, IntPtr parentWidget, IntPtr parent, IntPtr[] args, int numArgs, string keyword);
+
 		public T Create<T>() where T: class {
 			return Create<T>((QObject) null);
 		}
@@ -48,7 +52,22 @@
 			if (!SmokeMarshallers.IsSmokeClass(type))
 				throw new Exception("The generic type must be included in the bindings");
 			
-			QObject o = Create(SmokeMarshallers.SmokeClassName(type), parentWidget, parent, args, keyword);
+			IntPtr[] array = new IntPtr[args.Count];
+			for (int i = 0; i < args.Count; i++) {
+				array[i] = (IntPtr) GCHandle.Alloc(args[i]);
+			}
+			
+			IntPtr pw = IntPtr.Zero;
+			if (parentWidget != null)
+				pw = (IntPtr) GCHandle.Alloc(parentWidget);
+
+			IntPtr p = IntPtr.Zero;
+			if (parent != null)
+				p = (IntPtr) GCHandle.Alloc(parent);
+
+			IntPtr ret = KPluginFactory_Create((IntPtr) GCHandle.Alloc(this), SmokeMarshallers.SmokeClassName(type), pw, p,
+			                                   array, array.Length, keyword);
+			QObject o = (ret != IntPtr.Zero) ? (QObject) ((GCHandle) ret).Target : null;
 			T t = qobject_cast<T>(o);
 			if (t == null && o != null)
 				o.Dispose();
--- trunk/KDE/kdebindings/csharp/kimono/src/kimono.cpp #907978:907979
@@ -31,6 +31,7 @@
 #include <QMimeData>
 #include <QStringList>
 
+#include <KPluginFactory>
 #include <KUrl>
 
 QHash<int, char*> classNames;
@@ -117,6 +118,51 @@
 	}
 }
 
+class KPluginFactory_Create_Caller : public KPluginFactory
+{
+public:
+	QObject *call_create(const char *iface, QWidget *parentWidget,
+	                     QObject *parent, const QVariantList &args,
+	                     const QString &keyword)
+	{
+		return create(iface, parentWidget, parent, args, keyword);
+	}
+};
+
+Q_DECL_EXPORT void*
+KPluginFactory_Create(void *self, const char *classname, void *parentWidget, void *parent, void **args, int numArgs, const char *keyword)
+{
+	smokeqyoto_object *o = (smokeqyoto_object*) (*GetSmokeObject)(self);
+	(*FreeGCHandle)(self);
+	KPluginFactory_Create_Caller *factory = (KPluginFactory_Create_Caller*) o->ptr;
+	
+	QWidget *pw = 0;
+	if (parentWidget) {
+		o = (smokeqyoto_object*) (*GetSmokeObject)(parentWidget);
+		(*FreeGCHandle)(parentWidget);
+		pw = (QWidget*) o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QWidget").index);
+	}
+	
+	QObject *p = 0;
+	if (parent) {
+		o = (smokeqyoto_object*) (*GetSmokeObject)(parent);
+		(*FreeGCHandle)(parent);
+		p = (QObject*) o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject").index);
+	}
+	
+	QVariantList list;
+	for (int i = 0; i < numArgs; i++) {
+		o = (smokeqyoto_object*) (*GetSmokeObject)(args[i]);
+		(*FreeGCHandle)(args[i]);
+		list << *((QVariant*) o->ptr);
+	}
+	
+	QObject *ret = factory->call_create(classname, pw, p, list, keyword);
+	smokeqyoto_object *obj = alloc_smokeqyoto_object(false, qt_Smoke, qt_Smoke->idClass("QObject").index, ret);
+	const char *name = qyoto_resolve_classname(obj);
+	return (*CreateInstance)(name, obj);
+}
+
 extern Q_DECL_EXPORT void Init_kimono();
 
 static Qyoto::Binding binding;



More information about the Kde-bindings mailing list