ui/motif/container.c

changeset 455
391d8c7223d1
parent 452
a0620cf552a6
child 460
1274d84f44de
equal deleted inserted replaced
454:57a2c6c04966 455:391d8c7223d1
32 32
33 #include "container.h" 33 #include "container.h"
34 #include "../common/context.h" 34 #include "../common/context.h"
35 #include "../common/object.h" 35 #include "../common/object.h"
36 36
37 #include <cx/array_list.h>
38
37 #include "Grid.h" 39 #include "Grid.h"
38 40
39 41
40 UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) { 42 UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) {
41 Arg xargs[64]; 43 Arg xargs[64];
217 grid->x++; 219 grid->x++;
218 ui_reset_layout(ctn->layout); 220 ui_reset_layout(ctn->layout);
219 } 221 }
220 222
221 223
224 /* -------------------------- TabView Container -------------------------- */
225
226 static void ui_tabbar_resize(Widget widget, XtPointer udata, XtPointer cdata) {
227 printf("ui_tabbar_resize\n");
228
229 UiMotifTabView *tabview = udata;
230
231 int width = 0;
232 int height = 0;
233 XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
234 int button_width = width / 4;
235 int x = 0;
236
237 printf("width: %d\n", (int)width);
238
239 CxIterator i = cxListIterator(tabview->tabs);
240 cx_foreach(UiTab *, tab, i) {
241 XtVaSetValues(
242 tab->tab_button,
243 XmNx, x,
244 XmNy, 0,
245 XmNwidth,
246 button_width,
247
248 NULL);
249 x += button_width;
250 }
251
252 if(height <= tabview->height) {
253 XtVaSetValues(widget, XmNheight, tabview->height + 4, NULL);
254 }
255 }
256
257 static void ui_tabbar_expose(Widget widget, XtPointer udata, XtPointer cdata) {
258 printf("ui_tabbar_expose\n");
259
260 UiMotifTabView *tabview = udata;
261 CxIterator i = cxListIterator(tabview->tabs);
262 cx_foreach(UiTab *, tab, i) {
263 printf("y: %d\n", (int)tab->tab_button->core.y);
264 }
265
266 XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct *)cdata;
267 XEvent *event = cbs->event;
268 Display *dpy = XtDisplay(widget);
269
270 printf("width: %d\n", (int)widget->core.width);
271 }
272
273 UIWIDGET ui_tabview_create(UiObject *obj, UiTabViewArgs args) {
274 Arg xargs[16];
275 int n = 0;
276
277 UiContainerPrivate *ctn = ui_obj_container(obj);
278 UI_APPLY_LAYOUT(ctn->layout, args);
279
280 // create widgets
281 // form
282 // - tabbar (Drawing Area)
283 // - content (Frame)
284 UiMotifTabView *tabview = malloc(sizeof(UiMotifTabView));
285 memset(tabview, 0, sizeof(UiMotifTabView));
286 char *name = args.name ? (char*)args.name : "tabview";
287 XtSetArg(xargs[n], XmNuserData, tabview); n++;
288 Widget parent = ctn->prepare(ctn, xargs, &n);
289 Widget form = XmCreateForm(parent, name, xargs, n);
290 XtManageChild(form);
291
292 n = 0;
293 XtSetArg(xargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
294 XtSetArg(xargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
295 XtSetArg(xargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
296 XtSetArg(xargs[n], XmNorientation, XmHORIZONTAL); n++;
297 XtSetArg(xargs[n], XmNpacking, XmPACK_TIGHT); n++;
298 XtSetArg(xargs[n], XmNspacing, 1); n++;
299 XtSetArg(xargs[n], XmNmarginWidth, 0); n++;
300 XtSetArg(xargs[n], XmNmarginHeight, 0); n++;
301 Widget tabbar = XmCreateDrawingArea(form, "ui_test", xargs, n);
302 XtManageChild(tabbar);
303 XtAddCallback(tabbar, XmNresizeCallback , ui_tabbar_resize, tabview);
304 XtAddCallback(tabbar, XmNexposeCallback, ui_tabbar_expose, tabview);
305
306 n = 0;
307 XtSetArg(xargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
308 XtSetArg(xargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
309 XtSetArg(xargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
310 XtSetArg(xargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
311 XtSetArg(xargs[n], XmNtopWidget, tabbar); n++;
312 Widget content = XmCreateFrame(form, "tabviewcontent", xargs, n);
313
314 // setup tabview object, that holds all relevant objects
315 tabview->form = form;
316 tabview->tabbar = tabbar;
317 tabview->content = content;
318 tabview->tabview = args.tabview;
319 tabview->subcontainer = args.subcontainer;
320 tabview->select = ui_motif_tabview_select;
321 tabview->add = ui_motif_tabview_add_tab;
322 tabview->remove = ui_motif_tabview_remove;
323 tabview->tabs = cxArrayListCreateSimple(sizeof(UiTab), 8);
324
325 UiTabViewContainer *ct = ui_malloc(obj->ctx, sizeof(UiTabViewContainer));
326 ct->container.widget = form;
327 ct->container.type = UI_CONTAINER_TABVIEW;
328 ct->container.prepare = ui_tabview_container_prepare;
329 ct->container.add = ui_tabview_container_add;
330 ct->tabview = tabview;
331
332 uic_object_push_container(obj, (UiContainerX*)ct);
333
334 return form;
335 }
336
337 void ui_tab_create(UiObject *obj, const char* title) {
338 UiContainerPrivate *ctn = ui_obj_container(obj);
339 if(ctn->type != UI_CONTAINER_TABVIEW) {
340 fprintf(stderr, "UI Error: container is not a tabview\n");
341 return;
342 }
343
344 UiMotifTabView *tabview = NULL;
345 XtVaGetValues(ctn->widget, XmNuserData, &tabview, NULL);
346 if(!tabview) {
347 fprintf(stderr, "UI Error: no tabview\n");
348 return;
349 }
350
351
352 Widget child = ui_vbox_create(obj, (UiContainerArgs) { 0 });
353 if(tabview->current) {
354 XtUnmanageChild(child);
355 } else {
356 tabview->current = child;
357 }
358
359 tabview->add(tabview, -1, title, child);
360 }
361
362 void ui_motif_tabview_select(UiMotifTabView *tabview, int tab) {
363
364 }
365
366 void ui_motif_tabview_add_tab(UiMotifTabView *tabview, int index, const char *name, Widget child) {
367 UiTab tab;
368
369 Arg args[16];
370 int n = 0;
371
372 XmString label = XmStringCreateLocalized((char*)name);
373 XtSetArg(args[n], XmNlabelString, label); n++;
374 XtSetArg(args[n], XmNshadowThickness, 0); n++;
375 XtSetArg(args[n], XmNhighlightThickness, 0); n++;
376
377 Widget button = XmCreatePushButton(tabview->tabbar, "tab_button", args, 3);
378 XtManageChild(button);
379
380 if(tabview->height == 0) {
381 Dimension h;
382 XtVaGetValues(
383 button,
384 XmNarmColor,
385 &tabview->bg1,
386 XmNbackground,
387 &tabview->bg2,
388 XmNheight,
389 &h,
390 NULL);
391 tabview->height = h + 2; // border
392 }
393
394 tab.tab_button = button;
395 tab.child = child;
396 cxListAdd(tabview->tabs, &tab);
397 }
398
399 void ui_motif_tabview_remove(UiMotifTabView *tabview, int index) {
400
401 }
402
403 Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n) {
404 UiTabViewContainer *ct = (UiTabViewContainer*)ctn;
405 UiMotifTabView *tabview = ct->tabview;
406 int a = *n;
407 XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++;
408 XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++;
409 XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++;
410 XtSetArg(args[a], XmNtopAttachment, XmATTACH_WIDGET); a++;
411 XtSetArg(args[a], XmNtopWidget, tabview->tabbar); a++;
412 *n = a;
413 return tabview->form;
414 }
415
416 void ui_tabview_container_add(UiContainerPrivate *ctn, Widget widget) {
417 ui_reset_layout(ctn->layout);
418 }
419
420
421
222 /* -------------------- Container Helper Functions -------------------- */ 422 /* -------------------- Container Helper Functions -------------------- */
223 423
224 void ui_container_begin_close(UiObject *obj) { 424 void ui_container_begin_close(UiObject *obj) {
225 UiContainerPrivate *ct = ui_obj_container(obj); 425 UiContainerPrivate *ct = ui_obj_container(obj);
226 ct->container.close = 1; 426 ct->container.close = 1;

mercurial