soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SItemPanel.cpp
1//////////////////////////////////////////////////////////////////////////
2// Class Name: SOsrPanel
3// Creator: Huang Jianxiong
4// Version: 2011.10.20 - 1.0 - Create
5//////////////////////////////////////////////////////////////////////////
6#include "souistd.h"
7#include "core/SItemPanel.h"
8
9#pragma warning(disable : 4018)
10
11SNSBEGIN
12
13SOsrPanel::SOsrPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer)
14 : m_pHostProxy(pFrameHost)
15 , m_pItemContainer(pItemContainer)
16 , m_dwData(0)
17 , m_lpItemIndex(-1)
18{
19 SetContainer(this);
21 SASSERT(m_pHostProxy);
22 SASSERT(m_pItemContainer);
23 m_evtSet.addEvent(EVENTID(EventItemPanelClick));
24 m_evtSet.addEvent(EVENTID(EventItemPanelRclick));
25 m_evtSet.addEvent(EVENTID(EventItemPanelClickUp));
26 m_evtSet.addEvent(EVENTID(EventItemPanelRclickUp));
27 m_evtSet.addEvent(EVENTID(EventItemPanelDbclick));
28 m_evtSet.addEvent(EVENTID(EventItemPanelHover));
29 m_evtSet.addEvent(EVENTID(EventItemPanelLeave));
30}
31
32void SOsrPanel::OnFinalRelease()
33{
34 AddRef(); //防止重复进入该函数
35 SSendMessage(WM_DESTROY);
36 m_pHostProxy->GetHostContainer()->UnregisterTimelineHandler(this);
37 __baseCls::OnFinalRelease();
38}
39
40BOOL SOsrPanel::InitFromXml(THIS_ IXmlNode *pNode)
41{
42 BOOL bRet = __baseCls::InitFromXml(pNode);
43 if (bRet)
44 {
46 }
47 return bRet;
48}
49
50LRESULT SOsrPanel::DoFrameEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
51{
52 AddRef();
53
54 if (!IsDisabled())
55 {
56 switch (uMsg)
57 {
58 case WM_MOUSEHOVER:
59 {
61 EventItemPanelHover evt(this);
62 evt.wParam = wParam;
63 evt.lParam = lParam;
64 FireEvent(evt);
65 break;
66 }
67 case WM_MOUSELEAVE:
68 {
70 EventItemPanelLeave evt(this);
71 FireEvent(evt);
72 break;
73 }
74 case WM_LBUTTONDOWN:
75 {
76 EventItemPanelClick evt(this);
77 evt.wParam = wParam;
78 evt.lParam = lParam;
79 FireEvent(evt);
80 break;
81 }
82 case WM_RBUTTONDOWN:
83 {
84 EventItemPanelRclick evt(this);
85 evt.wParam = wParam;
86 evt.lParam = lParam;
87 FireEvent(evt);
88 break;
89 }
90 case WM_LBUTTONDBLCLK:
91 {
92 EventItemPanelDbclick evt(this);
93 evt.wParam = wParam;
94 evt.lParam = lParam;
95 FireEvent(evt);
96 break;
97 }
98 case WM_LBUTTONUP:
99 {
100 EventItemPanelClickUp evt(this);
101 evt.wParam = wParam;
102 evt.lParam = lParam;
103 FireEvent(evt);
104 break;
105 }
106 case WM_RBUTTONUP:
107 {
108 EventItemPanelRclickUp evt(this);
109 evt.wParam = wParam;
110 evt.lParam = lParam;
111 FireEvent(evt);
112 break;
113 }
114 }
115 }
116
117 SetMsgHandled(FALSE);
118
119 BOOL isMute = GetEventSet()->isMuted();
120 if (uMsg == WM_LBUTTONUP && !isMute)
121 {
122 GetEventSet()->setMutedState(true);
123 }
124 LRESULT lRet = SwndContainerImpl::DoFrameEvent(uMsg, wParam, lParam);
125 if (uMsg == WM_LBUTTONUP && !isMute)
126 {
127 GetEventSet()->setMutedState(false);
128 FireCommand();
129 }
130
131 Release();
132 return lRet;
133}
134
135BOOL SOsrPanel::OnFireEvent(IEvtArgs *evt)
136{
137 return m_pHostProxy->OnHostFireEvent(evt);
138}
139
140void SOsrPanel::GetContainerRect(RECT *ret) const
141{
142 CRect rcItem;
143 m_pItemContainer->OnItemGetRect(this, rcItem);
144 *ret = rcItem;
145}
146
147void SOsrPanel::UpdateRegion(IRegionS *rgn)
148{
149 CRect rc = GetItemRect();
150 rgn->Offset(rc.TopLeft());
151 m_pHostProxy->GetHostContainer()->UpdateRegion(rgn);
152}
153
154void SOsrPanel::OnRedraw(LPCRECT rc, BOOL bClip)
155{
156 if (m_pHostProxy->IsHostUpdateLocked())
157 return;
158
159 CRect rcItem = GetItemRect();
160 if (!rcItem.IsRectNull() && m_pHostProxy->IsHostVisible())
161 {
162 if (m_pItemContainer->IsItemRedrawDelay())
163 {
164 CRect rc2(rc);
165 rc2.OffsetRect(rcItem.TopLeft());
166 rc2.IntersectRect(rc2, rcItem);
167 CRect rcHostClient = m_pHostProxy->GetHostRect();
168 rc2.IntersectRect(rc2, rcHostClient);
169 m_pHostProxy->InvalidateHostRect(&rc2, bClip);
170 }
171 else
172 {
173 SAutoRefPtr<IRegionS> rgn;
174 GETRENDERFACTORY->CreateRegion(&rgn);
175 rgn->CombineRect(rc, RGN_COPY);
176 UpdateRegion(rgn);
177 }
178 }
179}
180
181BOOL SOsrPanel::OnReleaseSwndCapture()
182{
184 return FALSE;
185 m_pItemContainer->OnItemSetCapture(this, FALSE);
186 return TRUE;
187}
188
189SWND SOsrPanel::OnSetSwndCapture(SWND swnd)
190{
191 m_pItemContainer->OnItemSetCapture(this, TRUE);
193}
194
195HWND SOsrPanel::GetHostHwnd()
196{
197 return m_pHostProxy->GetHostContainer()->GetHostHwnd();
198}
199
200LPCWSTR SOsrPanel::GetTranslatorContext() const
201{
202 return m_pHostProxy->GetHostContainer()->GetTranslatorContext();
203}
204
205BOOL SOsrPanel::IsTranslucent() const
206{
207 return m_pHostProxy->GetHostContainer()->IsTranslucent();
208}
209
210BOOL SOsrPanel::IsSendWheel2Hover() const
211{
212 return m_pHostProxy->GetHostContainer()->IsSendWheel2Hover();
213}
214
215BOOL SOsrPanel::UpdateWindow(BOOL bForce)
216{
217 return m_pHostProxy->GetHostContainer()->UpdateWindow(bForce);
218}
219
220void SOsrPanel::UpdateTooltip()
221{
222 return m_pHostProxy->GetHostContainer()->UpdateTooltip();
223}
224void SOsrPanel::SetToolTip(LPCRECT rc, UINT tipAlign, LPCTSTR pszTip)
225{
226 if (rc)
227 {
228 CRect rc2;
229 m_pItemContainer->OnItemGetRect(this, rc2);
230 rc2.OffsetRect(rc->left, rc->top);
231 return m_pHostProxy->GetHostContainer()->SetToolTip(&rc2, tipAlign, pszTip);
232 }
233 else
234 {
235 return m_pHostProxy->GetHostContainer()->SetToolTip(rc, tipAlign, pszTip);
236 }
237}
238
239void SOsrPanel::ModifyItemState(DWORD dwStateAdd, DWORD dwStateRemove)
240{
241 ModifyState(dwStateAdd, dwStateRemove, FALSE);
242}
243
244SWND SOsrPanel::SwndFromPoint(CPoint &pt, bool bIncludeMsgTransparent)
245{
246 SWND hRet = SWindow::SwndFromPoint(pt, bIncludeMsgTransparent);
247 if (hRet == m_swnd)
248 hRet = 0;
249 return hRet;
250}
251
252void SOsrPanel::Draw(IRenderTarget *pRT, const CRect &rc)
253{
254 UpdateLayout();
256 SPainter painter;
257 BeforePaint(pRT, painter);
258 pRT->OffsetViewportOrg(rc.left, rc.top, NULL);
259 //没有矩阵变换的时候才启用clip region.
260 SAutoRefPtr<IRegionS> rgn;
261 SMatrix mtx;
262 pRT->GetTransform(mtx.fMat);
264 if (mtx.isIdentity())
265 {
266 pRT->GetClipRegion(&rgn);
267 }
268
269 pRT->BeginDraw();
270
271 RedrawRegion(pRT, rgn);
272 pRT->EndDraw();
273 pRT->OffsetViewportOrg(-rc.left, -rc.top, NULL);
274 AfterPaint(pRT, painter);
275}
276
277BOOL SOsrPanel::NeedRedrawWhenStateChange()
278{
279 return TRUE;
280}
281
282CRect SOsrPanel::GetItemRect() const
283{
284 CRect rcItem;
285 m_pItemContainer->OnItemGetRect(this, rcItem);
286 return rcItem;
287}
288void SOsrPanel::SetItemCapture(BOOL bCapture)
289{
290 m_pItemContainer->OnItemSetCapture(this, bCapture);
291}
292
293BOOL SOsrPanel::UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
294{
295 CRect rcItem = GetItemRect();
296 if (m_hHover == m_swnd)
297 {
298 tipInfo.swnd = m_swnd;
299 tipInfo.dwCookie = 0;
300 tipInfo.rcTarget = rcItem;
301 tipInfo.strTip = GetToolTipText();
302 return TRUE;
303 }
304
306 if (!pHover)
307 { // disabled窗口也可以有tooltip
308 tipInfo.swnd = 0;
309 return TRUE;
310 }
311
312 pt -= rcItem.TopLeft();
313 BOOL bRet = pHover->UpdateToolTip(pt, tipInfo);
314 if (bRet)
315 {
316 tipInfo.rcTarget.OffsetRect(rcItem.TopLeft());
317 }
318 return bRet;
319}
320
321IMessageLoop *SOsrPanel::GetMsgLoop()
322{
323 return m_pHostProxy->GetHostContainer()->GetMsgLoop();
324}
325
326IScriptModule *SOsrPanel::GetScriptModule()
327{
328 return m_pHostProxy->GetHostContainer()->GetScriptModule();
329}
330
331void SOsrPanel::FrameToHost(RECT *rc) const
332{
333 CRect rcItem = GetItemRect();
334 ::OffsetRect(rc, rcItem.left, rcItem.top);
335}
336
337//不继承宿主的字体,从指定的字体或者系统字体开始,避免在GetRenderTarget时还需要从宿主窗口到获取当前的文字属性。
338void SOsrPanel::BeforePaint(IRenderTarget *pRT, SPainter &painter)
339{
340 int iState = SState2Index::GetDefIndex(GetState(), true);
341 IFontPtr fontText = GetStyle().GetTextFont(iState);
342 COLORREF crText = GetStyle().GetTextColor(iState);
343 if (fontText == NULL)
344 fontText = GETUIDEF->GetFont(FF_DEFAULTFONT, GetScale());
345 if (crText == CR_INVALID)
346 crText = RGBA(0, 0, 0, 255);
347 pRT->SelectObject(fontText, (IRenderObj **)&painter.oldFont);
348 painter.oldTextColor = pRT->SetTextColor(crText);
349}
350
351void SOsrPanel::OnShowWindow(BOOL bShow, UINT nStatus)
352{
353 __baseCls::OnShowWindow(bShow, nStatus);
354 if (IsVisible(TRUE))
355 m_pHostProxy->GetHostContainer()->RegisterTimelineHandler(this);
356 else
357 m_pHostProxy->GetHostContainer()->UnregisterTimelineHandler(this);
358}
359
360void SOsrPanel::OnDestroy()
361{
362 m_pHostProxy->GetHostContainer()->UnregisterTimelineHandler(this);
363 __baseCls::OnDestroy();
364}
365
366int SOsrPanel::GetScale() const
367{
368 return m_pHostProxy->GetHostContainer()->GetScale();
369}
370
371void SOsrPanel::EnableIME(BOOL bEnable)
372{
373 m_pHostProxy->GetHostContainer()->EnableIME(bEnable);
374}
375
376void SOsrPanel::OnUpdateCursor()
377{
378 m_pHostProxy->GetHostContainer()->OnUpdateCursor();
379}
380
381void SOsrPanel::EnableHostPrivateUiDef(THIS_ BOOL bEnable)
382{
383 return m_pHostProxy->GetHostContainer()->EnableHostPrivateUiDef(bEnable);
384}
385
386BOOL SOsrPanel::IsItemInClip(const SMatrix &mtx, const CRect &rcClip, const IRegionS *clipRgn, const CRect &rcItem)
387{
388 if (!mtx.isIdentity()) // don't clip any item if matrix is not identify.
389 return TRUE;
390 CRect rc;
391 rc.IntersectRect(rcClip, rcItem);
392 return !rc.IsRectEmpty() && (!clipRgn || clipRgn->RectInRegion(rcItem));
393}
394
395LPARAM SOsrPanel::GetItemIndex() const
396{
397 return m_lpItemIndex;
398}
399
400void SOsrPanel::SetItemIndex(LPARAM lp)
401{
402 m_lpItemIndex = lp;
403}
404
405void SOsrPanel::SetItemData(LPARAM dwData)
406{
407 m_dwData = dwData;
408}
409
410LPARAM SOsrPanel::GetItemData() const
411{
412 return m_dwData;
413}
414
415void SOsrPanel::PtToHost(THIS_ POINT *pt) const
416{
417 CRect rcItem = GetItemRect();
418 pt->x += rcItem.left;
419 pt->y += rcItem.top;
420}
421
422void SOsrPanel::RequestRelayout(SWND hSource, BOOL bSourceResizable)
423{
424 __baseCls::RequestRelayout(hSource, bSourceResizable);
425 if (IsLayoutDirty())
426 {
427 m_pHostProxy->OnLayoutDirty();
428 }
429}
430
431BOOL SOsrPanel::PostTask(THIS_ IRunnable *runable, BOOL bAsync)
432{
433 return m_pHostProxy->GetHostContainer()->PostTask(runable, bAsync);
434}
435
436int SOsrPanel::RemoveTasksForObject(THIS_ void *pObj)
437{
438 return m_pHostProxy->GetHostContainer()->RemoveTasksForObject(pObj);
439}
440
441//////////////////////////////////////////////////////////////////////////
442SItemPanel *SItemPanel::Create(IHostProxy *pFrameHost, SXmlNode xmlNode, IItemContainer *pItemContainer)
443{
444 SItemPanel *pItem = new SItemPanel(pFrameHost, pItemContainer);
445 pItem->InitFromXml(&xmlNode);
447 return pItem;
448}
449
450SItemPanel::SItemPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer)
451 : TOsrPanelProxy<IItemPanel>(pFrameHost, pItemContainer)
452 , m_crBk(CR_INVALID)
453 , m_crHover(CR_INVALID)
454 , m_crSelBk(RGBA(0, 0, 128, 255))
455{
456}
457
458void SItemPanel::SetSkin(ISkinObj *pSkin)
459{
460 m_pBgSkin = pSkin;
461}
462
463void SItemPanel::SetColor(COLORREF crBk, COLORREF crSelBk)
464{
465 m_crBk = crBk;
466 m_crSelBk = crSelBk;
467}
468
469COLORREF SItemPanel::GetBkgndColor() const
470{
471 if ((m_dwState & WndState_Check) && m_crSelBk != CR_INVALID)
472 {
473 return m_crSelBk;
474 }
475 if ((m_dwState & WndState_Hover) && m_crHover != CR_INVALID)
476 {
477 return m_crHover;
478 }
479 return m_crBk;
480}
481
482BOOL SItemPanel::OnFireEvent(IEvtArgs *evt)
483{
484 EventOfPanel evt2(m_pHostProxy->GetHost());
485 evt2.pPanel = this;
486 evt2.pOrgEvt = evt;
487 return m_pHostProxy->OnHostFireEvent(&evt2);
488}
489
490SNSEND
@ WndState_Hover
Definition SWnd.h:76
@ WndState_Check
Definition SWnd.h:78
void setMutedState(BOOL setting)
设置事件集的静音状态
BOOL isMuted(void) const
检查事件集是否被静音
Definition SEventSet.h:281
The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructo...
Definition SMatrix.h:22
BOOL isIdentity() SCONST OVERRIDE
Checks if the matrix is the identity matrix.
Definition SMatrix.cpp:1777
void dirtyMatrixTypeCache()
Testing routine; the matrix's type cache should never need to be manually invalidated during normal u...
Definition SMatrix.h:905
void SetSwndDefAttr(IObject *pObject) const
Sets default attributes for a given object.
Helper class for painting.
Definition SWnd.h:178
SAutoRefPtr< IFontS > oldFont
Definition SWnd.h:185
COLORREF oldTextColor
Definition SWnd.h:186
static SApplication * getSingletonPtr(void)
Definition SSingleton.h:73
static int GetDefIndex(DWORD dwState, bool checkAsPushdown=false)
Gets the default index for a given state.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
Definition Swnd.cpp:1540
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handle tooltip updates.
Definition Swnd.cpp:277
DWORD GetState() SCONST OVERRIDE
Retrieves the current state of the window.
Definition Swnd.cpp:437
SWND SwndFromPoint(POINT *pt, BOOL bIncludeMsgTransparent=FALSE) SCONST OVERRIDE
Retrieves the window handle at a specified point.
BOOL IsLayoutDirty() SCONST OVERRIDE
Checks if the layout is dirty.
Definition Swnd.cpp:3451
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
Definition Swnd.cpp:646
BOOL m_dwState
Definition SWnd.h:2603
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
Definition Swnd.cpp:364
void UpdateLayout() OVERRIDE
Updates the layout of the window.
Definition Swnd.cpp:2251
SWindow()
Constructor.
Definition Swnd.cpp:104
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
Definition Swnd.cpp:1776
BOOL IsDisabled(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is disabled.
Definition Swnd.cpp:638
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
Definition SWnd.h:1290
SAutoRefPtr< ISkinObj > m_pBgSkin
Definition SWnd.h:2622
void RedrawRegion(IRenderTarget *pRT, IRegionS *pRgn)
Renders the content of the window and its child windows onto the RenderTarget.
Definition Swnd.cpp:1422
void RequestRelayout() OVERRIDE
Requests a relayout of the window.
Definition Swnd.cpp:2225
void SetMsgHandled(BOOL bHandled)
Sets the message handled flag.
Definition Swnd.cpp:212
virtual SStringT GetToolTipText()
Retrieves the tooltip text of the window.
Definition Swnd.cpp:3236
BOOL FireCommand() OVERRIDE
Fires a command event.
Definition Swnd.cpp:2713
DWORD ModifyState(DWORD dwStateAdd, DWORD dwStateRemove, BOOL bUpdate=FALSE) OVERRIDE
Modifies the state of the window.
Definition Swnd.cpp:443
const SwndStyle & GetStyle() const
Retrieves the style of the window.
Definition Swnd.cpp:716
SWND m_swnd
Member variables representing various properties of the window.
Definition SWnd.h:2577
static SWindow * GetWindow(SWND swnd)
Retrieves the SWindow pointer from a given handle.
Class representing an XML node.
Definition SXml.h:352
void BuildWndTreeZorder() OVERRIDE
Rebuilds the window tree's z-order.
void SetRoot(SWindow *pRoot)
Sets the root window of the container.
virtual LRESULT DoFrameEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Processes frame events.
BOOL OnReleaseSwndCapture() OVERRIDE
Releases the window capture.
SWND OnSetSwndCapture(SWND swnd) OVERRIDE
Sets the window capture.
IFontPtr GetTextFont(int iState)
Retrieves the text font for a specific state.
Definition SwndStyle.cpp:87
COLORREF GetTextColor(int iState)
Retrieves the text color for a specific state.
Definition SwndStyle.cpp:79
float fMat[kMCount]
Array of floats representing the matrix elements.
Definition SRender-i.h:975
Interface for message loops.
Definition SMsgLoop-i.h:42
Region object interface.
Definition SRender-i.h:792
void Offset(POINT pt) PURE
Offsets the region by a specified amount.
BOOL RectInRegion(LPCRECT lprect) SCONST PURE
Checks if a rectangle intersects with the region.
Interface for rendering target objects.
Definition SRender-i.h:1440
HRESULT GetTransform(float matrix[9]) SCONST PURE
Retrieves the current coordinate transformation matrix.
HRESULT SelectObject(IRenderObj *pObj, IRenderObj **pOldObj=NULL) PURE
Selects a new rendering object and optionally retrieves the previous one.
void EndDraw() PURE
End a drawing operation.
void BeginDraw() PURE
Start a drawing operation.
HRESULT OffsetViewportOrg(int xOff, int yOff, LPPOINT lpPoint=NULL) PURE
Offset the viewport origin.
HRESULT GetClipRegion(IRegionS **ppRegion) PURE
Get the current clip region.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.
Interface for Skin Objects.
Definition SSkinobj-i.h:29
Interface for XML nodes.
Definition sxml-i.h:128
Information for window tooltips.
Definition SWnd.h:208
CRect rcTarget
Definition SWnd.h:211
DWORD dwCookie
Definition SWnd.h:210
SStringT strTip
Definition SWnd.h:212