1 /*
2 **
3 ** confirm.c
4 **
5 ** Copyright (C) 1995, 1996 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
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 3 of the License, or
11 ** (at your option) any later version.
12 **
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.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING. If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author: Johannes Plass (plass@dipmza.physik.uni-mainz.de)
24 ** Department of Physic
25 ** Johannes Gutenberg-University
26 ** Mainz, Germany
27 **
28 ** Jose E. Marchesi (jemarch@gnu.org)
29 ** GNU Project
30 **
31 */
32 #include "ac_config.h"
33
34 #include "config.h"
35
36 #include <stdio.h>
37
38 /*
39 #define MESSAGES
40 */
41 #include "message.h"
42
43 #include "paths.h"
44 #include INC_X11(Intrinsic.h)
45 #include INC_X11(StringDefs.h)
46 #include INC_XAW(Label.h)
47 #include INC_X11(Shell.h)
48
49 #include "Aaa.h"
50 #include "Button.h"
51 #include "Ghostview.h"
52
53 #include "types.h"
54 #include "main_resources.h"
55 #include "main_globals.h"
56 #include "popup.h"
57 #include "widgets_misc.h"
58
59 /*### Application dependencies ##############################################*/
60
61 #define CONFIRM_TOPLEVEL toplevel
62 #define CONFIRM_POPUP_NAME "confirmPopup"
63 #define CONFIRM_POPUP confirmpopup
64
65 #include "confirm.h"
66
67 static Bool confirmPopupCreated = False;
68 static Bool confirmPopupVisible = False;
69 static Widget doneButton=NULL,cancelButton=NULL,confirmAaa=NULL;
70 static Widget message1=NULL,message2=NULL,message3=NULL;
71 static int preferedButton=0,initialButton=0;
72
73 /*########################################################
74 cb_popdownConfirmPopup
75 #########################################################*/
76
cb_popdownConfirmPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)77 void cb_popdownConfirmPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
78 {
79 BEGINMESSAGE(cb_popdownConfirmPopup)
80 if (confirmPopupVisible) {
81 XtPopdown(CONFIRM_POPUP);
82 confirmPopupVisible=False;
83 }
84 if (confirmPopupCreated==True) {
85 INFMESSAGE(destroying confirmpopup)
86 XtDestroyWidget(confirmpopup);
87 confirmpopup=NULL;
88 confirmPopupCreated = False;
89 message1=message2=message3=NULL;
90 }
91 ENDMESSAGE(cb_popdownConfirmPopup)
92 }
93
94 /*########################################################
95 cb_popupConfirmPopup
96 #########################################################*/
97
cb_popupConfirmPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)98 void cb_popupConfirmPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
99 {
100 BEGINMESSAGE(cb_popupConfirmPopup)
101 if (!confirmPopupVisible) {
102 if (!confirmPopupCreated) makeConfirmPopup();
103 if (initialButton==CONFIRM_BUTTON_DONE) preferedButton=CONFIRM_BUTTON_CANCEL;
104 else if (initialButton==CONFIRM_BUTTON_CANCEL) preferedButton=CONFIRM_BUTTON_DONE;
105 action_preferConfirmPopupButton(NULL, NULL, NULL, NULL);
106 popup_positionPopup(confirmpopup,viewFrame,POPUP_POSITION_POS,4,4);
107 XtPopup(CONFIRM_POPUP,XtGrabNone);
108 confirmPopupVisible=True;
109 }
110 ENDMESSAGE(cb_popupConfirmPopup)
111 }
112
113 /*########################################################
114 action_preferConfirmPopupButton
115 #########################################################*/
116
117 void
action_preferConfirmPopupButton(Widget w _GL_UNUSED,XEvent * event _GL_UNUSED,String * params _GL_UNUSED,Cardinal * num_params _GL_UNUSED)118 action_preferConfirmPopupButton(Widget w _GL_UNUSED, XEvent *event _GL_UNUSED, String *params _GL_UNUSED, Cardinal *num_params _GL_UNUSED)
119 {
120 Widget pref,pref_old;
121
122 BEGINMESSAGE(action_preferConfirmPopupButton)
123 if (preferedButton==CONFIRM_BUTTON_DONE) {
124 pref=cancelButton;
125 pref_old=doneButton;
126 preferedButton=CONFIRM_BUTTON_CANCEL;
127 } else {
128 pref=doneButton;
129 pref_old=cancelButton;
130 preferedButton=CONFIRM_BUTTON_DONE;
131 }
132 widgets_preferButton(pref,1);
133 widgets_preferButton(pref_old,0);
134 XtInstallAccelerators(confirmAaa,pref);
135 ENDMESSAGE(action_preferConfirmPopupButton)
136 }
137
138 /*########################################################
139 ConfirmPopupSetButton
140 #########################################################*/
141
ConfirmPopupSetButton(int button,XtCallbackProc callback)142 void ConfirmPopupSetButton(int button, XtCallbackProc callback)
143 {
144 Widget response=NULL;
145
146 BEGINMESSAGE(ConfirmPopupSetButton)
147 if (!confirmPopupCreated) makeConfirmPopup();
148 if (button&CONFIRM_BUTTON_DONE) response = doneButton;
149 else if (button&CONFIRM_BUTTON_CANCEL) response = cancelButton;
150
151 if (response && callback) {
152 XtRemoveAllCallbacks(response,XtNcallback);
153 XtAddCallback(response, XtNcallback,callback,NULL);
154 }
155 ENDMESSAGE(ConfirmPopupSetButton)
156 }
157
158 /*########################################################
159 ConfirmPopupSetMessage
160 #########################################################*/
161
ConfirmPopupSetMessage(String which,String message)162 void ConfirmPopupSetMessage(String which, String message)
163 {
164 Arg args[3];
165 Cardinal n;
166 char *name=NULL;
167 Widget *labelP = NULL;
168
169 BEGINMESSAGE(ConfirmPopupSetMessage)
170 if (!confirmPopupCreated) makeConfirmPopup();
171 if (!strcmp(which,"1")) { labelP = &message1; name="message1"; }
172 else if (!strcmp(which,"2")) { labelP = &message2; name="message2"; }
173 else if (!strcmp(which,"3")) { labelP = &message3; name="message3"; }
174 else {
175 ENDMESSAGE(ConfirmPopupSetMessage)
176 return;
177 }
178 if (message) {
179 n=0;
180 XtSetArg(args[n], XtNlabel, message); n++;
181 XtSetArg(args[n], XtNborderWidth, 0); n++;
182 if (!(*labelP))
183 *labelP=XtCreateManagedWidget(name,labelWidgetClass,confirmAaa, args, n);
184 else
185 XtSetValues(*labelP,args,n);
186 } else {
187 if (*labelP) {
188 n=0;
189 XtSetArg(args[n], XtNheight,0); n++;
190 XtSetValues(*labelP,args,n);
191 XtDestroyWidget(*labelP);
192 *labelP = NULL;
193 }
194 }
195 ENDMESSAGE(ConfirmPopupSetMessage)
196 }
197
198 /*########################################################
199 ConfirmPopupSetInitialButton
200 #########################################################*/
201
ConfirmPopupSetInitialButton(int button)202 void ConfirmPopupSetInitialButton(int button)
203 {
204 BEGINMESSAGE(ConfirmPopupSetInitialButton)
205 initialButton=button;
206 ENDMESSAGE(ConfirmPopupSetInitialButton)
207 }
208
209 /*########################################################
210 makeConfirmPopup
211 #########################################################*/
212
213 static char *tabTrans =
214 "\
215 <Key>Tab: GV_TogConfPrefBut()\
216 ";
217
makeConfirmPopup(void)218 void makeConfirmPopup(void)
219 {
220 Arg args[7];
221 Cardinal n;
222 static XtTranslations tab_trans=(XtTranslations)NULL;
223
224 BEGINMESSAGE(makeConfirmPopup)
225
226 n=0;
227 XtSetArg(args[n], XtNallowShellResize, True); n++;
228 CONFIRM_POPUP = XtCreatePopupShell(CONFIRM_POPUP_NAME,transientShellWidgetClass,CONFIRM_TOPLEVEL, args, n);
229
230 n=0;
231 XtSetArg(args[n], XtNresizeWidth, True); n++;
232 XtSetArg(args[n], XtNresizeHeight, True); n++;
233 confirmAaa = XtCreateManagedWidget("confirmAaa",aaaWidgetClass,CONFIRM_POPUP,args,n);
234
235 n=0;
236 doneButton=XtCreateManagedWidget("done",buttonWidgetClass,confirmAaa,args,n);
237 cancelButton=XtCreateManagedWidget("cancel",buttonWidgetClass,confirmAaa,args,n);
238
239 message1=message2=message3=NULL;
240
241 XtRealizeWidget(CONFIRM_POPUP);
242
243 XtSetKeyboardFocus(confirmAaa,confirmAaa);
244 if (!tab_trans) tab_trans=XtParseTranslationTable(tabTrans);
245 XtOverrideTranslations(confirmAaa,tab_trans);
246
247 XSetWMProtocols(XtDisplay(CONFIRM_POPUP),XtWindow(CONFIRM_POPUP),&wm_delete_window,1);
248 confirmPopupCreated=True;
249
250 ENDMESSAGE(makeConfirmPopup)
251 }
252