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;
33 W_ViewProcedureTable _LabelViewProcedures
= {
40 #define DEFAULT_WIDTH 60
41 #define DEFAULT_HEIGHT 14
42 #define DEFAULT_ALIGNMENT WALeft
43 #define DEFAULT_RELIEF WRFlat
44 #define DEFAULT_IMAGE_POSITION WIPNoImage
47 static void destroyLabel(Label
*lPtr
);
48 static void paintLabel(Label
*lPtr
);
51 static void handleEvents(XEvent
*event
, void *data
);
55 WMCreateLabel(WMWidget
*parent
)
59 lPtr
= wmalloc(sizeof(Label
));
60 memset(lPtr
, 0, sizeof(Label
));
62 lPtr
->widgetClass
= WC_Label
;
64 lPtr
->view
= W_CreateView(W_VIEW(parent
));
69 lPtr
->view
->self
= lPtr
;
71 lPtr
->textColor
= WMRetainColor(lPtr
->view
->screen
->black
);
73 WMCreateEventHandler(lPtr
->view
, ExposureMask
|StructureNotifyMask
,
76 W_ResizeView(lPtr
->view
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
77 lPtr
->flags
.alignment
= DEFAULT_ALIGNMENT
;
78 lPtr
->flags
.relief
= DEFAULT_RELIEF
;
79 lPtr
->flags
.imagePosition
= DEFAULT_IMAGE_POSITION
;
86 WMSetLabelImage(WMLabel
*lPtr
, WMPixmap
*image
)
88 if (lPtr
->image
!=NULL
)
89 WMReleasePixmap(lPtr
->image
);
92 lPtr
->image
= WMRetainPixmap(image
);
96 if (lPtr
->view
->flags
.realized
) {
103 WMGetLabelImage(WMLabel
*lPtr
)
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
)
146 lPtr
->caption
= wstrdup(text
);
148 lPtr
->caption
= NULL
;
150 if (lPtr
->view
->flags
.realized
) {
157 WMSetLabelFont(WMLabel
*lPtr
, WMFont
*font
)
159 if (lPtr
->font
!=NULL
)
160 WMReleaseFont(lPtr
->font
);
162 lPtr
->font
= WMRetainFont(font
);
166 if (lPtr
->view
->flags
.realized
) {
173 WMSetLabelTextColor(WMLabel
*lPtr
, WMColor
*color
)
176 WMReleaseColor(lPtr
->textColor
);
177 lPtr
->textColor
= WMRetainColor(color
);
182 WMSetLabelWraps(WMLabel
*lPtr
, Bool flag
)
184 if (lPtr
->flags
.noWrap
!= !flag
) {
185 lPtr
->flags
.noWrap
= !flag
;
186 if (lPtr
->view
->flags
.realized
)
193 paintLabel(Label
*lPtr
)
195 W_Screen
*scrPtr
= lPtr
->view
->screen
;
199 gc
= WMColorGC(lPtr
->textColor
);
201 gc
= WMColorGC(scrPtr
->black
);
203 W_PaintTextAndImage(lPtr
->view
, !lPtr
->flags
.noWrap
, gc
,
204 (lPtr
->font
!=NULL
? lPtr
->font
: scrPtr
->normalFont
),
205 lPtr
->flags
.relief
, lPtr
->caption
,
206 lPtr
->flags
.alignment
, lPtr
->image
,
207 lPtr
->flags
.imagePosition
, NULL
, 0);
213 handleEvents(XEvent
*event
, void *data
)
215 Label
*lPtr
= (Label
*)data
;
217 CHECK_CLASS(data
, WC_Label
);
220 switch (event
->type
) {
222 if (event
->xexpose
.count
!=0)
235 destroyLabel(Label
*lPtr
)
238 WMReleaseColor(lPtr
->textColor
);
244 WMReleaseFont(lPtr
->font
);
247 WMReleasePixmap(lPtr
->image
);