/* gmysql -- a graphical frontend to MySQL databases Copyright (C) 1998, 1999 Stephen R. Dodd This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "msgbox.h" static void msg_box_done( GtkWidget *widget, gpointer data ); static void msg_box_destroyed( GtkWidget *widget, gpointer data ); static gint msg_box_key_pressed( GtkWidget *widget, GdkEventKey *event ); MsgBox *msg_box_new( gchar *message ) { MsgBox *msg_box; GtkWidget *label, *dialog, *button; msg_box = g_new( MsgBox, 1 ); dialog = msg_box->dialog = gtk_dialog_new(); gtk_signal_connect( GTK_OBJECT( dialog ), "destroy", GTK_SIGNAL_FUNC( msg_box_destroyed ), msg_box ); gtk_signal_connect( GTK_OBJECT( dialog ), "key_press_event", GTK_SIGNAL_FUNC( msg_box_key_pressed ), NULL ); label = gtk_label_new( message ); gtk_misc_set_padding( GTK_MISC( label ), 5, 5 ); gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog )->vbox ), label, TRUE, TRUE, 0 ); gtk_widget_show( label ); button = gtk_button_new_with_label( "Dismiss" ); GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT ); gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog )->action_area ), button, TRUE, FALSE, 5 ); gtk_widget_grab_default( button ); /* must do after packing but before showing */ gtk_widget_show( button ); gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( msg_box_done ), msg_box ); gtk_widget_grab_focus( button ); #if !(CONFIG_GTK_MAJOR==1 && CONFIG_GTK_MINOR==0) gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE ); #endif /* not GTK 1.0 */ return msg_box; } void msg_box_show( MsgBox *msg_box ) { gtk_widget_show( msg_box->dialog ); gtk_widget_grab_focus( msg_box->dialog ); } void msg_box_done( GtkWidget *widget, gpointer data ) { MsgBox *msg_box; msg_box = MSG_BOX(data); gtk_widget_destroy( msg_box->dialog ); } gint msg_box_key_pressed( GtkWidget *widget, GdkEventKey *event ) { if( event->keyval == GDK_Escape ) gtk_widget_destroy( widget ); return FALSE; } void msg_box_destroyed( GtkWidget *widget, gpointer data ) { g_free( data ); }