bindings: Various Improvements
[sdk] / bindings / cpp / ecere.hpp
1 /****************************************************************************
2 ===========================================================================
3    Ecere Module
4 ===========================================================================
5 ****************************************************************************/
6 #if !defined(__ECERE_HPP__)
7 #define __ECERE_HPP__
8
9 #include "eC.hpp"
10 #include "ecere.h"
11
12 /****************************************************************************
13    ecere::gfx Namespace
14 ****************************************************************************/
15 ///////////// Surface Class /////////////////////////////////////////////////
16 class Surface : public Instance
17 {
18 public:
19    CONSTRUCT(Surface, Instance) { }
20
21    inline void writeTextf(int x, int y, const char * format, ...)
22    {
23       Surface_writeTextf(impl, x, y, format);   // var args are a pain to pass...
24    }
25 };
26
27 ///////////// FontResource Class /////////////////////////////////////////////////
28 class FontResource : public Instance
29 {
30 public:
31    CONSTRUCT(FontResource, Instance) { }
32
33    inline FontResource(constString faceName, float size = 10, eC_bool bold = false, eC_bool italic = false) : FontResource()
34    {
35       this->faceName = faceName;
36       this->size = size;
37       this->bold = bold;
38       this->italic = italic;
39    }
40
41    #undef PSELF
42    #define PSELF SELF(FontResource, bold)
43
44    property(bold,
45       set(eC_bool, bold, FontResource_set_bold(self ? self->impl : null, v))
46       get(eC_bool, bold, return FontResource_get_bold(self ? self->impl : null))
47    );
48    property(italic,
49       set(eC_bool, italic, FontResource_set_italic(self ? self->impl : null, v))
50       get(eC_bool, italic, return FontResource_get_italic(self ? self->impl : null))
51    );
52    property(faceName,
53       set(constString, faceName, FontResource_set_faceName(self ? self->impl : null, v))
54       get(constString, faceName, return FontResource_get_faceName(self ? self->impl : null))
55    );
56    property(size,
57       set(float, size, FontResource_set_size(self ? self->impl : null, v))
58       get(float, size, return FontResource_get_size(self ? self->impl : null))
59    );
60 };
61
62 /****************************************************************************
63    ecere::gui Namespace
64 ****************************************************************************/
65 ///////////// Window Class /////////////////////////////////////////////////
66 #define Window_class_registration(d) \
67    REGISTER_METHOD("OnRedraw", onRedraw, Window, d, void, (eC_Window o, eC_Surface s),    o, (*i, Surface { s }), (o, s), ); \
68    REGISTER_METHOD("OnCreate", onCreate, Window, d, bool, (eC_Window o),                  o, (*i),                (o),    true);
69
70 bool foo(eC_Instance o);
71
72 class Window : public Instance
73 {
74 public:
75    CONSTRUCT(Window, Instance) { }
76
77    REGISTER() { Window_class_registration(Window); }
78
79    VIRTUAL_METHOD(onCreate, Window, Window, bool, (Window &), (),
80       return Window_onCreate(self->impl));
81    VIRTUAL_METHOD(onRedraw, Window, Window, void, (Window &, Surface), (Surface surface),
82       return Window_onRedraw(self->impl, surface.impl));
83
84    DialogResult modal() { return Window_modal(impl); }
85
86    // TOCHECK: See if we'll need set/get methods in addition to 'properties' for SWIG
87    //void set_size(const Size & v) { Window_set_size(impl, &v); }
88    //void set_hasClose(eC_bool v)  { Window_set_hasClose(impl, v); }
89
90    #undef   PSELF
91    #define  PSELF SELF(Window, parent)
92
93    property(parent,
94       set(const Window &, parent, Window_set_parent(self ? self->impl : null, v.impl))
95       get(Window &, parent,
96          eC_Instance i = Window_get_parent(self ? self->impl : null);
97          return *(Window *)_INSTANCE(i, Window::_class.impl))
98
99       _set(const Window *, parent, Window_set_parent(self ? self->impl : null, v ? v->impl : null))
100       get(Window *, parent,
101          eC_Instance i = Window_get_parent(self ? self->impl : null);
102          return i ? (Window *)_INSTANCE(i, Window::_class.impl) : null)
103
104       get(Window, parent, return Window(Window_get_parent(self ? self->impl : null)));
105    );
106    property(size,
107       set(const Size &, size, Window_set_size(self ? self->impl : null, &v))
108       get(Size, size, { Size v; Window_get_size(self ? self->impl : null, &v); return v; })
109    );
110    property(clientSize,
111       set(const Size &, clientSize, Window_set_clientSize(self ? self->impl : null, &v))
112       get(Size,         clientSize, { Size v; Window_get_clientSize(self ? self->impl : null, &v); return v; })
113    );
114    property(position,
115       set(const Point &, position, Window_set_position(self ? self->impl : null, &v))
116       get(Point,         position, { Point v; Window_get_position(self ? self->impl : null, &v); return v; })
117    );
118    property(hasClose,
119       set(eC_bool, hasClose, Window_set_hasClose(self ? self->impl : null, v))
120       get(eC_bool, hasClose, return Window_get_hasClose(self ? self->impl : null))
121    );
122    property(hasMinimize,
123       set(eC_bool, hasMinimize, Window_set_hasMinimize(self ? self->impl : null, v))
124       get(eC_bool, hasMinimize, return Window_get_hasMinimize(self ? self->impl : null))
125    );
126    property(hasMaximize,
127       set(eC_bool, hasMaximize, Window_set_hasMaximize(self ? self->impl : null, v))
128       get(eC_bool, hasMaximize, return Window_get_hasMaximize(self ? self->impl : null))
129    );
130    property(caption,
131       set(constString, caption, Window_set_caption(self ? self->impl : null, v))
132       get(constString, caption, return Window_get_caption(self ? self->impl : null))
133    );
134    property(font,
135       set(const FontResource &, font, Window_set_font(self ? self->impl : null, v.impl))
136       get(FontResource &, font,
137             eC_Instance i = Window_get_font(self ? self->impl : null);
138             return *(FontResource *)_INSTANCE(i, FontResource::_class.impl))
139
140       _set(const FontResource *, font, Window_set_font(self ? self->impl : null, v->impl))
141       get(FontResource *, font,
142             eC_Instance i = Window_get_font(self ? self->impl : null);
143             return i ? (FontResource *)_INSTANCE(i, FontResource::_class.impl) : null)
144
145       get(FontResource, font, return FontResource(Window_get_font(self ? self->impl : null)))
146    );
147    property(borderStyle,
148       set(BorderStyle, borderStyle, Window_set_borderStyle(self ? self->impl : null, v))
149       get(BorderStyle, borderStyle, return Window_get_borderStyle(self ? self->impl : null))
150    );
151    property(background,
152       set(Color, background, Window_set_background(self ? self->impl : null, v))
153       get(Color, background, return Window_get_background(self ? self->impl : null))
154    );
155 };
156
157 ///////////// Label Class /////////////////////////////////////////////////
158 class Label : public Window
159 {
160 public:
161    CONSTRUCT(Label, Window) { }
162
163    REGISTER() { Window_class_registration(Label); }
164 };
165
166 ///////////// MessageBox Class /////////////////////////////////////////////////
167 class MessageBox : public Window
168 {
169 public:
170    CONSTRUCT(MessageBox, Window) { }
171
172    MessageBox(constString contents, constString caption = ""/*,  MessageBoxType type = ok*/) : MessageBox()
173    {
174       this->contents = contents;
175       this->caption = caption;
176    }
177    REGISTER() { Window_class_registration(MessageBox); }
178
179    #undef PSELF
180    #define PSELF SELF(MessageBox, contents)
181
182    property(contents,
183       set(constString, contents, MessageBox_set_contents(self ? self->impl : null, v))
184       get(constString, contents, return MessageBox_get_contents(self ? self->impl : null))
185    );
186 };
187
188 ///////////// Button Class /////////////////////////////////////////////////
189 #define Button_class_registration(d) \
190    Window_class_registration(d); \
191    REGISTER_METHOD("NotifyClicked", notifyClicked, Button, d, \
192       bool, (eC_Window m, eC_Button b, int x, int y, Modifiers mods), \
193       b, (*(Window *)INSTANCEL(m, m->_class), *(Button *)INSTANCEL(b, b->_class), x, y, mods), \
194       (m, b, x, y, mods), true);
195
196 class Button : public Window
197 {
198 public:
199    CONSTRUCT(Button, Window) { }
200
201    REGISTER() { Button_class_registration(Button); }
202
203    VIRTUAL_METHOD(notifyClicked, Button, Button, bool, (Window &, Button &, int, int, Modifiers), (Window & window, Button & button, int x, int y, Modifiers mods),
204       return Button_notifyClicked(self->impl, window.impl, button.impl, x, y, mods));
205 };
206
207 ///////////// ToolButton Class /////////////////////////////////////////////////////
208 class ToolButton : public Button
209 {
210 public:
211    CONSTRUCT(ToolButton, Button) { }
212    REGISTER() { Button_class_registration(ToolButton); }
213
214    #undef PSELF
215    #define PSELF SELF(ToolButton, Foo)
216 };
217
218 ///////////// GuiApplication Class /////////////////////////////////////////////////
219 class GuiApplication : public Application
220 {
221 public:
222    APP_CONSTRUCT(GuiApplication, Application)
223    {
224       Instance_evolve(&impl, GuiApplication::_class.impl);
225       _INSTANCE(impl, impl->_class) = this;
226       vTbl = _class.vTbl;
227    }
228
229    REGISTER() { Application_class_registration(GuiApplication); }
230 };
231
232 #endif