wmclockmon: rename `DFLAGS` `debug_CFLAGS`
[dockapps.git] / yawmppp / src / gtksetup / msgbox.c
blob83446f58807692d1591076d2e48ccc093aeb3f63
1 /*
3 Message Box Composite Widget
4 (currently included in various software packages)
5 Copyright (C) 1999-2000 Felipe Paulo Guazzi Bergo
6 bergo@seul.org
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <gtk/gtk.h>
28 #include "msgbox.h"
30 #include "bong.xpm"
31 #include "exclam.xpm"
32 #include "info.xpm"
33 #include "question.xpm"
35 /* PRIVATE */
37 void message_box_click_yes(GtkWidget *widget,gpointer data);
38 void message_box_click_no(GtkWidget *widget,gpointer data);
39 void message_box_click_cancel(GtkWidget *widget,gpointer data);
40 void message_box_click_ok(GtkWidget *widget,gpointer data);
41 gint immortal(GtkWidget *widget,GdkEvent *event,gpointer data);
43 struct msgbox_data {
44 gint answer_available;
45 MsgBoxResult answer;
46 } cmdata;
48 gchar ** mb_icons[5]={NULL,bong_xpm,info_xpm,exclam_xpm,question_xpm};
50 MsgBoxResult
51 message_box(GtkWindow *parent,char *txt,char *title,MsgBoxType mbt,MsgBoxIcon mbi)
53 GtkWidget *msgbox,*b[3],*lb,*tbl,*hs;
54 GdkBitmap *mask;
55 GdkPixmap *dqmark;
56 GtkWidget *tqmark;
57 GtkStyle *style;
58 int i,nb;
60 cmdata.answer_available=FALSE;
62 msgbox=gtk_window_new(GTK_WINDOW_DIALOG);
63 tbl=gtk_table_new(3,4,FALSE);
64 gtk_container_add(GTK_CONTAINER(msgbox),tbl);
65 gtk_window_set_title(GTK_WINDOW(msgbox),title);
66 if (parent!=NULL)
67 gtk_window_set_transient_for(GTK_WINDOW(msgbox),parent);
68 gtk_container_set_border_width(GTK_CONTAINER(msgbox),4);
69 gtk_window_set_position(GTK_WINDOW(msgbox),GTK_WIN_POS_CENTER);
70 gtk_window_set_policy(GTK_WINDOW(msgbox),TRUE,TRUE,TRUE);
71 gtk_widget_realize(msgbox);
73 style=gtk_widget_get_style(msgbox);
74 if (mbi!=MSGBOX_ICON_NONE) {
75 dqmark=gdk_pixmap_create_from_xpm_d(msgbox->window,&mask,
76 &style->bg[GTK_STATE_NORMAL],
77 mb_icons[mbi]);
78 tqmark=gtk_pixmap_new(dqmark,mask);
79 gtk_table_attach(GTK_TABLE(tbl),tqmark,0,1,0,1,GTK_FILL,GTK_FILL,5,5);
80 gtk_widget_show(tqmark);
83 lb=gtk_label_new(txt);
84 gtk_label_set_justify(GTK_LABEL(lb),GTK_JUSTIFY_LEFT);
85 gtk_table_attach(GTK_TABLE(tbl),lb,1,4,0,1,GTK_FILL,GTK_FILL,10,10);
86 gtk_widget_show(lb);
88 hs=gtk_hseparator_new();
89 gtk_table_attach(GTK_TABLE(tbl),hs,0,4,1,2,GTK_FILL,GTK_FILL,0,10);
90 gtk_widget_show(hs);
92 /* buttons */
94 switch(mbt) {
95 case MSGBOX_OK:
96 nb=1;
97 b[0]=gtk_button_new_with_label("OK");
98 gtk_signal_connect(GTK_OBJECT(b[0]),"clicked",
99 GTK_SIGNAL_FUNC(message_box_click_ok),NULL);
100 break;
101 case MSGBOX_OKCANCEL:
102 nb=2;
103 b[0]=gtk_button_new_with_label("OK");
104 gtk_signal_connect(GTK_OBJECT(b[0]),"clicked",
105 GTK_SIGNAL_FUNC(message_box_click_ok),NULL);
106 b[1]=gtk_button_new_with_label("Cancel");
107 gtk_signal_connect(GTK_OBJECT(b[1]),"clicked",
108 GTK_SIGNAL_FUNC(message_box_click_cancel),NULL);
109 break;
110 case MSGBOX_YESNO:
111 nb=2;
112 b[0]=gtk_button_new_with_label("Yes");
113 gtk_signal_connect(GTK_OBJECT(b[0]),"clicked",
114 GTK_SIGNAL_FUNC(message_box_click_yes),NULL);
115 b[1]=gtk_button_new_with_label("No");
116 gtk_signal_connect(GTK_OBJECT(b[1]),"clicked",
117 GTK_SIGNAL_FUNC(message_box_click_no),NULL);
118 break;
119 case MSGBOX_YESNOCANCEL:
120 nb=3;
121 b[0]=gtk_button_new_with_label("Yes");
122 gtk_signal_connect(GTK_OBJECT(b[0]),"clicked",
123 GTK_SIGNAL_FUNC(message_box_click_yes),NULL);
124 b[1]=gtk_button_new_with_label("No");
125 gtk_signal_connect(GTK_OBJECT(b[1]),"clicked",
126 GTK_SIGNAL_FUNC(message_box_click_no),NULL);
127 b[2]=gtk_button_new_with_label("Cancel");
128 gtk_signal_connect(GTK_OBJECT(b[2]),"clicked",
129 GTK_SIGNAL_FUNC(message_box_click_cancel),NULL);
130 break;
131 default:
132 nb=0;
135 for(i=0;i<nb;i++)
136 gtk_table_attach(GTK_TABLE(tbl),b[i],
137 4-nb+i,4-nb+i+1,
138 2,3,
139 GTK_FILL,
140 (i?GTK_SHRINK:GTK_FILL),2,2);
142 GTK_WIDGET_SET_FLAGS(b[0],GTK_CAN_DEFAULT);
143 gtk_widget_grab_default(b[0]);
145 for(i=0;i<nb;i++)
146 gtk_widget_show(b[i]);
148 gtk_signal_connect(GTK_OBJECT(msgbox),"delete_event",
149 GTK_SIGNAL_FUNC(immortal),NULL);
151 gtk_widget_show(tbl);
152 gtk_widget_show(msgbox);
153 gtk_grab_add(msgbox);
155 /* gtk_main MUST be running before message_box is called!!! */
156 while(!cmdata.answer_available)
157 gtk_main_iteration();
159 gtk_grab_remove(msgbox);
160 gtk_widget_destroy(msgbox);
162 return(cmdata.answer);
165 void message_box_click_yes(GtkWidget *widget,gpointer data) {
166 cmdata.answer=MSGBOX_R_YES;
167 cmdata.answer_available=TRUE;
170 void message_box_click_no(GtkWidget *widget,gpointer data) {
171 cmdata.answer=MSGBOX_R_NO;
172 cmdata.answer_available=TRUE;
175 void message_box_click_cancel(GtkWidget *widget,gpointer data) {
176 cmdata.answer=MSGBOX_R_CANCEL;
177 cmdata.answer_available=TRUE;
180 void message_box_click_ok(GtkWidget *widget,gpointer data) {
181 cmdata.answer=MSGBOX_R_OK;
182 cmdata.answer_available=TRUE;
185 gint immortal(GtkWidget *widget,GdkEvent *event,gpointer data) {
186 return TRUE;