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