8 W_DrawRelief(W_Screen
* scr
, Drawable d
, int x
, int y
, unsigned int width
,
9 unsigned int height
, WMReliefType relief
)
11 W_DrawReliefWithGC(scr
, d
, x
, y
, width
, height
, relief
,
12 WMColorGC(scr
->black
), WMColorGC(scr
->darkGray
),
13 WMColorGC(scr
->gray
), WMColorGC(scr
->white
));
17 W_DrawReliefWithGC(W_Screen
* scr
, Drawable d
, int x
, int y
, unsigned int width
,
18 unsigned int height
, WMReliefType relief
, GC black
, GC dark
, GC light
, GC white
)
20 Display
*dpy
= scr
->display
;
28 XDrawRectangle(dpy
, d
, black
, x
, y
, width
- 1, height
- 1);
64 XDrawLine(dpy
, d
, wgc
, x
, y
, x
+ width
- 1, y
);
65 if (width
> 2 && relief
!= WRRaised
&& relief
!= WRPushed
) {
66 XDrawLine(dpy
, d
, lgc
, x
+ 1, y
+ 1, x
+ width
- 3, y
+ 1);
69 XDrawLine(dpy
, d
, wgc
, x
, y
, x
, y
+ height
- 1);
70 if (height
> 2 && relief
!= WRRaised
&& relief
!= WRPushed
) {
71 XDrawLine(dpy
, d
, lgc
, x
+ 1, y
+ 1, x
+ 1, y
+ height
- 3);
75 XDrawLine(dpy
, d
, bgc
, x
, y
+ height
- 1, x
+ width
- 1, y
+ height
- 1);
76 if (width
> 2 && relief
!= WRPushed
) {
77 XDrawLine(dpy
, d
, dgc
, x
+ 1, y
+ height
- 2, x
+ width
- 2, y
+ height
- 2);
80 XDrawLine(dpy
, d
, bgc
, x
+ width
- 1, y
, x
+ width
- 1, y
+ height
- 1);
81 if (height
> 2 && relief
!= WRPushed
) {
82 XDrawLine(dpy
, d
, dgc
, x
+ width
- 2, y
+ 1, x
+ width
- 2, y
+ height
- 2);
86 static int findNextWord(const char *text
, int limit
)
90 len
= strcspn(text
, " \t\n\r");
91 pos
= len
+ strspn(text
+ len
, " \t\n\r");
98 static int fitText(const char *text
, WMFont
* font
, int width
, int wrap
)
100 int i
, w
, beforecrlf
, word1
, word2
;
102 /* text length before first cr/lf */
103 beforecrlf
= strcspn(text
, "\n");
105 if (!wrap
|| beforecrlf
== 0)
108 w
= WMWidthOfString(font
, text
, beforecrlf
);
110 /* text up to first crlf fits */
116 word2
= word1
+ findNextWord(text
+ word1
, beforecrlf
- word1
);
117 if (word2
>= beforecrlf
)
119 w
= WMWidthOfString(font
, text
, word2
);
125 for (i
= word1
; i
< word2
; i
++) {
126 w
= WMWidthOfString(font
, text
, i
);
132 /* keep words complete if possible */
133 if (!isspace(text
[i
]) && word1
> 0) {
135 } else if (isspace(text
[i
]) && i
< beforecrlf
) {
136 /* keep space on current row, so new row has next word in column 1 */
143 int W_GetTextHeight(WMFont
* font
, const char *text
, int width
, int wrap
)
145 const char *ptr
= text
;
147 int length
= strlen(text
);
149 int fheight
= WMFontHeight(font
);
153 count
= fitText(ptr
, font
, width
, wrap
);
157 if (isspace(ptr
[count
]))
167 W_PaintText(W_View
* view
, Drawable d
, WMFont
* font
, int x
, int y
,
168 int width
, WMAlignment alignment
, WMColor
* color
, int wrap
,
169 const char *text
, int length
)
171 const char *ptr
= text
;
175 int fheight
= WMFontHeight(font
);
178 count
= fitText(ptr
, font
, width
, wrap
);
180 line_width
= WMWidthOfString(font
, ptr
, count
);
181 if (alignment
== WALeft
)
183 else if (alignment
== WARight
)
184 line_x
= x
+ width
- line_width
;
186 line_x
= x
+ (width
- line_width
) / 2;
188 WMDrawString(view
->screen
, d
, color
, font
, line_x
, y
, ptr
, count
);
190 if (wrap
&& ptr
[count
] != '\n')
193 while (ptr
[count
] && ptr
[count
] == '\n') {
204 W_PaintTextAndImage(W_View
* view
, int wrap
, WMColor
* textColor
, W_Font
* font
,
205 WMReliefType relief
, const char *text
,
206 WMAlignment alignment
, W_Pixmap
* image
,
207 WMImagePosition position
, WMColor
* backColor
, int ofs
)
209 W_Screen
*screen
= view
->screen
;
212 Drawable d
= view
->window
;
215 d
= XCreatePixmap(screen
->display
, view
->window
, view
->size
.width
, view
->size
.height
, screen
->depth
);
220 XFillRectangle(screen
->display
, d
, WMColorGC(backColor
),
221 0, 0, view
->size
.width
, view
->size
.height
);
223 #ifndef DOUBLE_BUFFER
224 XClearWindow(screen
->display
, d
);
226 XSetForeground(screen
->display
, screen
->copyGC
, view
->attribs
.background_pixel
);
227 XFillRectangle(screen
->display
, d
, screen
->copyGC
, 0, 0, view
->size
.width
, view
->size
.height
);
231 if (relief
== WRFlat
) {
234 w
= view
->size
.width
;
235 h
= view
->size
.height
;
239 w
= view
->size
.width
- 3;
240 h
= view
->size
.height
- 3;
243 /* calc. image alignment */
244 if (position
!= WIPNoImage
&& image
!= NULL
) {
248 ix
= (view
->size
.width
- image
->width
) / 2;
249 iy
= (view
->size
.height
- image
->height
) / 2;
258 iy
= y
+ (h
- image
->height
) / 2;
259 x
= x
+ image
->width
+ 5;
261 w
-= image
->width
+ 5;
265 ix
= view
->size
.width
- image
->width
- x
;
266 iy
= y
+ (h
- image
->height
) / 2;
267 w
-= image
->width
+ 5;
271 ix
= (view
->size
.width
- image
->width
) / 2;
272 iy
= h
- image
->height
;
279 ix
= (view
->size
.width
- image
->width
) / 2;
289 XSetClipOrigin(screen
->display
, screen
->clipGC
, ix
, iy
);
290 XSetClipMask(screen
->display
, screen
->clipGC
, image
->mask
);
292 if (image
->depth
== 1)
293 XCopyPlane(screen
->display
, image
->pixmap
, d
, screen
->clipGC
,
294 0, 0, image
->width
, image
->height
, ix
, iy
, 1);
296 XCopyArea(screen
->display
, image
->pixmap
, d
, screen
->clipGC
,
297 0, 0, image
->width
, image
->height
, ix
, iy
);
301 if (position
!= WIPImageOnly
&& text
!= NULL
) {
304 textHeight
= W_GetTextHeight(font
, text
, w
- 8, wrap
);
305 W_PaintText(view
, d
, font
, x
+ ofs
+ 4, y
+ ofs
+ (h
- textHeight
) / 2, w
- 8,
306 alignment
, textColor
, wrap
, text
, strlen(text
));
310 W_DrawRelief(screen
, d
, 0, 0, view
->size
.width
, view
->size
.height
, relief
);
313 XCopyArea(screen
->display
, d
, view
->window
, screen
->copyGC
, 0, 0,
314 view
->size
.width
, view
->size
.height
, 0, 0);
315 XFreePixmap(screen
->display
, d
);
319 WMPoint
wmkpoint(int x
, int y
)
329 WMSize
wmksize(unsigned int width
, unsigned int height
)
334 size
.height
= height
;
339 WMRect
wmkrect(int x
, int y
, unsigned int width
, unsigned int height
)
345 rect
.size
.width
= width
;
346 rect
.size
.height
= height
;