From 5d30417e89c41464ea8759f71c8ada9948573e1a Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Wed, 2 Oct 2013 13:07:25 -0700 Subject: [PATCH 1/2] allow brackets to be dragged by the caption bar alot easier --- appshell/cef_dark_window.cpp | 31 ++++++++++++++++++++++++++++++- appshell/cef_dark_window.h | 3 ++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/appshell/cef_dark_window.cpp b/appshell/cef_dark_window.cpp index 2eb0d00ad..df06092a7 100644 --- a/appshell/cef_dark_window.cpp +++ b/appshell/cef_dark_window.cpp @@ -379,6 +379,27 @@ void cef_dark_window::ComputeCloseButtonRect(RECT& rect) rect.bottom = rect.top + mSysCloseButton->GetHeight(); } + +void cef_dark_window::ComputeRequiredMenuRect(RECT& rect) +{ + HMENU menu = GetMenu(); + int items = ::GetMenuItemCount(menu); + + ::SetRectEmpty(&rect); + + for (int i = 0; i < items; i++) { + RECT itemRect; + ::SetRectEmpty(&itemRect); + if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) { + ScreenToNonClient(&itemRect); + RECT dest; + ::CopyRect(&dest, &rect); + ::UnionRect(&dest, &rect, &itemRect); + ::CopyRect(&rect, &dest); + } + } +} + // Computes the Rect where the menu bar is drawn in window coordinates void cef_dark_window::ComputeMenuBarRect(RECT& rect) { @@ -782,7 +803,15 @@ int cef_dark_window::HandleNcHitTest(LPPOINT ptHit) if (ptHit->y >= rectWindow.bottom - ::GetSystemMetrics (SM_CYFRAME)) return HTBOTTOM; - return HTMENU; + // If it's not in the menu, it's in the caption + RECT rectMenu; + ComputeRequiredMenuRect(rectMenu); + NonClientToScreen(&rectMenu); + + if (::PtInRect(&rectMenu, *ptHit)) + return HTMENU; + + return HTCAPTION; } // Like UpdateNonClientArea, but sets up a clipping region to just update the system buttons diff --git a/appshell/cef_dark_window.h b/appshell/cef_dark_window.h index 116fe70a6..ae6c21202 100644 --- a/appshell/cef_dark_window.h +++ b/appshell/cef_dark_window.h @@ -118,7 +118,8 @@ class cef_dark_window : public cef_window virtual void ComputeMaximizeButtonRect(RECT& rect); virtual void ComputeCloseButtonRect(RECT& rect); virtual void ComputeMenuBarRect(RECT& rect); - + virtual void ComputeRequiredMenuRect(RECT& rect); + // Drawing Initializers void InitDrawingResources(); From f42cfa140e63e96b55abb242c7180f6cb12872de Mon Sep 17 00:00:00 2001 From: Jeff Booher Date: Thu, 3 Oct 2013 10:20:14 -0700 Subject: [PATCH 2/2] optimize union rect code --- appshell/cef_dark_window.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appshell/cef_dark_window.cpp b/appshell/cef_dark_window.cpp index df06092a7..688fbc53c 100644 --- a/appshell/cef_dark_window.cpp +++ b/appshell/cef_dark_window.cpp @@ -393,9 +393,9 @@ void cef_dark_window::ComputeRequiredMenuRect(RECT& rect) if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) { ScreenToNonClient(&itemRect); RECT dest; - ::CopyRect(&dest, &rect); - ::UnionRect(&dest, &rect, &itemRect); - ::CopyRect(&rect, &dest); + if (::UnionRect(&dest, &rect, &itemRect)) { + ::CopyRect(&rect, &dest); + } } } }