106 } |
106 } |
107 |
107 |
108 ucx_map_cstr_put(toolbar_items, name, item); |
108 ucx_map_cstr_put(toolbar_items, name, item); |
109 } |
109 } |
110 |
110 |
111 void ui_toolitem_toggle_st(char *name, char *stockid, ui_callback f, void *udata) { |
111 void ui_toolitem_toggle(const char *name, const char *label, const char *img, UiInteger *i) { |
112 ui_toolitem_toggle_stgr(name, stockid, f, udata, -1); |
112 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem)); |
113 } |
|
114 |
|
115 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) { |
|
116 UiStToolItem *item = malloc(sizeof(UiStToolItem)); |
|
117 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_st_widget; |
|
118 item->stockid = stockid; |
|
119 item->callback = f; |
|
120 item->userdata = udata; |
|
121 item->groups = NULL; |
|
122 item->isimportant = 0; |
|
123 |
|
124 // add groups |
|
125 va_list ap; |
|
126 va_start(ap, udata); |
|
127 int group; |
|
128 while((group = va_arg(ap, int)) != -1) { |
|
129 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
|
130 } |
|
131 va_end(ap); |
|
132 |
|
133 ucx_map_cstr_put(toolbar_items, name, item); |
|
134 } |
|
135 |
|
136 void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) { |
|
137 UiToolItem *item = malloc(sizeof(UiToolItem)); |
|
138 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
113 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
139 item->label = label; |
114 item->label = label; |
140 item->image = img; |
115 item->image = img; |
141 item->callback = f; |
116 item->stockid = NULL; |
142 item->userdata = udata; |
|
143 item->groups = NULL; |
117 item->groups = NULL; |
144 item->isimportant = 0; |
118 item->isimportant = 0; |
145 |
119 item->value = i; |
146 // add groups |
120 item->var = NULL; |
147 va_list ap; |
121 |
148 va_start(ap, udata); |
122 ucx_map_cstr_put(toolbar_items, name, item); |
149 int group; |
123 } |
150 while((group = va_arg(ap, int)) != -1) { |
124 |
151 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
125 void ui_toolitem_toggle_st(const char *name, const char *stockid, UiInteger *i) { |
152 } |
126 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem)); |
153 va_end(ap); |
127 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
|
128 item->label = NULL; |
|
129 item->image = NULL; |
|
130 item->stockid = stockid; |
|
131 item->groups = NULL; |
|
132 item->isimportant = 0; |
|
133 item->value = i; |
|
134 item->var = NULL; |
|
135 |
|
136 ucx_map_cstr_put(toolbar_items, name, item); |
|
137 } |
|
138 |
|
139 void ui_toolitem_toggle_nv(const char *name, const char *label, const char *img, const char *intvar) { |
|
140 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem)); |
|
141 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
|
142 item->label = label; |
|
143 item->image = img; |
|
144 item->stockid = NULL; |
|
145 item->groups = NULL; |
|
146 item->isimportant = 0; |
|
147 item->value = NULL; |
|
148 item->var = intvar; |
|
149 |
|
150 ucx_map_cstr_put(toolbar_items, name, item); |
|
151 } |
|
152 |
|
153 void ui_toolitem_toggle_stnv(const char *name, const char *stockid, const char *intvar) { |
|
154 UiToggleToolItem *item = malloc(sizeof(UiToggleToolItem)); |
|
155 item->item.add_to = (ui_toolbar_add_f)add_toolitem_toggle_widget; |
|
156 item->label = NULL; |
|
157 item->image = NULL; |
|
158 item->stockid = stockid; |
|
159 item->groups = NULL; |
|
160 item->isimportant = 0; |
|
161 item->value = NULL; |
|
162 item->var = intvar; |
154 |
163 |
155 ucx_map_cstr_put(toolbar_items, name, item); |
164 ucx_map_cstr_put(toolbar_items, name, item); |
156 } |
165 } |
157 |
166 |
158 |
167 |
297 if(item->groups) { |
306 if(item->groups) { |
298 uic_add_group_widget(obj->ctx, button, item->groups); |
307 uic_add_group_widget(obj->ctx, button, item->groups); |
299 } |
308 } |
300 } |
309 } |
301 |
310 |
302 void add_toolitem_toggle_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj) { |
311 void add_toolitem_toggle_widget(GtkToolbar *tb, UiToggleToolItem *item, UiObject *obj) { |
303 GtkToolItem *button = gtk_toggle_tool_button_new(); |
312 GtkToolItem *button; |
304 gtk_tool_item_set_homogeneous(button, FALSE); |
313 if(item->stockid) { |
305 if(item->label) { |
314 button = gtk_toggle_tool_button_new_from_stock(item->stockid); |
306 gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), item->label); |
315 } else { |
307 } |
316 button = gtk_toggle_tool_button_new(); |
308 if(item->image) { |
317 gtk_tool_item_set_homogeneous(button, FALSE); |
309 GdkPixbuf *pixbuf = ui_get_image(item->image); |
318 if(item->label) { |
310 GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); |
319 gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), item->label); |
311 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image); |
320 } |
312 } |
321 if(item->image) { |
313 |
322 GdkPixbuf *pixbuf = ui_get_image(item->image); |
314 if(item->callback) { |
323 GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); |
315 UiEventData *event = ucx_mempool_malloc( |
324 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), image); |
316 obj->ctx->mempool, |
325 } |
317 sizeof(UiEventData)); |
326 } |
318 event->obj = obj; |
327 |
319 event->userdata = item->userdata; |
328 UiVar *var; |
320 event->callback = item->callback; |
329 if(item->value) { |
|
330 var = malloc(sizeof(UiVar)); |
|
331 var->value = item->value; |
|
332 var->type = UI_VAR_SPECIAL; |
|
333 var->from = NULL; |
|
334 var->from_ctx = NULL; |
|
335 } else { |
|
336 var = uic_create_var(obj->ctx, item->var, UI_VAR_INTEGER); |
|
337 } |
|
338 |
|
339 if(var->value) { |
|
340 UiInteger *i = var->value; |
|
341 i->get = ui_tool_toggle_button_get; |
|
342 i->set = ui_tool_toggle_button_set; |
|
343 i->obj = button; |
321 |
344 |
322 g_signal_connect( |
345 if(i->value != 0) { |
323 button, |
346 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE); |
324 "toggled", |
347 } |
325 G_CALLBACK(ui_button_toggled), |
348 } |
326 event); |
349 |
327 } |
350 // register event |
328 |
351 // the event func will call the UiInteger observer callbacks |
|
352 UiEventData *event = ucx_mempool_malloc( |
|
353 obj->ctx->mempool, |
|
354 sizeof(UiEventData)); |
|
355 event->obj = obj; |
|
356 event->userdata = var; |
|
357 event->callback = NULL; |
|
358 |
|
359 g_signal_connect( |
|
360 button, |
|
361 "toggled", |
|
362 G_CALLBACK(ui_tool_button_toggled), |
|
363 event); |
|
364 |
|
365 // add item to toolbar |
329 gtk_toolbar_insert(tb, button, -1); |
366 gtk_toolbar_insert(tb, button, -1); |
330 |
367 |
331 if(item->groups) { |
368 if(item->groups) { |
332 uic_add_group_widget(obj->ctx, button, item->groups); |
369 uic_add_group_widget(obj->ctx, button, item->groups); |
333 } |
370 } |
334 } |
371 } |
335 |
372 |
336 void add_toolitem_toggle_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj) { |
373 void ui_tool_button_toggled(GtkToggleToolButton *widget, UiEventData *event) { |
337 GtkToolItem *button = gtk_toggle_tool_button_new_from_stock(item->stockid); |
374 UiEvent e; |
338 gtk_tool_item_set_homogeneous(button, FALSE); |
375 e.obj = event->obj; |
339 |
376 e.window = event->obj->window; |
340 if(item->callback) { |
377 e.document = event->obj->ctx->document; |
341 UiEventData *event = ucx_mempool_malloc( |
378 e.eventdata = NULL; |
342 obj->ctx->mempool, |
379 e.intval = gtk_toggle_tool_button_get_active(widget); |
343 sizeof(UiEventData)); |
380 |
344 event->obj = obj; |
381 UiVar *var = event->userdata; |
345 event->userdata = item->userdata; |
382 UiInteger *i = var->value; |
346 event->callback = item->callback; |
383 |
347 |
384 ui_notify_evt(i->observers, &e); |
348 g_signal_connect( |
385 } |
349 button, |
386 |
350 "toggled", |
387 int64_t ui_tool_toggle_button_get(UiInteger *integer) { |
351 G_CALLBACK(ui_button_toggled), |
388 integer->value = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(integer->obj)); |
352 event); |
389 return integer->value; |
353 } |
390 } |
354 |
391 |
355 gtk_toolbar_insert(tb, button, -1); |
392 void ui_tool_toggle_button_set(UiInteger *integer, int64_t value) { |
356 |
393 gboolean s = integer->value != 0 ? TRUE : FALSE; |
357 if(item->groups) { |
394 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(integer->obj), s); |
358 uic_add_group_widget(obj->ctx, button, item->groups); |
395 integer->value = s; |
359 } |
|
360 } |
396 } |
361 |
397 |
362 void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) { |
398 void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) { |
363 UiModel *modelinfo = ui_model(obj->ctx, UI_STRING, "", -1); |
399 UiModel *modelinfo = ui_model(obj->ctx, UI_STRING, "", -1); |
364 modelinfo->getvalue = cb->getvalue; |
400 modelinfo->getvalue = cb->getvalue; |