Sat, 04 Apr 2015 12:00:32 +0200
drawingarea based tab widget (Motif)
ui/motif/container.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.h | file | annotate | diff | comparison | revisions |
--- a/ui/motif/container.c Tue Feb 17 20:12:22 2015 +0100 +++ b/ui/motif/container.c Sat Apr 04 12:00:32 2015 +0200 @@ -474,6 +474,33 @@ /* document tabview */ +static void ui_tabbar_resize(Widget widget, XtPointer udata, XtPointer cdata) { + MotifTabbedPane *v = (MotifTabbedPane*)udata; + + int width = 0; + int height = 0; + XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); + int button_width = width / 4; + int x = 0; + UCX_FOREACH(elm, v->tabs) { + UiTab *tab = elm->data; + XtVaSetValues( + tab->tab_button, + XmNx, x, + XmNy, 0, + XmNwidth, + button_width, + NULL); + x += button_width; + } +} + +static void ui_tabbar_expose(Widget widget, XtPointer udata, XtPointer cdata) { + MotifTabbedPane *v = (MotifTabbedPane*)udata; + XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct *)cdata; + XEvent *event = cbs->event; +} + UiTabbedPane* ui_tabbed_document_view(UiObject *obj) { int n = 0; Arg args[16]; @@ -490,7 +517,9 @@ XtSetArg(args[3], XmNleftAttachment, XmATTACH_FORM); XtSetArg(args[4], XmNrightAttachment, XmATTACH_FORM); XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM); - Widget tabbar = XmCreateForm(tabview, "toolbar", args, 6); + XtSetArg(args[6], XmNmarginWidth, 0); + XtSetArg(args[7], XmNmarginHeight, 0); + Widget tabbar = XmCreateDrawingArea(tabview, "tabbar", args, 8); XtManageChild(tabbar); XtSetArg(args[0], XmNleftAttachment, XmATTACH_FORM); @@ -510,6 +539,11 @@ tabbedpane->tabs = NULL; tabbedpane->current = NULL; + XGCValues gcv; + + XtAddCallback(tabbar, XmNresizeCallback , ui_tabbar_resize, tabbedpane); + XtAddCallback(tabbar, XmNexposeCallback, ui_tabbar_expose, tabbedpane); + return &tabbedpane->view; } @@ -551,82 +585,22 @@ XmString label = XmStringCreateLocalized("tab"); XtSetArg(args[0], XmNlabelString, label); - XtSetArg(args[1], XmNshadowThickness, 1); - XtSetArg(args[2], XmNtraversalOn, FALSE); - XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM); - XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM); - XtSetArg(args[5], XmNhighlightThickness, 0); - XtSetArg(args[6], XmNindicatorOn, XmINDICATOR_NONE); - XtSetArg(args[7], XmNfillOnSelect, TRUE); - XtSetArg(args[8], XmNtopShadowColor, 1); + XtSetArg(args[1], XmNshadowThickness, 0); + XtSetArg(args[2], XmNhighlightThickness, 0); - Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 8); + Widget button = XmCreatePushButton(v->tabbar, "tab_button", args, 3); tab->tabbedpane = v; tab->content = content; - tab->tab_button = button; - - // layout - int is_first = 1; - size_t count = ucx_list_size(v->tabs); - int part = 100 / count; - int pos = 0; - int i = 0; - UCX_FOREACH(elm, v->tabs) { - UiTab *tt = elm->data; - if(is_first) { - XtVaSetValues( - tt->tab_button, - XmNleftAttachment, - XmATTACH_FORM, - XmNrightAttachment, - XmATTACH_POSITION, - XmNrightPosition, - pos + part, - XmNset, - FALSE, - NULL); - is_first = FALSE; - } else if(i < count - 1) { - XtVaSetValues( - tt->tab_button, - XmNleftAttachment, - XmATTACH_POSITION, - XmNleftPosition, - pos, - XmNrightAttachment, - XmATTACH_POSITION, - XmNrightPosition, - pos + part, - XmNset, - FALSE, - NULL); - } else { - XtVaSetValues( - tt->tab_button, - XmNleftAttachment, - XmATTACH_POSITION, - XmNleftPosition, - pos, - XmNrightAttachment, - XmATTACH_FORM, - XmNset, - FALSE, - NULL); - } - pos += part; - i++; - } - + tab->tab_button = button; XtManageChild(button); - XtVaSetValues(button, XmNset, TRUE, NULL); XtAddCallback( button, - XmNvalueChangedCallback, + XmNactivateCallback, (XtCallbackProc)ui_tab_button_callback, tab); - v->current = tab; ui_change_tab(v, tab); + ui_tabbar_resize(v->tabbar, v, NULL); return content; } @@ -639,13 +613,17 @@ } XtManageChild(tab->content->widget); - t->current = tab; ui_change_tab(t, tab); + } void ui_change_tab(MotifTabbedPane *pane, UiTab *tab) { UiContext *ctx = tab->content->ctx; ctx->parent->set_document(ctx->parent, ctx->document); + + pane->current = tab; + pane->index = ucx_list_find(pane->tabs, tab, NULL, NULL); + printf("index: %d\n", pane->index); } void ui_tab_set_document(UiContext *ctx, void *document) {