/* Copyright (C) 2001-2002 Kenichi Suto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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 "defs.h" #include "global.h" static void ok_warning(GtkWidget *widget, gpointer *data); GtkWidget *dialog; GtkWidget *warningDlg; void center_dialog(GtkWidget *window, GtkWidget *dialog){ gint window_x, window_y; gint window_width, window_height; gint dialog_x, dialog_y; gint dialog_width, dialog_height; gdk_window_get_root_origin(window->window, &window_x, &window_y); window_width = window->allocation.width; window_height = window->allocation.height; dialog_width = dialog->allocation.width; dialog_height = dialog->allocation.height; if((window_width <= dialog_width) || (window_height <= dialog_height)) return; dialog_x = window_x + (window_width - dialog_width) / 2; dialog_y = window_y + (window_height - dialog_height) / 2; gtk_window_reposition(GTK_WINDOW(dialog), dialog_x, dialog_y); } void warning(char *message){ GtkWidget *button; GtkWidget *label; GtkWidget *messageBox; warningDlg = gtk_dialog_new(); button = gtk_button_new_with_label("OK"); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (warningDlg)->action_area), button, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (ok_warning), (gpointer)"OK"); gtk_widget_show (button); // gtk_container_border_width(GTK_CONTAINER (GTK_DIALOG (warningDlg)->vbox), 5;) messageBox = gtk_vbox_new(FALSE,0); gtk_container_border_width(GTK_CONTAINER (messageBox), 10); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (warningDlg)->vbox), messageBox, TRUE,TRUE, 0); gtk_widget_show(messageBox); label = gtk_label_new (message); gtk_box_pack_start (GTK_BOX (messageBox), label, TRUE, TRUE, 0); gtk_widget_show (label); gtk_widget_show (warningDlg); center_dialog(window, warningDlg); gtk_grab_add(warningDlg); } static void ok_warning(GtkWidget *widget, gpointer *data){ gtk_grab_remove(warningDlg); gtk_widget_destroy(warningDlg); } DialogButtons *g_b; static void confirm_pushed(GtkWidget *widget, gpointer *data){ DialogButtons *b; int num; b = (DialogButtons *)gtk_object_get_user_data (GTK_OBJECT(dialog)); num = (int)data; b[num].callback(); gtk_grab_remove(dialog); gtk_widget_destroy(dialog); } void confirm(char *message, DialogButtons *b, int count){ GtkWidget *button; GtkWidget *label; int i; dialog = gtk_dialog_new(); gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), 10); for(i=0;iaction_area), button, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (confirm_pushed), (gpointer)i); gtk_widget_show (button); } label = gtk_label_new (message); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE,TRUE, 0); gtk_widget_show (label); gtk_widget_show (dialog); center_dialog(window, dialog); gtk_grab_add(dialog); gtk_object_set_user_data(GTK_OBJECT(dialog), b); }