49 static int window_default_width = 650; |
49 static int window_default_width = 650; |
50 static int window_default_height = 550; |
50 static int window_default_height = 550; |
51 |
51 |
52 static gboolean ui_window_destroy(void *data) { |
52 static gboolean ui_window_destroy(void *data) { |
53 UiObject *obj = data; |
53 UiObject *obj = data; |
54 UiEvent ev; |
54 uic_object_destroy(obj); |
55 ev.window = obj->window; |
|
56 ev.document = obj->ctx->document; |
|
57 ev.obj = obj; |
|
58 ev.eventdata = NULL; |
|
59 ev.intval = 0; |
|
60 |
|
61 if(obj->ctx->close_callback) { |
|
62 obj->ctx->close_callback(&ev, obj->ctx->close_data); |
|
63 } |
|
64 |
|
65 cxMempoolDestroy(obj->ctx->mp); |
|
66 |
55 |
67 nwindows--; |
56 nwindows--; |
68 #ifdef UI_GTK2 |
57 #ifdef UI_GTK2 |
69 if(nwindows == 0) { |
58 if(nwindows == 0) { |
70 gtk_main_quit(); |
59 gtk_main_quit(); |
72 #endif |
61 #endif |
73 |
62 |
74 return FALSE; |
63 return FALSE; |
75 } |
64 } |
76 |
65 |
|
66 void ui_window_widget_destroy(UiObject *obj) { |
|
67 #if GTK_MAJOR_VERSION >= 4 |
|
68 gtk_window_destroy(GTK_WINDOW(obj->widget)); |
|
69 #else |
|
70 gtk_widget_destroy(obj->widget); |
|
71 #endif |
|
72 } |
|
73 |
77 void ui_exit_event(GtkWidget *widget, gpointer data) { |
74 void ui_exit_event(GtkWidget *widget, gpointer data) { |
78 // delay exit handler |
75 // delay exit handler |
79 UiObject *obj = data; |
|
80 g_idle_add(ui_window_destroy, data); |
76 g_idle_add(ui_window_destroy, data); |
81 } |
77 } |
82 |
78 |
|
79 static gboolean ui_window_close_request(UiObject *obj) { |
|
80 uic_context_prepare_close(obj->ctx); |
|
81 obj->ref--; |
|
82 if(obj->ref > 0) { |
|
83 gtk_widget_hide(obj->widget); |
|
84 return TRUE; |
|
85 } else { |
|
86 return FALSE; |
|
87 } |
|
88 } |
|
89 |
83 #if GTK_MAJOR_VERSION >= 4 |
90 #if GTK_MAJOR_VERSION >= 4 |
84 static gboolean close_request(GtkWindow* self, UiContext *ctx) { |
91 static gboolean close_request(GtkWindow* self, UiObject *obj) { |
85 uic_context_prepare_close(ctx); |
92 return ui_window_close_request(obj); |
86 return FALSE; |
93 } |
87 } |
94 #else |
88 #else |
95 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) { |
89 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiContext *ctx) { |
96 return ui_window_close_request(obj); |
90 uic_context_prepare_close(ctx); |
|
91 return FALSE; |
|
92 } |
97 } |
93 #endif |
98 #endif |
94 |
99 |
95 static UiObject* create_window(const char *title, void *window_data, UiBool simple) { |
100 static UiObject* create_window(const char *title, void *window_data, UiBool simple) { |
96 CxMempool *mp = cxBasicMempoolCreate(256); |
101 CxMempool *mp = cxBasicMempoolCreate(256); |
97 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
102 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
|
103 obj->ref = 1; |
98 |
104 |
99 #ifdef UI_LIBADWAITA |
105 #ifdef UI_LIBADWAITA |
100 obj->widget = adw_application_window_new(ui_get_application()); |
106 obj->widget = adw_application_window_new(ui_get_application()); |
101 #elif !defined(UI_GTK2) |
107 #elif !defined(UI_GTK2) |
102 obj->widget = gtk_application_window_new(ui_get_application()); |
108 obj->widget = gtk_application_window_new(ui_get_application()); |
128 GTK_WINDOW(obj->widget), |
134 GTK_WINDOW(obj->widget), |
129 window_default_width, |
135 window_default_width, |
130 window_default_height); |
136 window_default_height); |
131 } |
137 } |
132 |
138 |
|
139 obj->destroy = ui_window_widget_destroy; |
133 g_signal_connect( |
140 g_signal_connect( |
134 obj->widget, |
141 obj->widget, |
135 "destroy", |
142 "destroy", |
136 G_CALLBACK(ui_exit_event), |
143 G_CALLBACK(ui_exit_event), |
137 obj); |
144 obj); |
138 #if GTK_MAJOR_VERSION >= 4 |
145 #if GTK_MAJOR_VERSION >= 4 |
139 g_signal_connect( |
146 g_signal_connect( |
140 obj->widget, |
147 obj->widget, |
141 "close-request", |
148 "close-request", |
142 G_CALLBACK(close_request), |
149 G_CALLBACK(close_request), |
143 obj->ctx); |
150 obj); |
144 #else |
151 #else |
145 g_signal_connect( |
152 g_signal_connect( |
146 obj->widget, |
153 obj->widget, |
147 "delete-event", |
154 "delete-event", |
148 G_CALLBACK(close_request), |
155 G_CALLBACK(close_request), |
149 obj->ctx); |
156 obj); |
150 #endif |
157 #endif |
151 |
158 |
152 GtkWidget *vbox = ui_gtk_vbox_new(0); |
159 GtkWidget *vbox = ui_gtk_vbox_new(0); |
153 #ifdef UI_LIBADWAITA |
160 #ifdef UI_LIBADWAITA |
154 GtkWidget *toolbar_view = adw_toolbar_view_new(); |
161 GtkWidget *toolbar_view = adw_toolbar_view_new(); |