msi/tests: Delete the temp .msi file in all failure cases.
[wine.git] / dlls / user32 / uitools.c
bloba8f3a0af84bf264fc36e90cf8c4fb6f578ec9684
1 /*
2 * User Interface Functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1997 Bertho A. Stultiens
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #define WINE_NO_INLINE_RECT
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "user_private.h"
30 #include "controls.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[] = {
40 -1, -1, -1, -1,
41 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
42 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
43 -1, -1, -1, -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[] = {
54 -1, -1, -1, -1,
55 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
56 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
57 -1, -1, -1, -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[] = {
68 -1, -1, -1, -1,
69 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
70 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
71 -1, -1, -1, -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[] = {
92 -1, -1, -1, -1,
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[] = {
106 -1, -1, -1, -1,
107 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
108 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
109 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
112 /* last COLOR id */
113 #define COLOR_MAX COLOR_MENUBAR
116 /***********************************************************************
117 * set_control_clipping
119 * Set clipping for a builtin control that uses CS_PARENTDC.
120 * Return the previous clip region if any.
122 HRGN set_control_clipping( HDC hdc, const RECT *rect )
124 RECT rc = *rect;
125 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
127 if (GetClipRgn( hdc, hrgn ) != 1)
129 DeleteObject( hrgn );
130 hrgn = 0;
132 DPtoLP( hdc, (POINT *)&rc, 2 );
133 if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */
135 rc.left++;
136 rc.right++;
138 IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
139 return hrgn;
142 /***********************************************************************
143 * UITOOLS_DrawDiagEdge
145 * Same as DrawEdge invoked with BF_DIAGONAL
147 * 03-Dec-1997: Changed by Bertho Stultiens
149 * See also comments with UITOOLS_DrawRectEdge()
151 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
152 UINT uType, UINT uFlags)
154 POINT Points[4];
155 signed char InnerI, OuterI;
156 HPEN InnerPen, OuterPen;
157 POINT SavePoint;
158 HPEN SavePen;
159 int spx, spy;
160 int epx, epy;
161 int Width = rc->right - rc->left;
162 int Height= rc->bottom - rc->top;
163 int SmallDiam = Width > Height ? Height : Width;
164 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
165 || (uType & BDR_OUTER) == BDR_OUTER)
166 && !(uFlags & (BF_FLAT|BF_MONO)) );
167 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
168 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
170 /* Init some vars */
171 OuterPen = InnerPen = GetStockObject(NULL_PEN);
172 SavePen = SelectObject(hdc, InnerPen);
173 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
175 /* Determine the colors of the edges */
176 if(uFlags & BF_MONO)
178 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
179 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
181 else if(uFlags & BF_FLAT)
183 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
184 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
186 else if(uFlags & BF_SOFT)
188 if(uFlags & BF_BOTTOM)
190 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
191 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
193 else
195 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
196 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
199 else
201 if(uFlags & BF_BOTTOM)
203 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
204 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
206 else
208 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
209 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
213 if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
214 if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
216 MoveToEx(hdc, 0, 0, &SavePoint);
218 /* Don't ask me why, but this is what is visible... */
219 /* This must be possible to do much simpler, but I fail to */
220 /* see the logic in the MS implementation (sigh...). */
221 /* So, this might look a bit brute force here (and it is), but */
222 /* it gets the job done;) */
224 switch(uFlags & BF_RECT)
226 case 0:
227 case BF_LEFT:
228 case BF_BOTTOM:
229 case BF_BOTTOMLEFT:
230 /* Left bottom endpoint */
231 epx = rc->left-1;
232 spx = epx + SmallDiam;
233 epy = rc->bottom;
234 spy = epy - SmallDiam;
235 break;
237 case BF_TOPLEFT:
238 case BF_BOTTOMRIGHT:
239 /* Left top endpoint */
240 epx = rc->left-1;
241 spx = epx + SmallDiam;
242 epy = rc->top-1;
243 spy = epy + SmallDiam;
244 break;
246 case BF_TOP:
247 case BF_RIGHT:
248 case BF_TOPRIGHT:
249 case BF_RIGHT|BF_LEFT:
250 case BF_RIGHT|BF_LEFT|BF_TOP:
251 case BF_BOTTOM|BF_TOP:
252 case BF_BOTTOM|BF_TOP|BF_LEFT:
253 case BF_BOTTOMRIGHT|BF_LEFT:
254 case BF_BOTTOMRIGHT|BF_TOP:
255 case BF_RECT:
256 /* Right top endpoint */
257 spx = rc->left;
258 epx = spx + SmallDiam;
259 spy = rc->bottom-1;
260 epy = spy - SmallDiam;
261 break;
264 MoveToEx(hdc, spx, spy, NULL);
265 SelectObject(hdc, OuterPen);
266 LineTo(hdc, epx, epy);
268 SelectObject(hdc, InnerPen);
270 switch(uFlags & (BF_RECT|BF_DIAGONAL))
272 case BF_DIAGONAL_ENDBOTTOMLEFT:
273 case (BF_DIAGONAL|BF_BOTTOM):
274 case BF_DIAGONAL:
275 case (BF_DIAGONAL|BF_LEFT):
276 MoveToEx(hdc, spx-1, spy, NULL);
277 LineTo(hdc, epx, epy-1);
278 Points[0].x = spx-add;
279 Points[0].y = spy;
280 Points[1].x = rc->left;
281 Points[1].y = rc->top;
282 Points[2].x = epx+1;
283 Points[2].y = epy-1-add;
284 Points[3] = Points[2];
285 break;
287 case BF_DIAGONAL_ENDBOTTOMRIGHT:
288 MoveToEx(hdc, spx-1, spy, NULL);
289 LineTo(hdc, epx, epy+1);
290 Points[0].x = spx-add;
291 Points[0].y = spy;
292 Points[1].x = rc->left;
293 Points[1].y = rc->bottom-1;
294 Points[2].x = epx+1;
295 Points[2].y = epy+1+add;
296 Points[3] = Points[2];
297 break;
299 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
300 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
301 case BF_DIAGONAL_ENDTOPRIGHT:
302 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
303 MoveToEx(hdc, spx+1, spy, NULL);
304 LineTo(hdc, epx, epy+1);
305 Points[0].x = epx-1;
306 Points[0].y = epy+1+add;
307 Points[1].x = rc->right-1;
308 Points[1].y = rc->top+add;
309 Points[2].x = rc->right-1;
310 Points[2].y = rc->bottom-1;
311 Points[3].x = spx+add;
312 Points[3].y = spy;
313 break;
315 case BF_DIAGONAL_ENDTOPLEFT:
316 MoveToEx(hdc, spx, spy-1, NULL);
317 LineTo(hdc, epx+1, epy);
318 Points[0].x = epx+1+add;
319 Points[0].y = epy+1;
320 Points[1].x = rc->right-1;
321 Points[1].y = rc->top;
322 Points[2].x = rc->right-1;
323 Points[2].y = rc->bottom-1-add;
324 Points[3].x = spx;
325 Points[3].y = spy-add;
326 break;
328 case (BF_DIAGONAL|BF_TOP):
329 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
330 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
331 MoveToEx(hdc, spx+1, spy-1, NULL);
332 LineTo(hdc, epx, epy);
333 Points[0].x = epx-1;
334 Points[0].y = epy+1;
335 Points[1].x = rc->right-1;
336 Points[1].y = rc->top;
337 Points[2].x = rc->right-1;
338 Points[2].y = rc->bottom-1-add;
339 Points[3].x = spx+add;
340 Points[3].y = spy-add;
341 break;
343 case (BF_DIAGONAL|BF_RIGHT):
344 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
345 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
346 MoveToEx(hdc, spx, spy, NULL);
347 LineTo(hdc, epx-1, epy+1);
348 Points[0].x = spx;
349 Points[0].y = spy;
350 Points[1].x = rc->left;
351 Points[1].y = rc->top+add;
352 Points[2].x = epx-1-add;
353 Points[2].y = epy+1+add;
354 Points[3] = Points[2];
355 break;
358 /* Fill the interior if asked */
359 if((uFlags & BF_MIDDLE) && retval)
361 HBRUSH hbsave;
362 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
363 :COLOR_BTNFACE);
364 HPEN hpsave;
365 HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
366 : COLOR_BTNFACE);
367 hbsave = SelectObject(hdc, hb);
368 hpsave = SelectObject(hdc, hp);
369 Polygon(hdc, Points, 4);
370 SelectObject(hdc, hbsave);
371 SelectObject(hdc, hpsave);
374 /* Adjust rectangle if asked */
375 if(uFlags & BF_ADJUST)
377 if(uFlags & BF_LEFT) rc->left += add;
378 if(uFlags & BF_RIGHT) rc->right -= add;
379 if(uFlags & BF_TOP) rc->top += add;
380 if(uFlags & BF_BOTTOM) rc->bottom -= add;
383 /* Cleanup */
384 SelectObject(hdc, SavePen);
385 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
387 return retval;
390 /***********************************************************************
391 * UITOOLS_DrawRectEdge
393 * Same as DrawEdge invoked without BF_DIAGONAL
394 * The width parameter sets the width of each outer and inner edge.
396 * 23-Nov-1997: Changed by Bertho Stultiens
398 * Well, I started testing this and found out that there are a few things
399 * that weren't quite as win95. The following rewrite should reproduce
400 * win95 results completely.
401 * The colorselection is table-driven to avoid awful if-statements.
402 * The table below show the color settings.
404 * Pen selection table for uFlags = 0
406 * uType | LTI | LTO | RBI | RBO
407 * ------+-------+-------+-------+-------
408 * 0000 | x | x | x | x
409 * 0001 | x | 22 | x | 21
410 * 0010 | x | 16 | x | 20
411 * 0011 | x | x | x | x
412 * ------+-------+-------+-------+-------
413 * 0100 | x | 20 | x | 16
414 * 0101 | 20 | 22 | 16 | 21
415 * 0110 | 20 | 16 | 16 | 20
416 * 0111 | x | x | x | x
417 * ------+-------+-------+-------+-------
418 * 1000 | x | 21 | x | 22
419 * 1001 | 21 | 22 | 22 | 21
420 * 1010 | 21 | 16 | 22 | 20
421 * 1011 | x | x | x | x
422 * ------+-------+-------+-------+-------
423 * 1100 | x | x | x | x
424 * 1101 | x | x (22)| x | x (21)
425 * 1110 | x | x (16)| x | x (20)
426 * 1111 | x | x | x | x
428 * Pen selection table for uFlags = BF_SOFT
430 * uType | LTI | LTO | RBI | RBO
431 * ------+-------+-------+-------+-------
432 * 0000 | x | x | x | x
433 * 0001 | x | 20 | x | 21
434 * 0010 | x | 21 | x | 20
435 * 0011 | x | x | x | x
436 * ------+-------+-------+-------+-------
437 * 0100 | x | 22 | x | 16
438 * 0101 | 22 | 20 | 16 | 21
439 * 0110 | 22 | 21 | 16 | 20
440 * 0111 | x | x | x | x
441 * ------+-------+-------+-------+-------
442 * 1000 | x | 16 | x | 22
443 * 1001 | 16 | 20 | 22 | 21
444 * 1010 | 16 | 21 | 22 | 20
445 * 1011 | x | x | x | x
446 * ------+-------+-------+-------+-------
447 * 1100 | x | x | x | x
448 * 1101 | x | x (20)| x | x (21)
449 * 1110 | x | x (21)| x | x (20)
450 * 1111 | x | x | x | x
452 * x = don't care; (n) = is what win95 actually uses
453 * LTI = left Top Inner line
454 * LTO = left Top Outer line
455 * RBI = Right Bottom Inner line
456 * RBO = Right Bottom Outer line
457 * 15 = COLOR_BTNFACE
458 * 16 = COLOR_BTNSHADOW
459 * 20 = COLOR_BTNHIGHLIGHT
460 * 21 = COLOR_3DDKSHADOW
461 * 22 = COLOR_3DLIGHT
465 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
466 UINT uType, UINT uFlags, UINT width)
468 signed char LTInnerI, LTOuterI;
469 signed char RBInnerI, RBOuterI;
470 HBRUSH lti_brush, lto_brush, rbi_brush, rbo_brush;
471 RECT InnerRect = *rc, fill_rect;
472 int lbi_offset = 0, lti_offset = 0, rti_offset = 0, rbi_offset = 0;
473 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
474 || (uType & BDR_OUTER) == BDR_OUTER)
475 && !(uFlags & (BF_FLAT|BF_MONO)) );
477 lti_brush = lto_brush = rbi_brush = rbo_brush = GetStockObject(NULL_BRUSH);
479 /* Determine the colors of the edges */
480 if(uFlags & BF_MONO)
482 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
483 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
485 else if(uFlags & BF_FLAT)
487 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
488 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
490 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
492 else if(uFlags & BF_SOFT)
494 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
495 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
496 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
497 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
499 else
501 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
502 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
503 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
504 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
507 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) lbi_offset = width;
508 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) rti_offset = width;
509 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) rbi_offset = width;
510 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) lti_offset = width;
512 if(LTInnerI != -1) lti_brush = GetSysColorBrush(LTInnerI);
513 if(LTOuterI != -1) lto_brush = GetSysColorBrush(LTOuterI);
514 if(RBInnerI != -1) rbi_brush = GetSysColorBrush(RBInnerI);
515 if(RBOuterI != -1) rbo_brush = GetSysColorBrush(RBOuterI);
517 /* Draw the outer edge */
518 if(uFlags & BF_TOP)
520 fill_rect = InnerRect;
521 fill_rect.bottom = fill_rect.top + width;
522 FillRect( hdc, &fill_rect, lto_brush );
524 if(uFlags & BF_LEFT)
526 fill_rect = InnerRect;
527 fill_rect.right = fill_rect.left + width;
528 FillRect( hdc, &fill_rect, lto_brush );
530 if(uFlags & BF_BOTTOM)
532 fill_rect = InnerRect;
533 fill_rect.top = fill_rect.bottom - width;
534 FillRect( hdc, &fill_rect, rbo_brush );
536 if(uFlags & BF_RIGHT)
538 fill_rect = InnerRect;
539 fill_rect.left = fill_rect.right - width;
540 FillRect( hdc, &fill_rect, rbo_brush );
543 /* Draw the inner edge */
544 if(uFlags & BF_TOP)
546 SetRect( &fill_rect, InnerRect.left + lti_offset, InnerRect.top + width,
547 InnerRect.right - rti_offset, InnerRect.top + 2 * width );
548 FillRect( hdc, &fill_rect, lti_brush );
550 if(uFlags & BF_LEFT)
552 SetRect( &fill_rect, InnerRect.left + width, InnerRect.top + lti_offset,
553 InnerRect.left + 2 * width, InnerRect.bottom - lbi_offset );
554 FillRect( hdc, &fill_rect, lti_brush );
556 if(uFlags & BF_BOTTOM)
558 SetRect( &fill_rect, InnerRect.left + lbi_offset, InnerRect.bottom - 2 * width,
559 InnerRect.right - rbi_offset, InnerRect.bottom - width );
560 FillRect( hdc, &fill_rect, rbi_brush );
562 if(uFlags & BF_RIGHT)
564 SetRect( &fill_rect, InnerRect.right - 2 * width, InnerRect.top + rti_offset,
565 InnerRect.right - width, InnerRect.bottom - rbi_offset );
566 FillRect( hdc, &fill_rect, rbi_brush );
569 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
571 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? width : 0)
572 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? width : 0);
574 if(uFlags & BF_LEFT) InnerRect.left += add;
575 if(uFlags & BF_RIGHT) InnerRect.right -= add;
576 if(uFlags & BF_TOP) InnerRect.top += add;
577 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
579 if((uFlags & BF_MIDDLE) && retval)
581 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
582 COLOR_WINDOW : COLOR_BTNFACE));
585 if(uFlags & BF_ADJUST)
586 *rc = InnerRect;
589 return retval;
593 /**********************************************************************
594 * DrawEdge (USER32.@)
596 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
598 TRACE("%p %s %04x %04x\n", hdc, wine_dbgstr_rect(rc), edge, flags );
600 if(flags & BF_DIAGONAL)
601 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
602 else
603 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags, 1);
607 /************************************************************************
608 * UITOOLS_MakeSquareRect
610 * Utility to create a square rectangle and returning the width
612 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
614 int Width = src->right - src->left;
615 int Height = src->bottom - src->top;
616 int SmallDiam = Width > Height ? Height : Width;
618 *dst = *src;
620 /* Make it a square box */
621 if(Width < Height) /* SmallDiam == Width */
623 dst->top += (Height-Width)/2;
624 dst->bottom = dst->top + SmallDiam;
626 else if(Width > Height) /* SmallDiam == Height */
628 dst->left += (Width-Height)/2;
629 dst->right = dst->left + SmallDiam;
632 return SmallDiam;
635 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
637 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
639 HBRUSH hbsave;
640 COLORREF bg;
642 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
643 bg = SetBkColor(dc, RGB(255, 255, 255));
644 hbsave = SelectObject(dc, SYSCOLOR_Get55AABrush());
645 PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
646 SelectObject(dc, hbsave);
647 SetBkColor(dc, bg);
649 else
651 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
655 /************************************************************************
656 * UITOOLS_DFC_ButtonPush
658 * Draw a push button coming from DrawFrameControl()
660 * Does a pretty good job in emulating MS behavior. Some quirks are
661 * however there because MS uses a TrueType font (Marlett) to draw
662 * the buttons.
664 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
666 UINT edge;
667 RECT myr = *r;
669 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
670 edge = EDGE_SUNKEN;
671 else
672 edge = EDGE_RAISED;
674 if(uFlags & DFCS_CHECKED)
676 if(uFlags & DFCS_MONO)
677 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST, 1);
678 else
679 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST, 1);
681 if (!(uFlags & DFCS_TRANSPARENT))
682 UITOOLS_DrawCheckedRect( dc, &myr );
684 else
686 if(uFlags & DFCS_MONO)
688 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST, 1);
689 if (!(uFlags & DFCS_TRANSPARENT))
690 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
692 else
694 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) |
695 ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT | BF_SOFT, 1);
699 /* Adjust rectangle if asked */
700 if(uFlags & DFCS_ADJUSTRECT)
701 InflateRect(r, -2, -2);
703 return TRUE;
707 /************************************************************************
708 * UITOOLS_DFC_ButtonCheck
710 * Draw a check/3state button coming from DrawFrameControl()
712 * Does a pretty good job in emulating MS behavior. Some quirks are
713 * however there because MS uses a TrueType font (Marlett) to draw
714 * the buttons.
717 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
719 RECT myr;
720 UINT flags = BF_RECT | BF_ADJUST;
722 UITOOLS_MakeSquareRect(r, &myr);
724 if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
725 else if(uFlags & DFCS_MONO) flags |= BF_MONO;
727 UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags, max( (myr.right - myr.left + 8) / 16, 1) );
729 if (!(uFlags & DFCS_TRANSPARENT))
731 if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
732 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
733 else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
734 UITOOLS_DrawCheckedRect( dc, &myr );
735 else
736 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
739 if(uFlags & DFCS_CHECKED)
741 POINT pt[6];
742 HPEN old_pen;
743 HBRUSH old_brush;
744 int color = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
745 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
747 pt[0].x = myr.right - 1;
748 pt[0].y = myr.top;
749 pt[1].x = pt[0].x;
750 pt[1].y = pt[0].y + (myr.bottom - myr.top) / 3;
751 pt[2].x = myr.left + (myr.right - myr.left) / 3;
752 pt[2].y = myr.bottom - 1;
753 pt[3].x = myr.left + 1;
754 pt[3].y = pt[2].y - (pt[2].x - pt[3].x);
755 pt[4].x = pt[3].x;
756 pt[4].y = pt[3].y - (myr.bottom - myr.top) / 3;
757 pt[5].x = pt[2].x;
758 pt[5].y = pt[2].y - (myr.bottom - myr.top) / 3;
760 old_brush = SelectObject( dc, GetSysColorBrush( color ) );
761 old_pen = SelectObject( dc, GetStockObject( NULL_PEN ));
762 Polygon( dc, pt, 6 );
763 SelectObject( dc, old_brush );
764 SelectObject( dc, old_pen );
766 return TRUE;
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
777 * the buttons.
779 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
781 RECT myr;
782 int i;
783 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
784 int BorderShrink = SmallDiam / 16;
785 HPEN hpsave;
786 HBRUSH hbsave;
787 int xc, yc;
789 if(BorderShrink < 1) BorderShrink = 1;
791 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
792 FillRect(dc, r, GetStockObject(BLACK_BRUSH));
793 else if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
794 FillRect(dc, r, GetStockObject(WHITE_BRUSH));
796 xc = myr.left + SmallDiam - SmallDiam/2;
797 yc = myr.top + SmallDiam - SmallDiam/2;
799 /* Define bounding box */
800 i = 14*SmallDiam/16;
801 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
803 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
805 hbsave = SelectObject(dc, GetStockObject(BLACK_BRUSH));
806 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
807 SelectObject(dc, hbsave);
809 else
811 if(uFlags & (DFCS_FLAT|DFCS_MONO))
813 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
814 hbsave = SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
815 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
816 SelectObject(dc, hbsave);
817 SelectObject(dc, hpsave);
819 else
821 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
822 hbsave = SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
823 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
825 SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNSHADOW));
826 SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
827 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
829 InflateRect(&myr, -BorderShrink, -BorderShrink);
830 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
831 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
832 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
834 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
835 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
836 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
837 SelectObject(dc, hbsave);
838 SelectObject(dc, hpsave);
841 i = 10*SmallDiam/16;
842 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
843 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
844 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
845 hbsave = SelectObject(dc, GetSysColorBrush(i));
846 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
847 SelectObject(dc, hbsave);
848 SelectObject(dc, hpsave);
851 if(uFlags & DFCS_CHECKED)
853 i = 6*SmallDiam/16;
854 i = i < 1 ? 1 : i;
855 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
857 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
858 hbsave = SelectObject(dc, GetSysColorBrush(i));
859 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
860 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
861 SelectObject(dc, hpsave);
862 SelectObject(dc, hbsave);
865 /* FIXME: M$ has a polygon in the center at relative points: */
866 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
867 /* 0.476, 0.525 */
868 /* 0.500, 0.500 */
869 /* 0.500, 0.499 */
870 /* when the button is unchecked. The reason for it is unknown. The */
871 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
872 /* least 3 times (it looks like a clip-region when you see it happen). */
873 /* I do not really see a reason why this should be implemented. If you */
874 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
875 /* font. */
877 return TRUE;
880 /***********************************************************************
881 * UITOOLS_DrawFrameButton
883 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
885 switch(uState & 0xff)
887 case DFCS_BUTTONPUSH:
888 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
890 case DFCS_BUTTONCHECK:
891 case DFCS_BUTTON3STATE:
892 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
894 case DFCS_BUTTONRADIOIMAGE:
895 case DFCS_BUTTONRADIOMASK:
896 case DFCS_BUTTONRADIO:
897 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
899 default:
900 WARN("Invalid button state=0x%04x\n", uState);
903 return FALSE;
906 /***********************************************************************
907 * UITOOLS_DrawFrameCaption
909 * Draw caption buttons (win95), coming from DrawFrameControl()
912 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
914 RECT myr;
915 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
916 HFONT hfsave, hf;
917 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
918 int xc = (myr.left+myr.right)/2;
919 int yc = (myr.top+myr.bottom)/2;
920 WCHAR str[] = {0, 0};
921 UINT alignsave;
922 int bksave;
923 COLORREF clrsave;
924 SIZE size;
926 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
928 switch(uFlags & 0xf)
930 case DFCS_CAPTIONCLOSE: str[0] = 0x72; break;
931 case DFCS_CAPTIONHELP: str[0] = 0x73; break;
932 case DFCS_CAPTIONMIN: str[0] = 0x30; break;
933 case DFCS_CAPTIONMAX: str[0] = 0x31; break;
934 case DFCS_CAPTIONRESTORE: str[0] = 0x32; break;
935 default:
936 WARN("Invalid caption; flags=0x%04x\n", uFlags);
937 return FALSE;
940 hf = CreateFontW(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
941 SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
942 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, L"Marlett");
943 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
944 bksave = SetBkMode(dc, TRANSPARENT);
945 clrsave = GetTextColor(dc);
946 hfsave = SelectObject(dc, hf);
947 GetTextExtentPoint32W(dc, str, 1, &size);
949 if(uFlags & DFCS_INACTIVE)
951 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
952 TextOutW(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
954 SetTextColor(dc, GetSysColor(colorIdx));
955 TextOutW(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
957 SelectObject(dc, hfsave);
958 SetTextColor(dc, clrsave);
959 SetBkMode(dc, bksave);
960 SetTextAlign(dc, alignsave);
961 DeleteObject(hf);
963 return TRUE;
967 /************************************************************************
968 * UITOOLS_DrawFrameScroll
970 * Draw a scroll-bar control coming from DrawFrameControl()
972 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
974 POINT Line[4];
975 RECT myr;
976 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
977 int i;
978 HBRUSH hbsave, hb, hb2;
979 HPEN hpsave, hp, hp2;
980 int tri = 290*SmallDiam/1000 - 1;
981 int d46, d93;
984 * This fixes a problem with really tiny "scroll" buttons. In particular
985 * with the updown control.
986 * Making sure that the arrow is as least 3 pixels wide (or high).
988 tri = max( 2, tri );
990 switch(uFlags & 0xff)
992 case DFCS_SCROLLCOMBOBOX:
993 case DFCS_SCROLLDOWN:
994 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
995 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
996 Line[0].x = Line[2].x - tri;
997 Line[1].x = Line[2].x + tri;
998 Line[0].y = Line[1].y = Line[2].y - tri;
999 break;
1001 case DFCS_SCROLLUP:
1002 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1003 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
1004 Line[0].x = Line[2].x - tri;
1005 Line[1].x = Line[2].x + tri;
1006 Line[0].y = Line[1].y = Line[2].y + tri;
1007 break;
1009 case DFCS_SCROLLLEFT:
1010 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1011 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1012 Line[0].y = Line[2].y - tri;
1013 Line[1].y = Line[2].y + tri;
1014 Line[0].x = Line[1].x = Line[2].x + tri;
1015 break;
1017 case DFCS_SCROLLRIGHT:
1018 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1019 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1020 Line[0].y = Line[2].y - tri;
1021 Line[1].y = Line[2].y + tri;
1022 Line[0].x = Line[1].x = Line[2].x - tri;
1023 break;
1025 case DFCS_SCROLLSIZEGRIP:
1026 /* This one breaks the flow... */
1027 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0), 1);
1028 hpsave = SelectObject(dc, GetStockObject(NULL_PEN));
1029 hbsave = SelectObject(dc, GetStockObject(NULL_BRUSH));
1030 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1032 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1033 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1035 else
1037 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1038 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1039 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1040 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1042 Line[0].x = Line[1].x = r->right-1;
1043 Line[2].y = Line[3].y = r->bottom-1;
1044 d46 = 46*SmallDiam/750;
1045 d93 = 93*SmallDiam/750;
1047 i = 586*SmallDiam/750;
1048 Line[0].y = r->bottom - i - 1;
1049 Line[3].x = r->right - i - 1;
1050 Line[1].y = Line[0].y + d46;
1051 Line[2].x = Line[3].x + d46;
1052 SelectObject(dc, hb);
1053 SelectObject(dc, hp);
1054 Polygon(dc, Line, 4);
1056 Line[1].y++; Line[2].x++;
1057 Line[0].y = Line[1].y + d93;
1058 Line[3].x = Line[2].x + d93;
1059 SelectObject(dc, hb2);
1060 SelectObject(dc, hp2);
1061 Polygon(dc, Line, 4);
1063 i = 398*SmallDiam/750;
1064 Line[0].y = r->bottom - i - 1;
1065 Line[3].x = r->right - i - 1;
1066 Line[1].y = Line[0].y + d46;
1067 Line[2].x = Line[3].x + d46;
1068 SelectObject(dc, hb);
1069 SelectObject(dc, hp);
1070 Polygon(dc, Line, 4);
1072 Line[1].y++; Line[2].x++;
1073 Line[0].y = Line[1].y + d93;
1074 Line[3].x = Line[2].x + d93;
1075 SelectObject(dc, hb2);
1076 SelectObject(dc, hp2);
1077 Polygon(dc, Line, 4);
1079 i = 210*SmallDiam/750;
1080 Line[0].y = r->bottom - i - 1;
1081 Line[3].x = r->right - i - 1;
1082 Line[1].y = Line[0].y + d46;
1083 Line[2].x = Line[3].x + d46;
1084 SelectObject(dc, hb);
1085 SelectObject(dc, hp);
1086 Polygon(dc, Line, 4);
1088 Line[1].y++; Line[2].x++;
1089 Line[0].y = Line[1].y + d93;
1090 Line[3].x = Line[2].x + d93;
1091 SelectObject(dc, hb2);
1092 SelectObject(dc, hp2);
1093 Polygon(dc, Line, 4);
1095 SelectObject(dc, hpsave);
1096 SelectObject(dc, hbsave);
1097 return TRUE;
1099 default:
1100 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1101 return FALSE;
1104 /* Here do the real scroll-bar controls end up */
1105 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1106 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1107 /* want for the normal scroll-arrow button. */
1108 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT, 1);
1109 else
1110 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1112 if(uFlags & DFCS_INACTIVE)
1114 hbsave = SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1115 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1116 Polygon(dc, Line, 3);
1117 SelectObject(dc, hpsave);
1118 SelectObject(dc, hbsave);
1121 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1122 for(i = 0; i < 3; i++)
1124 Line[i].x--;
1125 Line[i].y--;
1128 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1129 hbsave = SelectObject(dc, GetSysColorBrush(i));
1130 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
1131 Polygon(dc, Line, 3);
1132 SelectObject(dc, hpsave);
1133 SelectObject(dc, hbsave);
1135 return TRUE;
1138 /************************************************************************
1139 * UITOOLS_DrawFrameMenu
1141 * Draw a menu control coming from DrawFrameControl()
1143 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1145 POINT Points[6];
1146 RECT myr;
1147 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1148 int i;
1149 HBRUSH hbsave;
1150 HPEN hpsave;
1151 int xe, ye;
1152 int xc, yc;
1153 BOOL retval = TRUE;
1155 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1156 /* use anything else. I think I tried all sys-colors to change things */
1157 /* without luck. It seems as if this behavior is inherited from the */
1158 /* win31 DFC() implementation... (you remember, B/W menus). */
1160 FillRect(dc, r, GetStockObject(WHITE_BRUSH));
1162 hbsave = SelectObject(dc, GetStockObject(BLACK_BRUSH));
1163 hpsave = SelectObject(dc, GetStockObject(BLACK_PEN));
1165 switch(uFlags & 0xff)
1167 case DFCS_MENUARROW:
1168 i = 187*SmallDiam/750;
1169 Points[2].x = myr.left + 468*SmallDiam/750;
1170 Points[2].y = myr.top + 352*SmallDiam/750+1;
1171 Points[0].y = Points[2].y - i;
1172 Points[1].y = Points[2].y + i;
1173 Points[0].x = Points[1].x = Points[2].x - i;
1174 Polygon(dc, Points, 3);
1175 break;
1177 case DFCS_MENUBULLET:
1178 xe = myr.left;
1179 ye = myr.top + SmallDiam - SmallDiam/2;
1180 xc = myr.left + SmallDiam - SmallDiam/2;
1181 yc = myr.top + SmallDiam - SmallDiam/2;
1182 i = 234*SmallDiam/750;
1183 i = i < 1 ? 1 : i;
1184 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
1185 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1186 break;
1188 case DFCS_MENUCHECK:
1189 Points[0].x = myr.left + 253*SmallDiam/1000;
1190 Points[0].y = myr.top + 445*SmallDiam/1000;
1191 Points[1].x = myr.left + 409*SmallDiam/1000;
1192 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1193 Points[2].x = myr.left + 690*SmallDiam/1000;
1194 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1195 Points[3].x = Points[2].x;
1196 Points[3].y = Points[2].y + 3*SmallDiam/16;
1197 Points[4].x = Points[1].x;
1198 Points[4].y = Points[1].y + 3*SmallDiam/16;
1199 Points[5].x = Points[0].x;
1200 Points[5].y = Points[0].y + 3*SmallDiam/16;
1201 Polygon(dc, Points, 6);
1202 break;
1204 default:
1205 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1206 retval = FALSE;
1207 break;
1210 SelectObject(dc, hpsave);
1211 SelectObject(dc, hbsave);
1212 return retval;
1216 /**********************************************************************
1217 * DrawFrameControl (USER32.@)
1219 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1220 UINT uState )
1222 switch(uType)
1224 case DFC_BUTTON:
1225 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1226 case DFC_CAPTION:
1227 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1228 case DFC_MENU:
1229 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1230 /*case DFC_POPUPMENU:
1231 FIXME("DFC_POPUPMENU: not implemented\n");
1232 break;*/
1233 case DFC_SCROLL:
1234 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1235 default:
1236 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1238 return FALSE;
1242 /***********************************************************************
1243 * SetRect (USER32.@)
1245 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
1246 INT right, INT bottom )
1248 if (!rect) return FALSE;
1249 rect->left = left;
1250 rect->right = right;
1251 rect->top = top;
1252 rect->bottom = bottom;
1253 return TRUE;
1257 /***********************************************************************
1258 * SetRectEmpty (USER32.@)
1260 BOOL WINAPI SetRectEmpty( LPRECT rect )
1262 if (!rect) return FALSE;
1263 rect->left = rect->right = rect->top = rect->bottom = 0;
1264 return TRUE;
1268 /***********************************************************************
1269 * CopyRect (USER32.@)
1271 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
1273 if (!dest || !src) return FALSE;
1274 *dest = *src;
1275 return TRUE;
1279 /***********************************************************************
1280 * IsRectEmpty (USER32.@)
1282 * Bug compat: Windows checks for 0 or negative width/height.
1284 BOOL WINAPI IsRectEmpty( const RECT *rect )
1286 if (!rect) return TRUE;
1287 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
1291 /***********************************************************************
1292 * PtInRect (USER32.@)
1294 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
1296 if (!rect) return FALSE;
1297 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
1298 (pt.y >= rect->top) && (pt.y < rect->bottom));
1302 /***********************************************************************
1303 * OffsetRect (USER32.@)
1305 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
1307 if (!rect) return FALSE;
1308 rect->left += x;
1309 rect->right += x;
1310 rect->top += y;
1311 rect->bottom += y;
1312 return TRUE;
1316 /***********************************************************************
1317 * InflateRect (USER32.@)
1319 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
1321 if (!rect) return FALSE;
1322 rect->left -= x;
1323 rect->top -= y;
1324 rect->right += x;
1325 rect->bottom += y;
1326 return TRUE;
1330 /***********************************************************************
1331 * IntersectRect (USER32.@)
1333 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1335 if (!dest || !src1 || !src2) return FALSE;
1336 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
1337 (src1->left >= src2->right) || (src2->left >= src1->right) ||
1338 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
1340 SetRectEmpty( dest );
1341 return FALSE;
1343 dest->left = max( src1->left, src2->left );
1344 dest->right = min( src1->right, src2->right );
1345 dest->top = max( src1->top, src2->top );
1346 dest->bottom = min( src1->bottom, src2->bottom );
1347 return TRUE;
1351 /***********************************************************************
1352 * UnionRect (USER32.@)
1354 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1356 if (!dest) return FALSE;
1357 if (IsRectEmpty(src1))
1359 if (IsRectEmpty(src2))
1361 SetRectEmpty( dest );
1362 return FALSE;
1364 else *dest = *src2;
1366 else
1368 if (IsRectEmpty(src2)) *dest = *src1;
1369 else
1371 dest->left = min( src1->left, src2->left );
1372 dest->right = max( src1->right, src2->right );
1373 dest->top = min( src1->top, src2->top );
1374 dest->bottom = max( src1->bottom, src2->bottom );
1377 return TRUE;
1381 /***********************************************************************
1382 * EqualRect (USER32.@)
1384 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
1386 if (!rect1 || !rect2) return FALSE;
1387 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1388 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1392 /***********************************************************************
1393 * SubtractRect (USER32.@)
1395 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1397 RECT tmp;
1399 if (!dest) return FALSE;
1400 if (IsRectEmpty( src1 ))
1402 SetRectEmpty( dest );
1403 return FALSE;
1405 if (IntersectRect( &tmp, src1, src2 ))
1407 if (EqualRect( &tmp, src1 ))
1409 SetRectEmpty( dest );
1410 return FALSE;
1412 *dest = *src1;
1413 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1415 if (tmp.left == dest->left) dest->left = tmp.right;
1416 else if (tmp.right == dest->right) dest->right = tmp.left;
1418 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1420 if (tmp.top == dest->top) dest->top = tmp.bottom;
1421 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1424 else
1426 *dest = *src1;
1428 return TRUE;
1432 /***********************************************************************
1433 * FillRect (USER32.@)
1435 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1437 HBRUSH prev_brush;
1439 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( HandleToULong(hbrush) - 1 );
1441 prev_brush = SelectObject( hdc, hbrush );
1442 PatBlt( hdc, rect->left, rect->top,
1443 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1444 if (prev_brush) SelectObject( hdc, prev_brush );
1445 return 1;
1449 /***********************************************************************
1450 * InvertRect (USER32.@)
1452 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1454 return PatBlt( hdc, rect->left, rect->top,
1455 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1459 /***********************************************************************
1460 * FrameRect (USER32.@)
1462 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1464 HBRUSH prevBrush;
1465 RECT r = *rect;
1467 if (IsRectEmpty(&r)) return 0;
1468 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1470 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1471 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1472 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1473 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1475 SelectObject( hdc, prevBrush );
1476 return TRUE;
1480 /***********************************************************************
1481 * DrawFocusRect (USER32.@)
1483 * FIXME: PatBlt(PATINVERT) with background brush.
1485 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1487 HBRUSH hOldBrush;
1488 HPEN hOldPen, hNewPen;
1489 INT oldDrawMode, oldBkMode;
1490 LOGBRUSH lb;
1492 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1493 lb.lbStyle = BS_SOLID;
1494 lb.lbColor = 0;
1495 hNewPen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL);
1496 hOldPen = SelectObject(hdc, hNewPen);
1497 oldDrawMode = SetROP2(hdc, R2_NOT);
1498 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1500 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1502 SetBkMode(hdc, oldBkMode);
1503 SetROP2(hdc, oldDrawMode);
1504 SelectObject(hdc, hOldPen);
1505 DeleteObject(hNewPen);
1506 SelectObject(hdc, hOldBrush);
1508 return TRUE;
1512 /**********************************************************************
1513 * DrawAnimatedRects (USER32.@)
1515 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1517 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1518 return TRUE;
1522 /**********************************************************************
1523 * UITOOLS_DrawStateJam
1525 * Jams in the requested type in the dc
1527 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1528 LPRECT rc, UINT dtflags, BOOL unicode )
1530 HDC memdc;
1531 HBITMAP hbmsave;
1532 BOOL retval;
1533 INT cx = rc->right - rc->left;
1534 INT cy = rc->bottom - rc->top;
1536 switch(opcode)
1538 case DST_TEXT:
1539 case DST_PREFIXTEXT:
1540 if(unicode)
1541 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1542 else
1543 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1545 case DST_ICON:
1546 return NtUserDrawIconEx(hdc, rc->left, rc->top, (HICON)lp, 0, 0, 0, NULL, DI_NORMAL);
1548 case DST_BITMAP:
1549 memdc = CreateCompatibleDC(hdc);
1550 if(!memdc) return FALSE;
1551 hbmsave = SelectObject(memdc, (HBITMAP)lp);
1552 if(!hbmsave)
1554 DeleteDC(memdc);
1555 return FALSE;
1557 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1558 SelectObject(memdc, hbmsave);
1559 DeleteDC(memdc);
1560 return retval;
1562 case DST_COMPLEX:
1563 if(func) {
1564 BOOL bRet;
1565 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1567 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1568 bRet = func(hdc, lp, wp, cx, cy);
1569 /* Restore origin */
1570 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1571 return bRet;
1572 } else
1573 return FALSE;
1575 return FALSE;
1578 /**********************************************************************
1579 * UITOOLS_DrawState()
1581 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1582 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1584 HBITMAP hbm, hbmsave;
1585 HFONT hfsave;
1586 HBRUSH hbsave, hbrtmp = 0;
1587 HDC memdc;
1588 RECT rc;
1589 UINT dtflags = DT_NOCLIP;
1590 COLORREF fg, bg;
1591 UINT opcode = flags & 0xf;
1592 INT len = wp;
1593 BOOL retval, tmp;
1595 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1597 if (!lp) return FALSE;
1599 if(unicode)
1600 len = lstrlenW((LPWSTR)lp);
1601 else
1602 len = strlen((LPSTR)lp);
1605 /* Find out what size the image has if not given by caller */
1606 if(!cx || !cy)
1608 SIZE s;
1609 BITMAP bm;
1611 switch(opcode)
1613 case DST_TEXT:
1614 case DST_PREFIXTEXT:
1615 if(unicode)
1616 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1617 else
1618 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1619 if(!retval) return FALSE;
1620 break;
1622 case DST_ICON:
1623 if (!get_icon_size( (HICON)lp, &s )) return FALSE;
1624 break;
1626 case DST_BITMAP:
1627 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1628 s.cx = bm.bmWidth;
1629 s.cy = bm.bmHeight;
1630 break;
1632 case DST_COMPLEX: /* cx and cy must be set in this mode */
1633 return FALSE;
1636 if(!cx) cx = s.cx;
1637 if(!cy) cy = s.cy;
1640 SetRect(&rc, x, y, x + cx, y + cy);
1642 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1643 dtflags |= DT_RIGHT;
1644 if(opcode == DST_TEXT)
1645 dtflags |= DT_NOPREFIX;
1647 /* For DSS_NORMAL we just jam in the image and return */
1648 if((flags & 0x7ff0) == DSS_NORMAL)
1650 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1653 /* For all other states we need to convert the image to B/W in a local bitmap */
1654 /* before it is displayed */
1655 fg = SetTextColor(hdc, RGB(0, 0, 0));
1656 bg = SetBkColor(hdc, RGB(255, 255, 255));
1657 hbm = NULL; hbmsave = NULL;
1658 memdc = NULL; hbsave = NULL;
1659 retval = FALSE; /* assume failure */
1661 /* From here on we must use "goto cleanup" when something goes wrong */
1662 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1663 if(!hbm) goto cleanup;
1664 memdc = CreateCompatibleDC(hdc);
1665 if(!memdc) goto cleanup;
1666 hbmsave = SelectObject(memdc, hbm);
1667 if(!hbmsave) goto cleanup;
1668 SetRect(&rc, 0, 0, cx, cy);
1669 if(!FillRect(memdc, &rc, GetStockObject(WHITE_BRUSH))) goto cleanup;
1670 SetBkColor(memdc, RGB(255, 255, 255));
1671 SetTextColor(memdc, RGB(0, 0, 0));
1672 hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1673 SetLayout( memdc, GetLayout( hdc ));
1675 /* DST_COMPLEX may draw text as well,
1676 * so we must be sure that correct font is selected
1678 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1679 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1680 if(hfsave) SelectObject(memdc, hfsave);
1681 if(!tmp) goto cleanup;
1683 /* This state cause the image to be dithered */
1684 if(flags & DSS_UNION)
1686 hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
1687 if(!hbsave) goto cleanup;
1688 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1689 SelectObject(memdc, hbsave);
1690 if(!tmp) goto cleanup;
1693 if (flags & DSS_DISABLED)
1694 hbrtmp = GetSysColorBrush(COLOR_3DHILIGHT);
1695 else if (flags & DSS_DEFAULT)
1696 hbrtmp = GetSysColorBrush(COLOR_3DSHADOW);
1698 /* Draw light or dark shadow */
1699 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1701 hbsave = SelectObject(hdc, hbrtmp);
1702 if(!hbsave) goto cleanup;
1703 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1704 SelectObject(hdc, hbsave);
1707 if (flags & DSS_DISABLED)
1709 hbr = GetSysColorBrush(COLOR_3DSHADOW);
1711 else if (!hbr)
1713 hbr = GetStockObject(BLACK_BRUSH);
1716 hbsave = SelectObject(hdc, hbr);
1718 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1720 retval = TRUE; /* We succeeded */
1722 cleanup:
1723 SetTextColor(hdc, fg);
1724 SetBkColor(hdc, bg);
1726 if(hbsave) SelectObject(hdc, hbsave);
1727 if(hbmsave) SelectObject(memdc, hbmsave);
1728 if(hbm) DeleteObject(hbm);
1729 if(memdc) DeleteDC(memdc);
1731 return retval;
1734 /**********************************************************************
1735 * DrawStateA (USER32.@)
1737 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1738 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1739 INT x, INT y, INT cx, INT cy, UINT flags)
1741 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1744 /**********************************************************************
1745 * DrawStateW (USER32.@)
1747 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1748 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1749 INT x, INT y, INT cx, INT cy, UINT flags)
1751 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);