Use wxWindow::GetClientAreaOrigin() instead of MSW functions.
[wxWidgets.git] / src / msw / nonownedwnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/nonownedwnd.cpp
3 // Purpose: wxNonOwnedWindow implementation for MSW.
4 // Author: Vadim Zeitlin
5 // Created: 2011-10-09 (extracted from src/msw/toplevel.cpp)
6 // RCS-ID: $Id: $
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 // This class can't be implemented and hence is not used under Win CE.
27 #ifndef __WXWINCE__
28
29 #ifndef WX_PRECOMP
30 #include "wx/frame.h" // Only for wxFRAME_SHAPED.
31 #include "wx/region.h"
32 #include "wx/msw/private.h"
33 #endif // WX_PRECOMP
34
35 #include "wx/nonownedwnd.h"
36
37 // ============================================================================
38 // wxNonOwnedWindow implementation
39 // ============================================================================
40
41 bool wxNonOwnedWindow::SetShape(const wxRegion& region)
42 {
43 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
44 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
45
46 // The empty region signifies that the shape should be removed from the
47 // window.
48 if ( region.IsEmpty() )
49 {
50 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
51 {
52 wxLogLastError(wxT("SetWindowRgn"));
53 return false;
54 }
55 return true;
56 }
57
58 // Windows takes ownership of the region, so
59 // we'll have to make a copy of the region to give to it.
60 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
61 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
62 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
63 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
64 delete[] (char*) rgnData;
65
66 // SetWindowRgn expects the region to be in coordinates
67 // relative to the window, not the client area.
68 const wxPoint clientOrigin = GetClientAreaOrigin();
69 ::OffsetRgn(hrgn, -clientOrigin.x, -clientOrigin.y);
70
71 // Now call the shape API with the new region.
72 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
73 {
74 wxLogLastError(wxT("SetWindowRgn"));
75 return false;
76 }
77 return true;
78 }
79
80 #endif // !__WXWINCE__