UNIXworkcode

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 TOOLKIT_H 30 #define TOOLKIT_H 31 32 #include "../ui/toolkit.h" 33 #include "../common/context.h" 34 #include "../common/object.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 41 42 43 #if GLIB_MAJOR_VERSION * 1000 + GLIB_MINOR_VERSION > 2074 44 #define UI_G_APPLICATION_FLAGS G_APPLICATION_DEFAULT_FLAGS 45 #else 46 #define UI_G_APPLICATION_FLAGS G_APPLICATION_FLAGS_NONE 47 #endif 48 49 #ifdef UI_LIBADWAITA 50 #define UI_APPLICATION AdwApplication* 51 #define UI_APPLICATION_NEW(id) adw_application_new(id, UI_G_APPLICATION_FLAGS) 52 #elif GTK_MAJOR_VERSION >= 3 53 #define UI_APPLICATION GtkApplication* 54 #define UI_APPLICATION_NEW(id) gtk_application_new(id, UI_G_APPLICATION_FLAGS) 55 #endif 56 57 #if GTK_MAJOR_VERSION >= 4 58 #define WINDOW_SHOW(window) gtk_window_present(GTK_WINDOW(window)) 59 #define WINDOW_DESTROY(window) gtk_window_destroy(GTK_WINDOW(window)) 60 #define WINDOW_SET_CONTENT(window, child) gtk_window_set_child(GTK_WINDOW(window), child) 61 #define BOX_ADD(box, child) gtk_box_append(GTK_BOX(box), child) 62 #define BOX_ADD_EXPAND(box, child) gtk_widget_set_hexpand(child, TRUE); gtk_widget_set_vexpand(child, TRUE); gtk_box_append(GTK_BOX(box), child) 63 #define BOX_ADD_NO_EXPAND(box, child) gtk_box_append(GTK_BOX(box), child) 64 #define ENTRY_SET_TEXT(entry, text) gtk_editable_set_text(GTK_EDITABLE(entry), text) 65 #define ENTRY_GET_TEXT(entry) gtk_editable_get_text(GTK_EDITABLE(entry)) 66 #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new() 67 #define SCROLLEDWINDOW_SET_CHILD(sw, child) gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), child) 68 #define SCROLLEDWINDOW_GET_CHILD(sw) gtk_scrolled_window_get_child(GTK_SCROLLED_WINDOW(sw)) 69 #define FRAME_SET_CHILD(frame, child) gtk_frame_set_child(GTK_FRAME(frame), child) 70 #define EXPANDER_SET_CHILD(expander, child) gtk_expander_set_child(GTK_EXPANDER(expander), child) 71 #define WIDGET_ADD_CSS_CLASS(w, cssclass) gtk_widget_add_css_class(w, cssclass) 72 #define WIDGET_REMOVE_CSS_CLASS(w, cssclass) gtk_widget_remove_css_class(w, cssclass) 73 #define ICON_IMAGE(icon) gtk_image_new_from_icon_name(icon) 74 #define LISTBOX_REMOVE(listbox, row) gtk_list_box_remove(GTK_LIST_BOX(listbox), row) 75 #define LISTBOX_ROW_SET_CHILD(row, child) gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), child) 76 #else 77 #define WINDOW_SHOW(window) gtk_widget_show_all(window) 78 #define WINDOW_DESTROY(window) gtk_widget_destroy(window) 79 #define WINDOW_SET_CONTENT(window, child) gtk_container_add(GTK_CONTAINER(window), child) 80 #define BOX_ADD(box, child) gtk_container_add(GTK_CONTAINER(box), child) 81 #define BOX_ADD_EXPAND(box, child) gtk_box_pack_start(GTK_BOX(box), child, TRUE, TRUE, 0) 82 #define BOX_ADD_NO_EXPAND(box, child) gtk_box_pack_start(GTK_BOX(box), child, TRUE, FALSE, 0) 83 #define ENTRY_SET_TEXT(entry, text) gtk_entry_set_text(GTK_ENTRY(entry), text) 84 #define ENTRY_GET_TEXT(entry) gtk_entry_get_text(GTK_ENTRY(entry)) 85 #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new(NULL, NULL) 86 #define SCROLLEDWINDOW_SET_CHILD(sw, child) gtk_container_add(GTK_CONTAINER(sw), child) 87 #define SCROLLEDWINDOW_GET_CHILD(sw) gtk_bin_get_child(GTK_BIN(sw)) 88 #define FRAME_SET_CHILD(frame, child) gtk_container_add(GTK_CONTAINER(frame), child) 89 #define EXPANDER_SET_CHILD(expander, child) gtk_container_add(GTK_CONTAINER(expander), child) 90 #define WIDGET_ADD_CSS_CLASS(w, cssclass) gtk_style_context_add_class(gtk_widget_get_style_context(w), cssclass) 91 #define WIDGET_REMOVE_CSS_CLASS(w, cssclass) gtk_style_context_remove_class(gtk_widget_get_style_context(w), cssclass) 92 #define ICON_IMAGE(icon) gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON) 93 #define LISTBOX_REMOVE(listbox, row) gtk_container_remove(GTK_CONTAINER(listbox), row) 94 #define LISTBOX_ROW_SET_CHILD(row, child) gtk_container_add(GTK_CONTAINER(row), child) 95 #endif 96 97 #ifdef UI_GTK2 98 #undef SCROLLEDWINDOW_SET_CHILD 99 #define SCROLLEDWINDOW_SET_CHILD(sw, child) gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), child) 100 #endif 101 102 #if GTK_MAJOR_VERSION >= 4 103 #define UI_GTK_SINCE_V4(st) st 104 #define UI_GTK_SINCE_V3(st) 105 #define UI_GTK_V2(st) 106 #define UI_GTK_V3(st) 107 #define UI_GTK_V4(st) st 108 #elif GTK_MAJOR_VERSION >= 3 109 #define UI_GTK_SINCE_V4(st) st 110 #define UI_GTK_SINCE_V3(st) st 111 #define UI_GTK_V2(st) 112 #define UI_GTK_V3(st) st 113 #define UI_GTK_V4(st) 114 #else 115 #define UI_GTK_SINCE_V4(st) 116 #define UI_GTK_SINCE_V3(st) 117 #define UI_GTK_V2(st) st 118 #define UI_GTK_V3(st) 119 #define UI_GTK_V4(st) 120 #endif 121 122 123 typedef struct UiEventData { 124 UiObject *obj; 125 ui_callback callback; 126 void *userdata; 127 int value; 128 void *customdata; 129 } UiEventData; 130 131 typedef struct UiEventDataExt { 132 UiObject *obj; 133 ui_callback callback; 134 void *userdata; 135 ui_callback callback2; 136 void *userdata2; 137 int value0; 138 int value1; 139 int value2; 140 int value3; 141 void *customdata0; 142 void *customdata1; 143 void *customdata2; 144 void *customdata3; 145 } UiEventDataExt; 146 147 typedef struct UiVarEventData { 148 UiObject *obj; 149 UiVar *var; 150 UiObserver **observers; 151 ui_callback callback; 152 void *userdata; 153 } UiVarEventData; 154 155 #ifndef UI_GTK4 156 struct UiSelection { 157 GtkSelectionData *data; 158 }; 159 #endif 160 161 typedef enum UiOrientation UiOrientation; 162 enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL }; 163 164 #ifdef UI_APPLICATION 165 void ui_app_quit(); 166 GtkApplication* ui_get_application(); 167 #endif 168 169 int ui_get_scalefactor(); 170 171 void ui_set_name_and_style(GtkWidget *widget, const char *name, const char *style); 172 void ui_set_widget_groups(UiContext *ctx, GtkWidget *widget, const int *groups); 173 void ui_set_widget_ngroups(UiContext *ctx, GtkWidget *widget, const int *groups, size_t ngroups); 174 175 void ui_destroy_userdata(GtkWidget *object, void *userdata); 176 void ui_destroy_vardata(GtkWidget *object, UiVarEventData *data); 177 void ui_destroy_widget_var(GtkWidget *object, UiVar *var); 178 void ui_destroy_boundvar(UiContext *ctx, UiVar *var); 179 180 void ui_set_active_window(UiObject *obj); 181 UiObject *ui_get_active_window(); 182 183 #if GTK_MAJOR_VERSION >= 3 184 void ui_css_init(void); 185 #endif 186 187 #ifdef __cplusplus 188 } 189 #endif 190 191 #endif /* TOOLKIT_H */ 192 193