- updated code to use the new runmodal loop where necessary.
[wmaker-crm.git] / WINGs / widgets.c
blob8feae066e968377e0f0060c663d2c248495f7d87
3 #include "WINGsP.h"
5 #include <X11/Xutil.h>
7 #include <X11/cursorfont.h>
9 /********** data ************/
12 #define CHECK_BUTTON_ON_WIDTH 16
13 #define CHECK_BUTTON_ON_HEIGHT 16
15 static char *CHECK_BUTTON_ON[] = {
16 " %",
17 " .............%#",
18 " ........... .%#",
19 " .......... #.%#",
20 " ......... #%.%#",
21 " ........ #%..%#",
22 " ... #.. #%...%#",
23 " ... #% #%....%#",
24 " ... % #%.....%#",
25 " ... #%......%#",
26 " ... #%.......%#",
27 " ...#%........%#",
28 " .............%#",
29 " .............%#",
30 " %%%%%%%%%%%%%%#",
31 "%###############"};
33 #define CHECK_BUTTON_OFF_WIDTH 16
34 #define CHECK_BUTTON_OFF_HEIGHT 16
36 static char *CHECK_BUTTON_OFF[] = {
37 " %",
38 " .............%#",
39 " .............%#",
40 " .............%#",
41 " .............%#",
42 " .............%#",
43 " .............%#",
44 " .............%#",
45 " .............%#",
46 " .............%#",
47 " .............%#",
48 " .............%#",
49 " .............%#",
50 " .............%#",
51 " %%%%%%%%%%%%%%#",
52 "%###############"};
54 #define RADIO_BUTTON_ON_WIDTH 15
55 #define RADIO_BUTTON_ON_HEIGHT 15
56 static char *RADIO_BUTTON_ON[] = {
57 ".....%%%%%.....",
58 "...%%#####%%...",
59 "..%##.....%.%..",
60 ".%#%.. .....",
61 ".%#. ...",
62 "%#.. .. ",
63 "%#. . ",
64 "%#. . ",
65 "%#. . ",
66 "%#. . ",
67 ".%%. . .",
68 ".%.. . .",
69 "..%... .. ..",
70 ".... ..... ...",
71 "..... .....",
74 #define RADIO_BUTTON_OFF_WIDTH 15
75 #define RADIO_BUTTON_OFF_HEIGHT 15
76 static char *RADIO_BUTTON_OFF[] = {
77 ".....%%%%%.....",
78 "...%%#####%%...",
79 "..%##.......%..",
80 ".%#%...........",
81 ".%#............",
82 "%#............ ",
83 "%#............ ",
84 "%#............ ",
85 "%#............ ",
86 "%#............ ",
87 ".%%.......... .",
88 ".%........... .",
89 "..%......... ..",
90 ".... ..... ...",
91 "..... .....",
95 static char *BUTTON_ARROW[] = {
96 "..................",
97 "....##....#### ...",
98 "...#.%....#... ...",
99 "..#..%#####... ...",
100 ".#............ ...",
101 "#............. ...",
102 ".#............ ...",
103 "..#.. ...",
104 "...#. ............",
105 "....# ............"
108 #define BUTTON_ARROW_WIDTH 18
109 #define BUTTON_ARROW_HEIGHT 10
112 static char *BUTTON_ARROW2[] = {
113 " ",
114 " ## ####. ",
115 " # % # . ",
116 " # %##### . ",
117 " # . ",
118 "# . ",
119 " # . ",
120 " # .......... ",
121 " # . ",
122 " #. "
125 #define BUTTON_ARROW2_WIDTH 18
126 #define BUTTON_ARROW2_HEIGHT 10
129 static char *SCROLLER_DIMPLE[] = {
130 ".%###.",
131 "%#%%%%",
132 "#%%...",
133 "#%.. ",
134 "#%. ",
135 ".%. ."
138 #define SCROLLER_DIMPLE_WIDTH 6
139 #define SCROLLER_DIMPLE_HEIGHT 6
142 static char *SCROLLER_ARROW_UP[] = {
143 "....%....",
144 "....#....",
145 "...%#%...",
146 "...###...",
147 "..%###%..",
148 "..#####..",
149 ".%#####%.",
150 ".#######.",
151 "%#######%"
154 static char *HI_SCROLLER_ARROW_UP[] = {
155 " % ",
156 " % ",
157 " %%% ",
158 " %%% ",
159 " %%%%% ",
160 " %%%%% ",
161 " %%%%%%% ",
162 " %%%%%%% ",
163 "%%%%%%%%%"
166 #define SCROLLER_ARROW_UP_WIDTH 9
167 #define SCROLLER_ARROW_UP_HEIGHT 9
170 static char *SCROLLER_ARROW_DOWN[] = {
171 "%#######%",
172 ".#######.",
173 ".%#####%.",
174 "..#####..",
175 "..%###%..",
176 "...###...",
177 "...%#%...",
178 "....#....",
179 "....%...."
182 static char *HI_SCROLLER_ARROW_DOWN[] = {
183 "%%%%%%%%%",
184 " %%%%%%% ",
185 " %%%%%%% ",
186 " %%%%% ",
187 " %%%%% ",
188 " %%% ",
189 " %%% ",
190 " % ",
191 " % "
194 #define SCROLLER_ARROW_DOWN_WIDTH 9
195 #define SCROLLER_ARROW_DOWN_HEIGHT 9
199 static char *SCROLLER_ARROW_LEFT[] = {
200 "........%",
201 "......%##",
202 "....%####",
203 "..%######",
204 "%########",
205 "..%######",
206 "....%####",
207 "......%##",
208 "........%"
211 static char *HI_SCROLLER_ARROW_LEFT[] = {
212 " %",
213 " %%%",
214 " %%%%%",
215 " %%%%%%%",
216 "%%%%%%%%%",
217 " %%%%%%%",
218 " %%%%%",
219 " %%%",
220 " %"
223 #define SCROLLER_ARROW_LEFT_WIDTH 9
224 #define SCROLLER_ARROW_LEFT_HEIGHT 9
227 static char *SCROLLER_ARROW_RIGHT[] = {
228 "%........",
229 "##%......",
230 "####%....",
231 "######%..",
232 "########%",
233 "######%..",
234 "####%....",
235 "##%......",
236 "%........"
239 static char *HI_SCROLLER_ARROW_RIGHT[] = {
240 "% ",
241 "%%% ",
242 "%%%%% ",
243 "%%%%%%% ",
244 "%%%%%%%%%",
245 "%%%%%%% ",
246 "%%%%% ",
247 "%%% ",
248 "% "
251 #define SCROLLER_ARROW_RIGHT_WIDTH 9
252 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
255 static char *POPUP_INDICATOR[] = {
256 " #==",
257 " ......%#==",
258 " ......%#%%",
259 " ......%#%%",
260 " %%%%%%%#%%",
261 "#########%%",
262 "==%%%%%%%%%",
263 "==%%%%%%%%%"
266 #define POPUP_INDICATOR_WIDTH 11
267 #define POPUP_INDICATOR_HEIGHT 8
271 static char *PULLDOWN_INDICATOR[] = {
272 "=#######=",
273 "=%===== =",
274 "==%=== ==",
275 "==%=== ==",
276 "===%= ===",
277 "===%= ===",
278 "====%===="
280 #define PULLDOWN_INDICATOR_WIDTH 9
281 #define PULLDOWN_INDICATOR_HEIGHT 7
284 #define CHECK_MARK_WIDTH 8
285 #define CHECK_MARK_HEIGHT 10
287 static char *CHECK_MARK[] = {
288 "======== ",
289 "======= #",
290 "====== #%",
291 "===== #%=",
292 " #== #%==",
293 " #% #%===",
294 " % #%====",
295 " #%=====",
296 " #%======",
297 "#%======="};
300 #define STIPPLE_WIDTH 8
301 #define STIPPLE_HEIGHT 8
302 static unsigned char STIPPLE_BITS[] = {
303 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa
309 extern void W_ReadConfigurations(void);
312 static int userWidgetCount=0;
315 /***** end data ******/
318 static void
319 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
320 int width, int height)
322 int x, y;
323 GC whiteGC = WMColorGC(screen->white);
324 GC blackGC = WMColorGC(screen->black);
325 GC lightGC = WMColorGC(screen->gray);
326 GC darkGC = WMColorGC(screen->darkGray);
329 if (mask)
330 XSetForeground(screen->display, screen->monoGC, 0);
332 for (y = 0; y < height; y++) {
333 for (x = 0; x < width; x++) {
334 switch (data[y][x]) {
335 case ' ':
336 case 'w':
337 XDrawPoint(screen->display, d, whiteGC, x, y);
338 break;
340 case '=':
341 if (mask)
342 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
344 case '.':
345 case 'l':
346 XDrawPoint(screen->display, d, lightGC, x, y);
347 break;
349 case '%':
350 case 'd':
351 XDrawPoint(screen->display, d, darkGC, x, y);
352 break;
354 case '#':
355 case 'b':
356 default:
357 XDrawPoint(screen->display, d, blackGC, x, y);
358 break;
366 static WMPixmap*
367 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
369 Pixmap pixmap, mask = None;
371 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
372 sPtr->depth);
374 if (masked) {
375 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
376 XSetForeground(sPtr->display, sPtr->monoGC, 1);
377 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
380 renderPixmap(sPtr, pixmap, mask, data, width, height);
382 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
383 sPtr->depth);
387 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
388 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
390 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
391 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
394 static Bool
395 loadPixmaps(WMScreen *scr)
397 RImage *image, *tmp;
398 RColor gray;
399 RColor white;
401 gray.red = 0xae;
402 gray.green = 0xaa;
403 gray.blue = 0xae;
405 white.red = 0xff;
406 white.green = 0xff;
407 white.blue = 0xff;
409 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
410 if (!image)
411 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
412 if (!image) {
413 wwarning("WINGs: could not load widget images file: %s",
414 RMessageForError(RErrorCode));
415 return False;
417 /* home icon */
418 /* make it have a gray background */
419 tmp = RGetSubImage(image, 0, 0, 24, 24);
420 RCombineImageWithColor(tmp, &gray);
421 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
422 RDestroyImage(tmp);
423 /* make it have a white background */
424 tmp = RGetSubImage(image, 0, 0, 24, 24);
425 RCombineImageWithColor(tmp, &white);
426 scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
427 RDestroyImage(tmp);
429 /* trash can */
430 tmp = RGetSubImage(image, 104, 0, 24, 24);
431 RCombineImageWithColor(tmp, &white);
432 scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
433 RDestroyImage(tmp);
434 tmp = RGetSubImage(image, 104, 0, 24, 24);
435 RCombineImageWithColor(tmp, &white);
436 scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
437 RDestroyImage(tmp);
438 /* create dir */
439 tmp = RGetSubImage(image, 104, 24, 24, 24);
440 RCombineImageWithColor(tmp, &white);
441 scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
442 RDestroyImage(tmp);
443 tmp = RGetSubImage(image, 104, 24, 24, 24);
444 RCombineImageWithColor(tmp, &white);
445 scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
446 RDestroyImage(tmp);
447 /* diskettes */
448 tmp = RGetSubImage(image, 24, 80, 24, 24);
449 RCombineImageWithColor(tmp, &white);
450 scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
451 RDestroyImage(tmp);
452 tmp = RGetSubImage(image, 24, 80, 24, 24);
453 RCombineImageWithColor(tmp, &white);
454 scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
455 RDestroyImage(tmp);
456 /* unmount */
457 tmp = RGetSubImage(image, 0, 80, 24, 24);
458 RCombineImageWithColor(tmp, &white);
459 scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
460 RDestroyImage(tmp);
461 tmp = RGetSubImage(image, 0, 80, 24, 24);
462 RCombineImageWithColor(tmp, &white);
463 scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
464 RDestroyImage(tmp);
466 /* Magnifying Glass Icon for ColorPanel */
467 tmp = RGetSubImage(image, 24, 0, 40, 32);
468 RCombineImageWithColor(tmp, &gray);
469 scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
470 RDestroyImage(tmp);
471 /* ColorWheel Icon for ColorPanel */
472 tmp = RGetSubImage(image, 0, 25, 24, 24);
473 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
474 RDestroyImage(tmp);
475 /* GrayScale Icon for ColorPanel */
476 tmp = RGetSubImage(image, 65, 0, 40, 24);
477 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
478 RDestroyImage(tmp);
479 /* RGB Icon for ColorPanel */
480 tmp = RGetSubImage(image, 25, 33, 40, 24);
481 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
482 RDestroyImage(tmp);
483 /* CMYK Icon for ColorPanel */
484 tmp = RGetSubImage(image, 65, 25, 40, 24);
485 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
486 RDestroyImage(tmp);
487 /* HSB Icon for ColorPanel */
488 tmp = RGetSubImage(image, 0, 57, 40, 24);
489 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
490 RDestroyImage(tmp);
491 /* CustomColorPalette Icon for ColorPanel */
492 tmp = RGetSubImage(image, 81, 57, 40, 24);
493 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
494 RDestroyImage(tmp);
495 /* ColorList Icon for ColorPanel */
496 tmp = RGetSubImage(image, 41, 57, 40, 24);
497 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
498 RDestroyImage(tmp);
500 RDestroyImage(image);
502 #if 0
503 scr->defaultObjectIcon =
504 WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
505 if (!scr->defaultObjectIcon) {
506 scr->defaultObjectIcon =
507 WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
509 if (!scr->defaultObjectIcon) {
510 wwarning("WINGs: could not load default icon file");
511 return False;
513 #endif
514 return True;
519 WMScreen*
520 WMCreateSimpleApplicationScreen(Display *display)
522 WMScreen *scr;
524 scr = WMCreateScreen(display, DefaultScreen(display));
526 scr->aflags.hasAppIcon = 0;
527 scr->aflags.simpleApplication = 1;
529 return scr;
534 WMScreen*
535 WMCreateScreen(Display *display, int screen)
537 return WMCreateScreenWithRContext(display, screen,
538 RCreateContext(display, screen, NULL));
542 WMScreen*
543 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
545 W_Screen *scrPtr;
546 XGCValues gcv;
547 Pixmap stipple;
548 static int initialized = 0;
549 static char *atomNames[] = {
550 "_GNUSTEP_WM_ATTR",
551 "WM_DELETE_WINDOW",
552 "WM_PROTOCOLS",
553 "CLIPBOARD",
554 "XdndAware",
555 "XdndSelection",
556 "XdndEnter",
557 "XdndLeave",
558 "XdndPosition",
559 "XdndDrop",
560 "XdndFinished",
561 "XdndTypeList",
562 "XdndActionCopy",
563 "XdndActionMove",
564 "XdndActionLink",
565 "XdndActionAsk",
566 "XdndActionPrivate",
567 "XdndStatus",
568 "_WINGS_DND_MOUSE_OFFSET",
569 "WM_STATE"
571 Atom atoms[sizeof(atomNames)/sizeof(char*)];
572 int i = 0;
574 if (!initialized) {
576 initialized = 1;
578 W_ReadConfigurations();
580 assert(W_ApplicationInitialized());
583 scrPtr = malloc(sizeof(W_Screen));
584 if (!scrPtr)
585 return NULL;
586 memset(scrPtr, 0, sizeof(W_Screen));
588 scrPtr->aflags.hasAppIcon = 1;
590 scrPtr->display = display;
591 scrPtr->screen = screen;
592 scrPtr->rcontext = context;
594 scrPtr->depth = context->depth;
596 scrPtr->visual = context->visual;
597 scrPtr->lastEventTime = 0;
599 scrPtr->colormap = context->cmap;
601 scrPtr->rootWin = RootWindow(display, screen);
603 scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
605 /* initially allocate some colors */
606 WMWhiteColor(scrPtr);
607 WMBlackColor(scrPtr);
608 WMGrayColor(scrPtr);
609 WMDarkGrayColor(scrPtr);
611 gcv.graphics_exposures = False;
613 gcv.function = GXxor;
614 gcv.foreground = W_PIXEL(scrPtr->white);
615 if (gcv.foreground == 0) gcv.foreground = 1;
616 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
617 |GCGraphicsExposures|GCForeground, &gcv);
619 gcv.function = GXxor;
620 gcv.foreground = W_PIXEL(scrPtr->gray);
621 gcv.subwindow_mode = IncludeInferiors;
622 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
623 |GCGraphicsExposures|GCForeground
624 |GCSubwindowMode, &gcv);
626 gcv.function = GXcopy;
627 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
628 |GCGraphicsExposures, &gcv);
630 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
631 |GCGraphicsExposures, &gcv);
634 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
635 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
636 gcv.foreground = W_PIXEL(scrPtr->darkGray);
637 gcv.background = W_PIXEL(scrPtr->gray);
638 gcv.fill_style = FillStippled;
639 gcv.stipple = stipple;
640 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
641 GCForeground|GCBackground|GCStipple
642 |GCFillStyle|GCGraphicsExposures, &gcv);
644 gcv.foreground = W_PIXEL(scrPtr->black);
645 gcv.background = W_PIXEL(scrPtr->white);
646 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
647 GCForeground|GCBackground, &gcv);
649 /* we need a 1bpp drawable for the monoGC, so borrow this one */
650 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
652 scrPtr->stipple = stipple;
654 scrPtr->useMultiByte = WINGsConfiguration.useMultiByte;
656 scrPtr->normalFont = WMSystemFontOfSize(scrPtr,
657 WINGsConfiguration.defaultFontSize);
659 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr,
660 WINGsConfiguration.defaultFontSize);
662 if (!scrPtr->boldFont)
663 scrPtr->boldFont = scrPtr->normalFont;
665 if (!scrPtr->normalFont) {
666 wwarning("could not load any fonts. Make sure your font installation"
667 "and locale settings are correct.");
669 return NULL;
672 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
673 CHECK_BUTTON_ON_WIDTH,
674 CHECK_BUTTON_ON_HEIGHT, False);
676 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
677 CHECK_BUTTON_OFF_WIDTH,
678 CHECK_BUTTON_OFF_HEIGHT, False);
680 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
681 RADIO_BUTTON_ON_WIDTH,
682 RADIO_BUTTON_ON_HEIGHT, False);
684 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
685 RADIO_BUTTON_OFF_WIDTH,
686 RADIO_BUTTON_OFF_HEIGHT, False);
688 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
689 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
690 False);
692 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
693 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
694 False);
697 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
698 SCROLLER_DIMPLE_WIDTH,
699 SCROLLER_DIMPLE_HEIGHT, False);
702 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
703 SCROLLER_ARROW_UP_WIDTH,
704 SCROLLER_ARROW_UP_HEIGHT, True);
706 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
707 SCROLLER_ARROW_DOWN_WIDTH,
708 SCROLLER_ARROW_DOWN_HEIGHT, True);
710 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
711 SCROLLER_ARROW_LEFT_WIDTH,
712 SCROLLER_ARROW_LEFT_HEIGHT, True);
714 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
715 SCROLLER_ARROW_RIGHT_WIDTH,
716 SCROLLER_ARROW_RIGHT_HEIGHT, True);
718 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
719 SCROLLER_ARROW_UP_WIDTH,
720 SCROLLER_ARROW_UP_HEIGHT, True);
722 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
723 SCROLLER_ARROW_DOWN_WIDTH,
724 SCROLLER_ARROW_DOWN_HEIGHT, True);
726 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
727 SCROLLER_ARROW_LEFT_WIDTH,
728 SCROLLER_ARROW_LEFT_HEIGHT, True);
730 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
731 SCROLLER_ARROW_RIGHT_WIDTH,
732 SCROLLER_ARROW_RIGHT_HEIGHT, True);
734 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
735 POPUP_INDICATOR_WIDTH,
736 POPUP_INDICATOR_HEIGHT, True);
738 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
739 PULLDOWN_INDICATOR_WIDTH,
740 PULLDOWN_INDICATOR_HEIGHT, True);
742 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
743 CHECK_MARK_WIDTH,
744 CHECK_MARK_HEIGHT, True);
746 loadPixmaps(scrPtr);
748 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
750 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
753 XColor bla;
754 Pixmap blank;
756 blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
757 XSetForeground(display, scrPtr->monoGC, 0);
758 XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
760 scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
761 &bla, &bla, 0, 0);
762 XFreePixmap(display, blank);
765 #ifdef HAVE_XINTERNATOMS
766 XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
767 atoms);
768 #else
770 int i;
771 for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
772 atoms[i] = XInternAtom(display, atomNames[i], False);
775 #endif
777 i = 0;
778 scrPtr->attribsAtom = atoms[i++];
780 scrPtr->deleteWindowAtom = atoms[i++];
782 scrPtr->protocolsAtom = atoms[i++];
784 scrPtr->clipboardAtom = atoms[i++];
786 scrPtr->xdndAwareAtom = atoms[i++];
787 scrPtr->xdndSelectionAtom = atoms[i++];
788 scrPtr->xdndEnterAtom = atoms[i++];
789 scrPtr->xdndLeaveAtom = atoms[i++];
790 scrPtr->xdndPositionAtom = atoms[i++];
791 scrPtr->xdndDropAtom = atoms[i++];
792 scrPtr->xdndFinishedAtom = atoms[i++];
793 scrPtr->xdndTypeListAtom = atoms[i++];
794 scrPtr->xdndStatusAtom = atoms[i++];
796 scrPtr->xdndActionCopy = atoms[i++];
797 scrPtr->xdndActionMove = atoms[i++];
798 scrPtr->xdndActionLink = atoms[i++];
799 scrPtr->xdndActionAsk = atoms[i++];
800 scrPtr->xdndActionPrivate = atoms[i++];
802 scrPtr->wmIconDragOffsetAtom = atoms[i++];
804 scrPtr->wmStateAtom = atoms[i++];
806 scrPtr->rootView = W_CreateRootView(scrPtr);
809 scrPtr->balloon = W_CreateBalloon(scrPtr);
812 W_InitApplication(scrPtr);
814 return scrPtr;
819 void
820 WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font)
822 WMReleaseFont(scr->normalFont);
823 scr->normalFont = WMRetainFont(font);
827 void
828 WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font)
830 WMReleaseFont(scr->boldFont);
831 scr->boldFont = WMRetainFont(font);
836 void
837 WMHangData(WMWidget *widget, void *data)
839 W_VIEW(widget)->hangedData = data;
843 void*
844 WMGetHangedData(WMWidget *widget)
846 return W_VIEW(widget)->hangedData;
851 void
852 WMDestroyWidget(WMWidget *widget)
854 W_UnmapView(W_VIEW(widget));
855 W_DestroyView(W_VIEW(widget));
859 void
860 WMSetFocusToWidget(WMWidget *widget)
862 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
867 * WMRealizeWidget-
868 * Realizes the widget and all it's children.
871 void
872 WMRealizeWidget(WMWidget *w)
874 W_RealizeView(W_VIEW(w));
877 void
878 WMMapWidget(WMWidget *w)
880 W_MapView(W_VIEW(w));
884 void
885 WMReparentWidget(WMWidget *w, WMWidget *newParent, int x, int y)
887 W_ReparentView(W_VIEW(w), newParent, x, y);
891 static void
892 makeChildrenAutomap(W_View *view, int flag)
894 view = view->childrenList;
896 while (view) {
897 view->flags.mapWhenRealized = flag;
898 makeChildrenAutomap(view, flag);
900 view = view->nextSister;
905 void
906 WMMapSubwidgets(WMWidget *w)
908 /* make sure that subwidgets created after the parent was realized
909 * are mapped too */
910 if (!W_VIEW(w)->flags.realized) {
911 makeChildrenAutomap(W_VIEW(w), True);
912 } else {
913 W_MapSubviews(W_VIEW(w));
918 void
919 WMUnmapSubwidgets(WMWidget *w)
921 if (!W_VIEW(w)->flags.realized) {
922 makeChildrenAutomap(W_VIEW(w), False);
923 } else {
924 W_UnmapSubviews(W_VIEW(w));
930 void
931 WMUnmapWidget(WMWidget *w)
933 W_UnmapView(W_VIEW(w));
937 Bool
938 WMWidgetIsMapped(WMWidget *w)
940 return W_VIEW(w)->flags.mapped;
944 void
945 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
947 W_SetViewBackgroundColor(W_VIEW(w), color);
948 if (W_VIEW(w)->flags.mapped)
949 WMRedisplayWidget(w);
953 void
954 WMRaiseWidget(WMWidget *w)
956 W_RaiseView(W_VIEW(w));
960 void
961 WMLowerWidget(WMWidget *w)
963 W_LowerView(W_VIEW(w));
967 void
968 WMMoveWidget(WMWidget *w, int x, int y)
970 W_MoveView(W_VIEW(w), x, y);
974 void
975 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
977 W_ResizeView(W_VIEW(w), width, height);
982 W_Class
983 W_RegisterUserWidget(void)
985 userWidgetCount++;
987 return userWidgetCount + WC_UserWidget - 1;
992 RContext*
993 WMScreenRContext(WMScreen *scr)
995 return scr->rcontext;
1000 unsigned int
1001 WMWidgetWidth(WMWidget *w)
1003 return W_VIEW(w)->size.width;
1007 unsigned int
1008 WMWidgetHeight(WMWidget *w)
1010 return W_VIEW(w)->size.height;
1014 Window
1015 WMWidgetXID(WMWidget *w)
1017 return W_VIEW(w)->window;
1021 WMScreen*
1022 WMWidgetScreen(WMWidget *w)
1024 return W_VIEW(w)->screen;
1029 void
1030 WMScreenMainLoop(WMScreen *scr)
1032 XEvent event;
1034 while (1) {
1035 WMNextEvent(scr->display, &event);
1036 WMHandleEvent(&event);
1041 void
1042 WMBreakModalLoop(WMScreen *scr)
1044 scr->modalLoop = 0;
1048 void
1049 WMRunModalLoop(WMScreen *scr, WMView *view)
1051 /* why is scr passed if is determined from the view? */
1052 /*WMScreen *scr = view->screen;*/
1053 int oldModalLoop = scr->modalLoop;
1054 WMView *oldModalView = scr->modalView;
1056 scr->modalView = view;
1058 scr->modalLoop = 1;
1059 while (scr->modalLoop) {
1060 XEvent event;
1062 WMNextEvent(scr->display, &event);
1063 WMHandleEvent(&event);
1066 scr->modalView = oldModalView;
1067 scr->modalLoop = oldModalLoop;
1071 Display*
1072 WMScreenDisplay(WMScreen *scr)
1074 return scr->display;
1078 int
1079 WMScreenDepth(WMScreen *scr)
1081 return scr->depth;
1085 unsigned int
1086 WMScreenWidth(WMScreen *scr)
1088 return scr->rootView->size.width;
1092 unsigned int
1093 WMScreenHeight(WMScreen *scr)
1095 return scr->rootView->size.height;
1099 void
1100 WMRedisplayWidget(WMWidget *w)
1102 W_RedisplayView(W_VIEW(w));