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>
10 /* #define NTOS_MODE_USER */
11 /* #define WIN32_NO_STATUS */
15 /* #include <ndk/ntndk.h> */
16 /* #include <win32k/ntuser.h> */
18 /******************************************************************************/
20 static const signed char LTInnerNormal
[] = {
22 -1, COLOR_BTNHIGHLIGHT
, COLOR_BTNHIGHLIGHT
, -1,
23 -1, COLOR_3DDKSHADOW
, COLOR_3DDKSHADOW
, -1,
27 static const signed char LTOuterNormal
[] = {
28 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
29 COLOR_BTNHIGHLIGHT
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
30 COLOR_3DDKSHADOW
, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1,
31 -1, COLOR_3DLIGHT
, COLOR_BTNSHADOW
, -1
34 static const signed char RBInnerNormal
[] = {
36 -1, COLOR_BTNSHADOW
, COLOR_BTNSHADOW
, -1,
37 -1, COLOR_3DLIGHT
, COLOR_3DLIGHT
, -1,
41 static const signed char RBOuterNormal
[] = {
42 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
43 COLOR_BTNSHADOW
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
44 COLOR_3DLIGHT
, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1,
45 -1, COLOR_3DDKSHADOW
, COLOR_BTNHIGHLIGHT
, -1
49 MyIntDrawRectEdge(HDC hdc
, LPRECT rc
, UINT uType
, UINT uFlags
, THEME
*theme
)
51 signed char LTInnerI
, LTOuterI
;
52 signed char RBInnerI
, RBOuterI
;
53 HPEN LTInnerPen
, LTOuterPen
;
54 HPEN RBInnerPen
, RBOuterPen
;
63 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= (HPEN
)GetStockObject(NULL_PEN
);
64 SavePen
= (HPEN
)SelectObject(hdc
, LTInnerPen
);
66 /* Determine the colors of the edges */
67 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
68 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
69 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
70 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
72 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
)
74 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
)
76 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
)
78 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
)
82 LTInnerPen
= GetStockObject(DC_PEN
);
84 LTOuterPen
= GetStockObject(DC_PEN
);
86 RBInnerPen
= GetStockObject(DC_PEN
);
88 RBOuterPen
= GetStockObject(DC_PEN
);
91 hbr
= CreateSolidBrush(theme
->crColor
[COLOR_BTNFACE
]);
92 FillRect(hdc
, &InnerRect
, hbr
);
95 MoveToEx(hdc
, 0, 0, &SavePoint
);
97 /* Draw the outer edge */
98 SelectObject(hdc
, LTOuterPen
);
99 SetDCPenColor(hdc
, theme
->crColor
[LTOuterI
]);
102 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
103 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
107 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
108 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
110 SelectObject(hdc
, RBOuterPen
);
111 SetDCPenColor(hdc
, theme
->crColor
[RBOuterI
]);
112 if(uFlags
& BF_BOTTOM
)
114 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.bottom
-1, NULL
);
115 LineTo(hdc
, InnerRect
.right
, InnerRect
.bottom
-1);
117 if(uFlags
& BF_RIGHT
)
119 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.top
, NULL
);
120 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.bottom
);
123 /* Draw the inner edge */
124 SelectObject(hdc
, LTInnerPen
);
125 SetDCPenColor(hdc
, theme
->crColor
[LTInnerI
]);
128 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
129 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
133 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
134 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
136 SelectObject(hdc
, RBInnerPen
);
137 SetDCPenColor(hdc
, theme
->crColor
[RBInnerI
]);
138 if(uFlags
& BF_BOTTOM
)
140 MoveToEx(hdc
, InnerRect
.left
+LBpenplus
, InnerRect
.bottom
-2, NULL
);
141 LineTo(hdc
, InnerRect
.right
-RBpenplus
, InnerRect
.bottom
-2);
143 if(uFlags
& BF_RIGHT
)
145 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.top
+RTpenplus
, NULL
);
146 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-RBpenplus
);
150 SelectObject(hdc
, SavePen
);
151 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
156 MyDrawFrameButton(HDC hdc
, LPRECT rc
, UINT uState
, THEME
*theme
)
159 if(uState
& (DFCS_PUSHED
| DFCS_CHECKED
| DFCS_FLAT
))
163 return MyIntDrawRectEdge(hdc
, rc
, edge
, (uState
& DFCS_FLAT
) | BF_RECT
| BF_SOFT
, theme
);
167 MyMakeSquareRect(LPRECT src
, LPRECT dst
)
169 int Width
= src
->right
- src
->left
;
170 int Height
= src
->bottom
- src
->top
;
171 int SmallDiam
= Width
> Height
? Height
: Width
;
175 /* Make it a square box */
176 if (Width
< Height
) /* SmallDiam == Width */
178 dst
->top
+= (Height
-Width
)/2;
179 dst
->bottom
= dst
->top
+ SmallDiam
;
181 else if(Width
> Height
) /* SmallDiam == Height */
183 dst
->left
+= (Width
-Height
)/2;
184 dst
->right
= dst
->left
+ SmallDiam
;
191 MyDrawFrameCaption(HDC dc
, LPRECT r
, UINT uFlags
, THEME
*theme
)
194 HFONT hFont
, hOldFont
;
199 switch(uFlags
& 0xff)
201 case DFCS_CAPTIONCLOSE
:
204 case DFCS_CAPTIONHELP
:
207 case DFCS_CAPTIONMIN
:
210 case DFCS_CAPTIONMAX
:
213 case DFCS_CAPTIONRESTORE
:
217 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, BF_RECT
| BF_MIDDLE
| BF_SOFT
, theme
);
218 ZeroMemory(&lf
, sizeof(LOGFONT
));
219 MyMakeSquareRect(r
, &myr
);
224 if(uFlags
& DFCS_PUSHED
)
225 OffsetRect(&myr
,1,1);
226 lf
.lfHeight
= myr
.bottom
- myr
.top
;
228 lf
.lfWeight
= FW_NORMAL
;
229 lf
.lfCharSet
= DEFAULT_CHARSET
;
230 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
231 hFont
= CreateFontIndirect(&lf
);
232 /* save font and text color */
233 hOldFont
= SelectObject(dc
, hFont
);
234 clrsave
= GetTextColor(dc
);
235 bkmode
= GetBkMode(dc
);
236 /* set color and drawing mode */
237 SetBkMode(dc
, TRANSPARENT
);
238 if(uFlags
& DFCS_INACTIVE
)
241 SetTextColor(dc
, theme
->crColor
[COLOR_BTNHIGHLIGHT
]);
242 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
244 SetTextColor(dc
, theme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
245 /* draw selected symbol */
246 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
247 /* restore previous settings */
248 SetTextColor(dc
, clrsave
);
249 SelectObject(dc
, hOldFont
);
250 SetBkMode(dc
, bkmode
);
255 /******************************************************************************/
258 MyDrawFrameScroll(HDC dc
, LPRECT r
, UINT uFlags
, THEME
*theme
)
261 HFONT hFont
, hOldFont
;
266 switch(uFlags
& 0xff)
268 case DFCS_SCROLLCOMBOBOX
:
269 case DFCS_SCROLLDOWN
:
277 case DFCS_SCROLLLEFT
:
281 case DFCS_SCROLLRIGHT
:
285 MyIntDrawRectEdge(dc
, r
, (uFlags
& DFCS_PUSHED
) ? EDGE_SUNKEN
: EDGE_RAISED
, (uFlags
&DFCS_FLAT
) | BF_MIDDLE
| BF_RECT
, theme
);
286 ZeroMemory(&lf
, sizeof(LOGFONT
));
287 MyMakeSquareRect(r
, &myr
);
292 if(uFlags
& DFCS_PUSHED
)
293 OffsetRect(&myr
,1,1);
294 lf
.lfHeight
= myr
.bottom
- myr
.top
;
296 lf
.lfWeight
= FW_NORMAL
;
297 lf
.lfCharSet
= DEFAULT_CHARSET
;
298 lstrcpy(lf
.lfFaceName
, TEXT("Marlett"));
299 hFont
= CreateFontIndirect(&lf
);
300 /* save font and text color */
301 hOldFont
= SelectObject(dc
, hFont
);
302 clrsave
= GetTextColor(dc
);
303 bkmode
= GetBkMode(dc
);
304 /* set color and drawing mode */
305 SetBkMode(dc
, TRANSPARENT
);
306 if(uFlags
& DFCS_INACTIVE
)
309 SetTextColor(dc
, theme
->crColor
[COLOR_BTNHIGHLIGHT
]);
310 TextOut(dc
, myr
.left
+ 1, myr
.top
+ 1, &Symbol
, 1);
312 SetTextColor(dc
, theme
->crColor
[(uFlags
& DFCS_INACTIVE
) ? COLOR_BTNSHADOW
: COLOR_BTNTEXT
]);
313 /* draw selected symbol */
314 TextOut(dc
, myr
.left
, myr
.top
, &Symbol
, 1);
315 /* restore previous settings */
316 SetTextColor(dc
, clrsave
);
317 SelectObject(dc
, hOldFont
);
318 SetBkMode(dc
, bkmode
);
324 MyDrawFrameControl(HDC hDC
, LPRECT rc
, UINT uType
, UINT uState
, THEME
*theme
)
329 return MyDrawFrameButton(hDC
, rc
, uState
, theme
);
331 return MyDrawFrameCaption(hDC
, rc
, uState
, theme
);
333 return MyDrawFrameScroll(hDC
, rc
, uState
, theme
);
339 MyDrawEdge(HDC hDC
, LPRECT rc
, UINT edge
, UINT flags
, THEME
*theme
)
341 return MyIntDrawRectEdge(hDC
, rc
, edge
, flags
, theme
);
345 MyDrawCaptionButtons(HDC hdc
, LPRECT lpRect
, BOOL bMinMax
, int x
, THEME
*theme
)
351 rc3
.left
= lpRect
->right
- 2 - x
;
352 rc3
.top
= lpRect
->top
+ 2;
353 rc3
.right
= lpRect
->right
- 2;
354 rc3
.bottom
= lpRect
->bottom
- 2;
356 MyDrawFrameControl(hdc
, &rc3
, DFC_CAPTION
, DFCS_CAPTIONCLOSE
, theme
);
360 rc4
.left
= rc3
.left
- x
- 2;
362 rc4
.right
= rc3
.right
- x
- 2;
363 rc4
.bottom
= rc3
.bottom
;
365 MyDrawFrameControl(hdc
, &rc4
, DFC_CAPTION
, DFCS_CAPTIONMAX
, theme
);
367 rc5
.left
= rc4
.left
- x
;
369 rc5
.right
= rc4
.right
- x
;
370 rc5
.bottom
= rc4
.bottom
;
372 MyDrawFrameControl(hdc
, &rc5
, DFC_CAPTION
, DFCS_CAPTIONMIN
, theme
);
377 MyDrawScrollbar(HDC hdc
, LPRECT rc
, HBRUSH hbrScrollbar
, THEME
*theme
)
384 width
= rc
->right
- rc
->left
;
386 rcTop
.left
= rc
->left
;
387 rcTop
.right
= rc
->right
;
389 rcTop
.bottom
= rc
->top
+ width
;
391 rcMiddle
.left
= rc
->left
;
392 rcMiddle
.right
= rc
->right
;
393 rcMiddle
.top
= rc
->top
+ width
;
394 rcMiddle
.bottom
= rc
->bottom
- width
;
396 rcBottom
.left
= rc
->left
;
397 rcBottom
.right
= rc
->right
;
398 rcBottom
.top
= rc
->bottom
- width
;
399 rcBottom
.bottom
= rc
->bottom
;
401 MyDrawFrameControl(hdc
, &rcTop
, DFC_SCROLL
, DFCS_SCROLLUP
, theme
);
402 MyDrawFrameControl(hdc
, &rcBottom
, DFC_SCROLL
, DFCS_SCROLLDOWN
, theme
);
404 FillRect(hdc
, &rcMiddle
, hbrScrollbar
);
407 /******************************************************************************/
410 MyDrawCaptionTemp(HWND hwnd
, HDC hdc
, const RECT
*rect
, HFONT hFont
, HICON hIcon
, LPCWSTR str
, UINT uFlags
, THEME
*theme
)
413 return DrawCaptionTemp(hwnd
, hdc
, rect
, hFont
, hIcon
, str
, uFlags
);
416 /******************************************************************************/
419 MyDrawMenuBarTemp(HWND Wnd
, HDC DC
, LPRECT Rect
, HMENU Menu
, HFONT Font
, THEME
*theme
)
422 return DrawMenuBarTemp(Wnd
, DC
, Rect
, Menu
, Font
);