New Czech locales from Jiri Hnidek <Jiri.Hnidek@vslib.cz>
[wmaker-crm.git] / WINGs / widgets.c
blob9a613ced4f30fa02d419e660c11a70df9318f7f4
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);
622 /* create input method stuff */
623 W_InitIMStuff(scrPtr);
625 /* Create missing CUT_BUFFERs */
627 Atom *rootWinProps;
628 int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
629 int count;
631 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
632 for (i=0; i<count; i++) {
633 switch(rootWinProps[i]) {
634 case XA_CUT_BUFFER0:
635 exists[0] = 1; break;
636 case XA_CUT_BUFFER1:
637 exists[1] = 1; break;
638 case XA_CUT_BUFFER2:
639 exists[2] = 1; break;
640 case XA_CUT_BUFFER3:
641 exists[3] = 1; break;
642 case XA_CUT_BUFFER4:
643 exists[4] = 1; break;
644 case XA_CUT_BUFFER5:
645 exists[5] = 1; break;
646 case XA_CUT_BUFFER6:
647 exists[6] = 1; break;
648 case XA_CUT_BUFFER7:
649 exists[7] = 1; break;
650 default:
651 break;
654 if (rootWinProps) {
655 XFree(rootWinProps);
657 for (i=0; i<8; i++) {
658 if (!exists[i]) {
659 XStoreBuffer(display, "", 0, i);
664 scrPtr->ignoredModifierMask = 0;
666 int i;
667 XModifierKeymap *modmap;
668 KeyCode nlock, slock;
669 static int mask_table[8] = {
670 ShiftMask,LockMask,ControlMask,Mod1Mask,
671 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
673 unsigned int numLockMask, scrollLockMask;
675 nlock = XKeysymToKeycode(display, XK_Num_Lock);
676 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
679 * Find out the masks for the NumLock and ScrollLock modifiers,
680 * so that we can bind the grabs for when they are enabled too.
682 modmap = XGetModifierMapping(display);
684 if (modmap!=NULL && modmap->max_keypermod>0) {
685 for (i=0; i<8*modmap->max_keypermod; i++) {
686 if (modmap->modifiermap[i]==nlock && nlock!=0)
687 numLockMask = mask_table[i/modmap->max_keypermod];
688 else if (modmap->modifiermap[i]==slock && slock!=0)
689 scrollLockMask = mask_table[i/modmap->max_keypermod];
693 if (modmap)
694 XFreeModifiermap(modmap);
697 scrPtr->ignoredModifierMask = numLockMask|scrollLockMask|LockMask;
700 /* initially allocate some colors */
701 WMWhiteColor(scrPtr);
702 WMBlackColor(scrPtr);
703 WMGrayColor(scrPtr);
704 WMDarkGrayColor(scrPtr);
706 gcv.graphics_exposures = False;
708 gcv.function = GXxor;
709 gcv.foreground = W_PIXEL(scrPtr->white);
710 if (gcv.foreground == 0) gcv.foreground = 1;
711 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
712 |GCGraphicsExposures|GCForeground, &gcv);
714 gcv.function = GXxor;
715 gcv.foreground = W_PIXEL(scrPtr->gray);
716 gcv.subwindow_mode = IncludeInferiors;
717 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
718 |GCGraphicsExposures|GCForeground
719 |GCSubwindowMode, &gcv);
721 gcv.function = GXcopy;
722 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
723 |GCGraphicsExposures, &gcv);
725 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
726 |GCGraphicsExposures, &gcv);
729 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
730 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
731 gcv.foreground = W_PIXEL(scrPtr->darkGray);
732 gcv.background = W_PIXEL(scrPtr->gray);
733 gcv.fill_style = FillStippled;
734 gcv.stipple = stipple;
735 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
736 GCForeground|GCBackground|GCStipple
737 |GCFillStyle|GCGraphicsExposures, &gcv);
739 gcv.foreground = W_PIXEL(scrPtr->black);
740 gcv.background = W_PIXEL(scrPtr->white);
741 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
742 GCForeground|GCBackground, &gcv);
744 /* we need a 1bpp drawable for the monoGC, so borrow this one */
745 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
747 scrPtr->stipple = stipple;
749 scrPtr->useMultiByte = WINGsConfiguration.useMultiByte;
751 scrPtr->normalFont = WMSystemFontOfSize(scrPtr,
752 WINGsConfiguration.defaultFontSize);
754 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr,
755 WINGsConfiguration.defaultFontSize);
757 if (!scrPtr->boldFont)
758 scrPtr->boldFont = scrPtr->normalFont;
760 if (!scrPtr->normalFont) {
761 wwarning(_("could not load any fonts. Make sure your font installation"
762 "and locale settings are correct."));
764 return NULL;
767 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
768 CHECK_BUTTON_ON_WIDTH,
769 CHECK_BUTTON_ON_HEIGHT, False);
771 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
772 CHECK_BUTTON_OFF_WIDTH,
773 CHECK_BUTTON_OFF_HEIGHT, False);
775 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
776 RADIO_BUTTON_ON_WIDTH,
777 RADIO_BUTTON_ON_HEIGHT, False);
779 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
780 RADIO_BUTTON_OFF_WIDTH,
781 RADIO_BUTTON_OFF_HEIGHT, False);
783 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
784 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
785 False);
787 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
788 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
789 False);
792 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
793 SCROLLER_DIMPLE_WIDTH,
794 SCROLLER_DIMPLE_HEIGHT, False);
797 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
798 SCROLLER_ARROW_UP_WIDTH,
799 SCROLLER_ARROW_UP_HEIGHT, True);
801 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
802 SCROLLER_ARROW_DOWN_WIDTH,
803 SCROLLER_ARROW_DOWN_HEIGHT, True);
805 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
806 SCROLLER_ARROW_LEFT_WIDTH,
807 SCROLLER_ARROW_LEFT_HEIGHT, True);
809 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
810 SCROLLER_ARROW_RIGHT_WIDTH,
811 SCROLLER_ARROW_RIGHT_HEIGHT, True);
813 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
814 SCROLLER_ARROW_UP_WIDTH,
815 SCROLLER_ARROW_UP_HEIGHT, True);
817 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
818 SCROLLER_ARROW_DOWN_WIDTH,
819 SCROLLER_ARROW_DOWN_HEIGHT, True);
821 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
822 SCROLLER_ARROW_LEFT_WIDTH,
823 SCROLLER_ARROW_LEFT_HEIGHT, True);
825 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
826 SCROLLER_ARROW_RIGHT_WIDTH,
827 SCROLLER_ARROW_RIGHT_HEIGHT, True);
829 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
830 POPUP_INDICATOR_WIDTH,
831 POPUP_INDICATOR_HEIGHT, True);
833 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
834 PULLDOWN_INDICATOR_WIDTH,
835 PULLDOWN_INDICATOR_HEIGHT, True);
837 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
838 CHECK_MARK_WIDTH,
839 CHECK_MARK_HEIGHT, True);
841 loadPixmaps(scrPtr);
843 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
845 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
848 XColor bla;
849 Pixmap blank;
851 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
852 XSetForeground(display, scrPtr->monoGC, 0);
853 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
855 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
856 &bla, &bla, 0, 0);
857 XFreePixmap(display, blank);
860 #ifdef HAVE_XINTERNATOMS
861 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
862 atoms);
863 #else
864 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
865 atoms[i] = XInternAtom(display, atomNames[i], False);
867 #endif
869 i = 0;
870 scrPtr->attribsAtom = atoms[i++];
872 scrPtr->deleteWindowAtom = atoms[i++];
874 scrPtr->protocolsAtom = atoms[i++];
876 scrPtr->clipboardAtom = atoms[i++];
878 scrPtr->xdndAwareAtom = atoms[i++];
879 scrPtr->xdndSelectionAtom = atoms[i++];
880 scrPtr->xdndEnterAtom = atoms[i++];
881 scrPtr->xdndLeaveAtom = atoms[i++];
882 scrPtr->xdndPositionAtom = atoms[i++];
883 scrPtr->xdndDropAtom = atoms[i++];
884 scrPtr->xdndFinishedAtom = atoms[i++];
885 scrPtr->xdndTypeListAtom = atoms[i++];
886 scrPtr->xdndStatusAtom = atoms[i++];
888 scrPtr->xdndActionCopy = atoms[i++];
889 scrPtr->xdndActionMove = atoms[i++];
890 scrPtr->xdndActionLink = atoms[i++];
891 scrPtr->xdndActionAsk = atoms[i++];
892 scrPtr->xdndActionPrivate = atoms[i++];
894 scrPtr->wmIconDragOffsetAtom = atoms[i++];
896 scrPtr->wmStateAtom = atoms[i++];
898 scrPtr->rootView = W_CreateRootView(scrPtr);
900 scrPtr->balloon = W_CreateBalloon(scrPtr);
903 W_InitApplication(scrPtr);
905 return scrPtr;
910 void
911 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
913 WMReleaseFont(scr->normalFont);
914 scr->normalFont = WMRetainFont(font);
918 void
919 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
921 WMReleaseFont(scr->boldFont);
922 scr->boldFont = WMRetainFont(font);
927 void
928 WMHangData(WMWidget *widget, void *data)
930 W_VIEW(widget)->hangedData = data;
934 void*
935 WMGetHangedData(WMWidget *widget)
937 return W_VIEW(widget)->hangedData;
942 void
943 WMDestroyWidget(WMWidget *widget)
945 W_UnmapView(W_VIEW(widget));
946 W_DestroyView(W_VIEW(widget));
950 void
951 WMSetFocusToWidget(WMWidget *widget)
953 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
958 * WMRealizeWidget-
959 * Realizes the widget and all it's children.
962 void
963 WMRealizeWidget(WMWidget *w)
965 W_RealizeView(W_VIEW(w));
968 void
969 WMMapWidget(WMWidget *w)
971 W_MapView(W_VIEW(w));
975 void
976 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
978 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
982 static void
983 makeChildrenAutomap(W_View *view, int flag)
985 view = view->childrenList;
987 while (view) {
988 view->flags.mapWhenRealized = flag;
989 makeChildrenAutomap(view, flag);
991 view = view->nextSister;
996 void
997 WMMapSubwidgets(WMWidget *w)
999 /* make sure that subwidgets created after the parent was realized
1000 * are mapped too */
1001 if (!W_VIEW(w)->flags.realized) {
1002 makeChildrenAutomap(W_VIEW(w), True);
1003 } else {
1004 W_MapSubviews(W_VIEW(w));
1009 void
1010 WMUnmapSubwidgets(WMWidget *w)
1012 if (!W_VIEW(w)->flags.realized) {
1013 makeChildrenAutomap(W_VIEW(w), False);
1014 } else {
1015 W_UnmapSubviews(W_VIEW(w));
1021 void
1022 WMUnmapWidget(WMWidget *w)
1024 W_UnmapView(W_VIEW(w));
1028 Bool
1029 WMWidgetIsMapped(WMWidget *w)
1031 return W_VIEW(w)->flags.mapped;
1035 void
1036 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
1038 W_SetViewBackgroundColor(W_VIEW(w), color);
1039 if (W_VIEW(w)->flags.mapped)
1040 WMRedisplayWidget(w);
1044 void
1045 WMRaiseWidget(WMWidget *w)
1047 W_RaiseView(W_VIEW(w));
1051 void
1052 WMLowerWidget(WMWidget *w)
1054 W_LowerView(W_VIEW(w));
1058 void
1059 WMMoveWidget(WMWidget *w, int x, int y)
1061 W_MoveView(W_VIEW(w), x, y);
1065 void
1066 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
1068 W_ResizeView(W_VIEW(w), width, height);
1073 W_Class
1074 W_RegisterUserWidget(void)
1076 userWidgetCount++;
1078 return userWidgetCount + WC_UserWidget - 1;
1083 RContext*
1084 WMScreenRContext(WMScreen *scr)
1086 return scr->rcontext;
1091 unsigned int
1092 WMWidgetWidth(WMWidget *w)
1094 return W_VIEW(w)->size.width;
1098 unsigned int
1099 WMWidgetHeight(WMWidget *w)
1101 return W_VIEW(w)->size.height;
1105 Window
1106 WMWidgetXID(WMWidget *w)
1108 return W_VIEW(w)->window;
1112 WMScreen*
1113 WMWidgetScreen(WMWidget *w)
1115 return W_VIEW(w)->screen;
1120 void
1121 WMScreenMainLoop(WMScreen *scr)
1123 XEvent event;
1125 while (1) {
1126 WMNextEvent(scr->display, &event);
1127 WMHandleEvent(&event);
1132 void
1133 WMBreakModalLoop(WMScreen *scr)
1135 scr->modalLoop = 0;
1139 void
1140 WMRunModalLoop(WMScreen *scr, WMView *view)
1142 /* why is scr passed if is determined from the view? */
1143 /*WMScreen *scr = view->screen;*/
1144 int oldModalLoop = scr->modalLoop;
1145 WMView *oldModalView = scr->modalView;
1147 scr->modalView = view;
1149 scr->modalLoop = 1;
1150 while (scr->modalLoop) {
1151 XEvent event;
1153 WMNextEvent(scr->display, &event);
1154 WMHandleEvent(&event);
1157 scr->modalView = oldModalView;
1158 scr->modalLoop = oldModalLoop;
1162 Display*
1163 WMScreenDisplay(WMScreen *scr)
1165 return scr->display;
1169 int
1170 WMScreenDepth(WMScreen *scr)
1172 return scr->depth;
1176 unsigned int
1177 WMScreenWidth(WMScreen *scr)
1179 return scr->rootView->size.width;
1183 unsigned int
1184 WMScreenHeight(WMScreen *scr)
1186 return scr->rootView->size.height;
1190 void
1191 WMRedisplayWidget(WMWidget *w)
1193 W_RedisplayView(W_VIEW(w));