| 37 #include "../common/document.h" |
37 #include "../common/document.h" |
| 38 #include "../common/properties.h" |
38 #include "../common/properties.h" |
| 39 #include "../common/menu.h" |
39 #include "../common/menu.h" |
| 40 #include "../common/toolbar.h" |
40 #include "../common/toolbar.h" |
| 41 #include "../common/threadpool.h" |
41 #include "../common/threadpool.h" |
| |
42 #include "../common/app.h" |
| 42 |
43 |
| 43 #include <cx/string.h> |
44 #include <cx/string.h> |
| 44 #include <cx/printf.h> |
45 #include <cx/printf.h> |
| 45 |
46 |
| 46 #include <pthread.h> |
47 #include <pthread.h> |
| 48 #ifdef UI_APPLICATION |
49 #ifdef UI_APPLICATION |
| 49 UI_APPLICATION app; |
50 UI_APPLICATION app; |
| 50 #endif |
51 #endif |
| 51 |
52 |
| 52 static const char *application_name; |
53 static const char *application_name; |
| 53 |
|
| 54 static ui_callback startup_func; |
|
| 55 static void *startup_data; |
|
| 56 static ui_callback open_func; |
|
| 57 void *open_data; |
|
| 58 static ui_callback exit_func; |
|
| 59 void *exit_data; |
|
| 60 |
54 |
| 61 static ui_callback appclose_fnc; |
55 static ui_callback appclose_fnc; |
| 62 static void *appclose_udata; |
56 static void *appclose_udata; |
| 63 |
57 |
| 64 static UiObject *active_window; |
58 static UiObject *active_window; |
| 93 |
87 |
| 94 const char* ui_appname() { |
88 const char* ui_appname() { |
| 95 return application_name; |
89 return application_name; |
| 96 } |
90 } |
| 97 |
91 |
| 98 void ui_onstartup(ui_callback f, void *userdata) { |
|
| 99 startup_func = f; |
|
| 100 startup_data = userdata; |
|
| 101 } |
|
| 102 |
|
| 103 void ui_onopen(ui_callback f, void *userdata) { |
|
| 104 open_func = f; |
|
| 105 open_data = userdata; |
|
| 106 } |
|
| 107 |
|
| 108 void ui_onexit(ui_callback f, void *userdata) { |
|
| 109 exit_func = f; |
|
| 110 exit_data = userdata; |
|
| 111 } |
|
| 112 |
|
| 113 void ui_app_exit_on_shutdown(UiBool exitapp) { |
92 void ui_app_exit_on_shutdown(UiBool exitapp) { |
| 114 exit_on_shutdown = exitapp; |
93 exit_on_shutdown = exitapp; |
| 115 } |
94 } |
| 116 |
95 |
| 117 #ifdef UI_APPLICATION |
96 #ifdef UI_APPLICATION |
| 118 static void app_startup(GtkApplication* app, gpointer userdata) { |
97 static void app_startup(GtkApplication* app, gpointer userdata) { |
| 119 if(startup_func) { |
98 uic_application_startup(NULL); |
| 120 startup_func(NULL, startup_data); |
|
| 121 } |
|
| 122 } |
99 } |
| 123 |
100 |
| 124 static void app_activate(GtkApplication* app, gpointer userdata) { |
101 static void app_activate(GtkApplication* app, gpointer userdata) { |
| 125 //printf("activate\n"); |
102 //printf("activate\n"); |
| 126 } |
103 } |
| 127 |
104 |
| 128 static void app_shutdown(GtkApplication *app, gpointer userdata) { |
105 static void app_shutdown(GtkApplication *app, gpointer userdata) { |
| 129 if(exit_func) { |
106 uic_application_exit(NULL); |
| 130 exit_func(NULL, exit_data); |
|
| 131 } |
|
| 132 ui_app_save_settings(); |
107 ui_app_save_settings(); |
| 133 } |
108 } |
| 134 |
109 |
| 135 #endif |
110 #endif |
| 136 |
111 |
| 146 g_application_run(G_APPLICATION (app), 0, NULL); |
121 g_application_run(G_APPLICATION (app), 0, NULL); |
| 147 g_object_unref (app); |
122 g_object_unref (app); |
| 148 |
123 |
| 149 free(appid.ptr); |
124 free(appid.ptr); |
| 150 #else |
125 #else |
| 151 if(startup_func) { |
126 uic_application_startup(NULL); |
| 152 startup_func(NULL, startup_data); |
|
| 153 } |
|
| 154 gtk_main(); |
127 gtk_main(); |
| 155 if(exit_func) { |
128 uic_application_exit(NULL); |
| 156 exit_func(NULL, exit_data); |
|
| 157 } |
|
| 158 ui_app_save_settings(); |
129 ui_app_save_settings(); |
| 159 #endif |
130 #endif |
| 160 if(exit_on_shutdown) { |
131 if(exit_on_shutdown) { |
| 161 exit(0); |
132 exit(0); |
| 162 } |
133 } |
| 163 } |
134 } |
| 164 |
135 |
| 165 #ifndef UI_GTK2 |
136 #ifndef UI_GTK2 |
| 166 void ui_app_quit() { |
137 void ui_app_quit() { |
| 167 g_application_quit(G_APPLICATION(app)); |
138 g_application_quit(G_APPLICATION(app)); // TODO: fix, does not work |
| 168 } |
139 } |
| 169 |
140 |
| 170 GtkApplication* ui_get_application() { |
141 GtkApplication* ui_get_application() { |
| 171 return GTK_APPLICATION(app); |
142 return GTK_APPLICATION(app); |
| 172 } |
143 } |
| 173 #endif |
144 #endif |
| 174 |
145 |
| 175 void ui_show(UiObject *obj) { |
146 void ui_show(UiObject *obj) { |
| 176 gboolean visible = gtk_widget_is_visible(obj->widget); |
147 gboolean visible = gtk_widget_is_visible(obj->widget); |
| 177 |
148 |
| 178 uic_check_group_widgets(obj->ctx); |
149 uic_check_state_widgets(obj->ctx); |
| 179 #if GTK_MAJOR_VERSION >= 4 |
150 #if GTK_MAJOR_VERSION >= 4 |
| 180 gtk_window_present(GTK_WINDOW(obj->widget)); |
151 gtk_window_present(GTK_WINDOW(obj->widget)); |
| 181 #elif GTK_MAJOR_VERSION <= 3 |
152 #elif GTK_MAJOR_VERSION <= 3 |
| 182 gtk_widget_show_all(obj->widget); |
153 gtk_widget_show_all(obj->widget); |
| 183 #endif |
154 #endif |
| 261 #if GTK_MAJOR_VERSION <= 3 |
232 #if GTK_MAJOR_VERSION <= 3 |
| 262 gtk_widget_set_no_show_all(widget, !value); |
233 gtk_widget_set_no_show_all(widget, !value); |
| 263 #endif |
234 #endif |
| 264 } |
235 } |
| 265 |
236 |
| 266 void ui_set_visible(UIWIDGET widget, int visible) { |
237 void ui_set_visible(UIWIDGET widget, UiBool visible) { |
| 267 #if GTK_MAJOR_VERSION >= 4 |
238 #if GTK_MAJOR_VERSION >= 4 |
| 268 gtk_widget_set_visible(widget, visible); |
239 gtk_widget_set_visible(widget, visible); |
| 269 #else |
240 #else |
| 270 if(visible) { |
241 if(visible) { |
| 271 gtk_widget_set_no_show_all(widget, FALSE); |
|
| 272 gtk_widget_show_all(widget); |
242 gtk_widget_show_all(widget); |
| 273 } else { |
243 } else { |
| |
244 gtk_widget_set_no_show_all(widget, FALSE); |
| 274 gtk_widget_hide(widget); |
245 gtk_widget_hide(widget); |
| 275 } |
246 } |
| 276 #endif |
247 #endif |
| 277 } |
248 } |
| 278 |
249 |
| 344 |
315 |
| 345 #if GTK_MAJOR_VERSION >= 3 |
316 #if GTK_MAJOR_VERSION >= 3 |
| 346 |
317 |
| 347 #if GTK_MAJOR_VERSION == 4 |
318 #if GTK_MAJOR_VERSION == 4 |
| 348 static const char *ui_gtk_css = |
319 static const char *ui_gtk_css = |
| |
320 ".ui-entry-box {\n" |
| |
321 " background-color: alpha(currentColor, 0.1);" |
| |
322 " border-radius: 6px;" |
| |
323 " padding: 7px;" |
| |
324 "}\n" |
| 349 "#path-textfield-box {\n" |
325 "#path-textfield-box {\n" |
| 350 " background-color: alpha(currentColor, 0.1);" |
326 " background-color: alpha(currentColor, 0.1);" |
| 351 " border-radius: 6px;" |
327 " border-radius: 6px;" |
| 352 " padding: 0px;" |
328 " padding: 0px;" |
| 353 "}\n" |
329 "}\n" |
| 527 free(cls); |
503 free(cls); |
| 528 |
504 |
| 529 } |
505 } |
| 530 } |
506 } |
| 531 |
507 |
| 532 void ui_set_widget_groups(UiContext *ctx, GtkWidget *widget, const int *groups) { |
508 void ui_set_widget_states(UiContext *ctx, GtkWidget *widget, const int *states) { |
| 533 if(!groups) { |
509 if(!states) { |
| 534 return; |
510 return; |
| 535 } |
511 } |
| 536 size_t ngroups = uic_group_array_size(groups); |
512 size_t nstates = uic_state_array_size(states); |
| 537 ui_set_widget_ngroups(ctx, widget, groups, ngroups); |
513 ui_set_widget_nstates(ctx, widget, states, nstates); |
| 538 } |
514 } |
| 539 |
515 |
| 540 void ui_set_widget_ngroups(UiContext *ctx, GtkWidget *widget, const int *groups, size_t ngroups) { |
516 void ui_set_widget_nstates(UiContext *ctx, GtkWidget *widget, const int *states, size_t nstates) { |
| 541 if(ngroups > 0) { |
517 if(nstates > 0) { |
| 542 uic_add_group_widget_i(ctx, widget, (ui_enablefunc)ui_set_enabled, groups, ngroups); |
518 uic_add_state_widget_i(ctx, widget, (ui_enablefunc)ui_set_enabled, states, nstates); |
| 543 ui_set_enabled(widget, FALSE); |
519 ui_set_enabled(widget, FALSE); |
| 544 } |
520 } |
| 545 } |
521 } |
| 546 |
522 |
| 547 void ui_set_widget_visibility_states(UiContext *ctx, GtkWidget *widget, const int *states) { |
523 void ui_set_widget_visibility_states(UiContext *ctx, GtkWidget *widget, const int *states) { |
| 548 if(!states) { |
524 if(!states) { |
| 549 return; |
525 return; |
| 550 } |
526 } |
| 551 size_t nstates = uic_group_array_size(states); |
527 size_t nstates = uic_state_array_size(states); |
| 552 ui_set_widget_nvisibility_states(ctx, widget, states, nstates); |
528 ui_set_widget_nvisibility_states(ctx, widget, states, nstates); |
| 553 } |
529 } |
| 554 |
530 |
| 555 |
531 |
| 556 void ui_set_widget_nvisibility_states(UiContext *ctx, GtkWidget *widget, const int *states, size_t ngroups) { |
532 void ui_set_widget_nvisibility_states(UiContext *ctx, GtkWidget *widget, const int *states, size_t ngroups) { |
| 557 if(ngroups > 0) { |
533 if(ngroups > 0) { |
| 558 uic_add_group_widget_i(ctx, widget, (ui_enablefunc)ui_set_visible, states, ngroups); |
534 uic_add_state_widget_i(ctx, widget, (ui_enablefunc)ui_set_visible, states, ngroups); |
| 559 ui_set_visible(widget, FALSE); |
535 ui_set_visible(widget, FALSE); |
| 560 } |
536 } |
| 561 } |
537 } |