2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
37 #import <Cocoa/Cocoa.h>
38 #define UIWIDGET NSView*
39 #define UIMENU NSMenu*
41 typedef void* UIWIDGET;
45 #elif UI_GTK2 || UI_GTK3
48 #define UIWIDGET GtkWidget*
49 #define UIMENU GtkMenu*
55 #define UIWIDGET Widget
58 #elif defined(UI_QT4) || defined(UI_QT5)
60 #include <QApplication>
63 #define UIWIDGET QWidget*
65 #else /* __cplusplus */
66 #define UIWIDGET void*
71 #define UIWIDGET void*
86 #define UI_GROUP_SELECTION 20000
91 typedef struct UiObject UiObject;
92 typedef struct UiEvent UiEvent;
93 typedef struct UiMouseEvent UiMouseEvent;
94 typedef struct UiObserver UiObserver;
96 typedef struct UiInteger UiInteger;
97 typedef struct UiDouble UiDouble;
98 typedef struct UiString UiString;
99 typedef struct UiText UiText;
100 typedef struct UiList UiList;
101 typedef struct UiRange UiRange;
103 typedef struct UiStr UiStr;
105 /* begin opaque types */
106 typedef struct UiContext UiContext;
107 typedef struct UiContainer UiContainer;
109 typedef struct UiIcon UiIcon;
110 typedef struct UiImage UiImage;
112 typedef struct UiSelection UiSelection;
113 /* end opaque types */
115 typedef struct UiTabbedPane UiTabbedPane;
117 enum UiMouseEventType { UI_PRESS = 0, UI_PRESS2 };
121 typedef void(*ui_callback)(UiEvent*, void*); /* event, user data */
123 typedef void*(*ui_getvaluefunc)(void*, int);
125 typedef int(*ui_threadfunc)(void*);
127 typedef void(*ui_freefunc)(void*);
129 typedef void(*ui_enablefunc)(void*, UiBool);
148 * container interface
150 UiContainer *container;
153 * next container object
158 struct UiTabbedPane {
183 struct UiMouseEvent {
186 enum UiMouseEventType type;
191 ui_callback callback;
198 void (*free)(void *v);
202 int64_t (*get)(UiInteger*);
203 void (*set)(UiInteger*, int64_t);
207 UiObserver *observers;
211 double (*get)(UiDouble*);
212 void (*set)(UiDouble*, double);
216 UiObserver *observers;
220 char* (*get)(UiString*);
221 void (*set)(UiString*, char*);
225 UiObserver *observers;
229 void (*set)(UiText*, char*);
230 char* (*get)(UiText*);
231 char* (*getsubstr)(UiText*, int, int); /* text, begin, end */
232 void (*insert)(UiText*, int, char*);
233 void (*setposition)(UiText*,int);
234 int (*position)(UiText*);
235 void (*selection)(UiText*, int*, int*); /* text, begin, end */
236 int (*length)(UiText*);
237 void (*remove)(UiText*, int, int); /* text, begin, end */
242 // TODO: replacefunc, ...
243 UiObserver *observers;
250 /* get the first element */
251 void*(*first)(UiList *list);
252 /* get the next element */
253 void*(*next)(UiList *list);
254 /* get the nth element */
255 void*(*get)(UiList *list, int i);
256 /* get the number of elements */
257 int(*count)(UiList *list);
258 /* iterator changes after first() next() and get() */
260 /* private - implementation dependent */
263 /* binding function */
264 void (*update)(UiList *list, int i);
268 /* list of observers */
269 UiObserver *observers;
273 double (*get)(UiRange *range);
274 void (*set)(UiRange *range, double value);
275 void (*setrange)(UiRange *range, double min, double max);
276 void (*setextent)(UiRange *range, double extent);
282 /* list of observers */
283 UiObserver *observers;
287 void ui_init(char *appname, int argc, char **argv);
290 UiContext* ui_global_context(void);
292 void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata);
294 void ui_onstartup(ui_callback f, void *userdata);
295 void ui_onopen(ui_callback f, void *userdata);
296 void ui_onexit(ui_callback f, void *userdata);
299 void ui_show(UiObject *obj);
300 void ui_close(UiObject *obj);
302 void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd);
304 void* ui_document_new(size_t size);
305 void ui_document_destroy(void *doc);
307 void ui_set_document(UiObject *obj, void *document); // deprecated
308 void ui_detach_document(UiObject *obj); // deprecated
309 void* ui_get_document(UiObject *obj); // deprecated
310 void ui_set_subdocument(void *document, void *sub); // deprecated
311 void ui_detach_subdocument(void *document, void *sub); // deprecated
312 void* ui_get_subdocument(void *document); // deprecated
314 UiContext* ui_document_context(void *doc);
316 void ui_attach_document(UiContext *ctx, void *document);
317 void ui_detach_document2(UiContext *ctx, void *document);
319 void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...);
321 void ui_set_group(UiContext *ctx, int group);
322 void ui_unset_group(UiContext *ctx, int group);
323 int* ui_active_groups(UiContext *ctx, int *ngroups);
325 void* ui_malloc(UiContext *ctx, size_t size);
326 void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize);
327 void ui_free(UiContext *ctx, void *ptr);
328 void* ui_realloc(UiContext *ctx, void *ptr, size_t size);
332 UiInteger* ui_int_new(UiContext *ctx, char *name);
333 UiDouble* ui_double_new(UiContext *ctx, char *name);
334 UiString* ui_string_new(UiContext *ctx, char *name);
335 UiText* ui_text_new(UiContext *ctx, char *name);
336 UiRange* ui_range_new(UiContext *ctx, char *name);
338 UiObserver* ui_observer_new(ui_callback f, void *data);
339 UiObserver* ui_obsvlist_add(UiObserver *list, UiObserver *observer);
340 UiObserver* ui_add_observer(UiObserver *list, ui_callback f, void *data);
341 void ui_notify(UiObserver *observer, void *data);
342 void ui_notify_except(UiObserver *observer, UiObserver *exc, void *data);
343 void ui_notify_evt(UiObserver *observer, UiEvent *event);
346 UiList* ui_list_new(UiContext *ctx, char *name);
347 void* ui_list_first(UiList *list);
348 void* ui_list_next(UiList *list);
349 void* ui_list_get(UiList *list, int i);
350 int ui_list_count(UiList *list);
351 void ui_list_append(UiList *list, void *data);
352 void ui_list_prepend(UiList *list, void *data);
353 void ui_list_clear(UiList *list);
354 void ui_list_addobsv(UiList *list, ui_callback f, void *data);
355 void ui_list_notify(UiList *list);
357 void ui_clipboard_set(char *str);
358 char* ui_clipboard_get();
360 void ui_add_image(char *imgname, char *filename); // TODO: remove?
362 // general widget functions
363 void ui_set_enabled(UIWIDGET widget, int enabled);
364 void ui_set_show_all(UIWIDGET widget, int value);
365 void ui_set_visible(UIWIDGET widget, int visible);
372 #endif /* UI_TOOLKIT_H */