464 |
465 |
465 void ui_checkitem_set(UiInteger *i, int value) { |
466 void ui_checkitem_set(UiInteger *i, int value) { |
466 i->value = value; |
467 i->value = value; |
467 gtk_check_menu_item_set_active(i->obj, value); |
468 gtk_check_menu_item_set_active(i->obj, value); |
468 } |
469 } |
|
470 |
|
471 |
|
472 /* |
|
473 * widget menu functions |
|
474 */ |
|
475 |
|
476 static gboolean ui_button_press_event(GtkWidget *widget, GdkEvent *event, GtkMenu *menu) { |
|
477 if(event->type == GDK_BUTTON_PRESS) { |
|
478 GdkEventButton *e = (GdkEventButton*)event; |
|
479 if(e->button == 3) { |
|
480 gtk_widget_show_all(GTK_WIDGET(menu)); |
|
481 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, e->button, e->time); |
|
482 return TRUE; |
|
483 } |
|
484 } |
|
485 return FALSE; |
|
486 } |
|
487 |
|
488 void ui_contextmenu(UiObject *obj) { |
|
489 UiContainer *ct = uic_get_current_container(obj); |
|
490 ui_contextmenu_w(obj, ct->current); |
|
491 } |
|
492 |
|
493 void ui_contextmenu_w(UiObject *obj, UIWIDGET widget) { |
|
494 UiContainer *ct = uic_get_current_container(obj); |
|
495 |
|
496 GtkMenu *menu = GTK_MENU(gtk_menu_new()); |
|
497 g_signal_connect(widget, "button-press-event", (GCallback) ui_button_press_event, menu); |
|
498 |
|
499 ct->menu = menu; |
|
500 } |
|
501 |
|
502 void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) { |
|
503 ui_widget_menuitem_gr(obj, label, f, userdata, -1); |
|
504 } |
|
505 |
|
506 void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) { |
|
507 UiContainer *ct = uic_get_current_container(obj); |
|
508 if(!ct->menu) { |
|
509 return; |
|
510 } |
|
511 |
|
512 // add groups |
|
513 UcxList *groups = NULL; |
|
514 va_list ap; |
|
515 va_start(ap, userdata); |
|
516 int group; |
|
517 while((group = va_arg(ap, int)) != -1) { |
|
518 ucx_list_append(groups, (void*)(intptr_t)group); |
|
519 } |
|
520 va_end(ap); |
|
521 |
|
522 // create menuitem |
|
523 GtkWidget *widget = gtk_menu_item_new_with_mnemonic(label); |
|
524 |
|
525 if(f) { |
|
526 UiEventData *event = malloc(sizeof(UiEventData)); |
|
527 event->obj = obj; |
|
528 event->userdata = userdata; |
|
529 event->callback = f; |
|
530 event->value = 0; |
|
531 |
|
532 g_signal_connect( |
|
533 widget, |
|
534 "activate", |
|
535 G_CALLBACK(ui_menu_event_wrapper), |
|
536 event); |
|
537 g_signal_connect( |
|
538 widget, |
|
539 "destroy", |
|
540 G_CALLBACK(ui_destroy_userdata), |
|
541 event); |
|
542 } |
|
543 |
|
544 gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); |
|
545 |
|
546 if(groups) { |
|
547 uic_add_group_widget(obj->ctx, widget, groups); |
|
548 } |
|
549 } |
|
550 |
|
551 void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) { |
|
552 ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1); |
|
553 } |
|
554 |
|
555 void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) { |
|
556 UiContainer *ct = uic_get_current_container(obj); |
|
557 if(!ct->menu) { |
|
558 return; |
|
559 } |
|
560 |
|
561 // add groups |
|
562 UcxList *groups = NULL; |
|
563 va_list ap; |
|
564 va_start(ap, userdata); |
|
565 int group; |
|
566 while((group = va_arg(ap, int)) != -1) { |
|
567 ucx_list_append(groups, (void*)(intptr_t)group); |
|
568 } |
|
569 va_end(ap); |
|
570 |
|
571 // create menuitem |
|
572 GtkWidget *widget = gtk_image_menu_item_new_from_stock(stockid, obj->ctx->accel_group); |
|
573 |
|
574 if(f) { |
|
575 UiEventData *event = malloc(sizeof(UiEventData)); |
|
576 event->obj = obj; |
|
577 event->userdata = userdata; |
|
578 event->callback = f; |
|
579 event->value = 0; |
|
580 |
|
581 g_signal_connect( |
|
582 widget, |
|
583 "activate", |
|
584 G_CALLBACK(ui_menu_event_wrapper), |
|
585 event); |
|
586 g_signal_connect( |
|
587 widget, |
|
588 "destroy", |
|
589 G_CALLBACK(ui_destroy_userdata), |
|
590 event); |
|
591 } |
|
592 |
|
593 gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); |
|
594 |
|
595 if(groups) { |
|
596 uic_add_group_widget(obj->ctx, widget, groups); |
|
597 } |
|
598 } |