1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2014 Olaf Wintermann. All rights reserved. |
4 * Copyright 2017 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
162 ui_model_getvalue_f getvalue, |
162 ui_model_getvalue_f getvalue, |
163 ui_callback f, |
163 ui_callback f, |
164 void *udata) |
164 void *udata) |
165 { |
165 { |
166 UiToolbarComboBox *cb = malloc(sizeof(UiToolbarComboBox)); |
166 UiToolbarComboBox *cb = malloc(sizeof(UiToolbarComboBox)); |
167 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox; |
167 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox; |
168 cb->list = list; |
168 UiVar *var = malloc(sizeof(UiVar)); |
|
169 var->value = list; |
|
170 var->type = UI_VAR_SPECIAL; |
|
171 cb->var = var; |
169 cb->getvalue = getvalue; |
172 cb->getvalue = getvalue; |
170 cb->callback = f; |
173 cb->callback = f; |
171 cb->userdata = udata; |
174 cb->userdata = udata; |
172 |
175 |
173 ucx_map_cstr_put(toolbar_items, name, cb); |
176 ucx_map_cstr_put(toolbar_items, name, cb); |
355 } |
358 } |
356 |
359 |
357 void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) { |
360 void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) { |
358 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1); |
361 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1); |
359 modelinfo->getvalue = cb->getvalue; |
362 modelinfo->getvalue = cb->getvalue; |
360 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); |
363 UiListModel *model = ui_list_model_new(cb->var, modelinfo); |
361 listptr->list = cb->list; |
|
362 UiListModel *model = ui_list_model_new(listptr, modelinfo); |
|
363 |
364 |
364 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata); |
365 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata); |
365 GtkToolItem *item = gtk_tool_item_new(); |
366 GtkToolItem *item = gtk_tool_item_new(); |
366 gtk_container_add(GTK_CONTAINER(item), combobox); |
367 gtk_container_add(GTK_CONTAINER(item), combobox); |
367 gtk_toolbar_insert(tb, item, -1); |
368 gtk_toolbar_insert(tb, item, -1); |
368 } |
369 } |
369 |
370 |
370 void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) { |
371 void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) { |
371 // TODO |
372 UiVar *var = uic_create_var(obj->ctx, cb->listname, UI_VAR_LIST); |
372 } |
373 if(var) { |
373 |
374 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1); |
|
375 modelinfo->getvalue = cb->getvalue; |
|
376 UiListModel *model = ui_list_model_new(var, modelinfo); |
|
377 |
|
378 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata); |
|
379 GtkToolItem *item = gtk_tool_item_new(); |
|
380 gtk_container_add(GTK_CONTAINER(item), combobox); |
|
381 gtk_toolbar_insert(tb, item, -1); |
|
382 } |
|
383 } |
|
384 |