Browse Source

MSVC abi now runs QtTest as well as Itanium abi. Lots of refactorings to account for differences between abis.

git-svn-id: https://mono-soc-2010.googlecode.com/svn/trunk/cppinterop@79 a470b8cb-0e6f-1642-1b45-71e107334c4b
pull/1/head
alexander.corrado 15 years ago
parent
commit
10a82828b1
  1. 115
      Mono.VisualC.Interop/ABI/CppAbi.cs
  2. 23
      Mono.VisualC.Interop/ABI/Impl/ItaniumAbi.cs
  3. 22
      Mono.VisualC.Interop/ABI/Impl/MsvcAbi.cs
  4. 36
      Mono.VisualC.Interop/ABI/VTable.cs
  5. 4
      Mono.VisualC.Interop/ABI/VTableCOM.cs
  6. 11
      Mono.VisualC.Interop/ABI/VTableManaged.cs
  7. 25
      Mono.VisualC.Interop/Attributes.cs
  8. 2
      Mono.VisualC.Interop/Util.cs
  9. 1
      QtBindings/Core/QCoreApplication.cs
  10. 2
      QtBindings/Core/QObject.cs
  11. 1
      QtBindings/Gui/QAbstractButton.cs
  12. 12
      QtBindings/Gui/QApplication.cs
  13. 1
      QtBindings/Gui/QPushButton.cs
  14. 28
      QtBindings/Gui/QWidget.cs
  15. 1
      QtTest/Main.cs

115
Mono.VisualC.Interop/ABI/CppAbi.cs

@ -19,8 +19,6 @@ namespace Mono.VisualC.Interop.ABI { @@ -19,8 +19,6 @@ namespace Mono.VisualC.Interop.ABI {
//FIXME: Exception handling, operator overloading etc.
//FIXME: Allow interface to override default calling convention
//FIXME: Better interface validation- for example, throw exception
// when [VirtualDestructor] is applied to base interface but not derived
public abstract partial class CppAbi {
protected ModuleBuilder impl_module;
@ -55,6 +53,16 @@ namespace Mono.VisualC.Interop.ABI { @@ -55,6 +53,16 @@ namespace Mono.VisualC.Interop.ABI {
get { return Marshal.SizeOf (typeof (IntPtr)); }
}
// the padding in the data pointed to by the vtable pointer before the list of function pointers starts
public virtual int VTableTopPadding {
get { return 0; }
}
// the amount of extra room alloc'd after the function pointer list of the vtbl
public virtual int VTableBottomPadding {
get { return 0; }
}
protected virtual int NativeSize {
get {
// By default: native size = C++ class size + field offset padding (usually just vtable pointer)
@ -92,32 +100,21 @@ namespace Mono.VisualC.Interop.ABI { @@ -92,32 +100,21 @@ namespace Mono.VisualC.Interop.ABI {
DefineImplType ();
var properties = GetProperties ();
var methods = GetMethods (interface_type);
var bases = GetBasesRecursive (interface_type);
IEnumerable<MethodInfo> baseVirtualMethods = Enumerable.Empty<MethodInfo> ();
if (bases.Any ()) // FIXME: We're assuming that first declared base is non-virtual primary base (and thus shares primary vtable)
baseVirtualMethods = from method in GetVirtualMethods (bases.First ())
select method;
var vtableSlots = from method in baseVirtualMethods.Concat (GetVirtualMethods (interface_type))
let delegateType = DefineVTableDelegate (method)
select new { DelegateType = delegateType,
Override = GetManagedOverrideTrampoline (method, delegateType, vtable_override_filter)
};
var virtualDtorSlots = from iface in bases.With (interface_type)
where iface.IsDefined (typeof (VirtualDestructorAttribute), false)
from i in new int [] { 0, 1 }
select new { DelegateType = (Type)null, Override = (Delegate)null };
vtableSlots = vtableSlots.Concat (virtualDtorSlots);
var methods = GetMethods ();
var baseVirtualMethods = GetBaseVirtualMethods ();
// FIXME: Lazy generate vtable delegates and cache them
List<Type> delegateTypes = new List<Type> ();
List<Delegate> delegates = new List<Delegate> ();
foreach (var method in baseVirtualMethods.Concat (GetVirtualMethods ())) {
Type delType = DefineVTableDelegate (method);
delegateTypes.Add (delType);
delegates.Add (GetManagedOverrideTrampoline (method, delType, vtable_override_filter));
}
// ONLY make vtable if there are virtual methods
if (vtableSlots.Any ())
vtable = make_vtable_method (vtableSlots.Select (s => s.DelegateType).ToList (),
vtableSlots.Select (s => s.Override).ToArray ());
if (delegateTypes.Count > 0)
vtable = make_vtable_method (delegateTypes, delegates, VTableTopPadding, VTableBottomPadding);
else
vtable = null;
@ -151,6 +148,10 @@ namespace Mono.VisualC.Interop.ABI { @@ -151,6 +148,10 @@ namespace Mono.VisualC.Interop.ABI {
);
}
protected IEnumerable<MethodInfo> GetMethods ()
{
return GetMethods (interface_type);
}
protected virtual IEnumerable<MethodInfo> GetMethods (Type interfaceType)
{
// get all methods defined on inherited interfaces first
@ -169,6 +170,10 @@ namespace Mono.VisualC.Interop.ABI { @@ -169,6 +170,10 @@ namespace Mono.VisualC.Interop.ABI {
return methods;
}
protected IEnumerable<MethodInfo> GetVirtualMethods ()
{
return GetVirtualMethods (interface_type);
}
protected virtual IEnumerable<MethodInfo> GetVirtualMethods (Type interfaceType)
{
var delegates = (
@ -179,15 +184,41 @@ namespace Mono.VisualC.Interop.ABI { @@ -179,15 +184,41 @@ namespace Mono.VisualC.Interop.ABI {
return delegates;
}
protected virtual IEnumerable<Type> GetBasesRecursive (Type searchStart)
{
var immediateBases = (
from baseIface in searchStart.GetInterfaces ()
where baseIface.Name.Equals ("Base`1")
from iface in baseIface.GetGenericArguments ()
select iface
protected virtual IEnumerable<MethodInfo> GetBaseVirtualMethods ()
{
var bases = GetBasesRecursive ();
if (!bases.Any ())
return Enumerable.Empty<MethodInfo> ();
var virtualMethods = from iface in bases
from method in GetVirtualMethods (iface)
select method;
return virtualMethods;
}
protected IEnumerable<Type> GetImmediateBases ()
{
return GetImmediateBases (interface_type);
}
protected virtual IEnumerable<Type> GetImmediateBases (Type interfaceType)
{
var immediateBases = (
from baseIface in interfaceType.GetInterfaces ()
where baseIface.Name.Equals ("Base`1")
from iface in baseIface.GetGenericArguments ()
select iface
);
return immediateBases;
}
protected IEnumerable<Type> GetBasesRecursive ()
{
return GetBasesRecursive (interface_type);
}
protected IEnumerable<Type> GetBasesRecursive (Type searchStart)
{
var immediateBases = GetImmediateBases (searchStart);
if (!immediateBases.Any ())
return Enumerable.Empty<Type> ();
@ -198,7 +229,7 @@ namespace Mono.VisualC.Interop.ABI { @@ -198,7 +229,7 @@ namespace Mono.VisualC.Interop.ABI {
}
return allBases;
}
}
protected virtual void DefineImplType ()
{
@ -554,8 +585,8 @@ namespace Mono.VisualC.Interop.ABI { @@ -554,8 +585,8 @@ namespace Mono.VisualC.Interop.ABI {
il.Emit (OpCodes.Ldloc_S, nativePtr);
}
for (int i = argLoadStart; i <= parameterTypes.Length; i++) {
EmitSpecialParameterMarshal (il, parameterTypes [i - 1]);
il.Emit (OpCodes.Ldarg, i);
EmitSpecialParameterMarshal (il, parameterTypes [i - 1]);
}
il.Emit (OpCodes.Call, nativeMethod);
@ -565,6 +596,17 @@ namespace Mono.VisualC.Interop.ABI { @@ -565,6 +596,17 @@ namespace Mono.VisualC.Interop.ABI {
protected virtual void EmitSpecialParameterMarshal (ILGenerator il, Type parameterType)
{
// auto marshal bool to C++ bool type (0 = false , 1 = true )
if (parameterType.Equals (typeof (bool))) {
Label isTrue = il.DefineLabel ();
Label done = il.DefineLabel ();
il.Emit (OpCodes.Brtrue_S, isTrue);
il.Emit (OpCodes.Ldc_I4_0);
il.Emit (OpCodes.Br_S, done);
il.MarkLabel (isTrue);
il.Emit (OpCodes.Ldc_I4_1);
il.MarkLabel (done);
//il.Emit (OpCodes.Conv_I1);
}
// auto marshal ICppObject
}
@ -573,8 +615,11 @@ namespace Mono.VisualC.Interop.ABI { @@ -573,8 +615,11 @@ namespace Mono.VisualC.Interop.ABI {
var originalTypes = Util.GetMethodParameterTypes (method);
var pinvokeTypes = originalTypes.Transform (
For.AnyInputIn (typeof (bool)).Emit (typeof (byte)),
// CppInstancePtr implements ICppObject
For.InputsWhere ((Type t) => typeof (ICppObject).IsAssignableFrom (t)).Emit (typeof (IntPtr)),
For.UnmatchedInput<Type> ().Emit (t => t)
);
return pinvokeTypes;

23
Mono.VisualC.Interop/ABI/Impl/ItaniumAbi.cs

@ -21,6 +21,29 @@ namespace Mono.VisualC.Interop.ABI { @@ -21,6 +21,29 @@ namespace Mono.VisualC.Interop.ABI {
{
}
// Itanium puts all its virtual dtors at the bottom of the vtable (2 slots each).
// Since we will never be in a position of calling a dtor virtually, we can just pad the vtable out.
public override bool IsVirtual (MethodInfo method)
{
return base.IsVirtual (method) && !method.IsDefined (typeof (VirtualDestructorAttribute), false);
}
public override int VTableBottomPadding {
get {
int vtableBottomPadding = 0;
bool hasVdtor = false;
int vdtorPadding = Marshal.SizeOf (typeof (IntPtr)) * 2;
foreach (var iface in GetBasesRecursive ().With (interface_type)) {
if (hasVdtor || HasVirtualDtor (iface)) {
vtableBottomPadding += vdtorPadding;
hasVdtor = true;
}
}
return vtableBottomPadding;
}
}
public override CallingConvention? GetCallingConvention (MethodInfo methodInfo)
{
return CallingConvention.Cdecl;

22
Mono.VisualC.Interop/ABI/Impl/MsvcAbi.cs

@ -19,20 +19,28 @@ using Mono.VisualC.Interop; @@ -19,20 +19,28 @@ using Mono.VisualC.Interop;
namespace Mono.VisualC.Interop.ABI {
// FIXME: No 64-bit support
public class MsvcAbi : CppAbi {
public MsvcAbi ()
{
}
public class MsvcAbi : CppAbi {
public MsvcAbi ()
{
}
public override CallingConvention? GetCallingConvention (MethodInfo methodInfo)
public override CallingConvention? GetCallingConvention (MethodInfo methodInfo)
{
// FIXME: Varargs methods ... ?
// FIXME: Varargs methods ... ?
if (IsStatic (methodInfo))
return CallingConvention.Cdecl;
else
return CallingConvention.ThisCall;
}
}
// AFIK, MSVC places only its first base's virtual methods in the derived class's
// primary vtable.
protected override IEnumerable<Type> GetImmediateBases (Type interfaceType)
{
var immediateBases = base.GetImmediateBases (interfaceType);
return immediateBases.Take (1);
}
public override string GetMangledMethodName (MethodInfo methodInfo)
{

36
Mono.VisualC.Interop/ABI/VTable.cs

@ -15,13 +15,14 @@ using System.Reflection.Emit; @@ -15,13 +15,14 @@ using System.Reflection.Emit;
using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public delegate VTable MakeVTableDelegate (IList<Type> delegateTypes, Delegate [] overrides);
public delegate VTable MakeVTableDelegate (IList<Type> delegateTypes, IList<Delegate> overrides, int paddingTop, int paddingBottom);
// TODO: RTTI .. support virtual inheritance
public abstract class VTable : IDisposable {
public static MakeVTableDelegate DefaultImplementation = VTableManaged.Implementation;
protected int paddingTop, paddingBottom;
protected IntPtr basePtr, vtPtr;
// FIXME: Either make this a lazy list that only generates the delegate type if
@ -30,10 +31,10 @@ namespace Mono.VisualC.Interop.ABI { @@ -30,10 +31,10 @@ namespace Mono.VisualC.Interop.ABI {
// The Length of the array will be equal to the number of entries in the vtable;
// entries that aren't overridden will be NULL.
protected Delegate [] overrides;
protected IList<Delegate> overrides;
public virtual int EntryCount {
get { return overrides.Length; }
get { return overrides.Count; }
}
public virtual int EntrySize {
get { return Marshal.SizeOf (typeof (IntPtr)); }
@ -42,18 +43,21 @@ namespace Mono.VisualC.Interop.ABI { @@ -42,18 +43,21 @@ namespace Mono.VisualC.Interop.ABI {
public abstract MethodInfo PrepareVirtualCall (MethodInfo target, CallingConvention? callingConvention, ILGenerator callsite,
LocalBuilder nativePtr, FieldInfo vtableField, int vtableIndex);
// Subclasses must allocate vtPtr!
public VTable (IList<Type> delegateTypes, Delegate [] overrides)
// Subclasses should allocate vtPtr and then call WriteOverrides
public VTable (IList<Type> delegateTypes, IList<Delegate> overrides, int paddingTop, int paddingBottom)
{
this.delegate_types = delegateTypes;
this.overrides = overrides;
this.basePtr = IntPtr.Zero;
this.vtPtr = IntPtr.Zero;
this.paddingTop = paddingTop;
this.paddingBottom = paddingBottom;
}
protected virtual void WriteOverrides (int offset)
protected virtual void WriteOverrides ()
{
IntPtr vtEntryPtr;
int currentOffset = paddingTop;
for (int i = 0; i < EntryCount; i++) {
if (overrides [i] != null) // managed override
@ -61,8 +65,8 @@ namespace Mono.VisualC.Interop.ABI { @@ -61,8 +65,8 @@ namespace Mono.VisualC.Interop.ABI {
else
vtEntryPtr = IntPtr.Zero;
Marshal.WriteIntPtr (vtPtr, offset, vtEntryPtr);
offset += EntrySize;
Marshal.WriteIntPtr (vtPtr, currentOffset, vtEntryPtr);
currentOffset += EntrySize;
}
}
@ -71,15 +75,23 @@ namespace Mono.VisualC.Interop.ABI { @@ -71,15 +75,23 @@ namespace Mono.VisualC.Interop.ABI {
if (basePtr == IntPtr.Zero) {
basePtr = Marshal.ReadIntPtr (instance);
if ((basePtr != IntPtr.Zero) && (basePtr != vtPtr)) {
int offset = 0;
// FIXME: This could probably be a more efficient memcpy
for(int i = 0; i < paddingTop; i++)
Marshal.WriteByte(vtPtr, i, Marshal.ReadByte(basePtr, i));
int currentOffset = paddingTop;
for (int i = 0; i < EntryCount; i++) {
if (overrides [i] == null)
Marshal.WriteIntPtr (vtPtr, offset, Marshal.ReadIntPtr (basePtr, offset));
Marshal.WriteIntPtr (vtPtr, currentOffset, Marshal.ReadIntPtr (basePtr, currentOffset));
offset += EntrySize;
currentOffset += EntrySize;
}
}
// FIXME: This could probably be a more efficient memcpy
for(int i = 0; i < paddingBottom; i++)
Marshal.WriteByte(vtPtr, currentOffset + i, Marshal.ReadByte(basePtr, currentOffset + i));
}
}
Marshal.WriteIntPtr (instance, vtPtr);

4
Mono.VisualC.Interop/ABI/VTableCOM.cs

@ -18,8 +18,8 @@ using System.Runtime.InteropServices; @@ -18,8 +18,8 @@ using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public class VTableCOM : VTable {
public static MakeVTableDelegate Implementation = (types, overrides) => { return new VTableCOM (types, overrides); };
private VTableCOM (IList<Type> types, Delegate [] overrides) : base(types, overrides)
public static MakeVTableDelegate Implementation = (types, overrides, paddingTop, paddingBottom) => { return new VTableCOM (types, overrides, paddingTop, paddingBottom); };
private VTableCOM (IList<Type> types, IList<Delegate> overrides, int paddingTop, int paddingBottom) : base(types, overrides, paddingTop, paddingBottom)
{
}

11
Mono.VisualC.Interop/ABI/VTableManaged.cs

@ -17,12 +17,11 @@ using System.Runtime.InteropServices; @@ -17,12 +17,11 @@ using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public class VTableManaged : VTable {
public static MakeVTableDelegate Implementation = (types, overrides) => { return new VTableManaged (types, overrides); };
private VTableManaged (IList<Type> types, Delegate [] overrides) : base(types, overrides)
public static MakeVTableDelegate Implementation = (types, overrides, paddingTop, paddingBottom) => { return new VTableManaged (types, overrides, paddingTop, paddingBottom); };
private VTableManaged (IList<Type> types, IList<Delegate> overrides, int paddingTop, int paddingBottom) : base(types, overrides, paddingTop, paddingBottom)
{
this.vtPtr = Marshal.AllocHGlobal (EntryCount * EntrySize);
WriteOverrides (0);
this.vtPtr = Marshal.AllocHGlobal ((EntryCount * EntrySize) + paddingTop + paddingBottom);
WriteOverrides ();
}
public override MethodInfo PrepareVirtualCall (MethodInfo target, CallingConvention? callingConvention, ILGenerator callsite,
@ -60,7 +59,7 @@ namespace Mono.VisualC.Interop.ABI { @@ -60,7 +59,7 @@ namespace Mono.VisualC.Interop.ABI {
if (vtable == vtPtr) // do not return managed overrides
vtable = basePtr;
IntPtr ftnptr = Marshal.ReadIntPtr (vtable, index * EntrySize);
IntPtr ftnptr = Marshal.ReadIntPtr (vtable, (index * EntrySize) + paddingTop);
if (ftnptr == IntPtr.Zero)
return null;

25
Mono.VisualC.Interop/Attributes.cs

@ -17,7 +17,7 @@ namespace Mono.VisualC.Interop { @@ -17,7 +17,7 @@ namespace Mono.VisualC.Interop {
[AttributeUsage (AttributeTargets.Method)]
public class VirtualAttribute : Attribute {}
[AttributeUsage (AttributeTargets.Interface)]
[AttributeUsage (AttributeTargets.Method)]
public class VirtualDestructorAttribute : Attribute {}
[AttributeUsage (AttributeTargets.Method)]
@ -60,13 +60,30 @@ using Mono.VisualC.Interop; @@ -60,13 +60,30 @@ using Mono.VisualC.Interop;
public virtual bool IsVirtual (MethodInfo method)
{
return method.IsDefined (typeof (VirtualAttribute), false);
return method.IsDefined (typeof (VirtualAttribute), false) ||
method.IsDefined (typeof (VirtualDestructorAttribute), false);
}
// Ok, this is tricky.. return true if this class has a [VirtualDestructor]
// or any of its bases do, up the hierarchy.
public virtual bool IsVirtualDtor (MethodInfo method)
{
return GetMethodType (method) == MethodType.NativeDtor &&
interface_type.IsDefined (typeof (VirtualDestructorAttribute), false);
return HasVirtualDtor () && GetMethodType (method) == MethodType.NativeDtor;
}
public bool HasVirtualDtor ()
{
return HasVirtualDtor (interface_type);
}
public virtual bool HasVirtualDtor (Type interfaceType)
{
var methods = from iface in GetBasesRecursive ().With (interface_type)
from method in GetMethods (iface)
where method.IsDefined (typeof (VirtualDestructorAttribute), false)
select method;
return methods.Any ();
}
public virtual bool IsStatic (MethodInfo method)
{
return method.IsDefined (typeof (StaticAttribute), false);

2
Mono.VisualC.Interop/Util.cs

@ -69,7 +69,7 @@ namespace Mono.VisualC.Interop { @@ -69,7 +69,7 @@ namespace Mono.VisualC.Interop {
attr = attr | ParameterAttributes.HasFieldMarshal;
} else */ if (forPInvoke && existingMarshalAs != null) {
// TODO: This still doesn't feel like it's working right..
// FIXME: This still doesn't feel like it's working right.. especially for virtual functions
ConstructorInfo ctor = typeof (MarshalAsAttribute).GetConstructor (new Type[] { typeof (UnmanagedType) });
object[] args = new object [] { existingMarshalAs.Value };

1
QtBindings/Core/QCoreApplication.cs

@ -6,7 +6,6 @@ namespace Qt.Core { @@ -6,7 +6,6 @@ namespace Qt.Core {
public class QCoreApplication : QObject {
#region Sync with qcoreapplication.h
// C++ interface
[VirtualDestructor]
public interface IQCoreApplication : ICppClassOverridable<QCoreApplication>, Base<QObject.IQObject> {
// ...
void QCoreApplication (CppInstancePtr @this, [MangleAs ("int&")] IntPtr argc,

2
QtBindings/Core/QObject.cs

@ -6,7 +6,6 @@ namespace Qt.Core { @@ -6,7 +6,6 @@ namespace Qt.Core {
public class QObject : ICppObject {
#region Sync with qobject.h
// C++ interface
[VirtualDestructor]
public interface IQObject : ICppClassOverridable<QObject> {
// ...
[Virtual] /*QMetaObject */ IntPtr metaObject(CppInstancePtr @this);
@ -14,6 +13,7 @@ namespace Qt.Core { @@ -14,6 +13,7 @@ namespace Qt.Core {
[Virtual] int qt_metacall(CppInstancePtr @this, /*QMetaObject::Call */ int qMetaObjectCall, int x, /*void **/ IntPtr p);
// ...
void QObject (CppInstancePtr @this, QObject parent);
[VirtualDestructor] void vdtor (CppInstancePtr @this);
// ...
[Virtual] bool @event (CppInstancePtr @this, IntPtr qEvent);
[Virtual] bool eventFilter (CppInstancePtr @this, IntPtr qObject, IntPtr qEvent);

1
QtBindings/Gui/QAbstractButton.cs

@ -5,7 +5,6 @@ namespace Qt.Gui { @@ -5,7 +5,6 @@ namespace Qt.Gui {
public class QAbstractButton : QWidget {
#region Sync with qabstractbutton.h
// C++ interface
[VirtualDestructor]
public interface IQAbstractButton : ICppClassOverridable<QAbstractButton>, Base<QWidget.IQWidget> {
// ...
void QAbstractButton (CppInstancePtr @this, QWidget parent);

12
QtBindings/Gui/QApplication.cs

@ -8,7 +8,6 @@ namespace Qt.Gui { @@ -8,7 +8,6 @@ namespace Qt.Gui {
public class QApplication : QCoreApplication {
#region Sync with qapplication.h
// C++ interface
[VirtualDestructor]
public interface IQApplication : ICppClassOverridable<QApplication>, Base<QCoreApplication.IQCoreApplication> {
// ...
void QApplication (CppInstancePtr @this, [MangleAs ("int&")] IntPtr argc,
@ -20,17 +19,6 @@ namespace Qt.Gui { @@ -20,17 +19,6 @@ namespace Qt.Gui {
[Virtual] void saveState(CppInstancePtr @this, IntPtr qSessionManager); // was QSessionManager&
// ...
[Static] int exec ();
// TODO: HACK! Yeah... I'm not calculating the right number of vtable slots somewhere...
// ... add dummy methods until I figure it out...
/*
[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);
*/
}
// C++ fields
private struct _QApplication {

1
QtBindings/Gui/QPushButton.cs

@ -6,7 +6,6 @@ namespace Qt.Gui { @@ -6,7 +6,6 @@ namespace Qt.Gui {
public class QPushButton : QAbstractButton {
#region Sync with qpushbutton.h
// C++ interface
[VirtualDestructor]
public interface IQPushButton : ICppClassOverridable<QPushButton>, Base<QAbstractButton.IQAbstractButton> {
// ...
void QPushButton (CppInstancePtr @this, [MangleAs ("const QString &")] ref QString text, QWidget parent);

28
QtBindings/Gui/QWidget.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Mono.VisualC.Interop;
@ -8,12 +9,11 @@ namespace Qt.Gui { @@ -8,12 +9,11 @@ namespace Qt.Gui {
public class QWidget : QObject {
#region Sync with qwidget.h
// C++ interface
[VirtualDestructor]
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);
[Virtual] void setVisible (CppInstancePtr @this, /*[MarshalAs (UnmanagedType.U1)]*/ bool visible);
// ...
void resize (CppInstancePtr @this, [MangleAs ("const QSize &")] ref QSize size);
// ...
@ -54,19 +54,14 @@ namespace Qt.Gui { @@ -54,19 +54,14 @@ namespace Qt.Gui {
//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);
*/
[Virtual] bool focusNextPrevChild (CppInstancePtr @this, bool next);
[Virtual] void styleChange (CppInstancePtr @this, IntPtr qStyle); // compat
[Virtual] void enabledChange (CppInstancePtr @this, bool arg); // compat
[Virtual] void paletteChange (CppInstancePtr @this, /*const QPalette &*/ IntPtr qPalette); // compat
[Virtual] void fontChange (CppInstancePtr @this, /*const QFont &*/ IntPtr qFont); // compat
[Virtual] void windowActivationChange (CppInstancePtr @this, bool arg); // compat
[Virtual] void languageChange(CppInstancePtr @this); // compat
}
// C++ fields
private struct _QWidget {
@ -87,6 +82,7 @@ namespace Qt.Gui { @@ -87,6 +82,7 @@ namespace Qt.Gui {
throw new NotImplementedException ();
}
set {
//Debug.Assert (false, "Attach debugger now.");
impl.setVisible (native, value);
}
}
@ -101,7 +97,7 @@ namespace Qt.Gui { @@ -101,7 +97,7 @@ namespace Qt.Gui {
// 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; }
get { return impl.NativeSize + base.NativeSize + 4; }
}
public override void Dispose ()

1
QtTest/Main.cs

@ -7,6 +7,7 @@ namespace QtTest { @@ -7,6 +7,7 @@ namespace QtTest {
class MainClass {
public static void Main (string[] args)
{
//System.Diagnostics.Debug.Assert(false, "Whao");
using (QApplication app = new QApplication ()) {
using (QPushButton hello = new QPushButton ("Hello world!")) {

Loading…
Cancel
Save