4 typedef struct W_Label
{
11 WMFont
*font
; /* if NULL, use default */
16 WMReliefType relief
:3;
17 WMImagePosition imagePosition
:4;
18 WMAlignment alignment
:2;
20 unsigned int noWrap
:1;
22 unsigned int redrawPending
:1;
26 #define DEFAULT_WIDTH 60
27 #define DEFAULT_HEIGHT 14
28 #define DEFAULT_ALIGNMENT WALeft
29 #define DEFAULT_RELIEF WRFlat
30 #define DEFAULT_IMAGE_POSITION WIPNoImage
32 static void destroyLabel(Label
* lPtr
);
33 static void paintLabel(Label
* lPtr
);
35 static void handleEvents(XEvent
* event
, void *data
);
37 WMLabel
*WMCreateLabel(WMWidget
* parent
)
41 lPtr
= wmalloc(sizeof(Label
));
43 lPtr
->widgetClass
= WC_Label
;
45 lPtr
->view
= W_CreateView(W_VIEW(parent
));
50 lPtr
->view
->self
= lPtr
;
52 lPtr
->textColor
= WMRetainColor(lPtr
->view
->screen
->black
);
54 WMCreateEventHandler(lPtr
->view
, ExposureMask
| StructureNotifyMask
, handleEvents
, lPtr
);
56 W_ResizeView(lPtr
->view
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
57 lPtr
->flags
.alignment
= DEFAULT_ALIGNMENT
;
58 lPtr
->flags
.relief
= DEFAULT_RELIEF
;
59 lPtr
->flags
.imagePosition
= DEFAULT_IMAGE_POSITION
;
60 lPtr
->flags
.noWrap
= 1;
65 void WMSetLabelImage(WMLabel
* lPtr
, WMPixmap
* image
)
67 if (lPtr
->image
!= NULL
)
68 WMReleasePixmap(lPtr
->image
);
71 lPtr
->image
= WMRetainPixmap(image
);
75 if (lPtr
->view
->flags
.realized
) {
80 WMPixmap
*WMGetLabelImage(WMLabel
* lPtr
)
85 char *WMGetLabelText(WMLabel
* lPtr
)
90 void WMSetLabelImagePosition(WMLabel
* lPtr
, WMImagePosition position
)
92 lPtr
->flags
.imagePosition
= position
;
93 if (lPtr
->view
->flags
.realized
) {
98 void WMSetLabelTextAlignment(WMLabel
* lPtr
, WMAlignment alignment
)
100 lPtr
->flags
.alignment
= alignment
;
101 if (lPtr
->view
->flags
.realized
) {
106 void WMSetLabelRelief(WMLabel
* lPtr
, WMReliefType relief
)
108 lPtr
->flags
.relief
= relief
;
109 if (lPtr
->view
->flags
.realized
) {
114 void WMSetLabelText(WMLabel
* lPtr
, const char *text
)
117 wfree(lPtr
->caption
);
120 lPtr
->caption
= wstrdup(text
);
122 lPtr
->caption
= NULL
;
124 if (lPtr
->view
->flags
.realized
) {
129 WMFont
*WMGetLabelFont(WMLabel
* lPtr
)
134 void WMSetLabelFont(WMLabel
* lPtr
, WMFont
* font
)
136 if (lPtr
->font
!= NULL
)
137 WMReleaseFont(lPtr
->font
);
139 lPtr
->font
= WMRetainFont(font
);
143 if (lPtr
->view
->flags
.realized
) {
148 void WMSetLabelTextColor(WMLabel
* lPtr
, WMColor
* color
)
151 WMReleaseColor(lPtr
->textColor
);
152 lPtr
->textColor
= WMRetainColor(color
);
154 if (lPtr
->view
->flags
.realized
) {
159 void WMSetLabelWraps(WMLabel
* lPtr
, Bool flag
)
161 flag
= ((flag
== 0) ? 0 : 1);
162 if (lPtr
->flags
.noWrap
!= !flag
) {
163 lPtr
->flags
.noWrap
= !flag
;
164 if (lPtr
->view
->flags
.realized
)
169 static void paintLabel(Label
* lPtr
)
171 W_Screen
*scrPtr
= lPtr
->view
->screen
;
173 W_PaintTextAndImage(lPtr
->view
, !lPtr
->flags
.noWrap
,
174 lPtr
->textColor
? lPtr
->textColor
: scrPtr
->black
,
175 (lPtr
->font
!= NULL
? lPtr
->font
: scrPtr
->normalFont
),
176 lPtr
->flags
.relief
, lPtr
->caption
,
177 lPtr
->flags
.alignment
, lPtr
->image
, lPtr
->flags
.imagePosition
, NULL
, 0);
180 static void handleEvents(XEvent
* event
, void *data
)
182 Label
*lPtr
= (Label
*) data
;
184 CHECK_CLASS(data
, WC_Label
);
186 switch (event
->type
) {
188 if (event
->xexpose
.count
!= 0)
199 static void destroyLabel(Label
* lPtr
)
202 WMReleaseColor(lPtr
->textColor
);
205 wfree(lPtr
->caption
);
208 WMReleaseFont(lPtr
->font
);
211 WMReleasePixmap(lPtr
->image
);