ui/gtk/container.c

changeset 165
3f32db79a76e
parent 163
b70e2a77dea0
child 166
6e48030cf2db
equal deleted inserted replaced
164:1d912f78fd1d 165:3f32db79a76e
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <limits.h>
31 32
32 #include "container.h" 33 #include "container.h"
34 #include "toolkit.h"
35
33 #include "../common/context.h" 36 #include "../common/context.h"
34 #include "../common/object.h" 37 #include "../common/object.h"
35 38
36 GtkWidget* ui_gtk_vbox_new(int spacing) { 39 GtkWidget* ui_gtk_vbox_new(int spacing) {
37 #ifdef UI_GTK3 40 #ifdef UI_GTK3
364 367
365 void ui_select_tab(UIWIDGET tabview, int tab) { 368 void ui_select_tab(UIWIDGET tabview, int tab) {
366 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); 369 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
367 } 370 }
368 371
369 372 /* -------------------- Splitpane -------------------- */
370 /* -------------------- Sidebar -------------------- */ 373
374 static GtkWidget* create_paned(UiOrientation orientation) {
375 #ifdef UI_GTK3
376 switch(orientation) {
377 case UI_HORIZONTAL: return gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
378 case UI_VERTICAL: return gtk_paned_new(GTK_ORIENTATION_VERTICAL);
379 }
380 #else
381 switch(orientation) {
382 case UI_HORIZONTAL: return gtk_hpaned_new();
383 case UI_VERTICAL: return gtk_vpaned_new();
384 }
385 #endif
386 return NULL;
387 }
388
389 UIWIDGET ui_splitpane(UiObject *obj, int max, UiOrientation orientation) {
390 GtkWidget *paned = create_paned(orientation);
391 UiContainer *ct = uic_get_current_container(obj);
392 ct->add(ct, paned, TRUE);
393
394 if(max <= 0) max = INT_MAX;
395
396 UiPanedContainer *pctn = ucx_mempool_calloc(
397 obj->ctx->mempool,
398 1,
399 sizeof(UiPanedContainer));
400 pctn->container.widget = paned;
401 pctn->container.add = ui_paned_container_add;
402 pctn->current_pane = paned;
403 pctn->orientation = orientation;
404 pctn->max = max;
405 pctn->cur = 0;
406
407 UiObject *pobj = uic_object_new(obj, paned);
408 pobj->container = (UiContainer*)pctn;
409
410 uic_obj_add(obj, pobj);
411
412 return paned;
413 }
414
415 UIWIDGET ui_hsplitpane(UiObject *obj, int max) {
416 return ui_splitpane(obj, max, UI_HORIZONTAL);
417 }
418
419 UIWIDGET ui_vsplitpane(UiObject *obj, int max) {
420 return ui_splitpane(obj, max, UI_VERTICAL);
421 }
422
423 void ui_paned_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
424 UiPanedContainer *pctn = (UiPanedContainer*)ct;
425
426 gboolean resize = (ct->layout.hexpand || ct->layout.vexpand) ? TRUE : FALSE;
427 int width = ct->layout.width;
428 ui_reset_layout(ct->layout);
429
430 if(pctn->cur == 0) {
431 gtk_paned_pack1(GTK_PANED(pctn->current_pane), widget, resize, resize);
432 } else if(pctn->cur < pctn->max-1) {
433 GtkWidget *nextPane = create_paned(pctn->orientation);
434 gtk_paned_pack2(GTK_PANED(pctn->current_pane), nextPane, TRUE, TRUE);
435 gtk_paned_pack1(GTK_PANED(nextPane), widget, resize, resize);
436 pctn->current_pane = nextPane;
437 } else if(pctn->cur == pctn->max-1) {
438 gtk_paned_pack2(GTK_PANED(pctn->current_pane), widget, resize, resize);
439 width = 0; // disable potential call of gtk_paned_set_position
440 } else {
441 fprintf(stderr, "Splitpane max reached: %d\n", pctn->max);
442 return;
443 }
444
445 if(width > 0) {
446 gtk_paned_set_position(GTK_PANED(pctn->current_pane), width);
447 }
448
449 pctn->cur++;
450 }
451
452
453 /* -------------------- Sidebar (deprecated) -------------------- */
371 UIWIDGET ui_sidebar(UiObject *obj) { 454 UIWIDGET ui_sidebar(UiObject *obj) {
372 #ifdef UI_GTK3 455 #ifdef UI_GTK3
373 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); 456 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
374 #else 457 #else
375 GtkWidget *paned = gtk_hpaned_new(); 458 GtkWidget *paned = gtk_hpaned_new();
510 void ui_layout_vexpand(UiObject *obj, UiBool expand) { 593 void ui_layout_vexpand(UiObject *obj, UiBool expand) {
511 UiContainer *ct = uic_get_current_container(obj); 594 UiContainer *ct = uic_get_current_container(obj);
512 ct->layout.vexpand = expand; 595 ct->layout.vexpand = expand;
513 } 596 }
514 597
598 void ui_layout_width(UiObject *obj, int width) {
599 UiContainer *ct = uic_get_current_container(obj);
600 ct->layout.width = width;
601 }
602
515 void ui_layout_gridwidth(UiObject *obj, int width) { 603 void ui_layout_gridwidth(UiObject *obj, int width) {
516 UiContainer *ct = uic_get_current_container(obj); 604 UiContainer *ct = uic_get_current_container(obj);
517 ct->layout.gridwidth = width; 605 ct->layout.gridwidth = width;
518 } 606 }
519 607

mercurial