RE: GtkMenu question
- From: Julien Bramary <julien_bramary msn com>
- To: <gtk-list gnome org>
- Subject: RE: GtkMenu question
- Date: Mon, 14 Dec 2009 07:50:34 +0100
It works!
This is very clever, nice one Artur! I wouldn't have come up with this on my own.
For the reference a stripped down sample code provided below for a choice of 2 options:
static void choose_handler(void*, gpointer);
static gboolean idle_chooser(gpointer);
static void choose_deactivate_handler(void*, gpointer);
static void choose_handler(void*, gpointer);
enum {
FIRST_CHOICE = 1,
SECOND_CHOICE,
};
static gboolean has_chosen;
void popup_chooser(void) {
has_chosen = FALSE;
GtkWidget *popup = = gtk_menu_new();
GtkWidget *first_choice = gtk_menu_item_new_with_mnemonic("_First choice");
GtkWidget *second_choice = gtk_menu_item_new_with_mnemonic("_Second choice");
// Connect the signals as normal:
g_signal_connect (GTK_OBJECT (first_choice), "activate", G_CALLBACK (choose_handler), GINT_TO_POINTER(FIRST_CHOICE));
g_signal_connect (GTK_OBJECT (second_choice), "activate", G_CALLBACK (choose_handler), GINT_TO_POINTER(SECOND_CHOICE));
// Add a special handler on the menu for "deactivate":
g_signal_connect (GTK_OBJECT (choose_popup), "deactivate", G_CALLBACK (choose_deactivate_handler), NULL);
gtk_widget_show (first_choice);
gtk_widget_show (second_choice);
gtk_menu_attach( GTK_MENU(popup), first_choice, 0, 1, 0, 1);
gtk_menu_attach( GTK_MENU(popup), first_choice, 0, 1, 1, 2);
gtk_menu_popup ( GTK_MENU(popup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
}
// Define the handlers
static gboolean idle_chooser(gpointer trash) {
if ( ! has_chosen) {
printf("User has NOT chosen!\n");
// now make a choice [...]
}
else {
printf("User chose\n");
}
return FALSE;
}
static void choose_deactivate_handler(void *GtkWidget, gpointer value) {
g_idle_add(idle_chooser, NULL);
}
static void choose_handler(void *GtkWidget, gpointer value) {
has_chosen = TRUE;
}
Thanks a ton Artur!
Julien
From: artur-pub yandex ru
To: julien_bramary msn com
CC: gtk-list gnome org
Subject: Re: GtkMenu question
Date: Sun, 13 Dec 2009 22:20:28 +0300
13.12.09, 22:12, "Artur Galyamov" <artur-pub yandex ru>:
same iteration of main loop -- if so, you can play with g_idle_add() to set final value:
before popup -> set default value to tmp
on optional activate -> set activated value to tmp
... (iteration ends)
on high-priority idle -> set final value from tmp
Sorry.. forgot it: set idle callback at "hide" emission.
--
Artur
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]