Re: [gtk-list] Dialog Boxes - help




On Wed, 29 Sep 1999, Mark Volpe wrote:
> I'm writing a function that pops up a modal dialog with some
> text and buttons ( a la the Windows MessageBox function ). By itself
> it works fine, but what do I need to do to make sure it interfaces
> correctly with its parent window? I need to prevent the parent window
> from receiving delete events or else it wreaks
> havoc on my application. Here is what I have so far:
>

You can't really prevent delete events; you can set a hint that you don't
want them but some window managers (Enlightenment for example) ignore it.
I'm not sure how to set the hint, maybe someone else could post.

The way to handle this is to connect a delete_event handler which does
nothing and returns TRUE, preventing the default gtk_widget_destroy()
action. 
 
> guint message_box(GtkWidget *parent, ...)
> {
> 	GtkWidget *dialog;
> 	...
> 
> 	dialog=gtk_dialog_new();
> 
> 	gtk_widget_set_parent(dialog, parent);
> 
> 	/* To which GTK+ responds:
> 
> 	Gtk-CRITICAL **: file gtkwidget.c: line 3308 (gtk_widget_set_parent):
> assertion
> 	`!GTK_WIDGET_TOPLEVEL (widget)' failed.  */
> 

You don't want to call gtk_widget_set_parent(), it is an internal
function related to containers-children.

> 	gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
> 

This is what you do want.

> 	gtk_widget_show(dialog);
> 	gtk_grab_add(dialog);
>

gtk_window_set_modal() is slightly better than gtk_grab_add() here.
 	
> 	gtk_main();	/* Wait for user to click a button */
> 	
> 	/* Signal handler calls gtk_grab_remove(dialog),
> gtk_widget_destroy(dialog), and
> 	gtk_main_quit(), and sets up the return value */
> 

Just be sure you _always_ call gtk_main_quit() when the dialog closes, and
that you _never_ call gtk_main_quit() when the dialog didn't close, or you
have a mess on your hands. This is tricky to get right; GnomeDialog does
it for you. :-)

Havoc




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