Release 980315
[wine/multimedia.git] / controls / uitools.c
blobd3f814e09b4292f9e8450296e2feea9510184c8f
1 /*
2 * User Interface Functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1997 Bertho A. Stultiens
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "debug.h"
12 static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555,
13 0xaaaa, 0x5555, 0xaaaa, 0x5555 };
15 /* These tables are used in:
16 * UITOOLS_DrawDiagEdge()
17 * UITOOLS_DrawRectEdge()
19 static const char LTInnerNormal[] = {
20 -1, -1, -1, -1,
21 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
22 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
23 -1, -1, -1, -1
26 static const char LTOuterNormal[] = {
27 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
28 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
29 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
30 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
33 static const char RBInnerNormal[] = {
34 -1, -1, -1, -1,
35 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
36 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
37 -1, -1, -1, -1
40 static const char RBOuterNormal[] = {
41 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
42 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
43 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
44 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
47 static const char LTInnerSoft[] = {
48 -1, -1, -1, -1,
49 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
50 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
51 -1, -1, -1, -1
54 static const char LTOuterSoft[] = {
55 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
56 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
57 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
58 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
61 #define RBInnerSoft RBInnerNormal /* These are the same */
62 #define RBOuterSoft RBOuterNormal
64 static const char LTRBOuterMono[] = {
65 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
66 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
67 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
68 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
71 static const char LTRBInnerMono[] = {
72 -1, -1, -1, -1,
73 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
74 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
75 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
78 static const char LTRBOuterFlat[] = {
79 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
80 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
81 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
82 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
85 static const char LTRBInnerFlat[] = {
86 -1, -1, -1, -1,
87 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
88 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
89 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
92 /***********************************************************************
93 * UITOOLS_DrawDiagEdge
95 * Same as DrawEdge, but with BF_DIAGONAL
96 * I tested it extensively and as far as I can tell it is identical to the
97 * implementaion in Win95.
98 * I do not like that I create and
99 * use the 3 Pens to draw the diagonals. It would be better to draw them
100 * using the brushes returned by GetSysColorBrush func, but I did not have
101 * the patience to implement that yet.
103 /*********************************************************************
104 * 03-Dec-1997: Changed by Bertho Stultiens
106 * See also comments with UITOOLS_DrawRectEdge()
108 static BOOL32 UITOOLS_DrawDiagEdge(HDC32 hdc, LPRECT32 rc, UINT32 uType, UINT32 uFlags)
110 POINT32 Points[4];
111 char InnerI, OuterI;
112 HPEN32 InnerPen, OuterPen;
113 POINT32 SavePoint;
114 HPEN32 SavePen;
115 int spx, spy;
116 int epx, epy;
117 int Width = rc->right - rc->left;
118 int Height= rc->bottom - rc->top;
119 int SmallDiam = Width > Height ? Height : Width;
120 BOOL32 retval = !( ((uType & BDR_INNER) == BDR_INNER
121 || (uType & BDR_OUTER) == BDR_OUTER)
122 && !(uFlags & (BF_FLAT|BF_MONO)) );
123 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
124 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
126 /* Init some vars */
127 OuterPen = InnerPen = (HPEN32)GetStockObject32(NULL_PEN);
128 SavePen = (HPEN32)SelectObject32(hdc, InnerPen);
129 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
131 /* Determine the colors of the edges */
132 if(uFlags & BF_MONO)
134 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
135 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
137 else if(uFlags & BF_FLAT)
139 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
140 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
142 else if(uFlags & BF_SOFT)
144 if(uFlags & BF_BOTTOM)
146 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
147 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
149 else
151 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
152 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
155 else
157 if(uFlags & BF_BOTTOM)
159 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
160 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
162 else
164 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
165 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
169 if(InnerI != -1) InnerPen = GetSysColorPen32(InnerI);
170 if(OuterI != -1) OuterPen = GetSysColorPen32(OuterI);
172 MoveToEx32(hdc, 0, 0, &SavePoint);
174 /* Don't ask me why, but this is what is visible... */
175 /* This must be possible to do much simpler, but I fail to */
176 /* see the logic in the MS implementation (sigh...). */
177 /* So, this might look a bit brute force here (and it is), but */
178 /* it gets the job done;) */
180 switch(uFlags & BF_RECT)
182 case 0:
183 case BF_LEFT:
184 case BF_BOTTOM:
185 case BF_BOTTOMLEFT:
186 /* Left bottom endpoint */
187 epx = rc->left-1;
188 spx = epx + SmallDiam;
189 epy = rc->bottom;
190 spy = epy - SmallDiam;
191 break;
193 case BF_TOPLEFT:
194 case BF_BOTTOMRIGHT:
195 /* Left top endpoint */
196 epx = rc->left-1;
197 spx = epx + SmallDiam;
198 epy = rc->top-1;
199 spy = epy + SmallDiam;
200 break;
202 case BF_TOP:
203 case BF_RIGHT:
204 case BF_TOPRIGHT:
205 case BF_RIGHT|BF_LEFT:
206 case BF_RIGHT|BF_LEFT|BF_TOP:
207 case BF_BOTTOM|BF_TOP:
208 case BF_BOTTOM|BF_TOP|BF_LEFT:
209 case BF_BOTTOMRIGHT|BF_LEFT:
210 case BF_BOTTOMRIGHT|BF_TOP:
211 case BF_RECT:
212 /* Right top endpoint */
213 spx = rc->left;
214 epx = spx + SmallDiam;
215 spy = rc->bottom-1;
216 epy = spy - SmallDiam;
217 break;
220 MoveToEx32(hdc, spx, spy, NULL);
221 SelectObject32(hdc, OuterPen);
222 LineTo32(hdc, epx, epy);
224 SelectObject32(hdc, InnerPen);
226 switch(uFlags & (BF_RECT|BF_DIAGONAL))
228 case BF_DIAGONAL_ENDBOTTOMLEFT:
229 case (BF_DIAGONAL|BF_BOTTOM):
230 case BF_DIAGONAL:
231 case (BF_DIAGONAL|BF_LEFT):
232 MoveToEx32(hdc, spx-1, spy, NULL);
233 LineTo32(hdc, epx, epy-1);
234 Points[0].x = spx-add;
235 Points[0].y = spy;
236 Points[1].x = rc->left;
237 Points[1].y = rc->top;
238 Points[2].x = epx+1;
239 Points[2].y = epy-1-add;
240 Points[3] = Points[2];
241 break;
243 case BF_DIAGONAL_ENDBOTTOMRIGHT:
244 MoveToEx32(hdc, spx-1, spy, NULL);
245 LineTo32(hdc, epx, epy+1);
246 Points[0].x = spx-add;
247 Points[0].y = spy;
248 Points[1].x = rc->left;
249 Points[1].y = rc->bottom-1;
250 Points[2].x = epx+1;
251 Points[2].y = epy+1+add;
252 Points[3] = Points[2];
253 break;
255 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
256 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
257 case BF_DIAGONAL_ENDTOPRIGHT:
258 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
259 MoveToEx32(hdc, spx+1, spy, NULL);
260 LineTo32(hdc, epx, epy+1);
261 Points[0].x = epx-1;
262 Points[0].y = epy+1+add;
263 Points[1].x = rc->right-1;
264 Points[1].y = rc->top+add;
265 Points[2].x = rc->right-1;
266 Points[2].y = rc->bottom-1;
267 Points[3].x = spx+add;
268 Points[3].y = spy;
269 break;
271 case BF_DIAGONAL_ENDTOPLEFT:
272 MoveToEx32(hdc, spx, spy-1, NULL);
273 LineTo32(hdc, epx+1, epy);
274 Points[0].x = epx+1+add;
275 Points[0].y = epy+1;
276 Points[1].x = rc->right-1;
277 Points[1].y = rc->top;
278 Points[2].x = rc->right-1;
279 Points[2].y = rc->bottom-1-add;
280 Points[3].x = spx;
281 Points[3].y = spy-add;
282 break;
284 case (BF_DIAGONAL|BF_TOP):
285 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
286 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
287 MoveToEx32(hdc, spx+1, spy-1, NULL);
288 LineTo32(hdc, epx, epy);
289 Points[0].x = epx-1;
290 Points[0].y = epy+1;
291 Points[1].x = rc->right-1;
292 Points[1].y = rc->top;
293 Points[2].x = rc->right-1;
294 Points[2].y = rc->bottom-1-add;
295 Points[3].x = spx+add;
296 Points[3].y = spy-add;
297 break;
299 case (BF_DIAGONAL|BF_RIGHT):
300 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
301 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
302 MoveToEx32(hdc, spx, spy, NULL);
303 LineTo32(hdc, epx-1, epy+1);
304 Points[0].x = spx;
305 Points[0].y = spy;
306 Points[1].x = rc->left;
307 Points[1].y = rc->top+add;
308 Points[2].x = epx-1-add;
309 Points[2].y = epy+1+add;
310 Points[3] = Points[2];
311 break;
314 /* Fill the interior if asked */
315 if((uFlags & BF_MIDDLE) && retval)
317 HBRUSH32 hbsave;
318 HBRUSH32 hb = GetSysColorBrush32(uFlags & BF_MONO ? COLOR_WINDOW
319 :COLOR_BTNFACE);
320 HPEN32 hpsave;
321 HPEN32 hp = GetSysColorPen32(uFlags & BF_MONO ? COLOR_WINDOW
322 : COLOR_BTNFACE);
323 hbsave = (HBRUSH32)SelectObject32(hdc, hb);
324 hpsave = (HPEN32)SelectObject32(hdc, hp);
325 Polygon32(hdc, Points, 4);
326 SelectObject32(hdc, hbsave);
327 SelectObject32(hdc, hpsave);
330 /* Adjust rectangle if asked */
331 if(uFlags & BF_ADJUST)
333 if(uFlags & BF_LEFT) rc->left += add;
334 if(uFlags & BF_RIGHT) rc->right -= add;
335 if(uFlags & BF_TOP) rc->top += add;
336 if(uFlags & BF_BOTTOM) rc->bottom -= add;
339 /* Cleanup */
340 SelectObject32(hdc, SavePen);
341 MoveToEx32(hdc, SavePoint.x, SavePoint.y, NULL);
343 return retval;
346 /***********************************************************************
347 * UITOOLS_DrawRectEdge
349 * Same as DrawEdge, but without BF_DIAGONAL
350 * I tested this function and it works very well. You should not change it
351 * unless you find a bug. If you don't like the colors, it it not its
352 * fault - the system colors are not OK.
353 * Again, I tested this function on Win95 and I compared the output with the
354 * one generated by the native DrawEdge and it is identical on all cases that
355 * I tried, and I tried quite a few.
357 /*********************************************************************
358 * 23-Nov-1997: Changed by Bertho Stultiens
360 * Well, I started testing this and found out that there are a few things
361 * that weren't quite as win95. The following rewrite should reproduce
362 * win95 results completely.
363 * The colorselection is table-driven to avoid awfull if-statements.
364 * The table below show the color settings.
366 * Pen selection table for uFlags = 0
368 * uType | LTI | LTO | RBI | RBO
369 * ------+-------+-------+-------+-------
370 * 0000 | x | x | x | x
371 * 0001 | x | 22 | x | 21
372 * 0010 | x | 16 | x | 20
373 * 0011 | x | x | x | x
374 * ------+-------+-------+-------+-------
375 * 0100 | x | 20 | x | 16
376 * 0101 | 20 | 22 | 16 | 21
377 * 0110 | 20 | 16 | 16 | 20
378 * 0111 | x | x | x | x
379 * ------+-------+-------+-------+-------
380 * 1000 | x | 21 | x | 22
381 * 1001 | 21 | 22 | 22 | 21
382 * 1010 | 21 | 16 | 22 | 20
383 * 1011 | x | x | x | x
384 * ------+-------+-------+-------+-------
385 * 1100 | x | x | x | x
386 * 1101 | x | x (22)| x | x (21)
387 * 1110 | x | x (16)| x | x (20)
388 * 1111 | x | x | x | x
390 * Pen selection table for uFlags = BF_SOFT
392 * uType | LTI | LTO | RBI | RBO
393 * ------+-------+-------+-------+-------
394 * 0000 | x | x | x | x
395 * 0001 | x | 20 | x | 21
396 * 0010 | x | 21 | x | 20
397 * 0011 | x | x | x | x
398 * ------+-------+-------+-------+-------
399 * 0100 | x | 22 | x | 16
400 * 0101 | 22 | 20 | 16 | 21
401 * 0110 | 22 | 21 | 16 | 20
402 * 0111 | x | x | x | x
403 * ------+-------+-------+-------+-------
404 * 1000 | x | 16 | x | 22
405 * 1001 | 16 | 20 | 22 | 21
406 * 1010 | 16 | 21 | 22 | 20
407 * 1011 | x | x | x | x
408 * ------+-------+-------+-------+-------
409 * 1100 | x | x | x | x
410 * 1101 | x | x (20)| x | x (21)
411 * 1110 | x | x (21)| x | x (20)
412 * 1111 | x | x | x | x
414 * x = don't care; (n) = is what win95 actually uses
415 * LTI = left Top Inner line
416 * LTO = left Top Outer line
417 * RBI = Right Bottom Inner line
418 * RBO = Right Bottom Outer line
419 * 15 = COLOR_BTNFACE
420 * 16 = COLOR_BTNSHADOW
421 * 20 = COLOR_BTNHIGHLIGHT
422 * 21 = COLOR_3DDKSHADOW
423 * 22 = COLOR_3DLIGHT
427 static BOOL32 UITOOLS_DrawRectEdge(HDC32 hdc, LPRECT32 rc, UINT32 uType, UINT32 uFlags)
429 char LTInnerI, LTOuterI;
430 char RBInnerI, RBOuterI;
431 HPEN32 LTInnerPen, LTOuterPen;
432 HPEN32 RBInnerPen, RBOuterPen;
433 RECT32 InnerRect = *rc;
434 POINT32 SavePoint;
435 HPEN32 SavePen;
436 int LBpenplus = 0;
437 int LTpenplus = 0;
438 int RTpenplus = 0;
439 int RBpenplus = 0;
440 BOOL32 retval = !( ((uType & BDR_INNER) == BDR_INNER
441 || (uType & BDR_OUTER) == BDR_OUTER)
442 && !(uFlags & (BF_FLAT|BF_MONO)) );
444 /* Init some vars */
445 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN32)GetStockObject32(NULL_PEN);
446 SavePen = (HPEN32)SelectObject32(hdc, LTInnerPen);
448 /* Determine the colors of the edges */
449 if(uFlags & BF_MONO)
451 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
452 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
454 else if(uFlags & BF_FLAT)
456 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
457 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
459 else if(uFlags & BF_SOFT)
461 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
462 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
463 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
464 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
466 else
468 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
469 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
470 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
471 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
474 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
475 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
476 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
477 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
479 if(LTInnerI != -1) LTInnerPen = GetSysColorPen32(LTInnerI);
480 if(LTOuterI != -1) LTOuterPen = GetSysColorPen32(LTOuterI);
481 if(RBInnerI != -1) RBInnerPen = GetSysColorPen32(RBInnerI);
482 if(RBOuterI != -1) RBOuterPen = GetSysColorPen32(RBOuterI);
484 if((uFlags & BF_MIDDLE) && retval)
486 FillRect32(hdc, &InnerRect, GetSysColorBrush32(uFlags & BF_MONO ?
487 COLOR_WINDOW : COLOR_BTNFACE));
490 MoveToEx32(hdc, 0, 0, &SavePoint);
492 /* Draw the outer edge */
493 SelectObject32(hdc, LTOuterPen);
494 if(uFlags & BF_TOP)
496 MoveToEx32(hdc, InnerRect.left, InnerRect.top, NULL);
497 LineTo32(hdc, InnerRect.right, InnerRect.top);
499 if(uFlags & BF_LEFT)
501 MoveToEx32(hdc, InnerRect.left, InnerRect.top, NULL);
502 LineTo32(hdc, InnerRect.left, InnerRect.bottom);
504 SelectObject32(hdc, RBOuterPen);
505 if(uFlags & BF_BOTTOM)
507 MoveToEx32(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
508 LineTo32(hdc, InnerRect.left-1, InnerRect.bottom-1);
510 if(uFlags & BF_RIGHT)
512 MoveToEx32(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
513 LineTo32(hdc, InnerRect.right-1, InnerRect.top-1);
516 /* Draw the inner edge */
517 SelectObject32(hdc, LTInnerPen);
518 if(uFlags & BF_TOP)
520 MoveToEx32(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
521 LineTo32(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
523 if(uFlags & BF_LEFT)
525 MoveToEx32(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
526 LineTo32(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
528 SelectObject32(hdc, RBInnerPen);
529 if(uFlags & BF_BOTTOM)
531 MoveToEx32(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
532 LineTo32(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
534 if(uFlags & BF_RIGHT)
536 MoveToEx32(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
537 LineTo32(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
540 /* Adjust rectangle if asked */
541 if(uFlags & BF_ADJUST)
543 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
544 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
545 if(uFlags & BF_LEFT) rc->left += add;
546 if(uFlags & BF_RIGHT) rc->right -= add;
547 if(uFlags & BF_TOP) rc->top += add;
548 if(uFlags & BF_BOTTOM) rc->bottom -= add;
551 /* Cleanup */
552 SelectObject32(hdc, SavePen);
553 MoveToEx32(hdc, SavePoint.x, SavePoint.y, NULL);
554 return retval;
558 /**********************************************************************
559 * DrawEdge16 (USER.659)
561 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
563 RECT32 rect32;
564 BOOL32 ret;
566 CONV_RECT16TO32( rc, &rect32 );
567 ret = DrawEdge32( hdc, &rect32, edge, flags );
568 CONV_RECT32TO16( &rect32, rc );
569 return ret;
572 /**********************************************************************
573 * DrawEdge32 (USER32.154)
575 BOOL32 WINAPI DrawEdge32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
577 TRACE(graphics, "%04x %d,%d-%d,%d %04x %04x\n",
578 hdc, rc->left, rc->top, rc->right, rc->bottom,
579 edge, flags );
581 if(flags & BF_DIAGONAL)
582 return UITOOLS_DrawDiagEdge(hdc, rc, edge, flags);
583 else
584 return UITOOLS_DrawRectEdge(hdc, rc, edge, flags);
588 /************************************************************************
589 * UITOOLS_MakeSquareRect
591 * Utility to create a square rectangle and returning the width
593 static int UITOOLS_MakeSquareRect(LPRECT32 src, LPRECT32 dst)
595 int Width = src->right - src->left;
596 int Height = src->bottom - src->top;
597 int SmallDiam = Width > Height ? Height : Width;
599 *dst = *src;
601 /* Make it a square box */
602 if(Width < Height) /* SmallDiam == Width */
604 dst->top += (Height-Width)/2;
605 dst->bottom = dst->top + SmallDiam;
607 else if(Width > Height) /* SmallDiam == Height */
609 dst->left += (Width-Height)/2;
610 dst->right = dst->left + SmallDiam;
613 return SmallDiam;
617 /************************************************************************
618 * UITOOLS_DFC_ButtonPush
620 * Draw a push button coming from DrawFrameControl()
622 * Does a pretty good job in emulating MS behavior. Some quirks are
623 * however there because MS uses a TrueType font (Marlett) to draw
624 * the buttons.
626 static BOOL32 UITOOLS_DFC_ButtonPush(HDC32 dc, LPRECT32 r, UINT32 uFlags)
628 UINT32 edge;
629 RECT32 myr = *r;
631 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
632 edge = EDGE_SUNKEN;
633 else
634 edge = EDGE_RAISED;
636 if(uFlags & DFCS_CHECKED)
638 if(uFlags & DFCS_MONO)
639 UITOOLS_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
640 else
641 UITOOLS_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
643 if(GetSysColor32(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
645 HBITMAP32 hbm = CreateBitmap32(8, 8, 1, 1, wPattern_AA55);
646 HBRUSH32 hbsave;
647 HBRUSH32 hb = CreatePatternBrush32(hbm);
649 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
650 hbsave = (HBRUSH32)SelectObject32(dc, hb);
651 PatBlt32(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
652 SelectObject32(dc, hbsave);
653 DeleteObject32(hb);
654 DeleteObject32(hbm);
656 else
658 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
661 else
663 if(uFlags & DFCS_MONO)
665 UITOOLS_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
666 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
668 else
670 UITOOLS_DrawRectEdge(dc, r, edge, (uFlags&DFCS_FLAT) | BF_MIDDLE |BF_SOFT| BF_RECT);
674 /* Adjust rectangle if asked */
675 if(uFlags & DFCS_ADJUSTRECT)
677 r->left += 2;
678 r->right -= 2;
679 r->top += 2;
680 r->bottom -= 2;
683 return TRUE;
687 /************************************************************************
688 * UITOOLS_DFC_ButtonChcek
690 * Draw a check/3state button coming from DrawFrameControl()
692 * Does a pretty good job in emulating MS behavior. Some quirks are
693 * however there because MS uses a TrueType font (Marlett) to draw
694 * the buttons.
696 #define DFC_CHECKPOINTSMAX 6
698 static BOOL32 UITOOLS_DFC_ButtonCheck(HDC32 dc, LPRECT32 r, UINT32 uFlags)
700 RECT32 myr;
701 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
702 int BorderShrink = SmallDiam / 16;
704 if(BorderShrink < 1) BorderShrink = 1;
706 /* FIXME: The FillRect() sequence doesn't work for sizes less than */
707 /* 4 pixels in diameter. Not really a problem but it isn't M$'s */
708 /* 100% equivalent. */
709 if(uFlags & (DFCS_FLAT|DFCS_MONO))
711 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_WINDOWFRAME));
712 myr.left += 2 * BorderShrink;
713 myr.right -= 2 * BorderShrink;
714 myr.top += 2 * BorderShrink;
715 myr.bottom -= 2 * BorderShrink;
717 else
719 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
720 myr.right -= BorderShrink;
721 myr.bottom -= BorderShrink;
722 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNSHADOW));
723 myr.left += BorderShrink;
724 myr.top += BorderShrink;
725 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_3DLIGHT));
726 myr.right -= BorderShrink;
727 myr.bottom -= BorderShrink;
728 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_3DDKSHADOW));
729 myr.left += BorderShrink;
730 myr.top += BorderShrink;
733 if(uFlags & (DFCS_INACTIVE|DFCS_PUSHED))
735 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
737 else if(uFlags & DFCS_CHECKED)
739 if(GetSysColor32(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
741 HBITMAP32 hbm = CreateBitmap32(8, 8, 1, 1, wPattern_AA55);
742 HBRUSH32 hbsave;
743 HBRUSH32 hb = CreatePatternBrush32(hbm);
745 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
746 hbsave = (HBRUSH32)SelectObject32(dc, hb);
747 PatBlt32(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
748 SelectObject32(dc, hbsave);
749 DeleteObject32(hb);
750 DeleteObject32(hbm);
752 else
754 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
757 else
759 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_WINDOW));
762 if(uFlags & DFCS_CHECKED)
764 POINT32 CheckPoints[DFC_CHECKPOINTSMAX];
765 int i;
766 HBRUSH32 hbsave;
767 HPEN32 hpsave;
769 /* FIXME: This comes very close to M$'s checkmark, but not */
770 /* exactly... When small or large there is a few pixels */
771 /* shift. Not bad, but could be better :) */
772 UITOOLS_MakeSquareRect(r, &myr);
773 CheckPoints[0].x = myr.left + 253*SmallDiam/1000;
774 CheckPoints[0].y = myr.top + 345*SmallDiam/1000;
775 CheckPoints[1].x = myr.left + 409*SmallDiam/1000;
776 CheckPoints[1].y = CheckPoints[0].y + (CheckPoints[1].x-CheckPoints[0].x);
777 CheckPoints[2].x = myr.left + 690*SmallDiam/1000;
778 CheckPoints[2].y = CheckPoints[1].y - (CheckPoints[2].x-CheckPoints[1].x);
779 CheckPoints[3].x = CheckPoints[2].x;
780 CheckPoints[3].y = CheckPoints[2].y + 3*SmallDiam/16;
781 CheckPoints[4].x = CheckPoints[1].x;
782 CheckPoints[4].y = CheckPoints[1].y + 3*SmallDiam/16;
783 CheckPoints[5].x = CheckPoints[0].x;
784 CheckPoints[5].y = CheckPoints[0].y + 3*SmallDiam/16;
786 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
787 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
788 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(i));
789 Polygon32(dc, CheckPoints, DFC_CHECKPOINTSMAX);
790 SelectObject32(dc, hpsave);
791 SelectObject32(dc, hbsave);
793 return TRUE;
797 /************************************************************************
798 * UITOOLS_DFC_ButtonRadio
800 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
802 * Does a pretty good job in emulating MS behavior. Some quirks are
803 * however there because MS uses a TrueType font (Marlett) to draw
804 * the buttons.
806 static BOOL32 UITOOLS_DFC_ButtonRadio(HDC32 dc, LPRECT32 r, UINT32 uFlags)
808 RECT32 myr;
809 int i;
810 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
811 int BorderShrink = SmallDiam / 16;
812 HPEN32 hpsave;
813 HBRUSH32 hbsave;
814 int xe, ye;
815 int xc, yc;
817 if(BorderShrink < 1) BorderShrink = 1;
819 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
821 FillRect32(dc, r, (HBRUSH32)GetStockObject32(BLACK_BRUSH));
824 xe = myr.left;
825 ye = myr.top + SmallDiam - SmallDiam/2;
827 xc = myr.left + SmallDiam - SmallDiam/2;
828 yc = myr.top + SmallDiam - SmallDiam/2;
830 /* Define bounding box */
831 i = 14*SmallDiam/16;
832 myr.left = xc - i+i/2;
833 myr.right = xc + i/2;
834 myr.top = yc - i+i/2;
835 myr.bottom = yc + i/2;
837 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
839 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(BLACK_BRUSH));
840 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
841 SelectObject32(dc, hbsave);
843 else
845 if(uFlags & (DFCS_FLAT|DFCS_MONO))
847 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(COLOR_WINDOWFRAME));
848 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_WINDOWFRAME));
849 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
850 SelectObject32(dc, hbsave);
851 SelectObject32(dc, hpsave);
853 else
855 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(COLOR_BTNHIGHLIGHT));
856 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
857 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
859 SelectObject32(dc, GetSysColorPen32(COLOR_BTNSHADOW));
860 SelectObject32(dc, GetSysColorBrush32(COLOR_BTNSHADOW));
861 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
863 myr.left += BorderShrink;
864 myr.right -= BorderShrink;
865 myr.top += BorderShrink;
866 myr.bottom -= BorderShrink;
868 SelectObject32(dc, GetSysColorPen32(COLOR_3DLIGHT));
869 SelectObject32(dc, GetSysColorBrush32(COLOR_3DLIGHT));
870 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
872 SelectObject32(dc, GetSysColorPen32(COLOR_3DDKSHADOW));
873 SelectObject32(dc, GetSysColorBrush32(COLOR_3DDKSHADOW));
874 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
875 SelectObject32(dc, hbsave);
876 SelectObject32(dc, hpsave);
879 i = 10*SmallDiam/16;
880 myr.left = xc - i+i/2;
881 myr.right = xc + i/2;
882 myr.top = yc - i+i/2;
883 myr.bottom = yc + i/2;
884 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
885 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(i));
886 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
887 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
888 SelectObject32(dc, hbsave);
889 SelectObject32(dc, hpsave);
892 if(uFlags & DFCS_CHECKED)
894 i = 6*SmallDiam/16;
895 i = i < 1 ? 1 : i;
896 myr.left = xc - i+i/2;
897 myr.right = xc + i/2;
898 myr.top = yc - i+i/2;
899 myr.bottom = yc + i/2;
901 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
902 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
903 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(i));
904 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
905 SelectObject32(dc, hpsave);
906 SelectObject32(dc, hbsave);
909 /* FIXME: M$ has a polygon in the center at relative points: */
910 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
911 /* 0.476, 0.525 */
912 /* 0.500, 0.500 */
913 /* 0.500, 0.499 */
914 /* when the button is unchecked. The reason for it is unknown. The */
915 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
916 /* least 3 times (it looks like a clip-region when you see it happen). */
917 /* I do not really see a reason why this should be implemented. If you */
918 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
919 /* font. */
921 return TRUE;
924 /***********************************************************************
925 * UITOOLS_DrawFrameButton
927 static BOOL32 UITOOLS_DrawFrameButton(HDC32 hdc, LPRECT32 rc, UINT32 uState)
929 switch(uState & 0xff)
931 case DFCS_BUTTONPUSH:
932 return UITOOLS_DFC_ButtonPush(hdc, rc, uState);
934 case DFCS_BUTTONCHECK:
935 case DFCS_BUTTON3STATE:
936 return UITOOLS_DFC_ButtonCheck(hdc, rc, uState);
938 case DFCS_BUTTONRADIOIMAGE:
939 case DFCS_BUTTONRADIOMASK:
940 case DFCS_BUTTONRADIO:
941 return UITOOLS_DFC_ButtonRadio(hdc, rc, uState);
943 default:
944 WARN(uitools, "Invalid button state: 0x%04x\n", uState);
947 return FALSE;
950 /***********************************************************************
951 * UITOOLS_DrawFrameCaption
953 * Draw caption buttons (win95), coming from DrawFrameControl()
956 static BOOL32 UITOOLS_DrawFrameCaption(HDC32 dc, LPRECT32 r, UINT32 uFlags)
958 POINT32 Line1[10];
959 POINT32 Line2[10];
960 int Line1N;
961 int Line2N;
962 RECT32 myr;
963 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
964 int i;
965 HBRUSH32 hbsave;
966 HPEN32 hpsave;
967 HFONT32 hfsave, hf;
968 int xc = (myr.left+myr.right)/2;
969 int yc = (myr.top+myr.bottom)/2;
970 int edge, move;
971 char str[2] = "?";
972 UINT32 alignsave;
973 int bksave;
974 COLORREF clrsave;
975 SIZE32 size;
977 UITOOLS_DFC_ButtonPush(dc, r, uFlags & 0xff00);
979 switch(uFlags & 0xff)
981 case DFCS_CAPTIONCLOSE:
982 edge = 328*SmallDiam/1000;
983 move = 95*SmallDiam/1000;
984 Line1[0].x = Line2[0].x = Line1[1].x = Line2[1].x = xc - edge;
985 Line1[2].y = Line2[5].y = Line1[1].y = Line2[4].y = yc - edge;
986 Line1[3].x = Line2[3].x = Line1[4].x = Line2[4].x = xc + edge;
987 Line1[5].y = Line2[2].y = Line1[4].y = Line2[1].y = yc + edge;
988 Line1[2].x = Line2[2].x = Line1[1].x + move;
989 Line1[0].y = Line2[3].y = Line1[1].y + move;
990 Line1[5].x = Line2[5].x = Line1[4].x - move;
991 Line1[3].y = Line2[0].y = Line1[4].y - move;
992 Line1N = 6;
993 Line2N = 6;
994 break;
996 case DFCS_CAPTIONHELP:
997 /* This one breaks the flow */
998 /* FIXME: We need the Marlett font in order to get this right. */
1000 hf = CreateFont32A(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
1001 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
1002 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
1003 alignsave = SetTextAlign32(dc, TA_TOP|TA_LEFT);
1004 bksave = SetBkMode32(dc, TRANSPARENT);
1005 clrsave = GetTextColor32(dc);
1006 hfsave = (HFONT32)SelectObject32(dc, hf);
1007 GetTextExtentPoint32A(dc, str, 1, &size);
1009 if(uFlags & DFCS_INACTIVE)
1011 SetTextColor32(dc, GetSysColor32(COLOR_BTNHIGHLIGHT));
1012 TextOut32A(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
1014 SetTextColor32(dc, GetSysColor32(uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT));
1015 TextOut32A(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1017 SelectObject32(dc, hfsave);
1018 SetTextColor32(dc, clrsave);
1019 SetBkMode32(dc, bksave);
1020 SetTextAlign32(dc, alignsave);
1021 DeleteObject32(hf);
1022 return TRUE;
1024 case DFCS_CAPTIONMIN:
1025 Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2;
1026 Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1027 Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1;
1028 Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750;
1029 Line1N = 4;
1030 Line2N = 0;
1031 break;
1033 case DFCS_CAPTIONMAX:
1034 edge = 47*SmallDiam/750;
1035 Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3;
1036 Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1;
1037 Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1038 Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750;
1039 Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1040 Line1[3].x = Line1[4].x = Line1[1].x - edge;
1042 Line2[0].x = Line2[5].x = Line1[0].x;
1043 Line2[3].x = Line2[4].x = Line1[1].x;
1044 Line2[1].x = Line2[2].x = Line1[0].x + edge;
1045 Line2[0].y = Line2[1].y = Line1[0].y;
1046 Line2[4].y = Line2[5].y = Line1[2].y;
1047 Line2[2].y = Line2[3].y = Line1[2].y - edge;
1048 Line1N = 6;
1049 Line2N = 6;
1050 break;
1052 case DFCS_CAPTIONRESTORE:
1053 /* FIXME: this one looks bad at small sizes < 15x15 :( */
1054 edge = 47*SmallDiam/750;
1055 move = 420*SmallDiam/750;
1056 Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1057 Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1;
1058 Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1059 Line1[7].x = Line1[8].x = Line1[0].x + edge;
1060 Line1[1].x = Line1[2].x = Line1[0].x + move;
1061 Line1[5].x = Line1[6].x = Line1[1].x - edge;
1062 Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1063 Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1064 Line1[4].y = Line1[5].y = Line1[2].y - edge;
1065 Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1067 Line2[1].x = Line2[2].x = Line1[3].x;
1068 Line2[7].x = Line2[8].x = Line2[1].x - edge;
1069 Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1070 Line2[5].x = Line2[6].x = Line2[0].x + edge;
1071 Line2[0].y = Line2[1].y = Line1[9].y;
1072 Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1073 Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1074 Line2[6].y = Line2[7].y = Line2[2].y - edge;
1075 Line1N = 10;
1076 Line2N = 10;
1077 break;
1079 default:
1080 WARN(uitools, "Invalid caption; flags: 0x%04x\n", uFlags);
1081 return FALSE;
1084 /* Here the drawing takes place */
1085 if(uFlags & DFCS_INACTIVE)
1087 /* If we have an inactive button, then you see a shadow */
1088 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
1089 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(COLOR_BTNHIGHLIGHT));
1090 Polygon32(dc, Line1, Line1N);
1091 if(Line2N > 0)
1092 Polygon32(dc, Line2, Line2N);
1093 SelectObject32(dc, hpsave);
1094 SelectObject32(dc, hbsave);
1097 /* Correct for the shadow shift */
1098 for(i = 0; i < Line1N; i++)
1100 Line1[i].x--;
1101 Line1[i].y--;
1103 for(i = 0; i < Line2N; i++)
1105 Line2[i].x--;
1106 Line2[i].y--;
1109 /* Make the final picture */
1110 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1111 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
1112 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(i));
1114 Polygon32(dc, Line1, Line1N);
1115 if(Line2N > 0)
1116 Polygon32(dc, Line2, Line2N);
1117 SelectObject32(dc, hpsave);
1118 SelectObject32(dc, hbsave);
1120 return TRUE;
1124 /************************************************************************
1125 * UITOOLS_DrawFrameScroll
1127 * Draw a scroll-bar control coming from DrawFrameControl()
1129 static BOOL32 UITOOLS_DrawFrameScroll(HDC32 dc, LPRECT32 r, UINT32 uFlags)
1131 POINT32 Line[4];
1132 RECT32 myr;
1133 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1134 int i;
1135 HBRUSH32 hbsave, hb, hb2;
1136 HPEN32 hpsave, hp, hp2;
1137 int tri = 310*SmallDiam/1000;
1138 int d46, d93;
1140 switch(uFlags & 0xff)
1142 case DFCS_SCROLLCOMBOBOX:
1143 case DFCS_SCROLLDOWN:
1144 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1145 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
1146 Line[0].x = Line[2].x - tri;
1147 Line[1].x = Line[2].x + tri;
1148 Line[0].y = Line[1].y = Line[2].y - tri;
1149 break;
1151 case DFCS_SCROLLUP:
1152 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1153 Line[2].y = myr.top + 313*SmallDiam/1000 + 1;
1154 Line[0].x = Line[2].x - tri;
1155 Line[1].x = Line[2].x + tri;
1156 Line[0].y = Line[1].y = Line[2].y + tri;
1157 break;
1159 case DFCS_SCROLLLEFT:
1160 Line[2].x = myr.left + 313*SmallDiam/1000 + 1;
1161 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1162 Line[0].y = Line[2].y - tri;
1163 Line[1].y = Line[2].y + tri;
1164 Line[0].x = Line[1].x = Line[2].x + tri;
1165 break;
1167 case DFCS_SCROLLRIGHT:
1168 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1169 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1170 Line[0].y = Line[2].y - tri;
1171 Line[1].y = Line[2].y + tri;
1172 Line[0].x = Line[1].x = Line[2].x - tri;
1173 break;
1175 case DFCS_SCROLLSIZEGRIP:
1176 /* This one breaks the flow... */
1177 UITOOLS_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1178 hpsave = (HPEN32)SelectObject32(dc, GetStockObject32(NULL_PEN));
1179 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(NULL_BRUSH));
1180 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1182 hp = hp2 = GetSysColorPen32(COLOR_WINDOWFRAME);
1183 hb = hb2 = GetSysColorBrush32(COLOR_WINDOWFRAME);
1185 else
1187 hp = GetSysColorPen32(COLOR_BTNHIGHLIGHT);
1188 hp2 = GetSysColorPen32(COLOR_BTNSHADOW);
1189 hb = GetSysColorBrush32(COLOR_BTNHIGHLIGHT);
1190 hb2 = GetSysColorBrush32(COLOR_BTNSHADOW);
1192 Line[0].x = Line[1].x = r->right-1;
1193 Line[2].y = Line[3].y = r->bottom-1;
1194 d46 = 46*SmallDiam/750;
1195 d93 = 93*SmallDiam/750;
1197 i = 586*SmallDiam/750;
1198 Line[0].y = r->bottom - i - 1;
1199 Line[3].x = r->right - i - 1;
1200 Line[1].y = Line[0].y + d46;
1201 Line[2].x = Line[3].x + d46;
1202 SelectObject32(dc, hb);
1203 SelectObject32(dc, hp);
1204 Polygon32(dc, Line, 4);
1206 Line[1].y++; Line[2].x++;
1207 Line[0].y = Line[1].y + d93;
1208 Line[3].x = Line[2].x + d93;
1209 SelectObject32(dc, hb2);
1210 SelectObject32(dc, hp2);
1211 Polygon32(dc, Line, 4);
1213 i = 398*SmallDiam/750;
1214 Line[0].y = r->bottom - i - 1;
1215 Line[3].x = r->right - i - 1;
1216 Line[1].y = Line[0].y + d46;
1217 Line[2].x = Line[3].x + d46;
1218 SelectObject32(dc, hb);
1219 SelectObject32(dc, hp);
1220 Polygon32(dc, Line, 4);
1222 Line[1].y++; Line[2].x++;
1223 Line[0].y = Line[1].y + d93;
1224 Line[3].x = Line[2].x + d93;
1225 SelectObject32(dc, hb2);
1226 SelectObject32(dc, hp2);
1227 Polygon32(dc, Line, 4);
1229 i = 210*SmallDiam/750;
1230 Line[0].y = r->bottom - i - 1;
1231 Line[3].x = r->right - i - 1;
1232 Line[1].y = Line[0].y + d46;
1233 Line[2].x = Line[3].x + d46;
1234 SelectObject32(dc, hb);
1235 SelectObject32(dc, hp);
1236 Polygon32(dc, Line, 4);
1238 Line[1].y++; Line[2].x++;
1239 Line[0].y = Line[1].y + d93;
1240 Line[3].x = Line[2].x + d93;
1241 SelectObject32(dc, hb2);
1242 SelectObject32(dc, hp2);
1243 Polygon32(dc, Line, 4);
1245 SelectObject32(dc, hpsave);
1246 SelectObject32(dc, hbsave);
1247 return TRUE;
1249 default:
1250 WARN(uitools, "Invalid scroll; flags: 0x%04x\n", uFlags);
1251 return FALSE;
1254 /* Here do the real scroll-bar controls end up */
1255 UITOOLS_DFC_ButtonPush(dc, r, uFlags & 0xff00);
1257 if(uFlags & DFCS_INACTIVE)
1259 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
1260 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(COLOR_BTNHIGHLIGHT));
1261 Polygon32(dc, Line, 3);
1262 SelectObject32(dc, hpsave);
1263 SelectObject32(dc, hbsave);
1266 for(i = 0; i < 3; i++)
1268 Line[i].x--;
1269 Line[i].y--;
1272 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1273 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
1274 hpsave = (HPEN32)SelectObject32(dc, GetSysColorPen32(i));
1275 Polygon32(dc, Line, 3);
1276 SelectObject32(dc, hpsave);
1277 SelectObject32(dc, hbsave);
1279 return TRUE;
1282 /************************************************************************
1283 * UITOOLS_DrawFrameMenu
1285 * Draw a menu control coming from DrawFrameControl()
1287 static BOOL32 UITOOLS_DrawFrameMenu(HDC32 dc, LPRECT32 r, UINT32 uFlags)
1289 POINT32 Points[6];
1290 RECT32 myr;
1291 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1292 int i;
1293 HBRUSH32 hbsave;
1294 HPEN32 hpsave;
1295 int xe, ye;
1296 int xc, yc;
1297 BOOL32 retval = TRUE;
1299 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1300 /* use anything else. I think I tried all sys-colors to change things */
1301 /* without luck. It seems as if this behavior is inherited from the */
1302 /* win31 DFC() implementation... (you remember, B/W menus). */
1304 FillRect32(dc, r, (HBRUSH32)GetStockObject32(WHITE_BRUSH));
1306 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(BLACK_BRUSH));
1307 hpsave = (HPEN32)SelectObject32(dc, GetStockObject32(BLACK_PEN));
1309 switch(uFlags & 0xff)
1311 case DFCS_MENUARROW:
1312 i = 187*SmallDiam/750;
1313 Points[2].x = myr.left + 468*SmallDiam/750;
1314 Points[2].y = myr.top + 352*SmallDiam/750+1;
1315 Points[0].y = Points[2].y - i;
1316 Points[1].y = Points[2].y + i;
1317 Points[0].x = Points[1].x = Points[2].x - i;
1318 Polygon32(dc, Points, 3);
1319 break;
1321 case DFCS_MENUBULLET:
1322 xe = myr.left;
1323 ye = myr.top + SmallDiam - SmallDiam/2;
1324 xc = myr.left + SmallDiam - SmallDiam/2;
1325 yc = myr.top + SmallDiam - SmallDiam/2;
1326 i = 234*SmallDiam/750;
1327 i = i < 1 ? 1 : i;
1328 myr.left = xc - i+i/2;
1329 myr.right = xc + i/2;
1330 myr.top = yc - i+i/2;
1331 myr.bottom = yc + i/2;
1332 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1333 break;
1335 case DFCS_MENUCHECK:
1336 Points[0].x = myr.left + 253*SmallDiam/1000;
1337 Points[0].y = myr.top + 445*SmallDiam/1000;
1338 Points[1].x = myr.left + 409*SmallDiam/1000;
1339 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1340 Points[2].x = myr.left + 690*SmallDiam/1000;
1341 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1342 Points[3].x = Points[2].x;
1343 Points[3].y = Points[2].y + 3*SmallDiam/16;
1344 Points[4].x = Points[1].x;
1345 Points[4].y = Points[1].y + 3*SmallDiam/16;
1346 Points[5].x = Points[0].x;
1347 Points[5].y = Points[0].y + 3*SmallDiam/16;
1348 Polygon32(dc, Points, 6);
1349 break;
1351 default:
1352 WARN(uitools, "Invalid menu; flags: 0x%04x\n", uFlags);
1353 retval = FALSE;
1354 break;
1357 SelectObject32(dc, hpsave);
1358 SelectObject32(dc, hbsave);
1359 return retval;
1363 /**********************************************************************
1364 * DrawFrameControl16 (USER.656)
1366 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType,
1367 UINT16 uState )
1369 RECT32 rect32;
1370 BOOL32 ret;
1372 CONV_RECT16TO32( rc, &rect32 );
1373 ret = DrawFrameControl32( hdc, &rect32, uType, uState );
1374 CONV_RECT32TO16( &rect32, rc );
1375 return ret;
1379 /**********************************************************************
1380 * DrawFrameControl32 (USER32.157)
1382 BOOL32 WINAPI DrawFrameControl32( HDC32 hdc, LPRECT32 rc, UINT32 uType,
1383 UINT32 uState )
1385 /* Win95 doesn't support drawing in other mapping modes */
1386 if(GetMapMode32(hdc) != MM_TEXT)
1387 return FALSE;
1389 switch(uType)
1391 case DFC_BUTTON:
1392 return UITOOLS_DrawFrameButton(hdc, rc, uState);
1393 case DFC_CAPTION:
1394 return UITOOLS_DrawFrameCaption(hdc, rc, uState);
1395 case DFC_MENU:
1396 return UITOOLS_DrawFrameMenu(hdc, rc, uState);
1397 case DFC_SCROLL:
1398 return UITOOLS_DrawFrameScroll(hdc, rc, uState);
1399 default:
1400 WARN(uitools, "(%x,%p,%d,%x), bad type!\n",
1401 hdc,rc,uType,uState );
1403 return FALSE;