5 typedef struct W_Frame
{
12 WMReliefType relief
:4;
13 WMTitlePosition titlePosition
:4;
18 #define DEFAULT_RELIEF WRGroove
19 #define DEFAULT_TITLE_POSITION WTPAtTop
20 #define DEFAULT_WIDTH 40
21 #define DEFAULT_HEIGHT 40
24 static void destroyFrame(Frame
*fPtr
);
25 static void paintFrame(Frame
*fPtr
);
26 static void repaintFrame(Frame
*fPtr
);
31 WMSetFrameTitlePosition(WMFrame
*fPtr
, WMTitlePosition position
)
33 fPtr
->flags
.titlePosition
= position
;
35 if (fPtr
->view
->flags
.realized
) {
42 WMSetFrameRelief(WMFrame
*fPtr
, WMReliefType relief
)
44 fPtr
->flags
.relief
= relief
;
46 if (fPtr
->view
->flags
.realized
) {
53 WMSetFrameTitle(WMFrame
*fPtr
, char *title
)
59 fPtr
->caption
= wstrdup(title
);
63 if (fPtr
->view
->flags
.realized
) {
70 repaintFrame(Frame
*fPtr
)
72 W_View
*view
= fPtr
->view
;
73 W_Screen
*scrPtr
= view
->screen
;
75 XClearWindow(scrPtr
->display
, view
->window
);
81 paintFrame(Frame
*fPtr
)
83 W_View
*view
= fPtr
->view
;
84 W_Screen
*scrPtr
= view
->screen
;
85 WMFont
*font
= scrPtr
->normalFont
;
86 Display
*display
= scrPtr
->display
;
87 int tx
, ty
, tw
, th
, tlen
;
91 if (fPtr
->caption
!=NULL
) {
92 th
= WMFontHeight(font
);
93 tlen
= strlen(fPtr
->caption
);
99 fh
= view
->size
.height
;
102 switch (fPtr
->flags
.titlePosition
) {
106 fh
= view
->size
.height
- fy
;
112 fh
= view
->size
.height
- fy
;
118 fh
= view
->size
.height
;
122 ty
= view
->size
.height
- th
- 4;
124 fh
= view
->size
.height
;
128 ty
= view
->size
.height
- th
;
130 fh
= view
->size
.height
- th
/2;
134 ty
= view
->size
.height
- th
;
136 fh
= view
->size
.height
- th
- 4;
142 fh
= view
->size
.height
;
145 if (tlen
>0 && fPtr
->flags
.titlePosition
!=WTPNoTitle
) {
146 tw
= WMWidthOfString(font
, fPtr
->caption
, tlen
);
148 tx
= (view
->size
.width
- tw
) / 2;
162 region
= XCreateRegion();
166 rect
.width
= view
->size
.width
;
167 rect
.height
= view
->size
.height
;
168 XUnionRectWithRegion(&rect
, region
, region
);
170 tmp
= XCreateRegion();
175 XUnionRectWithRegion(&rect
, tmp
, tmp
);
176 XSubtractRegion(region
, tmp
, region
);
179 gc
[0] = WMColorGC(scrPtr
->black
);
180 gc
[1] = WMColorGC(scrPtr
->darkGray
);
181 gc
[2] = WMColorGC(scrPtr
->gray
);
182 gc
[3] = WMColorGC(scrPtr
->white
);
184 for (i
= 0; i
< 4; i
++) {
185 XSetRegion(display
, gc
[i
], region
);
187 XDestroyRegion(region
);
189 W_DrawReliefWithGC(scrPtr
, view
->window
, 0, fy
, view
->size
.width
, fh
,
190 fPtr
->flags
.relief
, gc
[0], gc
[1], gc
[2], gc
[3]);
192 for (i
= 0; i
< 4; i
++) {
193 XSetClipMask(display
, gc
[i
], None
);
198 /* can't draw AA text over and over again because it gets messed */
199 /* // TODO create the dbl buffer pixmap when create/set frame title */
200 if (scrPtr
->antialiasedText
) {
203 d
= XCreatePixmap(display
, view
->window
, tw
, th
, scrPtr
->depth
);
204 XFillRectangle(display
, d
, WMColorGC(view
->backColor
), 0, 0, tw
, th
);
206 WMDrawString(scrPtr
, d
, scrPtr
->black
, font
, 0, 0, fPtr
->caption
, tlen
);
207 XCopyArea(display
, d
, view
->window
, scrPtr
->copyGC
, 0, 0, tw
, th
, tx
, ty
);
208 XFreePixmap(display
, d
);
210 WMDrawString(scrPtr
, view
->window
, scrPtr
->black
, font
, tx
, ty
,
211 fPtr
->caption
, tlen
);
221 handleEvents(XEvent
*event
, void *data
)
223 Frame
*fPtr
= (Frame
*)data
;
225 CHECK_CLASS(data
, WC_Frame
);
227 switch (event
->type
) {
229 if (event
->xexpose
.count
== 0)
241 WMCreateFrame(WMWidget
*parent
)
245 fPtr
= wmalloc(sizeof(Frame
));
246 memset(fPtr
, 0, sizeof(Frame
));
248 fPtr
->widgetClass
= WC_Frame
;
250 fPtr
->view
= W_CreateView(W_VIEW(parent
));
255 fPtr
->view
->self
= fPtr
;
257 WMCreateEventHandler(fPtr
->view
, ExposureMask
|StructureNotifyMask
,
261 fPtr
->flags
.relief
= DEFAULT_RELIEF
;
262 fPtr
->flags
.titlePosition
= DEFAULT_TITLE_POSITION
;
264 WMResizeWidget(fPtr
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
271 destroyFrame(Frame
*fPtr
)
274 wfree(fPtr
->caption
);