Tue, 26 Jan 2016 19:45:28 +0100
added combobox (GTK)
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2014 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef UI_TOOLKIT_H #define UI_TOOLKIT_H #ifdef UI_COCOA #ifdef __OBJC__ #import <Cocoa/Cocoa.h> #define UIWIDGET NSView* #else typedef void* UIWIDGET; #endif #elif UI_GTK2 || UI_GTK3 #include <gtk/gtk.h> #define UIWIDGET GtkWidget* #define UIMENU GtkMenu* #define UI_GTK #elif UI_MOTIF #include <Xm/XmAll.h> #define UIWIDGET Widget #define UIMENU Widget #elif defined(UI_QT4) || defined(UI_QT5) #ifdef __cplusplus #include <QApplication> #include <QWidget> #include <QMenu> #define UIWIDGET QWidget* #define UIMENU QMenu* #else /* __cplusplus */ #define UIWIDGET void* #define UIMENU void* #endif #elif UI_WPF #define UIWIDGET void* #define UIMENU void* #endif #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifdef __cplusplus extern "C" { #endif #define UI_GROUP_SELECTION 20000 /* public types */ typedef int UiBool; typedef struct UiObject UiObject; typedef struct UiEvent UiEvent; typedef struct UiMouseEvent UiMouseEvent; typedef struct UiObserver UiObserver; typedef struct UiInteger UiInteger; typedef struct UiString UiString; typedef struct UiText UiText; typedef struct UiList UiList; /* private types */ typedef struct UiContext UiContext; typedef struct UiContainer UiContainer; typedef struct UiTabbedPane UiTabbedPane; enum UiMouseEventType { UI_PRESS = 0, UI_PRESS2 }; #define ui_getval(val) (val).get(&(val)) #define ui_setval(val, v) (val).set(&(val), v) #define ui_getsubstr(text, begin, end) (text).getsubstr(&(text), begin, end) #define ui_insert(text, begin, str) (text).insert(&(text), begin, str) #define ui_length(text) (text).length(&(text)) #define ui_selection(text, begin, end) (text).selection(&(text), begin, end) #define ui_position(text) (text).position(&(text)) #define ui_remove(text, begin, end) (text).remove(&(text), begin, end) typedef void(*ui_callback)(UiEvent*, void*); /* event, user data */ typedef void*(*ui_model_getvalue_f)(void*, int); typedef int(*ui_threadfunc)(void*); struct UiObject { /* * native widget */ UIWIDGET widget; /* * user window data */ void *window; /* * window context (private) */ UiContext *ctx; /* * container interface (private) */ UiContainer *container; /* * next container object */ UiObject *next; }; struct UiTabbedPane { /* * native widget */ UIWIDGET widget; /* * current document */ void *document; /* * parent context */ UiContext *ctx; }; struct UiEvent { UiObject *obj; void *document; void *window; void *eventdata; int intval; }; struct UiMouseEvent { int x; int y; enum UiMouseEventType type; int button; }; struct UiObserver { ui_callback callback; void *data; UiObserver *next; }; struct UiInteger { int (*get)(UiInteger*); void (*set)(UiInteger*, int); int value; void *obj; }; struct UiString { char* (*get)(UiString*); void (*set)(UiString*, char*); char* value; void *obj; }; struct UiText { void (*set)(UiText*, char*); char* (*get)(UiText*); char* (*getsubstr)(UiText*, int, int); // text, begin, end void (*insert)(UiText*, int, char*); void (*setposition)(UiText*,int); int (*position)(UiText*); void (*selection)(UiText*, int*, int*); // text, begin, end int (*length)(UiText*); void (*remove)(UiText*, int, int); // text, begin, end char *value; int pos; void *obj; void *undomgr; // TODO: replace, ... }; /* * abstract list */ struct UiList { /* get the first element */ void*(*first)(UiList *list); /* get the next element */ void*(*next)(UiList *list); /* get the nth element */ void*(*get)(UiList *list, int i); /* get the number of elements */ int(*count)(UiList *list); /* list of observers */ UiObserver *observers; /* iterator changes after first() next() and get() */ void *iter; /* private - implementation dependent */ void *data; }; void ui_init(char *appname, int argc, char **argv); char* ui_appname(); void ui_exitfunc(ui_callback f, void *userdata); void ui_openfilefunc(ui_callback f, void *userdata); void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata); void ui_main(); void ui_show(UiObject *obj); void ui_close(UiObject *obj); void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd); void ui_set_enabled(UIWIDGET widget, int enabled); void ui_set_show_all(UIWIDGET widget, int value); void ui_set_visible(UIWIDGET widget, int visible); UIWIDGET ui_vbox(UiObject *obj); UIWIDGET ui_hbox(UiObject *obj); UIWIDGET ui_vbox_sp(UiObject *obj, int margin, int spacing); UIWIDGET ui_hbox_sp(UiObject *obj, int margin, int spacing); UIWIDGET ui_grid(UiObject *obj); UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing); UIWIDGET ui_sidebar(UiObject *obj); void ui_end(UiObject *obj); UIWIDGET ui_tabview(UiObject *obj); void ui_tab(UiObject *obj, char *title); void ui_select_tab(UIWIDGET tabview, int tab); // box container layout functions void ui_layout_fill(UiObject *obj, UiBool fill); // grid container layout functions void ui_layout_hexpand(UiObject *obj, UiBool expand); void ui_layout_vexpand(UiObject *obj, UiBool expand); void ui_layout_gridwidth(UiObject *obj, int width); void ui_newline(UiObject *obj); UiTabbedPane* ui_tabbed_document_view(UiObject *obj); UiObject* ui_document_tab(UiTabbedPane *view); void ui_set_document(UiObject *obj, void *document); void ui_detach_document(UiObject *obj, void *document); void* ui_get_document(UiObject *obj); void ui_set_subdocument(void *document, void *sub); void ui_detach_subdocument(void *document, void *sub); void* ui_get_subdocument(void *document); void* ui_document_new(size_t size); void ui_document_destroy(void *doc); UiContext* ui_document_context(void *doc); // TODO: remove void* ui_document_malloc(void *doc, size_t size); void* ui_document_calloc(void *doc, size_t nelem, size_t elsize); void ui_document_free(void *doc, void *ptr); void* ui_document_realloc(void *doc, void *ptr, size_t size); // TODO: remove (or not) void ui_document_addint(void *doc, char *name); void ui_document_regint(void *doc, char *name, UiInteger *i); void ui_document_setint(void *doc, char *name, int val); int ui_document_getint(void *doc, char *name); void ui_document_regtext(void *doc, char *name, UiText *text); void ui_document_reglist(void *doc, char *name, UiList *list); // new: int ui_getint(UiObject *obj, char *name); char *ui_getstr(UiObject *obj, char *name); char* ui_gettext(UiObject *obj, char *name); void ui_set_group(UiContext *ctx, int group); void ui_unset_group(UiContext *ctx, int group); int* ui_active_groups(UiContext *ctx, int *ngroups); void* ui_malloc(UiContext *ctx, size_t size); void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize); void ui_free(UiContext *ctx, void *ptr); void* ui_realloc(UiContext *ctx, void *ptr, size_t size); // types UiObserver* ui_observer_new(ui_callback f, void *data); UiObserver* ui_obsvlist_add(UiObserver *list, UiObserver *observer); UiObserver* ui_add_observer(UiObserver *list, ui_callback f, void *data); void ui_notify(UiObserver *observer, void *data); void ui_notify_except(UiObserver *observer, UiObserver *exc, void *data); UiList* ui_list_new(void); void* ui_list_first(UiList *list); void* ui_list_next(UiList *list); void* ui_list_get(UiList *list, int i); int ui_list_count(UiList *list); void ui_list_append(UiList *list, void *data); void ui_list_prepend(UiList *list, void *data); void ui_list_addobsv(UiList *list, ui_callback f, void *data); void ui_list_notify(UiList *list); void ui_clipboard_set(char *str); char* ui_clipboard_get(); void ui_add_image(char *imgname, char *filename); // label widgets UIWIDGET ui_label(UiObject *obj, char *label); UIWIDGET ui_llabel(UiObject *obj, char *label); UIWIDGET ui_rlabel(UiObject *obj, char *label); UIWIDGET ui_space(UiObject *obj); UIWIDGET ui_separator(UiObject *obj); #ifdef __cplusplus } #endif #endif /* UI_TOOLKIT_H */