2 * ReactOS User32 Library
3 * - Various drawing functions
5 * Copyright 2001 Casper S. Hournstroup
6 * Copyright 2003 Andrew Greenwood
7 * Copyright 2003 Filip Navara
8 * Copyright 2009 Matthias Kupfer
9 * Copyright 2017 Katayama Hirofumi MZ
13 * Copyright 1993, 1994 Alexandre Julliard
14 * Copyright 2002 Bill Medland
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
35 /* GLOBALS *******************************************************************/
37 /* These tables are used in:
38 * UITOOLS_DrawDiagEdge()
39 * UITOOLS_DrawRectEdge()
41 static const signed char LTInnerNormal
[] = {
43 -1, COLOR_BTNHIGHLIGHT
, COLOR_BTNHIGHLIGHT
, -1,
44 -1, COLOR_3DDKSHADOW
, COLOR_3DDKSHADOW
, -1,
48 static const signed char LTOuterNormal
[] = {
49 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
50 COLOR_BTNHIGHLIGHT
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
51 COLOR_3DDKSHADOW
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
52 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1
55 static const signed char RBInnerNormal
[] = {
57 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, -1,
58 -1, COLOR_3DLIGHT
, COLOR_3DLIGHT
, -1,
62 static const signed char RBOuterNormal
[] = {
63 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
64 COLOR_BTNSHADOW
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
65 COLOR_3DLIGHT
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
66 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1
69 static const signed char LTInnerSoft
[] = {
71 -1, COLOR_3DLIGHT
, COLOR_3DLIGHT
, -1,
72 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, -1,
76 static const signed char LTOuterSoft
[] = {
77 -1, COLOR_BTNHIGHLIGHT
, COLOR_3DDKSHADOW
, -1,
78 COLOR_3DLIGHT
, COLOR_BTNHIGHLIGHT
, COLOR_3DDKSHADOW
, -1,
79 COLOR_BTNSHADOW
, COLOR_BTNHIGHLIGHT
, COLOR_3DDKSHADOW
, -1,
80 -1, COLOR_BTNHIGHLIGHT
, COLOR_3DDKSHADOW
, -1
83 #define RBInnerSoft RBInnerNormal /* These are the same */
84 #define RBOuterSoft RBOuterNormal
86 static const signed char LTRBOuterMono
[] = {
87 -1, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
88 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
89 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
90 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
93 static const signed char LTRBInnerMono
[] = {
95 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
96 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
97 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
100 static const signed char LTRBOuterFlat
[] = {
101 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
,
102 COLOR_BTNFACE
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
,
103 COLOR_BTNFACE
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
,
104 COLOR_BTNFACE
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
,
107 static const signed char LTRBInnerFlat
[] = {
109 -1, COLOR_BTNFACE
, COLOR_BTNFACE
, COLOR_BTNFACE
,
110 -1, COLOR_BTNFACE
, COLOR_BTNFACE
, COLOR_BTNFACE
,
111 -1, COLOR_BTNFACE
, COLOR_BTNFACE
, COLOR_BTNFACE
,
113 /* FUNCTIONS *****************************************************************/
116 HBRUSH WINAPI
GetSysColorBrush(int nIndex
);
118 /* Ported from WINE20020904 */
119 /* Same as DrawEdge invoked with BF_DIAGONAL */
120 static BOOL
IntDrawDiagEdge(HDC hdc
, LPRECT rc
, UINT uType
, UINT uFlags
)
123 signed char InnerI
, OuterI
;
124 HPEN InnerPen
, OuterPen
;
129 int Width
= rc
->right
- rc
->left
;
130 int Height
= rc
->bottom
- rc
->top
;
131 int SmallDiam
= Width
> Height
? Height
: Width
;
132 BOOL retval
= !( ((uType
& BDR_INNER
) == BDR_INNER
133 || (uType
& BDR_OUTER
) == BDR_OUTER
)
134 && !(uFlags
& (BF_FLAT
|BF_MONO
)) );
135 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
136 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
139 OuterPen
= InnerPen
= (HPEN
)GetStockObject(NULL_PEN
);
140 SavePen
= (HPEN
)SelectObject(hdc
, InnerPen
);
141 spx
= spy
= epx
= epy
= 0; /* Satisfy the compiler... */
143 /* Determine the colors of the edges */
146 InnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
147 OuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
149 else if(uFlags
& BF_FLAT
)
151 InnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
152 OuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
154 else if(uFlags
& BF_SOFT
)
156 if(uFlags
& BF_BOTTOM
)
158 InnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
159 OuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
163 InnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
164 OuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
169 if(uFlags
& BF_BOTTOM
)
171 InnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
172 OuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
176 InnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
177 OuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
181 if(InnerI
!= -1) InnerPen
= GetStockObject(DC_PEN
);
182 if(OuterI
!= -1) OuterPen
= GetStockObject(DC_PEN
);
184 MoveToEx(hdc
, 0, 0, &SavePoint
);
186 /* Don't ask me why, but this is what is visible... */
187 /* This must be possible to do much simpler, but I fail to */
188 /* see the logic in the MS implementation (sigh...). */
189 /* So, this might look a bit brute force here (and it is), but */
190 /* it gets the job done;) */
192 switch(uFlags
& BF_RECT
)
198 /* Left bottom endpoint */
200 spx
= epx
+ SmallDiam
;
202 spy
= epy
- SmallDiam
;
207 /* Left top endpoint */
209 spx
= epx
+ SmallDiam
;
211 spy
= epy
+ SmallDiam
;
217 case BF_RIGHT
|BF_LEFT
:
218 case BF_RIGHT
|BF_LEFT
|BF_TOP
:
219 case BF_BOTTOM
|BF_TOP
:
220 case BF_BOTTOM
|BF_TOP
|BF_LEFT
:
221 case BF_BOTTOMRIGHT
|BF_LEFT
:
222 case BF_BOTTOMRIGHT
|BF_TOP
:
224 /* Right top endpoint */
226 epx
= spx
+ SmallDiam
;
228 epy
= spy
- SmallDiam
;
232 MoveToEx(hdc
, spx
, spy
, NULL
);
233 SelectObject(hdc
, OuterPen
);
234 SetDCPenColor(hdc
, GetSysColor(OuterI
));
235 LineTo(hdc
, epx
, epy
);
237 SelectObject(hdc
, InnerPen
);
238 SetDCPenColor(hdc
, GetSysColor(InnerI
));
240 switch(uFlags
& (BF_RECT
|BF_DIAGONAL
))
242 case BF_DIAGONAL_ENDBOTTOMLEFT
:
243 case (BF_DIAGONAL
|BF_BOTTOM
):
245 case (BF_DIAGONAL
|BF_LEFT
):
246 MoveToEx(hdc
, spx
-1, spy
, NULL
);
247 LineTo(hdc
, epx
, epy
-1);
248 Points
[0].x
= spx
-add
;
250 Points
[1].x
= rc
->left
;
251 Points
[1].y
= rc
->top
;
253 Points
[2].y
= epy
-1-add
;
254 Points
[3] = Points
[2];
257 case BF_DIAGONAL_ENDBOTTOMRIGHT
:
258 MoveToEx(hdc
, spx
-1, spy
, NULL
);
259 LineTo(hdc
, epx
, epy
+1);
260 Points
[0].x
= spx
-add
;
262 Points
[1].x
= rc
->left
;
263 Points
[1].y
= rc
->bottom
-1;
265 Points
[2].y
= epy
+1+add
;
266 Points
[3] = Points
[2];
269 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
):
270 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
271 case BF_DIAGONAL_ENDTOPRIGHT
:
272 case (BF_DIAGONAL
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
273 MoveToEx(hdc
, spx
+1, spy
, NULL
);
274 LineTo(hdc
, epx
, epy
+1);
276 Points
[0].y
= epy
+1+add
;
277 Points
[1].x
= rc
->right
-1;
278 Points
[1].y
= rc
->top
+add
;
279 Points
[2].x
= rc
->right
-1;
280 Points
[2].y
= rc
->bottom
-1;
281 Points
[3].x
= spx
+add
;
285 case BF_DIAGONAL_ENDTOPLEFT
:
286 MoveToEx(hdc
, spx
, spy
-1, NULL
);
287 LineTo(hdc
, epx
+1, epy
);
288 Points
[0].x
= epx
+1+add
;
290 Points
[1].x
= rc
->right
-1;
291 Points
[1].y
= rc
->top
;
292 Points
[2].x
= rc
->right
-1;
293 Points
[2].y
= rc
->bottom
-1-add
;
295 Points
[3].y
= spy
-add
;
298 case (BF_DIAGONAL
|BF_TOP
):
299 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
):
300 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
|BF_LEFT
):
301 MoveToEx(hdc
, spx
+1, spy
-1, NULL
);
302 LineTo(hdc
, epx
, epy
);
305 Points
[1].x
= rc
->right
-1;
306 Points
[1].y
= rc
->top
;
307 Points
[2].x
= rc
->right
-1;
308 Points
[2].y
= rc
->bottom
-1-add
;
309 Points
[3].x
= spx
+add
;
310 Points
[3].y
= spy
-add
;
313 case (BF_DIAGONAL
|BF_RIGHT
):
314 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
):
315 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
|BF_BOTTOM
):
316 MoveToEx(hdc
, spx
, spy
, NULL
);
317 LineTo(hdc
, epx
-1, epy
+1);
320 Points
[1].x
= rc
->left
;
321 Points
[1].y
= rc
->top
+add
;
322 Points
[2].x
= epx
-1-add
;
323 Points
[2].y
= epy
+1+add
;
324 Points
[3] = Points
[2];
328 /* Fill the interior if asked */
329 if((uFlags
& BF_MIDDLE
) && retval
)
333 hbsave
= (HBRUSH
)SelectObject(hdc
, GetStockObject(DC_BRUSH
));
334 hpsave
= (HPEN
)SelectObject(hdc
, GetStockObject(DC_PEN
));
335 SetDCBrushColor(hdc
, GetSysColor(uFlags
& BF_MONO
? COLOR_WINDOW
: COLOR_BTNFACE
));
336 SetDCPenColor(hdc
, GetSysColor(uFlags
& BF_MONO
? COLOR_WINDOW
: COLOR_BTNFACE
));
337 Polygon(hdc
, Points
, 4);
338 SelectObject(hdc
, hbsave
);
339 SelectObject(hdc
, hpsave
);
342 /* Adjust rectangle if asked */
343 if(uFlags
& BF_ADJUST
)
345 if(uFlags
& BF_LEFT
) rc
->left
+= add
;
346 if(uFlags
& BF_RIGHT
) rc
->right
-= add
;
347 if(uFlags
& BF_TOP
) rc
->top
+= add
;
348 if(uFlags
& BF_BOTTOM
) rc
->bottom
-= add
;
352 SelectObject(hdc
, SavePen
);
353 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
358 /* Ported from WINE20020904 */
359 /* Same as DrawEdge invoked without BF_DIAGONAL
361 * 23-Nov-1997: Changed by Bertho Stultiens
362 * The width parameter sets the width of each outer and inner edge.
364 * Well, I started testing this and found out that there are a few things
365 * that weren't quite as win95. The following rewrite should reproduce
366 * win95 results completely.
367 * The colorselection is table-driven to avoid awfull if-statements.
368 * The table below show the color settings.
370 * Pen selection table for uFlags = 0
372 * uType | LTI | LTO | RBI | RBO
373 * ------+-------+-------+-------+-------
374 * 0000 | x | x | x | x
375 * 0001 | x | 22 | x | 21
376 * 0010 | x | 16 | x | 20
377 * 0011 | x | x | x | x
378 * ------+-------+-------+-------+-------
379 * 0100 | x | 20 | x | 16
380 * 0101 | 20 | 22 | 16 | 21
381 * 0110 | 20 | 16 | 16 | 20
382 * 0111 | x | x | x | x
383 * ------+-------+-------+-------+-------
384 * 1000 | x | 21 | x | 22
385 * 1001 | 21 | 22 | 22 | 21
386 * 1010 | 21 | 16 | 22 | 20
387 * 1011 | x | x | x | x
388 * ------+-------+-------+-------+-------
389 * 1100 | x | x | x | x
390 * 1101 | x | x (22)| x | x (21)
391 * 1110 | x | x (16)| x | x (20)
392 * 1111 | x | x | x | x
394 * Pen selection table for uFlags = BF_SOFT
396 * uType | LTI | LTO | RBI | RBO
397 * ------+-------+-------+-------+-------
398 * 0000 | x | x | x | x
399 * 0001 | x | 20 | x | 21
400 * 0010 | x | 21 | x | 20
401 * 0011 | x | x | x | x
402 * ------+-------+-------+-------+-------
403 * 0100 | x | 22 | x | 16
404 * 0101 | 22 | 20 | 16 | 21
405 * 0110 | 22 | 21 | 16 | 20
406 * 0111 | x | x | x | x
407 * ------+-------+-------+-------+-------
408 * 1000 | x | 16 | x | 22
409 * 1001 | 16 | 20 | 22 | 21
410 * 1010 | 16 | 21 | 22 | 20
411 * 1011 | x | x | x | x
412 * ------+-------+-------+-------+-------
413 * 1100 | x | x | x | x
414 * 1101 | x | x (20)| x | x (21)
415 * 1110 | x | x (21)| x | x (20)
416 * 1111 | x | x | x | x
418 * x = don't care; (n) = is what win95 actually uses
419 * LTI = left Top Inner line
420 * LTO = left Top Outer line
421 * RBI = Right Bottom Inner line
422 * RBO = Right Bottom Outer line
424 * 16 = COLOR_BTNSHADOW
425 * 20 = COLOR_BTNHIGHLIGHT
426 * 21 = COLOR_3DDKSHADOW
429 static BOOL
IntDrawRectEdge(HDC hdc
, LPRECT rc
, UINT uType
, UINT uFlags
, UINT width
)
431 signed char LTInnerI
, LTOuterI
;
432 signed char RBInnerI
, RBOuterI
;
433 HBRUSH lti_brush
, lto_brush
, rbi_brush
, rbo_brush
;
434 RECT InnerRect
= *rc
, fill_rect
;
435 int lbi_offset
= 0, lti_offset
= 0, rti_offset
= 0, rbi_offset
= 0;
436 BOOL retval
= !( ((uType
& BDR_INNER
) == BDR_INNER
437 || (uType
& BDR_OUTER
) == BDR_OUTER
)
438 && !(uFlags
& (BF_FLAT
|BF_MONO
)) );
440 lti_brush
= lto_brush
= rbi_brush
= rbo_brush
= GetStockObject(NULL_BRUSH
);
442 /* Determine the colors of the edges */
445 LTInnerI
= RBInnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
446 LTOuterI
= RBOuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
448 else if(uFlags
& BF_FLAT
)
450 LTInnerI
= RBInnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
451 LTOuterI
= RBOuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
453 /* Bertho Stultiens states above that this function exactly matches win95
454 * In win98 BF_FLAT rectangles have an inner border same color as the
455 * middle (COLOR_BTNFACE). I believe it's the same for win95 but since
456 * I don't know I go with Bertho and just sets it for win98 until proven
458 * Dennis Björklund, 10 June, 99
460 if( LTInnerI
!= -1 ) LTInnerI
= RBInnerI
= COLOR_BTNFACE
;
462 else if(uFlags
& BF_SOFT
)
464 LTInnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
465 LTOuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
466 RBInnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
467 RBOuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
471 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
472 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
473 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
474 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
477 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
) lbi_offset
= width
;
478 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
) rti_offset
= width
;
479 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
) rbi_offset
= width
;
480 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
) lti_offset
= width
;
482 if(LTInnerI
!= -1) lti_brush
= GetSysColorBrush(LTInnerI
);
483 if(LTOuterI
!= -1) lto_brush
= GetSysColorBrush(LTOuterI
);
484 if(RBInnerI
!= -1) rbi_brush
= GetSysColorBrush(RBInnerI
);
485 if(RBOuterI
!= -1) rbo_brush
= GetSysColorBrush(RBOuterI
);
487 /* Draw the outer edge */
490 fill_rect
= InnerRect
;
491 fill_rect
.bottom
= fill_rect
.top
+ width
;
492 FillRect( hdc
, &fill_rect
, lto_brush
);
496 fill_rect
= InnerRect
;
497 fill_rect
.right
= fill_rect
.left
+ width
;
498 FillRect( hdc
, &fill_rect
, lto_brush
);
500 if(uFlags
& BF_BOTTOM
)
502 fill_rect
= InnerRect
;
503 fill_rect
.top
= fill_rect
.bottom
- width
;
504 FillRect( hdc
, &fill_rect
, rbo_brush
);
506 if(uFlags
& BF_RIGHT
)
508 fill_rect
= InnerRect
;
509 fill_rect
.left
= fill_rect
.right
- width
;
510 FillRect( hdc
, &fill_rect
, rbo_brush
);
513 /* Draw the inner edge */
516 SetRect( &fill_rect
, InnerRect
.left
+ lti_offset
, InnerRect
.top
+ width
,
517 InnerRect
.right
- rti_offset
, InnerRect
.top
+ 2 * width
);
518 FillRect( hdc
, &fill_rect
, lti_brush
);
522 SetRect( &fill_rect
, InnerRect
.left
+ width
, InnerRect
.top
+ lti_offset
,
523 InnerRect
.left
+ 2 * width
, InnerRect
.bottom
- lbi_offset
);
524 FillRect( hdc
, &fill_rect
, lti_brush
);
526 if(uFlags
& BF_BOTTOM
)
528 SetRect( &fill_rect
, InnerRect
.left
+ lbi_offset
, InnerRect
.bottom
- 2 * width
,
529 InnerRect
.right
- rbi_offset
, InnerRect
.bottom
- width
);
530 FillRect( hdc
, &fill_rect
, rbi_brush
);
532 if(uFlags
& BF_RIGHT
)
534 SetRect( &fill_rect
, InnerRect
.right
- 2 * width
, InnerRect
.top
+ rti_offset
,
535 InnerRect
.right
- width
, InnerRect
.bottom
- rbi_offset
);
536 FillRect( hdc
, &fill_rect
, rbi_brush
);
539 if( ((uFlags
& BF_MIDDLE
) && retval
) || (uFlags
& BF_ADJUST
) )
541 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? width
: 0)
542 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? width
: 0);
544 if(uFlags
& BF_LEFT
) InnerRect
.left
+= add
;
545 if(uFlags
& BF_RIGHT
) InnerRect
.right
-= add
;
546 if(uFlags
& BF_TOP
) InnerRect
.top
+= add
;
547 if(uFlags
& BF_BOTTOM
) InnerRect
.bottom
-= add
;
549 if((uFlags
& BF_MIDDLE
) && retval
)
551 FillRect(hdc
, &InnerRect
, GetSysColorBrush(uFlags
& BF_MONO
?
552 COLOR_WINDOW
: COLOR_BTNFACE
));
555 if(uFlags
& BF_ADJUST
)
562 /* Ported from WINE20020904 */
563 /* Utility to create a square rectangle and returning the width */
564 static int UITOOLS_MakeSquareRect(LPRECT src
, LPRECT dst
)
566 int Width
= src
->right
- src
->left
;
567 int Height
= src
->bottom
- src
->top
;
568 int SmallDiam
= Width
> Height
? Height
: Width
;
572 /* Make it a square box */
573 if(Width
< Height
) /* SmallDiam == Width */
575 dst
->top
+= (Height
-Width
)/2;
576 dst
->bottom
= dst
->top
+ SmallDiam
;
578 else if(Width
> Height
) /* SmallDiam == Height */
580 dst
->left
+= (Width
-Height
)/2;
581 dst
->right
= dst
->left
+ SmallDiam
;
587 /* Ported from WINE20020904 */
588 static void UITOOLS_DrawCheckedRect( HDC dc
, LPRECT rect
)
590 if(GetSysColor(COLOR_BTNHIGHLIGHT
) == RGB(255, 255, 255))
595 FillRect(dc
, rect
, GetSysColorBrush(COLOR_BTNFACE
));
596 bg
= SetBkColor(dc
, RGB(255, 255, 255));
597 hbsave
= (HBRUSH
)SelectObject(dc
, gpsi
->hbrGray
);
598 PatBlt(dc
, rect
->left
, rect
->top
, rect
->right
-rect
->left
, rect
->bottom
-rect
->top
, 0x00FA0089);
599 SelectObject(dc
, hbsave
);
604 FillRect(dc
, rect
, GetSysColorBrush(COLOR_BTNHIGHLIGHT
));
608 /* Ported from WINE20020904 */
609 /* Draw a push button coming from DrawFrameControl()
611 * Does a pretty good job in emulating MS behavior. Some quirks are
612 * however there because MS uses a TrueType font (Marlett) to draw
615 * FIXME: This looks a little bit strange, needs to be rewritten completely
616 * (several quirks with adjust, DFCS_CHECKED aso)
618 static BOOL
UITOOLS95_DFC_ButtonPush(HDC dc
, LPRECT r
, UINT uFlags
)
623 if(uFlags
& (DFCS_PUSHED
| DFCS_CHECKED
| DFCS_FLAT
))
628 if(uFlags
& DFCS_CHECKED
)
630 if(uFlags
& DFCS_MONO
)
631 IntDrawRectEdge(dc
, &myr
, edge
, BF_MONO
|BF_RECT
|BF_ADJUST
, 1);
633 IntDrawRectEdge(dc
, &myr
, edge
, (uFlags
&DFCS_FLAT
)|BF_RECT
|BF_SOFT
|BF_ADJUST
, 1);
635 UITOOLS_DrawCheckedRect( dc
, &myr
);
639 if(uFlags
& DFCS_MONO
)
641 IntDrawRectEdge(dc
, &myr
, edge
, BF_MONO
|BF_RECT
|BF_ADJUST
, 1);
642 FillRect(dc
, &myr
, GetSysColorBrush(COLOR_BTNFACE
));
646 IntDrawRectEdge(dc
, r
, edge
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
| BF_SOFT
, 1);
650 /* Adjust rectangle if asked */
651 if(uFlags
& DFCS_ADJUSTRECT
)
652 InflateRect(r
, -2, -2);
657 static BOOL
UITOOLS95_DFC_ButtonCheckRadio(HDC dc
, LPRECT r
, UINT uFlags
, BOOL Radio
)
660 HFONT hFont
, hOldFont
;
662 TCHAR OutRight
, OutLeft
, InRight
, InLeft
, Center
;
663 INT X
, Y
, Width
, Height
, Shorter
;
664 INT BkMode
= GetBkMode(dc
);
665 COLORREF TextColor
= GetTextColor(dc
);
667 Width
= r
->right
- r
->left
;
668 Height
= r
->bottom
- r
->top
;
669 Shorter
= (Width
< Height
) ? Width
: Height
;
670 X
= r
->left
+ (Width
- Shorter
) / 2;
671 Y
= r
->top
+ (Height
- Shorter
) / 2;
675 OutRight
= 'j'; // Outer right
676 OutLeft
= 'k'; // Outer left
677 InRight
= 'l'; // inner left
678 InLeft
= 'm'; // inner right
679 Center
= 'n'; // center
683 OutRight
= 'c'; // Outer right
684 OutLeft
= 'd'; // Outer left
685 InRight
= 'e'; // inner left
686 InLeft
= 'f'; // inner right
687 Center
= 'g'; // center
690 ZeroMemory(&lf
, sizeof(LOGFONTW
));
691 lf
.lfHeight
= Shorter
;
692 lf
.lfCharSet
= DEFAULT_CHARSET
;
693 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
694 if (Radio
&& ((uFlags
& 0xFF) == DFCS_BUTTONRADIOMASK
))
696 lf
.lfQuality
= NONANTIALIASED_QUALITY
;
698 hFont
= CreateFontIndirect(&lf
);
699 hOldFont
= SelectObject(dc
, hFont
);
701 if (Radio
&& ((uFlags
& 0xFF) == DFCS_BUTTONRADIOMASK
))
704 // FIXME: improve font rendering
706 HGDIOBJ hbrOld
, hpenOld
;
707 FillRect(dc
, r
, (HBRUSH
)GetStockObject(WHITE_BRUSH
));
708 SetRect(&Rect
, X
, Y
, X
+ Shorter
, Y
+ Shorter
);
709 InflateRect(&Rect
, -(Shorter
* 8) / 54, -(Shorter
* 8) / 54);
710 hbrOld
= SelectObject(dc
, GetStockObject(BLACK_BRUSH
));
711 hpenOld
= SelectObject(dc
, GetStockObject(NULL_PEN
));
712 Ellipse(dc
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
713 SelectObject(dc
, hbrOld
);
714 SelectObject(dc
, hpenOld
);
716 SetBkMode(dc
, OPAQUE
);
717 SetBkColor(dc
, RGB(255, 255, 255));
718 SetTextColor(dc
, RGB(0, 0, 0));
719 TextOut(dc
, X
, Y
, &Center
, 1);
720 SetBkMode(dc
, TRANSPARENT
);
721 TextOut(dc
, X
, Y
, &OutRight
, 1);
722 TextOut(dc
, X
, Y
, &OutLeft
, 1);
723 TextOut(dc
, X
, Y
, &InRight
, 1);
724 TextOut(dc
, X
, Y
, &InLeft
, 1);
729 SetBkMode(dc
, TRANSPARENT
);
731 /* Center section, white for active, grey for inactive */
732 if ((uFlags
& (DFCS_INACTIVE
| DFCS_PUSHED
)))
736 SetTextColor(dc
, GetSysColor(i
));
737 TextOut(dc
, X
, Y
, &Center
, 1);
739 if (uFlags
& (DFCS_FLAT
| DFCS_MONO
))
741 SetTextColor(dc
, GetSysColor(COLOR_WINDOWFRAME
));
742 TextOut(dc
, X
, Y
, &OutRight
, 1);
743 TextOut(dc
, X
, Y
, &OutLeft
, 1);
744 TextOut(dc
, X
, Y
, &InRight
, 1);
745 TextOut(dc
, X
, Y
, &InLeft
, 1);
749 SetTextColor(dc
, GetSysColor(COLOR_BTNSHADOW
));
750 TextOut(dc
, X
, Y
, &OutRight
, 1);
751 SetTextColor(dc
, GetSysColor(COLOR_BTNHIGHLIGHT
));
752 TextOut(dc
, X
, Y
, &OutLeft
, 1);
753 SetTextColor(dc
, GetSysColor(COLOR_3DDKSHADOW
));
754 TextOut(dc
, X
, Y
, &InRight
, 1);
755 SetTextColor(dc
, GetSysColor(COLOR_3DLIGHT
));
756 TextOut(dc
, X
, Y
, &InLeft
, 1);
759 if (uFlags
& DFCS_CHECKED
)
761 TCHAR Check
= (Radio
) ? 'i' : 'b';
763 SetTextColor(dc
, GetSysColor(COLOR_WINDOWTEXT
));
764 TextOut(dc
, X
, Y
, &Check
, 1);
768 SelectObject(dc
, hOldFont
);
771 SetTextColor(dc
, TextColor
);
772 SetBkMode(dc
, BkMode
);
777 /* Ported from WINE20020904 */
778 static BOOL
UITOOLS95_DrawFrameButton(HDC hdc
, LPRECT rc
, UINT uState
)
780 switch(uState
& 0xff)
782 case DFCS_BUTTONPUSH
:
783 return UITOOLS95_DFC_ButtonPush(hdc
, rc
, uState
);
785 case DFCS_BUTTONCHECK
:
786 case DFCS_BUTTON3STATE
:
787 return UITOOLS95_DFC_ButtonCheckRadio(hdc
, rc
, uState
, FALSE
);
789 case DFCS_BUTTONRADIOIMAGE
:
790 case DFCS_BUTTONRADIOMASK
:
791 case DFCS_BUTTONRADIO
:
792 return UITOOLS95_DFC_ButtonCheckRadio(hdc
, rc
, uState
, TRUE
);
796 DbgPrint("Invalid button state=0x%04x\n", uState);
803 static BOOL
UITOOLS95_DrawFrameCaption(HDC dc
, LPRECT r
, UINT uFlags
)
806 HFONT hFont
, hOldFont
;
811 switch(uFlags
& 0xff)
813 case DFCS_CAPTIONCLOSE
:
816 case DFCS_CAPTIONHELP
:
819 case DFCS_CAPTIONMIN
:
822 case DFCS_CAPTIONMAX
:
825 case DFCS_CAPTIONRESTORE
:
829 WARN("Invalid caption; flags=0x%04x\n", uFlags
);
832 IntDrawRectEdge(dc
,r
,(uFlags
&DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, BF_RECT
| BF_MIDDLE
| BF_SOFT
, 1);
833 ZeroMemory(&lf
, sizeof(LOGFONTW
));
834 UITOOLS_MakeSquareRect(r
, &myr
);
839 if(uFlags
& DFCS_PUSHED
)
840 OffsetRect(&myr
,1,1);
841 lf
.lfHeight
= myr
.bottom
- myr
.top
;
843 lf
.lfWeight
= FW_NORMAL
;
844 lf
.lfCharSet
= DEFAULT_CHARSET
;
845 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
846 hFont
= CreateFontIndirect(&lf
);
847 /* save font and text color */
848 hOldFont
= SelectObject(dc
, hFont
);
849 clrsave
= GetTextColor(dc
);
850 bkmode
= GetBkMode(dc
);
851 /* set color and drawing mode */
852 SetBkMode(dc
, TRANSPARENT
);
853 if(uFlags
& DFCS_INACTIVE
)
856 SetTextColor(dc
, GetSysColor(COLOR_BTNHIGHLIGHT
));
857 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
859 SetTextColor(dc
, GetSysColor((uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
));
860 /* draw selected symbol */
861 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
862 /* restore previous settings */
863 SetTextColor(dc
, clrsave
);
864 SelectObject(dc
, hOldFont
);
865 SetBkMode(dc
, bkmode
);
870 static BOOL
UITOOLS95_DrawFrameScroll(HDC dc
, LPRECT r
, UINT uFlags
)
873 HFONT hFont
, hOldFont
;
878 switch(uFlags
& 0xff)
880 case DFCS_SCROLLCOMBOBOX
:
881 case DFCS_SCROLLDOWN
:
889 case DFCS_SCROLLLEFT
:
893 case DFCS_SCROLLRIGHT
:
897 case DFCS_SCROLLSIZEGRIP
:
898 case DFCS_SCROLLSIZEGRIPRIGHT
:
899 ZeroMemory(&lf
, sizeof(LOGFONTW
));
900 UITOOLS_MakeSquareRect(r
, &myr
);
901 lf
.lfHeight
= myr
.bottom
- myr
.top
;
903 lf
.lfWeight
= FW_NORMAL
;
904 lf
.lfCharSet
= DEFAULT_CHARSET
;
905 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
906 hFont
= CreateFontIndirect(&lf
);
907 /* save font and text color */
908 hOldFont
= SelectObject(dc
, hFont
);
909 clrsave
= GetTextColor(dc
);
910 bkmode
= GetBkMode(dc
);
911 /* set color and drawing mode */
912 SetBkMode(dc
, TRANSPARENT
);
913 if (!(uFlags
& (DFCS_MONO
| DFCS_FLAT
)))
915 SetTextColor(dc
, GetSysColor(COLOR_BTNHIGHLIGHT
));
916 /* draw selected symbol */
917 Symbol
= ((uFlags
& 0xff) == DFCS_SCROLLSIZEGRIP
) ? 'o' : 'x';
918 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
919 SetTextColor(dc
, GetSysColor(COLOR_BTNSHADOW
));
921 SetTextColor(dc
, GetSysColor(COLOR_WINDOWFRAME
));
922 /* draw selected symbol */
923 Symbol
= ((uFlags
& 0xff) == DFCS_SCROLLSIZEGRIP
) ? 'p' : 'y';
924 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
925 /* restore previous settings */
926 SetTextColor(dc
, clrsave
);
927 SelectObject(dc
, hOldFont
);
928 SetBkMode(dc
, bkmode
);
932 WARN("Invalid scroll; flags=0x%04x\n", uFlags
);
935 IntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
, 1);
936 ZeroMemory(&lf
, sizeof(LOGFONTW
));
937 UITOOLS_MakeSquareRect(r
, &myr
);
942 if(uFlags
& DFCS_PUSHED
)
943 OffsetRect(&myr
,1,1);
944 lf
.lfHeight
= myr
.bottom
- myr
.top
;
946 lf
.lfWeight
= FW_NORMAL
;
947 lf
.lfCharSet
= DEFAULT_CHARSET
;
948 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
949 hFont
= CreateFontIndirect(&lf
);
950 /* save font and text color */
951 hOldFont
= SelectObject(dc
, hFont
);
952 clrsave
= GetTextColor(dc
);
953 bkmode
= GetBkMode(dc
);
954 /* set color and drawing mode */
955 SetBkMode(dc
, TRANSPARENT
);
956 if(uFlags
& DFCS_INACTIVE
)
959 SetTextColor(dc
, GetSysColor(COLOR_BTNHIGHLIGHT
));
960 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
962 SetTextColor(dc
, GetSysColor((uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
));
963 /* draw selected symbol */
964 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
965 /* restore previous settings */
966 SetTextColor(dc
, clrsave
);
967 SelectObject(dc
, hOldFont
);
968 SetBkMode(dc
, bkmode
);
973 static BOOL
UITOOLS95_DrawFrameMenu(HDC dc
, LPRECT r
, UINT uFlags
)
975 // TODO: DFCS_TRANSPARENT upon DFCS_MENUARROWUP or DFCS_MENUARROWDOWN
977 HFONT hFont
, hOldFont
;
981 cxy
= UITOOLS_MakeSquareRect(r
, &myr
);
982 switch(uFlags
& 0xff)
984 case DFCS_MENUARROWUP
:
988 case DFCS_MENUARROWDOWN
:
996 case DFCS_MENUARROWRIGHT
:
997 Symbol
= 'w'; // FIXME: needs to confirm
1000 case DFCS_MENUBULLET
:
1004 case DFCS_MENUCHECK
:
1009 WARN("Invalid menu; flags=0x%04x\n", uFlags
);
1012 /* acquire ressources only if valid menu */
1013 ZeroMemory(&lf
, sizeof(LOGFONTW
));
1016 lf
.lfWeight
= FW_NORMAL
;
1017 lf
.lfCharSet
= DEFAULT_CHARSET
;
1018 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
1019 hFont
= CreateFontIndirect(&lf
);
1021 hOldFont
= SelectObject(dc
, hFont
);
1023 if ((uFlags
& 0xff) == DFCS_MENUARROWUP
||
1024 (uFlags
& 0xff) == DFCS_MENUARROWDOWN
)
1027 if (uFlags
& DFCS_INACTIVE
)
1030 SetTextColor(dc
, GetSysColor(COLOR_BTNHIGHLIGHT
));
1031 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
1034 SetTextColor(dc
, GetSysColor((uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
));
1036 /* draw selected symbol */
1037 nBkMode
= SetBkMode(dc
, TRANSPARENT
);
1038 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
1039 SetBkMode(dc
, nBkMode
);
1040 /* restore previous settings */
1041 SelectObject(dc
, hOldFont
);
1042 DeleteObject(hFont
);
1051 GRAYSTRINGPROC lpOutputFunc
,
1060 // AG: Mostly implemented, but probably won't work properly or return
1061 // correct error codes. I doubt it grays strings either... Untested!
1063 BOOL success
= FALSE
;
1066 HBITMAP MemBMP
= NULL
, OldBMP
= NULL
;
1067 HBRUSH OldBrush
= NULL
;
1068 HFONT OldFont
= NULL
;
1070 COLORREF ForeColor
, BackColor
;
1072 ForeColor
= SetTextColor(hDC
, RGB(0, 0, 0));
1073 BackColor
= SetBkColor(hDC
, RGB(255, 255, 255));
1077 // The documentation is a little vague on what exactly should happen
1078 // here. Something about using the same brush for window text???
1079 hBrush
= (HBRUSH
) GetCurrentObject(hDC
, OBJ_BRUSH
);
1082 if ((nCount
== -1) && (! lpOutputFunc
))
1087 // TODO: calculate the length (easy enough)
1090 nCount
= lstrlenW((WCHAR
*)lpData
);
1092 nCount
= lstrlenA((CHAR
*)lpData
);
1095 if (! nWidth
|| ! nHeight
)
1098 // TODO: calculate the rect
1101 success
= GetTextExtentPoint32W(hDC
, (WCHAR
*) lpData
, nCount
, &s
);
1103 success
= GetTextExtentPoint32A(hDC
, (CHAR
*) lpData
, nCount
, &s
);
1105 if (! success
) goto cleanup
;
1107 if (! nWidth
) nWidth
= s
.cx
;
1108 if (! nHeight
) nHeight
= s
.cy
;
1111 SetRect(&r
, X
, Y
, X
+ nWidth
, Y
+ nHeight
);
1113 MemDC
= CreateCompatibleDC(hDC
);
1114 if (! MemDC
) goto cleanup
;
1115 MemBMP
= CreateBitmap(nWidth
, nHeight
, 1, 1, NULL
);
1116 if (! MemBMP
) goto cleanup
;
1117 OldBMP
= SelectObject(MemDC
, MemBMP
);
1118 if (! OldBMP
) goto cleanup
;
1119 OldFont
= SelectObject(MemDC
, GetCurrentObject(hDC
, OBJ_FONT
));
1120 if (! OldFont
) goto cleanup
;
1121 OldBrush
= SelectObject(MemDC
, hBrush
);
1122 if (! OldBrush
) goto cleanup
;
1124 if (! BitBlt(MemDC
, 0, 0, nWidth
, nHeight
, hDC
, X
, Y
, SRCCOPY
)) goto cleanup
;
1126 SetTextColor(MemDC
, RGB(255, 255, 255));
1127 SetBkColor(MemDC
, RGB(0, 0, 0));
1131 success
= lpOutputFunc(MemDC
, lpData
, nCount
); // Set brush etc first?
1133 if ((nCount
== -1) && (! success
))
1135 // Don't gray (documented behaviour)
1136 success
= (BOOL
) BitBlt(hDC
, X
, Y
, nWidth
, nHeight
, MemDC
, 0, 0, SRCCOPY
);
1143 success
= TextOutW(MemDC
, 0, 0, (WCHAR
*) lpData
, nCount
);
1145 success
= TextOutA(MemDC
, 0, 0, (CHAR
*) lpData
, nCount
);
1147 if (! success
) goto cleanup
;
1149 hbsave
= (HBRUSH
)SelectObject(MemDC
, gpsi
->hbrGray
);
1150 PatBlt(MemDC
, 0, 0, nWidth
, nHeight
, 0x000A0329);
1151 SelectObject(MemDC
, hbsave
);
1154 if (! BitBlt(hDC
, X
, Y
, nWidth
, nHeight
, MemDC
, 0, 0, SRCCOPY
)) goto cleanup
;
1157 SetTextColor(hDC
, ForeColor
);
1158 SetBkColor(hDC
, BackColor
);
1162 if (OldFont
) SelectObject(MemDC
, OldFont
);
1163 if (OldBrush
) SelectObject(MemDC
, OldBrush
);
1164 if (OldBMP
) SelectObject(MemDC
, OldBMP
);
1165 if (MemBMP
) DeleteObject(MemBMP
);
1172 /**********************************************************************
1173 * PAINTING_DrawStateJam
1175 * Jams in the requested type in the dc
1177 static BOOL
PAINTING_DrawStateJam(HDC hdc
, UINT opcode
,
1178 DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1179 LPRECT rc
, UINT dtflags
, BOOL unicode
)
1184 INT cx
= rc
->right
- rc
->left
;
1185 INT cy
= rc
->bottom
- rc
->top
;
1190 case DST_PREFIXTEXT
:
1192 return DrawTextW(hdc
, (LPWSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1194 return DrawTextA(hdc
, (LPSTR
)lp
, (INT
)wp
, rc
, dtflags
);
1197 return DrawIconEx(hdc
, rc
->left
, rc
->top
, (HICON
)lp
, cx
, cy
, 0, NULL
, DI_NORMAL
);
1200 memdc
= CreateCompatibleDC(hdc
);
1203 hbmsave
= (HBITMAP
)SelectObject(memdc
, (HBITMAP
)lp
);
1209 retval
= BitBlt(hdc
, rc
->left
, rc
->top
, cx
, cy
, memdc
, 0, 0, SRCCOPY
);
1210 SelectObject(memdc
, hbmsave
);
1218 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1220 OffsetViewportOrgEx(hdc
, rc
->left
, rc
->top
, NULL
);
1221 bRet
= func(hdc
, lp
, wp
, cx
, cy
);
1222 /* Restore origin */
1223 OffsetViewportOrgEx(hdc
, -rc
->left
, -rc
->top
, NULL
);
1235 IntDrawState(HDC hdc
, HBRUSH hbr
, DRAWSTATEPROC func
, LPARAM lp
, WPARAM wp
,
1236 INT x
, INT y
, INT cx
, INT cy
, UINT flags
, BOOL unicode
)
1238 HBITMAP hbm
, hbmsave
;
1240 HBRUSH hbsave
, hbrtmp
= 0;
1243 UINT dtflags
= DT_NOCLIP
;
1245 UINT opcode
= flags
& 0xf;
1249 HFONT hFontOriginal
, hNaaFont
= NULL
;
1251 if((opcode
== DST_TEXT
|| opcode
== DST_PREFIXTEXT
) && !len
) /* The string is '\0' terminated */
1254 len
= lstrlenW((LPWSTR
)lp
);
1256 len
= lstrlenA((LPSTR
)lp
);
1259 hFontOriginal
= GetCurrentObject(hdc
, OBJ_FONT
);
1260 if (flags
& (DSS_MONO
| DSS_DISABLED
))
1262 /* Create a non-antialiased font */
1263 GetObjectW(hFontOriginal
, sizeof(lf
), &lf
);
1264 lf
.lfQuality
= NONANTIALIASED_QUALITY
;
1265 hNaaFont
= CreateFontIndirectW(&lf
);
1268 /* Find out what size the image has if not given by caller */
1277 case DST_PREFIXTEXT
:
1279 retval
= GetTextExtentPoint32W(hdc
, (LPWSTR
)lp
, len
, &s
);
1281 retval
= GetTextExtentPoint32A(hdc
, (LPSTR
)lp
, len
, &s
);
1287 if(!get_icon_size((HICON
)lp
, &s
))
1292 if(!GetObjectW((HBITMAP
)lp
, sizeof(bm
), &bm
))
1298 case DST_COMPLEX
: /* cx and cy must be set in this mode */
1302 ERR("Invalid opcode: %u\n", opcode
);
1310 SetRect(&rc
, x
, y
, x
+ cx
, y
+ cy
);
1312 if(flags
& DSS_RIGHT
) /* This one is not documented in the win32.hlp file */
1313 dtflags
|= DT_RIGHT
;
1314 if(opcode
== DST_TEXT
)
1315 dtflags
|= DT_NOPREFIX
;
1316 else if(opcode
== DST_PREFIXTEXT
)
1318 if (flags
& DSS_HIDEPREFIX
)
1319 dtflags
|= DT_HIDEPREFIX
;
1320 if (flags
& DSS_PREFIXONLY
)
1321 dtflags
|= DT_PREFIXONLY
;
1324 /* For DSS_NORMAL we just jam in the image and return */
1325 if((flags
& 0x79f0) == DSS_NORMAL
)
1327 return PAINTING_DrawStateJam(hdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1330 /* For all other states we need to convert the image to B/W in a local bitmap */
1331 /* before it is displayed */
1332 fg
= SetTextColor(hdc
, RGB(0, 0, 0));
1333 bg
= SetBkColor(hdc
, RGB(255, 255, 255));
1334 hbm
= NULL
; hbmsave
= NULL
;
1335 memdc
= NULL
; hbsave
= NULL
;
1336 retval
= FALSE
; /* assume failure */
1338 /* From here on we must use "goto cleanup" when something goes wrong */
1339 hbm
= CreateBitmap(cx
, cy
, 1, 1, NULL
);
1340 if(!hbm
) goto cleanup
;
1341 memdc
= CreateCompatibleDC(hdc
);
1342 if(!memdc
) goto cleanup
;
1343 hbmsave
= (HBITMAP
)SelectObject(memdc
, hbm
);
1344 if(!hbmsave
) goto cleanup
;
1345 SetRect(&rc
, 0, 0, cx
, cy
);
1346 if(!FillRect(memdc
, &rc
, (HBRUSH
)GetStockObject(WHITE_BRUSH
))) goto cleanup
;
1347 SetBkColor(memdc
, RGB(255, 255, 255));
1348 SetTextColor(memdc
, RGB(0, 0, 0));
1350 hfsave
= (HFONT
)SelectObject(memdc
, hNaaFont
);
1352 hfsave
= (HFONT
)SelectObject(memdc
, hFontOriginal
);
1353 SetLayout( memdc
, GetLayout( hdc
));
1355 /* DST_COMPLEX may draw text as well,
1356 * so we must be sure that correct font is selected
1358 if(!hfsave
&& (opcode
<= DST_PREFIXTEXT
)) goto cleanup
;
1359 tmp
= PAINTING_DrawStateJam(memdc
, opcode
, func
, lp
, len
, &rc
, dtflags
, unicode
);
1360 if(hfsave
) SelectObject(memdc
, hfsave
);
1361 if (hNaaFont
) DeleteObject(hNaaFont
);
1362 if(!tmp
) goto cleanup
;
1364 /* This state cause the image to be dithered */
1365 if(flags
& DSS_UNION
)
1367 hbsave
= (HBRUSH
)SelectObject(memdc
, gpsi
->hbrGray
);
1368 if(!hbsave
) goto cleanup
;
1369 tmp
= PatBlt(memdc
, 0, 0, cx
, cy
, 0x00FA0089);
1370 SelectObject(memdc
, hbsave
);
1371 if(!tmp
) goto cleanup
;
1374 if (flags
& DSS_DISABLED
)
1375 hbrtmp
= GetSysColorBrush(COLOR_3DHILIGHT
);
1376 else if (flags
& DSS_DEFAULT
)
1377 hbrtmp
= GetSysColorBrush(COLOR_3DSHADOW
);
1379 /* Draw light or dark shadow */
1380 if (flags
& (DSS_DISABLED
|DSS_DEFAULT
))
1382 if(!hbrtmp
) goto cleanup
;
1383 hbsave
= (HBRUSH
)SelectObject(hdc
, hbrtmp
);
1384 if(!hbsave
) goto cleanup
;
1385 if(!BitBlt(hdc
, x
+1, y
+1, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1386 SelectObject(hdc
, hbsave
);
1389 if (flags
& DSS_DISABLED
)
1391 hbr
= hbrtmp
= GetSysColorBrush(COLOR_3DSHADOW
);
1392 if(!hbrtmp
) goto cleanup
;
1396 hbr
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
1399 hbsave
= (HBRUSH
)SelectObject(hdc
, hbr
);
1401 if(!BitBlt(hdc
, x
, y
, cx
, cy
, memdc
, 0, 0, 0x00B8074A)) goto cleanup
;
1403 retval
= TRUE
; /* We succeeded */
1406 SetTextColor(hdc
, fg
);
1407 SetBkColor(hdc
, bg
);
1409 if(hbsave
) SelectObject(hdc
, hbsave
);
1410 if(hbmsave
) SelectObject(memdc
, hbmsave
);
1411 if(hbm
) DeleteObject(hbm
);
1412 if(memdc
) DeleteDC(memdc
);
1421 RealDrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
)
1423 if (GetMapMode(hDC
) != MM_TEXT
)
1429 return UITOOLS95_DrawFrameButton(hDC
, rc
, uState
);
1431 return UITOOLS95_DrawFrameCaption(hDC
, rc
, uState
);
1433 return UITOOLS95_DrawFrameMenu(hDC
, rc
, uState
);
1440 return UITOOLS95_DrawFrameScroll(hDC
, rc
, uState
);
1446 DrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
)
1448 BOOL Hook
, Ret
= FALSE
;
1452 Hook
= BeginIfHookedUserApiHook();
1454 /* Bypass SEH and go direct. */
1455 if (!Hook
) return RealDrawFrameControl(hDC
, rc
, uType
, uState
);
1459 Ret
= guah
.DrawFrameControl(hDC
, rc
, uType
, uState
);
1461 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1463 ERR("Got exception in hooked DrawFrameControl!\n");
1476 DrawEdge(HDC hDC
, LPRECT rc
, UINT edge
, UINT flags
)
1478 if (flags
& BF_DIAGONAL
)
1479 return IntDrawDiagEdge(hDC
, rc
, edge
, flags
);
1481 return IntDrawRectEdge(hDC
, rc
, edge
, flags
, 1);
1488 GrayStringA(HDC hDC
, HBRUSH hBrush
, GRAYSTRINGPROC lpOutputFunc
, LPARAM lpData
,
1489 int nCount
, int X
, int Y
, int nWidth
, int nHeight
)
1491 return IntGrayString(hDC
, hBrush
, lpOutputFunc
, lpData
, nCount
, X
, Y
, nWidth
, nHeight
, FALSE
);
1498 GrayStringW(HDC hDC
, HBRUSH hBrush
, GRAYSTRINGPROC lpOutputFunc
, LPARAM lpData
,
1499 int nCount
, int X
, int Y
, int nWidth
, int nHeight
)
1501 return IntGrayString(hDC
, hBrush
, lpOutputFunc
, lpData
, nCount
, X
, Y
, nWidth
, nHeight
, TRUE
);
1508 InvertRect(HDC hDC
, CONST RECT
*lprc
)
1510 return PatBlt(hDC
, lprc
->left
, lprc
->top
, lprc
->right
- lprc
->left
,
1511 lprc
->bottom
- lprc
->top
, DSTINVERT
);
1518 FrameRect(HDC hDC
, CONST RECT
*lprc
, HBRUSH hbr
)
1523 if (IsRectEmpty(&r
)) return 0;
1524 if (!(oldbrush
= SelectObject(hDC
, hbr
))) return 0;
1526 PatBlt(hDC
, r
.left
, r
.top
, 1, r
.bottom
- r
.top
, PATCOPY
);
1527 PatBlt(hDC
, r
.right
- 1, r
.top
, 1, r
.bottom
- r
.top
, PATCOPY
);
1528 PatBlt(hDC
, r
.left
, r
.top
, r
.right
- r
.left
, 1, PATCOPY
);
1529 PatBlt(hDC
, r
.left
, r
.bottom
- 1, r
.right
- r
.left
, 1, PATCOPY
);
1531 SelectObject(hDC
, oldbrush
);
1539 FlashWindow(HWND hWnd
, BOOL bInvert
)
1541 FLASHWINFO FlashWndInfo
;
1543 FlashWndInfo
.cbSize
= sizeof(FLASHWINFO
);
1544 FlashWndInfo
.hwnd
= hWnd
;
1545 FlashWndInfo
.dwFlags
= !bInvert
? 0 : (FLASHW_TRAY
| FLASHW_CAPTION
);
1546 FlashWndInfo
.uCount
= 1;
1547 FlashWndInfo
.dwTimeout
= 0;
1549 return NtUserFlashWindowEx(&FlashWndInfo
);
1556 FillRect(HDC hDC
, CONST RECT
*lprc
, HBRUSH hbr
)
1559 HBRUSH prevhbr
= NULL
;
1561 /* Select brush if specified */
1564 /* Handle system colors */
1565 if (hbr
<= (HBRUSH
)(COLOR_MENUBAR
+ 1))
1566 hbr
= GetSysColorBrush(PtrToUlong(hbr
) - 1);
1568 prevhbr
= SelectObject(hDC
, hbr
);
1569 if (prevhbr
== NULL
)
1573 Ret
= PatBlt(hDC
, lprc
->left
, lprc
->top
, lprc
->right
- lprc
->left
,
1574 lprc
->bottom
- lprc
->top
, PATCOPY
);
1576 /* Select old brush */
1578 SelectObject(hDC
, prevhbr
);
1587 DrawFocusRect(HDC hdc
, CONST RECT
*rect
)
1592 NtUserSystemParametersInfo(SPI_GETFOCUSBORDERWIDTH
, 0, &cx
, 0);
1593 NtUserSystemParametersInfo(SPI_GETFOCUSBORDERHEIGHT
, 0, &cy
, 0);
1595 OldObj
= SelectObject(hdc
, gpsi
->hbrGray
);
1598 PatBlt(hdc
, rect
->left
, rect
->top
, rect
->right
- rect
->left
, cy
, PATINVERT
);
1600 PatBlt(hdc
, rect
->left
, rect
->bottom
- cy
, rect
->right
- rect
->left
, cy
, PATINVERT
);
1602 PatBlt(hdc
, rect
->left
, rect
->top
+ cy
, cx
, rect
->bottom
- rect
->top
- (2 * cy
), PATINVERT
);
1604 PatBlt(hdc
, rect
->right
- cx
, rect
->top
+ cy
, cx
, rect
->bottom
- rect
->top
- (2 * cy
), PATINVERT
);
1606 SelectObject(hdc
, OldObj
);
1614 DrawStateA(HDC hDC
, HBRUSH hBrush
, DRAWSTATEPROC lpOutputFunc
, LPARAM lData
,
1615 WPARAM wData
, int x
, int y
, int cx
, int cy
, UINT fuFlags
)
1617 return IntDrawState(hDC
, hBrush
, lpOutputFunc
, lData
, wData
, x
, y
, cx
, cy
, fuFlags
, FALSE
);
1624 DrawStateW(HDC hDC
, HBRUSH hBrush
, DRAWSTATEPROC lpOutputFunc
, LPARAM lData
,
1625 WPARAM wData
, int x
, int y
, int cx
, int cy
, UINT fuFlags
)
1627 return IntDrawState(hDC
, hBrush
, lpOutputFunc
, lData
, wData
, x
, y
, cx
, cy
, fuFlags
, TRUE
);