Tue, 22 Jul 2014 19:15:44 +0200
improved motif tabs
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Tue Jul 22 09:51:17 2014 +0200 +++ b/application/main.c Tue Jul 22 19:15:44 2014 +0200 @@ -136,6 +136,13 @@ ui_textarea_nv(tab2, "text"); ui_set_document(tab2, doc2); + UiObject *tab3 = ui_document_tab(view); + Document *doc3 = ui_document_new(1024); + UiContext *ctx3 = ui_document_context(doc3); + ui_document_regtext(doc3, "text", &doc3->text); + ui_textarea_nv(tab3, "text"); + ui_set_document(tab3, doc3); + ui_show(window); ui_main();
--- a/ui/common/context.c Tue Jul 22 09:51:17 2014 +0200 +++ b/ui/common/context.c Tue Jul 22 19:15:44 2014 +0200 @@ -131,7 +131,9 @@ } } - docctx->obj->ctx->document = NULL; + if(docctx->obj) { + docctx->obj->ctx->document = NULL; + } docctx->obj = NULL; }
--- a/ui/motif/container.c Tue Jul 22 09:51:17 2014 +0200 +++ b/ui/motif/container.c Tue Jul 22 19:15:44 2014 +0200 @@ -98,7 +98,7 @@ XtSetArg(args[3], XmNleftAttachment, XmATTACH_FORM); XtSetArg(args[4], XmNrightAttachment, XmATTACH_FORM); XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM); - Widget tabbar = XmCreateRowColumn(tabview, "toolbar", args, 6); + Widget tabbar = XmCreateForm(tabview, "toolbar", args, 6); XtManageChild(tabbar); XtSetArg(args[0], XmNleftAttachment, XmATTACH_FORM); @@ -155,34 +155,88 @@ content->container = ui_frame_container(content, frame); content->next = NULL; - // add tab button + // add tab button + v->tabs = ucx_list_append_a(view->ctx->mempool->allocator, v->tabs, tab); + XmString label = XmStringCreateLocalized("tab"); XtSetArg(args[0], XmNlabelString, label); XtSetArg(args[1], XmNshadowThickness, 1); XtSetArg(args[2], XmNtraversalOn, FALSE); - Widget button = XmCreatePushButton(v->tabbar, "tab_button", args, 3); - XtManageChild(button); - XtAddCallback( - button, - XmNactivateCallback, - (XtCallbackProc)ui_tab_button_callback, - tab); + XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM); + XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM); + XtSetArg(args[5], XmNhighlightThickness, 0); + XtSetArg(args[6], XmNindicatorOn, XmINDICATOR_NONE); + Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 7); tab->tabbedpane = v; tab->content = content; tab->tab_button = button; - v->tabs = ucx_list_append_a(view->ctx->mempool->allocator, v->tabs, tab); + // 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, + NULL); + is_first = FALSE; + } else if(i < count - 1) { + XtVaSetValues( + tt->tab_button, + XmNleftAttachment, + XmATTACH_POSITION, + XmNleftPosition, + pos, + XmNrightAttachment, + XmATTACH_POSITION, + XmNrightPosition, + pos + part, + NULL); + } else { + XtVaSetValues( + tt->tab_button, + XmNleftAttachment, + XmATTACH_POSITION, + XmNleftPosition, + pos, + XmNrightAttachment, + XmATTACH_FORM, + NULL); + } + pos += part; + i++; + } + + + XtManageChild(button); + XtAddCallback( + button, + XmNvalueChangedCallback, + (XtCallbackProc)ui_tab_button_callback, + tab); + v->current = tab; ui_change_tab(v, tab); return content; } -void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) { +void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) { MotifTabbedPane *t = tab->tabbedpane; if(t->current) { XtUnmanageChild(t->current->content->widget); + XtVaSetValues(t->current->tab_button, XmNset, 0, NULL); } XtManageChild(tab->content->widget);