2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: lib/cpl/desk/draw.c
5 * PURPOSE: Providing drawing functions
7 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
14 #define MENU_BAR_ITEMS_SPACE (12)
16 /******************************************************************************/
18 static const signed char LTInnerNormal
[] = {
20 -1, COLOR_BTNHIGHLIGHT
, COLOR_BTNHIGHLIGHT
, -1,
21 -1, COLOR_3DDKSHADOW
, COLOR_3DDKSHADOW
, -1,
25 static const signed char LTOuterNormal
[] = {
26 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
27 COLOR_BTNHIGHLIGHT
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
28 COLOR_3DDKSHADOW
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
29 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1
32 static const signed char RBInnerNormal
[] = {
34 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, -1,
35 -1, COLOR_3DLIGHT
, COLOR_3DLIGHT
, -1,
39 static const signed char RBOuterNormal
[] = {
40 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
41 COLOR_BTNSHADOW
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
42 COLOR_3DLIGHT
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
43 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1
46 static const signed char LTRBOuterMono
[] = {
47 -1, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
48 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
49 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
50 COLOR_WINDOW
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
, COLOR_WINDOWFRAME
,
53 static const signed char LTRBInnerMono
[] = {
55 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
56 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
57 -1, COLOR_WINDOW
, COLOR_WINDOW
, COLOR_WINDOW
,
61 MyIntDrawRectEdge(HDC hdc
, LPRECT rc
, UINT uType
, UINT uFlags
, THEME
*theme
)
63 signed char LTInnerI
, LTOuterI
;
64 signed char RBInnerI
, RBOuterI
;
65 HPEN LTInnerPen
, LTOuterPen
;
66 HPEN RBInnerPen
, RBOuterPen
;
75 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= (HPEN
)GetStockObject(NULL_PEN
);
76 SavePen
= (HPEN
)SelectObject(hdc
, LTInnerPen
);
78 /* Determine the colors of the edges */
79 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
80 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
81 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
82 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
84 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
)
86 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
)
88 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
)
90 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
)
94 LTInnerPen
= GetStockObject(DC_PEN
);
96 LTOuterPen
= GetStockObject(DC_PEN
);
98 RBInnerPen
= GetStockObject(DC_PEN
);
100 RBOuterPen
= GetStockObject(DC_PEN
);
103 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_BTNFACE
]);
104 FillRect(hdc
, &InnerRect
, hbr
);
107 MoveToEx(hdc
, 0, 0, &SavePoint
);
109 /* Draw the outer edge */
110 SelectObject(hdc
, LTOuterPen
);
111 SetDCPenColor(hdc
, theme
->crColor
[LTOuterI
]);
114 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
115 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
119 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
120 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
122 SelectObject(hdc
, RBOuterPen
);
123 SetDCPenColor(hdc
, theme
->crColor
[RBOuterI
]);
124 if(uFlags
& BF_BOTTOM
)
126 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.bottom
-1, NULL
);
127 LineTo(hdc
, InnerRect
.right
, InnerRect
.bottom
-1);
129 if(uFlags
& BF_RIGHT
)
131 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.top
, NULL
);
132 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.bottom
);
135 /* Draw the inner edge */
136 SelectObject(hdc
, LTInnerPen
);
137 SetDCPenColor(hdc
, theme
->crColor
[LTInnerI
]);
140 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
141 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
145 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
146 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
148 SelectObject(hdc
, RBInnerPen
);
149 SetDCPenColor(hdc
, theme
->crColor
[RBInnerI
]);
150 if(uFlags
& BF_BOTTOM
)
152 MoveToEx(hdc
, InnerRect
.left
+LBpenplus
, InnerRect
.bottom
-2, NULL
);
153 LineTo(hdc
, InnerRect
.right
-RBpenplus
, InnerRect
.bottom
-2);
155 if(uFlags
& BF_RIGHT
)
157 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.top
+RTpenplus
, NULL
);
158 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-RBpenplus
);
161 if (uFlags
& BF_ADJUST
)
163 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
164 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
167 InnerRect
.left
+= add
;
168 if(uFlags
& BF_RIGHT
)
169 InnerRect
.right
-= add
;
171 InnerRect
.top
+= add
;
172 if(uFlags
& BF_BOTTOM
)
173 InnerRect
.bottom
-= add
;
175 if(uFlags
& BF_ADJUST
)
180 SelectObject(hdc
, SavePen
);
181 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
186 MyDrawFrameButton(HDC hdc
, LPRECT rc
, UINT uState
, THEME
*theme
)
189 if(uState
& (DFCS_PUSHED
| DFCS_CHECKED
| DFCS_FLAT
))
193 return MyIntDrawRectEdge(hdc
, rc
, edge
, (uState
& DFCS_FLAT
) | BF_RECT
| BF_SOFT
, theme
);
197 MyMakeSquareRect(LPRECT src
, LPRECT dst
)
199 int Width
= src
->right
- src
->left
;
200 int Height
= src
->bottom
- src
->top
;
201 int SmallDiam
= Width
> Height
? Height
: Width
;
205 /* Make it a square box */
206 if (Width
< Height
) /* SmallDiam == Width */
208 dst
->top
+= (Height
-Width
)/2;
209 dst
->bottom
= dst
->top
+ SmallDiam
;
211 else if(Width
> Height
) /* SmallDiam == Height */
213 dst
->left
+= (Width
-Height
)/2;
214 dst
->right
= dst
->left
+ SmallDiam
;
221 MyDrawFrameCaption(HDC dc
, LPRECT r
, UINT uFlags
, THEME
*theme
)
224 HFONT hFont
, hOldFont
;
229 switch(uFlags
& 0xff)
231 case DFCS_CAPTIONCLOSE
:
234 case DFCS_CAPTIONHELP
:
237 case DFCS_CAPTIONMIN
:
240 case DFCS_CAPTIONMAX
:
243 case DFCS_CAPTIONRESTORE
:
247 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, BF_RECT
| BF_MIDDLE
| BF_SOFT
, theme
);
248 ZeroMemory(&lf
, sizeof(LOGFONT
));
249 MyMakeSquareRect(r
, &myr
);
254 if(uFlags
& DFCS_PUSHED
)
255 OffsetRect(&myr
,1,1);
256 lf
.lfHeight
= myr
.bottom
- myr
.top
;
258 lf
.lfWeight
= FW_NORMAL
;
259 lf
.lfCharSet
= DEFAULT_CHARSET
;
260 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
261 hFont
= CreateFontIndirect(&lf
);
262 /* save font and text color */
263 hOldFont
= SelectObject(dc
, hFont
);
264 clrsave
= GetTextColor(dc
);
265 bkmode
= GetBkMode(dc
);
266 /* set color and drawing mode */
267 SetBkMode(dc
, TRANSPARENT
);
268 if(uFlags
& DFCS_INACTIVE
)
271 SetTextColor(dc
, theme
->crColor
[COLOR_BTNHIGHLIGHT
]);
272 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
274 SetTextColor(dc
, theme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
275 /* draw selected symbol */
276 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
277 /* restore previous settings */
278 SetTextColor(dc
, clrsave
);
279 SelectObject(dc
, hOldFont
);
280 SetBkMode(dc
, bkmode
);
285 /******************************************************************************/
288 MyDrawFrameScroll(HDC dc
, LPRECT r
, UINT uFlags
, THEME
*theme
)
291 HFONT hFont
, hOldFont
;
296 switch(uFlags
& 0xff)
298 case DFCS_SCROLLCOMBOBOX
:
299 case DFCS_SCROLLDOWN
:
307 case DFCS_SCROLLLEFT
:
311 case DFCS_SCROLLRIGHT
:
315 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
, theme
);
316 ZeroMemory(&lf
, sizeof(LOGFONT
));
317 MyMakeSquareRect(r
, &myr
);
322 if(uFlags
& DFCS_PUSHED
)
323 OffsetRect(&myr
,1,1);
324 lf
.lfHeight
= myr
.bottom
- myr
.top
;
326 lf
.lfWeight
= FW_NORMAL
;
327 lf
.lfCharSet
= DEFAULT_CHARSET
;
328 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
329 hFont
= CreateFontIndirect(&lf
);
330 /* save font and text color */
331 hOldFont
= SelectObject(dc
, hFont
);
332 clrsave
= GetTextColor(dc
);
333 bkmode
= GetBkMode(dc
);
334 /* set color and drawing mode */
335 SetBkMode(dc
, TRANSPARENT
);
336 if(uFlags
& DFCS_INACTIVE
)
339 SetTextColor(dc
, theme
->crColor
[COLOR_BTNHIGHLIGHT
]);
340 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
342 SetTextColor(dc
, theme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
343 /* draw selected symbol */
344 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
345 /* restore previous settings */
346 SetTextColor(dc
, clrsave
);
347 SelectObject(dc
, hOldFont
);
348 SetBkMode(dc
, bkmode
);
354 MyDrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
, THEME
*theme
)
359 return MyDrawFrameButton(hDC
, rc
, uState
, theme
);
361 return MyDrawFrameCaption(hDC
, rc
, uState
, theme
);
363 return MyDrawFrameScroll(hDC
, rc
, uState
, theme
);
369 MyDrawEdge(HDC hDC
, LPRECT rc
, UINT edge
, UINT flags
, THEME
*theme
)
371 return MyIntDrawRectEdge(hDC
, rc
, edge
, flags
, theme
);
375 MyDrawCaptionButtons(HDC hdc
, LPRECT lpRect
, BOOL bMinMax
, int x
, THEME
*theme
)
381 rc3
.left
= lpRect
->right
- 2 - x
;
382 rc3
.top
= lpRect
->top
+ 2;
383 rc3
.right
= lpRect
->right
- 2;
384 rc3
.bottom
= lpRect
->bottom
- 2;
386 MyDrawFrameControl(hdc
, &rc3
, DFC_CAPTION
, DFCS_CAPTIONCLOSE
, theme
);
390 rc4
.left
= rc3
.left
- x
- 2;
392 rc4
.right
= rc3
.right
- x
- 2;
393 rc4
.bottom
= rc3
.bottom
;
395 MyDrawFrameControl(hdc
, &rc4
, DFC_CAPTION
, DFCS_CAPTIONMAX
, theme
);
397 rc5
.left
= rc4
.left
- x
;
399 rc5
.right
= rc4
.right
- x
;
400 rc5
.bottom
= rc4
.bottom
;
402 MyDrawFrameControl(hdc
, &rc5
, DFC_CAPTION
, DFCS_CAPTIONMIN
, theme
);
407 MyDrawScrollbar(HDC hdc
, LPRECT rc
, HBRUSH hbrScrollbar
, THEME
*theme
)
414 width
= rc
->right
- rc
->left
;
416 rcTop
.left
= rc
->left
;
417 rcTop
.right
= rc
->right
;
419 rcTop
.bottom
= rc
->top
+ width
;
421 rcMiddle
.left
= rc
->left
;
422 rcMiddle
.right
= rc
->right
;
423 rcMiddle
.top
= rc
->top
+ width
;
424 rcMiddle
.bottom
= rc
->bottom
- width
;
426 rcBottom
.left
= rc
->left
;
427 rcBottom
.right
= rc
->right
;
428 rcBottom
.top
= rc
->bottom
- width
;
429 rcBottom
.bottom
= rc
->bottom
;
431 MyDrawFrameControl(hdc
, &rcTop
, DFC_SCROLL
, DFCS_SCROLLUP
, theme
);
432 MyDrawFrameControl(hdc
, &rcBottom
, DFC_SCROLL
, DFCS_SCROLLDOWN
, theme
);
434 FillRect(hdc
, &rcMiddle
, hbrScrollbar
);
437 /******************************************************************************/
440 MyDrawCaptionTemp(HWND hwnd
, HDC hdc
, const RECT
*rect
, HFONT hFont
, HICON hIcon
, LPCWSTR str
, UINT uFlags
, THEME
*theme
)
443 UINT VCenter
, Padding
;
449 Height
= theme
->Size
[SIZE_CAPTION_Y
] - 1;
450 VCenter
= (rect
->bottom
- rect
->top
) / 2;
451 Padding
= VCenter
- (Height
/ 2);
453 ButtonWidth
= theme
->Size
[SIZE_SIZE_X
] - 2;
455 if (uFlags
& DC_GRADIENT
)
457 GRADIENT_RECT gcap
= {0, 1};
461 Colors
[0] = theme
->crColor
[((uFlags
& DC_ACTIVE
) ?
462 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
)];
463 Colors
[1] = theme
->crColor
[((uFlags
& DC_ACTIVE
) ?
464 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
)];
466 vert
[0].x
= rect
->left
;
467 vert
[0].y
= rect
->top
;
468 vert
[0].Red
= (WORD
)Colors
[0]<<8;
469 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
470 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
473 vert
[1].x
= rect
->right
;
474 vert
[1].y
= rect
->bottom
;
475 vert
[1].Red
= (WORD
)Colors
[1]<<8;
476 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
477 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
480 GradientFill(hdc
, vert
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
);
484 if (uFlags
& DC_ACTIVE
)
485 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_ACTIVECAPTION
]);
487 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_INACTIVECAPTION
]);
488 FillRect(hdc
, rect
, hbr
);
492 hFontOld
= SelectObject(hdc
, hFont
);
493 SetBkMode(hdc
, TRANSPARENT
);
494 if (uFlags
& DC_ACTIVE
)
495 SetTextColor(hdc
, theme
->crColor
[COLOR_CAPTIONTEXT
]);
497 SetTextColor(hdc
, theme
->crColor
[COLOR_INACTIVECAPTIONTEXT
]);
498 rc
.left
= rect
->left
+ 2;
500 rc
.right
= rect
->right
;
501 rc
.bottom
= rect
->bottom
;
502 DrawTextW(hdc
, str
, -1, &rc
, DT_SINGLELINE
| DT_VCENTER
);
503 SelectObject(hdc
, hFontOld
);
507 /******************************************************************************/
510 MyDrawMenuBarTemp(HWND Wnd
, HDC DC
, LPRECT Rect
, HMENU Menu
, HFONT Font
, THEME
*theme
)
514 HGDIOBJ hPenOld
, hFontOld
;
519 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
521 flat_menu
= theme
->bFlatMenus
;
524 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_MENUBAR
]);
526 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_MENU
]);
527 FillRect(DC
, Rect
, hbr
);
530 hPen
= CreatePen(PS_SOLID
, 0, theme
->crColor
[COLOR_3DFACE
]);
531 hPenOld
= SelectObject(DC
, hPen
);
532 MoveToEx(DC
, Rect
->left
, Rect
->bottom
- 1, NULL
);
533 LineTo(DC
, Rect
->right
, Rect
->bottom
- 1);
534 SelectObject(DC
, hPenOld
);
537 bkgnd
= (flat_menu
? COLOR_MENUBAR
: COLOR_MENU
);
539 hFontOld
= SelectObject(DC
, Font
);
540 for(i
= 0; i
< 3; i
++)
542 GetMenuStringW(Menu
, i
, Text
, 128, MF_BYPOSITION
);
544 rect
.left
= rect
.right
= x
;
545 rect
.top
= Rect
->top
;
546 rect
.bottom
= Rect
->bottom
;
547 DrawTextW(DC
, Text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
548 rect
.bottom
= Rect
->bottom
;
549 rect
.right
+= MENU_BAR_ITEMS_SPACE
;
550 x
+= rect
.right
- rect
.left
;
556 SetTextColor(DC
, theme
->crColor
[COLOR_HIGHLIGHTTEXT
]);
557 SetBkColor(DC
, theme
->crColor
[COLOR_HIGHLIGHT
]);
559 InflateRect (&rect
, -1, -1);
560 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_MENUHILIGHT
]);
561 FillRect(DC
, &rect
, hbr
);
564 InflateRect (&rect
, 1, 1);
565 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_HIGHLIGHT
]);
566 FrameRect(DC
, &rect
, hbr
);
571 SetTextColor(DC
, theme
->crColor
[COLOR_MENUTEXT
]);
572 SetBkColor(DC
, theme
->crColor
[COLOR_MENU
]);
573 DrawEdge(DC
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
579 SetTextColor(DC
, theme
->crColor
[COLOR_GRAYTEXT
]);
581 SetTextColor(DC
, theme
->crColor
[COLOR_MENUTEXT
]);
583 SetBkColor(DC
, theme
->crColor
[bkgnd
]);
584 hbr
= CreateSolidBrush(theme
->crColor
[bkgnd
]);
585 FillRect(DC
, &rect
, hbr
);
589 SetBkMode(DC
, TRANSPARENT
);
591 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
592 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
596 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
597 SetTextColor(DC
, RGB(0xff, 0xff, 0xff));
598 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
599 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
600 SetTextColor(DC
, RGB(0x80, 0x80, 0x80));
602 DrawTextW(DC
, Text
, -1, &rect
, uFormat
);
604 SelectObject(DC
, hFontOld
);