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 static const WORD wPattern55AA[] =
37 0x5555, 0xaaaa, 0x5555, 0xaaaa,
38 0x5555, 0xaaaa, 0x5555, 0xaaaa
41 static HBRUSH hPattern55AABrush;
42 static HBITMAP hPattern55AABitmap;
44 /* These tables are used in:
45 * UITOOLS_DrawDiagEdge()
46 * UITOOLS_DrawRectEdge()
48 static const signed char LTInnerNormal[] = {
50 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
51 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
55 static const signed char LTOuterNormal[] = {
56 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
57 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
58 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
59 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
62 static const signed char RBInnerNormal[] = {
64 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
65 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
69 static const signed char RBOuterNormal[] = {
70 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
71 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
72 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
73 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
76 static const signed char LTInnerSoft[] = {
78 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
79 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
83 static const signed char LTOuterSoft[] = {
84 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
85 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
86 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
87 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
90 #define RBInnerSoft RBInnerNormal /* These are the same */
91 #define RBOuterSoft RBOuterNormal
93 static const signed char LTRBOuterMono[] = {
94 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
95 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
96 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
97 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
100 static const signed char LTRBInnerMono[] = {
102 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
103 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
104 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
107 static const signed char LTRBOuterFlat[] = {
108 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
109 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
110 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
111 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
114 static const signed char LTRBInnerFlat[] = {
116 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
117 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
118 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
122 #define COLOR_MAX COLOR_MENUBAR
125 /*********************************************************************
126 * UITOOLS_GetPattern55AABrush
128 HBRUSH UITOOLS_GetPattern55AABrush(void)
130 if (!hPattern55AABrush)
132 hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
133 hPattern55AABrush = CreatePatternBrush( hPattern55AABitmap );
135 return hPattern55AABrush;
139 /***********************************************************************
140 * UITOOLS_DrawDiagEdge
142 * Same as DrawEdge invoked with BF_DIAGONAL
144 * 03-Dec-1997: Changed by Bertho Stultiens
146 * See also comments with UITOOLS_DrawRectEdge()
148 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
149 UINT uType, UINT uFlags)
152 signed char InnerI, OuterI;
153 HPEN InnerPen, OuterPen;
158 int Width = rc->right - rc->left;
159 int Height= rc->bottom - rc->top;
160 int SmallDiam = Width > Height ? Height : Width;
161 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
162 || (uType & BDR_OUTER) == BDR_OUTER)
163 && !(uFlags & (BF_FLAT|BF_MONO)) );
164 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
165 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
168 OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
169 SavePen = (HPEN)SelectObject(hdc, InnerPen);
170 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
172 /* Determine the colors of the edges */
175 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
176 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
178 else if(uFlags & BF_FLAT)
180 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
181 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
183 else if(uFlags & BF_SOFT)
185 if(uFlags & BF_BOTTOM)
187 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
188 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
192 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
193 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
198 if(uFlags & BF_BOTTOM)
200 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
201 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
205 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
206 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
210 if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
211 if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
213 MoveToEx(hdc, 0, 0, &SavePoint);
215 /* Don't ask me why, but this is what is visible... */
216 /* This must be possible to do much simpler, but I fail to */
217 /* see the logic in the MS implementation (sigh...). */
218 /* So, this might look a bit brute force here (and it is), but */
219 /* it gets the job done;) */
221 switch(uFlags & BF_RECT)
227 /* Left bottom endpoint */
229 spx = epx + SmallDiam;
231 spy = epy - SmallDiam;
236 /* Left top endpoint */
238 spx = epx + SmallDiam;
240 spy = epy + SmallDiam;
246 case BF_RIGHT|BF_LEFT:
247 case BF_RIGHT|BF_LEFT|BF_TOP:
248 case BF_BOTTOM|BF_TOP:
249 case BF_BOTTOM|BF_TOP|BF_LEFT:
250 case BF_BOTTOMRIGHT|BF_LEFT:
251 case BF_BOTTOMRIGHT|BF_TOP:
253 /* Right top endpoint */
255 epx = spx + SmallDiam;
257 epy = spy - SmallDiam;
261 MoveToEx(hdc, spx, spy, NULL);
262 SelectObject(hdc, OuterPen);
263 LineTo(hdc, epx, epy);
265 SelectObject(hdc, InnerPen);
267 switch(uFlags & (BF_RECT|BF_DIAGONAL))
269 case BF_DIAGONAL_ENDBOTTOMLEFT:
270 case (BF_DIAGONAL|BF_BOTTOM):
272 case (BF_DIAGONAL|BF_LEFT):
273 MoveToEx(hdc, spx-1, spy, NULL);
274 LineTo(hdc, epx, epy-1);
275 Points[0].x = spx-add;
277 Points[1].x = rc->left;
278 Points[1].y = rc->top;
280 Points[2].y = epy-1-add;
281 Points[3] = Points[2];
284 case BF_DIAGONAL_ENDBOTTOMRIGHT:
285 MoveToEx(hdc, spx-1, spy, NULL);
286 LineTo(hdc, epx, epy+1);
287 Points[0].x = spx-add;
289 Points[1].x = rc->left;
290 Points[1].y = rc->bottom-1;
292 Points[2].y = epy+1+add;
293 Points[3] = Points[2];
296 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
297 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
298 case BF_DIAGONAL_ENDTOPRIGHT:
299 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
300 MoveToEx(hdc, spx+1, spy, NULL);
301 LineTo(hdc, epx, epy+1);
303 Points[0].y = epy+1+add;
304 Points[1].x = rc->right-1;
305 Points[1].y = rc->top+add;
306 Points[2].x = rc->right-1;
307 Points[2].y = rc->bottom-1;
308 Points[3].x = spx+add;
312 case BF_DIAGONAL_ENDTOPLEFT:
313 MoveToEx(hdc, spx, spy-1, NULL);
314 LineTo(hdc, epx+1, epy);
315 Points[0].x = epx+1+add;
317 Points[1].x = rc->right-1;
318 Points[1].y = rc->top;
319 Points[2].x = rc->right-1;
320 Points[2].y = rc->bottom-1-add;
322 Points[3].y = spy-add;
325 case (BF_DIAGONAL|BF_TOP):
326 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
327 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
328 MoveToEx(hdc, spx+1, spy-1, NULL);
329 LineTo(hdc, epx, epy);
332 Points[1].x = rc->right-1;
333 Points[1].y = rc->top;
334 Points[2].x = rc->right-1;
335 Points[2].y = rc->bottom-1-add;
336 Points[3].x = spx+add;
337 Points[3].y = spy-add;
340 case (BF_DIAGONAL|BF_RIGHT):
341 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
342 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
343 MoveToEx(hdc, spx, spy, NULL);
344 LineTo(hdc, epx-1, epy+1);
347 Points[1].x = rc->left;
348 Points[1].y = rc->top+add;
349 Points[2].x = epx-1-add;
350 Points[2].y = epy+1+add;
351 Points[3] = Points[2];
355 /* Fill the interior if asked */
356 if((uFlags & BF_MIDDLE) && retval)
359 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
362 HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
364 hbsave = (HBRUSH)SelectObject(hdc, hb);
365 hpsave = (HPEN)SelectObject(hdc, hp);
366 Polygon(hdc, Points, 4);
367 SelectObject(hdc, hbsave);
368 SelectObject(hdc, hpsave);
371 /* Adjust rectangle if asked */
372 if(uFlags & BF_ADJUST)
374 if(uFlags & BF_LEFT) rc->left += add;
375 if(uFlags & BF_RIGHT) rc->right -= add;
376 if(uFlags & BF_TOP) rc->top += add;
377 if(uFlags & BF_BOTTOM) rc->bottom -= add;
381 SelectObject(hdc, SavePen);
382 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
387 /***********************************************************************
388 * UITOOLS_DrawRectEdge
390 * Same as DrawEdge invoked without BF_DIAGONAL
392 * 23-Nov-1997: Changed by Bertho Stultiens
394 * Well, I started testing this and found out that there are a few things
395 * that weren't quite as win95. The following rewrite should reproduce
396 * win95 results completely.
397 * The colorselection is table-driven to avoid awfull if-statements.
398 * The table below show the color settings.
400 * Pen selection table for uFlags = 0
402 * uType | LTI | LTO | RBI | RBO
403 * ------+-------+-------+-------+-------
404 * 0000 | x | x | x | x
405 * 0001 | x | 22 | x | 21
406 * 0010 | x | 16 | x | 20
407 * 0011 | x | x | x | x
408 * ------+-------+-------+-------+-------
409 * 0100 | x | 20 | x | 16
410 * 0101 | 20 | 22 | 16 | 21
411 * 0110 | 20 | 16 | 16 | 20
412 * 0111 | x | x | x | x
413 * ------+-------+-------+-------+-------
414 * 1000 | x | 21 | x | 22
415 * 1001 | 21 | 22 | 22 | 21
416 * 1010 | 21 | 16 | 22 | 20
417 * 1011 | x | x | x | x
418 * ------+-------+-------+-------+-------
419 * 1100 | x | x | x | x
420 * 1101 | x | x (22)| x | x (21)
421 * 1110 | x | x (16)| x | x (20)
422 * 1111 | x | x | x | x
424 * Pen selection table for uFlags = BF_SOFT
426 * uType | LTI | LTO | RBI | RBO
427 * ------+-------+-------+-------+-------
428 * 0000 | x | x | x | x
429 * 0001 | x | 20 | x | 21
430 * 0010 | x | 21 | x | 20
431 * 0011 | x | x | x | x
432 * ------+-------+-------+-------+-------
433 * 0100 | x | 22 | x | 16
434 * 0101 | 22 | 20 | 16 | 21
435 * 0110 | 22 | 21 | 16 | 20
436 * 0111 | x | x | x | x
437 * ------+-------+-------+-------+-------
438 * 1000 | x | 16 | x | 22
439 * 1001 | 16 | 20 | 22 | 21
440 * 1010 | 16 | 21 | 22 | 20
441 * 1011 | x | x | x | x
442 * ------+-------+-------+-------+-------
443 * 1100 | x | x | x | x
444 * 1101 | x | x (20)| x | x (21)
445 * 1110 | x | x (21)| x | x (20)
446 * 1111 | x | x | x | x
448 * x = don't care; (n) = is what win95 actually uses
449 * LTI = left Top Inner line
450 * LTO = left Top Outer line
451 * RBI = Right Bottom Inner line
452 * RBO = Right Bottom Outer line
454 * 16 = COLOR_BTNSHADOW
455 * 20 = COLOR_BTNHIGHLIGHT
456 * 21 = COLOR_3DDKSHADOW
461 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
462 UINT uType, UINT uFlags)
464 signed char LTInnerI, LTOuterI;
465 signed char RBInnerI, RBOuterI;
466 HPEN LTInnerPen, LTOuterPen;
467 HPEN RBInnerPen, RBOuterPen;
468 RECT InnerRect = *rc;
475 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
476 || (uType & BDR_OUTER) == BDR_OUTER)
477 && !(uFlags & (BF_FLAT|BF_MONO)) );
480 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
481 SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
483 /* Determine the colors of the edges */
486 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
487 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
489 else if(uFlags & BF_FLAT)
491 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
492 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
494 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
496 else if(uFlags & BF_SOFT)
498 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
499 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
500 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
501 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
505 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
506 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
507 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
508 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
511 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
512 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
513 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
514 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
516 if(LTInnerI != -1) LTInnerPen = SYSCOLOR_GetPen(LTInnerI);
517 if(LTOuterI != -1) LTOuterPen = SYSCOLOR_GetPen(LTOuterI);
518 if(RBInnerI != -1) RBInnerPen = SYSCOLOR_GetPen(RBInnerI);
519 if(RBOuterI != -1) RBOuterPen = SYSCOLOR_GetPen(RBOuterI);
521 MoveToEx(hdc, 0, 0, &SavePoint);
523 /* Draw the outer edge */
524 SelectObject(hdc, LTOuterPen);
527 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
528 LineTo(hdc, InnerRect.right, InnerRect.top);
532 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
533 LineTo(hdc, InnerRect.left, InnerRect.bottom);
535 SelectObject(hdc, RBOuterPen);
536 if(uFlags & BF_BOTTOM)
538 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
539 LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1);
541 if(uFlags & BF_RIGHT)
543 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
544 LineTo(hdc, InnerRect.right-1, InnerRect.top-1);
547 /* Draw the inner edge */
548 SelectObject(hdc, LTInnerPen);
551 MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
552 LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
556 MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
557 LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
559 SelectObject(hdc, RBInnerPen);
560 if(uFlags & BF_BOTTOM)
562 MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
563 LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
565 if(uFlags & BF_RIGHT)
567 MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
568 LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
571 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
573 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
574 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
576 if(uFlags & BF_LEFT) InnerRect.left += add;
577 if(uFlags & BF_RIGHT) InnerRect.right -= add;
578 if(uFlags & BF_TOP) InnerRect.top += add;
579 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
581 if((uFlags & BF_MIDDLE) && retval)
583 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
584 COLOR_WINDOW : COLOR_BTNFACE));
587 if(uFlags & BF_ADJUST)
592 SelectObject(hdc, SavePen);
593 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
598 /**********************************************************************
599 * DrawEdge (USER32.@)
601 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
603 TRACE("%p %ld,%ld-%ld,%ld %04x %04x\n",
604 hdc, rc->left, rc->top, rc->right, rc->bottom, edge, flags );
606 if(flags & BF_DIAGONAL)
607 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
609 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags);
613 /************************************************************************
614 * UITOOLS_MakeSquareRect
616 * Utility to create a square rectangle and returning the width
618 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
620 int Width = src->right - src->left;
621 int Height = src->bottom - src->top;
622 int SmallDiam = Width > Height ? Height : Width;
626 /* Make it a square box */
627 if(Width < Height) /* SmallDiam == Width */
629 dst->top += (Height-Width)/2;
630 dst->bottom = dst->top + SmallDiam;
632 else if(Width > Height) /* SmallDiam == Height */
634 dst->left += (Width-Height)/2;
635 dst->right = dst->left + SmallDiam;
641 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
643 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
648 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
649 bg = SetBkColor(dc, RGB(255, 255, 255));
650 hbsave = SelectObject(dc, UITOOLS_GetPattern55AABrush());
651 PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
652 SelectObject(dc, hbsave);
657 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
661 /************************************************************************
662 * UITOOLS_DFC_ButtonPush
664 * Draw a push button coming from DrawFrameControl()
666 * Does a pretty good job in emulating MS behavior. Some quirks are
667 * however there because MS uses a TrueType font (Marlett) to draw
670 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
675 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
680 if(uFlags & DFCS_CHECKED)
682 if(uFlags & DFCS_MONO)
683 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
685 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
687 if (!(uFlags & DFCS_TRANSPARENT))
688 UITOOLS_DrawCheckedRect( dc, &myr );
692 if(uFlags & DFCS_MONO)
694 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
695 if (!(uFlags & DFCS_TRANSPARENT))
696 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
700 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) | ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT | BF_SOFT);
704 /* Adjust rectangle if asked */
705 if(uFlags & DFCS_ADJUSTRECT)
717 /************************************************************************
718 * UITOOLS_DFC_ButtonChcek
720 * Draw a check/3state button coming from DrawFrameControl()
722 * Does a pretty good job in emulating MS behavior. Some quirks are
723 * however there because MS uses a TrueType font (Marlett) to draw
727 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
730 UINT flags = BF_RECT | BF_ADJUST;
732 UITOOLS_MakeSquareRect(r, &myr);
734 if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
735 else if(uFlags & DFCS_MONO) flags |= BF_MONO;
737 UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags );
739 if (!(uFlags & DFCS_TRANSPARENT))
741 if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
742 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
743 else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
744 UITOOLS_DrawCheckedRect( dc, &myr );
746 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
749 if(uFlags & DFCS_CHECKED)
752 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
753 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
755 /* draw 7 bars, with h=3w to form the check */
757 bar.top = myr.top + 2;
758 for (k = 0; k < 7; k++) {
759 bar.left = bar.left + 1;
760 bar.top = (k < 3) ? bar.top + 1 : bar.top - 1;
761 bar.bottom = bar.top + 3;
762 bar.right = bar.left + 1;
763 FillRect(dc, &bar, GetSysColorBrush(i));
770 /************************************************************************
771 * UITOOLS_DFC_ButtonRadio
773 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
775 * Does a pretty good job in emulating MS behavior. Some quirks are
776 * however there because MS uses a TrueType font (Marlett) to draw
779 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
783 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
784 int BorderShrink = SmallDiam / 16;
789 if(BorderShrink < 1) BorderShrink = 1;
791 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
792 FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
794 xc = myr.left + SmallDiam - SmallDiam/2;
795 yc = myr.top + SmallDiam - SmallDiam/2;
797 /* Define bounding box */
799 myr.left = xc - i+i/2;
800 myr.right = xc + i/2;
801 myr.top = yc - i+i/2;
802 myr.bottom = yc + i/2;
804 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
806 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
807 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
808 SelectObject(dc, hbsave);
812 if(uFlags & (DFCS_FLAT|DFCS_MONO))
814 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
815 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
816 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
817 SelectObject(dc, hbsave);
818 SelectObject(dc, hpsave);
822 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
823 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
824 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
826 SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNSHADOW));
827 SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
828 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
830 myr.left += BorderShrink;
831 myr.right -= BorderShrink;
832 myr.top += BorderShrink;
833 myr.bottom -= BorderShrink;
835 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
836 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
837 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
839 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
840 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
841 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
842 SelectObject(dc, hbsave);
843 SelectObject(dc, hpsave);
847 myr.left = xc - i+i/2;
848 myr.right = xc + i/2;
849 myr.top = yc - i+i/2;
850 myr.bottom = yc + i/2;
851 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
852 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
853 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
854 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
855 SelectObject(dc, hbsave);
856 SelectObject(dc, hpsave);
859 if(uFlags & DFCS_CHECKED)
863 myr.left = xc - i+i/2;
864 myr.right = xc + i/2;
865 myr.top = yc - i+i/2;
866 myr.bottom = yc + i/2;
868 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
869 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
870 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
871 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
872 SelectObject(dc, hpsave);
873 SelectObject(dc, hbsave);
876 /* FIXME: M$ has a polygon in the center at relative points: */
877 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
881 /* when the button is unchecked. The reason for it is unknown. The */
882 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
883 /* least 3 times (it looks like a clip-region when you see it happen). */
884 /* I do not really see a reason why this should be implemented. If you */
885 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
891 /***********************************************************************
892 * UITOOLS_DrawFrameButton
894 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
896 switch(uState & 0xff)
898 case DFCS_BUTTONPUSH:
899 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
901 case DFCS_BUTTONCHECK:
902 case DFCS_BUTTON3STATE:
903 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
905 case DFCS_BUTTONRADIOIMAGE:
906 case DFCS_BUTTONRADIOMASK:
907 case DFCS_BUTTONRADIO:
908 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
911 WARN("Invalid button state=0x%04x\n", uState);
917 /***********************************************************************
918 * UITOOLS_DrawFrameCaption
920 * Draw caption buttons (win95), coming from DrawFrameControl()
923 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
930 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
935 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
936 int xc = (myr.left+myr.right)/2;
937 int yc = (myr.top+myr.bottom)/2;
945 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
947 switch(uFlags & 0xff)
949 case DFCS_CAPTIONCLOSE:
951 /* The "X" is made by drawing a series of lines.
952 * The number of lines drawn depends on the size
953 * of the bounding rect. e.g. For a 6x5 inside rect,
954 * two lines are drawn from top-left to bottom-right,
955 * and two lines from top-right to bottom-left.
957 * 0 1 2 3 4 5 0 1 2 3 4 5
963 * Drawing one line for every 6 pixels in width
964 * seems to provide the best proportions.
968 INT width = myr.right - myr.left - 5;
969 INT height = myr.bottom - myr.top - 6;
970 INT numLines = (width / 6) + 1;
972 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
974 start.x = myr.left + 2;
975 start.y = myr.top + 2;
982 if (uFlags & DFCS_PUSHED)
988 /* now use the width of each line */
989 width -= numLines - 1;
991 for (i = 0; i < numLines; i++)
993 MoveToEx(dc, start.x + i, start.y, &oldPos);
994 LineTo(dc, start.x + i + width, start.y + height);
996 MoveToEx(dc, start.x + i, start.y + height - 1, &oldPos);
997 LineTo(dc, start.x + i + width, start.y - 1);
1000 SelectObject(dc, hpsave);
1004 case DFCS_CAPTIONHELP:
1005 /* This one breaks the flow */
1006 /* FIXME: We need the Marlett font in order to get this right. */
1008 hf = CreateFontA(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
1009 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
1010 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
1011 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
1012 bksave = SetBkMode(dc, TRANSPARENT);
1013 clrsave = GetTextColor(dc);
1014 hfsave = (HFONT)SelectObject(dc, hf);
1015 GetTextExtentPoint32A(dc, str, 1, &size);
1017 if(uFlags & DFCS_INACTIVE)
1019 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
1020 TextOutA(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
1022 SetTextColor(dc, GetSysColor(colorIdx));
1023 TextOutA(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1025 SelectObject(dc, hfsave);
1026 SetTextColor(dc, clrsave);
1027 SetBkMode(dc, bksave);
1028 SetTextAlign(dc, alignsave);
1032 case DFCS_CAPTIONMIN:
1033 Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2;
1034 Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1035 Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1;
1036 Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750;
1041 case DFCS_CAPTIONMAX:
1042 edge = 47*SmallDiam/750;
1043 Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3;
1044 Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1;
1045 Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1046 Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750;
1047 Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1048 Line1[3].x = Line1[4].x = Line1[1].x - edge;
1050 Line2[0].x = Line2[5].x = Line1[0].x;
1051 Line2[3].x = Line2[4].x = Line1[1].x;
1052 Line2[1].x = Line2[2].x = Line1[0].x + edge;
1053 Line2[0].y = Line2[1].y = Line1[0].y;
1054 Line2[4].y = Line2[5].y = Line1[2].y;
1055 Line2[2].y = Line2[3].y = Line1[2].y - edge;
1060 case DFCS_CAPTIONRESTORE:
1061 /* FIXME: this one looks bad at small sizes < 15x15 :( */
1062 edge = 47*SmallDiam/750;
1063 move = 420*SmallDiam/750;
1064 Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1065 Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1;
1066 Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1067 Line1[7].x = Line1[8].x = Line1[0].x + edge;
1068 Line1[1].x = Line1[2].x = Line1[0].x + move;
1069 Line1[5].x = Line1[6].x = Line1[1].x - edge;
1070 Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1071 Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1072 Line1[4].y = Line1[5].y = Line1[2].y - edge;
1073 Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1075 Line2[1].x = Line2[2].x = Line1[3].x;
1076 Line2[7].x = Line2[8].x = Line2[1].x - edge;
1077 Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1078 Line2[5].x = Line2[6].x = Line2[0].x + edge;
1079 Line2[0].y = Line2[1].y = Line1[9].y;
1080 Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1081 Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1082 Line2[6].y = Line2[7].y = Line2[2].y - edge;
1088 WARN("Invalid caption; flags=0x%04x\n", uFlags);
1092 /* Here the drawing takes place */
1093 if(uFlags & DFCS_INACTIVE)
1095 /* If we have an inactive button, then you see a shadow */
1096 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1097 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1098 Polygon(dc, Line1, Line1N);
1100 Polygon(dc, Line2, Line2N);
1101 SelectObject(dc, hpsave);
1102 SelectObject(dc, hbsave);
1105 /* Correct for the shadow shift */
1106 if (!(uFlags & DFCS_PUSHED))
1108 for(i = 0; i < Line1N; i++)
1113 for(i = 0; i < Line2N; i++)
1120 /* Make the final picture */
1121 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(colorIdx));
1122 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
1124 Polygon(dc, Line1, Line1N);
1126 Polygon(dc, Line2, Line2N);
1127 SelectObject(dc, hpsave);
1128 SelectObject(dc, hbsave);
1134 /************************************************************************
1135 * UITOOLS_DrawFrameScroll
1137 * Draw a scroll-bar control coming from DrawFrameControl()
1139 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
1143 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1145 HBRUSH hbsave, hb, hb2;
1146 HPEN hpsave, hp, hp2;
1147 int tri = 290*SmallDiam/1000 - 1;
1151 * This fixes a problem with really tiny "scroll" buttons. In particular
1152 * with the updown control.
1153 * Making sure that the arrow is as least 3 pixels wide (or high).
1158 switch(uFlags & 0xff)
1160 case DFCS_SCROLLCOMBOBOX:
1161 case DFCS_SCROLLDOWN:
1162 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1163 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
1164 Line[0].x = Line[2].x - tri;
1165 Line[1].x = Line[2].x + tri;
1166 Line[0].y = Line[1].y = Line[2].y - tri;
1170 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1171 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
1172 Line[0].x = Line[2].x - tri;
1173 Line[1].x = Line[2].x + tri;
1174 Line[0].y = Line[1].y = Line[2].y + tri;
1177 case DFCS_SCROLLLEFT:
1178 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1179 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1180 Line[0].y = Line[2].y - tri;
1181 Line[1].y = Line[2].y + tri;
1182 Line[0].x = Line[1].x = Line[2].x + tri;
1185 case DFCS_SCROLLRIGHT:
1186 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1187 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1188 Line[0].y = Line[2].y - tri;
1189 Line[1].y = Line[2].y + tri;
1190 Line[0].x = Line[1].x = Line[2].x - tri;
1193 case DFCS_SCROLLSIZEGRIP:
1194 /* This one breaks the flow... */
1195 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1196 hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1197 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1198 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1200 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1201 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1205 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1206 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1207 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1208 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1210 Line[0].x = Line[1].x = r->right-1;
1211 Line[2].y = Line[3].y = r->bottom-1;
1212 d46 = 46*SmallDiam/750;
1213 d93 = 93*SmallDiam/750;
1215 i = 586*SmallDiam/750;
1216 Line[0].y = r->bottom - i - 1;
1217 Line[3].x = r->right - i - 1;
1218 Line[1].y = Line[0].y + d46;
1219 Line[2].x = Line[3].x + d46;
1220 SelectObject(dc, hb);
1221 SelectObject(dc, hp);
1222 Polygon(dc, Line, 4);
1224 Line[1].y++; Line[2].x++;
1225 Line[0].y = Line[1].y + d93;
1226 Line[3].x = Line[2].x + d93;
1227 SelectObject(dc, hb2);
1228 SelectObject(dc, hp2);
1229 Polygon(dc, Line, 4);
1231 i = 398*SmallDiam/750;
1232 Line[0].y = r->bottom - i - 1;
1233 Line[3].x = r->right - i - 1;
1234 Line[1].y = Line[0].y + d46;
1235 Line[2].x = Line[3].x + d46;
1236 SelectObject(dc, hb);
1237 SelectObject(dc, hp);
1238 Polygon(dc, Line, 4);
1240 Line[1].y++; Line[2].x++;
1241 Line[0].y = Line[1].y + d93;
1242 Line[3].x = Line[2].x + d93;
1243 SelectObject(dc, hb2);
1244 SelectObject(dc, hp2);
1245 Polygon(dc, Line, 4);
1247 i = 210*SmallDiam/750;
1248 Line[0].y = r->bottom - i - 1;
1249 Line[3].x = r->right - i - 1;
1250 Line[1].y = Line[0].y + d46;
1251 Line[2].x = Line[3].x + d46;
1252 SelectObject(dc, hb);
1253 SelectObject(dc, hp);
1254 Polygon(dc, Line, 4);
1256 Line[1].y++; Line[2].x++;
1257 Line[0].y = Line[1].y + d93;
1258 Line[3].x = Line[2].x + d93;
1259 SelectObject(dc, hb2);
1260 SelectObject(dc, hp2);
1261 Polygon(dc, Line, 4);
1263 SelectObject(dc, hpsave);
1264 SelectObject(dc, hbsave);
1268 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1272 /* Here do the real scroll-bar controls end up */
1273 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1274 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1275 /* want for the normal scroll-arrow button. */
1276 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1278 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1280 if(uFlags & DFCS_INACTIVE)
1282 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1283 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1284 Polygon(dc, Line, 3);
1285 SelectObject(dc, hpsave);
1286 SelectObject(dc, hbsave);
1289 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1290 for(i = 0; i < 3; i++)
1296 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1297 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1298 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
1299 Polygon(dc, Line, 3);
1300 SelectObject(dc, hpsave);
1301 SelectObject(dc, hbsave);
1306 /************************************************************************
1307 * UITOOLS_DrawFrameMenu
1309 * Draw a menu control coming from DrawFrameControl()
1311 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1315 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1323 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1324 /* use anything else. I think I tried all sys-colors to change things */
1325 /* without luck. It seems as if this behavior is inherited from the */
1326 /* win31 DFC() implementation... (you remember, B/W menus). */
1328 FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1330 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1331 hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1333 switch(uFlags & 0xff)
1335 case DFCS_MENUARROW:
1336 i = 187*SmallDiam/750;
1337 Points[2].x = myr.left + 468*SmallDiam/750;
1338 Points[2].y = myr.top + 352*SmallDiam/750+1;
1339 Points[0].y = Points[2].y - i;
1340 Points[1].y = Points[2].y + i;
1341 Points[0].x = Points[1].x = Points[2].x - i;
1342 Polygon(dc, Points, 3);
1345 case DFCS_MENUBULLET:
1347 ye = myr.top + SmallDiam - SmallDiam/2;
1348 xc = myr.left + SmallDiam - SmallDiam/2;
1349 yc = myr.top + SmallDiam - SmallDiam/2;
1350 i = 234*SmallDiam/750;
1352 myr.left = xc - i+i/2;
1353 myr.right = xc + i/2;
1354 myr.top = yc - i+i/2;
1355 myr.bottom = yc + i/2;
1356 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1359 case DFCS_MENUCHECK:
1360 Points[0].x = myr.left + 253*SmallDiam/1000;
1361 Points[0].y = myr.top + 445*SmallDiam/1000;
1362 Points[1].x = myr.left + 409*SmallDiam/1000;
1363 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1364 Points[2].x = myr.left + 690*SmallDiam/1000;
1365 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1366 Points[3].x = Points[2].x;
1367 Points[3].y = Points[2].y + 3*SmallDiam/16;
1368 Points[4].x = Points[1].x;
1369 Points[4].y = Points[1].y + 3*SmallDiam/16;
1370 Points[5].x = Points[0].x;
1371 Points[5].y = Points[0].y + 3*SmallDiam/16;
1372 Polygon(dc, Points, 6);
1376 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1381 SelectObject(dc, hpsave);
1382 SelectObject(dc, hbsave);
1387 /**********************************************************************
1388 * DrawFrameControl (USER32.@)
1390 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1393 /* Win95 doesn't support drawing in other mapping modes */
1394 if(GetMapMode(hdc) != MM_TEXT)
1400 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1402 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1404 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1405 /*case DFC_POPUPMENU:
1406 FIXME("DFC_POPUPMENU: not implemented\n");
1409 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1411 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1417 /***********************************************************************
1418 * FillRect (USER32.@)
1420 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1424 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1426 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1427 PatBlt( hdc, rect->left, rect->top,
1428 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1429 SelectObject( hdc, prevBrush );
1434 /***********************************************************************
1435 * InvertRect (USER32.@)
1437 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1439 return PatBlt( hdc, rect->left, rect->top,
1440 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1444 /***********************************************************************
1445 * FrameRect (USER32.@)
1447 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1452 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1453 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1455 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1456 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1457 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1458 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1460 SelectObject( hdc, prevBrush );
1465 /***********************************************************************
1466 * DrawFocusRect (USER32.@)
1468 * FIXME: PatBlt(PATINVERT) with background brush.
1470 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1473 HPEN hOldPen, hNewPen;
1474 INT oldDrawMode, oldBkMode;
1476 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1477 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1478 hOldPen = SelectObject(hdc, hNewPen);
1479 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1480 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1482 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1484 SetBkMode(hdc, oldBkMode);
1485 SetROP2(hdc, oldDrawMode);
1486 SelectObject(hdc, hOldPen);
1487 DeleteObject(hNewPen);
1488 SelectObject(hdc, hOldBrush);
1494 /**********************************************************************
1495 * DrawAnimatedRects (USER32.@)
1497 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1499 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1504 /**********************************************************************
1505 * UITOOLS_DrawStateJam
1507 * Jams in the requested type in the dc
1509 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1510 LPRECT rc, UINT dtflags, BOOL unicode )
1515 INT cx = rc->right - rc->left;
1516 INT cy = rc->bottom - rc->top;
1521 case DST_PREFIXTEXT:
1523 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1525 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1528 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1531 memdc = CreateCompatibleDC(hdc);
1532 if(!memdc) return FALSE;
1533 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1539 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1540 SelectObject(memdc, hbmsave);
1547 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1549 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1550 bRet = func(hdc, lp, wp, cx, cy);
1551 /* Restore origin */
1552 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1560 /**********************************************************************
1561 * UITOOLS_DrawState()
1563 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1564 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1566 HBITMAP hbm, hbmsave;
1568 HBRUSH hbsave, hbrtmp = 0;
1571 UINT dtflags = DT_NOCLIP;
1573 UINT opcode = flags & 0xf;
1577 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1580 len = strlenW((LPWSTR)lp);
1582 len = strlen((LPSTR)lp);
1585 /* Find out what size the image has if not given by caller */
1589 CURSORICONINFO *ici;
1595 case DST_PREFIXTEXT:
1597 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1599 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1600 if(!retval) return FALSE;
1604 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1605 if(!ici) return FALSE;
1607 s.cy = ici->nHeight;
1608 GlobalUnlock16((HGLOBAL16)lp);
1612 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1617 case DST_COMPLEX: /* cx and cy must be set in this mode */
1630 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1631 dtflags |= DT_RIGHT;
1632 if(opcode == DST_TEXT)
1633 dtflags |= DT_NOPREFIX;
1635 /* For DSS_NORMAL we just jam in the image and return */
1636 if((flags & 0x7ff0) == DSS_NORMAL)
1638 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1641 /* For all other states we need to convert the image to B/W in a local bitmap */
1642 /* before it is displayed */
1643 fg = SetTextColor(hdc, RGB(0, 0, 0));
1644 bg = SetBkColor(hdc, RGB(255, 255, 255));
1645 hbm = NULL; hbmsave = NULL;
1646 memdc = NULL; hbsave = NULL;
1647 retval = FALSE; /* assume failure */
1649 /* From here on we must use "goto cleanup" when something goes wrong */
1650 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1651 if(!hbm) goto cleanup;
1652 memdc = CreateCompatibleDC(hdc);
1653 if(!memdc) goto cleanup;
1654 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1655 if(!hbmsave) goto cleanup;
1656 rc.left = rc.top = 0;
1659 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1660 SetBkColor(memdc, RGB(255, 255, 255));
1661 SetTextColor(memdc, RGB(0, 0, 0));
1662 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1664 /* DST_COMPLEX may draw text as well,
1665 * so we must be sure that correct font is selected
1667 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1668 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1669 if(hfsave) SelectObject(memdc, hfsave);
1670 if(!tmp) goto cleanup;
1672 /* This state cause the image to be dithered */
1673 if(flags & DSS_UNION)
1675 hbsave = (HBRUSH)SelectObject(memdc, UITOOLS_GetPattern55AABrush());
1676 if(!hbsave) goto cleanup;
1677 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1678 SelectObject(memdc, hbsave);
1679 if(!tmp) goto cleanup;
1682 if (flags & DSS_DISABLED)
1683 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1684 else if (flags & DSS_DEFAULT)
1685 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1687 /* Draw light or dark shadow */
1688 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1690 if(!hbrtmp) goto cleanup;
1691 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1692 if(!hbsave) goto cleanup;
1693 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1694 SelectObject(hdc, hbsave);
1695 DeleteObject(hbrtmp);
1699 if (flags & DSS_DISABLED)
1701 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1702 if(!hbrtmp) goto cleanup;
1706 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1709 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1711 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1713 retval = TRUE; /* We succeeded */
1716 SetTextColor(hdc, fg);
1717 SetBkColor(hdc, bg);
1719 if(hbsave) SelectObject(hdc, hbsave);
1720 if(hbmsave) SelectObject(memdc, hbmsave);
1721 if(hbrtmp) DeleteObject(hbrtmp);
1722 if(hbm) DeleteObject(hbm);
1723 if(memdc) DeleteDC(memdc);
1728 /**********************************************************************
1729 * DrawStateA (USER32.@)
1731 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1732 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1733 INT x, INT y, INT cx, INT cy, UINT flags)
1735 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1738 /**********************************************************************
1739 * DrawStateW (USER32.@)
1741 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1742 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1743 INT x, INT y, INT cx, INT cy, UINT flags)
1745 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);