Correct SIZE_T size according to MS SDK.
[wine] / controls / uitools.c
1 /*
2  * User Interface Functions
3  *
4  * Copyright 1997 Dimitrie O. Paun
5  * Copyright 1997 Bertho A. Stultiens
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "wine/winuser16.h"
25 #include "winuser.h"
26 #include "user.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
30
31 static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555,
32                                        0xaaaa, 0x5555, 0xaaaa, 0x5555 };
33
34 /* These tables are used in:
35  * UITOOLS_DrawDiagEdge()
36  * UITOOLS_DrawRectEdge()
37  */
38 static const signed char LTInnerNormal[] = {
39     -1,           -1,                 -1,                 -1,
40     -1,           COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
41     -1,           COLOR_3DDKSHADOW,   COLOR_3DDKSHADOW,   -1,
42     -1,           -1,                 -1,                 -1
43 };
44
45 static const signed char LTOuterNormal[] = {
46     -1,                 COLOR_3DLIGHT,     COLOR_BTNSHADOW, -1,
47     COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT,     COLOR_BTNSHADOW, -1,
48     COLOR_3DDKSHADOW,   COLOR_3DLIGHT,     COLOR_BTNSHADOW, -1,
49     -1,                 COLOR_3DLIGHT,     COLOR_BTNSHADOW, -1
50 };
51
52 static const signed char RBInnerNormal[] = {
53     -1,           -1,                -1,              -1,
54     -1,           COLOR_BTNSHADOW,   COLOR_BTNSHADOW, -1,
55     -1,           COLOR_3DLIGHT,     COLOR_3DLIGHT,   -1,
56     -1,           -1,                -1,              -1
57 };
58
59 static const signed char RBOuterNormal[] = {
60     -1,              COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
61     COLOR_BTNSHADOW, COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
62     COLOR_3DLIGHT,   COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
63     -1,              COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1
64 };
65
66 static const signed char LTInnerSoft[] = {
67     -1,                  -1,                -1,              -1,
68     -1,                  COLOR_3DLIGHT,     COLOR_3DLIGHT,   -1,
69     -1,                  COLOR_BTNSHADOW,   COLOR_BTNSHADOW, -1,
70     -1,                  -1,                -1,              -1
71 };
72
73 static const signed char LTOuterSoft[] = {
74     -1,              COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
75     COLOR_3DLIGHT,   COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
76     COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
77     -1,              COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
78 };
79
80 #define RBInnerSoft RBInnerNormal   /* These are the same */
81 #define RBOuterSoft RBOuterNormal
82
83 static const signed char LTRBOuterMono[] = {
84     -1,           COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
85     COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
86     COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
87     COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
88 };
89
90 static const signed char LTRBInnerMono[] = {
91     -1, -1,           -1,           -1,
92     -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
93     -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
94     -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
95 };
96
97 static const signed char LTRBOuterFlat[] = {
98     -1,                COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
99     COLOR_BTNFACE,     COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
100     COLOR_BTNFACE,     COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
101     COLOR_BTNFACE,     COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
102 };
103
104 static const signed char LTRBInnerFlat[] = {
105     -1, -1,              -1,              -1,
106     -1, COLOR_BTNFACE,     COLOR_BTNFACE,     COLOR_BTNFACE,
107     -1, COLOR_BTNFACE,     COLOR_BTNFACE,     COLOR_BTNFACE,
108     -1, COLOR_BTNFACE,     COLOR_BTNFACE,     COLOR_BTNFACE,
109 };
110
111 /***********************************************************************
112  *           UITOOLS_DrawDiagEdge
113  *
114  * Same as DrawEdge invoked with BF_DIAGONAL
115  *
116  * 03-Dec-1997: Changed by Bertho Stultiens
117  *
118  * See also comments with UITOOLS_DrawRectEdge()
119  */
120 static BOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc,
121                                      UINT uType, UINT uFlags)
122 {
123     POINT Points[4];
124     signed char InnerI, OuterI;
125     HPEN InnerPen, OuterPen;
126     POINT SavePoint;
127     HPEN SavePen;
128     int spx, spy;
129     int epx, epy;
130     int Width = rc->right - rc->left;
131     int Height= rc->bottom - rc->top;
132     int SmallDiam = Width > Height ? Height : Width;
133     BOOL retval = !(   ((uType & BDR_INNER) == BDR_INNER
134                        || (uType & BDR_OUTER) == BDR_OUTER)
135                       && !(uFlags & (BF_FLAT|BF_MONO)) );
136     int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
137             + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
138
139     /* Init some vars */
140     OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
141     SavePen = (HPEN)SelectObject(hdc, InnerPen);
142     spx = spy = epx = epy = 0; /* Satisfy the compiler... */
143
144     /* Determine the colors of the edges */
145     if(uFlags & BF_MONO)
146     {
147         InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
148         OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
149     }
150     else if(uFlags & BF_FLAT)
151     {
152         InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
153         OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
154     }
155     else if(uFlags & BF_SOFT)
156     {
157         if(uFlags & BF_BOTTOM)
158         {
159             InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
160             OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
161         }
162         else
163         {
164             InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
165             OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
166         }
167     }
168     else
169     {
170         if(uFlags & BF_BOTTOM)
171         {
172             InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
173             OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
174         }
175         else
176         {
177             InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
178             OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
179         }
180     }
181
182     if(InnerI != -1) InnerPen = SYSCOLOR_GetPen(InnerI);
183     if(OuterI != -1) OuterPen = SYSCOLOR_GetPen(OuterI);
184
185     MoveToEx(hdc, 0, 0, &SavePoint);
186
187     /* Don't ask me why, but this is what is visible... */
188     /* This must be possible to do much simpler, but I fail to */
189     /* see the logic in the MS implementation (sigh...). */
190     /* So, this might look a bit brute force here (and it is), but */
191     /* it gets the job done;) */
192
193     switch(uFlags & BF_RECT)
194     {
195     case 0:
196     case BF_LEFT:
197     case BF_BOTTOM:
198     case BF_BOTTOMLEFT:
199         /* Left bottom endpoint */
200         epx = rc->left-1;
201         spx = epx + SmallDiam;
202         epy = rc->bottom;
203         spy = epy - SmallDiam;
204         break;
205
206     case BF_TOPLEFT:
207     case BF_BOTTOMRIGHT:
208         /* Left top endpoint */
209         epx = rc->left-1;
210         spx = epx + SmallDiam;
211         epy = rc->top-1;
212         spy = epy + SmallDiam;
213         break;
214
215     case BF_TOP:
216     case BF_RIGHT:
217     case BF_TOPRIGHT:
218     case BF_RIGHT|BF_LEFT:
219     case BF_RIGHT|BF_LEFT|BF_TOP:
220     case BF_BOTTOM|BF_TOP:
221     case BF_BOTTOM|BF_TOP|BF_LEFT:
222     case BF_BOTTOMRIGHT|BF_LEFT:
223     case BF_BOTTOMRIGHT|BF_TOP:
224     case BF_RECT:
225         /* Right top endpoint */
226         spx = rc->left;
227         epx = spx + SmallDiam;
228         spy = rc->bottom-1;
229         epy = spy - SmallDiam;
230         break;
231     }
232
233     MoveToEx(hdc, spx, spy, NULL);
234     SelectObject(hdc, OuterPen);
235     LineTo(hdc, epx, epy);
236
237     SelectObject(hdc, InnerPen);
238
239     switch(uFlags & (BF_RECT|BF_DIAGONAL))
240     {
241     case BF_DIAGONAL_ENDBOTTOMLEFT:
242     case (BF_DIAGONAL|BF_BOTTOM):
243     case BF_DIAGONAL:
244     case (BF_DIAGONAL|BF_LEFT):
245         MoveToEx(hdc, spx-1, spy, NULL);
246         LineTo(hdc, epx, epy-1);
247         Points[0].x = spx-add;
248         Points[0].y = spy;
249         Points[1].x = rc->left;
250         Points[1].y = rc->top;
251         Points[2].x = epx+1;
252         Points[2].y = epy-1-add;
253         Points[3] = Points[2];
254         break;
255
256     case BF_DIAGONAL_ENDBOTTOMRIGHT:
257         MoveToEx(hdc, spx-1, spy, NULL);
258         LineTo(hdc, epx, epy+1);
259         Points[0].x = spx-add;
260         Points[0].y = spy;
261         Points[1].x = rc->left;
262         Points[1].y = rc->bottom-1;
263         Points[2].x = epx+1;
264         Points[2].y = epy+1+add;
265         Points[3] = Points[2];
266         break;
267
268     case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
269     case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
270     case BF_DIAGONAL_ENDTOPRIGHT:
271     case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
272         MoveToEx(hdc, spx+1, spy, NULL);
273         LineTo(hdc, epx, epy+1);
274         Points[0].x = epx-1;
275         Points[0].y = epy+1+add;
276         Points[1].x = rc->right-1;
277         Points[1].y = rc->top+add;
278         Points[2].x = rc->right-1;
279         Points[2].y = rc->bottom-1;
280         Points[3].x = spx+add;
281         Points[3].y = spy;
282         break;
283
284     case BF_DIAGONAL_ENDTOPLEFT:
285         MoveToEx(hdc, spx, spy-1, NULL);
286         LineTo(hdc, epx+1, epy);
287         Points[0].x = epx+1+add;
288         Points[0].y = epy+1;
289         Points[1].x = rc->right-1;
290         Points[1].y = rc->top;
291         Points[2].x = rc->right-1;
292         Points[2].y = rc->bottom-1-add;
293         Points[3].x = spx;
294         Points[3].y = spy-add;
295         break;
296
297     case (BF_DIAGONAL|BF_TOP):
298     case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
299     case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
300         MoveToEx(hdc, spx+1, spy-1, NULL);
301         LineTo(hdc, epx, epy);
302         Points[0].x = epx-1;
303         Points[0].y = epy+1;
304         Points[1].x = rc->right-1;
305         Points[1].y = rc->top;
306         Points[2].x = rc->right-1;
307         Points[2].y = rc->bottom-1-add;
308         Points[3].x = spx+add;
309         Points[3].y = spy-add;
310         break;
311
312     case (BF_DIAGONAL|BF_RIGHT):
313     case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
314     case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
315         MoveToEx(hdc, spx, spy, NULL);
316         LineTo(hdc, epx-1, epy+1);
317         Points[0].x = spx;
318         Points[0].y = spy;
319         Points[1].x = rc->left;
320         Points[1].y = rc->top+add;
321         Points[2].x = epx-1-add;
322         Points[2].y = epy+1+add;
323         Points[3] = Points[2];
324         break;
325     }
326
327     /* Fill the interior if asked */
328     if((uFlags & BF_MIDDLE) && retval)
329     {
330         HBRUSH hbsave;
331         HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW
332                                          :COLOR_BTNFACE);
333         HPEN hpsave;
334         HPEN hp = SYSCOLOR_GetPen(uFlags & BF_MONO ? COLOR_WINDOW
335                                      : COLOR_BTNFACE);
336         hbsave = (HBRUSH)SelectObject(hdc, hb);
337         hpsave = (HPEN)SelectObject(hdc, hp);
338         Polygon(hdc, Points, 4);
339         SelectObject(hdc, hbsave);
340         SelectObject(hdc, hpsave);
341     }
342
343     /* Adjust rectangle if asked */
344     if(uFlags & BF_ADJUST)
345     {
346         if(uFlags & BF_LEFT)   rc->left   += add;
347         if(uFlags & BF_RIGHT)  rc->right  -= add;
348         if(uFlags & BF_TOP)    rc->top    += add;
349         if(uFlags & BF_BOTTOM) rc->bottom -= add;
350     }
351
352     /* Cleanup */
353     SelectObject(hdc, SavePen);
354     MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
355
356     return retval;
357 }
358
359 /***********************************************************************
360  *           UITOOLS_DrawRectEdge
361  *
362  * Same as DrawEdge invoked without BF_DIAGONAL
363  *
364  * 23-Nov-1997: Changed by Bertho Stultiens
365  *
366  * Well, I started testing this and found out that there are a few things
367  * that weren't quite as win95. The following rewrite should reproduce
368  * win95 results completely.
369  * The colorselection is table-driven to avoid awfull if-statements.
370  * The table below show the color settings.
371  *
372  * Pen selection table for uFlags = 0
373  *
374  * uType |  LTI  |  LTO  |  RBI  |  RBO
375  * ------+-------+-------+-------+-------
376  *  0000 |   x   |   x   |   x   |   x
377  *  0001 |   x   |  22   |   x   |  21
378  *  0010 |   x   |  16   |   x   |  20
379  *  0011 |   x   |   x   |   x   |   x
380  * ------+-------+-------+-------+-------
381  *  0100 |   x   |  20   |   x   |  16
382  *  0101 |  20   |  22   |  16   |  21
383  *  0110 |  20   |  16   |  16   |  20
384  *  0111 |   x   |   x   |   x   |   x
385  * ------+-------+-------+-------+-------
386  *  1000 |   x   |  21   |   x   |  22
387  *  1001 |  21   |  22   |  22   |  21
388  *  1010 |  21   |  16   |  22   |  20
389  *  1011 |   x   |   x   |   x   |   x
390  * ------+-------+-------+-------+-------
391  *  1100 |   x   |   x   |   x   |   x
392  *  1101 |   x   | x (22)|   x   | x (21)
393  *  1110 |   x   | x (16)|   x   | x (20)
394  *  1111 |   x   |   x   |   x   |   x
395  *
396  * Pen selection table for uFlags = BF_SOFT
397  *
398  * uType |  LTI  |  LTO  |  RBI  |  RBO
399  * ------+-------+-------+-------+-------
400  *  0000 |   x   |   x   |   x   |   x
401  *  0001 |   x   |  20   |   x   |  21
402  *  0010 |   x   |  21   |   x   |  20
403  *  0011 |   x   |   x   |   x   |   x
404  * ------+-------+-------+-------+-------
405  *  0100 |   x   |  22   |   x   |  16
406  *  0101 |  22   |  20   |  16   |  21
407  *  0110 |  22   |  21   |  16   |  20
408  *  0111 |   x   |   x   |   x   |   x
409  * ------+-------+-------+-------+-------
410  *  1000 |   x   |  16   |   x   |  22
411  *  1001 |  16   |  20   |  22   |  21
412  *  1010 |  16   |  21   |  22   |  20
413  *  1011 |   x   |   x   |   x   |   x
414  * ------+-------+-------+-------+-------
415  *  1100 |   x   |   x   |   x   |   x
416  *  1101 |   x   | x (20)|   x   | x (21)
417  *  1110 |   x   | x (21)|   x   | x (20)
418  *  1111 |   x   |   x   |   x   |   x
419  *
420  * x = don't care; (n) = is what win95 actually uses
421  * LTI = left Top Inner line
422  * LTO = left Top Outer line
423  * RBI = Right Bottom Inner line
424  * RBO = Right Bottom Outer line
425  * 15 = COLOR_BTNFACE
426  * 16 = COLOR_BTNSHADOW
427  * 20 = COLOR_BTNHIGHLIGHT
428  * 21 = COLOR_3DDKSHADOW
429  * 22 = COLOR_3DLIGHT
430  */
431
432
433 static BOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc,
434                                      UINT uType, UINT uFlags)
435 {
436     signed char LTInnerI, LTOuterI;
437     signed char RBInnerI, RBOuterI;
438     HPEN LTInnerPen, LTOuterPen;
439     HPEN RBInnerPen, RBOuterPen;
440     RECT InnerRect = *rc;
441     POINT SavePoint;
442     HPEN SavePen;
443     int LBpenplus = 0;
444     int LTpenplus = 0;
445     int RTpenplus = 0;
446     int RBpenplus = 0;
447     BOOL retval = !(   ((uType & BDR_INNER) == BDR_INNER
448                        || (uType & BDR_OUTER) == BDR_OUTER)
449                       && !(uFlags & (BF_FLAT|BF_MONO)) );
450
451     /* Init some vars */
452     LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
453     SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
454
455     /* Determine the colors of the edges */
456     if(uFlags & BF_MONO)
457     {
458         LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
459         LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
460     }
461     else if(uFlags & BF_FLAT)
462     {
463         LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
464         LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
465
466         /* Bertho Stultiens states above that this function exactly matches win95
467          * In win98 BF_FLAT rectangles have an inner border same color as the
468          * middle (COLOR_BTNFACE). I believe it's the same for win95 but since
469          * I don't know I go with Bertho and just sets it for win98 until proven
470          * otherwise.
471          *                                          Dennis Björklund, 10 June, 99
472          */
473         if( TWEAK_WineLook == WIN98_LOOK && LTInnerI != -1 )
474             LTInnerI = RBInnerI = COLOR_BTNFACE;
475     }
476     else if(uFlags & BF_SOFT)
477     {
478         LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
479         LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
480         RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
481         RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
482     }
483     else
484     {
485         LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
486         LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
487         RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
488         RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
489     }
490
491     if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT)   LBpenplus = 1;
492     if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT)       RTpenplus = 1;
493     if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
494     if((uFlags & BF_TOPLEFT) == BF_TOPLEFT)         LTpenplus = 1;
495
496     if(LTInnerI != -1) LTInnerPen = SYSCOLOR_GetPen(LTInnerI);
497     if(LTOuterI != -1) LTOuterPen = SYSCOLOR_GetPen(LTOuterI);
498     if(RBInnerI != -1) RBInnerPen = SYSCOLOR_GetPen(RBInnerI);
499     if(RBOuterI != -1) RBOuterPen = SYSCOLOR_GetPen(RBOuterI);
500
501     MoveToEx(hdc, 0, 0, &SavePoint);
502
503     /* Draw the outer edge */
504     SelectObject(hdc, LTOuterPen);
505     if(uFlags & BF_TOP)
506     {
507         MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
508         LineTo(hdc, InnerRect.right, InnerRect.top);
509     }
510     if(uFlags & BF_LEFT)
511     {
512         MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
513         LineTo(hdc, InnerRect.left, InnerRect.bottom);
514     }
515     SelectObject(hdc, RBOuterPen);
516     if(uFlags & BF_BOTTOM)
517     {
518         MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
519         LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1);
520     }
521     if(uFlags & BF_RIGHT)
522     {
523         MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
524         LineTo(hdc, InnerRect.right-1, InnerRect.top-1);
525     }
526
527     /* Draw the inner edge */
528     SelectObject(hdc, LTInnerPen);
529     if(uFlags & BF_TOP)
530     {
531         MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
532         LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
533     }
534     if(uFlags & BF_LEFT)
535     {
536         MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
537         LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
538     }
539     SelectObject(hdc, RBInnerPen);
540     if(uFlags & BF_BOTTOM)
541     {
542         MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
543         LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
544     }
545     if(uFlags & BF_RIGHT)
546     {
547         MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
548         LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
549     }
550
551     if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
552     {
553         int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
554                 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
555
556         if(uFlags & BF_LEFT)   InnerRect.left   += add;
557         if(uFlags & BF_RIGHT)  InnerRect.right  -= add;
558         if(uFlags & BF_TOP)    InnerRect.top    += add;
559         if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
560
561         if((uFlags & BF_MIDDLE) && retval)
562         {
563             FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ?
564                                                        COLOR_WINDOW : COLOR_BTNFACE));
565         }
566
567         if(uFlags & BF_ADJUST)
568             *rc = InnerRect;
569     }
570
571     /* Cleanup */
572     SelectObject(hdc, SavePen);
573     MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
574     return retval;
575 }
576
577
578 /**********************************************************************
579  *          DrawEdge   (USER.659)
580  */
581 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
582 {
583     RECT rect32;
584     BOOL ret;
585
586     CONV_RECT16TO32( rc, &rect32 );
587     ret = DrawEdge( hdc, &rect32, edge, flags );
588     CONV_RECT32TO16( &rect32, rc );
589     return ret;
590 }
591
592 /**********************************************************************
593  *          DrawEdge   (USER32.@)
594  */
595 BOOL WINAPI DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags )
596 {
597     TRACE("%04x %d,%d-%d,%d %04x %04x\n",
598           hdc, rc->left, rc->top, rc->right, rc->bottom, edge, flags );
599
600     if(flags & BF_DIAGONAL)
601       return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags);
602     else
603       return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags);
604 }
605
606
607 /************************************************************************
608  *      UITOOLS_MakeSquareRect
609  *
610  * Utility to create a square rectangle and returning the width
611  */
612 static int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst)
613 {
614     int Width  = src->right - src->left;
615     int Height = src->bottom - src->top;
616     int SmallDiam = Width > Height ? Height : Width;
617
618     *dst = *src;
619
620     /* Make it a square box */
621     if(Width < Height)      /* SmallDiam == Width */
622     {
623         dst->top += (Height-Width)/2;
624         dst->bottom = dst->top + SmallDiam;
625     }
626     else if(Width > Height) /* SmallDiam == Height */
627     {
628         dst->left += (Width-Height)/2;
629         dst->right = dst->left + SmallDiam;
630     }
631
632    return SmallDiam;
633 }
634
635 static void UITOOLS_DrawCheckedRect( HDC dc, LPRECT rect )
636 {
637     if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
638     {
639       HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wPattern_AA55);
640       HBRUSH hbsave;
641       HBRUSH hb = CreatePatternBrush(hbm);
642       COLORREF bg;
643
644       FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
645       bg = SetBkColor(dc, RGB(255, 255, 255));
646       hbsave = (HBRUSH)SelectObject(dc, hb);
647       PatBlt(dc, rect->left, rect->top, rect->right-rect->left, rect->bottom-rect->top, 0x00FA0089);
648       SelectObject(dc, hbsave);
649       SetBkColor(dc, bg);
650       DeleteObject(hb);
651       DeleteObject(hbm);
652     }
653     else
654     {
655         FillRect(dc, rect, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
656     }
657 }
658
659 /************************************************************************
660  *      UITOOLS_DFC_ButtonPush
661  *
662  * Draw a push button coming from DrawFrameControl()
663  *
664  * Does a pretty good job in emulating MS behavior. Some quirks are
665  * however there because MS uses a TrueType font (Marlett) to draw
666  * the buttons.
667  */
668 static BOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags)
669 {
670     UINT edge;
671     RECT myr = *r;
672
673     if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
674         edge = EDGE_SUNKEN;
675     else
676         edge = EDGE_RAISED;
677
678     if(uFlags & DFCS_CHECKED)
679     {
680         if(uFlags & DFCS_MONO)
681             UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
682         else
683             UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
684
685         if (!(uFlags & DFCS_TRANSPARENT))
686             UITOOLS_DrawCheckedRect( dc, &myr );
687     }
688     else
689     {
690         if(uFlags & DFCS_MONO)
691         {
692             UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
693             if (!(uFlags & DFCS_TRANSPARENT))
694                 FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
695         }
696         else
697         {
698             UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags & DFCS_FLAT) | ((uFlags & DFCS_TRANSPARENT) ? 0 : BF_MIDDLE) | BF_RECT);
699         }
700     }
701
702     /* Adjust rectangle if asked */
703     if(uFlags & DFCS_ADJUSTRECT)
704     {
705         r->left   += 2;
706         r->right  -= 2;
707         r->top    += 2;
708         r->bottom -= 2;
709     }
710
711     return TRUE;
712 }
713
714
715 /************************************************************************
716  *      UITOOLS_DFC_ButtonChcek
717  *
718  * Draw a check/3state button coming from DrawFrameControl()
719  *
720  * Does a pretty good job in emulating MS behavior. Some quirks are
721  * however there because MS uses a TrueType font (Marlett) to draw
722  * the buttons.
723  */
724
725 static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
726 {
727     RECT myr, bar;
728     UINT flags = BF_RECT | BF_ADJUST;
729
730     UITOOLS_MakeSquareRect(r, &myr);
731
732     if(uFlags & DFCS_FLAT) flags |= BF_FLAT;
733     else if(uFlags & DFCS_MONO) flags |= BF_MONO;
734
735     UITOOLS95_DrawRectEdge( dc, &myr, EDGE_SUNKEN, flags );
736
737     if (!(uFlags & DFCS_TRANSPARENT))
738     {
739         if(uFlags & (DFCS_INACTIVE | DFCS_PUSHED))
740             FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE));
741         else if( (uFlags & DFCS_BUTTON3STATE) && (uFlags & DFCS_CHECKED) )
742             UITOOLS_DrawCheckedRect( dc, &myr );
743         else
744             FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW));
745     }
746
747     if(uFlags & DFCS_CHECKED)
748     {
749         int i, k;
750         i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ?
751                 COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
752
753         /* draw 7 bars, with h=3w to form the check */
754         bar.left = myr.left;
755         bar.top = myr.top + 2;
756         for (k = 0; k < 7; k++) {
757             bar.left = bar.left + 1;
758             bar.top = (k < 3) ? bar.top + 1 : bar.top - 1;
759             bar.bottom = bar.top + 3;
760             bar.right = bar.left + 1;
761             FillRect(dc, &bar, GetSysColorBrush(i));
762         }
763     }
764     return TRUE;
765 }
766
767
768 /************************************************************************
769  *      UITOOLS_DFC_ButtonRadio
770  *
771  * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
772  *
773  * Does a pretty good job in emulating MS behavior. Some quirks are
774  * however there because MS uses a TrueType font (Marlett) to draw
775  * the buttons.
776  */
777 static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
778 {
779     RECT myr;
780     int i;
781     int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
782     int BorderShrink = SmallDiam / 16;
783     HPEN hpsave;
784     HBRUSH hbsave;
785     int xc, yc;
786
787     if(BorderShrink < 1) BorderShrink = 1;
788
789     if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
790         FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
791
792     xc = myr.left + SmallDiam - SmallDiam/2;
793     yc = myr.top  + SmallDiam - SmallDiam/2;
794
795     /* Define bounding box */
796     i = 14*SmallDiam/16;
797     myr.left   = xc - i+i/2;
798     myr.right  = xc + i/2;
799     myr.top    = yc - i+i/2;
800     myr.bottom = yc + i/2;
801
802     if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
803     {
804         hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
805         Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
806         SelectObject(dc, hbsave);
807     }
808     else
809     {
810         if(uFlags & (DFCS_FLAT|DFCS_MONO))
811         {
812             hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
813             hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
814             Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
815             SelectObject(dc, hbsave);
816             SelectObject(dc, hpsave);
817         }
818         else
819         {
820             hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
821             hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
822             Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
823
824             SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNSHADOW));
825             SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
826             Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
827
828             myr.left   += BorderShrink;
829             myr.right  -= BorderShrink;
830             myr.top    += BorderShrink;
831             myr.bottom -= BorderShrink;
832
833             SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DLIGHT));
834             SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
835             Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
836
837             SelectObject(dc, SYSCOLOR_GetPen(COLOR_3DDKSHADOW));
838             SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
839             Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
840             SelectObject(dc, hbsave);
841             SelectObject(dc, hpsave);
842         }
843
844         i = 10*SmallDiam/16;
845         myr.left   = xc - i+i/2;
846         myr.right  = xc + i/2;
847         myr.top    = yc - i+i/2;
848         myr.bottom = yc + i/2;
849         i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
850         hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
851         hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
852         Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
853         SelectObject(dc, hbsave);
854         SelectObject(dc, hpsave);
855     }
856
857     if(uFlags & DFCS_CHECKED)
858     {
859         i = 6*SmallDiam/16;
860         i = i < 1 ? 1 : i;
861         myr.left   = xc - i+i/2;
862         myr.right  = xc + i/2;
863         myr.top    = yc - i+i/2;
864         myr.bottom = yc + i/2;
865
866         i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
867         hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
868         hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
869         Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
870         SelectObject(dc, hpsave);
871         SelectObject(dc, hbsave);
872     }
873
874     /* FIXME: M$ has a polygon in the center at relative points: */
875     /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
876     /* 0.476, 0.525 */
877     /* 0.500, 0.500 */
878     /* 0.500, 0.499 */
879     /* when the button is unchecked. The reason for it is unknown. The */
880     /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
881     /* least 3 times (it looks like a clip-region when you see it happen). */
882     /* I do not really see a reason why this should be implemented. If you */
883     /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
884     /* font. */
885
886     return TRUE;
887 }
888
889 /***********************************************************************
890  *           UITOOLS_DrawFrameButton
891  */
892 static BOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState)
893 {
894     switch(uState & 0xff)
895     {
896     case DFCS_BUTTONPUSH:
897         return UITOOLS95_DFC_ButtonPush(hdc, rc, uState);
898
899     case DFCS_BUTTONCHECK:
900     case DFCS_BUTTON3STATE:
901         return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState);
902
903     case DFCS_BUTTONRADIOIMAGE:
904     case DFCS_BUTTONRADIOMASK:
905     case DFCS_BUTTONRADIO:
906         return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState);
907
908     default:
909         WARN("Invalid button state=0x%04x\n", uState);
910     }
911
912     return FALSE;
913 }
914
915 /***********************************************************************
916  *           UITOOLS_DrawFrameCaption
917  *
918  * Draw caption buttons (win95), coming from DrawFrameControl()
919  */
920
921 static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
922 {
923     POINT Line1[10];
924     POINT Line2[10];
925     int Line1N;
926     int Line2N;
927     RECT myr;
928     int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
929     int i;
930     HBRUSH hbsave;
931     HPEN hpsave;
932     HFONT hfsave, hf;
933     int colorIdx = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
934     int xc = (myr.left+myr.right)/2;
935     int yc = (myr.top+myr.bottom)/2;
936     int edge, move;
937     char str[2] = "?";
938     UINT alignsave;
939     int bksave;
940     COLORREF clrsave;
941     SIZE size;
942
943     UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00);
944
945     switch(uFlags & 0xff)
946     {
947     case DFCS_CAPTIONCLOSE:
948     {
949         /* The "X" is made by drawing a series of lines.
950          * The number of lines drawn depends on the size
951          * of the bounding rect.  e.g. For a 6x5 inside rect,
952          * two lines are drawn from top-left to bottom-right,
953          * and two lines from top-right to bottom-left.
954          *
955          * 0 1 2 3 4 5       0 1 2 3 4 5
956          * 1 * *                     * *
957          * 2   * *                 * *
958          * 3     * *             * *
959          * 4       * *         * *
960          *
961          * Drawing one line for every 6 pixels in width
962          * seems to provide the best proportions.
963          */
964
965         POINT start, oldPos;
966         INT width = myr.right - myr.left - 5;
967         INT height = myr.bottom - myr.top - 6;
968         INT numLines = (width / 6) + 1;
969
970         hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
971
972         start.x = myr.left + 2;
973         start.y = myr.top + 2;
974
975         if (width < 6)
976             height = width;
977         else
978             start.y++;
979
980         if (uFlags & DFCS_PUSHED)
981         {
982             start.x++;
983                         start.y++;
984         }
985
986         /* now use the width of each line */
987         width -= numLines - 1;
988
989         for (i = 0; i < numLines; i++)
990         {
991             MoveToEx(dc, start.x + i, start.y, &oldPos);
992             LineTo(dc, start.x + i + width, start.y + height);
993
994             MoveToEx(dc, start.x + i, start.y + height - 1, &oldPos);
995             LineTo(dc, start.x + i + width, start.y - 1);
996         }
997
998         SelectObject(dc, hpsave);
999         return TRUE;
1000     }
1001
1002     case DFCS_CAPTIONHELP:
1003         /* This one breaks the flow */
1004         /* FIXME: We need the Marlett font in order to get this right. */
1005
1006         hf = CreateFontA(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
1007                         ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
1008                         DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
1009         alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT);
1010         bksave = SetBkMode(dc, TRANSPARENT);
1011         clrsave = GetTextColor(dc);
1012         hfsave = (HFONT)SelectObject(dc, hf);
1013         GetTextExtentPoint32A(dc, str, 1, &size);
1014
1015         if(uFlags & DFCS_INACTIVE)
1016         {
1017             SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
1018             TextOutA(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
1019         }
1020         SetTextColor(dc, GetSysColor(colorIdx));
1021         TextOutA(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1022
1023         SelectObject(dc, hfsave);
1024         SetTextColor(dc, clrsave);
1025         SetBkMode(dc, bksave);
1026         SetTextAlign(dc, alignsave);
1027         DeleteObject(hf);
1028         return TRUE;
1029
1030     case DFCS_CAPTIONMIN:
1031         Line1[0].x = Line1[3].x = myr.left   +  96*SmallDiam/750+2;
1032         Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1033         Line1[0].y = Line1[1].y = myr.top    + 563*SmallDiam/750+1;
1034         Line1[2].y = Line1[3].y = Line1[0].y +  92*SmallDiam/750;
1035         Line1N = 4;
1036         Line2N = 0;
1037         break;
1038
1039     case DFCS_CAPTIONMAX:
1040         edge = 47*SmallDiam/750;
1041         Line1[0].x = Line1[5].x = myr.left +  57*SmallDiam/750+3;
1042         Line1[0].y = Line1[1].y = myr.top  + 143*SmallDiam/750+1;
1043         Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1044         Line1[5].y = Line1[4].y = Line1[0].y +  93*SmallDiam/750;
1045         Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1046         Line1[3].x = Line1[4].x = Line1[1].x -  edge;
1047
1048         Line2[0].x = Line2[5].x = Line1[0].x;
1049         Line2[3].x = Line2[4].x = Line1[1].x;
1050         Line2[1].x = Line2[2].x = Line1[0].x + edge;
1051         Line2[0].y = Line2[1].y = Line1[0].y;
1052         Line2[4].y = Line2[5].y = Line1[2].y;
1053         Line2[2].y = Line2[3].y = Line1[2].y - edge;
1054         Line1N = 6;
1055         Line2N = 6;
1056         break;
1057
1058     case DFCS_CAPTIONRESTORE:
1059         /* FIXME: this one looks bad at small sizes < 15x15 :( */
1060         edge = 47*SmallDiam/750;
1061         move = 420*SmallDiam/750;
1062         Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1063         Line1[0].y = Line1[1].y = myr.top  + 169*SmallDiam/750+1;
1064         Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1065         Line1[7].x = Line1[8].x = Line1[0].x + edge;
1066         Line1[1].x = Line1[2].x = Line1[0].x + move;
1067         Line1[5].x = Line1[6].x = Line1[1].x - edge;
1068         Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1069         Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1070         Line1[4].y = Line1[5].y = Line1[2].y - edge;
1071         Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1072
1073         Line2[1].x = Line2[2].x = Line1[3].x;
1074         Line2[7].x = Line2[8].x = Line2[1].x - edge;
1075         Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1076         Line2[5].x = Line2[6].x = Line2[0].x + edge;
1077         Line2[0].y = Line2[1].y = Line1[9].y;
1078         Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1079         Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1080         Line2[6].y = Line2[7].y = Line2[2].y - edge;
1081         Line1N = 10;
1082         Line2N = 10;
1083         break;
1084
1085     default:
1086         WARN("Invalid caption; flags=0x%04x\n", uFlags);
1087         return FALSE;
1088     }
1089
1090     /* Here the drawing takes place */
1091     if(uFlags & DFCS_INACTIVE)
1092     {
1093         /* If we have an inactive button, then you see a shadow */
1094         hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1095         hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1096         Polygon(dc, Line1, Line1N);
1097         if(Line2N > 0)
1098             Polygon(dc, Line2, Line2N);
1099         SelectObject(dc, hpsave);
1100         SelectObject(dc, hbsave);
1101     }
1102
1103     /* Correct for the shadow shift */
1104     if (!(uFlags & DFCS_PUSHED))
1105     {
1106         for(i = 0; i < Line1N; i++)
1107         {
1108             Line1[i].x--;
1109             Line1[i].y--;
1110         }
1111         for(i = 0; i < Line2N; i++)
1112         {
1113             Line2[i].x--;
1114             Line2[i].y--;
1115         }
1116     }
1117
1118     /* Make the final picture */
1119     hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(colorIdx));
1120     hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(colorIdx));
1121
1122     Polygon(dc, Line1, Line1N);
1123     if(Line2N > 0)
1124         Polygon(dc, Line2, Line2N);
1125     SelectObject(dc, hpsave);
1126     SelectObject(dc, hbsave);
1127
1128     return TRUE;
1129 }
1130
1131
1132 /************************************************************************
1133  *      UITOOLS_DrawFrameScroll
1134  *
1135  * Draw a scroll-bar control coming from DrawFrameControl()
1136  */
1137 static BOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags)
1138 {
1139     POINT Line[4];
1140     RECT myr;
1141     int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1142     int i;
1143     HBRUSH hbsave, hb, hb2;
1144     HPEN hpsave, hp, hp2;
1145     int tri = 290*SmallDiam/1000 - 1;
1146     int d46, d93;
1147
1148     /*
1149      * This fixes a problem with really tiny "scroll" buttons. In particular
1150      * with the updown control.
1151      * Making sure that the arrow is as least 3 pixels wide (or high).
1152      */
1153     if (tri == 0)
1154       tri = 1;
1155
1156     switch(uFlags & 0xff)
1157     {
1158     case DFCS_SCROLLCOMBOBOX:
1159     case DFCS_SCROLLDOWN:
1160         Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1161         Line[2].y = myr.top  + 687*SmallDiam/1000 + 1;
1162         Line[0].x = Line[2].x - tri;
1163         Line[1].x = Line[2].x + tri;
1164         Line[0].y = Line[1].y = Line[2].y - tri;
1165         break;
1166
1167     case DFCS_SCROLLUP:
1168         Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1169         Line[2].y = myr.bottom - (687*SmallDiam/1000 + 1);
1170         Line[0].x = Line[2].x - tri;
1171         Line[1].x = Line[2].x + tri;
1172         Line[0].y = Line[1].y = Line[2].y + tri;
1173         break;
1174
1175     case DFCS_SCROLLLEFT:
1176         Line[2].x = myr.right - (687*SmallDiam/1000 + 1);
1177         Line[2].y = myr.top  + 470*SmallDiam/1000 + 2;
1178         Line[0].y = Line[2].y - tri;
1179         Line[1].y = Line[2].y + tri;
1180         Line[0].x = Line[1].x = Line[2].x + tri;
1181         break;
1182
1183     case DFCS_SCROLLRIGHT:
1184         Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1185         Line[2].y = myr.top  + 470*SmallDiam/1000 + 2;
1186         Line[0].y = Line[2].y - tri;
1187         Line[1].y = Line[2].y + tri;
1188         Line[0].x = Line[1].x = Line[2].x - tri;
1189         break;
1190
1191     case DFCS_SCROLLSIZEGRIP:
1192         /* This one breaks the flow... */
1193         UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1194         hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN));
1195         hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
1196         if(uFlags & (DFCS_MONO|DFCS_FLAT))
1197         {
1198             hp = hp2 = SYSCOLOR_GetPen(COLOR_WINDOWFRAME);
1199             hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME);
1200         }
1201         else
1202         {
1203             hp  = SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT);
1204             hp2 = SYSCOLOR_GetPen(COLOR_BTNSHADOW);
1205             hb  = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
1206             hb2 = GetSysColorBrush(COLOR_BTNSHADOW);
1207         }
1208         Line[0].x = Line[1].x = r->right-1;
1209         Line[2].y = Line[3].y = r->bottom-1;
1210         d46 = 46*SmallDiam/750;
1211         d93 = 93*SmallDiam/750;
1212
1213         i = 586*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         SelectObject(dc, hb);
1219         SelectObject(dc, hp);
1220         Polygon(dc, Line, 4);
1221
1222         Line[1].y++; Line[2].x++;
1223         Line[0].y = Line[1].y + d93;
1224         Line[3].x = Line[2].x + d93;
1225         SelectObject(dc, hb2);
1226         SelectObject(dc, hp2);
1227         Polygon(dc, Line, 4);
1228
1229         i = 398*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         SelectObject(dc, hb);
1235         SelectObject(dc, hp);
1236         Polygon(dc, Line, 4);
1237
1238         Line[1].y++; Line[2].x++;
1239         Line[0].y = Line[1].y + d93;
1240         Line[3].x = Line[2].x + d93;
1241         SelectObject(dc, hb2);
1242         SelectObject(dc, hp2);
1243         Polygon(dc, Line, 4);
1244
1245         i = 210*SmallDiam/750;
1246         Line[0].y = r->bottom - i - 1;
1247         Line[3].x = r->right - i - 1;
1248         Line[1].y = Line[0].y + d46;
1249         Line[2].x = Line[3].x + d46;
1250         SelectObject(dc, hb);
1251         SelectObject(dc, hp);
1252         Polygon(dc, Line, 4);
1253
1254         Line[1].y++; Line[2].x++;
1255         Line[0].y = Line[1].y + d93;
1256         Line[3].x = Line[2].x + d93;
1257         SelectObject(dc, hb2);
1258         SelectObject(dc, hp2);
1259         Polygon(dc, Line, 4);
1260
1261         SelectObject(dc, hpsave);
1262         SelectObject(dc, hbsave);
1263         return TRUE;
1264
1265     default:
1266         WARN("Invalid scroll; flags=0x%04x\n", uFlags);
1267         return FALSE;
1268     }
1269
1270     /* Here do the real scroll-bar controls end up */
1271     if( ! (uFlags & (0xff00 & ~DFCS_ADJUSTRECT)) )
1272       /* UITOOLS95_DFC_ButtonPush always uses BF_SOFT which we don't */
1273       /* want for the normal scroll-arrow button. */
1274       UITOOLS95_DrawRectEdge( dc, r, EDGE_RAISED, (uFlags&DFCS_ADJUSTRECT) | BF_MIDDLE | BF_RECT);
1275     else
1276       UITOOLS95_DFC_ButtonPush(dc, r, (uFlags & 0xff00) );
1277
1278     if(uFlags & DFCS_INACTIVE)
1279     {
1280         hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
1281         hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(COLOR_BTNHIGHLIGHT));
1282         Polygon(dc, Line, 3);
1283         SelectObject(dc, hpsave);
1284         SelectObject(dc, hbsave);
1285     }
1286
1287     if( (uFlags & DFCS_INACTIVE) || !(uFlags & DFCS_PUSHED) )
1288       for(i = 0; i < 3; i++)
1289       {
1290         Line[i].x--;
1291         Line[i].y--;
1292       }
1293
1294     i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;
1295     hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
1296     hpsave = (HPEN)SelectObject(dc, SYSCOLOR_GetPen(i));
1297     Polygon(dc, Line, 3);
1298     SelectObject(dc, hpsave);
1299     SelectObject(dc, hbsave);
1300
1301     return TRUE;
1302 }
1303
1304 /************************************************************************
1305  *      UITOOLS_DrawFrameMenu
1306  *
1307  * Draw a menu control coming from DrawFrameControl()
1308  */
1309 static BOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags)
1310 {
1311     POINT Points[6];
1312     RECT myr;
1313     int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1314     int i;
1315     HBRUSH hbsave;
1316     HPEN hpsave;
1317     int xe, ye;
1318     int xc, yc;
1319     BOOL retval = TRUE;
1320
1321     /* Using black and white seems to be utterly wrong, but win95 doesn't */
1322     /* use anything else. I think I tried all sys-colors to change things */
1323     /* without luck. It seems as if this behavior is inherited from the */
1324     /* win31 DFC() implementation... (you remember, B/W menus). */
1325
1326     FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH));
1327
1328     hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
1329     hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN));
1330
1331     switch(uFlags & 0xff)
1332     {
1333     case DFCS_MENUARROW:
1334         i = 187*SmallDiam/750;
1335         Points[2].x = myr.left + 468*SmallDiam/750;
1336         Points[2].y = myr.top  + 352*SmallDiam/750+1;
1337         Points[0].y = Points[2].y - i;
1338         Points[1].y = Points[2].y + i;
1339         Points[0].x = Points[1].x = Points[2].x - i;
1340         Polygon(dc, Points, 3);
1341         break;
1342
1343     case DFCS_MENUBULLET:
1344         xe = myr.left;
1345         ye = myr.top  + SmallDiam - SmallDiam/2;
1346         xc = myr.left + SmallDiam - SmallDiam/2;
1347         yc = myr.top  + SmallDiam - SmallDiam/2;
1348         i = 234*SmallDiam/750;
1349         i = i < 1 ? 1 : i;
1350         myr.left   = xc - i+i/2;
1351         myr.right  = xc + i/2;
1352         myr.top    = yc - i+i/2;
1353         myr.bottom = yc + i/2;
1354         Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1355         break;
1356
1357     case DFCS_MENUCHECK:
1358         Points[0].x = myr.left + 253*SmallDiam/1000;
1359         Points[0].y = myr.top  + 445*SmallDiam/1000;
1360         Points[1].x = myr.left + 409*SmallDiam/1000;
1361         Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1362         Points[2].x = myr.left + 690*SmallDiam/1000;
1363         Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1364         Points[3].x = Points[2].x;
1365         Points[3].y = Points[2].y + 3*SmallDiam/16;
1366         Points[4].x = Points[1].x;
1367         Points[4].y = Points[1].y + 3*SmallDiam/16;
1368         Points[5].x = Points[0].x;
1369         Points[5].y = Points[0].y + 3*SmallDiam/16;
1370         Polygon(dc, Points, 6);
1371         break;
1372
1373     default:
1374         WARN("Invalid menu; flags=0x%04x\n", uFlags);
1375         retval = FALSE;
1376         break;
1377     }
1378
1379     SelectObject(dc, hpsave);
1380     SelectObject(dc, hbsave);
1381     return retval;
1382 }
1383
1384
1385 /**********************************************************************
1386  *          DrawFrameControl  (USER.656)
1387  */
1388 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType,
1389                                   UINT16 uState )
1390 {
1391     RECT rect32;
1392     BOOL ret;
1393
1394     CONV_RECT16TO32( rc, &rect32 );
1395     ret = DrawFrameControl( hdc, &rect32, uType, uState );
1396     CONV_RECT32TO16( &rect32, rc );
1397     return ret;
1398 }
1399
1400
1401 /**********************************************************************
1402  *          DrawFrameControl  (USER32.@)
1403  */
1404 BOOL WINAPI DrawFrameControl( HDC hdc, LPRECT rc, UINT uType,
1405                                   UINT uState )
1406 {
1407     /* Win95 doesn't support drawing in other mapping modes */
1408     if(GetMapMode(hdc) != MM_TEXT)
1409         return FALSE;
1410
1411     switch(uType)
1412     {
1413     case DFC_BUTTON:
1414       return UITOOLS95_DrawFrameButton(hdc, rc, uState);
1415     case DFC_CAPTION:
1416       return UITOOLS95_DrawFrameCaption(hdc, rc, uState);
1417     case DFC_MENU:
1418       return UITOOLS95_DrawFrameMenu(hdc, rc, uState);
1419     /*case DFC_POPUPMENU:
1420       FIXME("DFC_POPUPMENU: not implemented\n");
1421       break;*/
1422     case DFC_SCROLL:
1423       return UITOOLS95_DrawFrameScroll(hdc, rc, uState);
1424     default:
1425       WARN("(%x,%p,%d,%x), bad type!\n",
1426            hdc,rc,uType,uState );
1427     }
1428     return FALSE;
1429 }