| 50 return 0; |
50 return 0; |
| 51 } |
51 } |
| 52 return 1; |
52 return 1; |
| 53 } |
53 } |
| 54 |
54 |
| 55 UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) { |
|
| 56 UiObject* current = uic_current_obj(obj); |
|
| 57 |
|
| 58 UIWIDGET widget = create_widget(obj, args, userdata); |
|
| 59 |
|
| 60 UI_APPLY_LAYOUT1(current, args); |
|
| 61 current->container->add(current->container, widget, FALSE); |
|
| 62 |
|
| 63 return widget; |
|
| 64 } |
|
| 65 |
|
| 66 GtkWidget* ui_gtk_vbox_new(int spacing) { |
55 GtkWidget* ui_gtk_vbox_new(int spacing) { |
| 67 #if GTK_MAJOR_VERSION >= 3 |
56 #if GTK_MAJOR_VERSION >= 3 |
| 68 return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing); |
57 return gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing); |
| 69 #else |
58 #else |
| 70 return gtk_vbox_new(FALSE, spacing); |
59 return gtk_vbox_new(FALSE, spacing); |
| 1039 current->container->add(current->container, pane0, TRUE); |
1028 current->container->add(current->container, pane0, TRUE); |
| 1040 |
1029 |
| 1041 int max = args.max_panes == 0 ? 2 : args.max_panes; |
1030 int max = args.max_panes == 0 ? 2 : args.max_panes; |
| 1042 |
1031 |
| 1043 UiObject *newobj = uic_object_new(obj, pane0); |
1032 UiObject *newobj = uic_object_new(obj, pane0); |
| 1044 newobj->container = ui_splitpane_container(obj, pane0, orientation, max); |
1033 newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args.initial_position); |
| 1045 uic_obj_add(obj, newobj); |
1034 uic_obj_add(obj, newobj); |
| |
1035 |
| |
1036 g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container); |
| 1046 |
1037 |
| 1047 return pane0; |
1038 return pane0; |
| 1048 } |
1039 } |
| 1049 |
1040 |
| 1050 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { |
1041 UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { |
| 1053 |
1044 |
| 1054 UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { |
1045 UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { |
| 1055 return splitpane_create(obj, UI_VERTICAL, args); |
1046 return splitpane_create(obj, UI_VERTICAL, args); |
| 1056 } |
1047 } |
| 1057 |
1048 |
| 1058 UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientation orientation, int max) { |
1049 UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientation orientation, int max, int init) { |
| 1059 UiSplitPaneContainer *ct = ui_calloc(obj->ctx, 1, sizeof(UiSplitPaneContainer)); |
1050 UiSplitPaneContainer *ct = ui_calloc(obj->ctx, 1, sizeof(UiSplitPaneContainer)); |
| 1060 ct->container.widget = pane; |
1051 ct->container.widget = pane; |
| 1061 ct->container.add = ui_splitpane_container_add; |
1052 ct->container.add = ui_splitpane_container_add; |
| 1062 ct->current_pane = pane; |
1053 ct->current_pane = pane; |
| 1063 ct->orientation = orientation; |
1054 ct->orientation = orientation; |
| 1064 ct->max = max; |
1055 ct->max = max; |
| |
1056 ct->initial_position = init; |
| |
1057 ct->children = cxArrayListCreateSimple(CX_STORE_POINTERS, 4); |
| 1065 return (UiContainer*)ct; |
1058 return (UiContainer*)ct; |
| 1066 } |
1059 } |
| 1067 |
1060 |
| 1068 void ui_splitpane_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
1061 void ui_splitpane_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { |
| 1069 UiSplitPaneContainer *s = (UiSplitPaneContainer*)ct; |
1062 UiSplitPaneContainer *s = (UiSplitPaneContainer*)ct; |
| 1071 if(s->nchildren >= s->max) { |
1064 if(s->nchildren >= s->max) { |
| 1072 fprintf(stderr, "splitpane: maximum number of children reached\n"); |
1065 fprintf(stderr, "splitpane: maximum number of children reached\n"); |
| 1073 return; |
1066 return; |
| 1074 } |
1067 } |
| 1075 |
1068 |
| |
1069 cxListAdd(s->children, widget); |
| |
1070 |
| 1076 if(s->pos == 0) { |
1071 if(s->pos == 0) { |
| 1077 gtk_paned_set_start_child(GTK_PANED(s->current_pane), widget); |
1072 PANED_SET_CHILD1(s->current_pane, widget); |
| |
1073 if(s->initial_position > 0) { |
| |
1074 gtk_paned_set_position(GTK_PANED(s->current_pane), s->initial_position); |
| |
1075 } |
| 1078 s->pos++; |
1076 s->pos++; |
| 1079 s->nchildren++; |
1077 s->nchildren++; |
| 1080 } else { |
1078 } else { |
| 1081 if(s->nchildren+1 == s->max) { |
1079 if(s->nchildren+1 == s->max) { |
| 1082 gtk_paned_set_end_child(GTK_PANED(s->current_pane), widget); |
1080 PANED_SET_CHILD2(s->current_pane, widget); |
| 1083 } else { |
1081 } else { |
| 1084 GtkWidget *pane = create_paned(s->orientation); |
1082 GtkWidget *pane = create_paned(s->orientation); |
| 1085 gtk_paned_set_start_child(GTK_PANED(pane), widget); |
1083 PANED_SET_CHILD1(pane, widget); |
| 1086 gtk_paned_set_end_child(GTK_PANED(s->current_pane), pane); |
1084 PANED_SET_CHILD2(s->current_pane, pane); |
| 1087 s->current_pane = pane; |
1085 s->current_pane = pane; |
| 1088 } |
1086 } |
| 1089 |
1087 |
| 1090 s->pos = 0; |
1088 s->pos = 0; |
| 1091 s->nchildren++; |
1089 s->nchildren++; |
| |
1090 } |
| |
1091 } |
| |
1092 |
| |
1093 UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) { |
| |
1094 UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane"); |
| |
1095 if(!ct) { |
| |
1096 fprintf(stderr, "UI Error: not a splitpane\n"); |
| |
1097 return; |
| |
1098 } |
| |
1099 |
| |
1100 GtkWidget *w = cxListAt(ct->children, child_index); |
| |
1101 if(w) { |
| |
1102 gtk_widget_set_visible(w, visible); |
| 1092 } |
1103 } |
| 1093 } |
1104 } |
| 1094 |
1105 |
| 1095 /* -------------------- ItemList Container -------------------- */ |
1106 /* -------------------- ItemList Container -------------------- */ |
| 1096 |
1107 |