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
)
62 if (Style
== WS_DLGFRAME
|| Style
== WS_CAPTION
)
68 UserGetWindowIcon(PDRAW_CONTEXT pcontext
)
72 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_SMALL2
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
75 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_SMALL
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
78 SendMessageTimeout(pcontext
->hWnd
, WM_GETICON
, ICON_BIG
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
81 hIcon
= (HICON
)GetClassLong(pcontext
->hWnd
, GCL_HICONSM
);
84 hIcon
= (HICON
)GetClassLong(pcontext
->hWnd
, GCL_HICON
);
86 // See also win32ss/user/ntuser/nonclient.c!NC_IconForWindow
87 if (!hIcon
&& !(pcontext
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
88 hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_WINLOGO
);
93 WCHAR
*UserGetWindowCaption(HWND hwnd
)
97 text
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
98 if (text
) InternalGetWindowText(hwnd
, text
, len
);
103 ThemeDrawTitle(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
108 HRESULT WINAPI
ThemeDrawCaptionText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
109 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
110 DWORD dwTextFlags2
, const RECT
*pRect
, BOOL Active
)
114 HGDIOBJ oldFont
= NULL
;
117 COLORREF oldTextColor
;
121 hr
= GetThemeSysFont(0,TMT_CAPTIONFONT
,&logfont
);
124 hFont
= CreateFontIndirectW(&logfont
);
126 CopyRect(&rt
, pRect
);
128 oldFont
= SelectObject(hdc
, hFont
);
130 if(dwTextFlags2
& DTT_GRAYED
)
131 textColor
= GetSysColor(COLOR_GRAYTEXT
);
133 textColor
= GetSysColor(COLOR_INACTIVECAPTIONTEXT
);
135 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
137 oldTextColor
= SetTextColor(hdc
, textColor
);
138 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
139 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
140 SetBkMode(hdc
, oldBkMode
);
141 SetTextColor(hdc
, oldTextColor
);
144 SelectObject(hdc
, oldFont
);
151 ThemeInitDrawContext(PDRAW_CONTEXT pcontext
,
155 pcontext
->wi
.cbSize
= sizeof(pcontext
->wi
);
156 GetWindowInfo(hWnd
, &pcontext
->wi
);
157 pcontext
->hWnd
= hWnd
;
158 pcontext
->Active
= IsWindowActive(hWnd
, pcontext
->wi
.dwExStyle
);
159 pcontext
->theme
= MSSTYLES_OpenThemeClass(ActiveThemeFile
, NULL
, L
"WINDOW");
160 pcontext
->scrolltheme
= MSSTYLES_OpenThemeClass(ActiveThemeFile
, NULL
, L
"SCROLLBAR");
162 pcontext
->CaptionHeight
= pcontext
->wi
.cyWindowBorders
;
163 pcontext
->CaptionHeight
+= GetSystemMetrics(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
167 hRgn
= CreateRectRgnIndirect(&pcontext
->wi
.rcWindow
);
169 pcontext
->hRgn
= hRgn
;
171 pcontext
->hDC
= GetDCEx(hWnd
, hRgn
, DCX_WINDOW
| DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
);
175 ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext
)
177 ReleaseDC(pcontext
->hWnd
,pcontext
->hDC
);
179 CloseThemeData (pcontext
->theme
);
180 CloseThemeData (pcontext
->scrolltheme
);
182 if(pcontext
->hRgn
!= NULL
)
184 DeleteObject(pcontext
->hRgn
);
189 ThemeStartBufferedPaint(PDRAW_CONTEXT pcontext
, int cx
, int cy
)
193 pcontext
->hDCScreen
= pcontext
->hDC
;
194 pcontext
->hDC
= CreateCompatibleDC(pcontext
->hDCScreen
);
195 hbmp
= CreateCompatibleBitmap(pcontext
->hDCScreen
, cx
, cy
);
196 pcontext
->hbmpOld
= (HBITMAP
)SelectObject(pcontext
->hDC
, hbmp
);
200 ThemeEndBufferedPaint(PDRAW_CONTEXT pcontext
, int x
, int y
, int cx
, int cy
)
203 BitBlt(pcontext
->hDCScreen
, 0, 0, cx
, cy
, pcontext
->hDC
, x
, y
, SRCCOPY
);
204 hbmp
= (HBITMAP
) SelectObject(pcontext
->hDC
, pcontext
->hbmpOld
);
205 DeleteObject(pcontext
->hDC
);
208 pcontext
->hDC
= pcontext
->hDCScreen
;
212 ThemeDrawCaptionButton(PDRAW_CONTEXT pcontext
,
214 CAPTIONBUTTON buttonId
,
218 INT ButtonWidth
, ButtonHeight
, iPartId
;
220 ButtonHeight
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMSIZE
: SM_CYSIZE
);
221 ButtonWidth
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CXSMSIZE
: SM_CXSIZE
);
226 iPartId
= pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? WP_SMALLCLOSEBUTTON
: WP_CLOSEBUTTON
;
230 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
232 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
235 iStateId
= BUTTON_DISABLED
;
238 iPartId
= pcontext
->wi
.dwStyle
& WS_MAXIMIZE
? WP_RESTOREBUTTON
: WP_MAXBUTTON
;
242 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
244 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
247 iStateId
= BUTTON_DISABLED
;
250 iPartId
= WP_MINBUTTON
;
254 //FIXME: Implement Help Button
261 /* Calculate the position */
262 rcPart
.top
= prcCurrent
->top
;
263 rcPart
.right
= prcCurrent
->right
;
264 rcPart
.bottom
= rcPart
.top
+ ButtonHeight
;
265 rcPart
.left
= rcPart
.right
- ButtonWidth
;
266 prcCurrent
->right
-= ButtonWidth
+ BUTTON_GAP_SIZE
;
268 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, iPartId
, iStateId
, &rcPart
, NULL
);
272 ThemeGetButtonState(DWORD htCurrect
, DWORD htHot
, DWORD htDown
, BOOL Active
)
274 if (htHot
== htCurrect
)
277 return BUTTON_INACTIVE
;
278 if (htDown
== htCurrect
)
279 return BUTTON_PRESSED
;
281 return BUTTON_NORMAL
;
284 /* Used only from mouse event handlers */
286 ThemeDrawCaptionButtons(PDRAW_CONTEXT pcontext
, DWORD htHot
, DWORD htDown
)
290 /* Calculate the area of the caption */
291 rcCurrent
.top
= rcCurrent
.left
= 0;
292 rcCurrent
.right
= pcontext
->wi
.rcWindow
.right
- pcontext
->wi
.rcWindow
.left
;
293 rcCurrent
.bottom
= pcontext
->CaptionHeight
;
295 /* Add a padding around the objects of the caption */
296 InflateRect(&rcCurrent
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
297 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
299 /* Draw the buttons */
300 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, CLOSEBUTTON
,
301 ThemeGetButtonState(HTCLOSE
, htHot
, htDown
, pcontext
->Active
));
302 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MAXBUTTON
,
303 ThemeGetButtonState(HTMAXBUTTON
, htHot
, htDown
, pcontext
->Active
));
304 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MINBUTTON
,
305 ThemeGetButtonState(HTMINBUTTON
, htHot
, htDown
, pcontext
->Active
));
306 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, HELPBUTTON
,
307 ThemeGetButtonState(HTHELP
, htHot
, htDown
, pcontext
->Active
));
310 /* Used from WM_NCPAINT and WM_NCACTIVATE handlers */
312 ThemeDrawCaption(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
319 // See also win32ss/user/ntuser/nonclient.c!UserDrawCaptionBar
320 // and win32ss/user/ntuser/nonclient.c!UserDrawCaption
321 if ((pcontext
->wi
.dwStyle
& WS_SYSMENU
) && !(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
))
322 hIcon
= UserGetWindowIcon(pcontext
);
326 CaptionText
= UserGetWindowCaption(pcontext
->hWnd
);
328 /* Get the caption part and state id */
329 if (pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
330 iPart
= WP_SMALLCAPTION
;
331 else if (pcontext
->wi
.dwStyle
& WS_MAXIMIZE
)
332 iPart
= WP_MAXCAPTION
;
336 iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
338 /* Draw the caption background */
339 rcPart
= *prcCurrent
;
340 rcPart
.bottom
= rcPart
.top
+ pcontext
->CaptionHeight
;
341 prcCurrent
->top
= rcPart
.bottom
;
342 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,iPart
,iState
,&rcPart
,NULL
);
344 /* Add a padding around the objects of the caption */
345 InflateRect(&rcPart
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
346 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
348 /* Draw the caption buttons */
349 if (pcontext
->wi
.dwStyle
& WS_SYSMENU
)
351 iState
= pcontext
->Active
? BUTTON_NORMAL
: BUTTON_INACTIVE
;
353 ThemeDrawCaptionButton(pcontext
, &rcPart
, CLOSEBUTTON
, iState
);
354 ThemeDrawCaptionButton(pcontext
, &rcPart
, MAXBUTTON
, iState
);
355 ThemeDrawCaptionButton(pcontext
, &rcPart
, MINBUTTON
, iState
);
356 ThemeDrawCaptionButton(pcontext
, &rcPart
, HELPBUTTON
, iState
);
364 int IconHeight
= GetSystemMetrics(SM_CYSMICON
);
365 int IconWidth
= GetSystemMetrics(SM_CXSMICON
);
366 DrawIconEx(pcontext
->hDC
, rcPart
.left
, rcPart
.top
, hIcon
, IconWidth
, IconHeight
, 0, NULL
, DI_NORMAL
);
367 rcPart
.left
+= IconWidth
+ 4;
372 /* Draw the caption */
375 /* FIXME: Use DrawThemeTextEx */
376 ThemeDrawCaptionText(pcontext
->theme
,
381 lstrlenW(CaptionText
),
382 DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
,
386 HeapFree(GetProcessHeap(), 0, CaptionText
);
391 ThemeDrawBorders(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
394 int iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
396 /* Draw the bottom border */
397 rcPart
= *prcCurrent
;
398 rcPart
.top
= rcPart
.bottom
- pcontext
->wi
.cyWindowBorders
;
399 prcCurrent
->bottom
= rcPart
.top
;
400 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, WP_FRAMEBOTTOM
, iState
, &rcPart
, NULL
);
402 /* Draw the left border */
403 rcPart
= *prcCurrent
;
404 rcPart
.right
= rcPart
.left
+ pcontext
->wi
.cxWindowBorders
;
405 prcCurrent
->left
= rcPart
.right
;
406 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMELEFT
, iState
, &rcPart
, NULL
);
408 /* Draw the right border */
409 rcPart
= *prcCurrent
;
410 rcPart
.left
= rcPart
.right
- pcontext
->wi
.cxWindowBorders
;
411 prcCurrent
->right
= rcPart
.left
;
412 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMERIGHT
, iState
, &rcPart
, NULL
);
416 DrawClassicFrame(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
418 /* Draw outer edge */
419 if (UserHasWindowEdge(context
->wi
.dwStyle
, context
->wi
.dwExStyle
))
421 DrawEdge(context
->hDC
, prcCurrent
, EDGE_RAISED
, BF_RECT
| BF_ADJUST
);
423 else if (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
)
425 DrawEdge(context
->hDC
, prcCurrent
, BDR_SUNKENINNER
, BF_RECT
| BF_ADJUST
| BF_FLAT
);
428 /* Firstly the "thick" frame */
429 if ((context
->wi
.dwStyle
& WS_THICKFRAME
) && !(context
->wi
.dwStyle
& WS_MINIMIZE
))
432 (GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
)) *
433 GetSystemMetrics(SM_CXBORDER
);
435 (GetSystemMetrics(SM_CYFRAME
) - GetSystemMetrics(SM_CYDLGFRAME
)) *
436 GetSystemMetrics(SM_CYBORDER
);
438 SelectObject(context
->hDC
, GetSysColorBrush(
439 context
->Active
? COLOR_ACTIVEBORDER
: COLOR_INACTIVEBORDER
));
442 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
443 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
444 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
445 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
446 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
- 1,
447 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
448 PatBlt(context
->hDC
, prcCurrent
->right
- 1, prcCurrent
->top
,
449 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
451 InflateRect(prcCurrent
, -Width
, -Height
);
454 /* Now the other bit of the frame */
455 if (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_BORDER
) || (context
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
457 INT Width
= GetSystemMetrics(SM_CXBORDER
);
458 INT Height
= GetSystemMetrics(SM_CYBORDER
);
460 SelectObject(context
->hDC
, GetSysColorBrush(
461 (context
->wi
.dwExStyle
& (WS_EX_DLGMODALFRAME
| WS_EX_CLIENTEDGE
)) ? COLOR_3DFACE
:
462 (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
) ? COLOR_WINDOWFRAME
:
463 (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) ? COLOR_3DFACE
:
467 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
468 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
469 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
470 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
471 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
- 1,
472 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
473 PatBlt(context
->hDC
, prcCurrent
->right
- 1, prcCurrent
->top
,
474 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
476 InflateRect(prcCurrent
, -Width
, -Height
);
479 if (context
->wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
481 DrawEdge(context
->hDC
, prcCurrent
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
486 ThemeDrawMenuItem(PDRAW_CONTEXT pcontext
, HMENU Menu
, int imenu
)
489 BOOL flat_menu
= FALSE
;
492 WCHAR wstrItemText
[20];
494 HFONT FontOld
= NULL
;
495 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
497 Item
.cbSize
= sizeof(MENUITEMINFOW
);
498 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
499 Item
.dwTypeData
= wstrItemText
;
501 if (!GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
))
504 if(Item
.fType
& MF_SEPARATOR
)
510 Item
.dwTypeData
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, Item
.cch
* sizeof(WCHAR
));
511 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
512 GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
);
518 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
520 GetMenuItemRect(pcontext
->hWnd
, Menu
, imenu
, &Rect
);
522 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
524 SetBkColor(pcontext
->hDC
, GetSysColor(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
525 SetTextColor(pcontext
->hDC
, GetSysColor(Item
.fState
& MF_GRAYED
? COLOR_GRAYTEXT
: COLOR_MENUTEXT
));
527 if (0 != (Item
.fState
& MFS_DEFAULT
))
529 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFontBold
);
532 Rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
533 Rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
535 Text
= (PWCHAR
) Item
.dwTypeData
;
538 for (i
= 0; L
'\0' != Text
[i
]; i
++)
540 if (L
'\t' == Text
[i
] || L
'\b' == Text
[i
])
547 SetBkMode(pcontext
->hDC
, OPAQUE
);
549 if (0 != (Item
.fState
& MF_GRAYED
))
551 if (0 == (Item
.fState
& MF_HILITE
))
553 ++Rect
.left
; ++Rect
.top
; ++Rect
.right
; ++Rect
.bottom
;
554 SetTextColor(pcontext
->hDC
, RGB(0xff, 0xff, 0xff));
555 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
556 --Rect
.left
; --Rect
.top
; --Rect
.right
; --Rect
.bottom
;
558 SetTextColor(pcontext
->hDC
, RGB(0x80, 0x80, 0x80));
559 SetBkMode(pcontext
->hDC
, TRANSPARENT
);
562 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
564 /* Exclude from the clip region the area drawn by DrawText */
565 SetRect(&rcCalc
, 0,0,0,0);
566 DrawTextW(pcontext
->hDC
, Text
, i
, &rcCalc
, uFormat
| DT_CALCRECT
);
567 InflateRect( &Rect
, 0, -(rcCalc
.bottom
+1)/2);
568 ExcludeClipRect(pcontext
->hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
572 SelectObject(pcontext
->hDC
, FontOld
);
577 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext
, PRECT prcCurrent
)
580 MENUBARINFO MenuBarInfo
;
582 HFONT FontOld
= NULL
;
590 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
592 MenuBarInfo
.cbSize
= sizeof(MENUBARINFO
);
593 if (! GetMenuBarInfo(pcontext
->hWnd
, OBJID_MENU
, 0, &MenuBarInfo
))
596 Menu
= GetMenu(pcontext
->hWnd
);
597 if (GetMenuItemCount(Menu
) == 0)
600 Rect
= MenuBarInfo
.rcBar
;
601 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
603 /* Draw a line under the menu */
604 oldPen
= (HPEN
)SelectObject(pcontext
->hDC
, GetStockObject(DC_PEN
));
605 SetDCPenColor(pcontext
->hDC
, GetSysColor(COLOR_3DFACE
));
606 MoveToEx(pcontext
->hDC
, Rect
.left
, Rect
.bottom
, NULL
);
607 LineTo(pcontext
->hDC
, Rect
.right
, Rect
.bottom
);
608 SelectObject(pcontext
->hDC
, oldPen
);
610 /* Draw menu items */
611 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFont
);
613 for (i
= 0; i
< GetMenuItemCount(Menu
); i
++)
615 ThemeDrawMenuItem(pcontext
, Menu
, i
);
618 SelectObject(pcontext
->hDC
, FontOld
);
620 /* Fill the menu background area that isn't painted yet */
621 FillRect(pcontext
->hDC
, &Rect
, GetSysColorBrush(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
625 ThemePaintWindow(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
, BOOL bDoDoubleBuffering
)
627 if(!(pcontext
->wi
.dwStyle
& WS_VISIBLE
))
630 if(pcontext
->wi
.dwStyle
& WS_MINIMIZE
)
632 ThemeDrawTitle(pcontext
, prcCurrent
);
636 if((pcontext
->wi
.dwStyle
& WS_CAPTION
)==WS_CAPTION
)
638 if (bDoDoubleBuffering
)
639 ThemeStartBufferedPaint(pcontext
, prcCurrent
->right
, pcontext
->CaptionHeight
);
640 ThemeDrawCaption(pcontext
, prcCurrent
);
641 if (bDoDoubleBuffering
)
642 ThemeEndBufferedPaint(pcontext
, 0, 0, prcCurrent
->right
, pcontext
->CaptionHeight
);
643 ThemeDrawBorders(pcontext
, prcCurrent
);
647 DrawClassicFrame(pcontext
, prcCurrent
);
650 if(HAS_MENU(pcontext
->hWnd
, pcontext
->wi
.dwStyle
))
651 ThemeDrawMenuBar(pcontext
, prcCurrent
);
653 if(pcontext
->wi
.dwStyle
& WS_HSCROLL
)
654 ThemeDrawScrollBar(pcontext
, SB_HORZ
, NULL
);
656 if(pcontext
->wi
.dwStyle
& WS_VSCROLL
)
657 ThemeDrawScrollBar(pcontext
, SB_VERT
, NULL
);
665 ThemeHandleNCPaint(HWND hWnd
, HRGN hRgn
)
667 DRAW_CONTEXT context
;
670 ThemeInitDrawContext(&context
, hWnd
, hRgn
);
672 rcCurrent
= context
.wi
.rcWindow
;
673 OffsetRect( &rcCurrent
, -context
.wi
.rcWindow
.left
, -context
.wi
.rcWindow
.top
);
675 ThemePaintWindow(&context
, &rcCurrent
, TRUE
);
676 ThemeCleanupDrawContext(&context
);
682 ThemeHandleNcMouseMove(HWND hWnd
, DWORD ht
, POINT
* pt
)
684 DRAW_CONTEXT context
;
687 PWND_CONTEXT pcontext
;
689 /* First of all check if we have something to do here */
690 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
691 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
694 /* Get theme data for this window */
695 pcontext
= ThemeGetWndContext(hWnd
);
696 if (pcontext
== NULL
)
699 /* Begin tracking in the non client area if we are not tracking yet */
700 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
701 tme
.dwFlags
= TME_QUERY
;
702 tme
.hwndTrack
= hWnd
;
703 TrackMouseEvent(&tme
);
704 if (tme
.dwFlags
!= (TME_LEAVE
| TME_NONCLIENT
))
706 tme
.hwndTrack
= hWnd
;
707 tme
.dwFlags
= TME_LEAVE
| TME_NONCLIENT
;
708 TrackMouseEvent(&tme
);
711 ThemeInitDrawContext(&context
, hWnd
, 0);
712 if (context
.wi
.dwStyle
& WS_SYSMENU
)
714 if (HT_ISBUTTON(ht
) || HT_ISBUTTON(pcontext
->lastHitTest
))
715 ThemeDrawCaptionButtons(&context
, ht
, 0);
718 if (context
.wi
.dwStyle
& WS_HSCROLL
)
720 if (ht
== HTHSCROLL
|| pcontext
->lastHitTest
== HTHSCROLL
)
721 ThemeDrawScrollBar(&context
, SB_HORZ
, ht
== HTHSCROLL
? pt
: NULL
);
724 if (context
.wi
.dwStyle
& WS_VSCROLL
)
726 if (ht
== HTVSCROLL
|| pcontext
->lastHitTest
== HTVSCROLL
)
727 ThemeDrawScrollBar(&context
, SB_VERT
, ht
== HTVSCROLL
? pt
: NULL
);
729 ThemeCleanupDrawContext(&context
);
731 pcontext
->lastHitTest
= ht
;
737 ThemeHandleNcMouseLeave(HWND hWnd
)
739 DRAW_CONTEXT context
;
741 PWND_CONTEXT pWndContext
;
743 /* First of all check if we have something to do here */
744 style
= GetWindowLongW(hWnd
, GWL_STYLE
);
745 if((style
& (WS_CAPTION
|WS_HSCROLL
|WS_VSCROLL
))==0)
748 /* Get theme data for this window */
749 pWndContext
= ThemeGetWndContext(hWnd
);
750 if (pWndContext
== NULL
)
753 ThemeInitDrawContext(&context
, hWnd
, 0);
754 if (context
.wi
.dwStyle
& WS_SYSMENU
&& HT_ISBUTTON(pWndContext
->lastHitTest
))
755 ThemeDrawCaptionButtons(&context
, 0, 0);
757 if (context
.wi
.dwStyle
& WS_HSCROLL
&& pWndContext
->lastHitTest
== HTHSCROLL
)
758 ThemeDrawScrollBar(&context
, SB_HORZ
, NULL
);
760 if (context
.wi
.dwStyle
& WS_VSCROLL
&& pWndContext
->lastHitTest
== HTVSCROLL
)
761 ThemeDrawScrollBar(&context
, SB_VERT
, NULL
);
763 ThemeCleanupDrawContext(&context
);
765 pWndContext
->lastHitTest
= HTNOWHERE
;
771 ThemeHandleButton(HWND hWnd
, WPARAM wParam
)
777 DRAW_CONTEXT context
;
778 PWND_CONTEXT pWndContext
;
780 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
781 if (!((Style
& WS_CAPTION
) && (Style
& WS_SYSMENU
)))
790 if (!(Style
& WS_MINIMIZEBOX
))
792 SCMsg
= ((Style
& WS_MINIMIZE
) ? SC_RESTORE
: SC_MINIMIZE
);
795 if (!(Style
& WS_MAXIMIZEBOX
))
797 SCMsg
= ((Style
& WS_MAXIMIZE
) ? SC_RESTORE
: SC_MAXIMIZE
);
803 /* Get theme data for this window */
804 pWndContext
= ThemeGetWndContext(hWnd
);
805 if (pWndContext
== NULL
)
808 ThemeInitDrawContext(&context
, hWnd
, 0);
809 ThemeDrawCaptionButtons(&context
, 0, wParam
);
810 pWndContext
->lastHitTest
= wParam
;
816 if (GetMessageW(&Msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
) <= 0)
819 if (Msg
.message
== WM_LBUTTONUP
)
822 if (Msg
.message
!= WM_MOUSEMOVE
)
825 ht
= SendMessage(hWnd
, WM_NCHITTEST
, 0, MAKELPARAM(Msg
.pt
.x
, Msg
.pt
.y
));
826 Pressed
= (ht
== wParam
);
828 /* Only draw the buttons if the hit test changed */
829 if (ht
!= pWndContext
->lastHitTest
&&
830 (HT_ISBUTTON(ht
) || HT_ISBUTTON(pWndContext
->lastHitTest
)))
832 ThemeDrawCaptionButtons(&context
, 0, Pressed
? wParam
: 0);
833 pWndContext
->lastHitTest
= ht
;
837 ThemeDrawCaptionButtons(&context
, ht
, 0);
838 ThemeCleanupDrawContext(&context
);
843 SendMessageW(hWnd
, WM_SYSCOMMAND
, SCMsg
, 0);
848 DefWndNCHitTest(HWND hWnd
, POINT Point
)
854 wi
.cbSize
= sizeof(wi
);
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
))
945 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
946 ButtonWidth
= GetSystemMetrics(SM_CXSMSIZE
);
948 ButtonWidth
= GetSystemMetrics(SM_CXSIZE
);
951 ButtonWidth
+= BUTTON_GAP_SIZE
;
953 if (wi
.dwStyle
& WS_SYSMENU
)
955 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
957 WindowRect
.right
-= ButtonWidth
;
961 // if(!(wi.dwExStyle & WS_EX_DLGMODALFRAME))
962 // FIXME: The real test should check whether there is
963 // an icon for the system window, and if so, do the
964 // rect.left increase.
965 // See win32ss/user/user32/windows/nonclient.c!DefWndNCHitTest
966 // and win32ss/user/ntuser/nonclient.c!GetNCHitEx which does
968 WindowRect
.left
+= ButtonWidth
;
969 WindowRect
.right
-= ButtonWidth
;
972 if (Point
.x
< WindowRect
.left
)
974 if (WindowRect
.right
<= Point
.x
)
976 if (wi
.dwStyle
& WS_MAXIMIZEBOX
|| wi
.dwStyle
& WS_MINIMIZEBOX
)
977 WindowRect
.right
-= ButtonWidth
;
978 if (Point
.x
>= WindowRect
.right
)
980 if (wi
.dwStyle
& WS_MINIMIZEBOX
)
981 WindowRect
.right
-= ButtonWidth
;
982 if (Point
.x
>= WindowRect
.right
)
988 if(!(wi
.dwStyle
& WS_MINIMIZE
))
993 ScreenToClient(hWnd
, &ClientPoint
);
994 GetClientRect(hWnd
, &wi
.rcClient
);
996 if (PtInRect(&wi
.rcClient
, ClientPoint
))
1001 if ((menu
= GetMenu(hWnd
)) && !(wi
.dwStyle
& WS_CHILD
))
1003 if (Point
.x
> 0 && Point
.x
< WindowRect
.right
&& ClientPoint
.y
< 0)
1007 if (wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
1009 InflateRect(&WindowRect
, -2 * GetSystemMetrics(SM_CXBORDER
),
1010 -2 * GetSystemMetrics(SM_CYBORDER
));
1013 if ((wi
.dwStyle
& WS_VSCROLL
) && (wi
.dwStyle
& WS_HSCROLL
) &&
1014 (WindowRect
.bottom
- WindowRect
.top
) > GetSystemMetrics(SM_CYHSCROLL
))
1016 RECT ParentRect
, TempRect
= WindowRect
, TempRect2
= WindowRect
;
1017 HWND Parent
= GetParent(hWnd
);
1019 TempRect
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
1020 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1021 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1023 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1024 if (PtInRect(&TempRect
, Point
))
1027 TempRect2
.top
= TempRect2
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1028 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1029 TempRect2
.left
+= GetSystemMetrics(SM_CXVSCROLL
);
1031 TempRect2
.right
-= GetSystemMetrics(SM_CXVSCROLL
);
1032 if (PtInRect(&TempRect2
, Point
))
1035 TempRect
.top
= TempRect2
.top
;
1036 TempRect
.bottom
= TempRect2
.bottom
;
1038 GetClientRect(Parent
, &ParentRect
);
1039 if (PtInRect(&TempRect
, Point
) && HASSIZEGRIP(wi
.dwStyle
, wi
.dwExStyle
,
1040 GetWindowLongW(Parent
, GWL_STYLE
), wi
.rcWindow
, ParentRect
))
1042 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1043 return HTBOTTOMLEFT
;
1045 return HTBOTTOMRIGHT
;
1050 if (wi
.dwStyle
& WS_VSCROLL
)
1052 RECT TempRect
= WindowRect
;
1054 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1055 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1057 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1058 if (PtInRect(&TempRect
, Point
))
1061 else if (wi
.dwStyle
& WS_HSCROLL
)
1063 RECT TempRect
= WindowRect
;
1064 TempRect
.top
= TempRect
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1065 if (PtInRect(&TempRect
, Point
))
1075 ThemeWndProc(HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, WNDPROC DefWndProc
)
1080 return ThemeHandleNCPaint(hWnd
, (HRGN
)wParam
);
1082 // WM_NCUAHDRAWCAPTION : wParam are DC_* flags.
1084 case WM_NCUAHDRAWCAPTION
:
1086 // WM_NCUAHDRAWFRAME : wParam is HDC, lParam are DC_ACTIVE and or DC_REDRAWHUNGWND.
1088 case WM_NCUAHDRAWFRAME
:
1090 ThemeHandleNCPaint(hWnd
, (HRGN
)1);
1092 case WM_NCMOUSEMOVE
:
1095 Point
.x
= GET_X_LPARAM(lParam
);
1096 Point
.y
= GET_Y_LPARAM(lParam
);
1097 return ThemeHandleNcMouseMove(hWnd
, wParam
, &Point
);
1099 case WM_NCMOUSELEAVE
:
1100 return ThemeHandleNcMouseLeave(hWnd
);
1101 case WM_NCLBUTTONDOWN
:
1108 ThemeHandleButton(hWnd
, wParam
);
1112 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1117 Point
.x
= GET_X_LPARAM(lParam
);
1118 Point
.y
= GET_Y_LPARAM(lParam
);
1119 return DefWndNCHitTest(hWnd
, Point
);
1123 if((wParam
& 0xfff0) == SC_VSCROLL
||
1124 (wParam
& 0xfff0) == SC_HSCROLL
)
1127 Pt
.x
= (short)LOWORD(lParam
);
1128 Pt
.y
= (short)HIWORD(lParam
);
1129 NC_TrackScrollBar(hWnd
, wParam
, Pt
);
1134 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1138 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1142 HRESULT WINAPI
DrawNCPreview(HDC hDC
,
1145 LPCWSTR pszThemeFileName
,
1146 LPCWSTR pszColorName
,
1147 LPCWSTR pszSizeName
,
1148 PNONCLIENTMETRICSW pncMetrics
,
1149 COLORREF
* lpaRgbValues
)
1151 WNDCLASSEXW DummyPreviewWindowClass
;
1154 HTHEMEFILE hThemeFile
;
1155 DRAW_CONTEXT context
;
1158 /* FIXME: We also need to implement drawing the rest of the preview windows
1159 * and make use of the ncmetrics and colors passed as parameters */
1161 /* Create a dummy window that will be used to trick the paint funtions */
1162 memset(&DummyPreviewWindowClass
, 0, sizeof(DummyPreviewWindowClass
));
1163 DummyPreviewWindowClass
.cbSize
= sizeof(DummyPreviewWindowClass
);
1164 DummyPreviewWindowClass
.lpszClassName
= L
"DummyPreviewWindowClass";
1165 DummyPreviewWindowClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1166 DummyPreviewWindowClass
.hInstance
= hDllInst
;
1167 DummyPreviewWindowClass
.lpfnWndProc
= DefWindowProcW
;
1168 if (!RegisterClassExW(&DummyPreviewWindowClass
))
1171 hwndDummy
= CreateWindowExW(0, L
"DummyPreviewWindowClass", L
"Active window", WS_OVERLAPPEDWINDOW
,30,30,300,150,0,0,hDllInst
,NULL
);
1175 hres
= OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, &hThemeFile
,0);
1179 /* Initialize the special draw context for the preview */
1181 context
.hWnd
= hwndDummy
;
1182 context
.theme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"WINDOW", 0);
1185 context
.scrolltheme
= OpenThemeDataFromFile(hThemeFile
, hwndDummy
, L
"SCROLLBAR", 0);
1188 context
.Active
= TRUE
;
1189 context
.wi
.cbSize
= sizeof(context
.wi
);
1190 if (!GetWindowInfo(hwndDummy
, &context
.wi
))
1192 context
.wi
.dwStyle
|= WS_VISIBLE
;
1193 context
.CaptionHeight
= context
.wi
.cyWindowBorders
;
1194 context
.CaptionHeight
+= GetSystemMetrics(context
.wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
1195 context
.hRgn
= CreateRectRgnIndirect(&context
.wi
.rcWindow
);
1197 /* Paint the window on the preview hDC */
1198 rcCurrent
= context
.wi
.rcWindow
;
1199 ThemePaintWindow(&context
, &rcCurrent
, FALSE
);
1201 ThemeCleanupDrawContext(&context
);
1204 DestroyWindow(hwndDummy
);
1205 UnregisterClassW(L
"DummyPreviewWindowClass", hDllInst
);