- s/sprintf/snprintf
[wmaker-crm.git] / WINGs / widgets.c
blobf1d80e577ba61848cfbd9810ef4125268d7d1ae7
3 #include "WINGsP.h"
4 #include "wconfig.h"
6 #include <X11/Xutil.h>
7 #include <X11/Xatom.h>
8 #include <X11/keysym.h>
9 #include <X11/cursorfont.h>
11 /********** data ************/
14 #define CHECK_BUTTON_ON_WIDTH 16
15 #define CHECK_BUTTON_ON_HEIGHT 16
17 static char *CHECK_BUTTON_ON[] = {
18 " %",
19 " .............%#",
20 " ........... .%#",
21 " .......... #.%#",
22 " ......... #%.%#",
23 " ........ #%..%#",
24 " ... #.. #%...%#",
25 " ... #% #%....%#",
26 " ... % #%.....%#",
27 " ... #%......%#",
28 " ... #%.......%#",
29 " ...#%........%#",
30 " .............%#",
31 " .............%#",
32 " %%%%%%%%%%%%%%#",
33 "%###############"};
35 #define CHECK_BUTTON_OFF_WIDTH 16
36 #define CHECK_BUTTON_OFF_HEIGHT 16
38 static char *CHECK_BUTTON_OFF[] = {
39 " %",
40 " .............%#",
41 " .............%#",
42 " .............%#",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " .............%#",
53 " %%%%%%%%%%%%%%#",
54 "%###############"};
56 #define RADIO_BUTTON_ON_WIDTH 15
57 #define RADIO_BUTTON_ON_HEIGHT 15
58 static char *RADIO_BUTTON_ON[] = {
59 ".....%%%%%.....",
60 "...%%#####%%...",
61 "..%##.....%.%..",
62 ".%#%.. .....",
63 ".%#. ...",
64 "%#.. .. ",
65 "%#. . ",
66 "%#. . ",
67 "%#. . ",
68 "%#. . ",
69 ".%%. . .",
70 ".%.. . .",
71 "..%... .. ..",
72 ".... ..... ...",
73 "..... .....",
76 #define RADIO_BUTTON_OFF_WIDTH 15
77 #define RADIO_BUTTON_OFF_HEIGHT 15
78 static char *RADIO_BUTTON_OFF[] = {
79 ".....%%%%%.....",
80 "...%%#####%%...",
81 "..%##.......%..",
82 ".%#%...........",
83 ".%#............",
84 "%#............ ",
85 "%#............ ",
86 "%#............ ",
87 "%#............ ",
88 "%#............ ",
89 ".%%.......... .",
90 ".%........... .",
91 "..%......... ..",
92 ".... ..... ...",
93 "..... .....",
97 static char *BUTTON_ARROW[] = {
98 "..................",
99 "....##....#### ...",
100 "...#.%....#... ...",
101 "..#..%#####... ...",
102 ".#............ ...",
103 "#............. ...",
104 ".#............ ...",
105 "..#.. ...",
106 "...#. ............",
107 "....# ............"
110 #define BUTTON_ARROW_WIDTH 18
111 #define BUTTON_ARROW_HEIGHT 10
114 static char *BUTTON_ARROW2[] = {
115 " ",
116 " ## ####. ",
117 " # % # . ",
118 " # %##### . ",
119 " # . ",
120 "# . ",
121 " # . ",
122 " # .......... ",
123 " # . ",
124 " #. "
127 #define BUTTON_ARROW2_WIDTH 18
128 #define BUTTON_ARROW2_HEIGHT 10
131 static char *SCROLLER_DIMPLE[] = {
132 ".%###.",
133 "%#%%%%",
134 "#%%...",
135 "#%.. ",
136 "#%. ",
137 ".%. ."
140 #define SCROLLER_DIMPLE_WIDTH 6
141 #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
172 static char *SCROLLER_ARROW_DOWN[] = {
173 "%#######%",
174 ".#######.",
175 ".%#####%.",
176 "..#####..",
177 "..%###%..",
178 "...###...",
179 "...%#%...",
180 "....#....",
181 "....%...."
184 static char *HI_SCROLLER_ARROW_DOWN[] = {
185 "%%%%%%%%%",
186 " %%%%%%% ",
187 " %%%%%%% ",
188 " %%%%% ",
189 " %%%%% ",
190 " %%% ",
191 " %%% ",
192 " % ",
193 " % "
196 #define SCROLLER_ARROW_DOWN_WIDTH 9
197 #define SCROLLER_ARROW_DOWN_HEIGHT 9
201 static char *SCROLLER_ARROW_LEFT[] = {
202 "........%",
203 "......%##",
204 "....%####",
205 "..%######",
206 "%########",
207 "..%######",
208 "....%####",
209 "......%##",
210 "........%"
213 static char *HI_SCROLLER_ARROW_LEFT[] = {
214 " %",
215 " %%%",
216 " %%%%%",
217 " %%%%%%%",
218 "%%%%%%%%%",
219 " %%%%%%%",
220 " %%%%%",
221 " %%%",
222 " %"
225 #define SCROLLER_ARROW_LEFT_WIDTH 9
226 #define SCROLLER_ARROW_LEFT_HEIGHT 9
229 static char *SCROLLER_ARROW_RIGHT[] = {
230 "%........",
231 "##%......",
232 "####%....",
233 "######%..",
234 "########%",
235 "######%..",
236 "####%....",
237 "##%......",
238 "%........"
241 static char *HI_SCROLLER_ARROW_RIGHT[] = {
242 "% ",
243 "%%% ",
244 "%%%%% ",
245 "%%%%%%% ",
246 "%%%%%%%%%",
247 "%%%%%%% ",
248 "%%%%% ",
249 "%%% ",
250 "% "
253 #define SCROLLER_ARROW_RIGHT_WIDTH 9
254 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
257 static char *POPUP_INDICATOR[] = {
258 " #==",
259 " ......%#==",
260 " ......%#%%",
261 " ......%#%%",
262 " %%%%%%%#%%",
263 "#########%%",
264 "==%%%%%%%%%",
265 "==%%%%%%%%%"
268 #define POPUP_INDICATOR_WIDTH 11
269 #define POPUP_INDICATOR_HEIGHT 8
273 static char *PULLDOWN_INDICATOR[] = {
274 "=#######=",
275 "=%===== =",
276 "==%=== ==",
277 "==%=== ==",
278 "===%= ===",
279 "===%= ===",
280 "====%===="
282 #define PULLDOWN_INDICATOR_WIDTH 9
283 #define PULLDOWN_INDICATOR_HEIGHT 7
286 #define CHECK_MARK_WIDTH 8
287 #define CHECK_MARK_HEIGHT 10
289 static char *CHECK_MARK[] = {
290 "======== ",
291 "======= #",
292 "====== #%",
293 "===== #%=",
294 " #== #%==",
295 " #% #%===",
296 " % #%====",
297 " #%=====",
298 " #%======",
299 "#%======="};
302 #define STIPPLE_WIDTH 8
303 #define STIPPLE_HEIGHT 8
304 static unsigned char STIPPLE_BITS[] = {
305 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa
311 extern void W_ReadConfigurations(void);
314 static int userWidgetCount=0;
317 /***** end data ******/
320 static void
321 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
322 int width, int height)
324 int x, y;
325 GC whiteGC = WMColorGC(screen->white);
326 GC blackGC = WMColorGC(screen->black);
327 GC lightGC = WMColorGC(screen->gray);
328 GC darkGC = WMColorGC(screen->darkGray);
331 if (mask)
332 XSetForeground(screen->display, screen->monoGC, 0);
334 for (y = 0; y < height; y++) {
335 for (x = 0; x < width; x++) {
336 switch (data[y][x]) {
337 case ' ':
338 case 'w':
339 XDrawPoint(screen->display, d, whiteGC, x, y);
340 break;
342 case '=':
343 if (mask)
344 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
346 case '.':
347 case 'l':
348 XDrawPoint(screen->display, d, lightGC, x, y);
349 break;
351 case '%':
352 case 'd':
353 XDrawPoint(screen->display, d, darkGC, x, y);
354 break;
356 case '#':
357 case 'b':
358 default:
359 XDrawPoint(screen->display, d, blackGC, x, y);
360 break;
368 static WMPixmap*
369 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
371 Pixmap pixmap, mask = None;
373 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
374 sPtr->depth);
376 if (masked) {
377 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
378 XSetForeground(sPtr->display, sPtr->monoGC, 1);
379 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
382 renderPixmap(sPtr, pixmap, mask, data, width, height);
384 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
385 sPtr->depth);
389 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
390 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
392 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
393 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
396 static Bool
397 loadPixmaps(WMScreen *scr)
399 RImage *image, *tmp;
400 RColor gray;
401 RColor white;
403 gray.red = 0xae;
404 gray.green = 0xaa;
405 gray.blue = 0xae;
407 white.red = 0xff;
408 white.green = 0xff;
409 white.blue = 0xff;
411 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
412 if (!image)
413 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
414 if (!image) {
415 wwarning(_("WINGs: could not load widget images file: %s"),
416 RMessageForError(RErrorCode));
417 return False;
419 /* home icon */
420 /* make it have a gray background */
421 tmp = RGetSubImage(image, 0, 0, 24, 24);
422 RCombineImageWithColor(tmp, &gray);
423 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
424 RReleaseImage(tmp);
425 /* make it have a white background */
426 tmp = RGetSubImage(image, 0, 0, 24, 24);
427 RCombineImageWithColor(tmp, &white);
428 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
429 RReleaseImage(tmp);
431 /* trash can */
432 tmp = RGetSubImage(image, 104, 0, 24, 24);
433 RCombineImageWithColor(tmp, &white);
434 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
435 RReleaseImage(tmp);
436 tmp = RGetSubImage(image, 104, 0, 24, 24);
437 RCombineImageWithColor(tmp, &white);
438 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
439 RReleaseImage(tmp);
440 /* create dir */
441 tmp = RGetSubImage(image, 104, 24, 24, 24);
442 RCombineImageWithColor(tmp, &white);
443 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
444 RReleaseImage(tmp);
445 tmp = RGetSubImage(image, 104, 24, 24, 24);
446 RCombineImageWithColor(tmp, &white);
447 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
448 RReleaseImage(tmp);
449 /* diskettes */
450 tmp = RGetSubImage(image, 24, 80, 24, 24);
451 RCombineImageWithColor(tmp, &white);
452 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
453 RReleaseImage(tmp);
454 tmp = RGetSubImage(image, 24, 80, 24, 24);
455 RCombineImageWithColor(tmp, &white);
456 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
457 RReleaseImage(tmp);
458 /* unmount */
459 tmp = RGetSubImage(image, 0, 80, 24, 24);
460 RCombineImageWithColor(tmp, &white);
461 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
462 RReleaseImage(tmp);
463 tmp = RGetSubImage(image, 0, 80, 24, 24);
464 RCombineImageWithColor(tmp, &white);
465 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
466 RReleaseImage(tmp);
468 /* Magnifying Glass Icon for ColorPanel */
469 tmp = RGetSubImage(image, 24, 0, 40, 32);
470 RCombineImageWithColor(tmp, &gray);
471 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
472 RReleaseImage(tmp);
473 /* ColorWheel Icon for ColorPanel */
474 tmp = RGetSubImage(image, 0, 25, 24, 24);
475 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
476 RReleaseImage(tmp);
477 /* GrayScale Icon for ColorPanel */
478 tmp = RGetSubImage(image, 65, 0, 40, 24);
479 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
480 RReleaseImage(tmp);
481 /* RGB Icon for ColorPanel */
482 tmp = RGetSubImage(image, 25, 33, 40, 24);
483 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
484 RReleaseImage(tmp);
485 /* CMYK Icon for ColorPanel */
486 tmp = RGetSubImage(image, 65, 25, 40, 24);
487 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
488 RReleaseImage(tmp);
489 /* HSB Icon for ColorPanel */
490 tmp = RGetSubImage(image, 0, 57, 40, 24);
491 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
492 RReleaseImage(tmp);
493 /* CustomColorPalette Icon for ColorPanel */
494 tmp = RGetSubImage(image, 81, 57, 40, 24);
495 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
496 RReleaseImage(tmp);
497 /* ColorList Icon for ColorPanel */
498 tmp = RGetSubImage(image, 41, 57, 40, 24);
499 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
500 RReleaseImage(tmp);
502 RReleaseImage(image);
504 #if 0
505 scr->defaultObjectIcon =
506 WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
507 if (!scr->defaultObjectIcon) {
508 scr->defaultObjectIcon =
509 WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
511 if (!scr->defaultObjectIcon) {
512 wwarning("WINGs: could not load default icon file");
513 return False;
515 #endif
516 return True;
520 WMScreen*
521 WMOpenScreen(const char *display)
523 Display *dpy = XOpenDisplay(display);
525 if (!dpy) {
526 wwarning("WINGs: could not open display %s",
527 XDisplayName(display));
528 return NULL;
531 return WMCreateSimpleApplicationScreen(dpy);
535 WMScreen*
536 WMCreateSimpleApplicationScreen(Display *display)
538 WMScreen *scr;
540 scr = WMCreateScreen(display, DefaultScreen(display));
542 scr->aflags.hasAppIcon = 0;
543 scr->aflags.simpleApplication = 1;
545 return scr;
550 WMScreen*
551 WMCreateScreen(Display *display, int screen)
553 return WMCreateScreenWithRContext(display, screen,
554 RCreateContext(display, screen, NULL));
558 WMScreen*
559 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
561 W_Screen *scrPtr;
562 XGCValues gcv;
563 Pixmap stipple;
564 static int initialized = 0;
565 static char *atomNames[] = {
566 "_GNUSTEP_WM_ATTR",
567 "WM_DELETE_WINDOW",
568 "WM_PROTOCOLS",
569 "CLIPBOARD",
570 "XdndAware",
571 "XdndSelection",
572 "XdndEnter",
573 "XdndLeave",
574 "XdndPosition",
575 "XdndDrop",
576 "XdndFinished",
577 "XdndTypeList",
578 "XdndActionCopy",
579 "XdndActionMove",
580 "XdndActionLink",
581 "XdndActionAsk",
582 "XdndActionPrivate",
583 "XdndStatus",
584 "_WINGS_DND_MOUSE_OFFSET",
585 "WM_STATE"
587 Atom atoms[sizeof(atomNames)/sizeof(char*)];
588 int i;
590 if (!initialized) {
592 initialized = 1;
594 W_ReadConfigurations();
596 assert(W_ApplicationInitialized());
599 scrPtr = malloc(sizeof(W_Screen));
600 if (!scrPtr)
601 return NULL;
602 memset(scrPtr, 0, sizeof(W_Screen));
604 scrPtr->aflags.hasAppIcon = 1;
606 scrPtr->display = display;
607 scrPtr->screen = screen;
608 scrPtr->rcontext = context;
610 scrPtr->depth = context->depth;
612 scrPtr->visual = context->visual;
613 scrPtr->lastEventTime = 0;
615 scrPtr->colormap = context->cmap;
617 scrPtr->rootWin = RootWindow(display, screen);
619 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
621 /* Create missing CUT_BUFFERs */
623 Atom *rootWinProps;
624 int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
625 int count;
627 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
628 for (i=0; i<count; i++) {
629 switch(rootWinProps[i]) {
630 case XA_CUT_BUFFER0:
631 exists[0] = 1; break;
632 case XA_CUT_BUFFER1:
633 exists[1] = 1; break;
634 case XA_CUT_BUFFER2:
635 exists[2] = 1; break;
636 case XA_CUT_BUFFER3:
637 exists[3] = 1; break;
638 case XA_CUT_BUFFER4:
639 exists[4] = 1; break;
640 case XA_CUT_BUFFER5:
641 exists[5] = 1; break;
642 case XA_CUT_BUFFER6:
643 exists[6] = 1; break;
644 case XA_CUT_BUFFER7:
645 exists[7] = 1; break;
646 default:
647 break;
650 if (rootWinProps) {
651 XFree(rootWinProps);
653 for (i=0; i<8; i++) {
654 if (!exists[i]) {
655 XStoreBuffer(display, "", 0, i);
660 scrPtr->ignoredModifierMask = 0;
662 int i;
663 XModifierKeymap *modmap;
664 KeyCode nlock, slock;
665 static int mask_table[8] = {
666 ShiftMask,LockMask,ControlMask,Mod1Mask,
667 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
669 unsigned int numLockMask, scrollLockMask;
671 nlock = XKeysymToKeycode(display, XK_Num_Lock);
672 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
675 * Find out the masks for the NumLock and ScrollLock modifiers,
676 * so that we can bind the grabs for when they are enabled too.
678 modmap = XGetModifierMapping(display);
680 if (modmap!=NULL && modmap->max_keypermod>0) {
681 for (i=0; i<8*modmap->max_keypermod; i++) {
682 if (modmap->modifiermap[i]==nlock && nlock!=0)
683 numLockMask = mask_table[i/modmap->max_keypermod];
684 else if (modmap->modifiermap[i]==slock && slock!=0)
685 scrollLockMask = mask_table[i/modmap->max_keypermod];
689 if (modmap)
690 XFreeModifiermap(modmap);
693 scrPtr->ignoredModifierMask = numLockMask|scrollLockMask|LockMask;
696 /* initially allocate some colors */
697 WMWhiteColor(scrPtr);
698 WMBlackColor(scrPtr);
699 WMGrayColor(scrPtr);
700 WMDarkGrayColor(scrPtr);
702 gcv.graphics_exposures = False;
704 gcv.function = GXxor;
705 gcv.foreground = W_PIXEL(scrPtr->white);
706 if (gcv.foreground == 0) gcv.foreground = 1;
707 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
708 |GCGraphicsExposures|GCForeground, &gcv);
710 gcv.function = GXxor;
711 gcv.foreground = W_PIXEL(scrPtr->gray);
712 gcv.subwindow_mode = IncludeInferiors;
713 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
714 |GCGraphicsExposures|GCForeground
715 |GCSubwindowMode, &gcv);
717 gcv.function = GXcopy;
718 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
719 |GCGraphicsExposures, &gcv);
721 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
722 |GCGraphicsExposures, &gcv);
725 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
726 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
727 gcv.foreground = W_PIXEL(scrPtr->darkGray);
728 gcv.background = W_PIXEL(scrPtr->gray);
729 gcv.fill_style = FillStippled;
730 gcv.stipple = stipple;
731 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
732 GCForeground|GCBackground|GCStipple
733 |GCFillStyle|GCGraphicsExposures, &gcv);
735 gcv.foreground = W_PIXEL(scrPtr->black);
736 gcv.background = W_PIXEL(scrPtr->white);
737 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
738 GCForeground|GCBackground, &gcv);
740 /* we need a 1bpp drawable for the monoGC, so borrow this one */
741 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
743 scrPtr->stipple = stipple;
745 scrPtr->useMultiByte = WINGsConfiguration.useMultiByte;
747 scrPtr->normalFont = WMSystemFontOfSize(scrPtr,
748 WINGsConfiguration.defaultFontSize);
750 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr,
751 WINGsConfiguration.defaultFontSize);
753 if (!scrPtr->boldFont)
754 scrPtr->boldFont = scrPtr->normalFont;
756 if (!scrPtr->normalFont) {
757 wwarning(_("could not load any fonts. Make sure your font installation"
758 "and locale settings are correct."));
760 return NULL;
763 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
764 CHECK_BUTTON_ON_WIDTH,
765 CHECK_BUTTON_ON_HEIGHT, False);
767 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
768 CHECK_BUTTON_OFF_WIDTH,
769 CHECK_BUTTON_OFF_HEIGHT, False);
771 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
772 RADIO_BUTTON_ON_WIDTH,
773 RADIO_BUTTON_ON_HEIGHT, False);
775 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
776 RADIO_BUTTON_OFF_WIDTH,
777 RADIO_BUTTON_OFF_HEIGHT, False);
779 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
780 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
781 False);
783 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
784 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
785 False);
788 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
789 SCROLLER_DIMPLE_WIDTH,
790 SCROLLER_DIMPLE_HEIGHT, False);
793 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
794 SCROLLER_ARROW_UP_WIDTH,
795 SCROLLER_ARROW_UP_HEIGHT, True);
797 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
798 SCROLLER_ARROW_DOWN_WIDTH,
799 SCROLLER_ARROW_DOWN_HEIGHT, True);
801 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
802 SCROLLER_ARROW_LEFT_WIDTH,
803 SCROLLER_ARROW_LEFT_HEIGHT, True);
805 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
806 SCROLLER_ARROW_RIGHT_WIDTH,
807 SCROLLER_ARROW_RIGHT_HEIGHT, True);
809 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
810 SCROLLER_ARROW_UP_WIDTH,
811 SCROLLER_ARROW_UP_HEIGHT, True);
813 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
814 SCROLLER_ARROW_DOWN_WIDTH,
815 SCROLLER_ARROW_DOWN_HEIGHT, True);
817 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
818 SCROLLER_ARROW_LEFT_WIDTH,
819 SCROLLER_ARROW_LEFT_HEIGHT, True);
821 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
822 SCROLLER_ARROW_RIGHT_WIDTH,
823 SCROLLER_ARROW_RIGHT_HEIGHT, True);
825 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
826 POPUP_INDICATOR_WIDTH,
827 POPUP_INDICATOR_HEIGHT, True);
829 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
830 PULLDOWN_INDICATOR_WIDTH,
831 PULLDOWN_INDICATOR_HEIGHT, True);
833 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
834 CHECK_MARK_WIDTH,
835 CHECK_MARK_HEIGHT, True);
837 loadPixmaps(scrPtr);
839 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
841 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
844 XColor bla;
845 Pixmap blank;
847 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
848 XSetForeground(display, scrPtr->monoGC, 0);
849 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
851 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
852 &bla, &bla, 0, 0);
853 XFreePixmap(display, blank);
856 #ifdef HAVE_XINTERNATOMS
857 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
858 atoms);
859 #else
860 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
861 atoms[i] = XInternAtom(display, atomNames[i], False);
863 #endif
865 i = 0;
866 scrPtr->attribsAtom = atoms[i++];
868 scrPtr->deleteWindowAtom = atoms[i++];
870 scrPtr->protocolsAtom = atoms[i++];
872 scrPtr->clipboardAtom = atoms[i++];
874 scrPtr->xdndAwareAtom = atoms[i++];
875 scrPtr->xdndSelectionAtom = atoms[i++];
876 scrPtr->xdndEnterAtom = atoms[i++];
877 scrPtr->xdndLeaveAtom = atoms[i++];
878 scrPtr->xdndPositionAtom = atoms[i++];
879 scrPtr->xdndDropAtom = atoms[i++];
880 scrPtr->xdndFinishedAtom = atoms[i++];
881 scrPtr->xdndTypeListAtom = atoms[i++];
882 scrPtr->xdndStatusAtom = atoms[i++];
884 scrPtr->xdndActionCopy = atoms[i++];
885 scrPtr->xdndActionMove = atoms[i++];
886 scrPtr->xdndActionLink = atoms[i++];
887 scrPtr->xdndActionAsk = atoms[i++];
888 scrPtr->xdndActionPrivate = atoms[i++];
890 scrPtr->wmIconDragOffsetAtom = atoms[i++];
892 scrPtr->wmStateAtom = atoms[i++];
894 scrPtr->rootView = W_CreateRootView(scrPtr);
896 scrPtr->balloon = W_CreateBalloon(scrPtr);
899 W_InitApplication(scrPtr);
901 return scrPtr;
906 void
907 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
909 WMReleaseFont(scr->normalFont);
910 scr->normalFont = WMRetainFont(font);
914 void
915 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
917 WMReleaseFont(scr->boldFont);
918 scr->boldFont = WMRetainFont(font);
923 void
924 WMHangData(WMWidget *widget, void *data)
926 W_VIEW(widget)->hangedData = data;
930 void*
931 WMGetHangedData(WMWidget *widget)
933 return W_VIEW(widget)->hangedData;
938 void
939 WMDestroyWidget(WMWidget *widget)
941 W_UnmapView(W_VIEW(widget));
942 W_DestroyView(W_VIEW(widget));
946 void
947 WMSetFocusToWidget(WMWidget *widget)
949 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
954 * WMRealizeWidget-
955 * Realizes the widget and all it's children.
958 void
959 WMRealizeWidget(WMWidget *w)
961 W_RealizeView(W_VIEW(w));
964 void
965 WMMapWidget(WMWidget *w)
967 W_MapView(W_VIEW(w));
971 void
972 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
974 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
978 static void
979 makeChildrenAutomap(W_View *view, int flag)
981 view = view->childrenList;
983 while (view) {
984 view->flags.mapWhenRealized = flag;
985 makeChildrenAutomap(view, flag);
987 view = view->nextSister;
992 void
993 WMMapSubwidgets(WMWidget *w)
995 /* make sure that subwidgets created after the parent was realized
996 * are mapped too */
997 if (!W_VIEW(w)->flags.realized) {
998 makeChildrenAutomap(W_VIEW(w), True);
999 } else {
1000 W_MapSubviews(W_VIEW(w));
1005 void
1006 WMUnmapSubwidgets(WMWidget *w)
1008 if (!W_VIEW(w)->flags.realized) {
1009 makeChildrenAutomap(W_VIEW(w), False);
1010 } else {
1011 W_UnmapSubviews(W_VIEW(w));
1017 void
1018 WMUnmapWidget(WMWidget *w)
1020 W_UnmapView(W_VIEW(w));
1024 Bool
1025 WMWidgetIsMapped(WMWidget *w)
1027 return W_VIEW(w)->flags.mapped;
1031 void
1032 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
1034 W_SetViewBackgroundColor(W_VIEW(w), color);
1035 if (W_VIEW(w)->flags.mapped)
1036 WMRedisplayWidget(w);
1040 void
1041 WMRaiseWidget(WMWidget *w)
1043 W_RaiseView(W_VIEW(w));
1047 void
1048 WMLowerWidget(WMWidget *w)
1050 W_LowerView(W_VIEW(w));
1054 void
1055 WMMoveWidget(WMWidget *w, int x, int y)
1057 W_MoveView(W_VIEW(w), x, y);
1061 void
1062 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
1064 W_ResizeView(W_VIEW(w), width, height);
1069 W_Class
1070 W_RegisterUserWidget(void)
1072 userWidgetCount++;
1074 return userWidgetCount + WC_UserWidget - 1;
1079 RContext*
1080 WMScreenRContext(WMScreen *scr)
1082 return scr->rcontext;
1087 unsigned int
1088 WMWidgetWidth(WMWidget *w)
1090 return W_VIEW(w)->size.width;
1094 unsigned int
1095 WMWidgetHeight(WMWidget *w)
1097 return W_VIEW(w)->size.height;
1101 Window
1102 WMWidgetXID(WMWidget *w)
1104 return W_VIEW(w)->window;
1108 WMScreen*
1109 WMWidgetScreen(WMWidget *w)
1111 return W_VIEW(w)->screen;
1116 void
1117 WMScreenMainLoop(WMScreen *scr)
1119 XEvent event;
1121 while (1) {
1122 WMNextEvent(scr->display, &event);
1123 WMHandleEvent(&event);
1128 void
1129 WMBreakModalLoop(WMScreen *scr)
1131 scr->modalLoop = 0;
1135 void
1136 WMRunModalLoop(WMScreen *scr, WMView *view)
1138 /* why is scr passed if is determined from the view? */
1139 /*WMScreen *scr = view->screen;*/
1140 int oldModalLoop = scr->modalLoop;
1141 WMView *oldModalView = scr->modalView;
1143 scr->modalView = view;
1145 scr->modalLoop = 1;
1146 while (scr->modalLoop) {
1147 XEvent event;
1149 WMNextEvent(scr->display, &event);
1150 WMHandleEvent(&event);
1153 scr->modalView = oldModalView;
1154 scr->modalLoop = oldModalLoop;
1158 Display*
1159 WMScreenDisplay(WMScreen *scr)
1161 return scr->display;
1165 int
1166 WMScreenDepth(WMScreen *scr)
1168 return scr->depth;
1172 unsigned int
1173 WMScreenWidth(WMScreen *scr)
1175 return scr->rootView->size.width;
1179 unsigned int
1180 WMScreenHeight(WMScreen *scr)
1182 return scr->rootView->size.height;
1186 void
1187 WMRedisplayWidget(WMWidget *w)
1189 W_RedisplayView(W_VIEW(w));