mirror of https://github.com/mono/CppSharp.git
Browse Source
multiple inheritance. Automatic marshaling support for ICppObject with custom marshaler. Improvements to name mangling for ItaniumAbi. Lots more TODOs. git-svn-id: https://mono-soc-2010.googlecode.com/svn/trunk/cppinterop@50 a470b8cb-0e6f-1642-1b45-71e107334c4bpull/1/head
20 changed files with 568 additions and 96 deletions
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using Mono.VisualC.Interop; |
||||
|
||||
namespace Qt.Core { |
||||
[StructLayout (LayoutKind.Sequential)] |
||||
public struct QSize { |
||||
public int wd; |
||||
public int ht; |
||||
|
||||
public QSize (int w, int h) |
||||
{ |
||||
this.wd = w; |
||||
this.ht = h; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
using System; |
||||
using System.Text; |
||||
using System.Runtime.InteropServices; |
||||
using Mono.VisualC.Interop; |
||||
|
||||
namespace Qt.Core { |
||||
//TODO: Will this leak?
|
||||
[StructLayout (LayoutKind.Sequential)] |
||||
public unsafe struct QString { |
||||
#region Sync with qstring.h
|
||||
public interface IQString : ICppClass { |
||||
void QString(ref QString @this, |
||||
[MangleAs (typeof (QChar), Modifiers=CppModifiers.PointerToConst)] |
||||
IntPtr unicode, int size); |
||||
} |
||||
[StructLayout (LayoutKind.Sequential)] |
||||
private struct QChar {} |
||||
|
||||
[StructLayout (LayoutKind.Sequential)] |
||||
public struct Data { |
||||
public int @ref; |
||||
public int alloc, size; |
||||
public IntPtr data; |
||||
public ushort clean; |
||||
public ushort simpletext; |
||||
public ushort righttoleft; |
||||
public ushort asciiCache; |
||||
public ushort capacity; |
||||
public ushort reserved; |
||||
public IntPtr array; |
||||
} |
||||
|
||||
|
||||
public Data* d; |
||||
#endregion
|
||||
|
||||
private static IQString impl = Qt.Libs.QtCore.GetClass<IQString> ("QString"); |
||||
|
||||
public QString (string str) |
||||
{ |
||||
IntPtr strPtr = Marshal.StringToHGlobalUni (str); |
||||
impl.QString (ref this, strPtr, str.Length); |
||||
Marshal.FreeHGlobal (strPtr); |
||||
|
||||
// TODO: I deref this on construction to let Qt free it when it's done with it.
|
||||
// My assumption is that this struct will only be used to interop with Qt and
|
||||
// no managed class is going to hold on to it.
|
||||
this.DeRef (); |
||||
} |
||||
|
||||
public static implicit operator QString (string str) |
||||
{ |
||||
return new QString (str); |
||||
} |
||||
|
||||
public QString AddRef () |
||||
{ |
||||
d->@ref++; |
||||
return this; |
||||
} |
||||
|
||||
public QString DeRef () |
||||
{ |
||||
d->@ref--; |
||||
return this; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
using System; |
||||
using Mono.VisualC.Interop; |
||||
|
||||
namespace Qt.Gui { |
||||
public class QAbstractButton : QWidget { |
||||
#region Sync with qabstractbutton.h
|
||||
// C++ interface
|
||||
public interface IQAbstractButton : ICppClassOverridable<QAbstractButton>, Base<QWidget.IQWidget> { |
||||
// ...
|
||||
void QAbstractButton (CppInstancePtr @this, QWidget parent); |
||||
// ...
|
||||
[Virtual] void paintEvent (CppInstancePtr @this, /*QPaintEvent */ IntPtr e); // abstract
|
||||
[Virtual] bool hitButton (CppInstancePtr @this, /*const QPoint &*/ IntPtr pos); |
||||
[Virtual] void checkStateSet (CppInstancePtr @this); |
||||
[Virtual] void nextCheckState (CppInstancePtr @this); |
||||
} |
||||
private struct _QAbstractButton { |
||||
} |
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public QAbstractButton (IntPtr native) : base (native) |
||||
{ |
||||
} |
||||
/* |
||||
public override int NativeSize { |
||||
get { return impl.NativeSize + base.NativeSize; } |
||||
} |
||||
*/ |
||||
public override void Dispose () |
||||
{ |
||||
throw new Exception ("This should never be called!"); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
using System; |
||||
using Mono.VisualC.Interop; |
||||
|
||||
namespace Qt.Gui { |
||||
public class QPaintDevice : ICppObject { |
||||
#region Sync with qpaintdevice.h
|
||||
// C++ interface
|
||||
public interface IQPaintDevice : ICppClassOverridable<QPaintDevice> { |
||||
[Virtual] int devType (CppInstancePtr @this); |
||||
[Virtual] /*QPaintEngine */ IntPtr paintEngine (CppInstancePtr @this); // abstract
|
||||
//...
|
||||
void QPaintDevice (CppInstancePtr @this); |
||||
[Virtual] int metric (CppInstancePtr @this, /*PaintDeviceMetric*/ IntPtr metric); |
||||
} |
||||
// C++ fields
|
||||
private struct _QPaintDevice { |
||||
public ushort painters; |
||||
} |
||||
#endregion
|
||||
|
||||
private static IQPaintDevice impl = Qt.Libs.QtGui.GetClass<IQPaintDevice,_QPaintDevice,QPaintDevice> ("QPaintDevice"); |
||||
protected CppInstancePtr native; |
||||
|
||||
/* no point to this - subclasses will call QPaintDevice (IntPtr.Zero) |
||||
protected QPaintDevice () |
||||
{ |
||||
|
||||
} |
||||
*/ |
||||
|
||||
public QPaintDevice (IntPtr native) |
||||
{ |
||||
this.native = native; |
||||
} |
||||
|
||||
public IntPtr Native { |
||||
get { return (IntPtr)native; } |
||||
} |
||||
|
||||
public virtual int NativeSize { |
||||
get { return impl.NativeSize; } |
||||
} |
||||
|
||||
public void Dispose () |
||||
{ |
||||
throw new Exception ("This should never be called!"); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
using System; |
||||
using Mono.VisualC.Interop; |
||||
using Qt.Core; |
||||
|
||||
namespace Qt.Gui { |
||||
public class QPushButton : QAbstractButton { |
||||
#region Sync with qpushbutton.h
|
||||
// C++ interface
|
||||
public interface IQPushButton : ICppClassOverridable<QPushButton>, Base<QAbstractButton.IQAbstractButton> { |
||||
// ...
|
||||
void QPushButton (CppInstancePtr @this, [Const] ref QString text, |
||||
QWidget parent); |
||||
// ...
|
||||
} |
||||
// C++ fields
|
||||
private struct _QPushButton { |
||||
} |
||||
#endregion
|
||||
|
||||
private IQPushButton impl = Qt.Libs.QtGui.GetClass<IQPushButton,_QPushButton,QPushButton> ("QPushButton"); |
||||
|
||||
public QPushButton (string btnText, QWidget parent) : base (IntPtr.Zero) |
||||
{ |
||||
this.native = impl.Alloc (this); |
||||
|
||||
QString text = btnText; |
||||
impl.QPushButton (native, ref text, parent); |
||||
} |
||||
|
||||
public QPushButton (string text) : this (text, null) |
||||
{ |
||||
} |
||||
|
||||
public QPushButton (IntPtr native) : base (native) |
||||
{ |
||||
} |
||||
|
||||
public override int NativeSize { |
||||
get { return impl.NativeSize + base.NativeSize; } |
||||
} |
||||
|
||||
public override void Dispose () |
||||
{ |
||||
impl.Destruct (native); |
||||
native.Dispose (); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using Mono.VisualC.Interop; |
||||
|
||||
using Qt.Core; |
||||
|
||||
namespace Qt.Gui { |
||||
public class QWidget : QObject { |
||||
#region Sync with qwidget.h
|
||||
// C++ interface
|
||||
public interface IQWidget : ICppClassOverridable<QWidget>, Base<QObject.IQObject>, Base<QPaintDevice.IQPaintDevice> { |
||||
// ...
|
||||
void QWidget (CppInstancePtr @this, QWidget parent, /*Qt::WindowFlags */ int f); |
||||
// ...
|
||||
[Virtual] void setVisible (CppInstancePtr @this, bool visible); |
||||
// ...
|
||||
void resize (CppInstancePtr @this, [MangleAs (typeof (QSize), ByRef=true, Modifiers=CppModifiers.Const)] ref QSize size); |
||||
// ...
|
||||
[Virtual] /*QSize*/ int sizeHint (CppInstancePtr @this); |
||||
[Virtual] /*QSize*/ int minimumSizeHint (CppInstancePtr @this); |
||||
// ...
|
||||
[Virtual] int heightForWidth (CppInstancePtr @this, int width); |
||||
// ... protected:
|
||||
[Virtual] void mousePressEvent (CppInstancePtr @this, /*QMouseEvent */ IntPtr p); |
||||
[Virtual] void mouseReleaseEvent (CppInstancePtr @this, /*QMouseEvent */ IntPtr p); |
||||
[Virtual] void mouseDoubleClickEvent (CppInstancePtr @this, /*QMouseEvent */ IntPtr p); |
||||
[Virtual] void mouseMoveEvent (CppInstancePtr @this, /*QMouseEvent */ IntPtr p); |
||||
[Virtual] void wheelEvent (CppInstancePtr @this, /*QWheelEvent */ IntPtr p); |
||||
[Virtual] void keyPressEvent (CppInstancePtr @this, /*QKeyEvent */ IntPtr p); |
||||
[Virtual] void keyReleaseEvent (CppInstancePtr @this, /*QKeyEvent */ IntPtr p); |
||||
[Virtual] void focusInEvent (CppInstancePtr @this, /*QFocusEvent */ IntPtr p); |
||||
[Virtual] void focusOutEvent (CppInstancePtr @this, /*QFocusEvent */ IntPtr p); |
||||
[Virtual] void enterEvent (CppInstancePtr @this, /*QEvent */ IntPtr p); |
||||
[Virtual] void leaveEvent (CppInstancePtr @this, /*QEvent */ IntPtr p); |
||||
[Virtual] void paintEvent (CppInstancePtr @this, /*QPaintEvent */ IntPtr p); |
||||
[Virtual] void moveEvent (CppInstancePtr @this, /*QMoveEvent */ IntPtr p); |
||||
[Virtual] void resizeEvent (CppInstancePtr @this, /*QResizeEvent */ IntPtr p); |
||||
[Virtual] void closeEvent (CppInstancePtr @this, /*QCloseEvent */ IntPtr p); |
||||
[Virtual] void contextMenuEvent (CppInstancePtr @this, /*QContextMenuEvent */ IntPtr p); |
||||
[Virtual] void tabletEvent (CppInstancePtr @this, /*QTabletEvent */ IntPtr p); |
||||
[Virtual] void actionEvent (CppInstancePtr @this, /*QActionEvent */ IntPtr p); |
||||
[Virtual] void dragEnterEvent (CppInstancePtr @this, /*QDragEnterEvent */ IntPtr p); |
||||
[Virtual] void dragMoveEvent (CppInstancePtr @this, /*QDragMoveEvent */ IntPtr p); |
||||
[Virtual] void dragLeaveEvent (CppInstancePtr @this, /*QDragLeaveEvent */ IntPtr p); |
||||
[Virtual] void dropEvent (CppInstancePtr @this, /*QDropEvent */ IntPtr p); |
||||
[Virtual] void showEvent (CppInstancePtr @this, /*QShowEvent */ IntPtr p); |
||||
[Virtual] void hideEvent (CppInstancePtr @this, /*QHideEvent */ IntPtr p); |
||||
[Virtual] bool macEvent (CppInstancePtr @this, /*EventHandlerCallRef */ IntPtr p1, /*EventRef */ IntPtr p2); |
||||
[Virtual] void changeEvent (CppInstancePtr @this, /*QEvent */ IntPtr p); |
||||
// ...
|
||||
[Virtual] void inputMethodEvent (CppInstancePtr @this, /*QInputMethodEvent */ IntPtr p); |
||||
|
||||
//public:
|
||||
[Virtual] /*QVariant*/ IntPtr inputMethodQuery (CppInstancePtr @this, /*Qt::InputMethodQuery */ int x); |
||||
// ... protected:
|
||||
[Virtual] bool focusNextPrevChild (CppInstancePtr @this, bool next); |
||||
|
||||
// TODO: Determine correct number of vtable slots here too...
|
||||
[Virtual] void foo1 (CppInstancePtr @this); |
||||
[Virtual] void foo2 (CppInstancePtr @this); |
||||
[Virtual] void foo3 (CppInstancePtr @this); |
||||
[Virtual] void foo4 (CppInstancePtr @this); |
||||
[Virtual] void foo5 (CppInstancePtr @this); |
||||
[Virtual] void foo6 (CppInstancePtr @this); |
||||
[Virtual] void foo7 (CppInstancePtr @this); |
||||
[Virtual] void foo8 (CppInstancePtr @this); |
||||
} |
||||
// C++ fields
|
||||
private struct _QWidget { |
||||
public IntPtr data; |
||||
} |
||||
#endregion
|
||||
|
||||
private static IQWidget impl = Qt.Libs.QtGui.GetClass<IQWidget,_QWidget,QWidget> ("QWidget"); |
||||
|
||||
// TODO: ctor ...
|
||||
|
||||
public QWidget (IntPtr native) : base (native) |
||||
{ |
||||
} |
||||
|
||||
public bool Visible { |
||||
get { |
||||
throw new NotImplementedException (); |
||||
} |
||||
set { |
||||
impl.setVisible (native, value); |
||||
} |
||||
} |
||||
|
||||
public void Resize (int width, int height) |
||||
{ |
||||
QSize s = new QSize (width, height); |
||||
impl.resize (native, ref s); |
||||
} |
||||
|
||||
// TODO: HELP! I think this really should be:
|
||||
// sizeof(QWidget) [impl.NativeSize] + sizeof(QObject) [base.NativeSize] + sizeof(QPaintDevice) [????]
|
||||
// Works for now because we're already alloc'ing too much memory!!? (NativeSize property contains vtbl pointer)
|
||||
public override int NativeSize { |
||||
get { return impl.NativeSize + base.NativeSize; } |
||||
} |
||||
|
||||
public override void Dispose () |
||||
{ |
||||
throw new NotImplementedException (); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue