ui/gtk/container.c

branch
newapi
changeset 328
059cba080ab4
parent 313
b679cc6059ab
equal deleted inserted replaced
325:99a93a9250c4 328:059cba080ab4
226 ct->container.add = ui_tabview_container_add; 226 ct->container.add = ui_tabview_container_add;
227 return (UiContainer*)ct; 227 return (UiContainer*)ct;
228 } 228 }
229 229
230 void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { 230 void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
231 gtk_notebook_append_page( 231 UiGtkTabView *data = ui_widget_get_tabview_data(ct->widget);
232 GTK_NOTEBOOK(ct->widget), 232 if(!data) {
233 widget, 233 fprintf(stderr, "UI Error: widget is not a tabview");
234 gtk_label_new(ct->layout.label)); 234 return;
235 }
236 data->add_tab(ct->widget, -1, ct->layout.label, widget);
235 237
236 ui_reset_layout(ct->layout); 238 ui_reset_layout(ct->layout);
237 ct->current = widget; 239 ct->current = widget;
238 } 240 }
239 241
332 334
333 void ui_select_tab(UIWIDGET tabview, int tab) { 335 void ui_select_tab(UIWIDGET tabview, int tab) {
334 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); 336 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
335 } 337 }
336 338
339 void ui_notebook_tab_select(UIWIDGET tabview, int tab) {
340 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
341 }
342
343 void ui_notebook_tab_remove(UIWIDGET tabview, int tab) {
344 gtk_notebook_remove_page(GTK_NOTEBOOK(tabview), tab);
345 }
346
347 void ui_notebook_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) {
348 gtk_notebook_insert_page(
349 GTK_NOTEBOOK(widget),
350 child,
351 gtk_label_new(name),
352 index);
353 }
354
355 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) {
356 return g_object_get_data(G_OBJECT(tabview), "ui_tabview");
357 }
358
359 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
360 UiGtkTabView *data = malloc(sizeof(UiGtkTabView));
361 data->margin = args.margin;
362 data->spacing = args.spacing;
363 data->columnspacing = args.columnspacing;
364 data->rowspacing = args.rowspacing;
365
366 GtkWidget *widget = NULL;
367 switch(args.tabview) {
368 case UI_TABVIEW_DOC: {
369 // TODO
370 break;
371 }
372 case UI_TABVIEW_NAVIGATION_SIDE: {
373 // TODO
374 break;
375 }
376 case UI_TABVIEW_DEFAULT:
377 case UI_TABVIEW_NAVIGATION_TOP:
378 case UI_TABVIEW_NAVIGATION_TOP2: {
379 widget = gtk_notebook_new();
380 data->select_tab = ui_notebook_tab_select;
381 data->remove_tab = ui_notebook_tab_remove;
382 data->add_tab = ui_notebook_tab_add;
383 break;
384 }
385 case UI_TABVIEW_INVISIBLE: {
386 widget = gtk_notebook_new();
387 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE);
388 gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE);
389 data->select_tab = ui_notebook_tab_select;
390 data->remove_tab = ui_notebook_tab_remove;
391 data->add_tab = ui_notebook_tab_add;
392 break;
393 }
394 }
395
396 g_object_set_data(G_OBJECT(widget), "ui_tabview", data);
397 data->widget = widget;
398 data->subcontainer = args.subcontainer;
399
400 UiObject* current = uic_current_obj(obj);
401 UI_APPLY_LAYOUT1(current, args);
402 current->container->add(current->container, widget, TRUE);
403
404 UiObject *newobj = uic_object_new(obj, widget);
405 newobj->container = ui_tabview_container(obj, widget);
406 uic_obj_add(obj, newobj);
407 data->obj = newobj;
408
409 return widget;
410 }
411
412 void ui_tab_create(UiObject* obj, const char* title) {
413 UiObject* current = uic_current_obj(obj);
414 UiGtkTabView *data = ui_widget_get_tabview_data(current->widget);
415 if(!data) {
416 fprintf(stderr, "UI Error: widget is not a tabview\n");
417 return;
418 }
419
420 UiObject *newobj = ui_tabview_add(data->widget, title, -1);
421 current->next = newobj;
422 }
423
424
425
426 void ui_tabview_select(UIWIDGET tabview, int tab) {
427 UiGtkTabView *data = ui_widget_get_tabview_data(tabview);
428 if(!data) {
429 fprintf(stderr, "UI Error: widget is not a tabview\n");
430 return;
431 }
432 data->select_tab(tabview, tab);
433 }
434
435 void ui_tabview_remove(UIWIDGET tabview, int tab) {
436 UiGtkTabView *data = ui_widget_get_tabview_data(tabview);
437 if(!data) {
438 fprintf(stderr, "UI Error: widget is not a tabview\n");
439 return;
440 }
441 data->remove_tab(tabview, tab);
442 }
443
444 UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index) {
445 UiGtkTabView *data = ui_widget_get_tabview_data(tabview);
446 if(!data) {
447 fprintf(stderr, "UI Error: widget is not a tabview\n");
448 return NULL;
449 }
450
451 UiObject *newobj = cxCalloc(data->obj->ctx->allocator, 1, sizeof(UiObject));
452 newobj->ctx = data->obj->ctx;
453
454 GtkWidget *sub;
455 switch(data->subcontainer) {
456 default: {
457 sub = ui_gtk_vbox_new(data->spacing);
458 newobj->container = ui_box_container(newobj, sub, data->subcontainer);
459 break;
460 }
461 case UI_CONTAINER_HBOX: {
462 sub = ui_gtk_hbox_new(data->spacing);
463 newobj->container = ui_box_container(newobj, sub, data->subcontainer);
464 break;
465 }
466 case UI_CONTAINER_GRID: {
467 sub = create_grid(data->columnspacing, data->rowspacing);
468 newobj->container = ui_grid_container(newobj, sub);
469 break;
470 }
471 }
472 newobj->widget = sub;
473 GtkWidget *widget = box_set_margin(sub, data->margin);
474
475 data->add_tab(data->widget, tab_index, name, widget);
476
477 return newobj;
478 }
479
337 /* -------------------- Splitpane -------------------- */ 480 /* -------------------- Splitpane -------------------- */
338 481
339 static GtkWidget* create_paned(UiOrientation orientation) { 482 static GtkWidget* create_paned(UiOrientation orientation) {
340 #if GTK_MAJOR_VERSION >= 3 483 #if GTK_MAJOR_VERSION >= 3
341 switch(orientation) { 484 switch(orientation) {

mercurial