Code update for Window Maker version 0.50.0
[wmaker-crm.git] / WINGs / widgets.c
blobd0ff22c44d448b54cb302ec5ceaa13b8b9369b14
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};
306 extern void W_ReadConfigurations(void);
309 extern W_ViewProcedureTable _WindowViewProcedures;
310 extern W_ViewProcedureTable _FrameViewProcedures;
311 extern W_ViewProcedureTable _LabelViewProcedures;
312 extern W_ViewProcedureTable _ButtonViewProcedures;
313 extern W_ViewProcedureTable _TextFieldViewProcedures;
314 extern W_ViewProcedureTable _ScrollerViewProcedures;
315 extern W_ViewProcedureTable _ScrollViewProcedures;
316 extern W_ViewProcedureTable _ListViewProcedures;
317 extern W_ViewProcedureTable _BrowserViewProcedures;
318 extern W_ViewProcedureTable _PopUpButtonViewProcedures;
319 extern W_ViewProcedureTable _ColorWellViewProcedures;
320 extern W_ViewProcedureTable _ScrollViewViewProcedures;
321 extern W_ViewProcedureTable _SliderViewProcedures;
322 extern W_ViewProcedureTable _SplitViewViewProcedures;
325 * All widget classes defined must have an entry here.
327 static W_ViewProcedureTable *procedureTables[16];
329 static W_ViewProcedureTable **userProcedureTable = NULL;
330 static int userWidgetCount=0;
333 /***** end data ******/
337 static void
338 initProcedureTable()
340 procedureTables[WC_Window] = &_WindowViewProcedures;
341 procedureTables[WC_Frame] = &_FrameViewProcedures;
342 procedureTables[WC_Label] = &_LabelViewProcedures;
343 procedureTables[WC_Button] = &_ButtonViewProcedures;
344 procedureTables[WC_TextField] = &_TextFieldViewProcedures;
345 procedureTables[WC_Scroller] = &_ScrollerViewProcedures;
346 procedureTables[WC_List] = &_ListViewProcedures;
347 procedureTables[WC_Browser] = &_BrowserViewProcedures;
348 procedureTables[WC_PopUpButton] = &_PopUpButtonViewProcedures;
349 procedureTables[WC_ColorWell] = &_ColorWellViewProcedures;
350 procedureTables[WC_ScrollView] = &_ScrollViewViewProcedures;
351 procedureTables[WC_Slider] = &_SliderViewProcedures;
352 procedureTables[WC_SplitView] = &_SplitViewViewProcedures;
356 static void
357 renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data,
358 int width, int height)
360 int x, y;
361 GC whiteGC = W_GC(screen->white);
362 GC blackGC = W_GC(screen->black);
363 GC lightGC = W_GC(screen->gray);
364 GC darkGC = W_GC(screen->darkGray);
367 if (mask)
368 XSetForeground(screen->display, screen->monoGC, 0);
370 for (y = 0; y < height; y++) {
371 for (x = 0; x < width; x++) {
372 switch (data[y][x]) {
373 case ' ':
374 case 'w':
375 XDrawPoint(screen->display, d, whiteGC, x, y);
376 break;
378 case '=':
379 if (mask)
380 XDrawPoint(screen->display, mask, screen->monoGC, x, y);
382 case '.':
383 case 'l':
384 XDrawPoint(screen->display, d, lightGC, x, y);
385 break;
387 case '%':
388 case 'd':
389 XDrawPoint(screen->display, d, darkGC, x, y);
390 break;
392 case '#':
393 case 'b':
394 default:
395 XDrawPoint(screen->display, d, blackGC, x, y);
396 break;
404 static WMPixmap*
405 makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
407 Pixmap pixmap, mask = None;
409 pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height,
410 sPtr->depth);
412 if (masked) {
413 mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
414 XSetForeground(sPtr->display, sPtr->monoGC, 1);
415 XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
418 renderPixmap(sPtr, pixmap, mask, data, width, height);
420 return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
421 sPtr->depth);
424 #ifdef USE_TIFF
425 #define WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
426 #define DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
427 #else
428 #define WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
429 #define DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
430 #endif
432 static Bool
433 loadPixmaps(WMScreen *scr)
435 RImage *image, *tmp;
436 Pixmap pixmap;
437 RColor gray;
439 image = RLoadImage(scr->rcontext, WINGS_IMAGES_FILE, 0);
440 if (!image) {
441 wwarning("WINGs: could not load widget images file: %s",
442 RMessageForError(RErrorCode));
443 return False;
445 /* make it have a gray background */
446 gray.red = 0xae;
447 gray.green = 0xaa;
448 gray.blue = 0xae;
449 RCombineImageWithColor(image, &gray);
450 tmp = RGetSubImage(image, 0, 0, 24, 24);
451 if (!RConvertImage(scr->rcontext, tmp, &pixmap)) {
452 scr->homeIcon = NULL;
453 } else {
454 scr->homeIcon = WMCreatePixmapFromXPixmaps(scr, pixmap, None, 24, 24,
455 scr->depth);
457 RDestroyImage(tmp);
458 RDestroyImage(image);
460 #if 0
461 scr->defaultObjectIcon =
462 WMCreatePixmapFromFile(scr, DEFAULT_OBJECT_ICON_FILE);
463 if (!scr->defaultObjectIcon) {
464 wwarning("WINGs: could not load default icon file");
465 return False;
467 #endif
468 return True;
473 WMScreen*
474 WMCreateSimpleApplicationScreen(Display *display)
476 WMScreen *scr;
478 scr = WMCreateScreen(display, DefaultScreen(display));
480 scr->aflags.hasAppIcon = 0;
481 scr->aflags.simpleApplication = 1;
483 return scr;
488 WMScreen*
489 WMCreateScreen(Display *display, int screen)
491 return WMCreateScreenWithRContext(display, screen,
492 RCreateContext(display, screen, NULL));
496 WMScreen*
497 WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
499 W_Screen *scrPtr;
500 XGCValues gcv;
501 Pixmap stipple;
502 static int initialized = 0;
504 if (!initialized) {
506 initialized = 1;
508 initProcedureTable();
510 W_ReadConfigurations();
512 assert(W_ApplicationInitialized());
515 scrPtr = malloc(sizeof(W_Screen));
516 if (!scrPtr)
517 return NULL;
518 memset(scrPtr, 0, sizeof(W_Screen));
520 scrPtr->aflags.hasAppIcon = 1;
522 scrPtr->display = display;
523 scrPtr->screen = screen;
524 scrPtr->rcontext = context;
526 scrPtr->depth = context->depth;
528 scrPtr->visual = context->visual;
529 scrPtr->lastEventTime = 0;
531 scrPtr->colormap = context->cmap;
533 scrPtr->rootWin = RootWindow(display, screen);
536 /* initially allocate some colors */
537 WMWhiteColor(scrPtr);
538 WMBlackColor(scrPtr);
539 WMGrayColor(scrPtr);
540 WMDarkGrayColor(scrPtr);
542 gcv.graphics_exposures = False;
544 gcv.function = GXxor;
545 gcv.foreground = W_PIXEL(scrPtr->white);
546 if (gcv.foreground == 0) gcv.foreground = 1;
547 scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
548 |GCGraphicsExposures|GCForeground, &gcv);
550 gcv.function = GXxor;
551 gcv.foreground = W_PIXEL(scrPtr->gray);
552 gcv.subwindow_mode = IncludeInferiors;
553 scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
554 |GCGraphicsExposures|GCForeground
555 |GCSubwindowMode, &gcv);
557 gcv.function = GXcopy;
558 scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
559 |GCGraphicsExposures, &gcv);
561 scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
562 |GCGraphicsExposures, &gcv);
565 stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr),
566 STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
567 gcv.foreground = W_PIXEL(scrPtr->darkGray);
568 gcv.background = W_PIXEL(scrPtr->gray);
569 gcv.fill_style = FillStippled;
570 gcv.stipple = stipple;
571 scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
572 GCForeground|GCBackground|GCStipple
573 |GCFillStyle|GCGraphicsExposures, &gcv);
575 gcv.foreground = W_PIXEL(scrPtr->black);
576 gcv.background = W_PIXEL(scrPtr->white);
577 scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
578 GCForeground|GCBackground, &gcv);
580 /* we need a 1bpp drawable for the monoGC, so borrow this one */
581 scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
583 XFreePixmap(display, stipple);
586 scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 12);
588 scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 12);
590 if (!scrPtr->boldFont)
591 scrPtr->boldFont = scrPtr->normalFont;
593 if (!scrPtr->normalFont) {
594 wwarning("could not load any fonts. Make sure your font installation"
595 "and locale settings are correct.");
597 return NULL;
600 scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
601 CHECK_BUTTON_ON_WIDTH,
602 CHECK_BUTTON_ON_HEIGHT, False);
604 scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
605 CHECK_BUTTON_OFF_WIDTH,
606 CHECK_BUTTON_OFF_HEIGHT, False);
608 scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
609 RADIO_BUTTON_ON_WIDTH,
610 RADIO_BUTTON_ON_HEIGHT, False);
612 scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
613 RADIO_BUTTON_OFF_WIDTH,
614 RADIO_BUTTON_OFF_HEIGHT, False);
616 scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
617 BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT,
618 False);
620 scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
621 BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT,
622 False);
625 scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
626 SCROLLER_DIMPLE_WIDTH,
627 SCROLLER_DIMPLE_HEIGHT, False);
630 scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
631 SCROLLER_ARROW_UP_WIDTH,
632 SCROLLER_ARROW_UP_HEIGHT, True);
634 scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
635 SCROLLER_ARROW_DOWN_WIDTH,
636 SCROLLER_ARROW_DOWN_HEIGHT, True);
638 scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
639 SCROLLER_ARROW_LEFT_WIDTH,
640 SCROLLER_ARROW_LEFT_HEIGHT, True);
642 scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
643 SCROLLER_ARROW_RIGHT_WIDTH,
644 SCROLLER_ARROW_RIGHT_HEIGHT, True);
646 scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
647 SCROLLER_ARROW_UP_WIDTH,
648 SCROLLER_ARROW_UP_HEIGHT, True);
650 scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
651 SCROLLER_ARROW_DOWN_WIDTH,
652 SCROLLER_ARROW_DOWN_HEIGHT, True);
654 scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
655 SCROLLER_ARROW_LEFT_WIDTH,
656 SCROLLER_ARROW_LEFT_HEIGHT, True);
658 scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
659 SCROLLER_ARROW_RIGHT_WIDTH,
660 SCROLLER_ARROW_RIGHT_HEIGHT, True);
662 scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
663 POPUP_INDICATOR_WIDTH,
664 POPUP_INDICATOR_HEIGHT, True);
666 scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
667 PULLDOWN_INDICATOR_WIDTH,
668 PULLDOWN_INDICATOR_HEIGHT, True);
670 scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
671 CHECK_MARK_WIDTH,
672 CHECK_MARK_HEIGHT, True);
674 loadPixmaps(scrPtr);
676 scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
678 scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
680 scrPtr->internalMessage = XInternAtom(display, "_WINGS_MESSAGE", False);
682 scrPtr->attribsAtom = XInternAtom(display, "_GNUSTEP_WM_ATTR", False);
684 scrPtr->deleteWindowAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
686 scrPtr->protocolsAtom = XInternAtom(display, "WM_PROTOCOLS", False);
688 scrPtr->clipboardAtom = XInternAtom(display, "CLIPBOARD", False);
690 scrPtr->rootView = W_CreateRootView(scrPtr);
692 W_InitApplication(scrPtr);
694 return scrPtr;
698 void
699 WMHangData(WMWidget *widget, void *data)
701 W_VIEW(widget)->hangedData = data;
705 void*
706 WMGetHangedData(WMWidget *widget)
708 return W_VIEW(widget)->hangedData;
713 void
714 WMDestroyWidget(WMWidget *widget)
716 W_DestroyView(W_VIEW(widget));
720 void
721 WMSetFocusToWidget(WMWidget *widget)
723 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
728 * WMRealizeWidget-
729 * Realizes the widget and all it's children.
732 void
733 WMRealizeWidget(WMWidget *w)
735 W_RealizeView(W_VIEW(w));
738 void
739 WMMapWidget(WMWidget *w)
741 W_MapView(W_VIEW(w));
745 static void
746 makeChildrenAutomap(W_View *view, int flag)
748 view = view->childrenList;
750 while (view) {
751 view->flags.mapWhenRealized = flag;
752 makeChildrenAutomap(view, flag);
754 view = view->nextSister;
759 void
760 WMMapSubwidgets(WMWidget *w)
762 /* make sure that subwidgets created after the parent was realized
763 * are mapped too */
764 if (!W_VIEW(w)->flags.realized) {
765 makeChildrenAutomap(W_VIEW(w), True);
766 } else {
767 W_MapSubviews(W_VIEW(w));
772 void
773 WMUnmapSubwidgets(WMWidget *w)
775 if (!W_VIEW(w)->flags.realized) {
776 makeChildrenAutomap(W_VIEW(w), False);
777 } else {
778 W_UnmapSubviews(W_VIEW(w));
784 void
785 WMUnmapWidget(WMWidget *w)
787 W_UnmapView(W_VIEW(w));
791 void
792 WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
794 if (W_CLASS(w) < WC_UserWidget
795 && procedureTables[W_CLASS(w)]->setBackgroundColor) {
797 (*procedureTables[W_CLASS(w)]->setBackgroundColor)(w, color);
799 } else if (W_CLASS(w) >= WC_UserWidget
800 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor) {
802 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->setBackgroundColor)(w, color);
804 } else {
805 W_SetViewBackgroundColor(W_VIEW(w), color);
810 void
811 WMMoveWidget(WMWidget *w, int x, int y)
813 if (W_CLASS(w) < WC_UserWidget
814 && procedureTables[W_CLASS(w)]->move) {
816 (*procedureTables[W_CLASS(w)]->move)(w, x, y);
818 } else if (W_CLASS(w) >= WC_UserWidget
819 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->move) {
821 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->move)(w, x, y);
823 } else {
824 W_MoveView(W_VIEW(w), x, y);
829 void
830 WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
832 if (W_CLASS(w) < WC_UserWidget
833 && procedureTables[W_CLASS(w)]->resize) {
835 (*procedureTables[W_CLASS(w)]->resize)(w, width, height);
837 } else if (W_CLASS(w) >= WC_UserWidget
838 && userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize) {
840 (*userProcedureTable[W_CLASS(w)-WC_UserWidget]->resize)(w, width, height);
842 } else {
843 W_ResizeView(W_VIEW(w), width, height);
849 W_Class
850 W_RegisterUserWidget(W_ViewProcedureTable *procTable)
852 W_ViewProcedureTable **newTable;
854 userWidgetCount++;
855 newTable = wmalloc(sizeof(W_ViewProcedureTable*)*userWidgetCount);
856 memcpy(newTable, userProcedureTable,
857 sizeof(W_ViewProcedureTable*)*(userWidgetCount-1));
859 newTable[userWidgetCount-1] = procTable;
861 free(userProcedureTable);
863 userProcedureTable = newTable;
865 return userWidgetCount + WC_UserWidget - 1;
870 RContext*
871 WMScreenRContext(WMScreen *scr)
873 return scr->rcontext;
878 unsigned int
879 WMWidgetWidth(WMWidget *w)
881 return W_VIEW(w)->size.width;
885 unsigned int
886 WMWidgetHeight(WMWidget *w)
888 return W_VIEW(w)->size.height;
892 Window
893 WMWidgetXID(WMWidget *w)
895 return W_VIEW(w)->window;
899 WMScreen*
900 WMWidgetScreen(WMWidget *w)
902 return W_VIEW(w)->screen;
907 void
908 WMScreenMainLoop(WMScreen *scr)
910 XEvent event;
912 while (1) {
913 WMNextEvent(scr->display, &event);
914 WMHandleEvent(&event);
920 Display*
921 WMScreenDisplay(WMScreen *scr)
923 return scr->display;
927 int
928 WMScreenDepth(WMScreen *scr)
930 return scr->depth;
934 void
935 WMRedisplayWidget(WMWidget *w)
937 W_RedisplayView(W_VIEW(w));