updated changelog
[wmaker-crm.git] / WINGs / widgets.c
blob4ff5e288b3f7c6aeb8b1c32a065101f4077650db
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",
592 "UTF8_STRING",
593 "_NET_WM_NAME",
594 "_NET_WM_ICON_NAME",
595 "_NET_WM_ICON",
597 Atom atoms[sizeof(atomNames)/sizeof(char*)];
598 int i;
600 if (!initialized) {
602 initialized = 1;
604 W_ReadConfigurations();
606 assert(W_ApplicationInitialized());
609 scrPtr = malloc(sizeof(W_Screen));
610 if (!scrPtr)
611 return NULL;
612 memset(scrPtr, 0, sizeof(W_Screen));
614 scrPtr->aflags.hasAppIcon = 1;
616 scrPtr->display = display;
617 scrPtr->screen = screen;
618 scrPtr->rcontext = context;
620 scrPtr->depth = context->depth;
622 scrPtr->visual = context->visual;
623 scrPtr->lastEventTime = 0;
625 scrPtr->colormap = context->cmap;
627 scrPtr->rootWin = RootWindow(display, screen);
629 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
631 scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr),
632 scrPtr->visual, scrPtr->colormap);
634 /* Create missing CUT_BUFFERs */
636 Atom *rootWinProps;
637 int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
638 int count;
640 rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
641 for (i=0; i<count; i++) {
642 switch(rootWinProps[i]) {
643 case XA_CUT_BUFFER0:
644 exists[0] = 1; break;
645 case XA_CUT_BUFFER1:
646 exists[1] = 1; break;
647 case XA_CUT_BUFFER2:
648 exists[2] = 1; break;
649 case XA_CUT_BUFFER3:
650 exists[3] = 1; break;
651 case XA_CUT_BUFFER4:
652 exists[4] = 1; break;
653 case XA_CUT_BUFFER5:
654 exists[5] = 1; break;
655 case XA_CUT_BUFFER6:
656 exists[6] = 1; break;
657 case XA_CUT_BUFFER7:
658 exists[7] = 1; break;
659 default:
660 break;
663 if (rootWinProps) {
664 XFree(rootWinProps);
666 for (i=0; i<8; i++) {
667 if (!exists[i]) {
668 XStoreBuffer(display, "", 0, i);
673 scrPtr->ignoredModifierMask = 0;
675 int i;
676 XModifierKeymap *modmap;
677 KeyCode nlock, slock;
678 static int mask_table[8] = {
679 ShiftMask,LockMask,ControlMask,Mod1Mask,
680 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
682 unsigned int numLockMask=0, scrollLockMask=0;
684 nlock = XKeysymToKeycode(display, XK_Num_Lock);
685 slock = XKeysymToKeycode(display, XK_Scroll_Lock);
688 * Find out the masks for the NumLock and ScrollLock modifiers,
689 * so that we can bind the grabs for when they are enabled too.
691 modmap = XGetModifierMapping(display);
693 if (modmap!=NULL && modmap->max_keypermod>0) {
694 for (i=0; i<8*modmap->max_keypermod; i++) {
695 if (modmap->modifiermap[i]==nlock && nlock!=0)
696 numLockMask = mask_table[i/modmap->max_keypermod];
697 else if (modmap->modifiermap[i]==slock && slock!=0)
698 scrollLockMask = mask_table[i/modmap->max_keypermod];
702 if (modmap)
703 XFreeModifiermap(modmap);
706 scrPtr->ignoredModifierMask = numLockMask|scrollLockMask|LockMask;
709 /* initially allocate some colors */
710 WMWhiteColor(scrPtr);
711 WMBlackColor(scrPtr);
712 WMGrayColor(scrPtr);
713 WMDarkGrayColor(scrPtr);
715 gcv.graphics_exposures = False;
717 gcv.function = GXxor;
718 gcv.foreground = W_PIXEL(scrPtr->white);
719 if (gcv.foreground == 0) gcv.foreground = 1;
720 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
721 |GCGraphicsExposures|GCForeground, &gcv);
723 gcv.function = GXxor;
724 gcv.foreground = W_PIXEL(scrPtr->gray);
725 gcv.subwindow_mode = IncludeInferiors;
726 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
727 |GCGraphicsExposures|GCForeground
728 |GCSubwindowMode, &gcv);
730 gcv.function = GXcopy;
731 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
732 |GCGraphicsExposures, &gcv);
734 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
735 |GCGraphicsExposures, &gcv);
737 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
738 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
739 gcv.foreground = W_PIXEL(scrPtr->darkGray);
740 gcv.background = W_PIXEL(scrPtr->gray);
741 gcv.fill_style = FillStippled;
742 gcv.stipple = stipple;
743 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
744 GCForeground|GCBackground|GCStipple
745 |GCFillStyle|GCGraphicsExposures, &gcv);
747 scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr),
748 GCGraphicsExposures, &gcv);
749 scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr),
750 GCGraphicsExposures, &gcv);
752 /* we need a 1bpp drawable for the monoGC, so borrow this one */
753 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
755 scrPtr->stipple = stipple;
757 scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
759 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
761 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
763 if (!scrPtr->boldFont)
764 scrPtr->boldFont = scrPtr->normalFont;
766 if (!scrPtr->normalFont) {
767 wwarning(_("could not load any fonts. Make sure your font installation"
768 " and locale settings are correct."));
770 return NULL;
773 /* create input method stuff */
774 W_InitIM(scrPtr);
776 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
777 CHECK_BUTTON_ON_WIDTH,
778 CHECK_BUTTON_ON_HEIGHT, False);
780 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
781 CHECK_BUTTON_OFF_WIDTH,
782 CHECK_BUTTON_OFF_HEIGHT, False);
784 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
785 RADIO_BUTTON_ON_WIDTH,
786 RADIO_BUTTON_ON_HEIGHT, False);
788 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
789 RADIO_BUTTON_OFF_WIDTH,
790 RADIO_BUTTON_OFF_HEIGHT, False);
792 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
793 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
794 False);
796 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
797 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
798 False);
801 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
802 SCROLLER_DIMPLE_WIDTH,
803 SCROLLER_DIMPLE_HEIGHT, False);
806 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
807 SCROLLER_ARROW_UP_WIDTH,
808 SCROLLER_ARROW_UP_HEIGHT, True);
810 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
811 SCROLLER_ARROW_DOWN_WIDTH,
812 SCROLLER_ARROW_DOWN_HEIGHT, True);
814 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
815 SCROLLER_ARROW_LEFT_WIDTH,
816 SCROLLER_ARROW_LEFT_HEIGHT, True);
818 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
819 SCROLLER_ARROW_RIGHT_WIDTH,
820 SCROLLER_ARROW_RIGHT_HEIGHT, True);
822 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
823 SCROLLER_ARROW_UP_WIDTH,
824 SCROLLER_ARROW_UP_HEIGHT, True);
826 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
827 SCROLLER_ARROW_DOWN_WIDTH,
828 SCROLLER_ARROW_DOWN_HEIGHT, True);
830 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
831 SCROLLER_ARROW_LEFT_WIDTH,
832 SCROLLER_ARROW_LEFT_HEIGHT, True);
834 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
835 SCROLLER_ARROW_RIGHT_WIDTH,
836 SCROLLER_ARROW_RIGHT_HEIGHT, True);
838 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
839 POPUP_INDICATOR_WIDTH,
840 POPUP_INDICATOR_HEIGHT, True);
842 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
843 PULLDOWN_INDICATOR_WIDTH,
844 PULLDOWN_INDICATOR_HEIGHT, True);
846 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
847 CHECK_MARK_WIDTH,
848 CHECK_MARK_HEIGHT, True);
850 loadPixmaps(scrPtr);
852 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
854 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
857 XColor bla;
858 Pixmap blank;
860 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
861 XSetForeground(display, scrPtr->monoGC, 0);
862 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
864 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
865 &bla, &bla, 0, 0);
866 XFreePixmap(display, blank);
869 #ifdef HAVE_XINTERNATOMS
870 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
871 atoms);
872 #else
873 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
874 atoms[i] = XInternAtom(display, atomNames[i], False);
876 #endif
878 i = 0;
879 scrPtr->attribsAtom = atoms[i++];
881 scrPtr->deleteWindowAtom = atoms[i++];
883 scrPtr->protocolsAtom = atoms[i++];
885 scrPtr->clipboardAtom = atoms[i++];
887 scrPtr->xdndAwareAtom = atoms[i++];
888 scrPtr->xdndSelectionAtom = atoms[i++];
889 scrPtr->xdndEnterAtom = atoms[i++];
890 scrPtr->xdndLeaveAtom = atoms[i++];
891 scrPtr->xdndPositionAtom = atoms[i++];
892 scrPtr->xdndDropAtom = atoms[i++];
893 scrPtr->xdndFinishedAtom = atoms[i++];
894 scrPtr->xdndTypeListAtom = atoms[i++];
895 scrPtr->xdndActionListAtom = atoms[i++];
896 scrPtr->xdndActionDescriptionAtom = atoms[i++];
897 scrPtr->xdndStatusAtom = atoms[i++];
899 scrPtr->xdndActionCopy = atoms[i++];
900 scrPtr->xdndActionMove = atoms[i++];
901 scrPtr->xdndActionLink = atoms[i++];
902 scrPtr->xdndActionAsk = atoms[i++];
903 scrPtr->xdndActionPrivate = atoms[i++];
905 scrPtr->wmIconDragOffsetAtom = atoms[i++];
907 scrPtr->wmStateAtom = atoms[i++];
909 scrPtr->utf8String = atoms[i++];
910 scrPtr->netwmName = atoms[i++];
911 scrPtr->netwmIconName = atoms[i++];
912 scrPtr->netwmIcon = atoms[i++];
914 scrPtr->rootView = W_CreateRootView(scrPtr);
916 scrPtr->balloon = W_CreateBalloon(scrPtr);
918 W_InitApplication(scrPtr);
920 return scrPtr;
925 void
926 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
928 WMReleaseFont(scr->normalFont);
929 scr->normalFont = WMRetainFont(font);
933 void
934 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
936 WMReleaseFont(scr->boldFont);
937 scr->boldFont = WMRetainFont(font);
942 void
943 WMHangData(WMWidget *widget, void *data)
945 W_VIEW(widget)->hangedData = data;
949 void*
950 WMGetHangedData(WMWidget *widget)
952 return W_VIEW(widget)->hangedData;
957 void
958 WMDestroyWidget(WMWidget *widget)
960 W_UnmapView(W_VIEW(widget));
961 W_DestroyView(W_VIEW(widget));
965 void
966 WMSetFocusToWidget(WMWidget *widget)
968 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
973 * WMRealizeWidget-
974 * Realizes the widget and all it's children.
977 void
978 WMRealizeWidget(WMWidget *w)
980 W_RealizeView(W_VIEW(w));
983 void
984 WMMapWidget(WMWidget *w)
986 W_MapView(W_VIEW(w));
990 void
991 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
993 W_ReparentView(W_VIEW(w), W_VIEW(newParent), x, y);
997 static void
998 makeChildrenAutomap(W_View *view, int flag)
1000 view = view->childrenList;
1002 while (view) {
1003 view->flags.mapWhenRealized = flag;
1004 makeChildrenAutomap(view, flag);
1006 view = view->nextSister;
1011 void
1012 WMMapSubwidgets(WMWidget *w)
1014 /* make sure that subwidgets created after the parent was realized
1015 * are mapped too */
1016 if (!W_VIEW(w)->flags.realized) {
1017 makeChildrenAutomap(W_VIEW(w), True);
1018 } else {
1019 W_MapSubviews(W_VIEW(w));
1024 void
1025 WMUnmapSubwidgets(WMWidget *w)
1027 if (!W_VIEW(w)->flags.realized) {
1028 makeChildrenAutomap(W_VIEW(w), False);
1029 } else {
1030 W_UnmapSubviews(W_VIEW(w));
1036 void
1037 WMUnmapWidget(WMWidget *w)
1039 W_UnmapView(W_VIEW(w));
1043 Bool
1044 WMWidgetIsMapped(WMWidget *w)
1046 return W_VIEW(w)->flags.mapped;
1050 void
1051 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
1053 W_SetViewBackgroundColor(W_VIEW(w), color);
1054 if (W_VIEW(w)->flags.mapped)
1055 WMRedisplayWidget(w);
1059 WMColor*
1060 WMGetWidgetBackgroundColor(WMWidget *w)
1062 return W_VIEW(w)->backColor;
1066 void
1067 WMRaiseWidget(WMWidget *w)
1069 W_RaiseView(W_VIEW(w));
1073 void
1074 WMLowerWidget(WMWidget *w)
1076 W_LowerView(W_VIEW(w));
1080 void
1081 WMMoveWidget(WMWidget *w, int x, int y)
1083 W_MoveView(W_VIEW(w), x, y);
1087 void
1088 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
1090 W_ResizeView(W_VIEW(w), width, height);
1095 W_Class
1096 W_RegisterUserWidget(void)
1098 userWidgetCount++;
1100 return userWidgetCount + WC_UserWidget - 1;
1105 RContext*
1106 WMScreenRContext(WMScreen *scr)
1108 return scr->rcontext;
1113 unsigned int
1114 WMWidgetWidth(WMWidget *w)
1116 return W_VIEW(w)->size.width;
1120 unsigned int
1121 WMWidgetHeight(WMWidget *w)
1123 return W_VIEW(w)->size.height;
1127 Window
1128 WMWidgetXID(WMWidget *w)
1130 return W_VIEW(w)->window;
1134 WMScreen*
1135 WMWidgetScreen(WMWidget *w)
1137 return W_VIEW(w)->screen;
1142 void
1143 WMScreenMainLoop(WMScreen *scr)
1145 XEvent event;
1147 while (1) {
1148 WMNextEvent(scr->display, &event);
1149 WMHandleEvent(&event);
1154 void
1155 WMBreakModalLoop(WMScreen *scr)
1157 scr->modalLoop = 0;
1161 void
1162 WMRunModalLoop(WMScreen *scr, WMView *view)
1164 /* why is scr passed if is determined from the view? */
1165 /*WMScreen *scr = view->screen;*/
1166 int oldModalLoop = scr->modalLoop;
1167 WMView *oldModalView = scr->modalView;
1169 scr->modalView = view;
1171 scr->modalLoop = 1;
1172 while (scr->modalLoop) {
1173 XEvent event;
1175 WMNextEvent(scr->display, &event);
1176 WMHandleEvent(&event);
1179 scr->modalView = oldModalView;
1180 scr->modalLoop = oldModalLoop;
1184 Display*
1185 WMScreenDisplay(WMScreen *scr)
1187 return scr->display;
1192 WMScreenDepth(WMScreen *scr)
1194 return scr->depth;
1198 unsigned int
1199 WMScreenWidth(WMScreen *scr)
1201 return scr->rootView->size.width;
1205 unsigned int
1206 WMScreenHeight(WMScreen *scr)
1208 return scr->rootView->size.height;
1212 void
1213 WMRedisplayWidget(WMWidget *w)
1215 W_RedisplayView(W_VIEW(w));