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 #if GTK_CHECK_VERSION(2, 18, 0) |
|
84 gtk_widget_set_visible(obj->widget, FALSE); |
|
85 #else |
|
86 gtk_widget_hide(obj->widget); |
|
87 #endif |
|
88 return TRUE; |
|
89 } else { |
|
90 return FALSE; |
|
91 } |
|
92 } |
|
93 |
83 #if GTK_MAJOR_VERSION >= 4 |
94 #if GTK_MAJOR_VERSION >= 4 |
84 static gboolean close_request(GtkWindow* self, UiContext *ctx) { |
95 static gboolean close_request(GtkWindow* self, UiObject *obj) { |
85 uic_context_prepare_close(ctx); |
96 return ui_window_close_request(obj); |
86 return FALSE; |
97 } |
87 } |
98 #else |
88 #else |
99 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) { |
89 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiContext *ctx) { |
100 return ui_window_close_request(obj); |
90 uic_context_prepare_close(ctx); |
|
91 return FALSE; |
|
92 } |
101 } |
93 #endif |
102 #endif |
94 |
103 |
95 static UiObject* create_window(const char *title, void *window_data, UiBool simple) { |
104 static UiObject* create_window(const char *title, void *window_data, UiBool simple) { |
96 CxMempool *mp = cxBasicMempoolCreate(256); |
105 CxMempool *mp = cxBasicMempoolCreate(256); |
97 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
106 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
|
107 obj->ref = 0; |
98 |
108 |
99 #ifdef UI_LIBADWAITA |
109 #ifdef UI_LIBADWAITA |
100 obj->widget = adw_application_window_new(ui_get_application()); |
110 obj->widget = adw_application_window_new(ui_get_application()); |
101 #elif !defined(UI_GTK2) |
111 #elif !defined(UI_GTK2) |
102 obj->widget = gtk_application_window_new(ui_get_application()); |
112 obj->widget = gtk_application_window_new(ui_get_application()); |
128 GTK_WINDOW(obj->widget), |
138 GTK_WINDOW(obj->widget), |
129 window_default_width, |
139 window_default_width, |
130 window_default_height); |
140 window_default_height); |
131 } |
141 } |
132 |
142 |
|
143 obj->destroy = ui_window_widget_destroy; |
133 g_signal_connect( |
144 g_signal_connect( |
134 obj->widget, |
145 obj->widget, |
135 "destroy", |
146 "destroy", |
136 G_CALLBACK(ui_exit_event), |
147 G_CALLBACK(ui_exit_event), |
137 obj); |
148 obj); |
138 #if GTK_MAJOR_VERSION >= 4 |
149 #if GTK_MAJOR_VERSION >= 4 |
139 g_signal_connect( |
150 g_signal_connect( |
140 obj->widget, |
151 obj->widget, |
141 "close-request", |
152 "close-request", |
142 G_CALLBACK(close_request), |
153 G_CALLBACK(close_request), |
143 obj->ctx); |
154 obj); |
144 #else |
155 #else |
145 g_signal_connect( |
156 g_signal_connect( |
146 obj->widget, |
157 obj->widget, |
147 "delete-event", |
158 "delete-event", |
148 G_CALLBACK(close_request), |
159 G_CALLBACK(close_request), |
149 obj->ctx); |
160 obj); |
150 #endif |
161 #endif |
151 |
162 |
152 GtkWidget *vbox = ui_gtk_vbox_new(0); |
163 GtkWidget *vbox = ui_gtk_vbox_new(0); |
153 #ifdef UI_LIBADWAITA |
164 #ifdef UI_LIBADWAITA |
154 GtkWidget *toolbar_view = adw_toolbar_view_new(); |
165 GtkWidget *toolbar_view = adw_toolbar_view_new(); |
681 |
692 |
682 CxMempool *mp = cxBasicMempoolCreate(256); |
693 CxMempool *mp = cxBasicMempoolCreate(256); |
683 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
694 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
684 obj->ctx = uic_context(obj, mp); |
695 obj->ctx = uic_context(obj, mp); |
685 obj->widget = dialog; |
696 obj->widget = dialog; |
|
697 obj->ref = 0; |
|
698 obj->destroy = ui_window_widget_destroy; |
686 nwindows++; |
699 nwindows++; |
687 |
700 |
688 if(args.title != NULL) { |
701 if(args.title != NULL) { |
689 gtk_window_set_title(GTK_WINDOW(dialog), args.title); |
702 gtk_window_set_title(GTK_WINDOW(dialog), args.title); |
690 } |
703 } |
708 g_signal_connect( |
721 g_signal_connect( |
709 dialog, |
722 dialog, |
710 "destroy", |
723 "destroy", |
711 G_CALLBACK(ui_exit_event), |
724 G_CALLBACK(ui_exit_event), |
712 obj); |
725 obj); |
|
726 #if GTK_MAJOR_VERSION >= 4 |
|
727 g_signal_connect( |
|
728 obj->widget, |
|
729 "close-request", |
|
730 G_CALLBACK(close_request), |
|
731 obj); |
|
732 #else |
|
733 g_signal_connect( |
|
734 obj->widget, |
|
735 "delete-event", |
|
736 G_CALLBACK(close_request), |
|
737 obj); |
|
738 #endif |
713 |
739 |
714 #if GTK_MAJOR_VERSION < 4 |
740 #if GTK_MAJOR_VERSION < 4 |
715 GtkWidget *c = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); |
741 GtkWidget *c = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); |
716 gtk_container_remove(GTK_CONTAINER(dialog), c); |
742 gtk_container_remove(GTK_CONTAINER(dialog), c); |
717 #endif |
743 #endif |