ui/gtk/toolkit.c

changeset 108
77254bd6dccb
parent 103
6606616eca9f
child 109
c3dfcb8f0be7
equal deleted inserted replaced
107:b34bd1557c6c 108:77254bd6dccb
64 64
65 static UiObject *active_window; 65 static UiObject *active_window;
66 66
67 static int scale_factor = 1; 67 static int scale_factor = 1;
68 68
69 static UiBool exit_on_shutdown;
70
69 UIEXPORT void ui_init(const char *appname, int argc, char **argv) { 71 UIEXPORT void ui_init(const char *appname, int argc, char **argv) {
70 application_name = appname; 72 application_name = appname;
71 uic_init_global_context(); 73 uic_init_global_context();
72 74
73 #if GTK_MAJOR_VERSION >= 4 75 #if GTK_MAJOR_VERSION >= 4
108 void ui_onexit(ui_callback f, void *userdata) { 110 void ui_onexit(ui_callback f, void *userdata) {
109 exit_func = f; 111 exit_func = f;
110 exit_data = userdata; 112 exit_data = userdata;
111 } 113 }
112 114
113 115 void ui_app_exit_on_shutdown(UiBool exitapp) {
114 #ifndef UI_GTK2 116 exit_on_shutdown = exitapp;
117 }
118
119 #ifdef UI_APPLICATION
115 static void app_startup(GtkApplication* app, gpointer userdata) { 120 static void app_startup(GtkApplication* app, gpointer userdata) {
116 if(startup_func) { 121 if(startup_func) {
117 startup_func(NULL, startup_data); 122 startup_func(NULL, startup_data);
118 } 123 }
119 } 124 }
120 125
121 static void app_activate(GtkApplication* app, gpointer userdata) { 126 static void app_activate(GtkApplication* app, gpointer userdata) {
122 printf("activate\n"); 127 //printf("activate\n");
123 } 128 }
129
130 static void app_shutdown(GtkApplication *app, gpointer userdata) {
131 if(exit_func) {
132 exit_func(NULL, exit_data);
133 }
134 ui_app_save_settings();
135 }
136
124 #endif 137 #endif
125 138
126 void ui_main() { 139 void ui_main() {
127 #ifdef UI_APPLICATION 140 #ifdef UI_APPLICATION
128 cxmutstr appid = cx_asprintf( 141 cxmutstr appid = cx_asprintf(
129 "ui.%s", 142 "ui.%s",
130 application_name ? application_name : "application1"); 143 application_name ? application_name : "application1");
131 app = UI_APPLICATION_NEW(appid.ptr); 144 app = UI_APPLICATION_NEW(appid.ptr);
132 g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL); 145 g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL);
146 g_signal_connect (app, "shutdown", G_CALLBACK (app_shutdown), NULL);
133 g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL); 147 g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
134 g_application_run(G_APPLICATION (app), 0, NULL); 148 g_application_run(G_APPLICATION (app), 0, NULL);
135 g_object_unref (app); 149 g_object_unref (app);
136 150
137 free(appid.ptr); 151 free(appid.ptr);
138 #else 152 #else
139 if(startup_func) { 153 if(startup_func) {
140 startup_func(NULL, startup_data); 154 startup_func(NULL, startup_data);
141 } 155 }
142 gtk_main(); 156 gtk_main();
143 #endif
144 if(exit_func) { 157 if(exit_func) {
145 exit_func(NULL, exit_data); 158 exit_func(NULL, exit_data);
146 } 159 }
147 uic_store_app_properties(); 160 ui_app_save_settings();
161 #endif
162 if(exit_on_shutdown) {
163 exit(0);
164 }
148 } 165 }
149 166
150 #ifndef UI_GTK2 167 #ifndef UI_GTK2
151 void ui_app_quit() { 168 void ui_app_quit() {
152 g_application_quit(G_APPLICATION(app)); 169 g_application_quit(G_APPLICATION(app));
189 event.obj = job->obj; 206 event.obj = job->obj;
190 event.window = job->obj->window; 207 event.window = job->obj->window;
191 event.document = job->obj->ctx->document; 208 event.document = job->obj->ctx->document;
192 event.intval = 0; 209 event.intval = 0;
193 event.eventdata = NULL; 210 event.eventdata = NULL;
211 event.eventdatatype = 0;
194 212
195 job->finish_callback(&event, job->finish_data); 213 job->finish_callback(&event, job->finish_data);
196 free(job); 214 free(job);
197 return FALSE; 215 return FALSE;
198 } 216 }

mercurial