1 /*
2 **
3 ** info.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 **
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with GNU gv; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ** Boston, MA 02111-1307, USA.
21 **
22 ** Author: Johannes Plass (plass@thep.physik.uni-mainz.de)
23 ** Department of Physics
24 ** Johannes Gutenberg-University
25 ** Mainz, Germany
26 **
27 ** Jose E. Marchesi (jemarch@gnu.org)
28 ** GNU Project
29 **
30 */
31 #include "ac_config.h"
32
33 /*
34 #define MESSAGES
35 */
36 #include "message.h"
37
38 #include "config.h"
39 #ifdef HAVE_XAW3D_INTERNATIONAL
40 #include "VlistP.h"
41 #endif
42
43 #include <stdio.h>
44 #include <stdlib.h>
45
46 #include "paths.h"
47 #include INC_X11(Intrinsic.h)
48 #include INC_X11(StringDefs.h)
49 #include INC_XAW(Form.h)
50 #include INC_XAW(AsciiText.h)
51 #include INC_X11(Shell.h)
52 #include "Button.h"
53
54 /*### Application dependencies ##############################################*/
55
56 #define INFO_TOPLEVEL toplevel
57 #define INFO_APPLIC_CONTEXT app_con
58 #define INFO_POPUP infopopup
59 #define INFO_POPUP_NAME "infoPopup"
60
61 #include "types.h"
62 #include "popup.h"
63 #include "info.h"
64 #include "main_resources.h"
65 #include "main_globals.h"
66
67 /*### Global Variables ######################################################*/
68
69 static Widget infoform;
70 static Widget infodismiss;
71 static Widget infotext;
72 static Bool infoPopupCreated = False;
73 static Bool infoPopupVisible = False;
74 static int info_length;
75
FontSetWidth(XFontSet fnt)76 static int FontSetWidth( XFontSet fnt ) {
77 XRectangle ink_array_return, logical_array_return;
78 XRectangle overall_ink_return, overall_logical_return;
79 int num_chars_return;
80 XmbTextPerCharExtents( fnt, "A", 1,
81 &ink_array_return,
82 &logical_array_return, 1,
83 &num_chars_return,
84 &overall_ink_return,
85 &overall_logical_return );
86 return( overall_logical_return.width );
87 }
88 #define FontSetHeight(fnt) (XExtentsOfFontSet(fnt)->max_logical_extent.height)
89
90 /*###############################################################################
91 cb_popupInfoPopup
92 ###############################################################################*/
93
cb_popupInfoPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)94 void cb_popupInfoPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
95 {
96 BEGINMESSAGE(cb_popupInfoPopup)
97 if (!infoPopupCreated) { makeInfoPopup(); }
98 if (infoPopupVisible==True) {INFMESSAGE(InfoPopup already up) ENDMESSAGE(popupInfoPopup) return; }
99 /* Strange, the whole application gets stuck if we do the following.
100 Precisely, the XtSetArg of rootX,rootY in positionPopup
101 never comes back ....
102
103 positionPopup(infopopup,2,INFO_TOPLEVEL,50,50, 1,1);
104 */
105 XtPopup(infopopup, XtGrabNone);
106 infoPopupVisible=True;
107 ENDMESSAGE(cb_popupInfoPopup)
108 }
109
110 /*###############################################################################
111 cb_popdownInfoPopup
112 ###############################################################################*/
113
cb_popdownInfoPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)114 void cb_popdownInfoPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
115 {
116 BEGINMESSAGE(cb_popdownInfoPopup)
117 if (infoPopupCreated && infoPopupVisible) {
118 XtPopdown(infopopup);
119 infoPopupVisible = False;
120 }
121 ENDMESSAGE(cb_popdownInfoPopup)
122 }
123
124 /*###############################################################################
125 cb_appendInfoPopup
126 ###############################################################################*/
127
cb_appendInfoPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data)128 void cb_appendInfoPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data)
129 {
130 Arg args[5];
131 Cardinal n;
132 XawTextBlock message_block;
133 int skipErrors;
134
135 BEGINMESSAGE(cb_appendInfoPopup)
136 SMESSAGE((char*)call_data)
137 if (!infoPopupCreated) { makeInfoPopup(); }
138 message_block.firstPos = 0;
139 message_block.length = strlen(call_data);
140 message_block.ptr = call_data;
141 message_block.format = FMT8BIT;
142
143 XawTextDisableRedisplay(infotext);
144 n=0;
145 XtSetArg(args[n], XtNeditType, XawtextAppend); n++;
146 XtSetValues(infotext,args,n);
147 XawTextReplace(infotext, info_length, info_length, &message_block);
148 n=0;
149 XtSetArg(args[0], XtNeditType, XawtextRead); n++;
150 XtSetArg(args[1], XtNinsertPosition, info_length); n++;
151 XtSetValues(infotext,args,n);
152 XawTextEnableRedisplay(infotext);
153
154 info_length = info_length + message_block.length;
155
156 skipErrors = gv_infoSkipErrors;
157 if (gv_infoSkipErrors)
158 if (strstr((char*)call_data, "Error:") || strstr((char*)call_data, "ERROR:") || strstr((char*)call_data, "error:"))
159 --gv_infoSkipErrors;
160
161 if (!infoPopupVisible && gv_infoVerbose && !skipErrors)
162 if (gv_infoVerbose == 2 || strstr((char*)call_data, "Error:") || strstr((char*)call_data, "ERROR:") || strstr((char*)call_data, "error:"))
163 cb_popupInfoPopup((Widget)NULL,(XtPointer)NULL,(XtPointer)NULL);
164 ENDMESSAGE(cb_appendInfoPopup)
165 }
166
167 /*###############################################################################
168 cb_resetInfoPopup
169 ###############################################################################*/
170
cb_resetInfoPopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)171 void cb_resetInfoPopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
172 {
173 Arg args[5];
174 Cardinal n;
175 XawTextBlock message_block;
176
177 BEGINMESSAGE(resetInfoPopup)
178 if ((!infoPopupCreated) || (info_length == 0)) {
179 INFMESSAGE(nothing to do) ENDMESSAGE(resetInfoPopup) return;
180 }
181
182 n=0;
183 XtSetArg(args[n], XtNeditType, XawtextEdit); n++;
184 XtSetArg(args[n], XtNinsertPosition,1); n++;
185 XtSetValues(infotext, args,n);
186 message_block.length = 0;
187 XawTextReplace(infotext, 0, info_length, &message_block);
188 info_length = 0;
189 n=0;
190 XtSetArg(args[0], XtNeditType, XawtextRead); n++;
191 XtSetValues(infotext,args,n);
192
193 ENDMESSAGE(resetInfoPopup)
194 }
195
196 /*###############################################################################
197 makeInfoPopup
198 ###############################################################################*/
199
makeInfoPopup(void)200 void makeInfoPopup(void)
201 {
202 Arg args[12];
203 Cardinal n;
204 Dimension bottomMargin, leftMargin, rightMargin, topMargin;
205 Dimension width, height;
206 #ifdef HAVE_XAW3D_INTERNATIONAL
207 XFontSet fontset;
208 #endif
209 XFontStruct *font;
210 #ifdef HAVE_XAW3D_INTERNATIONAL
211 VlistWidget vw;
212 #endif
213
214 BEGINMESSAGE(makeInfoPopup)
215
216 n=0;
217 INFO_POPUP = XtCreatePopupShell(INFO_POPUP_NAME,topLevelShellWidgetClass,INFO_TOPLEVEL,args,n);
218
219 infoform = XtCreateManagedWidget("form", formWidgetClass,INFO_POPUP,args,n);
220 n=0;
221 XtSetArg(args[n], XtNfromVert,NULL); n++;
222 XtSetArg(args[n], XtNfromHoriz,NULL); n++;
223 XtSetArg(args[n], XtNtop, XtChainTop); n++;
224 XtSetArg(args[n], XtNbottom, XtChainBottom); n++;
225 XtSetArg(args[n], XtNleft, XtChainLeft); n++;
226 XtSetArg(args[n], XtNright, XtChainRight); n++;
227 XtSetArg(args[n], XtNscrollHorizontal, XawtextScrollWhenNeeded); n++;
228 XtSetArg(args[n], XtNscrollVertical, XawtextScrollWhenNeeded); n++;
229 XtSetArg(args[n], XtNdisplayCaret, False); n++;
230 infotext = XtCreateManagedWidget("text", asciiTextWidgetClass,infoform,args,n);
231
232 n=0;
233 XtSetArg(args[n], XtNfromVert, infotext); n++;
234 XtSetArg(args[n], XtNfromHoriz,NULL); n++;
235 XtSetArg(args[n], XtNtop, XtChainBottom); n++;
236 XtSetArg(args[n], XtNbottom, XtChainBottom); n++;
237 XtSetArg(args[n], XtNleft, XtChainLeft); n++;
238 XtSetArg(args[n], XtNright, XtChainRight); n++;
239 infodismiss = XtCreateManagedWidget("dismiss", buttonWidgetClass,infoform,args,n);
240 #ifdef HAVE_XAW3D_INTERNATIONAL
241 vw = (VlistWidget)infodismiss;
242 #endif
243 XtAddCallback(infodismiss, XtNcallback, cb_popdownInfoPopup,NULL);
244 XtInstallAccelerators(infoform, infodismiss);
245 XtInstallAccelerators(infotext, infodismiss);
246
247 n=0;
248 #ifdef HAVE_XAW3D_INTERNATIONAL
249 if( vw->simple.international == True ) {
250 XtSetArg(args[n], XtNfontSet, &fontset); n++;
251 } else {
252 #endif
253 XtSetArg(args[n], XtNfont, &font); n++;
254 #ifdef HAVE_XAW3D_INTERNATIONAL
255 }
256 #endif
257 XtSetArg(args[n], XtNbottomMargin, &bottomMargin); n++;
258 XtSetArg(args[n], XtNleftMargin, &leftMargin); n++;
259 XtSetArg(args[n], XtNrightMargin, &rightMargin); n++;
260 XtSetArg(args[n], XtNtopMargin, &topMargin); n++;
261 XtGetValues(infotext,args,n);
262
263 #ifdef HAVE_XAW3D_INTERNATIONAL
264 if( vw->simple.international == True ) {
265 width = FontSetWidth(fontset) * 80 + leftMargin + rightMargin;
266 height = FontSetHeight(fontset) * 22 + topMargin + bottomMargin;
267 } else {
268 #endif
269 width = font->max_bounds.width * 80 + leftMargin + rightMargin;
270 height = (font->ascent + font->descent) * 22 + topMargin + bottomMargin;
271 #ifdef HAVE_XAW3D_INTERNATIONAL
272 }
273 #endif
274 n=0;
275 XtSetArg(args[0], XtNwidth, width); n++;
276 XtSetValues(infodismiss, args,n);
277 XtSetArg(args[1], XtNheight, height); n++;
278 XtSetValues(infotext,args,n);
279
280 XtRealizeWidget(INFO_POPUP);
281 info_length=0;
282
283 XSetWMProtocols(XtDisplay(INFO_POPUP),XtWindow(INFO_POPUP),&wm_delete_window,1);
284
285 infoPopupCreated=True;
286 infoPopupVisible=False;
287 ENDMESSAGE(makeInfoPopup)
288 }
289