1 
2 #include "WINGsP.h"
3 #include "wconfig.h"
4 
5 #include <X11/Xft/Xft.h>
6 
7 #include <X11/Xutil.h>
8 #include <X11/Xatom.h>
9 #include <X11/keysym.h>
10 #include <X11/cursorfont.h>
11 
12 #include <X11/Xlocale.h>
13 
14 /********** data ************/
15 
16 #define CHECK_BUTTON_ON_WIDTH 	16
17 #define CHECK_BUTTON_ON_HEIGHT 	16
18 
19 static char *CHECK_BUTTON_ON[] = {
20 	"               %",
21 	" .............%#",
22 	" ........... .%#",
23 	" .......... #.%#",
24 	" ......... #%.%#",
25 	" ........ #%..%#",
26 	" ... #.. #%...%#",
27 	" ... #% #%....%#",
28 	" ... % #%.....%#",
29 	" ...  #%......%#",
30 	" ... #%.......%#",
31 	" ...#%........%#",
32 	" .............%#",
33 	" .............%#",
34 	" %%%%%%%%%%%%%%#",
35 	"%###############"
36 };
37 
38 #define CHECK_BUTTON_OFF_WIDTH 	16
39 #define CHECK_BUTTON_OFF_HEIGHT	16
40 
41 static char *CHECK_BUTTON_OFF[] = {
42 	"               %",
43 	" .............%#",
44 	" .............%#",
45 	" .............%#",
46 	" .............%#",
47 	" .............%#",
48 	" .............%#",
49 	" .............%#",
50 	" .............%#",
51 	" .............%#",
52 	" .............%#",
53 	" .............%#",
54 	" .............%#",
55 	" .............%#",
56 	" %%%%%%%%%%%%%%#",
57 	"%###############"
58 };
59 
60 #define RADIO_BUTTON_ON_WIDTH 	15
61 #define RADIO_BUTTON_ON_HEIGHT	15
62 static char *RADIO_BUTTON_ON[] = {
63 	".....%%%%%.....",
64 	"...%%#####%%...",
65 	"..%##.....%.%..",
66 	".%#%..    .....",
67 	".%#.        ...",
68 	"%#..        .. ",
69 	"%#.          . ",
70 	"%#.          . ",
71 	"%#.          . ",
72 	"%#.          . ",
73 	".%%.        . .",
74 	".%..        . .",
75 	"..%...    .. ..",
76 	".... .....  ...",
77 	".....     .....",
78 };
79 
80 #define RADIO_BUTTON_OFF_WIDTH 	15
81 #define RADIO_BUTTON_OFF_HEIGHT	15
82 static char *RADIO_BUTTON_OFF[] = {
83 	".....%%%%%.....",
84 	"...%%#####%%...",
85 	"..%##.......%..",
86 	".%#%...........",
87 	".%#............",
88 	"%#............ ",
89 	"%#............ ",
90 	"%#............ ",
91 	"%#............ ",
92 	"%#............ ",
93 	".%%.......... .",
94 	".%........... .",
95 	"..%......... ..",
96 	".... .....  ...",
97 	".....     .....",
98 };
99 
100 #define TRISTATE_BUTTON_ON_WIDTH 	15
101 #define TRISTATE_BUTTON_ON_HEIGHT	15
102 static char *TRISTATE_BUTTON_ON[] = {
103 	"%%%%%%%%%%%%%%.",
104 	"%%%%%%%%%%%%%. ",
105 	"%%           . ",
106 	"%% ##     ## . ",
107 	"%% ###   ### . ",
108 	"%%  ### ###  . ",
109 	"%%   #####   . ",
110 	"%%    ###    . ",
111 	"%%   #####   . ",
112 	"%%  ### ###  . ",
113 	"%% ###   ### . ",
114 	"%% ##     ## . ",
115 	"%%           . ",
116 	"%............. ",
117 	".              ",
118 };
119 
120 #define TRISTATE_BUTTON_OFF_WIDTH 	15
121 #define TRISTATE_BUTTON_OFF_HEIGHT	15
122 static char *TRISTATE_BUTTON_OFF[] = {
123 	"%%%%%%%%%%%%%%.",
124 	"%%%%%%%%%%%%%. ",
125 	"%%           . ",
126 	"%%           . ",
127 	"%%           . ",
128 	"%%           . ",
129 	"%%           . ",
130 	"%%           . ",
131 	"%%           . ",
132 	"%%           . ",
133 	"%%           . ",
134 	"%%           . ",
135 	"%%           . ",
136 	"%............. ",
137 	".              ",
138 };
139 
140 #define TRISTATE_BUTTON_TRI_WIDTH 	15
141 #define TRISTATE_BUTTON_TRI_HEIGHT	15
142 static char *TRISTATE_BUTTON_TRI[] = {
143 	"%%%%%%%%%%%%%%.",
144 	"%%%%%%%%%%%%%. ",
145 	"%%           . ",
146 	"%% # # # # # . ",
147 	"%%  # # # #  . ",
148 	"%% # # # # # . ",
149 	"%%  # # # #  . ",
150 	"%% # # # # # . ",
151 	"%%  # # # #  . ",
152 	"%% # # # # # . ",
153 	"%%  # # # #  . ",
154 	"%% # # # # # . ",
155 	"%%           . ",
156 	"%............. ",
157 	".              ",
158 };
159 
160 static char *BUTTON_ARROW[] = {
161 	"..................",
162 	"....##....#### ...",
163 	"...#.%....#... ...",
164 	"..#..%#####... ...",
165 	".#............ ...",
166 	"#............. ...",
167 	".#............ ...",
168 	"..#..          ...",
169 	"...#. ............",
170 	"....# ............"
171 };
172 
173 #define BUTTON_ARROW_WIDTH	18
174 #define BUTTON_ARROW_HEIGHT	10
175 
176 static char *BUTTON_ARROW2[] = {
177 	"                  ",
178 	"    ##    ####.   ",
179 	"   # %    #   .   ",
180 	"  #  %#####   .   ",
181 	" #            .   ",
182 	"#             .   ",
183 	" #            .   ",
184 	"  #  ..........   ",
185 	"   # .            ",
186 	"    #.            "
187 };
188 
189 #define BUTTON_ARROW2_WIDTH	18
190 #define BUTTON_ARROW2_HEIGHT	10
191 
192 static char *SCROLLER_DIMPLE[] = {
193 	".%###.",
194 	"%#%%%%",
195 	"#%%...",
196 	"#%..  ",
197 	"#%.   ",
198 	".%.  ."
199 };
200 
201 #define SCROLLER_DIMPLE_WIDTH   6
202 #define SCROLLER_DIMPLE_HEIGHT  6
203 
204 static char *SCROLLER_ARROW_UP[] = {
205 	"....%....",
206 	"....#....",
207 	"...%#%...",
208 	"...###...",
209 	"..%###%..",
210 	"..#####..",
211 	".%#####%.",
212 	".#######.",
213 	"%#######%"
214 };
215 
216 static char *HI_SCROLLER_ARROW_UP[] = {
217 	"    %    ",
218 	"    %    ",
219 	"   %%%   ",
220 	"   %%%   ",
221 	"  %%%%%  ",
222 	"  %%%%%  ",
223 	" %%%%%%% ",
224 	" %%%%%%% ",
225 	"%%%%%%%%%"
226 };
227 
228 #define SCROLLER_ARROW_UP_WIDTH   9
229 #define SCROLLER_ARROW_UP_HEIGHT  9
230 
231 static char *SCROLLER_ARROW_DOWN[] = {
232 	"%#######%",
233 	".#######.",
234 	".%#####%.",
235 	"..#####..",
236 	"..%###%..",
237 	"...###...",
238 	"...%#%...",
239 	"....#....",
240 	"....%...."
241 };
242 
243 static char *HI_SCROLLER_ARROW_DOWN[] = {
244 	"%%%%%%%%%",
245 	" %%%%%%% ",
246 	" %%%%%%% ",
247 	"  %%%%%  ",
248 	"  %%%%%  ",
249 	"   %%%   ",
250 	"   %%%   ",
251 	"    %    ",
252 	"    %    "
253 };
254 
255 #define SCROLLER_ARROW_DOWN_WIDTH   9
256 #define SCROLLER_ARROW_DOWN_HEIGHT  9
257 
258 static char *SCROLLER_ARROW_LEFT[] = {
259 	"........%",
260 	"......%##",
261 	"....%####",
262 	"..%######",
263 	"%########",
264 	"..%######",
265 	"....%####",
266 	"......%##",
267 	"........%"
268 };
269 
270 static char *HI_SCROLLER_ARROW_LEFT[] = {
271 	"        %",
272 	"      %%%",
273 	"    %%%%%",
274 	"  %%%%%%%",
275 	"%%%%%%%%%",
276 	"  %%%%%%%",
277 	"    %%%%%",
278 	"      %%%",
279 	"        %"
280 };
281 
282 #define SCROLLER_ARROW_LEFT_WIDTH   9
283 #define SCROLLER_ARROW_LEFT_HEIGHT  9
284 
285 static char *SCROLLER_ARROW_RIGHT[] = {
286 	"%........",
287 	"##%......",
288 	"####%....",
289 	"######%..",
290 	"########%",
291 	"######%..",
292 	"####%....",
293 	"##%......",
294 	"%........"
295 };
296 
297 static char *HI_SCROLLER_ARROW_RIGHT[] = {
298 	"%        ",
299 	"%%%      ",
300 	"%%%%%    ",
301 	"%%%%%%%  ",
302 	"%%%%%%%%%",
303 	"%%%%%%%  ",
304 	"%%%%%    ",
305 	"%%%      ",
306 	"%        "
307 };
308 
309 #define SCROLLER_ARROW_RIGHT_WIDTH   9
310 #define SCROLLER_ARROW_RIGHT_HEIGHT  9
311 
312 static char *POPUP_INDICATOR[] = {
313 	"        #==",
314 	" ......%#==",
315 	" ......%#%%",
316 	" ......%#%%",
317 	" %%%%%%%#%%",
318 	"#########%%",
319 	"==%%%%%%%%%",
320 	"==%%%%%%%%%"
321 };
322 
323 #define POPUP_INDICATOR_WIDTH	11
324 #define POPUP_INDICATOR_HEIGHT 	8
325 
326 static char *PULLDOWN_INDICATOR[] = {
327 	"=#######=",
328 	"=%===== =",
329 	"==%=== ==",
330 	"==%=== ==",
331 	"===%= ===",
332 	"===%= ===",
333 	"====%===="
334 };
335 
336 #define PULLDOWN_INDICATOR_WIDTH	9
337 #define PULLDOWN_INDICATOR_HEIGHT 	7
338 
339 #define CHECK_MARK_WIDTH 	8
340 #define CHECK_MARK_HEIGHT 	10
341 
342 static char *CHECK_MARK[] = {
343 	"======== ",
344 	"======= #",
345 	"====== #%",
346 	"===== #%=",
347 	" #== #%==",
348 	" #% #%===",
349 	" % #%====",
350 	"  #%=====",
351 	" #%======",
352 	"#%======="
353 };
354 
355 #define STIPPLE_WIDTH 8
356 #define STIPPLE_HEIGHT 8
357 static char STIPPLE_BITS[] = {
358 	0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
359 };
360 
361 static int userWidgetCount = 0;
362 
363 /*****  end data  ******/
364 
renderPixmap(W_Screen * screen,Pixmap d,Pixmap mask,char ** data,int width,int height)365 static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
366 {
367 	int x, y;
368 	GC whiteGC = WMColorGC(screen->white);
369 	GC blackGC = WMColorGC(screen->black);
370 	GC lightGC = WMColorGC(screen->gray);
371 	GC darkGC = WMColorGC(screen->darkGray);
372 
373 	if (mask)
374 		XSetForeground(screen->display, screen->monoGC, 0);
375 
376 	for (y = 0; y < height; y++) {
377 		for (x = 0; x < width; x++) {
378 			switch (data[y][x]) {
379 			case ' ':
380 			case 'w':
381 				XDrawPoint(screen->display, d, whiteGC, x, y);
382 				break;
383 
384 			case '=':
385 				if (mask)
386 					XDrawPoint(screen->display, mask, screen->monoGC, x, y);
387 
388 				/* FALLTHRU */
389 			case '.':
390 			case 'l':
391 				XDrawPoint(screen->display, d, lightGC, x, y);
392 				break;
393 
394 			case '%':
395 			case 'd':
396 				XDrawPoint(screen->display, d, darkGC, x, y);
397 				break;
398 
399 			case '#':
400 			case 'b':
401 			default:
402 				XDrawPoint(screen->display, d, blackGC, x, y);
403 				break;
404 			}
405 		}
406 	}
407 }
408 
makePixmap(W_Screen * sPtr,char ** data,int width,int height,int masked)409 static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
410 {
411 	Pixmap pixmap, mask = None;
412 
413 	pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
414 
415 	if (masked) {
416 		mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
417 		XSetForeground(sPtr->display, sPtr->monoGC, 1);
418 		XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
419 	}
420 
421 	renderPixmap(sPtr, pixmap, mask, data, width, height);
422 
423 	return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
424 }
425 
426 #define T_WINGS_IMAGES_FILE  RESOURCE_PATH"/Images.tiff"
427 #define X_WINGS_IMAGES_FILE  RESOURCE_PATH"/Images.xpm"
428 
loadPixmaps(WMScreen * scr)429 static Bool loadPixmaps(WMScreen * scr)
430 {
431 	RImage *image, *tmp;
432 	RColor gray;
433 	RColor white;
434 
435 	gray.red = 0xae;
436 	gray.green = 0xaa;
437 	gray.blue = 0xae;
438 
439 	white.red = 0xff;
440 	white.green = 0xff;
441 	white.blue = 0xff;
442 
443 	image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
444 	if (!image)
445 		image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
446 	if (!image) {
447 		wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
448 		return False;
449 	}
450 	/* home icon */
451 	/* make it have a gray background */
452 	tmp = RGetSubImage(image, 0, 0, 24, 24);
453 	RCombineImageWithColor(tmp, &gray);
454 	scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
455 	RReleaseImage(tmp);
456 	/* make it have a white background */
457 	tmp = RGetSubImage(image, 0, 0, 24, 24);
458 	RCombineImageWithColor(tmp, &white);
459 	scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
460 	RReleaseImage(tmp);
461 
462 	/* trash can */
463 	tmp = RGetSubImage(image, 104, 0, 24, 24);
464 	RCombineImageWithColor(tmp, &white);
465 	scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
466 	RReleaseImage(tmp);
467 	tmp = RGetSubImage(image, 104, 0, 24, 24);
468 	RCombineImageWithColor(tmp, &white);
469 	scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
470 	RReleaseImage(tmp);
471 	/* create dir */
472 	tmp = RGetSubImage(image, 104, 24, 24, 24);
473 	RCombineImageWithColor(tmp, &white);
474 	scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
475 	RReleaseImage(tmp);
476 	tmp = RGetSubImage(image, 104, 24, 24, 24);
477 	RCombineImageWithColor(tmp, &white);
478 	scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
479 	RReleaseImage(tmp);
480 	/* diskettes */
481 	tmp = RGetSubImage(image, 24, 80, 24, 24);
482 	RCombineImageWithColor(tmp, &white);
483 	scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
484 	RReleaseImage(tmp);
485 	tmp = RGetSubImage(image, 24, 80, 24, 24);
486 	RCombineImageWithColor(tmp, &white);
487 	scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
488 	RReleaseImage(tmp);
489 	/* unmount */
490 	tmp = RGetSubImage(image, 0, 80, 24, 24);
491 	RCombineImageWithColor(tmp, &white);
492 	scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
493 	RReleaseImage(tmp);
494 	tmp = RGetSubImage(image, 0, 80, 24, 24);
495 	RCombineImageWithColor(tmp, &white);
496 	scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
497 	RReleaseImage(tmp);
498 
499 	/* Magnifying Glass Icon for ColorPanel */
500 	tmp = RGetSubImage(image, 24, 0, 40, 32);
501 	RCombineImageWithColor(tmp, &gray);
502 	scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
503 	RReleaseImage(tmp);
504 	/* ColorWheel Icon for ColorPanel */
505 	tmp = RGetSubImage(image, 0, 25, 24, 24);
506 	scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
507 	RReleaseImage(tmp);
508 	/* GrayScale Icon for ColorPanel */
509 	tmp = RGetSubImage(image, 65, 0, 40, 24);
510 	scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
511 	RReleaseImage(tmp);
512 	/* RGB Icon for ColorPanel */
513 	tmp = RGetSubImage(image, 25, 33, 40, 24);
514 	scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
515 	RReleaseImage(tmp);
516 	/* CMYK Icon for ColorPanel */
517 	tmp = RGetSubImage(image, 65, 25, 40, 24);
518 	scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
519 	RReleaseImage(tmp);
520 	/* HSB Icon for ColorPanel */
521 	tmp = RGetSubImage(image, 0, 57, 40, 24);
522 	scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
523 	RReleaseImage(tmp);
524 	/* CustomColorPalette Icon for ColorPanel */
525 	tmp = RGetSubImage(image, 81, 57, 40, 24);
526 	scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
527 	RReleaseImage(tmp);
528 	/* ColorList Icon for ColorPanel */
529 	tmp = RGetSubImage(image, 41, 57, 40, 24);
530 	scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
531 	RReleaseImage(tmp);
532 
533 	RReleaseImage(image);
534 
535 	return True;
536 }
537 
WMOpenScreen(const char * display)538 WMScreen *WMOpenScreen(const char *display)
539 {
540 	Display *dpy = XOpenDisplay(display);
541 
542 	if (!dpy) {
543 		wwarning(_("WINGs: could not open display %s"), XDisplayName(display));
544 		return NULL;
545 	}
546 
547 	return WMCreateSimpleApplicationScreen(dpy);
548 }
549 
WMCreateSimpleApplicationScreen(Display * display)550 WMScreen *WMCreateSimpleApplicationScreen(Display * display)
551 {
552 	WMScreen *scr;
553 
554 	scr = WMCreateScreen(display, DefaultScreen(display));
555 
556 	scr->aflags.hasAppIcon = 0;
557 	scr->aflags.simpleApplication = 1;
558 
559 	return scr;
560 }
561 
WMCreateScreen(Display * display,int screen)562 WMScreen *WMCreateScreen(Display * display, int screen)
563 {
564 	return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
565 }
566 
WMCreateScreenWithRContext(Display * display,int screen,RContext * context)567 WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
568 {
569 	W_Screen *scrPtr;
570 	XGCValues gcv;
571 	Pixmap stipple;
572 	static int initialized = 0;
573 	static char *atomNames[] = {
574 		"_GNUSTEP_WM_ATTR",
575 		"WM_DELETE_WINDOW",
576 		"WM_PROTOCOLS",
577 		"CLIPBOARD",
578 		"XdndAware",
579 		"XdndSelection",
580 		"XdndEnter",
581 		"XdndLeave",
582 		"XdndPosition",
583 		"XdndDrop",
584 		"XdndFinished",
585 		"XdndTypeList",
586 		"XdndActionList",
587 		"XdndActionDescription",
588 		"XdndStatus",
589 		"XdndActionCopy",
590 		"XdndActionMove",
591 		"XdndActionLink",
592 		"XdndActionAsk",
593 		"XdndActionPrivate",
594 		"_WINGS_DND_MOUSE_OFFSET",
595 		"WM_STATE",
596 		"UTF8_STRING",
597 		"_NET_WM_NAME",
598 		"_NET_WM_ICON_NAME",
599 		"_NET_WM_ICON",
600 	};
601 	Atom atoms[wlengthof(atomNames)];
602 	int i;
603 
604 	if (!initialized) {
605 
606 		initialized = 1;
607 
608 		W_ReadConfigurations();
609 
610 		assert(W_ApplicationInitialized());
611 	}
612 
613 	scrPtr = malloc(sizeof(W_Screen));
614 	if (!scrPtr)
615 		return NULL;
616 	memset(scrPtr, 0, sizeof(W_Screen));
617 
618 	scrPtr->aflags.hasAppIcon = 1;
619 
620 	scrPtr->display = display;
621 	scrPtr->screen = screen;
622 	scrPtr->rcontext = context;
623 
624 	scrPtr->depth = context->depth;
625 
626 	scrPtr->visual = context->visual;
627 	scrPtr->lastEventTime = 0;
628 
629 	scrPtr->colormap = context->cmap;
630 
631 	scrPtr->rootWin = RootWindow(display, screen);
632 
633 	scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
634 
635 	scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
636 
637 	/* Create missing CUT_BUFFERs */
638 	{
639 		Atom *rootWinProps;
640 		int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
641 		int count;
642 
643 		rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
644 		for (i = 0; i < count; i++) {
645 			switch (rootWinProps[i]) {
646 			case XA_CUT_BUFFER0:
647 				exists[0] = 1;
648 				break;
649 			case XA_CUT_BUFFER1:
650 				exists[1] = 1;
651 				break;
652 			case XA_CUT_BUFFER2:
653 				exists[2] = 1;
654 				break;
655 			case XA_CUT_BUFFER3:
656 				exists[3] = 1;
657 				break;
658 			case XA_CUT_BUFFER4:
659 				exists[4] = 1;
660 				break;
661 			case XA_CUT_BUFFER5:
662 				exists[5] = 1;
663 				break;
664 			case XA_CUT_BUFFER6:
665 				exists[6] = 1;
666 				break;
667 			case XA_CUT_BUFFER7:
668 				exists[7] = 1;
669 				break;
670 			default:
671 				break;
672 			}
673 		}
674 		if (rootWinProps) {
675 			XFree(rootWinProps);
676 		}
677 		for (i = 0; i < 8; i++) {
678 			if (!exists[i]) {
679 				XStoreBuffer(display, "", 0, i);
680 			}
681 		}
682 	}
683 
684 	scrPtr->ignoredModifierMask = 0;
685 	{
686 		int i;
687 		XModifierKeymap *modmap;
688 		KeyCode nlock, slock;
689 		static int mask_table[8] = {
690 			ShiftMask, LockMask, ControlMask, Mod1Mask,
691 			Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
692 		};
693 		unsigned int numLockMask = 0, scrollLockMask = 0;
694 
695 		nlock = XKeysymToKeycode(display, XK_Num_Lock);
696 		slock = XKeysymToKeycode(display, XK_Scroll_Lock);
697 
698 		/*
699 		 * Find out the masks for the NumLock and ScrollLock modifiers,
700 		 * so that we can bind the grabs for when they are enabled too.
701 		 */
702 		modmap = XGetModifierMapping(display);
703 
704 		if (modmap != NULL && modmap->max_keypermod > 0) {
705 			for (i = 0; i < 8 * modmap->max_keypermod; i++) {
706 				if (modmap->modifiermap[i] == nlock && nlock != 0)
707 					numLockMask = mask_table[i / modmap->max_keypermod];
708 				else if (modmap->modifiermap[i] == slock && slock != 0)
709 					scrollLockMask = mask_table[i / modmap->max_keypermod];
710 			}
711 		}
712 
713 		if (modmap)
714 			XFreeModifiermap(modmap);
715 
716 		scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
717 	}
718 
719 	/* initially allocate some colors */
720 	WMWhiteColor(scrPtr);
721 	WMBlackColor(scrPtr);
722 	WMGrayColor(scrPtr);
723 	WMDarkGrayColor(scrPtr);
724 
725 	gcv.graphics_exposures = False;
726 
727 	gcv.function = GXxor;
728 	gcv.foreground = W_PIXEL(scrPtr->white);
729 	if (gcv.foreground == 0)
730 		gcv.foreground = 1;
731 	scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
732 				  | GCGraphicsExposures | GCForeground, &gcv);
733 
734 	gcv.function = GXxor;
735 	gcv.foreground = W_PIXEL(scrPtr->gray);
736 	gcv.subwindow_mode = IncludeInferiors;
737 	scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
738 				   | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
739 
740 	gcv.function = GXcopy;
741 	scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
742 
743 	scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
744 
745 	stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
746 	gcv.foreground = W_PIXEL(scrPtr->darkGray);
747 	gcv.background = W_PIXEL(scrPtr->gray);
748 	gcv.fill_style = FillStippled;
749 	gcv.stipple = stipple;
750 	scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
751 				      GCForeground | GCBackground | GCStipple
752 				      | GCFillStyle | GCGraphicsExposures, &gcv);
753 
754 	scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
755 	scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
756 
757 	/* we need a 1bpp drawable for the monoGC, so borrow this one */
758 	scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
759 
760 	scrPtr->stipple = stipple;
761 
762 	scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
763 
764 	scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
765 
766 	scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
767 
768 	if (!scrPtr->boldFont)
769 		scrPtr->boldFont = scrPtr->normalFont;
770 
771 	if (!scrPtr->normalFont) {
772 		wwarning(_("could not load any fonts. Make sure your font installation"
773 			   " and locale settings are correct."));
774 
775 		return NULL;
776 	}
777 
778 	/* create input method stuff */
779 	W_InitIM(scrPtr);
780 
781 	scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
782 						CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
783 
784 	scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
785 						 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
786 
787 	scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
788 						RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
789 
790 	scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
791 						 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
792 
793 	scrPtr->tristateButtonImageOn = makePixmap(scrPtr, TRISTATE_BUTTON_ON,
794 	                                           TRISTATE_BUTTON_ON_WIDTH, TRISTATE_BUTTON_ON_HEIGHT, False);
795 
796 	scrPtr->tristateButtonImageOff = makePixmap(scrPtr, TRISTATE_BUTTON_OFF,
797 	                                            TRISTATE_BUTTON_OFF_WIDTH, TRISTATE_BUTTON_OFF_HEIGHT, False);
798 
799 	scrPtr->tristateButtonImageTri = makePixmap(scrPtr, TRISTATE_BUTTON_TRI,
800 	                                            TRISTATE_BUTTON_TRI_WIDTH, TRISTATE_BUTTON_TRI_HEIGHT, False);
801 
802 	scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
803 
804 	scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
805 					       BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
806 
807 	scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
808 					    SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
809 
810 	scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
811 				     SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
812 
813 	scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
814 				       SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
815 
816 	scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
817 				       SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
818 
819 	scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
820 					SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
821 
822 	scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
823 				       SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
824 
825 	scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
826 					 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
827 
828 	scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
829 					 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
830 
831 	scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
832 					  SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
833 
834 	scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
835 					    POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
836 
837 	scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
838 					       PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
839 
840 	scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
841 
842 	loadPixmaps(scrPtr);
843 
844 	scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
845 
846 	scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
847 
848 	{
849 		XColor bla;
850 		Pixmap blank;
851 
852 		blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
853 		XSetForeground(display, scrPtr->monoGC, 0);
854 		XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
855 
856 		scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
857 		XFreePixmap(display, blank);
858 	}
859 
860 #ifdef HAVE_XINTERNATOMS
861 	XInternAtoms(display, atomNames, wlengthof(atomNames), False, atoms);
862 #else
863 	for (i = 0; i < wlengthof(atomNames); i++) {
864 		atoms[i] = XInternAtom(display, atomNames[i], False);
865 	}
866 #endif
867 
868 	i = 0;
869 	scrPtr->attribsAtom = atoms[i++];
870 
871 	scrPtr->deleteWindowAtom = atoms[i++];
872 
873 	scrPtr->protocolsAtom = atoms[i++];
874 
875 	scrPtr->clipboardAtom = atoms[i++];
876 
877 	scrPtr->xdndAwareAtom = atoms[i++];
878 	scrPtr->xdndSelectionAtom = atoms[i++];
879 	scrPtr->xdndEnterAtom = atoms[i++];
880 	scrPtr->xdndLeaveAtom = atoms[i++];
881 	scrPtr->xdndPositionAtom = atoms[i++];
882 	scrPtr->xdndDropAtom = atoms[i++];
883 	scrPtr->xdndFinishedAtom = atoms[i++];
884 	scrPtr->xdndTypeListAtom = atoms[i++];
885 	scrPtr->xdndActionListAtom = atoms[i++];
886 	scrPtr->xdndActionDescriptionAtom = atoms[i++];
887 	scrPtr->xdndStatusAtom = atoms[i++];
888 
889 	scrPtr->xdndActionCopy = atoms[i++];
890 	scrPtr->xdndActionMove = atoms[i++];
891 	scrPtr->xdndActionLink = atoms[i++];
892 	scrPtr->xdndActionAsk = atoms[i++];
893 	scrPtr->xdndActionPrivate = atoms[i++];
894 
895 	scrPtr->wmIconDragOffsetAtom = atoms[i++];
896 
897 	scrPtr->wmStateAtom = atoms[i++];
898 
899 	scrPtr->utf8String = atoms[i++];
900 	scrPtr->netwmName = atoms[i++];
901 	scrPtr->netwmIconName = atoms[i++];
902 	scrPtr->netwmIcon = atoms[i++];
903 
904 	scrPtr->rootView = W_CreateRootView(scrPtr);
905 
906 	scrPtr->balloon = W_CreateBalloon(scrPtr);
907 
908 	W_InitApplication(scrPtr);
909 
910 	return scrPtr;
911 }
912 
WMSetWidgetDefaultFont(WMScreen * scr,WMFont * font)913 void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
914 {
915 	WMReleaseFont(scr->normalFont);
916 	scr->normalFont = WMRetainFont(font);
917 }
918 
WMSetWidgetDefaultBoldFont(WMScreen * scr,WMFont * font)919 void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
920 {
921 	WMReleaseFont(scr->boldFont);
922 	scr->boldFont = WMRetainFont(font);
923 }
924 
WMHangData(WMWidget * widget,void * data)925 void WMHangData(WMWidget * widget, void *data)
926 {
927 	W_VIEW(widget)->hangedData = data;
928 }
929 
WMGetHangedData(WMWidget * widget)930 void *WMGetHangedData(WMWidget * widget)
931 {
932 	return W_VIEW(widget)->hangedData;
933 }
934 
WMDestroyWidget(WMWidget * widget)935 void WMDestroyWidget(WMWidget * widget)
936 {
937 	W_UnmapView(W_VIEW(widget));
938 	W_DestroyView(W_VIEW(widget));
939 }
940 
WMSetFocusToWidget(WMWidget * widget)941 void WMSetFocusToWidget(WMWidget * widget)
942 {
943 	W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
944 }
945 
946 /*
947  * WMRealizeWidget-
948  * 	Realizes the widget and all it's children.
949  *
950  */
WMRealizeWidget(WMWidget * w)951 void WMRealizeWidget(WMWidget * w)
952 {
953 	W_RealizeView(W_VIEW(w));
954 }
955 
WMMapWidget(WMWidget * w)956 void WMMapWidget(WMWidget * w)
957 {
958 	W_MapView(W_VIEW(w));
959 }
960 
WMReparentWidget(WMWidget * w,WMWidget * newParent,int x,int y)961 void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
962 {
963 	W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
964 }
965 
makeChildrenAutomap(W_View * view,int flag)966 static void makeChildrenAutomap(W_View * view, int flag)
967 {
968 	view = view->childrenList;
969 
970 	while (view) {
971 		view->flags.mapWhenRealized = flag;
972 		makeChildrenAutomap(view, flag);
973 
974 		view = view->nextSister;
975 	}
976 }
977 
WMMapSubwidgets(WMWidget * w)978 void WMMapSubwidgets(WMWidget * w)
979 {
980 	/* make sure that subwidgets created after the parent was realized
981 	 * are mapped too */
982 	if (!W_VIEW(w)->flags.realized) {
983 		makeChildrenAutomap(W_VIEW(w), True);
984 	} else {
985 		W_MapSubviews(W_VIEW(w));
986 	}
987 }
988 
WMUnmapSubwidgets(WMWidget * w)989 void WMUnmapSubwidgets(WMWidget * w)
990 {
991 	if (!W_VIEW(w)->flags.realized) {
992 		makeChildrenAutomap(W_VIEW(w), False);
993 	} else {
994 		W_UnmapSubviews(W_VIEW(w));
995 	}
996 }
997 
WMUnmapWidget(WMWidget * w)998 void WMUnmapWidget(WMWidget * w)
999 {
1000 	W_UnmapView(W_VIEW(w));
1001 }
1002 
WMWidgetIsMapped(WMWidget * w)1003 Bool WMWidgetIsMapped(WMWidget * w)
1004 {
1005 	return W_VIEW(w)->flags.mapped;
1006 }
1007 
WMSetWidgetBackgroundColor(WMWidget * w,WMColor * color)1008 void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
1009 {
1010 	W_SetViewBackgroundColor(W_VIEW(w), color);
1011 	if (W_VIEW(w)->flags.mapped)
1012 		WMRedisplayWidget(w);
1013 }
1014 
WMGetWidgetBackgroundColor(WMWidget * w)1015 WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
1016 {
1017 	return W_VIEW(w)->backColor;
1018 }
1019 
WMSetWidgetBackgroundPixmap(WMWidget * w,WMPixmap * pix)1020 void WMSetWidgetBackgroundPixmap(WMWidget *w, WMPixmap *pix)
1021 {
1022 	if (!pix)
1023 		return;
1024 
1025 	W_SetViewBackgroundPixmap(W_VIEW(w), pix);
1026 	if (W_VIEW(w)->flags.mapped)
1027 		WMRedisplayWidget(w);
1028 }
1029 
WMGetWidgetBackgroundPixmap(WMWidget * w)1030 WMPixmap *WMGetWidgetBackgroundPixmap(WMWidget *w)
1031 {
1032 	return W_VIEW(w)->backImage;
1033 }
1034 
WMRaiseWidget(WMWidget * w)1035 void WMRaiseWidget(WMWidget * w)
1036 {
1037 	W_RaiseView(W_VIEW(w));
1038 }
1039 
WMLowerWidget(WMWidget * w)1040 void WMLowerWidget(WMWidget * w)
1041 {
1042 	W_LowerView(W_VIEW(w));
1043 }
1044 
WMMoveWidget(WMWidget * w,int x,int y)1045 void WMMoveWidget(WMWidget * w, int x, int y)
1046 {
1047 	W_MoveView(W_VIEW(w), x, y);
1048 }
1049 
WMResizeWidget(WMWidget * w,unsigned int width,unsigned int height)1050 void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
1051 {
1052 	W_ResizeView(W_VIEW(w), width, height);
1053 }
1054 
W_RegisterUserWidget(void)1055 W_Class W_RegisterUserWidget(void)
1056 {
1057 	userWidgetCount++;
1058 
1059 	return userWidgetCount + WC_UserWidget - 1;
1060 }
1061 
WMScreenRContext(WMScreen * scr)1062 RContext *WMScreenRContext(WMScreen * scr)
1063 {
1064 	return scr->rcontext;
1065 }
1066 
WMWidgetWidth(WMWidget * w)1067 unsigned int WMWidgetWidth(WMWidget * w)
1068 {
1069 	return W_VIEW(w)->size.width;
1070 }
1071 
WMWidgetHeight(WMWidget * w)1072 unsigned int WMWidgetHeight(WMWidget * w)
1073 {
1074 	return W_VIEW(w)->size.height;
1075 }
1076 
WMWidgetXID(WMWidget * w)1077 Window WMWidgetXID(WMWidget * w)
1078 {
1079 	return W_VIEW(w)->window;
1080 }
1081 
WMWidgetScreen(WMWidget * w)1082 WMScreen *WMWidgetScreen(WMWidget * w)
1083 {
1084 	return W_VIEW(w)->screen;
1085 }
1086 
WMScreenMainLoop(WMScreen * scr)1087 void WMScreenMainLoop(WMScreen * scr)
1088 {
1089 	XEvent event;
1090 
1091 	while (1) {
1092 		WMNextEvent(scr->display, &event);
1093 		WMHandleEvent(&event);
1094 	}
1095 }
1096 
WMBreakModalLoop(WMScreen * scr)1097 void WMBreakModalLoop(WMScreen * scr)
1098 {
1099 	scr->modalLoop = 0;
1100 }
1101 
WMRunModalLoop(WMScreen * scr,WMView * view)1102 void WMRunModalLoop(WMScreen * scr, WMView * view)
1103 {
1104 	/* why is scr passed if is determined from the view? */
1105 	/*WMScreen *scr = view->screen; */
1106 	int oldModalLoop = scr->modalLoop;
1107 	WMView *oldModalView = scr->modalView;
1108 
1109 	scr->modalView = view;
1110 
1111 	scr->modalLoop = 1;
1112 	while (scr->modalLoop) {
1113 		XEvent event;
1114 
1115 		WMNextEvent(scr->display, &event);
1116 		WMHandleEvent(&event);
1117 	}
1118 
1119 	scr->modalView = oldModalView;
1120 	scr->modalLoop = oldModalLoop;
1121 }
1122 
WMScreenDisplay(WMScreen * scr)1123 Display *WMScreenDisplay(WMScreen * scr)
1124 {
1125 	return scr->display;
1126 }
1127 
WMScreenDepth(WMScreen * scr)1128 int WMScreenDepth(WMScreen * scr)
1129 {
1130 	return scr->depth;
1131 }
1132 
WMScreenWidth(WMScreen * scr)1133 unsigned int WMScreenWidth(WMScreen * scr)
1134 {
1135 	return scr->rootView->size.width;
1136 }
1137 
WMScreenHeight(WMScreen * scr)1138 unsigned int WMScreenHeight(WMScreen * scr)
1139 {
1140 	return scr->rootView->size.height;
1141 }
1142 
WMRedisplayWidget(WMWidget * w)1143 void WMRedisplayWidget(WMWidget * w)
1144 {
1145 	W_RedisplayView(W_VIEW(w));
1146 }
1147