ui/gtk/window.c

changeset 100
d2bd73d28ff1
parent 98
16e84fac48bd
equal deleted inserted replaced
99:b9767cb5b06b 100:d2bd73d28ff1
99 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) { 99 static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) {
100 return ui_window_close_request(obj); 100 return ui_window_close_request(obj);
101 } 101 }
102 #endif 102 #endif
103 103
104 static UiObject* create_window(const char *title, void *window_data, UiBool simple) { 104 static UiObject* create_window(const char *title, void *window_data, UiBool sidebar, UiBool simple) {
105 CxMempool *mp = cxBasicMempoolCreate(256); 105 CxMempool *mp = cxBasicMempoolCreate(256);
106 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); 106 UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
107 obj->ref = 0; 107 obj->ref = 0;
108 108
109 #ifdef UI_LIBADWAITA 109 #ifdef UI_LIBADWAITA
134 atoi(width), 134 atoi(width),
135 atoi(height)); 135 atoi(height));
136 } else { 136 } else {
137 gtk_window_set_default_size( 137 gtk_window_set_default_size(
138 GTK_WINDOW(obj->widget), 138 GTK_WINDOW(obj->widget),
139 window_default_width, 139 window_default_width + sidebar*250,
140 window_default_height); 140 window_default_height);
141 } 141 }
142 142
143 obj->destroy = ui_window_widget_destroy; 143 obj->destroy = ui_window_widget_destroy;
144 g_signal_connect( 144 g_signal_connect(
161 #endif 161 #endif
162 162
163 GtkWidget *vbox = ui_gtk_vbox_new(0); 163 GtkWidget *vbox = ui_gtk_vbox_new(0);
164 #ifdef UI_LIBADWAITA 164 #ifdef UI_LIBADWAITA
165 GtkWidget *toolbar_view = adw_toolbar_view_new(); 165 GtkWidget *toolbar_view = adw_toolbar_view_new();
166 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view);
167 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox); 166 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox);
167
168 GtkWidget *content_box = ui_gtk_vbox_new(0);
169 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
170
171 if(sidebar) {
172 GtkWidget *splitview = adw_overlay_split_view_new();
173 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), splitview);
174
175 GtkWidget *sidebar_toolbar_view = adw_toolbar_view_new();
176 adw_overlay_split_view_set_sidebar(ADW_OVERLAY_SPLIT_VIEW(splitview), sidebar_toolbar_view);
177 GtkWidget *sidebar_headerbar = adw_header_bar_new();
178 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), sidebar_headerbar);
179
180 adw_overlay_split_view_set_content(ADW_OVERLAY_SPLIT_VIEW(splitview), toolbar_view);
181
182 g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_toolbar_view);
183 } else {
184 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view);
185 }
186
168 187
169 GtkWidget *headerbar = adw_header_bar_new(); 188 GtkWidget *headerbar = adw_header_bar_new();
170 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar); 189 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar);
171 g_object_set_data(G_OBJECT(obj->widget), "ui_headerbar", headerbar); 190 g_object_set_data(G_OBJECT(obj->widget), "ui_headerbar", headerbar);
172 191
173 if(!simple) { 192 if(!simple) {
174 ui_fill_headerbar(obj, headerbar); 193 ui_fill_headerbar(obj, headerbar);
175 } 194 }
176 #elif GTK_MAJOR_VERSION >= 4 195 #elif GTK_MAJOR_VERSION >= 4
196 GtkWidget *content_box = ui_gtk_vbox_new(0);
177 WINDOW_SET_CONTENT(obj->widget, vbox); 197 WINDOW_SET_CONTENT(obj->widget, vbox);
178 #else 198 if(sidebar) {
179 gtk_container_add(GTK_CONTAINER(obj->widget), vbox); 199 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
180 200 GtkWidget *sidebar_vbox = ui_gtk_vbox_new(0);
201 gtk_paned_set_start_child(GTK_PANED(paned), sidebar_vbox);
202 gtk_paned_set_end_child(GTK_PANED(paned), content_box);
203 BOX_ADD_EXPAND(GTK_BOX(vbox), paned);
204 g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_vbox);
205 } else {
206 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
207 }
208 #else
181 if(!simple) { 209 if(!simple) {
182 // menu 210 // menu
183 if(uic_get_menu_list()) { 211 if(uic_get_menu_list()) {
184 GtkWidget *mb = ui_create_menubar(obj); 212 GtkWidget *mb = ui_create_menubar(obj);
185 if(mb) { 213 if(mb) {
196 } 224 }
197 225
198 //GtkWidget *hb = ui_create_headerbar(obj); 226 //GtkWidget *hb = ui_create_headerbar(obj);
199 //gtk_window_set_titlebar(GTK_WINDOW(obj->widget), hb); 227 //gtk_window_set_titlebar(GTK_WINDOW(obj->widget), hb);
200 } 228 }
229
230 GtkWidget *content_box = ui_gtk_vbox_new(0);
231 WINDOW_SET_CONTENT(obj->widget, vbox);
232 if(sidebar) {
233 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
234 GtkWidget *sidebar_vbox = ui_gtk_vbox_new(0);
235 gtk_paned_add1(GTK_PANED(paned), sidebar_vbox);
236 gtk_paned_add2(GTK_PANED(paned), content_box);
237 BOX_ADD_EXPAND(GTK_BOX(vbox), paned);
238 g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_vbox);
239 gtk_paned_set_position (GTK_PANED(paned), 200);
240 } else {
241 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
242 }
243
201 #endif 244 #endif
202 245
203 // window content 246 // window content
204 // the content has a (TODO: not yet) configurable frame 247 // the content has a (TODO: not yet) configurable frame
205 // TODO: really? why 248 // TODO: really? why
211 // content vbox 254 // content vbox
212 GtkWidget *content_box = ui_gtk_vbox_new(0); 255 GtkWidget *content_box = ui_gtk_vbox_new(0);
213 gtk_container_add(GTK_CONTAINER(frame), content_box); 256 gtk_container_add(GTK_CONTAINER(frame), content_box);
214 obj->container = ui_box_container(obj, content_box); 257 obj->container = ui_box_container(obj, content_box);
215 */ 258 */
216 GtkWidget *content_box = ui_gtk_vbox_new(0);
217 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
218 obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX); 259 obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX);
219 260
220 nwindows++; 261 nwindows++;
221 return obj; 262 return obj;
222 } 263 }
223 264
224 265
225 UiObject* ui_window(const char *title, void *window_data) { 266 UiObject* ui_window(const char *title, void *window_data) {
226 return create_window(title, window_data, FALSE); 267 return create_window(title, window_data, FALSE, FALSE);
268 }
269
270 UiObject *ui_sidebar_window(const char *title, void *window_data) {
271 return create_window(title, window_data, TRUE, FALSE);
227 } 272 }
228 273
229 UiObject* ui_simple_window(const char *title, void *window_data) { 274 UiObject* ui_simple_window(const char *title, void *window_data) {
230 return create_window(title, window_data, TRUE); 275 return create_window(title, window_data, FALSE, TRUE);
231 } 276 }
232 277
233 void ui_window_size(UiObject *obj, int width, int height) { 278 void ui_window_size(UiObject *obj, int width, int height) {
234 gtk_window_set_default_size( 279 gtk_window_set_default_size(
235 GTK_WINDOW(obj->widget), 280 GTK_WINDOW(obj->widget),

mercurial