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

Commit b8e3c8b

Browse files
committed
Merge pull request #445 from adobe/jeff/fix_aero_9
Fixes various Aero drawing issues
2 parents 70d041a + cfb2722 commit b8e3c8b

11 files changed

+266
-169
lines changed

appshell/cef_buffered_dc.h

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#pragma once
2+
/*
3+
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a
6+
* copy of this software and associated documentation files (the "Software"),
7+
* to deal in the Software without restriction, including without limitation
8+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
* and/or sell copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*/
23+
#include "cef_window.h"
24+
25+
26+
class cef_buffered_dc
27+
{
28+
public:
29+
cef_buffered_dc(cef_window* window, HDC hdc = NULL)
30+
: mWnd(window)
31+
, mWindowDC(hdc)
32+
, mDcMem(NULL)
33+
, mBitmap(NULL)
34+
, mBmOld(NULL)
35+
, mWidth(0)
36+
, mHeight(0)
37+
, mReleaseDcOnDestroy(false)
38+
{
39+
CommonInit();
40+
}
41+
42+
operator HDC()
43+
{
44+
return mDcMem;
45+
}
46+
47+
HDC GetWindowDC()
48+
{
49+
return mWindowDC;
50+
}
51+
52+
~cef_buffered_dc()
53+
{
54+
Destroy();
55+
}
56+
57+
private:
58+
cef_buffered_dc()
59+
{
60+
}
61+
62+
cef_buffered_dc(const cef_buffered_dc& other)
63+
{
64+
}
65+
66+
protected:
67+
void CommonInit()
68+
{
69+
if (mWnd) {
70+
if (mWindowDC == NULL) {
71+
mWindowDC = mWnd->GetDC();
72+
mReleaseDcOnDestroy = true;
73+
}
74+
75+
RECT rectWindow;
76+
mWnd->GetWindowRect(&rectWindow);
77+
mWidth = ::RectWidth(rectWindow);
78+
mHeight = ::RectHeight(rectWindow);
79+
80+
mDcMem = ::CreateCompatibleDC(mWindowDC);
81+
mBitmap = ::CreateCompatibleBitmap(mWindowDC, mWidth, mHeight);
82+
mBmOld = ::SelectObject(mDcMem, mBitmap);
83+
}
84+
}
85+
86+
void Destroy()
87+
{
88+
if (mWnd) {
89+
::BitBlt(mWindowDC, 0, 0, mWidth, mHeight, mDcMem, 0, 0, SRCCOPY);
90+
91+
::SelectObject(mDcMem, mBmOld);
92+
::DeleteObject(mBitmap);
93+
::DeleteDC(mDcMem);
94+
95+
if (mReleaseDcOnDestroy) {
96+
mWnd->ReleaseDC(mWindowDC);
97+
}
98+
}
99+
}
100+
101+
cef_window* mWnd;
102+
HDC mWindowDC;
103+
HDC mDcMem;
104+
HBITMAP mBitmap;
105+
HGDIOBJ mBmOld;
106+
int mWidth;
107+
int mHeight;
108+
bool mReleaseDcOnDestroy;
109+
};

appshell/cef_dark_aero_window.cpp

+11-48
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* DEALINGS IN THE SOFTWARE.
2121
*/
2222
#include "cef_dark_aero_window.h"
23-
23+
#include <stdio.h>
2424
// Constants
2525
static const int kWindowFrameSize = 8;
2626
static const int kSystemIconZoomFactorCX = kWindowFrameSize + 2;
@@ -318,44 +318,6 @@ void cef_dark_aero_window::InitDeviceContext(HDC hdc)
318318
}
319319
}
320320

321-
// Redraws the non-client area
322-
void cef_dark_aero_window::DoPaintNonClientArea(HDC hdc)
323-
{
324-
if (CanUseAeroGlass()) {
325-
EnforceMenuBackground();
326-
327-
HDC hdcOrig = hdc;
328-
RECT rectWindow;
329-
GetWindowRect(&rectWindow);
330-
331-
int Width = ::RectWidth(rectWindow);
332-
int Height = ::RectHeight(rectWindow);
333-
334-
HDC dcMem = ::CreateCompatibleDC(hdc);
335-
HBITMAP bm = ::CreateCompatibleBitmap(hdc, Width, Height);
336-
HGDIOBJ bmOld = ::SelectObject(dcMem, bm);
337-
338-
hdc = dcMem;
339-
340-
InitDeviceContext(hdc);
341-
InitDeviceContext(hdcOrig);
342-
343-
DoDrawFrame(hdc);
344-
DoDrawSystemMenuIcon(hdc);
345-
DoDrawTitlebarText(hdc);
346-
DoDrawSystemIcons(hdc);
347-
DoDrawMenuBar(hdc);
348-
349-
::BitBlt(hdcOrig, 0, 0, Width, Height, dcMem, 0, 0, SRCCOPY);
350-
351-
::SelectObject(dcMem, bmOld);
352-
::DeleteObject(bm);
353-
::DeleteDC(dcMem);
354-
} else {
355-
cef_dark_window::DoPaintNonClientArea(hdc);
356-
}
357-
}
358-
359321
// Force Drawing the non-client area.
360322
// Normally WM_NCPAINT is used but there are times when you
361323
// need to force drawing the entire non-client area when
@@ -397,7 +359,7 @@ void cef_dark_aero_window::ComputeMenuBarRect(RECT& rect) const
397359
ComputeWindowCaptionRect(rectCaption);
398360
GetRealClientRect(&rectClient);
399361

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

403365
rect.left = rectClient.left;
@@ -433,12 +395,10 @@ void cef_dark_aero_window::DrawMenuBar(HDC hdc)
433395
}
434396
}
435397

436-
// Redraws the menu bar
437398
void cef_dark_aero_window::UpdateMenuBar()
438399
{
439-
HDC hdc = GetWindowDC();
440-
DrawMenuBar(hdc);
441-
ReleaseDC(hdc);
400+
cef_buffered_dc dc(this);
401+
DrawMenuBar(dc);
442402
}
443403

444404
// The Aero version doesn't send us WM_DRAWITEM messages
@@ -586,7 +546,7 @@ BOOL cef_dark_aero_window::HandleNcCalcSize(BOOL calcValidRects, NCCALCSIZE_PARA
586546
pncsp->rgrc[0].right = pncsp->rgrc[0].right - 0;
587547
pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0;
588548

589-
*lr = 0;
549+
*lr = IsZoomed() ? WVR_REDRAW : 0;
590550
return TRUE;
591551
}
592552

@@ -641,15 +601,13 @@ LRESULT cef_dark_aero_window::DwpCustomFrameProc(UINT message, WPARAM wParam, LP
641601
return lr;
642602
}
643603

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

650609
switch (message)
651610
{
652-
653611
case WM_MEASUREITEM:
654612
if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
655613
return 0L;
@@ -673,9 +631,10 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
673631
LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc);
674632

675633
switch(message) {
634+
case WM_NCACTIVATE:
676635
case WM_ACTIVATE:
677636
if (mReady) {
678-
UpdateMenuBar();
637+
UpdateNonClientArea();
679638
}
680639
break;
681640
case WM_NCMOUSELEAVE:
@@ -742,6 +701,10 @@ LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
742701
case WM_EXITMENULOOP:
743702
mMenuActiveIndex = -1;
744703
break;
704+
case WM_ACTIVATEAPP:
705+
mIsActive = (BOOL)wParam;
706+
UpdateNonClientArea();
707+
break;
745708
}
746709

747710
return lr;

appshell/cef_dark_aero_window.h

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
#include "cef_dark_window.h"
2424
#include <dwmapi.h>
2525

26-
#define CDW_UPDATEMENU WM_USER+1004
26+
// Undocumented Aero Messages
27+
#define WM_UAHDESTROYWINDOW 0x0090
28+
#define WM_UAHDRAWMENU 0x0091
29+
#define WM_UAHDRAWMENUITEM 0x0092
30+
#define WM_UAHINITMENU 0x0093
31+
#define WM_UAHMEASUREMENUITEM 0x0094
32+
#define WM_UAHNCPAINTMENUPOPUP 0x0095
2733

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

8490
void PostHandleNcLeftButtonUp(UINT uHitTest, LPPOINT pt);
8591

86-
void DrawMenuBar(HDC hdc);
87-
void UpdateMenuBar();
88-
void HiliteMenuItemAt(LPPOINT pt);
92+
virtual void DrawMenuBar(HDC hdc);
93+
virtual void HiliteMenuItemAt(LPPOINT pt);
8994

9095
virtual void UpdateNonClientArea();
96+
virtual void UpdateMenuBar();
9197

9298
virtual void InitDeviceContext(HDC hdc);
93-
virtual void DoPaintNonClientArea(HDC hdc);
9499

95-
void ComputeMenuBarRect(RECT& rect) const;
96-
void ComputeWindowCaptionRect(RECT& rect) const;
97-
void ComputeWindowIconRect(RECT& rect) const;
100+
virtual void ComputeMenuBarRect(RECT& rect) const;
101+
virtual void ComputeWindowCaptionRect(RECT& rect) const;
102+
virtual void ComputeWindowIconRect(RECT& rect) const;
98103

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

0 commit comments

Comments
 (0)