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 flag
= ((flag
==0) ? 0 : 1);
196 if (lPtr
->flags
.noWrap
!= !flag
) {
197 lPtr
->flags
.noWrap
= !flag
;
198 if (lPtr
->view
->flags
.realized
)
205 paintLabel(Label
*lPtr
)
207 W_Screen
*scrPtr
= lPtr
->view
->screen
;
209 W_PaintTextAndImage(lPtr
->view
, !lPtr
->flags
.noWrap
,
210 lPtr
->textColor
? lPtr
->textColor
: scrPtr
->black
,
211 (lPtr
->font
!=NULL
? lPtr
->font
: scrPtr
->normalFont
),
212 lPtr
->flags
.relief
, lPtr
->caption
,
213 lPtr
->flags
.alignment
, lPtr
->image
,
214 lPtr
->flags
.imagePosition
, NULL
, 0);
220 handleEvents(XEvent
*event
, void *data
)
222 Label
*lPtr
= (Label
*)data
;
224 CHECK_CLASS(data
, WC_Label
);
227 switch (event
->type
) {
229 if (event
->xexpose
.count
!=0)
242 destroyLabel(Label
*lPtr
)
245 WMReleaseColor(lPtr
->textColor
);
248 wfree(lPtr
->caption
);
251 WMReleaseFont(lPtr
->font
);
254 WMReleasePixmap(lPtr
->image
);