Release 971221
[wine.git] / controls / uitools.c
blobe3c64de36e960ddb38cc8013f720dfce37ca0194
1 /*
2 * User Interface Functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1997 Bertho A. Stultiens
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "debug.h"
12 static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555,
13 0xaaaa, 0x5555, 0xaaaa, 0x5555 };
15 /* These tables are used in:
16 * UITOOLS_DrawDiagEdge()
17 * UITOOLS_DrawRectEdge()
19 static const char LTInnerNormal[] = {
20 -1, -1, -1, -1,
21 -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1,
22 -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1,
23 -1, -1, -1, -1
26 static const char LTOuterNormal[] = {
27 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
28 COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
29 COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1,
30 -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1
33 static const char RBInnerNormal[] = {
34 -1, -1, -1, -1,
35 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
36 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
37 -1, -1, -1, -1
40 static const char RBOuterNormal[] = {
41 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
42 COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
43 COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1,
44 -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
47 static const char LTInnerSoft[] = {
48 -1, -1, -1, -1,
49 -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1,
50 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1,
51 -1, -1, -1, -1
54 static const char LTOuterSoft[] = {
55 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
56 COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
57 COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1,
58 -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1
61 #define RBInnerSoft RBInnerNormal /* These are the same */
62 #define RBOuterSoft RBOuterNormal
64 static const char LTRBOuterMono[] = {
65 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
66 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
67 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
68 COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
71 static const char LTRBInnerMono[] = {
72 -1, -1, -1, -1,
73 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
74 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
75 -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
78 static const char LTRBOuterFlat[] = {
79 -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
80 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
81 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
82 COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW,
85 static const char LTRBInnerFlat[] = {
86 -1, -1, -1, -1,
87 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
88 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
89 -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
92 /***********************************************************************
93 * UITOOLS_DrawDiagEdge
95 * Same as DrawEdge, but with BF_DIAGONAL
96 * I tested it extensively and as far as I can tell it is identical to the
97 * implementaion in Win95.
98 * I do not like that I create and
99 * use the 3 Pens to draw the diagonals. It would be better to draw them
100 * using the brushes returned by GetSysColorBrush func, but I did not have
101 * the patience to implement that yet.
103 /*********************************************************************
104 * 03-Dec-1997: Changed by Bertho Stultiens
106 * See also comments with UITOOLS_DrawRectEdge()
108 static BOOL32 UITOOLS_DrawDiagEdge(HDC32 hdc, LPRECT32 rc, UINT32 uType, UINT32 uFlags)
110 POINT32 Points[4];
111 char InnerI, OuterI;
112 HPEN32 InnerPen, OuterPen;
113 POINT32 SavePoint;
114 HPEN32 SavePen;
115 int spx, spy;
116 int epx, epy;
117 int Width = rc->right - rc->left;
118 int Height= rc->bottom - rc->top;
119 int SmallDiam = Width > Height ? Height : Width;
120 BOOL32 retval = !( ((uType & BDR_INNER) == BDR_INNER
121 || (uType & BDR_OUTER) == BDR_OUTER)
122 && !(uFlags & (BF_FLAT|BF_MONO)) );
123 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
124 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
126 /* Init some vars */
127 OuterPen = InnerPen = (HPEN32)GetStockObject32(NULL_PEN);
128 SavePen = (HPEN32)SelectObject32(hdc, InnerPen);
129 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
131 /* Determine the colors of the edges */
132 if(uFlags & BF_MONO)
134 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
135 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
137 else if(uFlags & BF_FLAT)
139 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
140 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
142 else if(uFlags & BF_SOFT)
144 if(uFlags & BF_BOTTOM)
146 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
147 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
149 else
151 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
152 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
155 else
157 if(uFlags & BF_BOTTOM)
159 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
160 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
162 else
164 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
165 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
169 if(InnerI != -1) InnerPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)InnerI));
170 if(OuterI != -1) OuterPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)OuterI));
172 MoveToEx32(hdc, 0, 0, &SavePoint);
174 /* Don't ask me why, but this is what is visible... */
175 /* This must be possible to do much simpler, but I fail to */
176 /* see the logic in the MS implementation (sigh...). */
177 /* So, this might look a bit brute force here (and it is), but */
178 /* it gets the job done;) */
180 switch(uFlags & BF_RECT)
182 case 0:
183 case BF_LEFT:
184 case BF_BOTTOM:
185 case BF_BOTTOMLEFT:
186 /* Left bottom endpoint */
187 epx = rc->left-1;
188 spx = epx + SmallDiam;
189 epy = rc->bottom;
190 spy = epy - SmallDiam;
191 break;
193 case BF_TOPLEFT:
194 case BF_BOTTOMRIGHT:
195 /* Left top endpoint */
196 epx = rc->left-1;
197 spx = epx + SmallDiam;
198 epy = rc->top-1;
199 spy = epy + SmallDiam;
200 break;
202 case BF_TOP:
203 case BF_RIGHT:
204 case BF_TOPRIGHT:
205 case BF_RIGHT|BF_LEFT:
206 case BF_RIGHT|BF_LEFT|BF_TOP:
207 case BF_BOTTOM|BF_TOP:
208 case BF_BOTTOM|BF_TOP|BF_LEFT:
209 case BF_BOTTOMRIGHT|BF_LEFT:
210 case BF_BOTTOMRIGHT|BF_TOP:
211 case BF_RECT:
212 /* Right top endpoint */
213 spx = rc->left;
214 epx = spx + SmallDiam;
215 spy = rc->bottom-1;
216 epy = spy - SmallDiam;
217 break;
220 MoveToEx32(hdc, spx, spy, NULL);
221 SelectObject32(hdc, OuterPen);
222 LineTo32(hdc, epx, epy);
224 SelectObject32(hdc, InnerPen);
226 switch(uFlags & (BF_RECT|BF_DIAGONAL))
228 case BF_DIAGONAL_ENDBOTTOMLEFT:
229 case (BF_DIAGONAL|BF_BOTTOM):
230 case BF_DIAGONAL:
231 case (BF_DIAGONAL|BF_LEFT):
232 MoveToEx32(hdc, spx-1, spy, NULL);
233 LineTo32(hdc, epx, epy-1);
234 Points[0].x = spx-add;
235 Points[0].y = spy;
236 Points[1].x = rc->left;
237 Points[1].y = rc->top;
238 Points[2].x = epx+1;
239 Points[2].y = epy-1-add;
240 Points[3] = Points[2];
241 break;
243 case BF_DIAGONAL_ENDBOTTOMRIGHT:
244 MoveToEx32(hdc, spx-1, spy, NULL);
245 LineTo32(hdc, epx, epy+1);
246 Points[0].x = spx-add;
247 Points[0].y = spy;
248 Points[1].x = rc->left;
249 Points[1].y = rc->bottom-1;
250 Points[2].x = epx+1;
251 Points[2].y = epy+1+add;
252 Points[3] = Points[2];
253 break;
255 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
256 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
257 case BF_DIAGONAL_ENDTOPRIGHT:
258 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
259 MoveToEx32(hdc, spx+1, spy, NULL);
260 LineTo32(hdc, epx, epy+1);
261 Points[0].x = epx-1;
262 Points[0].y = epy+1+add;
263 Points[1].x = rc->right-1;
264 Points[1].y = rc->top+add;
265 Points[2].x = rc->right-1;
266 Points[2].y = rc->bottom-1;
267 Points[3].x = spx+add;
268 Points[3].y = spy;
269 break;
271 case BF_DIAGONAL_ENDTOPLEFT:
272 MoveToEx32(hdc, spx, spy-1, NULL);
273 LineTo32(hdc, epx+1, epy);
274 Points[0].x = epx+1+add;
275 Points[0].y = epy+1;
276 Points[1].x = rc->right-1;
277 Points[1].y = rc->top;
278 Points[2].x = rc->right-1;
279 Points[2].y = rc->bottom-1-add;
280 Points[3].x = spx;
281 Points[3].y = spy-add;
282 break;
284 case (BF_DIAGONAL|BF_TOP):
285 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
286 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
287 MoveToEx32(hdc, spx+1, spy-1, NULL);
288 LineTo32(hdc, epx, epy);
289 Points[0].x = epx-1;
290 Points[0].y = epy+1;
291 Points[1].x = rc->right-1;
292 Points[1].y = rc->top;
293 Points[2].x = rc->right-1;
294 Points[2].y = rc->bottom-1-add;
295 Points[3].x = spx+add;
296 Points[3].y = spy-add;
297 break;
299 case (BF_DIAGONAL|BF_RIGHT):
300 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
301 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
302 MoveToEx32(hdc, spx, spy, NULL);
303 LineTo32(hdc, epx-1, epy+1);
304 Points[0].x = spx;
305 Points[0].y = spy;
306 Points[1].x = rc->left;
307 Points[1].y = rc->top+add;
308 Points[2].x = epx-1-add;
309 Points[2].y = epy+1+add;
310 Points[3] = Points[2];
311 break;
314 /* Fill the interior if asked */
315 if((uFlags & BF_MIDDLE) && retval)
317 HBRUSH32 hbsave;
318 HBRUSH32 hb = uFlags & BF_MONO ? GetSysColorBrush32(COLOR_WINDOW)
319 : GetSysColorBrush32(COLOR_BTNFACE);
320 HPEN32 hpsave;
321 HPEN32 hp = CreatePen32(PS_SOLID, 0, uFlags & BF_MONO ? GetSysColor32(COLOR_WINDOW)
322 : GetSysColor32(COLOR_BTNFACE));
323 hbsave = (HBRUSH32)SelectObject32(hdc, hb);
324 hpsave = (HPEN32)SelectObject32(hdc, hp);
325 Polygon32(hdc, Points, 4);
326 SelectObject32(hdc, hbsave);
327 SelectObject32(hdc, hpsave);
328 DeleteObject32(hp);
331 /* Adjust rectangle if asked */
332 if(uFlags & BF_ADJUST)
334 if(uFlags & BF_LEFT) rc->left += add;
335 if(uFlags & BF_RIGHT) rc->right -= add;
336 if(uFlags & BF_TOP) rc->top += add;
337 if(uFlags & BF_BOTTOM) rc->bottom -= add;
340 /* Cleanup */
341 SelectObject32(hdc, SavePen);
342 if(InnerI != -1) DeleteObject32(InnerPen);
343 if(OuterI != -1) DeleteObject32(OuterPen);
344 MoveToEx32(hdc, SavePoint.x, SavePoint.y, NULL);
346 return retval;
349 /***********************************************************************
350 * UITOOLS_DrawRectEdge
352 * Same as DrawEdge, but without BF_DIAGONAL
353 * I tested this function and it works very well. You should not change it
354 * unless you find a bug. If you don't like the colors, it it not its
355 * fault - the system colors are not OK.
356 * Again, I tested this function on Win95 and I compared the output with the
357 * one generated by the native DrawEdge and it is identical on all cases that
358 * I tried, and I tried quite a few.
360 /*********************************************************************
361 * 23-Nov-1997: Changed by Bertho Stultiens
363 * Well, I started testing this and found out that there are a few things
364 * that weren't quite as win95. The following rewrite should reproduce
365 * win95 results completely.
366 * The colorselection is table-driven to avoid awfull if-statements.
367 * The table below show the color settings.
369 * Pen selection table for uFlags = 0
371 * uType | LTI | LTO | RBI | RBO
372 * ------+-------+-------+-------+-------
373 * 0000 | x | x | x | x
374 * 0001 | x | 22 | x | 21
375 * 0010 | x | 16 | x | 20
376 * 0011 | x | x | x | x
377 * ------+-------+-------+-------+-------
378 * 0100 | x | 20 | x | 16
379 * 0101 | 20 | 22 | 16 | 21
380 * 0110 | 20 | 16 | 16 | 20
381 * 0111 | x | x | x | x
382 * ------+-------+-------+-------+-------
383 * 1000 | x | 21 | x | 22
384 * 1001 | 21 | 22 | 22 | 21
385 * 1010 | 21 | 16 | 22 | 20
386 * 1011 | x | x | x | x
387 * ------+-------+-------+-------+-------
388 * 1100 | x | x | x | x
389 * 1101 | x | x (22)| x | x (21)
390 * 1110 | x | x (16)| x | x (20)
391 * 1111 | x | x | x | x
393 * Pen selection table for uFlags = BF_SOFT
395 * uType | LTI | LTO | RBI | RBO
396 * ------+-------+-------+-------+-------
397 * 0000 | x | x | x | x
398 * 0001 | x | 20 | x | 21
399 * 0010 | x | 21 | x | 20
400 * 0011 | x | x | x | x
401 * ------+-------+-------+-------+-------
402 * 0100 | x | 22 | x | 16
403 * 0101 | 22 | 20 | 16 | 21
404 * 0110 | 22 | 21 | 16 | 20
405 * 0111 | x | x | x | x
406 * ------+-------+-------+-------+-------
407 * 1000 | x | 16 | x | 22
408 * 1001 | 16 | 20 | 22 | 21
409 * 1010 | 16 | 21 | 22 | 20
410 * 1011 | x | x | x | x
411 * ------+-------+-------+-------+-------
412 * 1100 | x | x | x | x
413 * 1101 | x | x (20)| x | x (21)
414 * 1110 | x | x (21)| x | x (20)
415 * 1111 | x | x | x | x
417 * x = don't care; (n) = is what win95 actually uses
418 * LTI = left Top Inner line
419 * LTO = left Top Outer line
420 * RBI = Right Bottom Inner line
421 * RBO = Right Bottom Outer line
422 * 15 = COLOR_BTNFACE
423 * 16 = COLOR_BTNSHADOW
424 * 20 = COLOR_BTNHIGHLIGHT
425 * 21 = COLOR_3DDKSHADOW
426 * 22 = COLOR_3DLIGHT
430 static BOOL32 UITOOLS_DrawRectEdge(HDC32 hdc, LPRECT32 rc, UINT32 uType, UINT32 uFlags)
432 char LTInnerI, LTOuterI;
433 char RBInnerI, RBOuterI;
434 HPEN32 LTInnerPen, LTOuterPen;
435 HPEN32 RBInnerPen, RBOuterPen;
436 RECT32 InnerRect = *rc;
437 POINT32 SavePoint;
438 HPEN32 SavePen;
439 int LBpenplus = 0;
440 int LTpenplus = 0;
441 int RTpenplus = 0;
442 int RBpenplus = 0;
443 BOOL32 retval = !( ((uType & BDR_INNER) == BDR_INNER
444 || (uType & BDR_OUTER) == BDR_OUTER)
445 && !(uFlags & (BF_FLAT|BF_MONO)) );
447 /* Init some vars */
448 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN32)GetStockObject32(NULL_PEN);
449 SavePen = (HPEN32)SelectObject32(hdc, LTInnerPen);
451 /* Determine the colors of the edges */
452 if(uFlags & BF_MONO)
454 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
455 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
457 else if(uFlags & BF_FLAT)
459 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
460 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
462 else if(uFlags & BF_SOFT)
464 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
465 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
466 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
467 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
469 else
471 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
472 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
473 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
474 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
477 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
478 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
479 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
480 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
482 if(LTInnerI != -1) LTInnerPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)LTInnerI));
483 if(LTOuterI != -1) LTOuterPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)LTOuterI));
484 if(RBInnerI != -1) RBInnerPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)RBInnerI));
485 if(RBOuterI != -1) RBOuterPen = CreatePen32(PS_SOLID, 0, GetSysColor32((int)RBOuterI));
487 if((uFlags & BF_MIDDLE) && retval)
489 FillRect32(hdc, &InnerRect, (uFlags & BF_MONO) ? GetSysColorBrush32(COLOR_WINDOW)
490 : GetSysColorBrush32(COLOR_BTNFACE));
493 MoveToEx32(hdc, 0, 0, &SavePoint);
495 /* Draw the outer edge */
496 SelectObject32(hdc, LTOuterPen);
497 if(uFlags & BF_TOP)
499 MoveToEx32(hdc, InnerRect.left, InnerRect.top, NULL);
500 LineTo32(hdc, InnerRect.right, InnerRect.top);
502 if(uFlags & BF_LEFT)
504 MoveToEx32(hdc, InnerRect.left, InnerRect.top, NULL);
505 LineTo32(hdc, InnerRect.left, InnerRect.bottom);
507 SelectObject32(hdc, RBOuterPen);
508 if(uFlags & BF_BOTTOM)
510 MoveToEx32(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
511 LineTo32(hdc, InnerRect.left-1, InnerRect.bottom-1);
513 if(uFlags & BF_RIGHT)
515 MoveToEx32(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
516 LineTo32(hdc, InnerRect.right-1, InnerRect.top-1);
519 /* Draw the inner edge */
520 SelectObject32(hdc, LTInnerPen);
521 if(uFlags & BF_TOP)
523 MoveToEx32(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
524 LineTo32(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
526 if(uFlags & BF_LEFT)
528 MoveToEx32(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
529 LineTo32(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
531 SelectObject32(hdc, RBInnerPen);
532 if(uFlags & BF_BOTTOM)
534 MoveToEx32(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
535 LineTo32(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
537 if(uFlags & BF_RIGHT)
539 MoveToEx32(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
540 LineTo32(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
543 /* Adjust rectangle if asked */
544 if(uFlags & BF_ADJUST)
546 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
547 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
548 if(uFlags & BF_LEFT) rc->left += add;
549 if(uFlags & BF_RIGHT) rc->right -= add;
550 if(uFlags & BF_TOP) rc->top += add;
551 if(uFlags & BF_BOTTOM) rc->bottom -= add;
554 /* Cleanup */
555 SelectObject32(hdc, SavePen);
556 if(LTInnerI != -1) DeleteObject32(LTInnerPen);
557 if(LTOuterI != -1) DeleteObject32(LTOuterPen);
558 if(RBInnerI != -1) DeleteObject32(RBInnerPen);
559 if(RBOuterI != -1) DeleteObject32(RBOuterPen);
560 MoveToEx32(hdc, SavePoint.x, SavePoint.y, NULL);
561 return retval;
565 /**********************************************************************
566 * DrawEdge16 (USER.659)
568 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
570 RECT32 rect32;
571 BOOL32 ret;
573 CONV_RECT16TO32( rc, &rect32 );
574 ret = DrawEdge32( hdc, &rect32, edge, flags );
575 CONV_RECT32TO16( &rect32, rc );
576 return ret;
579 /**********************************************************************
580 * DrawEdge32 (USER32.154)
582 BOOL32 WINAPI DrawEdge32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
584 dprintf_graphics( stddeb, "DrawEdge: %04x %d,%d-%d,%d %04x %04x\n",
585 hdc, rc->left, rc->top, rc->right, rc->bottom,
586 edge, flags );
588 if(flags & BF_DIAGONAL)
589 return UITOOLS_DrawDiagEdge(hdc, rc, edge, flags);
590 else
591 return UITOOLS_DrawRectEdge(hdc, rc, edge, flags);
595 /************************************************************************
596 * UITOOLS_MakeSquareRect
598 * Utility to create a square rectangle and returning the width
600 static int UITOOLS_MakeSquareRect(LPRECT32 src, LPRECT32 dst)
602 int Width = src->right - src->left;
603 int Height = src->bottom - src->top;
604 int SmallDiam = Width > Height ? Height : Width;
606 *dst = *src;
608 /* Make it a square box */
609 if(Width < Height) /* SmallDiam == Width */
611 dst->top += (Height-Width)/2;
612 dst->bottom = dst->top + SmallDiam;
614 else if(Width > Height) /* SmallDiam == Height */
616 dst->left += (Width-Height)/2;
617 dst->right = dst->left + SmallDiam;
620 return SmallDiam;
624 /************************************************************************
625 * UITOOLS_DFC_ButtonPush
627 * Draw a push button coming from DrawFrameControl()
629 * Does a pretty good job in emulating MS behavior. Some quirks are
630 * however there because MS uses a TrueType font (Marlett) to draw
631 * the buttons.
633 static BOOL32 UITOOLS_DFC_ButtonPush(HDC32 dc, LPRECT32 r, UINT32 uFlags)
635 UINT32 edge;
636 RECT32 myr = *r;
638 if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
639 edge = EDGE_SUNKEN;
640 else
641 edge = EDGE_RAISED;
643 if(uFlags & DFCS_CHECKED)
645 if(uFlags & DFCS_MONO)
646 UITOOLS_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
647 else
648 UITOOLS_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST);
650 if(GetSysColor32(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
652 HBITMAP32 hbm = CreateBitmap32(8, 8, 1, 1, wPattern_AA55);
653 HBRUSH32 hbsave;
654 HBRUSH32 hb = CreatePatternBrush32(hbm);
656 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
657 hbsave = (HBRUSH32)SelectObject32(dc, hb);
658 PatBlt32(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
659 SelectObject32(dc, hbsave);
660 DeleteObject32(hb);
661 DeleteObject32(hbm);
663 else
665 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
668 else
670 if(uFlags & DFCS_MONO)
672 UITOOLS_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST);
673 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
675 else
677 UITOOLS_DrawRectEdge(dc, r, edge, (uFlags&DFCS_FLAT) | BF_MIDDLE |BF_SOFT| BF_RECT);
681 /* Adjust rectangle if asked */
682 if(uFlags & DFCS_ADJUSTRECT)
684 r->left += 2;
685 r->right -= 2;
686 r->top += 2;
687 r->bottom -= 2;
690 return TRUE;
694 /************************************************************************
695 * UITOOLS_DFC_ButtonChcek
697 * Draw a check/3state button coming from DrawFrameControl()
699 * Does a pretty good job in emulating MS behavior. Some quirks are
700 * however there because MS uses a TrueType font (Marlett) to draw
701 * the buttons.
703 #define DFC_CHECKPOINTSMAX 6
705 static BOOL32 UITOOLS_DFC_ButtonCheck(HDC32 dc, LPRECT32 r, UINT32 uFlags)
707 RECT32 myr;
708 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
709 int BorderShrink = SmallDiam / 16;
711 if(BorderShrink < 1) BorderShrink = 1;
713 /* FIXME: The FillRect() sequence doesn't work for sizes less than */
714 /* 4 pixels in diameter. Not really a problem but it isn't M$'s */
715 /* 100% equivalent. */
716 if(uFlags & (DFCS_FLAT|DFCS_MONO))
718 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_WINDOWFRAME));
719 myr.left += 2 * BorderShrink;
720 myr.right -= 2 * BorderShrink;
721 myr.top += 2 * BorderShrink;
722 myr.bottom -= 2 * BorderShrink;
724 else
726 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
727 myr.right -= BorderShrink;
728 myr.bottom -= BorderShrink;
729 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNSHADOW));
730 myr.left += BorderShrink;
731 myr.top += BorderShrink;
732 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_3DLIGHT));
733 myr.right -= BorderShrink;
734 myr.bottom -= BorderShrink;
735 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_3DDKSHADOW));
736 myr.left += BorderShrink;
737 myr.top += BorderShrink;
740 if(uFlags & (DFCS_INACTIVE|DFCS_PUSHED))
742 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
744 else if(uFlags & DFCS_CHECKED)
746 if(GetSysColor32(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255))
748 HBITMAP32 hbm = CreateBitmap32(8, 8, 1, 1, wPattern_AA55);
749 HBRUSH32 hbsave;
750 HBRUSH32 hb = CreatePatternBrush32(hbm);
752 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNFACE));
753 hbsave = (HBRUSH32)SelectObject32(dc, hb);
754 PatBlt32(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089);
755 SelectObject32(dc, hbsave);
756 DeleteObject32(hb);
757 DeleteObject32(hbm);
759 else
761 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
764 else
766 FillRect32(dc, &myr, GetSysColorBrush32(COLOR_WINDOW));
769 if(uFlags & DFCS_CHECKED)
771 POINT32 CheckPoints[DFC_CHECKPOINTSMAX];
772 int i;
773 HBRUSH32 hbsave;
774 HPEN32 hp, hpsave;
776 /* FIXME: This comes very close to M$'s checkmark, but not */
777 /* exactly... When small or large there is a few pixels */
778 /* shift. Not bad, but could be better :) */
779 UITOOLS_MakeSquareRect(r, &myr);
780 CheckPoints[0].x = myr.left + 253*SmallDiam/1000;
781 CheckPoints[0].y = myr.top + 345*SmallDiam/1000;
782 CheckPoints[1].x = myr.left + 409*SmallDiam/1000;
783 CheckPoints[1].y = CheckPoints[0].y + (CheckPoints[1].x-CheckPoints[0].x);
784 CheckPoints[2].x = myr.left + 690*SmallDiam/1000;
785 CheckPoints[2].y = CheckPoints[1].y - (CheckPoints[2].x-CheckPoints[1].x);
786 CheckPoints[3].x = CheckPoints[2].x;
787 CheckPoints[3].y = CheckPoints[2].y + 3*SmallDiam/16;
788 CheckPoints[4].x = CheckPoints[1].x;
789 CheckPoints[4].y = CheckPoints[1].y + 3*SmallDiam/16;
790 CheckPoints[5].x = CheckPoints[0].x;
791 CheckPoints[5].y = CheckPoints[0].y + 3*SmallDiam/16;
793 i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
794 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
795 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(i));
796 hpsave = (HPEN32)SelectObject32(dc, hp);
797 Polygon32(dc, CheckPoints, DFC_CHECKPOINTSMAX);
798 SelectObject32(dc, hpsave);
799 SelectObject32(dc, hbsave);
800 DeleteObject32(hp);
802 return TRUE;
806 /************************************************************************
807 * UITOOLS_DFC_ButtonRadio
809 * Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
811 * Does a pretty good job in emulating MS behavior. Some quirks are
812 * however there because MS uses a TrueType font (Marlett) to draw
813 * the buttons.
815 static BOOL32 UITOOLS_DFC_ButtonRadio(HDC32 dc, LPRECT32 r, UINT32 uFlags)
817 RECT32 myr;
818 int i;
819 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
820 int BorderShrink = SmallDiam / 16;
821 HPEN32 hpsave, hp;
822 HBRUSH32 hbsave;
823 int xe, ye;
824 int xc, yc;
826 if(BorderShrink < 1) BorderShrink = 1;
828 if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
830 FillRect32(dc, r, (HBRUSH32)GetStockObject32(BLACK_BRUSH));
833 xe = myr.left;
834 ye = myr.top + SmallDiam - SmallDiam/2;
836 xc = myr.left + SmallDiam - SmallDiam/2;
837 yc = myr.top + SmallDiam - SmallDiam/2;
839 /* Define bounding box */
840 i = 14*SmallDiam/16;
841 myr.left = xc - i+i/2;
842 myr.right = xc + i/2;
843 myr.top = yc - i+i/2;
844 myr.bottom = yc + i/2;
846 if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
848 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(BLACK_BRUSH));
849 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
850 SelectObject32(dc, hbsave);
852 else
854 if(uFlags & (DFCS_FLAT|DFCS_MONO))
856 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_WINDOWFRAME));
857 hpsave = (HPEN32)SelectObject32(dc, hp);
858 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_WINDOWFRAME));
859 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
860 SelectObject32(dc, hbsave);
861 SelectObject32(dc, hpsave);
862 DeleteObject32(hp);
864 else
866 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNHIGHLIGHT));
867 hpsave = (HPEN32)SelectObject32(dc, hp);
868 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
869 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
870 SelectObject32(dc, hbsave);
871 SelectObject32(dc, hpsave);
872 DeleteObject32(hp);
874 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNSHADOW));
875 hpsave = (HPEN32)SelectObject32(dc, hp);
876 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNSHADOW));
877 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
878 SelectObject32(dc, hbsave);
879 SelectObject32(dc, hpsave);
880 DeleteObject32(hp);
882 myr.left += BorderShrink;
883 myr.right -= BorderShrink;
884 myr.top += BorderShrink;
885 myr.bottom -= BorderShrink;
887 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_3DLIGHT));
888 hpsave = (HPEN32)SelectObject32(dc, hp);
889 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_3DLIGHT));
890 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top);
891 SelectObject32(dc, hbsave);
892 SelectObject32(dc, hpsave);
893 DeleteObject32(hp);
895 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_3DDKSHADOW));
896 hpsave = (HPEN32)SelectObject32(dc, hp);
897 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_3DDKSHADOW));
898 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom);
899 SelectObject32(dc, hbsave);
900 SelectObject32(dc, hpsave);
901 DeleteObject32(hp);
904 i = 10*SmallDiam/16;
905 myr.left = xc - i+i/2;
906 myr.right = xc + i/2;
907 myr.top = yc - i+i/2;
908 myr.bottom = yc + i/2;
909 i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
910 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(i));
911 hpsave = (HPEN32)SelectObject32(dc, hp);
912 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
913 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
914 SelectObject32(dc, hbsave);
915 SelectObject32(dc, hpsave);
916 DeleteObject32(hp);
919 if(uFlags & DFCS_CHECKED)
921 i = 6*SmallDiam/16;
922 i = i < 1 ? 1 : i;
923 myr.left = xc - i+i/2;
924 myr.right = xc + i/2;
925 myr.top = yc - i+i/2;
926 myr.bottom = yc + i/2;
928 i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
929 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(i));
930 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(i));
931 hpsave = (HPEN32)SelectObject32(dc, hp);
932 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
933 SelectObject32(dc, hpsave);
934 SelectObject32(dc, hbsave);
935 DeleteObject32(hp);
938 /* FIXME: M$ has a polygon in the center at relative points: */
939 /* 0.476, 0.476 (times SmallDiam, SmallDiam) */
940 /* 0.476, 0.525 */
941 /* 0.500, 0.500 */
942 /* 0.500, 0.499 */
943 /* when the button is unchecked. The reason for it is unknown. The */
944 /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */
945 /* least 3 times (it looks like a clip-region when you see it happen). */
946 /* I do not really see a reason why this should be implemented. If you */
947 /* have a good reason, let me know. Maybe this is a quirk in the Marlett */
948 /* font. */
950 return TRUE;
953 /***********************************************************************
954 * UITOOLS_DrawFrameButton
956 static BOOL32 UITOOLS_DrawFrameButton(HDC32 hdc, LPRECT32 rc, UINT32 uState)
958 switch(uState & 0xff)
960 case DFCS_BUTTONPUSH:
961 return UITOOLS_DFC_ButtonPush(hdc, rc, uState);
963 case DFCS_BUTTONCHECK:
964 case DFCS_BUTTON3STATE:
965 return UITOOLS_DFC_ButtonCheck(hdc, rc, uState);
967 case DFCS_BUTTONRADIOIMAGE:
968 case DFCS_BUTTONRADIOMASK:
969 case DFCS_BUTTONRADIO:
970 return UITOOLS_DFC_ButtonRadio(hdc, rc, uState);
972 default:
973 fprintf(stdnimp, "UITOOLS_DrawFrameButton: Report this: Invalid button state: 0x%04x\n", uState);
976 return FALSE;
979 /***********************************************************************
980 * UITOOLS_DrawFrameCaption
982 * Draw caption buttons (win95), coming from DrawFrameControl()
985 static BOOL32 UITOOLS_DrawFrameCaption(HDC32 dc, LPRECT32 r, UINT32 uFlags)
987 POINT32 Line1[10];
988 POINT32 Line2[10];
989 int Line1N;
990 int Line2N;
991 RECT32 myr;
992 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2;
993 int i;
994 HBRUSH32 hbsave;
995 HPEN32 hpsave, hp;
996 HFONT32 hfsave, hf;
997 int xc = (myr.left+myr.right)/2;
998 int yc = (myr.top+myr.bottom)/2;
999 int edge, move;
1000 char str[2] = "?";
1001 UINT32 alignsave;
1002 int bksave;
1003 COLORREF clrsave;
1004 SIZE32 size;
1006 UITOOLS_DFC_ButtonPush(dc, r, uFlags & 0xff00);
1008 switch(uFlags & 0xff)
1010 case DFCS_CAPTIONCLOSE:
1011 edge = 328*SmallDiam/1000;
1012 move = 95*SmallDiam/1000;
1013 Line1[0].x = Line2[0].x = Line1[1].x = Line2[1].x = xc - edge;
1014 Line1[2].y = Line2[5].y = Line1[1].y = Line2[4].y = yc - edge;
1015 Line1[3].x = Line2[3].x = Line1[4].x = Line2[4].x = xc + edge;
1016 Line1[5].y = Line2[2].y = Line1[4].y = Line2[1].y = yc + edge;
1017 Line1[2].x = Line2[2].x = Line1[1].x + move;
1018 Line1[0].y = Line2[3].y = Line1[1].y + move;
1019 Line1[5].x = Line2[5].x = Line1[4].x - move;
1020 Line1[3].y = Line2[0].y = Line1[4].y - move;
1021 Line1N = 6;
1022 Line2N = 6;
1023 break;
1025 case DFCS_CAPTIONHELP:
1026 /* This one breaks the flow */
1027 /* FIXME: We need the Marlett font in order to get this right. */
1029 hf = CreateFont32A(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
1030 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
1031 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System");
1032 alignsave = SetTextAlign32(dc, TA_TOP|TA_LEFT);
1033 bksave = SetBkMode32(dc, TRANSPARENT);
1034 clrsave = GetTextColor32(dc);
1035 hfsave = (HFONT32)SelectObject32(dc, hf);
1036 GetTextExtentPoint32A(dc, str, 1, &size);
1038 if(uFlags & DFCS_INACTIVE)
1040 SetTextColor32(dc, GetSysColor32(COLOR_BTNHIGHLIGHT));
1041 TextOut32A(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1);
1043 SetTextColor32(dc, GetSysColor32(uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT));
1044 TextOut32A(dc, xc-size.cx/2, yc-size.cy/2, str, 1);
1046 SelectObject32(dc, hfsave);
1047 SetTextColor32(dc, clrsave);
1048 SetBkMode32(dc, bksave);
1049 SetTextAlign32(dc, alignsave);
1050 DeleteObject32(hf);
1051 return TRUE;
1053 case DFCS_CAPTIONMIN:
1054 Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2;
1055 Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750;
1056 Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1;
1057 Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750;
1058 Line1N = 4;
1059 Line2N = 0;
1060 break;
1062 case DFCS_CAPTIONMAX:
1063 edge = 47*SmallDiam/750;
1064 Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3;
1065 Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1;
1066 Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750;
1067 Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750;
1068 Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750;
1069 Line1[3].x = Line1[4].x = Line1[1].x - edge;
1071 Line2[0].x = Line2[5].x = Line1[0].x;
1072 Line2[3].x = Line2[4].x = Line1[1].x;
1073 Line2[1].x = Line2[2].x = Line1[0].x + edge;
1074 Line2[0].y = Line2[1].y = Line1[0].y;
1075 Line2[4].y = Line2[5].y = Line1[2].y;
1076 Line2[2].y = Line2[3].y = Line1[2].y - edge;
1077 Line1N = 6;
1078 Line2N = 6;
1079 break;
1081 case DFCS_CAPTIONRESTORE:
1082 /* FIXME: this one looks bad at small sizes < 15x15 :( */
1083 edge = 47*SmallDiam/750;
1084 move = 420*SmallDiam/750;
1085 Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2;
1086 Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1;
1087 Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750;
1088 Line1[7].x = Line1[8].x = Line1[0].x + edge;
1089 Line1[1].x = Line1[2].x = Line1[0].x + move;
1090 Line1[5].x = Line1[6].x = Line1[1].x - edge;
1091 Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750;
1092 Line1[2].y = Line1[3].y = Line1[0].y + 327*SmallDiam/750;
1093 Line1[4].y = Line1[5].y = Line1[2].y - edge;
1094 Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750;
1096 Line2[1].x = Line2[2].x = Line1[3].x;
1097 Line2[7].x = Line2[8].x = Line2[1].x - edge;
1098 Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move;
1099 Line2[5].x = Line2[6].x = Line2[0].x + edge;
1100 Line2[0].y = Line2[1].y = Line1[9].y;
1101 Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750;
1102 Line2[2].y = Line2[3].y = Line2[0].y + 327*SmallDiam/750;
1103 Line2[6].y = Line2[7].y = Line2[2].y - edge;
1104 Line1N = 10;
1105 Line2N = 10;
1106 break;
1108 default:
1109 fprintf(stdnimp, "UITOOLS_DrawFrameCaption: Report this: Invalid caption; flags: 0x%04x\n", uFlags);
1110 return FALSE;
1113 /* Here the drawing takes place */
1114 if(uFlags & DFCS_INACTIVE)
1116 /* If we have an inactive button, then you see a shadow */
1117 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
1118 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNHIGHLIGHT));
1119 hpsave = (HPEN32)SelectObject32(dc, hp);
1120 Polygon32(dc, Line1, Line1N);
1121 if(Line2N > 0)
1122 Polygon32(dc, Line2, Line2N);
1123 SelectObject32(dc, hpsave);
1124 SelectObject32(dc, hbsave);
1125 DeleteObject32(hp);
1128 /* Correct for the shadow shift */
1129 for(i = 0; i < Line1N; i++)
1131 Line1[i].x--;
1132 Line1[i].y--;
1134 for(i = 0; i < Line2N; i++)
1136 Line2[i].x--;
1137 Line2[i].y--;
1140 /* Make the final picture */
1141 if(uFlags & DFCS_INACTIVE)
1143 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNSHADOW));
1144 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNSHADOW));
1146 else
1148 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNTEXT));
1149 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNTEXT));
1151 hpsave = (HPEN32)SelectObject32(dc, hp);
1152 Polygon32(dc, Line1, Line1N);
1153 if(Line2N > 0)
1154 Polygon32(dc, Line2, Line2N);
1155 SelectObject32(dc, hpsave);
1156 SelectObject32(dc, hbsave);
1157 DeleteObject32(hp);
1159 return TRUE;
1163 /************************************************************************
1164 * UITOOLS_DrawFrameScroll
1166 * Draw a scroll-bar control coming from DrawFrameControl()
1168 static BOOL32 UITOOLS_DrawFrameScroll(HDC32 dc, LPRECT32 r, UINT32 uFlags)
1170 POINT32 Line[4];
1171 RECT32 myr;
1172 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2;
1173 int i;
1174 HBRUSH32 hbsave, hb, hb2;
1175 HPEN32 hpsave, hp, hp2;
1176 int tri = 310*SmallDiam/1000;
1177 int d46, d93;
1179 switch(uFlags & 0xff)
1181 case DFCS_SCROLLCOMBOBOX:
1182 case DFCS_SCROLLDOWN:
1183 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1184 Line[2].y = myr.top + 687*SmallDiam/1000 + 1;
1185 Line[0].x = Line[2].x - tri;
1186 Line[1].x = Line[2].x + tri;
1187 Line[0].y = Line[1].y = Line[2].y - tri;
1188 break;
1190 case DFCS_SCROLLUP:
1191 Line[2].x = myr.left + 470*SmallDiam/1000 + 2;
1192 Line[2].y = myr.top + 313*SmallDiam/1000 + 1;
1193 Line[0].x = Line[2].x - tri;
1194 Line[1].x = Line[2].x + tri;
1195 Line[0].y = Line[1].y = Line[2].y + tri;
1196 break;
1198 case DFCS_SCROLLLEFT:
1199 Line[2].x = myr.left + 313*SmallDiam/1000 + 1;
1200 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1201 Line[0].y = Line[2].y - tri;
1202 Line[1].y = Line[2].y + tri;
1203 Line[0].x = Line[1].x = Line[2].x + tri;
1204 break;
1206 case DFCS_SCROLLRIGHT:
1207 Line[2].x = myr.left + 687*SmallDiam/1000 + 1;
1208 Line[2].y = myr.top + 470*SmallDiam/1000 + 2;
1209 Line[0].y = Line[2].y - tri;
1210 Line[1].y = Line[2].y + tri;
1211 Line[0].x = Line[1].x = Line[2].x - tri;
1212 break;
1214 case DFCS_SCROLLSIZEGRIP:
1215 /* This one breaks the flow... */
1216 UITOOLS_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0));
1217 hpsave = (HPEN32)SelectObject32(dc, GetStockObject32(NULL_PEN));
1218 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(NULL_BRUSH));
1219 if(uFlags & (DFCS_MONO|DFCS_FLAT))
1221 hp = hp2 = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_WINDOWFRAME));
1222 hb = hb2 = GetSysColorBrush32(COLOR_WINDOWFRAME);
1224 else
1226 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNHIGHLIGHT));
1227 hp2 = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNSHADOW));
1228 hb = GetSysColorBrush32(COLOR_BTNHIGHLIGHT);
1229 hb2 = GetSysColorBrush32(COLOR_BTNSHADOW);
1231 Line[0].x = Line[1].x = r->right-1;
1232 Line[2].y = Line[3].y = r->bottom-1;
1233 d46 = 46*SmallDiam/750;
1234 d93 = 93*SmallDiam/750;
1236 i = 586*SmallDiam/750;
1237 Line[0].y = r->bottom - i - 1;
1238 Line[3].x = r->right - i - 1;
1239 Line[1].y = Line[0].y + d46;
1240 Line[2].x = Line[3].x + d46;
1241 SelectObject32(dc, hb);
1242 SelectObject32(dc, hp);
1243 Polygon32(dc, Line, 4);
1245 Line[1].y++; Line[2].x++;
1246 Line[0].y = Line[1].y + d93;
1247 Line[3].x = Line[2].x + d93;
1248 SelectObject32(dc, hb2);
1249 SelectObject32(dc, hp2);
1250 Polygon32(dc, Line, 4);
1252 i = 398*SmallDiam/750;
1253 Line[0].y = r->bottom - i - 1;
1254 Line[3].x = r->right - i - 1;
1255 Line[1].y = Line[0].y + d46;
1256 Line[2].x = Line[3].x + d46;
1257 SelectObject32(dc, hb);
1258 SelectObject32(dc, hp);
1259 Polygon32(dc, Line, 4);
1261 Line[1].y++; Line[2].x++;
1262 Line[0].y = Line[1].y + d93;
1263 Line[3].x = Line[2].x + d93;
1264 SelectObject32(dc, hb2);
1265 SelectObject32(dc, hp2);
1266 Polygon32(dc, Line, 4);
1268 i = 210*SmallDiam/750;
1269 Line[0].y = r->bottom - i - 1;
1270 Line[3].x = r->right - i - 1;
1271 Line[1].y = Line[0].y + d46;
1272 Line[2].x = Line[3].x + d46;
1273 SelectObject32(dc, hb);
1274 SelectObject32(dc, hp);
1275 Polygon32(dc, Line, 4);
1277 Line[1].y++; Line[2].x++;
1278 Line[0].y = Line[1].y + d93;
1279 Line[3].x = Line[2].x + d93;
1280 SelectObject32(dc, hb2);
1281 SelectObject32(dc, hp2);
1282 Polygon32(dc, Line, 4);
1284 SelectObject32(dc, hpsave);
1285 SelectObject32(dc, hbsave);
1286 DeleteObject32(hp);
1287 DeleteObject32(hp2);
1288 return TRUE;
1290 default:
1291 fprintf(stdnimp, "UITOOLS_DrawFrameScroll: Report this: Invalid scroll; flags: 0x%04x\n", uFlags);
1292 return FALSE;
1295 /* Here do the real scroll-bar controls end up */
1296 UITOOLS_DFC_ButtonPush(dc, r, uFlags & 0xff00);
1298 if(uFlags & DFCS_INACTIVE)
1300 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNHIGHLIGHT));
1301 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNHIGHLIGHT));
1302 hpsave = (HPEN32)SelectObject32(dc, hp);
1303 Polygon32(dc, Line, 3);
1304 SelectObject32(dc, hpsave);
1305 SelectObject32(dc, hbsave);
1306 DeleteObject32(hp);
1309 for(i = 0; i < 3; i++)
1311 Line[i].x--;
1312 Line[i].y--;
1315 if(uFlags & DFCS_INACTIVE)
1317 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNSHADOW));
1318 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNSHADOW));
1320 else
1322 hbsave = (HBRUSH32)SelectObject32(dc, GetSysColorBrush32(COLOR_BTNTEXT));
1323 hp = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_BTNTEXT));
1325 hpsave = (HPEN32)SelectObject32(dc, hp);
1326 Polygon32(dc, Line, 3);
1327 SelectObject32(dc, hpsave);
1328 SelectObject32(dc, hbsave);
1329 DeleteObject32(hp);
1331 return TRUE;
1334 /************************************************************************
1335 * UITOOLS_DrawFrameMenu
1337 * Draw a menu control coming from DrawFrameControl()
1339 static BOOL32 UITOOLS_DrawFrameMenu(HDC32 dc, LPRECT32 r, UINT32 uFlags)
1341 POINT32 Points[6];
1342 RECT32 myr;
1343 int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
1344 int i;
1345 HBRUSH32 hbsave;
1346 HPEN32 hpsave;
1347 int xe, ye;
1348 int xc, yc;
1349 BOOL32 retval = TRUE;
1351 /* Using black and white seems to be utterly wrong, but win95 doesn't */
1352 /* use anything else. I think I tried all sys-colors to change things */
1353 /* without luck. It seems as if this behavior is inherited from the */
1354 /* win31 DFC() implementation... (you remember, B/W menus). */
1356 FillRect32(dc, r, (HBRUSH32)GetStockObject32(WHITE_BRUSH));
1358 hbsave = (HBRUSH32)SelectObject32(dc, GetStockObject32(BLACK_BRUSH));
1359 hpsave = (HPEN32)SelectObject32(dc, GetStockObject32(BLACK_PEN));
1361 switch(uFlags & 0xff)
1363 case DFCS_MENUARROW:
1364 i = 187*SmallDiam/750;
1365 Points[2].x = myr.left + 468*SmallDiam/750;
1366 Points[2].y = myr.top + 352*SmallDiam/750+1;
1367 Points[0].y = Points[2].y - i;
1368 Points[1].y = Points[2].y + i;
1369 Points[0].x = Points[1].x = Points[2].x - i;
1370 Polygon32(dc, Points, 3);
1371 break;
1373 case DFCS_MENUBULLET:
1374 xe = myr.left;
1375 ye = myr.top + SmallDiam - SmallDiam/2;
1376 xc = myr.left + SmallDiam - SmallDiam/2;
1377 yc = myr.top + SmallDiam - SmallDiam/2;
1378 i = 234*SmallDiam/750;
1379 i = i < 1 ? 1 : i;
1380 myr.left = xc - i+i/2;
1381 myr.right = xc + i/2;
1382 myr.top = yc - i+i/2;
1383 myr.bottom = yc + i/2;
1384 Pie32(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye);
1385 break;
1387 case DFCS_MENUCHECK:
1388 Points[0].x = myr.left + 253*SmallDiam/1000;
1389 Points[0].y = myr.top + 445*SmallDiam/1000;
1390 Points[1].x = myr.left + 409*SmallDiam/1000;
1391 Points[1].y = Points[0].y + (Points[1].x-Points[0].x);
1392 Points[2].x = myr.left + 690*SmallDiam/1000;
1393 Points[2].y = Points[1].y - (Points[2].x-Points[1].x);
1394 Points[3].x = Points[2].x;
1395 Points[3].y = Points[2].y + 3*SmallDiam/16;
1396 Points[4].x = Points[1].x;
1397 Points[4].y = Points[1].y + 3*SmallDiam/16;
1398 Points[5].x = Points[0].x;
1399 Points[5].y = Points[0].y + 3*SmallDiam/16;
1400 Polygon32(dc, Points, 6);
1401 break;
1403 default:
1404 fprintf(stdnimp, "UITOOLS_DrawFrameMenu: Report this: Invalid menu; flags: 0x%04x\n", uFlags);
1405 retval = FALSE;
1406 break;
1409 SelectObject32(dc, hpsave);
1410 SelectObject32(dc, hbsave);
1411 return retval;
1415 /**********************************************************************
1416 * DrawFrameControl16 (USER.656)
1418 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType,
1419 UINT16 uState )
1421 RECT32 rect32;
1422 BOOL32 ret;
1424 CONV_RECT16TO32( rc, &rect32 );
1425 ret = DrawFrameControl32( hdc, &rect32, uType, uState );
1426 CONV_RECT32TO16( &rect32, rc );
1427 return ret;
1431 /**********************************************************************
1432 * DrawFrameControl32 (USER32.157)
1434 BOOL32 WINAPI DrawFrameControl32( HDC32 hdc, LPRECT32 rc, UINT32 uType,
1435 UINT32 uState )
1437 /* Win95 doesn't support drawing in other mapping modes */
1438 if(GetMapMode32(hdc) != MM_TEXT)
1439 return FALSE;
1441 switch(uType)
1443 case DFC_BUTTON:
1444 return UITOOLS_DrawFrameButton(hdc, rc, uState);
1445 case DFC_CAPTION:
1446 return UITOOLS_DrawFrameCaption(hdc, rc, uState);
1447 case DFC_MENU:
1448 return UITOOLS_DrawFrameMenu(hdc, rc, uState);
1449 case DFC_SCROLL:
1450 return UITOOLS_DrawFrameScroll(hdc, rc, uState);
1451 default:
1452 fprintf( stdnimp,"DrawFrameControl32(%x,%p,%d,%x), bad type!\n",
1453 hdc,rc,uType,uState );
1455 return FALSE;