ui/gtk/container.c

branch
newapi
changeset 336
56c12f44c2d3
parent 333
634e3ce80afe
child 344
870dd3d41d83
equal deleted inserted replaced
335:91d4f0391282 336:56c12f44c2d3
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <limits.h> 31 #include <limits.h>
32 32
33 #include "container.h" 33 #include "container.h"
34 #include "toolkit.h" 34 #include "toolkit.h"
35 #include "headerbar.h"
35 36
36 #include "../common/context.h" 37 #include "../common/context.h"
37 #include "../common/object.h" 38 #include "../common/object.h"
38 39
39 40
631 data->add_tab(data->widget, tab_index, name, widget); 632 data->add_tab(data->widget, tab_index, name, widget);
632 633
633 return newobj; 634 return newobj;
634 } 635 }
635 636
637
638 /* -------------------- Headerbar -------------------- */
639
640 static void hb_set_part(UiObject *obj, int part) {
641 UiObject* current = uic_current_obj(obj);
642 GtkWidget *headerbar = current->widget;
643
644 UiHeaderbarContainer *hb = cxCalloc(
645 obj->ctx->allocator,
646 1,
647 sizeof(UiHeaderbarContainer));
648 memcpy(hb, current->container, sizeof(UiHeaderbarContainer));
649
650 UiObject *newobj = uic_object_new(obj, headerbar);
651 newobj->container = (UiContainer*)hb;
652 uic_obj_add(obj, newobj);
653
654 hb->part = part;
655 }
656
657 void ui_headerbar_start_create(UiObject *obj) {
658 hb_set_part(obj, 0);
659 }
660
661 void ui_headerbar_center_create(UiObject *obj) {
662 hb_set_part(obj, 2);
663 }
664
665 void ui_headerbar_end_create(UiObject *obj) {
666 hb_set_part(obj, 1);
667 }
668
669 UIWIDGET ui_headerbar_fallback_create(UiObject *obj, UiHeaderbarArgs args) {
670 UiObject *current = uic_current_obj(obj);
671 UiContainer *ct = current->container;
672 UI_APPLY_LAYOUT1(current, args);
673
674 GtkWidget *box = ui_gtk_hbox_new(args.alt_spacing);
675 ui_set_name_and_style(box, args.name, args.style_class);
676 ct->add(ct, box, FALSE);
677
678 UiObject *newobj = uic_object_new(obj, box);
679 newobj->container = ui_headerbar_fallback_container(obj, box);
680 uic_obj_add(obj, newobj);
681
682 return box;
683 }
684
685 static void hb_fallback_set_part(UiObject *obj, int part) {
686 UiObject* current = uic_current_obj(obj);
687 GtkWidget *headerbar = current->widget;
688
689 UiObject *newobj = uic_object_new(obj, headerbar);
690 newobj->container = ui_headerbar_container(obj, headerbar);
691 uic_obj_add(obj, newobj);
692
693 UiHeaderbarContainer *hb = (UiHeaderbarContainer*)newobj->container;
694 hb->part = part;
695 }
696
697 UiContainer* ui_headerbar_fallback_container(UiObject *obj, GtkWidget *headerbar) {
698 UiHeaderbarContainer *ct = cxCalloc(
699 obj->ctx->allocator,
700 1,
701 sizeof(UiHeaderbarContainer));
702 ct->container.widget = headerbar;
703 ct->container.add = ui_headerbar_fallback_container_add;
704 return (UiContainer*)ct;
705 }
706
707 void ui_headerbar_fallback_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
708 UiHeaderbarContainer *hb = (UiHeaderbarContainer*)ct;
709 BOX_ADD(ct->widget, widget);
710 }
711
712 #if GTK_CHECK_VERSION(3, 10, 0)
713
714 UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs args) {
715 GtkWidget *headerbar = g_object_get_data(G_OBJECT(obj->widget), "ui_headerbar");
716 if(!headerbar) {
717 return ui_headerbar_fallback_create(obj, args);
718 }
719
720 UiObject *newobj = uic_object_new(obj, headerbar);
721 newobj->container = ui_headerbar_container(obj, headerbar);
722 uic_obj_add(obj, newobj);
723
724 return headerbar;
725 }
726
727 UiContainer* ui_headerbar_container(UiObject *obj, GtkWidget *headerbar) {
728 UiHeaderbarContainer *ct = cxCalloc(
729 obj->ctx->allocator,
730 1,
731 sizeof(UiHeaderbarContainer));
732 ct->container.widget = headerbar;
733 ct->container.add = ui_headerbar_container_add;
734 return (UiContainer*)ct;
735 }
736
737 void ui_headerbar_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
738 UiHeaderbarContainer *hb = (UiHeaderbarContainer*)ct;
739 if(hb->part == 0) {
740 UI_HEADERBAR_PACK_START(ct->widget, widget);
741 } else if(hb->part == 1) {
742 UI_HEADERBAR_PACK_END(ct->widget, widget);
743 } else if(hb->part == 2) {
744 if(!hb->centerbox) {
745 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
746 hb->centerbox = box;
747 UI_HEADERBAR_SET_TITLE_WIDGET(ct->widget, box);
748 }
749 BOX_ADD(hb->centerbox, widget);
750 }
751 }
752
753 #else
754
755 UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs args) {
756 return ui_headerbar_fallback_create(obj, args);
757 }
758
759 #endif
760
636 /* -------------------- Splitpane -------------------- */ 761 /* -------------------- Splitpane -------------------- */
637 762
638 static GtkWidget* create_paned(UiOrientation orientation) { 763 static GtkWidget* create_paned(UiOrientation orientation) {
639 #if GTK_MAJOR_VERSION >= 3 764 #if GTK_MAJOR_VERSION >= 3
640 switch(orientation) { 765 switch(orientation) {

mercurial