Add generate-mapfile-from-header.sh to distribution tarball.
[wmaker-crm.git] / WINGs / widgets.c
blob2cb27b8a34a65d56e89b0b0858009b5717fc6a22
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 static char *BUTTON_ARROW[] = {
101 "..................",
102 "....##....#### ...",
103 "...#.%....#... ...",
104 "..#..%#####... ...",
105 ".#............ ...",
106 "#............. ...",
107 ".#............ ...",
108 "..#.. ...",
109 "...#. ............",
110 "....# ............"
113 #define BUTTON_ARROW_WIDTH 18
114 #define BUTTON_ARROW_HEIGHT 10
116 static char *BUTTON_ARROW2[] = {
117 " ",
118 " ## ####. ",
119 " # % # . ",
120 " # %##### . ",
121 " # . ",
122 "# . ",
123 " # . ",
124 " # .......... ",
125 " # . ",
126 " #. "
129 #define BUTTON_ARROW2_WIDTH 18
130 #define BUTTON_ARROW2_HEIGHT 10
132 static char *SCROLLER_DIMPLE[] = {
133 ".%###.",
134 "%#%%%%",
135 "#%%...",
136 "#%.. ",
137 "#%. ",
138 ".%. ."
141 #define SCROLLER_DIMPLE_WIDTH 6
142 #define SCROLLER_DIMPLE_HEIGHT 6
144 static char *SCROLLER_ARROW_UP[] = {
145 "....%....",
146 "....#....",
147 "...%#%...",
148 "...###...",
149 "..%###%..",
150 "..#####..",
151 ".%#####%.",
152 ".#######.",
153 "%#######%"
156 static char *HI_SCROLLER_ARROW_UP[] = {
157 " % ",
158 " % ",
159 " %%% ",
160 " %%% ",
161 " %%%%% ",
162 " %%%%% ",
163 " %%%%%%% ",
164 " %%%%%%% ",
165 "%%%%%%%%%"
168 #define SCROLLER_ARROW_UP_WIDTH 9
169 #define SCROLLER_ARROW_UP_HEIGHT 9
171 static char *SCROLLER_ARROW_DOWN[] = {
172 "%#######%",
173 ".#######.",
174 ".%#####%.",
175 "..#####..",
176 "..%###%..",
177 "...###...",
178 "...%#%...",
179 "....#....",
180 "....%...."
183 static char *HI_SCROLLER_ARROW_DOWN[] = {
184 "%%%%%%%%%",
185 " %%%%%%% ",
186 " %%%%%%% ",
187 " %%%%% ",
188 " %%%%% ",
189 " %%% ",
190 " %%% ",
191 " % ",
192 " % "
195 #define SCROLLER_ARROW_DOWN_WIDTH 9
196 #define SCROLLER_ARROW_DOWN_HEIGHT 9
198 static char *SCROLLER_ARROW_LEFT[] = {
199 "........%",
200 "......%##",
201 "....%####",
202 "..%######",
203 "%########",
204 "..%######",
205 "....%####",
206 "......%##",
207 "........%"
210 static char *HI_SCROLLER_ARROW_LEFT[] = {
211 " %",
212 " %%%",
213 " %%%%%",
214 " %%%%%%%",
215 "%%%%%%%%%",
216 " %%%%%%%",
217 " %%%%%",
218 " %%%",
219 " %"
222 #define SCROLLER_ARROW_LEFT_WIDTH 9
223 #define SCROLLER_ARROW_LEFT_HEIGHT 9
225 static char *SCROLLER_ARROW_RIGHT[] = {
226 "%........",
227 "##%......",
228 "####%....",
229 "######%..",
230 "########%",
231 "######%..",
232 "####%....",
233 "##%......",
234 "%........"
237 static char *HI_SCROLLER_ARROW_RIGHT[] = {
238 "% ",
239 "%%% ",
240 "%%%%% ",
241 "%%%%%%% ",
242 "%%%%%%%%%",
243 "%%%%%%% ",
244 "%%%%% ",
245 "%%% ",
246 "% "
249 #define SCROLLER_ARROW_RIGHT_WIDTH 9
250 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
252 static char *POPUP_INDICATOR[] = {
253 " #==",
254 " ......%#==",
255 " ......%#%%",
256 " ......%#%%",
257 " %%%%%%%#%%",
258 "#########%%",
259 "==%%%%%%%%%",
260 "==%%%%%%%%%"
263 #define POPUP_INDICATOR_WIDTH 11
264 #define POPUP_INDICATOR_HEIGHT 8
266 static char *PULLDOWN_INDICATOR[] = {
267 "=#######=",
268 "=%===== =",
269 "==%=== ==",
270 "==%=== ==",
271 "===%= ===",
272 "===%= ===",
273 "====%===="
276 #define PULLDOWN_INDICATOR_WIDTH 9
277 #define PULLDOWN_INDICATOR_HEIGHT 7
279 #define CHECK_MARK_WIDTH 8
280 #define CHECK_MARK_HEIGHT 10
282 static char *CHECK_MARK[] = {
283 "======== ",
284 "======= #",
285 "====== #%",
286 "===== #%=",
287 " #== #%==",
288 " #% #%===",
289 " % #%====",
290 " #%=====",
291 " #%======",
292 "#%======="
295 #define STIPPLE_WIDTH 8
296 #define STIPPLE_HEIGHT 8
297 static char STIPPLE_BITS[] = {
298 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
301 static int userWidgetCount = 0;
303 /***** end data ******/
305 static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
307 int x, y;
308 GC whiteGC = WMColorGC(screen->white);
309 GC blackGC = WMColorGC(screen->black);
310 GC lightGC = WMColorGC(screen->gray);
311 GC darkGC = WMColorGC(screen->darkGray);
313 if (mask)
314 XSetForeground(screen->display, screen->monoGC, 0);
316 for (y = 0; y < height; y++) {
317 for (x = 0; x < width; x++) {
318 switch (data[y][x]) {
319 case ' ':
320 case 'w':
321 XDrawPoint(screen->display, d, whiteGC, x, y);
322 break;
324 case '=':
325 if (mask)
326 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
328 case '.':
329 case 'l':
330 XDrawPoint(screen->display, d, lightGC, x, y);
331 break;
333 case '%':
334 case 'd':
335 XDrawPoint(screen->display, d, darkGC, x, y);
336 break;
338 case '#':
339 case 'b':
340 default:
341 XDrawPoint(screen->display, d, blackGC, x, y);
342 break;
348 static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
350 Pixmap pixmap, mask = None;
352 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
354 if (masked) {
355 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
356 XSetForeground(sPtr->display, sPtr->monoGC, 1);
357 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
360 renderPixmap(sPtr, pixmap, mask, data, width, height);
362 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
365 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
366 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
368 static Bool loadPixmaps(WMScreen * scr)
370 RImage *image, *tmp;
371 RColor gray;
372 RColor white;
374 gray.red = 0xae;
375 gray.green = 0xaa;
376 gray.blue = 0xae;
378 white.red = 0xff;
379 white.green = 0xff;
380 white.blue = 0xff;
382 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
383 if (!image)
384 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
385 if (!image) {
386 wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
387 return False;
389 /* home icon */
390 /* make it have a gray background */
391 tmp = RGetSubImage(image, 0, 0, 24, 24);
392 RCombineImageWithColor(tmp, &gray);
393 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
394 RReleaseImage(tmp);
395 /* make it have a white background */
396 tmp = RGetSubImage(image, 0, 0, 24, 24);
397 RCombineImageWithColor(tmp, &white);
398 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
399 RReleaseImage(tmp);
401 /* trash can */
402 tmp = RGetSubImage(image, 104, 0, 24, 24);
403 RCombineImageWithColor(tmp, &white);
404 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
405 RReleaseImage(tmp);
406 tmp = RGetSubImage(image, 104, 0, 24, 24);
407 RCombineImageWithColor(tmp, &white);
408 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
409 RReleaseImage(tmp);
410 /* create dir */
411 tmp = RGetSubImage(image, 104, 24, 24, 24);
412 RCombineImageWithColor(tmp, &white);
413 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
414 RReleaseImage(tmp);
415 tmp = RGetSubImage(image, 104, 24, 24, 24);
416 RCombineImageWithColor(tmp, &white);
417 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
418 RReleaseImage(tmp);
419 /* diskettes */
420 tmp = RGetSubImage(image, 24, 80, 24, 24);
421 RCombineImageWithColor(tmp, &white);
422 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
423 RReleaseImage(tmp);
424 tmp = RGetSubImage(image, 24, 80, 24, 24);
425 RCombineImageWithColor(tmp, &white);
426 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
427 RReleaseImage(tmp);
428 /* unmount */
429 tmp = RGetSubImage(image, 0, 80, 24, 24);
430 RCombineImageWithColor(tmp, &white);
431 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
432 RReleaseImage(tmp);
433 tmp = RGetSubImage(image, 0, 80, 24, 24);
434 RCombineImageWithColor(tmp, &white);
435 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
436 RReleaseImage(tmp);
438 /* Magnifying Glass Icon for ColorPanel */
439 tmp = RGetSubImage(image, 24, 0, 40, 32);
440 RCombineImageWithColor(tmp, &gray);
441 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
442 RReleaseImage(tmp);
443 /* ColorWheel Icon for ColorPanel */
444 tmp = RGetSubImage(image, 0, 25, 24, 24);
445 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
446 RReleaseImage(tmp);
447 /* GrayScale Icon for ColorPanel */
448 tmp = RGetSubImage(image, 65, 0, 40, 24);
449 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
450 RReleaseImage(tmp);
451 /* RGB Icon for ColorPanel */
452 tmp = RGetSubImage(image, 25, 33, 40, 24);
453 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
454 RReleaseImage(tmp);
455 /* CMYK Icon for ColorPanel */
456 tmp = RGetSubImage(image, 65, 25, 40, 24);
457 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
458 RReleaseImage(tmp);
459 /* HSB Icon for ColorPanel */
460 tmp = RGetSubImage(image, 0, 57, 40, 24);
461 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
462 RReleaseImage(tmp);
463 /* CustomColorPalette Icon for ColorPanel */
464 tmp = RGetSubImage(image, 81, 57, 40, 24);
465 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
466 RReleaseImage(tmp);
467 /* ColorList Icon for ColorPanel */
468 tmp = RGetSubImage(image, 41, 57, 40, 24);
469 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
470 RReleaseImage(tmp);
472 RReleaseImage(image);
474 return True;
477 WMScreen *WMOpenScreen(const char *display)
479 Display *dpy = XOpenDisplay(display);
481 if (!dpy) {
482 wwarning("WINGs: could not open display %s", XDisplayName(display));
483 return NULL;
486 return WMCreateSimpleApplicationScreen(dpy);
489 WMScreen *WMCreateSimpleApplicationScreen(Display * display)
491 WMScreen *scr;
493 scr = WMCreateScreen(display, DefaultScreen(display));
495 scr->aflags.hasAppIcon = 0;
496 scr->aflags.simpleApplication = 1;
498 return scr;
501 WMScreen *WMCreateScreen(Display * display, int screen)
503 return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
506 WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
508 W_Screen *scrPtr;
509 XGCValues gcv;
510 Pixmap stipple;
511 static int initialized = 0;
512 static char *atomNames[] = {
513 "_GNUSTEP_WM_ATTR",
514 "WM_DELETE_WINDOW",
515 "WM_PROTOCOLS",
516 "CLIPBOARD",
517 "XdndAware",
518 "XdndSelection",
519 "XdndEnter",
520 "XdndLeave",
521 "XdndPosition",
522 "XdndDrop",
523 "XdndFinished",
524 "XdndTypeList",
525 "XdndActionList",
526 "XdndActionDescription",
527 "XdndStatus",
528 "XdndActionCopy",
529 "XdndActionMove",
530 "XdndActionLink",
531 "XdndActionAsk",
532 "XdndActionPrivate",
533 "_WINGS_DND_MOUSE_OFFSET",
534 "WM_STATE",
535 "UTF8_STRING",
536 "_NET_WM_NAME",
537 "_NET_WM_ICON_NAME",
538 "_NET_WM_ICON",
540 Atom atoms[wlengthof(atomNames)];
541 int i;
543 if (!initialized) {
545 initialized = 1;
547 W_ReadConfigurations();
549 assert(W_ApplicationInitialized());
552 scrPtr = malloc(sizeof(W_Screen));
553 if (!scrPtr)
554 return NULL;
555 memset(scrPtr, 0, sizeof(W_Screen));
557 scrPtr->aflags.hasAppIcon = 1;
559 scrPtr->display = display;
560 scrPtr->screen = screen;
561 scrPtr->rcontext = context;
563 scrPtr->depth = context->depth;
565 scrPtr->visual = context->visual;
566 scrPtr->lastEventTime = 0;
568 scrPtr->colormap = context->cmap;
570 scrPtr->rootWin = RootWindow(display, screen);
572 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
574 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
576 /* Create missing CUT_BUFFERs */
578 Atom *rootWinProps;
579 int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
580 int count;
582 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
583 for (i = 0; i < count; i++) {
584 switch (rootWinProps[i]) {
585 case XA_CUT_BUFFER0:
586 exists[0] = 1;
587 break;
588 case XA_CUT_BUFFER1:
589 exists[1] = 1;
590 break;
591 case XA_CUT_BUFFER2:
592 exists[2] = 1;
593 break;
594 case XA_CUT_BUFFER3:
595 exists[3] = 1;
596 break;
597 case XA_CUT_BUFFER4:
598 exists[4] = 1;
599 break;
600 case XA_CUT_BUFFER5:
601 exists[5] = 1;
602 break;
603 case XA_CUT_BUFFER6:
604 exists[6] = 1;
605 break;
606 case XA_CUT_BUFFER7:
607 exists[7] = 1;
608 break;
609 default:
610 break;
613 if (rootWinProps) {
614 XFree(rootWinProps);
616 for (i = 0; i < 8; i++) {
617 if (!exists[i]) {
618 XStoreBuffer(display, "", 0, i);
623 scrPtr->ignoredModifierMask = 0;
625 int i;
626 XModifierKeymap *modmap;
627 KeyCode nlock, slock;
628 static int mask_table[8] = {
629 ShiftMask, LockMask, ControlMask, Mod1Mask,
630 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
632 unsigned int numLockMask = 0, scrollLockMask = 0;
634 nlock = XKeysymToKeycode(display, XK_Num_Lock);
635 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
638 * Find out the masks for the NumLock and ScrollLock modifiers,
639 * so that we can bind the grabs for when they are enabled too.
641 modmap = XGetModifierMapping(display);
643 if (modmap != NULL && modmap->max_keypermod > 0) {
644 for (i = 0; i < 8 * modmap->max_keypermod; i++) {
645 if (modmap->modifiermap[i] == nlock && nlock != 0)
646 numLockMask = mask_table[i / modmap->max_keypermod];
647 else if (modmap->modifiermap[i] == slock && slock != 0)
648 scrollLockMask = mask_table[i / modmap->max_keypermod];
652 if (modmap)
653 XFreeModifiermap(modmap);
655 scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
658 /* initially allocate some colors */
659 WMWhiteColor(scrPtr);
660 WMBlackColor(scrPtr);
661 WMGrayColor(scrPtr);
662 WMDarkGrayColor(scrPtr);
664 gcv.graphics_exposures = False;
666 gcv.function = GXxor;
667 gcv.foreground = W_PIXEL(scrPtr->white);
668 if (gcv.foreground == 0)
669 gcv.foreground = 1;
670 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
671 | GCGraphicsExposures | GCForeground, &gcv);
673 gcv.function = GXxor;
674 gcv.foreground = W_PIXEL(scrPtr->gray);
675 gcv.subwindow_mode = IncludeInferiors;
676 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
677 | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
679 gcv.function = GXcopy;
680 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
682 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
684 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
685 gcv.foreground = W_PIXEL(scrPtr->darkGray);
686 gcv.background = W_PIXEL(scrPtr->gray);
687 gcv.fill_style = FillStippled;
688 gcv.stipple = stipple;
689 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
690 GCForeground | GCBackground | GCStipple
691 | GCFillStyle | GCGraphicsExposures, &gcv);
693 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
694 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
696 /* we need a 1bpp drawable for the monoGC, so borrow this one */
697 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
699 scrPtr->stipple = stipple;
701 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
703 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
705 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
707 if (!scrPtr->boldFont)
708 scrPtr->boldFont = scrPtr->normalFont;
710 if (!scrPtr->normalFont) {
711 wwarning(_("could not load any fonts. Make sure your font installation"
712 " and locale settings are correct."));
714 return NULL;
717 /* create input method stuff */
718 W_InitIM(scrPtr);
720 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
721 CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
723 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
724 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
726 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
727 RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
729 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
730 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
732 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
734 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
735 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
737 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
738 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
740 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
741 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
743 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
744 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
746 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
747 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
749 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
750 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
752 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
753 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
755 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
756 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
758 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
759 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
761 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
762 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
764 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
765 POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
767 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
768 PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
770 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
772 loadPixmaps(scrPtr);
774 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
776 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
779 XColor bla;
780 Pixmap blank;
782 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
783 XSetForeground(display, scrPtr->monoGC, 0);
784 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
786 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
787 XFreePixmap(display, blank);
790 #ifdef HAVE_XINTERNATOMS
791 XInternAtoms(display, atomNames, wlengthof(atomNames), False, atoms);
792 #else
793 for (i = 0; i < wlengthof(atomNames); i++) {
794 atoms[i] = XInternAtom(display, atomNames[i], False);
796 #endif
798 i = 0;
799 scrPtr->attribsAtom = atoms[i++];
801 scrPtr->deleteWindowAtom = atoms[i++];
803 scrPtr->protocolsAtom = atoms[i++];
805 scrPtr->clipboardAtom = atoms[i++];
807 scrPtr->xdndAwareAtom = atoms[i++];
808 scrPtr->xdndSelectionAtom = atoms[i++];
809 scrPtr->xdndEnterAtom = atoms[i++];
810 scrPtr->xdndLeaveAtom = atoms[i++];
811 scrPtr->xdndPositionAtom = atoms[i++];
812 scrPtr->xdndDropAtom = atoms[i++];
813 scrPtr->xdndFinishedAtom = atoms[i++];
814 scrPtr->xdndTypeListAtom = atoms[i++];
815 scrPtr->xdndActionListAtom = atoms[i++];
816 scrPtr->xdndActionDescriptionAtom = atoms[i++];
817 scrPtr->xdndStatusAtom = atoms[i++];
819 scrPtr->xdndActionCopy = atoms[i++];
820 scrPtr->xdndActionMove = atoms[i++];
821 scrPtr->xdndActionLink = atoms[i++];
822 scrPtr->xdndActionAsk = atoms[i++];
823 scrPtr->xdndActionPrivate = atoms[i++];
825 scrPtr->wmIconDragOffsetAtom = atoms[i++];
827 scrPtr->wmStateAtom = atoms[i++];
829 scrPtr->utf8String = atoms[i++];
830 scrPtr->netwmName = atoms[i++];
831 scrPtr->netwmIconName = atoms[i++];
832 scrPtr->netwmIcon = atoms[i++];
834 scrPtr->rootView = W_CreateRootView(scrPtr);
836 scrPtr->balloon = W_CreateBalloon(scrPtr);
838 W_InitApplication(scrPtr);
840 return scrPtr;
843 void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
845 WMReleaseFont(scr->normalFont);
846 scr->normalFont = WMRetainFont(font);
849 void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
851 WMReleaseFont(scr->boldFont);
852 scr->boldFont = WMRetainFont(font);
855 void WMHangData(WMWidget * widget, void *data)
857 W_VIEW(widget)->hangedData = data;
860 void *WMGetHangedData(WMWidget * widget)
862 return W_VIEW(widget)->hangedData;
865 void WMDestroyWidget(WMWidget * widget)
867 W_UnmapView(W_VIEW(widget));
868 W_DestroyView(W_VIEW(widget));
871 void WMSetFocusToWidget(WMWidget * widget)
873 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
877 * WMRealizeWidget-
878 * Realizes the widget and all it's children.
881 void WMRealizeWidget(WMWidget * w)
883 W_RealizeView(W_VIEW(w));
886 void WMMapWidget(WMWidget * w)
888 W_MapView(W_VIEW(w));
891 void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
893 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
896 static void makeChildrenAutomap(W_View * view, int flag)
898 view = view->childrenList;
900 while (view) {
901 view->flags.mapWhenRealized = flag;
902 makeChildrenAutomap(view, flag);
904 view = view->nextSister;
908 void WMMapSubwidgets(WMWidget * w)
910 /* make sure that subwidgets created after the parent was realized
911 * are mapped too */
912 if (!W_VIEW(w)->flags.realized) {
913 makeChildrenAutomap(W_VIEW(w), True);
914 } else {
915 W_MapSubviews(W_VIEW(w));
919 void WMUnmapSubwidgets(WMWidget * w)
921 if (!W_VIEW(w)->flags.realized) {
922 makeChildrenAutomap(W_VIEW(w), False);
923 } else {
924 W_UnmapSubviews(W_VIEW(w));
928 void WMUnmapWidget(WMWidget * w)
930 W_UnmapView(W_VIEW(w));
933 Bool WMWidgetIsMapped(WMWidget * w)
935 return W_VIEW(w)->flags.mapped;
938 void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
940 W_SetViewBackgroundColor(W_VIEW(w), color);
941 if (W_VIEW(w)->flags.mapped)
942 WMRedisplayWidget(w);
945 WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
947 return W_VIEW(w)->backColor;
950 void WMSetWidgetBackgroundPixmap(WMWidget *w, WMPixmap *pix)
952 if (!pix)
953 return;
955 W_SetViewBackgroundPixmap(W_VIEW(w), pix);
956 if (W_VIEW(w)->flags.mapped)
957 WMRedisplayWidget(w);
960 WMPixmap *WMGetWidgetBackgroundPixmap(WMWidget *w)
962 return W_VIEW(w)->backImage;
965 void WMRaiseWidget(WMWidget * w)
967 W_RaiseView(W_VIEW(w));
970 void WMLowerWidget(WMWidget * w)
972 W_LowerView(W_VIEW(w));
975 void WMMoveWidget(WMWidget * w, int x, int y)
977 W_MoveView(W_VIEW(w), x, y);
980 void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
982 W_ResizeView(W_VIEW(w), width, height);
985 W_Class W_RegisterUserWidget(void)
987 userWidgetCount++;
989 return userWidgetCount + WC_UserWidget - 1;
992 RContext *WMScreenRContext(WMScreen * scr)
994 return scr->rcontext;
997 unsigned int WMWidgetWidth(WMWidget * w)
999 return W_VIEW(w)->size.width;
1002 unsigned int WMWidgetHeight(WMWidget * w)
1004 return W_VIEW(w)->size.height;
1007 Window WMWidgetXID(WMWidget * w)
1009 return W_VIEW(w)->window;
1012 WMScreen *WMWidgetScreen(WMWidget * w)
1014 return W_VIEW(w)->screen;
1017 void WMScreenMainLoop(WMScreen * scr)
1019 XEvent event;
1021 while (1) {
1022 WMNextEvent(scr->display, &event);
1023 WMHandleEvent(&event);
1027 void WMBreakModalLoop(WMScreen * scr)
1029 scr->modalLoop = 0;
1032 void WMRunModalLoop(WMScreen * scr, WMView * view)
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;
1039 scr->modalView = view;
1041 scr->modalLoop = 1;
1042 while (scr->modalLoop) {
1043 XEvent event;
1045 WMNextEvent(scr->display, &event);
1046 WMHandleEvent(&event);
1049 scr->modalView = oldModalView;
1050 scr->modalLoop = oldModalLoop;
1053 Display *WMScreenDisplay(WMScreen * scr)
1055 return scr->display;
1058 int WMScreenDepth(WMScreen * scr)
1060 return scr->depth;
1063 unsigned int WMScreenWidth(WMScreen * scr)
1065 return scr->rootView->size.width;
1068 unsigned int WMScreenHeight(WMScreen * scr)
1070 return scr->rootView->size.height;
1073 void WMRedisplayWidget(WMWidget * w)
1075 W_RedisplayView(W_VIEW(w));