- Removed obsoleted options from WMGLOBAL and from the WINGs internal
[wmaker-crm.git] / WINGs / widgets.c
blobac89ce0840b75964da199428c0a138633f2d53b6
3 #include "WINGsP.h"
4 #include "wconfig.h"
6 #include <X11/Xft/Xft.h>
8 #include <X11/Xutil.h>
9 #include <X11/Xatom.h>
10 #include <X11/keysym.h>
11 #include <X11/cursorfont.h>
13 #include <X11/Xlocale.h>
15 /********** data ************/
18 #define CHECK_BUTTON_ON_WIDTH 16
19 #define CHECK_BUTTON_ON_HEIGHT 16
21 static char *CHECK_BUTTON_ON[] = {
22 " %",
23 " .............%#",
24 " ........... .%#",
25 " .......... #.%#",
26 " ......... #%.%#",
27 " ........ #%..%#",
28 " ... #.. #%...%#",
29 " ... #% #%....%#",
30 " ... % #%.....%#",
31 " ... #%......%#",
32 " ... #%.......%#",
33 " ...#%........%#",
34 " .............%#",
35 " .............%#",
36 " %%%%%%%%%%%%%%#",
37 "%###############"};
39 #define CHECK_BUTTON_OFF_WIDTH 16
40 #define CHECK_BUTTON_OFF_HEIGHT 16
42 static char *CHECK_BUTTON_OFF[] = {
43 " %",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " .............%#",
53 " .............%#",
54 " .............%#",
55 " .............%#",
56 " .............%#",
57 " %%%%%%%%%%%%%%#",
58 "%###############"};
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 "..... .....",
101 static char *BUTTON_ARROW[] = {
102 "..................",
103 "....##....#### ...",
104 "...#.%....#... ...",
105 "..#..%#####... ...",
106 ".#............ ...",
107 "#............. ...",
108 ".#............ ...",
109 "..#.. ...",
110 "...#. ............",
111 "....# ............"
114 #define BUTTON_ARROW_WIDTH 18
115 #define BUTTON_ARROW_HEIGHT 10
118 static char *BUTTON_ARROW2[] = {
119 " ",
120 " ## ####. ",
121 " # % # . ",
122 " # %##### . ",
123 " # . ",
124 "# . ",
125 " # . ",
126 " # .......... ",
127 " # . ",
128 " #. "
131 #define BUTTON_ARROW2_WIDTH 18
132 #define BUTTON_ARROW2_HEIGHT 10
135 static char *SCROLLER_DIMPLE[] = {
136 ".%###.",
137 "%#%%%%",
138 "#%%...",
139 "#%.. ",
140 "#%. ",
141 ".%. ."
144 #define SCROLLER_DIMPLE_WIDTH 6
145 #define SCROLLER_DIMPLE_HEIGHT 6
148 static char *SCROLLER_ARROW_UP[] = {
149 "....%....",
150 "....#....",
151 "...%#%...",
152 "...###...",
153 "..%###%..",
154 "..#####..",
155 ".%#####%.",
156 ".#######.",
157 "%#######%"
160 static char *HI_SCROLLER_ARROW_UP[] = {
161 " % ",
162 " % ",
163 " %%% ",
164 " %%% ",
165 " %%%%% ",
166 " %%%%% ",
167 " %%%%%%% ",
168 " %%%%%%% ",
169 "%%%%%%%%%"
172 #define SCROLLER_ARROW_UP_WIDTH 9
173 #define SCROLLER_ARROW_UP_HEIGHT 9
176 static char *SCROLLER_ARROW_DOWN[] = {
177 "%#######%",
178 ".#######.",
179 ".%#####%.",
180 "..#####..",
181 "..%###%..",
182 "...###...",
183 "...%#%...",
184 "....#....",
185 "....%...."
188 static char *HI_SCROLLER_ARROW_DOWN[] = {
189 "%%%%%%%%%",
190 " %%%%%%% ",
191 " %%%%%%% ",
192 " %%%%% ",
193 " %%%%% ",
194 " %%% ",
195 " %%% ",
196 " % ",
197 " % "
200 #define SCROLLER_ARROW_DOWN_WIDTH 9
201 #define SCROLLER_ARROW_DOWN_HEIGHT 9
205 static char *SCROLLER_ARROW_LEFT[] = {
206 "........%",
207 "......%##",
208 "....%####",
209 "..%######",
210 "%########",
211 "..%######",
212 "....%####",
213 "......%##",
214 "........%"
217 static char *HI_SCROLLER_ARROW_LEFT[] = {
218 " %",
219 " %%%",
220 " %%%%%",
221 " %%%%%%%",
222 "%%%%%%%%%",
223 " %%%%%%%",
224 " %%%%%",
225 " %%%",
226 " %"
229 #define SCROLLER_ARROW_LEFT_WIDTH 9
230 #define SCROLLER_ARROW_LEFT_HEIGHT 9
233 static char *SCROLLER_ARROW_RIGHT[] = {
234 "%........",
235 "##%......",
236 "####%....",
237 "######%..",
238 "########%",
239 "######%..",
240 "####%....",
241 "##%......",
242 "%........"
245 static char *HI_SCROLLER_ARROW_RIGHT[] = {
246 "% ",
247 "%%% ",
248 "%%%%% ",
249 "%%%%%%% ",
250 "%%%%%%%%%",
251 "%%%%%%% ",
252 "%%%%% ",
253 "%%% ",
254 "% "
257 #define SCROLLER_ARROW_RIGHT_WIDTH 9
258 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
261 static char *POPUP_INDICATOR[] = {
262 " #==",
263 " ......%#==",
264 " ......%#%%",
265 " ......%#%%",
266 " %%%%%%%#%%",
267 "#########%%",
268 "==%%%%%%%%%",
269 "==%%%%%%%%%"
272 #define POPUP_INDICATOR_WIDTH 11
273 #define POPUP_INDICATOR_HEIGHT 8
277 static char *PULLDOWN_INDICATOR[] = {
278 "=#######=",
279 "=%===== =",
280 "==%=== ==",
281 "==%=== ==",
282 "===%= ===",
283 "===%= ===",
284 "====%===="
286 #define PULLDOWN_INDICATOR_WIDTH 9
287 #define PULLDOWN_INDICATOR_HEIGHT 7
290 #define CHECK_MARK_WIDTH 8
291 #define CHECK_MARK_HEIGHT 10
293 static char *CHECK_MARK[] = {
294 "======== ",
295 "======= #",
296 "====== #%",
297 "===== #%=",
298 " #== #%==",
299 " #% #%===",
300 " % #%====",
301 " #%=====",
302 " #%======",
303 "#%======="};
306 #define STIPPLE_WIDTH 8
307 #define STIPPLE_HEIGHT 8
308 static unsigned char STIPPLE_BITS[] = {
309 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
315 extern void W_ReadConfigurations(void);
318 static int userWidgetCount=0;
321 /***** end data ******/
324 static void
325 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
326 int width, int height)
328 int x, y;
329 GC whiteGC = WMColorGC(screen->white);
330 GC blackGC = WMColorGC(screen->black);
331 GC lightGC = WMColorGC(screen->gray);
332 GC darkGC = WMColorGC(screen->darkGray);
335 if (mask)
336 XSetForeground(screen->display, screen->monoGC, 0);
338 for (y = 0; y < height; y++) {
339 for (x = 0; x < width; x++) {
340 switch (data[y][x]) {
341 case ' ':
342 case 'w':
343 XDrawPoint(screen->display, d, whiteGC, x, y);
344 break;
346 case '=':
347 if (mask)
348 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
350 case '.':
351 case 'l':
352 XDrawPoint(screen->display, d, lightGC, x, y);
353 break;
355 case '%':
356 case 'd':
357 XDrawPoint(screen->display, d, darkGC, x, y);
358 break;
360 case '#':
361 case 'b':
362 default:
363 XDrawPoint(screen->display, d, blackGC, x, y);
364 break;
372 static WMPixmap*
373 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
375 Pixmap pixmap, mask = None;
377 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
378 sPtr->depth);
380 if (masked) {
381 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
382 XSetForeground(sPtr->display, sPtr->monoGC, 1);
383 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
386 renderPixmap(sPtr, pixmap, mask, data, width, height);
388 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
389 sPtr->depth);
393 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
394 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
396 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
397 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
400 static Bool
401 loadPixmaps(WMScreen *scr)
403 RImage *image, *tmp;
404 RColor gray;
405 RColor white;
407 gray.red = 0xae;
408 gray.green = 0xaa;
409 gray.blue = 0xae;
411 white.red = 0xff;
412 white.green = 0xff;
413 white.blue = 0xff;
415 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
416 if (!image)
417 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
418 if (!image) {
419 wwarning(_("WINGs: could not load widget images file: %s"),
420 RMessageForError(RErrorCode));
421 return False;
423 /* home icon */
424 /* make it have a gray background */
425 tmp = RGetSubImage(image, 0, 0, 24, 24);
426 RCombineImageWithColor(tmp, &gray);
427 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
428 RReleaseImage(tmp);
429 /* make it have a white background */
430 tmp = RGetSubImage(image, 0, 0, 24, 24);
431 RCombineImageWithColor(tmp, &white);
432 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
433 RReleaseImage(tmp);
435 /* trash can */
436 tmp = RGetSubImage(image, 104, 0, 24, 24);
437 RCombineImageWithColor(tmp, &white);
438 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
439 RReleaseImage(tmp);
440 tmp = RGetSubImage(image, 104, 0, 24, 24);
441 RCombineImageWithColor(tmp, &white);
442 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
443 RReleaseImage(tmp);
444 /* create dir */
445 tmp = RGetSubImage(image, 104, 24, 24, 24);
446 RCombineImageWithColor(tmp, &white);
447 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
448 RReleaseImage(tmp);
449 tmp = RGetSubImage(image, 104, 24, 24, 24);
450 RCombineImageWithColor(tmp, &white);
451 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
452 RReleaseImage(tmp);
453 /* diskettes */
454 tmp = RGetSubImage(image, 24, 80, 24, 24);
455 RCombineImageWithColor(tmp, &white);
456 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
457 RReleaseImage(tmp);
458 tmp = RGetSubImage(image, 24, 80, 24, 24);
459 RCombineImageWithColor(tmp, &white);
460 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
461 RReleaseImage(tmp);
462 /* unmount */
463 tmp = RGetSubImage(image, 0, 80, 24, 24);
464 RCombineImageWithColor(tmp, &white);
465 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
466 RReleaseImage(tmp);
467 tmp = RGetSubImage(image, 0, 80, 24, 24);
468 RCombineImageWithColor(tmp, &white);
469 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
470 RReleaseImage(tmp);
472 /* Magnifying Glass Icon for ColorPanel */
473 tmp = RGetSubImage(image, 24, 0, 40, 32);
474 RCombineImageWithColor(tmp, &gray);
475 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
476 RReleaseImage(tmp);
477 /* ColorWheel Icon for ColorPanel */
478 tmp = RGetSubImage(image, 0, 25, 24, 24);
479 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
480 RReleaseImage(tmp);
481 /* GrayScale Icon for ColorPanel */
482 tmp = RGetSubImage(image, 65, 0, 40, 24);
483 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
484 RReleaseImage(tmp);
485 /* RGB Icon for ColorPanel */
486 tmp = RGetSubImage(image, 25, 33, 40, 24);
487 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
488 RReleaseImage(tmp);
489 /* CMYK Icon for ColorPanel */
490 tmp = RGetSubImage(image, 65, 25, 40, 24);
491 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
492 RReleaseImage(tmp);
493 /* HSB Icon for ColorPanel */
494 tmp = RGetSubImage(image, 0, 57, 40, 24);
495 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
496 RReleaseImage(tmp);
497 /* CustomColorPalette Icon for ColorPanel */
498 tmp = RGetSubImage(image, 81, 57, 40, 24);
499 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
500 RReleaseImage(tmp);
501 /* ColorList Icon for ColorPanel */
502 tmp = RGetSubImage(image, 41, 57, 40, 24);
503 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
504 RReleaseImage(tmp);
506 RReleaseImage(image);
508 #if 0
509 scr->defaultObjectIcon =
510 WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
511 if (!scr->defaultObjectIcon) {
512 scr->defaultObjectIcon =
513 WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
515 if (!scr->defaultObjectIcon) {
516 wwarning("WINGs: could not load default icon file");
517 return False;
519 #endif
520 return True;
524 WMScreen*
525 WMOpenScreen(const char *display)
527 Display *dpy = XOpenDisplay(display);
529 if (!dpy) {
530 wwarning("WINGs: could not open display %s",
531 XDisplayName(display));
532 return NULL;
535 return WMCreateSimpleApplicationScreen(dpy);
539 WMScreen*
540 WMCreateSimpleApplicationScreen(Display *display)
542 WMScreen *scr;
544 scr = WMCreateScreen(display, DefaultScreen(display));
546 scr->aflags.hasAppIcon = 0;
547 scr->aflags.simpleApplication = 1;
549 return scr;
554 WMScreen*
555 WMCreateScreen(Display *display, int screen)
557 return WMCreateScreenWithRContext(display, screen,
558 RCreateContext(display, screen, NULL));
562 WMScreen*
563 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
565 W_Screen *scrPtr;
566 XGCValues gcv;
567 Pixmap stipple;
568 static int initialized = 0;
569 static char *atomNames[] = {
570 "_GNUSTEP_WM_ATTR",
571 "WM_DELETE_WINDOW",
572 "WM_PROTOCOLS",
573 "CLIPBOARD",
574 "XdndAware",
575 "XdndSelection",
576 "XdndEnter",
577 "XdndLeave",
578 "XdndPosition",
579 "XdndDrop",
580 "XdndFinished",
581 "XdndTypeList",
582 "XdndActionList",
583 "XdndActionDescription",
584 "XdndStatus",
585 "XdndActionCopy",
586 "XdndActionMove",
587 "XdndActionLink",
588 "XdndActionAsk",
589 "XdndActionPrivate",
590 "_WINGS_DND_MOUSE_OFFSET",
591 "WM_STATE"
593 Atom atoms[sizeof(atomNames)/sizeof(char*)];
594 int i;
596 if (!initialized) {
598 initialized = 1;
600 W_ReadConfigurations();
602 assert(W_ApplicationInitialized());
605 scrPtr = malloc(sizeof(W_Screen));
606 if (!scrPtr)
607 return NULL;
608 memset(scrPtr, 0, sizeof(W_Screen));
610 scrPtr->aflags.hasAppIcon = 1;
612 scrPtr->display = display;
613 scrPtr->screen = screen;
614 scrPtr->rcontext = context;
616 scrPtr->depth = context->depth;
618 scrPtr->visual = context->visual;
619 scrPtr->lastEventTime = 0;
621 scrPtr->colormap = context->cmap;
623 scrPtr->rootWin = RootWindow(display, screen);
625 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
627 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr),
628 scrPtr->visual, scrPtr->colormap);
630 /* create input method stuff */
631 W_InitIMStuff(scrPtr);
633 /* Create missing CUT_BUFFERs */
635 Atom *rootWinProps;
636 int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
637 int count;
639 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
640 for (i=0; i<count; i++) {
641 switch(rootWinProps[i]) {
642 case XA_CUT_BUFFER0:
643 exists[0] = 1; break;
644 case XA_CUT_BUFFER1:
645 exists[1] = 1; break;
646 case XA_CUT_BUFFER2:
647 exists[2] = 1; break;
648 case XA_CUT_BUFFER3:
649 exists[3] = 1; break;
650 case XA_CUT_BUFFER4:
651 exists[4] = 1; break;
652 case XA_CUT_BUFFER5:
653 exists[5] = 1; break;
654 case XA_CUT_BUFFER6:
655 exists[6] = 1; break;
656 case XA_CUT_BUFFER7:
657 exists[7] = 1; break;
658 default:
659 break;
662 if (rootWinProps) {
663 XFree(rootWinProps);
665 for (i=0; i<8; i++) {
666 if (!exists[i]) {
667 XStoreBuffer(display, "", 0, i);
672 scrPtr->ignoredModifierMask = 0;
674 int i;
675 XModifierKeymap *modmap;
676 KeyCode nlock, slock;
677 static int mask_table[8] = {
678 ShiftMask,LockMask,ControlMask,Mod1Mask,
679 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
681 unsigned int numLockMask=0, scrollLockMask=0;
683 nlock = XKeysymToKeycode(display, XK_Num_Lock);
684 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
687 * Find out the masks for the NumLock and ScrollLock modifiers,
688 * so that we can bind the grabs for when they are enabled too.
690 modmap = XGetModifierMapping(display);
692 if (modmap!=NULL && modmap->max_keypermod>0) {
693 for (i=0; i<8*modmap->max_keypermod; i++) {
694 if (modmap->modifiermap[i]==nlock && nlock!=0)
695 numLockMask = mask_table[i/modmap->max_keypermod];
696 else if (modmap->modifiermap[i]==slock && slock!=0)
697 scrollLockMask = mask_table[i/modmap->max_keypermod];
701 if (modmap)
702 XFreeModifiermap(modmap);
705 scrPtr->ignoredModifierMask = numLockMask|scrollLockMask|LockMask;
708 /* initially allocate some colors */
709 WMWhiteColor(scrPtr);
710 WMBlackColor(scrPtr);
711 WMGrayColor(scrPtr);
712 WMDarkGrayColor(scrPtr);
714 gcv.graphics_exposures = False;
716 gcv.function = GXxor;
717 gcv.foreground = W_PIXEL(scrPtr->white);
718 if (gcv.foreground == 0) gcv.foreground = 1;
719 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
720 |GCGraphicsExposures|GCForeground, &gcv);
722 gcv.function = GXxor;
723 gcv.foreground = W_PIXEL(scrPtr->gray);
724 gcv.subwindow_mode = IncludeInferiors;
725 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
726 |GCGraphicsExposures|GCForeground
727 |GCSubwindowMode, &gcv);
729 gcv.function = GXcopy;
730 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
731 |GCGraphicsExposures, &gcv);
733 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
734 |GCGraphicsExposures, &gcv);
736 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
737 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
738 gcv.foreground = W_PIXEL(scrPtr->darkGray);
739 gcv.background = W_PIXEL(scrPtr->gray);
740 gcv.fill_style = FillStippled;
741 gcv.stipple = stipple;
742 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
743 GCForeground|GCBackground|GCStipple
744 |GCFillStyle|GCGraphicsExposures, &gcv);
746 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr),
747 GCGraphicsExposures, &gcv);
748 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr),
749 GCGraphicsExposures, &gcv);
751 /* we need a 1bpp drawable for the monoGC, so borrow this one */
752 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
754 scrPtr->stipple = stipple;
756 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
758 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
760 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
762 if (!scrPtr->boldFont)
763 scrPtr->boldFont = scrPtr->normalFont;
765 if (!scrPtr->normalFont) {
766 wwarning(_("could not load any fonts. Make sure your font installation"
767 " and locale settings are correct."));
769 return NULL;
772 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
773 CHECK_BUTTON_ON_WIDTH,
774 CHECK_BUTTON_ON_HEIGHT, False);
776 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
777 CHECK_BUTTON_OFF_WIDTH,
778 CHECK_BUTTON_OFF_HEIGHT, False);
780 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
781 RADIO_BUTTON_ON_WIDTH,
782 RADIO_BUTTON_ON_HEIGHT, False);
784 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
785 RADIO_BUTTON_OFF_WIDTH,
786 RADIO_BUTTON_OFF_HEIGHT, False);
788 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
789 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
790 False);
792 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
793 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
794 False);
797 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
798 SCROLLER_DIMPLE_WIDTH,
799 SCROLLER_DIMPLE_HEIGHT, False);
802 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
803 SCROLLER_ARROW_UP_WIDTH,
804 SCROLLER_ARROW_UP_HEIGHT, True);
806 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
807 SCROLLER_ARROW_DOWN_WIDTH,
808 SCROLLER_ARROW_DOWN_HEIGHT, True);
810 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
811 SCROLLER_ARROW_LEFT_WIDTH,
812 SCROLLER_ARROW_LEFT_HEIGHT, True);
814 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
815 SCROLLER_ARROW_RIGHT_WIDTH,
816 SCROLLER_ARROW_RIGHT_HEIGHT, True);
818 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
819 SCROLLER_ARROW_UP_WIDTH,
820 SCROLLER_ARROW_UP_HEIGHT, True);
822 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
823 SCROLLER_ARROW_DOWN_WIDTH,
824 SCROLLER_ARROW_DOWN_HEIGHT, True);
826 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
827 SCROLLER_ARROW_LEFT_WIDTH,
828 SCROLLER_ARROW_LEFT_HEIGHT, True);
830 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
831 SCROLLER_ARROW_RIGHT_WIDTH,
832 SCROLLER_ARROW_RIGHT_HEIGHT, True);
834 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
835 POPUP_INDICATOR_WIDTH,
836 POPUP_INDICATOR_HEIGHT, True);
838 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
839 PULLDOWN_INDICATOR_WIDTH,
840 PULLDOWN_INDICATOR_HEIGHT, True);
842 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
843 CHECK_MARK_WIDTH,
844 CHECK_MARK_HEIGHT, True);
846 loadPixmaps(scrPtr);
848 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
850 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
853 XColor bla;
854 Pixmap blank;
856 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
857 XSetForeground(display, scrPtr->monoGC, 0);
858 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
860 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
861 &bla, &bla, 0, 0);
862 XFreePixmap(display, blank);
865 #ifdef HAVE_XINTERNATOMS
866 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
867 atoms);
868 #else
869 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
870 atoms[i] = XInternAtom(display, atomNames[i], False);
872 #endif
874 i = 0;
875 scrPtr->attribsAtom = atoms[i++];
877 scrPtr->deleteWindowAtom = atoms[i++];
879 scrPtr->protocolsAtom = atoms[i++];
881 scrPtr->clipboardAtom = atoms[i++];
883 scrPtr->xdndAwareAtom = atoms[i++];
884 scrPtr->xdndSelectionAtom = atoms[i++];
885 scrPtr->xdndEnterAtom = atoms[i++];
886 scrPtr->xdndLeaveAtom = atoms[i++];
887 scrPtr->xdndPositionAtom = atoms[i++];
888 scrPtr->xdndDropAtom = atoms[i++];
889 scrPtr->xdndFinishedAtom = atoms[i++];
890 scrPtr->xdndTypeListAtom = atoms[i++];
891 scrPtr->xdndActionListAtom = atoms[i++];
892 scrPtr->xdndActionDescriptionAtom = atoms[i++];
893 scrPtr->xdndStatusAtom = atoms[i++];
895 scrPtr->xdndActionCopy = atoms[i++];
896 scrPtr->xdndActionMove = atoms[i++];
897 scrPtr->xdndActionLink = atoms[i++];
898 scrPtr->xdndActionAsk = atoms[i++];
899 scrPtr->xdndActionPrivate = atoms[i++];
901 scrPtr->wmIconDragOffsetAtom = atoms[i++];
903 scrPtr->wmStateAtom = atoms[i++];
905 scrPtr->rootView = W_CreateRootView(scrPtr);
907 scrPtr->balloon = W_CreateBalloon(scrPtr);
910 W_InitApplication(scrPtr);
912 return scrPtr;
917 void
918 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
920 WMReleaseFont(scr->normalFont);
921 scr->normalFont = WMRetainFont(font);
925 void
926 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
928 WMReleaseFont(scr->boldFont);
929 scr->boldFont = WMRetainFont(font);
934 void
935 WMHangData(WMWidget *widget, void *data)
937 W_VIEW(widget)->hangedData = data;
941 void*
942 WMGetHangedData(WMWidget *widget)
944 return W_VIEW(widget)->hangedData;
949 void
950 WMDestroyWidget(WMWidget *widget)
952 W_UnmapView(W_VIEW(widget));
953 W_DestroyView(W_VIEW(widget));
957 void
958 WMSetFocusToWidget(WMWidget *widget)
960 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
965 * WMRealizeWidget-
966 * Realizes the widget and all it's children.
969 void
970 WMRealizeWidget(WMWidget *w)
972 W_RealizeView(W_VIEW(w));
975 void
976 WMMapWidget(WMWidget *w)
978 W_MapView(W_VIEW(w));
982 void
983 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
985 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
989 static void
990 makeChildrenAutomap(W_View *view, int flag)
992 view = view->childrenList;
994 while (view) {
995 view->flags.mapWhenRealized = flag;
996 makeChildrenAutomap(view, flag);
998 view = view->nextSister;
1003 void
1004 WMMapSubwidgets(WMWidget *w)
1006 /* make sure that subwidgets created after the parent was realized
1007 * are mapped too */
1008 if (!W_VIEW(w)->flags.realized) {
1009 makeChildrenAutomap(W_VIEW(w), True);
1010 } else {
1011 W_MapSubviews(W_VIEW(w));
1016 void
1017 WMUnmapSubwidgets(WMWidget *w)
1019 if (!W_VIEW(w)->flags.realized) {
1020 makeChildrenAutomap(W_VIEW(w), False);
1021 } else {
1022 W_UnmapSubviews(W_VIEW(w));
1028 void
1029 WMUnmapWidget(WMWidget *w)
1031 W_UnmapView(W_VIEW(w));
1035 Bool
1036 WMWidgetIsMapped(WMWidget *w)
1038 return W_VIEW(w)->flags.mapped;
1042 void
1043 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
1045 W_SetViewBackgroundColor(W_VIEW(w), color);
1046 if (W_VIEW(w)->flags.mapped)
1047 WMRedisplayWidget(w);
1051 WMColor*
1052 WMGetWidgetBackgroundColor(WMWidget *w)
1054 return W_VIEW(w)->backColor;
1058 void
1059 WMRaiseWidget(WMWidget *w)
1061 W_RaiseView(W_VIEW(w));
1065 void
1066 WMLowerWidget(WMWidget *w)
1068 W_LowerView(W_VIEW(w));
1072 void
1073 WMMoveWidget(WMWidget *w, int x, int y)
1075 W_MoveView(W_VIEW(w), x, y);
1079 void
1080 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
1082 W_ResizeView(W_VIEW(w), width, height);
1087 W_Class
1088 W_RegisterUserWidget(void)
1090 userWidgetCount++;
1092 return userWidgetCount + WC_UserWidget - 1;
1097 RContext*
1098 WMScreenRContext(WMScreen *scr)
1100 return scr->rcontext;
1105 unsigned int
1106 WMWidgetWidth(WMWidget *w)
1108 return W_VIEW(w)->size.width;
1112 unsigned int
1113 WMWidgetHeight(WMWidget *w)
1115 return W_VIEW(w)->size.height;
1119 Window
1120 WMWidgetXID(WMWidget *w)
1122 return W_VIEW(w)->window;
1126 WMScreen*
1127 WMWidgetScreen(WMWidget *w)
1129 return W_VIEW(w)->screen;
1134 void
1135 WMScreenMainLoop(WMScreen *scr)
1137 XEvent event;
1139 while (1) {
1140 WMNextEvent(scr->display, &event);
1141 WMHandleEvent(&event);
1146 void
1147 WMBreakModalLoop(WMScreen *scr)
1149 scr->modalLoop = 0;
1153 void
1154 WMRunModalLoop(WMScreen *scr, WMView *view)
1156 /* why is scr passed if is determined from the view? */
1157 /*WMScreen *scr = view->screen;*/
1158 int oldModalLoop = scr->modalLoop;
1159 WMView *oldModalView = scr->modalView;
1161 scr->modalView = view;
1163 scr->modalLoop = 1;
1164 while (scr->modalLoop) {
1165 XEvent event;
1167 WMNextEvent(scr->display, &event);
1168 WMHandleEvent(&event);
1171 scr->modalView = oldModalView;
1172 scr->modalLoop = oldModalLoop;
1176 Display*
1177 WMScreenDisplay(WMScreen *scr)
1179 return scr->display;
1184 WMScreenDepth(WMScreen *scr)
1186 return scr->depth;
1190 unsigned int
1191 WMScreenWidth(WMScreen *scr)
1193 return scr->rootView->size.width;
1197 unsigned int
1198 WMScreenHeight(WMScreen *scr)
1200 return scr->rootView->size.height;
1204 void
1205 WMRedisplayWidget(WMWidget *w)
1207 W_RedisplayView(W_VIEW(w));