user/tests: Remove todo_wine from a few tests that (usually) succeed.
[wine/multimedia.git] / dlls / user / uitools.c
blobbe2384151202a77d0ed00cff9a78f3a07e1789d7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "wine/winuser16.h"
28 #include "winuser.h"
29 #include "user_private.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
35 /* These tables are used in:
36 * UITOOLS_DrawDiagEdge()
37 * UITOOLS_DrawRectEdge()
39 static const signed char LTInnerNormal[] = {
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 * UITOOLS_DrawDiagEdge
119 * Same as DrawEdge invoked with BF_DIAGONAL
121 * 03-Dec-1997: Changed by Bertho Stultiens
123 * See also comments with UITOOLS_DrawRectEdge()
125 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
126 UINT uType, UINT uFlags)
128 POINT Points[4];
129 signed char InnerI, OuterI;
130 HPEN InnerPen, OuterPen;
131 POINT SavePoint;
132 HPEN SavePen;
133 int spx, spy;
134 int epx, epy;
135 int Width = rc->right - rc->left;
136 int Height= rc->bottom - rc->top;
137 int SmallDiam = Width > Height ? Height : Width;
138 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
139 || (uType & BDR_OUTER) == BDR_OUTER)
140 && !(uFlags & (BF_FLAT|BF_MONO)) );
141 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
142 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
144 /* Init some vars */
145 OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
146 SavePen = (HPEN)SelectObject(hdc, InnerPen);
147 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
149 /* Determine the colors of the edges */
150 if(uFlags & BF_MONO)
152 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
153 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
155 else if(uFlags & BF_FLAT)
157 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
158 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
160 else if(uFlags & BF_SOFT)
162 if(uFlags & BF_BOTTOM)
164 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
165 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
167 else
169 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
170 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
173 else
175 if(uFlags & BF_BOTTOM)
177 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
178 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
180 else
182 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
183 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
187 if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
188 if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
190 MoveToEx(hdc, 0, 0, &SavePoint);
192 /* Don't ask me why, but this is what is visible... */
193 /* This must be possible to do much simpler, but I fail to */
194 /* see the logic in the MS implementation (sigh...). */
195 /* So, this might look a bit brute force here (and it is), but */
196 /* it gets the job done;) */
198 switch(uFlags & BF_RECT)
200 case 0:
201 case BF_LEFT:
202 case BF_BOTTOM:
203 case BF_BOTTOMLEFT:
204 /* Left bottom endpoint */
205 epx = rc->left-1;
206 spx = epx + SmallDiam;
207 epy = rc->bottom;
208 spy = epy - SmallDiam;
209 break;
211 case BF_TOPLEFT:
212 case BF_BOTTOMRIGHT:
213 /* Left top endpoint */
214 epx = rc->left-1;
215 spx = epx + SmallDiam;
216 epy = rc->top-1;
217 spy = epy + SmallDiam;
218 break;
220 case BF_TOP:
221 case BF_RIGHT:
222 case BF_TOPRIGHT:
223 case BF_RIGHT|BF_LEFT:
224 case BF_RIGHT|BF_LEFT|BF_TOP:
225 case BF_BOTTOM|BF_TOP:
226 case BF_BOTTOM|BF_TOP|BF_LEFT:
227 case BF_BOTTOMRIGHT|BF_LEFT:
228 case BF_BOTTOMRIGHT|BF_TOP:
229 case BF_RECT:
230 /* Right top endpoint */
231 spx = rc->left;
232 epx = spx + SmallDiam;
233 spy = rc->bottom-1;
234 epy = spy - SmallDiam;
235 break;
238 MoveToEx(hdc, spx, spy, NULL);
239 SelectObject(hdc, OuterPen);
240 LineTo(hdc, epx, epy);
242 SelectObject(hdc, InnerPen);
244 switch(uFlags & (BF_RECT|BF_DIAGONAL))
246 case BF_DIAGONAL_ENDBOTTOMLEFT:
247 case (BF_DIAGONAL|BF_BOTTOM):
248 case BF_DIAGONAL:
249 case (BF_DIAGONAL|BF_LEFT):
250 MoveToEx(hdc, spx-1, spy, NULL);
251 LineTo(hdc, epx, epy-1);
252 Points[0].x = spx-add;
253 Points[0].y = spy;
254 Points[1].x = rc->left;
255 Points[1].y = rc->top;
256 Points[2].x = epx+1;
257 Points[2].y = epy-1-add;
258 Points[3] = Points[2];
259 break;
261 case BF_DIAGONAL_ENDBOTTOMRIGHT:
262 MoveToEx(hdc, spx-1, spy, NULL);
263 LineTo(hdc, epx, epy+1);
264 Points[0].x = spx-add;
265 Points[0].y = spy;
266 Points[1].x = rc->left;
267 Points[1].y = rc->bottom-1;
268 Points[2].x = epx+1;
269 Points[2].y = epy+1+add;
270 Points[3] = Points[2];
271 break;
273 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
274 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
275 case BF_DIAGONAL_ENDTOPRIGHT:
276 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
277 MoveToEx(hdc, spx+1, spy, NULL);
278 LineTo(hdc, epx, epy+1);
279 Points[0].x = epx-1;
280 Points[0].y = epy+1+add;
281 Points[1].x = rc->right-1;
282 Points[1].y = rc->top+add;
283 Points[2].x = rc->right-1;
284 Points[2].y = rc->bottom-1;
285 Points[3].x = spx+add;
286 Points[3].y = spy;
287 break;
289 case BF_DIAGONAL_ENDTOPLEFT:
290 MoveToEx(hdc, spx, spy-1, NULL);
291 LineTo(hdc, epx+1, epy);
292 Points[0].x = epx+1+add;
293 Points[0].y = epy+1;
294 Points[1].x = rc->right-1;
295 Points[1].y = rc->top;
296 Points[2].x = rc->right-1;
297 Points[2].y = rc->bottom-1-add;
298 Points[3].x = spx;
299 Points[3].y = spy-add;
300 break;
302 case (BF_DIAGONAL|BF_TOP):
303 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
304 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
305 MoveToEx(hdc, spx+1, spy-1, NULL);
306 LineTo(hdc, epx, epy);
307 Points[0].x = epx-1;
308 Points[0].y = epy+1;
309 Points[1].x = rc->right-1;
310 Points[1].y = rc->top;
311 Points[2].x = rc->right-1;
312 Points[2].y = rc->bottom-1-add;
313 Points[3].x = spx+add;
314 Points[3].y = spy-add;
315 break;
317 case (BF_DIAGONAL|BF_RIGHT):
318 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
319 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
320 MoveToEx(hdc, spx, spy, NULL);
321 LineTo(hdc, epx-1, epy+1);
322 Points[0].x = spx;
323 Points[0].y = spy;
324 Points[1].x = rc->left;
325 Points[1].y = rc->top+add;
326 Points[2].x = epx-1-add;
327 Points[2].y = epy+1+add;
328 Points[3] = Points[2];
329 break;
332 /* Fill the interior if asked */
333 if((uFlags & BF_MIDDLE) && retval)
335 HBRUSH hbsave;
336 HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
337 :COLOR_BTNFACE);
338 HPEN hpsave;
339 HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
340 : COLOR_BTNFACE);
341 hbsave = (HBRUSH)SelectObject(hdc, hb);
342 hpsave = (HPEN)SelectObject(hdc, hp);
343 Polygon(hdc, Points, 4);
344 SelectObject(hdc, hbsave);
345 SelectObject(hdc, hpsave);
348 /* Adjust rectangle if asked */
349 if(uFlags & BF_ADJUST)
351 if(uFlags & BF_LEFT) rc->left += add;
352 if(uFlags & BF_RIGHT) rc->right -= add;
353 if(uFlags & BF_TOP) rc->top += add;
354 if(uFlags & BF_BOTTOM) rc->bottom -= add;
357 /* Cleanup */
358 SelectObject(hdc, SavePen);
359 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
361 return retval;
364 /***********************************************************************
365 * UITOOLS_DrawRectEdge
367 * Same as DrawEdge invoked without BF_DIAGONAL
369 * 23-Nov-1997: Changed by Bertho Stultiens
371 * Well, I started testing this and found out that there are a few things
372 * that weren't quite as win95. The following rewrite should reproduce
373 * win95 results completely.
374 * The colorselection is table-driven to avoid awfull if-statements.
375 * The table below show the color settings.
377 * Pen selection table for uFlags = 0
379 * uType | LTI | LTO | RBI | RBO
380 * ------+-------+-------+-------+-------
381 * 0000 | x | x | x | x
382 * 0001 | x | 22 | x | 21
383 * 0010 | x | 16 | x | 20
384 * 0011 | x | x | x | x
385 * ------+-------+-------+-------+-------
386 * 0100 | x | 20 | x | 16
387 * 0101 | 20 | 22 | 16 | 21
388 * 0110 | 20 | 16 | 16 | 20
389 * 0111 | x | x | x | x
390 * ------+-------+-------+-------+-------
391 * 1000 | x | 21 | x | 22
392 * 1001 | 21 | 22 | 22 | 21
393 * 1010 | 21 | 16 | 22 | 20
394 * 1011 | x | x | x | x
395 * ------+-------+-------+-------+-------
396 * 1100 | x | x | x | x
397 * 1101 | x | x (22)| x | x (21)
398 * 1110 | x | x (16)| x | x (20)
399 * 1111 | x | x | x | x
401 * Pen selection table for uFlags = BF_SOFT
403 * uType | LTI | LTO | RBI | RBO
404 * ------+-------+-------+-------+-------
405 * 0000 | x | x | x | x
406 * 0001 | x | 20 | x | 21
407 * 0010 | x | 21 | x | 20
408 * 0011 | x | x | x | x
409 * ------+-------+-------+-------+-------
410 * 0100 | x | 22 | x | 16
411 * 0101 | 22 | 20 | 16 | 21
412 * 0110 | 22 | 21 | 16 | 20
413 * 0111 | x | x | x | x
414 * ------+-------+-------+-------+-------
415 * 1000 | x | 16 | x | 22
416 * 1001 | 16 | 20 | 22 | 21
417 * 1010 | 16 | 21 | 22 | 20
418 * 1011 | x | x | x | x
419 * ------+-------+-------+-------+-------
420 * 1100 | x | x | x | x
421 * 1101 | x | x (20)| x | x (21)
422 * 1110 | x | x (21)| x | x (20)
423 * 1111 | x | x | x | x
425 * x = don't care; (n) = is what win95 actually uses
426 * LTI = left Top Inner line
427 * LTO = left Top Outer line
428 * RBI = Right Bottom Inner line
429 * RBO = Right Bottom Outer line
430 * 15 = COLOR_BTNFACE
431 * 16 = COLOR_BTNSHADOW
432 * 20 = COLOR_BTNHIGHLIGHT
433 * 21 = COLOR_3DDKSHADOW
434 * 22 = COLOR_3DLIGHT
438 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
439 UINT uType, UINT uFlags)
441 signed char LTInnerI, LTOuterI;
442 signed char RBInnerI, RBOuterI;
443 HPEN LTInnerPen, LTOuterPen;
444 HPEN RBInnerPen, RBOuterPen;
445 RECT InnerRect = *rc;
446 POINT SavePoint;
447 HPEN SavePen;
448 int LBpenplus = 0;
449 int LTpenplus = 0;
450 int RTpenplus = 0;
451 int RBpenplus = 0;
452 BOOL retval = !( ((uType & BDR_INNER) == BDR_INNER
453 || (uType & BDR_OUTER) == BDR_OUTER)
454 && !(uFlags & (BF_FLAT|BF_MONO)) );
456 /* Init some vars */
457 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
458 SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
460 /* Determine the colors of the edges */
461 if(uFlags & BF_MONO)
463 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
464 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
466 else if(uFlags & BF_FLAT)
468 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
469 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
471 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
473 else if(uFlags & BF_SOFT)
475 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
476 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
477 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
478 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
480 else
482 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
483 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
484 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
485 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
488 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
489 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
490 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
491 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
493 if(LTInnerI != -1) LTInnerPen = SYSCOLOR_GetPen(LTInnerI);
494 if(LTOuterI != -1) LTOuterPen = SYSCOLOR_GetPen(LTOuterI);
495 if(RBInnerI != -1) RBInnerPen = SYSCOLOR_GetPen(RBInnerI);
496 if(RBOuterI != -1) RBOuterPen = SYSCOLOR_GetPen(RBOuterI);
498 MoveToEx(hdc, 0, 0, &SavePoint);
500 /* Draw the outer edge */
501 SelectObject(hdc, LTOuterPen);
502 if(uFlags & BF_TOP)
504 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
505 LineTo(hdc, InnerRect.right, InnerRect.top);
507 if(uFlags & BF_LEFT)
509 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
510 LineTo(hdc, InnerRect.left, InnerRect.bottom);
512 SelectObject(hdc, RBOuterPen);
513 if(uFlags & BF_BOTTOM)
515 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
516 LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1);
518 if(uFlags & BF_RIGHT)
520 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
521 LineTo(hdc, InnerRect.right-1, InnerRect.top-1);
524 /* Draw the inner edge */
525 SelectObject(hdc, LTInnerPen);
526 if(uFlags & BF_TOP)
528 MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
529 LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
531 if(uFlags & BF_LEFT)
533 MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
534 LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
536 SelectObject(hdc, RBInnerPen);
537 if(uFlags & BF_BOTTOM)
539 MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
540 LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
542 if(uFlags & BF_RIGHT)
544 MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
545 LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
548 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
550 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
551 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
553 if(uFlags & BF_LEFT) InnerRect.left += add;
554 if(uFlags & BF_RIGHT) InnerRect.right -= add;
555 if(uFlags & BF_TOP) InnerRect.top += add;
556 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
558 if((uFlags & BF_MIDDLE) && retval)
560 FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
561 COLOR_WINDOW : COLOR_BTNFACE));
564 if(uFlags & BF_ADJUST)
565 *rc = InnerRect;
568 /* Cleanup */
569 SelectObject(hdc, SavePen);
570 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
571 return retval;
575 /**********************************************************************
576 * DrawEdge (USER32.@)
578 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
580 TRACE("%p %ld,%ld-%ld,%ld %04x %04x\n",
581 hdc, rc->left, rc->top, rc->right, rc->bottom, edge, flags );
583 if(flags & BF_DIAGONAL)
584 return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
585 else
586 return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags);
590 /************************************************************************
591 * UITOOLS_MakeSquareRect
593 * Utility to create a square rectangle and returning the width
595 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
597 int Width = src->right - src->left;
598 int Height = src->bottom - src->top;
599 int SmallDiam = Width > Height ? Height : Width;
601 *dst = *src;
603 /* Make it a square box */
604 if(Width < Height) /* SmallDiam == Width */
606 dst->top += (Height-Width)/2;
607 dst->bottom = dst->top + SmallDiam;
609 else if(Width > Height) /* SmallDiam == Height */
611 dst->left += (Width-Height)/2;
612 dst->right = dst->left + SmallDiam;
615 return SmallDiam;
618 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
620 if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
622 HBRUSH hbsave;
623 COLORREF bg;
625 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
626 bg = SetBkColor(dc, RGB(255, 255, 255));
627 hbsave = SelectObject(dc, SYSCOLOR_55AABrush);
628 PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
629 SelectObject(dc, hbsave);
630 SetBkColor(dc, bg);
632 else
634 FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
638 /************************************************************************
639 * UITOOLS_DFC_ButtonPush
641 * Draw a push button coming from DrawFrameControl()
643 * Does a pretty good job in emulating MS behavior. Some quirks are
644 * however there because MS uses a TrueType font (Marlett) to draw
645 * the buttons.
647 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
649 UINT edge;
650 RECT myr = *r;
652 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
653 edge = EDGE_SUNKEN;
654 else
655 edge = EDGE_RAISED;
657 if(uFlags & DFCS_CHECKED)
659 if(uFlags & DFCS_MONO)
660 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
661 else
662 UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
664 if (!(uFlags & DFCS_TRANSPARENT))
665 UITOOLS_DrawCheckedRect( dc, &myr );
667 else
669 if(uFlags & DFCS_MONO)
671 UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
672 if (!(uFlags & DFCS_TRANSPARENT))
673 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
675 else
677 UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) | ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT | BF_SOFT);
681 /* Adjust rectangle if asked */
682 if(uFlags & DFCS_ADJUSTRECT)
684 r->left += 2;
685 r->right -= 2;
686 r->top += 2;
687 r->bottom -= 2;
690 return TRUE;
694 /************************************************************************
695 * UITOOLS_DFC_ButtonChcek
697 * Draw a check/3state button coming from DrawFrameControl()
699 * Does a pretty good job in emulating MS behavior. Some quirks are
700 * however there because MS uses a TrueType font (Marlett) to draw
701 * the buttons.
704 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
706 RECT myr, bar;
707 UINT flags = BF_RECT | BF_ADJUST;
709 UITOOLS_MakeSquareRect(r, &myr);
711 if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
712 else if(uFlags & DFCS_MONO) flags |= BF_MONO;
714 UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags );
716 if (!(uFlags & DFCS_TRANSPARENT))
718 if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
719 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
720 else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
721 UITOOLS_DrawCheckedRect( dc, &myr );
722 else
723 FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
726 if(uFlags & DFCS_CHECKED)
728 int i, k;
729 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
730 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
732 /* draw 7 bars, with h=3w to form the check */
733 bar.left = myr.left;
734 bar.top = myr.top + 2;
735 for (k = 0; k < 7; k++) {
736 bar.left = bar.left + 1;
737 bar.top = (k < 3) ? bar.top + 1 : bar.top - 1;
738 bar.bottom = bar.top + 3;
739 bar.right = bar.left + 1;
740 FillRect(dc, &bar, GetSysColorBrush(i));
743 return TRUE;
747 /************************************************************************
748 * UITOOLS_DFC_ButtonRadio
750 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
752 * Does a pretty good job in emulating MS behavior. Some quirks are
753 * however there because MS uses a TrueType font (Marlett) to draw
754 * the buttons.
756 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
758 RECT myr;
759 int i;
760 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
761 int BorderShrink = SmallDiam / 16;
762 HPEN hpsave;
763 HBRUSH hbsave;
764 int xc, yc;
766 if(BorderShrink < 1) BorderShrink = 1;
768 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
769 FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
771 xc = myr.left + SmallDiam - SmallDiam/2;
772 yc = myr.top + SmallDiam - SmallDiam/2;
774 /* Define bounding box */
775 i = 14*SmallDiam/16;
776 myr.left = xc - i+i/2;
777 myr.right = xc + i/2;
778 myr.top = yc - i+i/2;
779 myr.bottom = yc + i/2;
781 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
783 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
784 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
785 SelectObject(dc, hbsave);
787 else
789 if(uFlags & (DFCS_FLAT|DFCS_MONO))
791 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
792 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
793 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
794 SelectObject(dc, hbsave);
795 SelectObject(dc, hpsave);
797 else
799 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
800 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
801 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
803 SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNSHADOW));
804 SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
805 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
807 myr.left += BorderShrink;
808 myr.right -= BorderShrink;
809 myr.top += BorderShrink;
810 myr.bottom -= BorderShrink;
812 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
813 SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
814 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
816 SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
817 SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
818 Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
819 SelectObject(dc, hbsave);
820 SelectObject(dc, hpsave);
823 i = 10*SmallDiam/16;
824 myr.left = xc - i+i/2;
825 myr.right = xc + i/2;
826 myr.top = yc - i+i/2;
827 myr.bottom = yc + i/2;
828 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
829 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
830 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
831 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
832 SelectObject(dc, hbsave);
833 SelectObject(dc, hpsave);
836 if(uFlags & DFCS_CHECKED)
838 i = 6*SmallDiam/16;
839 i = i < 1 ? 1 : i;
840 myr.left = xc - i+i/2;
841 myr.right = xc + i/2;
842 myr.top = yc - i+i/2;
843 myr.bottom = yc + i/2;
845 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
846 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
847 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
848 Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
849 SelectObject(dc, hpsave);
850 SelectObject(dc, hbsave);
853 /* FIXME: M$ has a polygon in the center at relative points: */
854 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
855 /* 0.476, 0.525 */
856 /* 0.500, 0.500 */
857 /* 0.500, 0.499 */
858 /* when the button is unchecked. The reason for it is unknown. The */
859 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
860 /* least 3 times (it looks like a clip-region when you see it happen). */
861 /* I do not really see a reason why this should be implemented. If you */
862 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
863 /* font. */
865 return TRUE;
868 /***********************************************************************
869 * UITOOLS_DrawFrameButton
871 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
873 switch(uState & 0xff)
875 case DFCS_BUTTONPUSH:
876 return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
878 case DFCS_BUTTONCHECK:
879 case DFCS_BUTTON3STATE:
880 return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
882 case DFCS_BUTTONRADIOIMAGE:
883 case DFCS_BUTTONRADIOMASK:
884 case DFCS_BUTTONRADIO:
885 return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
887 default:
888 WARN("Invalid button state=0x%04x\n", uState);
891 return FALSE;
894 /***********************************************************************
895 * UITOOLS_DrawFrameCaption
897 * Draw caption buttons (win95), coming from DrawFrameControl()
900 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
902 RECT myr;
903 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
904 HFONT hfsave, hf;
905 int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
906 int xc = (myr.left+myr.right)/2;
907 int yc = (myr.top+myr.bottom)/2;
908 WCHAR str[2] = {0, 0};
909 static const WCHAR glyphFontName[] = { 'M','a','r','l','e','t','t',0 };
910 UINT alignsave;
911 int bksave;
912 COLORREF clrsave;
913 SIZE size;
915 UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
917 switch(uFlags & 0xff)
919 case DFCS_CAPTIONCLOSE: str[0] = 0x72; break;
920 case DFCS_CAPTIONHELP: str[0] = 0x73; break;
921 case DFCS_CAPTIONMIN: str[0] = 0x30; break;
922 case DFCS_CAPTIONMAX: str[0] = 0x31; break;
923 case DFCS_CAPTIONRESTORE: str[0] = 0x32; break;
924 default:
925 WARN("Invalid caption; flags=0x%04x\n", uFlags);
926 return FALSE;
929 hf = CreateFontW(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
930 SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
931 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, glyphFontName);
932 alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
933 bksave = SetBkMode(dc, TRANSPARENT);
934 clrsave = GetTextColor(dc);
935 hfsave = (HFONT)SelectObject(dc, hf);
936 GetTextExtentPoint32W(dc, str, 1, &size);
938 if(uFlags & DFCS_INACTIVE)
940 SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
941 TextOutW(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
943 SetTextColor(dc, GetSysColor(colorIdx));
944 TextOutW(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
946 SelectObject(dc, hfsave);
947 SetTextColor(dc, clrsave);
948 SetBkMode(dc, bksave);
949 SetTextAlign(dc, alignsave);
950 DeleteObject(hf);
952 return TRUE;
956 /************************************************************************
957 * UITOOLS_DrawFrameScroll
959 * Draw a scroll-bar control coming from DrawFrameControl()
961 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
963 POINT Line[4];
964 RECT myr;
965 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
966 int i;
967 HBRUSH hbsave, hb, hb2;
968 HPEN hpsave, hp, hp2;
969 int tri = 290*SmallDiam/1000 - 1;
970 int d46, d93;
973 * This fixes a problem with really tiny "scroll" buttons. In particular
974 * with the updown control.
975 * Making sure that the arrow is as least 3 pixels wide (or high).
977 if (tri == 0)
978 tri = 1;
980 switch(uFlags & 0xff)
982 case DFCS_SCROLLCOMBOBOX:
983 case DFCS_SCROLLDOWN:
984 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
985 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
986 Line[0].x = Line[2].x - tri;
987 Line[1].x = Line[2].x + tri;
988 Line[0].y = Line[1].y = Line[2].y - tri;
989 break;
991 case DFCS_SCROLLUP:
992 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
993 Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
994 Line[0].x = Line[2].x - tri;
995 Line[1].x = Line[2].x + tri;
996 Line[0].y = Line[1].y = Line[2].y + tri;
997 break;
999 case DFCS_SCROLLLEFT:
1000 Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1001 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1002 Line[0].y = Line[2].y - tri;
1003 Line[1].y = Line[2].y + tri;
1004 Line[0].x = Line[1].x = Line[2].x + tri;
1005 break;
1007 case DFCS_SCROLLRIGHT:
1008 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1009 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1010 Line[0].y = Line[2].y - tri;
1011 Line[1].y = Line[2].y + tri;
1012 Line[0].x = Line[1].x = Line[2].x - tri;
1013 break;
1015 case DFCS_SCROLLSIZEGRIP:
1016 /* This one breaks the flow... */
1017 UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1018 hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1019 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1020 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1022 hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1023 hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1025 else
1027 hp = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1028 hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1029 hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1030 hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1032 Line[0].x = Line[1].x = r->right-1;
1033 Line[2].y = Line[3].y = r->bottom-1;
1034 d46 = 46*SmallDiam/750;
1035 d93 = 93*SmallDiam/750;
1037 i = 586*SmallDiam/750;
1038 Line[0].y = r->bottom - i - 1;
1039 Line[3].x = r->right - i - 1;
1040 Line[1].y = Line[0].y + d46;
1041 Line[2].x = Line[3].x + d46;
1042 SelectObject(dc, hb);
1043 SelectObject(dc, hp);
1044 Polygon(dc, Line, 4);
1046 Line[1].y++; Line[2].x++;
1047 Line[0].y = Line[1].y + d93;
1048 Line[3].x = Line[2].x + d93;
1049 SelectObject(dc, hb2);
1050 SelectObject(dc, hp2);
1051 Polygon(dc, Line, 4);
1053 i = 398*SmallDiam/750;
1054 Line[0].y = r->bottom - i - 1;
1055 Line[3].x = r->right - i - 1;
1056 Line[1].y = Line[0].y + d46;
1057 Line[2].x = Line[3].x + d46;
1058 SelectObject(dc, hb);
1059 SelectObject(dc, hp);
1060 Polygon(dc, Line, 4);
1062 Line[1].y++; Line[2].x++;
1063 Line[0].y = Line[1].y + d93;
1064 Line[3].x = Line[2].x + d93;
1065 SelectObject(dc, hb2);
1066 SelectObject(dc, hp2);
1067 Polygon(dc, Line, 4);
1069 i = 210*SmallDiam/750;
1070 Line[0].y = r->bottom - i - 1;
1071 Line[3].x = r->right - i - 1;
1072 Line[1].y = Line[0].y + d46;
1073 Line[2].x = Line[3].x + d46;
1074 SelectObject(dc, hb);
1075 SelectObject(dc, hp);
1076 Polygon(dc, Line, 4);
1078 Line[1].y++; Line[2].x++;
1079 Line[0].y = Line[1].y + d93;
1080 Line[3].x = Line[2].x + d93;
1081 SelectObject(dc, hb2);
1082 SelectObject(dc, hp2);
1083 Polygon(dc, Line, 4);
1085 SelectObject(dc, hpsave);
1086 SelectObject(dc, hbsave);
1087 return TRUE;
1089 default:
1090 WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1091 return FALSE;
1094 /* Here do the real scroll-bar controls end up */
1095 if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1096 /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1097 /* want for the normal scroll-arrow button. */
1098 UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1099 else
1100 UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1102 if(uFlags & DFCS_INACTIVE)
1104 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1105 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1106 Polygon(dc, Line, 3);
1107 SelectObject(dc, hpsave);
1108 SelectObject(dc, hbsave);
1111 if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1112 for(i = 0; i < 3; i++)
1114 Line[i].x--;
1115 Line[i].y--;
1118 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1119 hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1120 hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
1121 Polygon(dc, Line, 3);
1122 SelectObject(dc, hpsave);
1123 SelectObject(dc, hbsave);
1125 return TRUE;
1128 /************************************************************************
1129 * UITOOLS_DrawFrameMenu
1131 * Draw a menu control coming from DrawFrameControl()
1133 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1135 POINT Points[6];
1136 RECT myr;
1137 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1138 int i;
1139 HBRUSH hbsave;
1140 HPEN hpsave;
1141 int xe, ye;
1142 int xc, yc;
1143 BOOL retval = TRUE;
1145 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1146 /* use anything else. I think I tried all sys-colors to change things */
1147 /* without luck. It seems as if this behavior is inherited from the */
1148 /* win31 DFC() implementation... (you remember, B/W menus). */
1150 FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1152 hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1153 hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1155 switch(uFlags & 0xff)
1157 case DFCS_MENUARROW:
1158 i = 187*SmallDiam/750;
1159 Points[2].x = myr.left + 468*SmallDiam/750;
1160 Points[2].y = myr.top + 352*SmallDiam/750+1;
1161 Points[0].y = Points[2].y - i;
1162 Points[1].y = Points[2].y + i;
1163 Points[0].x = Points[1].x = Points[2].x - i;
1164 Polygon(dc, Points, 3);
1165 break;
1167 case DFCS_MENUBULLET:
1168 xe = myr.left;
1169 ye = myr.top + SmallDiam - SmallDiam/2;
1170 xc = myr.left + SmallDiam - SmallDiam/2;
1171 yc = myr.top + SmallDiam - SmallDiam/2;
1172 i = 234*SmallDiam/750;
1173 i = i < 1 ? 1 : i;
1174 myr.left = xc - i+i/2;
1175 myr.right = xc + i/2;
1176 myr.top = yc - i+i/2;
1177 myr.bottom = yc + i/2;
1178 Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1179 break;
1181 case DFCS_MENUCHECK:
1182 Points[0].x = myr.left + 253*SmallDiam/1000;
1183 Points[0].y = myr.top + 445*SmallDiam/1000;
1184 Points[1].x = myr.left + 409*SmallDiam/1000;
1185 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1186 Points[2].x = myr.left + 690*SmallDiam/1000;
1187 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1188 Points[3].x = Points[2].x;
1189 Points[3].y = Points[2].y + 3*SmallDiam/16;
1190 Points[4].x = Points[1].x;
1191 Points[4].y = Points[1].y + 3*SmallDiam/16;
1192 Points[5].x = Points[0].x;
1193 Points[5].y = Points[0].y + 3*SmallDiam/16;
1194 Polygon(dc, Points, 6);
1195 break;
1197 default:
1198 WARN("Invalid menu; flags=0x%04x\n", uFlags);
1199 retval = FALSE;
1200 break;
1203 SelectObject(dc, hpsave);
1204 SelectObject(dc, hbsave);
1205 return retval;
1209 /**********************************************************************
1210 * DrawFrameControl (USER32.@)
1212 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1213 UINT uState )
1215 /* Win95 doesn't support drawing in other mapping modes */
1216 if(GetMapMode(hdc) != MM_TEXT)
1217 return FALSE;
1219 switch(uType)
1221 case DFC_BUTTON:
1222 return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1223 case DFC_CAPTION:
1224 return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1225 case DFC_MENU:
1226 return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1227 /*case DFC_POPUPMENU:
1228 FIXME("DFC_POPUPMENU: not implemented\n");
1229 break;*/
1230 case DFC_SCROLL:
1231 return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1232 default:
1233 WARN("(%p,%p,%d,%x), bad type!\n", hdc,rc,uType,uState );
1235 return FALSE;
1239 /***********************************************************************
1240 * SetRect (USER32.@)
1242 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
1243 INT right, INT bottom )
1245 if (!rect) return FALSE;
1246 rect->left = left;
1247 rect->right = right;
1248 rect->top = top;
1249 rect->bottom = bottom;
1250 return TRUE;
1254 /***********************************************************************
1255 * SetRectEmpty (USER32.@)
1257 BOOL WINAPI SetRectEmpty( LPRECT rect )
1259 if (!rect) return FALSE;
1260 rect->left = rect->right = rect->top = rect->bottom = 0;
1261 return TRUE;
1265 /***********************************************************************
1266 * CopyRect (USER32.@)
1268 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
1270 if (!dest || !src) return FALSE;
1271 *dest = *src;
1272 return TRUE;
1276 /***********************************************************************
1277 * IsRectEmpty (USER32.@)
1279 * Bug compat: Windows checks for 0 or negative width/height.
1281 BOOL WINAPI IsRectEmpty( const RECT *rect )
1283 if (!rect) return TRUE;
1284 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
1288 /***********************************************************************
1289 * PtInRect (USER32.@)
1291 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
1293 if (!rect) return FALSE;
1294 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
1295 (pt.y >= rect->top) && (pt.y < rect->bottom));
1299 /***********************************************************************
1300 * OffsetRect (USER32.@)
1302 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
1304 if (!rect) return FALSE;
1305 rect->left += x;
1306 rect->right += x;
1307 rect->top += y;
1308 rect->bottom += y;
1309 return TRUE;
1313 /***********************************************************************
1314 * InflateRect (USER32.@)
1316 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
1318 if (!rect) return FALSE;
1319 rect->left -= x;
1320 rect->top -= y;
1321 rect->right += x;
1322 rect->bottom += y;
1323 return TRUE;
1327 /***********************************************************************
1328 * IntersectRect (USER32.@)
1330 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1332 if (!dest || !src1 || !src2) return FALSE;
1333 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
1334 (src1->left >= src2->right) || (src2->left >= src1->right) ||
1335 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
1337 SetRectEmpty( dest );
1338 return FALSE;
1340 dest->left = max( src1->left, src2->left );
1341 dest->right = min( src1->right, src2->right );
1342 dest->top = max( src1->top, src2->top );
1343 dest->bottom = min( src1->bottom, src2->bottom );
1344 return TRUE;
1348 /***********************************************************************
1349 * UnionRect (USER32.@)
1351 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1353 if (!dest) return FALSE;
1354 if (IsRectEmpty(src1))
1356 if (IsRectEmpty(src2))
1358 SetRectEmpty( dest );
1359 return FALSE;
1361 else *dest = *src2;
1363 else
1365 if (IsRectEmpty(src2)) *dest = *src1;
1366 else
1368 dest->left = min( src1->left, src2->left );
1369 dest->right = max( src1->right, src2->right );
1370 dest->top = min( src1->top, src2->top );
1371 dest->bottom = max( src1->bottom, src2->bottom );
1374 return TRUE;
1378 /***********************************************************************
1379 * EqualRect (USER32.@)
1381 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
1383 if (!rect1 || !rect2) return FALSE;
1384 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
1385 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
1389 /***********************************************************************
1390 * SubtractRect (USER32.@)
1392 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1, const RECT *src2 )
1394 RECT tmp;
1396 if (!dest) return FALSE;
1397 if (IsRectEmpty( src1 ))
1399 SetRectEmpty( dest );
1400 return FALSE;
1402 *dest = *src1;
1403 if (IntersectRect( &tmp, src1, src2 ))
1405 if (EqualRect( &tmp, dest ))
1407 SetRectEmpty( dest );
1408 return FALSE;
1410 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
1412 if (tmp.left == dest->left) dest->left = tmp.right;
1413 else if (tmp.right == dest->right) dest->right = tmp.left;
1415 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
1417 if (tmp.top == dest->top) dest->top = tmp.bottom;
1418 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
1421 return TRUE;
1425 /***********************************************************************
1426 * FillRect (USER32.@)
1428 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1430 HBRUSH prevBrush;
1432 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1434 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1435 PatBlt( hdc, rect->left, rect->top,
1436 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1437 SelectObject( hdc, prevBrush );
1438 return 1;
1442 /***********************************************************************
1443 * InvertRect (USER32.@)
1445 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1447 return PatBlt( hdc, rect->left, rect->top,
1448 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1452 /***********************************************************************
1453 * FrameRect (USER32.@)
1455 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1457 HBRUSH prevBrush;
1458 RECT r = *rect;
1460 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1461 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1463 PatBlt( hdc, r.left, r.top, 1, r.bottom - r.top, PATCOPY );
1464 PatBlt( hdc, r.right - 1, r.top, 1, r.bottom - r.top, PATCOPY );
1465 PatBlt( hdc, r.left, r.top, r.right - r.left, 1, PATCOPY );
1466 PatBlt( hdc, r.left, r.bottom - 1, r.right - r.left, 1, PATCOPY );
1468 SelectObject( hdc, prevBrush );
1469 return TRUE;
1473 /***********************************************************************
1474 * DrawFocusRect (USER32.@)
1476 * FIXME: PatBlt(PATINVERT) with background brush.
1478 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1480 HBRUSH hOldBrush;
1481 HPEN hOldPen, hNewPen;
1482 INT oldDrawMode, oldBkMode;
1484 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1485 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1486 hOldPen = SelectObject(hdc, hNewPen);
1487 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1488 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1490 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1492 SetBkMode(hdc, oldBkMode);
1493 SetROP2(hdc, oldDrawMode);
1494 SelectObject(hdc, hOldPen);
1495 DeleteObject(hNewPen);
1496 SelectObject(hdc, hOldBrush);
1498 return TRUE;
1502 /**********************************************************************
1503 * DrawAnimatedRects (USER32.@)
1505 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni, const RECT* lprcFrom, const RECT* lprcTo )
1507 FIXME("(%p,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1508 return TRUE;
1512 /**********************************************************************
1513 * UITOOLS_DrawStateJam
1515 * Jams in the requested type in the dc
1517 static BOOL UITOOLS_DrawStateJam( HDC hdc, UINT opcode, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1518 LPRECT rc, UINT dtflags, BOOL unicode )
1520 HDC memdc;
1521 HBITMAP hbmsave;
1522 BOOL retval;
1523 INT cx = rc->right - rc->left;
1524 INT cy = rc->bottom - rc->top;
1526 switch(opcode)
1528 case DST_TEXT:
1529 case DST_PREFIXTEXT:
1530 if(unicode)
1531 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1532 else
1533 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1535 case DST_ICON:
1536 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1538 case DST_BITMAP:
1539 memdc = CreateCompatibleDC(hdc);
1540 if(!memdc) return FALSE;
1541 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1542 if(!hbmsave)
1544 DeleteDC(memdc);
1545 return FALSE;
1547 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1548 SelectObject(memdc, hbmsave);
1549 DeleteDC(memdc);
1550 return retval;
1552 case DST_COMPLEX:
1553 if(func) {
1554 BOOL bRet;
1555 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1557 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1558 bRet = func(hdc, lp, wp, cx, cy);
1559 /* Restore origin */
1560 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1561 return bRet;
1562 } else
1563 return FALSE;
1565 return FALSE;
1568 /**********************************************************************
1569 * UITOOLS_DrawState()
1571 static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1572 INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode )
1574 HBITMAP hbm, hbmsave;
1575 HFONT hfsave;
1576 HBRUSH hbsave, hbrtmp = 0;
1577 HDC memdc;
1578 RECT rc;
1579 UINT dtflags = DT_NOCLIP;
1580 COLORREF fg, bg;
1581 UINT opcode = flags & 0xf;
1582 INT len = wp;
1583 BOOL retval, tmp;
1585 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1587 if(unicode)
1588 len = strlenW((LPWSTR)lp);
1589 else
1590 len = strlen((LPSTR)lp);
1593 /* Find out what size the image has if not given by caller */
1594 if(!cx || !cy)
1596 SIZE s;
1597 CURSORICONINFO *ici;
1598 BITMAP bm;
1600 switch(opcode)
1602 case DST_TEXT:
1603 case DST_PREFIXTEXT:
1604 if(unicode)
1605 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1606 else
1607 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1608 if(!retval) return FALSE;
1609 break;
1611 case DST_ICON:
1612 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1613 if(!ici) return FALSE;
1614 s.cx = ici->nWidth;
1615 s.cy = ici->nHeight;
1616 GlobalUnlock16((HGLOBAL16)lp);
1617 break;
1619 case DST_BITMAP:
1620 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm)) return FALSE;
1621 s.cx = bm.bmWidth;
1622 s.cy = bm.bmHeight;
1623 break;
1625 case DST_COMPLEX: /* cx and cy must be set in this mode */
1626 return FALSE;
1629 if(!cx) cx = s.cx;
1630 if(!cy) cy = s.cy;
1633 rc.left = x;
1634 rc.top = y;
1635 rc.right = x + cx;
1636 rc.bottom = y + cy;
1638 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1639 dtflags |= DT_RIGHT;
1640 if(opcode == DST_TEXT)
1641 dtflags |= DT_NOPREFIX;
1643 /* For DSS_NORMAL we just jam in the image and return */
1644 if((flags & 0x7ff0) == DSS_NORMAL)
1646 return UITOOLS_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
1649 /* For all other states we need to convert the image to B/W in a local bitmap */
1650 /* before it is displayed */
1651 fg = SetTextColor(hdc, RGB(0, 0, 0));
1652 bg = SetBkColor(hdc, RGB(255, 255, 255));
1653 hbm = NULL; hbmsave = NULL;
1654 memdc = NULL; hbsave = NULL;
1655 retval = FALSE; /* assume failure */
1657 /* From here on we must use "goto cleanup" when something goes wrong */
1658 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1659 if(!hbm) goto cleanup;
1660 memdc = CreateCompatibleDC(hdc);
1661 if(!memdc) goto cleanup;
1662 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1663 if(!hbmsave) goto cleanup;
1664 rc.left = rc.top = 0;
1665 rc.right = cx;
1666 rc.bottom = cy;
1667 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1668 SetBkColor(memdc, RGB(255, 255, 255));
1669 SetTextColor(memdc, RGB(0, 0, 0));
1670 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1672 /* DST_COMPLEX may draw text as well,
1673 * so we must be sure that correct font is selected
1675 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1676 tmp = UITOOLS_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
1677 if(hfsave) SelectObject(memdc, hfsave);
1678 if(!tmp) goto cleanup;
1680 /* This state cause the image to be dithered */
1681 if(flags & DSS_UNION)
1683 hbsave = (HBRUSH)SelectObject(memdc, SYSCOLOR_55AABrush);
1684 if(!hbsave) goto cleanup;
1685 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1686 SelectObject(memdc, hbsave);
1687 if(!tmp) goto cleanup;
1690 if (flags & DSS_DISABLED)
1691 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1692 else if (flags & DSS_DEFAULT)
1693 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1695 /* Draw light or dark shadow */
1696 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1698 if(!hbrtmp) goto cleanup;
1699 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1700 if(!hbsave) goto cleanup;
1701 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1702 SelectObject(hdc, hbsave);
1703 DeleteObject(hbrtmp);
1704 hbrtmp = 0;
1707 if (flags & DSS_DISABLED)
1709 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1710 if(!hbrtmp) goto cleanup;
1712 else if (!hbr)
1714 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1717 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1719 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1721 retval = TRUE; /* We succeeded */
1723 cleanup:
1724 SetTextColor(hdc, fg);
1725 SetBkColor(hdc, bg);
1727 if(hbsave) SelectObject(hdc, hbsave);
1728 if(hbmsave) SelectObject(memdc, hbmsave);
1729 if(hbrtmp) DeleteObject(hbrtmp);
1730 if(hbm) DeleteObject(hbm);
1731 if(memdc) DeleteDC(memdc);
1733 return retval;
1736 /**********************************************************************
1737 * DrawStateA (USER32.@)
1739 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1740 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1741 INT x, INT y, INT cx, INT cy, UINT flags)
1743 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE);
1746 /**********************************************************************
1747 * DrawStateW (USER32.@)
1749 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1750 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1751 INT x, INT y, INT cx, INT cy, UINT flags)
1753 return UITOOLS_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE);