31 |
31 |
32 #include "container.h" |
32 #include "container.h" |
33 #include "../common/context.h" |
33 #include "../common/context.h" |
34 #include "../common/object.h" |
34 #include "../common/object.h" |
35 |
35 |
36 |
36 static UiBool ui_lb2bool(UiLayoutBool b) { |
|
37 return b == UI_LAYOUT_TRUE ? TRUE : FALSE; |
|
38 } |
|
39 |
|
40 static UiLayoutBool ui_bool2lb(UiBool b) { |
|
41 return b ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE; |
|
42 } |
|
43 |
|
44 GtkWidget* ui_gtk_vbox_new() { |
|
45 #ifdef UI_GTK3 |
|
46 return gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
|
47 #else |
|
48 return gtk_vbox_new(FALSE, 0); |
|
49 #endif |
|
50 } |
|
51 |
|
52 GtkWidget* ui_gtk_hbox_new() { |
|
53 #ifdef UI_GTK3 |
|
54 return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
55 #else |
|
56 return gtk_hbox_new(FALSE, 0); |
|
57 #endif |
|
58 } |
|
59 |
|
60 /* -------------------- Frame Container (deprecated) -------------------- */ |
37 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { |
61 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { |
38 UiContainer *ct = ucx_mempool_malloc( |
62 UiContainer *ct = ucx_mempool_calloc( |
39 obj->ctx->mempool, |
63 obj->ctx->mempool, |
|
64 1, |
40 sizeof(UiContainer)); |
65 sizeof(UiContainer)); |
41 ct->widget = frame; |
66 ct->widget = frame; |
42 ct->add = ui_frame_container_add; |
67 ct->add = ui_frame_container_add; |
43 return ct; |
68 return ct; |
44 } |
69 } |
45 |
70 |
46 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget) { |
71 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
47 gtk_container_add(GTK_CONTAINER(ct->widget), widget); |
72 gtk_container_add(GTK_CONTAINER(ct->widget), widget); |
48 } |
73 ui_reset_layout(ct->layout); |
49 |
74 } |
50 |
75 |
|
76 |
|
77 /* -------------------- Box Container -------------------- */ |
|
78 UiContainer* ui_box_container(UiObject *obj, GtkWidget *box) { |
|
79 UiBoxContainer *ct = ucx_mempool_calloc( |
|
80 obj->ctx->mempool, |
|
81 1, |
|
82 sizeof(UiBoxContainer)); |
|
83 ct->container.widget = box; |
|
84 ct->container.add = ui_box_container_add; |
|
85 return (UiContainer*)ct; |
|
86 } |
|
87 |
|
88 void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
89 UiBoxContainer *bc = (UiBoxContainer*)ct; |
|
90 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { |
|
91 fill = ui_lb2bool(ct->layout.fill); |
|
92 } |
|
93 |
|
94 if(bc->has_fill && fill) { |
|
95 fprintf(stderr, "UiError: container has 2 filled widgets"); |
|
96 fill = FALSE; |
|
97 } |
|
98 if(fill) { |
|
99 bc->has_fill = TRUE; |
|
100 } |
|
101 |
|
102 UiBool expand = fill; |
|
103 gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0); |
|
104 |
|
105 ui_reset_layout(ct->layout); |
|
106 } |
|
107 |
|
108 |
|
109 /* -------------------- Sidebar -------------------- */ |
51 UIWIDGET ui_sidebar(UiObject *obj) { |
110 UIWIDGET ui_sidebar(UiObject *obj) { |
52 #ifdef UI_GTK3 |
111 #ifdef UI_GTK3 |
53 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); |
112 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); |
54 #else |
113 #else |
55 GtkWidget *paned = gtk_hpaned_new(); |
114 GtkWidget *paned = gtk_hpaned_new(); |
56 #endif |
115 #endif |
57 gtk_paned_set_position(GTK_PANED(paned), 200); |
116 gtk_paned_set_position(GTK_PANED(paned), 200); |
58 |
117 |
59 GtkWidget *sidebar; |
118 GtkWidget *sidebar = ui_gtk_vbox_new(); |
60 #ifdef UI_GTK3 |
|
61 sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
|
62 #else |
|
63 sidebar = gtk_vbox_new(FALSE, 0); |
|
64 #endif |
|
65 gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE); |
119 gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE); |
66 |
120 |
67 UiObject *left = uic_object_new(obj, sidebar); |
121 UiObject *left = uic_object_new(obj, sidebar); |
68 UiContainer *ct1 = ucx_mempool_malloc( |
122 UiContainer *ct1 = ui_box_container(obj, sidebar); |
69 obj->ctx->mempool, |
|
70 sizeof(UiContainer)); |
|
71 ct1->widget = sidebar; |
|
72 ct1->add = ui_box_add; |
|
73 left->container = ct1; |
123 left->container = ct1; |
74 |
124 |
75 UiObject *right = uic_object_new(obj, sidebar); |
125 UiObject *right = uic_object_new(obj, sidebar); |
76 UiContainer *ct2 = ucx_mempool_malloc( |
126 UiContainer *ct2 = ucx_mempool_malloc( |
77 obj->ctx->mempool, |
127 obj->ctx->mempool, |
79 ct2->widget = paned; |
129 ct2->widget = paned; |
80 ct2->add = ui_split_container_add2; |
130 ct2->add = ui_split_container_add2; |
81 right->container = ct2; |
131 right->container = ct2; |
82 |
132 |
83 UiContainer *ct = uic_get_current_container(obj); |
133 UiContainer *ct = uic_get_current_container(obj); |
84 ct->add(ct, paned); |
134 ct->add(ct, paned, TRUE); |
85 |
135 |
86 uic_obj_add(obj, right); |
136 uic_obj_add(obj, right); |
87 uic_obj_add(obj, left); |
137 uic_obj_add(obj, left); |
88 |
138 |
89 return sidebar; |
139 return sidebar; |
90 } |
140 } |
91 |
141 |
92 void ui_split_container_add1(UiContainer *ct, GtkWidget *widget) { |
142 void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
|
143 // TODO: remove |
93 gtk_paned_pack1(GTK_PANED(ct->widget), widget, TRUE, FALSE); |
144 gtk_paned_pack1(GTK_PANED(ct->widget), widget, TRUE, FALSE); |
94 } |
145 } |
95 |
146 |
96 void ui_split_container_add2(UiContainer *ct, GtkWidget *widget) { |
147 void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
97 gtk_paned_pack2(GTK_PANED(ct->widget), widget, TRUE, FALSE); |
148 gtk_paned_pack2(GTK_PANED(ct->widget), widget, TRUE, FALSE); |
98 } |
149 } |
99 |
150 |
100 |
151 |
101 void ui_box_add(UiContainer *ct, GtkWidget *widget) { |
152 /* -------------------- Document Tabview -------------------- */ |
102 gtk_box_pack_start(GTK_BOX(ct->widget), widget, TRUE, TRUE, 0); |
|
103 } |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 static void page_change(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) { |
153 static void page_change(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) { |
109 GQuark q = g_quark_from_static_string("ui.tab.object"); |
154 GQuark q = g_quark_from_static_string("ui.tab.object"); |
110 UiObject *tab = g_object_get_qdata(G_OBJECT(page), q); |
155 UiObject *tab = g_object_get_qdata(G_OBJECT(page), q); |
111 if(!tab) { |
156 if(!tab) { |
112 return; |
157 return; |