ui/motif/container.c

changeset 53
62205699cd0e
parent 52
25e5390cce41
child 54
97bafeca1c7c
equal deleted inserted replaced
52:25e5390cce41 53:62205699cd0e
96 XtSetArg(args[1], XmNpacking, XmPACK_TIGHT); 96 XtSetArg(args[1], XmNpacking, XmPACK_TIGHT);
97 XtSetArg(args[2], XmNspacing, 1); 97 XtSetArg(args[2], XmNspacing, 1);
98 XtSetArg(args[3], XmNleftAttachment, XmATTACH_FORM); 98 XtSetArg(args[3], XmNleftAttachment, XmATTACH_FORM);
99 XtSetArg(args[4], XmNrightAttachment, XmATTACH_FORM); 99 XtSetArg(args[4], XmNrightAttachment, XmATTACH_FORM);
100 XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM); 100 XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM);
101 Widget tabbar = XmCreateRowColumn(tabview, "toolbar", args, 6); 101 Widget tabbar = XmCreateForm(tabview, "toolbar", args, 6);
102 XtManageChild(tabbar); 102 XtManageChild(tabbar);
103 103
104 XtSetArg(args[0], XmNleftAttachment, XmATTACH_FORM); 104 XtSetArg(args[0], XmNleftAttachment, XmATTACH_FORM);
105 XtSetArg(args[1], XmNrightAttachment, XmATTACH_FORM); 105 XtSetArg(args[1], XmNrightAttachment, XmATTACH_FORM);
106 XtSetArg(args[2], XmNtopAttachment, XmATTACH_WIDGET); 106 XtSetArg(args[2], XmNtopAttachment, XmATTACH_WIDGET);
153 content->widget = frame; 153 content->widget = frame;
154 content->window = view->ctx->obj->window; 154 content->window = view->ctx->obj->window;
155 content->container = ui_frame_container(content, frame); 155 content->container = ui_frame_container(content, frame);
156 content->next = NULL; 156 content->next = NULL;
157 157
158 // add tab button 158 // add tab button
159 v->tabs = ucx_list_append_a(view->ctx->mempool->allocator, v->tabs, tab);
160
159 XmString label = XmStringCreateLocalized("tab"); 161 XmString label = XmStringCreateLocalized("tab");
160 XtSetArg(args[0], XmNlabelString, label); 162 XtSetArg(args[0], XmNlabelString, label);
161 XtSetArg(args[1], XmNshadowThickness, 1); 163 XtSetArg(args[1], XmNshadowThickness, 1);
162 XtSetArg(args[2], XmNtraversalOn, FALSE); 164 XtSetArg(args[2], XmNtraversalOn, FALSE);
163 Widget button = XmCreatePushButton(v->tabbar, "tab_button", args, 3); 165 XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM);
166 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
167 XtSetArg(args[5], XmNhighlightThickness, 0);
168 XtSetArg(args[6], XmNindicatorOn, XmINDICATOR_NONE);
169
170 Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 7);
171 tab->tabbedpane = v;
172 tab->content = content;
173 tab->tab_button = button;
174
175 // layout
176 int is_first = 1;
177 size_t count = ucx_list_size(v->tabs);
178 int part = 100 / count;
179 int pos = 0;
180 int i = 0;
181 UCX_FOREACH(elm, v->tabs) {
182 UiTab *tt = elm->data;
183 if(is_first) {
184 XtVaSetValues(
185 tt->tab_button,
186 XmNleftAttachment,
187 XmATTACH_FORM,
188 XmNrightAttachment,
189 XmATTACH_POSITION,
190 XmNrightPosition,
191 pos + part,
192 NULL);
193 is_first = FALSE;
194 } else if(i < count - 1) {
195 XtVaSetValues(
196 tt->tab_button,
197 XmNleftAttachment,
198 XmATTACH_POSITION,
199 XmNleftPosition,
200 pos,
201 XmNrightAttachment,
202 XmATTACH_POSITION,
203 XmNrightPosition,
204 pos + part,
205 NULL);
206 } else {
207 XtVaSetValues(
208 tt->tab_button,
209 XmNleftAttachment,
210 XmATTACH_POSITION,
211 XmNleftPosition,
212 pos,
213 XmNrightAttachment,
214 XmATTACH_FORM,
215 NULL);
216 }
217 pos += part;
218 i++;
219 }
220
221
164 XtManageChild(button); 222 XtManageChild(button);
165 XtAddCallback( 223 XtAddCallback(
166 button, 224 button,
167 XmNactivateCallback, 225 XmNvalueChangedCallback,
168 (XtCallbackProc)ui_tab_button_callback, 226 (XtCallbackProc)ui_tab_button_callback,
169 tab); 227 tab);
170 228
171 tab->tabbedpane = v;
172 tab->content = content;
173 tab->tab_button = button;
174
175 v->tabs = ucx_list_append_a(view->ctx->mempool->allocator, v->tabs, tab);
176 v->current = tab; 229 v->current = tab;
177 ui_change_tab(v, tab); 230 ui_change_tab(v, tab);
178 231
179 return content; 232 return content;
180 } 233 }
181 234
182 void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) { 235 void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d) {
183 MotifTabbedPane *t = tab->tabbedpane; 236 MotifTabbedPane *t = tab->tabbedpane;
184 if(t->current) { 237 if(t->current) {
185 XtUnmanageChild(t->current->content->widget); 238 XtUnmanageChild(t->current->content->widget);
239 XtVaSetValues(t->current->tab_button, XmNset, 0, NULL);
186 } 240 }
187 XtManageChild(tab->content->widget); 241 XtManageChild(tab->content->widget);
188 242
189 t->current = tab; 243 t->current = tab;
190 ui_change_tab(t, tab); 244 ui_change_tab(t, tab);

mercurial