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