strncpy's third argument should be the length of the dest buffer, not the source.
[wmaker-crm.git] / WINGs / widgets.c
blob16cbfaea5bd89dd3bdb33e036a14ea8fff070c1d
2 #include "WINGsP.h"
3 #include "wconfig.h"
5 #include <X11/Xft/Xft.h>
7 #include <X11/Xutil.h>
8 #include <X11/Xatom.h>
9 #include <X11/keysym.h>
10 #include <X11/cursorfont.h>
12 #include <X11/Xlocale.h>
14 /********** data ************/
16 #define CHECK_BUTTON_ON_WIDTH 16
17 #define CHECK_BUTTON_ON_HEIGHT 16
19 static char *CHECK_BUTTON_ON[] = {
20 " %",
21 " .............%#",
22 " ........... .%#",
23 " .......... #.%#",
24 " ......... #%.%#",
25 " ........ #%..%#",
26 " ... #.. #%...%#",
27 " ... #% #%....%#",
28 " ... % #%.....%#",
29 " ... #%......%#",
30 " ... #%.......%#",
31 " ...#%........%#",
32 " .............%#",
33 " .............%#",
34 " %%%%%%%%%%%%%%#",
35 "%###############"
38 #define CHECK_BUTTON_OFF_WIDTH 16
39 #define CHECK_BUTTON_OFF_HEIGHT 16
41 static char *CHECK_BUTTON_OFF[] = {
42 " %",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " .............%#",
53 " .............%#",
54 " .............%#",
55 " .............%#",
56 " %%%%%%%%%%%%%%#",
57 "%###############"
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 "..... .....",
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 "..... .....",
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 ". ",
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 ". ",
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 ". ",
160 static char *BUTTON_ARROW[] = {
161 "..................",
162 "....##....#### ...",
163 "...#.%....#... ...",
164 "..#..%#####... ...",
165 ".#............ ...",
166 "#............. ...",
167 ".#............ ...",
168 "..#.. ...",
169 "...#. ............",
170 "....# ............"
173 #define BUTTON_ARROW_WIDTH 18
174 #define BUTTON_ARROW_HEIGHT 10
176 static char *BUTTON_ARROW2[] = {
177 " ",
178 " ## ####. ",
179 " # % # . ",
180 " # %##### . ",
181 " # . ",
182 "# . ",
183 " # . ",
184 " # .......... ",
185 " # . ",
186 " #. "
189 #define BUTTON_ARROW2_WIDTH 18
190 #define BUTTON_ARROW2_HEIGHT 10
192 static char *SCROLLER_DIMPLE[] = {
193 ".%###.",
194 "%#%%%%",
195 "#%%...",
196 "#%.. ",
197 "#%. ",
198 ".%. ."
201 #define SCROLLER_DIMPLE_WIDTH 6
202 #define SCROLLER_DIMPLE_HEIGHT 6
204 static char *SCROLLER_ARROW_UP[] = {
205 "....%....",
206 "....#....",
207 "...%#%...",
208 "...###...",
209 "..%###%..",
210 "..#####..",
211 ".%#####%.",
212 ".#######.",
213 "%#######%"
216 static char *HI_SCROLLER_ARROW_UP[] = {
217 " % ",
218 " % ",
219 " %%% ",
220 " %%% ",
221 " %%%%% ",
222 " %%%%% ",
223 " %%%%%%% ",
224 " %%%%%%% ",
225 "%%%%%%%%%"
228 #define SCROLLER_ARROW_UP_WIDTH 9
229 #define SCROLLER_ARROW_UP_HEIGHT 9
231 static char *SCROLLER_ARROW_DOWN[] = {
232 "%#######%",
233 ".#######.",
234 ".%#####%.",
235 "..#####..",
236 "..%###%..",
237 "...###...",
238 "...%#%...",
239 "....#....",
240 "....%...."
243 static char *HI_SCROLLER_ARROW_DOWN[] = {
244 "%%%%%%%%%",
245 " %%%%%%% ",
246 " %%%%%%% ",
247 " %%%%% ",
248 " %%%%% ",
249 " %%% ",
250 " %%% ",
251 " % ",
252 " % "
255 #define SCROLLER_ARROW_DOWN_WIDTH 9
256 #define SCROLLER_ARROW_DOWN_HEIGHT 9
258 static char *SCROLLER_ARROW_LEFT[] = {
259 "........%",
260 "......%##",
261 "....%####",
262 "..%######",
263 "%########",
264 "..%######",
265 "....%####",
266 "......%##",
267 "........%"
270 static char *HI_SCROLLER_ARROW_LEFT[] = {
271 " %",
272 " %%%",
273 " %%%%%",
274 " %%%%%%%",
275 "%%%%%%%%%",
276 " %%%%%%%",
277 " %%%%%",
278 " %%%",
279 " %"
282 #define SCROLLER_ARROW_LEFT_WIDTH 9
283 #define SCROLLER_ARROW_LEFT_HEIGHT 9
285 static char *SCROLLER_ARROW_RIGHT[] = {
286 "%........",
287 "##%......",
288 "####%....",
289 "######%..",
290 "########%",
291 "######%..",
292 "####%....",
293 "##%......",
294 "%........"
297 static char *HI_SCROLLER_ARROW_RIGHT[] = {
298 "% ",
299 "%%% ",
300 "%%%%% ",
301 "%%%%%%% ",
302 "%%%%%%%%%",
303 "%%%%%%% ",
304 "%%%%% ",
305 "%%% ",
306 "% "
309 #define SCROLLER_ARROW_RIGHT_WIDTH 9
310 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
312 static char *POPUP_INDICATOR[] = {
313 " #==",
314 " ......%#==",
315 " ......%#%%",
316 " ......%#%%",
317 " %%%%%%%#%%",
318 "#########%%",
319 "==%%%%%%%%%",
320 "==%%%%%%%%%"
323 #define POPUP_INDICATOR_WIDTH 11
324 #define POPUP_INDICATOR_HEIGHT 8
326 static char *PULLDOWN_INDICATOR[] = {
327 "=#######=",
328 "=%===== =",
329 "==%=== ==",
330 "==%=== ==",
331 "===%= ===",
332 "===%= ===",
333 "====%===="
336 #define PULLDOWN_INDICATOR_WIDTH 9
337 #define PULLDOWN_INDICATOR_HEIGHT 7
339 #define CHECK_MARK_WIDTH 8
340 #define CHECK_MARK_HEIGHT 10
342 static char *CHECK_MARK[] = {
343 "======== ",
344 "======= #",
345 "====== #%",
346 "===== #%=",
347 " #== #%==",
348 " #% #%===",
349 " % #%====",
350 " #%=====",
351 " #%======",
352 "#%======="
355 #define STIPPLE_WIDTH 8
356 #define STIPPLE_HEIGHT 8
357 static char STIPPLE_BITS[] = {
358 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
361 static int userWidgetCount = 0;
363 /***** end data ******/
365 static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
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);
373 if (mask)
374 XSetForeground(screen->display, screen->monoGC, 0);
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;
384 case '=':
385 if (mask)
386 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
388 /* FALLTHRU */
389 case '.':
390 case 'l':
391 XDrawPoint(screen->display, d, lightGC, x, y);
392 break;
394 case '%':
395 case 'd':
396 XDrawPoint(screen->display, d, darkGC, x, y);
397 break;
399 case '#':
400 case 'b':
401 default:
402 XDrawPoint(screen->display, d, blackGC, x, y);
403 break;
409 static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
411 Pixmap pixmap, mask = None;
413 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
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);
421 renderPixmap(sPtr, pixmap, mask, data, width, height);
423 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
426 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
427 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
429 static Bool loadPixmaps(WMScreen * scr)
431 RImage *image, *tmp;
432 RColor gray;
433 RColor white;
435 gray.red = 0xae;
436 gray.green = 0xaa;
437 gray.blue = 0xae;
439 white.red = 0xff;
440 white.green = 0xff;
441 white.blue = 0xff;
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;
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);
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);
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);
533 RReleaseImage(image);
535 return True;
538 WMScreen *WMOpenScreen(const char *display)
540 Display *dpy = XOpenDisplay(display);
542 if (!dpy) {
543 wwarning(_("WINGs: could not open display %s"), XDisplayName(display));
544 return NULL;
547 return WMCreateSimpleApplicationScreen(dpy);
550 WMScreen *WMCreateSimpleApplicationScreen(Display * display)
552 WMScreen *scr;
554 scr = WMCreateScreen(display, DefaultScreen(display));
556 scr->aflags.hasAppIcon = 0;
557 scr->aflags.simpleApplication = 1;
559 return scr;
562 WMScreen *WMCreateScreen(Display * display, int screen)
564 return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
567 WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
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",
601 Atom atoms[wlengthof(atomNames)];
602 int i;
604 if (!initialized) {
606 initialized = 1;
608 W_ReadConfigurations();
610 assert(W_ApplicationInitialized());
613 scrPtr = malloc(sizeof(W_Screen));
614 if (!scrPtr)
615 return NULL;
616 memset(scrPtr, 0, sizeof(W_Screen));
618 scrPtr->aflags.hasAppIcon = 1;
620 scrPtr->display = display;
621 scrPtr->screen = screen;
622 scrPtr->rcontext = context;
624 scrPtr->depth = context->depth;
626 scrPtr->visual = context->visual;
627 scrPtr->lastEventTime = 0;
629 scrPtr->colormap = context->cmap;
631 scrPtr->rootWin = RootWindow(display, screen);
633 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
635 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
637 /* Create missing CUT_BUFFERs */
639 Atom *rootWinProps;
640 int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
641 int count;
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;
674 if (rootWinProps) {
675 XFree(rootWinProps);
677 for (i = 0; i < 8; i++) {
678 if (!exists[i]) {
679 XStoreBuffer(display, "", 0, i);
684 scrPtr->ignoredModifierMask = 0;
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
693 unsigned int numLockMask = 0, scrollLockMask = 0;
695 nlock = XKeysymToKeycode(display, XK_Num_Lock);
696 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
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.
702 modmap = XGetModifierMapping(display);
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];
713 if (modmap)
714 XFreeModifiermap(modmap);
716 scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
719 /* initially allocate some colors */
720 WMWhiteColor(scrPtr);
721 WMBlackColor(scrPtr);
722 WMGrayColor(scrPtr);
723 WMDarkGrayColor(scrPtr);
725 gcv.graphics_exposures = False;
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);
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);
740 gcv.function = GXcopy;
741 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
743 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
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);
754 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
755 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
757 /* we need a 1bpp drawable for the monoGC, so borrow this one */
758 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
760 scrPtr->stipple = stipple;
762 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
764 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
766 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
768 if (!scrPtr->boldFont)
769 scrPtr->boldFont = scrPtr->normalFont;
771 if (!scrPtr->normalFont) {
772 wwarning(_("could not load any fonts. Make sure your font installation"
773 " and locale settings are correct."));
775 return NULL;
778 /* create input method stuff */
779 W_InitIM(scrPtr);
781 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
782 CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
784 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
785 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
787 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
788 RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
790 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
791 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
793 scrPtr->tristateButtonImageOn = makePixmap(scrPtr, TRISTATE_BUTTON_ON,
794 TRISTATE_BUTTON_ON_WIDTH, TRISTATE_BUTTON_ON_HEIGHT, False);
796 scrPtr->tristateButtonImageOff = makePixmap(scrPtr, TRISTATE_BUTTON_OFF,
797 TRISTATE_BUTTON_OFF_WIDTH, TRISTATE_BUTTON_OFF_HEIGHT, False);
799 scrPtr->tristateButtonImageTri = makePixmap(scrPtr, TRISTATE_BUTTON_TRI,
800 TRISTATE_BUTTON_TRI_WIDTH, TRISTATE_BUTTON_TRI_HEIGHT, False);
802 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
804 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
805 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
807 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
808 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
810 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
811 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
813 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
814 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
816 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
817 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
819 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
820 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
822 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
823 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
825 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
826 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
828 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
829 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
831 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
832 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
834 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
835 POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
837 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
838 PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
840 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
842 loadPixmaps(scrPtr);
844 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
846 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
849 XColor bla;
850 Pixmap blank;
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);
856 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
857 XFreePixmap(display, blank);
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);
866 #endif
868 i = 0;
869 scrPtr->attribsAtom = atoms[i++];
871 scrPtr->deleteWindowAtom = atoms[i++];
873 scrPtr->protocolsAtom = atoms[i++];
875 scrPtr->clipboardAtom = atoms[i++];
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++];
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++];
895 scrPtr->wmIconDragOffsetAtom = atoms[i++];
897 scrPtr->wmStateAtom = atoms[i++];
899 scrPtr->utf8String = atoms[i++];
900 scrPtr->netwmName = atoms[i++];
901 scrPtr->netwmIconName = atoms[i++];
902 scrPtr->netwmIcon = atoms[i++];
904 scrPtr->rootView = W_CreateRootView(scrPtr);
906 scrPtr->balloon = W_CreateBalloon(scrPtr);
908 W_InitApplication(scrPtr);
910 return scrPtr;
913 void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
915 WMReleaseFont(scr->normalFont);
916 scr->normalFont = WMRetainFont(font);
919 void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
921 WMReleaseFont(scr->boldFont);
922 scr->boldFont = WMRetainFont(font);
925 void WMHangData(WMWidget * widget, void *data)
927 W_VIEW(widget)->hangedData = data;
930 void *WMGetHangedData(WMWidget * widget)
932 return W_VIEW(widget)->hangedData;
935 void WMDestroyWidget(WMWidget * widget)
937 W_UnmapView(W_VIEW(widget));
938 W_DestroyView(W_VIEW(widget));
941 void WMSetFocusToWidget(WMWidget * widget)
943 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
947 * WMRealizeWidget-
948 * Realizes the widget and all it's children.
951 void WMRealizeWidget(WMWidget * w)
953 W_RealizeView(W_VIEW(w));
956 void WMMapWidget(WMWidget * w)
958 W_MapView(W_VIEW(w));
961 void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
963 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
966 static void makeChildrenAutomap(W_View * view, int flag)
968 view = view->childrenList;
970 while (view) {
971 view->flags.mapWhenRealized = flag;
972 makeChildrenAutomap(view, flag);
974 view = view->nextSister;
978 void WMMapSubwidgets(WMWidget * w)
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));
989 void WMUnmapSubwidgets(WMWidget * w)
991 if (!W_VIEW(w)->flags.realized) {
992 makeChildrenAutomap(W_VIEW(w), False);
993 } else {
994 W_UnmapSubviews(W_VIEW(w));
998 void WMUnmapWidget(WMWidget * w)
1000 W_UnmapView(W_VIEW(w));
1003 Bool WMWidgetIsMapped(WMWidget * w)
1005 return W_VIEW(w)->flags.mapped;
1008 void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
1010 W_SetViewBackgroundColor(W_VIEW(w), color);
1011 if (W_VIEW(w)->flags.mapped)
1012 WMRedisplayWidget(w);
1015 WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
1017 return W_VIEW(w)->backColor;
1020 void WMSetWidgetBackgroundPixmap(WMWidget *w, WMPixmap *pix)
1022 if (!pix)
1023 return;
1025 W_SetViewBackgroundPixmap(W_VIEW(w), pix);
1026 if (W_VIEW(w)->flags.mapped)
1027 WMRedisplayWidget(w);
1030 WMPixmap *WMGetWidgetBackgroundPixmap(WMWidget *w)
1032 return W_VIEW(w)->backImage;
1035 void WMRaiseWidget(WMWidget * w)
1037 W_RaiseView(W_VIEW(w));
1040 void WMLowerWidget(WMWidget * w)
1042 W_LowerView(W_VIEW(w));
1045 void WMMoveWidget(WMWidget * w, int x, int y)
1047 W_MoveView(W_VIEW(w), x, y);
1050 void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
1052 W_ResizeView(W_VIEW(w), width, height);
1055 W_Class W_RegisterUserWidget(void)
1057 userWidgetCount++;
1059 return userWidgetCount + WC_UserWidget - 1;
1062 RContext *WMScreenRContext(WMScreen * scr)
1064 return scr->rcontext;
1067 unsigned int WMWidgetWidth(WMWidget * w)
1069 return W_VIEW(w)->size.width;
1072 unsigned int WMWidgetHeight(WMWidget * w)
1074 return W_VIEW(w)->size.height;
1077 Window WMWidgetXID(WMWidget * w)
1079 return W_VIEW(w)->window;
1082 WMScreen *WMWidgetScreen(WMWidget * w)
1084 return W_VIEW(w)->screen;
1087 void WMScreenMainLoop(WMScreen * scr)
1089 XEvent event;
1091 while (1) {
1092 WMNextEvent(scr->display, &event);
1093 WMHandleEvent(&event);
1097 void WMBreakModalLoop(WMScreen * scr)
1099 scr->modalLoop = 0;
1102 void WMRunModalLoop(WMScreen * scr, WMView * view)
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;
1109 scr->modalView = view;
1111 scr->modalLoop = 1;
1112 while (scr->modalLoop) {
1113 XEvent event;
1115 WMNextEvent(scr->display, &event);
1116 WMHandleEvent(&event);
1119 scr->modalView = oldModalView;
1120 scr->modalLoop = oldModalLoop;
1123 Display *WMScreenDisplay(WMScreen * scr)
1125 return scr->display;
1128 int WMScreenDepth(WMScreen * scr)
1130 return scr->depth;
1133 unsigned int WMScreenWidth(WMScreen * scr)
1135 return scr->rootView->size.width;
1138 unsigned int WMScreenHeight(WMScreen * scr)
1140 return scr->rootView->size.height;
1143 void WMRedisplayWidget(WMWidget * w)
1145 W_RedisplayView(W_VIEW(w));