mirror of https://github.com/mono/CppSharp.git
Browse Source
git-svn-id: https://mono-soc-2010.googlecode.com/svn/trunk/cppinterop@48 a470b8cb-0e6f-1642-1b45-71e107334c4bpull/1/head
23 changed files with 682 additions and 58 deletions
@ -0,0 +1,49 @@ |
|||||||
|
using System; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
namespace Mono.VisualC.Interop { |
||||||
|
public class CppObjectMarshaler : ICustomMarshaler { |
||||||
|
private static CppObjectMarshaler marshaler = null; |
||||||
|
private CppObjectMarshaler () { |
||||||
|
} |
||||||
|
|
||||||
|
public IntPtr MarshalManagedToNative (object managedObj) |
||||||
|
{ |
||||||
|
if (managedObj == null) |
||||||
|
return IntPtr.Zero; |
||||||
|
|
||||||
|
ICppObject cppObject = managedObj as ICppObject; |
||||||
|
if (cppObject == null) |
||||||
|
throw new ArgumentException ("Object to marshal must implement ICppObject"); |
||||||
|
|
||||||
|
return cppObject.Native; |
||||||
|
} |
||||||
|
|
||||||
|
public object MarshalNativeToManaged (IntPtr pNativeData) |
||||||
|
{ |
||||||
|
throw new NotImplementedException (); |
||||||
|
} |
||||||
|
|
||||||
|
public void CleanUpManagedData (object ManagedObj) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void CleanUpNativeData (IntPtr pNativeData) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public int GetNativeDataSize () |
||||||
|
{ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
public static ICustomMarshaler GetInstance(string cookie) |
||||||
|
{ |
||||||
|
if(marshaler == null) |
||||||
|
marshaler = new CppObjectMarshaler (); |
||||||
|
return marshaler; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,27 @@ |
|||||||
|
using System.Reflection; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("QtBindings")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyCompany("")] |
||||||
|
[assembly: AssemblyProduct("")] |
||||||
|
[assembly: AssemblyCopyright("")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")] |
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
@ -0,0 +1,83 @@ |
|||||||
|
using System; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
|
||||||
|
namespace Qt.Core { |
||||||
|
public class QCoreApplication : QObject { |
||||||
|
#region Sync with qcoreapplication.h
|
||||||
|
// C++ interface
|
||||||
|
protected interface IQCoreApplication : ICppClassOverridable<QCoreApplication>, Base<QObject.IQObject> { |
||||||
|
void QCoreApplication (CppInstancePtr @this, [MangleAs ("System.Int32&")] IntPtr argc, |
||||||
|
[MangleAs (typeof (string[]))] IntPtr argv); |
||||||
|
// ...
|
||||||
|
[Static] int exec (); |
||||||
|
// ...
|
||||||
|
[Virtual] bool notify (CppInstancePtr @this, IntPtr qObject, IntPtr qEvent); |
||||||
|
[Virtual] bool compressEvent (CppInstancePtr @this, IntPtr qEvent, IntPtr qObject, IntPtr qPostEventList); |
||||||
|
} |
||||||
|
// C++ fields
|
||||||
|
private struct _QCoreApplication { |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
private static IQCoreApplication impl = Qt.Libs.QtCore.GetClass<IQCoreApplication,_QCoreApplication,QCoreApplication> ("QCoreApplication"); |
||||||
|
|
||||||
|
protected IntPtr argc; |
||||||
|
protected IntPtr argv; |
||||||
|
|
||||||
|
|
||||||
|
public QCoreApplication () : this (true) |
||||||
|
{ |
||||||
|
this.native = impl.Alloc (this); |
||||||
|
impl.QCoreApplication (native, argc, argv); |
||||||
|
} |
||||||
|
|
||||||
|
protected QCoreApplication (bool foo) : base (IntPtr.Zero) |
||||||
|
{ |
||||||
|
// for some reason, this includes arg0, but the args passed to Main (string[]) do not!
|
||||||
|
string[] args = Environment.GetCommandLineArgs (); |
||||||
|
|
||||||
|
int argCount = args.Length; |
||||||
|
argc = Marshal.AllocHGlobal (sizeof (int)); |
||||||
|
Marshal.WriteInt32 (argc, argCount); |
||||||
|
|
||||||
|
argv = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (IntPtr)) * argCount); |
||||||
|
for (var i = 0; i < argCount; i++) { |
||||||
|
IntPtr arg = Marshal.StringToHGlobalAnsi (args [i]); |
||||||
|
Marshal.WriteIntPtr (argv, i * Marshal.SizeOf (typeof (IntPtr)), arg); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public QCoreApplication (IntPtr native) : base (native) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
// TODO: Should this be virtual in C#? was static in C++, but alas,
|
||||||
|
// I made it an instance, since that seems to fit .net semantics a bit better...
|
||||||
|
// but if I don't make it virtual, then what to do about Exec () in QApplication?
|
||||||
|
public virtual int Exec () |
||||||
|
{ |
||||||
|
return impl.exec (); |
||||||
|
} |
||||||
|
|
||||||
|
public override int NativeSize { |
||||||
|
get { return impl.NativeSize + base.NativeSize; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Dispose () |
||||||
|
{ |
||||||
|
impl.Destruct (native); |
||||||
|
FreeArgcAndArgv (); |
||||||
|
native.Dispose (); |
||||||
|
} |
||||||
|
|
||||||
|
protected void FreeArgcAndArgv () |
||||||
|
{ |
||||||
|
Marshal.FreeHGlobal (argc); |
||||||
|
for (var i = 0; i < Environment.GetCommandLineArgs ().Length; i++) |
||||||
|
Marshal.FreeHGlobal (Marshal.ReadIntPtr (argv, i * Marshal.SizeOf (typeof (IntPtr)))); |
||||||
|
Marshal.FreeHGlobal (argv); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,10 @@ |
|||||||
|
using System; |
||||||
|
namespace Qt.Core { |
||||||
|
public static class QGlobal { |
||||||
|
|
||||||
|
public const string QT_VERSION_STR = "4.6.2"; |
||||||
|
public const int QT_VERSION = 0x040602; |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,61 @@ |
|||||||
|
using System; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
|
||||||
|
namespace Qt.Core { |
||||||
|
public class QObject : ICppObject { |
||||||
|
#region Sync with qobject.h
|
||||||
|
// C++ interface
|
||||||
|
protected interface IQObject : ICppClassOverridable<QObject> { |
||||||
|
void QObject (CppInstancePtr @this, [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof (CppObjectMarshaler))] QObject parent); |
||||||
|
[Virtual] bool @event (CppInstancePtr @this, IntPtr qEvent); |
||||||
|
[Virtual] bool eventFilter (CppInstancePtr @this, IntPtr qObject, IntPtr qEvent); |
||||||
|
[Virtual] void timerEvent (CppInstancePtr @this, IntPtr qTimerEvent); |
||||||
|
[Virtual] void childEvent (CppInstancePtr @this, IntPtr qChildEvent); |
||||||
|
[Virtual] void customEvent (CppInstancePtr @this, IntPtr qEvent); |
||||||
|
[Virtual] void connectNotify (CppInstancePtr @this, string signal); |
||||||
|
[Virtual] void disconnectNotify (CppInstancePtr @this, string signal); |
||||||
|
} |
||||||
|
// C++ fields
|
||||||
|
private struct _QObject { |
||||||
|
public IntPtr d_ptr; |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
private static IQObject impl = Qt.Libs.QtCore.GetClass<IQObject,_QObject,QObject> ("QObject"); |
||||||
|
protected CppInstancePtr native; |
||||||
|
|
||||||
|
public QObject () |
||||||
|
{ |
||||||
|
native = impl.Alloc (this); |
||||||
|
impl.QObject (native, null); |
||||||
|
} |
||||||
|
|
||||||
|
public QObject (QObject parent) |
||||||
|
{ |
||||||
|
native = impl.Alloc (this); |
||||||
|
impl.QObject (native, parent); |
||||||
|
} |
||||||
|
|
||||||
|
public QObject (IntPtr native) |
||||||
|
{ |
||||||
|
this.native = native; |
||||||
|
} |
||||||
|
|
||||||
|
public IntPtr Native { |
||||||
|
get { return (IntPtr)native; } |
||||||
|
} |
||||||
|
|
||||||
|
public virtual int NativeSize { |
||||||
|
get { return impl.NativeSize; } |
||||||
|
} |
||||||
|
|
||||||
|
public virtual void Dispose () |
||||||
|
{ |
||||||
|
impl.Destruct (native); |
||||||
|
native.Dispose (); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,56 @@ |
|||||||
|
using System; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
|
||||||
|
using Qt.Core; |
||||||
|
|
||||||
|
namespace Qt.Gui { |
||||||
|
public class QApplication : QCoreApplication { |
||||||
|
#region Sync with qapplication.h
|
||||||
|
// C++ interface
|
||||||
|
protected interface IQApplication : ICppClassOverridable<QApplication>, Base<QCoreApplication.IQCoreApplication> { |
||||||
|
void QApplication (CppInstancePtr @this, [MangleAs ("System.Int32&")] IntPtr argc, |
||||||
|
[MangleAs (typeof (string[]))] IntPtr argv, int version); |
||||||
|
[Virtual] bool macEventFilter(CppInstancePtr @this, IntPtr eventHandlerCallRef, IntPtr eventRef); |
||||||
|
// ...
|
||||||
|
[Virtual] void commitData(CppInstancePtr @this, IntPtr qSessionManager); // was QSessionManager&
|
||||||
|
[Virtual] void saveState(CppInstancePtr @this, IntPtr qSessionManager); // was QSessionManager&
|
||||||
|
// ...
|
||||||
|
[Static] int exec (); |
||||||
|
} |
||||||
|
// C++ fields
|
||||||
|
private struct _QApplication { |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
private static IQApplication impl = Qt.Libs.QtGui.GetClass<IQApplication,_QApplication,QApplication> ("QApplication"); |
||||||
|
|
||||||
|
public QApplication () : base (true) |
||||||
|
{ |
||||||
|
this.native = impl.Alloc (this); |
||||||
|
impl.QApplication (native, argc, argv, QGlobal.QT_VERSION); |
||||||
|
} |
||||||
|
|
||||||
|
public QApplication (IntPtr native) : base (native) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override int Exec () |
||||||
|
{ |
||||||
|
return impl.exec (); |
||||||
|
} |
||||||
|
|
||||||
|
public override int NativeSize { |
||||||
|
get { return impl.NativeSize + base.NativeSize; } |
||||||
|
} |
||||||
|
|
||||||
|
public override void Dispose () |
||||||
|
{ |
||||||
|
impl.Destruct (native); |
||||||
|
FreeArgcAndArgv (); |
||||||
|
native.Dispose (); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,25 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
using Mono.VisualC.Interop; |
||||||
|
using Mono.VisualC.Interop.ABI; |
||||||
|
|
||||||
|
namespace Qt { |
||||||
|
internal static class Libs { |
||||||
|
public static CppLibrary QtCore = null; |
||||||
|
public static CppLibrary QtGui = null; |
||||||
|
|
||||||
|
static Libs () |
||||||
|
{ |
||||||
|
CppAbi abi; |
||||||
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT) |
||||||
|
abi = new MsvcAbi (); |
||||||
|
else |
||||||
|
abi = new ItaniumAbi (); |
||||||
|
|
||||||
|
|
||||||
|
QtCore = new CppLibrary ("/Library/Frameworks/QtCore.framework/Versions/Current/QtCore", abi); |
||||||
|
QtGui = new CppLibrary ("/Library/Frameworks/QtGui.framework/Versions/Current/QtGui", abi); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,63 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<ProductVersion>8.0.50727</ProductVersion> |
||||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||||
|
<ProjectGuid>{66212CA6-B8C2-4307-ADDE-DAFEAAB339B9}</ProjectGuid> |
||||||
|
<OutputType>Library</OutputType> |
||||||
|
<RootNamespace>Qt</RootNamespace> |
||||||
|
<AssemblyName>QtBindings</AssemblyName> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>full</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Debug</OutputPath> |
||||||
|
<DefineConstants>DEBUG</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<ConsolePause>false</ConsolePause> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||||
|
<DebugType>none</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Release</OutputPath> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<ConsolePause>false</ConsolePause> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="System" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="AssemblyInfo.cs" /> |
||||||
|
<Compile Include="Libs.cs" /> |
||||||
|
<Compile Include="Gui\QApplication.cs" /> |
||||||
|
<Compile Include="Core\QGlobal.cs" /> |
||||||
|
<Compile Include="Core\QCoreApplication.cs" /> |
||||||
|
<Compile Include="Core\QObject.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\Mono.VisualC.Interop\Mono.VisualC.Interop.csproj"> |
||||||
|
<Project>{4A864586-93C5-4DC1-8A80-F094A88506D7}</Project> |
||||||
|
<Name>Mono.VisualC.Interop</Name> |
||||||
|
</ProjectReference> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<None Include="QtBindings.dll.config"> |
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||||
|
</None> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Folder Include="Gui\" /> |
||||||
|
<Folder Include="Core\" /> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||||
|
<ProjectExtensions> |
||||||
|
<MonoDevelop> |
||||||
|
<Properties InternalTargetFrameworkVersion="3.5" /> |
||||||
|
</MonoDevelop> |
||||||
|
</ProjectExtensions> |
||||||
|
</Project> |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
<configuration> |
||||||
|
<dllmap dll="QtCore4" os="osx" target="/Library/Frameworks/QtCore.framework/Versions/Current/QtCore" /> |
||||||
|
<dllmap dll="QtGui4" os="osx" target="/Library/Frameworks/QtGui.framework/Versions/Current/QtGui" /> |
||||||
|
</configuration> |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
using System.Reflection; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("QtTest")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyCompany("")] |
||||||
|
[assembly: AssemblyProduct("")] |
||||||
|
[assembly: AssemblyCopyright("")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")] |
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
@ -0,0 +1,16 @@ |
|||||||
|
using System; |
||||||
|
using Qt.Core; |
||||||
|
|
||||||
|
|
||||||
|
namespace QtTest { |
||||||
|
class MainClass { |
||||||
|
public static int Main (string[] args) |
||||||
|
{ |
||||||
|
using (QCoreApplication app = new QCoreApplication ()) { |
||||||
|
|
||||||
|
return app.Exec (); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,50 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<ProductVersion>8.0.50727</ProductVersion> |
||||||
|
<SchemaVersion>2.0</SchemaVersion> |
||||||
|
<ProjectGuid>{3EE6B50E-58FB-4391-AF01-3FCB1A29B0D7}</ProjectGuid> |
||||||
|
<OutputType>Exe</OutputType> |
||||||
|
<RootNamespace>QtTest</RootNamespace> |
||||||
|
<AssemblyName>QtTest</AssemblyName> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||||
|
<DebugSymbols>true</DebugSymbols> |
||||||
|
<DebugType>full</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Debug</OutputPath> |
||||||
|
<DefineConstants>DEBUG</DefineConstants> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<ConsolePause>false</ConsolePause> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||||
|
<DebugType>none</DebugType> |
||||||
|
<Optimize>false</Optimize> |
||||||
|
<OutputPath>bin\Release</OutputPath> |
||||||
|
<ErrorReport>prompt</ErrorReport> |
||||||
|
<WarningLevel>4</WarningLevel> |
||||||
|
<Externalconsole>true</Externalconsole> |
||||||
|
</PropertyGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="System" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="Main.cs" /> |
||||||
|
<Compile Include="AssemblyInfo.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||||
|
<ProjectExtensions> |
||||||
|
<MonoDevelop> |
||||||
|
<Properties InternalTargetFrameworkVersion="3.5" /> |
||||||
|
</MonoDevelop> |
||||||
|
</ProjectExtensions> |
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\QtBindings\QtBindings.csproj"> |
||||||
|
<Project>{66212CA6-B8C2-4307-ADDE-DAFEAAB339B9}</Project> |
||||||
|
<Name>QtBindings</Name> |
||||||
|
</ProjectReference> |
||||||
|
</ItemGroup> |
||||||
|
</Project> |
||||||
Loading…
Reference in new issue