ui/gtk/container.c

changeset 786
150a1180f7ec
parent 783
25b2da0aac15
child 794
ebd7b3394501
equal deleted inserted replaced
785:b943e3d618f0 786:150a1180f7ec
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;
1048 1051
1049 return box; 1052 return box;
1050 } 1053 }
1051 #endif 1054 #endif
1052 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_box_set_margin(box, args->margin);
1066 BOX_ADD_EXPAND(pbox, box);
1067
1068 UiObject *newobj = uic_object_new(obj, box);
1069 newobj->container = ui_box_container(obj, box, UI_CONTAINER_VBOX);
1070 uic_obj_add(obj, newobj);
1071
1072 return box;
1073 }
1074
1075 UIWIDGET ui_left_panel_create(UiObject *obj, UiSidebarArgs *args) {
1076 return splitwindow_panel(obj, g_object_get_data(G_OBJECT(obj->widget), "ui_left_panel"), args);
1077 }
1078
1079 UIWIDGET ui_right_panel_create(UiObject *obj, UiSidebarArgs *args) {
1080 return splitwindow_panel(obj, g_object_get_data(G_OBJECT(obj->widget), "ui_right_panel"), args);
1081 }
1082
1083
1053 /* -------------------- Splitpane -------------------- */ 1084 /* -------------------- Splitpane -------------------- */
1054 1085
1055 static GtkWidget* create_paned(UiOrientation orientation) { 1086 static GtkWidget* create_paned(UiOrientation orientation) {
1056 #if GTK_MAJOR_VERSION >= 3 1087 #if GTK_MAJOR_VERSION >= 3
1057 switch(orientation) { 1088 switch(orientation) {
1065 } 1096 }
1066 #endif 1097 #endif
1067 return NULL; 1098 return NULL;
1068 } 1099 }
1069 1100
1070 1101 static void save_pane_pos(GtkWidget *widget, char *property_name) {
1102 int pos = gtk_paned_get_position(GTK_PANED(widget));
1103 char buf[32];
1104 snprintf(buf, 32, "%d", pos);
1105 ui_set_property(property_name, buf);
1106 free(property_name);
1107 }
1071 1108
1072 static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs *args) { 1109 static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs *args) {
1073 UiObject* current = uic_current_obj(obj); 1110 UiObject* current = uic_current_obj(obj);
1074 1111
1075 GtkWidget *pane0 = create_paned(orientation); 1112 GtkWidget *pane0 = create_paned(orientation);
1076 1113
1077 UI_APPLY_LAYOUT2(current, args); 1114 UI_APPLY_LAYOUT2(current, args);
1078 current->container->add(current->container, pane0); 1115 current->container->add(current->container, pane0);
1079 1116
1080 int max = args->max_panes == 0 ? 2 : args->max_panes; 1117 int max = args->max_panes == 0 ? 2 : args->max_panes;
1118
1119 if(args->position_property) {
1120 const char *pos_str = ui_get_property(args->position_property);
1121 if(pos_str) {
1122 char *end;
1123 long pos = strtol(pos_str, &end, 10);
1124 if(*end == '\0') {
1125 args->initial_position = (int)pos;
1126 }
1127 }
1128
1129 g_signal_connect(
1130 pane0,
1131 "destroy",
1132 G_CALLBACK(save_pane_pos),
1133 strdup(args->position_property));
1134 }
1081 1135
1082 UiObject *newobj = uic_object_new(obj, pane0); 1136 UiObject *newobj = uic_object_new(obj, pane0);
1083 newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args->initial_position); 1137 newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args->initial_position);
1084 uic_obj_add(obj, newobj); 1138 uic_obj_add(obj, newobj);
1085 1139
1086 g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container); 1140 g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container);
1141
1142 UiVar *var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
1143 if(var) {
1144 UiSplitPaneContainer *s = (UiSplitPaneContainer*)newobj->container;
1145 UiInteger *i = var->value;
1146 s->initial_position = i->value;
1147
1148 i->obj = s;
1149 i->get = ui_splitpane_get;
1150 i->set = ui_splitpane_set;
1151 }
1087 1152
1088 return pane0; 1153 return pane0;
1089 } 1154 }
1090 1155
1091 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) { 1156 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs *args) {
1136 } 1201 }
1137 1202
1138 s->pos = 0; 1203 s->pos = 0;
1139 s->nchildren++; 1204 s->nchildren++;
1140 } 1205 }
1206 }
1207
1208 int64_t ui_splitpane_get(UiInteger *i) {
1209 UiSplitPaneContainer *s = i->obj;
1210 i->value = gtk_paned_get_position(GTK_PANED(s->container.widget));
1211 return i->value;
1212 }
1213
1214 void ui_splitpane_set(UiInteger *i, int64_t value) {
1215 UiSplitPaneContainer *s = i->obj;
1216 i->value = value;
1217 gtk_paned_set_position(GTK_PANED(s->container.widget), (int)value);
1141 } 1218 }
1142 1219
1143 UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) { 1220 UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) {
1144 UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane"); 1221 UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane");
1145 if(!ct) { 1222 if(!ct) {

mercurial