| 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 } |