/* 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 "qbox.h" static void q_box_done( GtkWidget *widget, gpointer data ); static void q_box_destroyed( GtkWidget *widget, gpointer data ); static gint q_box_key_pressed( GtkWidget *widget, GdkEventKey *event ); QBox *q_box_new( gchar *message, gchar *but0, gchar *but1 ) { QBox *q_box; GtkWidget *label, *dialog, *button; q_box = g_new( QBox, 1 ); dialog = q_box->dialog = gtk_dialog_new(); gtk_signal_connect( GTK_OBJECT( dialog ), "destroy", GTK_SIGNAL_FUNC( q_box_destroyed ), q_box ); gtk_signal_connect( GTK_OBJECT( dialog ), "key_press_event", GTK_SIGNAL_FUNC( q_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 ); gtk_box_set_homogeneous( GTK_BOX( GTK_DIALOG( dialog )->action_area ), TRUE ); q_box->but0 = button = gtk_button_new_with_label( but0 ); GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT ); /*gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog )->action_area ), button, TRUE, TRUE, 5 ); */gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->action_area ), button ); 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( q_box_done ), q_box ); q_box->but1 = button = gtk_button_new_with_label( but1 ); GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT ); /*gtk_box_pack_end( GTK_BOX( GTK_DIALOG( dialog )->action_area ), button, TRUE, TRUE, 5 ); */gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->action_area ), button ); gtk_widget_show( button ); gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( q_box_done ), q_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 q_box; } gint q_box_do_modal( QBox *q_box ) { gint res; gtk_widget_show( q_box->dialog ); gtk_widget_grab_focus( q_box->dialog ); gtk_main(); res = q_box->res; gtk_widget_destroy( q_box->dialog ); return res; } void q_box_done( GtkWidget *widget, gpointer data ) { QBox *q_box; q_box = Q_BOX(data); if( widget == q_box->but0 ) q_box->res = 0; else q_box->res = 1; gtk_main_quit(); } gint q_box_key_pressed( GtkWidget *widget, GdkEventKey *event ) { if( event->keyval == GDK_Escape ) gtk_widget_destroy( widget ); return FALSE; } void q_box_destroyed( GtkWidget *widget, gpointer data ) { g_free( data ); }