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
[] = {
33 #define CHECK_BUTTON_OFF_WIDTH 16
34 #define CHECK_BUTTON_OFF_HEIGHT 16
36 static char *CHECK_BUTTON_OFF
[] = {
54 #define RADIO_BUTTON_ON_WIDTH 15
55 #define RADIO_BUTTON_ON_HEIGHT 15
56 static char *RADIO_BUTTON_ON
[] = {
74 #define RADIO_BUTTON_OFF_WIDTH 15
75 #define RADIO_BUTTON_OFF_HEIGHT 15
76 static char *RADIO_BUTTON_OFF
[] = {
95 static char *BUTTON_ARROW
[] = {
100 ".#............ ...",
101 "#............. ...",
102 ".#............ ...",
104 "...#. ............",
108 #define BUTTON_ARROW_WIDTH 18
109 #define BUTTON_ARROW_HEIGHT 10
112 static char *BUTTON_ARROW2
[] = {
125 #define BUTTON_ARROW2_WIDTH 18
126 #define BUTTON_ARROW2_HEIGHT 10
129 static char *SCROLLER_DIMPLE
[] = {
138 #define SCROLLER_DIMPLE_WIDTH 6
139 #define SCROLLER_DIMPLE_HEIGHT 6
142 static char *SCROLLER_ARROW_UP
[] = {
154 static char *HI_SCROLLER_ARROW_UP
[] = {
166 #define SCROLLER_ARROW_UP_WIDTH 9
167 #define SCROLLER_ARROW_UP_HEIGHT 9
170 static char *SCROLLER_ARROW_DOWN
[] = {
182 static char *HI_SCROLLER_ARROW_DOWN
[] = {
194 #define SCROLLER_ARROW_DOWN_WIDTH 9
195 #define SCROLLER_ARROW_DOWN_HEIGHT 9
199 static char *SCROLLER_ARROW_LEFT
[] = {
211 static char *HI_SCROLLER_ARROW_LEFT
[] = {
223 #define SCROLLER_ARROW_LEFT_WIDTH 9
224 #define SCROLLER_ARROW_LEFT_HEIGHT 9
227 static char *SCROLLER_ARROW_RIGHT
[] = {
239 static char *HI_SCROLLER_ARROW_RIGHT
[] = {
251 #define SCROLLER_ARROW_RIGHT_WIDTH 9
252 #define SCROLLER_ARROW_RIGHT_HEIGHT 9
255 static char *POPUP_INDICATOR
[] = {
266 #define POPUP_INDICATOR_WIDTH 11
267 #define POPUP_INDICATOR_HEIGHT 8
271 static char *PULLDOWN_INDICATOR
[] = {
280 #define PULLDOWN_INDICATOR_WIDTH 9
281 #define PULLDOWN_INDICATOR_HEIGHT 7
284 #define STIPPLE_WIDTH 8
285 #define STIPPLE_HEIGHT 8
286 static unsigned char STIPPLE_BITS
[] = {
287 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
291 extern W_ViewProcedureTable _WindowViewProcedures
;
292 extern W_ViewProcedureTable _FrameViewProcedures
;
293 extern W_ViewProcedureTable _LabelViewProcedures
;
294 extern W_ViewProcedureTable _ButtonViewProcedures
;
295 extern W_ViewProcedureTable _TextFieldViewProcedures
;
296 extern W_ViewProcedureTable _ScrollerViewProcedures
;
297 extern W_ViewProcedureTable _ScrollViewProcedures
;
298 extern W_ViewProcedureTable _ListViewProcedures
;
299 extern W_ViewProcedureTable _BrowserViewProcedures
;
300 extern W_ViewProcedureTable _PopUpButtonViewProcedures
;
301 extern W_ViewProcedureTable _ColorWellViewProcedures
;
302 extern W_ViewProcedureTable _ScrollViewViewProcedures
;
303 extern W_ViewProcedureTable _SliderViewProcedures
;
304 extern W_ViewProcedureTable _SplitViewViewProcedures
;
307 * All widget classes defined must have an entry here.
309 static W_ViewProcedureTable
*procedureTables
[16];
311 static W_ViewProcedureTable
**userProcedureTable
= NULL
;
312 static int userWidgetCount
=0;
315 /***** end data ******/
322 procedureTables
[WC_Window
] = &_WindowViewProcedures
;
323 procedureTables
[WC_Frame
] = &_FrameViewProcedures
;
324 procedureTables
[WC_Label
] = &_LabelViewProcedures
;
325 procedureTables
[WC_Button
] = &_ButtonViewProcedures
;
326 procedureTables
[WC_TextField
] = &_TextFieldViewProcedures
;
327 procedureTables
[WC_Scroller
] = &_ScrollerViewProcedures
;
328 procedureTables
[WC_List
] = &_ListViewProcedures
;
329 procedureTables
[WC_Browser
] = &_BrowserViewProcedures
;
330 procedureTables
[WC_PopUpButton
] = &_PopUpButtonViewProcedures
;
331 procedureTables
[WC_ColorWell
] = &_ColorWellViewProcedures
;
332 procedureTables
[WC_ScrollView
] = &_ScrollViewViewProcedures
;
333 procedureTables
[WC_Slider
] = &_SliderViewProcedures
;
334 procedureTables
[WC_SplitView
] = &_SplitViewViewProcedures
;
339 renderPixmap(W_Screen
*screen
, Pixmap d
, Pixmap mask
, char **data
,
340 int width
, int height
)
343 GC whiteGC
= W_GC(screen
->white
);
344 GC blackGC
= W_GC(screen
->black
);
345 GC lightGC
= W_GC(screen
->gray
);
346 GC darkGC
= W_GC(screen
->darkGray
);
350 XSetForeground(screen
->display
, screen
->monoGC
, 0);
352 for (y
= 0; y
< height
; y
++) {
353 for (x
= 0; x
< width
; x
++) {
354 switch (data
[y
][x
]) {
357 XDrawPoint(screen
->display
, d
, whiteGC
, x
, y
);
362 XDrawPoint(screen
->display
, mask
, screen
->monoGC
, x
, y
);
366 XDrawPoint(screen
->display
, d
, lightGC
, x
, y
);
371 XDrawPoint(screen
->display
, d
, darkGC
, x
, y
);
377 XDrawPoint(screen
->display
, d
, blackGC
, x
, y
);
387 makePixmap(W_Screen
*sPtr
, char **data
, int width
, int height
, int masked
)
389 Pixmap pixmap
, mask
= None
;
391 pixmap
= XCreatePixmap(sPtr
->display
, W_DRAWABLE(sPtr
), width
, height
,
395 mask
= XCreatePixmap(sPtr
->display
, W_DRAWABLE(sPtr
), width
, height
, 1);
396 XSetForeground(sPtr
->display
, sPtr
->monoGC
, 1);
397 XFillRectangle(sPtr
->display
, mask
, sPtr
->monoGC
, 0, 0, width
, height
);
400 renderPixmap(sPtr
, pixmap
, mask
, data
, width
, height
);
402 return WMCreatePixmapFromXPixmaps(sPtr
, pixmap
, mask
, width
, height
,
407 #define WINGS_IMAGES_FILE RESOURCE_PATH"/Images.tiff"
408 #define DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
410 #define WINGS_IMAGES_FILE RESOURCE_PATH"/Images.xpm"
411 #define DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
415 loadPixmaps(WMScreen
*scr
)
421 image
= RLoadImage(scr
->rcontext
, WINGS_IMAGES_FILE
, 0);
423 wwarning("WINGs: could not load widget images file: %s",
424 RMessageForError(RErrorCode
));
427 /* make it have a gray background */
431 RCombineImageWithColor(image
, &gray
);
432 tmp
= RGetSubImage(image
, 0, 0, 24, 24);
433 if (!RConvertImage(scr
->rcontext
, tmp
, &pixmap
)) {
434 scr
->homeIcon
= NULL
;
436 scr
->homeIcon
= WMCreatePixmapFromXPixmaps(scr
, pixmap
, None
, 24, 24,
440 RDestroyImage(image
);
443 scr
->defaultObjectIcon
=
444 WMCreatePixmapFromFile(scr
, DEFAULT_OBJECT_ICON_FILE
);
445 if (!scr
->defaultObjectIcon
) {
446 wwarning("WINGs: could not load default icon file");
456 WMCreateSimpleApplicationScreen(Display
*display
)
460 scr
= WMCreateScreen(display
, DefaultScreen(display
));
462 scr
->aflags
.hasAppIcon
= 0;
463 scr
->aflags
.simpleApplication
= 1;
471 WMCreateScreen(Display
*display
, int screen
)
473 return WMCreateScreenWithRContext(display
, screen
,
474 RCreateContext(display
, screen
, NULL
));
479 WMCreateScreenWithRContext(Display
*display
, int screen
, RContext
*context
)
484 static int initialized
= 0;
490 initProcedureTable();
492 assert(W_ApplicationInitialized());
495 scrPtr
= malloc(sizeof(W_Screen
));
498 memset(scrPtr
, 0, sizeof(W_Screen
));
500 scrPtr
->aflags
.hasAppIcon
= 1;
502 scrPtr
->display
= display
;
503 scrPtr
->screen
= screen
;
504 scrPtr
->rcontext
= context
;
506 scrPtr
->depth
= context
->depth
;
508 scrPtr
->visual
= context
->visual
;
509 scrPtr
->lastEventTime
= 0;
511 scrPtr
->colormap
= context
->cmap
;
513 scrPtr
->rootWin
= RootWindow(display
, screen
);
516 /* initially allocate some colors */
517 WMWhiteColor(scrPtr
);
518 WMBlackColor(scrPtr
);
520 WMDarkGrayColor(scrPtr
);
522 gcv
.graphics_exposures
= False
;
524 gcv
.function
= GXxor
;
525 gcv
.foreground
= W_PIXEL(scrPtr
->white
);
526 if (gcv
.foreground
== 0) gcv
.foreground
= 1;
527 scrPtr
->xorGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
), GCFunction
528 |GCGraphicsExposures
|GCForeground
, &gcv
);
530 gcv
.function
= GXxor
;
531 gcv
.foreground
= W_PIXEL(scrPtr
->gray
);
532 gcv
.subwindow_mode
= IncludeInferiors
;
533 scrPtr
->ixorGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
), GCFunction
534 |GCGraphicsExposures
|GCForeground
535 |GCSubwindowMode
, &gcv
);
537 gcv
.function
= GXcopy
;
538 scrPtr
->copyGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
), GCFunction
539 |GCGraphicsExposures
, &gcv
);
541 scrPtr
->clipGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
), GCFunction
542 |GCGraphicsExposures
, &gcv
);
545 stipple
= XCreateBitmapFromData(display
, W_DRAWABLE(scrPtr
),
546 STIPPLE_BITS
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
547 gcv
.foreground
= W_PIXEL(scrPtr
->darkGray
);
548 gcv
.background
= W_PIXEL(scrPtr
->gray
);
549 gcv
.fill_style
= FillStippled
;
550 gcv
.stipple
= stipple
;
551 scrPtr
->stippleGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
),
552 GCForeground
|GCBackground
|GCStipple
553 |GCFillStyle
|GCGraphicsExposures
, &gcv
);
555 gcv
.foreground
= W_PIXEL(scrPtr
->black
);
556 gcv
.background
= W_PIXEL(scrPtr
->white
);
557 scrPtr
->textFieldGC
= XCreateGC(display
, W_DRAWABLE(scrPtr
),
558 GCForeground
|GCBackground
, &gcv
);
560 /* we need a 1bpp drawable for the monoGC, so borrow this one */
561 scrPtr
->monoGC
= XCreateGC(display
, stipple
, 0, NULL
);
563 XFreePixmap(display
, stipple
);
566 scrPtr
->normalFont
= WMSystemFontOfSize(scrPtr
, 12);
568 scrPtr
->boldFont
= WMBoldSystemFontOfSize(scrPtr
, 12);
570 scrPtr
->checkButtonImageOn
= makePixmap(scrPtr
, CHECK_BUTTON_ON
,
571 CHECK_BUTTON_ON_WIDTH
,
572 CHECK_BUTTON_ON_HEIGHT
, False
);
574 scrPtr
->checkButtonImageOff
= makePixmap(scrPtr
, CHECK_BUTTON_OFF
,
575 CHECK_BUTTON_OFF_WIDTH
,
576 CHECK_BUTTON_OFF_HEIGHT
, False
);
578 scrPtr
->radioButtonImageOn
= makePixmap(scrPtr
, RADIO_BUTTON_ON
,
579 RADIO_BUTTON_ON_WIDTH
,
580 RADIO_BUTTON_ON_HEIGHT
, False
);
582 scrPtr
->radioButtonImageOff
= makePixmap(scrPtr
, RADIO_BUTTON_OFF
,
583 RADIO_BUTTON_OFF_WIDTH
,
584 RADIO_BUTTON_OFF_HEIGHT
, False
);
586 scrPtr
->buttonArrow
= makePixmap(scrPtr
, BUTTON_ARROW
,
587 BUTTON_ARROW_WIDTH
, BUTTON_ARROW_HEIGHT
,
590 scrPtr
->pushedButtonArrow
= makePixmap(scrPtr
, BUTTON_ARROW2
,
591 BUTTON_ARROW2_WIDTH
, BUTTON_ARROW2_HEIGHT
,
595 scrPtr
->scrollerDimple
= makePixmap(scrPtr
, SCROLLER_DIMPLE
,
596 SCROLLER_DIMPLE_WIDTH
,
597 SCROLLER_DIMPLE_HEIGHT
, False
);
600 scrPtr
->upArrow
= makePixmap(scrPtr
, SCROLLER_ARROW_UP
,
601 SCROLLER_ARROW_UP_WIDTH
,
602 SCROLLER_ARROW_UP_HEIGHT
, True
);
604 scrPtr
->downArrow
= makePixmap(scrPtr
, SCROLLER_ARROW_DOWN
,
605 SCROLLER_ARROW_DOWN_WIDTH
,
606 SCROLLER_ARROW_DOWN_HEIGHT
, True
);
608 scrPtr
->leftArrow
= makePixmap(scrPtr
, SCROLLER_ARROW_LEFT
,
609 SCROLLER_ARROW_LEFT_WIDTH
,
610 SCROLLER_ARROW_LEFT_HEIGHT
, True
);
612 scrPtr
->rightArrow
= makePixmap(scrPtr
, SCROLLER_ARROW_RIGHT
,
613 SCROLLER_ARROW_RIGHT_WIDTH
,
614 SCROLLER_ARROW_RIGHT_HEIGHT
, True
);
616 scrPtr
->hiUpArrow
= makePixmap(scrPtr
, HI_SCROLLER_ARROW_UP
,
617 SCROLLER_ARROW_UP_WIDTH
,
618 SCROLLER_ARROW_UP_HEIGHT
, True
);
620 scrPtr
->hiDownArrow
= makePixmap(scrPtr
, HI_SCROLLER_ARROW_DOWN
,
621 SCROLLER_ARROW_DOWN_WIDTH
,
622 SCROLLER_ARROW_DOWN_HEIGHT
, True
);
624 scrPtr
->hiLeftArrow
= makePixmap(scrPtr
, HI_SCROLLER_ARROW_LEFT
,
625 SCROLLER_ARROW_LEFT_WIDTH
,
626 SCROLLER_ARROW_LEFT_HEIGHT
, True
);
628 scrPtr
->hiRightArrow
= makePixmap(scrPtr
, HI_SCROLLER_ARROW_RIGHT
,
629 SCROLLER_ARROW_RIGHT_WIDTH
,
630 SCROLLER_ARROW_RIGHT_HEIGHT
, True
);
632 scrPtr
->popUpIndicator
= makePixmap(scrPtr
, POPUP_INDICATOR
,
633 POPUP_INDICATOR_WIDTH
,
634 POPUP_INDICATOR_HEIGHT
, True
);
636 scrPtr
->pullDownIndicator
= makePixmap(scrPtr
, PULLDOWN_INDICATOR
,
637 PULLDOWN_INDICATOR_WIDTH
,
638 PULLDOWN_INDICATOR_HEIGHT
, True
);
641 scrPtr
->defaultCursor
= XCreateFontCursor(display
, XC_left_ptr
);
643 scrPtr
->textCursor
= XCreateFontCursor(display
, XC_xterm
);
645 scrPtr
->internalMessage
= XInternAtom(display
, "_WINGS_MESSAGE", False
);
647 scrPtr
->attribsAtom
= XInternAtom(display
, "_GNUSTEP_WM_ATTR", False
);
649 scrPtr
->deleteWindowAtom
= XInternAtom(display
, "WM_DELETE_WINDOW", False
);
651 scrPtr
->protocolsAtom
= XInternAtom(display
, "WM_PROTOCOLS", False
);
653 scrPtr
->clipboardAtom
= XInternAtom(display
, "CLIPBOARD", False
);
655 scrPtr
->rootView
= W_CreateRootView(scrPtr
);
657 W_InitApplication(scrPtr
);
664 WMHangData(WMWidget
*widget
, void *data
)
666 W_VIEW(widget
)->hangedData
= data
;
671 WMGetHangedData(WMWidget
*widget
)
673 return W_VIEW(widget
)->hangedData
;
679 WMDestroyWidget(WMWidget
*widget
)
681 W_DestroyView(W_VIEW(widget
));
686 WMSetFocusToWidget(WMWidget
*widget
)
688 W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget
)), W_VIEW(widget
));
694 * Realizes the widget and all it's children.
698 WMRealizeWidget(WMWidget
*w
)
700 W_RealizeView(W_VIEW(w
));
704 WMMapWidget(WMWidget
*w
)
706 W_MapView(W_VIEW(w
));
711 makeChildrenAutomap(W_View
*view
, int flag
)
713 view
= view
->childrenList
;
716 view
->flags
.mapWhenRealized
= flag
;
717 makeChildrenAutomap(view
, flag
);
719 view
= view
->nextSister
;
725 WMMapSubwidgets(WMWidget
*w
)
727 /* make sure that subwidgets created after the parent was realized
729 if (!W_VIEW(w
)->flags
.realized
) {
730 makeChildrenAutomap(W_VIEW(w
), True
);
732 W_MapSubviews(W_VIEW(w
));
738 WMUnmapSubwidgets(WMWidget
*w
)
740 if (!W_VIEW(w
)->flags
.realized
) {
741 makeChildrenAutomap(W_VIEW(w
), False
);
743 W_UnmapSubviews(W_VIEW(w
));
750 WMUnmapWidget(WMWidget
*w
)
752 W_UnmapView(W_VIEW(w
));
757 WMSetWidgetBackgroundColor(WMWidget
*w
, WMColor
*color
)
759 if (W_CLASS(w
) < WC_UserWidget
760 && procedureTables
[W_CLASS(w
)]->setBackgroundColor
) {
762 (*procedureTables
[W_CLASS(w
)]->setBackgroundColor
)(w
, color
);
764 } else if (W_CLASS(w
) >= WC_UserWidget
765 && userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->setBackgroundColor
) {
767 (*userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->setBackgroundColor
)(w
, color
);
770 W_SetViewBackgroundColor(W_VIEW(w
), color
);
776 WMMoveWidget(WMWidget
*w
, int x
, int y
)
778 if (W_CLASS(w
) < WC_UserWidget
779 && procedureTables
[W_CLASS(w
)]->move
) {
781 (*procedureTables
[W_CLASS(w
)]->move
)(w
, x
, y
);
783 } else if (W_CLASS(w
) >= WC_UserWidget
784 && userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->move
) {
786 (*userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->move
)(w
, x
, y
);
789 W_MoveView(W_VIEW(w
), x
, y
);
795 WMResizeWidget(WMWidget
*w
, unsigned int width
, unsigned int height
)
797 if (W_CLASS(w
) < WC_UserWidget
798 && procedureTables
[W_CLASS(w
)]->resize
) {
800 (*procedureTables
[W_CLASS(w
)]->resize
)(w
, width
, height
);
802 } else if (W_CLASS(w
) >= WC_UserWidget
803 && userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->resize
) {
805 (*userProcedureTable
[W_CLASS(w
)-WC_UserWidget
]->resize
)(w
, width
, height
);
808 W_ResizeView(W_VIEW(w
), width
, height
);
815 W_RegisterUserWidget(W_ViewProcedureTable
*procTable
)
817 W_ViewProcedureTable
**newTable
;
820 newTable
= wmalloc(sizeof(W_ViewProcedureTable
*)*userWidgetCount
);
821 memcpy(newTable
, userProcedureTable
,
822 sizeof(W_ViewProcedureTable
*)*(userWidgetCount
-1));
824 newTable
[userWidgetCount
-1] = procTable
;
826 free(userProcedureTable
);
828 userProcedureTable
= newTable
;
830 return userWidgetCount
+ WC_UserWidget
- 1;
836 WMScreenRContext(WMScreen
*scr
)
838 return scr
->rcontext
;
844 WMWidgetWidth(WMWidget
*w
)
846 return W_VIEW(w
)->size
.width
;
851 WMWidgetHeight(WMWidget
*w
)
853 return W_VIEW(w
)->size
.height
;
858 WMWidgetXID(WMWidget
*w
)
860 return W_VIEW(w
)->window
;
865 WMWidgetScreen(WMWidget
*w
)
867 return W_VIEW(w
)->screen
;
873 WMScreenMainLoop(WMScreen
*scr
)
878 WMNextEvent(scr
->display
, &event
);
879 WMHandleEvent(&event
);
886 WMScreenDisplay(WMScreen
*scr
)
893 WMScreenDepth(WMScreen
*scr
)
900 WMRedisplayWidget(WMWidget
*w
)
902 W_RedisplayView(W_VIEW(w
));