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