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
10 #include "wine/debug.h"
12 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
14 HFONT hMenuFont
= NULL
;
15 HFONT hMenuFontBold
= NULL
;
17 void InitMenuFont(VOID
)
21 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
23 if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(ncm
), &ncm
, 0))
28 hMenuFont
= CreateFontIndirect(&ncm
.lfMenuFont
);
30 ncm
.lfMenuFont
.lfWeight
= max(ncm
.lfMenuFont
.lfWeight
+ 300, 1000);
31 hMenuFontBold
= CreateFontIndirect(&ncm
.lfMenuFont
);
36 IsWindowActive(HWND hWnd
, DWORD ExStyle
)
40 if (ExStyle
& WS_EX_MDICHILD
)
42 ret
= IsChild(GetForegroundWindow(), hWnd
);
44 ret
= (hWnd
== (HWND
)SendMessageW(GetParent(hWnd
), WM_MDIGETACTIVE
, 0, 0));
48 ret
= (GetForegroundWindow() == hWnd
);
55 UserHasWindowEdge(DWORD Style
, DWORD ExStyle
)
57 if (Style
& WS_MINIMIZE
)
59 if (ExStyle
& WS_EX_DLGMODALFRAME
)
61 if (ExStyle
& WS_EX_STATICEDGE
)
63 if (Style
& WS_THICKFRAME
)
65 if (Style
== WS_DLGFRAME
|| Style
== WS_CAPTION
)
71 UserGetWindowIcon(HWND hwnd
)
75 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_SMALL2
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
78 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_SMALL
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
81 SendMessageTimeout(hwnd
, WM_GETICON
, ICON_BIG
, 0, SMTO_ABORTIFHUNG
, 1000, (PDWORD_PTR
)&hIcon
);
84 hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICONSM
);
87 hIcon
= (HICON
)GetClassLong(hwnd
, GCL_HICON
);
90 hIcon
= LoadIcon(NULL
, IDI_WINLOGO
);
95 WCHAR
*UserGetWindowCaption(HWND hwnd
)
99 text
= (WCHAR
*)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
100 if (text
) InternalGetWindowText(hwnd
, text
, len
);
105 ThemeDrawTitle(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
110 HRESULT WINAPI
ThemeDrawCaptionText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
111 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
112 DWORD dwTextFlags2
, const RECT
*pRect
, BOOL Active
)
116 HGDIOBJ oldFont
= NULL
;
119 COLORREF oldTextColor
;
123 hr
= GetThemeSysFont(0,TMT_CAPTIONFONT
,&logfont
);
126 hFont
= CreateFontIndirectW(&logfont
);
128 CopyRect(&rt
, pRect
);
130 oldFont
= SelectObject(hdc
, hFont
);
132 if(dwTextFlags2
& DTT_GRAYED
)
133 textColor
= GetSysColor(COLOR_GRAYTEXT
);
135 textColor
= GetSysColor(COLOR_INACTIVECAPTIONTEXT
);
137 textColor
= GetSysColor(COLOR_CAPTIONTEXT
);
139 oldTextColor
= SetTextColor(hdc
, textColor
);
140 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
141 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
142 SetBkMode(hdc
, oldBkMode
);
143 SetTextColor(hdc
, oldTextColor
);
146 SelectObject(hdc
, oldFont
);
153 ThemeInitDrawContext(PDRAW_CONTEXT pcontext
,
157 pcontext
->wi
.cbSize
= sizeof(pcontext
->wi
);
158 GetWindowInfo(hWnd
, &pcontext
->wi
);
159 pcontext
->hWnd
= hWnd
;
160 pcontext
->Active
= IsWindowActive(hWnd
, pcontext
->wi
.dwExStyle
);
161 pcontext
->hPrevTheme
= GetPropW(hWnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
162 pcontext
->theme
= OpenThemeData(pcontext
->hWnd
, L
"WINDOW");
163 pcontext
->scrolltheme
= OpenThemeData(pcontext
->hWnd
, L
"SCROLLBAR");
165 pcontext
->CaptionHeight
= pcontext
->wi
.cyWindowBorders
;
166 pcontext
->CaptionHeight
+= GetSystemMetrics(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMCAPTION
: SM_CYCAPTION
);
170 hRgn
= CreateRectRgnIndirect(&pcontext
->wi
.rcWindow
);
172 pcontext
->hRgn
= hRgn
;
174 pcontext
->hDC
= GetDCEx(hWnd
, hRgn
, DCX_WINDOW
| DCX_INTERSECTRGN
| DCX_USESTYLE
| DCX_KEEPCLIPRGN
);
178 ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext
)
180 ReleaseDC(pcontext
->hWnd
,pcontext
->hDC
);
182 CloseThemeData (pcontext
->theme
);
183 CloseThemeData (pcontext
->scrolltheme
);
185 SetPropW(pcontext
->hWnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), pcontext
->hPrevTheme
);
187 if(pcontext
->hRgn
!= NULL
)
189 DeleteObject(pcontext
->hRgn
);
194 ThemeStartBufferedPaint(PDRAW_CONTEXT pcontext
, int cx
, int cy
)
198 pcontext
->hDCScreen
= pcontext
->hDC
;
199 pcontext
->hDC
= CreateCompatibleDC(pcontext
->hDCScreen
);
200 hbmp
= CreateCompatibleBitmap(pcontext
->hDCScreen
, cx
, cy
);
201 pcontext
->hbmpOld
= (HBITMAP
)SelectObject(pcontext
->hDC
, hbmp
);
205 ThemeEndBufferedPaint(PDRAW_CONTEXT pcontext
, int x
, int y
, int cx
, int cy
)
208 BitBlt(pcontext
->hDCScreen
, 0, 0, cx
, cy
, pcontext
->hDC
, x
, y
, SRCCOPY
);
209 hbmp
= (HBITMAP
) SelectObject(pcontext
->hDC
, pcontext
->hbmpOld
);
210 DeleteObject(pcontext
->hDC
);
213 pcontext
->hDC
= pcontext
->hDCScreen
;
217 ThemeDrawCaptionButton(PDRAW_CONTEXT pcontext
,
219 CAPTIONBUTTON buttonId
,
223 INT ButtonWidth
, ButtonHeight
, iPartId
;
225 ButtonHeight
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CYSMSIZE
: SM_CYSIZE
);
226 ButtonWidth
= GetSystemMetrics( pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? SM_CXSMSIZE
: SM_CXSIZE
);
231 iPartId
= pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
? WP_SMALLCLOSEBUTTON
: WP_CLOSEBUTTON
;
235 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
237 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
240 iStateId
= BUTTON_DISABLED
;
243 iPartId
= pcontext
->wi
.dwStyle
& WS_MAXIMIZE
? WP_RESTOREBUTTON
: WP_MAXBUTTON
;
247 if (!(pcontext
->wi
.dwStyle
& WS_MINIMIZEBOX
))
249 if (!(pcontext
->wi
.dwStyle
& WS_MAXIMIZEBOX
))
252 iStateId
= BUTTON_DISABLED
;
255 iPartId
= WP_MINBUTTON
;
259 //FIXME: Implement Help Button
266 /* Calculate the position */
267 rcPart
.top
= prcCurrent
->top
;
268 rcPart
.right
= prcCurrent
->right
;
269 rcPart
.bottom
= rcPart
.top
+ ButtonHeight
;
270 rcPart
.left
= rcPart
.right
- ButtonWidth
;
271 prcCurrent
->right
-= ButtonWidth
+ BUTTON_GAP_SIZE
;
273 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, iPartId
, iStateId
, &rcPart
, NULL
);
277 ThemeGetButtonState(DWORD htCurrect
, DWORD htHot
, DWORD htDown
, BOOL Active
)
279 if (htHot
== htCurrect
)
282 return BUTTON_INACTIVE
;
283 if (htDown
== htCurrect
)
284 return BUTTON_PRESSED
;
286 return BUTTON_NORMAL
;
289 /* Used only from mouse event handlers */
291 ThemeDrawCaptionButtons(PDRAW_CONTEXT pcontext
, DWORD htHot
, DWORD htDown
)
295 /* Check if the window has caption buttons */
296 if (!((pcontext
->wi
.dwStyle
& WS_CAPTION
) && (pcontext
->wi
.dwStyle
& WS_SYSMENU
)))
299 rcCurrent
.top
= rcCurrent
.left
= 0;
300 rcCurrent
.right
= pcontext
->wi
.rcWindow
.right
- pcontext
->wi
.rcWindow
.left
;
301 rcCurrent
.bottom
= pcontext
->CaptionHeight
;
303 /* Add a padding around the objects of the caption */
304 InflateRect(&rcCurrent
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
305 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
307 /* Draw the buttons */
308 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, CLOSEBUTTON
,
309 ThemeGetButtonState(HTCLOSE
, htHot
, htDown
, pcontext
->Active
));
310 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MAXBUTTON
,
311 ThemeGetButtonState(HTMAXBUTTON
, htHot
, htDown
, pcontext
->Active
));
312 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, MINBUTTON
,
313 ThemeGetButtonState(HTMINBUTTON
, htHot
, htDown
, pcontext
->Active
));
314 ThemeDrawCaptionButton(pcontext
, &rcCurrent
, HELPBUTTON
,
315 ThemeGetButtonState(HTHELP
, htHot
, htDown
, pcontext
->Active
));
318 /* Used from WM_NCPAINT and WM_NCACTIVATE handlers*/
320 ThemeDrawCaption(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
327 hIcon
= UserGetWindowIcon(pcontext
->hWnd
);
328 CaptionText
= UserGetWindowCaption(pcontext
->hWnd
);
330 /* Get the caption part and state id */
331 if (pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
332 iPart
= WP_SMALLCAPTION
;
333 else if (pcontext
->wi
.dwStyle
& WS_MAXIMIZE
)
334 iPart
= WP_MAXCAPTION
;
338 iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
340 /* Draw the caption background*/
341 rcPart
= *prcCurrent
;
342 rcPart
.bottom
= pcontext
->CaptionHeight
;
343 prcCurrent
->top
= rcPart
.bottom
;
344 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,iPart
,iState
,&rcPart
,NULL
);
346 /* Add a padding around the objects of the caption */
347 InflateRect(&rcPart
, -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
,
348 -(int)pcontext
->wi
.cyWindowBorders
-BUTTON_GAP_SIZE
);
350 /* Draw the caption buttons */
351 if (pcontext
->wi
.dwStyle
& WS_SYSMENU
)
353 iState
= pcontext
->Active
? BUTTON_NORMAL
: BUTTON_INACTIVE
;
355 ThemeDrawCaptionButton(pcontext
, &rcPart
, CLOSEBUTTON
, iState
);
356 ThemeDrawCaptionButton(pcontext
, &rcPart
, MAXBUTTON
, iState
);
357 ThemeDrawCaptionButton(pcontext
, &rcPart
, MINBUTTON
, iState
);
358 ThemeDrawCaptionButton(pcontext
, &rcPart
, HELPBUTTON
, iState
);
364 if(hIcon
&& !(pcontext
->wi
.dwExStyle
& WS_EX_TOOLWINDOW
))
366 int IconHeight
= GetSystemMetrics(SM_CYSMICON
);
367 int IconWidth
= GetSystemMetrics(SM_CXSMICON
);
368 DrawIconEx(pcontext
->hDC
, rcPart
.left
, rcPart
.top
, hIcon
, IconWidth
, IconHeight
, 0, NULL
, DI_NORMAL
);
369 rcPart
.left
+= IconWidth
+ 4;
374 /* Draw the caption */
377 /*FIXME: Use DrawThemeTextEx*/
378 ThemeDrawCaptionText(pcontext
->theme
,
383 lstrlenW(CaptionText
),
384 DT_VCENTER
| DT_SINGLELINE
| DT_END_ELLIPSIS
,
388 HeapFree(GetProcessHeap(), 0, CaptionText
);
393 ThemeDrawBorders(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
396 int iState
= pcontext
->Active
? FS_ACTIVE
: FS_INACTIVE
;
398 /* Draw the bottom border */
399 rcPart
= *prcCurrent
;
400 rcPart
.top
= rcPart
.bottom
- pcontext
->wi
.cyWindowBorders
;
401 prcCurrent
->bottom
= rcPart
.top
;
402 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
, WP_FRAMEBOTTOM
, iState
, &rcPart
, NULL
);
404 /* Draw the left border */
405 rcPart
= *prcCurrent
;
406 rcPart
.right
= pcontext
->wi
.cxWindowBorders
;
407 prcCurrent
->left
= rcPart
.right
;
408 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMELEFT
, iState
, &rcPart
, NULL
);
410 /* Draw the right border */
411 rcPart
= *prcCurrent
;
412 rcPart
.left
= rcPart
.right
- pcontext
->wi
.cxWindowBorders
;
413 prcCurrent
->right
= rcPart
.left
;
414 DrawThemeBackground(pcontext
->theme
, pcontext
->hDC
,WP_FRAMERIGHT
, iState
, &rcPart
, NULL
);
418 DrawClassicFrame(PDRAW_CONTEXT context
, RECT
* prcCurrent
)
420 /* Draw outer edge */
421 if (UserHasWindowEdge(context
->wi
.dwStyle
, context
->wi
.dwExStyle
))
423 DrawEdge(context
->hDC
, prcCurrent
, EDGE_RAISED
, BF_RECT
| BF_ADJUST
);
425 else if (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
)
427 DrawEdge(context
->hDC
, prcCurrent
, BDR_SUNKENINNER
, BF_RECT
| BF_ADJUST
| BF_FLAT
);
430 /* Firstly the "thick" frame */
431 if ((context
->wi
.dwStyle
& WS_THICKFRAME
) && !(context
->wi
.dwStyle
& WS_MINIMIZE
))
434 (GetSystemMetrics(SM_CXFRAME
) - GetSystemMetrics(SM_CXDLGFRAME
)) *
435 GetSystemMetrics(SM_CXBORDER
);
437 (GetSystemMetrics(SM_CYFRAME
) - GetSystemMetrics(SM_CYDLGFRAME
)) *
438 GetSystemMetrics(SM_CYBORDER
);
440 SelectObject(context
->hDC
, GetSysColorBrush(
441 context
->Active
? COLOR_ACTIVEBORDER
: COLOR_INACTIVEBORDER
));
444 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
445 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
446 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
447 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
448 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
449 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
450 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
451 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
453 InflateRect(prcCurrent
, -Width
, -Height
);
456 /* Now the other bit of the frame */
457 if (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_BORDER
) || context
->wi
.dwExStyle
& WS_EX_DLGMODALFRAME
)
459 INT Width
= GetSystemMetrics(SM_CXBORDER
);
460 INT Height
= GetSystemMetrics(SM_CYBORDER
);
462 SelectObject(context
->hDC
, GetSysColorBrush(
463 (context
->wi
.dwExStyle
& (WS_EX_DLGMODALFRAME
| WS_EX_CLIENTEDGE
)) ? COLOR_3DFACE
:
464 (context
->wi
.dwExStyle
& WS_EX_STATICEDGE
) ? COLOR_WINDOWFRAME
:
465 (context
->wi
.dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) ? COLOR_3DFACE
:
469 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
470 prcCurrent
->right
- prcCurrent
->left
, Height
, PATCOPY
);
471 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->top
,
472 Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
473 PatBlt(context
->hDC
, prcCurrent
->left
, prcCurrent
->bottom
,
474 prcCurrent
->right
- prcCurrent
->left
, -Height
, PATCOPY
);
475 PatBlt(context
->hDC
, prcCurrent
->right
, prcCurrent
->top
,
476 -Width
, prcCurrent
->bottom
- prcCurrent
->top
, PATCOPY
);
478 InflateRect(prcCurrent
, -Width
, -Height
);
481 if (context
->wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
483 DrawEdge(context
->hDC
, prcCurrent
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
488 ThemeDrawMenuItem(PDRAW_CONTEXT pcontext
, HMENU Menu
, int imenu
)
491 BOOL flat_menu
= FALSE
;
494 WCHAR wstrItemText
[20];
496 HFONT FontOld
= NULL
;
497 UINT uFormat
= DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
;
499 Item
.cbSize
= sizeof(MENUITEMINFOW
);
500 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
501 Item
.dwTypeData
= wstrItemText
;
503 if (!GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
))
506 if(Item
.fType
& MF_SEPARATOR
)
512 Item
.dwTypeData
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, Item
.cch
* sizeof(WCHAR
));
513 Item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
514 GetMenuItemInfoW(Menu
, imenu
, TRUE
, &Item
);
520 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
522 GetMenuItemRect(pcontext
->hWnd
, Menu
, imenu
, &Rect
);
525 OffsetRect(&Rect
, -pcontext
->wi
.rcClient
.left
, -pcontext
->wi
.rcClient
.top
);
527 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
530 SetBkColor(pcontext
->hDC
, GetSysColor(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
531 SetTextColor(pcontext
->hDC
, GetSysColor(Item
.fState
& MF_GRAYED
? COLOR_GRAYTEXT
: COLOR_MENUTEXT
));
533 if (0 != (Item
.fState
& MFS_DEFAULT
))
535 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFontBold
);
538 Rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
539 Rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
541 Text
= (PWCHAR
) Item
.dwTypeData
;
544 for (i
= 0; L
'\0' != Text
[i
]; i
++)
546 if (L
'\t' == Text
[i
] || L
'\b' == Text
[i
])
553 SetBkMode(pcontext
->hDC
, OPAQUE
);
555 if (0 != (Item
.fState
& MF_GRAYED
))
557 if (0 == (Item
.fState
& MF_HILITE
))
559 ++Rect
.left
; ++Rect
.top
; ++Rect
.right
; ++Rect
.bottom
;
560 SetTextColor(pcontext
->hDC
, RGB(0xff, 0xff, 0xff));
561 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
562 --Rect
.left
; --Rect
.top
; --Rect
.right
; --Rect
.bottom
;
564 SetTextColor(pcontext
->hDC
, RGB(0x80, 0x80, 0x80));
565 SetBkMode(pcontext
->hDC
, TRANSPARENT
);
568 DrawTextW(pcontext
->hDC
, Text
, i
, &Rect
, uFormat
);
570 /* Exclude from the clip region the area drawn by DrawText */
571 SetRect(&rcCalc
, 0,0,0,0);
572 DrawTextW(pcontext
->hDC
, Text
, i
, &rcCalc
, uFormat
| DT_CALCRECT
);
573 InflateRect( &Rect
, 0, -(rcCalc
.bottom
+1)/2);
574 ExcludeClipRect(pcontext
->hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
578 SelectObject(pcontext
->hDC
, FontOld
);
583 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext
, PRECT prcCurrent
)
586 MENUBARINFO MenuBarInfo
;
588 HFONT FontOld
= NULL
;
596 flat_menu
= GetThemeSysBool(pcontext
->theme
, TMT_FLATMENUS
);
598 MenuBarInfo
.cbSize
= sizeof(MENUBARINFO
);
599 if (! GetMenuBarInfo(pcontext
->hWnd
, OBJID_MENU
, 0, &MenuBarInfo
))
602 Menu
= GetMenu(pcontext
->hWnd
);
603 if (GetMenuItemCount(Menu
) == 0)
606 Rect
= MenuBarInfo
.rcBar
;
607 OffsetRect(&Rect
, -pcontext
->wi
.rcWindow
.left
, -pcontext
->wi
.rcWindow
.top
);
609 /* Draw a line under the menu*/
610 oldPen
= (HPEN
)SelectObject(pcontext
->hDC
, GetStockObject(DC_PEN
));
611 SetDCPenColor(pcontext
->hDC
, GetSysColor(COLOR_3DFACE
));
612 MoveToEx(pcontext
->hDC
, Rect
.left
, Rect
.bottom
, NULL
);
613 LineTo(pcontext
->hDC
, Rect
.right
, Rect
.bottom
);
614 SelectObject(pcontext
->hDC
, oldPen
);
616 /* Draw menu items */
617 FontOld
= (HFONT
)SelectObject(pcontext
->hDC
, hMenuFont
);
619 for (i
= 0; i
< GetMenuItemCount(Menu
); i
++)
621 ThemeDrawMenuItem(pcontext
, Menu
, i
);
624 SelectObject(pcontext
->hDC
, FontOld
);
626 /* Fill the menu background area that isn't painted yet*/
627 FillRect(pcontext
->hDC
, &Rect
, GetSysColorBrush(flat_menu
? COLOR_MENUBAR
: COLOR_MENU
));
631 ThemePaintWindow(PDRAW_CONTEXT pcontext
, RECT
* prcCurrent
)
633 if(!(pcontext
->wi
.dwStyle
& WS_VISIBLE
))
636 if(pcontext
->wi
.dwStyle
& WS_MINIMIZE
)
638 ThemeDrawTitle(pcontext
, prcCurrent
);
642 if((pcontext
->wi
.dwStyle
& WS_CAPTION
)==WS_CAPTION
)
644 ThemeStartBufferedPaint(pcontext
, prcCurrent
->right
, pcontext
->CaptionHeight
);
645 ThemeDrawCaption(pcontext
, prcCurrent
);
646 ThemeEndBufferedPaint(pcontext
, 0, 0, prcCurrent
->right
, pcontext
->CaptionHeight
);
647 ThemeDrawBorders(pcontext
, prcCurrent
);
651 DrawClassicFrame(pcontext
, prcCurrent
);
654 if(HAS_MENU(pcontext
->hWnd
, pcontext
->wi
.dwStyle
))
655 ThemeDrawMenuBar(pcontext
, prcCurrent
);
657 if(pcontext
->wi
.dwStyle
& WS_HSCROLL
)
658 ThemeDrawScrollBar(pcontext
, SB_HORZ
, NULL
);
660 if(pcontext
->wi
.dwStyle
& WS_VSCROLL
)
661 ThemeDrawScrollBar(pcontext
, SB_VERT
, NULL
);
669 ThemeHandleNCPaint(HWND hWnd
, HRGN hRgn
)
671 DRAW_CONTEXT context
;
674 ThemeInitDrawContext(&context
, hWnd
, hRgn
);
676 rcCurrent
= context
.wi
.rcWindow
;
677 OffsetRect( &rcCurrent
, -context
.wi
.rcWindow
.left
, -context
.wi
.rcWindow
.top
);
679 ThemePaintWindow(&context
, &rcCurrent
);
680 ThemeCleanupDrawContext(&context
);
686 ThemeHandleNcMouseMove(HWND hWnd
, DWORD ht
, POINT
* pt
)
688 DRAW_CONTEXT context
;
691 tme
.cbSize
= sizeof(TRACKMOUSEEVENT
);
692 tme
.dwFlags
= TME_QUERY
;
693 tme
.hwndTrack
= hWnd
;
694 TrackMouseEvent(&tme
);
695 if (tme
.dwFlags
!= (TME_LEAVE
| TME_NONCLIENT
))
697 tme
.hwndTrack
= hWnd
;
698 tme
.dwFlags
= TME_LEAVE
| TME_NONCLIENT
;
699 TrackMouseEvent(&tme
);
702 ThemeInitDrawContext(&context
, hWnd
, 0);
703 ThemeDrawCaptionButtons(&context
, ht
, 0);
705 if(context
.wi
.dwStyle
& WS_HSCROLL
)
706 ThemeDrawScrollBar(&context
, SB_HORZ
, ht
== HTHSCROLL
? pt
: NULL
);
708 if(context
.wi
.dwStyle
& WS_VSCROLL
)
709 ThemeDrawScrollBar(&context
, SB_VERT
, ht
== HTVSCROLL
? pt
: NULL
);
711 ThemeCleanupDrawContext(&context
);
717 ThemeHandleNcMouseLeave(HWND hWnd
)
719 DRAW_CONTEXT context
;
721 ThemeInitDrawContext(&context
, hWnd
, 0);
722 ThemeDrawCaptionButtons(&context
, 0, 0);
724 if(context
.wi
.dwStyle
& WS_HSCROLL
)
725 ThemeDrawScrollBar(&context
, SB_HORZ
, NULL
);
727 if(context
.wi
.dwStyle
& WS_VSCROLL
)
728 ThemeDrawScrollBar(&context
, SB_VERT
, NULL
);
730 ThemeCleanupDrawContext(&context
);
736 ThemeHandleButton(HWND hWnd
, WPARAM wParam
)
739 BOOL Pressed
= TRUE
; // , OldState;
742 DRAW_CONTEXT context
;
744 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
748 if (!(Style
& WS_SYSMENU
))
753 if (!(Style
& WS_MINIMIZEBOX
))
755 SCMsg
= ((Style
& WS_MINIMIZE
) ? SC_RESTORE
: SC_MINIMIZE
);
758 if (!(Style
& WS_MAXIMIZEBOX
))
760 SCMsg
= ((Style
& WS_MAXIMIZE
) ? SC_RESTORE
: SC_MAXIMIZE
);
766 ThemeInitDrawContext(&context
, hWnd
, 0);
767 ThemeDrawCaptionButtons(&context
, 0, wParam
);
773 if (GetMessageW(&Msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
) <= 0)
776 if (Msg
.message
== WM_LBUTTONUP
)
779 if (Msg
.message
!= WM_MOUSEMOVE
)
782 //OldState = Pressed;
783 ht
= SendMessage(hWnd
, WM_NCHITTEST
, 0, MAKELPARAM(Msg
.pt
.x
, Msg
.pt
.y
));
784 Pressed
= (ht
== wParam
);
786 ThemeDrawCaptionButtons(&context
, 0, Pressed
? wParam
: 0);
789 ThemeDrawCaptionButtons(&context
, 0, 0);
790 ThemeCleanupDrawContext(&context
);
795 SendMessageW(hWnd
, WM_SYSCOMMAND
, SCMsg
, 0);
800 DefWndNCHitTest(HWND hWnd
, POINT Point
)
806 GetWindowInfo(hWnd
, &wi
);
808 if (!PtInRect(&wi
.rcWindow
, Point
))
812 WindowRect
= wi
.rcWindow
;
814 if (UserHasWindowEdge(wi
.dwStyle
, wi
.dwExStyle
))
818 InflateRect(&WindowRect
, -(int)wi
.cxWindowBorders
, -(int)wi
.cyWindowBorders
);
819 XSize
= GetSystemMetrics(SM_CXSIZE
) * GetSystemMetrics(SM_CXBORDER
);
820 YSize
= GetSystemMetrics(SM_CYSIZE
) * GetSystemMetrics(SM_CYBORDER
);
821 if (!PtInRect(&WindowRect
, Point
))
825 ThickFrame
= (wi
.dwStyle
& WS_THICKFRAME
);
826 if (Point
.y
< WindowRect
.top
)
828 if(wi
.dwStyle
& WS_MINIMIZE
)
832 if (Point
.x
< (WindowRect
.left
+ XSize
))
834 if (Point
.x
>= (WindowRect
.right
- XSize
))
838 if (Point
.y
>= WindowRect
.bottom
)
840 if(wi
.dwStyle
& WS_MINIMIZE
)
844 if (Point
.x
< (WindowRect
.left
+ XSize
))
846 if (Point
.x
>= (WindowRect
.right
- XSize
))
847 return HTBOTTOMRIGHT
;
850 if (Point
.x
< WindowRect
.left
)
852 if(wi
.dwStyle
& WS_MINIMIZE
)
856 if (Point
.y
< (WindowRect
.top
+ YSize
))
858 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
862 if (Point
.x
>= WindowRect
.right
)
864 if(wi
.dwStyle
& WS_MINIMIZE
)
868 if (Point
.y
< (WindowRect
.top
+ YSize
))
870 if (Point
.y
>= (WindowRect
.bottom
- YSize
))
871 return HTBOTTOMRIGHT
;
878 if (wi
.dwExStyle
& WS_EX_STATICEDGE
)
879 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
880 -GetSystemMetrics(SM_CYBORDER
));
881 if (!PtInRect(&WindowRect
, Point
))
885 if ((wi
.dwStyle
& WS_CAPTION
) == WS_CAPTION
)
887 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
888 WindowRect
.top
+= GetSystemMetrics(SM_CYSMCAPTION
);
890 WindowRect
.top
+= GetSystemMetrics(SM_CYCAPTION
);
892 if (!PtInRect(&WindowRect
, Point
))
897 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
898 ButtonWidth
= GetSystemMetrics(SM_CXSMSIZE
);
900 ButtonWidth
= GetSystemMetrics(SM_CXSIZE
);
903 ButtonWidth
+= BUTTON_GAP_SIZE
;
905 if (wi
.dwStyle
& WS_SYSMENU
)
907 if (wi
.dwExStyle
& WS_EX_TOOLWINDOW
)
909 WindowRect
.right
-= ButtonWidth
;
913 if(!(wi
.dwExStyle
& WS_EX_DLGMODALFRAME
))
914 WindowRect
.left
+= ButtonWidth
;
915 WindowRect
.right
-= ButtonWidth
;
918 if (Point
.x
< WindowRect
.left
)
920 if (WindowRect
.right
<= Point
.x
)
922 if (wi
.dwStyle
& WS_MAXIMIZEBOX
|| wi
.dwStyle
& WS_MINIMIZEBOX
)
923 WindowRect
.right
-= ButtonWidth
;
924 if (Point
.x
>= WindowRect
.right
)
926 if (wi
.dwStyle
& WS_MINIMIZEBOX
)
927 WindowRect
.right
-= ButtonWidth
;
928 if (Point
.x
>= WindowRect
.right
)
934 if(!(wi
.dwStyle
& WS_MINIMIZE
))
939 ScreenToClient(hWnd
, &ClientPoint
);
940 GetClientRect(hWnd
, &wi
.rcClient
);
942 if (PtInRect(&wi
.rcClient
, ClientPoint
))
947 if ((menu
= GetMenu(hWnd
)) && !(wi
.dwStyle
& WS_CHILD
))
949 if (Point
.x
> 0 && Point
.x
< WindowRect
.right
&& ClientPoint
.y
< 0)
953 if (wi
.dwExStyle
& WS_EX_CLIENTEDGE
)
955 InflateRect(&WindowRect
, -2 * GetSystemMetrics(SM_CXBORDER
),
956 -2 * GetSystemMetrics(SM_CYBORDER
));
959 if ((wi
.dwStyle
& WS_VSCROLL
) && (wi
.dwStyle
& WS_HSCROLL
) &&
960 (WindowRect
.bottom
- WindowRect
.top
) > GetSystemMetrics(SM_CYHSCROLL
))
962 RECT ParentRect
, TempRect
= WindowRect
, TempRect2
= WindowRect
;
963 HWND Parent
= GetParent(hWnd
);
965 TempRect
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
966 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
967 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
969 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
970 if (PtInRect(&TempRect
, Point
))
973 TempRect2
.top
= TempRect2
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
974 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
975 TempRect2
.left
+= GetSystemMetrics(SM_CXVSCROLL
);
977 TempRect2
.right
-= GetSystemMetrics(SM_CXVSCROLL
);
978 if (PtInRect(&TempRect2
, Point
))
981 TempRect
.top
= TempRect2
.top
;
982 TempRect
.bottom
= TempRect2
.bottom
;
984 GetClientRect(Parent
, &ParentRect
);
985 if (PtInRect(&TempRect
, Point
) && HASSIZEGRIP(wi
.dwStyle
, wi
.dwExStyle
,
986 GetWindowLongW(Parent
, GWL_STYLE
), wi
.rcWindow
, ParentRect
))
988 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
991 return HTBOTTOMRIGHT
;
996 if (wi
.dwStyle
& WS_VSCROLL
)
998 RECT TempRect
= WindowRect
;
1000 if ((wi
.dwExStyle
& WS_EX_LEFTSCROLLBAR
) != 0)
1001 TempRect
.right
= TempRect
.left
+ GetSystemMetrics(SM_CXVSCROLL
);
1003 TempRect
.left
= TempRect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1004 if (PtInRect(&TempRect
, Point
))
1007 else if (wi
.dwStyle
& WS_HSCROLL
)
1009 RECT TempRect
= WindowRect
;
1010 TempRect
.top
= TempRect
.bottom
- GetSystemMetrics(SM_CYHSCROLL
);
1011 if (PtInRect(&TempRect
, Point
))
1021 ThemeWndProc(HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, WNDPROC DefWndProc
)
1026 return ThemeHandleNCPaint(hWnd
, (HRGN
)wParam
);
1028 ThemeHandleNCPaint(hWnd
, (HRGN
)1);
1030 case WM_NCMOUSEMOVE
:
1033 Point
.x
= GET_X_LPARAM(lParam
);
1034 Point
.y
= GET_Y_LPARAM(lParam
);
1035 return ThemeHandleNcMouseMove(hWnd
, wParam
, &Point
);
1037 case WM_NCMOUSELEAVE
:
1038 return ThemeHandleNcMouseLeave(hWnd
);
1039 case WM_NCLBUTTONDOWN
:
1046 ThemeHandleButton(hWnd
, wParam
);
1050 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1055 Point
.x
= GET_X_LPARAM(lParam
);
1056 Point
.y
= GET_Y_LPARAM(lParam
);
1057 return DefWndNCHitTest(hWnd
, Point
);
1061 if((wParam
& 0xfff0) == SC_VSCROLL
||
1062 (wParam
& 0xfff0) == SC_HSCROLL
)
1065 Pt
.x
= (short)LOWORD(lParam
);
1066 Pt
.y
= (short)HIWORD(lParam
);
1067 NC_TrackScrollBar(hWnd
, wParam
, Pt
);
1071 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);
1074 case WM_NCUAHDRAWCAPTION
:
1075 case WM_NCUAHDRAWFRAME
:
1076 /* FIXME: how should these be handled? */
1079 return DefWndProc(hWnd
, Msg
, wParam
, lParam
);