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
);
33 IsWindowActive(HWND hWnd
, DWORD ExStyle
)
37 if (ExStyle
& WS_EX_MDICHILD
)
39 ret
= IsChild(GetForegroundWindow(), hWnd
);
41 ret
= (hWnd
== (HWND
)SendMessageW(GetParent(hWnd
), WM_MDIGETACTIVE
, 0, 0));
45 ret
= (GetForegroundWindow() == hWnd
);
52 UserHasWindowEdge(DWORD Style
, DWORD ExStyle
)
54 if (Style
& WS_MINIMIZE
)
56 if (ExStyle
& WS_EX_DLGMODALFRAME
)
58 if (ExStyle
& WS_EX_STATICEDGE
)
60 if (Style
& WS_THICKFRAME
)
62 if (Style
== WS_DLGFRAME
|| Style
== WS_CAPTION
)
68 UserGetWindowIcon(HWND hwnd
)
72 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_SMALL2
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
75 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_SMALL
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
78 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_BIG
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
81 hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICONSM
);
84 hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICON
);
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 hIcon
= UserGetWindowIcon(pcontext
->hWnd
);
319 CaptionText
= UserGetWindowCaption(pcontext
->hWnd
);
321 /* Get the caption part and state id */
322 if (pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
323 iPart
= WP_SMALLCAPTION
;
324 else if (pcontext
->wi
.dwStyle
& WS_MAXIMIZE
)
325 iPart
= WP_MAXCAPTION
;
329 iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
331 /* Draw the caption background*/
332 rcPart
= *prcCurrent
;
333 rcPart
.bottom
= rcPart
.top
+ pcontext
->CaptionHeight
;
334 prcCurrent
->top
= rcPart
.bottom
;
335 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,iPart
,iState
,&rcPart
,NULL
);
337 /* Add a padding around the objects of the caption */
338 InflateRect(&rcPart
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
339 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
341 /* Draw the caption buttons */
342 if (pcontext
->wi
.dwStyle
& WS_SYSMENU
)
344 iState
= pcontext
->Active
? BUTTON_NORMAL
: BUTTON_INACTIVE
;
346 ThemeDrawCaptionButton(pcontext
, &rcPart
, CLOSEBUTTON
, iState
);
347 ThemeDrawCaptionButton(pcontext
, &rcPart
, MAXBUTTON
, iState
);
348 ThemeDrawCaptionButton(pcontext
, &rcPart
, MINBUTTON
, iState
);
349 ThemeDrawCaptionButton(pcontext
, &rcPart
, HELPBUTTON
, iState
);
355 if(hIcon
&& !(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
356 && !(pcontext
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
358 int IconHeight
= GetSystemMetrics(SM_CYSMICON
);
359 int IconWidth
= GetSystemMetrics(SM_CXSMICON
);
360 DrawIconEx(pcontext
->hDC
, rcPart
.left
, rcPart
.top
, hIcon
, IconWidth
, IconHeight
, 0, NULL
, DI_NORMAL
);
361 rcPart
.left
+= IconWidth
+ 4;
366 /* Draw the caption */
369 /*FIXME: Use DrawThemeTextEx*/
370 ThemeDrawCaptionText(pcontext
->theme
,
375 lstrlenW(CaptionText
),
376 DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
,
380 HeapFree(GetProcessHeap(), 0, CaptionText
);
385 ThemeDrawBorders(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
388 int iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
390 /* Draw the bottom border */
391 rcPart
= *prcCurrent
;
392 rcPart
.top
= rcPart
.bottom
- pcontext
->wi
.cyWindowBorders
;
393 prcCurrent
->bottom
= rcPart
.top
;
394 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, WP_FRAMEBOTTOM
, iState
, &rcPart
, NULL
);
396 /* Draw the left border */
397 rcPart
= *prcCurrent
;
398 rcPart
.right
= rcPart
.left
+ pcontext
->wi
.cxWindowBorders
;
399 prcCurrent
->left
= rcPart
.right
;
400 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMELEFT
, iState
, &rcPart
, NULL
);
402 /* Draw the right border */
403 rcPart
= *prcCurrent
;
404 rcPart
.left
= rcPart
.right
- pcontext
->wi
.cxWindowBorders
;
405 prcCurrent
->right
= rcPart
.left
;
406 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMERIGHT
, iState
, &rcPart
, NULL
);
410 DrawClassicFrame(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
412 /* Draw outer edge */
413 if (UserHasWindowEdge(context
->wi
.dwStyle
, context
->wi
.dwExStyle
))
415 DrawEdge(context
->hDC
, prcCurrent
, EDGE_RAISED
, BF_RECT
| BF_ADJUST
);
417 else if (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
)
419 DrawEdge(context
->hDC
, prcCurrent
, BDR_SUNKENINNER
, BF_RECT
| BF_ADJUST
| BF_FLAT
);
422 /* Firstly the "thick" frame */
423 if ((context
->wi
.dwStyle
& WS_THICKFRAME
) && !(context
->wi
.dwStyle
& WS_MINIMIZE
))
426 (GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
)) *
427 GetSystemMetrics(SM_CXBORDER
);
429 (GetSystemMetrics(SM_CYFRAME
) - GetSystemMetrics(SM_CYDLGFRAME
)) *
430 GetSystemMetrics(SM_CYBORDER
);
432 SelectObject(context
->hDC
, GetSysColorBrush(
433 context
->Active
? COLOR_ACTIVEBORDER
: COLOR_INACTIVEBORDER
));
436 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
437 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
438 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
439 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
440 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
441 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
442 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
443 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
445 InflateRect(prcCurrent
, -Width
, -Height
);
448 /* Now the other bit of the frame */
449 if (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_BORDER
) || context
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
)
451 INT Width
= GetSystemMetrics(SM_CXBORDER
);
452 INT Height
= GetSystemMetrics(SM_CYBORDER
);
454 SelectObject(context
->hDC
, GetSysColorBrush(
455 (context
->wi
.dwExStyle
& (WS_EX_DLGMODALFRAME
| WS_EX_CLIENTEDGE
)) ? COLOR_3DFACE
:
456 (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
) ? COLOR_WINDOWFRAME
:
457 (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) ? COLOR_3DFACE
:
461 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
462 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
463 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
464 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
465 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
466 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
467 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
468 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
470 InflateRect(prcCurrent
, -Width
, -Height
);
473 if (context
->wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
475 DrawEdge(context
->hDC
, prcCurrent
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
480 ThemeDrawMenuItem(PDRAW_CONTEXT pcontext
, HMENU Menu
, int imenu
)
483 BOOL flat_menu
= FALSE
;
486 WCHAR wstrItemText
[20];
488 HFONT FontOld
= NULL
;
489 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
491 Item
.cbSize
= sizeof(MENUITEMINFOW
);
492 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
493 Item
.dwTypeData
= wstrItemText
;
495 if (!GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
))
498 if(Item
.fType
& MF_SEPARATOR
)
504 Item
.dwTypeData
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, Item
.cch
* sizeof(WCHAR
));
505 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
506 GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
);
512 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
514 GetMenuItemRect(pcontext
->hWnd
, Menu
, imenu
, &Rect
);
516 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
518 SetBkColor(pcontext
->hDC
, GetSysColor(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
519 SetTextColor(pcontext
->hDC
, GetSysColor(Item
.fState
& MF_GRAYED
? COLOR_GRAYTEXT
: COLOR_MENUTEXT
));
521 if (0 != (Item
.fState
& MFS_DEFAULT
))
523 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFontBold
);
526 Rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
527 Rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
529 Text
= (PWCHAR
) Item
.dwTypeData
;
532 for (i
= 0; L
'\0' != Text
[i
]; i
++)
534 if (L
'\t' == Text
[i
] || L
'\b' == Text
[i
])
541 SetBkMode(pcontext
->hDC
, OPAQUE
);
543 if (0 != (Item
.fState
& MF_GRAYED
))
545 if (0 == (Item
.fState
& MF_HILITE
))
547 ++Rect
.left
; ++Rect
.top
; ++Rect
.right
; ++Rect
.bottom
;
548 SetTextColor(pcontext
->hDC
, RGB(0xff, 0xff, 0xff));
549 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
550 --Rect
.left
; --Rect
.top
; --Rect
.right
; --Rect
.bottom
;
552 SetTextColor(pcontext
->hDC
, RGB(0x80, 0x80, 0x80));
553 SetBkMode(pcontext
->hDC
, TRANSPARENT
);
556 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
558 /* Exclude from the clip region the area drawn by DrawText */
559 SetRect(&rcCalc
, 0,0,0,0);
560 DrawTextW(pcontext
->hDC
, Text
, i
, &rcCalc
, uFormat
| DT_CALCRECT
);
561 InflateRect( &Rect
, 0, -(rcCalc
.bottom
+1)/2);
562 ExcludeClipRect(pcontext
->hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
566 SelectObject(pcontext
->hDC
, FontOld
);
571 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext
, PRECT prcCurrent
)
574 MENUBARINFO MenuBarInfo
;
576 HFONT FontOld
= NULL
;
584 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
586 MenuBarInfo
.cbSize
= sizeof(MENUBARINFO
);
587 if (! GetMenuBarInfo(pcontext
->hWnd
, OBJID_MENU
, 0, &MenuBarInfo
))
590 Menu
= GetMenu(pcontext
->hWnd
);
591 if (GetMenuItemCount(Menu
) == 0)
594 Rect
= MenuBarInfo
.rcBar
;
595 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
597 /* Draw a line under the menu*/
598 oldPen
= (HPEN
)SelectObject(pcontext
->hDC
, GetStockObject(DC_PEN
));
599 SetDCPenColor(pcontext
->hDC
, GetSysColor(COLOR_3DFACE
));
600 MoveToEx(pcontext
->hDC
, Rect
.left
, Rect
.bottom
, NULL
);
601 LineTo(pcontext
->hDC
, Rect
.right
, Rect
.bottom
);
602 SelectObject(pcontext
->hDC
, oldPen
);
604 /* Draw menu items */
605 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFont
);
607 for (i
= 0; i
< GetMenuItemCount(Menu
); i
++)
609 ThemeDrawMenuItem(pcontext
, Menu
, i
);
612 SelectObject(pcontext
->hDC
, FontOld
);
614 /* Fill the menu background area that isn't painted yet*/
615 FillRect(pcontext
->hDC
, &Rect
, GetSysColorBrush(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
619 ThemePaintWindow(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
, BOOL bDoDoubleBuffering
)
621 if(!(pcontext
->wi
.dwStyle
& WS_VISIBLE
))
624 if(pcontext
->wi
.dwStyle
& WS_MINIMIZE
)
626 ThemeDrawTitle(pcontext
, prcCurrent
);
630 if((pcontext
->wi
.dwStyle
& WS_CAPTION
)==WS_CAPTION
)
632 if (bDoDoubleBuffering
)
633 ThemeStartBufferedPaint(pcontext
, prcCurrent
->right
, pcontext
->CaptionHeight
);
634 ThemeDrawCaption(pcontext
, prcCurrent
);
635 if (bDoDoubleBuffering
)
636 ThemeEndBufferedPaint(pcontext
, 0, 0, prcCurrent
->right
, pcontext
->CaptionHeight
);
637 ThemeDrawBorders(pcontext
, prcCurrent
);
641 DrawClassicFrame(pcontext
, prcCurrent
);
644 if(HAS_MENU(pcontext
->hWnd
, pcontext
->wi
.dwStyle
))
645 ThemeDrawMenuBar(pcontext
, prcCurrent
);
647 if(pcontext
->wi
.dwStyle
& WS_HSCROLL
)
648 ThemeDrawScrollBar(pcontext
, SB_HORZ
, NULL
);
650 if(pcontext
->wi
.dwStyle
& WS_VSCROLL
)
651 ThemeDrawScrollBar(pcontext
, SB_VERT
, NULL
);
659 ThemeHandleNCPaint(HWND hWnd
, HRGN hRgn
)
661 DRAW_CONTEXT context
;
664 ThemeInitDrawContext(&context
, hWnd
, hRgn
);
666 rcCurrent
= context
.wi
.rcWindow
;
667 OffsetRect( &rcCurrent
, -context
.wi
.rcWindow
.left
, -context
.wi
.rcWindow
.top
);
669 ThemePaintWindow(&context
, &rcCurrent
, TRUE
);
670 ThemeCleanupDrawContext(&context
);
676 ThemeHandleNcMouseMove(HWND hWnd
, DWORD ht
, POINT
* pt
)
678 DRAW_CONTEXT context
;
681 PWND_CONTEXT pcontext
;
683 /* First of all check if we have something to do here */
684 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
685 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
688 /* Get theme data for this window */
689 pcontext
= ThemeGetWndContext(hWnd
);
690 if (pcontext
== NULL
)
693 /* Begin tracking in the non client area if we are not tracking yet */
694 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
695 tme
.dwFlags
= TME_QUERY
;
696 tme
.hwndTrack
= hWnd
;
697 TrackMouseEvent(&tme
);
698 if (tme
.dwFlags
!= (TME_LEAVE
| TME_NONCLIENT
))
700 tme
.hwndTrack
= hWnd
;
701 tme
.dwFlags
= TME_LEAVE
| TME_NONCLIENT
;
702 TrackMouseEvent(&tme
);
705 /* Dont do any drawing if the hit test wasn't changed */
706 if (ht
== pcontext
->lastHitTest
)
709 ThemeInitDrawContext(&context
, hWnd
, 0);
710 if (context
.wi
.dwStyle
& WS_SYSMENU
)
712 if (HT_ISBUTTON(ht
) || HT_ISBUTTON(pcontext
->lastHitTest
))
713 ThemeDrawCaptionButtons(&context
, ht
, 0);
716 if (context
.wi
.dwStyle
& WS_HSCROLL
)
718 if (ht
== HTHSCROLL
|| pcontext
->lastHitTest
== HTHSCROLL
)
719 ThemeDrawScrollBar(&context
, SB_HORZ
, ht
== HTHSCROLL
? pt
: NULL
);
722 if (context
.wi
.dwStyle
& WS_VSCROLL
)
724 if (ht
== HTVSCROLL
|| pcontext
->lastHitTest
== HTVSCROLL
)
725 ThemeDrawScrollBar(&context
, SB_VERT
, ht
== HTVSCROLL
? pt
: NULL
);
727 ThemeCleanupDrawContext(&context
);
729 pcontext
->lastHitTest
= ht
;
735 ThemeHandleNcMouseLeave(HWND hWnd
)
737 DRAW_CONTEXT context
;
739 PWND_CONTEXT pWndContext
;
741 /* First of all check if we have something to do here */
742 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
743 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
746 /* Get theme data for this window */
747 pWndContext
= ThemeGetWndContext(hWnd
);
748 if (pWndContext
== NULL
)
751 ThemeInitDrawContext(&context
, hWnd
, 0);
752 if (context
.wi
.dwStyle
& WS_SYSMENU
&& HT_ISBUTTON(pWndContext
->lastHitTest
))
753 ThemeDrawCaptionButtons(&context
, 0, 0);
755 if (context
.wi
.dwStyle
& WS_HSCROLL
&& pWndContext
->lastHitTest
== HTHSCROLL
)
756 ThemeDrawScrollBar(&context
, SB_HORZ
, NULL
);
758 if (context
.wi
.dwStyle
& WS_VSCROLL
&& pWndContext
->lastHitTest
== HTVSCROLL
)
759 ThemeDrawScrollBar(&context
, SB_VERT
, NULL
);
761 ThemeCleanupDrawContext(&context
);
763 pWndContext
->lastHitTest
= HTNOWHERE
;
769 ThemeHandleButton(HWND hWnd
, WPARAM wParam
)
775 DRAW_CONTEXT context
;
776 PWND_CONTEXT pWndContext
;
778 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
779 if (!((Style
& WS_CAPTION
) && (Style
& WS_SYSMENU
)))
788 if (!(Style
& WS_MINIMIZEBOX
))
790 SCMsg
= ((Style
& WS_MINIMIZE
) ? SC_RESTORE
: SC_MINIMIZE
);
793 if (!(Style
& WS_MAXIMIZEBOX
))
795 SCMsg
= ((Style
& WS_MAXIMIZE
) ? SC_RESTORE
: SC_MAXIMIZE
);
801 /* Get theme data for this window */
802 pWndContext
= ThemeGetWndContext(hWnd
);
803 if (pWndContext
== NULL
)
806 ThemeInitDrawContext(&context
, hWnd
, 0);
807 ThemeDrawCaptionButtons(&context
, 0, wParam
);
808 pWndContext
->lastHitTest
= wParam
;
814 if (GetMessageW(&Msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
) <= 0)
817 if (Msg
.message
== WM_LBUTTONUP
)
820 if (Msg
.message
!= WM_MOUSEMOVE
)
823 ht
= SendMessage(hWnd
, WM_NCHITTEST
, 0, MAKELPARAM(Msg
.pt
.x
, Msg
.pt
.y
));
824 Pressed
= (ht
== wParam
);
826 /* Only draw the buttons if the hit test changed */
827 if (ht
!= pWndContext
->lastHitTest
&&
828 (HT_ISBUTTON(ht
) || HT_ISBUTTON(pWndContext
->lastHitTest
)))
830 ThemeDrawCaptionButtons(&context
, 0, Pressed
? wParam
: 0);
831 pWndContext
->lastHitTest
= ht
;
835 ThemeDrawCaptionButtons(&context
, ht
, 0);
836 ThemeCleanupDrawContext(&context
);
841 SendMessageW(hWnd
, WM_SYSCOMMAND
, SCMsg
, 0);
846 DefWndNCHitTest(HWND hWnd
, POINT Point
)
852 GetWindowInfo(hWnd
, &wi
);
854 if (!PtInRect(&wi
.rcWindow
, Point
))
858 WindowRect
= wi
.rcWindow
;
860 if (UserHasWindowEdge(wi
.dwStyle
, wi
.dwExStyle
))
864 InflateRect(&WindowRect
, -(int)wi
.cxWindowBorders
, -(int)wi
.cyWindowBorders
);
865 XSize
= GetSystemMetrics(SM_CXSIZE
) * GetSystemMetrics(SM_CXBORDER
);
866 YSize
= GetSystemMetrics(SM_CYSIZE
) * GetSystemMetrics(SM_CYBORDER
);
867 if (!PtInRect(&WindowRect
, Point
))
871 ThickFrame
= (wi
.dwStyle
& WS_THICKFRAME
);
872 if (Point
.y
< WindowRect
.top
)
874 if(wi
.dwStyle
& WS_MINIMIZE
)
878 if (Point
.x
< (WindowRect
.left
+ XSize
))
880 if (Point
.x
>= (WindowRect
.right
- XSize
))
884 if (Point
.y
>= WindowRect
.bottom
)
886 if(wi
.dwStyle
& WS_MINIMIZE
)
890 if (Point
.x
< (WindowRect
.left
+ XSize
))
892 if (Point
.x
>= (WindowRect
.right
- XSize
))
893 return HTBOTTOMRIGHT
;
896 if (Point
.x
< WindowRect
.left
)
898 if(wi
.dwStyle
& WS_MINIMIZE
)
902 if (Point
.y
< (WindowRect
.top
+ YSize
))
904 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
908 if (Point
.x
>= WindowRect
.right
)
910 if(wi
.dwStyle
& WS_MINIMIZE
)
914 if (Point
.y
< (WindowRect
.top
+ YSize
))
916 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
917 return HTBOTTOMRIGHT
;
924 if (wi
.dwExStyle
& WS_EX_STATICEDGE
)
925 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
926 -GetSystemMetrics(SM_CYBORDER
));
927 if (!PtInRect(&WindowRect
, Point
))
931 if ((wi
.dwStyle
& WS_CAPTION
) == WS_CAPTION
)
933 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
934 WindowRect
.top
+= GetSystemMetrics(SM_CYSMCAPTION
);
936 WindowRect
.top
+= GetSystemMetrics(SM_CYCAPTION
);
938 if (!PtInRect(&WindowRect
, Point
))
943 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
944 ButtonWidth
= GetSystemMetrics(SM_CXSMSIZE
);
946 ButtonWidth
= GetSystemMetrics(SM_CXSIZE
);
949 ButtonWidth
+= BUTTON_GAP_SIZE
;
951 if (wi
.dwStyle
& WS_SYSMENU
)
953 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
955 WindowRect
.right
-= ButtonWidth
;
959 if(!(wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
960 WindowRect
.left
+= ButtonWidth
;
961 WindowRect
.right
-= ButtonWidth
;
964 if (Point
.x
< WindowRect
.left
)
966 if (WindowRect
.right
<= Point
.x
)
968 if (wi
.dwStyle
& WS_MAXIMIZEBOX
|| wi
.dwStyle
& WS_MINIMIZEBOX
)
969 WindowRect
.right
-= ButtonWidth
;
970 if (Point
.x
>= WindowRect
.right
)
972 if (wi
.dwStyle
& WS_MINIMIZEBOX
)
973 WindowRect
.right
-= ButtonWidth
;
974 if (Point
.x
>= WindowRect
.right
)
980 if(!(wi
.dwStyle
& WS_MINIMIZE
))
985 ScreenToClient(hWnd
, &ClientPoint
);
986 GetClientRect(hWnd
, &wi
.rcClient
);
988 if (PtInRect(&wi
.rcClient
, ClientPoint
))
993 if ((menu
= GetMenu(hWnd
)) && !(wi
.dwStyle
& WS_CHILD
))
995 if (Point
.x
> 0 && Point
.x
< WindowRect
.right
&& ClientPoint
.y
< 0)
999 if (wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
1001 InflateRect(&WindowRect
, -2 * GetSystemMetrics(SM_CXBORDER
),
1002 -2 * GetSystemMetrics(SM_CYBORDER
));
1005 if ((wi
.dwStyle
& WS_VSCROLL
) && (wi
.dwStyle
& WS_HSCROLL
) &&
1006 (WindowRect
.bottom
- WindowRect
.top
) > GetSystemMetrics(SM_CYHSCROLL
))
1008 RECT ParentRect
, TempRect
= WindowRect
, TempRect2
= WindowRect
;
1009 HWND Parent
= GetParent(hWnd
);
1011 TempRect
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
1012 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1013 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1015 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1016 if (PtInRect(&TempRect
, Point
))
1019 TempRect2
.top
= TempRect2
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1020 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1021 TempRect2
.left
+= GetSystemMetrics(SM_CXVSCROLL
);
1023 TempRect2
.right
-= GetSystemMetrics(SM_CXVSCROLL
);
1024 if (PtInRect(&TempRect2
, Point
))
1027 TempRect
.top
= TempRect2
.top
;
1028 TempRect
.bottom
= TempRect2
.bottom
;
1030 GetClientRect(Parent
, &ParentRect
);
1031 if (PtInRect(&TempRect
, Point
) && HASSIZEGRIP(wi
.dwStyle
, wi
.dwExStyle
,
1032 GetWindowLongW(Parent
, GWL_STYLE
), wi
.rcWindow
, ParentRect
))
1034 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1035 return HTBOTTOMLEFT
;
1037 return HTBOTTOMRIGHT
;
1042 if (wi
.dwStyle
& WS_VSCROLL
)
1044 RECT TempRect
= WindowRect
;
1046 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1047 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1049 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1050 if (PtInRect(&TempRect
, Point
))
1053 else if (wi
.dwStyle
& WS_HSCROLL
)
1055 RECT TempRect
= WindowRect
;
1056 TempRect
.top
= TempRect
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1057 if (PtInRect(&TempRect
, Point
))
1067 ThemeWndProc(HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, WNDPROC DefWndProc
)
1072 return ThemeHandleNCPaint(hWnd
, (HRGN
)wParam
);
1073 case WM_NCUAHDRAWCAPTION
:
1074 case WM_NCUAHDRAWFRAME
:
1076 ThemeHandleNCPaint(hWnd
, (HRGN
)1);
1078 case WM_NCMOUSEMOVE
:
1081 Point
.x
= GET_X_LPARAM(lParam
);
1082 Point
.y
= GET_Y_LPARAM(lParam
);
1083 return ThemeHandleNcMouseMove(hWnd
, wParam
, &Point
);
1085 case WM_NCMOUSELEAVE
:
1086 return ThemeHandleNcMouseLeave(hWnd
);
1087 case WM_NCLBUTTONDOWN
:
1094 ThemeHandleButton(hWnd
, wParam
);
1098 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1103 Point
.x
= GET_X_LPARAM(lParam
);
1104 Point
.y
= GET_Y_LPARAM(lParam
);
1105 return DefWndNCHitTest(hWnd
, Point
);
1109 if((wParam
& 0xfff0) == SC_VSCROLL
||
1110 (wParam
& 0xfff0) == SC_HSCROLL
)
1113 Pt
.x
= (short)LOWORD(lParam
);
1114 Pt
.y
= (short)HIWORD(lParam
);
1115 NC_TrackScrollBar(hWnd
, wParam
, Pt
);
1120 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1124 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1128 HRESULT WINAPI
DrawNCPreview(HDC hDC
,
1131 LPCWSTR pszThemeFileName
,
1132 LPCWSTR pszColorName
,
1133 LPCWSTR pszSizeName
,
1134 PNONCLIENTMETRICSW pncMetrics
,
1135 COLORREF
* lpaRgbValues
)
1137 WNDCLASSEXW DummyPreviewWindowClass
;
1140 HTHEMEFILE hThemeFile
;
1141 DRAW_CONTEXT context
;
1144 /* FIXME: We also need to implement drawing the rest of the preview windows
1145 * and make use of the ncmetrics and colors passed as parameters */
1147 /* Create a dummy window that will be used to trick the paint funtions */
1148 memset(&DummyPreviewWindowClass
, 0, sizeof(DummyPreviewWindowClass
));
1149 DummyPreviewWindowClass
.cbSize
= sizeof(DummyPreviewWindowClass
);
1150 DummyPreviewWindowClass
.lpszClassName
= L
"DummyPreviewWindowClass";
1151 DummyPreviewWindowClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1152 DummyPreviewWindowClass
.hInstance
= hDllInst
;
1153 DummyPreviewWindowClass
.lpfnWndProc
= DefWindowProcW
;
1154 if (!RegisterClassExW(&DummyPreviewWindowClass
))
1157 hwndDummy
= CreateWindowExW(0, L
"DummyPreviewWindowClass", L
"Active window", WS_OVERLAPPEDWINDOW
,30,30,300,150,0,0,hDllInst
,NULL
);
1161 hres
= OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, &hThemeFile
,0);
1165 /* Initialize the special draw context for the preview */
1167 context
.hWnd
= hwndDummy
;
1168 context
.theme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"WINDOW", 0);
1171 context
.scrolltheme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"SCROLLBAR", 0);
1174 context
.Active
= TRUE
;
1175 if (!GetWindowInfo(hwndDummy
, &context
.wi
))
1177 context
.wi
.dwStyle
|= WS_VISIBLE
;
1178 context
.CaptionHeight
= context
.wi
.cyWindowBorders
;
1179 context
.CaptionHeight
+= GetSystemMetrics(context
.wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
1180 context
.hRgn
= CreateRectRgnIndirect(&context
.wi
.rcWindow
);
1182 /* Paint the window on the preview hDC */
1183 rcCurrent
= context
.wi
.rcWindow
;
1184 ThemePaintWindow(&context
, &rcCurrent
, FALSE
);
1186 ThemeCleanupDrawContext(&context
);
1189 DestroyWindow(hwndDummy
);
1190 UnregisterClassW(L
"DummyPreviewWindowClass", hDllInst
);