source: trunk/src/user32/uitools.cpp@ 1110

Last change on this file since 1110 was 1110, checked in by cbratschi, 26 years ago

added DT_END_ELLIPSIS for DrawTextA/W

File size: 68.9 KB
Line 
1/* $Id: uitools.cpp,v 1.8 1999-10-02 13:57:29 cbratschi Exp $ */
2/*
3 * User Interface Functions
4 *
5 * Copyright 1997 Dimitrie O. Paun
6 * Copyright 1997 Bertho A. Stultiens
7 * Copyright 1999 Achim Hasenmueller
8 * Copyright 1999 Christoph Bratschi
9 * Copyright 1999 Rene Pronk
10 */
11
12#include "winuser.h"
13#include "user32.h"
14
15static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555,
16 0xaaaa, 0x5555, 0xaaaa, 0x5555 };
17
18/* These tables are used in:
19 * UITOOLS_DrawDiagEdge()
20 * UITOOLS_DrawRectEdge()
21 */
22static const char LTInnerNormal[] = {
23 -1, -1, -1, -1,
24 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
25 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
26 -1, -1, -1, -1
27};
28
29static const char LTOuterNormal[] = {
30 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
31 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
32 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
33 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
34};
35
36static const char RBInnerNormal[] = {
37 -1, -1, -1, -1,
38 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
39 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
40 -1, -1, -1, -1
41};
42
43static const char RBOuterNormal[] = {
44 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
45 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
46 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
47 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
48};
49
50static const char LTInnerSoft[] = {
51 -1, -1, -1, -1,
52 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
53 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
54 -1, -1, -1, -1
55};
56
57static const char LTOuterSoft[] = {
58 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
59 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
60 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
61 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
62};
63
64#define RBInnerSoft RBInnerNormal /* These are the same */
65#define RBOuterSoft RBOuterNormal
66
67static const char LTRBOuterMono[] = {
68 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
69 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
70 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
71 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
72};
73
74static const char LTRBInnerMono[] = {
75 -1, -1, -1, -1,
76 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
77 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
78 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
79};
80
81static const char LTRBOuterFlat[] = {
82 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
83 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
84 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
85 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
86};
87
88static const char LTRBInnerFlat[] = {
89 -1, -1, -1, -1,
90 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
91 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
92 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
93};
94
95/***********************************************************************
96 * UITOOLS_DrawDiagEdge
97 *
98 * Same as DrawEdge invoked with BF_DIAGONAL
99 *
100 * 03-Dec-1997: Changed by Bertho Stultiens
101 *
102 * See also comments with UITOOLS_DrawRectEdge()
103 */
104static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
105 UINT uType, UINT uFlags)
106{
107 POINT Points[4];
108 char InnerI, OuterI;
109 HPEN InnerPen, OuterPen;
110 POINT SavePoint;
111 HPEN SavePen;
112 int spx, spy;
113 int epx, epy;
114 int Width = rc->right - rc->left;
115 int Height= rc->bottom - rc->top;
116 int SmallDiam = Width > Height ? Height : Width;
117 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
118 || (uType & BDR_OUTER) == BDR_OUTER)
119 && !(uFlags & (BF_FLAT|BF_MONO)) );
120 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
121 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
122
123 if (IsRectEmpty(rc)) return retval; //nothing to do
124
125 /* Init some vars */
126 OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
127 SavePen = (HPEN)SelectObject(hdc, InnerPen);
128 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
129
130 /* Determine the colors of the edges */
131 if(uFlags & BF_MONO)
132 {
133 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
134 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
135 }
136 else if(uFlags & BF_FLAT)
137 {
138 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
139 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
140 }
141 else if(uFlags & BF_SOFT)
142 {
143 if(uFlags & BF_BOTTOM)
144 {
145 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
146 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
147 }
148 else
149 {
150 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
151 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
152 }
153 }
154 else
155 {
156 if(uFlags & BF_BOTTOM)
157 {
158 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
159 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
160 }
161 else
162 {
163 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
164 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
165 }
166 }
167
168 if(InnerI != -1) InnerPen = GetSysColorPen(InnerI);
169 if(OuterI != -1) OuterPen = GetSysColorPen(OuterI);
170
171 MoveToEx(hdc, 0, 0, &SavePoint);
172
173 /* Don't ask me why, but this is what is visible... */
174 /* This must be possible to do much simpler, but I fail to */
175 /* see the logic in the MS implementation (sigh...). */
176 /* So, this might look a bit brute force here (and it is), but */
177 /* it gets the job done;) */
178
179 switch(uFlags & BF_RECT)
180 {
181 case 0:
182 case BF_LEFT:
183 case BF_BOTTOM:
184 case BF_BOTTOMLEFT:
185 /* Left bottom endpoint */
186 epx = rc->left-1;
187 spx = epx + SmallDiam;
188 epy = rc->bottom;
189 spy = epy - SmallDiam;
190 epx++;
191 epy--;
192 break;
193
194 case BF_TOPLEFT:
195 case BF_BOTTOMRIGHT:
196 /* Left top endpoint */
197 epx = rc->left-1;
198 spx = epx + SmallDiam;
199 epy = rc->top-1;
200 spy = epy + SmallDiam;
201 epx++;
202 epy++;
203 break;
204
205 case BF_TOP:
206 case BF_RIGHT:
207 case BF_TOPRIGHT:
208 case BF_RIGHT|BF_LEFT:
209 case BF_RIGHT|BF_LEFT|BF_TOP:
210 case BF_BOTTOM|BF_TOP:
211 case BF_BOTTOM|BF_TOP|BF_LEFT:
212 case BF_BOTTOMRIGHT|BF_LEFT:
213 case BF_BOTTOMRIGHT|BF_TOP:
214 case BF_RECT:
215 /* Right top endpoint */
216 spx = rc->left;
217 epx = spx + SmallDiam;
218 spy = rc->bottom-1;
219 epy = spy - SmallDiam;
220 epx--;
221 epy++;
222 break;
223 }
224
225 MoveToEx(hdc, spx, spy, NULL);
226 SelectObject(hdc, OuterPen);
227 LineTo(hdc, epx, epy);
228
229 SelectObject(hdc, InnerPen);
230
231 switch(uFlags & (BF_RECT|BF_DIAGONAL))
232 {
233 case BF_DIAGONAL_ENDBOTTOMLEFT:
234 case (BF_DIAGONAL|BF_BOTTOM):
235 case BF_DIAGONAL:
236 case (BF_DIAGONAL|BF_LEFT):
237 MoveToEx(hdc, spx-1, spy, NULL);
238 LineTo(hdc, epx, epy-1);
239 Points[0].x = spx-add;
240 Points[0].y = spy;
241 Points[1].x = rc->left;
242 Points[1].y = rc->top;
243 Points[2].x = epx+1;
244 Points[2].y = epy-1-add;
245 Points[3] = Points[2];
246 break;
247
248 case BF_DIAGONAL_ENDBOTTOMRIGHT:
249 MoveToEx(hdc, spx-1, spy, NULL);
250 LineTo(hdc, epx, epy+1);
251 Points[0].x = spx-add;
252 Points[0].y = spy;
253 Points[1].x = rc->left;
254 Points[1].y = rc->bottom-1;
255 Points[2].x = epx+1;
256 Points[2].y = epy+1+add;
257 Points[3] = Points[2];
258 break;
259
260 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
261 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
262 case BF_DIAGONAL_ENDTOPRIGHT:
263 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
264 MoveToEx(hdc, spx+1, spy, NULL);
265 LineTo(hdc, epx, epy+1);
266 Points[0].x = epx-1;
267 Points[0].y = epy+1+add;
268 Points[1].x = rc->right-1;
269 Points[1].y = rc->top+add;
270 Points[2].x = rc->right-1;
271 Points[2].y = rc->bottom-1;
272 Points[3].x = spx+add;
273 Points[3].y = spy;
274 break;
275
276 case BF_DIAGONAL_ENDTOPLEFT:
277 MoveToEx(hdc, spx, spy-1, NULL);
278 LineTo(hdc, epx+1, epy);
279 Points[0].x = epx+1+add;
280 Points[0].y = epy+1;
281 Points[1].x = rc->right-1;
282 Points[1].y = rc->top;
283 Points[2].x = rc->right-1;
284 Points[2].y = rc->bottom-1-add;
285 Points[3].x = spx;
286 Points[3].y = spy-add;
287 break;
288
289 case (BF_DIAGONAL|BF_TOP):
290 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
291 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
292 MoveToEx(hdc, spx+1, spy-1, NULL);
293 LineTo(hdc, epx, epy);
294 Points[0].x = epx-1;
295 Points[0].y = epy+1;
296 Points[1].x = rc->right-1;
297 Points[1].y = rc->top;
298 Points[2].x = rc->right-1;
299 Points[2].y = rc->bottom-1-add;
300 Points[3].x = spx+add;
301 Points[3].y = spy-add;
302 break;
303
304 case (BF_DIAGONAL|BF_RIGHT):
305 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
306 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
307 MoveToEx(hdc, spx, spy, NULL);
308 LineTo(hdc, epx-1, epy+1);
309 Points[0].x = spx;
310 Points[0].y = spy;
311 Points[1].x = rc->left;
312 Points[1].y = rc->top+add;
313 Points[2].x = epx-1-add;
314 Points[2].y = epy+1+add;
315 Points[3] = Points[2];
316 break;
317 }
318
319 /* Fill the interior if asked */
320 if((uFlags & BF_MIDDLE) && retval)
321 {
322 HBRUSH hbsave;
323 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
324 :COLOR_BTNFACE);
325 HPEN hpsave;
326 HPEN hp = GetSysColorPen(uFlags & BF_MONO ? COLOR_WINDOW
327 : COLOR_BTNFACE);
328 hbsave = (HBRUSH)SelectObject(hdc, hb);
329 hpsave = (HPEN)SelectObject(hdc, hp);
330 Polygon(hdc, Points, 4);
331 SelectObject(hdc, hbsave);
332 SelectObject(hdc, hpsave);
333 }
334
335 /* Adjust rectangle if asked */
336 if(uFlags & BF_ADJUST)
337 {
338 if(uFlags & BF_LEFT) rc->left += add;
339 if(uFlags & BF_RIGHT) rc->right -= add;
340 if(uFlags & BF_TOP) rc->top += add;
341 if(uFlags & BF_BOTTOM) rc->bottom -= add;
342 }
343
344 /* Cleanup */
345 SelectObject(hdc, SavePen);
346 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
347
348 return retval;
349}
350
351/***********************************************************************
352 * UITOOLS_DrawRectEdge
353 *
354 * Same as DrawEdge invoked without BF_DIAGONAL
355 *
356 * 23-Nov-1997: Changed by Bertho Stultiens
357 * 25-June-1999: Changed by Christoph Bratschi
358 *
359 * Attention: only draw in the rect's range!
360 * left to right-1
361 * top to bottom-1
362 *
363 * Well, I started testing this and found out that there are a few things
364 * that weren't quite as win95. The following rewrite should reproduce
365 * win95 results completely.
366 * The colorselection is table-driven to avoid awfull if-statements.
367 * The table below show the color settings.
368 *
369 * Pen selection table for uFlags = 0
370 *
371 * uType | LTI | LTO | RBI | RBO
372 * ------+-------+-------+-------+-------
373 * 0000 | x | x | x | x
374 * 0001 | x | 22 | x | 21
375 * 0010 | x | 16 | x | 20
376 * 0011 | x | x | x | x
377 * ------+-------+-------+-------+-------
378 * 0100 | x | 20 | x | 16
379 * 0101 | 20 | 22 | 16 | 21
380 * 0110 | 20 | 16 | 16 | 20
381 * 0111 | x | x | x | x
382 * ------+-------+-------+-------+-------
383 * 1000 | x | 21 | x | 22
384 * 1001 | 21 | 22 | 22 | 21
385 * 1010 | 21 | 16 | 22 | 20
386 * 1011 | x | x | x | x
387 * ------+-------+-------+-------+-------
388 * 1100 | x | x | x | x
389 * 1101 | x | x (22)| x | x (21)
390 * 1110 | x | x (16)| x | x (20)
391 * 1111 | x | x | x | x
392 *
393 * Pen selection table for uFlags = BF_SOFT
394 *
395 * uType | LTI | LTO | RBI | RBO
396 * ------+-------+-------+-------+-------
397 * 0000 | x | x | x | x
398 * 0001 | x | 20 | x | 21
399 * 0010 | x | 21 | x | 20
400 * 0011 | x | x | x | x
401 * ------+-------+-------+-------+-------
402 * 0100 | x | 22 | x | 16
403 * 0101 | 22 | 20 | 16 | 21
404 * 0110 | 22 | 21 | 16 | 20
405 * 0111 | x | x | x | x
406 * ------+-------+-------+-------+-------
407 * 1000 | x | 16 | x | 22
408 * 1001 | 16 | 20 | 22 | 21
409 * 1010 | 16 | 21 | 22 | 20
410 * 1011 | x | x | x | x
411 * ------+-------+-------+-------+-------
412 * 1100 | x | x | x | x
413 * 1101 | x | x (20)| x | x (21)
414 * 1110 | x | x (21)| x | x (20)
415 * 1111 | x | x | x | x
416 *
417 * x = don't care; (n) = is what win95 actually uses
418 * LTI = left Top Inner line
419 * LTO = left Top Outer line
420 * RBI = Right Bottom Inner line
421 * RBO = Right Bottom Outer line
422 * 15 = COLOR_BTNFACE
423 * 16 = COLOR_BTNSHADOW
424 * 20 = COLOR_BTNHIGHLIGHT
425 * 21 = COLOR_3DDKSHADOW
426 * 22 = COLOR_3DLIGHT
427 */
428
429
430static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
431 UINT uType, UINT uFlags)
432{
433 char LTInnerI, LTOuterI;
434 char RBInnerI, RBOuterI;
435 HPEN LTInnerPen, LTOuterPen;
436 HPEN RBInnerPen, RBOuterPen;
437 RECT InnerRect = *rc;
438 POINT SavePoint;
439 HPEN SavePen;
440 int LBpenplus = 0;
441 int LTpenplus = 0;
442 int RTpenplus = 0;
443 int RBpenplus = 0;
444 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
445 || (uType & BDR_OUTER) == BDR_OUTER)
446 && !(uFlags & (BF_FLAT|BF_MONO)) );
447
448 if (IsRectEmpty(rc)) return retval; //nothing to do
449
450 /* Init some vars */
451 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
452 SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
453
454 /* Determine the colors of the edges */
455 if(uFlags & BF_MONO)
456 {
457 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
458 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
459 }
460 else if(uFlags & BF_FLAT)
461 {
462 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
463 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
464
465 /* Bertho Stultiens states above that this function exactly matches win95
466 * In win98 BF_FLAT rectangels have an inner border same color as the
467 * middle (COLOR_BTNFACE). I believe it's the same for win95 but since
468 * I don't know I go with Bertho and just sets it for win98 until proven
469 * otherwise.
470 * Dennis Björklund, 10 June, 99
471 */
472 if(LTInnerI != -1 )
473 LTInnerI = RBInnerI = COLOR_BTNFACE;
474 }
475 else if(uFlags & BF_SOFT)
476 {
477 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
478 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
479 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
480 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
481 }
482 else
483 {
484 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
485 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
486 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
487 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
488 }
489
490 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
491 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
492 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
493 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
494
495 if(LTInnerI != -1) LTInnerPen = GetSysColorPen(LTInnerI);
496 if(LTOuterI != -1) LTOuterPen = GetSysColorPen(LTOuterI);
497 if(RBInnerI != -1) RBInnerPen = GetSysColorPen(RBInnerI);
498 if(RBOuterI != -1) RBOuterPen = GetSysColorPen(RBOuterI);
499
500 MoveToEx(hdc, 0, 0, &SavePoint);
501
502 /* Draw the outer edge */
503 SelectObject(hdc, LTOuterPen);
504 if(uFlags & BF_TOP)
505 {
506 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
507 LineTo(hdc, InnerRect.right-1, InnerRect.top);
508 }
509 if(uFlags & BF_LEFT)
510 {
511 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
512 LineTo(hdc, InnerRect.left, InnerRect.bottom-1);
513 }
514
515 SelectObject(hdc, RBOuterPen);
516 if(uFlags & BF_BOTTOM)
517 {
518 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
519 LineTo(hdc, InnerRect.left, InnerRect.bottom-1);
520 }
521 if(uFlags & BF_RIGHT)
522 {
523 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
524 LineTo(hdc, InnerRect.right-1, InnerRect.top);
525 }
526
527 /* Draw the inner edge */
528 SelectObject(hdc, LTInnerPen);
529 if(uFlags & BF_TOP)
530 {
531 MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
532 LineTo(hdc, InnerRect.right-RTpenplus-1, InnerRect.top+1);
533 }
534 if(uFlags & BF_LEFT)
535 {
536 MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
537 LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus-1);
538 }
539 SelectObject(hdc, RBInnerPen);
540 if(uFlags & BF_BOTTOM)
541 {
542 MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
543 LineTo(hdc, InnerRect.left+LBpenplus, InnerRect.bottom-2);
544 }
545 if(uFlags & BF_RIGHT)
546 {
547 MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
548 LineTo(hdc, InnerRect.right-2, InnerRect.top+RTpenplus);
549 }
550
551 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
552 {
553 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
554 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
555
556 if(uFlags & BF_LEFT) InnerRect.left += add;
557 if(uFlags & BF_RIGHT) InnerRect.right -= add;
558 if(uFlags & BF_TOP) InnerRect.top += add;
559 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
560
561 if((uFlags & BF_MIDDLE) && retval)
562 {
563 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
564 COLOR_WINDOW : COLOR_BTNFACE));
565 }
566
567 if(uFlags & BF_ADJUST)
568 *rc = InnerRect;
569 }
570
571 /* Cleanup */
572 SelectObject(hdc, SavePen);
573 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
574 return retval;
575}
576
577
578//**********************************************************************
579// DrawEdge (USER32.155)
580//
581BOOL WIN32API DrawEdge(HDC hdc, LPRECT rc, UINT edge, UINT flags)
582{
583
584 if (flags & BF_DIAGONAL)
585 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
586 else
587 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags);
588}
589
590/************************************************************************
591 * UITOOLS_MakeSquareRect
592 *
593 * Utility to create a square rectangle and returning the width
594 */
595static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
596{
597 int Width = src->right - src->left;
598 int Height = src->bottom - src->top;
599 int SmallDiam = Width > Height ? Height : Width;
600
601 *dst = *src;
602
603 /* Make it a square box */
604 if(Width < Height) /* SmallDiam == Width */
605 {
606 dst->top += (Height-Width)/2;
607 dst->bottom = dst->top + SmallDiam;
608 }
609 else if(Width > Height) /* SmallDiam == Height */
610 {
611 dst->left += (Width-Height)/2;
612 dst->right = dst->left + SmallDiam;
613 }
614
615 return SmallDiam;
616}
617
618
619/************************************************************************
620 * UITOOLS_DFC_ButtonPush
621 *
622 * Draw a push button coming from DrawFrameControl()
623 *
624 * Does a pretty good job in emulating MS behavior. Some quirks are
625 * however there because MS uses a TrueType font (Marlett) to draw
626 * the buttons.
627 */
628static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
629{
630 UINT edge;
631 RECT myr = *r;
632
633 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
634 edge = EDGE_SUNKEN;
635 else
636 edge = EDGE_RAISED;
637
638 if(uFlags & DFCS_CHECKED)
639 {
640 if(uFlags & DFCS_MONO)
641 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
642 else
643 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
644
645 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
646 {
647 HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wPattern_AA55);
648 HBRUSH hbsave;
649 HBRUSH hb = CreatePatternBrush(hbm);
650
651 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
652 hbsave = (HBRUSH)SelectObject(dc, hb);
653 PatBlt(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
654 SelectObject(dc, hbsave);
655 DeleteObject(hb);
656 DeleteObject(hbm);
657 }
658 else
659 {
660 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
661 }
662 }
663 else
664 {
665 if(uFlags & DFCS_MONO)
666 {
667 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
668 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
669 }
670 else
671 {
672 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags&DFCS_FLAT) | BF_MIDDLE |BF_SOFT| BF_RECT);
673 }
674 }
675
676 /* Adjust rectangle if asked */
677 if(uFlags & DFCS_ADJUSTRECT)
678 {
679 r->left += 2;
680 r->right -= 2;
681 r->top += 2;
682 r->bottom -= 2;
683 }
684
685 return TRUE;
686}
687
688
689/************************************************************************
690 * UITOOLS_DFC_ButtonChcek
691 *
692 * Draw a check/3state button coming from DrawFrameControl()
693 *
694 * Does a pretty good job in emulating MS behavior. Some quirks are
695 * however there because MS uses a TrueType font (Marlett) to draw
696 * the buttons.
697 */
698#define DFC_CHECKPOINTSMAX 6
699
700static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
701{
702 RECT myr;
703 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
704 int BorderShrink = SmallDiam / 16;
705
706 if(BorderShrink < 1) BorderShrink = 1;
707
708 /* FIXME: The FillRect() sequence doesn't work for sizes less than */
709 /* 4 pixels in diameter. Not really a problem but it isn't M$'s */
710 /* 100% equivalent. */
711 if(uFlags & (DFCS_FLAT|DFCS_MONO))
712 {
713 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOWFRAME));
714 myr.left += 2 * BorderShrink;
715 myr.right -= 2 * BorderShrink;
716 myr.top += 2 * BorderShrink;
717 myr.bottom -= 2 * BorderShrink;
718 }
719 else
720 {
721 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
722 myr.right -= BorderShrink;
723 myr.bottom -= BorderShrink;
724 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNSHADOW));
725 myr.left += BorderShrink;
726 myr.top += BorderShrink;
727 FillRect(dc, &myr, GetSysColorBrush(COLOR_3DLIGHT));
728 myr.right -= BorderShrink;
729 myr.bottom -= BorderShrink;
730 FillRect(dc, &myr, GetSysColorBrush(COLOR_3DDKSHADOW));
731 myr.left += BorderShrink;
732 myr.top += BorderShrink;
733 }
734
735 if(uFlags & (DFCS_INACTIVE|DFCS_PUSHED))
736 {
737 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
738 }
739 else if(uFlags & DFCS_CHECKED)
740 {
741 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
742 {
743 HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wPattern_AA55);
744 HBRUSH hbsave;
745 HBRUSH hb = CreatePatternBrush(hbm);
746
747 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
748 hbsave = (HBRUSH)SelectObject(dc, hb);
749 PatBlt(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
750 SelectObject(dc, hbsave);
751 DeleteObject(hb);
752 DeleteObject(hbm);
753 }
754 else
755 {
756 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
757 }
758 }
759 else
760 {
761 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
762 }
763
764 if(uFlags & DFCS_CHECKED)
765 {
766 POINT CheckPoints[DFC_CHECKPOINTSMAX];
767 int i;
768 HBRUSH hbsave;
769 HPEN hpsave;
770
771 /* FIXME: This comes very close to M$'s checkmark, but not */
772 /* exactly... When small or large there is a few pixels */
773 /* shift. Not bad, but could be better :) */
774 UITOOLS_MakeSquareRect(r, &myr);
775 CheckPoints[0].x = myr.left + 253*SmallDiam/1000;
776 CheckPoints[0].y = myr.top + 345*SmallDiam/1000;
777 CheckPoints[1].x = myr.left + 409*SmallDiam/1000;
778 CheckPoints[1].y = CheckPoints[0].y + (CheckPoints[1].x-CheckPoints[0].x);
779 CheckPoints[2].x = myr.left + 690*SmallDiam/1000;
780 CheckPoints[2].y = CheckPoints[1].y - (CheckPoints[2].x-CheckPoints[1].x);
781 CheckPoints[3].x = CheckPoints[2].x;
782 CheckPoints[3].y = CheckPoints[2].y + 3*SmallDiam/16;
783 CheckPoints[4].x = CheckPoints[1].x;
784 CheckPoints[4].y = CheckPoints[1].y + 3*SmallDiam/16;
785 CheckPoints[5].x = CheckPoints[0].x;
786 CheckPoints[5].y = CheckPoints[0].y + 3*SmallDiam/16;
787
788 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
789 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
790 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
791 Polygon(dc, CheckPoints, DFC_CHECKPOINTSMAX);
792 SelectObject(dc, hpsave);
793 SelectObject(dc, hbsave);
794 }
795 return TRUE;
796}
797
798
799/************************************************************************
800 * UITOOLS_DFC_ButtonRadio
801 *
802 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
803 *
804 * Does a pretty good job in emulating MS behavior. Some quirks are
805 * however there because MS uses a TrueType font (Marlett) to draw
806 * the buttons.
807 */
808static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
809{
810 RECT myr;
811 int i;
812 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
813 int BorderShrink = SmallDiam / 16;
814 HPEN hpsave;
815 HBRUSH hbsave;
816 int xe, ye;
817 int xc, yc;
818
819 if(BorderShrink < 1) BorderShrink = 1;
820
821 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
822 {
823 FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
824 }
825
826 xe = myr.left;
827 ye = myr.top + SmallDiam - SmallDiam/2;
828
829 xc = myr.left + SmallDiam - SmallDiam/2;
830 yc = myr.top + SmallDiam - SmallDiam/2;
831
832 /* Define bounding box */
833 i = 14*SmallDiam/16;
834 myr.left = xc - i+i/2;
835 myr.right = xc + i/2;
836 myr.top = yc - i+i/2;
837 myr.bottom = yc + i/2;
838
839 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
840 {
841 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
842 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
843 SelectObject(dc, hbsave);
844 }
845 else
846 {
847 if(uFlags & (DFCS_FLAT|DFCS_MONO))
848 {
849 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_WINDOWFRAME));
850 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
851 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
852 SelectObject(dc, hbsave);
853 SelectObject(dc, hpsave);
854 }
855 else
856 {
857 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT));
858 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
859 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
860
861 SelectObject(dc, GetSysColorPen(COLOR_BTNSHADOW));
862 SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
863 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
864
865 myr.left += BorderShrink;
866 myr.right -= BorderShrink;
867 myr.top += BorderShrink;
868 myr.bottom -= BorderShrink;
869
870 SelectObject(dc, GetSysColorPen(COLOR_3DLIGHT));
871 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
872 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
873
874 SelectObject(dc, GetSysColorPen(COLOR_3DDKSHADOW));
875 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
876 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
877 SelectObject(dc, hbsave);
878 SelectObject(dc, hpsave);
879 }
880
881 i = 10*SmallDiam/16;
882 myr.left = xc - i+i/2;
883 myr.right = xc + i/2;
884 myr.top = yc - i+i/2;
885 myr.bottom = yc + i/2;
886 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
887 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
888 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
889 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
890 SelectObject(dc, hbsave);
891 SelectObject(dc, hpsave);
892 }
893
894 if(uFlags & DFCS_CHECKED)
895 {
896 i = 6*SmallDiam/16;
897 i = i < 1 ? 1 : i;
898 myr.left = xc - i+i/2;
899 myr.right = xc + i/2;
900 myr.top = yc - i+i/2;
901 myr.bottom = yc + i/2;
902
903 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
904 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
905 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
906 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
907 SelectObject(dc, hpsave);
908 SelectObject(dc, hbsave);
909 }
910
911 /* FIXME: M$ has a polygon in the center at relative points: */
912 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
913 /* 0.476, 0.525 */
914 /* 0.500, 0.500 */
915 /* 0.500, 0.499 */
916 /* when the button is unchecked. The reason for it is unknown. The */
917 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
918 /* least 3 times (it looks like a clip-region when you see it happen). */
919 /* I do not really see a reason why this should be implemented. If you */
920 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
921 /* font. */
922
923 return TRUE;
924}
925
926/***********************************************************************
927 * UITOOLS_DrawFrameButton
928 */
929static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
930{
931 switch(uState & 0xff)
932 {
933 case DFCS_BUTTONPUSH:
934 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
935
936 case DFCS_BUTTONCHECK:
937 case DFCS_BUTTON3STATE:
938 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
939
940 case DFCS_BUTTONRADIOIMAGE:
941 case DFCS_BUTTONRADIOMASK:
942 case DFCS_BUTTONRADIO:
943 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
944
945// default:
946// WARN("Invalid button state=0x%04x\n", uState);
947 }
948
949 return FALSE;
950}
951
952/***********************************************************************
953 * UITOOLS_DrawFrameCaption
954 *
955 * Draw caption buttons (win95), coming from DrawFrameControl()
956 */
957
958static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
959{
960 POINT Line1[10];
961 POINT Line2[10];
962 int Line1N;
963 int Line2N;
964 RECT myr;
965 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
966 int i;
967 HBRUSH hbsave;
968 HPEN hpsave;
969 HFONT hfsave, hf;
970 int xc = (myr.left+myr.right)/2;
971 int yc = (myr.top+myr.bottom)/2;
972 int edge, move;
973 char str[2] = "?";
974 UINT alignsave;
975 int bksave;
976 COLORREF clrsave;
977 SIZE size;
978
979 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
980
981 switch(uFlags & 0xff)
982 {
983 case DFCS_CAPTIONCLOSE:
984 edge = 328*SmallDiam/1000;
985 move = 95*SmallDiam/1000;
986 Line1[0].x = Line2[0].x = Line1[1].x = Line2[1].x = xc - edge;
987 Line1[2].y = Line2[5].y = Line1[1].y = Line2[4].y = yc - edge;
988 Line1[3].x = Line2[3].x = Line1[4].x = Line2[4].x = xc + edge;
989 Line1[5].y = Line2[2].y = Line1[4].y = Line2[1].y = yc + edge;
990 Line1[2].x = Line2[2].x = Line1[1].x + move;
991 Line1[0].y = Line2[3].y = Line1[1].y + move;
992 Line1[5].x = Line2[5].x = Line1[4].x - move;
993 Line1[3].y = Line2[0].y = Line1[4].y - move;
994 Line1N = 6;
995 Line2N = 6;
996 break;
997
998 case DFCS_CAPTIONHELP:
999 /* This one breaks the flow */
1000 /* FIXME: We need the Marlett font in order to get this right. */
1001
1002 hf = CreateFontA(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
1003 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
1004 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
1005 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
1006 bksave = SetBkMode(dc, TRANSPARENT);
1007 clrsave = GetTextColor(dc);
1008 hfsave = (HFONT)SelectObject(dc, hf);
1009 GetTextExtentPoint32A(dc, str, 1, &size);
1010
1011 if(uFlags & DFCS_INACTIVE)
1012 {
1013 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
1014 TextOutA(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
1015 }
1016 SetTextColor(dc, GetSysColor(uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT));
1017 TextOutA(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1018
1019 SelectObject(dc, hfsave);
1020 SetTextColor(dc, clrsave);
1021 SetBkMode(dc, bksave);
1022 SetTextAlign(dc, alignsave);
1023 DeleteObject(hf);
1024 return TRUE;
1025
1026 case DFCS_CAPTIONMIN:
1027 Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2;
1028 Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1029 Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1;
1030 Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750;
1031 Line1N = 4;
1032 Line2N = 0;
1033 break;
1034
1035 case DFCS_CAPTIONMAX:
1036 edge = 47*SmallDiam/750;
1037 Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3;
1038 Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1;
1039 Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1040 Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750;
1041 Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1042 Line1[3].x = Line1[4].x = Line1[1].x - edge;
1043
1044 Line2[0].x = Line2[5].x = Line1[0].x;
1045 Line2[3].x = Line2[4].x = Line1[1].x;
1046 Line2[1].x = Line2[2].x = Line1[0].x + edge;
1047 Line2[0].y = Line2[1].y = Line1[0].y;
1048 Line2[4].y = Line2[5].y = Line1[2].y;
1049 Line2[2].y = Line2[3].y = Line1[2].y - edge;
1050 Line1N = 6;
1051 Line2N = 6;
1052 break;
1053
1054 case DFCS_CAPTIONRESTORE:
1055 /* FIXME: this one looks bad at small sizes < 15x15 :( */
1056 edge = 47*SmallDiam/750;
1057 move = 420*SmallDiam/750;
1058 Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1059 Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1;
1060 Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1061 Line1[7].x = Line1[8].x = Line1[0].x + edge;
1062 Line1[1].x = Line1[2].x = Line1[0].x + move;
1063 Line1[5].x = Line1[6].x = Line1[1].x - edge;
1064 Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1065 Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1066 Line1[4].y = Line1[5].y = Line1[2].y - edge;
1067 Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1068
1069 Line2[1].x = Line2[2].x = Line1[3].x;
1070 Line2[7].x = Line2[8].x = Line2[1].x - edge;
1071 Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1072 Line2[5].x = Line2[6].x = Line2[0].x + edge;
1073 Line2[0].y = Line2[1].y = Line1[9].y;
1074 Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1075 Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1076 Line2[6].y = Line2[7].y = Line2[2].y - edge;
1077 Line1N = 10;
1078 Line2N = 10;
1079 break;
1080
1081 default:
1082// WARN("Invalid caption; flags=0x%04x\n", uFlags);
1083 return FALSE;
1084 }
1085
1086 /* Here the drawing takes place */
1087 if(uFlags & DFCS_INACTIVE)
1088 {
1089 /* If we have an inactive button, then you see a shadow */
1090 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1091 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT));
1092 Polygon(dc, Line1, Line1N);
1093 if(Line2N > 0)
1094 Polygon(dc, Line2, Line2N);
1095 SelectObject(dc, hpsave);
1096 SelectObject(dc, hbsave);
1097 }
1098
1099 /* Correct for the shadow shift */
1100 for(i = 0; i < Line1N; i++)
1101 {
1102 Line1[i].x--;
1103 Line1[i].y--;
1104 }
1105 for(i = 0; i < Line2N; i++)
1106 {
1107 Line2[i].x--;
1108 Line2[i].y--;
1109 }
1110
1111 /* Make the final picture */
1112 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1113 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1114 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
1115
1116 Polygon(dc, Line1, Line1N);
1117 if(Line2N > 0)
1118 Polygon(dc, Line2, Line2N);
1119 SelectObject(dc, hpsave);
1120 SelectObject(dc, hbsave);
1121
1122 return TRUE;
1123}
1124
1125
1126/************************************************************************
1127 * UITOOLS_DrawFrameScroll
1128 *
1129 * Draw a scroll-bar control coming from DrawFrameControl()
1130 */
1131static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
1132{
1133 POINT Line[4];
1134 RECT myr;
1135 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1136 int i;
1137 HBRUSH hbsave, hb, hb2;
1138 HPEN hpsave, hp, hp2;
1139 int tri = 290*SmallDiam/1000 -1;
1140 int d46, d93;
1141
1142 switch(uFlags & 0xff)
1143 {
1144 case DFCS_SCROLLCOMBOBOX:
1145 case DFCS_SCROLLDOWN:
1146 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1147 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
1148 Line[0].x = Line[2].x - tri;
1149 Line[1].x = Line[2].x + tri;
1150 Line[0].y = Line[1].y = Line[2].y - tri;
1151 break;
1152
1153 case DFCS_SCROLLUP:
1154 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1155 Line[2].y = myr.bottom - 687*SmallDiam/1000 + 1;
1156 Line[0].x = Line[2].x - tri;
1157 Line[1].x = Line[2].x + tri;
1158 Line[0].y = Line[1].y = Line[2].y + tri;
1159 break;
1160
1161 case DFCS_SCROLLLEFT:
1162 Line[2].x = myr.right - 687*SmallDiam/1000 + 1;
1163 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1164 Line[0].y = Line[2].y - tri;
1165 Line[1].y = Line[2].y + tri;
1166 Line[0].x = Line[1].x = Line[2].x + tri;
1167 break;
1168
1169 case DFCS_SCROLLRIGHT:
1170 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1171 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1172 Line[0].y = Line[2].y - tri;
1173 Line[1].y = Line[2].y + tri;
1174 Line[0].x = Line[1].x = Line[2].x - tri;
1175 break;
1176
1177 case DFCS_SCROLLSIZEGRIP:
1178 /* This one breaks the flow... */
1179 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1180 hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1181 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1182 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1183 {
1184 hp = hp2 = GetSysColorPen(COLOR_WINDOWFRAME);
1185 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1186 }
1187 else
1188 {
1189 hp = GetSysColorPen(COLOR_BTNHIGHLIGHT);
1190 hp2 = GetSysColorPen(COLOR_BTNSHADOW);
1191 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1192 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1193 }
1194 Line[0].x = Line[1].x = r->right-1;
1195 Line[2].y = Line[3].y = r->bottom-1;
1196 d46 = 46*SmallDiam/750;
1197 d93 = 93*SmallDiam/750;
1198
1199 i = 586*SmallDiam/750;
1200 Line[0].y = r->bottom - i - 1;
1201 Line[3].x = r->right - i - 1;
1202 Line[1].y = Line[0].y + d46;
1203 Line[2].x = Line[3].x + d46;
1204 SelectObject(dc, hb);
1205 SelectObject(dc, hp);
1206 Polygon(dc, Line, 4);
1207
1208 Line[1].y++; Line[2].x++;
1209 Line[0].y = Line[1].y + d93;
1210 Line[3].x = Line[2].x + d93;
1211 SelectObject(dc, hb2);
1212 SelectObject(dc, hp2);
1213 Polygon(dc, Line, 4);
1214
1215 i = 398*SmallDiam/750;
1216 Line[0].y = r->bottom - i - 1;
1217 Line[3].x = r->right - i - 1;
1218 Line[1].y = Line[0].y + d46;
1219 Line[2].x = Line[3].x + d46;
1220 SelectObject(dc, hb);
1221 SelectObject(dc, hp);
1222 Polygon(dc, Line, 4);
1223
1224 Line[1].y++; Line[2].x++;
1225 Line[0].y = Line[1].y + d93;
1226 Line[3].x = Line[2].x + d93;
1227 SelectObject(dc, hb2);
1228 SelectObject(dc, hp2);
1229 Polygon(dc, Line, 4);
1230
1231 i = 210*SmallDiam/750;
1232 Line[0].y = r->bottom - i - 1;
1233 Line[3].x = r->right - i - 1;
1234 Line[1].y = Line[0].y + d46;
1235 Line[2].x = Line[3].x + d46;
1236 SelectObject(dc, hb);
1237 SelectObject(dc, hp);
1238 Polygon(dc, Line, 4);
1239
1240 Line[1].y++; Line[2].x++;
1241 Line[0].y = Line[1].y + d93;
1242 Line[3].x = Line[2].x + d93;
1243 SelectObject(dc, hb2);
1244 SelectObject(dc, hp2);
1245 Polygon(dc, Line, 4);
1246
1247 SelectObject(dc, hpsave);
1248 SelectObject(dc, hbsave);
1249 return TRUE;
1250
1251 default:
1252// WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1253 return FALSE;
1254 }
1255
1256 /* Here do the real scroll-bar controls end up */
1257 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1258 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1259 /* want for the normal scroll-arrow button. */
1260 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1261 else
1262 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1263
1264 if(uFlags & DFCS_INACTIVE)
1265 {
1266 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1267 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT));
1268 Polygon(dc, Line, 3);
1269 SelectObject(dc, hpsave);
1270 SelectObject(dc, hbsave);
1271 }
1272
1273 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1274 for(i = 0; i < 3; i++)
1275 {
1276 Line[i].x--;
1277 Line[i].y--;
1278 }
1279
1280 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1281 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1282 hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
1283 Polygon(dc, Line, 3);
1284 SelectObject(dc, hpsave);
1285 SelectObject(dc, hbsave);
1286
1287 return TRUE;
1288}
1289
1290/************************************************************************
1291 * UITOOLS_DrawFrameMenu
1292 *
1293 * Draw a menu control coming from DrawFrameControl()
1294 */
1295static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1296{
1297 POINT Points[6];
1298 RECT myr;
1299 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1300 int i;
1301 HBRUSH hbsave;
1302 HPEN hpsave;
1303 int xe, ye;
1304 int xc, yc;
1305 BOOL retval = TRUE;
1306
1307 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1308 /* use anything else. I think I tried all sys-colors to change things */
1309 /* without luck. It seems as if this behavior is inherited from the */
1310 /* win31 DFC() implementation... (you remember, B/W menus). */
1311
1312 FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1313
1314 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1315 hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1316
1317 switch(uFlags & 0xff)
1318 {
1319 case DFCS_MENUARROW:
1320 i = 187*SmallDiam/750;
1321 Points[2].x = myr.left + 468*SmallDiam/750;
1322 Points[2].y = myr.top + 352*SmallDiam/750+1;
1323 Points[0].y = Points[2].y - i;
1324 Points[1].y = Points[2].y + i;
1325 Points[0].x = Points[1].x = Points[2].x - i;
1326 Polygon(dc, Points, 3);
1327 break;
1328
1329 case DFCS_MENUBULLET:
1330 xe = myr.left;
1331 ye = myr.top + SmallDiam - SmallDiam/2;
1332 xc = myr.left + SmallDiam - SmallDiam/2;
1333 yc = myr.top + SmallDiam - SmallDiam/2;
1334 i = 234*SmallDiam/750;
1335 i = i < 1 ? 1 : i;
1336 myr.left = xc - i+i/2;
1337 myr.right = xc + i/2;
1338 myr.top = yc - i+i/2;
1339 myr.bottom = yc + i/2;
1340 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1341 break;
1342
1343 case DFCS_MENUCHECK:
1344 Points[0].x = myr.left + 253*SmallDiam/1000;
1345 Points[0].y = myr.top + 445*SmallDiam/1000;
1346 Points[1].x = myr.left + 409*SmallDiam/1000;
1347 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1348 Points[2].x = myr.left + 690*SmallDiam/1000;
1349 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1350 Points[3].x = Points[2].x;
1351 Points[3].y = Points[2].y + 3*SmallDiam/16;
1352 Points[4].x = Points[1].x;
1353 Points[4].y = Points[1].y + 3*SmallDiam/16;
1354 Points[5].x = Points[0].x;
1355 Points[5].y = Points[0].y + 3*SmallDiam/16;
1356 Polygon(dc, Points, 6);
1357 break;
1358
1359 default:
1360// WARN("Invalid menu; flags=0x%04x\n", uFlags);
1361 retval = FALSE;
1362 break;
1363 }
1364
1365 SelectObject(dc, hpsave);
1366 SelectObject(dc, hbsave);
1367 return retval;
1368}
1369
1370/**********************************************************************
1371 * DrawFrameControl (USER32.158)
1372 */
1373BOOL WIN32API DrawFrameControl(HDC hdc, LPRECT rc, UINT uType,
1374 UINT uState )
1375{
1376 /* Win95 doesn't support drawing in other mapping modes */
1377 if(GetMapMode(hdc) != MM_TEXT)
1378 return FALSE;
1379
1380 switch(uType)
1381 {
1382 case DFC_BUTTON:
1383 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1384 case DFC_CAPTION:
1385 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1386 case DFC_MENU:
1387 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1388 case DFC_SCROLL:
1389 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1390// default:
1391// WARN("(%x,%p,%d,%x), bad type!\n",
1392// hdc,rc,uType,uState );
1393 }
1394 return FALSE;
1395}
1396
1397
1398/*****************************************************************************
1399 * Name : int WIN32API DrawTextExA
1400 * Purpose : The DrawTextEx function draw the text in the rectangle
1401 * Parameters:
1402 * Variables :
1403 * Result : If the function succeeds, the return value is the height of the
1404 * text, otherwise zero.
1405 * Remark : TODO: Returned number of characters is always the entire string
1406 * since there is no way to know the real answer this way.
1407 * Status : PARTIALLY IMPLEMENTED AND TESTED
1408 *
1409 * Author : Rene Pronk [Thu, 1999/07/29 15:03]
1410 * Christoph Bratschi: implemented DT_END_ELLIPSIS (Header control)
1411 *****************************************************************************/
1412
1413int WIN32API DrawTextExA (HDC hdc, LPCSTR lpchText, int cchText, LPRECT lprc,
1414 UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
1415
1416 int result;
1417 UINT oldDTFormat;
1418
1419 dprintf(("USER32:DrawTextExA (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
1420 hdc, lpchText, cchText, lprc, dwDTFormat, lpDTParams));
1421
1422 if (lpDTParams != NULL) {
1423 // 'create' margins
1424 lprc->left += lpDTParams->iLeftMargin;
1425 lprc->right -= lpDTParams->iRightMargin;
1426
1427 // just assume all the text has been drawn
1428 if (cchText != -1)
1429 lpDTParams->uiLengthDrawn = cchText;
1430 else {
1431 // determine string length
1432 int size = 0;
1433 while ((BYTE) *(lpchText + size) != 0)
1434 size ++;
1435 lpDTParams->uiLengthDrawn = size;
1436 }
1437 }
1438
1439 oldDTFormat = dwDTFormat & ~(DT_END_ELLIPSIS | DT_PATH_ELLIPSIS | DT_MODIFYSTRING | DT_EXPANDTABS);
1440 if (dwDTFormat & DT_END_ELLIPSIS && lpchText && (cchText != 0))
1441 {
1442 int textWidth,width;
1443 RECT rect;
1444
1445 if (cchText == -1) cchText = lstrlenA(lpchText);
1446 SetRectEmpty(&rect);
1447 DrawTextA(hdc,lpchText,cchText,&rect,oldDTFormat | DT_CALCRECT);
1448 width = lprc->right-lprc->left;
1449 textWidth = rect.right-rect.left;
1450 if (textWidth > width && width > 0)
1451 {
1452 char* newText;
1453 int endWidth,newTextLen;
1454
1455 DrawTextA(hdc,"...",3,&rect,DT_CALCRECT | DT_SINGLELINE | DT_LEFT);
1456 endWidth = rect.right-rect.left;
1457 newText = (char*)malloc(cchText+3);
1458 lstrcpyA(newText,lpchText);
1459 newTextLen = cchText+1;
1460 do
1461 {
1462 newTextLen--;
1463 DrawTextA(hdc,newText,newTextLen,&rect,oldDTFormat | DT_CALCRECT);
1464 textWidth = rect.right-rect.left;
1465 } while (textWidth+endWidth > width && newTextLen > 1);
1466
1467 lstrcpyA(&newText[newTextLen],"...");
1468 result = DrawTextA(hdc,newText,-1,lprc,oldDTFormat);;
1469
1470 if (dwDTFormat & DT_MODIFYSTRING) lstrcpynA((LPSTR)lpchText,newText,cchText);
1471 free(newText);
1472 } else result = DrawTextA(hdc,lpchText,cchText,lprc,oldDTFormat);
1473 } else
1474 result = DrawTextA (hdc, lpchText, cchText, lprc, oldDTFormat);
1475
1476 if (lpDTParams != NULL) {
1477 // don't forget to restore the margins
1478 lprc->left -= lpDTParams->iLeftMargin;
1479 lprc->right += lpDTParams->iRightMargin;
1480 }
1481
1482 return result;
1483}
1484
1485
1486
1487/*****************************************************************************
1488 * Name : int WIN32API DrawTextExW
1489 * Purpose : The DrawTextEx function draw the text in the rectangle
1490 * Parameters:
1491 * Variables :
1492 * Result : If the function succeeds, the return value is the height of the
1493 * text, otherwise zero.
1494 * Remark : TODO: Returned number of characters is always the entire string
1495 * since there is no way to know the real answer this way.
1496 * Status : PARTIALLY IMPLEMENTED AND TESTED
1497 *
1498 * Author : Rene Pronk [Thu, 1999/07/29 15:03]
1499 *****************************************************************************/
1500
1501int WIN32API DrawTextExW (HDC hdc, LPWSTR lpchText, int cchText, LPRECT lprc,
1502 UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
1503
1504 char *astring = UnicodeToAsciiString((LPWSTR)lpchText);
1505 int rc;
1506
1507 dprintf(("USER32:DrawTextExW (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
1508 hdc, astring, cchText, lprc, dwDTFormat, lpDTParams));
1509
1510 rc = DrawTextExA (hdc, astring, cchText, lprc, dwDTFormat, lpDTParams);
1511 if (dwDTFormat & DT_MODIFYSTRING) AsciiToUnicode(astring,lpchText);
1512 FreeAsciiString(astring);
1513 return(rc);
1514}
1515
1516
1517/******************************************************************************
1518 *
1519 * This function is used by Paint_DrawState which is inturn used by both
1520 * DrawStateA and DrawStateW. The code is directly borrowed from Wine.
1521 *
1522 ******************************************************************************/
1523
1524static BOOL Paint_DrawStateJam(HDC hdc, UINT opcode,
1525 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1526 LPRECT rc, UINT dtflags, BOOL unicode)
1527{
1528 HDC memdc;
1529 HBITMAP hbmsave;
1530 BOOL retval;
1531 INT cx = rc->right - rc->left;
1532 INT cy = rc->bottom - rc->top;
1533
1534 switch(opcode)
1535 {
1536 case DST_TEXT:
1537 case DST_PREFIXTEXT:
1538 if(unicode)
1539 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1540 else
1541 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1542
1543 case DST_ICON:
1544 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1545
1546 case DST_BITMAP:
1547 memdc = CreateCompatibleDC(hdc);
1548 if(!memdc) return FALSE;
1549 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1550 if(!hbmsave)
1551 {
1552 DeleteDC(memdc);
1553 return FALSE;
1554 }
1555 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1556 SelectObject(memdc, hbmsave);
1557 DeleteDC(memdc);
1558 return retval;
1559
1560 case DST_COMPLEX:
1561 if(func)
1562 return func(hdc, lp, wp, cx, cy);
1563 else
1564 return FALSE;
1565 }
1566 return FALSE;
1567}
1568
1569
1570/******************************************************************************
1571 *
1572 * This function is used by both DrawStateA and DrawStateW. The code is directly
1573 * borrowed from Wine
1574 *
1575 ******************************************************************************/
1576BOOL Paint_DrawState (HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1577 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode)
1578{
1579 HBITMAP hbm, hbmsave;
1580 HFONT hfsave;
1581 HBRUSH hbsave;
1582 HDC memdc;
1583 RECT rc;
1584 UINT dtflags = DT_NOCLIP;
1585 COLORREF fg, bg;
1586 UINT opcode = flags & 0xf;
1587 INT len = wp;
1588 BOOL retval, tmp;
1589
1590 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1591 {
1592 if(unicode)
1593 len = lstrlenW((LPWSTR)lp);
1594 else
1595 len = lstrlenA((LPSTR)lp);
1596 }
1597
1598 /* Find out what size the image has if not given by caller */
1599 if(!cx || !cy)
1600 {
1601 SIZE s;
1602 BITMAP bmp;
1603
1604 switch(opcode)
1605 {
1606 case DST_TEXT:
1607 case DST_PREFIXTEXT:
1608 if(unicode)
1609 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1610 else
1611 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1612 if(!retval) return FALSE;
1613 break;
1614
1615 case DST_ICON:
1616 /* Just assume the icon has the size given by GetSystemMetrics. This should be
1617 valid since both CreateIcon and LoadIcon can't create icons with different
1618 sizes. I wouldn't how else to get the size of the icon. RP
1619 */
1620 s.cx = GetSystemMetrics (SM_CXICON);
1621 s.cy = GetSystemMetrics (SM_CYICON);
1622 break;
1623
1624 case DST_BITMAP:
1625 retval = GetObjectA ((HBITMAP) lp, sizeof (BITMAP), &bmp);
1626 if(retval == 0) return FALSE;
1627 s.cx = bmp.bmWidth;
1628 s.cy = bmp.bmHeight;
1629 break;
1630
1631 case DST_COMPLEX: /* cx and cy must be set in this mode */
1632 return FALSE;
1633 }
1634
1635 if(!cx) cx = s.cx;
1636 if(!cy) cy = s.cy;
1637 }
1638
1639 rc.left = x;
1640 rc.top = y;
1641 rc.right = x + cx;
1642 rc.bottom = y + cy;
1643
1644 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1645 dtflags |= DT_RIGHT;
1646 if(opcode == DST_TEXT)
1647 dtflags |= DT_NOPREFIX;
1648
1649 /* For DSS_NORMAL we just jam in the image and return */
1650 if((flags & 0x7ff0) == DSS_NORMAL)
1651 {
1652 return Paint_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1653 }
1654
1655 /* For all other states we need to convert the image to B/W in a local bitmap */
1656 /* before it is displayed */
1657 fg = SetTextColor(hdc, RGB(0, 0, 0));
1658 bg = SetBkColor(hdc, RGB(255, 255, 255));
1659 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1660 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1661 retval = FALSE; /* assume failure */
1662
1663 /* From here on we must use "goto cleanup" when something goes wrong */
1664 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1665 if(!hbm) goto cleanup;
1666 memdc = CreateCompatibleDC(hdc);
1667 if(!memdc) goto cleanup;
1668 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1669 if(!hbmsave) goto cleanup;
1670 rc.left = rc.top = 0;
1671 rc.right = cx;
1672 rc.bottom = cy;
1673 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1674 SetBkColor(memdc, RGB(255, 255, 255));
1675 SetTextColor(memdc, RGB(0, 0, 0));
1676 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1677 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
1678 tmp = Paint_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1679 if(hfsave) SelectObject(memdc, hfsave);
1680 if(!tmp) goto cleanup;
1681
1682 /* These states cause the image to be dithered */
1683 if(flags & (DSS_UNION|DSS_DISABLED))
1684 {
1685 WORD wPattern55AA[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
1686 HBITMAP hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
1687 HBRUSH hPattern55AABrush = CreatePatternBrush(hPattern55AABitmap);
1688
1689 hbsave = (HBRUSH)SelectObject(memdc, hPattern55AABrush);
1690 if(!hbsave) goto cleanup;
1691 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1692 if(hbsave) SelectObject(memdc, hbsave);
1693 if(!tmp) goto cleanup;
1694 }
1695
1696 hbsave = (HBRUSH)SelectObject(hdc, hbr ? hbr : GetStockObject(WHITE_BRUSH));
1697 if(!hbsave) goto cleanup;
1698
1699 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1700
1701 /* DSS_DEFAULT makes the image boldface */
1702 if(flags & DSS_DEFAULT)
1703 {
1704 if(!BitBlt(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1705 }
1706
1707 retval = TRUE; /* We succeeded */
1708
1709cleanup:
1710 SetTextColor(hdc, fg);
1711 SetBkColor(hdc, bg);
1712
1713 if(hbsave) SelectObject(hdc, hbsave);
1714 if(hbmsave) SelectObject(memdc, hbmsave);
1715 if(hbm) DeleteObject(hbm);
1716 if(memdc) DeleteDC(memdc);
1717
1718 return retval;
1719}
1720
1721
1722
1723/*****************************************************************************
1724 * Name : BOOL WIN32API DrawStateA
1725 * Purpose : Draws a bitmap, icon, text or complex object in one of the following
1726 * states: normal, disabled, union or mono
1727 * Parameters:
1728 * Variables :
1729 * Result : If the function succeeds, the return value is a handle of the
1730 * window station associated with the calling process.
1731 * If the function fails, the return value is NULL. This can occur
1732 * if the calling process is not an application written for Windows
1733 * NT. To get extended error information, call GetLastError.
1734 * Remark : Disabled doesn't look like the Windows implementation, but it does
1735 * look disabled.
1736 * Status : PARTIALLY IMPLEMENTED
1737 *
1738 * Author : Rene Pronk [Sun, 1999/07/25 21:27]
1739 *****************************************************************************/
1740
1741BOOL WIN32API DrawStateA(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
1742 WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
1743{
1744 dprintf(("USER32:DrawStateA (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
1745 hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
1746
1747 return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, FALSE);
1748}
1749
1750
1751
1752/*****************************************************************************
1753 * Name : BOOL WIN32API DrawStateW
1754 * Purpose : Draws a bitmap, icon, text or complex object in one of the following
1755 * states: normal, disabled, union or mono
1756 * Parameters:
1757 * Variables :
1758 * Result : If the function succeeds, the return value is a handle of the
1759 * window station associated with the calling process.
1760 * If the function fails, the return value is NULL. This can occur
1761 * if the calling process is not an application written for Windows
1762 * NT. To get extended error information, call GetLastError.
1763 * Remark : Disabled doesn't look like the Windows implementation, but it does
1764 * look disabled.
1765 * Status : PARTIALLY IMPLEMENTED
1766 *
1767 * Author : Rene Pronk [Sun, 1999/07/25 21:27]
1768 *****************************************************************************/
1769
1770BOOL WIN32API DrawStateW(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
1771 WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
1772{
1773 dprintf(("USER32:DrawStateW (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
1774 hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
1775
1776 return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, TRUE);
1777}
1778//******************************************************************************
1779//******************************************************************************
1780BOOL WIN32API DrawFocusRect( HDC arg1, const RECT * arg2)
1781{
1782#ifdef DEBUG
1783 WriteLog("USER32: DrawFocusRect\n");
1784#endif
1785 return O32_DrawFocusRect(arg1, arg2);
1786}
1787//******************************************************************************
1788//******************************************************************************
1789BOOL WIN32API DrawIcon( HDC arg1, int arg2, int arg3, HICON arg4)
1790{
1791#ifdef DEBUG
1792 WriteLog("USER32: DrawIcon\n");
1793#endif
1794 return O32_DrawIcon(arg1, arg2, arg3, arg4);
1795}
1796//******************************************************************************
1797//******************************************************************************
1798BOOL WIN32API DrawIconEx(HDC hdc, int xLeft, int xRight, HICON hIcon,
1799 int cxWidth, int cyWidth, UINT istepIfAniCur,
1800 HBRUSH hbrFlickerFreeDraw, UINT diFlags)
1801{
1802#ifdef DEBUG
1803 WriteLog("USER32: DrawIcon, partially implemented\n");
1804#endif
1805 return O32_DrawIcon(hdc, xLeft, xRight, hIcon);
1806}
1807//******************************************************************************
1808//******************************************************************************
1809BOOL WIN32API DrawMenuBar( HWND arg1)
1810{
1811#ifdef DEBUG
1812 WriteLog("USER32: DrawMenuBar\n");
1813#endif
1814 return O32_DrawMenuBar(arg1);
1815}
1816//******************************************************************************
1817//******************************************************************************
1818int WIN32API DrawTextW( HDC arg1, LPCWSTR arg2, int arg3, PRECT arg4, UINT arg5)
1819{
1820 char *astring = UnicodeToAsciiString((LPWSTR)arg2);
1821 int rc;
1822
1823#ifdef DEBUG
1824 WriteLog("USER32: DrawTextW %s\n", astring);
1825#endif
1826 rc = O32_DrawText(arg1, astring, arg3, arg4, arg5);
1827 FreeAsciiString(astring);
1828 return(rc);
1829}
1830//******************************************************************************
1831//******************************************************************************
1832int WIN32API DrawTextA(HDC arg1, LPCSTR arg2, int arg3, PRECT arg4, UINT arg5)
1833{
1834#ifdef DEBUG
1835 WriteLog("USER32: DrawTextA %s", arg2);
1836#endif
1837 return O32_DrawText(arg1, arg2, arg3, arg4, arg5);
1838}
1839/*****************************************************************************
1840 * Name : BOOL WIN32API DrawAnimatedRects
1841 * Purpose : The DrawAnimatedRects function draws a wire-frame rectangle
1842 * and animates it to indicate the opening of an icon or the
1843 * minimizing or maximizing of a window.
1844 * Parameters: HWND hwnd handle of clipping window
1845 * int idAni type of animation
1846 * CONST RECT * lprcFrom address of rectangle coordinates (minimized)
1847 * CONST RECT * lprcTo address of rectangle coordinates (restored)
1848 * Variables :
1849 * Result : If the function succeeds, the return value is TRUE.
1850 * If the function fails, the return value is FALSE.
1851 * Remark :
1852 * Status : UNTESTED STUB
1853 *
1854 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1855 *****************************************************************************/
1856
1857BOOL WIN32API DrawAnimatedRects(HWND hwnd,
1858 int idAni,
1859 CONST RECT *lprcFrom,
1860 CONST RECT *lprcTo)
1861{
1862 dprintf(("USER32:DrawAnimatedRects (%08xh,%u,%08xh,%08x) not implemented.\n",
1863 hwnd,
1864 idAni,
1865 lprcFrom,
1866 lprcTo));
1867
1868 return (TRUE);
1869}
1870
1871
1872/*****************************************************************************
1873 * Name : VOID WIN32API DrawCaption
1874 * Purpose : The DrawCaption function draws a window caption.
1875 * Parameters: HDC hdc handle of device context
1876 * LPRECT lprc address of bounding rectangle coordinates
1877 * HFONT hfont handle of font for caption
1878 * HICON hicon handle of icon in caption
1879 * LPSTR lpszText address of caption string
1880 * WORD wFlags drawing options
1881 * Variables :
1882 * Result :
1883 * Remark :
1884 * Status : UNTESTED STUB
1885 *
1886 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1887 *****************************************************************************/
1888
1889BOOL WIN32API DrawCaption (HWND hwnd,
1890 HDC hdc,
1891 const RECT *lprc,
1892 UINT wFlags)
1893{
1894 dprintf(("USER32:DrawCaption (%08xh,%08xh,%08xh,%08xh) not implemented.\n",
1895 hwnd,
1896 hdc,
1897 lprc,
1898 wFlags));
1899
1900 return FALSE;
1901}
1902/***********************************************************************
1903 * DrawCaptionTemp32A [USER32.599]
1904 *
1905 * PARAMS
1906 *
1907 * RETURNS
1908 * Success:
1909 * Failure:
1910 */
1911
1912BOOL WIN32API DrawCaptionTempA(HWND hwnd,
1913 HDC hdc,
1914 const RECT *rect,
1915 HFONT hFont,
1916 HICON hIcon,
1917 LPCSTR str,
1918 UINT uFlags)
1919{
1920 RECT rc = *rect;
1921
1922 dprintf(("USER32: DrawCaptionTempA(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
1923 hwnd,
1924 hdc,
1925 rect,
1926 hFont,
1927 hIcon,
1928 str,
1929 uFlags));
1930
1931 /* drawing background */
1932 if (uFlags & DC_INBUTTON)
1933 {
1934 O32_FillRect (hdc,
1935 &rc,
1936 GetSysColorBrush (COLOR_3DFACE));
1937
1938 if (uFlags & DC_ACTIVE)
1939 {
1940 HBRUSH hbr = O32_SelectObject (hdc,
1941 GetSysColorBrush (COLOR_ACTIVECAPTION));
1942 O32_PatBlt (hdc,
1943 rc.left,
1944 rc.top,
1945 rc.right - rc.left,
1946 rc.bottom - rc.top,
1947 0xFA0089);
1948
1949 O32_SelectObject (hdc,
1950 hbr);
1951 }
1952 }
1953 else
1954 {
1955 O32_FillRect (hdc,
1956 &rc,
1957 GetSysColorBrush ((uFlags & DC_ACTIVE) ?
1958 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
1959 }
1960
1961
1962 /* drawing icon */
1963 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP))
1964 {
1965 POINT pt;
1966
1967 pt.x = rc.left + 2;
1968 pt.y = (rc.bottom + rc.top - O32_GetSystemMetrics(SM_CYSMICON)) / 2;
1969
1970 if (hIcon)
1971 {
1972 DrawIconEx (hdc,
1973 pt.x,
1974 pt.y,
1975 hIcon,
1976 O32_GetSystemMetrics(SM_CXSMICON),
1977 O32_GetSystemMetrics(SM_CYSMICON),
1978 0,
1979 0,
1980 DI_NORMAL);
1981 }
1982 else
1983 {
1984 /* @@@PH 1999/06/08 not ported yet, just don't draw any icon
1985 WND *wndPtr = WIN_FindWndPtr(hwnd);
1986 HICON hAppIcon = 0;
1987
1988 if (wndPtr->class->hIconSm)
1989 hAppIcon = wndPtr->class->hIconSm;
1990 else
1991 if (wndPtr->class->hIcon)
1992 hAppIcon = wndPtr->class->hIcon;
1993
1994 DrawIconEx (hdc,
1995 pt.x,
1996 pt.y,
1997 hAppIcon,
1998 GetSystemMetrics(SM_CXSMICON),
1999 GetSystemMetrics(SM_CYSMICON),
2000 0,
2001 0,
2002 DI_NORMAL);
2003
2004 WIN_ReleaseWndPtr(wndPtr);
2005 */
2006 }
2007
2008 rc.left += (rc.bottom - rc.top);
2009 }
2010
2011 /* drawing text */
2012 if (uFlags & DC_TEXT)
2013 {
2014 HFONT hOldFont;
2015
2016 if (uFlags & DC_INBUTTON)
2017 O32_SetTextColor (hdc,
2018 O32_GetSysColor (COLOR_BTNTEXT));
2019 else
2020 if (uFlags & DC_ACTIVE)
2021 O32_SetTextColor (hdc,
2022 O32_GetSysColor (COLOR_CAPTIONTEXT));
2023 else
2024 O32_SetTextColor (hdc,
2025 O32_GetSysColor (COLOR_INACTIVECAPTIONTEXT));
2026
2027 O32_SetBkMode (hdc,
2028 TRANSPARENT);
2029
2030 if (hFont)
2031 hOldFont = O32_SelectObject (hdc,
2032 hFont);
2033 else
2034 {
2035 NONCLIENTMETRICSA nclm;
2036 HFONT hNewFont;
2037
2038 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
2039 O32_SystemParametersInfo (SPI_GETNONCLIENTMETRICS,
2040 0,
2041 &nclm,
2042 0);
2043 hNewFont = O32_CreateFontIndirect ((uFlags & DC_SMALLCAP) ?
2044 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
2045 hOldFont = O32_SelectObject (hdc,
2046 hNewFont);
2047 }
2048
2049 if (str)
2050 O32_DrawText (hdc,
2051 str,
2052 -1,
2053 &rc,
2054 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
2055 else
2056 {
2057 CHAR szText[128];
2058 INT nLen;
2059
2060 nLen = O32_GetWindowText (hwnd,
2061 szText,
2062 128);
2063
2064 O32_DrawText (hdc,
2065 szText,
2066 nLen,
2067 &rc,
2068 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
2069 }
2070
2071 if (hFont)
2072 O32_SelectObject (hdc,
2073 hOldFont);
2074 else
2075 O32_DeleteObject (O32_SelectObject (hdc,
2076 hOldFont));
2077 }
2078
2079 /* drawing focus ??? */
2080 if (uFlags & 0x2000)
2081 {
2082 dprintf(("USER32: DrawCaptionTempA undocumented flag (0x2000)!\n"));
2083 }
2084
2085 return 0;
2086}
2087
2088
2089/***********************************************************************
2090 * DrawCaptionTemp32W [USER32.602]
2091 *
2092 * PARAMS
2093 *
2094 * RETURNS
2095 * Success:
2096 * Failure:
2097 */
2098
2099BOOL WIN32API DrawCaptionTempW (HWND hwnd,
2100 HDC hdc,
2101 const RECT *rect,
2102 HFONT hFont,
2103 HICON hIcon,
2104 LPCWSTR str,
2105 UINT uFlags)
2106{
2107 LPSTR strAscii = UnicodeToAsciiString((LPWSTR)str);
2108
2109 BOOL res = DrawCaptionTempA (hwnd,
2110 hdc,
2111 rect,
2112 hFont,
2113 hIcon,
2114 strAscii,
2115 uFlags);
2116
2117 FreeAsciiString(strAscii);
2118
2119 return res;
2120}
2121
2122//******************************************************************************
2123//******************************************************************************
Note: See TracBrowser for help on using the repository browser.