Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Fixes several aero and dark shell issues #443

Closed
wants to merge 13 commits into from
109 changes: 109 additions & 0 deletions appshell/cef_buffered_dc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once
/*
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "cef_window.h"


class cef_buffered_dc
{
public:
cef_buffered_dc(cef_window* window, HDC hdc = NULL)
: mWnd(window)
, mWindowDC(hdc)
, mDcMem(NULL)
, mBitmap(NULL)
, mBmOld(NULL)
, mWidth(0)
, mHeight(0)
, mReleaseDcOnDestroy(false)
{
CommonInit();
}

operator HDC()
{
return mDcMem;
}

HDC GetWindowDC()
{
return mWindowDC;
}

~cef_buffered_dc()
{
Destroy();
}

private:
cef_buffered_dc()
{
}

cef_buffered_dc(const cef_buffered_dc& other)
{
}

protected:
void CommonInit()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be safe, you should check for mWnd != NULL. eg. someone else uses this class or maybe if new code sneaks in that calls the hidden constructor from within this class.

if (mWnd) {
if (mWindowDC == NULL) {
mWindowDC = mWnd->GetDC();
mReleaseDcOnDestroy = true;
}

RECT rectWindow;
mWnd->GetWindowRect(&rectWindow);
mWidth = ::RectWidth(rectWindow);
mHeight = ::RectHeight(rectWindow);

mDcMem = ::CreateCompatibleDC(mWindowDC);
mBitmap = ::CreateCompatibleBitmap(mWindowDC, mWidth, mHeight);
mBmOld = ::SelectObject(mDcMem, mBitmap);
}
}

void Destroy()
{
if (mWnd) {
::BitBlt(mWindowDC, 0, 0, mWidth, mHeight, mDcMem, 0, 0, SRCCOPY);

::SelectObject(mDcMem, mBmOld);
::DeleteObject(mBitmap);
::DeleteDC(mDcMem);

if (mReleaseDcOnDestroy) {
mWnd->ReleaseDC(mWindowDC);
}
}
}

cef_window* mWnd;
HDC mWindowDC;
HDC mDcMem;
HBITMAP mBitmap;
HGDIOBJ mBmOld;
int mWidth;
int mHeight;
bool mReleaseDcOnDestroy;
};
59 changes: 11 additions & 48 deletions appshell/cef_dark_aero_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "cef_dark_aero_window.h"

#include <stdio.h>
// Constants
static const int kWindowFrameSize = 8;
static const int kSystemIconZoomFactorCX = kWindowFrameSize + 2;
Expand Down Expand Up @@ -318,44 +318,6 @@ void cef_dark_aero_window::InitDeviceContext(HDC hdc)
}
}

// Redraws the non-client area
void cef_dark_aero_window::DoPaintNonClientArea(HDC hdc)
{
if (CanUseAeroGlass()) {
EnforceMenuBackground();

HDC hdcOrig = hdc;
RECT rectWindow;
GetWindowRect(&rectWindow);

int Width = ::RectWidth(rectWindow);
int Height = ::RectHeight(rectWindow);

HDC dcMem = ::CreateCompatibleDC(hdc);
HBITMAP bm = ::CreateCompatibleBitmap(hdc, Width, Height);
HGDIOBJ bmOld = ::SelectObject(dcMem, bm);

hdc = dcMem;

InitDeviceContext(hdc);
InitDeviceContext(hdcOrig);

DoDrawFrame(hdc);
DoDrawSystemMenuIcon(hdc);
DoDrawTitlebarText(hdc);
DoDrawSystemIcons(hdc);
DoDrawMenuBar(hdc);

::BitBlt(hdcOrig, 0, 0, Width, Height, dcMem, 0, 0, SRCCOPY);

::SelectObject(dcMem, bmOld);
::DeleteObject(bm);
::DeleteDC(dcMem);
} else {
cef_dark_window::DoPaintNonClientArea(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
Expand Down Expand Up @@ -397,7 +359,7 @@ void cef_dark_aero_window::ComputeMenuBarRect(RECT& rect) const
ComputeWindowCaptionRect(rectCaption);
GetRealClientRect(&rectClient);

rect.top = rectCaption.bottom + 1;
rect.top = ::GetSystemMetrics(SM_CYFRAME) + mNcMetrics.iCaptionHeight + 1;
rect.bottom = rectClient.top - 1;

rect.left = rectClient.left;
Expand Down Expand Up @@ -433,12 +395,10 @@ void cef_dark_aero_window::DrawMenuBar(HDC hdc)
}
}

// Redraws the menu bar
void cef_dark_aero_window::UpdateMenuBar()
{
HDC hdc = GetWindowDC();
DrawMenuBar(hdc);
ReleaseDC(hdc);
cef_buffered_dc dc(this);
DrawMenuBar(dc);
}

// The Aero version doesn't send us WM_DRAWITEM messages
Expand Down Expand Up @@ -586,7 +546,7 @@ BOOL cef_dark_aero_window::HandleNcCalcSize(BOOL calcValidRects, NCCALCSIZE_PARA
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;
return TRUE;
}

Expand Down Expand Up @@ -641,15 +601,13 @@ LRESULT cef_dark_aero_window::DwpCustomFrameProc(UINT message, WPARAM wParam, LP
return lr;
}


// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
bool callDefWindowProc = true;

switch (message)
{

case WM_MEASUREITEM:
if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
return 0L;
Expand All @@ -673,9 +631,10 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc);

switch(message) {
case WM_NCACTIVATE:
case WM_ACTIVATE:
if (mReady) {
UpdateMenuBar();
UpdateNonClientArea();
}
break;
case WM_NCMOUSELEAVE:
Expand Down Expand Up @@ -742,6 +701,10 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
case WM_EXITMENULOOP:
mMenuActiveIndex = -1;
break;
case WM_ACTIVATEAPP:
mIsActive = (BOOL)wParam;
UpdateNonClientArea();
break;
}

return lr;
Expand Down
21 changes: 13 additions & 8 deletions appshell/cef_dark_aero_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
#include "cef_dark_window.h"
#include <dwmapi.h>

#define CDW_UPDATEMENU WM_USER+1004
// Undocumented Aero Messages
#define WM_UAHDESTROYWINDOW 0x0090
#define WM_UAHDRAWMENU 0x0091
#define WM_UAHDRAWMENUITEM 0x0092
#define WM_UAHINITMENU 0x0093
#define WM_UAHMEASUREMENUITEM 0x0094
#define WM_UAHNCPAINTMENUPOPUP 0x0095

// prototypes for DWM function pointers
typedef HRESULT (STDAPICALLTYPE *PFNDWMEFICA)(HWND hWnd, __in const MARGINS* pMarInset);
Expand Down Expand Up @@ -83,18 +89,17 @@ class cef_dark_aero_window : public cef_dark_window

void PostHandleNcLeftButtonUp(UINT uHitTest, LPPOINT pt);

void DrawMenuBar(HDC hdc);
void UpdateMenuBar();
void HiliteMenuItemAt(LPPOINT pt);
virtual void DrawMenuBar(HDC hdc);
virtual void HiliteMenuItemAt(LPPOINT pt);

virtual void UpdateNonClientArea();
virtual void UpdateMenuBar();

virtual void InitDeviceContext(HDC hdc);
virtual void DoPaintNonClientArea(HDC hdc);

void ComputeMenuBarRect(RECT& rect) const;
void ComputeWindowCaptionRect(RECT& rect) const;
void ComputeWindowIconRect(RECT& rect) const;
virtual void ComputeMenuBarRect(RECT& rect) const;
virtual void ComputeWindowCaptionRect(RECT& rect) const;
virtual void ComputeWindowIconRect(RECT& rect) const;

LRESULT DwpCustomFrameProc(UINT message, WPARAM wParam, LPARAM lParam, bool* pfCallDefWindowProc);

Expand Down
Loading