9 W_DrawRelief(W_Screen
*scr
, Drawable d
, int x
, int y
, unsigned int width
,
10 unsigned int height
, WMReliefType relief
)
12 W_DrawReliefWithGC(scr
, d
, x
, y
, width
, height
, relief
,
13 WMColorGC(scr
->black
), WMColorGC(scr
->darkGray
),
14 WMColorGC(scr
->gray
), WMColorGC(scr
->white
));
19 W_DrawReliefWithGC(W_Screen
*scr
, Drawable d
, int x
, int y
, unsigned int width
,
20 unsigned int height
, WMReliefType relief
,
21 GC black
, GC dark
, GC light
, GC white
)
23 Display
*dpy
= scr
->display
;
31 XDrawRectangle(dpy
, d
, black
, x
, y
, width
-1, height
-1);
67 XDrawLine(dpy
, d
, wgc
, x
, y
, x
+width
-1, y
);
68 if (width
> 2 && relief
!= WRRaised
&& relief
!=WRPushed
) {
69 XDrawLine(dpy
, d
, lgc
, x
+1, y
+1, x
+width
-3, y
+1);
72 XDrawLine(dpy
, d
, wgc
, x
, y
, x
, y
+height
-1);
73 if (height
> 2 && relief
!= WRRaised
&& relief
!=WRPushed
) {
74 XDrawLine(dpy
, d
, lgc
, x
+1, y
+1, x
+1, y
+height
-3);
78 XDrawLine(dpy
, d
, bgc
, x
, y
+height
-1, x
+width
-1, y
+height
-1);
79 if (width
> 2 && relief
!=WRPushed
) {
80 XDrawLine(dpy
, d
, dgc
, x
+1, y
+height
-2, x
+width
-2, y
+height
-2);
83 XDrawLine(dpy
, d
, bgc
, x
+width
-1, y
, x
+width
-1, y
+height
-1);
84 if (height
> 2 && relief
!=WRPushed
) {
85 XDrawLine(dpy
, d
, dgc
, x
+width
-2, y
+1, x
+width
-2, y
+height
-2);
91 findNextWord(char *text
, int limit
)
95 len
= strcspn(text
, " \t\n\r");
96 pos
= len
+ strspn(text
+len
, " \t\n\r");
105 fitText(char *text
, WMFont
*font
, int width
, int wrap
)
107 int i
, w
, beforecrlf
, word1
, word2
;
109 /* text length before first cr/lf */
110 beforecrlf
= strcspn(text
, "\n");
112 if (!wrap
|| beforecrlf
==0)
115 w
= WMWidthOfString(font
, text
, beforecrlf
);
117 /* text up to first crlf fits */
123 word2
= word1
+ findNextWord(text
+word1
, beforecrlf
-word1
);
124 if (word2
>= beforecrlf
)
126 w
= WMWidthOfString(font
, text
, word2
);
132 for (i
=word1
; i
<word2
; i
++) {
133 w
= WMWidthOfString(font
, text
, i
);
139 /* keep words complete if possible */
140 if (!isspace(text
[i
]) && word1
>0) {
142 } else if (isspace(text
[i
]) && i
<beforecrlf
) {
143 /* keep space on current row, so new row has next word in column 1 */
153 fitText(char *text
, WMFont
*font
, int width
, int wrap
)
168 w
= WMWidthOfString(font
, text
, i
);
169 } while (w
< width
&& text
[i
]!='\n' && text
[i
]!=0);
174 /* keep words complete */
175 if (!isspace(text
[i
])) {
177 while (j
>1 && !isspace(text
[j
]) && text
[j
]!=0)
183 i
= strcspn(text
, "\n");
191 W_GetTextHeight(WMFont
*font
, char *text
, int width
, int wrap
)
195 int length
= strlen(text
);
197 int fheight
= WMFontHeight(font
);
201 count
= fitText(ptr
, font
, width
, wrap
);
205 if (isspace(ptr
[count
]))
216 W_PaintText(W_View
*view
, Drawable d
, WMFont
*font
, int x
, int y
,
217 int width
, WMAlignment alignment
, WMColor
*color
,
218 int wrap
, char *text
, int length
)
224 int fheight
= WMFontHeight(font
);
227 count
= fitText(ptr
, font
, width
, wrap
);
229 line_width
= WMWidthOfString(font
, ptr
, count
);
230 if (alignment
==WALeft
)
232 else if (alignment
==WARight
)
233 line_x
= x
+ width
- line_width
;
235 line_x
= x
+ (width
- line_width
) / 2;
237 WMDrawString(view
->screen
, d
, color
, font
, line_x
, y
, ptr
, count
);
239 if (wrap
&& ptr
[count
]!='\n')
242 while (ptr
[count
] && ptr
[count
]=='\n') {
254 W_PaintTextAndImage(W_View
*view
, int wrap
, WMColor
*textColor
, W_Font
*font
,
255 WMReliefType relief
, char *text
,
256 WMAlignment alignment
, W_Pixmap
*image
,
257 WMImagePosition position
, WMColor
*backColor
, int ofs
)
259 W_Screen
*screen
= view
->screen
;
262 Drawable d
= view
->window
;
266 d
= XCreatePixmap(screen
->display
, view
->window
,
267 view
->size
.width
, view
->size
.height
, screen
->depth
);
272 XFillRectangle(screen
->display
, d
, WMColorGC(backColor
),
273 0, 0, view
->size
.width
, view
->size
.height
);
275 #ifndef DOUBLE_BUFFER
276 XClearWindow(screen
->display
, d
);
278 XSetForeground(screen
->display
, screen
->copyGC
,
279 view
->attribs
.background_pixel
);
280 XFillRectangle(screen
->display
, d
, screen
->copyGC
, 0, 0,
281 view
->size
.width
, view
->size
.height
);
286 if (relief
== WRFlat
) {
289 w
= view
->size
.width
;
290 h
= view
->size
.height
;
294 w
= view
->size
.width
- 3;
295 h
= view
->size
.height
- 3;
298 /* calc. image alignment */
299 if (position
!=WIPNoImage
&& image
!=NULL
) {
303 ix
= (view
->size
.width
- image
->width
) / 2;
304 iy
= (view
->size
.height
- image
->height
) / 2;
313 iy
= y
+ (h
- image
->height
) / 2;
314 x
= x
+ image
->width
+ 5;
316 w
-= image
->width
+ 5;
320 ix
= view
->size
.width
- image
->width
- x
;
321 iy
= y
+ (h
- image
->height
) / 2;
322 w
-= image
->width
+ 5;
326 ix
= (view
->size
.width
- image
->width
) / 2;
327 iy
= h
- image
->height
;
334 ix
= (view
->size
.width
- image
->width
) / 2;
344 XSetClipOrigin(screen
->display
, screen
->clipGC
, ix
, iy
);
345 XSetClipMask(screen
->display
, screen
->clipGC
, image
->mask
);
348 XCopyPlane(screen
->display
, image
->pixmap
, d
, screen
->clipGC
,
349 0, 0, image
->width
, image
->height
, ix
, iy
, 1);
351 XCopyArea(screen
->display
, image
->pixmap
, d
, screen
->clipGC
,
352 0, 0, image
->width
, image
->height
, ix
, iy
);
356 if (position
!= WIPImageOnly
&& text
!=NULL
) {
359 textHeight
= W_GetTextHeight(font
, text
, w
-8, wrap
);
360 W_PaintText(view
, d
, font
, x
+ofs
+4, y
+ofs
+ (h
-textHeight
)/2, w
-8,
361 alignment
, textColor
, wrap
, text
, strlen(text
));
366 W_DrawRelief(screen
, d
, 0, 0, view
->size
.width
, view
->size
.height
, relief
);
369 XCopyArea(screen
->display
, d
, view
->window
, screen
->copyGC
, 0, 0,
370 view
->size
.width
, view
->size
.height
, 0, 0);
371 XFreePixmap(screen
->display
, d
);
378 wmkpoint(int x
, int y
)
390 wmksize(unsigned int width
, unsigned int height
)
395 size
.height
= height
;
402 wmkrect(int x
, int y
, unsigned int width
, unsigned int height
)
408 rect
.size
.width
= width
;
409 rect
.size
.height
= height
;