Re: Accelerators and gtk_grab_add



Tim Janik wrote:
> 
> On 24 Jul 2000, Havoc Pennington wrote:
> 
> >
> > Matt Carlson <mindbender@lokigames.com> writes:
> > > Hi folks.  I'm having trouble with menu accelerators whenever I
> > > bring up a modal dialog.  I tried to disable them through the use of
> > > gtk_grab_add(), but accelerators don't seem to be affected by this
> > > function.  Is there a way to do this?  Thanks in advance for your
> > > time.
> > >
> >
> > Yikes, that seems like a pretty serious bug. CC'd Tim to see if he has
> > comments.
> 
> i'm not able to reproduce this, and i couldn't imagine how
> accelerators could get delivered to windows while there's
> a modal dialog popped up (dialog modality does involve gtk_grab_add()
> btw).

Yah, I know.  If fact, I don't even bother with the gtk_window_set_modal()
function.

> so if you could send me a short test case matt, that'd be aprechiated.

I've attached it.  I've programmatically set the menuitem accelerator to the
'N' key...for convenience.  Just run the program, select the "Do Something"
menu option, move the window out of the way, move the cursor over the main
window, use the 'N' key to bring up another dialog (which shouldn't happen).
Thanks for your help. :)


===============================================================================
Matt Carlson                                      250 El Camino Real, Suite 100
Programmer                                                     Tustin, CA 92780
Loki Entertainment Software                http://www.lokigames.com/~mindbender
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>


gint CloseWindow( void )
{
	gtk_main_quit();

	return TRUE;
}


static gint MenuItemEventHandler( void )
{
	/* Create a new dialog and display it. */
	GtkWidget * window = gtk_window_new( GTK_WINDOW_DIALOG );
	gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_CENTER );
	gtk_widget_set_usize( window, 100, 100 );

	GtkWidget * vbox = gtk_vbox_new( FALSE, 0 );
	gtk_container_add( GTK_CONTAINER(window), vbox );
	gtk_widget_show( vbox );

	GtkWidget * label = gtk_label_new( "Main dialog area" );
	gtk_box_pack_start( GTK_BOX(vbox), label, TRUE, FALSE, 0 );
	gtk_widget_show( label );

	GtkWidget * button = gtk_button_new_with_label( "  OK  " );
	gtk_box_pack_start( GTK_BOX(vbox), button, TRUE, FALSE, 0 );
	gtk_signal_connect( GTK_OBJECT(button), "clicked",
								 GTK_SIGNAL_FUNC(CloseWindow), NULL );
	gtk_widget_show( button );

	gtk_signal_connect( GTK_OBJECT(window), "delete_event",
							  GTK_SIGNAL_FUNC(CloseWindow), NULL );
	gtk_widget_show( window );

	/* Basically make it a modal dialog */
	gtk_grab_add( window );

	gtk_main();

	gtk_grab_remove( window );

	/* Kill it! */
	gtk_widget_destroy( window );
	gtk_main_iteration();

	/* Don't propagate the event any further */
	return TRUE;
}


int main( int argc, char ** argv )
{
	gtk_init( &argc, &argv );

	GtkWidget * window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
	gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_CENTER );
	gtk_widget_set_usize( window, 200, 200 );

	GtkWidget * vbox = gtk_vbox_new( FALSE, 0 );
	gtk_container_add( GTK_CONTAINER(window), vbox );
	gtk_widget_show( vbox );

	GtkWidget * menubar = gtk_menu_bar_new();
	gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
	gtk_widget_show( menubar );

	GtkWidget * menu = gtk_menu_new();

	GtkWidget * majormenu = gtk_menu_item_new_with_label("File");
	gtk_menu_bar_append( GTK_MENU_BAR(menubar), majormenu );
	gtk_widget_show( majormenu );

	GtkWidget * submenu = gtk_menu_new();
	gtk_menu_item_set_submenu( GTK_MENU_ITEM(majormenu), submenu );

	GtkWidget * menuitem = gtk_menu_item_new_with_label( "Do Something" );
	gtk_menu_append( GTK_MENU(submenu), menuitem );
	gtk_signal_connect( GTK_OBJECT(menuitem), "activate",
							  GTK_SIGNAL_FUNC(MenuItemEventHandler), NULL );
	/* Just for kicks let's add an accelerator programmatically */
	gtk_widget_add_accelerator( menuitem, "activate",
										 gtk_accel_group_get_default(),
										 GDK_N, 0, GTK_ACCEL_VISIBLE );
	gtk_widget_show( menuitem );

	gtk_signal_connect( GTK_OBJECT(window), "delete_event",
							  GTK_SIGNAL_FUNC(CloseWindow), NULL );
	gtk_widget_show( window );

	gtk_main();

	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]