4 typedef struct W_Frame
{
12 WMReliefType relief
:4;
13 WMTitlePosition titlePosition
:4;
17 #define DEFAULT_RELIEF WRGroove
18 #define DEFAULT_TITLE_POSITION WTPAtTop
19 #define DEFAULT_WIDTH 40
20 #define DEFAULT_HEIGHT 40
22 static void destroyFrame(Frame
* fPtr
);
23 static void paintFrame(Frame
* fPtr
);
24 static void repaintFrame(Frame
* fPtr
);
26 void WMSetFrameTitlePosition(WMFrame
* fPtr
, WMTitlePosition position
)
28 fPtr
->flags
.titlePosition
= position
;
30 if (fPtr
->view
->flags
.realized
) {
35 void WMSetFrameRelief(WMFrame
* fPtr
, WMReliefType relief
)
37 fPtr
->flags
.relief
= relief
;
39 if (fPtr
->view
->flags
.realized
) {
44 void WMSetFrameTitle(WMFrame
* fPtr
, const char *title
)
50 fPtr
->caption
= wstrdup(title
);
54 if (fPtr
->view
->flags
.realized
) {
59 static void repaintFrame(Frame
* fPtr
)
61 W_View
*view
= fPtr
->view
;
62 W_Screen
*scrPtr
= view
->screen
;
64 XClearWindow(scrPtr
->display
, view
->window
);
68 static void paintFrame(Frame
* fPtr
)
70 W_View
*view
= fPtr
->view
;
71 W_Screen
*scrPtr
= view
->screen
;
72 WMFont
*font
= scrPtr
->normalFont
;
73 Display
*display
= scrPtr
->display
;
74 int tx
, ty
, tw
, th
, tlen
;
78 if (fPtr
->caption
!= NULL
) {
79 th
= WMFontHeight(font
);
80 tlen
= strlen(fPtr
->caption
);
86 switch (fPtr
->flags
.titlePosition
) {
90 fh
= view
->size
.height
- fy
;
96 fh
= view
->size
.height
- fy
;
102 fh
= view
->size
.height
;
106 ty
= view
->size
.height
- th
- 4;
108 fh
= view
->size
.height
;
112 ty
= view
->size
.height
- th
;
114 fh
= view
->size
.height
- th
/ 2;
118 ty
= view
->size
.height
- th
;
120 fh
= view
->size
.height
- th
- 4;
126 fh
= view
->size
.height
;
129 if (tlen
> 0 && fPtr
->flags
.titlePosition
!= WTPNoTitle
) {
130 tw
= WMWidthOfString(font
, fPtr
->caption
, tlen
);
132 tx
= (view
->size
.width
- tw
) / 2;
146 region
= XCreateRegion();
150 rect
.width
= view
->size
.width
;
151 rect
.height
= view
->size
.height
;
152 XUnionRectWithRegion(&rect
, region
, region
);
154 tmp
= XCreateRegion();
159 XUnionRectWithRegion(&rect
, tmp
, tmp
);
160 XSubtractRegion(region
, tmp
, region
);
163 gc
[0] = WMColorGC(scrPtr
->black
);
164 gc
[1] = WMColorGC(scrPtr
->darkGray
);
165 gc
[2] = WMColorGC(scrPtr
->gray
);
166 gc
[3] = WMColorGC(scrPtr
->white
);
168 for (i
= 0; i
< 4; i
++) {
169 XSetRegion(display
, gc
[i
], region
);
171 XDestroyRegion(region
);
173 W_DrawReliefWithGC(scrPtr
, view
->window
, 0, fy
, view
->size
.width
, fh
,
174 fPtr
->flags
.relief
, gc
[0], gc
[1], gc
[2], gc
[3]);
176 for (i
= 0; i
< 4; i
++) {
177 XSetClipMask(display
, gc
[i
], None
);
182 /* can't draw AA text over and over again because it gets messed */
183 /* // TODO create the dbl buffer pixmap when create/set frame title */
184 if (scrPtr
->antialiasedText
) {
187 d
= XCreatePixmap(display
, view
->window
, tw
, th
, scrPtr
->depth
);
188 XFillRectangle(display
, d
, WMColorGC(view
->backColor
), 0, 0, tw
, th
);
190 WMDrawString(scrPtr
, d
, fPtr
->textColor
? fPtr
->textColor
: scrPtr
->black
, font
, 0, 0, fPtr
->caption
, tlen
);
191 XCopyArea(display
, d
, view
->window
, scrPtr
->copyGC
, 0, 0, tw
, th
, tx
, ty
);
192 XFreePixmap(display
, d
);
194 WMDrawString(scrPtr
, view
->window
, scrPtr
->black
, font
, tx
, ty
, fPtr
->caption
, tlen
);
199 static void handleEvents(XEvent
* event
, void *data
)
201 Frame
*fPtr
= (Frame
*) data
;
203 CHECK_CLASS(data
, WC_Frame
);
205 switch (event
->type
) {
207 if (event
->xexpose
.count
== 0)
217 void WMSetFrameTitleColor(WMFrame
*fPtr
, WMColor
*color
)
220 WMReleaseColor(fPtr
->textColor
);
221 fPtr
->textColor
= WMRetainColor(color
);
223 if (fPtr
->view
->flags
.realized
) {
228 WMFrame
*WMCreateFrame(WMWidget
* parent
)
232 fPtr
= wmalloc(sizeof(Frame
));
234 fPtr
->widgetClass
= WC_Frame
;
236 fPtr
->view
= W_CreateView(W_VIEW(parent
));
241 fPtr
->view
->self
= fPtr
;
242 fPtr
->textColor
= WMRetainColor(fPtr
->view
->screen
->black
);
244 WMCreateEventHandler(fPtr
->view
, ExposureMask
| StructureNotifyMask
, handleEvents
, fPtr
);
246 fPtr
->flags
.relief
= DEFAULT_RELIEF
;
247 fPtr
->flags
.titlePosition
= DEFAULT_TITLE_POSITION
;
249 WMResizeWidget(fPtr
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
254 static void destroyFrame(Frame
* fPtr
)
257 wfree(fPtr
->caption
);