ui/motif/container.c

changeset 64
6ef2c7f73a30
parent 63
46a42f0c4f93
child 65
4697592e24ba
--- a/ui/motif/container.c	Mon Jan 05 11:49:46 2015 +0100
+++ b/ui/motif/container.c	Mon Jan 05 14:47:19 2015 +0100
@@ -302,6 +302,47 @@
     ucx_list_free(rowdim);
 }
 
+UiContainer* ui_tabview_container(UiObject *obj, Widget frame) {
+    UiTabViewContainer *ct = ucx_mempool_calloc(
+            obj->ctx->mempool,
+            1,
+            sizeof(UiTabViewContainer));
+    ct->context = obj->ctx;
+    ct->container.widget = frame;
+    ct->container.prepare = ui_tabview_container_prepare;
+    ct->container.add = ui_tabview_container_add;
+    return (UiContainer*)ct;
+}
+
+Widget ui_tabview_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
+    int a = *n;
+    XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++;
+    XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++;
+    XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++;
+    XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++;
+    *n = a;
+    return ct->widget;
+}
+
+void ui_tabview_container_add(UiContainer *ct, Widget widget) {
+    UiTabViewContainer *tabview = (UiTabViewContainer*)ct; 
+    
+    if(tabview->current) {
+        XtUnmanageChild(tabview->current);
+    }
+    if(tabview->tabs) {
+        // not the first tab, so unmanage the new widget
+        //XtUnmanageChild(widget);
+    } else {
+        tabview->current = widget;
+    }
+    tabview->current = widget;
+    
+    tabview->tabs = ucx_list_append(tabview->tabs, widget);
+    
+    ui_reset_layout(ct->layout);
+}
+
 UIWIDGET ui_box(UiObject *obj, UiBoxOrientation orientation) {
     UiContainer *ct = uic_get_current_container(obj);
     
@@ -381,6 +422,59 @@
     return sidebar;
 }
 
+UIWIDGET ui_tabview(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    // create a simple frame as container widget
+    // when tabs are selected, the current child will be replaced by the
+    // the new tab widget
+    Arg args[16];
+    int n = 0;
+    XtSetArg(args[n], XmNshadowType, XmSHADOW_ETCHED_OUT);
+    n++;
+    XtSetArg(args[n], XmNshadowThickness, 0);
+    n++;
+    Widget parent = ct->prepare(ct, args, &n, TRUE);
+    Widget form = XmCreateForm(parent, "tabview", args, n);
+    ct->add(ct, form);
+    XtManageChild(form);
+    
+    UiObject *tabviewobj = uic_object_new(obj, form);
+    tabviewobj->container = ui_tabview_container(obj, form);
+    uic_obj_add(obj, tabviewobj);
+    
+    XtVaSetValues(form, XmNuserData, tabviewobj->container, NULL);
+    
+    return form;
+}
+
+void ui_tab(UiObject *obj, char *title) {
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->layout.label = title;
+    
+    ui_vbox(obj);
+}
+
+void ui_select_tab(UIWIDGET tabview, int tab) {
+    UiTabViewContainer *ct = NULL;
+    XtVaGetValues(tabview, XmNuserData, &ct, NULL);
+    if(ct) {
+        XtUnmanageChild(ct->current);
+        UcxList *elm = ucx_list_get(ct->tabs, tab);
+        if(elm) {
+            XtManageChild(elm->data);
+            ct->current = elm->data;
+        } else {
+            fprintf(stderr, "UiError: front tab index: %d\n", tab);
+        }
+    } else {
+        fprintf(stderr, "UiError: widget is not a tabview\n");
+    }
+}
+
+
+/* document tabview */
+
 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) {
     int n = 0;
     Arg args[16];

mercurial