|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2017 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef UI_TOOLKIT_H |
|
30 #define UI_TOOLKIT_H |
|
31 |
|
32 #include <inttypes.h> |
|
33 |
|
34 #ifdef UI_COCOA |
|
35 |
|
36 #ifdef __OBJC__ |
|
37 #import <Cocoa/Cocoa.h> |
|
38 #define UIWIDGET NSView* |
|
39 #define UIMENU NSMenu* |
|
40 #else |
|
41 typedef void* UIWIDGET; |
|
42 typedef void* UIMENU; |
|
43 #endif |
|
44 |
|
45 #elif UI_GTK2 || UI_GTK3 |
|
46 |
|
47 #include <gtk/gtk.h> |
|
48 #define UIWIDGET GtkWidget* |
|
49 #define UIMENU GtkMenu* |
|
50 #define UI_GTK |
|
51 |
|
52 #elif UI_MOTIF |
|
53 |
|
54 #include <Xm/XmAll.h> |
|
55 #define UIWIDGET Widget |
|
56 #define UIMENU Widget |
|
57 |
|
58 #elif defined(UI_QT4) || defined(UI_QT5) |
|
59 #ifdef __cplusplus |
|
60 #include <QApplication> |
|
61 #include <QWidget> |
|
62 #include <QMenu> |
|
63 #define UIWIDGET QWidget* |
|
64 #define UIMENU QMenu* |
|
65 #else /* __cplusplus */ |
|
66 #define UIWIDGET void* |
|
67 #define UIMENU void* |
|
68 #endif |
|
69 |
|
70 #elif UI_WINUI |
|
71 |
|
72 #define UIEXPORT __declspec(dllexport) |
|
73 |
|
74 #ifdef __cplusplus |
|
75 |
|
76 #ifndef UI_WINUI_PCH |
|
77 #include <Windows.h> |
|
78 #undef GetCurrentTime |
|
79 #include <winrt/Windows.Foundation.Collections.h> |
|
80 #include <winrt/Windows.UI.Xaml.Interop.h> |
|
81 #include <winrt/Microsoft.UI.Xaml.Controls.h> |
|
82 #endif |
|
83 |
|
84 class UiWindow { |
|
85 public: |
|
86 winrt::Microsoft::UI::Xaml::Window window { nullptr }; |
|
87 |
|
88 UiWindow(winrt::Microsoft::UI::Xaml::Window& win); |
|
89 }; |
|
90 |
|
91 class UiWidget { |
|
92 public: |
|
93 winrt::Microsoft::UI::Xaml::UIElement uielement; |
|
94 void* data1 = nullptr; |
|
95 void* data2 = nullptr; |
|
96 void* data3 = nullptr; |
|
97 UiWidget(winrt::Microsoft::UI::Xaml::UIElement& elm); |
|
98 |
|
99 }; |
|
100 |
|
101 #define UIWIDGET UiWidget* |
|
102 #define UIWINDOW UiWindow* |
|
103 #define UIMENU void* |
|
104 |
|
105 /* |
|
106 // winrt::Microsoft::UI::Xaml::UIElement |
|
107 #define UIWIDGET void* |
|
108 // winrt::Microsoft::UI::Xaml::Window |
|
109 #define UIWINDOW void* |
|
110 #define UIMENU void* |
|
111 */ |
|
112 |
|
113 #else |
|
114 #define UIWIDGET void* |
|
115 #define UIWINDOW void* |
|
116 #define UIMENU void* |
|
117 #endif |
|
118 |
|
119 |
|
120 #endif |
|
121 |
|
122 #ifndef TRUE |
|
123 #define TRUE 1 |
|
124 #endif |
|
125 #ifndef FALSE |
|
126 #define FALSE 0 |
|
127 #endif |
|
128 |
|
129 #ifndef UIEXPORT |
|
130 #define UIEXPORT |
|
131 #endif |
|
132 |
|
133 #ifdef __cplusplus |
|
134 extern "C" { |
|
135 #endif |
|
136 |
|
137 #define UI_GROUP_SELECTION 20000 |
|
138 |
|
139 #define UI_GROUPS(...) (int[]){ __VA_ARGS__, -1 } |
|
140 |
|
141 /* public types */ |
|
142 typedef int UiBool; |
|
143 |
|
144 typedef struct UiObject UiObject; |
|
145 typedef struct UiEvent UiEvent; |
|
146 typedef struct UiMouseEvent UiMouseEvent; |
|
147 typedef struct UiObserver UiObserver; |
|
148 |
|
149 typedef struct UiInteger UiInteger; |
|
150 typedef struct UiDouble UiDouble; |
|
151 typedef struct UiString UiString; |
|
152 typedef struct UiText UiText; |
|
153 typedef struct UiList UiList; |
|
154 typedef struct UiRange UiRange; |
|
155 |
|
156 typedef struct UiStr UiStr; |
|
157 |
|
158 /* begin opaque types */ |
|
159 typedef struct UiContext UiContext; |
|
160 typedef struct UiContainer UiContainer; |
|
161 |
|
162 typedef struct UiIcon UiIcon; |
|
163 typedef struct UiImage UiImage; |
|
164 |
|
165 typedef struct UiDnD UiDnD; |
|
166 /* end opaque types */ |
|
167 |
|
168 typedef struct UiTabbedPane UiTabbedPane; |
|
169 |
|
170 typedef enum UiTri UiTri; |
|
171 |
|
172 enum UiMouseEventType { UI_PRESS = 0, UI_PRESS2 }; |
|
173 |
|
174 |
|
175 |
|
176 typedef void(*ui_callback)(UiEvent*, void*); /* event, user data */ |
|
177 |
|
178 typedef void*(*ui_getvaluefunc)(void*, int); |
|
179 |
|
180 typedef int(*ui_threadfunc)(void*); |
|
181 |
|
182 typedef void(*ui_freefunc)(void*); |
|
183 |
|
184 typedef void(*ui_enablefunc)(void*, UiBool); |
|
185 |
|
186 struct UiObject { |
|
187 /* |
|
188 * native widget |
|
189 */ |
|
190 UIWIDGET widget; |
|
191 |
|
192 #ifdef UI_WINUI |
|
193 /* |
|
194 * native window object |
|
195 */ |
|
196 UIWINDOW wobj; |
|
197 #endif |
|
198 |
|
199 /* |
|
200 * user window data |
|
201 */ |
|
202 void *window; |
|
203 |
|
204 /* |
|
205 * window context |
|
206 */ |
|
207 UiContext *ctx; |
|
208 |
|
209 /* |
|
210 * container interface |
|
211 */ |
|
212 UiContainer *container; |
|
213 |
|
214 /* |
|
215 * next container object |
|
216 */ |
|
217 UiObject *next; |
|
218 }; |
|
219 |
|
220 struct UiTabbedPane { |
|
221 /* |
|
222 * native widget |
|
223 */ |
|
224 UIWIDGET widget; |
|
225 |
|
226 /* |
|
227 * current document |
|
228 */ |
|
229 void *document; |
|
230 |
|
231 /* |
|
232 * parent context |
|
233 */ |
|
234 UiContext *ctx; |
|
235 }; |
|
236 |
|
237 struct UiEvent { |
|
238 UiObject *obj; |
|
239 void *document; |
|
240 void *window; |
|
241 void *eventdata; |
|
242 int intval; |
|
243 }; |
|
244 |
|
245 struct UiMouseEvent { |
|
246 int x; |
|
247 int y; |
|
248 enum UiMouseEventType type; |
|
249 int button; |
|
250 }; |
|
251 |
|
252 struct UiObserver { |
|
253 ui_callback callback; |
|
254 void *data; |
|
255 UiObserver *next; |
|
256 }; |
|
257 |
|
258 struct UiStr { |
|
259 char *ptr; |
|
260 void (*free)(void *v); |
|
261 }; |
|
262 |
|
263 struct UiInteger { |
|
264 int64_t (*get)(UiInteger*); |
|
265 void (*set)(UiInteger*, int64_t); |
|
266 void *obj; |
|
267 |
|
268 int64_t value; |
|
269 UiObserver *observers; |
|
270 }; |
|
271 |
|
272 struct UiDouble { |
|
273 double (*get)(UiDouble*); |
|
274 void (*set)(UiDouble*, double); |
|
275 void *obj; |
|
276 |
|
277 double value; |
|
278 UiObserver *observers; |
|
279 }; |
|
280 |
|
281 struct UiString { |
|
282 char* (*get)(UiString*); |
|
283 void (*set)(UiString*, const char*); |
|
284 void *obj; |
|
285 |
|
286 UiStr value; |
|
287 UiObserver *observers; |
|
288 }; |
|
289 |
|
290 struct UiText { |
|
291 void (*set)(UiText*, char*); |
|
292 char* (*get)(UiText*); |
|
293 char* (*getsubstr)(UiText*, int, int); /* text, begin, end */ |
|
294 void (*insert)(UiText*, int, char*); |
|
295 void (*setposition)(UiText*,int); |
|
296 int (*position)(UiText*); |
|
297 void (*selection)(UiText*, int*, int*); /* text, begin, end */ |
|
298 int (*length)(UiText*); |
|
299 void (*remove)(UiText*, int, int); /* text, begin, end */ |
|
300 UiStr value; |
|
301 int pos; |
|
302 void *obj; |
|
303 void *undomgr; |
|
304 // TODO: replacefunc, ... |
|
305 UiObserver *observers; |
|
306 }; |
|
307 |
|
308 /* |
|
309 * abstract list |
|
310 */ |
|
311 struct UiList { |
|
312 /* get the first element */ |
|
313 void*(*first)(UiList *list); |
|
314 /* get the next element */ |
|
315 void*(*next)(UiList *list); |
|
316 /* get the nth element */ |
|
317 void*(*get)(UiList *list, int i); |
|
318 /* get the number of elements */ |
|
319 int(*count)(UiList *list); |
|
320 /* iterator changes after first() next() and get() */ |
|
321 void *iter; |
|
322 /* private - implementation dependent */ |
|
323 void *data; |
|
324 |
|
325 /* binding function */ |
|
326 void (*update)(UiList *list, int i); |
|
327 /* binding object */ |
|
328 void *obj; |
|
329 |
|
330 /* list of observers */ |
|
331 UiObserver *observers; |
|
332 }; |
|
333 |
|
334 struct UiRange { |
|
335 double (*get)(UiRange *range); |
|
336 void (*set)(UiRange *range, double value); |
|
337 void (*setrange)(UiRange *range, double min, double max); |
|
338 void (*setextent)(UiRange *range, double extent); |
|
339 double value; |
|
340 double min; |
|
341 double max; |
|
342 double extent; |
|
343 void *obj; |
|
344 /* list of observers */ |
|
345 UiObserver *observers; |
|
346 }; |
|
347 |
|
348 enum UiTri { |
|
349 UI_DEFAULT = 0, |
|
350 UI_ON, |
|
351 UI_OFF |
|
352 }; |
|
353 |
|
354 |
|
355 UIEXPORT void ui_init(const char *appname, int argc, char **argv); |
|
356 UIEXPORT const char* ui_appname(); |
|
357 |
|
358 UIEXPORT UiContext* ui_global_context(void); |
|
359 |
|
360 UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata); |
|
361 |
|
362 UIEXPORT void ui_onstartup(ui_callback f, void *userdata); |
|
363 UIEXPORT void ui_onopen(ui_callback f, void *userdata); |
|
364 UIEXPORT void ui_onexit(ui_callback f, void *userdata); |
|
365 |
|
366 UIEXPORT void ui_main(); |
|
367 UIEXPORT void ui_show(UiObject *obj); |
|
368 UIEXPORT void ui_close(UiObject *obj); |
|
369 |
|
370 UIEXPORT void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd); |
|
371 |
|
372 UIEXPORT void* ui_document_new(size_t size); |
|
373 UIEXPORT void ui_document_destroy(void *doc); |
|
374 |
|
375 UIEXPORT void ui_set_document(UiObject *obj, void *document); // deprecated |
|
376 UIEXPORT void ui_detach_document(UiObject *obj); // deprecated |
|
377 UIEXPORT void* ui_get_document(UiObject *obj); // deprecated |
|
378 UIEXPORT void ui_set_subdocument(void *document, void *sub); // deprecated |
|
379 UIEXPORT void ui_detach_subdocument(void *document, void *sub); // deprecated |
|
380 UIEXPORT void* ui_get_subdocument(void *document); // deprecated |
|
381 |
|
382 UIEXPORT UiContext* ui_document_context(void *doc); |
|
383 |
|
384 UIEXPORT void ui_attach_document(UiContext *ctx, void *document); |
|
385 UIEXPORT void ui_detach_document2(UiContext *ctx, void *document); |
|
386 |
|
387 UIEXPORT void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...); |
|
388 |
|
389 UIEXPORT void ui_set_group(UiContext *ctx, int group); |
|
390 UIEXPORT void ui_unset_group(UiContext *ctx, int group); |
|
391 UIEXPORT int* ui_active_groups(UiContext *ctx, int *ngroups); |
|
392 |
|
393 UIEXPORT void* ui_malloc(UiContext *ctx, size_t size); |
|
394 UIEXPORT void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize); |
|
395 UIEXPORT void ui_free(UiContext *ctx, void *ptr); |
|
396 UIEXPORT void* ui_realloc(UiContext *ctx, void *ptr, size_t size); |
|
397 |
|
398 // types |
|
399 |
|
400 UIEXPORT UiInteger* ui_int_new(UiContext *ctx, char *name); |
|
401 UIEXPORT UiDouble* ui_double_new(UiContext *ctx, char *name); |
|
402 UIEXPORT UiString* ui_string_new(UiContext *ctx, char *name); |
|
403 UIEXPORT UiText* ui_text_new(UiContext *ctx, char *name); |
|
404 UIEXPORT UiRange* ui_range_new(UiContext *ctx, char *name); |
|
405 |
|
406 UIEXPORT UiObserver* ui_observer_new(ui_callback f, void *data); |
|
407 UIEXPORT UiObserver* ui_obsvlist_add(UiObserver *list, UiObserver *observer); |
|
408 UIEXPORT UiObserver* ui_add_observer(UiObserver *list, ui_callback f, void *data); |
|
409 UIEXPORT void ui_notify(UiObserver *observer, void *data); |
|
410 UIEXPORT void ui_notify_except(UiObserver *observer, UiObserver *exc, void *data); |
|
411 UIEXPORT void ui_notify_evt(UiObserver *observer, UiEvent *event); |
|
412 |
|
413 |
|
414 UIEXPORT UiList* ui_list_new(UiContext *ctx, char *name); |
|
415 UIEXPORT void* ui_list_first(UiList *list); |
|
416 UIEXPORT void* ui_list_next(UiList *list); |
|
417 UIEXPORT void* ui_list_get(UiList *list, int i); |
|
418 UIEXPORT int ui_list_count(UiList *list); |
|
419 UIEXPORT void ui_list_append(UiList *list, void *data); |
|
420 UIEXPORT void ui_list_prepend(UiList *list, void *data); |
|
421 UIEXPORT void ui_list_clear(UiList *list); |
|
422 UIEXPORT void ui_list_addobsv(UiList *list, ui_callback f, void *data); |
|
423 UIEXPORT void ui_list_notify(UiList *list); |
|
424 |
|
425 UIEXPORT void ui_clipboard_set(char *str); |
|
426 UIEXPORT char* ui_clipboard_get(); |
|
427 |
|
428 UIEXPORT void ui_add_image(char *imgname, char *filename); // TODO: remove? |
|
429 |
|
430 // general widget functions |
|
431 UIEXPORT void ui_set_enabled(UIWIDGET widget, int enabled); |
|
432 UIEXPORT void ui_set_show_all(UIWIDGET widget, int value); |
|
433 UIEXPORT void ui_set_visible(UIWIDGET widget, int visible); |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 UIEXPORT UiIcon* ui_icon(const char* name, size_t size); |
|
440 UIEXPORT UiIcon* ui_imageicon(const char* file); |
|
441 UIEXPORT void ui_icon_free(UiIcon* icon); |
|
442 |
|
443 UIEXPORT UiIcon* ui_foldericon(size_t size); |
|
444 UIEXPORT UiIcon* ui_fileicon(size_t size); |
|
445 |
|
446 #ifdef __cplusplus |
|
447 } |
|
448 #endif |
|
449 |
|
450 #endif /* UI_TOOLKIT_H */ |
|
451 |