Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / widgets.c
blob39cc3eff2bc15ea8e35f3eeb67bae095d76c0ad9
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 extern void W_ReadConfigurations(void);
303 static int userWidgetCount = 0;
305 /***** end data ******/
307 static void renderPixmap(W_Screen * screen, Pixmap d, Pixmap mask, char **data, int width, int height)
309 int x, y;
310 GC whiteGC = WMColorGC(screen->white);
311 GC blackGC = WMColorGC(screen->black);
312 GC lightGC = WMColorGC(screen->gray);
313 GC darkGC = WMColorGC(screen->darkGray);
315 if (mask)
316 XSetForeground(screen->display, screen->monoGC, 0);
318 for (y = 0; y < height; y++) {
319 for (x = 0; x < width; x++) {
320 switch (data[y][x]) {
321 case ' ':
322 case 'w':
323 XDrawPoint(screen->display, d, whiteGC, x, y);
324 break;
326 case '=':
327 if (mask)
328 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
330 case '.':
331 case 'l':
332 XDrawPoint(screen->display, d, lightGC, x, y);
333 break;
335 case '%':
336 case 'd':
337 XDrawPoint(screen->display, d, darkGC, x, y);
338 break;
340 case '#':
341 case 'b':
342 default:
343 XDrawPoint(screen->display, d, blackGC, x, y);
344 break;
350 static WMPixmap *makePixmap(W_Screen * sPtr, char **data, int width, int height, int masked)
352 Pixmap pixmap, mask = None;
354 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, sPtr->depth);
356 if (masked) {
357 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
358 XSetForeground(sPtr->display, sPtr->monoGC, 1);
359 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
362 renderPixmap(sPtr, pixmap, mask, data, width, height);
364 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height, sPtr->depth);
367 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
368 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
370 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
371 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
373 static Bool loadPixmaps(WMScreen * scr)
375 RImage *image, *tmp;
376 RColor gray;
377 RColor white;
379 gray.red = 0xae;
380 gray.green = 0xaa;
381 gray.blue = 0xae;
383 white.red = 0xff;
384 white.green = 0xff;
385 white.blue = 0xff;
387 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
388 if (!image)
389 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
390 if (!image) {
391 wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
392 return False;
394 /* home icon */
395 /* make it have a gray background */
396 tmp = RGetSubImage(image, 0, 0, 24, 24);
397 RCombineImageWithColor(tmp, &gray);
398 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
399 RReleaseImage(tmp);
400 /* make it have a white background */
401 tmp = RGetSubImage(image, 0, 0, 24, 24);
402 RCombineImageWithColor(tmp, &white);
403 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
404 RReleaseImage(tmp);
406 /* trash can */
407 tmp = RGetSubImage(image, 104, 0, 24, 24);
408 RCombineImageWithColor(tmp, &white);
409 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
410 RReleaseImage(tmp);
411 tmp = RGetSubImage(image, 104, 0, 24, 24);
412 RCombineImageWithColor(tmp, &white);
413 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
414 RReleaseImage(tmp);
415 /* create dir */
416 tmp = RGetSubImage(image, 104, 24, 24, 24);
417 RCombineImageWithColor(tmp, &white);
418 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
419 RReleaseImage(tmp);
420 tmp = RGetSubImage(image, 104, 24, 24, 24);
421 RCombineImageWithColor(tmp, &white);
422 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
423 RReleaseImage(tmp);
424 /* diskettes */
425 tmp = RGetSubImage(image, 24, 80, 24, 24);
426 RCombineImageWithColor(tmp, &white);
427 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
428 RReleaseImage(tmp);
429 tmp = RGetSubImage(image, 24, 80, 24, 24);
430 RCombineImageWithColor(tmp, &white);
431 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
432 RReleaseImage(tmp);
433 /* unmount */
434 tmp = RGetSubImage(image, 0, 80, 24, 24);
435 RCombineImageWithColor(tmp, &white);
436 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
437 RReleaseImage(tmp);
438 tmp = RGetSubImage(image, 0, 80, 24, 24);
439 RCombineImageWithColor(tmp, &white);
440 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
441 RReleaseImage(tmp);
443 /* Magnifying Glass Icon for ColorPanel */
444 tmp = RGetSubImage(image, 24, 0, 40, 32);
445 RCombineImageWithColor(tmp, &gray);
446 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
447 RReleaseImage(tmp);
448 /* ColorWheel Icon for ColorPanel */
449 tmp = RGetSubImage(image, 0, 25, 24, 24);
450 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
451 RReleaseImage(tmp);
452 /* GrayScale Icon for ColorPanel */
453 tmp = RGetSubImage(image, 65, 0, 40, 24);
454 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
455 RReleaseImage(tmp);
456 /* RGB Icon for ColorPanel */
457 tmp = RGetSubImage(image, 25, 33, 40, 24);
458 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
459 RReleaseImage(tmp);
460 /* CMYK Icon for ColorPanel */
461 tmp = RGetSubImage(image, 65, 25, 40, 24);
462 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
463 RReleaseImage(tmp);
464 /* HSB Icon for ColorPanel */
465 tmp = RGetSubImage(image, 0, 57, 40, 24);
466 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
467 RReleaseImage(tmp);
468 /* CustomColorPalette Icon for ColorPanel */
469 tmp = RGetSubImage(image, 81, 57, 40, 24);
470 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
471 RReleaseImage(tmp);
472 /* ColorList Icon for ColorPanel */
473 tmp = RGetSubImage(image, 41, 57, 40, 24);
474 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
475 RReleaseImage(tmp);
477 RReleaseImage(image);
479 #if 0
480 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
481 if (!scr->defaultObjectIcon) {
482 scr->defaultObjectIcon = WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
484 if (!scr->defaultObjectIcon) {
485 wwarning("WINGs: could not load default icon file");
486 return False;
488 #endif
489 return True;
492 WMScreen *WMOpenScreen(const char *display)
494 Display *dpy = XOpenDisplay(display);
496 if (!dpy) {
497 wwarning("WINGs: could not open display %s", XDisplayName(display));
498 return NULL;
501 return WMCreateSimpleApplicationScreen(dpy);
504 WMScreen *WMCreateSimpleApplicationScreen(Display * display)
506 WMScreen *scr;
508 scr = WMCreateScreen(display, DefaultScreen(display));
510 scr->aflags.hasAppIcon = 0;
511 scr->aflags.simpleApplication = 1;
513 return scr;
516 WMScreen *WMCreateScreen(Display * display, int screen)
518 return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
521 WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
523 W_Screen *scrPtr;
524 XGCValues gcv;
525 Pixmap stipple;
526 static int initialized = 0;
527 static char *atomNames[] = {
528 "_GNUSTEP_WM_ATTR",
529 "WM_DELETE_WINDOW",
530 "WM_PROTOCOLS",
531 "CLIPBOARD",
532 "XdndAware",
533 "XdndSelection",
534 "XdndEnter",
535 "XdndLeave",
536 "XdndPosition",
537 "XdndDrop",
538 "XdndFinished",
539 "XdndTypeList",
540 "XdndActionList",
541 "XdndActionDescription",
542 "XdndStatus",
543 "XdndActionCopy",
544 "XdndActionMove",
545 "XdndActionLink",
546 "XdndActionAsk",
547 "XdndActionPrivate",
548 "_WINGS_DND_MOUSE_OFFSET",
549 "WM_STATE",
550 "UTF8_STRING",
551 "_NET_WM_NAME",
552 "_NET_WM_ICON_NAME",
553 "_NET_WM_ICON",
555 Atom atoms[sizeof(atomNames) / sizeof(char *)];
556 int i;
558 if (!initialized) {
560 initialized = 1;
562 W_ReadConfigurations();
564 assert(W_ApplicationInitialized());
567 scrPtr = malloc(sizeof(W_Screen));
568 if (!scrPtr)
569 return NULL;
570 memset(scrPtr, 0, sizeof(W_Screen));
572 scrPtr->aflags.hasAppIcon = 1;
574 scrPtr->display = display;
575 scrPtr->screen = screen;
576 scrPtr->rcontext = context;
578 scrPtr->depth = context->depth;
580 scrPtr->visual = context->visual;
581 scrPtr->lastEventTime = 0;
583 scrPtr->colormap = context->cmap;
585 scrPtr->rootWin = RootWindow(display, screen);
587 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
589 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);
591 /* Create missing CUT_BUFFERs */
593 Atom *rootWinProps;
594 int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
595 int count;
597 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
598 for (i = 0; i < count; i++) {
599 switch (rootWinProps[i]) {
600 case XA_CUT_BUFFER0:
601 exists[0] = 1;
602 break;
603 case XA_CUT_BUFFER1:
604 exists[1] = 1;
605 break;
606 case XA_CUT_BUFFER2:
607 exists[2] = 1;
608 break;
609 case XA_CUT_BUFFER3:
610 exists[3] = 1;
611 break;
612 case XA_CUT_BUFFER4:
613 exists[4] = 1;
614 break;
615 case XA_CUT_BUFFER5:
616 exists[5] = 1;
617 break;
618 case XA_CUT_BUFFER6:
619 exists[6] = 1;
620 break;
621 case XA_CUT_BUFFER7:
622 exists[7] = 1;
623 break;
624 default:
625 break;
628 if (rootWinProps) {
629 XFree(rootWinProps);
631 for (i = 0; i < 8; i++) {
632 if (!exists[i]) {
633 XStoreBuffer(display, "", 0, i);
638 scrPtr->ignoredModifierMask = 0;
640 int i;
641 XModifierKeymap *modmap;
642 KeyCode nlock, slock;
643 static int mask_table[8] = {
644 ShiftMask, LockMask, ControlMask, Mod1Mask,
645 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
647 unsigned int numLockMask = 0, scrollLockMask = 0;
649 nlock = XKeysymToKeycode(display, XK_Num_Lock);
650 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
653 * Find out the masks for the NumLock and ScrollLock modifiers,
654 * so that we can bind the grabs for when they are enabled too.
656 modmap = XGetModifierMapping(display);
658 if (modmap != NULL && modmap->max_keypermod > 0) {
659 for (i = 0; i < 8 * modmap->max_keypermod; i++) {
660 if (modmap->modifiermap[i] == nlock && nlock != 0)
661 numLockMask = mask_table[i / modmap->max_keypermod];
662 else if (modmap->modifiermap[i] == slock && slock != 0)
663 scrollLockMask = mask_table[i / modmap->max_keypermod];
667 if (modmap)
668 XFreeModifiermap(modmap);
670 scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
673 /* initially allocate some colors */
674 WMWhiteColor(scrPtr);
675 WMBlackColor(scrPtr);
676 WMGrayColor(scrPtr);
677 WMDarkGrayColor(scrPtr);
679 gcv.graphics_exposures = False;
681 gcv.function = GXxor;
682 gcv.foreground = W_PIXEL(scrPtr->white);
683 if (gcv.foreground == 0)
684 gcv.foreground = 1;
685 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
686 | GCGraphicsExposures | GCForeground, &gcv);
688 gcv.function = GXxor;
689 gcv.foreground = W_PIXEL(scrPtr->gray);
690 gcv.subwindow_mode = IncludeInferiors;
691 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
692 | GCGraphicsExposures | GCForeground | GCSubwindowMode, &gcv);
694 gcv.function = GXcopy;
695 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
697 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
699 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
700 gcv.foreground = W_PIXEL(scrPtr->darkGray);
701 gcv.background = W_PIXEL(scrPtr->gray);
702 gcv.fill_style = FillStippled;
703 gcv.stipple = stipple;
704 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
705 GCForeground | GCBackground | GCStipple
706 | GCFillStyle | GCGraphicsExposures, &gcv);
708 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
709 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
711 /* we need a 1bpp drawable for the monoGC, so borrow this one */
712 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
714 scrPtr->stipple = stipple;
716 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
718 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
720 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
722 if (!scrPtr->boldFont)
723 scrPtr->boldFont = scrPtr->normalFont;
725 if (!scrPtr->normalFont) {
726 wwarning(_("could not load any fonts. Make sure your font installation"
727 " and locale settings are correct."));
729 return NULL;
732 /* create input method stuff */
733 W_InitIM(scrPtr);
735 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
736 CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
738 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
739 CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
741 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
742 RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
744 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
745 RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
747 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
749 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
750 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
752 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
753 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
755 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
756 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
758 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
759 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
761 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
762 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
764 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
765 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
767 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
768 SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
770 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
771 SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
773 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
774 SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
776 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
777 SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
779 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
780 POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
782 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
783 PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
785 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
787 loadPixmaps(scrPtr);
789 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
791 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
794 XColor bla;
795 Pixmap blank;
797 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
798 XSetForeground(display, scrPtr->monoGC, 0);
799 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
801 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
802 XFreePixmap(display, blank);
805 #ifdef HAVE_XINTERNATOMS
806 XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(char *), False, atoms);
807 #else
808 for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++) {
809 atoms[i] = XInternAtom(display, atomNames[i], False);
811 #endif
813 i = 0;
814 scrPtr->attribsAtom = atoms[i++];
816 scrPtr->deleteWindowAtom = atoms[i++];
818 scrPtr->protocolsAtom = atoms[i++];
820 scrPtr->clipboardAtom = atoms[i++];
822 scrPtr->xdndAwareAtom = atoms[i++];
823 scrPtr->xdndSelectionAtom = atoms[i++];
824 scrPtr->xdndEnterAtom = atoms[i++];
825 scrPtr->xdndLeaveAtom = atoms[i++];
826 scrPtr->xdndPositionAtom = atoms[i++];
827 scrPtr->xdndDropAtom = atoms[i++];
828 scrPtr->xdndFinishedAtom = atoms[i++];
829 scrPtr->xdndTypeListAtom = atoms[i++];
830 scrPtr->xdndActionListAtom = atoms[i++];
831 scrPtr->xdndActionDescriptionAtom = atoms[i++];
832 scrPtr->xdndStatusAtom = atoms[i++];
834 scrPtr->xdndActionCopy = atoms[i++];
835 scrPtr->xdndActionMove = atoms[i++];
836 scrPtr->xdndActionLink = atoms[i++];
837 scrPtr->xdndActionAsk = atoms[i++];
838 scrPtr->xdndActionPrivate = atoms[i++];
840 scrPtr->wmIconDragOffsetAtom = atoms[i++];
842 scrPtr->wmStateAtom = atoms[i++];
844 scrPtr->utf8String = atoms[i++];
845 scrPtr->netwmName = atoms[i++];
846 scrPtr->netwmIconName = atoms[i++];
847 scrPtr->netwmIcon = atoms[i++];
849 scrPtr->rootView = W_CreateRootView(scrPtr);
851 scrPtr->balloon = W_CreateBalloon(scrPtr);
853 W_InitApplication(scrPtr);
855 return scrPtr;
858 void WMSetWidgetDefaultFont(WMScreen * scr, WMFont * font)
860 WMReleaseFont(scr->normalFont);
861 scr->normalFont = WMRetainFont(font);
864 void WMSetWidgetDefaultBoldFont(WMScreen * scr, WMFont * font)
866 WMReleaseFont(scr->boldFont);
867 scr->boldFont = WMRetainFont(font);
870 void WMHangData(WMWidget * widget, void *data)
872 W_VIEW(widget)->hangedData = data;
875 void *WMGetHangedData(WMWidget * widget)
877 return W_VIEW(widget)->hangedData;
880 void WMDestroyWidget(WMWidget * widget)
882 W_UnmapView(W_VIEW(widget));
883 W_DestroyView(W_VIEW(widget));
886 void WMSetFocusToWidget(WMWidget * widget)
888 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
892 * WMRealizeWidget-
893 * Realizes the widget and all it's children.
896 void WMRealizeWidget(WMWidget * w)
898 W_RealizeView(W_VIEW(w));
901 void WMMapWidget(WMWidget * w)
903 W_MapView(W_VIEW(w));
906 void WMReparentWidget(WMWidget * w, WMWidget * newParent, int x, int y)
908 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
911 static void makeChildrenAutomap(W_View * view, int flag)
913 view = view->childrenList;
915 while (view) {
916 view->flags.mapWhenRealized = flag;
917 makeChildrenAutomap(view, flag);
919 view = view->nextSister;
923 void WMMapSubwidgets(WMWidget * w)
925 /* make sure that subwidgets created after the parent was realized
926 * are mapped too */
927 if (!W_VIEW(w)->flags.realized) {
928 makeChildrenAutomap(W_VIEW(w), True);
929 } else {
930 W_MapSubviews(W_VIEW(w));
934 void WMUnmapSubwidgets(WMWidget * w)
936 if (!W_VIEW(w)->flags.realized) {
937 makeChildrenAutomap(W_VIEW(w), False);
938 } else {
939 W_UnmapSubviews(W_VIEW(w));
943 void WMUnmapWidget(WMWidget * w)
945 W_UnmapView(W_VIEW(w));
948 Bool WMWidgetIsMapped(WMWidget * w)
950 return W_VIEW(w)->flags.mapped;
953 void WMSetWidgetBackgroundColor(WMWidget * w, WMColor * color)
955 W_SetViewBackgroundColor(W_VIEW(w), color);
956 if (W_VIEW(w)->flags.mapped)
957 WMRedisplayWidget(w);
960 WMColor *WMGetWidgetBackgroundColor(WMWidget * w)
962 return W_VIEW(w)->backColor;
965 void WMRaiseWidget(WMWidget * w)
967 W_RaiseView(W_VIEW(w));
970 void WMLowerWidget(WMWidget * w)
972 W_LowerView(W_VIEW(w));
975 void WMMoveWidget(WMWidget * w, int x, int y)
977 W_MoveView(W_VIEW(w), x, y);
980 void WMResizeWidget(WMWidget * w, unsigned int width, unsigned int height)
982 W_ResizeView(W_VIEW(w), width, height);
985 W_Class W_RegisterUserWidget(void)
987 userWidgetCount++;
989 return userWidgetCount + WC_UserWidget - 1;
992 RContext *WMScreenRContext(WMScreen * scr)
994 return scr->rcontext;
997 unsigned int WMWidgetWidth(WMWidget * w)
999 return W_VIEW(w)->size.width;
1002 unsigned int WMWidgetHeight(WMWidget * w)
1004 return W_VIEW(w)->size.height;
1007 Window WMWidgetXID(WMWidget * w)
1009 return W_VIEW(w)->window;
1012 WMScreen *WMWidgetScreen(WMWidget * w)
1014 return W_VIEW(w)->screen;
1017 void WMScreenMainLoop(WMScreen * scr)
1019 XEvent event;
1021 while (1) {
1022 WMNextEvent(scr->display, &event);
1023 WMHandleEvent(&event);
1027 void WMBreakModalLoop(WMScreen * scr)
1029 scr->modalLoop = 0;
1032 void WMRunModalLoop(WMScreen * scr, WMView * view)
1034 /* why is scr passed if is determined from the view? */
1035 /*WMScreen *scr = view->screen; */
1036 int oldModalLoop = scr->modalLoop;
1037 WMView *oldModalView = scr->modalView;
1039 scr->modalView = view;
1041 scr->modalLoop = 1;
1042 while (scr->modalLoop) {
1043 XEvent event;
1045 WMNextEvent(scr->display, &event);
1046 WMHandleEvent(&event);
1049 scr->modalView = oldModalView;
1050 scr->modalLoop = oldModalLoop;
1053 Display *WMScreenDisplay(WMScreen * scr)
1055 return scr->display;
1058 int WMScreenDepth(WMScreen * scr)
1060 return scr->depth;
1063 unsigned int WMScreenWidth(WMScreen * scr)
1065 return scr->rootView->size.width;
1068 unsigned int WMScreenHeight(WMScreen * scr)
1070 return scr->rootView->size.height;
1073 void WMRedisplayWidget(WMWidget * w)
1075 W_RedisplayView(W_VIEW(w));