Move wxTopLevelWindow::SetShape() down to wxNonOwnedWindow.

Also add wxNonOwnedWindow for wxMSW (which previously simply typedef'd it to
wxWindow) and document this class now that it provides some user-visible
functionality.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69364 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-10-10 10:53:23 +00:00
parent 95c0502bae
commit 5bd0ee9966
22 changed files with 359 additions and 78 deletions

81
src/msw/nonownedwnd.cpp Normal file
View File

@@ -0,0 +1,81 @@
///////////////////////////////////////////////////////////////////////////////
// Name: src/msw/nonownedwnd.cpp
// Purpose: wxNonOwnedWindow implementation for MSW.
// Author: Vadim Zeitlin
// Created: 2011-10-09 (extracted from src/msw/toplevel.cpp)
// RCS-ID: $Id: $
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include "wx/nonownedwnd.h"
// ============================================================================
// wxNonOwnedWindow implementation
// ============================================================================
#ifndef __WXWINCE__
bool wxNonOwnedWindow::SetShape(const wxRegion& region)
{
wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
// The empty region signifies that the shape should be removed from the
// window.
if ( region.IsEmpty() )
{
if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
{
wxLogLastError(wxT("SetWindowRgn"));
return false;
}
return true;
}
// Windows takes ownership of the region, so
// we'll have to make a copy of the region to give to it.
DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
delete[] (char*) rgnData;
// SetWindowRgn expects the region to be in coordinates
// relative to the window, not the client area. Figure
// out the offset, if any.
RECT rect;
DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
::GetClientRect(GetHwnd(), &rect);
::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
::OffsetRgn(hrgn, -rect.left, -rect.top);
// Now call the shape API with the new region.
if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
{
wxLogLastError(wxT("SetWindowRgn"));
return false;
}
return true;
}
#endif // !__WXWINCE__