1 /*
2  * Author:      William Chia-Wei Cheng (bill.cheng@acm.org)
3  *
4  * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5  *
6  * This file may be distributed under the terms of the Q Public License
7  * as defined by Trolltech AS of Norway and appearing in the file
8  * LICENSE.QPL included in the packaging of this file.
9  *
10  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11  * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12  * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * @(#)$Header: /mm2/home/cvs/bc-src/tgif/setup.c,v 1.86 2011/06/02 17:35:50 cvsps Exp $
19  */
20 
21 #define _INCLUDE_FROM_SETUP_C_
22 
23 #include "tgifdefs.h"
24 #include "cmdids.h"
25 #include "expfdefs.h"
26 
27 #include "attr.e"
28 #include "auxtext.e"
29 #include "chat.e"
30 #include "choice.e"
31 #include "choose.e"
32 #include "cmd.e"
33 #include "color.e"
34 #include "cursor.e"
35 #include "cutpaste.e"
36 #include "dialog.e"
37 #include "drawing.e"
38 #include "dup.e"
39 #include "edit.e"
40 #include "exec.e"
41 #include "file.e"
42 #include "font.e"
43 #include "grid.e"
44 #include "help.e"
45 #include "imgproc.e"
46 #include "import.e"
47 #include "inmethod.e"
48 #include "mainloop.e"
49 #include "mainmenu.e"
50 #include "mark.e"
51 #include "markup.e"
52 #include "menu.e"
53 #include "miniline.e"
54 #include "move.e"
55 #include "msg.e"
56 #include "names.e"
57 #include "navigate.e"
58 #include "nkf.e"
59 #include "page.e"
60 #include "pattern.e"
61 #include "pin.e"
62 #include "poly.e"
63 #include "ps.e"
64 #include "raster.e"
65 #include "remote.e"
66 #include "ruler.e"
67 #include "scroll.e"
68 #include "select.e"
69 #include "setup.e"
70 #include "shape.e"
71 #include "shortcut.e"
72 #include "special.e"
73 #include "spline.e"
74 #include "stk.e"
75 #include "stretch.e"
76 #include "strtbl.e"
77 #include "tangram2.e"
78 #include "tdgtlist.e"
79 #include "text.e"
80 #include "tgcwheel.e"
81 #include "tginssym.e"
82 #include "tidget.e"
83 #include "util.e"
84 #include "version.e"
85 #include "wb.e"
86 #include "xbitmap.e"
87 #include "xpixmap.e"
88 #include "xprtfltr.e"
89 #include "z_intrf.e"
90 
91 #include "tgificon.xbm"
92 
93 #define DEF_VSBAR_H 64
94 #define DEF_HSBAR_W 128
95 
96 #define DRAW_WINDOW_W (5*ONE_INCH)
97 #define DRAW_WINDOW_H (4*ONE_INCH)
98 #define CHOICE_WINDOW_W (12*CHOICE_IMAGE_W)
99 #define CHOICE_WINDOW_H (CHOICE_IMAGE_H<<1)
100 #define VSBAR_H (DRAW_WINDOW_H+RULER_W+(BRDR_W<<1))
101 #define HSBAR_W 128
102 #define PAGE_DUMMY_WINDOW_W 3
103 #define PAGE_WINDOW_W (DRAW_WINDOW_W+RULER_W-HSBAR_W-PAGE_DUMMY_WINDOW_W)
104 #define COLOR_DUMMY_WINDOW_H 3
105 #define COLOR_WINDOW_H (DRAW_WINDOW_H+RULER_W-VSBAR_H-COLOR_DUMMY_WINDOW_H)
106 #define TITLE_WINDOW_W (DRAW_WINDOW_W+RULER_W+BRDR_W+SCROLLBAR_W+(BRDR_W<<1))
107 #define TITLE_WINDOW_H (MENU_IMAGE_H<<1)
108 #define MSG_WINDOW_W (TITLE_WINDOW_W-CHOICE_WINDOW_W-(BRDR_W<<1))
109 #define MSG_WINDOW_H (CHOICE_WINDOW_H)
110 #define ICON_WINDOW_W 64
111 #define ICON_WINDOW_H 64
112 #define MENUBAR_WINDOW_W (TITLE_WINDOW_W)
113 #define MENUBAR_WINDOW_H 20
114 #define USER_REDRAW_WINDOW_W 44
115 #define USER_REDRAW_WINDOW_H 20
116 #define STATUS_WINDOW_W (TITLE_WINDOW_W-USER_REDRAW_WINDOW_W-(BRDR_W<<1))
117 #define STATUS_WINDOW_H 20
118 #define MODE_WINDOW_W (CHOICE_IMAGE_W)
119 #define MODE_WINDOW_H (DRAW_WINDOW_H+RULER_W+(BRDR_W<<1))
120 #define CHAT_WINDOW_W (TITLE_WINDOW_W)
121 #define CHAT_WINDOW_H 40
122 
123 int	debugNoPointerGrab=FALSE;
124 int	debugCopyPaste=FALSE;
125 
126 unsigned int	mainWinW = 0;
127 unsigned int	mainWinH = 0;
128 int	vSBarH = VSBAR_H;
129 int	hSBarW = HSBAR_W;
130 int	scrollBarW = SCROLLBAR_W;
131 int	rulerW = RULER_W;
132 int	brdrW = BRDR_W;
133 int	windowPadding = 0;
134 int	pageWindowW = PAGE_WINDOW_W;
135 int	pageDummyWindowW = PAGE_DUMMY_WINDOW_W;
136 int	colorWindowH = COLOR_WINDOW_H;
137 int	colorDummyWindowH = COLOR_DUMMY_WINDOW_H;
138 int	msgWindowW = MSG_WINDOW_W;
139 int	msgWindowH = MSG_WINDOW_H;
140 int	choiceImageW = CHOICE_IMAGE_W;
141 int	choiceImageH = CHOICE_IMAGE_H;
142 int	choiceWindowW = CHOICE_WINDOW_W;
143 int	choiceWindowH = CHOICE_WINDOW_H;
144 int	menuImageW = MENU_IMAGE_W;
145 int	menuImageH = MENU_IMAGE_H;
146 int	titleWindowW = TITLE_WINDOW_W;
147 int	titleWindowH = TITLE_WINDOW_H;
148 int	iconWindowW = ICON_WINDOW_W;
149 int	iconWindowH = ICON_WINDOW_H;
150 int	menubarWindowW = MENUBAR_WINDOW_W;
151 int	menubarWindowH = MENUBAR_WINDOW_H;
152 int	userRedrawWindowW = USER_REDRAW_WINDOW_W;
153 int	userRedrawWindowH = USER_REDRAW_WINDOW_H;
154 int	statusWindowW = STATUS_WINDOW_W;
155 int	statusWindowH = STATUS_WINDOW_H;
156 int	statusSubWindowW[MAX_STATUS_BTNS];
157 int	statusSubWindowH[MAX_STATUS_BTNS];
158 int	modeWindowW = MODE_WINDOW_W;
159 int	modeWindowH = MODE_WINDOW_H;
160 int	chatWindowW = CHAT_WINDOW_W;
161 int	chatWindowH = CHAT_WINDOW_H;
162 
163 int	initialMenubarWindowH=MENUBAR_WINDOW_H;
164 
165 static int	statusSubWindowX[MAX_STATUS_BTNS];
166 static int	statusSubWindowY[MAX_STATUS_BTNS];
167 
168 Display		* mainDisplay=NULL;
169 Colormap	mainColormap=(Colormap)0;
170 unsigned int	mainDepth;
171 int		mainScreen;
172 Visual		* mainVisual=NULL;
173 
174 Window	rootWindow=None;
175 Window	mainWindow=None;
176 Window	drawWindow=None;
177 Window	choiceWindow=None;
178 Window	titleWindow=None;
179 Window	msgWindow=None;
180 Window	vSBarWindow=None;
181 Window	hSBarWindow=None;
182 Window	vRuleWindow=None;
183 Window	hRuleWindow=None;
184 Window	iconWindow=None;
185 Window	iconBaseWindow=None;
186 Window	menubarWindow=None;
187 Window	userRedrawWindow=None;
188 Window	statusWindow=None;
189 Window	modeWindow=None;
190 Window	pageWindow=None;
191 Window	pageDummyWindow=None;
192 Window	colorWindow=None;
193 Window	colorDummyWindow=None;
194 Window	chatWindow=None;
195 
196 #ifndef A4PAPER
197 int	onePageWidth = (85*ONE_INCH)/10;
198 int	onePageHeight = 11*ONE_INCH;
199 int	paperWidth = (85*ONE_INCH)/10;
200 int	paperHeight = 11*ONE_INCH;
201 #else /* A4PAPER */
202 int	onePageWidth = (825*ONE_INCH)/100;
203 int	onePageHeight = (117*ONE_INCH)/10;
204 int	paperWidth = (825*ONE_INCH)/100;
205 int	paperHeight = (117*ONE_INCH)/10;
206 #endif /* A4PAPER */
207 int	drawOrigX = 0;
208 int	drawOrigY = 0;
209 int	drawWinW = DRAW_WINDOW_W;
210 int	drawWinH = DRAW_WINDOW_H;
211 
212 int	zoomScale = 0;
213 int	zoomedIn = FALSE;
214 
215 struct BBRec	drawWinBBox;
216 
217 int	colorDisplay = FALSE;
218 int	fullTrueColorMode = FALSE;
219 int	noAntiAlias = TRUE;
220 int	threeDLook = FALSE;
221 int	fileModified = FALSE;
222 int	objId = 0;
223 
224 int	myBgPixel=INVALID;
225 int	myFgPixel=INVALID;
226 int	myRubberBandPixel=INVALID;
227 int	myBorderPixel=INVALID;
228 int	myWhitePixel=INVALID;
229 int	myBlackPixel=INVALID;
230 int	myLtGryPixel=INVALID;
231 int	myDkGryPixel=INVALID;
232 int	myVryLtPixel=INVALID;
233 int	myYellowPixel=INVALID;
234 int	reverseVideo = FALSE;
235 
236 char	drawPath[MAXPATHLENGTH]; /* last char is NOT '/' */
237 char	bootDir[MAXPATHLENGTH+2];
238 char	homeDir[MAXPATHLENGTH];
239 char	tgifDir[MAXPATHLENGTH];
240 char	tmpDir[MAXPATHLENGTH];
241 
242 int	symPathNumEntries = INVALID;
243 char	* * symPath=NULL;
244 
245 int	initDrawWinW=INVALID, initDrawWinH=INVALID;
246 
247 short	handleSize=3;
248 int	resizeTextOnStretch=FALSE;
249 
250 Window	dummyWindow1=None, dummyWindow2=None;
251 
252 Window	statusSubWindow[MAX_STATUS_BTNS];
253 
254 int	noMenubar=FALSE;
255 int	noStatusWindow=FALSE;
256 int	noChoiceWindow=FALSE;
257 int	noModeWindow=FALSE;
258 int	noChatWindow=TRUE;
259 
260 Atom	executeCmdByIDAtom=(Atom)0;
261 
262 int	curChoiceBeforeMakeQuiescent=NOTHING;
263 
264 int	noMinWinSize=TRUE;
265 
266 int	canvasWindowOnly=FALSE;
267 
268 int	talkToSelfFiledesInitialized=FALSE;
269 int	talkToSelfFiledes[2];
270 
271 Atom	compoundTextAtom=(Atom)0;
272 Atom	textAtom=(Atom)0;
273 Atom	utf8StringAtom=(Atom)0;
274 Atom	tgifProtocolAtom=(Atom)0;
275 Atom	tmpSelectionAtom=(Atom)0;
276 
277 static Atom	wmDeleteWindowAtom=(Atom)0;
278 static Atom	targetsAtom=(Atom)0;
279 
280 static int	baseScrollBarW=SCROLLBAR_W;
281 
RegisterWM_DELETE_WINDOW(win)282 void RegisterWM_DELETE_WINDOW(win)
283    Window win;
284 {
285 #ifndef NOTR4MODE
286    XSetWMProtocols(mainDisplay, win, &wmDeleteWindowAtom, 1);
287 #endif
288 }
289 
IsWM_DELETE_WINDOW(pXEvent)290 int IsWM_DELETE_WINDOW(pXEvent)
291    XEvent *pXEvent;
292 {
293    if (pXEvent->type == ClientMessage) {
294       char *psz=XGetAtomName(mainDisplay, pXEvent->xclient.message_type);
295 
296       if (psz == NULL) {
297          /* this should not happen, but just in case */
298       } else if (strcmp("WM_PROTOCOLS", psz) == 0 &&
299             pXEvent->xclient.data.l[0] == wmDeleteWindowAtom) {
300          XFree((void*)psz);
301          return TRUE;
302       }
303       if (psz != NULL) XFree((void*)psz);
304    }
305    return FALSE;
306 }
307 
UpdDrawWinWH()308 void UpdDrawWinWH()
309 {
310    drawWinW = ABS_SIZE(initDrawWinW);
311    drawWinH = ABS_SIZE(initDrawWinH);
312 }
313 
UpdDrawWinBBox()314 void UpdDrawWinBBox()
315 {
316    drawWinBBox.ltx = drawOrigX;
317    drawWinBBox.lty = drawOrigY;
318    drawWinBBox.rbx = drawOrigX + drawWinW-1;
319    drawWinBBox.rby = drawOrigY + drawWinH-1;
320 }
321 
322 #include "xbm/btn1.xbm"
323 
324 static
CalcStatusSubWinGeom()325 void CalcStatusSubWinGeom()
326 {
327    register int i;
328    int left=0, w=(int)(statusWindowW/3), win_y, right=0, win_h;
329 
330    win_y = 1;
331    if (threeDLook) {
332       win_y += (windowPadding>>1);
333       win_h = statusWindowH-4;
334    } else {
335       win_h = statusWindowH-2-(brdrW<<1);
336    }
337    for (i=0; i < MAX_STATUS_BTNS; i++) {
338       int win_x, win_w;
339 
340       right += w;
341       if (right >= statusWindowW) right = statusWindowW-1;
342       win_x = left+(brdrW<<2)+btn1_width+2+(windowPadding>>1);
343       win_w = right-left-(brdrW*6)-btn1_width-2-(windowPadding>>1);
344       statusSubWindowX[i] = win_x;
345       statusSubWindowY[i] = win_y;
346       statusSubWindowW[i] = win_w;
347       statusSubWindowH[i] = win_h;
348       left += w;
349    }
350 }
351 
InitWinSizes()352 void InitWinSizes()
353 {
354    int choice_cols=(CHOICE_WINDOW_W/choiceImageW);
355    int choice_rows=(CHOICE_WINDOW_H/choiceImageH);
356    int min_draw_win_w=0;
357 
358    initDrawWinW = drawWinW;
359    initDrawWinH = drawWinH;
360    choiceWindowW = CHOICE_WINDOW_W+windowPadding*(choice_cols+2);
361    choiceWindowH = CHOICE_WINDOW_H+windowPadding*(choice_rows+2);
362    msgWindowW = ((msgFontSet==NULL && msgFontPtr==NULL) ? defaultFontWidth :
363          msgFontWidth) + (windowPadding<<1);
364    msgWindowH = choiceWindowH;
365    titleWindowH = (((msgFontSet==NULL && msgFontPtr==NULL) ? defaultFontHeight :
366          msgFontHeight) << (showVersion ? 1 : 0)) + windowPadding + 4;
367    userRedrawWindowH = statusWindowH;
368    rulerW = RULER_W + windowPadding;
369    scrollBarW = baseScrollBarW+windowPadding;
370 
371    modeWindowW = CHOICE_IMAGE_W+windowPadding+(windowPadding<<1);
372 
373    if (drawWinH < ONE_INCH) drawWinH = ONE_INCH;
374    min_draw_win_w = choiceWindowW + msgWindowW -
375          (noModeWindow ? 0 : modeWindowW+(brdrW<<1)) - rulerW - scrollBarW;
376    if (drawWinW < min_draw_win_w) drawWinW = min_draw_win_w;
377 
378    modeWindowH = drawWinH+rulerW+(brdrW<<2)+windowPadding;
379    if (threeDLook) {
380       colorDummyWindowH = COLOR_DUMMY_WINDOW_H + windowPadding;
381       pageDummyWindowW = PAGE_DUMMY_WINDOW_W + windowPadding;
382    }
383    pageWindowW = drawWinW+rulerW-hSBarW-pageDummyWindowW;
384    if (pageWindowW <= 0) pageWindowW = 1;
385    colorWindowH = drawWinH+rulerW-DEF_VSBAR_H-colorDummyWindowH;
386    vSBarH = drawWinH+rulerW+(brdrW<<1);
387    titleWindowW = (noModeWindow ? 0 : modeWindowW+(brdrW<<1)) +
388          drawWinW+rulerW+brdrW+scrollBarW+(brdrW<<1);
389    menubarWindowW = titleWindowW;
390    statusWindowW = titleWindowW-userRedrawWindowW-(brdrW<<1);
391    chatWindowW = titleWindowW;
392    CalcMenubarWindowHeight();
393    msgWindowW = titleWindowW-choiceWindowW-(brdrW<<1);
394    mainWinW = titleWindowW+(brdrW<<1);
395    mainWinH = (noMenubar ? 0 : menubarWindowH+(brdrW<<1)) +
396          (noStatusWindow ? 0 : statusWindowH+(brdrW<<1)) +
397          (noChoiceWindow ? 0 : msgWindowH+(brdrW<<1)) +
398          (noChatWindow ? 0 : chatWindowH+(brdrW<<1)) +
399          titleWindowH+vSBarH+scrollBarW+6*brdrW;
400    if (colorLayers) vSBarH = DEF_VSBAR_H;
401    CalcStatusSubWinGeom();
402    SetChatWindowGeom();
403 }
404 
InverseInitWinSizes()405 void InverseInitWinSizes()
406    /* derive other win sizes from mainWinW and mainWinH */
407 {
408    titleWindowW = mainWinW-(brdrW<<1);
409    menubarWindowW = titleWindowW;
410    chatWindowW = titleWindowW;
411    statusWindowW = titleWindowW-userRedrawWindowW-(brdrW<<1);
412    CalcMenubarWindowHeight();
413    msgWindowW = titleWindowW-choiceWindowW-(brdrW<<1);
414    vSBarH = mainWinH - titleWindowH - scrollBarW - 6*brdrW -
415          (noMenubar ? 0 : menubarWindowH+(brdrW<<1)) -
416          (noStatusWindow ? 0 : statusWindowH+(brdrW<<1)) -
417          (noChoiceWindow ? 0 : msgWindowH+(brdrW<<1)) -
418          (noChatWindow ? 0 : chatWindowH+(brdrW<<1));
419    drawWinH = initDrawWinH = vSBarH-rulerW-(brdrW<<1);
420    drawWinW = initDrawWinW = titleWindowW-scrollBarW-rulerW-(brdrW<<2) -
421          (noModeWindow ? 0 : modeWindowW+(brdrW<<1));
422    modeWindowH = drawWinH+rulerW+(brdrW<<2);
423    pageWindowW = titleWindowW-scrollBarW-hSBarW-pageDummyWindowW-(brdrW<<2);
424    if (pageWindowW <= 0) pageWindowW = 1;
425    colorWindowH = drawWinH+rulerW-DEF_VSBAR_H-colorDummyWindowH;
426    if (colorLayers) vSBarH = DEF_VSBAR_H;
427    CalcMenubarWindowHeight();
428    CalcStatusSubWinGeom();
429    SetChatWindowGeom();
430 }
431 
ComputeMainWinXY(MainWinX,MainWinY)432 void ComputeMainWinXY(MainWinX, MainWinY)
433    int *MainWinX, *MainWinY;
434 {
435    int win_x, win_y, done = FALSE;
436    unsigned int win_w, win_h, win_brdr_w, win_d, num_child;
437    Window win=mainWindow, root_win, parent_win, *child_wins;
438 
439    *MainWinX = *MainWinY = 0;
440    while (!done) {
441       XGetGeometry(mainDisplay, win, &root_win, &win_x, &win_y, &win_w,
442             &win_h, &win_brdr_w, &win_d);
443       *MainWinX += win_x;
444       *MainWinY += win_y;
445       if (XQueryTree(mainDisplay, win, &root_win, &parent_win, &child_wins,
446             &num_child) == 0) {
447          return;
448       }
449       if (child_wins != NULL) XFree((void *)child_wins);
450       if (parent_win == rootWindow) {
451          done = TRUE;
452       } else {
453          win = parent_win;
454       }
455    }
456 }
457 
458 static
DoReconfigure()459 void DoReconfigure()
460 {
461    int cur_y=0, x_offset=(noModeWindow ? 0 : modeWindowW+(brdrW<<1));
462    int draw_win_x_offset=0, draw_win_y_offset=0;
463 
464    XResizeWindow(mainDisplay, titleWindow, titleWindowW, titleWindowH);
465    cur_y += titleWindowH + (brdrW<<1);
466    if (!noMenubar) {
467       XResizeWindow(mainDisplay, menubarWindow, menubarWindowW,
468             menubarWindowH);
469       cur_y += menubarWindowH + (brdrW<<1);
470    }
471    if (!noChoiceWindow) {
472       XMoveWindow(mainDisplay, choiceWindow, 0, cur_y);
473       if (msgWindowW > 0) {
474          XMoveResizeWindow(mainDisplay, msgWindow, choiceWindowW+(brdrW<<1),
475                cur_y, msgWindowW, msgWindowH);
476       } else {
477          XMoveWindow(mainDisplay, msgWindow, choiceWindowW+(brdrW<<1), cur_y);
478       }
479       cur_y += msgWindowH + (brdrW<<1);
480    }
481    if (!noModeWindow) {
482       XMoveResizeWindow(mainDisplay, modeWindow, 0, cur_y,
483             modeWindowW, modeWindowH);
484    }
485    XMoveResizeWindow(mainDisplay, dummyWindow1, x_offset, cur_y,
486          rulerW, rulerW);
487    XMoveResizeWindow(mainDisplay, hRuleWindow, x_offset+rulerW+(brdrW<<1),
488          cur_y, drawWinW, rulerW-windowPadding);
489    if (colorLayers) {
490       XMoveResizeWindow(mainDisplay, colorWindow,
491             x_offset+drawWinW+rulerW+(brdrW<<2), cur_y, scrollBarW,
492             colorWindowH);
493       XMoveWindow(mainDisplay, colorDummyWindow,
494             x_offset+drawWinW+rulerW+(brdrW<<2),
495             cur_y+colorWindowH+(brdrW<<1));
496       XMoveResizeWindow(mainDisplay, vSBarWindow,
497             x_offset+drawWinW+rulerW+(brdrW<<2),
498             cur_y+colorWindowH+colorDummyWindowH+(brdrW<<2), scrollBarW,
499             DEF_VSBAR_H);
500    } else {
501       XMoveResizeWindow(mainDisplay, vSBarWindow,
502             x_offset+drawWinW+rulerW+(brdrW<<2), cur_y, scrollBarW, vSBarH);
503    }
504    cur_y += rulerW + (brdrW<<1);
505    XMoveResizeWindow(mainDisplay, vRuleWindow, x_offset, cur_y,
506          rulerW-windowPadding, drawWinH);
507    XMoveResizeWindow(mainDisplay, drawWindow, x_offset+rulerW+(brdrW<<1),
508          cur_y, drawWinW, drawWinH);
509    if (inSlideShow) {
510       draw_win_x_offset = x_offset+rulerW+(brdrW<<1);
511       draw_win_y_offset = cur_y;
512    }
513    cur_y += drawWinH + (brdrW<<1);
514    if (pageWindowW > 0) {
515       XMoveResizeWindow(mainDisplay, pageWindow, 0, cur_y, pageWindowW,
516             scrollBarW+(brdrW<<1));
517       MakeCurPageTabVisible();
518    } else {
519       XMoveWindow(mainDisplay, pageWindow, 0, cur_y);
520    }
521    XMoveWindow(mainDisplay, pageDummyWindow, pageWindowW, cur_y);
522    XMoveWindow(mainDisplay, hSBarWindow,
523          pageWindowW+pageDummyWindowW+(brdrW<<1), cur_y);
524    XMoveWindow(mainDisplay, dummyWindow2,
525          x_offset+drawWinW+rulerW+(brdrW<<2), cur_y);
526    cur_y += scrollBarW + (brdrW<<1);
527    if (!noStatusWindow) {
528       int i;
529 
530       XMoveWindow(mainDisplay, userRedrawWindow, 0, cur_y);
531       XMoveResizeWindow(mainDisplay, statusWindow,
532             userRedrawWindowW+(brdrW<<1), cur_y,
533             statusWindowW, statusWindowH);
534       for (i=0; i < MAX_STATUS_BTNS; i++) {
535          XMoveResizeWindow(mainDisplay, statusSubWindow[i],
536                statusSubWindowX[i], statusSubWindowY[i],
537                statusSubWindowW[i], statusSubWindowH[i]);
538       }
539       cur_y += statusWindowH + (brdrW<<1);
540    }
541    if (!noChatWindow) {
542       MoveResizeChatWindow(0, cur_y, chatWindowW, chatWindowH);
543       cur_y += chatWindowH + (brdrW<<1);
544    }
545    if (inSlideShow) {
546       int dpy_w=DisplayWidth(mainDisplay,mainScreen);
547       int dpy_h=DisplayHeight(mainDisplay,mainScreen);
548       int x_off=((dpy_w-ZOOMED_SIZE(onePageWidth))>>1);
549       int y_off=((dpy_h-ZOOMED_SIZE(onePageHeight))>>1);
550       int new_x=slideShowXOffset+x_off;
551       int new_y=slideShowYOffset+y_off;
552       int changed=FALSE;
553 
554       XMoveResizeWindow(mainDisplay, drawWindow,
555             new_x+draw_win_x_offset, new_y+draw_win_y_offset,
556             ZOOMED_SIZE(onePageWidth)-(slideShowXOffset<<1),
557             ZOOMED_SIZE(onePageHeight-(slideShowYOffset<<1)));
558       if (ZOOMED_SIZE(onePageWidth) > drawWinW) {
559          drawWinW = ZOOMED_SIZE(onePageWidth);
560          changed = TRUE;
561       }
562       if (ZOOMED_SIZE(onePageHeight) > drawWinH) {
563          drawWinH = ZOOMED_SIZE(onePageHeight);
564          changed = TRUE;
565       }
566       if (changed) {
567          InitWinSizes();
568       }
569    }
570 }
571 
Reconfigure(Forced)572 void Reconfigure(Forced)
573    int Forced;
574 {
575    int i;
576    Window root_win;
577    int win_x, win_y, main_win_x, main_win_y;
578    unsigned int win_w, win_h, win_brdr_w, win_d;
579    XEvent ev;
580 
581    ComputeMainWinXY(&main_win_x, &main_win_y);
582    XGetGeometry(mainDisplay, mainWindow, &root_win, &win_x, &win_y, &win_w,
583          &win_h, &win_brdr_w, &win_d);
584    if (!iconWindowShown && !Forced && win_w == mainWinW && win_h == mainWinH) {
585       SaveStackingOrder();
586       if (pinnedMainMenu) {
587          MoveMainMenuWindow(main_win_x, main_win_y);
588       } else {
589          SaveMainWinPosition(main_win_x, main_win_y);
590       }
591       for (i = 0; i < numStacking; i++) {
592          XMapRaised(mainDisplay, stackingWins[i]);
593       }
594       while (XCheckWindowEvent(mainDisplay, mainWindow,
595             VisibilityChangeMask | StructureNotifyMask, &ev)) ;
596 
597       XFlush(mainDisplay);
598       return;
599    }
600    if (!Forced && !iconWindowShown) {
601       SaveStackingOrder();
602       for (i = 0; i < numStacking; i++) {
603          XMapRaised(mainDisplay, stackingWins[i]);
604       }
605    }
606 
607    mainWinW = win_w;
608    mainWinH = win_h;
609 
610    menubarWindowW = mainWinW - (brdrW<<1);
611    CalcMenubarWindowHeight();
612    if (canvasWindowOnly) {
613       initDrawWinW = mainWinW-(brdrW<<1);
614       initDrawWinH = mainWinH-(brdrW<<1);
615    } else {
616       initDrawWinW = mainWinW - rulerW - scrollBarW - 6*brdrW -
617          (noModeWindow ? 0 : modeWindowW+(brdrW<<1));
618       initDrawWinH = mainWinH - titleWindowH -
619             (noMenubar ? 0 : menubarWindowH+(brdrW<<1)) -
620             (noStatusWindow ? 0 : statusWindowH+(brdrW<<1)) -
621             (noChoiceWindow ? 0 : msgWindowH+(brdrW<<1)) -
622             (noChatWindow ? 0 : chatWindowH+(brdrW<<1)) -
623             rulerW - scrollBarW - 8*brdrW;
624    }
625    drawWinW = initDrawWinW;
626    drawWinH = initDrawWinH;
627    modeWindowH = drawWinH+rulerW+(brdrW<<2);
628    colorWindowH = initDrawWinH+rulerW-DEF_VSBAR_H-colorDummyWindowH-(brdrW<<1);
629    vSBarH = (colorLayers ? DEF_VSBAR_H : initDrawWinH + rulerW + (brdrW<<1));
630    if (noModeWindow) {
631       pageWindowW = initDrawWinW+rulerW-hSBarW-pageDummyWindowW;
632       titleWindowW = initDrawWinW + rulerW + scrollBarW + (brdrW<<2);
633    } else {
634       pageWindowW = initDrawWinW+rulerW+modeWindowW+(brdrW<<1)-hSBarW-
635             pageDummyWindowW;
636       titleWindowW = initDrawWinW + rulerW + modeWindowW + scrollBarW +
637             (brdrW*6);
638    }
639    if (pageWindowW <= 0) pageWindowW = 1;
640    menubarWindowW = titleWindowW;
641    chatWindowW = titleWindowW;
642    if (!noChatWindow) SetChatWindowGeom();
643    statusWindowW = titleWindowW-userRedrawWindowW-(brdrW<<1);
644    CalcMenubarWindowHeight();
645    msgWindowW = titleWindowW - choiceWindowW - (brdrW<<1);
646    CalcStatusSubWinGeom();
647    if (canvasWindowOnly) {
648       XResizeWindow(mainDisplay, drawWindow, drawWinW, drawWinH);
649    } else {
650       DoReconfigure();
651    }
652    UpdDrawWinWH();
653    UpdDrawWinBBox();
654    UpdScrollWinWH();
655    SetDefaultDrawWinClipRecs();
656    SaveMainWinPosition(main_win_x, main_win_y);
657 }
658 
TgHandleCmdEvent(pXEv)659 int TgHandleCmdEvent(pXEv)
660    XEvent *pXEv;
661    /* must call TgIsCmdEvent() right before calling this function */
662 {
663    return ExecuteCmdById((int)(pXEv->xclient.data.s[1]),
664          (int)(pXEv->xclient.data.s[2]));
665 }
666 
TgIsCmdEvent(pXEv)667 int TgIsCmdEvent(pXEv)
668    XEvent *pXEv;
669 {
670    if (pXEv->xany.window == mainWindow && pXEv->type == ClientMessage) {
671       if (executeCmdByIDAtom == pXEv->xclient.message_type &&
672             pXEv->xclient.data.s[0] == TG_COMMAND) {
673          return TRUE;
674       }
675    }
676    return FALSE;
677 }
678 
679 static
HandleSelectionClear(input)680 void HandleSelectionClear(input)
681    XEvent *input;
682 {
683    Window win=(Window)0;
684    Atom selection=(Atom)0;
685    Time time;
686 
687    win = input->xselectionclear.window;
688    selection = input->xselectionclear.selection;
689    time = input->xselectionclear.time;
690 
691    if (debugCopyPaste) {
692       static int id=0;
693       char *atom_name=NULL;
694 
695       printf("\n%1d: SelectionClear.\n", ++id);
696 
697       atom_name = XGetAtomName(mainDisplay, selection);
698       printf("%1d: Selection name is '%s'.\n", id, atom_name);
699       XFree(atom_name);
700    }
701    if (startSelectionOwnershipTimeValid) {
702       endSelectionOwnershipTime = time;
703       endSelectionOwnershipTimeValid = TRUE;
704    }
705    ClearSelection();
706 }
707 
708 static
DebugSelectRequest(property,target,level,msg)709 void DebugSelectRequest(property, target, level, msg)
710    Atom property, target;
711    int level;
712    char *msg;
713 {
714    if (debugCopyPaste > level) {
715       /*
716        * After tgif does a Copy, tgif will get SelectionRequest at
717        *         a regular interval
718        */
719       static int id=0;
720       char *atom_name=NULL;
721 
722       if (msg == NULL) {
723          printf("\n%1d: SelectionRequest.\n", ++id);
724       } else {
725          printf("\n%1d: SelectionRequest (%s).\n", ++id, msg);
726       }
727       atom_name = XGetAtomName(mainDisplay, property);
728       printf("%1d: Property name is '%s'.\n", id, atom_name);
729       XFree(atom_name);
730 
731       atom_name = XGetAtomName(mainDisplay, target);
732       printf("%1d: Target name is '%s'.\n", id, atom_name);
733       XFree(atom_name);
734    }
735 }
736 
HandleSelectionRequest(input)737 void HandleSelectionRequest(input)
738    XEvent *input;
739 {
740    Window requestor=(Window)0;
741    Atom property=(Atom)0, target=(Atom)0, selection=(Atom)0;
742    Time time=(Time)0;
743    XEvent sent_ev;
744    unsigned char empty_buf[1];
745 
746    *empty_buf = '\0';
747    requestor = input->xselectionrequest.requestor;
748    selection = input->xselectionrequest.selection;
749    target = input->xselectionrequest.target;
750    property = input->xselectionrequest.property;
751    time = input->xselectionrequest.time;
752 
753    /* do not translate -- program constants */
754    DebugSelectRequest(property, target, 1, "function entry point");
755    memset(&sent_ev, 0, sizeof(XEvent));
756 
757    sent_ev.xselection.type = SelectionNotify;
758    sent_ev.xselection.display = mainDisplay;
759    sent_ev.xselection.requestor = requestor;
760    sent_ev.xselection.selection = selection;
761    sent_ev.xselection.time = input->xselectionrequest.time;
762    sent_ev.xselection.target = target;
763    sent_ev.xselection.property = None;
764 
765    if (target == targetsAtom) {
766       /*
767        * The selection manager is asking tgif what can you convert the
768        *         object copied into (i.e., what are the possobiel targets)?
769        */
770       Atom targets[5];
771       int num_targets=0;
772 
773       DebugSelectRequest(property, target, 0, "TARGETS");
774       if (gSetCutBufferInfo.tgif_valid) {
775          targets[num_targets++] = tgifProtocolAtom;
776       }
777       if (gSetCutBufferInfo.utf8_valid) {
778          targets[num_targets++] = utf8StringAtom;
779       }
780       if (gSetCutBufferInfo.text_valid) {
781          targets[num_targets++] = compoundTextAtom;
782          targets[num_targets++] = textAtom;
783          targets[num_targets++] = XA_STRING;
784       }
785       XChangeProperty(mainDisplay, requestor, property, target, 32,
786             PropModeReplace, (unsigned char *)targets, num_targets);
787       sent_ev.xselection.property = property;
788    } else if (target == XA_STRING || target == textAtom) {
789       DebugSelectRequest(property, target, 0, "XA_STRING or TEXT");
790       if (gSetCutBufferInfo.text_valid) {
791          XChangeProperty(mainDisplay, requestor, property, target, 8,
792                PropModeReplace,
793                (unsigned char *)(gSetCutBufferInfo.text_dyn_str.s),
794                gSetCutBufferInfo.text_dyn_str.sz);
795       } else {
796          XChangeProperty(mainDisplay, requestor, property, target, 8,
797                PropModeReplace, empty_buf, 0);
798       }
799       sent_ev.xselection.property = property;
800    } else if (target == utf8StringAtom) {
801       DebugSelectRequest(property, target, 0, "UTF8_STRING");
802       if (gSetCutBufferInfo.utf8_valid) {
803          XChangeProperty(mainDisplay, requestor, property, target, 8,
804                PropModeReplace,
805                (unsigned char *)(gSetCutBufferInfo.utf8_dyn_str.s),
806                gSetCutBufferInfo.utf8_dyn_str.sz);
807       } else {
808          XChangeProperty(mainDisplay, requestor, property, target, 8,
809                PropModeReplace, empty_buf, 0);
810       }
811       sent_ev.xselection.property = property;
812    } else if (target == tgifProtocolAtom) {
813       DebugSelectRequest(property, target, 0, "_TGIF_PROTOCOL_ATOM");
814       if (gSetCutBufferInfo.tgif_valid) {
815          XChangeProperty(mainDisplay, requestor, property, target, 8,
816                PropModeReplace,
817                (unsigned char *)(gSetCutBufferInfo.tgif_dyn_str.s),
818                gSetCutBufferInfo.tgif_dyn_str.sz);
819       } else {
820          XChangeProperty(mainDisplay, requestor, property, target, 8,
821                PropModeReplace, empty_buf, 0);
822       }
823       sent_ev.xselection.property = property;
824    } else if (target == compoundTextAtom) {
825       XTextProperty text_property;
826 
827       if (gSetCutBufferInfo.utf8_valid) {
828          DebugSelectRequest(property, target, 0, "COMPOUND_TEXT for UTF8");
829 #ifndef _NO_XUTF8FUNCTIONS
830          Xutf8TextListToTextProperty(mainDisplay,
831                &(gSetCutBufferInfo.utf8_dyn_str.s), 1,
832                XCompoundTextStyle, &text_property);
833 #endif /* ~_NO_XUTF8FUNCTIONS */
834       } else if (gSetCutBufferInfo.text_valid) {
835          DebugSelectRequest(property, target, 0, "COMPOUND_TEXT not UTF8");
836          XmbTextListToTextProperty(mainDisplay,
837                &(gSetCutBufferInfo.text_dyn_str.s), 1,
838                XCompoundTextStyle, &text_property);
839       } else {
840          char *psz_buf=(char*)empty_buf;
841 
842          DebugSelectRequest(property, target, 0, "COMPOUND_TEXT (none)");
843          XmbTextListToTextProperty(mainDisplay, &psz_buf, 1,
844                XCompoundTextStyle, &text_property);
845       }
846       XChangeProperty(mainDisplay, requestor, property, target,
847             text_property.format, PropModeReplace, text_property.value,
848             text_property.nitems);
849       sent_ev.xselection.property = property;
850    }
851    XSendEvent(mainDisplay, requestor, False, NoEventMask, &sent_ev);
852 }
853 
854 static XComposeStatus c_stat;
855 
mainWinEventHandler(input)856 int mainWinEventHandler(input)
857    XEvent *input;
858 {
859    register int i;
860    int configure=FALSE;
861 
862    if (inSlideShow && input->type == KeyPress) {
863       char s[80];
864       KeySym key_sym;
865       int has_ch=FALSE;
866       XKeyEvent *key_ev=(&(input->xkey));
867 
868       has_ch = XLookupString(key_ev, s, sizeof(s), &key_sym, &c_stat);
869       TranslateKeys(s, &key_sym);
870 
871       if (CharIsESC(key_ev, s, key_sym, &has_ch)) {
872          LeaveSlideShow();
873          return INVALID;
874       }
875       switch (key_sym) {
876       case XK_Left: PrevSlide(); return INVALID;
877       case XK_KP_Left: PrevSlide(); return INVALID;
878       case XK_Right: NextSlide(); return INVALID;
879       case XK_KP_Right: NextSlide(); return INVALID;
880       default: break;
881       }
882    } else if (input->type == SelectionRequest) {
883       HandleSelectionRequest(input);
884       return INVALID;
885    } else if (input->type == SelectionClear) {
886       HandleSelectionClear(input);
887       return INVALID;
888    } else if (input->type == UnmapNotify) {
889       Iconify();
890    } else if (input->type == MapNotify) {
891       UnIconify();
892    } else if (input->type == ConfigureNotify) {
893 #ifdef _DO_BENCHMARK_AT_START
894       static int first_time=TRUE;
895 
896       if (first_time) {
897          SendCommandToSelf(CMDID_BENCHMARK, INVALID);
898          first_time = FALSE;
899       }
900 #endif /* _DO_BENCHMARK_AT_START */
901       configure = TRUE;
902    } else if (input->type == VisibilityNotify &&
903          input->xvisibility.state == VisibilityUnobscured) {
904       if (iconWindowShown) {
905          UnIconify();
906       } else {
907          SaveStackingOrder();
908          for (i = 0; i < numStacking; i++) {
909             XMapRaised(mainDisplay, stackingWins[i]);
910          }
911       }
912    } else if (input->type == ClientMessage) {
913       if (executeCmdByIDAtom == input->xclient.message_type &&
914             input->xclient.data.s[0] == TG_COMMAND) {
915          return ExecuteCmdById((int)(input->xclient.data.s[1]),
916                (int)(input->xclient.data.s[2]));
917       } else {
918          char *c_ptr=NULL;
919 
920          c_ptr = XGetAtomName(mainDisplay, input->xclient.message_type);
921 
922          if (c_ptr == NULL) {
923             /* this should not happen, but just in case */
924          } else if (strcmp("WM_MOVED", c_ptr) == 0) {
925             configure = TRUE;
926          } else if (strcmp("WM_PROTOCOLS", c_ptr) == 0 &&
927                input->xclient.data.l[0] == wmDeleteWindowAtom) {
928             XFree((void*)c_ptr);
929             return QuitProc();
930          } else if (curChoice == DRAWTEXT && canvasFontDoubleByte &&
931                textCursorShown && tgIMExpectClientMessage(mainDisplay,
932                mainWindow)) {
933             char buf[80];
934             XKeyEvent key_ev;
935 
936             *buf = '\0';
937             memset(&key_ev, 0, sizeof(XKeyEvent));
938             key_ev.type = KeyPress;
939             key_ev.display = mainDisplay;
940             key_ev.window = drawWindow;
941             key_ev.root = rootWindow;
942             key_ev.same_screen = 1;
943             if (tgIMHandleClientMessage(mainDisplay,
944                   mainWindow, &(input->xclient), &key_ev, buf)) {
945                int has_ch=TRUE;
946                KeySym key_sym=(KeySym)0;
947 
948                if (((*buf) & 0x80) != '\0') {
949                   key_sym = XK_space;
950                   has_ch = strlen(buf);
951                } else {
952                   key_sym = (KeySym)(key_ev.keycode);
953                   TranslateKeys(buf, &key_sym);
954                }
955                /*
956                 * This is probably not needed.
957                 *
958                 * ClearCopyUTF8Info();
959                 * if (textHighlight) {
960                 *    if (!CanCopyHighLightedTextAsUTF8Strings(NULL)) {
961                 *       ClearCopyUTF8Info();
962                 *    } else if (gstCopyUTF8Info.double_byte_valid &&
963                 *          !gstCopyUTF8Info.single_byte_valid) {
964                 *       CalcSingleByteInfoForCopyUTF8(NULL);
965                 *    }
966                 * }
967                 */
968                HandleTextFromBuffer(&key_ev, buf, key_sym, has_ch);
969             }
970          } else {
971             sprintf(gszMsgBox, "mainWindow ClientMessage: '%s'.", c_ptr);
972             Msg(gszMsgBox);
973          }
974          if (c_ptr != NULL) XFree((void*)c_ptr);
975       }
976    }
977 
978    if (configure) Reconfigure(FALSE);
979    if (showCrossHair) {
980       SetNullCursor(drawWindow);
981    }
982    return INVALID;
983 }
984 
CleanUpPaperSize()985 void CleanUpPaperSize()
986 {
987    if (psPageHeightInInch != NULL) free(psPageHeightInInch);
988    if (psPageWidthInInch != NULL) free(psPageWidthInInch);
989    if (psYOff != NULL) free(psYOff);
990    if (psYOffStr != NULL) {
991       free(psYOffStr[0]);
992       free(psYOffStr[1]);
993       free(psYOffStr);
994    }
995    psYOffStr = NULL;
996    psYOff = psPageWidthInInch = psPageHeightInInch = NULL;
997 }
998 
InitPaperSize()999 void InitPaperSize()
1000 {
1001    float fval=(float)0;
1002 
1003    if (psYOffStr != NULL) CleanUpPaperSize();
1004 
1005    psYOffStr = (char**)malloc(MAXPAGESTYLES*sizeof(char *));
1006    if (psYOffStr == NULL) FailAllocMessage();
1007    psYOffStr[0] = (char*)malloc(20*sizeof(char));
1008    psYOffStr[1] = (char*)malloc(2*sizeof(char));
1009    if (psYOffStr[0] == NULL || psYOffStr[1] == NULL) FailAllocMessage();
1010    fval = (float)(((float)onePageHeight)/((float)ONE_INCH));
1011    FormatFloat(&fval, psYOffStr[0]);
1012    sprintf(psYOffStr[1], "0");
1013    psYOff = (float*)malloc(MAXPAGESTYLES*sizeof(float));
1014    if (psYOff == NULL) FailAllocMessage();
1015    psYOff[0] = ((float)onePageHeight)/((float)ONE_INCH);
1016    psYOff[1] = (float)0.0;
1017    psPageWidthInInch = (float*)malloc(MAXPAGESTYLES*sizeof(float));
1018    if (psPageWidthInInch == NULL) FailAllocMessage();
1019    psPageWidthInInch[0] = ((float)onePageWidth)/((float)ONE_INCH);
1020    psPageWidthInInch[1] = ((float)onePageHeight)/((float)ONE_INCH);
1021    psPageHeightInInch = (float*)malloc(MAXPAGESTYLES*sizeof(float));
1022    if (psPageHeightInInch == NULL) FailAllocMessage();
1023    psPageHeightInInch[0] = ((float)onePageHeight)/((float)ONE_INCH);
1024    psPageHeightInInch[1] = ((float)onePageWidth)/((float)ONE_INCH);
1025 }
1026 
1027 static Pixmap	wmIconPixmap=None, wmIconPixmapMask=None;
1028 
1029 static
GetWMIconPixmap(pPixmap,pPixmapMask)1030 int GetWMIconPixmap(pPixmap, pPixmapMask)
1031    Pixmap *pPixmap, *pPixmapMask;
1032 {
1033    Pixmap pixmap=None, bitmap=None;
1034    XImage *image=NULL, *bitmap_image=NULL;
1035    int rc=0, image_w=0, image_h=0, w=0, h=0, ncolors=0, chars_per_pixel=0;
1036    int first_pixel_is_bg=FALSE, *pixels=NULL;
1037    char fname[MAXPATHLENGTH], *color_char=NULL, **color_str=NULL;
1038    char *xpm_data=NULL;
1039    char *c_ptr=XGetDefault(mainDisplay,TOOL_NAME, "WMIconPixmap");
1040 
1041    *pPixmap = *pPixmapMask = None;
1042    if (c_ptr == NULL) return FALSE;
1043    if (*c_ptr == DIR_SEP) {
1044       strncpy(fname, c_ptr, sizeof(fname));
1045    } else {
1046       sprintf(fname, "%s%c%s", drawPath, DIR_SEP, c_ptr);
1047    }
1048    c_ptr = UtilStrRChr(fname, '.');
1049    if (c_ptr != NULL && UtilStrICmp(c_ptr, ".xpm") == 0) {
1050       rc = MyReadPixmapFile(fname, &image_w, &image_h, &w, &h, &pixmap,
1051             &image, &bitmap, &bitmap_image, &ncolors, &chars_per_pixel,
1052             &first_pixel_is_bg, &color_char, &color_str, &pixels,
1053             &xpm_data);
1054    } else {
1055       int x_hot=0, y_hot=0;
1056       unsigned int tmp_w=0, tmp_h=0;
1057 
1058       rc = XReadBitmapFile(mainDisplay, mainWindow, fname, &tmp_w, &tmp_h,
1059             &pixmap, &x_hot, &y_hot);
1060    }
1061    if (rc != BitmapSuccess) {
1062       fprintf(stderr, TgLoadCachedString(CSTID_FAIL_READ_ICONPXMP_USE_BMP),
1063             fname);
1064       fprintf(stderr, "\n");
1065       return FALSE;
1066    }
1067    if (image != NULL) XDestroyImage(image);
1068    if (bitmap_image != NULL) XDestroyImage(bitmap_image);
1069    if (color_char != NULL) free(color_char);
1070    if (color_str != NULL) {
1071       int i;
1072 
1073       for (i=0; i < ncolors; i++) free(color_str[i]);
1074       free(color_str);
1075    }
1076    if (pixels != NULL) free(pixels);
1077    *pPixmap = pixmap;
1078    *pPixmapMask = bitmap;
1079    return TRUE;
1080 }
1081 
InitTmpDir()1082 void InitTmpDir()
1083 {
1084    int tmp_dir_in_x_def=FALSE;
1085    char *c_ptr=NULL;
1086    struct stat stat_buf;
1087 
1088    if ((c_ptr=getenv("HOME")) == NULL) {
1089       strcpy(homeDir, DIR_SEP_STR);
1090    } else if (strlen(c_ptr) >= MAXPATHLENGTH-1) {
1091       strcpy(homeDir, DIR_SEP_STR);
1092    } else {
1093       strcpy(homeDir, c_ptr);
1094    }
1095    sprintf(tgifDir, "%s%c.%s", homeDir, DIR_SEP, TOOL_NAME);
1096    memset(&stat_buf, 0, sizeof(struct stat));
1097    if (stat(tgifDir, &stat_buf) != 0) {
1098       /* directory does not exist */
1099       if (mkdir(tgifDir, 0755) != 0) {
1100          fprintf(stderr, TgLoadString(STID_CANT_CREATE_NAMED_DIRECTORY),
1101                tgifDir);
1102          fprintf(stderr, "\n");
1103          if (!PRTGIF) {
1104             fprintf(stderr, "\t");
1105             fprintf(stderr, TgLoadString(STID_OPR_USING_NAMED_DIR_WILL_FAIL),
1106                   tgifDir);
1107             fprintf(stderr, "\n");
1108          }
1109       }
1110    }
1111    if (*bootDir == '\0') {
1112       GetWorkingDirectory(bootDir, sizeof(bootDir));
1113    }
1114    if (!PRTGIF || cmdLineOpenDisplay) {
1115       /* do not translate -- program constants */
1116       if (mainDisplay != NULL &&
1117             (c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TmpDir")) != NULL) {
1118          UtilTrimBlanks(c_ptr);
1119          if (*c_ptr == '\0') {
1120             fprintf(stderr, TgLoadString(STID_INVALID_DIR_IN_X_DEFAULT),
1121                   c_ptr, TOOL_NAME, "TmpDir");
1122             fprintf(stderr, "\n");
1123          } else {
1124             UtilStrCpyN(tmpDir, sizeof(tmpDir)-1, c_ptr);
1125             strcat(tmpDir, DIR_SEP_STR);
1126             if (UtilIsDirectory(tmpDir)) {
1127                tmp_dir_in_x_def = TRUE;
1128             } else {
1129                fprintf(stderr, TgLoadString(STID_TMP_DIR_NOT_EXIST_USE_XDEF),
1130                      tmpDir, TOOL_NAME, "TmpDir");
1131                fprintf(stderr, "\n");
1132             }
1133          }
1134       }
1135    }
1136    if (!tmp_dir_in_x_def) {
1137 #ifndef _TMP_DIR_IN_HOME_DIR
1138       UtilStrCpyN(tmpDir, sizeof(tmpDir), TMP_DIR);
1139       if (!PRTGIF || cmdLineOpenDisplay) {
1140          if (mainDisplay != NULL &&
1141                (c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TmpDirInHomeDir")) !=
1142                NULL && UtilStrICmp(c_ptr, "true") == 0) {
1143             UtilStrCpyN(tmpDir, sizeof(tmpDir)-1, tgifDir);
1144             strcat(tmpDir, DIR_SEP_STR);
1145          }
1146       }
1147 #else /* _TMP_DIR_IN_HOME_DIR */
1148       UtilStrCpyN(tmpDir, sizeof(tmpDir)-1, tgifDir);
1149       strcat(tmpDir, DIR_SEP_STR);
1150       if (!PRTGIF || cmdLineOpenDisplay) {
1151          if (mainDisplay != NULL &&
1152                (c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TmpDirInHomeDir")) !=
1153                NULL && UtilStrICmp(c_ptr, "false") == 0) {
1154             UtilStrCpyN(tmpDir, sizeof(tmpDir), TMP_DIR);
1155          }
1156       }
1157 #endif /* ~_TMP_DIR_IN_HOME_DIR */
1158    }
1159 }
1160 
1161 static
InitAntiAlias()1162 int InitAntiAlias()
1163    /*
1164     * Get here because fullTrueColorMode is TRUE.  So, by default, we
1165     *         will use antialiased fonts, unless Tgif.NoAntialias is set
1166     *         to TRUE.
1167     * Need to add code to talk to the xft server.
1168     */
1169 {
1170 #ifdef NOT_DEFINED
1171    char *c_ptr=NULL;
1172 
1173    noAntiAlias = FALSE;
1174    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "NoAntialias")) !=
1175          NULL && UtilStrICmp(c_ptr, "true") == 0) {
1176       noAntiAlias = TRUE;
1177    }
1178 #endif /* NOT_DEFINED */
1179    /*
1180     * Add code here to talk to the xft server.
1181     */
1182    return TRUE;
1183 }
1184 
Setup()1185 void Setup()
1186 {
1187    int bitmask=0, x_neg_in_def=FALSE, y_neg_in_def=FALSE;
1188    int x_in_cmdline=FALSE, y_in_cmdline=FALSE, cur_y=0, i, x_offset=0;
1189    int bg_pixel=(-1), def_x_neg=0, def_y_neg=0, paper_size_set=FALSE;
1190    char *c_ptr=NULL;
1191    double dval=(double)0;
1192    XWMHints wmhints;
1193    XSizeHints sizehints;
1194    XClassHint classhints;
1195 
1196    *homeDir = *bootDir = *tgifDir = '\0';
1197    debugNoPointerGrab = FALSE;
1198 #ifdef _TGIF_DBG
1199    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1200          "DebugNoPointerGrab")) != NULL && UtilStrICmp(c_ptr, "true") == 0) {
1201       debugNoPointerGrab = TRUE;
1202    }
1203 #endif /* _TGIF_DBG */
1204    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "Synchronize")) != NULL) {
1205       if (UtilStrICmp(c_ptr, "on") == 0 || UtilStrICmp(c_ptr, "true") == 0) {
1206          XSynchronize(mainDisplay, True);
1207       }
1208    }
1209    showVersion = FALSE;
1210    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "DontShowVersion")) != NULL &&
1211          UtilStrICmp(c_ptr, "false") == 0) {
1212       showVersion = TRUE;
1213    }
1214 
1215    *printCommand = '\0';
1216    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "PrintCommand")) != NULL) {
1217       strcpy(printCommand, c_ptr);
1218    } else {
1219 #ifdef PRINT_CMD
1220       strcpy(printCommand, PRINT_CMD);
1221 #else
1222 #ifdef VMS
1223       strcpy(printCommand, "print");
1224 #else
1225 #ifdef SYSV
1226       strcpy(printCommand, "lp -dpostscript");
1227 #else
1228       strcpy(printCommand, "lpr");
1229 #endif /* SYSV */
1230 #endif /* VMS */
1231 #endif /* PRINT_CMD */
1232    }
1233    if (!PRTGIF) *outputDir = '\0';
1234    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "PrintDirectory")) != NULL) {
1235       strcpy(outputDir, c_ptr);
1236    }
1237    whereToPrint = LATEX_FIG;
1238    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "WhereToPrint")) != NULL) {
1239       if (UtilStrICmp(c_ptr, "Printer") == 0) {
1240          whereToPrint = PRINTER;
1241       } else if (UtilStrICmp(c_ptr, "EPS") == 0) {
1242          whereToPrint = LATEX_FIG;
1243       } else if (UtilStrICmp(c_ptr, "PS") == 0) {
1244          whereToPrint = PS_FILE;
1245       } else if (UtilStrICmp(c_ptr, "Bitmap") == 0) {
1246          whereToPrint = XBM_FILE;
1247       } else if (UtilStrICmp(c_ptr, "Text") == 0) {
1248          whereToPrint = TEXT_FILE;
1249       } else if (UtilStrICmp(c_ptr, "EPSI") == 0) {
1250          whereToPrint = EPSI_FILE;
1251       } else if (UtilStrICmp(c_ptr, "GIF") == 0) {
1252          whereToPrint = GIF_FILE;
1253       } else if (UtilStrICmp(c_ptr, "HTML") == 0) {
1254          whereToPrint = HTML_FILE;
1255       } else if (UtilStrICmp(c_ptr, "PDF") == 0) {
1256          whereToPrint = PDF_FILE;
1257       } else if (UtilStrICmp(c_ptr, "TiffEPSI") == 0 ||
1258             UtilStrICmp(c_ptr, "WinEPSI") == 0) {
1259          whereToPrint = TIFFEPSI_FILE;
1260       } else if (UtilStrICmp(c_ptr, "PNG") == 0) {
1261          whereToPrint = PNG_FILE;
1262       } else if (UtilStrICmp(c_ptr, "JPEG") == 0) {
1263          whereToPrint = JPEG_FILE;
1264       } else if (UtilStrICmp(c_ptr, "PPM") == 0 ||
1265             UtilStrICmp(c_ptr, "PBM") == 0) {
1266          whereToPrint = PPM_FILE;
1267       } else if (UtilStrICmp(c_ptr, "NetList") == 0) {
1268          whereToPrint = NETLIST_FILE;
1269       } else if (UtilStrICmp(c_ptr, "SVG") == 0) {
1270          whereToPrint = SVG_FILE;
1271       } else {
1272          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1273                TOOL_NAME, "WhereToPrint", c_ptr, "EPS");
1274          fprintf(stderr, "\n");
1275       }
1276    }
1277    useGray = FALSE;
1278    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"UseGrayScale")) != NULL) {
1279       if (UtilStrICmp("true", c_ptr) == 0) {
1280          useGray = TRUE;
1281       }
1282    }
1283    autoPan = TRUE;
1284    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"AutoPanInEditText")) != NULL) {
1285       if (UtilStrICmp("false", c_ptr) == 0) {
1286          autoPan = FALSE;
1287       }
1288    }
1289    moveMode = UNCONST_MOVE;
1290    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"ConstrainedMove")) != NULL) {
1291       if (UtilStrICmp("true", c_ptr) == 0) {
1292          moveMode = CONST_MOVE;
1293       }
1294    }
1295    doubleQuoteDoubleQuote = FALSE;
1296    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"DoubleQuoteDoubleQuote"))
1297          != NULL) {
1298       if (UtilStrICmp("true", c_ptr) == 0) {
1299          doubleQuoteDoubleQuote = TRUE;
1300       }
1301    }
1302    gridSystem = ENGLISH_GRID;
1303    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "GridSystem")) != NULL) {
1304       if (UtilStrICmp("Metric", c_ptr) == 0) {
1305          gridSystem = METRIC_GRID;
1306       }
1307    }
1308    xyEnglishGrid = DEFAULT_ENGLISH_GRID;
1309    xyMetricGrid = DEFAULT_METRIC_GRID;
1310    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "InitialGrid")) != NULL) {
1311       int grid_size=atoi(c_ptr);
1312 
1313       switch (gridSystem) {
1314       case ENGLISH_GRID:
1315          if (grid_size < -2 || grid_size > 2) {
1316             fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1317                   TOOL_NAME, "InitialGrid", c_ptr, 0);
1318             fprintf(stderr, "\n");
1319          } else {
1320             xyEnglishGrid = HALF_INCH>>(2-grid_size);
1321          }
1322          break;
1323       case METRIC_GRID:
1324          if (grid_size < -1 || grid_size > 2) {
1325             fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1326                   TOOL_NAME, "InitialGrid", c_ptr, 0);
1327             fprintf(stderr, "\n");
1328          } else {
1329             switch (grid_size) {
1330             case -1: xyMetricGrid = ONE_MM; break;
1331             case 0: xyMetricGrid = TWO_MM; break;
1332             case 1: xyMetricGrid = FIVE_MM; break;
1333             case 2: xyMetricGrid = ONE_CM; break;
1334             }
1335          }
1336          break;
1337       }
1338    }
1339    splineTol = 9;
1340    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"SplineTolerance")) != NULL) {
1341       splineTol = atoi(c_ptr);
1342       if (splineTol < 3 || splineTol > 13) {
1343          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1344                TOOL_NAME, "SplineTolerance", c_ptr, 9);
1345          fprintf(stderr, "\n");
1346          splineTol = 9;
1347       }
1348    }
1349    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"SplineRubberband")) != NULL) {
1350       if (UtilStrICmp(c_ptr, "false") == 0) {
1351          sprintf(gszMsgBox, TgLoadString(STID_NAMED_XDEF_IS_OBSOLETE),
1352                TOOL_NAME, "SplineRubberband");
1353          MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1354       }
1355    }
1356    saveTmpOnReturn = TRUE;
1357    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"SaveTmpOnReturn")) != NULL) {
1358       if (UtilStrICmp(c_ptr, "false") == 0) {
1359          saveTmpOnReturn = FALSE;
1360       }
1361    }
1362    dropObsIconAttrWhenUpdate = FALSE;
1363    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1364          "DropObsIconAttrWhenUpdate")) != NULL) {
1365       if (UtilStrICmp("true", c_ptr) == 0) {
1366          dropObsIconAttrWhenUpdate = TRUE;
1367       }
1368    }
1369    useRecentDupDistance = TRUE;
1370    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1371          "UseRecentDupDistance")) != NULL) {
1372       if (UtilStrICmp("false", c_ptr) == 0) {
1373          useRecentDupDistance = FALSE;
1374       }
1375    }
1376    handleSize = 3;
1377    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "HandleSize")) != NULL) {
1378       handleSize = atoi(c_ptr);
1379       if (handleSize < 2 || handleSize > 6) {
1380          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1381                TOOL_NAME, "HandleSize", c_ptr, 3);
1382          fprintf(stderr, "\n");
1383          handleSize = 3;
1384       }
1385    }
1386    historyDepth = -1;
1387    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "HistoryDepth")) != NULL) {
1388       historyDepth = atoi(c_ptr);
1389    }
1390    defaultHistoryDepth = historyDepth;
1391 
1392    undoRedoRestoreDrawingMode = TRUE;
1393    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1394          "UndoRedoRestoreDrawingMode")) != NULL &&
1395          UtilStrICmp("false", c_ptr) == 0) {
1396       undoRedoRestoreDrawingMode = FALSE;
1397    }
1398    canvasWindowOnly = FALSE;
1399    if (cmdLineCWO) {
1400       canvasWindowOnly = TRUE;
1401    } else if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"CanvasWindowOnly")) !=
1402          NULL) {
1403       if (UtilStrICmp("true", c_ptr) == 0) {
1404          canvasWindowOnly = TRUE;
1405       }
1406    }
1407    btn1Warp = FALSE;
1408    if (canvasWindowOnly) {
1409       if (cmdLineBtn1Warp) {
1410          btn1Warp = TRUE;
1411       } else if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,
1412             "QuickWarp")) != NULL) {
1413          if (UtilStrICmp("on", c_ptr) == 0 || UtilStrICmp("true", c_ptr) == 0) {
1414             btn1Warp = TRUE;
1415          }
1416       } else if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,
1417             "SingleButtonWarp")) != NULL) {
1418          if (UtilStrICmp("true", c_ptr) == 0) {
1419             btn1Warp = TRUE;
1420          }
1421       }
1422    }
1423    saveCommentsInSaveNew = TRUE;
1424    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1425          "SaveCommentsInSaveNew")) != NULL) {
1426       if (UtilStrICmp("false", c_ptr) == 0 ) {
1427          saveCommentsInSaveNew = FALSE;
1428       }
1429    }
1430    usePsAdobeString = FALSE;
1431    *adobeString = *epsfString = '\0';
1432 #ifdef _USE_PS_ADOBE_STRING
1433    {
1434       char buf[MAXSTRING];
1435 
1436       UtilStrCpyN(buf, sizeof(buf), _USE_PS_ADOBE_STRING);
1437       if (!ParsePsAdobeString(buf,&usePsAdobeString,adobeString,epsfString)) {
1438          fprintf(stderr, TgLoadString(STID_BAD_COMPILE_OPT_USE_ALT_STR),
1439                "_USE_PS_ADOBE_STRING", _USE_PS_ADOBE_STRING, "false");
1440          fprintf(stderr, "\n");
1441          usePsAdobeString = FALSE;
1442          *adobeString = *epsfString = '\0';
1443       }
1444    }
1445 #endif /* _USE_PS_ADOBE_STRING */
1446    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"UsePsAdobeString")) != NULL) {
1447       char tmp_str[80];
1448 
1449       usePsAdobeString = FALSE;
1450       *adobeString = *epsfString = '\0';
1451 
1452       UtilStrCpyN(tmp_str, sizeof(tmp_str), c_ptr);
1453       if (!ParsePsAdobeString(tmp_str, &usePsAdobeString, adobeString,
1454             epsfString)) {
1455          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1456                TOOL_NAME, "UsePsAdobeString", tmp_str, "false");
1457          fprintf(stderr, "\n");
1458          usePsAdobeString = FALSE;
1459          *adobeString = *epsfString = '\0';
1460       }
1461    }
1462    groupedTextEditable = TRUE;
1463    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "GroupedTextEditable")) !=
1464          NULL && UtilStrICmp(c_ptr, "false") == 0) {
1465       groupedTextEditable = FALSE;
1466    }
1467    intrCheckInterval = 10;
1468    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"IntrCheckInterval")) != NULL) {
1469       intrCheckInterval = atoi(c_ptr);
1470    }
1471    tiledPageScaling = 0.9;
1472    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"TiledPageScaling")) != NULL) {
1473       tiledPageScaling = (float)atof(c_ptr);
1474       if (tiledPageScaling <= 0.0 || tiledPageScaling > 1.0) {
1475          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1476                TOOL_NAME, "TiledPageScaling", c_ptr, "0.9");
1477          fprintf(stderr, "\n");
1478          tiledPageScaling = 0.9;
1479       }
1480    }
1481    stickyMenuSelection = TRUE;
1482    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1483          "StickyMenuSelection")) != NULL && UtilStrICmp("false", c_ptr) == 0) {
1484       stickyMenuSelection = FALSE;
1485    }
1486    gridShown = TRUE;
1487    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"InitialShowGrid")) != NULL) {
1488       if (UtilStrICmp("false", c_ptr) == 0) {
1489          gridShown = FALSE;
1490       }
1491    }
1492    snapOn = TRUE;
1493    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"InitialSnapOn")) != NULL) {
1494       if (UtilStrICmp("false", c_ptr) == 0) {
1495          snapOn = FALSE;
1496       }
1497    }
1498    noMenubar = FALSE;
1499    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"NoMenubar")) != NULL) {
1500       if (UtilStrICmp("true", c_ptr) == 0) {
1501          noMenubar = TRUE;
1502       }
1503    }
1504    noStatusWindow = FALSE;
1505    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"NoStatusWindow")) != NULL) {
1506       if (UtilStrICmp("true", c_ptr) == 0) {
1507          noStatusWindow = TRUE;
1508       }
1509    }
1510    noChoiceWindow = FALSE;
1511    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"NoChoiceWindow")) != NULL) {
1512       if (UtilStrICmp("true", c_ptr) == 0) {
1513          noChoiceWindow = TRUE;
1514       }
1515    }
1516    if (cmdLineNoModeWindow) {
1517       noModeWindow = TRUE;
1518    } else {
1519       noModeWindow = FALSE;
1520       if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"NoModeWindow")) != NULL) {
1521          if (UtilStrICmp("true", c_ptr) == 0) {
1522             noModeWindow = TRUE;
1523          }
1524       }
1525    }
1526    if (gstWBInfo.do_whiteboard) {
1527       if (cmdLineNoChatWindow) {
1528          noChatWindow = TRUE;
1529       } else {
1530          noChatWindow = FALSE;
1531          if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"NoChatWindow"))
1532                != NULL) {
1533             if (UtilStrICmp("true", c_ptr) == 0) {
1534                noChatWindow = TRUE;
1535             }
1536          }
1537       }
1538    }
1539    scrollBarW = baseScrollBarW = SCROLLBAR_W;
1540    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "ScrollBarWidth")) != NULL) {
1541       baseScrollBarW = atoi(c_ptr);
1542       if (baseScrollBarW < 2 || baseScrollBarW > 16) {
1543          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_RNG_USE_ALT_VAL),
1544                TOOL_NAME, "ScrollBarWidth", c_ptr, 2, 16, SCROLLBAR_W);
1545          fprintf(stderr, "\n");
1546          baseScrollBarW = SCROLLBAR_W;
1547       }
1548    }
1549    paper_size_set = FALSE;
1550    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"InitialPaperSize")) != NULL) {
1551       paper_size_set = SetPaperSize(c_ptr);
1552    }
1553    if (cmdLineLetter) {
1554       paper_size_set = SetPaperSize("letter");
1555    }
1556    pageStyle = PORTRAIT;
1557    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PageStyleLandscape")) !=
1558          NULL && UtilStrICmp("true", c_ptr) == 0) {
1559       pageStyle = LANDSCAPE;
1560       paper_size_set = TRUE;
1561    }
1562    /* do not translate -- program constants */
1563    wmDeleteWindowAtom = XInternAtom(mainDisplay, "WM_DELETE_WINDOW", False);
1564    targetsAtom = XInternAtom(mainDisplay, "TARGETS", False);
1565    utf8StringAtom = XInternAtom(mainDisplay, "UTF8_STRING", False);
1566    tgifProtocolAtom = XInternAtom(mainDisplay, TGIF_PROTOCOL_ATOM, False);
1567    tmpSelectionAtom = XInternAtom(mainDisplay, "TGIF_TMP_SELECTION_ATOM",
1568          False);
1569    compoundTextAtom = XInternAtom(mainDisplay, "COMPOUND_TEXT", False);
1570    textAtom = XInternAtom(mainDisplay, "TEXT", False);
1571    executeCmdByIDAtom = XInternAtom(mainDisplay, "TGIF_EXECUTE_CMD_BY_ID",
1572          False);
1573 
1574    InitStrTable();
1575    InitPaperSize();
1576 
1577    printMag = (float)100.0;
1578    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PercentPrintReduction")) !=
1579          NULL) {
1580       float print_reduction=(float)0.0;
1581 
1582       if (sscanf(c_ptr, "%f", &print_reduction) != 1) {
1583          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1584                TOOL_NAME, "PercentPrintReduction", c_ptr, 100);
1585          fprintf(stderr, "\n");
1586          print_reduction = (float)100.0;
1587       }
1588       if (printMag != print_reduction) {
1589          printMag = print_reduction;
1590          paper_size_set = TRUE;
1591       }
1592    }
1593    if (paper_size_set) UpdPageStyle(pageStyle);
1594 
1595    usePaperSizeStoredInFile = TRUE;
1596    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"UsePaperSizeStoredInFile")) !=
1597          NULL && UtilStrICmp("false", c_ptr) == 0) {
1598       usePaperSizeStoredInFile = FALSE;
1599    }
1600    oneMotionSelectMove = FALSE;
1601    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"OneMotionSelMove")) != NULL) {
1602       if (UtilStrICmp("true", c_ptr) == 0) {
1603          oneMotionSelectMove = TRUE;
1604       }
1605    }
1606    queryZoomInPoint = FALSE;
1607    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"QueryZoomInPoint")) != NULL) {
1608       if (UtilStrICmp("true",c_ptr)==0 || UtilStrICmp("always",c_ptr)==0) {
1609          queryZoomInPoint = TRUE;
1610       } else if (UtilStrICmp("no_select",c_ptr) == 0) {
1611          queryZoomInPoint = INVALID;
1612       } else if (UtilStrICmp("no_query",c_ptr) == 0) {
1613          queryZoomInPoint = BAD;
1614       }
1615    }
1616    lineStyle = LS_RIGHT;
1617    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"InitialArrowStyle")) != NULL) {
1618       if (UtilStrICmp("NONE",c_ptr) == 0) {
1619          lineStyle = LS_PLAIN;
1620       } else if (UtilStrICmp("RIGHT",c_ptr) == 0) {
1621          lineStyle = LS_RIGHT;
1622       } else if (UtilStrICmp("LEFT",c_ptr) == 0) {
1623          lineStyle = LS_LEFT;
1624       } else if (UtilStrICmp("DOUBLE",c_ptr) == 0) {
1625          lineStyle = LS_DOUBLE;
1626       } else {
1627          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1628                TOOL_NAME, "InitialArrowStyle", c_ptr, "RIGHT");
1629          fprintf(stderr, "\n");
1630       }
1631    }
1632    showPageInEPS = TRUE;
1633    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"ShowPageInEPS")) !=
1634          NULL && UtilStrICmp("false", c_ptr) == 0) {
1635       showPageInEPS = FALSE;
1636    }
1637    oneMotionTimeout = 200;
1638    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"OneMotionTimeout")) != NULL) {
1639       oneMotionTimeout = atoi(c_ptr);
1640       if (oneMotionTimeout < 0 || oneMotionTimeout >= 1000) {
1641          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_RNG_USE_ALT_VAL),
1642                TOOL_NAME, "OneMotionTimeout", c_ptr, 0, 1000, 200);
1643          fprintf(stderr, "\n");
1644          oneMotionTimeout = 200;
1645       }
1646    }
1647    minMoveInterval = 0;
1648    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"MinMoveInterval")) != NULL) {
1649       minMoveInterval = atoi(c_ptr);
1650       if (minMoveInterval < 0 || minMoveInterval >= 1000) {
1651          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_RNG_USE_ALT_VAL),
1652                TOOL_NAME, "MinMoveInterval", c_ptr, 0, 1000, 0);
1653          fprintf(stderr, "\n");
1654          minMoveInterval = 0;
1655       }
1656    }
1657    rotationIncrement = (45<<6); /* initially 45 degrees */
1658    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"RotationIncrement")) != NULL) {
1659       float fval;
1660 
1661       if (sscanf(c_ptr, "%f", &fval) != 1 || fval < (float)0.0) {
1662          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_VALUE),
1663                TOOL_NAME, "RotationIncrement", c_ptr, 45);
1664          fprintf(stderr, "\n");
1665       } else {
1666          while (fval < (float)360.0) fval += (float)360.0;
1667          while (fval >= (float)360.0) fval -= (float)360.0;
1668          fval *= 64.0;
1669          rotationIncrement = round(fval);
1670       }
1671    }
1672    stretchableText = TRUE;
1673    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "StretchableText")) != NULL &&
1674          UtilStrICmp(c_ptr, "false") == 0) {
1675       stretchableText = FALSE;
1676    }
1677    compoundObjWithTextStretchableForPSE = FALSE;
1678    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1679          "CompoundObjWithTextStretchableForPSE")) != NULL &&
1680          UtilStrICmp(c_ptr, "true") == 0) {
1681       compoundObjWithTextStretchableForPSE = TRUE;
1682    }
1683    SetEditTextSizeValue(0);
1684    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "EditTextSize")) != NULL) {
1685       int new_edit_text_size=atoi(c_ptr);
1686 
1687       if (new_edit_text_size == 0) {
1688       } else if (new_edit_text_size < 4 || new_edit_text_size > 34) {
1689          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_RNG_USE_ALT_VAL),
1690                TOOL_NAME, "EditTextSize", c_ptr, 4, 34, 14);
1691          fprintf(stderr, "\n");
1692          SetEditTextSizeValue(14);
1693       } else {
1694          SetEditTextSizeValue(new_edit_text_size);
1695       }
1696    }
1697    tmpFileMode = PSFILE_MOD;
1698    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TmpFileMode")) != NULL) {
1699       int nFileMode=0;
1700 
1701       strcpy(gszMsgBox, c_ptr);
1702 
1703       UtilTrimBlanks(gszMsgBox);
1704       if (*gszMsgBox != '\0' && sscanf(gszMsgBox, "%o", &nFileMode) == 1) {
1705          if (nFileMode >= 0) {
1706             tmpFileMode = nFileMode;
1707          } else {
1708             fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_OCTVALUE),
1709                   TOOL_NAME, "TmpFileMode", gszMsgBox, PSFILE_MOD);
1710             fprintf(stderr, "\n");
1711          }
1712       }
1713    }
1714    titledPinnedMenu = TRUE;
1715    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TitledPinnedMenu")) !=
1716          NULL && UtilStrICmp(c_ptr, "false") == 0) {
1717       titledPinnedMenu = FALSE;
1718    }
1719    gfVectorWarpSoftness = (float)2.0;
1720    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"VectorWarpSoftness")) !=
1721          NULL) {
1722       if (sscanf(c_ptr, "%f", &gfVectorWarpSoftness) != 1) {
1723          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1724                TOOL_NAME, "VectorWarpSoftness", c_ptr, "2.0");
1725          fprintf(stderr, "\n");
1726          gfVectorWarpSoftness = (float)2.0;
1727       } else if (gfVectorWarpSoftness > 4.0 || gfVectorWarpSoftness < 1.0) {
1728          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_RNG_USE_ALT_STR),
1729                TOOL_NAME, "VectorWarpSoftness", c_ptr, "1.0", "4.0", "2.0");
1730          fprintf(stderr, "\n");
1731          gfVectorWarpSoftness = (float)2.0;
1732       }
1733    }
1734    queryPolyNameOnConnect = TRUE;
1735    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "QueryPolyNameOnConnect")) !=
1736          NULL && UtilStrICmp(c_ptr, "false") == 0) {
1737       queryPolyNameOnConnect = FALSE;
1738    }
1739    shiftForDiagMouseMove = TRUE;
1740    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1741          "ShiftForDiagMouseMove")) != NULL) {
1742       if (UtilStrICmp(c_ptr, "true") == 0) {
1743          shiftForDiagMouseMove = TRUE;
1744       } else if (UtilStrICmp(c_ptr, "false") == 0) {
1745          shiftForDiagMouseMove = FALSE;
1746       }
1747    }
1748    useRecentForDiagMouseMove = FALSE;
1749 #ifdef RESTRICTED_MOUSE_MOVE
1750    useRecentForDiagMouseMove = TRUE;
1751 #endif /* RESTRICTED_MOUSE_MOVE */
1752    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1753          "UseRecentForDiagMouseMove")) != NULL) {
1754       if (UtilStrICmp(c_ptr, "true") == 0) {
1755          useRecentForDiagMouseMove = TRUE;
1756       } else if (UtilStrICmp(c_ptr, "false") == 0) {
1757          useRecentForDiagMouseMove = FALSE;
1758       }
1759    }
1760    flushColormapOnOpen = FALSE;
1761 #ifdef USE_FLUSH_COLORMAP
1762    flushColormapOnOpen = TRUE;
1763 #endif /* USE_FLUSH_COLORMAP */
1764    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1765          "FlushColormapOnOpen")) != NULL) {
1766       if (UtilStrICmp(c_ptr, "true") == 0) {
1767          flushColormapOnOpen = TRUE;
1768       } else if (UtilStrICmp(c_ptr, "false") == 0) {
1769          flushColormapOnOpen = FALSE;
1770       }
1771    }
1772    transPat = FALSE;
1773    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TransparentPattern")) !=
1774          NULL && UtilStrICmp(c_ptr, "true") == 0) {
1775       transPat = TRUE;
1776    }
1777    initialMenubarWindowH = MENUBAR_WINDOW_H;
1778 
1779    *scanFileFullPath = *scanFileName = '\0';
1780    scanLineNum = 0;
1781 
1782    colorDisplay = (cmdLineBW || DisplayPlanes(mainDisplay,mainScreen)==1 ||
1783          mainVisual->class==StaticGray) ? FALSE : TRUE;
1784    fullTrueColorMode = FALSE;
1785    if (colorDisplay && mainVisual->class == TrueColor) {
1786       if (HasZlibSupport()) {
1787          /* starting with tgif-4.2.3, this is the default */
1788          fullTrueColorMode = TRUE;
1789 #ifdef _TGIF_DBG
1790       } else {
1791          fprintf(stderr, TgLoadString(STID_CANNOT_SET_XDEF_TRUE_NO_ZLIB),
1792                TOOL_NAME, "EnableTrueColorImages", TOOL_NAME);
1793          fprintf(stderr, "\n");
1794 #endif /* _TGIF_DBG */
1795       }
1796       if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"EnableTrueColorImages")) !=
1797             NULL && UtilStrICmp(c_ptr, "false") == 0) {
1798          fullTrueColorMode = FALSE;
1799       }
1800    }
1801    noAntiAlias = TRUE;
1802    if (fullTrueColorMode) {
1803       InitAntiAlias();
1804    }
1805    threeDLook = colorDisplay;
1806    if (threeDLook && (c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "3DLook")) !=
1807          NULL && UtilStrICmp(c_ptr, "false") == 0) {
1808       threeDLook = FALSE;
1809    }
1810    dialogboxUse3DBorder = threeDLook;
1811    if (threeDLook && (c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1812          "DialogboxUse3DBorder")) != NULL && UtilStrICmp(c_ptr, "false") == 0) {
1813       dialogboxUse3DBorder = FALSE;
1814    }
1815    if (threeDLook) {
1816       windowPadding = WINDOW_PADDING;
1817       brdrW = 0;
1818    }
1819    InitColor();
1820    bg_pixel = (threeDLook ? myLtGryPixel : myBgPixel);
1821 
1822    if ((c_ptr=getenv("TGIFPATH")) == NULL) {
1823       if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TGIFPATH")) != NULL) {
1824          strcpy(drawPath, c_ptr);
1825       } else {
1826          strcpy(drawPath, TGIF_PATH);
1827       }
1828    } else if (strlen(c_ptr) >= 255) {
1829       strcpy(drawPath, TGIF_PATH);
1830    } else {
1831       strcpy(drawPath, c_ptr);
1832    }
1833    i = strlen(drawPath);
1834    if (drawPath[i-1] == DIR_SEP) drawPath[i-1] = '\0';
1835 
1836    InitTmpDir();
1837 
1838    enableMouseWheel = TRUE;
1839    if (threeDLook && (c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1840          "EnableMouseWheel")) != NULL && UtilStrICmp(c_ptr, "false") == 0) {
1841       enableMouseWheel = FALSE;
1842    }
1843    btn2PopupMainMenu = TRUE;
1844    if (threeDLook && (c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1845          "Btn2PopupMainMenu")) != NULL && UtilStrICmp(c_ptr, "false") == 0) {
1846       btn2PopupMainMenu = FALSE;
1847    }
1848    defRightMarginEnabled = INVALID;
1849    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"EnableRightMargin")) != NULL) {
1850       if (UtilStrICmp("true", c_ptr) == 0) {
1851          defRightMarginEnabled = TRUE;
1852       } else {
1853          defRightMarginEnabled = FALSE;
1854       }
1855    }
1856    if (gridSystem == ENGLISH_GRID) {
1857       defRightMargin = ONE_INCH;
1858    } else {
1859       defRightMargin = (ONE_CM<<1)+(ONE_CM>>1);
1860    }
1861    dval = ((double)defRightMargin) * ((double)100) * ((double)TIK_PER_PIXEL) /
1862          ((double)printMag);
1863    defRightMargin = round(dval);
1864    if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"RightMargin")) != NULL) {
1865       char spec_buf[40];
1866 
1867       UtilStrCpyN(spec_buf, sizeof(spec_buf), c_ptr);
1868       UtilTrimBlanks(spec_buf);
1869       if (GetDimensionInDouble(spec_buf, TRUE, &dval)) {
1870          dval = dval * ((double)100) * ((double)TIK_PER_PIXEL) /
1871                ((double)printMag);
1872          defRightMargin = round(dval);
1873       } else {
1874          fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
1875                TOOL_NAME, "RightMargin", c_ptr,
1876                (gridSystem==ENGLISH_GRID) ? "1 in" : "2.5 cm");
1877          fprintf(stderr, "\n");
1878       }
1879    }
1880    rightMargin = defRightMargin;
1881    rightMarginEnabled = defRightMarginEnabled;
1882    rightMarginActive = (rightMarginEnabled == TRUE);
1883 
1884    InitFonts();
1885 
1886    initialMenubarWindowH = defaultFontHeight;
1887    if (msgFontSet==NULL && msgFontPtr == NULL) {
1888       statusSubWindowH[0] = defaultFontHeight+2+windowPadding;
1889    } else {
1890       statusSubWindowH[0] = msgFontHeight+2+windowPadding;
1891    }
1892    statusWindowH = max(statusSubWindowH[0]+(brdrW<<1)+2, btn1_height+2);
1893    if (threeDLook) {
1894       statusWindowH += windowPadding;
1895    }
1896    userRedrawWindowH = statusWindowH;
1897 
1898    InitChat();
1899    chatWindowH = GetInitialChatWindowHeight();
1900    if (threeDLook) {
1901       chatWindowH += windowPadding;
1902    }
1903    noMinWinSize = TRUE;
1904    if (threeDLook && (c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
1905          "NoMinWinSize")) != NULL && UtilStrICmp(c_ptr, "false") == 0) {
1906       noMinWinSize = FALSE;
1907    }
1908    if (noMinWinSize) {
1909       sizehints.flags = PSize;
1910    } else {
1911       sizehints.flags = PSize | PMinSize;
1912    }
1913    sizehints.x = 0;
1914    sizehints.y = 0;
1915    sizehints.width = mainWinW;
1916    sizehints.height = mainWinH;
1917 
1918    if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "Geometry")) != NULL) {
1919       bitmask = XParseGeometry(c_ptr, &(sizehints.x), &(sizehints.y),
1920             (unsigned int *)&(sizehints.width),
1921             (unsigned int *)&(sizehints.height));
1922       if (bitmask & (XValue | YValue)) sizehints.flags |= USPosition;
1923       if (bitmask & (WidthValue | HeightValue)) {
1924          sizehints.flags |= USSize;
1925          drawWinW = sizehints.width;
1926          drawWinH = sizehints.height;
1927          InitWinSizes();
1928          mainWinW = sizehints.width;
1929          mainWinH = sizehints.height;
1930          InverseInitWinSizes();
1931       }
1932       if (bitmask & XNegative) {
1933          x_neg_in_def = TRUE;
1934          def_x_neg = sizehints.x;
1935       }
1936       if (bitmask & YNegative) {
1937          y_neg_in_def = TRUE;
1938          def_y_neg = sizehints.y;
1939       }
1940    }
1941 
1942    if (geometrySpecified && *geometrySpec != '\0') {
1943       bitmask = XParseGeometry(geometrySpec, &(sizehints.x), &(sizehints.y),
1944             (unsigned int *)&(sizehints.width),
1945             (unsigned int *)&(sizehints.height));
1946       if (bitmask & (XValue | YValue)) sizehints.flags |= USPosition;
1947       if (bitmask & (WidthValue | HeightValue)) {
1948          sizehints.flags |= USSize;
1949          drawWinW = sizehints.width;
1950          drawWinH = sizehints.height;
1951          InitWinSizes();
1952          mainWinW = sizehints.width;
1953          mainWinH = sizehints.height;
1954          InverseInitWinSizes();
1955       }
1956       if (bitmask & XValue) x_in_cmdline = TRUE;
1957       if (bitmask & YValue) y_in_cmdline = TRUE;
1958    }
1959    InitWinSizes();
1960 
1961    if (canvasWindowOnly) {
1962       noMenubar = TRUE;
1963       noStatusWindow = TRUE;
1964       noChoiceWindow = TRUE;
1965       noModeWindow = TRUE;
1966       noChatWindow = TRUE;
1967 
1968       mainWinW = initDrawWinW;
1969       mainWinH = initDrawWinH;
1970 
1971       switch (gridSystem) {
1972       case ENGLISH_GRID:
1973          sizehints.min_width = HALF_INCH+3*brdrW;
1974          sizehints.min_height = HALF_INCH+3*brdrW;
1975          break;
1976       case METRIC_GRID:
1977          sizehints.min_width = ONE_CM+3*brdrW;
1978          sizehints.min_height = ONE_CM+3*brdrW;
1979          break;
1980       }
1981       if (mainWinW > sizehints.min_width) {
1982          sizehints.width = mainWinW;
1983       } else {
1984          sizehints.width = sizehints.min_width = mainWinW;
1985       }
1986       if (mainWinH > sizehints.min_height) {
1987          sizehints.height = mainWinH;
1988       } else {
1989          sizehints.height = sizehints.min_height = mainWinH;
1990       }
1991       drawWinW = initDrawWinW = mainWinW-(brdrW<<1);
1992       drawWinH = initDrawWinH = mainWinH-(brdrW<<1);
1993       if (msgWindowW <= 0) msgWindowW = 1;
1994    } else {
1995       sizehints.min_width =
1996             (noModeWindow ? 0 : modeWindowW+(brdrW<<1))+
1997             choiceWindowW+(brdrW<<2)+defaultFontWidth;
1998       sizehints.min_height =
1999             (noMenubar ? 0 : menubarWindowH+(brdrW<<1))+
2000             (noStatusWindow ? 0 : statusWindowH+(brdrW<<1))+
2001             (noChoiceWindow ? 0 : msgWindowH+(brdrW<<1))+
2002             (noChatWindow ? 0 : chatWindowH+(brdrW<<1))+
2003             titleWindowH+ONE_INCH+rulerW+scrollBarW+8*brdrW;
2004       if (mainWinW > sizehints.min_width) {
2005          sizehints.width = mainWinW;
2006       } else {
2007          mainWinW = sizehints.width = sizehints.min_width;
2008       }
2009       if (mainWinH > sizehints.min_height) {
2010          sizehints.height = mainWinH;
2011       } else {
2012          mainWinH = sizehints.height = sizehints.min_height;
2013       }
2014       InverseInitWinSizes();
2015    }
2016    if (bitmask & XNegative) {
2017       sizehints.x += DisplayWidth(mainDisplay,mainScreen)-mainWinW-1;
2018    } else if (!x_in_cmdline && x_neg_in_def) {
2019       sizehints.x = def_x_neg+DisplayWidth(mainDisplay,mainScreen)-mainWinW-1;
2020    }
2021    if (bitmask & YNegative) {
2022       sizehints.y += DisplayHeight(mainDisplay,mainScreen)-mainWinH-1;
2023    } else if (!y_in_cmdline && y_neg_in_def) {
2024       sizehints.y = def_y_neg+DisplayHeight(mainDisplay,mainScreen)-mainWinH-1;
2025    }
2026    if ((mainWindow=XCreateSimpleWindow(mainDisplay, rootWindow,
2027          sizehints.x, sizehints.y, sizehints.width, sizehints.height,
2028          brdrW, myBorderPixel, myBgPixel)) == 0) {
2029       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2030    }
2031    if (gstWBInfo.do_whiteboard) {
2032       if ( cmdLineParentWindowID > 0 ) {
2033          XReparentWindow(mainDisplay, mainWindow, cmdLineParentWindowID, 0, 0);
2034       }
2035    } else {
2036       if ( cmdLineTgrm2 && cmdLineParentWindowID > 0 ) {
2037          XReparentWindow(mainDisplay, mainWindow, cmdLineParentWindowID, 0, 0);
2038       }
2039    }
2040    if (newColormapUsed) {
2041       XSetWindowColormap(mainDisplay, mainWindow, mainColormap);
2042    }
2043    InitMenu();
2044    InitPattern();
2045 
2046    InitRuler();
2047    InitNames();
2048    InitStk();
2049    InitXBm();
2050    InitXPm();
2051    CreateCursor();
2052    lastPageNum = 1;
2053    InitPage();
2054    InitPins();
2055    InitInputMethods();
2056    InitPS();
2057 
2058    if ((titleWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0, 0,
2059          titleWindowW, titleWindowH, brdrW, myBorderPixel, bg_pixel)) == 0) {
2060       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2061    }
2062    cur_y += titleWindowH + (brdrW<<1);
2063 
2064    if ((menubarWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0,
2065          cur_y, menubarWindowW, menubarWindowH, brdrW, myBorderPixel,
2066          bg_pixel)) == 0) {
2067       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2068    }
2069    if (!noMenubar) {
2070       cur_y += menubarWindowH + (brdrW<<1);
2071    }
2072    if ((choiceWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0, cur_y,
2073          choiceWindowW, choiceWindowH, brdrW, myBorderPixel, bg_pixel)) == 0) {
2074       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2075    }
2076    if ((msgWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2077          choiceWindowW+(brdrW<<1), cur_y,
2078          msgWindowW, msgWindowH, brdrW, myBorderPixel, myBgPixel)) == 0) {
2079       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2080    }
2081    if (!noChoiceWindow) {
2082       cur_y += msgWindowH + (brdrW<<1);
2083    }
2084    InitChoice();
2085 
2086    if ((modeWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0,
2087          cur_y, modeWindowW, modeWindowH, brdrW, myBorderPixel,
2088          bg_pixel)) == 0) {
2089       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2090    }
2091    x_offset = (noModeWindow ? 0 : modeWindowW+(brdrW<<1));
2092    if ((dummyWindow1=XCreateSimpleWindow(mainDisplay, mainWindow, x_offset,
2093          cur_y, rulerW, rulerW, 1, myBorderPixel, myBgPixel)) == 0) {
2094       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2095    }
2096    if ((hRuleWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2097          x_offset+rulerW+(brdrW<<1), cur_y, drawWinW, rulerW-windowPadding,
2098          1, myBorderPixel, myBgPixel)) == 0) {
2099       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2100    }
2101    if ((colorWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2102          x_offset+(brdrW<<2)+rulerW+drawWinW, cur_y, scrollBarW, colorWindowH,
2103          brdrW, myBorderPixel, bg_pixel)) == 0) {
2104       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2105    }
2106    if ((colorDummyWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2107          x_offset+(brdrW<<2)+rulerW+drawWinW, cur_y+colorWindowH+(brdrW<<1),
2108          scrollBarW, colorDummyWindowH, brdrW, myBorderPixel, bg_pixel)) == 0) {
2109       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2110    }
2111    if ((vSBarWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2112          x_offset+(brdrW<<2)+rulerW+drawWinW,
2113          colorLayers ? cur_y+colorWindowH+colorDummyWindowH+(brdrW<<2) : cur_y,
2114          scrollBarW, vSBarH, brdrW, myBorderPixel, bg_pixel)) == 0) {
2115       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2116    }
2117    cur_y += rulerW + (brdrW<<1);
2118 
2119    if ((vRuleWindow=XCreateSimpleWindow(mainDisplay, mainWindow, x_offset,
2120          cur_y, rulerW-windowPadding, drawWinH, 1, myBorderPixel,
2121          myBgPixel)) == 0) {
2122       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2123    }
2124    if ((drawWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2125          x_offset+rulerW+(brdrW<<1), cur_y, drawWinW, drawWinH, 0,
2126          myBorderPixel, myBgPixel)) == 0) {
2127       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2128    }
2129    cur_y += drawWinH + (brdrW<<1);
2130 
2131    if ((pageWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0, cur_y,
2132          pageWindowW, scrollBarW+(brdrW<<1), 0, myBorderPixel,
2133          bg_pixel)) == 0) {
2134       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2135    }
2136    if ((pageDummyWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2137          pageWindowW, cur_y, pageDummyWindowW, scrollBarW, brdrW,
2138          myBorderPixel, bg_pixel)) == 0) {
2139       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2140    }
2141    if ((hSBarWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2142          pageWindowW+pageDummyWindowW+(brdrW<<1), cur_y,
2143          hSBarW, scrollBarW, brdrW, myBorderPixel, bg_pixel)) == 0) {
2144       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2145    }
2146    if ((dummyWindow2=XCreateSimpleWindow(mainDisplay, mainWindow,
2147          x_offset+rulerW+drawWinW+(brdrW<<2), cur_y,
2148          scrollBarW, scrollBarW, brdrW, myBorderPixel, bg_pixel)) == 0) {
2149       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2150    }
2151    cur_y += scrollBarW + (brdrW<<1);
2152 
2153    if ((userRedrawWindow=XCreateSimpleWindow(mainDisplay, mainWindow, 0,
2154          cur_y, userRedrawWindowW, userRedrawWindowH, brdrW, myBorderPixel,
2155          bg_pixel)) == 0) {
2156       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2157    }
2158    if ((statusWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2159          userRedrawWindowW+(brdrW<<1), cur_y, statusWindowW, statusWindowH,
2160          brdrW, myBorderPixel, bg_pixel)) == 0) {
2161       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2162    }
2163    cur_y += statusWindowH + (brdrW<<1);
2164 
2165    if ((chatWindow=XCreateSimpleWindow(mainDisplay, mainWindow,
2166          0, cur_y, chatWindowW, chatWindowH, brdrW, myBorderPixel,
2167          bg_pixel)) == 0) {
2168       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2169    }
2170    InitScroll();
2171    CalcStatusSubWinGeom();
2172    for (i=0; i < MAX_STATUS_BTNS; i++) {
2173       if ((statusSubWindow[i]=XCreateSimpleWindow(mainDisplay,
2174             statusWindow, statusSubWindowX[i], statusSubWindowY[i],
2175             statusSubWindowW[i], statusSubWindowH[i], brdrW,
2176             myBorderPixel, bg_pixel)) == 0) {
2177          FailToCreateWindowMessage("Setup()", NULL, TRUE);
2178       }
2179    }
2180    InitTidget();
2181    InitColorWheel();
2182    InitInsertSymbol();
2183 
2184    if (!CreateChatSubWindows()) {
2185       FailToCreateWindowMessage("Setup()", NULL, TRUE);
2186    }
2187    if (!noChatWindow) {
2188       cur_y += chatWindowH + (brdrW<<1);
2189    }
2190    if (!noStatusWindow) {
2191       cur_y += statusWindowH + (brdrW<<1);
2192    }
2193    if (canvasWindowOnly) {
2194       XMoveResizeWindow(mainDisplay, drawWindow, 0, 0, drawWinW, drawWinH);
2195       XResizeWindow(mainDisplay, mainWindow, mainWinW, mainWinH);
2196    }
2197 
2198 #ifdef NOTR4MODE
2199    XSetNormalHints(mainDisplay, mainWindow, &sizehints);
2200 #else /* ~NOTR4MODE */
2201    XSetWMNormalHints(mainDisplay, mainWindow, &sizehints);
2202 #endif /* NOTR4MODE */
2203    XStoreName(mainDisplay, mainWindow, TOOL_NAME);
2204 
2205    UpdDrawWinBBox();
2206    InitTitle();
2207    InitStatus();
2208    SetCanvasFont();
2209 
2210    InitText();
2211    InitRemote();
2212    InitNavigate();
2213    InitExec();
2214    InitImageProc();
2215    InitImport();
2216    InitHelp();
2217    InitShape();
2218 
2219    InitExportFilters();
2220    InitProperties();
2221    InitCutPaste();
2222    InitEdit();
2223    InitMark();
2224    InitVersion();
2225    InitMiniLines();
2226 
2227    if (PRTGIF) {
2228       return;
2229    }
2230 #ifndef _NO_NKF
2231    InitNKF();
2232 #endif /* ~_NO_NKF */
2233 
2234    if (cmdLineTgrm2) {
2235       InitTangram2();
2236    }
2237    InitShortCut();
2238    InitHtml();
2239    InitRecentFiles();
2240    InitMeasureTooltip();
2241    InitPoly();
2242    InitSpecial();
2243    InitAttr();
2244    InitTalkToSelfFiledes();
2245 
2246 #ifdef MAPBEFORESELECT
2247    XMapWindow(mainDisplay, mainWindow);
2248    XSelectInput(mainDisplay, mainWindow, KeyPressMask | StructureNotifyMask
2249          | VisibilityChangeMask | FocusChangeMask);
2250 #else
2251    XSelectInput(mainDisplay, mainWindow, KeyPressMask | StructureNotifyMask
2252          | VisibilityChangeMask | FocusChangeMask);
2253    XMapWindow(mainDisplay, mainWindow);
2254 #endif
2255    XDefineCursor(mainDisplay, mainWindow, defaultCursor);
2256 
2257    RegisterWM_DELETE_WINDOW(mainWindow);
2258 
2259 #ifdef MAPBEFORESELECT
2260    if (canvasWindowOnly) {
2261       XMapWindow(mainDisplay, drawWindow);
2262       XSelectInput(mainDisplay, drawWindow, ButtonReleaseMask |
2263             ButtonPressMask | PointerMotionMask | KeyPressMask |
2264             KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask |
2265             PropertyChangeMask);
2266    } else {
2267       XMapWindow(mainDisplay, titleWindow);
2268       XSelectInput(mainDisplay, titleWindow, ExposureMask |
2269             EnterWindowMask | LeaveWindowMask | ButtonPressMask |
2270             PointerMotionMask);
2271 
2272       if (menubarWindow != None) XMapWindow(mainDisplay, menubarWindow);
2273       XSelectInput(mainDisplay, menubarWindow, ExposureMask |
2274             EnterWindowMask | LeaveWindowMask | ButtonPressMask |
2275             PointerMotionMask);
2276 
2277       if (!noChoiceWindow) XMapWindow(mainDisplay, msgWindow);
2278       XSelectInput(mainDisplay, msgWindow, ButtonPressMask |
2279             ButtonReleaseMask | PointerMotionMask | ExposureMask |
2280             EnterWindowMask);
2281 
2282       if (!noChoiceWindow) XMapWindow(mainDisplay, choiceWindow);
2283       XSelectInput(mainDisplay, choiceWindow,
2284             ButtonReleaseMask | ButtonPressMask | ExposureMask |
2285             PointerMotionMask | EnterWindowMask | LeaveWindowMask);
2286 
2287       XMapWindow(mainDisplay, hRuleWindow);
2288       XSelectInput(mainDisplay, hRuleWindow,
2289             ButtonPressMask | ExposureMask | EnterWindowMask);
2290       XMapWindow(mainDisplay, vRuleWindow);
2291       XSelectInput(mainDisplay, vRuleWindow,
2292             ButtonPressMask | ExposureMask | EnterWindowMask);
2293 
2294       XMapWindow(mainDisplay, drawWindow);
2295       XSelectInput(mainDisplay, drawWindow, ButtonReleaseMask |
2296             ButtonPressMask | PointerMotionMask | KeyPressMask |
2297             KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask |
2298             PropertyChangeMask);
2299 
2300       if (colorLayers) {
2301          XMapWindow(mainDisplay, colorWindow);
2302          XSelectInput(mainDisplay, colorWindow, ButtonPressMask |
2303                PointerMotionMask | ExposureMask | EnterWindowMask);
2304          XMapWindow(mainDisplay, colorDummyWindow);
2305          XSelectInput(mainDisplay, colorDummyWindow, ButtonPressMask |
2306                ExposureMask | EnterWindowMask);
2307       } else {
2308          XSelectInput(mainDisplay, colorWindow, ButtonPressMask |
2309                PointerMotionMask | ExposureMask | EnterWindowMask);
2310          XSelectInput(mainDisplay, colorDummyWindow, ButtonPressMask |
2311                ExposureMask | EnterWindowMask);
2312       }
2313       XMapWindow(mainDisplay, vSBarWindow);
2314       XSelectInput(mainDisplay, vSBarWindow, ButtonPressMask |
2315             ExposureMask | EnterWindowMask | PointerMotionMask);
2316 
2317       XMapWindow(mainDisplay, pageWindow);
2318       XSelectInput(mainDisplay, pageWindow, ButtonPressMask |
2319             PointerMotionMask | ExposureMask | EnterWindowMask);
2320       XMapWindow(mainDisplay, pageDummyWindow);
2321       XSelectInput(mainDisplay, pageDummyWindow, ButtonPressMask |
2322             ExposureMask | EnterWindowMask);
2323       XMapWindow(mainDisplay, hSBarWindow);
2324       XSelectInput(mainDisplay, hSBarWindow, ButtonPressMask |
2325             ExposureMask | EnterWindowMask | PointerMotionMask);
2326       XMapWindow(mainDisplay, dummyWindow1);
2327       XSelectInput(mainDisplay, dummyWindow1, ButtonPressMask | ExposureMask |
2328             EnterWindowMask | LeaveWindowMask);
2329       XMapWindow(mainDisplay, dummyWindow2);
2330       XSelectInput(mainDisplay, dummyWindow2, ExposureMask | EnterWindowMask);
2331 
2332       if (!noChatWindow) {
2333          XMapWindow(mainDisplay, chatWindow);
2334       }
2335       MapChatSubWindows();
2336       XSelectInput(mainDisplay, chatWindow,
2337             KeyPressMask | ButtonPressMask | ExposureMask |
2338             StructureNotifyMask | EnterWindowMask | LeaveWindowMask);
2339 
2340       if (!noStatusWindow) {
2341          XMapWindow(mainDisplay, userRedrawWindow);
2342          XSelectInput(mainDisplay, userRedrawWindow, ButtonPressMask |
2343                ExposureMask | EnterWindowMask);
2344          XMapWindow(mainDisplay, statusWindow);
2345          XSelectInput(mainDisplay, statusWindow, ExposureMask |
2346                EnterWindowMask);
2347          for (i=0; i < MAX_STATUS_BTNS; i++) {
2348             XMapWindow(mainDisplay, statusSubWindow[i]);
2349          }
2350       } else {
2351          XSelectInput(mainDisplay, userRedrawWindow, ButtonPressMask |
2352                ExposureMask | EnterWindowMask);
2353          XSelectInput(mainDisplay, statusWindow, ExposureMask |
2354                EnterWindowMask);
2355       }
2356       if (!noModeWindow) XMapWindow(mainDisplay, modeWindow);
2357       XSelectInput(mainDisplay, modeWindow, ButtonPressMask | ExposureMask |
2358             PointerMotionMask | EnterWindowMask | LeaveWindowMask);
2359    }
2360 #else /* ~MAPBEFORESELECT */
2361    if (canvasWindowOnly) {
2362       XSelectInput(mainDisplay, drawWindow, ButtonReleaseMask |
2363             ButtonPressMask | PointerMotionMask | KeyPressMask |
2364             KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask |
2365             PropertyChangeMask);
2366       XMapWindow(mainDisplay, drawWindow);
2367    } else {
2368       XSelectInput(mainDisplay, titleWindow, ExposureMask |
2369             EnterWindowMask | LeaveWindowMask | ButtonPressMask |
2370             PointerMotionMask);
2371       XMapWindow(mainDisplay, titleWindow);
2372 
2373       XSelectInput(mainDisplay, menubarWindow, ExposureMask |
2374             EnterWindowMask | LeaveWindowMask | ButtonPressMask |
2375             PointerMotionMask);
2376       if (menubarWindow != None) XMapWindow(mainDisplay, menubarWindow);
2377 
2378       XSelectInput(mainDisplay, msgWindow, ButtonPressMask |
2379             ButtonReleaseMask | PointerMotionMask | ExposureMask |
2380             EnterWindowMask);
2381       if (!noChoiceWindow) XMapWindow(mainDisplay, msgWindow);
2382 
2383       XSelectInput(mainDisplay, choiceWindow,
2384             ButtonReleaseMask | ButtonPressMask | ExposureMask |
2385             PointerMotionMask | EnterWindowMask | LeaveWindowMask);
2386       if (!noChoiceWindow) XMapWindow(mainDisplay, choiceWindow);
2387 
2388       XSelectInput(mainDisplay, hRuleWindow,
2389             ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
2390             ExposureMask | EnterWindowMask);
2391       XMapWindow(mainDisplay, hRuleWindow);
2392       XSelectInput(mainDisplay, vRuleWindow,
2393             ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
2394             ExposureMask | EnterWindowMask);
2395       XMapWindow(mainDisplay, vRuleWindow);
2396 
2397       XSelectInput(mainDisplay, drawWindow, ButtonReleaseMask |
2398             ButtonPressMask | PointerMotionMask | KeyPressMask |
2399             KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask |
2400             PropertyChangeMask);
2401       XMapWindow(mainDisplay, drawWindow);
2402 
2403       if (colorLayers) {
2404          XSelectInput(mainDisplay, colorWindow, ButtonPressMask |
2405                PointerMotionMask | ExposureMask | EnterWindowMask);
2406          XMapWindow(mainDisplay, colorWindow);
2407          XSelectInput(mainDisplay, colorDummyWindow, ButtonPressMask |
2408                ExposureMask | EnterWindowMask);
2409          XMapWindow(mainDisplay, colorDummyWindow);
2410       } else {
2411          XSelectInput(mainDisplay, colorWindow, ButtonPressMask |
2412                PointerMotionMask | ExposureMask | EnterWindowMask);
2413          XSelectInput(mainDisplay, colorDummyWindow, ButtonPressMask |
2414                ExposureMask | EnterWindowMask);
2415       }
2416       XSelectInput(mainDisplay, vSBarWindow, ButtonPressMask |
2417             ExposureMask | EnterWindowMask | PointerMotionMask);
2418       XMapWindow(mainDisplay, vSBarWindow);
2419 
2420       XSelectInput(mainDisplay, pageWindow, ButtonPressMask |
2421             PointerMotionMask | ExposureMask | EnterWindowMask);
2422       XMapWindow(mainDisplay, pageWindow);
2423       XSelectInput(mainDisplay, pageDummyWindow, ButtonPressMask |
2424             ExposureMask | EnterWindowMask);
2425       XMapWindow(mainDisplay, pageDummyWindow);
2426       XSelectInput(mainDisplay, hSBarWindow, ButtonPressMask |
2427             ExposureMask | EnterWindowMask | PointerMotionMask);
2428       XMapWindow(mainDisplay, hSBarWindow);
2429       XSelectInput(mainDisplay, dummyWindow1, ButtonPressMask | ExposureMask |
2430             EnterWindowMask | LeaveWindowMask);
2431       XMapWindow(mainDisplay, dummyWindow1);
2432       XSelectInput(mainDisplay, dummyWindow2, ExposureMask | EnterWindowMask);
2433       XMapWindow(mainDisplay, dummyWindow2);
2434 
2435       XSelectInput(mainDisplay, chatWindow,
2436             KeyPressMask | ButtonPressMask | ExposureMask |
2437             StructureNotifyMask | EnterWindowMask | LeaveWindowMask);
2438       if (!noChatWindow) {
2439          XMapWindow(mainDisplay, chatWindow);
2440       }
2441       MapChatSubWindows();
2442 
2443       if (!noStatusWindow) {
2444          XSelectInput(mainDisplay, userRedrawWindow, ButtonPressMask |
2445                ExposureMask | EnterWindowMask);
2446          XMapWindow(mainDisplay, userRedrawWindow);
2447          XSelectInput(mainDisplay, statusWindow, ExposureMask |
2448                EnterWindowMask);
2449          XMapWindow(mainDisplay, statusWindow);
2450          for (i=0; i < MAX_STATUS_BTNS; i++) {
2451             XMapWindow(mainDisplay, statusSubWindow[i]);
2452          }
2453       } else {
2454          XSelectInput(mainDisplay, userRedrawWindow, ButtonPressMask |
2455                ExposureMask | EnterWindowMask);
2456          XSelectInput(mainDisplay, statusWindow, ExposureMask |
2457                EnterWindowMask);
2458       }
2459       XSelectInput(mainDisplay, modeWindow, ButtonPressMask | ExposureMask |
2460             PointerMotionMask | EnterWindowMask | LeaveWindowMask);
2461       if (!noModeWindow) XMapWindow(mainDisplay, modeWindow);
2462    }
2463 #endif
2464 
2465    wmhints.flags = InputHint;
2466    wmhints.input = True;
2467    wmhints.icon_pixmap = None;
2468 
2469    if (iconWindowCreated) {
2470       unsigned int dummy_icon_w, dummy_icon_h;
2471 
2472       sizehints.flags = PSize | PMinSize | PMaxSize;
2473       sizehints.width = sizehints.min_width = sizehints.max_width =
2474             iconWindowW+(brdrW<<1);
2475       sizehints.height = sizehints.min_height = sizehints.max_height =
2476             iconWindowH+(brdrW<<1);
2477 
2478       wmhints.flags |= IconWindowHint;
2479       wmhints.icon_window = iconBaseWindow;
2480 
2481       if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"IconGeometry")) != NULL) {
2482          bitmask = XParseGeometry(c_ptr, &(sizehints.x), &(sizehints.y),
2483                &dummy_icon_w, &dummy_icon_h);
2484          if ((bitmask & XValue) && (bitmask & YValue)) {
2485             if (bitmask & XNegative) sizehints.x += DisplayWidth (mainDisplay,
2486                   mainScreen) - iconWindowW - (brdrW<<1) - 1;
2487             if (bitmask & YNegative) sizehints.y += DisplayHeight(mainDisplay,
2488                   mainScreen) - iconWindowH - (brdrW<<1) - 1;
2489 
2490             sizehints.flags |= USPosition;
2491 
2492             wmhints.flags |= IconPositionHint;
2493             wmhints.icon_x = sizehints.x;
2494             wmhints.icon_y = sizehints.y;
2495          } else {
2496             fprintf(stderr, TgLoadString(STID_INVALID_XDEF),
2497                   TOOL_NAME, "IconGeometry", c_ptr);
2498             fprintf(stderr, "\n");
2499          }
2500       }
2501 #ifdef NOTR4MODE
2502       XSetNormalHints(mainDisplay, iconBaseWindow, &sizehints);
2503 #else /* ~NOTR4MODE */
2504       XSetWMNormalHints(mainDisplay, iconBaseWindow, &sizehints);
2505 #endif /* NOTR4MODE */
2506    } else {
2507       if (((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "UseWMIconPixmap")) ==
2508             NULL) || UtilStrICmp(c_ptr, "false") != 0) {
2509          wmhints.icon_mask = None;
2510          wmhints.initial_state = NormalState;
2511          if (!GetWMIconPixmap(&wmIconPixmap, &wmIconPixmapMask)) {
2512             wmhints.icon_pixmap = wmIconPixmap =
2513                   XCreateBitmapFromData(mainDisplay, mainWindow,
2514                   (char*)tgificon_bits, tgificon_width, tgificon_height);
2515          } else {
2516             wmhints.icon_pixmap = wmIconPixmap;
2517             if (wmIconPixmapMask != None) {
2518                wmhints.icon_mask = wmIconPixmapMask;
2519                wmhints.flags |= IconMaskHint;
2520             }
2521          }
2522          wmhints.flags |= IconPixmapHint | StateHint;
2523          /* FlushUndoBuffer(); */
2524       }
2525    }
2526    XSetWMHints(mainDisplay, mainWindow, &wmhints);
2527 
2528    wmhints.flags = InputHint;
2529    wmhints.input = True;
2530    XSetWMHints(mainDisplay, drawWindow, &wmhints);
2531 
2532    memset(&classhints, 0, sizeof(XClassHint));
2533    classhints.res_name = TOOL_NAME;
2534    classhints.res_class = TOOL_NAME;
2535 #ifdef NOTR4MODE
2536    XSetClassHint(mainDisplay, mainWindow, &classhints);
2537 #else /* ~NOTR4MODE */
2538    XSetWMProperties(mainDisplay, mainWindow, NULL, NULL, NULL, 0, NULL, NULL,
2539          &classhints);
2540 #endif /* NOTR4MODE */
2541 }
2542 
CleanUpResiduals()2543 void CleanUpResiduals()
2544 {
2545    if (wmIconPixmap != None) {
2546       XFreePixmap(mainDisplay, wmIconPixmap);
2547       wmIconPixmap = None;
2548    }
2549    if (wmIconPixmapMask != None) {
2550       XFreePixmap(mainDisplay, wmIconPixmapMask);
2551       wmIconPixmapMask = None;
2552    }
2553    CleanUpPaperSize();
2554    if (displayName != NULL) {
2555       UtilFree(displayName);
2556       displayName = NULL;
2557    }
2558    if (btn1_bits == NULL) { }
2559 }
2560 
TieLooseEnds()2561 int TieLooseEnds()
2562    /* returns TRUE if something got created */
2563    /* returns FALSE otherwise */
2564 {
2565    if (curChoice == DRAWTEXT) return CreateTextObj(TRUE, TRUE);
2566    return FALSE;
2567 }
2568 
MakeQuiescent()2569 void MakeQuiescent()
2570 {
2571    curChoiceBeforeMakeQuiescent = curChoice;
2572    TieLooseEnds();
2573    SetCurChoice(NOTHING);
2574    if (topSel != NULL) {
2575       HighLightReverse();
2576       RemoveAllSel();
2577    }
2578    UpdSelBBox();
2579 }
2580 
SetFileModified(modified)2581 void SetFileModified(modified)
2582    int modified;
2583 {
2584    if (modified != fileModified) {
2585       fileModified = modified;
2586       if (fileModified && gstWBInfo.do_whiteboard) {
2587          SetUnSavableFile(TRUE);
2588       }
2589       if (!PRTGIF) {
2590          RedrawTitleWindow();
2591       }
2592    }
2593 }
2594