- fixed problem with WINGs based apps exiting with a "X_RotateProperties"
[wmaker-crm.git] / WINGs / widgets.c
blob0d828188d3306ac74978ca7d8ab306fa948a84f6
3 #include "WINGsP.h"
5 #include <X11/Xutil.h>
6 #include <X11/Xatom.h>
7 #include <X11/keysym.h>
8 #include <X11/cursorfont.h>
10 /********** data ************/
13 #define CHECK_BUTTON_ON_WIDTH 16
14 #define CHECK_BUTTON_ON_HEIGHT 16
16 static char *CHECK_BUTTON_ON[] = {
17 " %",
18 " .............%#",
19 " ........... .%#",
20 " .......... #.%#",
21 " ......... #%.%#",
22 " ........ #%..%#",
23 " ... #.. #%...%#",
24 " ... #% #%....%#",
25 " ... % #%.....%#",
26 " ... #%......%#",
27 " ... #%.......%#",
28 " ...#%........%#",
29 " .............%#",
30 " .............%#",
31 " %%%%%%%%%%%%%%#",
32 "%###############"};
34 #define CHECK_BUTTON_OFF_WIDTH 16
35 #define CHECK_BUTTON_OFF_HEIGHT 16
37 static char *CHECK_BUTTON_OFF[] = {
38 " %",
39 " .............%#",
40 " .............%#",
41 " .............%#",
42 " .............%#",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " %%%%%%%%%%%%%%#",
53 "%###############"};
55 #define RADIO_BUTTON_ON_WIDTH 15
56 #define RADIO_BUTTON_ON_HEIGHT 15
57 static char *RADIO_BUTTON_ON[] = {
58 ".....%%%%%.....",
59 "...%%#####%%...",
60 "..%##.....%.%..",
61 ".%#%.. .....",
62 ".%#. ...",
63 "%#.. .. ",
64 "%#. . ",
65 "%#. . ",
66 "%#. . ",
67 "%#. . ",
68 ".%%. . .",
69 ".%.. . .",
70 "..%... .. ..",
71 ".... ..... ...",
72 "..... .....",
75 #define RADIO_BUTTON_OFF_WIDTH 15
76 #define RADIO_BUTTON_OFF_HEIGHT 15
77 static char *RADIO_BUTTON_OFF[] = {
78 ".....%%%%%.....",
79 "...%%#####%%...",
80 "..%##.......%..",
81 ".%#%...........",
82 ".%#............",
83 "%#............ ",
84 "%#............ ",
85 "%#............ ",
86 "%#............ ",
87 "%#............ ",
88 ".%%.......... .",
89 ".%........... .",
90 "..%......... ..",
91 ".... ..... ...",
92 "..... .....",
96 static char *BUTTON_ARROW[] = {
97 "..................",
98 "....##....#### ...",
99 "...#.%....#... ...",
100 "..#..%#####... ...",
101 ".#............ ...",
102 "#............. ...",
103 ".#............ ...",
104 "..#.. ...",
105 "...#. ............",
106 "....# ............"
109 #define BUTTON_ARROW_WIDTH 18
110 #define BUTTON_ARROW_HEIGHT 10
113 static char *BUTTON_ARROW2[] = {
114 " ",
115 " ## ####. ",
116 " # % # . ",
117 " # %##### . ",
118 " # . ",
119 "# . ",
120 " # . ",
121 " # .......... ",
122 " # . ",
123 " #. "
126 #define BUTTON_ARROW2_WIDTH 18
127 #define BUTTON_ARROW2_HEIGHT 10
130 static char *SCROLLER_DIMPLE[] = {
131 ".%###.",
132 "%#%%%%",
133 "#%%...",
134 "#%.. ",
135 "#%. ",
136 ".%. ."
139 #define SCROLLER_DIMPLE_WIDTH 6
140 #define SCROLLER_DIMPLE_HEIGHT 6
143 static char *SCROLLER_ARROW_UP[] = {
144 "....%....",
145 "....#....",
146 "...%#%...",
147 "...###...",
148 "..%###%..",
149 "..#####..",
150 ".%#####%.",
151 ".#######.",
152 "%#######%"
155 static char *HI_SCROLLER_ARROW_UP[] = {
156 " % ",
157 " % ",
158 " %%% ",
159 " %%% ",
160 " %%%%% ",
161 " %%%%% ",
162 " %%%%%%% ",
163 " %%%%%%% ",
164 "%%%%%%%%%"
167 #define SCROLLER_ARROW_UP_WIDTH 9
168 #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
200 static char *SCROLLER_ARROW_LEFT[] = {
201 "........%",
202 "......%##",
203 "....%####",
204 "..%######",
205 "%########",
206 "..%######",
207 "....%####",
208 "......%##",
209 "........%"
212 static char *HI_SCROLLER_ARROW_LEFT[] = {
213 " %",
214 " %%%",
215 " %%%%%",
216 " %%%%%%%",
217 "%%%%%%%%%",
218 " %%%%%%%",
219 " %%%%%",
220 " %%%",
221 " %"
224 #define SCROLLER_ARROW_LEFT_WIDTH 9
225 #define SCROLLER_ARROW_LEFT_HEIGHT 9
228 static char *SCROLLER_ARROW_RIGHT[] = {
229 "%........",
230 "##%......",
231 "####%....",
232 "######%..",
233 "########%",
234 "######%..",
235 "####%....",
236 "##%......",
237 "%........"
240 static char *HI_SCROLLER_ARROW_RIGHT[] = {
241 "% ",
242 "%%% ",
243 "%%%%% ",
244 "%%%%%%% ",
245 "%%%%%%%%%",
246 "%%%%%%% ",
247 "%%%%% ",
248 "%%% ",
249 "% "
252 #define SCROLLER_ARROW_RIGHT_WIDTH 9
253 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
256 static char *POPUP_INDICATOR[] = {
257 " #==",
258 " ......%#==",
259 " ......%#%%",
260 " ......%#%%",
261 " %%%%%%%#%%",
262 "#########%%",
263 "==%%%%%%%%%",
264 "==%%%%%%%%%"
267 #define POPUP_INDICATOR_WIDTH 11
268 #define POPUP_INDICATOR_HEIGHT 8
272 static char *PULLDOWN_INDICATOR[] = {
273 "=#######=",
274 "=%===== =",
275 "==%=== ==",
276 "==%=== ==",
277 "===%= ===",
278 "===%= ===",
279 "====%===="
281 #define PULLDOWN_INDICATOR_WIDTH 9
282 #define PULLDOWN_INDICATOR_HEIGHT 7
285 #define CHECK_MARK_WIDTH 8
286 #define CHECK_MARK_HEIGHT 10
288 static char *CHECK_MARK[] = {
289 "======== ",
290 "======= #",
291 "====== #%",
292 "===== #%=",
293 " #== #%==",
294 " #% #%===",
295 " % #%====",
296 " #%=====",
297 " #%======",
298 "#%======="};
301 #define STIPPLE_WIDTH 8
302 #define STIPPLE_HEIGHT 8
303 static unsigned char STIPPLE_BITS[] = {
304 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa
310 extern void W_ReadConfigurations(void);
313 static int userWidgetCount=0;
316 /***** end data ******/
319 static void
320 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
321 int width, int height)
323 int x, y;
324 GC whiteGC = WMColorGC(screen->white);
325 GC blackGC = WMColorGC(screen->black);
326 GC lightGC = WMColorGC(screen->gray);
327 GC darkGC = WMColorGC(screen->darkGray);
330 if (mask)
331 XSetForeground(screen->display, screen->monoGC, 0);
333 for (y = 0; y < height; y++) {
334 for (x = 0; x < width; x++) {
335 switch (data[y][x]) {
336 case ' ':
337 case 'w':
338 XDrawPoint(screen->display, d, whiteGC, x, y);
339 break;
341 case '=':
342 if (mask)
343 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
345 case '.':
346 case 'l':
347 XDrawPoint(screen->display, d, lightGC, x, y);
348 break;
350 case '%':
351 case 'd':
352 XDrawPoint(screen->display, d, darkGC, x, y);
353 break;
355 case '#':
356 case 'b':
357 default:
358 XDrawPoint(screen->display, d, blackGC, x, y);
359 break;
367 static WMPixmap*
368 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
370 Pixmap pixmap, mask = None;
372 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
373 sPtr->depth);
375 if (masked) {
376 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
377 XSetForeground(sPtr->display, sPtr->monoGC, 1);
378 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
381 renderPixmap(sPtr, pixmap, mask, data, width, height);
383 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
384 sPtr->depth);
388 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
389 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
391 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
392 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
395 static Bool
396 loadPixmaps(WMScreen *scr)
398 RImage *image, *tmp;
399 RColor gray;
400 RColor white;
402 gray.red = 0xae;
403 gray.green = 0xaa;
404 gray.blue = 0xae;
406 white.red = 0xff;
407 white.green = 0xff;
408 white.blue = 0xff;
410 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
411 if (!image)
412 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
413 if (!image) {
414 wwarning("WINGs: could not load widget images file: %s",
415 RMessageForError(RErrorCode));
416 return False;
418 /* home icon */
419 /* make it have a gray background */
420 tmp = RGetSubImage(image, 0, 0, 24, 24);
421 RCombineImageWithColor(tmp, &gray);
422 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
423 RReleaseImage(tmp);
424 /* make it have a white background */
425 tmp = RGetSubImage(image, 0, 0, 24, 24);
426 RCombineImageWithColor(tmp, &white);
427 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
428 RReleaseImage(tmp);
430 /* trash can */
431 tmp = RGetSubImage(image, 104, 0, 24, 24);
432 RCombineImageWithColor(tmp, &white);
433 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
434 RReleaseImage(tmp);
435 tmp = RGetSubImage(image, 104, 0, 24, 24);
436 RCombineImageWithColor(tmp, &white);
437 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
438 RReleaseImage(tmp);
439 /* create dir */
440 tmp = RGetSubImage(image, 104, 24, 24, 24);
441 RCombineImageWithColor(tmp, &white);
442 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
443 RReleaseImage(tmp);
444 tmp = RGetSubImage(image, 104, 24, 24, 24);
445 RCombineImageWithColor(tmp, &white);
446 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
447 RReleaseImage(tmp);
448 /* diskettes */
449 tmp = RGetSubImage(image, 24, 80, 24, 24);
450 RCombineImageWithColor(tmp, &white);
451 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
452 RReleaseImage(tmp);
453 tmp = RGetSubImage(image, 24, 80, 24, 24);
454 RCombineImageWithColor(tmp, &white);
455 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
456 RReleaseImage(tmp);
457 /* unmount */
458 tmp = RGetSubImage(image, 0, 80, 24, 24);
459 RCombineImageWithColor(tmp, &white);
460 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
461 RReleaseImage(tmp);
462 tmp = RGetSubImage(image, 0, 80, 24, 24);
463 RCombineImageWithColor(tmp, &white);
464 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
465 RReleaseImage(tmp);
467 /* Magnifying Glass Icon for ColorPanel */
468 tmp = RGetSubImage(image, 24, 0, 40, 32);
469 RCombineImageWithColor(tmp, &gray);
470 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
471 RReleaseImage(tmp);
472 /* ColorWheel Icon for ColorPanel */
473 tmp = RGetSubImage(image, 0, 25, 24, 24);
474 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
475 RReleaseImage(tmp);
476 /* GrayScale Icon for ColorPanel */
477 tmp = RGetSubImage(image, 65, 0, 40, 24);
478 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
479 RReleaseImage(tmp);
480 /* RGB Icon for ColorPanel */
481 tmp = RGetSubImage(image, 25, 33, 40, 24);
482 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
483 RReleaseImage(tmp);
484 /* CMYK Icon for ColorPanel */
485 tmp = RGetSubImage(image, 65, 25, 40, 24);
486 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
487 RReleaseImage(tmp);
488 /* HSB Icon for ColorPanel */
489 tmp = RGetSubImage(image, 0, 57, 40, 24);
490 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
491 RReleaseImage(tmp);
492 /* CustomColorPalette Icon for ColorPanel */
493 tmp = RGetSubImage(image, 81, 57, 40, 24);
494 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
495 RReleaseImage(tmp);
496 /* ColorList Icon for ColorPanel */
497 tmp = RGetSubImage(image, 41, 57, 40, 24);
498 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
499 RReleaseImage(tmp);
501 RReleaseImage(image);
503 #if 0
504 scr->defaultObjectIcon =
505 WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
506 if (!scr->defaultObjectIcon) {
507 scr->defaultObjectIcon =
508 WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
510 if (!scr->defaultObjectIcon) {
511 wwarning("WINGs: could not load default icon file");
512 return False;
514 #endif
515 return True;
519 WMScreen*
520 WMOpenScreen(const char *display)
522 Display *dpy = XOpenDisplay(display);
524 if (!dpy) {
525 wwarning("WINGs: could not open display %s",
526 XDisplayName(display));
527 return NULL;
530 return WMCreateSimpleApplicationScreen(dpy);
534 WMScreen*
535 WMCreateSimpleApplicationScreen(Display *display)
537 WMScreen *scr;
539 scr = WMCreateScreen(display, DefaultScreen(display));
541 scr->aflags.hasAppIcon = 0;
542 scr->aflags.simpleApplication = 1;
544 return scr;
549 WMScreen*
550 WMCreateScreen(Display *display, int screen)
552 return WMCreateScreenWithRContext(display, screen,
553 RCreateContext(display, screen, NULL));
557 WMScreen*
558 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
560 W_Screen *scrPtr;
561 XGCValues gcv;
562 Pixmap stipple;
563 static int initialized = 0;
564 static char *atomNames[] = {
565 "_GNUSTEP_WM_ATTR",
566 "WM_DELETE_WINDOW",
567 "WM_PROTOCOLS",
568 "CLIPBOARD",
569 "XdndAware",
570 "XdndSelection",
571 "XdndEnter",
572 "XdndLeave",
573 "XdndPosition",
574 "XdndDrop",
575 "XdndFinished",
576 "XdndTypeList",
577 "XdndActionCopy",
578 "XdndActionMove",
579 "XdndActionLink",
580 "XdndActionAsk",
581 "XdndActionPrivate",
582 "XdndStatus",
583 "_WINGS_DND_MOUSE_OFFSET",
584 "WM_STATE"
586 Atom atoms[sizeof(atomNames)/sizeof(char*)];
587 int i;
589 if (!initialized) {
591 initialized = 1;
593 W_ReadConfigurations();
595 assert(W_ApplicationInitialized());
598 scrPtr = malloc(sizeof(W_Screen));
599 if (!scrPtr)
600 return NULL;
601 memset(scrPtr, 0, sizeof(W_Screen));
603 scrPtr->aflags.hasAppIcon = 1;
605 scrPtr->display = display;
606 scrPtr->screen = screen;
607 scrPtr->rcontext = context;
609 scrPtr->depth = context->depth;
611 scrPtr->visual = context->visual;
612 scrPtr->lastEventTime = 0;
614 scrPtr->colormap = context->cmap;
616 scrPtr->rootWin = RootWindow(display, screen);
618 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
620 /* Create missing CUT_BUFFERs */
622 Atom *rootWinProps;
623 int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
624 int count;
626 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
627 for (i=0; i<count; i++) {
628 switch(rootWinProps[i]) {
629 case XA_CUT_BUFFER0:
630 exists[0] = 1; break;
631 case XA_CUT_BUFFER1:
632 exists[1] = 1; break;
633 case XA_CUT_BUFFER2:
634 exists[2] = 1; break;
635 case XA_CUT_BUFFER3:
636 exists[3] = 1; break;
637 case XA_CUT_BUFFER4:
638 exists[4] = 1; break;
639 case XA_CUT_BUFFER5:
640 exists[5] = 1; break;
641 case XA_CUT_BUFFER6:
642 exists[6] = 1; break;
643 case XA_CUT_BUFFER7:
644 exists[7] = 1; break;
645 default:
646 break;
649 if (rootWinProps) {
650 XFree(rootWinProps);
652 for (i=0; i<8; i++) {
653 if (!exists[i]) {
654 XStoreBuffer(display, "", 0, i);
659 scrPtr->ignoredModifierMask = 0;
661 int i;
662 XModifierKeymap *modmap;
663 KeyCode nlock, slock;
664 static int mask_table[8] = {
665 ShiftMask,LockMask,ControlMask,Mod1Mask,
666 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
668 unsigned int numLockMask, scrollLockMask;
670 nlock = XKeysymToKeycode(display, XK_Num_Lock);
671 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
674 * Find out the masks for the NumLock and ScrollLock modifiers,
675 * so that we can bind the grabs for when they are enabled too.
677 modmap = XGetModifierMapping(display);
679 if (modmap!=NULL && modmap->max_keypermod>0) {
680 for (i=0; i<8*modmap->max_keypermod; i++) {
681 if (modmap->modifiermap[i]==nlock && nlock!=0)
682 numLockMask = mask_table[i/modmap->max_keypermod];
683 else if (modmap->modifiermap[i]==slock && slock!=0)
684 scrollLockMask = mask_table[i/modmap->max_keypermod];
688 if (modmap)
689 XFreeModifiermap(modmap);
692 scrPtr->ignoredModifierMask = numLockMask|scrollLockMask|LockMask;
695 /* initially allocate some colors */
696 WMWhiteColor(scrPtr);
697 WMBlackColor(scrPtr);
698 WMGrayColor(scrPtr);
699 WMDarkGrayColor(scrPtr);
701 gcv.graphics_exposures = False;
703 gcv.function = GXxor;
704 gcv.foreground = W_PIXEL(scrPtr->white);
705 if (gcv.foreground == 0) gcv.foreground = 1;
706 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
707 |GCGraphicsExposures|GCForeground, &gcv);
709 gcv.function = GXxor;
710 gcv.foreground = W_PIXEL(scrPtr->gray);
711 gcv.subwindow_mode = IncludeInferiors;
712 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
713 |GCGraphicsExposures|GCForeground
714 |GCSubwindowMode, &gcv);
716 gcv.function = GXcopy;
717 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
718 |GCGraphicsExposures, &gcv);
720 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
721 |GCGraphicsExposures, &gcv);
724 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
725 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
726 gcv.foreground = W_PIXEL(scrPtr->darkGray);
727 gcv.background = W_PIXEL(scrPtr->gray);
728 gcv.fill_style = FillStippled;
729 gcv.stipple = stipple;
730 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
731 GCForeground|GCBackground|GCStipple
732 |GCFillStyle|GCGraphicsExposures, &gcv);
734 gcv.foreground = W_PIXEL(scrPtr->black);
735 gcv.background = W_PIXEL(scrPtr->white);
736 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
737 GCForeground|GCBackground, &gcv);
739 /* we need a 1bpp drawable for the monoGC, so borrow this one */
740 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
742 scrPtr->stipple = stipple;
744 scrPtr->useMultiByte = WINGsConfiguration.useMultiByte;
746 scrPtr->normalFont = WMSystemFontOfSize(scrPtr,
747 WINGsConfiguration.defaultFontSize);
749 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr,
750 WINGsConfiguration.defaultFontSize);
752 if (!scrPtr->boldFont)
753 scrPtr->boldFont = scrPtr->normalFont;
755 if (!scrPtr->normalFont) {
756 wwarning("could not load any fonts. Make sure your font installation"
757 "and locale settings are correct.");
759 return NULL;
762 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
763 CHECK_BUTTON_ON_WIDTH,
764 CHECK_BUTTON_ON_HEIGHT, False);
766 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
767 CHECK_BUTTON_OFF_WIDTH,
768 CHECK_BUTTON_OFF_HEIGHT, False);
770 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
771 RADIO_BUTTON_ON_WIDTH,
772 RADIO_BUTTON_ON_HEIGHT, False);
774 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
775 RADIO_BUTTON_OFF_WIDTH,
776 RADIO_BUTTON_OFF_HEIGHT, False);
778 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
779 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
780 False);
782 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
783 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
784 False);
787 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
788 SCROLLER_DIMPLE_WIDTH,
789 SCROLLER_DIMPLE_HEIGHT, False);
792 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
793 SCROLLER_ARROW_UP_WIDTH,
794 SCROLLER_ARROW_UP_HEIGHT, True);
796 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
797 SCROLLER_ARROW_DOWN_WIDTH,
798 SCROLLER_ARROW_DOWN_HEIGHT, True);
800 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
801 SCROLLER_ARROW_LEFT_WIDTH,
802 SCROLLER_ARROW_LEFT_HEIGHT, True);
804 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
805 SCROLLER_ARROW_RIGHT_WIDTH,
806 SCROLLER_ARROW_RIGHT_HEIGHT, True);
808 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
809 SCROLLER_ARROW_UP_WIDTH,
810 SCROLLER_ARROW_UP_HEIGHT, True);
812 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
813 SCROLLER_ARROW_DOWN_WIDTH,
814 SCROLLER_ARROW_DOWN_HEIGHT, True);
816 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
817 SCROLLER_ARROW_LEFT_WIDTH,
818 SCROLLER_ARROW_LEFT_HEIGHT, True);
820 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
821 SCROLLER_ARROW_RIGHT_WIDTH,
822 SCROLLER_ARROW_RIGHT_HEIGHT, True);
824 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
825 POPUP_INDICATOR_WIDTH,
826 POPUP_INDICATOR_HEIGHT, True);
828 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
829 PULLDOWN_INDICATOR_WIDTH,
830 PULLDOWN_INDICATOR_HEIGHT, True);
832 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
833 CHECK_MARK_WIDTH,
834 CHECK_MARK_HEIGHT, True);
836 loadPixmaps(scrPtr);
838 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
840 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
843 XColor bla;
844 Pixmap blank;
846 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
847 XSetForeground(display, scrPtr->monoGC, 0);
848 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
850 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
851 &bla, &bla, 0, 0);
852 XFreePixmap(display, blank);
855 #ifdef HAVE_XINTERNATOMS
856 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
857 atoms);
858 #else
859 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
860 atoms[i] = XInternAtom(display, atomNames[i], False);
862 #endif
864 i = 0;
865 scrPtr->attribsAtom = atoms[i++];
867 scrPtr->deleteWindowAtom = atoms[i++];
869 scrPtr->protocolsAtom = atoms[i++];
871 scrPtr->clipboardAtom = atoms[i++];
873 scrPtr->xdndAwareAtom = atoms[i++];
874 scrPtr->xdndSelectionAtom = atoms[i++];
875 scrPtr->xdndEnterAtom = atoms[i++];
876 scrPtr->xdndLeaveAtom = atoms[i++];
877 scrPtr->xdndPositionAtom = atoms[i++];
878 scrPtr->xdndDropAtom = atoms[i++];
879 scrPtr->xdndFinishedAtom = atoms[i++];
880 scrPtr->xdndTypeListAtom = atoms[i++];
881 scrPtr->xdndStatusAtom = atoms[i++];
883 scrPtr->xdndActionCopy = atoms[i++];
884 scrPtr->xdndActionMove = atoms[i++];
885 scrPtr->xdndActionLink = atoms[i++];
886 scrPtr->xdndActionAsk = atoms[i++];
887 scrPtr->xdndActionPrivate = atoms[i++];
889 scrPtr->wmIconDragOffsetAtom = atoms[i++];
891 scrPtr->wmStateAtom = atoms[i++];
893 scrPtr->rootView = W_CreateRootView(scrPtr);
895 scrPtr->balloon = W_CreateBalloon(scrPtr);
898 W_InitApplication(scrPtr);
900 return scrPtr;
905 void
906 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
908 WMReleaseFont(scr->normalFont);
909 scr->normalFont = WMRetainFont(font);
913 void
914 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
916 WMReleaseFont(scr->boldFont);
917 scr->boldFont = WMRetainFont(font);
922 void
923 WMHangData(WMWidget *widget, void *data)
925 W_VIEW(widget)->hangedData = data;
929 void*
930 WMGetHangedData(WMWidget *widget)
932 return W_VIEW(widget)->hangedData;
937 void
938 WMDestroyWidget(WMWidget *widget)
940 W_UnmapView(W_VIEW(widget));
941 W_DestroyView(W_VIEW(widget));
945 void
946 WMSetFocusToWidget(WMWidget *widget)
948 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
953 * WMRealizeWidget-
954 * Realizes the widget and all it's children.
957 void
958 WMRealizeWidget(WMWidget *w)
960 W_RealizeView(W_VIEW(w));
963 void
964 WMMapWidget(WMWidget *w)
966 W_MapView(W_VIEW(w));
970 void
971 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
973 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
977 static void
978 makeChildrenAutomap(W_View *view, int flag)
980 view = view->childrenList;
982 while (view) {
983 view->flags.mapWhenRealized = flag;
984 makeChildrenAutomap(view, flag);
986 view = view->nextSister;
991 void
992 WMMapSubwidgets(WMWidget *w)
994 /* make sure that subwidgets created after the parent was realized
995 * are mapped too */
996 if (!W_VIEW(w)->flags.realized) {
997 makeChildrenAutomap(W_VIEW(w), True);
998 } else {
999 W_MapSubviews(W_VIEW(w));
1004 void
1005 WMUnmapSubwidgets(WMWidget *w)
1007 if (!W_VIEW(w)->flags.realized) {
1008 makeChildrenAutomap(W_VIEW(w), False);
1009 } else {
1010 W_UnmapSubviews(W_VIEW(w));
1016 void
1017 WMUnmapWidget(WMWidget *w)
1019 W_UnmapView(W_VIEW(w));
1023 Bool
1024 WMWidgetIsMapped(WMWidget *w)
1026 return W_VIEW(w)->flags.mapped;
1030 void
1031 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
1033 W_SetViewBackgroundColor(W_VIEW(w), color);
1034 if (W_VIEW(w)->flags.mapped)
1035 WMRedisplayWidget(w);
1039 void
1040 WMRaiseWidget(WMWidget *w)
1042 W_RaiseView(W_VIEW(w));
1046 void
1047 WMLowerWidget(WMWidget *w)
1049 W_LowerView(W_VIEW(w));
1053 void
1054 WMMoveWidget(WMWidget *w, int x, int y)
1056 W_MoveView(W_VIEW(w), x, y);
1060 void
1061 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
1063 W_ResizeView(W_VIEW(w), width, height);
1068 W_Class
1069 W_RegisterUserWidget(void)
1071 userWidgetCount++;
1073 return userWidgetCount + WC_UserWidget - 1;
1078 RContext*
1079 WMScreenRContext(WMScreen *scr)
1081 return scr->rcontext;
1086 unsigned int
1087 WMWidgetWidth(WMWidget *w)
1089 return W_VIEW(w)->size.width;
1093 unsigned int
1094 WMWidgetHeight(WMWidget *w)
1096 return W_VIEW(w)->size.height;
1100 Window
1101 WMWidgetXID(WMWidget *w)
1103 return W_VIEW(w)->window;
1107 WMScreen*
1108 WMWidgetScreen(WMWidget *w)
1110 return W_VIEW(w)->screen;
1115 void
1116 WMScreenMainLoop(WMScreen *scr)
1118 XEvent event;
1120 while (1) {
1121 WMNextEvent(scr->display, &event);
1122 WMHandleEvent(&event);
1127 void
1128 WMBreakModalLoop(WMScreen *scr)
1130 scr->modalLoop = 0;
1134 void
1135 WMRunModalLoop(WMScreen *scr, WMView *view)
1137 /* why is scr passed if is determined from the view? */
1138 /*WMScreen *scr = view->screen;*/
1139 int oldModalLoop = scr->modalLoop;
1140 WMView *oldModalView = scr->modalView;
1142 scr->modalView = view;
1144 scr->modalLoop = 1;
1145 while (scr->modalLoop) {
1146 XEvent event;
1148 WMNextEvent(scr->display, &event);
1149 WMHandleEvent(&event);
1152 scr->modalView = oldModalView;
1153 scr->modalLoop = oldModalLoop;
1157 Display*
1158 WMScreenDisplay(WMScreen *scr)
1160 return scr->display;
1164 int
1165 WMScreenDepth(WMScreen *scr)
1167 return scr->depth;
1171 unsigned int
1172 WMScreenWidth(WMScreen *scr)
1174 return scr->rootView->size.width;
1178 unsigned int
1179 WMScreenHeight(WMScreen *scr)
1181 return scr->rootView->size.height;
1185 void
1186 WMRedisplayWidget(WMWidget *w)
1188 W_RedisplayView(W_VIEW(w));