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

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
* adobe/brackets#7222
* adobe/brackets#5288
* adobe/brackets#6801

Added
cef_buffered_dc for easier impl of buffered drawing

Removed dup
f474f06#commitcomment-6319894
  • Loading branch information
JeffryBooher committed May 14, 2014
1 parent 70d041a commit 4a220ed
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 123 deletions.
105 changes: 105 additions & 0 deletions appshell/cef_buffered_dc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma once
/*
* Copyright (c) 2013 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)
: mWnd(window)
, mWindowDC(NULL)
, mDcMem(NULL)
, mBitmap(NULL)
, mBmOld(NULL)
, mWidth(0)
, mHeight(0)
, mReleaseDcOnDestroy(true)
{
mWindowDC = mWnd->GetDC();
CommonInit();
}

cef_buffered_dc(cef_window* window, HDC hdc)
: 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()
{
::BitBlt(mWindowDC, 0, 0, mWidth, mHeight, mDcMem, 0, 0, SRCCOPY);

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

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

private:
cef_buffered_dc(const cef_buffered_dc&)
{
}

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

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

protected:
cef_window* mWnd;
HDC mWindowDC;
HDC mDcMem;
HBITMAP mBitmap;
HGDIOBJ mBmOld;
int mWidth;
int mHeight;
bool mReleaseDcOnDestroy;
};
53 changes: 6 additions & 47 deletions appshell/cef_dark_aero_window.cpp
Original file line number Diff line number Diff line change
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,13 +395,6 @@ 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);
}

// The Aero version doesn't send us WM_DRAWITEM messages
// to draw the item when hovering so we have to do that
Expand Down Expand Up @@ -675,7 +630,7 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
switch(message) {
case WM_ACTIVATE:
if (mReady) {
UpdateMenuBar();
UpdateNonClientArea();
}
break;
case WM_NCMOUSELEAVE:
Expand Down Expand Up @@ -742,6 +697,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
12 changes: 5 additions & 7 deletions appshell/cef_dark_aero_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,16 @@ 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 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

0 comments on commit 4a220ed

Please sign in to comment.