bug fix for balloons and some other minor things
[wmaker-crm.git] / WINGs / widgets.c
blob8d213d59119765dd2aa82ad8457453ec36b6f399
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);
472 tmp = RGetSubImage(image, 24, 0, 40, 32);
473 RCombineImageWithColor(tmp, &white);
474 scr->altMagnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
475 RDestroyImage(tmp);
477 /* ColorWheel Icon for ColorPanel */
478 tmp = RGetSubImage(image, 0, 25, 24, 24);
479 scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
480 RDestroyImage(tmp);
481 /* GrayScale Icon for ColorPanel */
482 tmp = RGetSubImage(image, 65, 0, 40, 24);
483 scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
484 RDestroyImage(tmp);
485 /* RGB Icon for ColorPanel */
486 tmp = RGetSubImage(image, 25, 33, 40, 24);
487 scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
488 RDestroyImage(tmp);
489 /* CMYK Icon for ColorPanel */
490 tmp = RGetSubImage(image, 65, 25, 40, 24);
491 scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
492 RDestroyImage(tmp);
493 /* HSB Icon for ColorPanel */
494 tmp = RGetSubImage(image, 0, 57, 40, 24);
495 scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
496 RDestroyImage(tmp);
497 /* CustomColorPalette Icon for ColorPanel */
498 tmp = RGetSubImage(image, 81, 57, 40, 24);
499 scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
500 RDestroyImage(tmp);
501 /* ColorList Icon for ColorPanel */
502 tmp = RGetSubImage(image, 41, 57, 40, 24);
503 scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
504 RDestroyImage(tmp);
506 RDestroyImage(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;
525 WMScreen*
526 WMCreateSimpleApplicationScreen(Display *display)
528 WMScreen *scr;
530 scr = WMCreateScreen(display, DefaultScreen(display));
532 scr->aflags.hasAppIcon = 0;
533 scr->aflags.simpleApplication = 1;
535 return scr;
540 WMScreen*
541 WMCreateScreen(Display *display, int screen)
543 return WMCreateScreenWithRContext(display, screen,
544 RCreateContext(display, screen, NULL));
548 WMScreen*
549 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
551 W_Screen *scrPtr;
552 XGCValues gcv;
553 Pixmap stipple;
554 static int initialized = 0;
556 if (!initialized) {
558 initialized = 1;
560 initProcedureTable();
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 /* initially allocate some colors */
590 WMWhiteColor(scrPtr);
591 WMBlackColor(scrPtr);
592 WMGrayColor(scrPtr);
593 WMDarkGrayColor(scrPtr);
595 gcv.graphics_exposures = False;
597 gcv.function = GXxor;
598 gcv.foreground = W_PIXEL(scrPtr->white);
599 if (gcv.foreground == 0) gcv.foreground = 1;
600 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
601 |GCGraphicsExposures|GCForeground, &gcv);
603 gcv.function = GXxor;
604 gcv.foreground = W_PIXEL(scrPtr->gray);
605 gcv.subwindow_mode = IncludeInferiors;
606 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
607 |GCGraphicsExposures|GCForeground
608 |GCSubwindowMode, &gcv);
610 gcv.function = GXcopy;
611 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
612 |GCGraphicsExposures, &gcv);
614 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
615 |GCGraphicsExposures, &gcv);
618 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
619 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
620 gcv.foreground = W_PIXEL(scrPtr->darkGray);
621 gcv.background = W_PIXEL(scrPtr->gray);
622 gcv.fill_style = FillStippled;
623 gcv.stipple = stipple;
624 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
625 GCForeground|GCBackground|GCStipple
626 |GCFillStyle|GCGraphicsExposures, &gcv);
628 gcv.foreground = W_PIXEL(scrPtr->black);
629 gcv.background = W_PIXEL(scrPtr->white);
630 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
631 GCForeground|GCBackground, &gcv);
633 /* we need a 1bpp drawable for the monoGC, so borrow this one */
634 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
636 scrPtr->stipple = stipple;
638 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 12);
640 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 12);
642 if (!scrPtr->boldFont)
643 scrPtr->boldFont = scrPtr->normalFont;
645 if (!scrPtr->normalFont) {
646 wwarning("could not load any fonts. Make sure your font installation"
647 "and locale settings are correct.");
649 return NULL;
652 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
653 CHECK_BUTTON_ON_WIDTH,
654 CHECK_BUTTON_ON_HEIGHT, False);
656 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
657 CHECK_BUTTON_OFF_WIDTH,
658 CHECK_BUTTON_OFF_HEIGHT, False);
660 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
661 RADIO_BUTTON_ON_WIDTH,
662 RADIO_BUTTON_ON_HEIGHT, False);
664 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
665 RADIO_BUTTON_OFF_WIDTH,
666 RADIO_BUTTON_OFF_HEIGHT, False);
668 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
669 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
670 False);
672 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
673 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
674 False);
677 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
678 SCROLLER_DIMPLE_WIDTH,
679 SCROLLER_DIMPLE_HEIGHT, False);
682 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
683 SCROLLER_ARROW_UP_WIDTH,
684 SCROLLER_ARROW_UP_HEIGHT, True);
686 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
687 SCROLLER_ARROW_DOWN_WIDTH,
688 SCROLLER_ARROW_DOWN_HEIGHT, True);
690 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
691 SCROLLER_ARROW_LEFT_WIDTH,
692 SCROLLER_ARROW_LEFT_HEIGHT, True);
694 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
695 SCROLLER_ARROW_RIGHT_WIDTH,
696 SCROLLER_ARROW_RIGHT_HEIGHT, True);
698 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
699 SCROLLER_ARROW_UP_WIDTH,
700 SCROLLER_ARROW_UP_HEIGHT, True);
702 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
703 SCROLLER_ARROW_DOWN_WIDTH,
704 SCROLLER_ARROW_DOWN_HEIGHT, True);
706 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
707 SCROLLER_ARROW_LEFT_WIDTH,
708 SCROLLER_ARROW_LEFT_HEIGHT, True);
710 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
711 SCROLLER_ARROW_RIGHT_WIDTH,
712 SCROLLER_ARROW_RIGHT_HEIGHT, True);
714 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
715 POPUP_INDICATOR_WIDTH,
716 POPUP_INDICATOR_HEIGHT, True);
718 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
719 PULLDOWN_INDICATOR_WIDTH,
720 PULLDOWN_INDICATOR_HEIGHT, True);
722 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
723 CHECK_MARK_WIDTH,
724 CHECK_MARK_HEIGHT, True);
726 loadPixmaps(scrPtr);
728 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
730 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
732 scrPtr->internalMessage = XInternAtom(display, "_WINGS_MESSAGE", False);
734 scrPtr->attribsAtom = XInternAtom(display, "_GNUSTEP_WM_ATTR", False);
736 scrPtr->deleteWindowAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
738 scrPtr->protocolsAtom = XInternAtom(display, "WM_PROTOCOLS", False);
740 scrPtr->clipboardAtom = XInternAtom(display, "CLIPBOARD", False);
742 scrPtr->rootView = W_CreateRootView(scrPtr);
745 scrPtr->balloon = W_CreateBalloon(scrPtr);
748 W_InitApplication(scrPtr);
750 return scrPtr;
754 void
755 WMHangData(WMWidget *widget, void *data)
757 W_VIEW(widget)->hangedData = data;
761 void*
762 WMGetHangedData(WMWidget *widget)
764 return W_VIEW(widget)->hangedData;
769 void
770 WMDestroyWidget(WMWidget *widget)
772 W_DestroyView(W_VIEW(widget));
776 void
777 WMSetFocusToWidget(WMWidget *widget)
779 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
784 * WMRealizeWidget-
785 * Realizes the widget and all it's children.
788 void
789 WMRealizeWidget(WMWidget *w)
791 W_RealizeView(W_VIEW(w));
794 void
795 WMMapWidget(WMWidget *w)
797 W_MapView(W_VIEW(w));
801 static void
802 makeChildrenAutomap(W_View *view, int flag)
804 view = view->childrenList;
806 while (view) {
807 view->flags.mapWhenRealized = flag;
808 makeChildrenAutomap(view, flag);
810 view = view->nextSister;
815 void
816 WMMapSubwidgets(WMWidget *w)
818 /* make sure that subwidgets created after the parent was realized
819 * are mapped too */
820 if (!W_VIEW(w)->flags.realized) {
821 makeChildrenAutomap(W_VIEW(w), True);
822 } else {
823 W_MapSubviews(W_VIEW(w));
828 void
829 WMUnmapSubwidgets(WMWidget *w)
831 if (!W_VIEW(w)->flags.realized) {
832 makeChildrenAutomap(W_VIEW(w), False);
833 } else {
834 W_UnmapSubviews(W_VIEW(w));
840 void
841 WMUnmapWidget(WMWidget *w)
843 W_UnmapView(W_VIEW(w));
847 void
848 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
850 if (W_CLASS(w) < WC_UserWidget
851 && procedureTables[W_CLASS(w)]->setBackgroundColor) {
853 (*procedureTables[W_CLASS(w)]->setBackgroundColor)(w, color);
855 } else if (W_CLASS(w) >= WC_UserWidget
856 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor) {
858 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor)(w, color);
860 } else {
861 W_SetViewBackgroundColor(W_VIEW(w), color);
866 void
867 WMMoveWidget(WMWidget *w, int x, int y)
869 if (W_CLASS(w) < WC_UserWidget
870 && procedureTables[W_CLASS(w)]->move) {
872 (*procedureTables[W_CLASS(w)]->move)(w, x, y);
874 } else if (W_CLASS(w) >= WC_UserWidget
875 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->move) {
877 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->move)(w, x, y);
879 } else {
880 W_MoveView(W_VIEW(w), x, y);
885 void
886 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
888 if (W_CLASS(w) < WC_UserWidget
889 && procedureTables[W_CLASS(w)]->resize) {
891 (*procedureTables[W_CLASS(w)]->resize)(w, width, height);
893 } else if (W_CLASS(w) >= WC_UserWidget
894 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize) {
896 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize)(w, width, height);
898 } else {
899 W_ResizeView(W_VIEW(w), width, height);
905 W_Class
906 W_RegisterUserWidget(W_ViewProcedureTable *procTable)
908 W_ViewProcedureTable **newTable;
910 userWidgetCount++;
911 newTable = wmalloc(sizeof(W_ViewProcedureTable*)*userWidgetCount);
912 memcpy(newTable, userProcedureTable,
913 sizeof(W_ViewProcedureTable*)*(userWidgetCount-1));
915 newTable[userWidgetCount-1] = procTable;
917 free(userProcedureTable);
919 userProcedureTable = newTable;
921 return userWidgetCount + WC_UserWidget - 1;
926 RContext*
927 WMScreenRContext(WMScreen *scr)
929 return scr->rcontext;
934 unsigned int
935 WMWidgetWidth(WMWidget *w)
937 return W_VIEW(w)->size.width;
941 unsigned int
942 WMWidgetHeight(WMWidget *w)
944 return W_VIEW(w)->size.height;
948 Window
949 WMWidgetXID(WMWidget *w)
951 return W_VIEW(w)->window;
955 WMScreen*
956 WMWidgetScreen(WMWidget *w)
958 return W_VIEW(w)->screen;
963 void
964 WMScreenMainLoop(WMScreen *scr)
966 XEvent event;
968 while (1) {
969 WMNextEvent(scr->display, &event);
970 WMHandleEvent(&event);
976 Display*
977 WMScreenDisplay(WMScreen *scr)
979 return scr->display;
983 int
984 WMScreenDepth(WMScreen *scr)
986 return scr->depth;
990 void
991 WMRedisplayWidget(WMWidget *w)
993 W_RedisplayView(W_VIEW(w));