bindings: Base methods support in Instance class
[sdk] / bindings / c / ecere.h
1 // Preprocessor directives can be added at the beginning (Can't store them in AST)
2
3 /****************************************************************************
4 ===========================================================================
5    Ecere Module
6 ===========================================================================
7 ****************************************************************************/
8 #if !defined(__ECERE_H__)
9 #define __ECERE_H__
10
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15
16 #include "eC.h"
17
18 #define ECERE_APP_INTRO(c) \
19       APP_INTRO \
20       ecere_init(app); \
21       loadTranslatedStrings(null, MODULE_NAME); \
22       Instance_evolve(&app, class_ ## c);
23
24 #define ECERE_APP_OUTRO \
25       unloadTranslatedStrings(MODULE_NAME); \
26       APP_OUTRO
27
28 #define GUIAPP_INTRO ECERE_APP_INTRO(GuiApplication)
29
30 // GENERATED:
31
32 #define Class           eC_Class
33 #define Instance        eC_Instance
34 #define Module          eC_Module
35
36 #define Surface         eC_Surface
37 #define FontResource    eC_FontResource
38
39 #define Window          eC_Window
40 #define DataBox         eC_DataBox
41 #define Button          eC_Button
42 #define Label           eC_Label
43 #define MessageBox      eC_MessageBox
44 #define GuiApplication  eC_GuiApplication
45
46 // Virtual Method Calls
47 #define Window_onCreate(x)    ({  eC_Window i = x; \
48                                   bool (* method)(eC_Window) = (bool (*)(eC_Instance))(i ? i->_vTbl : class_Window->_vTbl)[Window_onCreate_vTblID]; \
49                                   method ? method(i) : true; })
50
51 #define Window_onRedraw(x, s) ({  eC_Window i = x; \
52                                   void (* method)(eC_Window, eC_Surface) = (void (*)(eC_Window, eC_Surface))(i ? i->_vTbl : class_Window->_vTbl)[Window_onRedraw_vTblID]; \
53                                   if(method) method(i, s); })
54
55 #define Button_notifyClicked(t, m, b, x, y, mods)    ({ eC_Button i = t; \
56                                                       bool (* method)(eC_Window, eC_Button, int, int, Modifiers) = (bool (*)(eC_Window, eC_Button, int, int, Modifiers))(i ? i->_vTbl : class_Button->_vTbl)[Button_notifyClicked_vTblID]; \
57                                                       method ? method(m, b, x, y, mods) : true; })
58
59 // Bit Class Member Access
60 #define COLOR_r_MASK       0x00FF0000
61 #define COLOR_r_SHIFT      16
62 #define COLOR_g_MASK       0x0000FF00
63 #define COLOR_g_SHIFT      8
64 #define COLOR_b_MASK       0x000000FF
65 #define COLOR_b_SHIFT      0
66
67 #define COLOR(r, g, b)     ((((Color)(r)) << COLOR_r_SHIFT) | ((Color)(g) << COLOR_g_SHIFT) | ((Color)(b)) << COLOR_b_SHIFT)
68 #define COLOR_r(x)         ((((Color)(x)) & COLOR_r_MASK) >> COLOR_r_SHIFT)
69 #define COLOR_g(x)         ((((Color)(x)) & COLOR_g_MASK) >> COLOR_g_SHIFT)
70 #define COLOR_b(x)         ((((Color)(x)) & COLOR_b_MASK) >> COLOR_b_SHIFT)
71 #define COLOR_SET_r(x, r)  (x) = ((Color)(x) & ~((Color)COLOR_r_MASK)) | (((Color)(r)) << COLOR_r_SHIFT)
72 #define COLOR_SET_g(x, g)  (x) = ((Color)(x) & ~((Color)COLOR_g_MASK)) | (((Color)(g)) << COLOR_g_SHIFT)
73 #define COLOR_SET_b(x, b)  (x) = ((Color)(x) & ~((Color)COLOR_b_MASK)) | (((Color)(b)) << COLOR_b_SHIFT)
74
75 #define BORDERBITS_contour_mask  0x00000001
76 #define BORDERBITS_contour_shift 0
77 #define BORDERBITS_fixed_mask    0x00000002
78 #define BORDERBITS_fixed_shift   1
79 #define BORDERBITS_sizable_mask  0x00000004
80 #define BORDERBITS_sizable_shift 2
81 #define BORDERBITS_deep_mask     0x00000008
82 #define BORDERBITS_deep__shift   3
83 #define BORDERBITS_bevel_mask    0x00000010
84 #define BORDERBITS_bevel_shift   4
85 #define BORDERBITS_thin_mask     0x00000020
86 #define BORDERBITS_thin_shift    5
87
88 #define BORDERBITS_contour(x)    ((((BorderBits)(x)) & BORDERBITS_contour_MASK) >> BORDERBITS_contours_SHIFT)
89 #define BORDERBITS_fixed(x)      ((((BorderBits)(x)) & BORDERBITS_fixed_MASK) >> BORDERBITS_fixed_SHIFT)
90 #define BORDERBITS_sizable(x)    ((((BorderBits)(x)) & BORDERBITS_sizable_MASK) >> BORDERBITS_sizable_SHIFT)
91 #define BORDERBITS_deep(x)       ((((BorderBits)(x)) & BORDERBITS_deep_MASK) >> BORDERBITS_deep_SHIFT)
92 #define BORDERBITS_bevel(x)      ((((BorderBits)(x)) & BORDERBITS_bevel_MASK) >> BORDERBITS_bevel_SHIFT)
93 #define BORDERBITS_thin(x)       ((((BorderBits)(x)) & BORDERBITS_thin_MASK) >> BORDERBITS_thin_SHIFT)
94
95 // Structs
96 struct Size { int w, h; };
97 struct Point { int x, y; };
98
99 // Struct Typedefs
100 typedef struct Size Size;
101 typedef struct Point Point;
102
103 /****************************************************************************
104    ecere::gfx Namespace
105 ****************************************************************************/
106 // Color Bit Class
107 typedef uint32 Color;
108
109 // System Color Enum
110 #if !CPP11
111 typedef Color SystemColor;
112 #endif
113
114 enum SystemColor
115 #if CPP11
116    : Color
117 #endif
118 {
119    formColor = COLOR(229, 234, 245)
120 };
121
122 ///////////// Surface Class /////////////////////////////////////////////////
123
124 typedef Instance Surface;
125
126 extern Class * class_Surface;
127
128 // Methods
129 extern Method * method_Surface_writeTextf;
130
131 extern void (* Surface_writeTextf)(Surface s, int x, int y, const char * format, ...);
132
133
134 ///////////// FontResource Class /////////////////////////////////////////////////
135 extern Class * class_FontResource;
136
137 typedef Instance FontResource;
138
139 // Properties
140 extern Property * property_FontResource_faceName;
141 extern Property * property_FontResource_size;
142
143 extern void (* FontResource_set_faceName)(FontResource f, constString v);
144 extern constString (* FontResource_get_faceName)(FontResource f);
145
146 extern void (* FontResource_set_size)(FontResource f, float v);
147 extern float (* FontResource_get_size)(FontResource f);
148
149 extern void (* FontResource_set_bold)(FontResource f, bool v);
150 extern bool (* FontResource_get_bold)(FontResource f);
151
152 extern void (* FontResource_set_italic)(FontResource f, bool v);
153 extern bool (* FontResource_get_italic)(FontResource f);
154
155 /****************************************************************************
156    ecere::gui Namespace
157 ****************************************************************************/
158
159 // Bit Class Typedefs
160 typedef uint32 Modifiers;
161 typedef uint32 BorderBits;
162
163 // Enum Typedefs
164 #if !CPP11
165 typedef BorderBits BorderStyle;
166 #endif
167
168 #if !CPP11
169 typedef int64 DialogResult;
170 #endif
171
172 // Enumerations
173 enum DialogResult
174 #if CPP11
175    : int64
176 #endif
177 {
178    cancel = 0,
179    yes = 1,
180    no = 2,
181    ok = 3
182 };
183
184 enum BorderStyle
185 #if CPP11
186    : BorderBits
187 #endif
188 {
189    none,
190    contour      = BORDERBITS_contour_mask,
191    fixed        = BORDERBITS_fixed_mask | contour,
192    sizable      = BORDERBITS_sizable_mask | fixed,
193    thin         = BORDERBITS_thin_mask | fixed,
194    sizableThin  = BORDERBITS_sizable_mask | thin,
195    deep         = BORDERBITS_deep_mask,
196    bevel        = BORDERBITS_bevel_mask,
197    sizableDeep  = sizable|deep,
198    sizableBevel = sizable|bevel,
199    fixedDeep    = fixed|deep,
200    fixedBevel   = fixed|bevel,
201    deepContour  = deep|contour
202 };
203
204 ///////////// Window Class /////////////////////////////////////////////////
205 typedef Instance Window;
206
207 extern Class * class_Window;
208
209 // Properties
210 extern Property * property_Window_caption;
211 extern Property * property_Window_caption;
212 extern Property * property_Window_size;
213 extern Property * property_Window_clientSize;
214 extern Property * property_Window_hasClose;
215 extern Property * property_Window_hasMinimize;
216 extern Property * property_Window_hasMaximize;
217 extern Property * property_Window_borderStyle;
218 extern Property * property_Window_background;
219 extern Property * property_Window_parent;
220 extern Property * property_Window_position;
221 extern Property * property_Window_font;
222
223 extern void (* Window_set_borderStyle)(Window w, BorderStyle v);
224 extern BorderStyle (* Window_get_borderStyle)(Window w);
225
226 extern void (* Window_set_size)(Window w, const Size * v);
227 extern void (* Window_get_size)(Window w, Size * v);
228
229 extern void (* Window_set_clientSize)(Window w, const Size * v);
230 extern void (* Window_get_clientSize)(Window w, Size * v);
231
232 extern void (* Window_set_hasClose)(Window w, bool v);
233 extern bool (* Window_get_hasClose)(Window w);
234
235 extern void (* Window_set_hasMaximize)(Window w, bool v);
236 extern bool (* Window_get_hasMaximize)(Window w);
237
238 extern void (* Window_set_hasMinimize)(Window w, bool v);
239 extern bool (* Window_get_hasMinimize)(Window w);
240
241 extern void (* Window_set_parent)(Window w, Window v);
242 extern Window (* Window_get_parent)(Window w);
243
244 extern void (* Window_set_background)(Window w, Color v);
245 extern Color (* Window_get_background)(Window w);
246
247 extern void (* Window_set_position)(Window w, const Point * v);
248 extern void (* Window_get_position)(Window w, Point * v);
249
250 extern void (* Window_set_font)(Window w, FontResource v);
251 extern FontResource (* Window_get_font)(Window w);
252
253 extern void (* Window_set_caption)(Window w, constString v);
254 extern constString (* Window_get_caption)(Window w);
255
256 // Methods
257 extern DialogResult (* Window_modal)(Window);
258
259 extern Method * method_Window_modal;
260 extern Method * method_Window_onCreate;
261
262 extern int Window_onCreate_vTblID;
263 extern int Window_onRedraw_vTblID;
264
265 ///////////// Label Class /////////////////////////////////////////////////
266 extern Class * class_Label;
267
268 typedef Instance Label;
269
270 ///////////// MessageBox Class /////////////////////////////////////////////////
271 typedef Window MessageBox;
272
273 extern Class * class_MessageBox;
274
275 // Properties
276 extern Property * property_MessageBox_contents;
277
278 extern void (* MessageBox_set_contents)(MessageBox m, constString v);
279 extern constString (* MessageBox_get_contents)(MessageBox m);
280
281 ///////////// Button Class /////////////////////////////////////////////////
282 typedef Window Button;
283
284 extern Class * class_Button;
285
286 // Method IDs
287 extern int Button_notifyClicked_vTblID;
288
289
290 extern Class * class_ToolButton;
291
292 ///////////// DataBox Class /////////////////////////////////////////////////
293 typedef Window DataBox;
294
295 ///////////// GuiApplication Class /////////////////////////////////////////////////
296 extern Class * class_GuiApplication;
297
298 typedef Instance GuiApplication;
299
300 Module ecere_init(Module fromModule);
301
302 #ifdef __cplusplus
303    #undef Button
304    #undef MessageBox
305    #undef Label
306    #undef Window
307    #undef DataBox
308    #undef GuiApplication
309
310    #undef FontResource
311    #undef Surface
312
313    #undef Module
314    #undef Class
315    #undef Instance
316 };
317 #endif
318
319 #endif