]> git.saurik.com Git - wxWidgets.git/blob - src/msw/nonownedwnd.cpp
Fix PCH-less build after adding wxNonOwnerWindow in wxMSW.
[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 #ifndef WX_PRECOMP
27 #include "wx/frame.h" // Only for wxFRAME_SHAPED.
28 #include "wx/region.h"
29 #include "wx/msw/private.h"
30 #endif // WX_PRECOMP
31
32 #include "wx/nonownedwnd.h"
33
34 // ============================================================================
35 // wxNonOwnedWindow implementation
36 // ============================================================================
37
38 #ifndef __WXWINCE__
39
40 bool wxNonOwnedWindow::SetShape(const wxRegion& region)
41 {
42 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
43 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
44
45 // The empty region signifies that the shape should be removed from the
46 // window.
47 if ( region.IsEmpty() )
48 {
49 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
50 {
51 wxLogLastError(wxT("SetWindowRgn"));
52 return false;
53 }
54 return true;
55 }
56
57 // Windows takes ownership of the region, so
58 // we'll have to make a copy of the region to give to it.
59 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
60 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
61 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
62 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
63 delete[] (char*) rgnData;
64
65 // SetWindowRgn expects the region to be in coordinates
66 // relative to the window, not the client area. Figure
67 // out the offset, if any.
68 RECT rect;
69 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
70 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
71 ::GetClientRect(GetHwnd(), &rect);
72 ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
73 ::OffsetRgn(hrgn, -rect.left, -rect.top);
74
75 // Now call the shape API with the new region.
76 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
77 {
78 wxLogLastError(wxT("SetWindowRgn"));
79 return false;
80 }
81 return true;
82 }
83
84 #endif // !__WXWINCE__