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
))
357 int IconHeight
= GetSystemMetrics(SM_CYSMICON
);
358 int IconWidth
= GetSystemMetrics(SM_CXSMICON
);
359 DrawIconEx(pcontext
->hDC
, rcPart
.left
, rcPart
.top
, hIcon
, IconWidth
, IconHeight
, 0, NULL
, DI_NORMAL
);
360 rcPart
.left
+= IconWidth
+ 4;
365 /* Draw the caption */
368 /*FIXME: Use DrawThemeTextEx*/
369 ThemeDrawCaptionText(pcontext
->theme
,
374 lstrlenW(CaptionText
),
375 DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
,
379 HeapFree(GetProcessHeap(), 0, CaptionText
);
384 ThemeDrawBorders(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
387 int iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
389 /* Draw the bottom border */
390 rcPart
= *prcCurrent
;
391 rcPart
.top
= rcPart
.bottom
- pcontext
->wi
.cyWindowBorders
;
392 prcCurrent
->bottom
= rcPart
.top
;
393 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, WP_FRAMEBOTTOM
, iState
, &rcPart
, NULL
);
395 /* Draw the left border */
396 rcPart
= *prcCurrent
;
397 rcPart
.right
= rcPart
.left
+ pcontext
->wi
.cxWindowBorders
;
398 prcCurrent
->left
= rcPart
.right
;
399 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMELEFT
, iState
, &rcPart
, NULL
);
401 /* Draw the right border */
402 rcPart
= *prcCurrent
;
403 rcPart
.left
= rcPart
.right
- pcontext
->wi
.cxWindowBorders
;
404 prcCurrent
->right
= rcPart
.left
;
405 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMERIGHT
, iState
, &rcPart
, NULL
);
409 DrawClassicFrame(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
411 /* Draw outer edge */
412 if (UserHasWindowEdge(context
->wi
.dwStyle
, context
->wi
.dwExStyle
))
414 DrawEdge(context
->hDC
, prcCurrent
, EDGE_RAISED
, BF_RECT
| BF_ADJUST
);
416 else if (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
)
418 DrawEdge(context
->hDC
, prcCurrent
, BDR_SUNKENINNER
, BF_RECT
| BF_ADJUST
| BF_FLAT
);
421 /* Firstly the "thick" frame */
422 if ((context
->wi
.dwStyle
& WS_THICKFRAME
) && !(context
->wi
.dwStyle
& WS_MINIMIZE
))
425 (GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
)) *
426 GetSystemMetrics(SM_CXBORDER
);
428 (GetSystemMetrics(SM_CYFRAME
) - GetSystemMetrics(SM_CYDLGFRAME
)) *
429 GetSystemMetrics(SM_CYBORDER
);
431 SelectObject(context
->hDC
, GetSysColorBrush(
432 context
->Active
? COLOR_ACTIVEBORDER
: COLOR_INACTIVEBORDER
));
435 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
436 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
437 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
438 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
439 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
440 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
441 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
442 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
444 InflateRect(prcCurrent
, -Width
, -Height
);
447 /* Now the other bit of the frame */
448 if (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_BORDER
) || context
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
)
450 INT Width
= GetSystemMetrics(SM_CXBORDER
);
451 INT Height
= GetSystemMetrics(SM_CYBORDER
);
453 SelectObject(context
->hDC
, GetSysColorBrush(
454 (context
->wi
.dwExStyle
& (WS_EX_DLGMODALFRAME
| WS_EX_CLIENTEDGE
)) ? COLOR_3DFACE
:
455 (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
) ? COLOR_WINDOWFRAME
:
456 (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) ? COLOR_3DFACE
:
460 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
461 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
462 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
463 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
464 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
465 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
466 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
467 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
469 InflateRect(prcCurrent
, -Width
, -Height
);
472 if (context
->wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
474 DrawEdge(context
->hDC
, prcCurrent
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
479 ThemeDrawMenuItem(PDRAW_CONTEXT pcontext
, HMENU Menu
, int imenu
)
482 BOOL flat_menu
= FALSE
;
485 WCHAR wstrItemText
[20];
487 HFONT FontOld
= NULL
;
488 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
490 Item
.cbSize
= sizeof(MENUITEMINFOW
);
491 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
492 Item
.dwTypeData
= wstrItemText
;
494 if (!GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
))
497 if(Item
.fType
& MF_SEPARATOR
)
503 Item
.dwTypeData
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, Item
.cch
* sizeof(WCHAR
));
504 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
505 GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
);
511 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
513 GetMenuItemRect(pcontext
->hWnd
, Menu
, imenu
, &Rect
);
516 OffsetRect(&Rect
, -pcontext
->wi
.rcClient
.left
, -pcontext
->wi
.rcClient
.top
);
518 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
521 SetBkColor(pcontext
->hDC
, GetSysColor(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
522 SetTextColor(pcontext
->hDC
, GetSysColor(Item
.fState
& MF_GRAYED
? COLOR_GRAYTEXT
: COLOR_MENUTEXT
));
524 if (0 != (Item
.fState
& MFS_DEFAULT
))
526 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFontBold
);
529 Rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
530 Rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
532 Text
= (PWCHAR
) Item
.dwTypeData
;
535 for (i
= 0; L
'\0' != Text
[i
]; i
++)
537 if (L
'\t' == Text
[i
] || L
'\b' == Text
[i
])
544 SetBkMode(pcontext
->hDC
, OPAQUE
);
546 if (0 != (Item
.fState
& MF_GRAYED
))
548 if (0 == (Item
.fState
& MF_HILITE
))
550 ++Rect
.left
; ++Rect
.top
; ++Rect
.right
; ++Rect
.bottom
;
551 SetTextColor(pcontext
->hDC
, RGB(0xff, 0xff, 0xff));
552 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
553 --Rect
.left
; --Rect
.top
; --Rect
.right
; --Rect
.bottom
;
555 SetTextColor(pcontext
->hDC
, RGB(0x80, 0x80, 0x80));
556 SetBkMode(pcontext
->hDC
, TRANSPARENT
);
559 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
561 /* Exclude from the clip region the area drawn by DrawText */
562 SetRect(&rcCalc
, 0,0,0,0);
563 DrawTextW(pcontext
->hDC
, Text
, i
, &rcCalc
, uFormat
| DT_CALCRECT
);
564 InflateRect( &Rect
, 0, -(rcCalc
.bottom
+1)/2);
565 ExcludeClipRect(pcontext
->hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
569 SelectObject(pcontext
->hDC
, FontOld
);
574 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext
, PRECT prcCurrent
)
577 MENUBARINFO MenuBarInfo
;
579 HFONT FontOld
= NULL
;
587 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
589 MenuBarInfo
.cbSize
= sizeof(MENUBARINFO
);
590 if (! GetMenuBarInfo(pcontext
->hWnd
, OBJID_MENU
, 0, &MenuBarInfo
))
593 Menu
= GetMenu(pcontext
->hWnd
);
594 if (GetMenuItemCount(Menu
) == 0)
597 Rect
= MenuBarInfo
.rcBar
;
598 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
600 /* Draw a line under the menu*/
601 oldPen
= (HPEN
)SelectObject(pcontext
->hDC
, GetStockObject(DC_PEN
));
602 SetDCPenColor(pcontext
->hDC
, GetSysColor(COLOR_3DFACE
));
603 MoveToEx(pcontext
->hDC
, Rect
.left
, Rect
.bottom
, NULL
);
604 LineTo(pcontext
->hDC
, Rect
.right
, Rect
.bottom
);
605 SelectObject(pcontext
->hDC
, oldPen
);
607 /* Draw menu items */
608 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFont
);
610 for (i
= 0; i
< GetMenuItemCount(Menu
); i
++)
612 ThemeDrawMenuItem(pcontext
, Menu
, i
);
615 SelectObject(pcontext
->hDC
, FontOld
);
617 /* Fill the menu background area that isn't painted yet*/
618 FillRect(pcontext
->hDC
, &Rect
, GetSysColorBrush(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
622 ThemePaintWindow(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
, BOOL bDoDoubleBuffering
)
624 if(!(pcontext
->wi
.dwStyle
& WS_VISIBLE
))
627 if(pcontext
->wi
.dwStyle
& WS_MINIMIZE
)
629 ThemeDrawTitle(pcontext
, prcCurrent
);
633 if((pcontext
->wi
.dwStyle
& WS_CAPTION
)==WS_CAPTION
)
635 if (bDoDoubleBuffering
)
636 ThemeStartBufferedPaint(pcontext
, prcCurrent
->right
, pcontext
->CaptionHeight
);
637 ThemeDrawCaption(pcontext
, prcCurrent
);
638 if (bDoDoubleBuffering
)
639 ThemeEndBufferedPaint(pcontext
, 0, 0, prcCurrent
->right
, pcontext
->CaptionHeight
);
640 ThemeDrawBorders(pcontext
, prcCurrent
);
644 DrawClassicFrame(pcontext
, prcCurrent
);
647 if(HAS_MENU(pcontext
->hWnd
, pcontext
->wi
.dwStyle
))
648 ThemeDrawMenuBar(pcontext
, prcCurrent
);
650 if(pcontext
->wi
.dwStyle
& WS_HSCROLL
)
651 ThemeDrawScrollBar(pcontext
, SB_HORZ
, NULL
);
653 if(pcontext
->wi
.dwStyle
& WS_VSCROLL
)
654 ThemeDrawScrollBar(pcontext
, SB_VERT
, NULL
);
662 ThemeHandleNCPaint(HWND hWnd
, HRGN hRgn
)
664 DRAW_CONTEXT context
;
667 ThemeInitDrawContext(&context
, hWnd
, hRgn
);
669 rcCurrent
= context
.wi
.rcWindow
;
670 OffsetRect( &rcCurrent
, -context
.wi
.rcWindow
.left
, -context
.wi
.rcWindow
.top
);
672 ThemePaintWindow(&context
, &rcCurrent
, TRUE
);
673 ThemeCleanupDrawContext(&context
);
679 ThemeHandleNcMouseMove(HWND hWnd
, DWORD ht
, POINT
* pt
)
681 DRAW_CONTEXT context
;
684 PWND_CONTEXT pcontext
;
686 /* First of all check if we have something to do here */
687 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
688 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
691 /* Get theme data for this window */
692 pcontext
= ThemeGetWndContext(hWnd
);
693 if (pcontext
== NULL
)
696 /* Begin tracking in the non client area if we are not tracking yet */
697 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
698 tme
.dwFlags
= TME_QUERY
;
699 tme
.hwndTrack
= hWnd
;
700 TrackMouseEvent(&tme
);
701 if (tme
.dwFlags
!= (TME_LEAVE
| TME_NONCLIENT
))
703 tme
.hwndTrack
= hWnd
;
704 tme
.dwFlags
= TME_LEAVE
| TME_NONCLIENT
;
705 TrackMouseEvent(&tme
);
708 /* Dont do any drawing if the hit test wasn't changed */
709 if (ht
== pcontext
->lastHitTest
)
712 ThemeInitDrawContext(&context
, hWnd
, 0);
713 if (context
.wi
.dwStyle
& WS_SYSMENU
)
715 if (HT_ISBUTTON(ht
) || HT_ISBUTTON(pcontext
->lastHitTest
))
716 ThemeDrawCaptionButtons(&context
, ht
, 0);
719 if (context
.wi
.dwStyle
& WS_HSCROLL
)
721 if (ht
== HTHSCROLL
|| pcontext
->lastHitTest
== HTHSCROLL
)
722 ThemeDrawScrollBar(&context
, SB_HORZ
, ht
== HTHSCROLL
? pt
: NULL
);
725 if (context
.wi
.dwStyle
& WS_VSCROLL
)
727 if (ht
== HTVSCROLL
|| pcontext
->lastHitTest
== HTVSCROLL
)
728 ThemeDrawScrollBar(&context
, SB_VERT
, ht
== HTVSCROLL
? pt
: NULL
);
730 ThemeCleanupDrawContext(&context
);
732 pcontext
->lastHitTest
= ht
;
738 ThemeHandleNcMouseLeave(HWND hWnd
)
740 DRAW_CONTEXT context
;
742 PWND_CONTEXT pWndContext
;
744 /* First of all check if we have something to do here */
745 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
746 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
749 /* Get theme data for this window */
750 pWndContext
= ThemeGetWndContext(hWnd
);
751 if (pWndContext
== NULL
)
754 ThemeInitDrawContext(&context
, hWnd
, 0);
755 if (context
.wi
.dwStyle
& WS_SYSMENU
&& HT_ISBUTTON(pWndContext
->lastHitTest
))
756 ThemeDrawCaptionButtons(&context
, 0, 0);
758 if (context
.wi
.dwStyle
& WS_HSCROLL
&& pWndContext
->lastHitTest
== HTHSCROLL
)
759 ThemeDrawScrollBar(&context
, SB_HORZ
, NULL
);
761 if (context
.wi
.dwStyle
& WS_VSCROLL
&& pWndContext
->lastHitTest
== HTVSCROLL
)
762 ThemeDrawScrollBar(&context
, SB_VERT
, NULL
);
764 ThemeCleanupDrawContext(&context
);
766 pWndContext
->lastHitTest
= HTNOWHERE
;
772 ThemeHandleButton(HWND hWnd
, WPARAM wParam
)
778 DRAW_CONTEXT context
;
779 PWND_CONTEXT pWndContext
;
781 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
782 if (!((Style
& WS_CAPTION
) && (Style
& WS_SYSMENU
)))
791 if (!(Style
& WS_MINIMIZEBOX
))
793 SCMsg
= ((Style
& WS_MINIMIZE
) ? SC_RESTORE
: SC_MINIMIZE
);
796 if (!(Style
& WS_MAXIMIZEBOX
))
798 SCMsg
= ((Style
& WS_MAXIMIZE
) ? SC_RESTORE
: SC_MAXIMIZE
);
804 /* Get theme data for this window */
805 pWndContext
= ThemeGetWndContext(hWnd
);
806 if (pWndContext
== NULL
)
809 ThemeInitDrawContext(&context
, hWnd
, 0);
810 ThemeDrawCaptionButtons(&context
, 0, wParam
);
811 pWndContext
->lastHitTest
= wParam
;
817 if (GetMessageW(&Msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
) <= 0)
820 if (Msg
.message
== WM_LBUTTONUP
)
823 if (Msg
.message
!= WM_MOUSEMOVE
)
826 ht
= SendMessage(hWnd
, WM_NCHITTEST
, 0, MAKELPARAM(Msg
.pt
.x
, Msg
.pt
.y
));
827 Pressed
= (ht
== wParam
);
829 /* Only draw the buttons if the hit test changed */
830 if (ht
!= pWndContext
->lastHitTest
&&
831 (HT_ISBUTTON(ht
) || HT_ISBUTTON(pWndContext
->lastHitTest
)))
833 ThemeDrawCaptionButtons(&context
, 0, Pressed
? wParam
: 0);
834 pWndContext
->lastHitTest
= ht
;
838 ThemeDrawCaptionButtons(&context
, ht
, 0);
839 ThemeCleanupDrawContext(&context
);
844 SendMessageW(hWnd
, WM_SYSCOMMAND
, SCMsg
, 0);
849 DefWndNCHitTest(HWND hWnd
, POINT Point
)
855 GetWindowInfo(hWnd
, &wi
);
857 if (!PtInRect(&wi
.rcWindow
, Point
))
861 WindowRect
= wi
.rcWindow
;
863 if (UserHasWindowEdge(wi
.dwStyle
, wi
.dwExStyle
))
867 InflateRect(&WindowRect
, -(int)wi
.cxWindowBorders
, -(int)wi
.cyWindowBorders
);
868 XSize
= GetSystemMetrics(SM_CXSIZE
) * GetSystemMetrics(SM_CXBORDER
);
869 YSize
= GetSystemMetrics(SM_CYSIZE
) * GetSystemMetrics(SM_CYBORDER
);
870 if (!PtInRect(&WindowRect
, Point
))
874 ThickFrame
= (wi
.dwStyle
& WS_THICKFRAME
);
875 if (Point
.y
< WindowRect
.top
)
877 if(wi
.dwStyle
& WS_MINIMIZE
)
881 if (Point
.x
< (WindowRect
.left
+ XSize
))
883 if (Point
.x
>= (WindowRect
.right
- XSize
))
887 if (Point
.y
>= WindowRect
.bottom
)
889 if(wi
.dwStyle
& WS_MINIMIZE
)
893 if (Point
.x
< (WindowRect
.left
+ XSize
))
895 if (Point
.x
>= (WindowRect
.right
- XSize
))
896 return HTBOTTOMRIGHT
;
899 if (Point
.x
< WindowRect
.left
)
901 if(wi
.dwStyle
& WS_MINIMIZE
)
905 if (Point
.y
< (WindowRect
.top
+ YSize
))
907 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
911 if (Point
.x
>= WindowRect
.right
)
913 if(wi
.dwStyle
& WS_MINIMIZE
)
917 if (Point
.y
< (WindowRect
.top
+ YSize
))
919 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
920 return HTBOTTOMRIGHT
;
927 if (wi
.dwExStyle
& WS_EX_STATICEDGE
)
928 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
929 -GetSystemMetrics(SM_CYBORDER
));
930 if (!PtInRect(&WindowRect
, Point
))
934 if ((wi
.dwStyle
& WS_CAPTION
) == WS_CAPTION
)
936 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
937 WindowRect
.top
+= GetSystemMetrics(SM_CYSMCAPTION
);
939 WindowRect
.top
+= GetSystemMetrics(SM_CYCAPTION
);
941 if (!PtInRect(&WindowRect
, Point
))
946 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
947 ButtonWidth
= GetSystemMetrics(SM_CXSMSIZE
);
949 ButtonWidth
= GetSystemMetrics(SM_CXSIZE
);
952 ButtonWidth
+= BUTTON_GAP_SIZE
;
954 if (wi
.dwStyle
& WS_SYSMENU
)
956 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
958 WindowRect
.right
-= ButtonWidth
;
962 if(!(wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
963 WindowRect
.left
+= ButtonWidth
;
964 WindowRect
.right
-= ButtonWidth
;
967 if (Point
.x
< WindowRect
.left
)
969 if (WindowRect
.right
<= Point
.x
)
971 if (wi
.dwStyle
& WS_MAXIMIZEBOX
|| wi
.dwStyle
& WS_MINIMIZEBOX
)
972 WindowRect
.right
-= ButtonWidth
;
973 if (Point
.x
>= WindowRect
.right
)
975 if (wi
.dwStyle
& WS_MINIMIZEBOX
)
976 WindowRect
.right
-= ButtonWidth
;
977 if (Point
.x
>= WindowRect
.right
)
983 if(!(wi
.dwStyle
& WS_MINIMIZE
))
988 ScreenToClient(hWnd
, &ClientPoint
);
989 GetClientRect(hWnd
, &wi
.rcClient
);
991 if (PtInRect(&wi
.rcClient
, ClientPoint
))
996 if ((menu
= GetMenu(hWnd
)) && !(wi
.dwStyle
& WS_CHILD
))
998 if (Point
.x
> 0 && Point
.x
< WindowRect
.right
&& ClientPoint
.y
< 0)
1002 if (wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
1004 InflateRect(&WindowRect
, -2 * GetSystemMetrics(SM_CXBORDER
),
1005 -2 * GetSystemMetrics(SM_CYBORDER
));
1008 if ((wi
.dwStyle
& WS_VSCROLL
) && (wi
.dwStyle
& WS_HSCROLL
) &&
1009 (WindowRect
.bottom
- WindowRect
.top
) > GetSystemMetrics(SM_CYHSCROLL
))
1011 RECT ParentRect
, TempRect
= WindowRect
, TempRect2
= WindowRect
;
1012 HWND Parent
= GetParent(hWnd
);
1014 TempRect
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
1015 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1016 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1018 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1019 if (PtInRect(&TempRect
, Point
))
1022 TempRect2
.top
= TempRect2
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1023 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1024 TempRect2
.left
+= GetSystemMetrics(SM_CXVSCROLL
);
1026 TempRect2
.right
-= GetSystemMetrics(SM_CXVSCROLL
);
1027 if (PtInRect(&TempRect2
, Point
))
1030 TempRect
.top
= TempRect2
.top
;
1031 TempRect
.bottom
= TempRect2
.bottom
;
1033 GetClientRect(Parent
, &ParentRect
);
1034 if (PtInRect(&TempRect
, Point
) && HASSIZEGRIP(wi
.dwStyle
, wi
.dwExStyle
,
1035 GetWindowLongW(Parent
, GWL_STYLE
), wi
.rcWindow
, ParentRect
))
1037 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1038 return HTBOTTOMLEFT
;
1040 return HTBOTTOMRIGHT
;
1045 if (wi
.dwStyle
& WS_VSCROLL
)
1047 RECT TempRect
= WindowRect
;
1049 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1050 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1052 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1053 if (PtInRect(&TempRect
, Point
))
1056 else if (wi
.dwStyle
& WS_HSCROLL
)
1058 RECT TempRect
= WindowRect
;
1059 TempRect
.top
= TempRect
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1060 if (PtInRect(&TempRect
, Point
))
1070 ThemeWndProc(HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, WNDPROC DefWndProc
)
1075 return ThemeHandleNCPaint(hWnd
, (HRGN
)wParam
);
1076 case WM_NCUAHDRAWCAPTION
:
1077 case WM_NCUAHDRAWFRAME
:
1079 ThemeHandleNCPaint(hWnd
, (HRGN
)1);
1081 case WM_NCMOUSEMOVE
:
1084 Point
.x
= GET_X_LPARAM(lParam
);
1085 Point
.y
= GET_Y_LPARAM(lParam
);
1086 return ThemeHandleNcMouseMove(hWnd
, wParam
, &Point
);
1088 case WM_NCMOUSELEAVE
:
1089 return ThemeHandleNcMouseLeave(hWnd
);
1090 case WM_NCLBUTTONDOWN
:
1097 ThemeHandleButton(hWnd
, wParam
);
1101 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1106 Point
.x
= GET_X_LPARAM(lParam
);
1107 Point
.y
= GET_Y_LPARAM(lParam
);
1108 return DefWndNCHitTest(hWnd
, Point
);
1112 if((wParam
& 0xfff0) == SC_VSCROLL
||
1113 (wParam
& 0xfff0) == SC_HSCROLL
)
1116 Pt
.x
= (short)LOWORD(lParam
);
1117 Pt
.y
= (short)HIWORD(lParam
);
1118 NC_TrackScrollBar(hWnd
, wParam
, Pt
);
1123 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1127 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1131 HRESULT WINAPI
DrawNCPreview(HDC hDC
,
1134 LPCWSTR pszThemeFileName
,
1135 LPCWSTR pszColorName
,
1136 LPCWSTR pszSizeName
,
1137 PNONCLIENTMETRICSW pncMetrics
,
1138 COLORREF
* lpaRgbValues
)
1140 WNDCLASSEXW DummyPreviewWindowClass
;
1143 HTHEMEFILE hThemeFile
;
1144 DRAW_CONTEXT context
;
1147 /* FIXME: We also need to implement drawing the rest of the preview windows
1148 * and make use of the ncmetrics and colors passed as parameters */
1150 /* Create a dummy window that will be used to trick the paint funtions */
1151 memset(&DummyPreviewWindowClass
, 0, sizeof(DummyPreviewWindowClass
));
1152 DummyPreviewWindowClass
.cbSize
= sizeof(DummyPreviewWindowClass
);
1153 DummyPreviewWindowClass
.lpszClassName
= L
"DummyPreviewWindowClass";
1154 DummyPreviewWindowClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1155 DummyPreviewWindowClass
.hInstance
= hDllInst
;
1156 DummyPreviewWindowClass
.lpfnWndProc
= DefWindowProcW
;
1157 if (!RegisterClassExW(&DummyPreviewWindowClass
))
1160 hwndDummy
= CreateWindowExW(0, L
"DummyPreviewWindowClass", L
"Active window", WS_OVERLAPPEDWINDOW
,30,30,300,150,0,0,hDllInst
,NULL
);
1164 hres
= OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, &hThemeFile
,0);
1168 /* Initialize the special draw context for the preview */
1170 context
.hWnd
= hwndDummy
;
1171 context
.theme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"WINDOW", 0);
1174 context
.scrolltheme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"SCROLLBAR", 0);
1177 context
.Active
= TRUE
;
1178 if (!GetWindowInfo(hwndDummy
, &context
.wi
))
1180 context
.wi
.dwStyle
|= WS_VISIBLE
;
1181 context
.CaptionHeight
= context
.wi
.cyWindowBorders
;
1182 context
.CaptionHeight
+= GetSystemMetrics(context
.wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
1183 context
.hRgn
= CreateRectRgnIndirect(&context
.wi
.rcWindow
);
1185 /* Paint the window on the preview hDC */
1186 rcCurrent
= context
.wi
.rcWindow
;
1187 ThemePaintWindow(&context
, &rcCurrent
, FALSE
);
1189 ThemeCleanupDrawContext(&context
);
1192 DestroyWindow(hwndDummy
);
1193 UnregisterClassW(L
"DummyPreviewWindowClass", hDllInst
);