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
);
102 if((uFlags
& MY_BF_ACTIVEBORDER
))
103 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_ACTIVEBORDER
]);
105 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_BTNFACE
]);
106 FillRect(hdc
, &InnerRect
, hbr
);
109 MoveToEx(hdc
, 0, 0, &SavePoint
);
111 /* Draw the outer edge */
112 SelectObject(hdc
, LTOuterPen
);
113 SetDCPenColor(hdc
, scheme
->crColor
[LTOuterI
]);
116 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
117 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
121 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
122 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
124 SelectObject(hdc
, RBOuterPen
);
125 SetDCPenColor(hdc
, scheme
->crColor
[RBOuterI
]);
126 if(uFlags
& BF_BOTTOM
)
128 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.bottom
-1, NULL
);
129 LineTo(hdc
, InnerRect
.right
, InnerRect
.bottom
-1);
131 if(uFlags
& BF_RIGHT
)
133 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.top
, NULL
);
134 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.bottom
);
137 /* Draw the inner edge */
138 SelectObject(hdc
, LTInnerPen
);
139 SetDCPenColor(hdc
, scheme
->crColor
[LTInnerI
]);
142 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
143 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
147 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
148 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
150 SelectObject(hdc
, RBInnerPen
);
151 SetDCPenColor(hdc
, scheme
->crColor
[RBInnerI
]);
152 if(uFlags
& BF_BOTTOM
)
154 MoveToEx(hdc
, InnerRect
.left
+LBpenplus
, InnerRect
.bottom
-2, NULL
);
155 LineTo(hdc
, InnerRect
.right
-RBpenplus
, InnerRect
.bottom
-2);
157 if(uFlags
& BF_RIGHT
)
159 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.top
+RTpenplus
, NULL
);
160 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-RBpenplus
);
163 if (uFlags
& BF_ADJUST
)
165 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
166 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
169 InnerRect
.left
+= add
;
170 if(uFlags
& BF_RIGHT
)
171 InnerRect
.right
-= add
;
173 InnerRect
.top
+= add
;
174 if(uFlags
& BF_BOTTOM
)
175 InnerRect
.bottom
-= add
;
177 if(uFlags
& BF_ADJUST
)
182 SelectObject(hdc
, SavePen
);
183 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
188 MyDrawFrameButton(HDC hdc
, LPRECT rc
, UINT uState
, COLOR_SCHEME
*scheme
)
191 if(uState
& (DFCS_PUSHED
| DFCS_CHECKED
| DFCS_FLAT
))
195 return MyIntDrawRectEdge(hdc
, rc
, edge
, (uState
& DFCS_FLAT
) | BF_RECT
| BF_SOFT
, scheme
);
199 MyMakeSquareRect(LPRECT src
, LPRECT dst
)
201 int Width
= src
->right
- src
->left
;
202 int Height
= src
->bottom
- src
->top
;
203 int SmallDiam
= Width
> Height
? Height
: Width
;
207 /* Make it a square box */
208 if (Width
< Height
) /* SmallDiam == Width */
210 dst
->top
+= (Height
-Width
)/2;
211 dst
->bottom
= dst
->top
+ SmallDiam
;
213 else if(Width
> Height
) /* SmallDiam == Height */
215 dst
->left
+= (Width
-Height
)/2;
216 dst
->right
= dst
->left
+ SmallDiam
;
223 MyDrawFrameCaption(HDC dc
, LPRECT r
, UINT uFlags
, COLOR_SCHEME
*scheme
)
226 HFONT hFont
, hOldFont
;
231 switch(uFlags
& 0xff)
233 case DFCS_CAPTIONCLOSE
:
236 case DFCS_CAPTIONHELP
:
239 case DFCS_CAPTIONMIN
:
242 case DFCS_CAPTIONMAX
:
245 case DFCS_CAPTIONRESTORE
:
249 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, BF_RECT
| BF_MIDDLE
| BF_SOFT
, scheme
);
250 ZeroMemory(&lf
, sizeof(LOGFONT
));
251 MyMakeSquareRect(r
, &myr
);
256 if(uFlags
& DFCS_PUSHED
)
257 OffsetRect(&myr
,1,1);
258 lf
.lfHeight
= myr
.bottom
- myr
.top
;
260 lf
.lfWeight
= FW_NORMAL
;
261 lf
.lfCharSet
= DEFAULT_CHARSET
;
262 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
263 hFont
= CreateFontIndirect(&lf
);
264 /* Save font and text color */
265 hOldFont
= SelectObject(dc
, hFont
);
266 clrsave
= GetTextColor(dc
);
267 bkmode
= GetBkMode(dc
);
268 /* Set color and drawing mode */
269 SetBkMode(dc
, TRANSPARENT
);
270 if(uFlags
& DFCS_INACTIVE
)
273 SetTextColor(dc
, scheme
->crColor
[COLOR_BTNHIGHLIGHT
]);
274 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
276 SetTextColor(dc
, scheme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
277 /* Draw selected symbol */
278 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
279 /* Restore previous settings */
280 SetTextColor(dc
, clrsave
);
281 SelectObject(dc
, hOldFont
);
282 SetBkMode(dc
, bkmode
);
287 /******************************************************************************/
290 MyDrawFrameScroll(HDC dc
, LPRECT r
, UINT uFlags
, COLOR_SCHEME
*scheme
)
293 HFONT hFont
, hOldFont
;
298 switch(uFlags
& 0xff)
300 case DFCS_SCROLLCOMBOBOX
:
301 case DFCS_SCROLLDOWN
:
309 case DFCS_SCROLLLEFT
:
313 case DFCS_SCROLLRIGHT
:
317 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
, scheme
);
318 ZeroMemory(&lf
, sizeof(LOGFONT
));
319 MyMakeSquareRect(r
, &myr
);
324 if(uFlags
& DFCS_PUSHED
)
325 OffsetRect(&myr
,1,1);
326 lf
.lfHeight
= myr
.bottom
- myr
.top
;
328 lf
.lfWeight
= FW_NORMAL
;
329 lf
.lfCharSet
= DEFAULT_CHARSET
;
330 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
331 hFont
= CreateFontIndirect(&lf
);
332 /* Save font and text color */
333 hOldFont
= SelectObject(dc
, hFont
);
334 clrsave
= GetTextColor(dc
);
335 bkmode
= GetBkMode(dc
);
336 /* Set color and drawing mode */
337 SetBkMode(dc
, TRANSPARENT
);
338 if(uFlags
& DFCS_INACTIVE
)
341 SetTextColor(dc
, scheme
->crColor
[COLOR_BTNHIGHLIGHT
]);
342 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
344 SetTextColor(dc
, scheme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
345 /* Draw selected symbol */
346 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
347 /* restore previous settings */
348 SetTextColor(dc
, clrsave
);
349 SelectObject(dc
, hOldFont
);
350 SetBkMode(dc
, bkmode
);
356 MyDrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
, COLOR_SCHEME
*scheme
)
361 return MyDrawFrameButton(hDC
, rc
, uState
, scheme
);
363 return MyDrawFrameCaption(hDC
, rc
, uState
, scheme
);
365 return MyDrawFrameScroll(hDC
, rc
, uState
, scheme
);
371 MyDrawEdge(HDC hDC
, LPRECT rc
, UINT edge
, UINT flags
, COLOR_SCHEME
*scheme
)
373 return MyIntDrawRectEdge(hDC
, rc
, edge
, flags
, scheme
);
377 MyDrawCaptionButtons(HDC hdc
, LPRECT lpRect
, BOOL bMinMax
, int x
, COLOR_SCHEME
*scheme
)
383 rc3
.left
= lpRect
->right
- 2 - x
;
384 rc3
.top
= lpRect
->top
+ 2;
385 rc3
.right
= lpRect
->right
- 2;
386 rc3
.bottom
= lpRect
->bottom
- 2;
388 MyDrawFrameControl(hdc
, &rc3
, DFC_CAPTION
, DFCS_CAPTIONCLOSE
, scheme
);
392 rc4
.left
= rc3
.left
- x
- 2;
394 rc4
.right
= rc3
.right
- x
- 2;
395 rc4
.bottom
= rc3
.bottom
;
397 MyDrawFrameControl(hdc
, &rc4
, DFC_CAPTION
, DFCS_CAPTIONMAX
, scheme
);
399 rc5
.left
= rc4
.left
- x
;
401 rc5
.right
= rc4
.right
- x
;
402 rc5
.bottom
= rc4
.bottom
;
404 MyDrawFrameControl(hdc
, &rc5
, DFC_CAPTION
, DFCS_CAPTIONMIN
, scheme
);
409 MyDrawScrollbar(HDC hdc
, LPRECT rc
, HBRUSH hbrScrollbar
, COLOR_SCHEME
*scheme
)
416 width
= rc
->right
- rc
->left
;
418 rcTop
.left
= rc
->left
;
419 rcTop
.right
= rc
->right
;
421 rcTop
.bottom
= rc
->top
+ width
;
423 rcMiddle
.left
= rc
->left
;
424 rcMiddle
.right
= rc
->right
;
425 rcMiddle
.top
= rc
->top
+ width
;
426 rcMiddle
.bottom
= rc
->bottom
- width
;
428 rcBottom
.left
= rc
->left
;
429 rcBottom
.right
= rc
->right
;
430 rcBottom
.top
= rc
->bottom
- width
;
431 rcBottom
.bottom
= rc
->bottom
;
433 MyDrawFrameControl(hdc
, &rcTop
, DFC_SCROLL
, DFCS_SCROLLUP
, scheme
);
434 MyDrawFrameControl(hdc
, &rcBottom
, DFC_SCROLL
, DFCS_SCROLLDOWN
, scheme
);
436 FillRect(hdc
, &rcMiddle
, hbrScrollbar
);
439 /******************************************************************************/
442 MyDrawCaptionTemp(HWND hwnd
, HDC hdc
, const RECT
*rect
, HFONT hFont
, HICON hIcon
, LPCWSTR str
, UINT uFlags
, COLOR_SCHEME
*scheme
)
445 //UINT VCenter, Padding;
451 //Height = scheme->Size[SIZE_CAPTION_Y] - 1;
452 //VCenter = (rect->bottom - rect->top) / 2;
453 //Padding = VCenter - (Height / 2);
455 //ButtonWidth = scheme->Size[SIZE_SIZE_X] - 2;
457 if (uFlags
& DC_GRADIENT
)
459 GRADIENT_RECT gcap
= {0, 1};
463 Colors
[0] = scheme
->crColor
[((uFlags
& DC_ACTIVE
) ?
464 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
)];
465 Colors
[1] = scheme
->crColor
[((uFlags
& DC_ACTIVE
) ?
466 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
)];
468 vert
[0].x
= rect
->left
;
469 vert
[0].y
= rect
->top
;
470 vert
[0].Red
= (WORD
)Colors
[0]<<8;
471 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
472 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
475 vert
[1].x
= rect
->right
;
476 vert
[1].y
= rect
->bottom
;
477 vert
[1].Red
= (WORD
)Colors
[1]<<8;
478 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
479 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
482 GdiGradientFill(hdc
, vert
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
);
486 if (uFlags
& DC_ACTIVE
)
487 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_ACTIVECAPTION
]);
489 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_INACTIVECAPTION
]);
490 FillRect(hdc
, rect
, hbr
);
494 hFontOld
= SelectObject(hdc
, hFont
);
495 SetBkMode(hdc
, TRANSPARENT
);
496 if (uFlags
& DC_ACTIVE
)
497 SetTextColor(hdc
, scheme
->crColor
[COLOR_CAPTIONTEXT
]);
499 SetTextColor(hdc
, scheme
->crColor
[COLOR_INACTIVECAPTIONTEXT
]);
500 rc
.left
= rect
->left
+ 2;
502 rc
.right
= rect
->right
;
503 rc
.bottom
= rect
->bottom
;
504 DrawTextW(hdc
, str
, -1, &rc
, DT_SINGLELINE
| DT_VCENTER
);
505 SelectObject(hdc
, hFontOld
);
509 /******************************************************************************/
512 MyDrawMenuBarTemp(HWND Wnd
, HDC DC
, LPRECT Rect
, HMENU Menu
, HFONT Font
, COLOR_SCHEME
*scheme
)
516 HGDIOBJ hPenOld
, hFontOld
;
521 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
523 flat_menu
= scheme
->bFlatMenus
;
526 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENUBAR
]);
528 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENU
]);
529 FillRect(DC
, Rect
, hbr
);
532 hPen
= CreatePen(PS_SOLID
, 0, scheme
->crColor
[COLOR_3DFACE
]);
533 hPenOld
= SelectObject(DC
, hPen
);
534 MoveToEx(DC
, Rect
->left
, Rect
->bottom
- 1, NULL
);
535 LineTo(DC
, Rect
->right
, Rect
->bottom
- 1);
536 SelectObject(DC
, hPenOld
);
539 bkgnd
= (flat_menu
? COLOR_MENUBAR
: COLOR_MENU
);
541 hFontOld
= SelectObject(DC
, Font
);
542 for(i
= 0; i
< 3; i
++)
544 GetMenuStringW(Menu
, i
, Text
, 128, MF_BYPOSITION
);
546 rect
.left
= rect
.right
= x
;
547 rect
.top
= Rect
->top
;
548 rect
.bottom
= Rect
->bottom
;
549 DrawTextW(DC
, Text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
550 rect
.bottom
= Rect
->bottom
;
551 rect
.right
+= MENU_BAR_ITEMS_SPACE
;
552 x
+= rect
.right
- rect
.left
;
558 SetTextColor(DC
, scheme
->crColor
[COLOR_HIGHLIGHTTEXT
]);
559 SetBkColor(DC
, scheme
->crColor
[COLOR_HIGHLIGHT
]);
561 InflateRect (&rect
, -1, -1);
562 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_MENUHILIGHT
]);
563 FillRect(DC
, &rect
, hbr
);
566 InflateRect (&rect
, 1, 1);
567 hbr
= CreateSolidBrush(scheme
->crColor
[COLOR_HIGHLIGHT
]);
568 FrameRect(DC
, &rect
, hbr
);
573 SetTextColor(DC
, scheme
->crColor
[COLOR_MENUTEXT
]);
574 SetBkColor(DC
, scheme
->crColor
[COLOR_MENU
]);
575 DrawEdge(DC
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
581 SetTextColor(DC
, scheme
->crColor
[COLOR_GRAYTEXT
]);
583 SetTextColor(DC
, scheme
->crColor
[COLOR_MENUTEXT
]);
585 SetBkColor(DC
, scheme
->crColor
[bkgnd
]);
586 hbr
= CreateSolidBrush(scheme
->crColor
[bkgnd
]);
587 FillRect(DC
, &rect
, hbr
);
591 SetBkMode(DC
, TRANSPARENT
);
593 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
594 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
598 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
599 SetTextColor(DC
, RGB(0xff, 0xff, 0xff));
600 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
601 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
602 SetTextColor(DC
, RGB(0x80, 0x80, 0x80));
604 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
606 SelectObject(DC
, hFontOld
);