From 4a9715ea8b604339b36d6ee9930e1dafd3175b98 Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Thu, 16 Oct 2014 01:34:01 -0700 Subject: [PATCH 1/4] allow for nuding auto-hide taskbars --- appshell/cef_dark_aero_window.cpp | 376 ++++++++++++++++++++++-------- appshell/cef_dark_aero_window.h | 6 +- appshell/cef_dark_window.cpp | 34 ++- appshell/cef_dark_window.h | 3 +- appshell/cef_main_window.cpp | 11 +- 5 files changed, 321 insertions(+), 109 deletions(-) diff --git a/appshell/cef_dark_aero_window.cpp b/appshell/cef_dark_aero_window.cpp index 31d90e247..c7e5cdf9b 100644 --- a/appshell/cef_dark_aero_window.cpp +++ b/appshell/cef_dark_aero_window.cpp @@ -21,10 +21,15 @@ */ #include "cef_dark_aero_window.h" #include +#include +#include + // Constants static const int kWindowFrameSize = 8; static const int kSystemIconZoomFactorCX = kWindowFrameSize + 2; static const int kSystemIconZoomFactorCY = kWindowFrameSize + 4; +// add 1px to the window frame size to get the 1px edge for the task bar +static const int kAutoHideTaskBarSize = kWindowFrameSize + 1; // dll instance to dynamically load the Desktop Window Manager DLL static CDwmDLL gDesktopWindowManagerDLL; @@ -50,10 +55,9 @@ HINSTANCE CDwmDLL::LoadLibrary() if (mhDwmDll == NULL) { // dynamically load dwmapi.dll if running Windows Vista or later (ie. not on XP) - OSVERSIONINFO osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + ::OSVERSIONINFO osvi = {0}; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); + ::GetVersionEx(&osvi); if ((osvi.dwMajorVersion > 5) || ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) )) { mhDwmDll = ::LoadLibrary(TEXT("dwmapi.dll")); @@ -93,6 +97,83 @@ HRESULT CDwmDLL::DwmIsCompositionEnabled(BOOL* pfEnabled) } +namespace WindowsTaskBar +{ + // Constants + const BYTE TOP_EDGE = 0x01; + const BYTE LEFT_EDGE = 0x02; + const BYTE BOTTOM_EDGE = 0x04; + const BYTE RIGHT_EDGE = 0x08; + + // Helper struct + struct EdgeMatch { + BYTE flag; + UINT edge; + }; + + // Helper array + const EdgeMatch matchers[] = + { + {TOP_EDGE, ABE_TOP}, + {LEFT_EDGE, ABE_LEFT}, + {BOTTOM_EDGE, ABE_BOTTOM}, + {RIGHT_EDGE, ABE_RIGHT} + }; + + // API + bool edgeHasAutoHideTaskBar(UINT edge, HMONITOR monitor) + { + ::APPBARDATA bar = {0}; + bar.cbSize = sizeof (bar); + bar.uEdge = edge; + + ::MONITORINFO info = {0}; + info.cbSize = sizeof(info); + + // We'll use the monitor info that we're querying + // to see if an auto-hide bar intersects that monitor + ::GetMonitorInfo(monitor, &info); + + HWND taskbar = (HWND)::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &bar); + + // There's no auto-hide bar on this edge so Short-circuit here + // to prevent doing extra work that we don't need to. + if (!::IsWindow(taskbar)) { + return false; + } + + // Qualify task bars by checking for WS_EX_TOPMOST + DWORD dwStyle = (DWORD)::GetWindowLong(taskbar, GWL_EXSTYLE); + + // This will get the position of the task bar when it + // isn't hidden so we can see if it intersects the monitor + ::SHAppBarMessage(ABM_GETTASKBARPOS, &bar); + + // We could use MonitorFromWindow but, with multiple monitors and a collapsed auto hide task bar, + // the system will think that a collapsed task bar on the right edge of the left monitor + // belongs on the left edge of the right monitor so querying monitor info will return the wrong thing. + RECT tbOther; + BOOL intersection = ::IntersectRect(&tbOther, &info.rcMonitor, &bar.rc); + + return ((dwStyle & WS_EX_TOPMOST) && intersection); + } + + // API + WORD GetAutoHideEdges(HWND wnd) + { + WORD result = 0; + HMONITOR monitor = ::MonitorFromWindow(wnd, MONITOR_DEFAULTTOPRIMARY); + + for (int i = 0; i < _countof(matchers); i++) { + if (edgeHasAutoHideTaskBar(matchers[i].edge, monitor)) { + result |= matchers[i].flag; + } + } + return result; + } +}; + +// Dark Aero Window Implementation cef_dark_aero_window::cef_dark_aero_window() : mReady(false), mMenuHiliteIndex(-1), @@ -157,50 +238,6 @@ BOOL cef_dark_aero_window::HandleActivate() return SUCCEEDED(hr); } -// Computes the Rect where the System Icon is drawn in window coordinates -void cef_dark_aero_window::ComputeWindowIconRect(RECT& rect) const -{ - if (CanUseAeroGlass()) { - int top = ::kWindowFrameSize; - int left = ::kWindowFrameSize; - - if (IsZoomed()) { - top = ::kSystemIconZoomFactorCY; - left = ::kSystemIconZoomFactorCX; - } - - ::SetRectEmpty(&rect); - rect.top = top; - rect.left = left; - rect.bottom = rect.top + ::GetSystemMetrics(SM_CYSMICON); - rect.right = rect.left + ::GetSystemMetrics(SM_CXSMICON); - } else { - cef_dark_window::ComputeWindowIconRect(rect); - } -} - -// Computes the Rect where the window caption is drawn in window coordinates -void cef_dark_aero_window::ComputeWindowCaptionRect(RECT& rect) const -{ - if (CanUseAeroGlass()) { - RECT wr; - GetWindowRect(&wr); - - rect.top = ::kWindowFrameSize; - rect.bottom = rect.top + mNcMetrics.iCaptionHeight; - - RECT ir; - ComputeWindowIconRect(ir); - - RECT mr; - ComputeMinimizeButtonRect(mr); - - rect.left = ir.right + ::kWindowFrameSize; - rect.right = mr.left - ::kWindowFrameSize; - } else { - cef_dark_window::ComputeWindowCaptionRect(rect); - } -} // WM_NCHITTEST handler int cef_dark_aero_window::HandleNcHitTest(LPPOINT ptHit) @@ -213,35 +250,35 @@ int cef_dark_aero_window::HandleNcHitTest(LPPOINT ptHit) RECT rectCaption; ComputeWindowCaptionRect(rectCaption); - NonClientToScreen(&rectCaption); + ClientToScreen(&rectCaption); if (::PtInRect(&rectCaption, *ptHit)) return HTCAPTION; RECT rectCloseButton; ComputeCloseButtonRect(rectCloseButton); - NonClientToScreen(&rectCloseButton); + ClientToScreen(&rectCloseButton); if (::PtInRect(&rectCloseButton, *ptHit)) return HTCLOSE; RECT rectMaximizeButton; ComputeMaximizeButtonRect(rectMaximizeButton); - NonClientToScreen(&rectMaximizeButton); + ClientToScreen(&rectMaximizeButton); if (::PtInRect(&rectMaximizeButton, *ptHit)) return HTMAXBUTTON; RECT rectMinimizeButton; ComputeMinimizeButtonRect(rectMinimizeButton); - NonClientToScreen(&rectMinimizeButton); + ClientToScreen(&rectMinimizeButton); if (::PtInRect(&rectMinimizeButton, *ptHit)) return HTMINBUTTON; RECT rectSysIcon; ComputeWindowIconRect(rectSysIcon); - NonClientToScreen(&rectSysIcon); + ClientToScreen(&rectSysIcon); if (::PtInRect(&rectSysIcon, *ptHit)) return HTSYSMENU; @@ -286,7 +323,7 @@ int cef_dark_aero_window::HandleNcHitTest(LPPOINT ptHit) RECT rectMenu; ComputeRequiredMenuRect(rectMenu); - NonClientToScreen(&rectMenu); + ClientToScreen(&rectMenu); if (::PtInRect(&rectMenu, *ptHit)) return HTMENU; @@ -295,7 +332,7 @@ int cef_dark_aero_window::HandleNcHitTest(LPPOINT ptHit) // on a menu item, then return caption so // the window can be dragged from the dead space ComputeMenuBarRect(rectMenu); - NonClientToScreen(&rectMenu); + ClientToScreen(&rectMenu); if (::PtInRect(&rectMenu, *ptHit)) return HTCAPTION; @@ -318,22 +355,6 @@ void cef_dark_aero_window::InitDeviceContext(HDC hdc) } } -// Force Drawing the non-client area. -// Normally WM_NCPAINT is used but there are times when you -// need to force drawing the entire non-client area when -// legacy windows message handlers start drawing non-client -// artifacts over top of us -void cef_dark_aero_window::UpdateNonClientArea() -{ - if (CanUseAeroGlass()) { - HDC hdc = GetDC(); - DoPaintNonClientArea(hdc); - ReleaseDC(hdc); - } else { - cef_dark_window::UpdateNonClientArea(); - } -} - // WM_PAINT handler // since we're extending the client area into the non-client // area, we have to draw all of the non-clinet stuff during @@ -342,33 +363,11 @@ BOOL cef_dark_aero_window::HandlePaint() { PAINTSTRUCT ps; HDC hdc = BeginPaint(&ps); - DoPaintNonClientArea(hdc); - EndPaint(&ps); return TRUE; } -// Computes the Rect where the menu bar is drawn in window coordinates -void cef_dark_aero_window::ComputeMenuBarRect(RECT& rect) const -{ - if (CanUseAeroGlass()) { - RECT rectClient; - RECT rectCaption; - - ComputeWindowCaptionRect(rectCaption); - GetRealClientRect(&rectClient); - - rect.top = ::GetSystemMetrics(SM_CYFRAME) + mNcMetrics.iCaptionHeight + 1; - rect.bottom = rectClient.top - 1; - - rect.left = rectClient.left; - rect.right = rectClient.right; - } else { - cef_dark_window::ComputeMenuBarRect(rect); - } -} - void cef_dark_aero_window::DrawMenuBar(HDC hdc) { RECT rectWindow ; @@ -449,7 +448,8 @@ void cef_dark_aero_window::HiliteMenuItemAt(LPPOINT pt) dis.itemAction = ODA_DRAWENTIRE; dis.hDC = hdc; - ScreenToNonClient(&itemRect); + AdjustMenuItemRect(itemRect); + ::CopyRect(&dis.rcItem, &itemRect); if (mmi.fState & MFS_HILITE) { @@ -514,6 +514,58 @@ BOOL cef_dark_aero_window::HandleNcMouseMove(UINT uHitTest, LPPOINT pt) return FALSE; } +// WM_GETMINMAXINFO handler +BOOL cef_dark_aero_window::HandleGetMinMaxInfo(LPMINMAXINFO mmi) +{ + if (CanUseAeroGlass()) { + HMONITOR hm = ::MonitorFromWindow(mWnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO mi = {0}; + mi.cbSize = sizeof (mi); + + ::GetMonitorInfo(hm, &mi); + + mmi->ptMaxSize.x = mi.rcWork.right + ::kWindowFrameSize; + mmi->ptMaxSize.y = mi.rcWork.bottom + ::kWindowFrameSize; + mmi->ptMaxPosition.x = -::kWindowFrameSize; + mmi->ptMaxPosition.y = -::kWindowFrameSize; + } + + return TRUE; +} + +BOOL cef_dark_aero_window::HandleSettingChange(UINT uFlags, LPCWSTR lpszSection) +{ + if (uFlags == SPI_SETWORKAREA && CanUseAeroGlass() && IsZoomed() && WindowsTaskBar::GetAutoHideEdges(mWnd)) { + // HACK: Force the window to remaximize if the auto hide edges setting changed. + // This is a somewhat violent repositioning so we heavily qualify it to + // the app running on a monitor that has an autohide taskbar and + // the window is maximized. This ensures that window fills the work area + // after moving a taskbar to another edge + SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0L); + SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0L); + } + return TRUE; +} + + +void cef_dark_aero_window::AdjustRectForAutoHideBars(LPRECT rect) const +{ + if (CanUseAeroGlass() && IsZoomed()) + { + // adjust for auto-hide task bar + WORD edges = WindowsTaskBar::GetAutoHideEdges(mWnd); + if (edges & WindowsTaskBar::TOP_EDGE) { + rect->top -= ::kWindowFrameSize; + rect->bottom -= ::kWindowFrameSize; + } + if (edges & WindowsTaskBar::LEFT_EDGE) { + rect->left -= ::kWindowFrameSize; + rect->right -= ::kWindowFrameSize; + } + } +} + + // This is a special version of GetClientRect for Aero Glass // to give us the portion of the window that is not our custom // non-client glass so we can: @@ -534,6 +586,20 @@ BOOL cef_dark_aero_window::GetRealClientRect(LPRECT rect) const rect->left += ::kWindowFrameSize; rect->right -= ::kWindowFrameSize; + if (CanUseAeroGlass() && IsZoomed()) + { + // adjust for auto-hide task bar + WORD edges = WindowsTaskBar::GetAutoHideEdges(mWnd); + if (edges & WindowsTaskBar::BOTTOM_EDGE) { + rect->bottom += ::kWindowFrameSize; + } + if (edges & WindowsTaskBar::RIGHT_EDGE) { + rect->right += ::kWindowFrameSize; + } + if (edges & WindowsTaskBar::LEFT_EDGE) { + rect->left -= ::kWindowFrameSize; + } + } return TRUE; } @@ -541,15 +607,122 @@ BOOL cef_dark_aero_window::GetRealClientRect(LPRECT rect) const // Basically tells the system that there is no non-client area BOOL cef_dark_aero_window::HandleNcCalcSize(BOOL calcValidRects, NCCALCSIZE_PARAMS* pncsp, LRESULT* lr) { - pncsp->rgrc[0].left = pncsp->rgrc[0].left + 0; - pncsp->rgrc[0].top = pncsp->rgrc[0].top + 0; - pncsp->rgrc[0].right = pncsp->rgrc[0].right - 0; - pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0; + *lr = 0; - *lr = IsZoomed() ? WVR_REDRAW : 0; + if (CanUseAeroGlass() && IsZoomed()) + { + WORD edges = WindowsTaskBar::GetAutoHideEdges(mWnd); + // adjust for auto-hide task bar + if (edges & WindowsTaskBar::BOTTOM_EDGE) { + pncsp->rgrc[0].bottom -= kAutoHideTaskBarSize; + if (calcValidRects) { + pncsp->rgrc[1].bottom -= kAutoHideTaskBarSize; + } + } + if (edges & WindowsTaskBar::TOP_EDGE) { + pncsp->rgrc[0].top += kAutoHideTaskBarSize; + if (calcValidRects) { + pncsp->rgrc[1].top += kAutoHideTaskBarSize; + } + } + if (edges & WindowsTaskBar::RIGHT_EDGE) { + pncsp->rgrc[0].right -= kAutoHideTaskBarSize; + if (calcValidRects) { + pncsp->rgrc[1].right -= kAutoHideTaskBarSize; + } + } + if (edges & WindowsTaskBar::LEFT_EDGE) { + pncsp->rgrc[0].left += kAutoHideTaskBarSize; + if (calcValidRects) { + pncsp->rgrc[1].left += kAutoHideTaskBarSize; + } + } + } + + *lr |= IsZoomed() ? WVR_REDRAW : 0; return TRUE; } + +// Computes the Rect where the System Icon is drawn in window coordinates +void cef_dark_aero_window::ComputeWindowIconRect(RECT& rect) const +{ + if (CanUseAeroGlass()) { + int top = ::kWindowFrameSize; + int left = ::kWindowFrameSize; + + if (IsZoomed()) { + top = ::kSystemIconZoomFactorCY; + left = ::kSystemIconZoomFactorCX; + } + + ::SetRectEmpty(&rect); + rect.top = top; + rect.left = left; + rect.bottom = rect.top + ::GetSystemMetrics(SM_CYSMICON); + rect.right = rect.left + ::GetSystemMetrics(SM_CXSMICON); + + AdjustRectForAutoHideBars(&rect); + } else { + cef_dark_window::ComputeWindowIconRect(rect); + } +} + +// Computes the Rect where the window caption is drawn in window coordinates +void cef_dark_aero_window::ComputeWindowCaptionRect(RECT& rect) const +{ + if (CanUseAeroGlass()) { + RECT wr; + GetWindowRect(&wr); + + rect.top = ::kWindowFrameSize; + rect.bottom = rect.top + mNcMetrics.iCaptionHeight; + + RECT ir; + ComputeWindowIconRect(ir); + + RECT mr; + ComputeMinimizeButtonRect(mr); + + rect.left = ir.right + ::kWindowFrameSize; + rect.right = mr.left - ::kWindowFrameSize; + + AdjustRectForAutoHideBars(&rect); + } else { + cef_dark_window::ComputeWindowCaptionRect(rect); + } +} + +// Computes the Rect where the menu bar is drawn in window coordinates +void cef_dark_aero_window::ComputeMenuBarRect(RECT& rect) const +{ + if (CanUseAeroGlass()) { + RECT rectClient; + RECT rectCaption; + + GetRealClientRect(&rectClient); + + if (IsZoomed()) { + ComputeWindowCaptionRect(rectCaption); + rect.top = rectCaption.bottom; + } else { + rect.top = ::GetSystemMetrics(SM_CYFRAME) + mNcMetrics.iCaptionHeight + 1; + } + rect.bottom = rectClient.top - 1; + + rect.left = rectClient.left; + rect.right = rectClient.right; + } else { + cef_dark_window::ComputeMenuBarRect(rect); + } +} + +void cef_dark_aero_window::ComputeCloseButtonRect(RECT& rect) const +{ + cef_dark_window::ComputeCloseButtonRect(rect); + AdjustRectForAutoHideBars(&rect); +} + // Helper to dispatch messages to the Desktop Window Manager for processing LRESULT cef_dark_aero_window::DwpCustomFrameProc(UINT message, WPARAM wParam, LPARAM lParam, bool* pfCallDefWindowProc) { @@ -631,6 +804,10 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc); switch(message) { + case WM_SETTINGCHANGE: + HandleSettingChange((UINT)wParam, (LPCWSTR)lParam); + break; + case WM_NCACTIVATE: case WM_ACTIVATE: if (mReady) { @@ -683,6 +860,9 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa switch (message) { + case WM_GETMINMAXINFO: + HandleGetMinMaxInfo((LPMINMAXINFO) lParam); + break; case WM_SETTEXT: case WM_WINDOWPOSCHANGING: case WM_WINDOWPOSCHANGED: diff --git a/appshell/cef_dark_aero_window.h b/appshell/cef_dark_aero_window.h index e2a2215a8..e7fc9373b 100644 --- a/appshell/cef_dark_aero_window.h +++ b/appshell/cef_dark_aero_window.h @@ -83,6 +83,8 @@ class cef_dark_aero_window : public cef_dark_window BOOL HandleNcCalcSize(BOOL calcValidRects, NCCALCSIZE_PARAMS* lpncsp, LRESULT* lr); BOOL HandleNcMouseMove(UINT uHitTest, LPPOINT pt); BOOL HandleNcLeftButtonDown(UINT uHitTest, LPPOINT pt); + BOOL HandleGetMinMaxInfo(LPMINMAXINFO mmi); + BOOL HandleSettingChange(UINT uFlags, LPCWSTR lpszSection); void HandleNcMouseLeave(); int HandleNcHitTest(LPPOINT ptHit); @@ -92,7 +94,6 @@ class cef_dark_aero_window : public cef_dark_window virtual void DrawMenuBar(HDC hdc); virtual void HiliteMenuItemAt(LPPOINT pt); - virtual void UpdateNonClientArea(); virtual void UpdateMenuBar(); virtual void InitDeviceContext(HDC hdc); @@ -100,6 +101,9 @@ class cef_dark_aero_window : public cef_dark_window virtual void ComputeMenuBarRect(RECT& rect) const; virtual void ComputeWindowCaptionRect(RECT& rect) const; virtual void ComputeWindowIconRect(RECT& rect) const; + virtual void ComputeCloseButtonRect(RECT& rect) const; + + void AdjustRectForAutoHideBars(LPRECT rect) const; LRESULT DwpCustomFrameProc(UINT message, WPARAM wParam, LPARAM lParam, bool* pfCallDefWindowProc); diff --git a/appshell/cef_dark_window.cpp b/appshell/cef_dark_window.cpp index 785792f81..b7e15ae8c 100644 --- a/appshell/cef_dark_window.cpp +++ b/appshell/cef_dark_window.cpp @@ -41,6 +41,7 @@ extern HINSTANCE hInst; static ULONG_PTR gdiplusToken = NULL; // Constants +static const int kMenuPadding = 4; static const int kWindowFrameZoomFactorCY = 4; static const int kSystemIconZoomFactorCY = 4; static const int kSystemIconZoomFactorCX = 2; @@ -400,7 +401,9 @@ void cef_dark_window::ComputeRequiredMenuRect(RECT& rect) const RECT itemRect; ::SetRectEmpty(&itemRect); if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) { - ScreenToNonClient(&itemRect); + itemRect.bottom += ::kMenuPadding; + AdjustMenuItemRect(itemRect); + RECT dest; if (::UnionRect(&dest, &rect, &itemRect)) { ::CopyRect(&rect, &dest); @@ -622,6 +625,15 @@ void cef_dark_window::InitDeviceContext(HDC hdc) ::ExcludeClipRect(hdc, rectClipClient.left, rectClipClient.top, rectClipClient.right, rectClipClient.bottom); } +void cef_dark_window::AdjustMenuItemRect(RECT &itemRect) const +{ + if (CanUseAeroGlass() && IsZoomed()) { + ScreenToClient(&itemRect); + } else { + ScreenToNonClient(&itemRect); + } +} + // This Really just Draws the menu bar items since it assumes // that the background has already been drawn using DoDrawFrame void cef_dark_window::DoDrawMenuBar(HDC hdc) @@ -643,7 +655,7 @@ void cef_dark_window::DoDrawMenuBar(HDC hdc) ::SetRectEmpty(&itemRect); if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) { - ScreenToNonClient(&itemRect); + AdjustMenuItemRect(itemRect); POINT ptTopLeftItem = {itemRect.left, itemRect.top}; @@ -683,11 +695,11 @@ void cef_dark_window::DoDrawMenuBar(HDC hdc) void cef_dark_window::DoPaintNonClientArea(HDC hdc) { EnforceMenuBackground(); - cef_buffered_dc dc(this, hdc); InitDeviceContext(dc); InitDeviceContext(dc.GetWindowDC()); + DoDrawFrame(dc); DoDrawSystemMenuIcon(dc); DoDrawTitlebarText(dc); @@ -709,7 +721,13 @@ void cef_dark_window::DoRepaintClientArea() // artifacts over top of us void cef_dark_window::UpdateNonClientArea() { - HDC hdc = GetWindowDC(); + HDC hdc; + if (CanUseAeroGlass()) { + hdc = GetDC(); + } else { + hdc = GetWindowDC(); + } + DoPaintNonClientArea(hdc); ReleaseDC(hdc); } @@ -830,7 +848,13 @@ void cef_dark_window::UpdateNonClientButtons () { // create a simple clipping region // that only includes the system buttons (min/max/restore/close) - HDC hdc = GetWindowDC(); + HDC hdc; + + if (CanUseAeroGlass()) { + hdc = GetDC(); + } else { + hdc = GetWindowDC(); + } RECT rectCloseButton ; ComputeCloseButtonRect (rectCloseButton) ; diff --git a/appshell/cef_dark_window.h b/appshell/cef_dark_window.h index 0e3945964..c4451d00a 100644 --- a/appshell/cef_dark_window.h +++ b/appshell/cef_dark_window.h @@ -128,7 +128,8 @@ class cef_dark_window : public cef_window virtual void ComputeMenuBarRect(RECT& rect) const; virtual void ComputeRequiredMenuRect(RECT& rect) const; - + virtual void AdjustMenuItemRect(RECT& itemRect) const; + // Drawing Initializers void InitDrawingResources(); void LoadSysButtonImages(); diff --git a/appshell/cef_main_window.cpp b/appshell/cef_main_window.cpp index 4388074fd..4f448e8d4 100644 --- a/appshell/cef_main_window.cpp +++ b/appshell/cef_main_window.cpp @@ -500,10 +500,6 @@ LRESULT cef_main_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (HandlePaint()) return 0L; break; - case WM_GETMINMAXINFO: - if (HandleGetMinMaxInfo((LPMINMAXINFO) lParam)) - return 0L; - break; case WM_DESTROY: if (HandleDestroy()) return 0L; @@ -528,5 +524,12 @@ LRESULT cef_main_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) LRESULT lr = cef_host_window::WindowProc(message, wParam, lParam); + switch (message) + { + case WM_GETMINMAXINFO: + HandleGetMinMaxInfo((LPMINMAXINFO) lParam); + break; + } + return lr; } From 06467ebf3364c3c33a9a8908d5876e0d65a4becc Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Thu, 16 Oct 2014 08:51:00 -0700 Subject: [PATCH 2/4] Fix tabs --- appshell/cef_dark_aero_window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appshell/cef_dark_aero_window.cpp b/appshell/cef_dark_aero_window.cpp index c7e5cdf9b..c095159f6 100644 --- a/appshell/cef_dark_aero_window.cpp +++ b/appshell/cef_dark_aero_window.cpp @@ -662,7 +662,7 @@ void cef_dark_aero_window::ComputeWindowIconRect(RECT& rect) const rect.bottom = rect.top + ::GetSystemMetrics(SM_CYSMICON); rect.right = rect.left + ::GetSystemMetrics(SM_CXSMICON); - AdjustRectForAutoHideBars(&rect); + AdjustRectForAutoHideBars(&rect); } else { cef_dark_window::ComputeWindowIconRect(rect); } @@ -687,7 +687,7 @@ void cef_dark_aero_window::ComputeWindowCaptionRect(RECT& rect) const rect.left = ir.right + ::kWindowFrameSize; rect.right = mr.left - ::kWindowFrameSize; - AdjustRectForAutoHideBars(&rect); + AdjustRectForAutoHideBars(&rect); } else { cef_dark_window::ComputeWindowCaptionRect(rect); } From 13e32bc05a376c34517ee3141c2cc1c09d3723a7 Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Thu, 16 Oct 2014 10:56:11 -0700 Subject: [PATCH 3/4] compute width rather than use right/bottom edges as width --- appshell/cef_dark_aero_window.cpp | 20 ++++++++--------- appshell/cef_window.h | 37 ++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/appshell/cef_dark_aero_window.cpp b/appshell/cef_dark_aero_window.cpp index c095159f6..002bfb1cf 100644 --- a/appshell/cef_dark_aero_window.cpp +++ b/appshell/cef_dark_aero_window.cpp @@ -517,18 +517,18 @@ BOOL cef_dark_aero_window::HandleNcMouseMove(UINT uHitTest, LPPOINT pt) // WM_GETMINMAXINFO handler BOOL cef_dark_aero_window::HandleGetMinMaxInfo(LPMINMAXINFO mmi) { - if (CanUseAeroGlass()) { - HMONITOR hm = ::MonitorFromWindow(mWnd, MONITOR_DEFAULTTONEAREST); - MONITORINFO mi = {0}; - mi.cbSize = sizeof (mi); + if (CanUseAeroGlass()) { + HMONITOR hm = ::MonitorFromWindow(mWnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO mi = {0}; + mi.cbSize = sizeof (mi); - ::GetMonitorInfo(hm, &mi); + ::GetMonitorInfo(hm, &mi); + mmi->ptMaxSize.x = ::RectWidth(mi.rcWork) + ::kWindowFrameSize; + mmi->ptMaxSize.y = ::RectHeight(mi.rcWork) + ::kWindowFrameSize; - mmi->ptMaxSize.x = mi.rcWork.right + ::kWindowFrameSize; - mmi->ptMaxSize.y = mi.rcWork.bottom + ::kWindowFrameSize; - mmi->ptMaxPosition.x = -::kWindowFrameSize; - mmi->ptMaxPosition.y = -::kWindowFrameSize; - } + mmi->ptMaxPosition.x = -::kWindowFrameSize; + mmi->ptMaxPosition.y = -::kWindowFrameSize; + } return TRUE; } diff --git a/appshell/cef_window.h b/appshell/cef_window.h index 2f45353ca..2d71970de 100644 --- a/appshell/cef_window.h +++ b/appshell/cef_window.h @@ -28,9 +28,6 @@ class cef_window; class cef_menu; // RECT helpers -static __inline int RectWidth(const RECT &r) { return r.right - r.left; } -static __inline int RectHeight(const RECT &r) { return r.bottom - r.top; } - static __inline void RectSwapLeftRight(RECT &r) { LONG temp = r.left; @@ -38,6 +35,40 @@ static __inline void RectSwapLeftRight(RECT &r) r.right = temp; } +static __inline void NormalizeRect(RECT& r) +{ + int nTemp; + if (r.left > r.right) + { + nTemp = r.left; + r.left = r.right; + r.right = nTemp; + } + if (r.top > r.bottom) + { + nTemp = r.top; + r.top = r.bottom; + r.bottom = nTemp; + } +} + +static __inline int RectWidth(const RECT &rIn) +{ + RECT r; + ::CopyRect(&r, &rIn); + ::NormalizeRect(r); + return r.right - r.left; +} + +static __inline int RectHeight(const RECT &rIn) +{ + RECT r; + ::CopyRect(&r, &rIn); + ::NormalizeRect(r); + return r.bottom - r.top; +} + + // Undocumented Flags for GetDCEx() #ifndef DCX_USESTYLE #define DCX_USESTYLE 0x00010000 From 10e13786b3ff115de070589cc63ae6e444707083 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 16 Oct 2014 11:47:55 -0700 Subject: [PATCH 4/4] fix whitespace consistency --- appshell/cef_dark_aero_window.cpp | 16 ++++++++-------- appshell/cef_dark_window.cpp | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/appshell/cef_dark_aero_window.cpp b/appshell/cef_dark_aero_window.cpp index 002bfb1cf..a8e83bf2c 100644 --- a/appshell/cef_dark_aero_window.cpp +++ b/appshell/cef_dark_aero_window.cpp @@ -343,7 +343,7 @@ int cef_dark_aero_window::HandleNcHitTest(LPPOINT ptHit) // Setup the device context for drawing void cef_dark_aero_window::InitDeviceContext(HDC hdc) { - if (CanUseAeroGlass()) { + if (CanUseAeroGlass()) { RECT rectClipClient; SetRectEmpty(&rectClipClient); GetRealClientRect(&rectClipClient); @@ -386,8 +386,8 @@ void cef_dark_aero_window::DrawMenuBar(HDC hdc) HRGN hrgnUpdate = ::CreateRectRgnIndirect(&rectMenu); if (::SelectClipRgn(hdc, hrgnUpdate) != NULLREGION) { - DoDrawFrame(hdc); // Draw menu bar background - DoDrawMenuBar(hdc); // DraW menu items + DoDrawFrame(hdc); // Draw menu bar background + DoDrawMenuBar(hdc); // DraW menu items } ::DeleteObject(hrgnUpdate); @@ -523,7 +523,7 @@ BOOL cef_dark_aero_window::HandleGetMinMaxInfo(LPMINMAXINFO mmi) mi.cbSize = sizeof (mi); ::GetMonitorInfo(hm, &mi); - mmi->ptMaxSize.x = ::RectWidth(mi.rcWork) + ::kWindowFrameSize; + mmi->ptMaxSize.x = ::RectWidth(mi.rcWork) + ::kWindowFrameSize; mmi->ptMaxSize.y = ::RectHeight(mi.rcWork) + ::kWindowFrameSize; mmi->ptMaxPosition.x = -::kWindowFrameSize; @@ -653,7 +653,7 @@ void cef_dark_aero_window::ComputeWindowIconRect(RECT& rect) const if (IsZoomed()) { top = ::kSystemIconZoomFactorCY; - left = ::kSystemIconZoomFactorCX; + left = ::kSystemIconZoomFactorCX; } ::SetRectEmpty(&rect); @@ -661,8 +661,8 @@ void cef_dark_aero_window::ComputeWindowIconRect(RECT& rect) const rect.left = left; rect.bottom = rect.top + ::GetSystemMetrics(SM_CYSMICON); rect.right = rect.left + ::GetSystemMetrics(SM_CXSMICON); - - AdjustRectForAutoHideBars(&rect); + + AdjustRectForAutoHideBars(&rect); } else { cef_dark_window::ComputeWindowIconRect(rect); } @@ -687,7 +687,7 @@ void cef_dark_aero_window::ComputeWindowCaptionRect(RECT& rect) const rect.left = ir.right + ::kWindowFrameSize; rect.right = mr.left - ::kWindowFrameSize; - AdjustRectForAutoHideBars(&rect); + AdjustRectForAutoHideBars(&rect); } else { cef_dark_window::ComputeWindowCaptionRect(rect); } diff --git a/appshell/cef_dark_window.cpp b/appshell/cef_dark_window.cpp index b7e15ae8c..d406294f1 100644 --- a/appshell/cef_dark_window.cpp +++ b/appshell/cef_dark_window.cpp @@ -315,7 +315,7 @@ void cef_dark_window::ComputeWindowIconRect(RECT& rect) const if (IsZoomed()) { top += ::kSystemIconZoomFactorCY; - left += ::kSystemIconZoomFactorCX; + left += ::kSystemIconZoomFactorCX; } ::SetRectEmpty(&rect); rect.top = top; @@ -722,7 +722,7 @@ void cef_dark_window::DoRepaintClientArea() void cef_dark_window::UpdateNonClientArea() { HDC hdc; - if (CanUseAeroGlass()) { + if (CanUseAeroGlass()) { hdc = GetDC(); } else { hdc = GetWindowDC();