tooltips interferes with menu popup
- From: "Edward A. Falk" <falk efalk org>
- To: gtk-list gnome org
- Subject: tooltips interferes with menu popup
- Date: Thu, 6 Jun 2002 22:58:25 -0700
Hi; anyone notice this problem before? The menu.c sample program
gives code to pop up a window from the button press callback. If
you attach a tooltip to the button, the menu no longer works
correctly.
Sample code follows:
/* example-start menu menu.c */
#include <stdio.h>
#include <gtk/gtk.h>
static gint button_press (GtkWidget *, GdkEvent *);
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *menu;
GtkWidget *menu_items;
GtkWidget *vbox;
GtkWidget *button;
GtkTooltips *tips ;
char buf[128];
int i;
gtk_init (&argc, &argv);
tips = gtk_tooltips_new() ;
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize (GTK_WIDGET (window), 200, 100);
gtk_window_set_title (GTK_WINDOW (window), "GTK Menu Test");
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_main_quit, NULL);
menu = gtk_menu_new ();
for (i = 0; i < 3; i++)
{
sprintf (buf, "Test-undermenu - %d", i);
menu_items = gtk_menu_item_new_with_label (buf);
gtk_menu_append (GTK_MENU (menu), menu_items);
gtk_widget_show (menu_items);
}
/* A vbox to put a menu and a button in: */
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
/* Create a button to which to attach menu as a popup */
button = gtk_button_new_with_label ("press me");
gtk_signal_connect_object (GTK_OBJECT (button), "event",
GTK_SIGNAL_FUNC (button_press), GTK_OBJECT (menu));
gtk_box_pack_end (GTK_BOX (vbox), button, TRUE, TRUE, 2);
/* This line breaks the popup menu */
gtk_tooltips_set_tip(tips, button, "press this button", NULL) ;
gtk_widget_show (button);
/* always display the window as the last step so it all splashes on
* the screen at once. */
gtk_widget_show (window);
gtk_main ();
return(0);
}
/* Respond to a button-press by posting a menu passed in as widget.
*
* Note that the "widget" argument is the menu being posted, NOT
* the button that was pressed.
*/
static gint button_press( GtkWidget *widget,
GdkEvent *event )
{
if (event->type == GDK_BUTTON_PRESS) {
GdkEventButton *bevent = (GdkEventButton *) event;
gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
/* Tell calling code that we have handled this event; the buck
* stops here. */
return TRUE;
}
/* Tell calling code that we have not handled this event; pass it on. */
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]