2 * User Interface Functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1997 Bertho A. Stultiens
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/winuser16.h"
29 #include "user_private.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
35 /* These tables are used in:
36 * UITOOLS_DrawDiagEdge()
37 * UITOOLS_DrawRectEdge()
39 static const signed char LTInnerNormal[] = {
41 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
42 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
46 static const signed char LTOuterNormal[] = {
47 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
48 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
49 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
50 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
53 static const signed char RBInnerNormal[] = {
55 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
56 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
60 static const signed char RBOuterNormal[] = {
61 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
62 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
63 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
64 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
67 static const signed char LTInnerSoft[] = {
69 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
70 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
74 static const signed char LTOuterSoft[] = {
75 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
76 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
77 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
78 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
81 #define RBInnerSoft RBInnerNormal /* These are the same */
82 #define RBOuterSoft RBOuterNormal
84 static const signed char LTRBOuterMono[] = {
85 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
86 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
87 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
88 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
91 static const signed char LTRBInnerMono[] = {
93 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
94 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
95 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
98 static const signed char LTRBOuterFlat[] = {
99 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
100 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
101 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
102 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
105 static const signed char LTRBInnerFlat[] = {
107 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
108 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
109 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
113 #define COLOR_MAX COLOR_MENUBAR
116 /***********************************************************************
117 * UITOOLS_DrawDiagEdge
119 * Same as DrawEdge invoked with BF_DIAGONAL
121 * 03-Dec-1997: Changed by Bertho Stultiens
123 * See also comments with UITOOLS_DrawRectEdge()
125 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
126 UINT uType, UINT uFlags)
129 signed char InnerI, OuterI;
130 HPEN InnerPen, OuterPen;
135 int Width = rc->right - rc->left;
136 int Height= rc->bottom - rc->top;
137 int SmallDiam = Width > Height ? Height : Width;
138 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
139 || (uType & BDR_OUTER) == BDR_OUTER)
140 && !(uFlags & (BF_FLAT|BF_MONO)) );
141 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
142 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
145 OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
146 SavePen = (HPEN)SelectObject(hdc, InnerPen);
147 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
149 /* Determine the colors of the edges */
152 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
153 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
155 else if(uFlags & BF_FLAT)
157 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
158 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
160 else if(uFlags & BF_SOFT)
162 if(uFlags & BF_BOTTOM)
164 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
165 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
169 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
170 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
175 if(uFlags & BF_BOTTOM)
177 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
178 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
182 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
183 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
187 if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
188 if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
190 MoveToEx(hdc, 0, 0, &SavePoint);
192 /* Don't ask me why, but this is what is visible... */
193 /* This must be possible to do much simpler, but I fail to */
194 /* see the logic in the MS implementation (sigh...). */
195 /* So, this might look a bit brute force here (and it is), but */
196 /* it gets the job done;) */
198 switch(uFlags & BF_RECT)
204 /* Left bottom endpoint */
206 spx = epx + SmallDiam;
208 spy = epy - SmallDiam;
213 /* Left top endpoint */
215 spx = epx + SmallDiam;
217 spy = epy + SmallDiam;
223 case BF_RIGHT|BF_LEFT:
224 case BF_RIGHT|BF_LEFT|BF_TOP:
225 case BF_BOTTOM|BF_TOP:
226 case BF_BOTTOM|BF_TOP|BF_LEFT:
227 case BF_BOTTOMRIGHT|BF_LEFT:
228 case BF_BOTTOMRIGHT|BF_TOP:
230 /* Right top endpoint */
232 epx = spx + SmallDiam;
234 epy = spy - SmallDiam;
238 MoveToEx(hdc, spx, spy, NULL);
239 SelectObject(hdc, OuterPen);
240 LineTo(hdc, epx, epy);
242 SelectObject(hdc, InnerPen);
244 switch(uFlags & (BF_RECT|BF_DIAGONAL))
246 case BF_DIAGONAL_ENDBOTTOMLEFT:
247 case (BF_DIAGONAL|BF_BOTTOM):
249 case (BF_DIAGONAL|BF_LEFT):
250 MoveToEx(hdc, spx-1, spy, NULL);
251 LineTo(hdc, epx, epy-1);
252 Points[0].x = spx-add;
254 Points[1].x = rc->left;
255 Points[1].y = rc->top;
257 Points[2].y = epy-1-add;
258 Points[3] = Points[2];
261 case BF_DIAGONAL_ENDBOTTOMRIGHT:
262 MoveToEx(hdc, spx-1, spy, NULL);
263 LineTo(hdc, epx, epy+1);
264 Points[0].x = spx-add;
266 Points[1].x = rc->left;
267 Points[1].y = rc->bottom-1;
269 Points[2].y = epy+1+add;
270 Points[3] = Points[2];
273 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
274 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
275 case BF_DIAGONAL_ENDTOPRIGHT:
276 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
277 MoveToEx(hdc, spx+1, spy, NULL);
278 LineTo(hdc, epx, epy+1);
280 Points[0].y = epy+1+add;
281 Points[1].x = rc->right-1;
282 Points[1].y = rc->top+add;
283 Points[2].x = rc->right-1;
284 Points[2].y = rc->bottom-1;
285 Points[3].x = spx+add;
289 case BF_DIAGONAL_ENDTOPLEFT:
290 MoveToEx(hdc, spx, spy-1, NULL);
291 LineTo(hdc, epx+1, epy);
292 Points[0].x = epx+1+add;
294 Points[1].x = rc->right-1;
295 Points[1].y = rc->top;
296 Points[2].x = rc->right-1;
297 Points[2].y = rc->bottom-1-add;
299 Points[3].y = spy-add;
302 case (BF_DIAGONAL|BF_TOP):
303 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
304 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
305 MoveToEx(hdc, spx+1, spy-1, NULL);
306 LineTo(hdc, epx, epy);
309 Points[1].x = rc->right-1;
310 Points[1].y = rc->top;
311 Points[2].x = rc->right-1;
312 Points[2].y = rc->bottom-1-add;
313 Points[3].x = spx+add;
314 Points[3].y = spy-add;
317 case (BF_DIAGONAL|BF_RIGHT):
318 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
319 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
320 MoveToEx(hdc, spx, spy, NULL);
321 LineTo(hdc, epx-1, epy+1);
324 Points[1].x = rc->left;
325 Points[1].y = rc->top+add;
326 Points[2].x = epx-1-add;
327 Points[2].y = epy+1+add;
328 Points[3] = Points[2];
332 /* Fill the interior if asked */
333 if((uFlags & BF_MIDDLE) && retval)
336 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
339 HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
341 hbsave = (HBRUSH)SelectObject(hdc, hb);
342 hpsave = (HPEN)SelectObject(hdc, hp);
343 Polygon(hdc, Points, 4);
344 SelectObject(hdc, hbsave);
345 SelectObject(hdc, hpsave);
348 /* Adjust rectangle if asked */
349 if(uFlags & BF_ADJUST)
351 if(uFlags & BF_LEFT) rc->left += add;
352 if(uFlags & BF_RIGHT) rc->right -= add;
353 if(uFlags & BF_TOP) rc->top += add;
354 if(uFlags & BF_BOTTOM) rc->bottom -= add;
358 SelectObject(hdc, SavePen);
359 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
364 /***********************************************************************
365 * UITOOLS_DrawRectEdge
367 * Same as DrawEdge invoked without BF_DIAGONAL
369 * 23-Nov-1997: Changed by Bertho Stultiens
371 * Well, I started testing this and found out that there are a few things
372 * that weren't quite as win95. The following rewrite should reproduce
373 * win95 results completely.
374 * The colorselection is table-driven to avoid awfull if-statements.
375 * The table below show the color settings.
377 * Pen selection table for uFlags = 0
379 * uType | LTI | LTO | RBI | RBO
380 * ------+-------+-------+-------+-------
381 * 0000 | x | x | x | x
382 * 0001 | x | 22 | x | 21
383 * 0010 | x | 16 | x | 20
384 * 0011 | x | x | x | x
385 * ------+-------+-------+-------+-------
386 * 0100 | x | 20 | x | 16
387 * 0101 | 20 | 22 | 16 | 21
388 * 0110 | 20 | 16 | 16 | 20
389 * 0111 | x | x | x | x
390 * ------+-------+-------+-------+-------
391 * 1000 | x | 21 | x | 22
392 * 1001 | 21 | 22 | 22 | 21
393 * 1010 | 21 | 16 | 22 | 20
394 * 1011 | x | x | x | x
395 * ------+-------+-------+-------+-------
396 * 1100 | x | x | x | x
397 * 1101 | x | x (22)| x | x (21)
398 * 1110 | x | x (16)| x | x (20)
399 * 1111 | x | x | x | x
401 * Pen selection table for uFlags = BF_SOFT
403 * uType | LTI | LTO | RBI | RBO
404 * ------+-------+-------+-------+-------
405 * 0000 | x | x | x | x
406 * 0001 | x | 20 | x | 21
407 * 0010 | x | 21 | x | 20
408 * 0011 | x | x | x | x
409 * ------+-------+-------+-------+-------
410 * 0100 | x | 22 | x | 16
411 * 0101 | 22 | 20 | 16 | 21
412 * 0110 | 22 | 21 | 16 | 20
413 * 0111 | x | x | x | x
414 * ------+-------+-------+-------+-------
415 * 1000 | x | 16 | x | 22
416 * 1001 | 16 | 20 | 22 | 21
417 * 1010 | 16 | 21 | 22 | 20
418 * 1011 | x | x | x | x
419 * ------+-------+-------+-------+-------
420 * 1100 | x | x | x | x
421 * 1101 | x | x (20)| x | x (21)
422 * 1110 | x | x (21)| x | x (20)
423 * 1111 | x | x | x | x
425 * x = don't care; (n) = is what win95 actually uses
426 * LTI = left Top Inner line
427 * LTO = left Top Outer line
428 * RBI = Right Bottom Inner line
429 * RBO = Right Bottom Outer line
431 * 16 = COLOR_BTNSHADOW
432 * 20 = COLOR_BTNHIGHLIGHT
433 * 21 = COLOR_3DDKSHADOW
438 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
439 UINT uType, UINT uFlags)
441 signed char LTInnerI, LTOuterI;
442 signed char RBInnerI, RBOuterI;
443 HPEN LTInnerPen, LTOuterPen;
444 HPEN RBInnerPen, RBOuterPen;
445 RECT InnerRect = *rc;
452 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
453 || (uType & BDR_OUTER) == BDR_OUTER)
454 && !(uFlags & (BF_FLAT|BF_MONO)) );
457 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
458 SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
460 /* Determine the colors of the edges */
463 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
464 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
466 else if(uFlags & BF_FLAT)
468 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
469 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
471 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
473 else if(uFlags & BF_SOFT)
475 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
476 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
477 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
478 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
482 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
483 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
484 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
485 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
488 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
489 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
490 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
491 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
493 if(LTInnerI != -1) LTInnerPen = SYSCOLOR_GetPen(LTInnerI);
494 if(LTOuterI != -1) LTOuterPen = SYSCOLOR_GetPen(LTOuterI);
495 if(RBInnerI != -1) RBInnerPen = SYSCOLOR_GetPen(RBInnerI);
496 if(RBOuterI != -1) RBOuterPen = SYSCOLOR_GetPen(RBOuterI);
498 MoveToEx(hdc, 0, 0, &SavePoint);
500 /* Draw the outer edge */
501 SelectObject(hdc, LTOuterPen);
504 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
505 LineTo(hdc, InnerRect.right, InnerRect.top);
509 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
510 LineTo(hdc, InnerRect.left, InnerRect.bottom);
512 SelectObject(hdc, RBOuterPen);
513 if(uFlags & BF_BOTTOM)
515 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
516 LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1);
518 if(uFlags & BF_RIGHT)
520 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
521 LineTo(hdc, InnerRect.right-1, InnerRect.top-1);
524 /* Draw the inner edge */
525 SelectObject(hdc, LTInnerPen);
528 MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
529 LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
533 MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
534 LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
536 SelectObject(hdc, RBInnerPen);
537 if(uFlags & BF_BOTTOM)
539 MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
540 LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
542 if(uFlags & BF_RIGHT)
544 MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
545 LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
548 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
550 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
551 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
553 if(uFlags & BF_LEFT) InnerRect.left += add;
554 if(uFlags & BF_RIGHT) InnerRect.right -= add;
555 if(uFlags & BF_TOP) InnerRect.top += add;
556 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
558 if((uFlags & BF_MIDDLE) && retval)
560 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
561 COLOR_WINDOW : COLOR_BTNFACE));
564 if(uFlags & BF_ADJUST)
569 SelectObject(hdc, SavePen);
570 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
575 /**********************************************************************
576 * DrawEdge (USER32.@)
578 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
580 TRACE("%p %d,%d-%d,%d %04x %04x\n",
581 hdc, rc->left, rc->top, rc->right, rc->bottom, edge, flags );
583 if(flags & BF_DIAGONAL)
584 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
586 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags);
590 /************************************************************************
591 * UITOOLS_MakeSquareRect
593 * Utility to create a square rectangle and returning the width
595 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
597 int Width = src->right - src->left;
598 int Height = src->bottom - src->top;
599 int SmallDiam = Width > Height ? Height : Width;
603 /* Make it a square box */
604 if(Width < Height) /* SmallDiam == Width */
606 dst->top += (Height-Width)/2;
607 dst->bottom = dst->top + SmallDiam;
609 else if(Width > Height) /* SmallDiam == Height */
611 dst->left += (Width-Height)/2;
612 dst->right = dst->left + SmallDiam;
618 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
620 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
625 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
626 bg = SetBkColor(dc, RGB(255, 255, 255));
627 hbsave = SelectObject(dc, SYSCOLOR_55AABrush);
628 PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
629 SelectObject(dc, hbsave);
634 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
638 /************************************************************************
639 * UITOOLS_DFC_ButtonPush
641 * Draw a push button coming from DrawFrameControl()
643 * Does a pretty good job in emulating MS behavior. Some quirks are
644 * however there because MS uses a TrueType font (Marlett) to draw
647 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
652 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
657 if(uFlags & DFCS_CHECKED)
659 if(uFlags & DFCS_MONO)
660 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
662 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
664 if (!(uFlags & DFCS_TRANSPARENT))
665 UITOOLS_DrawCheckedRect( dc, &myr );
669 if(uFlags & DFCS_MONO)
671 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
672 if (!(uFlags & DFCS_TRANSPARENT))
673 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
677 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) | ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT | BF_SOFT);
681 /* Adjust rectangle if asked */
682 if(uFlags & DFCS_ADJUSTRECT)
694 /************************************************************************
695 * UITOOLS_DFC_ButtonChcek
697 * Draw a check/3state button coming from DrawFrameControl()
699 * Does a pretty good job in emulating MS behavior. Some quirks are
700 * however there because MS uses a TrueType font (Marlett) to draw
704 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
707 UINT flags = BF_RECT | BF_ADJUST;
709 UITOOLS_MakeSquareRect(r, &myr);
711 if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
712 else if(uFlags & DFCS_MONO) flags |= BF_MONO;
714 UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags );
716 if (!(uFlags & DFCS_TRANSPARENT))
718 if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
719 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
720 else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
721 UITOOLS_DrawCheckedRect( dc, &myr );
723 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
726 if(uFlags & DFCS_CHECKED)
729 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
730 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
732 /* draw 7 bars, with h=3w to form the check */
734 bar.top = myr.top + 2;
735 for (k = 0; k < 7; k++) {
736 bar.left = bar.left + 1;
737 bar.top = (k < 3) ? bar.top + 1 : bar.top - 1;
738 bar.bottom = bar.top + 3;
739 bar.right = bar.left + 1;
740 FillRect(dc, &bar, GetSysColorBrush(i));
747 /************************************************************************
748 * UITOOLS_DFC_ButtonRadio
750 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
752 * Does a pretty good job in emulating MS behavior. Some quirks are
753 * however there because MS uses a TrueType font (Marlett) to draw
756 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
760 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
761 int BorderShrink = SmallDiam / 16;
766 if(BorderShrink < 1) BorderShrink = 1;
768 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
769 FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
771 xc = myr.left + SmallDiam - SmallDiam/2;
772 yc = myr.top + SmallDiam - SmallDiam/2;
774 /* Define bounding box */
776 myr.left = xc - i+i/2;
777 myr.right = xc + i/2;
778 myr.top = yc - i+i/2;
779 myr.bottom = yc + i/2;
781 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
783 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
784 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
785 SelectObject(dc, hbsave);
789 if(uFlags & (DFCS_FLAT|DFCS_MONO))
791 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
792 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
793 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
794 SelectObject(dc, hbsave);
795 SelectObject(dc, hpsave);
799 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
800 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
801 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
803 SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNSHADOW));
804 SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
805 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
807 myr.left += BorderShrink;
808 myr.right -= BorderShrink;
809 myr.top += BorderShrink;
810 myr.bottom -= BorderShrink;
812 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
813 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
814 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
816 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
817 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
818 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
819 SelectObject(dc, hbsave);
820 SelectObject(dc, hpsave);
824 myr.left = xc - i+i/2;
825 myr.right = xc + i/2;
826 myr.top = yc - i+i/2;
827 myr.bottom = yc + i/2;
828 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
829 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
830 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
831 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
832 SelectObject(dc, hbsave);
833 SelectObject(dc, hpsave);
836 if(uFlags & DFCS_CHECKED)
840 myr.left = xc - i+i/2;
841 myr.right = xc + i/2;
842 myr.top = yc - i+i/2;
843 myr.bottom = yc + i/2;
845 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
846 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
847 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
848 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
849 SelectObject(dc, hpsave);
850 SelectObject(dc, hbsave);
853 /* FIXME: M$ has a polygon in the center at relative points: */
854 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
858 /* when the button is unchecked. The reason for it is unknown. The */
859 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
860 /* least 3 times (it looks like a clip-region when you see it happen). */
861 /* I do not really see a reason why this should be implemented. If you */
862 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
868 /***********************************************************************
869 * UITOOLS_DrawFrameButton
871 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
873 switch(uState & 0xff)
875 case DFCS_BUTTONPUSH:
876 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
878 case DFCS_BUTTONCHECK:
879 case DFCS_BUTTON3STATE:
880 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
882 case DFCS_BUTTONRADIOIMAGE:
883 case DFCS_BUTTONRADIOMASK:
884 case DFCS_BUTTONRADIO:
885 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
888 WARN("Invalid button state=0x%04x\n", uState);
894 /***********************************************************************
895 * UITOOLS_DrawFrameCaption
897 * Draw caption buttons (win95), coming from DrawFrameControl()
900 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
903 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
905 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
906 int xc = (myr.left+myr.right)/2;
907 int yc = (myr.top+myr.bottom)/2;
908 WCHAR str[2] = {0, 0};
909 static const WCHAR glyphFontName[] = { 'M','a','r','l','e','t','t',0 };
915 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
917 switch(uFlags & 0xff)
919 case DFCS_CAPTIONCLOSE: str[0] = 0x72; break;
920 case DFCS_CAPTIONHELP: str[0] = 0x73; break;
921 case DFCS_CAPTIONMIN: str[0] = 0x30; break;
922 case DFCS_CAPTIONMAX: str[0] = 0x31; break;
923 case DFCS_CAPTIONRESTORE: str[0] = 0x32; break;
925 WARN("Invalid caption; flags=0x%04x\n", uFlags);
929 hf = CreateFontW(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
930 SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
931 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, glyphFontName);
932 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
933 bksave = SetBkMode(dc, TRANSPARENT);
934 clrsave = GetTextColor(dc);
935 hfsave = (HFONT)SelectObject(dc, hf);
936 GetTextExtentPoint32W(dc, str, 1, &size);
938 if(uFlags & DFCS_INACTIVE)
940 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
941 TextOutW(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
943 SetTextColor(dc, GetSysColor(colorIdx));
944 TextOutW(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
946 SelectObject(dc, hfsave);
947 SetTextColor(dc, clrsave);
948 SetBkMode(dc, bksave);
949 SetTextAlign(dc, alignsave);
956 /************************************************************************
957 * UITOOLS_DrawFrameScroll
959 * Draw a scroll-bar control coming from DrawFrameControl()
961 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
965 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
967 HBRUSH hbsave, hb, hb2;
968 HPEN hpsave, hp, hp2;
969 int tri = 290*SmallDiam/1000 - 1;
973 * This fixes a problem with really tiny "scroll" buttons. In particular
974 * with the updown control.
975 * Making sure that the arrow is as least 3 pixels wide (or high).
980 switch(uFlags & 0xff)
982 case DFCS_SCROLLCOMBOBOX:
983 case DFCS_SCROLLDOWN:
984 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
985 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
986 Line[0].x = Line[2].x - tri;
987 Line[1].x = Line[2].x + tri;
988 Line[0].y = Line[1].y = Line[2].y - tri;
992 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
993 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
994 Line[0].x = Line[2].x - tri;
995 Line[1].x = Line[2].x + tri;
996 Line[0].y = Line[1].y = Line[2].y + tri;
999 case DFCS_SCROLLLEFT:
1000 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1001 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1002 Line[0].y = Line[2].y - tri;
1003 Line[1].y = Line[2].y + tri;
1004 Line[0].x = Line[1].x = Line[2].x + tri;
1007 case DFCS_SCROLLRIGHT:
1008 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1009 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1010 Line[0].y = Line[2].y - tri;
1011 Line[1].y = Line[2].y + tri;
1012 Line[0].x = Line[1].x = Line[2].x - tri;
1015 case DFCS_SCROLLSIZEGRIP:
1016 /* This one breaks the flow... */
1017 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1018 hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1019 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1020 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1022 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1023 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1027 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1028 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1029 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1030 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1032 Line[0].x = Line[1].x = r->right-1;
1033 Line[2].y = Line[3].y = r->bottom-1;
1034 d46 = 46*SmallDiam/750;
1035 d93 = 93*SmallDiam/750;
1037 i = 586*SmallDiam/750;
1038 Line[0].y = r->bottom - i - 1;
1039 Line[3].x = r->right - i - 1;
1040 Line[1].y = Line[0].y + d46;
1041 Line[2].x = Line[3].x + d46;
1042 SelectObject(dc, hb);
1043 SelectObject(dc, hp);
1044 Polygon(dc, Line, 4);
1046 Line[1].y++; Line[2].x++;
1047 Line[0].y = Line[1].y + d93;
1048 Line[3].x = Line[2].x + d93;
1049 SelectObject(dc, hb2);
1050 SelectObject(dc, hp2);
1051 Polygon(dc, Line, 4);
1053 i = 398*SmallDiam/750;
1054 Line[0].y = r->bottom - i - 1;
1055 Line[3].x = r->right - i - 1;
1056 Line[1].y = Line[0].y + d46;
1057 Line[2].x = Line[3].x + d46;
1058 SelectObject(dc, hb);
1059 SelectObject(dc, hp);
1060 Polygon(dc, Line, 4);
1062 Line[1].y++; Line[2].x++;
1063 Line[0].y = Line[1].y + d93;
1064 Line[3].x = Line[2].x + d93;
1065 SelectObject(dc, hb2);
1066 SelectObject(dc, hp2);
1067 Polygon(dc, Line, 4);
1069 i = 210*SmallDiam/750;
1070 Line[0].y = r->bottom - i - 1;
1071 Line[3].x = r->right - i - 1;
1072 Line[1].y = Line[0].y + d46;
1073 Line[2].x = Line[3].x + d46;
1074 SelectObject(dc, hb);
1075 SelectObject(dc, hp);
1076 Polygon(dc, Line, 4);
1078 Line[1].y++; Line[2].x++;
1079 Line[0].y = Line[1].y + d93;
1080 Line[3].x = Line[2].x + d93;
1081 SelectObject(dc, hb2);
1082 SelectObject(dc, hp2);
1083 Polygon(dc, Line, 4);
1085 SelectObject(dc, hpsave);
1086 SelectObject(dc, hbsave);
1090 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1094 /* Here do the real scroll-bar controls end up */
1095 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1096 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1097 /* want for the normal scroll-arrow button. */
1098 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1100 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1102 if(uFlags & DFCS_INACTIVE)
1104 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1105 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1106 Polygon(dc, Line, 3);
1107 SelectObject(dc, hpsave);
1108 SelectObject(dc, hbsave);
1111 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1112 for(i = 0; i < 3; i++)
1118 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1119 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1120 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
1121 Polygon(dc, Line, 3);
1122 SelectObject(dc, hpsave);
1123 SelectObject(dc, hbsave);
1128 /************************************************************************
1129 * UITOOLS_DrawFrameMenu
1131 * Draw a menu control coming from DrawFrameControl()
1133 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1137 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1145 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1146 /* use anything else. I think I tried all sys-colors to change things */
1147 /* without luck. It seems as if this behavior is inherited from the */
1148 /* win31 DFC() implementation... (you remember, B/W menus). */
1150 FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1152 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1153 hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1155 switch(uFlags & 0xff)
1157 case DFCS_MENUARROW:
1158 i = 187*SmallDiam/750;
1159 Points[2].x = myr.left + 468*SmallDiam/750;
1160 Points[2].y = myr.top + 352*SmallDiam/750+1;
1161 Points[0].y = Points[2].y - i;
1162 Points[1].y = Points[2].y + i;
1163 Points[0].x = Points[1].x = Points[2].x - i;
1164 Polygon(dc, Points, 3);
1167 case DFCS_MENUBULLET:
1169 ye = myr.top + SmallDiam - SmallDiam/2;
1170 xc = myr.left + SmallDiam - SmallDiam/2;
1171 yc = myr.top + SmallDiam - SmallDiam/2;
1172 i = 234*SmallDiam/750;
1174 myr.left = xc - i+i/2;
1175 myr.right = xc + i/2;
1176 myr.top = yc - i+i/2;
1177 myr.bottom = yc + i/2;
1178 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1181 case DFCS_MENUCHECK:
1182 Points[0].x = myr.left + 253*SmallDiam/1000;
1183 Points[0].y = myr.top + 445*SmallDiam/1000;
1184 Points[1].x = myr.left + 409*SmallDiam/1000;
1185 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1186 Points[2].x = myr.left + 690*SmallDiam/1000;
1187 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1188 Points[3].x = Points[2].x;
1189 Points[3].y = Points[2].y + 3*SmallDiam/16;
1190 Points[4].x = Points[1].x;
1191 Points[4].y = Points[1].y + 3*SmallDiam/16;
1192 Points[5].x = Points[0].x;
1193 Points[5].y = Points[0].y + 3*SmallDiam/16;
1194 Polygon(dc, Points, 6);
1198 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1203 SelectObject(dc, hpsave);
1204 SelectObject(dc, hbsave);
1209 /**********************************************************************
1210 * DrawFrameControl (USER32.@)
1212 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1215 /* Win95 doesn't support drawing in other mapping modes */
1216 if(GetMapMode(hdc) != MM_TEXT)
1222 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1224 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1226 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1227 /*case DFC_POPUPMENU:
1228 FIXME("DFC_POPUPMENU: not implemented\n");
1231 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1233 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1239 /***********************************************************************
1240 * SetRect (USER32.@)
1242 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
1243 INT right, INT bottom )
1245 if (!rect) return FALSE;
1247 rect->right = right;
1249 rect->bottom = bottom;
1254 /***********************************************************************
1255 * SetRectEmpty (USER32.@)
1257 BOOL WINAPI SetRectEmpty( LPRECT rect )
1259 if (!rect) return FALSE;
1260 rect->left = rect->right = rect->top = rect->bottom = 0;
1265 /***********************************************************************
1266 * CopyRect (USER32.@)
1268 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
1270 if (!dest || !src) return FALSE;
1276 /***********************************************************************
1277 * IsRectEmpty (USER32.@)
1279 * Bug compat: Windows checks for 0 or negative width/height.
1281 BOOL WINAPI IsRectEmpty( const RECT *rect )
1283 if (!rect) return TRUE;
1284 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
1288 /***********************************************************************
1289 * PtInRect (USER32.@)
1291 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
1293 if (!rect) return FALSE;
1294 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
1295 (pt.y >= rect->top) && (pt.y < rect->bottom));
1299 /***********************************************************************
1300 * OffsetRect (USER32.@)
1302 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
1304 if (!rect) return FALSE;
1313 /***********************************************************************
1314 * InflateRect (USER32.@)
1316 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
1318 if (!rect) return FALSE;
1327 /***********************************************************************
1328 * IntersectRect (USER32.@)
1330 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1332 if (!dest || !src1 || !src2) return FALSE;
1333 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
1334 (src1->left >= src2->right) || (src2->left >= src1->right) ||
1335 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
1337 SetRectEmpty( dest );
1340 dest->left = max( src1->left, src2->left );
1341 dest->right = min( src1->right, src2->right );
1342 dest->top = max( src1->top, src2->top );
1343 dest->bottom = min( src1->bottom, src2->bottom );
1348 /***********************************************************************
1349 * UnionRect (USER32.@)
1351 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1353 if (!dest) return FALSE;
1354 if (IsRectEmpty(src1))
1356 if (IsRectEmpty(src2))
1358 SetRectEmpty( dest );
1365 if (IsRectEmpty(src2)) *dest = *src1;
1368 dest->left = min( src1->left, src2->left );
1369 dest->right = max( src1->right, src2->right );
1370 dest->top = min( src1->top, src2->top );
1371 dest->bottom = max( src1->bottom, src2->bottom );
1378 /***********************************************************************
1379 * EqualRect (USER32.@)
1381 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
1383 if (!rect1 || !rect2) return FALSE;
1384 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1385 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1389 /***********************************************************************
1390 * SubtractRect (USER32.@)
1392 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1396 if (!dest) return FALSE;
1397 if (IsRectEmpty( src1 ))
1399 SetRectEmpty( dest );
1403 if (IntersectRect( &tmp, src1, src2 ))
1405 if (EqualRect( &tmp, dest ))
1407 SetRectEmpty( dest );
1410 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1412 if (tmp.left == dest->left) dest->left = tmp.right;
1413 else if (tmp.right == dest->right) dest->right = tmp.left;
1415 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1417 if (tmp.top == dest->top) dest->top = tmp.bottom;
1418 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1425 /***********************************************************************
1426 * FillRect (USER32.@)
1428 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1432 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1434 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1435 PatBlt( hdc, rect->left, rect->top,
1436 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1437 SelectObject( hdc, prevBrush );
1442 /***********************************************************************
1443 * InvertRect (USER32.@)
1445 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1447 return PatBlt( hdc, rect->left, rect->top,
1448 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1452 /***********************************************************************
1453 * FrameRect (USER32.@)
1455 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1460 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1461 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1463 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1464 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1465 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1466 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1468 SelectObject( hdc, prevBrush );
1473 /***********************************************************************
1474 * DrawFocusRect (USER32.@)
1476 * FIXME: PatBlt(PATINVERT) with background brush.
1478 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1481 HPEN hOldPen, hNewPen;
1482 INT oldDrawMode, oldBkMode;
1485 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1486 lb.lbStyle = BS_SOLID;
1487 lb.lbColor = GetSysColor(COLOR_WINDOWTEXT);
1488 hNewPen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL);
1489 hOldPen = SelectObject(hdc, hNewPen);
1490 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1491 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1493 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1495 SetBkMode(hdc, oldBkMode);
1496 SetROP2(hdc, oldDrawMode);
1497 SelectObject(hdc, hOldPen);
1498 DeleteObject(hNewPen);
1499 SelectObject(hdc, hOldBrush);
1505 /**********************************************************************
1506 * DrawAnimatedRects (USER32.@)
1508 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1510 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1515 /**********************************************************************
1516 * UITOOLS_DrawStateJam
1518 * Jams in the requested type in the dc
1520 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1521 LPRECT rc, UINT dtflags, BOOL unicode )
1526 INT cx = rc->right - rc->left;
1527 INT cy = rc->bottom - rc->top;
1532 case DST_PREFIXTEXT:
1534 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1536 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1539 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1542 memdc = CreateCompatibleDC(hdc);
1543 if(!memdc) return FALSE;
1544 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1550 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1551 SelectObject(memdc, hbmsave);
1558 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1560 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1561 bRet = func(hdc, lp, wp, cx, cy);
1562 /* Restore origin */
1563 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1571 /**********************************************************************
1572 * UITOOLS_DrawState()
1574 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1575 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1577 HBITMAP hbm, hbmsave;
1579 HBRUSH hbsave, hbrtmp = 0;
1582 UINT dtflags = DT_NOCLIP;
1584 UINT opcode = flags & 0xf;
1588 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1591 len = strlenW((LPWSTR)lp);
1593 len = strlen((LPSTR)lp);
1596 /* Find out what size the image has if not given by caller */
1600 CURSORICONINFO *ici;
1606 case DST_PREFIXTEXT:
1608 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1610 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1611 if(!retval) return FALSE;
1615 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1616 if(!ici) return FALSE;
1618 s.cy = ici->nHeight;
1619 GlobalUnlock16((HGLOBAL16)lp);
1623 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1628 case DST_COMPLEX: /* cx and cy must be set in this mode */
1641 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1642 dtflags |= DT_RIGHT;
1643 if(opcode == DST_TEXT)
1644 dtflags |= DT_NOPREFIX;
1646 /* For DSS_NORMAL we just jam in the image and return */
1647 if((flags & 0x7ff0) == DSS_NORMAL)
1649 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1652 /* For all other states we need to convert the image to B/W in a local bitmap */
1653 /* before it is displayed */
1654 fg = SetTextColor(hdc, RGB(0, 0, 0));
1655 bg = SetBkColor(hdc, RGB(255, 255, 255));
1656 hbm = NULL; hbmsave = NULL;
1657 memdc = NULL; hbsave = NULL;
1658 retval = FALSE; /* assume failure */
1660 /* From here on we must use "goto cleanup" when something goes wrong */
1661 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1662 if(!hbm) goto cleanup;
1663 memdc = CreateCompatibleDC(hdc);
1664 if(!memdc) goto cleanup;
1665 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1666 if(!hbmsave) goto cleanup;
1667 rc.left = rc.top = 0;
1670 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1671 SetBkColor(memdc, RGB(255, 255, 255));
1672 SetTextColor(memdc, RGB(0, 0, 0));
1673 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1675 /* DST_COMPLEX may draw text as well,
1676 * so we must be sure that correct font is selected
1678 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1679 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1680 if(hfsave) SelectObject(memdc, hfsave);
1681 if(!tmp) goto cleanup;
1683 /* This state cause the image to be dithered */
1684 if(flags & DSS_UNION)
1686 hbsave = (HBRUSH)SelectObject(memdc, SYSCOLOR_55AABrush);
1687 if(!hbsave) goto cleanup;
1688 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1689 SelectObject(memdc, hbsave);
1690 if(!tmp) goto cleanup;
1693 if (flags & DSS_DISABLED)
1694 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1695 else if (flags & DSS_DEFAULT)
1696 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1698 /* Draw light or dark shadow */
1699 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1701 if(!hbrtmp) goto cleanup;
1702 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1703 if(!hbsave) goto cleanup;
1704 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1705 SelectObject(hdc, hbsave);
1706 DeleteObject(hbrtmp);
1710 if (flags & DSS_DISABLED)
1712 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1713 if(!hbrtmp) goto cleanup;
1717 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1720 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1722 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1724 retval = TRUE; /* We succeeded */
1727 SetTextColor(hdc, fg);
1728 SetBkColor(hdc, bg);
1730 if(hbsave) SelectObject(hdc, hbsave);
1731 if(hbmsave) SelectObject(memdc, hbmsave);
1732 if(hbrtmp) DeleteObject(hbrtmp);
1733 if(hbm) DeleteObject(hbm);
1734 if(memdc) DeleteDC(memdc);
1739 /**********************************************************************
1740 * DrawStateA (USER32.@)
1742 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1743 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1744 INT x, INT y, INT cx, INT cy, UINT flags)
1746 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1749 /**********************************************************************
1750 * DrawStateW (USER32.@)
1752 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1753 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1754 INT x, INT y, INT cx, INT cy, UINT flags)
1756 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);