Use of optionmenu's
- From: "Aslak Johansen"<cornersite crosswinds net>
- To: gtk-list redhat com
- Subject: Use of optionmenu's
- Date: Wed, 30 Jun 1999 19:39:49 +400
Subject: Use of optionmenu's
Hi ...
I am trying to figure out how to see which option is selected in an gtk_option_menu.
There must be a simple way to do so!
Lets take an example:
"
/* gtk3.c */
#include <gtk/gtk.h>
#include <stdio.h>
GtkWidget *window;
GtkWidget *box;
GtkWidget *quitbutton, *button;
GtkWidget *omenu, *menu;
GtkWidget *radiobox;
GSList *radiogroup = NULL;
GtkWidget *menuitem1, *menuitem2, *menuitem3;
gint destroyapp (GtkWidget *widget, gpointer gdata) {
g_print ("Quitting ...\n");
gtk_main_quit ();
return (FALSE);
}
void checkfunc (GtkWidget *widget, gpointer gdata) {
/* I know this don't work; What I don't know is how to make it work! */
/* The idea is to let the program output the state of omenu. */
if (GTK_TOGGLE_BUTTON (menuitem1)->active) {
printf (" menuitem1 is selected!\n\n");
}
if (GTK_TOGGLE_BUTTON (menuitem2)->active) {
printf (" menuitem2 is selected!\n\n");
}
if (GTK_TOGGLE_BUTTON (menuitem3)->active) {
printf (" menuitem3 is selected!\n\n");
}
}
int main (int argc, char *argv[]) {
gtk_init (&argc, &argv);
g_print ("Starting gtk3 test app ...\n\n");
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "test app3!");
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (destroyapp), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
box = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show (box);
quitbutton = gtk_button_new_with_label ("Quit");
gtk_box_pack_start (GTK_BOX (box), quitbutton, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (quitbutton), "clicked",
GTK_SIGNAL_FUNC (destroyapp), NULL);
gtk_widget_show (quitbutton);
omenu = gtk_option_menu_new ();
gtk_box_pack_start (GTK_BOX (box), omenu, FALSE, FALSE, 0);
menu = gtk_menu_new ();
radiobox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), radiobox, FALSE, FALSE, 0);
gtk_widget_show (radiobox);
menuitem1 = gtk_radio_menu_item_new_with_label (radiogroup, "menuitem1");
radiogroup = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem1));
gtk_menu_append (GTK_MENU (menu), menuitem1);
gtk_widget_show (menuitem1);
menuitem2 = gtk_radio_menu_item_new_with_label (radiogroup, "menuitem2");
radiogroup = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem2));
gtk_menu_append (GTK_MENU (menu), menuitem2);
gtk_widget_show (menuitem2);
menuitem3 = gtk_radio_menu_item_new_with_label (radiogroup, "menuitem3");
radiogroup = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem3));
gtk_menu_append (GTK_MENU (menu), menuitem3);
gtk_widget_show (menuitem3);
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
gtk_widget_show (omenu);
button = gtk_button_new_with_label ("Start");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (checkfunc), NULL);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
"
Can anybody help me? I have looked in the GTK tutorial (http://www.gtk.org/tutorial/)
and Eric Harlow's "Developing Linux Applications", so I'm a bit out of resources
for this question!
Many thanks,
Aslak
cornersite@crosswinds.net
http://www.crosswinds.net/denmark/~cornersite/
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]