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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 %ld,%ld-%ld,%ld %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)
907 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
912 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
913 int xc = (myr.left+myr.right)/2;
914 int yc = (myr.top+myr.bottom)/2;
922 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
924 switch(uFlags & 0xff)
926 case DFCS_CAPTIONCLOSE:
928 /* The "X" is made by drawing a series of lines.
929 * The number of lines drawn depends on the size
930 * of the bounding rect. e.g. For a 6x5 inside rect,
931 * two lines are drawn from top-left to bottom-right,
932 * and two lines from top-right to bottom-left.
934 * 0 1 2 3 4 5 0 1 2 3 4 5
940 * Drawing one line for every 6 pixels in width
941 * seems to provide the best proportions.
945 INT width = myr.right - myr.left - 5;
946 INT height = myr.bottom - myr.top - 6;
947 INT numLines = (width / 6) + 1;
949 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
951 start.x = myr.left + 2;
952 start.y = myr.top + 2;
959 if (uFlags & DFCS_PUSHED)
965 /* now use the width of each line */
966 width -= numLines - 1;
968 for (i = 0; i < numLines; i++)
970 MoveToEx(dc, start.x + i, start.y, &oldPos);
971 LineTo(dc, start.x + i + width, start.y + height);
973 MoveToEx(dc, start.x + i, start.y + height - 1, &oldPos);
974 LineTo(dc, start.x + i + width, start.y - 1);
977 SelectObject(dc, hpsave);
981 case DFCS_CAPTIONHELP:
982 /* This one breaks the flow */
983 /* FIXME: We need the Marlett font in order to get this right. */
985 hf = CreateFontA(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
986 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
987 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
988 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
989 bksave = SetBkMode(dc, TRANSPARENT);
990 clrsave = GetTextColor(dc);
991 hfsave = (HFONT)SelectObject(dc, hf);
992 GetTextExtentPoint32A(dc, str, 1, &size);
994 if(uFlags & DFCS_INACTIVE)
996 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
997 TextOutA(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
999 SetTextColor(dc, GetSysColor(colorIdx));
1000 TextOutA(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1002 SelectObject(dc, hfsave);
1003 SetTextColor(dc, clrsave);
1004 SetBkMode(dc, bksave);
1005 SetTextAlign(dc, alignsave);
1009 case DFCS_CAPTIONMIN:
1010 Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2;
1011 Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1012 Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1;
1013 Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750;
1018 case DFCS_CAPTIONMAX:
1019 edge = 47*SmallDiam/750;
1020 Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3;
1021 Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1;
1022 Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1023 Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750;
1024 Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1025 Line1[3].x = Line1[4].x = Line1[1].x - edge;
1027 Line2[0].x = Line2[5].x = Line1[0].x;
1028 Line2[3].x = Line2[4].x = Line1[1].x;
1029 Line2[1].x = Line2[2].x = Line1[0].x + edge;
1030 Line2[0].y = Line2[1].y = Line1[0].y;
1031 Line2[4].y = Line2[5].y = Line1[2].y;
1032 Line2[2].y = Line2[3].y = Line1[2].y - edge;
1037 case DFCS_CAPTIONRESTORE:
1038 /* FIXME: this one looks bad at small sizes < 15x15 :( */
1039 edge = 47*SmallDiam/750;
1040 move = 420*SmallDiam/750;
1041 Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1042 Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1;
1043 Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1044 Line1[7].x = Line1[8].x = Line1[0].x + edge;
1045 Line1[1].x = Line1[2].x = Line1[0].x + move;
1046 Line1[5].x = Line1[6].x = Line1[1].x - edge;
1047 Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1048 Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1049 Line1[4].y = Line1[5].y = Line1[2].y - edge;
1050 Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1052 Line2[1].x = Line2[2].x = Line1[3].x;
1053 Line2[7].x = Line2[8].x = Line2[1].x - edge;
1054 Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1055 Line2[5].x = Line2[6].x = Line2[0].x + edge;
1056 Line2[0].y = Line2[1].y = Line1[9].y;
1057 Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1058 Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1059 Line2[6].y = Line2[7].y = Line2[2].y - edge;
1065 WARN("Invalid caption; flags=0x%04x\n", uFlags);
1069 /* Here the drawing takes place */
1070 if(uFlags & DFCS_INACTIVE)
1072 /* If we have an inactive button, then you see a shadow */
1073 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1074 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1075 Polygon(dc, Line1, Line1N);
1077 Polygon(dc, Line2, Line2N);
1078 SelectObject(dc, hpsave);
1079 SelectObject(dc, hbsave);
1082 /* Correct for the shadow shift */
1083 if (!(uFlags & DFCS_PUSHED))
1085 for(i = 0; i < Line1N; i++)
1090 for(i = 0; i < Line2N; i++)
1097 /* Make the final picture */
1098 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(colorIdx));
1099 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
1101 Polygon(dc, Line1, Line1N);
1103 Polygon(dc, Line2, Line2N);
1104 SelectObject(dc, hpsave);
1105 SelectObject(dc, hbsave);
1111 /************************************************************************
1112 * UITOOLS_DrawFrameScroll
1114 * Draw a scroll-bar control coming from DrawFrameControl()
1116 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
1120 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1122 HBRUSH hbsave, hb, hb2;
1123 HPEN hpsave, hp, hp2;
1124 int tri = 290*SmallDiam/1000 - 1;
1128 * This fixes a problem with really tiny "scroll" buttons. In particular
1129 * with the updown control.
1130 * Making sure that the arrow is as least 3 pixels wide (or high).
1135 switch(uFlags & 0xff)
1137 case DFCS_SCROLLCOMBOBOX:
1138 case DFCS_SCROLLDOWN:
1139 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1140 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
1141 Line[0].x = Line[2].x - tri;
1142 Line[1].x = Line[2].x + tri;
1143 Line[0].y = Line[1].y = Line[2].y - tri;
1147 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1148 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
1149 Line[0].x = Line[2].x - tri;
1150 Line[1].x = Line[2].x + tri;
1151 Line[0].y = Line[1].y = Line[2].y + tri;
1154 case DFCS_SCROLLLEFT:
1155 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1156 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1157 Line[0].y = Line[2].y - tri;
1158 Line[1].y = Line[2].y + tri;
1159 Line[0].x = Line[1].x = Line[2].x + tri;
1162 case DFCS_SCROLLRIGHT:
1163 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1164 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1165 Line[0].y = Line[2].y - tri;
1166 Line[1].y = Line[2].y + tri;
1167 Line[0].x = Line[1].x = Line[2].x - tri;
1170 case DFCS_SCROLLSIZEGRIP:
1171 /* This one breaks the flow... */
1172 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1173 hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1174 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1175 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1177 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1178 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1182 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1183 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1184 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1185 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1187 Line[0].x = Line[1].x = r->right-1;
1188 Line[2].y = Line[3].y = r->bottom-1;
1189 d46 = 46*SmallDiam/750;
1190 d93 = 93*SmallDiam/750;
1192 i = 586*SmallDiam/750;
1193 Line[0].y = r->bottom - i - 1;
1194 Line[3].x = r->right - i - 1;
1195 Line[1].y = Line[0].y + d46;
1196 Line[2].x = Line[3].x + d46;
1197 SelectObject(dc, hb);
1198 SelectObject(dc, hp);
1199 Polygon(dc, Line, 4);
1201 Line[1].y++; Line[2].x++;
1202 Line[0].y = Line[1].y + d93;
1203 Line[3].x = Line[2].x + d93;
1204 SelectObject(dc, hb2);
1205 SelectObject(dc, hp2);
1206 Polygon(dc, Line, 4);
1208 i = 398*SmallDiam/750;
1209 Line[0].y = r->bottom - i - 1;
1210 Line[3].x = r->right - i - 1;
1211 Line[1].y = Line[0].y + d46;
1212 Line[2].x = Line[3].x + d46;
1213 SelectObject(dc, hb);
1214 SelectObject(dc, hp);
1215 Polygon(dc, Line, 4);
1217 Line[1].y++; Line[2].x++;
1218 Line[0].y = Line[1].y + d93;
1219 Line[3].x = Line[2].x + d93;
1220 SelectObject(dc, hb2);
1221 SelectObject(dc, hp2);
1222 Polygon(dc, Line, 4);
1224 i = 210*SmallDiam/750;
1225 Line[0].y = r->bottom - i - 1;
1226 Line[3].x = r->right - i - 1;
1227 Line[1].y = Line[0].y + d46;
1228 Line[2].x = Line[3].x + d46;
1229 SelectObject(dc, hb);
1230 SelectObject(dc, hp);
1231 Polygon(dc, Line, 4);
1233 Line[1].y++; Line[2].x++;
1234 Line[0].y = Line[1].y + d93;
1235 Line[3].x = Line[2].x + d93;
1236 SelectObject(dc, hb2);
1237 SelectObject(dc, hp2);
1238 Polygon(dc, Line, 4);
1240 SelectObject(dc, hpsave);
1241 SelectObject(dc, hbsave);
1245 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1249 /* Here do the real scroll-bar controls end up */
1250 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1251 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1252 /* want for the normal scroll-arrow button. */
1253 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1255 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1257 if(uFlags & DFCS_INACTIVE)
1259 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1260 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1261 Polygon(dc, Line, 3);
1262 SelectObject(dc, hpsave);
1263 SelectObject(dc, hbsave);
1266 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1267 for(i = 0; i < 3; i++)
1273 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1274 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1275 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
1276 Polygon(dc, Line, 3);
1277 SelectObject(dc, hpsave);
1278 SelectObject(dc, hbsave);
1283 /************************************************************************
1284 * UITOOLS_DrawFrameMenu
1286 * Draw a menu control coming from DrawFrameControl()
1288 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1292 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1300 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1301 /* use anything else. I think I tried all sys-colors to change things */
1302 /* without luck. It seems as if this behavior is inherited from the */
1303 /* win31 DFC() implementation... (you remember, B/W menus). */
1305 FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1307 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1308 hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1310 switch(uFlags & 0xff)
1312 case DFCS_MENUARROW:
1313 i = 187*SmallDiam/750;
1314 Points[2].x = myr.left + 468*SmallDiam/750;
1315 Points[2].y = myr.top + 352*SmallDiam/750+1;
1316 Points[0].y = Points[2].y - i;
1317 Points[1].y = Points[2].y + i;
1318 Points[0].x = Points[1].x = Points[2].x - i;
1319 Polygon(dc, Points, 3);
1322 case DFCS_MENUBULLET:
1324 ye = myr.top + SmallDiam - SmallDiam/2;
1325 xc = myr.left + SmallDiam - SmallDiam/2;
1326 yc = myr.top + SmallDiam - SmallDiam/2;
1327 i = 234*SmallDiam/750;
1329 myr.left = xc - i+i/2;
1330 myr.right = xc + i/2;
1331 myr.top = yc - i+i/2;
1332 myr.bottom = yc + i/2;
1333 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1336 case DFCS_MENUCHECK:
1337 Points[0].x = myr.left + 253*SmallDiam/1000;
1338 Points[0].y = myr.top + 445*SmallDiam/1000;
1339 Points[1].x = myr.left + 409*SmallDiam/1000;
1340 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1341 Points[2].x = myr.left + 690*SmallDiam/1000;
1342 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1343 Points[3].x = Points[2].x;
1344 Points[3].y = Points[2].y + 3*SmallDiam/16;
1345 Points[4].x = Points[1].x;
1346 Points[4].y = Points[1].y + 3*SmallDiam/16;
1347 Points[5].x = Points[0].x;
1348 Points[5].y = Points[0].y + 3*SmallDiam/16;
1349 Polygon(dc, Points, 6);
1353 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1358 SelectObject(dc, hpsave);
1359 SelectObject(dc, hbsave);
1364 /**********************************************************************
1365 * DrawFrameControl (USER32.@)
1367 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1370 /* Win95 doesn't support drawing in other mapping modes */
1371 if(GetMapMode(hdc) != MM_TEXT)
1377 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1379 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1381 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1382 /*case DFC_POPUPMENU:
1383 FIXME("DFC_POPUPMENU: not implemented\n");
1386 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1388 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1394 /***********************************************************************
1395 * SetRect (USER32.@)
1397 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
1398 INT right, INT bottom )
1400 if (!rect) return FALSE;
1402 rect->right = right;
1404 rect->bottom = bottom;
1409 /***********************************************************************
1410 * SetRectEmpty (USER32.@)
1412 BOOL WINAPI SetRectEmpty( LPRECT rect )
1414 if (!rect) return FALSE;
1415 rect->left = rect->right = rect->top = rect->bottom = 0;
1420 /***********************************************************************
1421 * CopyRect (USER32.@)
1423 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
1425 if (!dest || !src) return FALSE;
1431 /***********************************************************************
1432 * IsRectEmpty (USER32.@)
1434 * Bug compat: Windows checks for 0 or negative width/height.
1436 BOOL WINAPI IsRectEmpty( const RECT *rect )
1438 if (!rect) return TRUE;
1439 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
1443 /***********************************************************************
1444 * PtInRect (USER32.@)
1446 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
1448 if (!rect) return FALSE;
1449 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
1450 (pt.y >= rect->top) && (pt.y < rect->bottom));
1454 /***********************************************************************
1455 * OffsetRect (USER32.@)
1457 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
1459 if (!rect) return FALSE;
1468 /***********************************************************************
1469 * InflateRect (USER32.@)
1471 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
1473 if (!rect) return FALSE;
1482 /***********************************************************************
1483 * IntersectRect (USER32.@)
1485 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1487 if (!dest || !src1 || !src2) return FALSE;
1488 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
1489 (src1->left >= src2->right) || (src2->left >= src1->right) ||
1490 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
1492 SetRectEmpty( dest );
1495 dest->left = max( src1->left, src2->left );
1496 dest->right = min( src1->right, src2->right );
1497 dest->top = max( src1->top, src2->top );
1498 dest->bottom = min( src1->bottom, src2->bottom );
1503 /***********************************************************************
1504 * UnionRect (USER32.@)
1506 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1508 if (!dest) return FALSE;
1509 if (IsRectEmpty(src1))
1511 if (IsRectEmpty(src2))
1513 SetRectEmpty( dest );
1520 if (IsRectEmpty(src2)) *dest = *src1;
1523 dest->left = min( src1->left, src2->left );
1524 dest->right = max( src1->right, src2->right );
1525 dest->top = min( src1->top, src2->top );
1526 dest->bottom = max( src1->bottom, src2->bottom );
1533 /***********************************************************************
1534 * EqualRect (USER32.@)
1536 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
1538 if (!rect1 || !rect2) return FALSE;
1539 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1540 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1544 /***********************************************************************
1545 * SubtractRect (USER32.@)
1547 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1551 if (!dest) return FALSE;
1552 if (IsRectEmpty( src1 ))
1554 SetRectEmpty( dest );
1558 if (IntersectRect( &tmp, src1, src2 ))
1560 if (EqualRect( &tmp, dest ))
1562 SetRectEmpty( dest );
1565 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1567 if (tmp.left == dest->left) dest->left = tmp.right;
1568 else if (tmp.right == dest->right) dest->right = tmp.left;
1570 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1572 if (tmp.top == dest->top) dest->top = tmp.bottom;
1573 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1580 /***********************************************************************
1581 * FillRect (USER32.@)
1583 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1587 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1589 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1590 PatBlt( hdc, rect->left, rect->top,
1591 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1592 SelectObject( hdc, prevBrush );
1597 /***********************************************************************
1598 * InvertRect (USER32.@)
1600 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1602 return PatBlt( hdc, rect->left, rect->top,
1603 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1607 /***********************************************************************
1608 * FrameRect (USER32.@)
1610 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1615 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1616 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1618 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1619 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1620 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1621 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1623 SelectObject( hdc, prevBrush );
1628 /***********************************************************************
1629 * DrawFocusRect (USER32.@)
1631 * FIXME: PatBlt(PATINVERT) with background brush.
1633 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1636 HPEN hOldPen, hNewPen;
1637 INT oldDrawMode, oldBkMode;
1639 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1640 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1641 hOldPen = SelectObject(hdc, hNewPen);
1642 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1643 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1645 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1647 SetBkMode(hdc, oldBkMode);
1648 SetROP2(hdc, oldDrawMode);
1649 SelectObject(hdc, hOldPen);
1650 DeleteObject(hNewPen);
1651 SelectObject(hdc, hOldBrush);
1657 /**********************************************************************
1658 * DrawAnimatedRects (USER32.@)
1660 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1662 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1667 /**********************************************************************
1668 * UITOOLS_DrawStateJam
1670 * Jams in the requested type in the dc
1672 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1673 LPRECT rc, UINT dtflags, BOOL unicode )
1678 INT cx = rc->right - rc->left;
1679 INT cy = rc->bottom - rc->top;
1684 case DST_PREFIXTEXT:
1686 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1688 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1691 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1694 memdc = CreateCompatibleDC(hdc);
1695 if(!memdc) return FALSE;
1696 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1702 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1703 SelectObject(memdc, hbmsave);
1710 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1712 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1713 bRet = func(hdc, lp, wp, cx, cy);
1714 /* Restore origin */
1715 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1723 /**********************************************************************
1724 * UITOOLS_DrawState()
1726 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1727 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1729 HBITMAP hbm, hbmsave;
1731 HBRUSH hbsave, hbrtmp = 0;
1734 UINT dtflags = DT_NOCLIP;
1736 UINT opcode = flags & 0xf;
1740 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1743 len = strlenW((LPWSTR)lp);
1745 len = strlen((LPSTR)lp);
1748 /* Find out what size the image has if not given by caller */
1752 CURSORICONINFO *ici;
1758 case DST_PREFIXTEXT:
1760 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1762 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1763 if(!retval) return FALSE;
1767 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1768 if(!ici) return FALSE;
1770 s.cy = ici->nHeight;
1771 GlobalUnlock16((HGLOBAL16)lp);
1775 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1780 case DST_COMPLEX: /* cx and cy must be set in this mode */
1793 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1794 dtflags |= DT_RIGHT;
1795 if(opcode == DST_TEXT)
1796 dtflags |= DT_NOPREFIX;
1798 /* For DSS_NORMAL we just jam in the image and return */
1799 if((flags & 0x7ff0) == DSS_NORMAL)
1801 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1804 /* For all other states we need to convert the image to B/W in a local bitmap */
1805 /* before it is displayed */
1806 fg = SetTextColor(hdc, RGB(0, 0, 0));
1807 bg = SetBkColor(hdc, RGB(255, 255, 255));
1808 hbm = NULL; hbmsave = NULL;
1809 memdc = NULL; hbsave = NULL;
1810 retval = FALSE; /* assume failure */
1812 /* From here on we must use "goto cleanup" when something goes wrong */
1813 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1814 if(!hbm) goto cleanup;
1815 memdc = CreateCompatibleDC(hdc);
1816 if(!memdc) goto cleanup;
1817 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1818 if(!hbmsave) goto cleanup;
1819 rc.left = rc.top = 0;
1822 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1823 SetBkColor(memdc, RGB(255, 255, 255));
1824 SetTextColor(memdc, RGB(0, 0, 0));
1825 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1827 /* DST_COMPLEX may draw text as well,
1828 * so we must be sure that correct font is selected
1830 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1831 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1832 if(hfsave) SelectObject(memdc, hfsave);
1833 if(!tmp) goto cleanup;
1835 /* This state cause the image to be dithered */
1836 if(flags & DSS_UNION)
1838 hbsave = (HBRUSH)SelectObject(memdc, SYSCOLOR_55AABrush);
1839 if(!hbsave) goto cleanup;
1840 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1841 SelectObject(memdc, hbsave);
1842 if(!tmp) goto cleanup;
1845 if (flags & DSS_DISABLED)
1846 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1847 else if (flags & DSS_DEFAULT)
1848 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1850 /* Draw light or dark shadow */
1851 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1853 if(!hbrtmp) goto cleanup;
1854 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1855 if(!hbsave) goto cleanup;
1856 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1857 SelectObject(hdc, hbsave);
1858 DeleteObject(hbrtmp);
1862 if (flags & DSS_DISABLED)
1864 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1865 if(!hbrtmp) goto cleanup;
1869 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1872 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1874 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1876 retval = TRUE; /* We succeeded */
1879 SetTextColor(hdc, fg);
1880 SetBkColor(hdc, bg);
1882 if(hbsave) SelectObject(hdc, hbsave);
1883 if(hbmsave) SelectObject(memdc, hbmsave);
1884 if(hbrtmp) DeleteObject(hbrtmp);
1885 if(hbm) DeleteObject(hbm);
1886 if(memdc) DeleteDC(memdc);
1891 /**********************************************************************
1892 * DrawStateA (USER32.@)
1894 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1895 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1896 INT x, INT y, INT cx, INT cy, UINT flags)
1898 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1901 /**********************************************************************
1902 * DrawStateW (USER32.@)
1904 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1905 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1906 INT x, INT y, INT cx, INT cy, UINT flags)
1908 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);