Browse Source

Removed the Qt example binding code.

pull/1/head
triton 12 years ago
parent
commit
b2e708d720
  1. 96
      examples/qt/Qt.cs
  2. 41
      examples/qt/cpp/qt-gui-filters.xml
  3. 21
      examples/qt/cpp/qt-gui.cpp
  4. 3
      examples/qt/cpp/qt-gui.h
  5. 25
      examples/qt/demos/hello.cs
  6. 11
      examples/qt/premake4.lua
  7. 20
      examples/qt/src/QApplication.cs
  8. 50
      examples/qt/src/QCoreApplication.cs
  9. 13
      examples/qt/src/QFlags.cs
  10. 20
      examples/qt/src/QPoint.cs
  11. 20
      examples/qt/src/QPushButton.cs
  12. 20
      examples/qt/src/QSize.cs
  13. 71
      examples/qt/src/QString.cs
  14. 16
      examples/qt/src/QWidget.cs

96
examples/qt/Qt.cs

@ -1,96 +0,0 @@ @@ -1,96 +0,0 @@
using System.Collections.Generic;
using Cxxi.Generators;
using Cxxi.Generators.CLI;
using Cxxi.Passes;
using Cxxi.Types;
namespace Cxxi.Libraries
{
class Qt : ILibrary
{
public void Preprocess(Library lib)
{
// Qt Base
lib.IgnoreFile("qalgorithms.h");
lib.IgnoreFile("qarraydata.h");
lib.IgnoreFile("qatomic.h");
lib.IgnoreFile("qatomic_x86.h");
lib.IgnoreFile("qbytearray.h");
lib.IgnoreFile("qbasicatomic.h");
lib.IgnoreFile("qflags.h");
lib.IgnoreFile("qglobal.h");
lib.IgnoreFile("qstring.h");
lib.IgnoreFile("qrefcount.h");
lib.IgnoreFile("qtypeinfo.h");
lib.IgnoreFile("qtypetraits.h");
lib.IgnoreClassWithName("QForeachContainer");
lib.IgnoreClassWithName("QFlags");
lib.IgnoreClassWithName("QUrlTwoFlags");
lib.SetClassAsValueType("QChar");
lib.SetClassAsValueType("QPair");
lib.SetClassAsValueType("QPoint");
lib.SetClassAsValueType("QPointF");
}
public void Postprocess(Library lib)
{
}
public void Setup(DriverOptions options)
{
options.LibraryName = "Qt";
options.OutputNamespace = "Qt";
options.OutputDir = @"C:\Users\triton\Development\cxxi\examples\qt\wrappers";
options.IncludeDirs.Add(@"C:\Qt\Qt5.0.1\5.0.1\msvc2010\include");
options.GeneratorKind = LanguageGeneratorKind.CPlusPlusCLI;
SetupHeaders(options.Headers);
}
public void SetupHeaders(List<string> headers)
{
var sources = new string[]
{
"QtCore/QPoint",
"QtCore/QUrl",
};
headers.AddRange(sources);
}
public void SetupPasses(PassBuilder p)
{
p.RemovePrefix("Q");
const RenameTargets renameTargets = RenameTargets.Function
| RenameTargets.Method | RenameTargets.Field;
p.RenameDeclsCase(renameTargets, RenameCasePattern.UpperCamelCase);
p.FunctionToInstanceMethod();
p.FunctionToStaticMethod();
p.CheckDuplicateNames();
}
public void GenerateStart(TextTemplate template)
{
if (template is CLISourcesTemplate)
template.WriteLine("#include \"_Marshal.h\"");
}
public void GenerateAfterNamespaces(TextTemplate template)
{
if (template is CLISourcesTemplate)
template.WriteLine("using namespace clix;");
}
}
static class Program
{
public static void Main(string[] args)
{
Cxxi.Program.Run(new Libraries.Qt());
}
}
}

41
examples/qt/cpp/qt-gui-filters.xml

@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
<!--
This XML filter file format.
There are 3 different modes:
Include -> include this type in the generated output
Exclude -> do not include this type in the generated output. methods using this type will be removed (virtual methods will be stubbed with IntPtr)
External -> do not include this type in the generated output, but expect an implementation to be provided
The type of external implementation can be specified:
class (default) -> this type is implemented as a managed reference type
struct -> this type is implemented as a managed value type. when passed as pointer or reference, the managed "ref" prefix will be used
Rename -> include this type in the generated output, but rename to the specified managed type (specified in "to" attribute, "implementation" attribute also allowed)
The default behavior is Include. Change the default by specifying the default attribute on the top-level Filter tag.
Specify exceptions to the default behavior with child nodes named after one of the modes above…
-->
<Filter default="Exclude">
<Include>QObject</Include>
<Include>Qt</Include>
<Include>Qt::ConnectionType</Include>
<Include>Qt::KeyboardModifier</Include>
<Include>Qt::MouseButton</Include>
<Include>Qt::ButtonState</Include>
<Include>QApplication</Include>
<Include>QCoreApplication</Include>
<Include>QWidget</Include>
<Include>QAbstractButton</Include>
<Include>QPushButton</Include>
<Include>QPaintDevice</Include>
<Include>QEvent</Include>
<Include>QInputEvent</Include>
<Include>QMouseEvent</Include>
<Include>QTimerEvent</Include>
<External implementation="struct">QString</External>
<External implementation="struct">QSize</External>
<External implementation="struct">QPoint</External>
<External implementation="struct">QFlags&lt;Qt::KeyboardModifier&gt;</External>
</Filter>

21
examples/qt/cpp/qt-gui.cpp

@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
/*
* These are not in the unix version of qt, and -fkeep-inline-functions will generate
* references to their vtables etc., making the library unloadable.
*/
#define QT_NO_STYLE_WINDOWSVISTA
#define QT_NO_STYLE_WINDOWSXP
#define QT_NO_STYLE_S60
#define QT_NO_STYLE_WINDOWSCE
#define QT_NO_STYLE_WINDOWSMOBILE
#define QT_NO_QWSEMBEDWIDGET
// this one was annoying to track down!
#define QT_NO_TRANSLATION
#include "QtGui/QApplication"
#include "QtGui/QPushButton"
int main ()
{
}

3
examples/qt/cpp/qt-gui.h

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
#include "QApplication"
#include "qevent.h"
#include "QPushButton"

25
examples/qt/demos/hello.cs

@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
using System;
using System.Diagnostics;
using Qt.Gui;
using Qt.Gui.Qt;
using Mono.Cxxi;
namespace QtTest {
class MainClass {
public static void Main (string[] args)
{
using (QApplication app = new QApplication ()) {
using (QPushButton hello = new QPushButton ("Hello world!")) {
hello.Resize (200, 30);
QObject.Connect (hello, "2clicked()", app, "1aboutQt()", ConnectionType.AutoConnection);
hello.SetVisible (true);
QApplication.Exec ();
}
}
}
}
}

11
examples/qt/premake4.lua

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
project "Qt"
kind "ConsoleApp"
language "C#"
location "."
files { "**.cs", "./*.lua" }
links { "Bridge", "Generator" }

20
examples/qt/src/QApplication.cs

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
public partial class QApplication {
public partial interface IQApplication {
[Constructor] CppInstancePtr QApplication (CppInstancePtr @this, [MangleAs ("int&")] IntPtr argc, [MangleAs ("char**")] IntPtr argv, int version);
}
public QApplication () : base (impl.TypeInfo)
{
InitArgcAndArgv ();
Native = impl.QApplication (impl.Alloc (this), argc, argv, 0x040602);
}
}
}

50
examples/qt/src/QCoreApplication.cs

@ -1,50 +0,0 @@ @@ -1,50 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
public partial class QCoreApplication {
public partial interface IQCoreApplication {
[Constructor] CppInstancePtr QCoreApplication (CppInstancePtr @this, [MangleAs ("int&")] IntPtr argc, [MangleAs ("char**")] IntPtr argv);
}
protected IntPtr argc, argv;
public QCoreApplication () : base (impl.TypeInfo)
{
InitArgcAndArgv ();
Native = impl.QCoreApplication (impl.Alloc (this), argc, argv);
}
partial void AfterDestruct ()
{
FreeArgcAndArgv ();
}
protected void InitArgcAndArgv ()
{
var args = Environment.GetCommandLineArgs ();
var 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);
}
}
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);
}
}
}

13
examples/qt/src/QFlags.cs

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
[StructLayout (LayoutKind.Sequential)]
public struct QFlags<T> where T : struct {
public T Value;
}
}

20
examples/qt/src/QPoint.cs

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
[StructLayout (LayoutKind.Sequential)]
public struct QPoint {
private int xy, yx; //Wtf.. on Mac the order is y, x; elsewhere x, y
public QPoint (int x, int y)
{
//FIXME: do some snazzy stuff to get this right.. for now, I'm a mac user :P
this.yx = x;
this.xy = y;
}
}
}

20
examples/qt/src/QPushButton.cs

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
public partial class QPushButton {
public QPushButton (QString text, QWidget parent)
: this (ref text, parent)
{
}
public QPushButton (QString text)
: this (ref text, null)
{
}
}
}

20
examples/qt/src/QSize.cs

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
[StructLayout (LayoutKind.Sequential)]
public struct QSize {
public int Width;
public int Height;
public QSize (int w, int h)
{
this.Width = w;
this.Height = h;
}
}
}

71
examples/qt/src/QString.cs

@ -1,71 +0,0 @@ @@ -1,71 +0,0 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
//TODO: Will this leak?
[StructLayout (LayoutKind.Sequential)]
public unsafe struct QString {
#region Sync with qstring.h
public interface IQString : ICppClass {
[Constructor] void QString(ref QString @this, [MangleAs ("const QChar*")] IntPtr unicode, int size);
}
[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 = Libs.QtGui.GetClass<IQString> ("QString");
public QString (string str) : this ()
{
var 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 override string ToString ()
{
return Marshal.PtrToStringUni (d->data, d->size);
}
public QString AddRef ()
{
d->@ref++;
return this;
}
public QString DeRef ()
{
d->@ref--;
return this;
}
}
}

16
examples/qt/src/QWidget.cs

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
public partial class QWidget {
public void Resize (int width, int height)
{
var size = new QSize (width, height);
impl.resize (Native, ref size);
}
}
}
Loading…
Cancel
Save