2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/draw.c
5 * PURPOSE: Providing drawing functions
7 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
12 #define MENU_BAR_ITEMS_SPACE (12)
14 /******************************************************************************/
16 static const signed char LTInnerNormal
[] = {
18 -1, COLOR_BTNHIGHLIGHT
, COLOR_BTNHIGHLIGHT
, -1,
19 -1, COLOR_3DDKSHADOW
, COLOR_3DDKSHADOW
, -1,
23 static const signed char LTOuterNormal
[] = {
24 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
25 COLOR_BTNHIGHLIGHT
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
26 COLOR_3DDKSHADOW
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
27 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1
30 static const signed char RBInnerNormal
[] = {
32 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, -1,
33 -1, COLOR_3DLIGHT
, COLOR_3DLIGHT
, -1,
37 static const signed char RBOuterNormal
[] = {
38 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
39 COLOR_BTNSHADOW
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
40 COLOR_3DLIGHT
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
41 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1
44 static const signed char LTRBOuterMono
[] = {
45 -1, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
46 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
47 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
48 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
51 static const signed char LTRBInnerMono
[] = {
53 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
54 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
55 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
59 MyIntDrawRectEdge(HDC hdc
, LPRECT rc
, UINT uType
, UINT uFlags
, COLOR_SCHEME
*scheme
)
61 signed char LTInnerI
, LTOuterI
;
62 signed char RBInnerI
, RBOuterI
;
63 HPEN LTInnerPen
, LTOuterPen
;
64 HPEN RBInnerPen
, RBOuterPen
;
73 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= (HPEN
)GetStockObject(NULL_PEN
);
74 SavePen
= (HPEN
)SelectObject(hdc
, LTInnerPen
);
76 /* Determine the colors of the edges */
77 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
78 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
79 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
80 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
82 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
)
84 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
)
86 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
)
88 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
)
92 LTInnerPen
= GetStockObject(DC_PEN
);
94 LTOuterPen
= GetStockObject(DC_PEN
);
96 RBInnerPen
= GetStockObject(DC_PEN
);
98 RBOuterPen
= GetStockObject(DC_PEN
);
101 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_BTNFACE
]);
102 FillRect(hdc
, &InnerRect
, hbr
);
105 MoveToEx(hdc
, 0, 0, &SavePoint
);
107 /* Draw the outer edge */
108 SelectObject(hdc
, LTOuterPen
);
109 SetDCPenColor(hdc
, scheme
->crColor
[LTOuterI
]);
112 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
113 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
117 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
118 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
120 SelectObject(hdc
, RBOuterPen
);
121 SetDCPenColor(hdc
, scheme
->crColor
[RBOuterI
]);
122 if(uFlags
& BF_BOTTOM
)
124 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.bottom
-1, NULL
);
125 LineTo(hdc
, InnerRect
.right
, InnerRect
.bottom
-1);
127 if(uFlags
& BF_RIGHT
)
129 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.top
, NULL
);
130 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.bottom
);
133 /* Draw the inner edge */
134 SelectObject(hdc
, LTInnerPen
);
135 SetDCPenColor(hdc
, scheme
->crColor
[LTInnerI
]);
138 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
139 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
143 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
144 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
146 SelectObject(hdc
, RBInnerPen
);
147 SetDCPenColor(hdc
, scheme
->crColor
[RBInnerI
]);
148 if(uFlags
& BF_BOTTOM
)
150 MoveToEx(hdc
, InnerRect
.left
+LBpenplus
, InnerRect
.bottom
-2, NULL
);
151 LineTo(hdc
, InnerRect
.right
-RBpenplus
, InnerRect
.bottom
-2);
153 if(uFlags
& BF_RIGHT
)
155 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.top
+RTpenplus
, NULL
);
156 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-RBpenplus
);
159 if (uFlags
& BF_ADJUST
)
161 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
162 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
165 InnerRect
.left
+= add
;
166 if(uFlags
& BF_RIGHT
)
167 InnerRect
.right
-= add
;
169 InnerRect
.top
+= add
;
170 if(uFlags
& BF_BOTTOM
)
171 InnerRect
.bottom
-= add
;
173 if(uFlags
& BF_ADJUST
)
178 SelectObject(hdc
, SavePen
);
179 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
184 MyDrawFrameButton(HDC hdc
, LPRECT rc
, UINT uState
, COLOR_SCHEME
*scheme
)
187 if(uState
& (DFCS_PUSHED
| DFCS_CHECKED
| DFCS_FLAT
))
191 return MyIntDrawRectEdge(hdc
, rc
, edge
, (uState
& DFCS_FLAT
) | BF_RECT
| BF_SOFT
, scheme
);
195 MyMakeSquareRect(LPRECT src
, LPRECT dst
)
197 int Width
= src
->right
- src
->left
;
198 int Height
= src
->bottom
- src
->top
;
199 int SmallDiam
= Width
> Height
? Height
: Width
;
203 /* Make it a square box */
204 if (Width
< Height
) /* SmallDiam == Width */
206 dst
->top
+= (Height
-Width
)/2;
207 dst
->bottom
= dst
->top
+ SmallDiam
;
209 else if(Width
> Height
) /* SmallDiam == Height */
211 dst
->left
+= (Width
-Height
)/2;
212 dst
->right
= dst
->left
+ SmallDiam
;
219 MyDrawFrameCaption(HDC dc
, LPRECT r
, UINT uFlags
, COLOR_SCHEME
*scheme
)
222 HFONT hFont
, hOldFont
;
227 switch(uFlags
& 0xff)
229 case DFCS_CAPTIONCLOSE
:
232 case DFCS_CAPTIONHELP
:
235 case DFCS_CAPTIONMIN
:
238 case DFCS_CAPTIONMAX
:
241 case DFCS_CAPTIONRESTORE
:
245 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, BF_RECT
| BF_MIDDLE
| BF_SOFT
, scheme
);
246 ZeroMemory(&lf
, sizeof(LOGFONT
));
247 MyMakeSquareRect(r
, &myr
);
252 if(uFlags
& DFCS_PUSHED
)
253 OffsetRect(&myr
,1,1);
254 lf
.lfHeight
= myr
.bottom
- myr
.top
;
256 lf
.lfWeight
= FW_NORMAL
;
257 lf
.lfCharSet
= DEFAULT_CHARSET
;
258 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
259 hFont
= CreateFontIndirect(&lf
);
260 /* Save font and text color */
261 hOldFont
= SelectObject(dc
, hFont
);
262 clrsave
= GetTextColor(dc
);
263 bkmode
= GetBkMode(dc
);
264 /* Set color and drawing mode */
265 SetBkMode(dc
, TRANSPARENT
);
266 if(uFlags
& DFCS_INACTIVE
)
269 SetTextColor(dc
, scheme
->crColor
[COLOR_BTNHIGHLIGHT
]);
270 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
272 SetTextColor(dc
, scheme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
273 /* Draw selected symbol */
274 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
275 /* Restore previous settings */
276 SetTextColor(dc
, clrsave
);
277 SelectObject(dc
, hOldFont
);
278 SetBkMode(dc
, bkmode
);
283 /******************************************************************************/
286 MyDrawFrameScroll(HDC dc
, LPRECT r
, UINT uFlags
, COLOR_SCHEME
*scheme
)
289 HFONT hFont
, hOldFont
;
294 switch(uFlags
& 0xff)
296 case DFCS_SCROLLCOMBOBOX
:
297 case DFCS_SCROLLDOWN
:
305 case DFCS_SCROLLLEFT
:
309 case DFCS_SCROLLRIGHT
:
313 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
, scheme
);
314 ZeroMemory(&lf
, sizeof(LOGFONT
));
315 MyMakeSquareRect(r
, &myr
);
320 if(uFlags
& DFCS_PUSHED
)
321 OffsetRect(&myr
,1,1);
322 lf
.lfHeight
= myr
.bottom
- myr
.top
;
324 lf
.lfWeight
= FW_NORMAL
;
325 lf
.lfCharSet
= DEFAULT_CHARSET
;
326 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
327 hFont
= CreateFontIndirect(&lf
);
328 /* Save font and text color */
329 hOldFont
= SelectObject(dc
, hFont
);
330 clrsave
= GetTextColor(dc
);
331 bkmode
= GetBkMode(dc
);
332 /* Set color and drawing mode */
333 SetBkMode(dc
, TRANSPARENT
);
334 if(uFlags
& DFCS_INACTIVE
)
337 SetTextColor(dc
, scheme
->crColor
[COLOR_BTNHIGHLIGHT
]);
338 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
340 SetTextColor(dc
, scheme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
341 /* Draw selected symbol */
342 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
343 /* restore previous settings */
344 SetTextColor(dc
, clrsave
);
345 SelectObject(dc
, hOldFont
);
346 SetBkMode(dc
, bkmode
);
352 MyDrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
, COLOR_SCHEME
*scheme
)
357 return MyDrawFrameButton(hDC
, rc
, uState
, scheme
);
359 return MyDrawFrameCaption(hDC
, rc
, uState
, scheme
);
361 return MyDrawFrameScroll(hDC
, rc
, uState
, scheme
);
367 MyDrawEdge(HDC hDC
, LPRECT rc
, UINT edge
, UINT flags
, COLOR_SCHEME
*scheme
)
369 return MyIntDrawRectEdge(hDC
, rc
, edge
, flags
, scheme
);
373 MyDrawCaptionButtons(HDC hdc
, LPRECT lpRect
, BOOL bMinMax
, int x
, COLOR_SCHEME
*scheme
)
379 rc3
.left
= lpRect
->right
- 2 - x
;
380 rc3
.top
= lpRect
->top
+ 2;
381 rc3
.right
= lpRect
->right
- 2;
382 rc3
.bottom
= lpRect
->bottom
- 2;
384 MyDrawFrameControl(hdc
, &rc3
, DFC_CAPTION
, DFCS_CAPTIONCLOSE
, scheme
);
388 rc4
.left
= rc3
.left
- x
- 2;
390 rc4
.right
= rc3
.right
- x
- 2;
391 rc4
.bottom
= rc3
.bottom
;
393 MyDrawFrameControl(hdc
, &rc4
, DFC_CAPTION
, DFCS_CAPTIONMAX
, scheme
);
395 rc5
.left
= rc4
.left
- x
;
397 rc5
.right
= rc4
.right
- x
;
398 rc5
.bottom
= rc4
.bottom
;
400 MyDrawFrameControl(hdc
, &rc5
, DFC_CAPTION
, DFCS_CAPTIONMIN
, scheme
);
405 MyDrawScrollbar(HDC hdc
, LPRECT rc
, HBRUSH hbrScrollbar
, COLOR_SCHEME
*scheme
)
412 width
= rc
->right
- rc
->left
;
414 rcTop
.left
= rc
->left
;
415 rcTop
.right
= rc
->right
;
417 rcTop
.bottom
= rc
->top
+ width
;
419 rcMiddle
.left
= rc
->left
;
420 rcMiddle
.right
= rc
->right
;
421 rcMiddle
.top
= rc
->top
+ width
;
422 rcMiddle
.bottom
= rc
->bottom
- width
;
424 rcBottom
.left
= rc
->left
;
425 rcBottom
.right
= rc
->right
;
426 rcBottom
.top
= rc
->bottom
- width
;
427 rcBottom
.bottom
= rc
->bottom
;
429 MyDrawFrameControl(hdc
, &rcTop
, DFC_SCROLL
, DFCS_SCROLLUP
, scheme
);
430 MyDrawFrameControl(hdc
, &rcBottom
, DFC_SCROLL
, DFCS_SCROLLDOWN
, scheme
);
432 FillRect(hdc
, &rcMiddle
, hbrScrollbar
);
435 /******************************************************************************/
438 MyDrawCaptionTemp(HWND hwnd
, HDC hdc
, const RECT
*rect
, HFONT hFont
, HICON hIcon
, LPCWSTR str
, UINT uFlags
, COLOR_SCHEME
*scheme
)
441 //UINT VCenter, Padding;
447 //Height = scheme->Size[SIZE_CAPTION_Y] - 1;
448 //VCenter = (rect->bottom - rect->top) / 2;
449 //Padding = VCenter - (Height / 2);
451 //ButtonWidth = scheme->Size[SIZE_SIZE_X] - 2;
453 if (uFlags
& DC_GRADIENT
)
455 GRADIENT_RECT gcap
= {0, 1};
459 Colors
[0] = scheme
->crColor
[((uFlags
& DC_ACTIVE
) ?
460 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
)];
461 Colors
[1] = scheme
->crColor
[((uFlags
& DC_ACTIVE
) ?
462 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
)];
464 vert
[0].x
= rect
->left
;
465 vert
[0].y
= rect
->top
;
466 vert
[0].Red
= (WORD
)Colors
[0]<<8;
467 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
468 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
471 vert
[1].x
= rect
->right
;
472 vert
[1].y
= rect
->bottom
;
473 vert
[1].Red
= (WORD
)Colors
[1]<<8;
474 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
475 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
478 GdiGradientFill(hdc
, vert
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
);
482 if (uFlags
& DC_ACTIVE
)
483 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_ACTIVECAPTION
]);
485 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_INACTIVECAPTION
]);
486 FillRect(hdc
, rect
, hbr
);
490 hFontOld
= SelectObject(hdc
, hFont
);
491 SetBkMode(hdc
, TRANSPARENT
);
492 if (uFlags
& DC_ACTIVE
)
493 SetTextColor(hdc
, scheme
->crColor
[COLOR_CAPTIONTEXT
]);
495 SetTextColor(hdc
, scheme
->crColor
[COLOR_INACTIVECAPTIONTEXT
]);
496 rc
.left
= rect
->left
+ 2;
498 rc
.right
= rect
->right
;
499 rc
.bottom
= rect
->bottom
;
500 DrawTextW(hdc
, str
, -1, &rc
, DT_SINGLELINE
| DT_VCENTER
);
501 SelectObject(hdc
, hFontOld
);
505 /******************************************************************************/
508 MyDrawMenuBarTemp(HWND Wnd
, HDC DC
, LPRECT Rect
, HMENU Menu
, HFONT Font
, COLOR_SCHEME
*scheme
)
512 HGDIOBJ hPenOld
, hFontOld
;
517 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
519 flat_menu
= scheme
->bFlatMenus
;
522 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENUBAR
]);
524 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENU
]);
525 FillRect(DC
, Rect
, hbr
);
528 hPen
= CreatePen(PS_SOLID
, 0, scheme
->crColor
[COLOR_3DFACE
]);
529 hPenOld
= SelectObject(DC
, hPen
);
530 MoveToEx(DC
, Rect
->left
, Rect
->bottom
- 1, NULL
);
531 LineTo(DC
, Rect
->right
, Rect
->bottom
- 1);
532 SelectObject(DC
, hPenOld
);
535 bkgnd
= (flat_menu
? COLOR_MENUBAR
: COLOR_MENU
);
537 hFontOld
= SelectObject(DC
, Font
);
538 for(i
= 0; i
< 3; i
++)
540 GetMenuStringW(Menu
, i
, Text
, 128, MF_BYPOSITION
);
542 rect
.left
= rect
.right
= x
;
543 rect
.top
= Rect
->top
;
544 rect
.bottom
= Rect
->bottom
;
545 DrawTextW(DC
, Text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
546 rect
.bottom
= Rect
->bottom
;
547 rect
.right
+= MENU_BAR_ITEMS_SPACE
;
548 x
+= rect
.right
- rect
.left
;
554 SetTextColor(DC
, scheme
->crColor
[COLOR_HIGHLIGHTTEXT
]);
555 SetBkColor(DC
, scheme
->crColor
[COLOR_HIGHLIGHT
]);
557 InflateRect (&rect
, -1, -1);
558 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENUHILIGHT
]);
559 FillRect(DC
, &rect
, hbr
);
562 InflateRect (&rect
, 1, 1);
563 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_HIGHLIGHT
]);
564 FrameRect(DC
, &rect
, hbr
);
569 SetTextColor(DC
, scheme
->crColor
[COLOR_MENUTEXT
]);
570 SetBkColor(DC
, scheme
->crColor
[COLOR_MENU
]);
571 DrawEdge(DC
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
577 SetTextColor(DC
, scheme
->crColor
[COLOR_GRAYTEXT
]);
579 SetTextColor(DC
, scheme
->crColor
[COLOR_MENUTEXT
]);
581 SetBkColor(DC
, scheme
->crColor
[bkgnd
]);
582 hbr
= CreateSolidBrush(scheme
->crColor
[bkgnd
]);
583 FillRect(DC
, &rect
, hbr
);
587 SetBkMode(DC
, TRANSPARENT
);
589 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
590 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
594 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
595 SetTextColor(DC
, RGB(0xff, 0xff, 0xff));
596 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
597 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
598 SetTextColor(DC
, RGB(0x80, 0x80, 0x80));
600 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
602 SelectObject(DC
, hFontOld
);