WPrefs: set default to 1st color in gradient texture
[wmaker-crm.git] / WINGs / widgets.c
blob75b44e7008cbfd94b6a7a4f747106cb39d53104a
2 #include "WINGsP.h"
3 #include "wconfig.h"
5 #include <X11/Xft/Xft.h>
7 #include <X11/Xutil.h>
8 #include <X11/Xatom.h>
9 #include <X11/keysym.h>
10 #include <X11/cursorfont.h>
12 #include <X11/Xlocale.h>
14 /********** data ************/
16 #define CHECK_BUTTON_ON_WIDTH 16
17 #define CHECK_BUTTON_ON_HEIGHT 16
19 static char *CHECK_BUTTON_ON[] = {
20 " %",
21 " .............%#",
22 " ........... .%#",
23 " .......... #.%#",
24 " ......... #%.%#",
25 " ........ #%..%#",
26 " ... #.. #%...%#",
27 " ... #% #%....%#",
28 " ... % #%.....%#",
29 " ... #%......%#",
30 " ... #%.......%#",
31 " ...#%........%#",
32 " .............%#",
33 " .............%#",
34 " %%%%%%%%%%%%%%#",
35 "%###############"
38 #define CHECK_BUTTON_OFF_WIDTH 16
39 #define CHECK_BUTTON_OFF_HEIGHT 16
41 static char *CHECK_BUTTON_OFF[] = {
42 " %",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " .............%#",
52 " .............%#",
53 " .............%#",
54 " .............%#",
55 " .............%#",
56 " %%%%%%%%%%%%%%#",
57 "%###############"
60 #define RADIO_BUTTON_ON_WIDTH 15
61 #define RADIO_BUTTON_ON_HEIGHT 15
62 static char *RADIO_BUTTON_ON[] = {
63 ".....%%%%%.....",
64 "...%%#####%%...",
65 "..%##.....%.%..",
66 ".%#%.. .....",
67 ".%#. ...",
68 "%#.. .. ",
69 "%#. . ",
70 "%#. . ",
71 "%#. . ",
72 "%#. . ",
73 ".%%. . .",
74 ".%.. . .",
75 "..%... .. ..",
76 ".... ..... ...",
77 "..... .....",
80 #define RADIO_BUTTON_OFF_WIDTH 15
81 #define RADIO_BUTTON_OFF_HEIGHT 15
82 static char *RADIO_BUTTON_OFF[] = {
83 ".....%%%%%.....",
84 "...%%#####%%...",
85 "..%##.......%..",
86 ".%#%...........",
87 ".%#............",
88 "%#............ ",
89 "%#............ ",
90 "%#............ ",
91 "%#............ ",
92 "%#............ ",
93 ".%%.......... .",
94 ".%........... .",
95 "..%......... ..",
96 ".... ..... ...",
97 "..... .....",
100 static char *BUTTON_ARROW[] = {
101 "..................",
102 "....##....#### ...",
103 "...#.%....#... ...",
104 "..#..%#####... ...",
105 ".#............ ...",
106 "#............. ...",
107 ".#............ ...",
108 "..#.. ...",
109 "...#. ............",
110 "....# ............"
113 #define BUTTON_ARROW_WIDTH 18
114 #define BUTTON_ARROW_HEIGHT 10
116 static char *BUTTON_ARROW2[] = {
117 " ",
118 " ## ####. ",
119 " # % # . ",
120 " # %##### . ",
121 " # . ",
122 "# . ",
123 " # . ",
124 " # .......... ",
125 " # . ",
126 " #. "
129 #define BUTTON_ARROW2_WIDTH 18
130 #define BUTTON_ARROW2_HEIGHT 10
132 static char *SCROLLER_DIMPLE[] = {
133 ".%###.",
134 "%#%%%%",
135 "#%%...",
136 "#%.. ",
137 "#%. ",
138 ".%. ."
141 #define SCROLLER_DIMPLE_WIDTH 6
142 #define SCROLLER_DIMPLE_HEIGHT 6
144 static char *SCROLLER_ARROW_UP[] = {
145 "....%....",
146 "....#....",
147 "...%#%...",
148 "...###...",
149 "..%###%..",
150 "..#####..",
151 ".%#####%.",
152 ".#######.",
153 "%#######%"
156 static char *HI_SCROLLER_ARROW_UP[] = {
157 " % ",
158 " % ",
159 " %%% ",
160 " %%% ",
161 " %%%%% ",
162 " %%%%% ",
163 " %%%%%%% ",
164 " %%%%%%% ",
165 "%%%%%%%%%"
168 #define SCROLLER_ARROW_UP_WIDTH 9
169 #define SCROLLER_ARROW_UP_HEIGHT 9
171 static char *SCROLLER_ARROW_DOWN[] = {
172 "%#######%",
173 ".#######.",
174 ".%#####%.",
175 "..#####..",
176 "..%###%..",
177 "...###...",
178 "...%#%...",
179 "....#....",
180 "....%...."
183 static char *HI_SCROLLER_ARROW_DOWN[] = {
184 "%%%%%%%%%",
185 " %%%%%%% ",
186 " %%%%%%% ",
187 " %%%%% ",
188 " %%%%% ",
189 " %%% ",
190 " %%% ",
191 " % ",
192 " % "
195 #define SCROLLER_ARROW_DOWN_WIDTH 9
196 #define SCROLLER_ARROW_DOWN_HEIGHT 9
198 static char *SCROLLER_ARROW_LEFT[] = {
199 "........%",
200 "......%##",
201 "....%####",
202 "..%######",
203 "%########",
204 "..%######",
205 "....%####",
206 "......%##",
207 "........%"
210 static char *HI_SCROLLER_ARROW_LEFT[] = {
211 " %",
212 " %%%",
213 " %%%%%",
214 " %%%%%%%",
215 "%%%%%%%%%",
216 " %%%%%%%",
217 " %%%%%",
218 " %%%",
219 " %"
222 #define SCROLLER_ARROW_LEFT_WIDTH 9
223 #define SCROLLER_ARROW_LEFT_HEIGHT 9
225 static char *SCROLLER_ARROW_RIGHT[] = {
226 "%........",
227 "##%......",
228 "####%....",
229 "######%..",
230 "########%",
231 "######%..",
232 "####%....",
233 "##%......",
234 "%........"
237 static char *HI_SCROLLER_ARROW_RIGHT[] = {
238 "% ",
239 "%%% ",
240 "%%%%% ",
241 "%%%%%%% ",
242 "%%%%%%%%%",
243 "%%%%%%% ",
244 "%%%%% ",
245 "%%% ",
246 "% "
249 #define SCROLLER_ARROW_RIGHT_WIDTH 9
250 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
252 static char *POPUP_INDICATOR[] = {
253 " #==",
254 " ......%#==",
255 " ......%#%%",
256 " ......%#%%",
257 " %%%%%%%#%%",
258 "#########%%",
259 "==%%%%%%%%%",
260 "==%%%%%%%%%"
263 #define POPUP_INDICATOR_WIDTH 11
264 #define POPUP_INDICATOR_HEIGHT 8
266 static char *PULLDOWN_INDICATOR[] = {
267 "=#######=",
268 "=%===== =",
269 "==%=== ==",
270 "==%=== ==",
271 "===%= ===",
272 "===%= ===",
273 "====%===="
276 #define PULLDOWN_INDICATOR_WIDTH 9
277 #define PULLDOWN_INDICATOR_HEIGHT 7
279 #define CHECK_MARK_WIDTH 8
280 #define CHECK_MARK_HEIGHT 10
282 static char *CHECK_MARK[] = {
283 "======== ",
284 "======= #",
285 "====== #%",
286 "===== #%=",
287 " #== #%==",
288 " #% #%===",
289 " % #%====",
290 " #%=====",
291 " #%======",
292 "#%======="
295 #define STIPPLE_WIDTH 8
296 #define STIPPLE_HEIGHT 8
297 static char STIPPLE_BITS[] = {
298 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
301 static int userWidgetCount = 0;
303 /***** end data ******/
305 static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
307 int x, y;
308 GC whiteGC = WMColorGC(screen->white);
309 GC blackGC = WMColorGC(screen->black);
310 GC lightGC = WMColorGC(screen->gray);
311 GC darkGC = WMColorGC(screen->darkGray);
313 if (mask)
314 XSetForeground(screen->display, screen->monoGC, 0);
316 for (y = 0; y < height; y++) {
317 for (x = 0; x < width; x++) {
318 switch (data[y][x]) {
319 case ' ':
320 case 'w':
321 XDrawPoint(screen->display, d, whiteGC, x, y);
322 break;
324 case '=':
325 if (mask)
326 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
328 case '.':
329 case 'l':
330 XDrawPoint(screen->display, d, lightGC, x, y);
331 break;
333 case '%':
334 case 'd':
335 XDrawPoint(screen->display, d, darkGC, x, y);
336 break;
338 case '#':
339 case 'b':
340 default:
341 XDrawPoint(screen->display, d, blackGC, x, y);
342 break;
348 static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
350 Pixmap pixmap, mask = None;
352 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
354 if (masked) {
355 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
356 XSetForeground(sPtr->display, sPtr->monoGC, 1);
357 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
360 renderPixmap(sPtr, pixmap, mask, data, width, height);
362 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
365 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
366 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
368 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
369 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
371 static Bool loadPixmaps(WMScreen * scr)
373 RImage *image, *tmp;
374 RColor gray;
375 RColor white;
377 gray.red = 0xae;
378 gray.green = 0xaa;
379 gray.blue = 0xae;
381 white.red = 0xff;
382 white.green = 0xff;
383 white.blue = 0xff;
385 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
386 if (!image)
387 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
388 if (!image) {
389 wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
390 return False;
392 /* home icon */
393 /* make it have a gray background */
394 tmp = RGetSubImage(image, 0, 0, 24, 24);
395 RCombineImageWithColor(tmp, &gray);
396 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
397 RReleaseImage(tmp);
398 /* make it have a white background */
399 tmp = RGetSubImage(image, 0, 0, 24, 24);
400 RCombineImageWithColor(tmp, &white);
401 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
402 RReleaseImage(tmp);
404 /* trash can */
405 tmp = RGetSubImage(image, 104, 0, 24, 24);
406 RCombineImageWithColor(tmp, &white);
407 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
408 RReleaseImage(tmp);
409 tmp = RGetSubImage(image, 104, 0, 24, 24);
410 RCombineImageWithColor(tmp, &white);
411 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
412 RReleaseImage(tmp);
413 /* create dir */
414 tmp = RGetSubImage(image, 104, 24, 24, 24);
415 RCombineImageWithColor(tmp, &white);
416 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
417 RReleaseImage(tmp);
418 tmp = RGetSubImage(image, 104, 24, 24, 24);
419 RCombineImageWithColor(tmp, &white);
420 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
421 RReleaseImage(tmp);
422 /* diskettes */
423 tmp = RGetSubImage(image, 24, 80, 24, 24);
424 RCombineImageWithColor(tmp, &white);
425 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
426 RReleaseImage(tmp);
427 tmp = RGetSubImage(image, 24, 80, 24, 24);
428 RCombineImageWithColor(tmp, &white);
429 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
430 RReleaseImage(tmp);
431 /* unmount */
432 tmp = RGetSubImage(image, 0, 80, 24, 24);
433 RCombineImageWithColor(tmp, &white);
434 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
435 RReleaseImage(tmp);
436 tmp = RGetSubImage(image, 0, 80, 24, 24);
437 RCombineImageWithColor(tmp, &white);
438 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
439 RReleaseImage(tmp);
441 /* Magnifying Glass Icon for ColorPanel */
442 tmp = RGetSubImage(image, 24, 0, 40, 32);
443 RCombineImageWithColor(tmp, &gray);
444 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
445 RReleaseImage(tmp);
446 /* ColorWheel Icon for ColorPanel */
447 tmp = RGetSubImage(image, 0, 25, 24, 24);
448 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
449 RReleaseImage(tmp);
450 /* GrayScale Icon for ColorPanel */
451 tmp = RGetSubImage(image, 65, 0, 40, 24);
452 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
453 RReleaseImage(tmp);
454 /* RGB Icon for ColorPanel */
455 tmp = RGetSubImage(image, 25, 33, 40, 24);
456 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
457 RReleaseImage(tmp);
458 /* CMYK Icon for ColorPanel */
459 tmp = RGetSubImage(image, 65, 25, 40, 24);
460 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
461 RReleaseImage(tmp);
462 /* HSB Icon for ColorPanel */
463 tmp = RGetSubImage(image, 0, 57, 40, 24);
464 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
465 RReleaseImage(tmp);
466 /* CustomColorPalette Icon for ColorPanel */
467 tmp = RGetSubImage(image, 81, 57, 40, 24);
468 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
469 RReleaseImage(tmp);
470 /* ColorList Icon for ColorPanel */
471 tmp = RGetSubImage(image, 41, 57, 40, 24);
472 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
473 RReleaseImage(tmp);
475 RReleaseImage(image);
477 #if 0
478 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
479 if (!scr->defaultObjectIcon) {
480 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
482 if (!scr->defaultObjectIcon) {
483 wwarning("WINGs: could not load default icon file");
484 return False;
486 #endif
487 return True;
490 WMScreen *WMOpenScreen(const char *display)
492 Display *dpy = XOpenDisplay(display);
494 if (!dpy) {
495 wwarning("WINGs: could not open display %s", XDisplayName(display));
496 return NULL;
499 return WMCreateSimpleApplicationScreen(dpy);
502 WMScreen *WMCreateSimpleApplicationScreen(Display * display)
504 WMScreen *scr;
506 scr = WMCreateScreen(display, DefaultScreen(display));
508 scr->aflags.hasAppIcon = 0;
509 scr->aflags.simpleApplication = 1;
511 return scr;
514 WMScreen *WMCreateScreen(Display * display, int screen)
516 return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
519 WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
521 W_Screen *scrPtr;
522 XGCValues gcv;
523 Pixmap stipple;
524 static int initialized = 0;
525 static char *atomNames[] = {
526 "_GNUSTEP_WM_ATTR",
527 "WM_DELETE_WINDOW",
528 "WM_PROTOCOLS",
529 "CLIPBOARD",
530 "XdndAware",
531 "XdndSelection",
532 "XdndEnter",
533 "XdndLeave",
534 "XdndPosition",
535 "XdndDrop",
536 "XdndFinished",
537 "XdndTypeList",
538 "XdndActionList",
539 "XdndActionDescription",
540 "XdndStatus",
541 "XdndActionCopy",
542 "XdndActionMove",
543 "XdndActionLink",
544 "XdndActionAsk",
545 "XdndActionPrivate",
546 "_WINGS_DND_MOUSE_OFFSET",
547 "WM_STATE",
548 "UTF8_STRING",
549 "_NET_WM_NAME",
550 "_NET_WM_ICON_NAME",
551 "_NET_WM_ICON",
553 Atom atoms[wlengthof(atomNames)];
554 int i;
556 if (!initialized) {
558 initialized = 1;
560 W_ReadConfigurations();
562 assert(W_ApplicationInitialized());
565 scrPtr = malloc(sizeof(W_Screen));
566 if (!scrPtr)
567 return NULL;
568 memset(scrPtr, 0, sizeof(W_Screen));
570 scrPtr->aflags.hasAppIcon = 1;
572 scrPtr->display = display;
573 scrPtr->screen = screen;
574 scrPtr->rcontext = context;
576 scrPtr->depth = context->depth;
578 scrPtr->visual = context->visual;
579 scrPtr->lastEventTime = 0;
581 scrPtr->colormap = context->cmap;
583 scrPtr->rootWin = RootWindow(display, screen);
585 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
587 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
589 /* Create missing CUT_BUFFERs */
591 Atom *rootWinProps;
592 int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
593 int count;
595 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
596 for (i = 0; i < count; i++) {
597 switch (rootWinProps[i]) {
598 case XA_CUT_BUFFER0:
599 exists[0] = 1;
600 break;
601 case XA_CUT_BUFFER1:
602 exists[1] = 1;
603 break;
604 case XA_CUT_BUFFER2:
605 exists[2] = 1;
606 break;
607 case XA_CUT_BUFFER3:
608 exists[3] = 1;
609 break;
610 case XA_CUT_BUFFER4:
611 exists[4] = 1;
612 break;
613 case XA_CUT_BUFFER5:
614 exists[5] = 1;
615 break;
616 case XA_CUT_BUFFER6:
617 exists[6] = 1;
618 break;
619 case XA_CUT_BUFFER7:
620 exists[7] = 1;
621 break;
622 default:
623 break;
626 if (rootWinProps) {
627 XFree(rootWinProps);
629 for (i = 0; i < 8; i++) {
630 if (!exists[i]) {
631 XStoreBuffer(display, "", 0, i);
636 scrPtr->ignoredModifierMask = 0;
638 int i;
639 XModifierKeymap *modmap;
640 KeyCode nlock, slock;
641 static int mask_table[8] = {
642 ShiftMask, LockMask, ControlMask, Mod1Mask,
643 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
645 unsigned int numLockMask = 0, scrollLockMask = 0;
647 nlock = XKeysymToKeycode(display, XK_Num_Lock);
648 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
651 * Find out the masks for the NumLock and ScrollLock modifiers,
652 * so that we can bind the grabs for when they are enabled too.
654 modmap = XGetModifierMapping(display);
656 if (modmap != NULL && modmap->max_keypermod > 0) {
657 for (i = 0; i < 8 * modmap->max_keypermod; i++) {
658 if (modmap->modifiermap[i] == nlock && nlock != 0)
659 numLockMask = mask_table[i / modmap->max_keypermod];
660 else if (modmap->modifiermap[i] == slock && slock != 0)
661 scrollLockMask = mask_table[i / modmap->max_keypermod];
665 if (modmap)
666 XFreeModifiermap(modmap);
668 scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
671 /* initially allocate some colors */
672 WMWhiteColor(scrPtr);
673 WMBlackColor(scrPtr);
674 WMGrayColor(scrPtr);
675 WMDarkGrayColor(scrPtr);
677 gcv.graphics_exposures = False;
679 gcv.function = GXxor;
680 gcv.foreground = W_PIXEL(scrPtr->white);
681 if (gcv.foreground == 0)
682 gcv.foreground = 1;
683 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
684 | GCGraphicsExposures | GCForeground, &gcv);
686 gcv.function = GXxor;
687 gcv.foreground = W_PIXEL(scrPtr->gray);
688 gcv.subwindow_mode = IncludeInferiors;
689 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
690 | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
692 gcv.function = GXcopy;
693 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
695 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
697 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
698 gcv.foreground = W_PIXEL(scrPtr->darkGray);
699 gcv.background = W_PIXEL(scrPtr->gray);
700 gcv.fill_style = FillStippled;
701 gcv.stipple = stipple;
702 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
703 GCForeground | GCBackground | GCStipple
704 | GCFillStyle | GCGraphicsExposures, &gcv);
706 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
707 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
709 /* we need a 1bpp drawable for the monoGC, so borrow this one */
710 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
712 scrPtr->stipple = stipple;
714 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
716 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
718 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
720 if (!scrPtr->boldFont)
721 scrPtr->boldFont = scrPtr->normalFont;
723 if (!scrPtr->normalFont) {
724 wwarning(_("could not load any fonts. Make sure your font installation"
725 " and locale settings are correct."));
727 return NULL;
730 /* create input method stuff */
731 W_InitIM(scrPtr);
733 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
734 CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
736 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
737 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
739 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
740 RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
742 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
743 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
745 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
747 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
748 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
750 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
751 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
753 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
754 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
756 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
757 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
759 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
760 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
762 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
763 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
765 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
766 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
768 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
769 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
771 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
772 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
774 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
775 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
777 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
778 POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
780 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
781 PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
783 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
785 loadPixmaps(scrPtr);
787 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
789 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
792 XColor bla;
793 Pixmap blank;
795 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
796 XSetForeground(display, scrPtr->monoGC, 0);
797 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
799 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
800 XFreePixmap(display, blank);
803 #ifdef HAVE_XINTERNATOMS
804 XInternAtoms(display, atomNames, wlengthof(atomNames), False, atoms);
805 #else
806 for (i = 0; i < wlengthof(atomNames); i++) {
807 atoms[i] = XInternAtom(display, atomNames[i], False);
809 #endif
811 i = 0;
812 scrPtr->attribsAtom = atoms[i++];
814 scrPtr->deleteWindowAtom = atoms[i++];
816 scrPtr->protocolsAtom = atoms[i++];
818 scrPtr->clipboardAtom = atoms[i++];
820 scrPtr->xdndAwareAtom = atoms[i++];
821 scrPtr->xdndSelectionAtom = atoms[i++];
822 scrPtr->xdndEnterAtom = atoms[i++];
823 scrPtr->xdndLeaveAtom = atoms[i++];
824 scrPtr->xdndPositionAtom = atoms[i++];
825 scrPtr->xdndDropAtom = atoms[i++];
826 scrPtr->xdndFinishedAtom = atoms[i++];
827 scrPtr->xdndTypeListAtom = atoms[i++];
828 scrPtr->xdndActionListAtom = atoms[i++];
829 scrPtr->xdndActionDescriptionAtom = atoms[i++];
830 scrPtr->xdndStatusAtom = atoms[i++];
832 scrPtr->xdndActionCopy = atoms[i++];
833 scrPtr->xdndActionMove = atoms[i++];
834 scrPtr->xdndActionLink = atoms[i++];
835 scrPtr->xdndActionAsk = atoms[i++];
836 scrPtr->xdndActionPrivate = atoms[i++];
838 scrPtr->wmIconDragOffsetAtom = atoms[i++];
840 scrPtr->wmStateAtom = atoms[i++];
842 scrPtr->utf8String = atoms[i++];
843 scrPtr->netwmName = atoms[i++];
844 scrPtr->netwmIconName = atoms[i++];
845 scrPtr->netwmIcon = atoms[i++];
847 scrPtr->rootView = W_CreateRootView(scrPtr);
849 scrPtr->balloon = W_CreateBalloon(scrPtr);
851 W_InitApplication(scrPtr);
853 return scrPtr;
856 void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
858 WMReleaseFont(scr->normalFont);
859 scr->normalFont = WMRetainFont(font);
862 void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
864 WMReleaseFont(scr->boldFont);
865 scr->boldFont = WMRetainFont(font);
868 void WMHangData(WMWidget * widget, void *data)
870 W_VIEW(widget)->hangedData = data;
873 void *WMGetHangedData(WMWidget * widget)
875 return W_VIEW(widget)->hangedData;
878 void WMDestroyWidget(WMWidget * widget)
880 W_UnmapView(W_VIEW(widget));
881 W_DestroyView(W_VIEW(widget));
884 void WMSetFocusToWidget(WMWidget * widget)
886 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
890 * WMRealizeWidget-
891 * Realizes the widget and all it's children.
894 void WMRealizeWidget(WMWidget * w)
896 W_RealizeView(W_VIEW(w));
899 void WMMapWidget(WMWidget * w)
901 W_MapView(W_VIEW(w));
904 void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
906 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
909 static void makeChildrenAutomap(W_View * view, int flag)
911 view = view->childrenList;
913 while (view) {
914 view->flags.mapWhenRealized = flag;
915 makeChildrenAutomap(view, flag);
917 view = view->nextSister;
921 void WMMapSubwidgets(WMWidget * w)
923 /* make sure that subwidgets created after the parent was realized
924 * are mapped too */
925 if (!W_VIEW(w)->flags.realized) {
926 makeChildrenAutomap(W_VIEW(w), True);
927 } else {
928 W_MapSubviews(W_VIEW(w));
932 void WMUnmapSubwidgets(WMWidget * w)
934 if (!W_VIEW(w)->flags.realized) {
935 makeChildrenAutomap(W_VIEW(w), False);
936 } else {
937 W_UnmapSubviews(W_VIEW(w));
941 void WMUnmapWidget(WMWidget * w)
943 W_UnmapView(W_VIEW(w));
946 Bool WMWidgetIsMapped(WMWidget * w)
948 return W_VIEW(w)->flags.mapped;
951 void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
953 W_SetViewBackgroundColor(W_VIEW(w), color);
954 if (W_VIEW(w)->flags.mapped)
955 WMRedisplayWidget(w);
958 WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
960 return W_VIEW(w)->backColor;
963 void WMRaiseWidget(WMWidget * w)
965 W_RaiseView(W_VIEW(w));
968 void WMLowerWidget(WMWidget * w)
970 W_LowerView(W_VIEW(w));
973 void WMMoveWidget(WMWidget * w, int x, int y)
975 W_MoveView(W_VIEW(w), x, y);
978 void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
980 W_ResizeView(W_VIEW(w), width, height);
983 W_Class W_RegisterUserWidget(void)
985 userWidgetCount++;
987 return userWidgetCount + WC_UserWidget - 1;
990 RContext *WMScreenRContext(WMScreen * scr)
992 return scr->rcontext;
995 unsigned int WMWidgetWidth(WMWidget * w)
997 return W_VIEW(w)->size.width;
1000 unsigned int WMWidgetHeight(WMWidget * w)
1002 return W_VIEW(w)->size.height;
1005 Window WMWidgetXID(WMWidget * w)
1007 return W_VIEW(w)->window;
1010 WMScreen *WMWidgetScreen(WMWidget * w)
1012 return W_VIEW(w)->screen;
1015 void WMScreenMainLoop(WMScreen * scr)
1017 XEvent event;
1019 while (1) {
1020 WMNextEvent(scr->display, &event);
1021 WMHandleEvent(&event);
1025 void WMBreakModalLoop(WMScreen * scr)
1027 scr->modalLoop = 0;
1030 void WMRunModalLoop(WMScreen * scr, WMView * view)
1032 /* why is scr passed if is determined from the view? */
1033 /*WMScreen *scr = view->screen; */
1034 int oldModalLoop = scr->modalLoop;
1035 WMView *oldModalView = scr->modalView;
1037 scr->modalView = view;
1039 scr->modalLoop = 1;
1040 while (scr->modalLoop) {
1041 XEvent event;
1043 WMNextEvent(scr->display, &event);
1044 WMHandleEvent(&event);
1047 scr->modalView = oldModalView;
1048 scr->modalLoop = oldModalLoop;
1051 Display *WMScreenDisplay(WMScreen * scr)
1053 return scr->display;
1056 int WMScreenDepth(WMScreen * scr)
1058 return scr->depth;
1061 unsigned int WMScreenWidth(WMScreen * scr)
1063 return scr->rootView->size.width;
1066 unsigned int WMScreenHeight(WMScreen * scr)
1068 return scr->rootView->size.height;
1071 void WMRedisplayWidget(WMWidget * w)
1073 W_RedisplayView(W_VIEW(w));