- made deiconification not automatically focus window in sloppy focus
[wmaker-crm.git] / WINGs / widgets.c
bloba1e88542bedfaa094c11692e190e092b8f5f47d5
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 2
301 #define STIPPLE_HEIGHT 2
302 static unsigned char STIPPLE_BITS[] = {0x01, 0x02};
305 extern void W_ReadConfigurations(void);
308 extern W_ViewProcedureTable _WindowViewProcedures;
309 extern W_ViewProcedureTable _FrameViewProcedures;
310 extern W_ViewProcedureTable _LabelViewProcedures;
311 extern W_ViewProcedureTable _ButtonViewProcedures;
312 extern W_ViewProcedureTable _TextFieldViewProcedures;
313 extern W_ViewProcedureTable _ScrollerViewProcedures;
314 extern W_ViewProcedureTable _ScrollViewProcedures;
315 extern W_ViewProcedureTable _ListViewProcedures;
316 extern W_ViewProcedureTable _BrowserViewProcedures;
317 extern W_ViewProcedureTable _PopUpButtonViewProcedures;
318 extern W_ViewProcedureTable _ColorWellViewProcedures;
319 extern W_ViewProcedureTable _ScrollViewViewProcedures;
320 extern W_ViewProcedureTable _SliderViewProcedures;
321 extern W_ViewProcedureTable _SplitViewViewProcedures;
324 * All widget classes defined must have an entry here.
326 static W_ViewProcedureTable *procedureTables[16];
328 static W_ViewProcedureTable **userProcedureTable = NULL;
329 static int userWidgetCount=0;
332 /***** end data ******/
336 static void
337 initProcedureTable()
339 procedureTables[WC_Window] = &_WindowViewProcedures;
340 procedureTables[WC_Frame] = &_FrameViewProcedures;
341 procedureTables[WC_Label] = &_LabelViewProcedures;
342 procedureTables[WC_Button] = &_ButtonViewProcedures;
343 procedureTables[WC_TextField] = &_TextFieldViewProcedures;
344 procedureTables[WC_Scroller] = &_ScrollerViewProcedures;
345 procedureTables[WC_List] = &_ListViewProcedures;
346 procedureTables[WC_Browser] = &_BrowserViewProcedures;
347 procedureTables[WC_PopUpButton] = &_PopUpButtonViewProcedures;
348 procedureTables[WC_ColorWell] = &_ColorWellViewProcedures;
349 procedureTables[WC_ScrollView] = &_ScrollViewViewProcedures;
350 procedureTables[WC_Slider] = &_SliderViewProcedures;
351 procedureTables[WC_SplitView] = &_SplitViewViewProcedures;
355 static void
356 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
357 int width, int height)
359 int x, y;
360 GC whiteGC = WMColorGC(screen->white);
361 GC blackGC = WMColorGC(screen->black);
362 GC lightGC = WMColorGC(screen->gray);
363 GC darkGC = WMColorGC(screen->darkGray);
366 if (mask)
367 XSetForeground(screen->display, screen->monoGC, 0);
369 for (y = 0; y < height; y++) {
370 for (x = 0; x < width; x++) {
371 switch (data[y][x]) {
372 case ' ':
373 case 'w':
374 XDrawPoint(screen->display, d, whiteGC, x, y);
375 break;
377 case '=':
378 if (mask)
379 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
381 case '.':
382 case 'l':
383 XDrawPoint(screen->display, d, lightGC, x, y);
384 break;
386 case '%':
387 case 'd':
388 XDrawPoint(screen->display, d, darkGC, x, y);
389 break;
391 case '#':
392 case 'b':
393 default:
394 XDrawPoint(screen->display, d, blackGC, x, y);
395 break;
403 static WMPixmap*
404 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
406 Pixmap pixmap, mask = None;
408 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
409 sPtr->depth);
411 if (masked) {
412 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
413 XSetForeground(sPtr->display, sPtr->monoGC, 1);
414 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
417 renderPixmap(sPtr, pixmap, mask, data, width, height);
419 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
420 sPtr->depth);
424 #define T_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
425 #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
427 #define X_WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
428 #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
431 static Bool
432 loadPixmaps(WMScreen *scr)
434 RImage *image, *tmp;
435 RColor gray;
436 RColor white;
438 gray.red = 0xae;
439 gray.green = 0xaa;
440 gray.blue = 0xae;
442 white.red = 0xff;
443 white.green = 0xff;
444 white.blue = 0xff;
446 image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
447 if (!image)
448 image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
449 if (!image) {
450 wwarning("WINGs: could not load widget images file: %s",
451 RMessageForError(RErrorCode));
452 return False;
454 /* home icon */
455 /* make it have a gray background */
456 tmp = RGetSubImage(image, 0, 0, 24, 24);
457 RCombineImageWithColor(tmp, &gray);
458 scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
459 RDestroyImage(tmp);
460 /* make it have a white background */
461 tmp = RGetSubImage(image, 0, 0, 24, 24);
462 RCombineImageWithColor(tmp, &white);
463 scr->altHomeIcon = 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 tmp = RGetSubImage(image, 24, 0, 40, 32);
472 RCombineImageWithColor(tmp, &white);
473 scr->altMagnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
474 RDestroyImage(tmp);
475 /* ColorWheel Icon for ColorPanel */
476 tmp = RGetSubImage(image, 0, 25, 24, 24);
477 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
478 RDestroyImage(tmp);
479 /* GrayScale Icon for ColorPanel */
480 tmp = RGetSubImage(image, 65, 0, 40, 24);
481 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
482 RDestroyImage(tmp);
483 /* RGB Icon for ColorPanel */
484 tmp = RGetSubImage(image, 25, 33, 40, 24);
485 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
486 RDestroyImage(tmp);
487 /* CMYK Icon for ColorPanel */
488 tmp = RGetSubImage(image, 65, 25, 40, 24);
489 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
490 RDestroyImage(tmp);
491 /* HSB Icon for ColorPanel */
492 tmp = RGetSubImage(image, 0, 57, 40, 24);
493 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
494 RDestroyImage(tmp);
495 /* CustomColorPalette Icon for ColorPanel */
496 tmp = RGetSubImage(image, 81, 57, 40, 24);
497 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
498 RDestroyImage(tmp);
499 /* ColorList Icon for ColorPanel */
500 tmp = RGetSubImage(image, 41, 57, 40, 24);
501 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
502 RDestroyImage(tmp);
504 RDestroyImage(image);
506 #if 0
507 scr->defaultObjectIcon =
508 WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
509 if (!scr->defaultObjectIcon) {
510 scr->defaultObjectIcon =
511 WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
513 if (!scr->defaultObjectIcon) {
514 wwarning("WINGs: could not load default icon file");
515 return False;
517 #endif
518 return True;
523 WMScreen*
524 WMCreateSimpleApplicationScreen(Display *display)
526 WMScreen *scr;
528 scr = WMCreateScreen(display, DefaultScreen(display));
530 scr->aflags.hasAppIcon = 0;
531 scr->aflags.simpleApplication = 1;
533 return scr;
538 WMScreen*
539 WMCreateScreen(Display *display, int screen)
541 return WMCreateScreenWithRContext(display, screen,
542 RCreateContext(display, screen, NULL));
546 WMScreen*
547 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
549 W_Screen *scrPtr;
550 XGCValues gcv;
551 Pixmap stipple;
552 static int initialized = 0;
554 if (!initialized) {
556 initialized = 1;
558 initProcedureTable();
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 /* initially allocate some colors */
588 WMWhiteColor(scrPtr);
589 WMBlackColor(scrPtr);
590 WMGrayColor(scrPtr);
591 WMDarkGrayColor(scrPtr);
593 gcv.graphics_exposures = False;
595 gcv.function = GXxor;
596 gcv.foreground = W_PIXEL(scrPtr->white);
597 if (gcv.foreground == 0) gcv.foreground = 1;
598 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
599 |GCGraphicsExposures|GCForeground, &gcv);
601 gcv.function = GXxor;
602 gcv.foreground = W_PIXEL(scrPtr->gray);
603 gcv.subwindow_mode = IncludeInferiors;
604 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
605 |GCGraphicsExposures|GCForeground
606 |GCSubwindowMode, &gcv);
608 gcv.function = GXcopy;
609 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
610 |GCGraphicsExposures, &gcv);
612 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
613 |GCGraphicsExposures, &gcv);
616 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
617 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
618 gcv.foreground = W_PIXEL(scrPtr->darkGray);
619 gcv.background = W_PIXEL(scrPtr->gray);
620 gcv.fill_style = FillStippled;
621 gcv.stipple = stipple;
622 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
623 GCForeground|GCBackground|GCStipple
624 |GCFillStyle|GCGraphicsExposures, &gcv);
626 gcv.foreground = W_PIXEL(scrPtr->black);
627 gcv.background = W_PIXEL(scrPtr->white);
628 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
629 GCForeground|GCBackground, &gcv);
631 /* we need a 1bpp drawable for the monoGC, so borrow this one */
632 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
634 scrPtr->stipple = stipple;
636 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 12);
638 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 12);
640 if (!scrPtr->boldFont)
641 scrPtr->boldFont = scrPtr->normalFont;
643 if (!scrPtr->normalFont) {
644 wwarning("could not load any fonts. Make sure your font installation"
645 "and locale settings are correct.");
647 return NULL;
650 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
651 CHECK_BUTTON_ON_WIDTH,
652 CHECK_BUTTON_ON_HEIGHT, False);
654 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
655 CHECK_BUTTON_OFF_WIDTH,
656 CHECK_BUTTON_OFF_HEIGHT, False);
658 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
659 RADIO_BUTTON_ON_WIDTH,
660 RADIO_BUTTON_ON_HEIGHT, False);
662 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
663 RADIO_BUTTON_OFF_WIDTH,
664 RADIO_BUTTON_OFF_HEIGHT, False);
666 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
667 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
668 False);
670 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
671 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
672 False);
675 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
676 SCROLLER_DIMPLE_WIDTH,
677 SCROLLER_DIMPLE_HEIGHT, False);
680 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
681 SCROLLER_ARROW_UP_WIDTH,
682 SCROLLER_ARROW_UP_HEIGHT, True);
684 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
685 SCROLLER_ARROW_DOWN_WIDTH,
686 SCROLLER_ARROW_DOWN_HEIGHT, True);
688 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
689 SCROLLER_ARROW_LEFT_WIDTH,
690 SCROLLER_ARROW_LEFT_HEIGHT, True);
692 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
693 SCROLLER_ARROW_RIGHT_WIDTH,
694 SCROLLER_ARROW_RIGHT_HEIGHT, True);
696 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
697 SCROLLER_ARROW_UP_WIDTH,
698 SCROLLER_ARROW_UP_HEIGHT, True);
700 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
701 SCROLLER_ARROW_DOWN_WIDTH,
702 SCROLLER_ARROW_DOWN_HEIGHT, True);
704 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
705 SCROLLER_ARROW_LEFT_WIDTH,
706 SCROLLER_ARROW_LEFT_HEIGHT, True);
708 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
709 SCROLLER_ARROW_RIGHT_WIDTH,
710 SCROLLER_ARROW_RIGHT_HEIGHT, True);
712 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
713 POPUP_INDICATOR_WIDTH,
714 POPUP_INDICATOR_HEIGHT, True);
716 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
717 PULLDOWN_INDICATOR_WIDTH,
718 PULLDOWN_INDICATOR_HEIGHT, True);
720 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
721 CHECK_MARK_WIDTH,
722 CHECK_MARK_HEIGHT, True);
724 loadPixmaps(scrPtr);
726 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
728 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
730 scrPtr->internalMessage = XInternAtom(display, "_WINGS_MESSAGE", False);
732 scrPtr->attribsAtom = XInternAtom(display, "_GNUSTEP_WM_ATTR", False);
734 scrPtr->deleteWindowAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
736 scrPtr->protocolsAtom = XInternAtom(display, "WM_PROTOCOLS", False);
738 scrPtr->clipboardAtom = XInternAtom(display, "CLIPBOARD", False);
740 scrPtr->rootView = W_CreateRootView(scrPtr);
743 scrPtr->balloon = W_CreateBalloon(scrPtr);
746 W_InitApplication(scrPtr);
748 return scrPtr;
752 void
753 WMHangData(WMWidget *widget, void *data)
755 W_VIEW(widget)->hangedData = data;
759 void*
760 WMGetHangedData(WMWidget *widget)
762 return W_VIEW(widget)->hangedData;
767 void
768 WMDestroyWidget(WMWidget *widget)
770 W_DestroyView(W_VIEW(widget));
774 void
775 WMSetFocusToWidget(WMWidget *widget)
777 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
782 * WMRealizeWidget-
783 * Realizes the widget and all it's children.
786 void
787 WMRealizeWidget(WMWidget *w)
789 W_RealizeView(W_VIEW(w));
792 void
793 WMMapWidget(WMWidget *w)
795 W_MapView(W_VIEW(w));
799 static void
800 makeChildrenAutomap(W_View *view, int flag)
802 view = view->childrenList;
804 while (view) {
805 view->flags.mapWhenRealized = flag;
806 makeChildrenAutomap(view, flag);
808 view = view->nextSister;
813 void
814 WMMapSubwidgets(WMWidget *w)
816 /* make sure that subwidgets created after the parent was realized
817 * are mapped too */
818 if (!W_VIEW(w)->flags.realized) {
819 makeChildrenAutomap(W_VIEW(w), True);
820 } else {
821 W_MapSubviews(W_VIEW(w));
826 void
827 WMUnmapSubwidgets(WMWidget *w)
829 if (!W_VIEW(w)->flags.realized) {
830 makeChildrenAutomap(W_VIEW(w), False);
831 } else {
832 W_UnmapSubviews(W_VIEW(w));
838 void
839 WMUnmapWidget(WMWidget *w)
841 W_UnmapView(W_VIEW(w));
845 void
846 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
848 if (W_CLASS(w) < WC_UserWidget
849 && procedureTables[W_CLASS(w)]->setBackgroundColor) {
851 (*procedureTables[W_CLASS(w)]->setBackgroundColor)(w, color);
853 } else if (W_CLASS(w) >= WC_UserWidget
854 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor) {
856 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor)(w, color);
858 } else {
859 W_SetViewBackgroundColor(W_VIEW(w), color);
864 void
865 WMMoveWidget(WMWidget *w, int x, int y)
867 if (W_CLASS(w) < WC_UserWidget
868 && procedureTables[W_CLASS(w)]->move) {
870 (*procedureTables[W_CLASS(w)]->move)(w, x, y);
872 } else if (W_CLASS(w) >= WC_UserWidget
873 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->move) {
875 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->move)(w, x, y);
877 } else {
878 W_MoveView(W_VIEW(w), x, y);
883 void
884 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
886 if (W_CLASS(w) < WC_UserWidget
887 && procedureTables[W_CLASS(w)]->resize) {
889 (*procedureTables[W_CLASS(w)]->resize)(w, width, height);
891 } else if (W_CLASS(w) >= WC_UserWidget
892 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize) {
894 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize)(w, width, height);
896 } else {
897 W_ResizeView(W_VIEW(w), width, height);
903 W_Class
904 W_RegisterUserWidget(W_ViewProcedureTable *procTable)
906 W_ViewProcedureTable **newTable;
908 userWidgetCount++;
909 newTable = wmalloc(sizeof(W_ViewProcedureTable*)*userWidgetCount);
910 memcpy(newTable, userProcedureTable,
911 sizeof(W_ViewProcedureTable*)*(userWidgetCount-1));
913 newTable[userWidgetCount-1] = procTable;
915 free(userProcedureTable);
917 userProcedureTable = newTable;
919 return userWidgetCount + WC_UserWidget - 1;
924 RContext*
925 WMScreenRContext(WMScreen *scr)
927 return scr->rcontext;
932 unsigned int
933 WMWidgetWidth(WMWidget *w)
935 return W_VIEW(w)->size.width;
939 unsigned int
940 WMWidgetHeight(WMWidget *w)
942 return W_VIEW(w)->size.height;
946 Window
947 WMWidgetXID(WMWidget *w)
949 return W_VIEW(w)->window;
953 WMScreen*
954 WMWidgetScreen(WMWidget *w)
956 return W_VIEW(w)->screen;
961 void
962 WMScreenMainLoop(WMScreen *scr)
964 XEvent event;
966 while (1) {
967 WMNextEvent(scr->display, &event);
968 WMHandleEvent(&event);
974 Display*
975 WMScreenDisplay(WMScreen *scr)
977 return scr->display;
981 int
982 WMScreenDepth(WMScreen *scr)
984 return scr->depth;
988 void
989 WMRedisplayWidget(WMWidget *w)
991 W_RedisplayView(W_VIEW(w));