soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SRealWnd.cpp
1#include <souistd.h>
2#include <control/SRealWnd.h>
4#include <helper/obj-ref-impl.hpp>
5
6SNSBEGIN
7
8class DefRealWndHandler : public TObjRefImpl2<IRealWndHandler, DefRealWndHandler> {
9 public:
10 DefRealWndHandler(SRealWnd *pRealWnd)
11 : m_owner(pRealWnd)
12 {
13 }
14
15 HWND WINAPI OnRealWndCreate(IWindow *pRealWnd) OVERRIDE
16 {
17 EventRealWndCreate evt(m_owner);
18 evt.hRet = 0;
19 m_owner->FireEvent(&evt);
20 return evt.hRet;
21 }
22 void WINAPI OnRealWndDestroy(IWindow *pRealWnd) OVERRIDE
23 {
24 EventRealWndDestroy evt(m_owner);
25 m_owner->FireEvent(&evt);
26 }
27 BOOL WINAPI OnRealWndInit(IWindow *pRealWnd) OVERRIDE
28 {
29 EventRealWndInit evt(m_owner);
30 evt.bRet = FALSE;
31 m_owner->FireEvent(&evt);
32 return evt.bRet;
33 }
34
35 BOOL WINAPI OnRealWndPosition(IWindow *pRealWnd, const RECT *rcWnd) OVERRIDE
36 {
37 EventRealWndPosition evt(m_owner);
38 evt.rc = *rcWnd;
39 evt.bRet = FALSE;
40 m_owner->FireEvent(&evt);
41 return evt.bRet;
42 }
43
44 protected:
45 SRealWnd *m_owner;
46};
47
49 : m_bInit(FALSE)
50 , m_lpData(0)
51 , m_hRealWnd(0)
52{
53 GetEventSet()->addEvent(EVENTID(EventRealWndCreate));
54 GetEventSet()->addEvent(EVENTID(EventRealWndDestroy));
55 GetEventSet()->addEvent(EVENTID(EventRealWndInit));
56 GetEventSet()->addEvent(EVENTID(EventRealWndPosition));
57
58 m_pRealWndHandler = GETREALWNDHANDLER;
60 {
61 m_pRealWndHandler.Attach(new DefRealWndHandler(this));
62 }
63}
64
68
70{
71 return FALSE;
72}
73
75{
76 if (IsVisible(TRUE) && !IsWindow(m_hRealWnd))
77 {
79 }
80 if (IsWindow(m_hRealWnd))
81 {
82 ShowWindow(m_hRealWnd, IsVisible(TRUE) ? SW_SHOW : SW_HIDE);
83 }
84}
85
86void SRealWnd::OnShowWindow(BOOL bShow, UINT nStatus)
87{
88 __baseCls::OnShowWindow(bShow, nStatus);
90}
91
93{
94 if (IsWindow(m_hRealWnd))
95 {
96 m_pRealWndHandler->OnRealWndDestroy(this);
97 }
98 __baseCls::OnDestroy();
99}
100
102{
103 SXmlNode xmlNode(pNode);
104 m_xmlParams.root().append_copy(xmlNode.child(L"params"));
105 BOOL bRet = __baseCls::InitFromXml(pNode);
106 if (bRet)
107 {
108 if (m_bInit)
109 InitRealWnd();
110 }
111 return bRet;
112}
113
114HWND SRealWnd::GetRealHwnd(BOOL bAutoCreate /*=TRUE*/)
115{
116 if (!bAutoCreate)
117 return m_hRealWnd;
118
119 if (!m_bInit && !IsWindow(m_hRealWnd))
120 {
121 InitRealWnd();
122 }
123
124 return m_hRealWnd;
125}
126
128{
129 m_dwStyle |= WS_CHILD;
130 m_hRealWnd = m_pRealWndHandler->OnRealWndCreate(this);
131
132 if (::IsWindow(m_hRealWnd))
133 {
134 CRect rcClient;
135 GetClientRect(&rcClient);
136 SetRealWndPos(m_hRealWnd, &rcClient);
137 m_pRealWndHandler->OnRealWndInit(this);
138 return TRUE;
139 }
140 return FALSE;
141}
142
143BOOL SRealWnd::OnRelayout(const CRect &rcWnd)
144{
145 if (!__baseCls::OnRelayout(rcWnd))
146 return FALSE;
147
148 HWND hRealWnd = GetRealHwnd(FALSE);
149 if (::IsWindow(hRealWnd))
150 {
151 SetRealWndPos(hRealWnd, &rcWnd);
152 }
153 return TRUE;
154}
155
156void SRealWnd::SetRealWndPos(HWND hRealWnd, const CRect *prc)
157{
158 if (!m_pRealWndHandler->OnRealWndPosition(this, prc))
159 {
160 CPoint pt = prc->TopLeft();
161 if (GetWindowLong(hRealWnd, GWL_STYLE) & WS_POPUP)
162 {
163 ::ClientToScreen(GetContainer()->GetHostHwnd(), &pt);
164 }
165 ::SetWindowPos(hRealWnd, 0, pt.x, pt.y, prc->Width(), prc->Height(), SWP_NOZORDER);
166 }
167}
168
169SNSEND
Interface for handling real window creation and destruction.
BOOL addEvent(DWORD dwEventID, LPCWSTR pszEventHandlerName)
添加一个新事件到事件集
HWND GetRealHwnd(BOOL bAutoCreate=TRUE) OVERRIDE
Get the handle of the real window.
Definition SRealWnd.cpp:114
void OnDestroy()
Handle destroy event.
Definition SRealWnd.cpp:92
SAutoRefPtr< IRealWndHandler > m_pRealWndHandler
Definition SRealWnd.h:193
virtual BOOL NeedRedrawWhenStateChange()
Determine if the control needs to be redrawn when its state changes.
Definition SRealWnd.cpp:69
virtual ~SRealWnd()
Destructor.
Definition SRealWnd.cpp:65
BOOL m_bInit
Definition SRealWnd.h:188
BOOL InitRealWnd()
Initialize the real window.
Definition SRealWnd.cpp:127
SRealWnd()
Constructor.
Definition SRealWnd.cpp:48
virtual BOOL WINAPI InitFromXml(IXmlNode *pNode)
Initialize the control from an XML node.
Definition SRealWnd.cpp:101
LPVOID m_lpData
Definition SRealWnd.h:191
DWORD m_dwStyle
Definition SRealWnd.h:184
SXmlDoc m_xmlParams
Definition SRealWnd.h:186
void SetRealWndPos(HWND hRealWnd, const CRect *prc)
Set the position of the real window.
Definition SRealWnd.cpp:156
HWND m_hRealWnd
Definition SRealWnd.h:190
void ShowRealWindow()
Show the real window.
Definition SRealWnd.cpp:74
virtual BOOL OnRelayout(const CRect &rcWnd)
Handle layout changes.
Definition SRealWnd.cpp:143
void OnShowWindow(BOOL bShow, UINT nStatus)
Handle show window event.
Definition SRealWnd.cpp:86
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
Definition Swnd.cpp:646
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
Definition Swnd.cpp:679
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
Definition Swnd.cpp:243
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
Definition SWnd.h:1290
HWND GetHostHwnd() OVERRIDE
Retrieves the host window handle.
Definition Swnd.cpp:3616
Class representing an XML node.
Definition SXml.h:352
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
Definition SXml.cpp:423
Template class extending TObjRefImpl with a specific final release behavior.
Interface for XML nodes.
Definition sxml-i.h:128