36 #include "model.h" |
36 #include "model.h" |
37 #include "image.h" |
37 #include "image.h" |
38 #include "../common/document.h" |
38 #include "../common/document.h" |
39 #include "../common/properties.h" |
39 #include "../common/properties.h" |
40 |
40 |
|
41 #include <ucx/utils.h> |
|
42 |
41 #include <pthread.h> |
43 #include <pthread.h> |
42 |
44 |
|
45 static GtkApplication *app; |
|
46 |
43 static char *application_name; |
47 static char *application_name; |
|
48 |
|
49 static ui_callback startup_func; |
|
50 static void *startup_data; |
|
51 static ui_callback open_func; |
|
52 void *open_data; |
|
53 static ui_callback exit_func; |
|
54 void *exit_data; |
44 |
55 |
45 static ui_callback appclose_fnc; |
56 static ui_callback appclose_fnc; |
46 static void *appclose_udata; |
57 static void *appclose_udata; |
47 |
58 |
48 static UiObject *active_window; |
59 static UiObject *active_window; |
64 |
75 |
65 char* ui_appname() { |
76 char* ui_appname() { |
66 return application_name; |
77 return application_name; |
67 } |
78 } |
68 |
79 |
69 void ui_exitfunc(ui_callback f, void *userdata) { |
80 void ui_onstartup(ui_callback f, void *userdata) { |
70 appclose_fnc = f; |
81 startup_func = f; |
71 appclose_udata = userdata; |
82 startup_data = userdata; |
72 } |
83 } |
73 |
84 |
74 void ui_openfilefunc(ui_callback f, void *userdata) { |
85 void ui_onopen(ui_callback f, void *userdata) { |
75 // OS X only |
86 open_func = f; |
|
87 open_data = userdata; |
|
88 } |
|
89 |
|
90 void ui_onexit(ui_callback f, void *userdata) { |
|
91 exit_func = f; |
|
92 exit_data = userdata; |
|
93 } |
|
94 |
|
95 |
|
96 static void app_startup(GtkApplication* app, gpointer userdata) { |
|
97 startup_func(NULL, startup_data); |
|
98 } |
|
99 |
|
100 static void app_activate(GtkApplication* app, gpointer userdata) { |
|
101 printf("activate\n"); |
76 } |
102 } |
77 |
103 |
78 void ui_main() { |
104 void ui_main() { |
|
105 #ifndef GTK2_LEGACY |
|
106 sstr_t appid = ucx_sprintf( |
|
107 "ui.%s", |
|
108 application_name ? application_name : "application1"); |
|
109 |
|
110 app = gtk_application_new( |
|
111 appid.ptr, |
|
112 G_APPLICATION_FLAGS_NONE); |
|
113 g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL); |
|
114 g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL); |
|
115 g_application_run(G_APPLICATION (app), 0, NULL); |
|
116 g_object_unref (app); |
|
117 |
|
118 free(appid.ptr); |
|
119 #else |
79 gtk_main(); |
120 gtk_main(); |
|
121 #endif |
80 if(appclose_fnc) { |
122 if(appclose_fnc) { |
81 appclose_fnc(NULL, appclose_udata); |
123 appclose_fnc(NULL, appclose_udata); |
82 } |
124 } |
83 uic_store_app_properties(); |
125 uic_store_app_properties(); |
|
126 } |
|
127 |
|
128 void ui_app_quit() { |
|
129 g_application_quit(G_APPLICATION(app)); |
|
130 } |
|
131 |
|
132 GtkApplication* ui_get_application() { |
|
133 return app; |
84 } |
134 } |
85 |
135 |
86 void ui_show(UiObject *obj) { |
136 void ui_show(UiObject *obj) { |
87 uic_check_group_widgets(obj->ctx); |
137 uic_check_group_widgets(obj->ctx); |
88 gtk_widget_show_all(obj->widget); |
138 gtk_widget_show_all(obj->widget); |