Entry widget as a menu item not editable help?
- From: Kerry Keal <needles industrialmusic com>
- To: gtk-list gnome org
- Subject: Entry widget as a menu item not editable help?
- Date: 21 Mar 2002 23:54:51 -0800
Hi,
I'm using gtk+ 1.2.10. I'm trying to create a menu item that contains
an entry widget. I'm able to put the entry widget into the menu, except
it is not editable and does not give callbacks. Could someone please
help? Below, I created a small sample program that can be compiled with:
gcc -Wall `pkg-config gtk+ --cflags --libs` main.c
Any help appreciated.
Regards,
Kerry
-----Sample Code Below----
#include <gtk/gtk.h>
#include <stdio.h>
static void entry_CB( GtkWidget *widget, gpointer data )
{
printf("entry callback\n");
}
static void label_CB( GtkWidget *widget, gpointer data )
{
printf("label callback\n");
}
int main(int argc, char *argv[])
{
GtkWidget *entry_item,*label_item,*menu;
GtkWidget *entryW,*menu_bar,*top_item,*vbox;
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize (GTK_WIDGET(window), 300, 200);
menu = gtk_menu_new ();
label_item = gtk_menu_item_new_with_label("label");
entry_item = gtk_menu_item_new();
gtk_widget_show(label_item);
gtk_widget_show(entry_item);
gtk_signal_connect (GTK_OBJECT (label_item), "activate",
GTK_SIGNAL_FUNC (label_CB),
NULL);
/* You can't type in this entry widget or get a callback */
entryW = gtk_entry_new();
gtk_widget_show(entryW);
gtk_entry_set_max_length(GTK_ENTRY(entryW),7);
gtk_editable_set_editable(GTK_EDITABLE(entryW),TRUE);
gtk_signal_connect(GTK_OBJECT(entryW), "activate",
GTK_SIGNAL_FUNC(entry_CB),
NULL);
gtk_container_add(GTK_CONTAINER(entry_item),entryW);
gtk_menu_append (GTK_MENU (menu), label_item);
gtk_menu_append (GTK_MENU (menu), entry_item);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
menu_bar = gtk_menu_bar_new();
gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 2);
gtk_widget_show (menu_bar);
top_item = gtk_menu_item_new_with_label ("Head");
gtk_widget_show (top_item);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (top_item), menu);
gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), top_item);
gtk_widget_show (window);
gtk_main ();
return 0;
}
--
Milhouse: We've got to spread this stuff around. Let's put it on the
internet!
Bart: No we've got to reach people whose opinion actually matters.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]