d2d1/tests: Fix stroke style object leak (Valgrind).
[wine.git] / dlls / user32 / uitools.c
blob73ec34bff1ab9583bd623adf93101c2bb3cfd05a
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/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
36 /* These tables are used in:
37 * UITOOLS_DrawDiagEdge()
38 * UITOOLS_DrawRectEdge()
40 static const signed char LTInnerNormal[] = {
41 -1, -1, -1, -1,
42 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
43 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
44 -1, -1, -1, -1
47 static const signed char LTOuterNormal[] = {
48 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
49 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
50 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
51 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
54 static const signed char RBInnerNormal[] = {
55 -1, -1, -1, -1,
56 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
57 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
58 -1, -1, -1, -1
61 static const signed char RBOuterNormal[] = {
62 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
63 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
64 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
65 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
68 static const signed char LTInnerSoft[] = {
69 -1, -1, -1, -1,
70 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
71 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
72 -1, -1, -1, -1
75 static const signed char LTOuterSoft[] = {
76 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
77 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
78 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
79 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
82 #define RBInnerSoft RBInnerNormal /* These are the same */
83 #define RBOuterSoft RBOuterNormal
85 static const signed char LTRBOuterMono[] = {
86 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
87 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
88 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
89 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
92 static const signed char LTRBInnerMono[] = {
93 -1, -1, -1, -1,
94 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
95 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
96 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
99 static const signed char LTRBOuterFlat[] = {
100 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
101 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
102 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
103 COLOR_BTNFACE, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
106 static const signed char LTRBInnerFlat[] = {
107 -1, -1, -1, -1,
108 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
109 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
110 -1, COLOR_BTNFACE, COLOR_BTNFACE, COLOR_BTNFACE,
113 /* last COLOR id */
114 #define COLOR_MAX COLOR_MENUBAR
117 /***********************************************************************
118 * set_control_clipping
120 * Set clipping for a builtin control that uses CS_PARENTDC.
121 * Return the previous clip region if any.
123 HRGN set_control_clipping( HDC hdc, const RECT *rect )
125 RECT rc = *rect;
126 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
128 if (GetClipRgn( hdc, hrgn ) != 1)
130 DeleteObject( hrgn );
131 hrgn = 0;
133 DPtoLP( hdc, (POINT *)&rc, 2 );
134 if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */
136 rc.left++;
137 rc.right++;
139 IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
140 return hrgn;
143 /***********************************************************************
144 * UITOOLS_DrawDiagEdge
146 * Same as DrawEdge invoked with BF_DIAGONAL
148 * 03-Dec-1997: Changed by Bertho Stultiens
150 * See also comments with UITOOLS_DrawRectEdge()
152 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
153 UINT uType, UINT uFlags)
155 POINT Points[4];
156 signed char InnerI, OuterI;
157 HPEN InnerPen, OuterPen;
158 POINT SavePoint;
159 HPEN SavePen;
160 int spx, spy;
161 int epx, epy;
162 int Width = rc->right - rc->left;
163 int Height= rc->bottom - rc->top;
164 int SmallDiam = Width > Height ? Height : Width;
165 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
166 || (uType & BDR_OUTER) == BDR_OUTER)
167 && !(uFlags & (BF_FLAT|BF_MONO)) );
168 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
169 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
171 /* Init some vars */
172 OuterPen = InnerPen = GetStockObject(NULL_PEN);
173 SavePen = SelectObject(hdc, InnerPen);
174 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
176 /* Determine the colors of the edges */
177 if(uFlags & BF_MONO)
179 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
180 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
182 else if(uFlags & BF_FLAT)
184 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
185 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
187 else if(uFlags & BF_SOFT)
189 if(uFlags & BF_BOTTOM)
191 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
192 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
194 else
196 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
197 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
200 else
202 if(uFlags & BF_BOTTOM)
204 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
205 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
207 else
209 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
210 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
214 if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
215 if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
217 MoveToEx(hdc, 0, 0, &SavePoint);
219 /* Don't ask me why, but this is what is visible... */
220 /* This must be possible to do much simpler, but I fail to */
221 /* see the logic in the MS implementation (sigh...). */
222 /* So, this might look a bit brute force here (and it is), but */
223 /* it gets the job done;) */
225 switch(uFlags & BF_RECT)
227 case 0:
228 case BF_LEFT:
229 case BF_BOTTOM:
230 case BF_BOTTOMLEFT:
231 /* Left bottom endpoint */
232 epx = rc->left-1;
233 spx = epx + SmallDiam;
234 epy = rc->bottom;
235 spy = epy - SmallDiam;
236 break;
238 case BF_TOPLEFT:
239 case BF_BOTTOMRIGHT:
240 /* Left top endpoint */
241 epx = rc->left-1;
242 spx = epx + SmallDiam;
243 epy = rc->top-1;
244 spy = epy + SmallDiam;
245 break;
247 case BF_TOP:
248 case BF_RIGHT:
249 case BF_TOPRIGHT:
250 case BF_RIGHT|BF_LEFT:
251 case BF_RIGHT|BF_LEFT|BF_TOP:
252 case BF_BOTTOM|BF_TOP:
253 case BF_BOTTOM|BF_TOP|BF_LEFT:
254 case BF_BOTTOMRIGHT|BF_LEFT:
255 case BF_BOTTOMRIGHT|BF_TOP:
256 case BF_RECT:
257 /* Right top endpoint */
258 spx = rc->left;
259 epx = spx + SmallDiam;
260 spy = rc->bottom-1;
261 epy = spy - SmallDiam;
262 break;
265 MoveToEx(hdc, spx, spy, NULL);
266 SelectObject(hdc, OuterPen);
267 LineTo(hdc, epx, epy);
269 SelectObject(hdc, InnerPen);
271 switch(uFlags & (BF_RECT|BF_DIAGONAL))
273 case BF_DIAGONAL_ENDBOTTOMLEFT:
274 case (BF_DIAGONAL|BF_BOTTOM):
275 case BF_DIAGONAL:
276 case (BF_DIAGONAL|BF_LEFT):
277 MoveToEx(hdc, spx-1, spy, NULL);
278 LineTo(hdc, epx, epy-1);
279 Points[0].x = spx-add;
280 Points[0].y = spy;
281 Points[1].x = rc->left;
282 Points[1].y = rc->top;
283 Points[2].x = epx+1;
284 Points[2].y = epy-1-add;
285 Points[3] = Points[2];
286 break;
288 case BF_DIAGONAL_ENDBOTTOMRIGHT:
289 MoveToEx(hdc, spx-1, spy, NULL);
290 LineTo(hdc, epx, epy+1);
291 Points[0].x = spx-add;
292 Points[0].y = spy;
293 Points[1].x = rc->left;
294 Points[1].y = rc->bottom-1;
295 Points[2].x = epx+1;
296 Points[2].y = epy+1+add;
297 Points[3] = Points[2];
298 break;
300 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
301 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
302 case BF_DIAGONAL_ENDTOPRIGHT:
303 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
304 MoveToEx(hdc, spx+1, spy, NULL);
305 LineTo(hdc, epx, epy+1);
306 Points[0].x = epx-1;
307 Points[0].y = epy+1+add;
308 Points[1].x = rc->right-1;
309 Points[1].y = rc->top+add;
310 Points[2].x = rc->right-1;
311 Points[2].y = rc->bottom-1;
312 Points[3].x = spx+add;
313 Points[3].y = spy;
314 break;
316 case BF_DIAGONAL_ENDTOPLEFT:
317 MoveToEx(hdc, spx, spy-1, NULL);
318 LineTo(hdc, epx+1, epy);
319 Points[0].x = epx+1+add;
320 Points[0].y = epy+1;
321 Points[1].x = rc->right-1;
322 Points[1].y = rc->top;
323 Points[2].x = rc->right-1;
324 Points[2].y = rc->bottom-1-add;
325 Points[3].x = spx;
326 Points[3].y = spy-add;
327 break;
329 case (BF_DIAGONAL|BF_TOP):
330 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
331 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
332 MoveToEx(hdc, spx+1, spy-1, NULL);
333 LineTo(hdc, epx, epy);
334 Points[0].x = epx-1;
335 Points[0].y = epy+1;
336 Points[1].x = rc->right-1;
337 Points[1].y = rc->top;
338 Points[2].x = rc->right-1;
339 Points[2].y = rc->bottom-1-add;
340 Points[3].x = spx+add;
341 Points[3].y = spy-add;
342 break;
344 case (BF_DIAGONAL|BF_RIGHT):
345 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
346 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
347 MoveToEx(hdc, spx, spy, NULL);
348 LineTo(hdc, epx-1, epy+1);
349 Points[0].x = spx;
350 Points[0].y = spy;
351 Points[1].x = rc->left;
352 Points[1].y = rc->top+add;
353 Points[2].x = epx-1-add;
354 Points[2].y = epy+1+add;
355 Points[3] = Points[2];
356 break;
359 /* Fill the interior if asked */
360 if((uFlags & BF_MIDDLE) && retval)
362 HBRUSH hbsave;
363 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
364 :COLOR_BTNFACE);
365 HPEN hpsave;
366 HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
367 : COLOR_BTNFACE);
368 hbsave = SelectObject(hdc, hb);
369 hpsave = SelectObject(hdc, hp);
370 Polygon(hdc, Points, 4);
371 SelectObject(hdc, hbsave);
372 SelectObject(hdc, hpsave);
375 /* Adjust rectangle if asked */
376 if(uFlags & BF_ADJUST)
378 if(uFlags & BF_LEFT) rc->left += add;
379 if(uFlags & BF_RIGHT) rc->right -= add;
380 if(uFlags & BF_TOP) rc->top += add;
381 if(uFlags & BF_BOTTOM) rc->bottom -= add;
384 /* Cleanup */
385 SelectObject(hdc, SavePen);
386 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
388 return retval;
391 /***********************************************************************
392 * UITOOLS_DrawRectEdge
394 * Same as DrawEdge invoked without BF_DIAGONAL
395 * The width parameter sets the width of each outer and inner edge.
397 * 23-Nov-1997: Changed by Bertho Stultiens
399 * Well, I started testing this and found out that there are a few things
400 * that weren't quite as win95. The following rewrite should reproduce
401 * win95 results completely.
402 * The colorselection is table-driven to avoid awful if-statements.
403 * The table below show the color settings.
405 * Pen selection table for uFlags = 0
407 * uType | LTI | LTO | RBI | RBO
408 * ------+-------+-------+-------+-------
409 * 0000 | x | x | x | x
410 * 0001 | x | 22 | x | 21
411 * 0010 | x | 16 | x | 20
412 * 0011 | x | x | x | x
413 * ------+-------+-------+-------+-------
414 * 0100 | x | 20 | x | 16
415 * 0101 | 20 | 22 | 16 | 21
416 * 0110 | 20 | 16 | 16 | 20
417 * 0111 | x | x | x | x
418 * ------+-------+-------+-------+-------
419 * 1000 | x | 21 | x | 22
420 * 1001 | 21 | 22 | 22 | 21
421 * 1010 | 21 | 16 | 22 | 20
422 * 1011 | x | x | x | x
423 * ------+-------+-------+-------+-------
424 * 1100 | x | x | x | x
425 * 1101 | x | x (22)| x | x (21)
426 * 1110 | x | x (16)| x | x (20)
427 * 1111 | x | x | x | x
429 * Pen selection table for uFlags = BF_SOFT
431 * uType | LTI | LTO | RBI | RBO
432 * ------+-------+-------+-------+-------
433 * 0000 | x | x | x | x
434 * 0001 | x | 20 | x | 21
435 * 0010 | x | 21 | x | 20
436 * 0011 | x | x | x | x
437 * ------+-------+-------+-------+-------
438 * 0100 | x | 22 | x | 16
439 * 0101 | 22 | 20 | 16 | 21
440 * 0110 | 22 | 21 | 16 | 20
441 * 0111 | x | x | x | x
442 * ------+-------+-------+-------+-------
443 * 1000 | x | 16 | x | 22
444 * 1001 | 16 | 20 | 22 | 21
445 * 1010 | 16 | 21 | 22 | 20
446 * 1011 | x | x | x | x
447 * ------+-------+-------+-------+-------
448 * 1100 | x | x | x | x
449 * 1101 | x | x (20)| x | x (21)
450 * 1110 | x | x (21)| x | x (20)
451 * 1111 | x | x | x | x
453 * x = don't care; (n) = is what win95 actually uses
454 * LTI = left Top Inner line
455 * LTO = left Top Outer line
456 * RBI = Right Bottom Inner line
457 * RBO = Right Bottom Outer line
458 * 15 = COLOR_BTNFACE
459 * 16 = COLOR_BTNSHADOW
460 * 20 = COLOR_BTNHIGHLIGHT
461 * 21 = COLOR_3DDKSHADOW
462 * 22 = COLOR_3DLIGHT
466 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
467 UINT uType, UINT uFlags, UINT width)
469 signed char LTInnerI, LTOuterI;
470 signed char RBInnerI, RBOuterI;
471 HBRUSH lti_brush, lto_brush, rbi_brush, rbo_brush;
472 RECT InnerRect = *rc, fill_rect;
473 int lbi_offset = 0, lti_offset = 0, rti_offset = 0, rbi_offset = 0;
474 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
475 || (uType & BDR_OUTER) == BDR_OUTER)
476 && !(uFlags & (BF_FLAT|BF_MONO)) );
478 lti_brush = lto_brush = rbi_brush = rbo_brush = GetStockObject(NULL_BRUSH);
480 /* Determine the colors of the edges */
481 if(uFlags & BF_MONO)
483 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
484 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
486 else if(uFlags & BF_FLAT)
488 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
489 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
491 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
493 else if(uFlags & BF_SOFT)
495 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
496 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
497 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
498 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
500 else
502 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
503 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
504 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
505 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
508 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) lbi_offset = width;
509 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) rti_offset = width;
510 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) rbi_offset = width;
511 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) lti_offset = width;
513 if(LTInnerI != -1) lti_brush = GetSysColorBrush(LTInnerI);
514 if(LTOuterI != -1) lto_brush = GetSysColorBrush(LTOuterI);
515 if(RBInnerI != -1) rbi_brush = GetSysColorBrush(RBInnerI);
516 if(RBOuterI != -1) rbo_brush = GetSysColorBrush(RBOuterI);
518 /* Draw the outer edge */
519 if(uFlags & BF_TOP)
521 fill_rect = InnerRect;
522 fill_rect.bottom = fill_rect.top + width;
523 FillRect( hdc, &fill_rect, lto_brush );
525 if(uFlags & BF_LEFT)
527 fill_rect = InnerRect;
528 fill_rect.right = fill_rect.left + width;
529 FillRect( hdc, &fill_rect, lto_brush );
531 if(uFlags & BF_BOTTOM)
533 fill_rect = InnerRect;
534 fill_rect.top = fill_rect.bottom - width;
535 FillRect( hdc, &fill_rect, rbo_brush );
537 if(uFlags & BF_RIGHT)
539 fill_rect = InnerRect;
540 fill_rect.left = fill_rect.right - width;
541 FillRect( hdc, &fill_rect, rbo_brush );
544 /* Draw the inner edge */
545 if(uFlags & BF_TOP)
547 SetRect( &fill_rect, InnerRect.left + lti_offset, InnerRect.top + width,
548 InnerRect.right - rti_offset, InnerRect.top + 2 * width );
549 FillRect( hdc, &fill_rect, lti_brush );
551 if(uFlags & BF_LEFT)
553 SetRect( &fill_rect, InnerRect.left + width, InnerRect.top + lti_offset,
554 InnerRect.left + 2 * width, InnerRect.bottom - lbi_offset );
555 FillRect( hdc, &fill_rect, lti_brush );
557 if(uFlags & BF_BOTTOM)
559 SetRect( &fill_rect, InnerRect.left + lbi_offset, InnerRect.bottom - 2 * width,
560 InnerRect.right - rbi_offset, InnerRect.bottom - width );
561 FillRect( hdc, &fill_rect, rbi_brush );
563 if(uFlags & BF_RIGHT)
565 SetRect( &fill_rect, InnerRect.right - 2 * width, InnerRect.top + rti_offset,
566 InnerRect.right - width, InnerRect.bottom - rbi_offset );
567 FillRect( hdc, &fill_rect, rbi_brush );
570 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
572 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? width : 0)
573 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? width : 0);
575 if(uFlags & BF_LEFT) InnerRect.left += add;
576 if(uFlags & BF_RIGHT) InnerRect.right -= add;
577 if(uFlags & BF_TOP) InnerRect.top += add;
578 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
580 if((uFlags & BF_MIDDLE) && retval)
582 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
583 COLOR_WINDOW : COLOR_BTNFACE));
586 if(uFlags & BF_ADJUST)
587 *rc = InnerRect;
590 return retval;
594 /**********************************************************************
595 * DrawEdge (USER32.@)
597 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
599 TRACE("%p %s %04x %04x\n", hdc, wine_dbgstr_rect(rc), edge, flags );
601 if(flags & BF_DIAGONAL)
602 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
603 else
604 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags, 1);
608 /************************************************************************
609 * UITOOLS_MakeSquareRect
611 * Utility to create a square rectangle and returning the width
613 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
615 int Width = src->right - src->left;
616 int Height = src->bottom - src->top;
617 int SmallDiam = Width > Height ? Height : Width;
619 *dst = *src;
621 /* Make it a square box */
622 if(Width < Height) /* SmallDiam == Width */
624 dst->top += (Height-Width)/2;
625 dst->bottom = dst->top + SmallDiam;
627 else if(Width > Height) /* SmallDiam == Height */
629 dst->left += (Width-Height)/2;
630 dst->right = dst->left + SmallDiam;
633 return SmallDiam;
636 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
638 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
640 HBRUSH hbsave;
641 COLORREF bg;
643 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
644 bg = SetBkColor(dc, RGB(255, 255, 255));
645 hbsave = SelectObject(dc, SYSCOLOR_Get55AABrush());
646 PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
647 SelectObject(dc, hbsave);
648 SetBkColor(dc, bg);
650 else
652 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
656 /************************************************************************
657 * UITOOLS_DFC_ButtonPush
659 * Draw a push button coming from DrawFrameControl()
661 * Does a pretty good job in emulating MS behavior. Some quirks are
662 * however there because MS uses a TrueType font (Marlett) to draw
663 * the buttons.
665 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
667 UINT edge;
668 RECT myr = *r;
670 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
671 edge = EDGE_SUNKEN;
672 else
673 edge = EDGE_RAISED;
675 if(uFlags & DFCS_CHECKED)
677 if(uFlags & DFCS_MONO)
678 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST, 1);
679 else
680 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST, 1);
682 if (!(uFlags & DFCS_TRANSPARENT))
683 UITOOLS_DrawCheckedRect( dc, &myr );
685 else
687 if(uFlags & DFCS_MONO)
689 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST, 1);
690 if (!(uFlags & DFCS_TRANSPARENT))
691 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
693 else
695 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) |
696 ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT | BF_SOFT, 1);
700 /* Adjust rectangle if asked */
701 if(uFlags & DFCS_ADJUSTRECT)
702 InflateRect(r, -2, -2);
704 return TRUE;
708 /************************************************************************
709 * UITOOLS_DFC_ButtonCheck
711 * Draw a check/3state button coming from DrawFrameControl()
713 * Does a pretty good job in emulating MS behavior. Some quirks are
714 * however there because MS uses a TrueType font (Marlett) to draw
715 * the buttons.
718 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
720 RECT myr;
721 UINT flags = BF_RECT | BF_ADJUST;
723 UITOOLS_MakeSquareRect(r, &myr);
725 if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
726 else if(uFlags & DFCS_MONO) flags |= BF_MONO;
728 UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags, max( (myr.right - myr.left + 8) / 16, 1) );
730 if (!(uFlags & DFCS_TRANSPARENT))
732 if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
733 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
734 else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
735 UITOOLS_DrawCheckedRect( dc, &myr );
736 else
737 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
740 if(uFlags & DFCS_CHECKED)
742 POINT pt[6];
743 HPEN old_pen;
744 HBRUSH old_brush;
745 int color = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
746 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
748 pt[0].x = myr.right - 1;
749 pt[0].y = myr.top;
750 pt[1].x = pt[0].x;
751 pt[1].y = pt[0].y + (myr.bottom - myr.top) / 3;
752 pt[2].x = myr.left + (myr.right - myr.left) / 3;
753 pt[2].y = myr.bottom - 1;
754 pt[3].x = myr.left + 1;
755 pt[3].y = pt[2].y - (pt[2].x - pt[3].x);
756 pt[4].x = pt[3].x;
757 pt[4].y = pt[3].y - (myr.bottom - myr.top) / 3;
758 pt[5].x = pt[2].x;
759 pt[5].y = pt[2].y - (myr.bottom - myr.top) / 3;
761 old_brush = SelectObject( dc, GetSysColorBrush( color ) );
762 old_pen = SelectObject( dc, GetStockObject( NULL_PEN ));
763 Polygon( dc, pt, 6 );
764 SelectObject( dc, old_brush );
765 SelectObject( dc, old_pen );
767 return TRUE;
771 /************************************************************************
772 * UITOOLS_DFC_ButtonRadio
774 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
776 * Does a pretty good job in emulating MS behavior. Some quirks are
777 * however there because MS uses a TrueType font (Marlett) to draw
778 * the buttons.
780 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
782 RECT myr;
783 int i;
784 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
785 int BorderShrink = SmallDiam / 16;
786 HPEN hpsave;
787 HBRUSH hbsave;
788 int xc, yc;
790 if(BorderShrink < 1) BorderShrink = 1;
792 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
793 FillRect(dc, r, GetStockObject(BLACK_BRUSH));
794 else if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
795 FillRect(dc, r, GetStockObject(WHITE_BRUSH));
797 xc = myr.left + SmallDiam - SmallDiam/2;
798 yc = myr.top + SmallDiam - SmallDiam/2;
800 /* Define bounding box */
801 i = 14*SmallDiam/16;
802 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
804 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
806 hbsave = SelectObject(dc, GetStockObject(BLACK_BRUSH));
807 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
808 SelectObject(dc, hbsave);
810 else
812 if(uFlags & (DFCS_FLAT|DFCS_MONO))
814 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
815 hbsave = SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
816 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
817 SelectObject(dc, hbsave);
818 SelectObject(dc, hpsave);
820 else
822 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
823 hbsave = 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 InflateRect(&myr, -BorderShrink, -BorderShrink);
831 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
832 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
833 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
835 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
836 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
837 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
838 SelectObject(dc, hbsave);
839 SelectObject(dc, hpsave);
842 i = 10*SmallDiam/16;
843 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
844 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
845 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
846 hbsave = SelectObject(dc, GetSysColorBrush(i));
847 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
848 SelectObject(dc, hbsave);
849 SelectObject(dc, hpsave);
852 if(uFlags & DFCS_CHECKED)
854 i = 6*SmallDiam/16;
855 i = i < 1 ? 1 : i;
856 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
858 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
859 hbsave = SelectObject(dc, GetSysColorBrush(i));
860 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
861 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
862 SelectObject(dc, hpsave);
863 SelectObject(dc, hbsave);
866 /* FIXME: M$ has a polygon in the center at relative points: */
867 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
868 /* 0.476, 0.525 */
869 /* 0.500, 0.500 */
870 /* 0.500, 0.499 */
871 /* when the button is unchecked. The reason for it is unknown. The */
872 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
873 /* least 3 times (it looks like a clip-region when you see it happen). */
874 /* I do not really see a reason why this should be implemented. If you */
875 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
876 /* font. */
878 return TRUE;
881 /***********************************************************************
882 * UITOOLS_DrawFrameButton
884 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
886 switch(uState & 0xff)
888 case DFCS_BUTTONPUSH:
889 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
891 case DFCS_BUTTONCHECK:
892 case DFCS_BUTTON3STATE:
893 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
895 case DFCS_BUTTONRADIOIMAGE:
896 case DFCS_BUTTONRADIOMASK:
897 case DFCS_BUTTONRADIO:
898 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
900 default:
901 WARN("Invalid button state=0x%04x\n", uState);
904 return FALSE;
907 /***********************************************************************
908 * UITOOLS_DrawFrameCaption
910 * Draw caption buttons (win95), coming from DrawFrameControl()
913 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
915 RECT myr;
916 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
917 HFONT hfsave, hf;
918 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
919 int xc = (myr.left+myr.right)/2;
920 int yc = (myr.top+myr.bottom)/2;
921 WCHAR str[] = {0, 0};
922 static const WCHAR glyphFontName[] = { 'M','a','r','l','e','t','t',0 };
923 UINT alignsave;
924 int bksave;
925 COLORREF clrsave;
926 SIZE size;
928 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
930 switch(uFlags & 0xf)
932 case DFCS_CAPTIONCLOSE: str[0] = 0x72; break;
933 case DFCS_CAPTIONHELP: str[0] = 0x73; break;
934 case DFCS_CAPTIONMIN: str[0] = 0x30; break;
935 case DFCS_CAPTIONMAX: str[0] = 0x31; break;
936 case DFCS_CAPTIONRESTORE: str[0] = 0x32; break;
937 default:
938 WARN("Invalid caption; flags=0x%04x\n", uFlags);
939 return FALSE;
942 hf = CreateFontW(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
943 SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
944 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, glyphFontName);
945 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
946 bksave = SetBkMode(dc, TRANSPARENT);
947 clrsave = GetTextColor(dc);
948 hfsave = SelectObject(dc, hf);
949 GetTextExtentPoint32W(dc, str, 1, &size);
951 if(uFlags & DFCS_INACTIVE)
953 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
954 TextOutW(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
956 SetTextColor(dc, GetSysColor(colorIdx));
957 TextOutW(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
959 SelectObject(dc, hfsave);
960 SetTextColor(dc, clrsave);
961 SetBkMode(dc, bksave);
962 SetTextAlign(dc, alignsave);
963 DeleteObject(hf);
965 return TRUE;
969 /************************************************************************
970 * UITOOLS_DrawFrameScroll
972 * Draw a scroll-bar control coming from DrawFrameControl()
974 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
976 POINT Line[4];
977 RECT myr;
978 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
979 int i;
980 HBRUSH hbsave, hb, hb2;
981 HPEN hpsave, hp, hp2;
982 int tri = 290*SmallDiam/1000 - 1;
983 int d46, d93;
986 * This fixes a problem with really tiny "scroll" buttons. In particular
987 * with the updown control.
988 * Making sure that the arrow is as least 3 pixels wide (or high).
990 tri = max( 2, tri );
992 switch(uFlags & 0xff)
994 case DFCS_SCROLLCOMBOBOX:
995 case DFCS_SCROLLDOWN:
996 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
997 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
998 Line[0].x = Line[2].x - tri;
999 Line[1].x = Line[2].x + tri;
1000 Line[0].y = Line[1].y = Line[2].y - tri;
1001 break;
1003 case DFCS_SCROLLUP:
1004 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1005 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
1006 Line[0].x = Line[2].x - tri;
1007 Line[1].x = Line[2].x + tri;
1008 Line[0].y = Line[1].y = Line[2].y + tri;
1009 break;
1011 case DFCS_SCROLLLEFT:
1012 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1013 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1014 Line[0].y = Line[2].y - tri;
1015 Line[1].y = Line[2].y + tri;
1016 Line[0].x = Line[1].x = Line[2].x + tri;
1017 break;
1019 case DFCS_SCROLLRIGHT:
1020 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1021 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1022 Line[0].y = Line[2].y - tri;
1023 Line[1].y = Line[2].y + tri;
1024 Line[0].x = Line[1].x = Line[2].x - tri;
1025 break;
1027 case DFCS_SCROLLSIZEGRIP:
1028 /* This one breaks the flow... */
1029 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0), 1);
1030 hpsave = SelectObject(dc, GetStockObject(NULL_PEN));
1031 hbsave = SelectObject(dc, GetStockObject(NULL_BRUSH));
1032 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1034 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1035 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1037 else
1039 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1040 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1041 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1042 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1044 Line[0].x = Line[1].x = r->right-1;
1045 Line[2].y = Line[3].y = r->bottom-1;
1046 d46 = 46*SmallDiam/750;
1047 d93 = 93*SmallDiam/750;
1049 i = 586*SmallDiam/750;
1050 Line[0].y = r->bottom - i - 1;
1051 Line[3].x = r->right - i - 1;
1052 Line[1].y = Line[0].y + d46;
1053 Line[2].x = Line[3].x + d46;
1054 SelectObject(dc, hb);
1055 SelectObject(dc, hp);
1056 Polygon(dc, Line, 4);
1058 Line[1].y++; Line[2].x++;
1059 Line[0].y = Line[1].y + d93;
1060 Line[3].x = Line[2].x + d93;
1061 SelectObject(dc, hb2);
1062 SelectObject(dc, hp2);
1063 Polygon(dc, Line, 4);
1065 i = 398*SmallDiam/750;
1066 Line[0].y = r->bottom - i - 1;
1067 Line[3].x = r->right - i - 1;
1068 Line[1].y = Line[0].y + d46;
1069 Line[2].x = Line[3].x + d46;
1070 SelectObject(dc, hb);
1071 SelectObject(dc, hp);
1072 Polygon(dc, Line, 4);
1074 Line[1].y++; Line[2].x++;
1075 Line[0].y = Line[1].y + d93;
1076 Line[3].x = Line[2].x + d93;
1077 SelectObject(dc, hb2);
1078 SelectObject(dc, hp2);
1079 Polygon(dc, Line, 4);
1081 i = 210*SmallDiam/750;
1082 Line[0].y = r->bottom - i - 1;
1083 Line[3].x = r->right - i - 1;
1084 Line[1].y = Line[0].y + d46;
1085 Line[2].x = Line[3].x + d46;
1086 SelectObject(dc, hb);
1087 SelectObject(dc, hp);
1088 Polygon(dc, Line, 4);
1090 Line[1].y++; Line[2].x++;
1091 Line[0].y = Line[1].y + d93;
1092 Line[3].x = Line[2].x + d93;
1093 SelectObject(dc, hb2);
1094 SelectObject(dc, hp2);
1095 Polygon(dc, Line, 4);
1097 SelectObject(dc, hpsave);
1098 SelectObject(dc, hbsave);
1099 return TRUE;
1101 default:
1102 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1103 return FALSE;
1106 /* Here do the real scroll-bar controls end up */
1107 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1108 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1109 /* want for the normal scroll-arrow button. */
1110 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT, 1);
1111 else
1112 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1114 if(uFlags & DFCS_INACTIVE)
1116 hbsave = SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1117 hpsave = SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1118 Polygon(dc, Line, 3);
1119 SelectObject(dc, hpsave);
1120 SelectObject(dc, hbsave);
1123 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1124 for(i = 0; i < 3; i++)
1126 Line[i].x--;
1127 Line[i].y--;
1130 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1131 hbsave = SelectObject(dc, GetSysColorBrush(i));
1132 hpsave = SelectObject(dc, SYSCOLOR_GetPen(i));
1133 Polygon(dc, Line, 3);
1134 SelectObject(dc, hpsave);
1135 SelectObject(dc, hbsave);
1137 return TRUE;
1140 /************************************************************************
1141 * UITOOLS_DrawFrameMenu
1143 * Draw a menu control coming from DrawFrameControl()
1145 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1147 POINT Points[6];
1148 RECT myr;
1149 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1150 int i;
1151 HBRUSH hbsave;
1152 HPEN hpsave;
1153 int xe, ye;
1154 int xc, yc;
1155 BOOL retval = TRUE;
1157 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1158 /* use anything else. I think I tried all sys-colors to change things */
1159 /* without luck. It seems as if this behavior is inherited from the */
1160 /* win31 DFC() implementation... (you remember, B/W menus). */
1162 FillRect(dc, r, GetStockObject(WHITE_BRUSH));
1164 hbsave = SelectObject(dc, GetStockObject(BLACK_BRUSH));
1165 hpsave = SelectObject(dc, GetStockObject(BLACK_PEN));
1167 switch(uFlags & 0xff)
1169 case DFCS_MENUARROW:
1170 i = 187*SmallDiam/750;
1171 Points[2].x = myr.left + 468*SmallDiam/750;
1172 Points[2].y = myr.top + 352*SmallDiam/750+1;
1173 Points[0].y = Points[2].y - i;
1174 Points[1].y = Points[2].y + i;
1175 Points[0].x = Points[1].x = Points[2].x - i;
1176 Polygon(dc, Points, 3);
1177 break;
1179 case DFCS_MENUBULLET:
1180 xe = myr.left;
1181 ye = myr.top + SmallDiam - SmallDiam/2;
1182 xc = myr.left + SmallDiam - SmallDiam/2;
1183 yc = myr.top + SmallDiam - SmallDiam/2;
1184 i = 234*SmallDiam/750;
1185 i = i < 1 ? 1 : i;
1186 SetRect(&myr, xc - i + i / 2, yc - i + i / 2, xc + i / 2, yc + i / 2);
1187 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1188 break;
1190 case DFCS_MENUCHECK:
1191 Points[0].x = myr.left + 253*SmallDiam/1000;
1192 Points[0].y = myr.top + 445*SmallDiam/1000;
1193 Points[1].x = myr.left + 409*SmallDiam/1000;
1194 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1195 Points[2].x = myr.left + 690*SmallDiam/1000;
1196 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1197 Points[3].x = Points[2].x;
1198 Points[3].y = Points[2].y + 3*SmallDiam/16;
1199 Points[4].x = Points[1].x;
1200 Points[4].y = Points[1].y + 3*SmallDiam/16;
1201 Points[5].x = Points[0].x;
1202 Points[5].y = Points[0].y + 3*SmallDiam/16;
1203 Polygon(dc, Points, 6);
1204 break;
1206 default:
1207 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1208 retval = FALSE;
1209 break;
1212 SelectObject(dc, hpsave);
1213 SelectObject(dc, hbsave);
1214 return retval;
1218 /**********************************************************************
1219 * DrawFrameControl (USER32.@)
1221 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1222 UINT uState )
1224 switch(uType)
1226 case DFC_BUTTON:
1227 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1228 case DFC_CAPTION:
1229 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1230 case DFC_MENU:
1231 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1232 /*case DFC_POPUPMENU:
1233 FIXME("DFC_POPUPMENU: not implemented\n");
1234 break;*/
1235 case DFC_SCROLL:
1236 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1237 default:
1238 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1240 return FALSE;
1244 /***********************************************************************
1245 * SetRect (USER32.@)
1247 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
1248 INT right, INT bottom )
1250 if (!rect) return FALSE;
1251 rect->left = left;
1252 rect->right = right;
1253 rect->top = top;
1254 rect->bottom = bottom;
1255 return TRUE;
1259 /***********************************************************************
1260 * SetRectEmpty (USER32.@)
1262 BOOL WINAPI SetRectEmpty( LPRECT rect )
1264 if (!rect) return FALSE;
1265 rect->left = rect->right = rect->top = rect->bottom = 0;
1266 return TRUE;
1270 /***********************************************************************
1271 * CopyRect (USER32.@)
1273 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
1275 if (!dest || !src) return FALSE;
1276 *dest = *src;
1277 return TRUE;
1281 /***********************************************************************
1282 * IsRectEmpty (USER32.@)
1284 * Bug compat: Windows checks for 0 or negative width/height.
1286 BOOL WINAPI IsRectEmpty( const RECT *rect )
1288 if (!rect) return TRUE;
1289 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
1293 /***********************************************************************
1294 * PtInRect (USER32.@)
1296 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
1298 if (!rect) return FALSE;
1299 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
1300 (pt.y >= rect->top) && (pt.y < rect->bottom));
1304 /***********************************************************************
1305 * OffsetRect (USER32.@)
1307 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
1309 if (!rect) return FALSE;
1310 rect->left += x;
1311 rect->right += x;
1312 rect->top += y;
1313 rect->bottom += y;
1314 return TRUE;
1318 /***********************************************************************
1319 * InflateRect (USER32.@)
1321 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
1323 if (!rect) return FALSE;
1324 rect->left -= x;
1325 rect->top -= y;
1326 rect->right += x;
1327 rect->bottom += y;
1328 return TRUE;
1332 /***********************************************************************
1333 * IntersectRect (USER32.@)
1335 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1337 if (!dest || !src1 || !src2) return FALSE;
1338 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
1339 (src1->left >= src2->right) || (src2->left >= src1->right) ||
1340 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
1342 SetRectEmpty( dest );
1343 return FALSE;
1345 dest->left = max( src1->left, src2->left );
1346 dest->right = min( src1->right, src2->right );
1347 dest->top = max( src1->top, src2->top );
1348 dest->bottom = min( src1->bottom, src2->bottom );
1349 return TRUE;
1353 /***********************************************************************
1354 * UnionRect (USER32.@)
1356 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1358 if (!dest) return FALSE;
1359 if (IsRectEmpty(src1))
1361 if (IsRectEmpty(src2))
1363 SetRectEmpty( dest );
1364 return FALSE;
1366 else *dest = *src2;
1368 else
1370 if (IsRectEmpty(src2)) *dest = *src1;
1371 else
1373 dest->left = min( src1->left, src2->left );
1374 dest->right = max( src1->right, src2->right );
1375 dest->top = min( src1->top, src2->top );
1376 dest->bottom = max( src1->bottom, src2->bottom );
1379 return TRUE;
1383 /***********************************************************************
1384 * EqualRect (USER32.@)
1386 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
1388 if (!rect1 || !rect2) return FALSE;
1389 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1390 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1394 /***********************************************************************
1395 * SubtractRect (USER32.@)
1397 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1399 RECT tmp;
1401 if (!dest) return FALSE;
1402 if (IsRectEmpty( src1 ))
1404 SetRectEmpty( dest );
1405 return FALSE;
1407 if (IntersectRect( &tmp, src1, src2 ))
1409 if (EqualRect( &tmp, src1 ))
1411 SetRectEmpty( dest );
1412 return FALSE;
1414 *dest = *src1;
1415 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1417 if (tmp.left == dest->left) dest->left = tmp.right;
1418 else if (tmp.right == dest->right) dest->right = tmp.left;
1420 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1422 if (tmp.top == dest->top) dest->top = tmp.bottom;
1423 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1426 else
1428 *dest = *src1;
1430 return TRUE;
1434 /***********************************************************************
1435 * FillRect (USER32.@)
1437 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1439 HBRUSH prev_brush;
1441 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( HandleToULong(hbrush) - 1 );
1443 prev_brush = SelectObject( hdc, hbrush );
1444 PatBlt( hdc, rect->left, rect->top,
1445 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1446 if (prev_brush) SelectObject( hdc, prev_brush );
1447 return 1;
1451 /***********************************************************************
1452 * InvertRect (USER32.@)
1454 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1456 return PatBlt( hdc, rect->left, rect->top,
1457 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1461 /***********************************************************************
1462 * FrameRect (USER32.@)
1464 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1466 HBRUSH prevBrush;
1467 RECT r = *rect;
1469 if (IsRectEmpty(&r)) return 0;
1470 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1472 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1473 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1474 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1475 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1477 SelectObject( hdc, prevBrush );
1478 return TRUE;
1482 /***********************************************************************
1483 * DrawFocusRect (USER32.@)
1485 * FIXME: PatBlt(PATINVERT) with background brush.
1487 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1489 HBRUSH hOldBrush;
1490 HPEN hOldPen, hNewPen;
1491 INT oldDrawMode, oldBkMode;
1492 LOGBRUSH lb;
1494 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1495 lb.lbStyle = BS_SOLID;
1496 lb.lbColor = 0;
1497 hNewPen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL);
1498 hOldPen = SelectObject(hdc, hNewPen);
1499 oldDrawMode = SetROP2(hdc, R2_NOT);
1500 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1502 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1504 SetBkMode(hdc, oldBkMode);
1505 SetROP2(hdc, oldDrawMode);
1506 SelectObject(hdc, hOldPen);
1507 DeleteObject(hNewPen);
1508 SelectObject(hdc, hOldBrush);
1510 return TRUE;
1514 /**********************************************************************
1515 * DrawAnimatedRects (USER32.@)
1517 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1519 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1520 return TRUE;
1524 /**********************************************************************
1525 * UITOOLS_DrawStateJam
1527 * Jams in the requested type in the dc
1529 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1530 LPRECT rc, UINT dtflags, BOOL unicode )
1532 HDC memdc;
1533 HBITMAP hbmsave;
1534 BOOL retval;
1535 INT cx = rc->right - rc->left;
1536 INT cy = rc->bottom - rc->top;
1538 switch(opcode)
1540 case DST_TEXT:
1541 case DST_PREFIXTEXT:
1542 if(unicode)
1543 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1544 else
1545 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1547 case DST_ICON:
1548 return DrawIconEx(hdc, rc->left, rc->top, (HICON)lp, 0, 0, 0, NULL, DI_NORMAL);
1550 case DST_BITMAP:
1551 memdc = CreateCompatibleDC(hdc);
1552 if(!memdc) return FALSE;
1553 hbmsave = SelectObject(memdc, (HBITMAP)lp);
1554 if(!hbmsave)
1556 DeleteDC(memdc);
1557 return FALSE;
1559 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1560 SelectObject(memdc, hbmsave);
1561 DeleteDC(memdc);
1562 return retval;
1564 case DST_COMPLEX:
1565 if(func) {
1566 BOOL bRet;
1567 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1569 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1570 bRet = func(hdc, lp, wp, cx, cy);
1571 /* Restore origin */
1572 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1573 return bRet;
1574 } else
1575 return FALSE;
1577 return FALSE;
1580 /**********************************************************************
1581 * UITOOLS_DrawState()
1583 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1584 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1586 HBITMAP hbm, hbmsave;
1587 HFONT hfsave;
1588 HBRUSH hbsave, hbrtmp = 0;
1589 HDC memdc;
1590 RECT rc;
1591 UINT dtflags = DT_NOCLIP;
1592 COLORREF fg, bg;
1593 UINT opcode = flags & 0xf;
1594 INT len = wp;
1595 BOOL retval, tmp;
1597 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1599 if (!lp) return FALSE;
1601 if(unicode)
1602 len = strlenW((LPWSTR)lp);
1603 else
1604 len = strlen((LPSTR)lp);
1607 /* Find out what size the image has if not given by caller */
1608 if(!cx || !cy)
1610 SIZE s;
1611 BITMAP bm;
1613 switch(opcode)
1615 case DST_TEXT:
1616 case DST_PREFIXTEXT:
1617 if(unicode)
1618 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1619 else
1620 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1621 if(!retval) return FALSE;
1622 break;
1624 case DST_ICON:
1625 if (!get_icon_size( (HICON)lp, &s )) return FALSE;
1626 break;
1628 case DST_BITMAP:
1629 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1630 s.cx = bm.bmWidth;
1631 s.cy = bm.bmHeight;
1632 break;
1634 case DST_COMPLEX: /* cx and cy must be set in this mode */
1635 return FALSE;
1638 if(!cx) cx = s.cx;
1639 if(!cy) cy = s.cy;
1642 SetRect(&rc, x, y, x + cx, y + cy);
1644 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1645 dtflags |= DT_RIGHT;
1646 if(opcode == DST_TEXT)
1647 dtflags |= DT_NOPREFIX;
1649 /* For DSS_NORMAL we just jam in the image and return */
1650 if((flags & 0x7ff0) == DSS_NORMAL)
1652 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1655 /* For all other states we need to convert the image to B/W in a local bitmap */
1656 /* before it is displayed */
1657 fg = SetTextColor(hdc, RGB(0, 0, 0));
1658 bg = SetBkColor(hdc, RGB(255, 255, 255));
1659 hbm = NULL; hbmsave = NULL;
1660 memdc = NULL; hbsave = NULL;
1661 retval = FALSE; /* assume failure */
1663 /* From here on we must use "goto cleanup" when something goes wrong */
1664 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1665 if(!hbm) goto cleanup;
1666 memdc = CreateCompatibleDC(hdc);
1667 if(!memdc) goto cleanup;
1668 hbmsave = SelectObject(memdc, hbm);
1669 if(!hbmsave) goto cleanup;
1670 SetRect(&rc, 0, 0, cx, cy);
1671 if(!FillRect(memdc, &rc, GetStockObject(WHITE_BRUSH))) goto cleanup;
1672 SetBkColor(memdc, RGB(255, 255, 255));
1673 SetTextColor(memdc, RGB(0, 0, 0));
1674 hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1675 SetLayout( memdc, GetLayout( hdc ));
1677 /* DST_COMPLEX may draw text as well,
1678 * so we must be sure that correct font is selected
1680 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1681 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1682 if(hfsave) SelectObject(memdc, hfsave);
1683 if(!tmp) goto cleanup;
1685 /* This state cause the image to be dithered */
1686 if(flags & DSS_UNION)
1688 hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
1689 if(!hbsave) goto cleanup;
1690 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1691 SelectObject(memdc, hbsave);
1692 if(!tmp) goto cleanup;
1695 if (flags & DSS_DISABLED)
1696 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1697 else if (flags & DSS_DEFAULT)
1698 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1700 /* Draw light or dark shadow */
1701 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1703 if(!hbrtmp) goto cleanup;
1704 hbsave = SelectObject(hdc, hbrtmp);
1705 if(!hbsave) goto cleanup;
1706 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1707 SelectObject(hdc, hbsave);
1708 DeleteObject(hbrtmp);
1709 hbrtmp = 0;
1712 if (flags & DSS_DISABLED)
1714 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1715 if(!hbrtmp) goto cleanup;
1717 else if (!hbr)
1719 hbr = GetStockObject(BLACK_BRUSH);
1722 hbsave = SelectObject(hdc, hbr);
1724 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1726 retval = TRUE; /* We succeeded */
1728 cleanup:
1729 SetTextColor(hdc, fg);
1730 SetBkColor(hdc, bg);
1732 if(hbsave) SelectObject(hdc, hbsave);
1733 if(hbmsave) SelectObject(memdc, hbmsave);
1734 if(hbrtmp) DeleteObject(hbrtmp);
1735 if(hbm) DeleteObject(hbm);
1736 if(memdc) DeleteDC(memdc);
1738 return retval;
1741 /**********************************************************************
1742 * DrawStateA (USER32.@)
1744 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1745 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1746 INT x, INT y, INT cx, INT cy, UINT flags)
1748 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1751 /**********************************************************************
1752 * DrawStateW (USER32.@)
1754 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1755 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1756 INT x, INT y, INT cx, INT cy, UINT flags)
1758 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);