ui/gtk/container.c

changeset 110
c00e968d018b
parent 108
77254bd6dccb
child 112
c3f2f16fa4b8
equal deleted inserted replaced
109:c3dfcb8f0be7 110:c00e968d018b
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 <string.h>
31 #include <limits.h> 32 #include <limits.h>
32 33
33 #include "container.h" 34 #include "container.h"
34 #include "toolkit.h" 35 #include "toolkit.h"
35 #include "headerbar.h" 36 #include "headerbar.h"
36 37
37 #include "../common/context.h" 38 #include "../common/context.h"
38 #include "../common/object.h" 39 #include "../common/object.h"
40
41 #include "../ui/properties.h"
39 42
40 43
41 void ui_container_begin_close(UiObject *obj) { 44 void ui_container_begin_close(UiObject *obj) {
42 UiContainer *ct = uic_get_current_container(obj); 45 UiContainer *ct = uic_get_current_container(obj);
43 ct->close = 1; 46 ct->close = 1;
191 int hfill = FALSE; 194 int hfill = FALSE;
192 int vfill = FALSE; 195 int vfill = FALSE;
193 if(!ct->layout.override_defaults) { 196 if(!ct->layout.override_defaults) {
194 if(grid->def_hexpand) { 197 if(grid->def_hexpand) {
195 hexpand = TRUE; 198 hexpand = TRUE;
196 hfill = TRUE; 199 }
197 } else if(grid->def_hfill) { 200 if(grid->def_hfill) {
198 hfill = TRUE; 201 hfill = TRUE;
199 } 202 }
200 if(grid->def_vexpand) { 203 if(grid->def_vexpand) {
201 vexpand = TRUE; 204 vexpand = TRUE;
202 vfill = TRUE; 205 }
203 } else if(grid->def_vfill) { 206 if(grid->def_vfill) {
204 vfill = TRUE; 207 vfill = TRUE;
205 } 208 }
206 } 209 }
207 210
208 UiBool fill = ct->layout.fill; 211 UiBool fill = ct->layout.fill;
209 if(ct->layout.hexpand) { 212 if(ct->layout.hexpand) {
210 hexpand = TRUE; 213 hexpand = TRUE;
211 hfill = TRUE; 214 }
212 } else if(ct->layout.hfill) { 215 if(ct->layout.hfill) {
213 hfill = TRUE; 216 hfill = TRUE;
214 } 217 }
215 if(ct->layout.vexpand) { 218 if(ct->layout.vexpand) {
216 vexpand = TRUE; 219 vexpand = TRUE;
217 vfill = TRUE; 220 }
218 } else if(ct->layout.vfill) { 221 if(ct->layout.vfill) {
219 vfill = TRUE; 222 vfill = TRUE;
220 } 223 }
221 if(fill) { 224 if(fill) {
222 hfill = TRUE; 225 hfill = TRUE;
223 vfill = TRUE; 226 vfill = TRUE;
227 hexpand = TRUE;
228 vexpand = TRUE;
224 } 229 }
225 230
226 if(!hfill) { 231 if(!hfill) {
227 gtk_widget_set_halign(widget, GTK_ALIGN_START); 232 gtk_widget_set_halign(widget, GTK_ALIGN_START);
228 } 233 }
1046 1051
1047 return box; 1052 return box;
1048 } 1053 }
1049 #endif 1054 #endif
1050 1055
1056 /* ------------------------ Split Window Panels ------------------------ */
1057
1058 static UIWIDGET splitwindow_panel(UiObject *obj, GtkWidget *pbox, UiSidebarArgs *args) {
1059 if(!pbox) {
1060 fprintf(stderr, "Error: window is not a splitview window\n");
1061 return NULL;
1062 }
1063
1064 GtkWidget *box = ui_gtk_vbox_new(args->spacing);
1065 ui_set_name_and_style(box, args->name, args->style_class);
1066 ui_box_set_margin(box, args->margin);
1067 BOX_ADD_EXPAND(pbox, box);
1068
1069 UiObject *newobj = uic_object_new(obj, box);
1070 newobj->container = ui_box_container(obj, box, UI_CONTAINER_VBOX);
1071 uic_obj_add(obj, newobj);
1072
1073 return box;
1074 }
1075
1076 UIWIDGET ui_left_panel_create(UiObject *obj, UiSidebarArgs *args) {
1077 return splitwindow_panel(obj, g_object_get_data(G_OBJECT(obj->widget), "ui_left_panel"), args);
1078 }
1079
1080 UIWIDGET ui_right_panel_create(UiObject *obj, UiSidebarArgs *args) {
1081 return splitwindow_panel(obj, g_object_get_data(G_OBJECT(obj->widget), "ui_right_panel"), args);
1082 }
1083
1084
1051 /* -------------------- Splitpane -------------------- */ 1085 /* -------------------- Splitpane -------------------- */
1052 1086
1053 static GtkWidget* create_paned(UiOrientation orientation) { 1087 static GtkWidget* create_paned(UiOrientation orientation) {
1054 #if GTK_MAJOR_VERSION >= 3 1088 #if GTK_MAJOR_VERSION >= 3
1055 switch(orientation) { 1089 switch(orientation) {
1063 } 1097 }
1064 #endif 1098 #endif
1065 return NULL; 1099 return NULL;
1066 } 1100 }
1067 1101
1068 1102 static void save_pane_pos(GtkWidget *widget, char *property_name) {
1103 int pos = gtk_paned_get_position(GTK_PANED(widget));
1104 char buf[32];
1105 snprintf(buf, 32, "%d", pos);
1106 ui_set_property(property_name, buf);
1107 free(property_name);
1108 }
1069 1109
1070 static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs *args) { 1110 static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs *args) {
1071 UiObject* current = uic_current_obj(obj); 1111 UiObject* current = uic_current_obj(obj);
1072 1112
1073 GtkWidget *pane0 = create_paned(orientation); 1113 GtkWidget *pane0 = create_paned(orientation);
1074 1114
1075 UI_APPLY_LAYOUT2(current, args); 1115 UI_APPLY_LAYOUT2(current, args);
1076 current->container->add(current->container, pane0); 1116 current->container->add(current->container, pane0);
1077 1117
1078 int max = args->max_panes == 0 ? 2 : args->max_panes; 1118 int max = args->max_panes == 0 ? 2 : args->max_panes;
1119
1120 if(args->position_property) {
1121 const char *pos_str = ui_get_property(args->position_property);
1122 if(pos_str) {
1123 char *end;
1124 long pos = strtol(pos_str, &end, 10);
1125 if(*end == '\0') {
1126 args->initial_position = (int)pos;
1127 }
1128 }
1129
1130 g_signal_connect(
1131 pane0,
1132 "destroy",
1133 G_CALLBACK(save_pane_pos),
1134 strdup(args->position_property));
1135 }
1079 1136
1080 UiObject *newobj = uic_object_new(obj, pane0); 1137 UiObject *newobj = uic_object_new(obj, pane0);
1081 newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args->initial_position); 1138 newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args->initial_position);
1082 uic_obj_add(obj, newobj); 1139 uic_obj_add(obj, newobj);
1083 1140
1084 g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container); 1141 g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container);
1142
1143 UiVar *var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
1144 if(var) {
1145 UiSplitPaneContainer *s = (UiSplitPaneContainer*)newobj->container;
1146 UiInteger *i = var->value;
1147 s->initial_position = i->value;
1148
1149 i->obj = s;
1150 i->get = ui_splitpane_get;
1151 i->set = ui_splitpane_set;
1152 }
1085 1153
1086 return pane0; 1154 return pane0;
1087 } 1155 }
1088 1156
1089 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) { 1157 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) {
1134 } 1202 }
1135 1203
1136 s->pos = 0; 1204 s->pos = 0;
1137 s->nchildren++; 1205 s->nchildren++;
1138 } 1206 }
1207 }
1208
1209 int64_t ui_splitpane_get(UiInteger *i) {
1210 UiSplitPaneContainer *s = i->obj;
1211 i->value = gtk_paned_get_position(GTK_PANED(s->container.widget));
1212 return i->value;
1213 }
1214
1215 void ui_splitpane_set(UiInteger *i, int64_t value) {
1216 UiSplitPaneContainer *s = i->obj;
1217 i->value = value;
1218 gtk_paned_set_position(GTK_PANED(s->container.widget), (int)value);
1139 } 1219 }
1140 1220
1141 UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) { 1221 UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) {
1142 UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane"); 1222 UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane");
1143 if(!ct) { 1223 if(!ct) {

mercurial