2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS uxtheme.dll
4 * FILE: dll/win32/uxtheme/nonclient.c
5 * PURPOSE: uxtheme non client area management
6 * PROGRAMMER: Giannis Adamopoulos
11 HFONT hMenuFont
= NULL
;
12 HFONT hMenuFontBold
= NULL
;
14 void InitMenuFont(VOID
)
18 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
20 if (!SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0))
25 hMenuFont
= CreateFontIndirect(&ncm
.lfMenuFont
);
27 ncm
.lfMenuFont
.lfWeight
= max(ncm
.lfMenuFont
.lfWeight
+ 300, 1000);
28 hMenuFontBold
= CreateFontIndirect(&ncm
.lfMenuFont
);
32 IsWindowActive(HWND hWnd
, DWORD ExStyle
)
36 if (ExStyle
& WS_EX_MDICHILD
)
38 ret
= IsChild(GetForegroundWindow(), hWnd
);
40 ret
= (hWnd
== (HWND
)SendMessageW(GetParent(hWnd
), WM_MDIGETACTIVE
, 0, 0));
44 ret
= (GetForegroundWindow() == hWnd
);
51 UserHasWindowEdge(DWORD Style
, DWORD ExStyle
)
53 if (Style
& WS_MINIMIZE
)
55 if (ExStyle
& WS_EX_DLGMODALFRAME
)
57 if (ExStyle
& WS_EX_STATICEDGE
)
59 if (Style
& WS_THICKFRAME
)
61 if (Style
== WS_DLGFRAME
|| Style
== WS_CAPTION
)
67 UserGetWindowIcon(PDRAW_CONTEXT pcontext
)
71 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_SMALL2
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
74 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_SMALL
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
77 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_BIG
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
80 hIcon
= (HICON
)GetClassLong(pcontext
->hWnd
, GCL_HICONSM
);
83 hIcon
= (HICON
)GetClassLong(pcontext
->hWnd
, GCL_HICON
);
85 // See also win32ss/user/ntuser/nonclient.c!NC_IconForWindow
86 if (!hIcon
&& !(pcontext
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
87 hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
92 WCHAR
*UserGetWindowCaption(HWND hwnd
)
96 text
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
97 if (text
) InternalGetWindowText(hwnd
, text
, len
);
102 ThemeDrawTitle(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
107 HRESULT WINAPI
ThemeDrawCaptionText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
108 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
109 DWORD dwTextFlags2
, const RECT
*pRect
, BOOL Active
)
113 HGDIOBJ oldFont
= NULL
;
116 COLORREF oldTextColor
;
120 hr
= GetThemeSysFont(0,TMT_CAPTIONFONT
,&logfont
);
123 hFont
= CreateFontIndirectW(&logfont
);
125 CopyRect(&rt
, pRect
);
127 oldFont
= SelectObject(hdc
, hFont
);
129 if(dwTextFlags2
& DTT_GRAYED
)
130 textColor
= GetSysColor(COLOR_GRAYTEXT
);
132 textColor
= GetSysColor(COLOR_INACTIVECAPTIONTEXT
);
134 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
136 oldTextColor
= SetTextColor(hdc
, textColor
);
137 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
138 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
139 SetBkMode(hdc
, oldBkMode
);
140 SetTextColor(hdc
, oldTextColor
);
143 SelectObject(hdc
, oldFont
);
150 ThemeInitDrawContext(PDRAW_CONTEXT pcontext
,
154 pcontext
->wi
.cbSize
= sizeof(pcontext
->wi
);
155 GetWindowInfo(hWnd
, &pcontext
->wi
);
156 pcontext
->hWnd
= hWnd
;
157 pcontext
->Active
= IsWindowActive(hWnd
, pcontext
->wi
.dwExStyle
);
158 pcontext
->theme
= MSSTYLES_OpenThemeClass(ActiveThemeFile
, NULL
, L
"WINDOW");
159 pcontext
->scrolltheme
= MSSTYLES_OpenThemeClass(ActiveThemeFile
, NULL
, L
"SCROLLBAR");
161 pcontext
->CaptionHeight
= pcontext
->wi
.cyWindowBorders
;
162 pcontext
->CaptionHeight
+= GetSystemMetrics(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
166 hRgn
= CreateRectRgnIndirect(&pcontext
->wi
.rcWindow
);
168 pcontext
->hRgn
= hRgn
;
170 pcontext
->hDC
= GetDCEx(hWnd
, hRgn
, DCX_WINDOW
| DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
);
174 ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext
)
176 ReleaseDC(pcontext
->hWnd
,pcontext
->hDC
);
178 CloseThemeData (pcontext
->theme
);
179 CloseThemeData (pcontext
->scrolltheme
);
181 if(pcontext
->hRgn
!= NULL
)
183 DeleteObject(pcontext
->hRgn
);
188 ThemeStartBufferedPaint(PDRAW_CONTEXT pcontext
, int cx
, int cy
)
192 pcontext
->hDCScreen
= pcontext
->hDC
;
193 pcontext
->hDC
= CreateCompatibleDC(pcontext
->hDCScreen
);
194 hbmp
= CreateCompatibleBitmap(pcontext
->hDCScreen
, cx
, cy
);
195 pcontext
->hbmpOld
= (HBITMAP
)SelectObject(pcontext
->hDC
, hbmp
);
199 ThemeEndBufferedPaint(PDRAW_CONTEXT pcontext
, int x
, int y
, int cx
, int cy
)
202 BitBlt(pcontext
->hDCScreen
, 0, 0, cx
, cy
, pcontext
->hDC
, x
, y
, SRCCOPY
);
203 hbmp
= (HBITMAP
) SelectObject(pcontext
->hDC
, pcontext
->hbmpOld
);
204 DeleteObject(pcontext
->hDC
);
207 pcontext
->hDC
= pcontext
->hDCScreen
;
211 ThemeDrawCaptionButton(PDRAW_CONTEXT pcontext
,
213 CAPTIONBUTTON buttonId
,
217 INT ButtonWidth
, ButtonHeight
, iPartId
;
219 ButtonHeight
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMSIZE
: SM_CYSIZE
);
220 ButtonWidth
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CXSMSIZE
: SM_CXSIZE
);
225 iPartId
= pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? WP_SMALLCLOSEBUTTON
: WP_CLOSEBUTTON
;
229 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
231 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
234 iStateId
= BUTTON_DISABLED
;
237 iPartId
= pcontext
->wi
.dwStyle
& WS_MAXIMIZE
? WP_RESTOREBUTTON
: WP_MAXBUTTON
;
241 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
243 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
246 iStateId
= BUTTON_DISABLED
;
249 iPartId
= WP_MINBUTTON
;
253 //FIXME: Implement Help Button
260 /* Calculate the position */
261 rcPart
.top
= prcCurrent
->top
;
262 rcPart
.right
= prcCurrent
->right
;
263 rcPart
.bottom
= rcPart
.top
+ ButtonHeight
;
264 rcPart
.left
= rcPart
.right
- ButtonWidth
;
265 prcCurrent
->right
-= ButtonWidth
+ BUTTON_GAP_SIZE
;
267 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, iPartId
, iStateId
, &rcPart
, NULL
);
271 ThemeGetButtonState(DWORD htCurrect
, DWORD htHot
, DWORD htDown
, BOOL Active
)
273 if (htHot
== htCurrect
)
276 return BUTTON_INACTIVE
;
277 if (htDown
== htCurrect
)
278 return BUTTON_PRESSED
;
280 return BUTTON_NORMAL
;
283 /* Used only from mouse event handlers */
285 ThemeDrawCaptionButtons(PDRAW_CONTEXT pcontext
, DWORD htHot
, DWORD htDown
)
289 /* Calculate the area of the caption */
290 rcCurrent
.top
= rcCurrent
.left
= 0;
291 rcCurrent
.right
= pcontext
->wi
.rcWindow
.right
- pcontext
->wi
.rcWindow
.left
;
292 rcCurrent
.bottom
= pcontext
->CaptionHeight
;
294 /* Add a padding around the objects of the caption */
295 InflateRect(&rcCurrent
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
296 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
298 /* Draw the buttons */
299 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, CLOSEBUTTON
,
300 ThemeGetButtonState(HTCLOSE
, htHot
, htDown
, pcontext
->Active
));
301 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MAXBUTTON
,
302 ThemeGetButtonState(HTMAXBUTTON
, htHot
, htDown
, pcontext
->Active
));
303 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MINBUTTON
,
304 ThemeGetButtonState(HTMINBUTTON
, htHot
, htDown
, pcontext
->Active
));
305 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, HELPBUTTON
,
306 ThemeGetButtonState(HTHELP
, htHot
, htDown
, pcontext
->Active
));
309 /* Used from WM_NCPAINT and WM_NCACTIVATE handlers */
311 ThemeDrawCaption(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
318 // See also win32ss/user/ntuser/nonclient.c!UserDrawCaptionBar
319 // and win32ss/user/ntuser/nonclient.c!UserDrawCaption
320 if ((pcontext
->wi
.dwStyle
& WS_SYSMENU
) && !(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
))
321 hIcon
= UserGetWindowIcon(pcontext
);
325 CaptionText
= UserGetWindowCaption(pcontext
->hWnd
);
327 /* Get the caption part and state id */
328 if (pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
329 iPart
= WP_SMALLCAPTION
;
330 else if (pcontext
->wi
.dwStyle
& WS_MAXIMIZE
)
331 iPart
= WP_MAXCAPTION
;
335 iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
337 /* Draw the caption background */
338 rcPart
= *prcCurrent
;
339 rcPart
.bottom
= rcPart
.top
+ pcontext
->CaptionHeight
;
340 prcCurrent
->top
= rcPart
.bottom
;
341 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,iPart
,iState
,&rcPart
,NULL
);
343 /* Add a padding around the objects of the caption */
344 InflateRect(&rcPart
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
345 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
347 /* Draw the caption buttons */
348 if (pcontext
->wi
.dwStyle
& WS_SYSMENU
)
350 iState
= pcontext
->Active
? BUTTON_NORMAL
: BUTTON_INACTIVE
;
352 ThemeDrawCaptionButton(pcontext
, &rcPart
, CLOSEBUTTON
, iState
);
353 ThemeDrawCaptionButton(pcontext
, &rcPart
, MAXBUTTON
, iState
);
354 ThemeDrawCaptionButton(pcontext
, &rcPart
, MINBUTTON
, iState
);
355 ThemeDrawCaptionButton(pcontext
, &rcPart
, HELPBUTTON
, iState
);
363 int IconHeight
= GetSystemMetrics(SM_CYSMICON
);
364 int IconWidth
= GetSystemMetrics(SM_CXSMICON
);
365 DrawIconEx(pcontext
->hDC
, rcPart
.left
, rcPart
.top
, hIcon
, IconWidth
, IconHeight
, 0, NULL
, DI_NORMAL
);
366 rcPart
.left
+= IconWidth
+ 4;
371 /* Draw the caption */
374 /* FIXME: Use DrawThemeTextEx */
375 ThemeDrawCaptionText(pcontext
->theme
,
380 lstrlenW(CaptionText
),
381 DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
,
385 HeapFree(GetProcessHeap(), 0, CaptionText
);
390 ThemeDrawBorders(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
393 int iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
395 /* Draw the bottom border */
396 rcPart
= *prcCurrent
;
397 rcPart
.top
= rcPart
.bottom
- pcontext
->wi
.cyWindowBorders
;
398 prcCurrent
->bottom
= rcPart
.top
;
399 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, WP_FRAMEBOTTOM
, iState
, &rcPart
, NULL
);
401 /* Draw the left border */
402 rcPart
= *prcCurrent
;
403 rcPart
.right
= rcPart
.left
+ pcontext
->wi
.cxWindowBorders
;
404 prcCurrent
->left
= rcPart
.right
;
405 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMELEFT
, iState
, &rcPart
, NULL
);
407 /* Draw the right border */
408 rcPart
= *prcCurrent
;
409 rcPart
.left
= rcPart
.right
- pcontext
->wi
.cxWindowBorders
;
410 prcCurrent
->right
= rcPart
.left
;
411 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMERIGHT
, iState
, &rcPart
, NULL
);
415 DrawClassicFrame(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
417 /* Draw outer edge */
418 if (UserHasWindowEdge(context
->wi
.dwStyle
, context
->wi
.dwExStyle
))
420 DrawEdge(context
->hDC
, prcCurrent
, EDGE_RAISED
, BF_RECT
| BF_ADJUST
);
422 else if (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
)
424 DrawEdge(context
->hDC
, prcCurrent
, BDR_SUNKENINNER
, BF_RECT
| BF_ADJUST
| BF_FLAT
);
427 /* Firstly the "thick" frame */
428 if ((context
->wi
.dwStyle
& WS_THICKFRAME
) && !(context
->wi
.dwStyle
& WS_MINIMIZE
))
431 (GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
)) *
432 GetSystemMetrics(SM_CXBORDER
);
434 (GetSystemMetrics(SM_CYFRAME
) - GetSystemMetrics(SM_CYDLGFRAME
)) *
435 GetSystemMetrics(SM_CYBORDER
);
437 SelectObject(context
->hDC
, GetSysColorBrush(
438 context
->Active
? COLOR_ACTIVEBORDER
: COLOR_INACTIVEBORDER
));
441 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
442 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
443 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
444 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
445 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
446 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
447 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
448 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
450 InflateRect(prcCurrent
, -Width
, -Height
);
453 /* Now the other bit of the frame */
454 if (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_BORDER
) || (context
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
456 INT Width
= GetSystemMetrics(SM_CXBORDER
);
457 INT Height
= GetSystemMetrics(SM_CYBORDER
);
459 SelectObject(context
->hDC
, GetSysColorBrush(
460 (context
->wi
.dwExStyle
& (WS_EX_DLGMODALFRAME
| WS_EX_CLIENTEDGE
)) ? COLOR_3DFACE
:
461 (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
) ? COLOR_WINDOWFRAME
:
462 (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) ? COLOR_3DFACE
:
466 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
467 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
468 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
469 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
470 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
471 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
472 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
473 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
475 InflateRect(prcCurrent
, -Width
, -Height
);
478 if (context
->wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
480 DrawEdge(context
->hDC
, prcCurrent
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
485 ThemeDrawMenuItem(PDRAW_CONTEXT pcontext
, HMENU Menu
, int imenu
)
488 BOOL flat_menu
= FALSE
;
491 WCHAR wstrItemText
[20];
493 HFONT FontOld
= NULL
;
494 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
496 Item
.cbSize
= sizeof(MENUITEMINFOW
);
497 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
498 Item
.dwTypeData
= wstrItemText
;
500 if (!GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
))
503 if(Item
.fType
& MF_SEPARATOR
)
509 Item
.dwTypeData
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, Item
.cch
* sizeof(WCHAR
));
510 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
511 GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
);
517 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
519 GetMenuItemRect(pcontext
->hWnd
, Menu
, imenu
, &Rect
);
521 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
523 SetBkColor(pcontext
->hDC
, GetSysColor(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
524 SetTextColor(pcontext
->hDC
, GetSysColor(Item
.fState
& MF_GRAYED
? COLOR_GRAYTEXT
: COLOR_MENUTEXT
));
526 if (0 != (Item
.fState
& MFS_DEFAULT
))
528 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFontBold
);
531 Rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
532 Rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
534 Text
= (PWCHAR
) Item
.dwTypeData
;
537 for (i
= 0; L
'\0' != Text
[i
]; i
++)
539 if (L
'\t' == Text
[i
] || L
'\b' == Text
[i
])
546 SetBkMode(pcontext
->hDC
, OPAQUE
);
548 if (0 != (Item
.fState
& MF_GRAYED
))
550 if (0 == (Item
.fState
& MF_HILITE
))
552 ++Rect
.left
; ++Rect
.top
; ++Rect
.right
; ++Rect
.bottom
;
553 SetTextColor(pcontext
->hDC
, RGB(0xff, 0xff, 0xff));
554 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
555 --Rect
.left
; --Rect
.top
; --Rect
.right
; --Rect
.bottom
;
557 SetTextColor(pcontext
->hDC
, RGB(0x80, 0x80, 0x80));
558 SetBkMode(pcontext
->hDC
, TRANSPARENT
);
561 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
563 /* Exclude from the clip region the area drawn by DrawText */
564 SetRect(&rcCalc
, 0,0,0,0);
565 DrawTextW(pcontext
->hDC
, Text
, i
, &rcCalc
, uFormat
| DT_CALCRECT
);
566 InflateRect( &Rect
, 0, -(rcCalc
.bottom
+1)/2);
567 ExcludeClipRect(pcontext
->hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
571 SelectObject(pcontext
->hDC
, FontOld
);
576 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext
, PRECT prcCurrent
)
579 MENUBARINFO MenuBarInfo
;
581 HFONT FontOld
= NULL
;
589 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
591 MenuBarInfo
.cbSize
= sizeof(MENUBARINFO
);
592 if (! GetMenuBarInfo(pcontext
->hWnd
, OBJID_MENU
, 0, &MenuBarInfo
))
595 Menu
= GetMenu(pcontext
->hWnd
);
596 if (GetMenuItemCount(Menu
) == 0)
599 Rect
= MenuBarInfo
.rcBar
;
600 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
602 /* Draw a line under the menu */
603 oldPen
= (HPEN
)SelectObject(pcontext
->hDC
, GetStockObject(DC_PEN
));
604 SetDCPenColor(pcontext
->hDC
, GetSysColor(COLOR_3DFACE
));
605 MoveToEx(pcontext
->hDC
, Rect
.left
, Rect
.bottom
, NULL
);
606 LineTo(pcontext
->hDC
, Rect
.right
, Rect
.bottom
);
607 SelectObject(pcontext
->hDC
, oldPen
);
609 /* Draw menu items */
610 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFont
);
612 for (i
= 0; i
< GetMenuItemCount(Menu
); i
++)
614 ThemeDrawMenuItem(pcontext
, Menu
, i
);
617 SelectObject(pcontext
->hDC
, FontOld
);
619 /* Fill the menu background area that isn't painted yet */
620 FillRect(pcontext
->hDC
, &Rect
, GetSysColorBrush(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
624 ThemePaintWindow(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
, BOOL bDoDoubleBuffering
)
626 if(!(pcontext
->wi
.dwStyle
& WS_VISIBLE
))
629 if(pcontext
->wi
.dwStyle
& WS_MINIMIZE
)
631 ThemeDrawTitle(pcontext
, prcCurrent
);
635 if((pcontext
->wi
.dwStyle
& WS_CAPTION
)==WS_CAPTION
)
637 if (bDoDoubleBuffering
)
638 ThemeStartBufferedPaint(pcontext
, prcCurrent
->right
, pcontext
->CaptionHeight
);
639 ThemeDrawCaption(pcontext
, prcCurrent
);
640 if (bDoDoubleBuffering
)
641 ThemeEndBufferedPaint(pcontext
, 0, 0, prcCurrent
->right
, pcontext
->CaptionHeight
);
642 ThemeDrawBorders(pcontext
, prcCurrent
);
646 DrawClassicFrame(pcontext
, prcCurrent
);
649 if(HAS_MENU(pcontext
->hWnd
, pcontext
->wi
.dwStyle
))
650 ThemeDrawMenuBar(pcontext
, prcCurrent
);
652 if(pcontext
->wi
.dwStyle
& WS_HSCROLL
)
653 ThemeDrawScrollBar(pcontext
, SB_HORZ
, NULL
);
655 if(pcontext
->wi
.dwStyle
& WS_VSCROLL
)
656 ThemeDrawScrollBar(pcontext
, SB_VERT
, NULL
);
664 ThemeHandleNCPaint(HWND hWnd
, HRGN hRgn
)
666 DRAW_CONTEXT context
;
669 ThemeInitDrawContext(&context
, hWnd
, hRgn
);
671 rcCurrent
= context
.wi
.rcWindow
;
672 OffsetRect( &rcCurrent
, -context
.wi
.rcWindow
.left
, -context
.wi
.rcWindow
.top
);
674 ThemePaintWindow(&context
, &rcCurrent
, TRUE
);
675 ThemeCleanupDrawContext(&context
);
681 ThemeHandleNcMouseMove(HWND hWnd
, DWORD ht
, POINT
* pt
)
683 DRAW_CONTEXT context
;
686 PWND_CONTEXT pcontext
;
688 /* First of all check if we have something to do here */
689 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
690 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
693 /* Get theme data for this window */
694 pcontext
= ThemeGetWndContext(hWnd
);
695 if (pcontext
== NULL
)
698 /* Begin tracking in the non client area if we are not tracking yet */
699 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
700 tme
.dwFlags
= TME_QUERY
;
701 tme
.hwndTrack
= hWnd
;
702 TrackMouseEvent(&tme
);
703 if (tme
.dwFlags
!= (TME_LEAVE
| TME_NONCLIENT
))
705 tme
.hwndTrack
= hWnd
;
706 tme
.dwFlags
= TME_LEAVE
| TME_NONCLIENT
;
707 TrackMouseEvent(&tme
);
710 /* Dont do any drawing if the hit test wasn't changed */
711 if (ht
== pcontext
->lastHitTest
)
714 ThemeInitDrawContext(&context
, hWnd
, 0);
715 if (context
.wi
.dwStyle
& WS_SYSMENU
)
717 if (HT_ISBUTTON(ht
) || HT_ISBUTTON(pcontext
->lastHitTest
))
718 ThemeDrawCaptionButtons(&context
, ht
, 0);
721 if (context
.wi
.dwStyle
& WS_HSCROLL
)
723 if (ht
== HTHSCROLL
|| pcontext
->lastHitTest
== HTHSCROLL
)
724 ThemeDrawScrollBar(&context
, SB_HORZ
, ht
== HTHSCROLL
? pt
: NULL
);
727 if (context
.wi
.dwStyle
& WS_VSCROLL
)
729 if (ht
== HTVSCROLL
|| pcontext
->lastHitTest
== HTVSCROLL
)
730 ThemeDrawScrollBar(&context
, SB_VERT
, ht
== HTVSCROLL
? pt
: NULL
);
732 ThemeCleanupDrawContext(&context
);
734 pcontext
->lastHitTest
= ht
;
740 ThemeHandleNcMouseLeave(HWND hWnd
)
742 DRAW_CONTEXT context
;
744 PWND_CONTEXT pWndContext
;
746 /* First of all check if we have something to do here */
747 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
748 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
751 /* Get theme data for this window */
752 pWndContext
= ThemeGetWndContext(hWnd
);
753 if (pWndContext
== NULL
)
756 ThemeInitDrawContext(&context
, hWnd
, 0);
757 if (context
.wi
.dwStyle
& WS_SYSMENU
&& HT_ISBUTTON(pWndContext
->lastHitTest
))
758 ThemeDrawCaptionButtons(&context
, 0, 0);
760 if (context
.wi
.dwStyle
& WS_HSCROLL
&& pWndContext
->lastHitTest
== HTHSCROLL
)
761 ThemeDrawScrollBar(&context
, SB_HORZ
, NULL
);
763 if (context
.wi
.dwStyle
& WS_VSCROLL
&& pWndContext
->lastHitTest
== HTVSCROLL
)
764 ThemeDrawScrollBar(&context
, SB_VERT
, NULL
);
766 ThemeCleanupDrawContext(&context
);
768 pWndContext
->lastHitTest
= HTNOWHERE
;
774 ThemeHandleButton(HWND hWnd
, WPARAM wParam
)
780 DRAW_CONTEXT context
;
781 PWND_CONTEXT pWndContext
;
783 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
784 if (!((Style
& WS_CAPTION
) && (Style
& WS_SYSMENU
)))
793 if (!(Style
& WS_MINIMIZEBOX
))
795 SCMsg
= ((Style
& WS_MINIMIZE
) ? SC_RESTORE
: SC_MINIMIZE
);
798 if (!(Style
& WS_MAXIMIZEBOX
))
800 SCMsg
= ((Style
& WS_MAXIMIZE
) ? SC_RESTORE
: SC_MAXIMIZE
);
806 /* Get theme data for this window */
807 pWndContext
= ThemeGetWndContext(hWnd
);
808 if (pWndContext
== NULL
)
811 ThemeInitDrawContext(&context
, hWnd
, 0);
812 ThemeDrawCaptionButtons(&context
, 0, wParam
);
813 pWndContext
->lastHitTest
= wParam
;
819 if (GetMessageW(&Msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
) <= 0)
822 if (Msg
.message
== WM_LBUTTONUP
)
825 if (Msg
.message
!= WM_MOUSEMOVE
)
828 ht
= SendMessage(hWnd
, WM_NCHITTEST
, 0, MAKELPARAM(Msg
.pt
.x
, Msg
.pt
.y
));
829 Pressed
= (ht
== wParam
);
831 /* Only draw the buttons if the hit test changed */
832 if (ht
!= pWndContext
->lastHitTest
&&
833 (HT_ISBUTTON(ht
) || HT_ISBUTTON(pWndContext
->lastHitTest
)))
835 ThemeDrawCaptionButtons(&context
, 0, Pressed
? wParam
: 0);
836 pWndContext
->lastHitTest
= ht
;
840 ThemeDrawCaptionButtons(&context
, ht
, 0);
841 ThemeCleanupDrawContext(&context
);
846 SendMessageW(hWnd
, WM_SYSCOMMAND
, SCMsg
, 0);
851 DefWndNCHitTest(HWND hWnd
, POINT Point
)
857 GetWindowInfo(hWnd
, &wi
);
859 if (!PtInRect(&wi
.rcWindow
, Point
))
863 WindowRect
= wi
.rcWindow
;
865 if (UserHasWindowEdge(wi
.dwStyle
, wi
.dwExStyle
))
869 InflateRect(&WindowRect
, -(int)wi
.cxWindowBorders
, -(int)wi
.cyWindowBorders
);
870 XSize
= GetSystemMetrics(SM_CXSIZE
) * GetSystemMetrics(SM_CXBORDER
);
871 YSize
= GetSystemMetrics(SM_CYSIZE
) * GetSystemMetrics(SM_CYBORDER
);
872 if (!PtInRect(&WindowRect
, Point
))
876 ThickFrame
= (wi
.dwStyle
& WS_THICKFRAME
);
877 if (Point
.y
< WindowRect
.top
)
879 if(wi
.dwStyle
& WS_MINIMIZE
)
883 if (Point
.x
< (WindowRect
.left
+ XSize
))
885 if (Point
.x
>= (WindowRect
.right
- XSize
))
889 if (Point
.y
>= WindowRect
.bottom
)
891 if(wi
.dwStyle
& WS_MINIMIZE
)
895 if (Point
.x
< (WindowRect
.left
+ XSize
))
897 if (Point
.x
>= (WindowRect
.right
- XSize
))
898 return HTBOTTOMRIGHT
;
901 if (Point
.x
< WindowRect
.left
)
903 if(wi
.dwStyle
& WS_MINIMIZE
)
907 if (Point
.y
< (WindowRect
.top
+ YSize
))
909 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
913 if (Point
.x
>= WindowRect
.right
)
915 if(wi
.dwStyle
& WS_MINIMIZE
)
919 if (Point
.y
< (WindowRect
.top
+ YSize
))
921 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
922 return HTBOTTOMRIGHT
;
929 if (wi
.dwExStyle
& WS_EX_STATICEDGE
)
930 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
931 -GetSystemMetrics(SM_CYBORDER
));
932 if (!PtInRect(&WindowRect
, Point
))
936 if ((wi
.dwStyle
& WS_CAPTION
) == WS_CAPTION
)
938 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
939 WindowRect
.top
+= GetSystemMetrics(SM_CYSMCAPTION
);
941 WindowRect
.top
+= GetSystemMetrics(SM_CYCAPTION
);
943 if (!PtInRect(&WindowRect
, Point
))
947 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
948 ButtonWidth
= GetSystemMetrics(SM_CXSMSIZE
);
950 ButtonWidth
= GetSystemMetrics(SM_CXSIZE
);
953 ButtonWidth
+= BUTTON_GAP_SIZE
;
955 if (wi
.dwStyle
& WS_SYSMENU
)
957 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
959 WindowRect
.right
-= ButtonWidth
;
963 // if(!(wi.dwExStyle & WS_EX_DLGMODALFRAME))
964 // FIXME: The real test should check whether there is
965 // an icon for the system window, and if so, do the
966 // rect.left increase.
967 // See win32ss/user/user32/windows/nonclient.c!DefWndNCHitTest
968 // and win32ss/user/ntuser/nonclient.c!GetNCHitEx which does
970 WindowRect
.left
+= ButtonWidth
;
971 WindowRect
.right
-= ButtonWidth
;
974 if (Point
.x
< WindowRect
.left
)
976 if (WindowRect
.right
<= Point
.x
)
978 if (wi
.dwStyle
& WS_MAXIMIZEBOX
|| wi
.dwStyle
& WS_MINIMIZEBOX
)
979 WindowRect
.right
-= ButtonWidth
;
980 if (Point
.x
>= WindowRect
.right
)
982 if (wi
.dwStyle
& WS_MINIMIZEBOX
)
983 WindowRect
.right
-= ButtonWidth
;
984 if (Point
.x
>= WindowRect
.right
)
990 if(!(wi
.dwStyle
& WS_MINIMIZE
))
995 ScreenToClient(hWnd
, &ClientPoint
);
996 GetClientRect(hWnd
, &wi
.rcClient
);
998 if (PtInRect(&wi
.rcClient
, ClientPoint
))
1003 if ((menu
= GetMenu(hWnd
)) && !(wi
.dwStyle
& WS_CHILD
))
1005 if (Point
.x
> 0 && Point
.x
< WindowRect
.right
&& ClientPoint
.y
< 0)
1009 if (wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
1011 InflateRect(&WindowRect
, -2 * GetSystemMetrics(SM_CXBORDER
),
1012 -2 * GetSystemMetrics(SM_CYBORDER
));
1015 if ((wi
.dwStyle
& WS_VSCROLL
) && (wi
.dwStyle
& WS_HSCROLL
) &&
1016 (WindowRect
.bottom
- WindowRect
.top
) > GetSystemMetrics(SM_CYHSCROLL
))
1018 RECT ParentRect
, TempRect
= WindowRect
, TempRect2
= WindowRect
;
1019 HWND Parent
= GetParent(hWnd
);
1021 TempRect
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
1022 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1023 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1025 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1026 if (PtInRect(&TempRect
, Point
))
1029 TempRect2
.top
= TempRect2
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1030 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1031 TempRect2
.left
+= GetSystemMetrics(SM_CXVSCROLL
);
1033 TempRect2
.right
-= GetSystemMetrics(SM_CXVSCROLL
);
1034 if (PtInRect(&TempRect2
, Point
))
1037 TempRect
.top
= TempRect2
.top
;
1038 TempRect
.bottom
= TempRect2
.bottom
;
1040 GetClientRect(Parent
, &ParentRect
);
1041 if (PtInRect(&TempRect
, Point
) && HASSIZEGRIP(wi
.dwStyle
, wi
.dwExStyle
,
1042 GetWindowLongW(Parent
, GWL_STYLE
), wi
.rcWindow
, ParentRect
))
1044 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1045 return HTBOTTOMLEFT
;
1047 return HTBOTTOMRIGHT
;
1052 if (wi
.dwStyle
& WS_VSCROLL
)
1054 RECT TempRect
= WindowRect
;
1056 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1057 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1059 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1060 if (PtInRect(&TempRect
, Point
))
1063 else if (wi
.dwStyle
& WS_HSCROLL
)
1065 RECT TempRect
= WindowRect
;
1066 TempRect
.top
= TempRect
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1067 if (PtInRect(&TempRect
, Point
))
1077 ThemeWndProc(HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, WNDPROC DefWndProc
)
1082 return ThemeHandleNCPaint(hWnd
, (HRGN
)wParam
);
1084 // WM_NCUAHDRAWCAPTION : wParam are DC_* flags.
1086 case WM_NCUAHDRAWCAPTION
:
1088 // WM_NCUAHDRAWFRAME : wParam is HDC, lParam are DC_ACTIVE and or DC_REDRAWHUNGWND.
1090 case WM_NCUAHDRAWFRAME
:
1092 ThemeHandleNCPaint(hWnd
, (HRGN
)1);
1094 case WM_NCMOUSEMOVE
:
1097 Point
.x
= GET_X_LPARAM(lParam
);
1098 Point
.y
= GET_Y_LPARAM(lParam
);
1099 return ThemeHandleNcMouseMove(hWnd
, wParam
, &Point
);
1101 case WM_NCMOUSELEAVE
:
1102 return ThemeHandleNcMouseLeave(hWnd
);
1103 case WM_NCLBUTTONDOWN
:
1110 ThemeHandleButton(hWnd
, wParam
);
1114 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1119 Point
.x
= GET_X_LPARAM(lParam
);
1120 Point
.y
= GET_Y_LPARAM(lParam
);
1121 return DefWndNCHitTest(hWnd
, Point
);
1125 if((wParam
& 0xfff0) == SC_VSCROLL
||
1126 (wParam
& 0xfff0) == SC_HSCROLL
)
1129 Pt
.x
= (short)LOWORD(lParam
);
1130 Pt
.y
= (short)HIWORD(lParam
);
1131 NC_TrackScrollBar(hWnd
, wParam
, Pt
);
1136 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1140 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1144 HRESULT WINAPI
DrawNCPreview(HDC hDC
,
1147 LPCWSTR pszThemeFileName
,
1148 LPCWSTR pszColorName
,
1149 LPCWSTR pszSizeName
,
1150 PNONCLIENTMETRICSW pncMetrics
,
1151 COLORREF
* lpaRgbValues
)
1153 WNDCLASSEXW DummyPreviewWindowClass
;
1156 HTHEMEFILE hThemeFile
;
1157 DRAW_CONTEXT context
;
1160 /* FIXME: We also need to implement drawing the rest of the preview windows
1161 * and make use of the ncmetrics and colors passed as parameters */
1163 /* Create a dummy window that will be used to trick the paint funtions */
1164 memset(&DummyPreviewWindowClass
, 0, sizeof(DummyPreviewWindowClass
));
1165 DummyPreviewWindowClass
.cbSize
= sizeof(DummyPreviewWindowClass
);
1166 DummyPreviewWindowClass
.lpszClassName
= L
"DummyPreviewWindowClass";
1167 DummyPreviewWindowClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1168 DummyPreviewWindowClass
.hInstance
= hDllInst
;
1169 DummyPreviewWindowClass
.lpfnWndProc
= DefWindowProcW
;
1170 if (!RegisterClassExW(&DummyPreviewWindowClass
))
1173 hwndDummy
= CreateWindowExW(0, L
"DummyPreviewWindowClass", L
"Active window", WS_OVERLAPPEDWINDOW
,30,30,300,150,0,0,hDllInst
,NULL
);
1177 hres
= OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, &hThemeFile
,0);
1181 /* Initialize the special draw context for the preview */
1183 context
.hWnd
= hwndDummy
;
1184 context
.theme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"WINDOW", 0);
1187 context
.scrolltheme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"SCROLLBAR", 0);
1190 context
.Active
= TRUE
;
1191 if (!GetWindowInfo(hwndDummy
, &context
.wi
))
1193 context
.wi
.dwStyle
|= WS_VISIBLE
;
1194 context
.CaptionHeight
= context
.wi
.cyWindowBorders
;
1195 context
.CaptionHeight
+= GetSystemMetrics(context
.wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
1196 context
.hRgn
= CreateRectRgnIndirect(&context
.wi
.rcWindow
);
1198 /* Paint the window on the preview hDC */
1199 rcCurrent
= context
.wi
.rcWindow
;
1200 ThemePaintWindow(&context
, &rcCurrent
, FALSE
);
1202 ThemeCleanupDrawContext(&context
);
1205 DestroyWindow(hwndDummy
);
1206 UnregisterClassW(L
"DummyPreviewWindowClass", hDllInst
);