9 typedef struct W_Label
{
16 WMFont
*font
; /* if NULL, use default */
21 WMReliefType relief
:3;
22 WMImagePosition imagePosition
:4;
23 WMAlignment alignment
:2;
25 unsigned int noWrap
:1;
27 unsigned int redrawPending
:1;
32 #define DEFAULT_WIDTH 60
33 #define DEFAULT_HEIGHT 14
34 #define DEFAULT_ALIGNMENT WALeft
35 #define DEFAULT_RELIEF WRFlat
36 #define DEFAULT_IMAGE_POSITION WIPNoImage
39 static void destroyLabel(Label
*lPtr
);
40 static void paintLabel(Label
*lPtr
);
43 static void handleEvents(XEvent
*event
, void *data
);
47 WMCreateLabel(WMWidget
*parent
)
51 lPtr
= wmalloc(sizeof(Label
));
52 memset(lPtr
, 0, sizeof(Label
));
54 lPtr
->widgetClass
= WC_Label
;
56 lPtr
->view
= W_CreateView(W_VIEW(parent
));
61 lPtr
->view
->self
= lPtr
;
63 lPtr
->textColor
= WMRetainColor(lPtr
->view
->screen
->black
);
65 WMCreateEventHandler(lPtr
->view
, ExposureMask
|StructureNotifyMask
,
68 W_ResizeView(lPtr
->view
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
69 lPtr
->flags
.alignment
= DEFAULT_ALIGNMENT
;
70 lPtr
->flags
.relief
= DEFAULT_RELIEF
;
71 lPtr
->flags
.imagePosition
= DEFAULT_IMAGE_POSITION
;
72 lPtr
->flags
.noWrap
= 1;
79 WMSetLabelImage(WMLabel
*lPtr
, WMPixmap
*image
)
81 if (lPtr
->image
!=NULL
)
82 WMReleasePixmap(lPtr
->image
);
85 lPtr
->image
= WMRetainPixmap(image
);
89 if (lPtr
->view
->flags
.realized
) {
96 WMGetLabelImage(WMLabel
*lPtr
)
103 WMGetLabelText(WMLabel
*lPtr
)
105 return lPtr
->caption
;
110 WMSetLabelImagePosition(WMLabel
*lPtr
, WMImagePosition position
)
112 lPtr
->flags
.imagePosition
= position
;
113 if (lPtr
->view
->flags
.realized
) {
120 WMSetLabelTextAlignment(WMLabel
*lPtr
, WMAlignment alignment
)
122 lPtr
->flags
.alignment
= alignment
;
123 if (lPtr
->view
->flags
.realized
) {
130 WMSetLabelRelief(WMLabel
*lPtr
, WMReliefType relief
)
132 lPtr
->flags
.relief
= relief
;
133 if (lPtr
->view
->flags
.realized
) {
140 WMSetLabelText(WMLabel
*lPtr
, char *text
)
143 wfree(lPtr
->caption
);
146 lPtr
->caption
= wstrdup(text
);
148 lPtr
->caption
= NULL
;
150 if (lPtr
->view
->flags
.realized
) {
157 WMGetLabelFont(WMLabel
*lPtr
)
164 WMSetLabelFont(WMLabel
*lPtr
, WMFont
*font
)
166 if (lPtr
->font
!=NULL
)
167 WMReleaseFont(lPtr
->font
);
169 lPtr
->font
= WMRetainFont(font
);
173 if (lPtr
->view
->flags
.realized
) {
180 WMSetLabelTextColor(WMLabel
*lPtr
, WMColor
*color
)
183 WMReleaseColor(lPtr
->textColor
);
184 lPtr
->textColor
= WMRetainColor(color
);
186 if (lPtr
->view
->flags
.realized
) {
193 WMSetLabelWraps(WMLabel
*lPtr
, Bool flag
)
195 if (lPtr
->flags
.noWrap
!= !flag
) {
196 lPtr
->flags
.noWrap
= !flag
;
197 if (lPtr
->view
->flags
.realized
)
204 paintLabel(Label
*lPtr
)
206 W_Screen
*scrPtr
= lPtr
->view
->screen
;
210 gc
= WMColorGC(lPtr
->textColor
);
212 gc
= WMColorGC(scrPtr
->black
);
214 W_PaintTextAndImage(lPtr
->view
, !lPtr
->flags
.noWrap
, gc
,
215 (lPtr
->font
!=NULL
? lPtr
->font
: scrPtr
->normalFont
),
216 lPtr
->flags
.relief
, lPtr
->caption
,
217 lPtr
->flags
.alignment
, lPtr
->image
,
218 lPtr
->flags
.imagePosition
, NULL
, 0);
224 handleEvents(XEvent
*event
, void *data
)
226 Label
*lPtr
= (Label
*)data
;
228 CHECK_CLASS(data
, WC_Label
);
231 switch (event
->type
) {
233 if (event
->xexpose
.count
!=0)
246 destroyLabel(Label
*lPtr
)
249 WMReleaseColor(lPtr
->textColor
);
252 wfree(lPtr
->caption
);
255 WMReleaseFont(lPtr
->font
);
258 WMReleasePixmap(lPtr
->image
);