Replace Tmem_nasm.asm with C++ code. Patch by pyro.
[Glide64.git] / messagebox.c
blobfdfd7f8c4fef1bceba6eff3fd9433c84e91f6f93
1 /***************************************************************************
2 messagebox.c - description
3 -------------------
4 begin : Tue Nov 12 2002
5 copyright : (C) 2002 by blight
6 email : blight@Ashitaka
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "messagebox.h"
19 #include "support.h"
21 #include <gtk/gtk.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 // include icons
27 #include "icons/messagebox-error.xpm"
28 #include "icons/messagebox-info.xpm"
29 #include "icons/messagebox-quest.xpm"
30 #include "icons/messagebox-warn.xpm"
32 static gint delete_question_event(GtkWidget *widget, GdkEvent *event, gpointer data)
34 return TRUE; // undeleteable
37 static void
38 button1_clicked( GtkWidget *widget, gpointer data )
40 int *ret = (int *)data;
42 *ret = 1;
45 static void
46 button2_clicked( GtkWidget *widget, gpointer data )
48 int *ret = (int *)data;
50 *ret = 2;
53 static void
54 button3_clicked( GtkWidget *widget, gpointer data )
56 int *ret = (int *)data;
58 *ret = 3;
61 int
62 messagebox( const char *title, int flags, const char *fmt, ... )
64 va_list ap;
65 char buf[2049];
66 int ret = 0;
68 GtkWidget *dialog;
69 GtkWidget *hbox;
70 GtkWidget *icon = NULL;
71 GtkWidget *label;
72 GtkWidget *button1, *button2 = NULL, *button3 = NULL;
74 va_start( ap, fmt );
75 vsnprintf( buf, 2048, fmt, ap );
76 va_end( ap );
78 // check flags
79 switch( flags & 0x000000FF )
81 case MB_ABORTRETRYIGNORE:
82 button1 = gtk_button_new_with_label( "Abort" );
83 button2 = gtk_button_new_with_label( "Retry" );
84 button3 = gtk_button_new_with_label( "Ignore" );
85 break;
87 case MB_CANCELTRYCONTINUE:
88 button1 = gtk_button_new_with_label( "Cancel" );
89 button2 = gtk_button_new_with_label( "Retry" );
90 button3 = gtk_button_new_with_label( "Continue" );
91 break;
93 case MB_OKCANCEL:
94 button1 = gtk_button_new_with_label( "Ok" );
95 button2 = gtk_button_new_with_label( "Cancel" );
96 break;
98 case MB_RETRYCANCEL:
99 button1 = gtk_button_new_with_label( "Retry" );
100 button2 = gtk_button_new_with_label( "Cancel" );
101 break;
103 case MB_YESNO:
104 button1 = gtk_button_new_with_label( "Yes" );
105 button2 = gtk_button_new_with_label( "No" );
106 break;
108 case MB_YESNOCANCEL:
109 button1 = gtk_button_new_with_label( "Yes" );
110 button2 = gtk_button_new_with_label( "No" );
111 button3 = gtk_button_new_with_label( "Cancel" );
112 break;
114 case MB_OK:
115 default:
116 button1 = gtk_button_new_with_label( "Ok" );
119 dialog = gtk_dialog_new();
120 gtk_container_set_border_width( GTK_CONTAINER(dialog), 10 );
121 gtk_window_set_title( GTK_WINDOW(dialog), title );
122 gtk_window_set_policy( GTK_WINDOW(dialog), 0, 0, 0 );
123 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
124 GTK_SIGNAL_FUNC(delete_question_event), (gpointer)NULL );
126 hbox = gtk_hbox_new( FALSE, 5 );
127 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 0 );
128 gtk_widget_show( hbox );
130 // icon
131 switch( flags & 0x00000F00 )
133 case MB_ICONWARNING:
134 icon = create_pixmap_d( dialog, messagebox_warn_xpm );
135 break;
137 case MB_ICONINFORMATION:
138 icon = create_pixmap_d( dialog, messagebox_info_xpm );
139 break;
141 case MB_ICONQUESTION:
142 icon = create_pixmap_d( dialog, messagebox_quest_xpm );
143 break;
145 case MB_ICONERROR:
146 icon = create_pixmap_d( dialog, messagebox_error_xpm );
147 break;
150 if( icon )
152 gtk_box_pack_start( GTK_BOX(hbox), icon, FALSE, FALSE, 0 );
153 gtk_widget_show( icon );
156 label = gtk_label_new( buf );
157 gtk_box_pack_start( GTK_BOX(hbox), label, TRUE, TRUE, 0 );
158 gtk_widget_show( label );
160 if( button1 )
162 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->action_area), button1, TRUE, TRUE, 0 );
163 gtk_widget_show( button1 );
164 gtk_signal_connect( GTK_OBJECT(button1), "clicked",
165 GTK_SIGNAL_FUNC(button1_clicked), (gpointer)&ret );
168 if( button2 )
170 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->action_area), button2, TRUE, TRUE, 0 );
171 gtk_widget_show( button2 );
172 gtk_signal_connect( GTK_OBJECT(button2), "clicked",
173 GTK_SIGNAL_FUNC(button2_clicked), (gpointer)&ret );
175 if( button3 )
177 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->action_area), button3, TRUE, TRUE, 0 );
178 gtk_widget_show( button3 );
179 gtk_signal_connect( GTK_OBJECT(button3), "clicked",
180 GTK_SIGNAL_FUNC(button3_clicked), (gpointer)&ret );
183 gtk_widget_show( dialog );
185 while( !ret )
186 if( gtk_main_iteration() )
187 break;
189 gtk_widget_destroy( dialog );
191 return ret;