soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
shostwnd.cpp
1#include "souistd.h"
2
3#include "SApp.h"
4#include "core/SHostWnd.h"
5#include "helper/SAutoBuf.h"
6#include "helper/SColor.h"
7#include "helper/SplitString.h"
8#include "helper/STime.h"
9#include <helper/SHostMgr.h>
10#include <core/SHostPresenter.h>
11#ifdef _WIN32
12#include <Imm.h>
13#pragma comment(lib, "imm32.lib")
14#endif
15SNSBEGIN
16
17//////////////////////////////////////////////////////////////////////////
18// SDummyWnd
19//////////////////////////////////////////////////////////////////////////
20class SDummyWnd : public SNativeWnd {
21 public:
22 SDummyWnd(SHostWnd *pOwner)
23 : m_pOwner(pOwner)
24 {
25 }
26
27 void OnPaint(HDC dc)
28 {
29 PAINTSTRUCT ps;
30 ::BeginPaint(m_hWnd, &ps);
31 ::EndPaint(m_hWnd, &ps);
32 m_pOwner->OnPrint(NULL);
33 }
34
35 void OnDestroy()
36 {
37 m_pOwner->m_dummyWnd = NULL;
38 }
39
40 virtual void OnFinalMessage(HWND hWnd)
41 {
42 delete this;
43 }
44
45 BEGIN_MSG_MAP_EX(SDummyWnd)
46 MSG_WM_PAINT(OnPaint)
47 MSG_WM_DESTROY(OnDestroy)
48 END_MSG_MAP()
49 private:
50 SHostWnd *m_pOwner;
51};
52
53//////////////////////////////////////////////////////////////////////////
54// SHostWndAttr
55//////////////////////////////////////////////////////////////////////////
57 : m_hAppIconSmall(NULL)
58 , m_hAppIconBig(NULL)
59{
60 Init();
61}
62
64{
65 if (m_hAppIconSmall)
66 DestroyIcon(m_hAppIconSmall);
67 if (m_hAppIconBig)
68 DestroyIcon(m_hAppIconBig);
69}
70
72{
73 m_bResizable = FALSE;
74 m_bTranslucent = FALSE;
75 m_bAutoShape = FALSE;
76 m_bAppWnd = FALSE;
77 m_bToolWnd = FALSE;
78 m_wndType = WT_UNDEFINE;
79 m_bAllowSpy = TRUE;
80 m_bSendWheel2Hover = FALSE;
81 m_bHasMsgLoop = TRUE;
82 m_dwStyle = (0);
83 m_dwExStyle = (0);
84 if (m_hAppIconSmall)
85 DestroyIcon(m_hAppIconSmall);
86 if (m_hAppIconBig)
87 DestroyIcon(m_hAppIconBig);
88 m_hAppIconSmall = NULL;
89 m_hAppIconBig = NULL;
90}
91
93{
94 return m_strTrCtx;
95}
96
97CRect SHostWndAttr::GetMaxInset(int nScale) const
98{
99 CRect rcRet;
100 rcRet.left = m_rcMaxInset[0].toPixelSize(nScale);
101 rcRet.top = m_rcMaxInset[1].toPixelSize(nScale);
102 rcRet.right = m_rcMaxInset[2].toPixelSize(nScale);
103 rcRet.bottom = m_rcMaxInset[3].toPixelSize(nScale);
104 return rcRet;
105}
106
107CRect SHostWndAttr::GetMargin(int nScale) const
108{
109 CRect rcRet;
110 rcRet.left = m_rcMargin[0].toPixelSize(nScale);
111 rcRet.top = m_rcMargin[1].toPixelSize(nScale);
112 rcRet.right = m_rcMargin[2].toPixelSize(nScale);
113 rcRet.bottom = m_rcMargin[3].toPixelSize(nScale);
114 return rcRet;
115}
116
117CSize SHostWndAttr::GetMinSize(int nScale) const
118{
119 CSize szRet;
120 szRet.cx = m_szMin[0].toPixelSize(nScale);
121 szRet.cy = m_szMin[1].toPixelSize(nScale);
122 return szRet;
123}
124
125void SHostWndAttr::SetTranslucent(bool bTranslucent)
126{
127 m_bTranslucent = bTranslucent;
128}
129
130void SHostWndAttr::SetTrCtx(const SStringW &strTrCtx)
131{
132 m_strTrCtx = strTrCtx;
133}
134
136{
137 m_bSendWheel2Hover = value;
138}
139
140//////////////////////////////////////////////////////////////////////////
141// SRootWindow
142//////////////////////////////////////////////////////////////////////////
143
144enum
145{
146 kAni4Destroy = 1,
147 kAni4Hide = 2,
148};
149
150enum AniState
151{
152 Ani_none = 0,
153 Ani_win_enter = 1,
154 Ani_win_exit = 2,
155 Ani_win = (Ani_win_enter | Ani_win_exit),
156 Ani_host = 4,
157 Ani_All = (Ani_win | Ani_host),
158};
159
160SRootWindow::SRootWindow(SHostWnd *pHostWnd)
161 : m_pHostWnd(pHostWnd)
162{
163 GetEventSet()->addEvent(EVENTID(EventInit));
164 GetEventSet()->addEvent(EVENTID(EventExit));
165 GetEventSet()->addEvent(EVENTID(EventMenuCmd));
166}
167
168void SRootWindow::OnAnimationInvalidate(IAnimation *pAni, bool bErase)
169{
170 if (bErase)
171 {
172 CRect rcWnd = GetClientRect();
173 m_pHostWnd->m_memRT->BeginDraw();
174 m_pHostWnd->m_memRT->ClearRect(rcWnd, 0);
175 m_pHostWnd->m_memRT->EndDraw();
176 }
177 SWindow::OnAnimationInvalidate(pAni, bErase);
178 if (!bErase)
179 Update();
180}
181
182void SRootWindow::OnAnimationStop(IAnimation *pAni)
183{
185 if (pAni == m_aniEnter || pAni == m_aniExit)
186 {
187 m_pHostWnd->m_AniState &= ~Ani_win;
188 if (pAni == m_aniExit)
189 {
190 ULONG_PTR data = pAni->getUserData();
191 if (data == kAni4Destroy)
192 m_pHostWnd->SNativeWnd::DestroyWindow();
193 else if (data == kAni4Hide)
194 {
195 m_pHostWnd->SNativeWnd::SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
196 }
197 pAni->setUserData(0);
198 }
199 }
200}
201
203{
204 int iState = SState2Index::GetDefIndex(GetState(), true);
205 SwndStyle &style = SWindow::GetStyle();
206 IFontPtr pFont = style.GetTextFont(iState);
207 if (pFont)
208 pRT->SelectObject(pFont, (IRenderObj **)&painter.oldFont);
209 else
210 pRT->SelectObject(GETUIDEF->GetFont(FF_DEFAULTFONT, GetScale()), NULL);
211
212 COLORREF crTxt = style.GetTextColor(iState);
213 if (crTxt != CR_INVALID)
214 painter.oldTextColor = pRT->SetTextColor(crTxt);
215 else
216 pRT->SetTextColor(RGBA(0, 0, 0, 255));
217}
218
220{
221 pRT->SelectDefaultObject(OT_FONT, NULL);
222}
223
225{
226 if (!IsLayoutDirty())
227 return;
228 SIZE szAppSet = m_pHostWnd->m_szAppSetted;
229 if ((szAppSet.cx <= 0 || szAppSet.cy <= 0) && GetLayoutParam()->IsWrapContent(Any))
230 {
231 int nWid = szAppSet.cx;
232 if (nWid <= 0)
233 {
234 nWid = GetLayoutParam()->IsSpecifiedSize(Horz) ? GetLayoutParam()->GetSpecifiedSize(Horz).toPixelSize(GetScale()) : SIZE_WRAP_CONTENT;
235 }
236 int nHei = szAppSet.cy;
237 if (nHei <= 0)
238 {
239 nHei = GetLayoutParam()->IsSpecifiedSize(Vert) ? GetLayoutParam()->GetSpecifiedSize(Vert).toPixelSize(GetScale()) : SIZE_WRAP_CONTENT;
240 }
241 CSize szRoot;
242 GetDesiredSize(&szRoot, nWid, nHei);
243 OnRelayout(CRect(CPoint(), szRoot));
244 }
245 else
246 {
248 }
249}
250
252{
253 SStringT str = S_CW2T(tr(m_pHostWnd->m_hostAttr.m_strTitle));
254 m_pHostWnd->SetWindowText(str);
255 return 3;
256}
257
259{
260 m_layoutDirty = dirty_self;
263}
264
265void SRootWindow::RequestRelayout(SWND hSource, BOOL bSourceResizable)
266{
267 SWindow *pSource = SWindowMgr::GetWindow(hSource);
268 SASSERT(pSource);
269
270 if (m_layoutDirty != dirty_self)
271 m_layoutDirty = (hSource == m_swnd || bSourceResizable) ? dirty_self : dirty_child;
272
273 CRect rcSour = pSource->GetWindowRect();
274 while (rcSour.IsRectEmpty())
275 {
276 pSource = pSource->GetParent();
277 if (!pSource)
278 break;
279 rcSour = pSource->GetWindowRect();
280 }
281 m_pHostWnd->OnRedraw(rcSour, FALSE);
282}
283
284SHostWnd *SRootWindow::GetHostWnd() const
285{
286 return m_pHostWnd;
287}
288
290{
291 EventMenuCmd evt(this);
292 evt.menuId = menuID;
293 FireEvent(evt);
294}
295
296//////////////////////////////////////////////////////////////////////////
297// SHostWnd
298//////////////////////////////////////////////////////////////////////////
299
302
304{
305 s_HideLocalUiDef = bHide;
306}
307
309{
310 s_TaskQueueBufSize = nBufSize;
311}
312
313SHostWnd::SHostWnd(LPCWSTR pszResName /*= NULL*/)
314{
315 if (pszResName)
316 m_strXmlLayout = S_CW2T(pszResName);
317 _Init();
318}
319
320SHostWnd::SHostWnd(LPCSTR pszResName)
321{
322 if (pszResName)
323 m_strXmlLayout = S_CA2T(pszResName, CP_UTF8);
324 _Init();
325}
326
328{
330 m_bTrackFlag = FALSE;
331 m_bNeedRepaint = FALSE;
332 m_bNeedAllRepaint = TRUE;
333 m_pTipCtrl = NULL;
334 m_dummyWnd = NULL;
335 m_szAppSetted = CSize(0, 0);
336 m_nAutoSizing = 0;
337 m_bResizing = false;
338 m_dwThreadID = 0;
339 m_AniState = 0;
340 m_pRoot = NULL;
341 m_pNcPainter.Attach(new SNcPainter(this));
342 m_msgMouse.message = 0;
343
344 m_hostAnimationHandler.m_pHostWnd = this;
345 m_evtHandler.fun = NULL;
346 m_evtHandler.ctx = NULL;
348 m_xmlInit = NULL;
349}
350
352{
353 if (m_pRoot)
354 {
355 m_pRoot->Release();
356 m_pRoot = NULL;
357 }
359}
360
361HWND SHostWnd::CreateEx(HWND hWndParent, DWORD dwStyle, DWORD dwExStyle, int x, int y, int nWidth, int nHeight, IXmlNode *xmlInit)
362{
363 if (NULL != m_hWnd)
364 return m_hWnd;
366 SXmlDoc xmlDoc;
367 SXmlNode xmlRoot;
368 if (!xmlInit)
369 {
370 xmlRoot = OnGetInitXmlNode(xmlDoc);
371 if (!xmlRoot)
372 {
373 SSLOGW() << "OnGetInitXmlNode return empty xml";
374 }
375 else
376 {
377 xmlInit = &xmlRoot;
378 }
379 }
380 // read translucent property
381 m_hostAttr.Init();
382 m_hostAttr.InitFromXml(xmlInit);
383 if (m_hostAttr.m_bTranslucent)
384 {
385 dwExStyle |= WS_EX_LAYERED;
386#ifndef _WIN32
387 dwExStyle |= WS_EX_COMPOSITED;
388#endif //_WIN32
389 }
390 m_xmlInit = xmlInit;
391 HWND hWnd = SNativeWnd::CreateNative(_T("HOSTWND"), dwStyle, dwExStyle, x, y, nWidth, nHeight, hWndParent, 0);
392 m_xmlInit = NULL;
393 UpdateAutoSizeCount(false);
394 if (!hWnd)
395 return NULL;
396
397 if ((nWidth == 0 || nHeight == 0) && (x == 0 && y == 0))
398 CenterWindow(hWndParent);
399 return hWnd;
400}
401
402HWND SHostWnd::Create(HWND hWndParent, int x, int y, int nWidth, int nHeight)
403{
404 DWORD dwStyle = WS_CLIPCHILDREN;
405 if (hWndParent)
406 dwStyle |= WS_TABSTOP;
407 return CreateEx(hWndParent, dwStyle, 0, x, y, nWidth, nHeight);
408}
409
410BOOL SHostWnd::onRootResize(IEvtArgs *e)
411{
412 if (!m_bResizing)
413 {
414 EventSwndSize *e2 = sobj_cast<EventSwndSize>(e);
416 CRect rcWnd(CPoint(), e2->szWnd);
417 rcWnd.InflateRect(GetRoot()->GetStyle().GetMargin());
418 SetWindowPos(NULL, 0, 0, rcWnd.Width(), rcWnd.Height(), SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
419 UpdateAutoSizeCount(false);
420 }
421 return TRUE;
422}
423
424void SHostWnd::EnablePrivateUiDef(THIS_ BOOL bEnable)
425{
427 return;
428 if (bEnable)
429 {
430 if (++m_cEnableUiDefCount == 1)
431 GETUIDEF->PushUiDefInfo(m_privateUiDefInfo, TRUE);
432 }
433 else
434 {
435 if (--m_cEnableUiDefCount == 0)
436 GETUIDEF->PopUiDefInfo(m_privateUiDefInfo, TRUE);
437 }
438}
439
441{
442 SASSERT(pNode);
443 if (pNode->Empty())
444 {
445 SASSERT_MSGA(FALSE, "Null XML node");
446 return FALSE;
447 }
449 return FALSE;
450
451 m_privateUiDefInfo = NULL;
453 IUiDefInfo *pUiDefInfo = SUiDef::CreateUiDefInfo();
454 if (pUiDefInfo->Init2(pNode, FALSE))
455 { // init private uidef info.
456 m_privateUiDefInfo = pUiDefInfo;
457 }
458 pUiDefInfo->Release();
459 EnablePrivateUiDef(TRUE);
460
461 if (m_AniState != Ani_none)
462 {
463 if (m_AniState & Ani_host)
465 if (m_AniState & Ani_win)
466 GetRoot()->GetAnimation()->cancel();
467 SASSERT(m_AniState == Ani_none);
468 }
469
470 // free old script module
471 if (m_pScriptModule)
472 {
473 GetMsgLoop()->RemoveIdleHandler(m_pScriptModule->getIdleHandler());
474 EventExit evt(GetRoot());
475 GetRoot()->FireEvent(evt);
476 m_pScriptModule = NULL;
477 }
478
479 //为了能够重入,先销毁原有的SOUI窗口
480 GetRoot()->SSendMessage(WM_DESTROY);
481 m_bFirstShow = TRUE;
482
483 //加载脚本数据
484 SXmlNode xmlNode(pNode);
485 SXmlNode xmlScript = xmlNode.child(L"script");
486 if (xmlScript)
487 { // create new script module
488 xmlScript.set_userdata(1);
490 if (m_pScriptModule)
491 {
492 IIdleHandler *pIdleHandler = m_pScriptModule->getIdleHandler();
493 if (pIdleHandler)
494 GetMsgLoop()->AddIdleHandler(pIdleHandler);
495 SXmlAttr attrSrc = xmlScript.attribute(L"src");
496 if (attrSrc)
497 {
498 SStringT strSrc = S_CW2T(attrSrc.value());
499 SStringTList lstSrc;
500 ParseResID(strSrc, lstSrc);
501 LPCTSTR pszType = NULL;
502 LPCTSTR pszName = NULL;
503 if (lstSrc.GetCount() == 2)
504 {
505 pszType = lstSrc[0];
506 pszName = lstSrc[1];
507 }
508 else
509 {
510 pszName = strSrc;
511 }
512 {
513 size_t dwSize = SApplication::getSingleton().GetRawBufferSize(pszType, pszName);
514 if (dwSize)
515 {
516 SAutoBuf buff(dwSize);
517 SApplication::getSingleton().GetRawBuffer(pszType, pszName, buff, dwSize);
518 m_pScriptModule->executeScriptBuffer(buff, dwSize);
519 }
520 }
521 }
522 else
523 {
524 //从script节点的cdata中获取脚本
525 SStringW strScript = xmlScript.child_value();
526 if (!strScript.IsEmpty())
527 {
528 SStringA utf8Script = S_CW2A(strScript, CP_UTF8);
529 m_pScriptModule->executeScriptBuffer(utf8Script, utf8Script.GetLength());
530 }
531 }
532 }
533 }
534 SXmlNode xmlNcPainter = xmlNode.child(SNcPainter::GetClassName());
535 xmlNcPainter.set_userdata(1);
536 m_pNcPainter->InitFromXml(&xmlNcPainter);
537
538 DWORD dwStyle = SNativeWnd::GetStyle();
539 DWORD dwExStyle = SNativeWnd::GetExStyle();
540
541 if (m_hostAttr.m_bResizable)
542 {
543 dwStyle |= WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME;
544 }
545 else
546 {
547 dwStyle |= WS_MINIMIZEBOX;
548 }
549 if (m_hostAttr.m_bAppWnd)
550 {
551 dwStyle |= WS_SYSMENU;
552 dwExStyle |= WS_EX_APPWINDOW;
553 }
554 else if (m_hostAttr.m_bToolWnd)
555 {
556 dwExStyle |= WS_EX_TOOLWINDOW;
557 }
558
559 if (m_hostAttr.m_dwStyle != 0)
560 dwStyle = m_hostAttr.m_dwStyle & (~WS_VISIBLE);
561 if (m_hostAttr.m_dwExStyle != 0)
562 dwExStyle = m_hostAttr.m_dwExStyle;
563
564 ModifyStyle(0, dwStyle);
565 ModifyStyleEx(0, dwExStyle);
566 m_pRoot->OnLanguageChanged();
567
568 if (m_hostAttr.m_hAppIconSmall)
569 {
570 SendMessage(WM_SETICON, FALSE, (LPARAM)m_hostAttr.m_hAppIconSmall);
571 }
572 if (m_hostAttr.m_hAppIconBig)
573 {
574 SendMessage(WM_SETICON, TRUE, (LPARAM)m_hostAttr.m_hAppIconBig);
575 }
576
577 // compatible with 2.x width and height properties in soui element.
578 SXmlAttr attrWid = xmlNode.attribute(L"width");
579 SXmlAttr attrHei = xmlNode.attribute(L"height");
580 SXmlNode xmlRoot = xmlNode.child(L"root");
581 xmlRoot.set_userdata(1);
582 if (attrWid && !xmlRoot.attribute(attrWid.name()))
583 xmlRoot.append_copy(attrWid);
584 if (attrHei && !xmlRoot.attribute(attrHei.name()))
585 xmlRoot.append_copy(attrHei);
586
587 GetRoot()->InitFromXml(&xmlRoot);
588
589 if (IsTranslucent())
590 {
591#ifdef _WIN32
592 if (!m_dummyWnd)
593 {
594 SetWindowLongPtr(GWL_EXSTYLE, GetWindowLongPtr(GWL_EXSTYLE) | WS_EX_LAYERED);
595 m_dummyWnd = new SDummyWnd(this);
596 HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
597 MONITORINFO info = { sizeof(MONITORINFO) };
598 GetMonitorInfo(hMonitor, &info);
599 SStringT dummyTitle = SStringT().Format(_T("%s_dummy"), m_hostAttr.m_strTitle.c_str());
600 m_dummyWnd->CreateNative(dummyTitle, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE, info.rcWork.left, info.rcWork.top, 1, 1, m_hWnd, 0, NULL);
601 m_dummyWnd->SetWindowLongPtr(GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE | WS_EX_LAYERED);
602 ::SetLayeredWindowAttributes(m_dummyWnd->m_hWnd, 0, 0, LWA_ALPHA);
603 if (IsWindowVisible())
604 {
605 m_dummyWnd->ShowWindow(SW_SHOWNOACTIVATE);
606 }
607 }
608#endif //_WIN32
609 }
610 else if (dwExStyle & WS_EX_LAYERED || GetRoot()->GetAlpha() != 0xFF)
611 {
612 if (m_dummyWnd)
613 {
614 m_dummyWnd->DestroyWindow(); // m_dummyWnd will be set to null in SDummyWnd::OnDestroy
615 }
616 if (!(dwExStyle & WS_EX_LAYERED))
617 {
618#ifdef _WIN32
619 ModifyStyleEx(0, WS_EX_LAYERED);
620#else
621 ModifyStyleEx(0, WS_EX_LAYERED | WS_EX_COMPOSITED);
622#endif //_WIN32
623 }
624 SetLayeredWindowAttributes(0, GetRoot()->GetAlpha(), LWA_ALPHA);
625 }
626 m_memRT = NULL;
627 if (IsTranslucent())
628 {
629 CRect rcWnd;
631 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcWnd.Width(), rcWnd.Height());
632 }
633 else
634 {
635 GETRENDERFACTORY->CreateRenderTarget2(&m_memRT, m_hWnd);
636 }
637
639
640 int nWidth = m_szAppSetted.cx;
641 int nHeight = m_szAppSetted.cy;
642 CSize szNc = m_pNcPainter->GetNcSize();
643 CSize szRoot;
644 if (nWidth == 0)
645 nWidth = SIZE_WRAP_CONTENT;
646 if (nHeight == 0)
647 nHeight = SIZE_WRAP_CONTENT;
648 GetRoot()->GetDesiredSize(&szRoot, nWidth, nHeight);
649
650 ILayoutParam *pLayoutParam = GetRoot()->GetLayoutParam();
651 if (nWidth == 0 && pLayoutParam->IsSpecifiedSize(Horz))
652 {
653 nWidth = pLayoutParam->GetSpecifiedSize(Horz).toPixelSize(GetScale()) + szNc.cx;
654 }
655 if (nHeight == 0 && pLayoutParam->IsSpecifiedSize(Vert))
656 {
657 nHeight = pLayoutParam->GetSpecifiedSize(Vert).toPixelSize(GetScale()) + szNc.cy;
658 }
659
660 if (nWidth <= 0 || nHeight <= 0)
661 { //计算出root大小
662 if (nWidth <= 0)
663 {
664 nWidth = SIZE_WRAP_CONTENT;
665 }
666 if (nHeight <= 0)
667 {
668 nHeight = SIZE_WRAP_CONTENT;
669 }
670
671 if (nWidth == SIZE_WRAP_CONTENT)
672 nWidth = szRoot.cx + szNc.cx;
673 if (nHeight == SIZE_WRAP_CONTENT)
674 nHeight = szRoot.cy + szNc.cy;
675 GetRoot()->GetEventSet()->subscribeEvent(EventSwndSize::EventID, Subscriber(&SHostWnd::onRootResize, this));
676 }
677
678 if (nWidth != m_szAppSetted.cx || nHeight != m_szAppSetted.cy)
679 {
681 SetWindowPos(NULL, 0, 0, nWidth, nHeight, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
682 UpdateAutoSizeCount(false);
683 }
684
685 CRect rcClient;
686 SNativeWnd::GetClientRect(&rcClient);
687 GetRoot()->OnRelayout(rcClient);
688
689 //设置重绘标记
690 m_bNeedAllRepaint = TRUE;
691 m_bNeedRepaint = TRUE;
692 m_rgnInvalidate->Clear();
693
694 EventInit evt(GetRoot());
695 GetRoot()->FireEvent(evt);
696
697 // handle user xml node
698 SXmlNode xmlChild = xmlNode.first_child();
699 while (xmlChild)
700 {
701 if (xmlChild.get_userdata() != 1)
702 {
703 OnUserXmlNode(xmlChild);
704 }
705 else
706 {
707 xmlChild.set_userdata(0);
708 }
709 xmlChild = xmlChild.next_sibling();
710 }
711
713 EnablePrivateUiDef(FALSE);
714
715 return TRUE;
716}
717
719{
720 m_bNeedAllRepaint = TRUE;
721 m_rgnInvalidate->Clear();
722 _Invalidate(NULL);
723}
724
725void SHostWnd::_RedrawRegion(IRegionS *pRgnUpdate, CRect &rcInvalid)
726{
727 m_memRT->BeginDraw();
728 CRect rcWnd = m_pRoot->GetWindowRect();
729
730 SPainter painter;
731 m_pRoot->BeforePaint(m_memRT, painter);
732
733 if (!pRgnUpdate->IsEmpty())
734 {
735 pRgnUpdate->GetRgnBox(&rcInvalid);
736 rcInvalid.IntersectRect(rcInvalid, rcWnd);
737 m_memRT->PushClipRegion(pRgnUpdate, RGN_COPY);
738 }
739 else
740 {
741 rcInvalid = rcWnd;
742 pRgnUpdate->CombineRect(&rcWnd, RGN_COPY);
743 m_memRT->PushClipRect(&rcInvalid, RGN_COPY);
744 }
745 //清除残留的alpha值
746 m_memRT->ClearRect(rcInvalid, 0);
747
748 int clipState = 0;
749 m_memRT->SaveClip(&clipState);
750 _ExcludeVideoCanvasFromPaint(m_memRT); // exclude video canvas region from normal paint routine.
751 GetRoot()->RedrawRegion(m_memRT, pRgnUpdate);
752 m_memRT->RestoreClip(clipState);
753 _PaintVideoCanvasForeground(m_memRT); // paint foreground of video canvas.
754
755 m_memRT->PopClip();
756
757 m_pRoot->AfterPaint(m_memRT, painter);
758 m_memRT->EndDraw();
759}
760
761void SHostWnd::OnPrint(HDC dc, UINT uFlags)
762{
763 if (!(GetRoot()->IsLayoutDirty() || IsWindowVisible()))
764 return;
765 //刷新前重新布局,会自动检查布局脏标志
767
769 {
770 m_rgnInvalidate->Clear();
771 m_bNeedAllRepaint = FALSE;
772 m_bNeedRepaint = TRUE;
773 }
774
775 CRect rcInvalid;
776 if (m_bNeedRepaint)
777 {
778 m_bNeedRepaint = FALSE;
780 // m_rgnInvalidate有可能在RedrawRegion时被修改,必须生成一个临时的区域对象
782 m_rgnInvalidate = NULL;
783 GETRENDERFACTORY->CreateRegion(&m_rgnInvalidate);
784 _RedrawRegion(pRgnUpdate, rcInvalid);
785 }
786 else
787 { //缓存已经更新好了,只需要重新更新到窗口
788 m_rgnInvalidate->GetRgnBox(&rcInvalid);
789 m_rgnInvalidate->Clear();
790 }
791 if (dc)
792 { //由系统发的WM_PAINT或者WM_PRINT产生的重绘请求
793 CRect rcUpdate;
794 ::GetClipBox(dc, &rcUpdate);
795 rcInvalid = rcInvalid | rcUpdate;
796 }
797 UpdatePresenter(dc, m_memRT, rcInvalid, 255, uFlags);
798}
799
801{
802 PAINTSTRUCT ps;
803 dc = ::BeginPaint(m_hWnd, &ps);
804#ifdef _WIN32
805 OnPrint(m_hostAttr.m_bTranslucent ? NULL : dc);
806#else
807 OnPrint(dc);
808#endif //_WIN32
809 ::EndPaint(m_hWnd, &ps);
810}
811
813{
814 return TRUE;
815}
816
818{
819 return GETTOOLTIPFACTORY->CreateToolTip(m_hWnd);
820}
821
823{
824 GETTOOLTIPFACTORY->DestroyToolTip(pTooltip);
825}
826
828{
830 return xmlDoc.root().first_child();
831}
832
834{
835 if (m_strXmlLayout.IsEmpty())
836 {
837 SSLOGW() << "resId is empty";
838 return FALSE;
839 }
840 return LOADXML(xmlDoc, m_strXmlLayout);
841}
842
844{
845 return new SRootWindow(this);
846}
847
848int SHostWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
849{
850 if (!m_presenter)
851 {
852 m_presenter.Attach(new SHostPresenter(this));
853 }
854 m_presenter->OnHostCreate();
855 m_dwThreadID = GetCurrentThreadId();
858 m_memRT = NULL;
859 CRect rcWnd = GetClientRect();
860 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcWnd.Width(), rcWnd.Height());
861 m_rgnInvalidate = NULL;
862 GETRENDERFACTORY->CreateRegion(&m_rgnInvalidate);
863 m_szAppSetted.cx = lpCreateStruct->cx;
864 m_szAppSetted.cy = lpCreateStruct->cy;
865
866 if (m_pRoot)
867 {
868 m_pRoot->Release();
869 m_pRoot = NULL;
870 }
872 m_pRoot->SetContainer(this);
874
875 // load xml resource
876 SXmlDoc xmlDoc;
877 SXmlNode xmlRoot;
878 IXmlNode *pXmlRoot = m_xmlInit;
879 if (!pXmlRoot)
880 {
881 xmlRoot = OnGetInitXmlNode(xmlDoc);
882 if (!xmlRoot)
883 {
884 SSLOGW() << "OnGetInitXmlNode return empty xml";
885 }
886 else
887 {
888 pXmlRoot = &xmlRoot;
889 }
890 }
891 if (pXmlRoot && !InitFromXml(pXmlRoot))
892 return -1;
895 if (m_pTipCtrl && m_hostAttr.m_bHasMsgLoop)
897 UpdateAutoSizeCount(false);
898 return 0;
899}
900
902{
903 m_presenter->OnHostDestroy();
904 m_presenter = NULL;
905 EventExit evt(GetRoot());
906 GetRoot()->FireEvent(evt);
907
908 GetRoot()->SSendMessage(WM_DESTROY);
909 GetRoot()->SSendMessage(UM_SETSCALE, 100);
910 if (m_pTipCtrl)
911 {
912 if (m_hostAttr.m_bHasMsgLoop)
915 m_pTipCtrl = NULL;
916 }
917 if (m_pScriptModule)
918 {
919 IIdleHandler *pIdleHandler = m_pScriptModule->getIdleHandler();
920 if (pIdleHandler)
921 GetMsgLoop()->RemoveIdleHandler(pIdleHandler);
922 m_pScriptModule = NULL;
923 }
924
925 if (!s_HideLocalUiDef)
926 EnablePrivateUiDef(FALSE);
927 SASSERT(m_cEnableUiDefCount == 0);
928 m_privateUiDefInfo = NULL;
929
930 m_memRT = NULL;
931 m_rgnInvalidate = NULL;
932
933 // clear pending tasks.
934 SPOSITION pos = m_runnables.GetHeadPosition();
935 while (pos)
936 {
937 IRunnable *pRunnable = m_runnables.GetNext(pos);
938 pRunnable->Release();
939 }
940 m_runnables.RemoveAll();
941
943 // exit app. (copy from wtl)
944 if (m_hostAttr.m_wndType == SHostWndAttr::WT_APPMAIN || (m_hostAttr.m_wndType == SHostWndAttr::WT_UNDEFINE && (SNativeWnd::GetStyle() & (WS_CHILD | WS_POPUP)) == 0 && (SNativeWnd::GetExStyle() & WS_EX_TOOLWINDOW) == 0))
945 GetMsgLoop()->Quit(1);
946}
947
948void SHostWnd::OnSize(UINT nType, CSize size)
949{
950 SetMsgHandled(FALSE); // chain wm_size to ncpainter.
952 if (IsIconic())
953 return;
954 if (size.cx == 0 || size.cy == 0)
955 return;
956
957 BOOL bSizeChange = size != m_szPrev;
958 // SSLOGI() << "on host size,szPrev=" << m_szPrev.cx << "," << m_szPrev.cy << " size=" << size.cx << "," << size.cy << " sizeChange=" << bSizeChange;
959 if (bSizeChange)
960 {
961 if (m_nAutoSizing == 0)
962 {
963 m_szAppSetted = size;
964 }
965 m_bResizing = TRUE;
966 m_memRT->Resize(size);
967 BOOL bDirty = GetRoot()->IsLayoutDirty();
968 GetRoot()->OnRelayout(CRect(0, 0, size.cx, size.cy));
969 if (m_nAutoSizing && bDirty)
970 GetRoot()->m_layoutDirty = SWindow::dirty_self;
971 m_presenter->OnHostResize(size);
972 m_bResizing = FALSE;
973 m_szPrev = size;
974 }
975 _Redraw();
976}
977
978void SHostWnd::OnMouseMove(UINT nFlags, CPoint point)
979{
980 if (!m_bTrackFlag)
981 {
982 TRACKMOUSEEVENT tme;
983 tme.cbSize = sizeof(tme);
984 tme.hwndTrack = m_hWnd;
985 tme.dwFlags = TME_LEAVE;
986 tme.dwHoverTime = 0;
987 m_bTrackFlag = TrackMouseEvent(&tme);
988 }
989 OnMouseEvent(WM_MOUSEMOVE, nFlags, MAKELPARAM(point.x, point.y));
990}
991
993{
994 m_bTrackFlag = FALSE;
995 OnMouseEvent(WM_MOUSELEAVE, 0, 0);
996}
997
998BOOL SHostWnd::OnSetCursor(HWND hwnd, UINT nHitTest, UINT message)
999{
1000 if (hwnd != m_hWnd)
1001 return FALSE;
1002 if (nHitTest == HTCLIENT)
1003 {
1004 CPoint pt;
1005 GetCursorPos(&pt);
1006 ScreenToClient(&pt);
1007 return DoFrameEvent(WM_SETCURSOR, 0, MAKELPARAM(pt.x, pt.y)) != 0;
1008 }
1009 return DefWindowProc() != 0;
1010}
1011
1012void SHostWnd::OnTimer(UINT_PTR idEvent)
1013{
1014 if (m_memRT == NULL) // host was destroyed
1015 return;
1016 if (idEvent == kPulseTimer)
1017 {
1018 if (!IsIconic())
1019 {
1021 }
1022 return;
1023 }
1024 else if (idEvent == kTaskTimer)
1025 {
1026 OnRunTasks(0, 0, 0);
1027 return;
1028 }
1029
1030 STimerID sTimerID((DWORD)idEvent);
1031 if (sTimerID.bSwndTimer)
1032 {
1033 SWindow *pSwnd = SWindowMgr::GetWindow((SWND)sTimerID.swnd);
1034 if (pSwnd)
1035 {
1036 pSwnd->SSendMessage(WM_TIMER, sTimerID.uTimerID, 0);
1037 }
1038 else
1039 {
1040 //窗口已经删除,自动清除该窗口的定时器
1041 ::KillTimer(m_hWnd, idEvent);
1042 }
1043 }
1044 else
1045 {
1046 SetMsgHandled(FALSE);
1047 }
1048}
1049
1050LRESULT SHostWnd::OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
1051{
1052 switch (uMsg)
1053 {
1054 case WM_LBUTTONDOWN:
1055 case WM_LBUTTONDBLCLK:
1056 case WM_RBUTTONDOWN:
1057 case WM_RBUTTONDBLCLK:
1058 case WM_MBUTTONDOWN:
1059 case WM_MBUTTONDBLCLK:
1060 m_msgMouse.message = uMsg;
1061 m_msgMouse.wParam = wParam;
1062 m_msgMouse.lParam = lParam;
1063 if (SNativeWnd::GetStyle() & WS_CHILD)
1064 SNativeWnd::SetFocus(); //子窗口情况下才自动获取焦点
1065 break;
1066 case WM_LBUTTONUP:
1067 if (!(SNativeWnd::GetStyle() & WS_CHILD))
1068 {
1069 m_pNcPainter->OnLButtonUp(wParam, lParam);
1070 }
1071 case WM_MBUTTONUP:
1072 case WM_RBUTTONUP:
1073 m_msgMouse.message = 0;
1074 break;
1075 case WM_MOUSEMOVE:
1076 m_msgMouse.message = 0;
1077 m_msgMouse.wParam = wParam;
1078 m_msgMouse.lParam = lParam;
1079 m_pNcPainter->OnMouseMove(wParam, lParam);
1080 break;
1081 case WM_MOUSELEAVE:
1082 m_msgMouse.message = uMsg;
1083 m_msgMouse.wParam = 0;
1084 m_msgMouse.lParam = 0;
1085 break;
1086 default:
1087 break;
1088 }
1089
1090 DoFrameEvent(uMsg, wParam, lParam); //将鼠标消息转发到SWindow处理
1091
1092 UpdateTooltip();
1093
1094 return 0;
1095}
1096
1097LRESULT SHostWnd::OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
1098{
1099 if (uMsg == WM_SYSKEYDOWN || uMsg == WM_SYSKEYUP)
1100 {
1101 SWindow *pFocus = SWindowMgr::GetWindow(m_focusMgr.GetFocusedHwnd());
1102 if (!pFocus || !(pFocus->OnGetDlgCode() & SC_WANTSYSKEY))
1103 {
1104 SetMsgHandled(FALSE);
1105 return 0;
1106 }
1107 }
1108 LRESULT lRet = DoFrameEvent(uMsg, wParam, lParam);
1109 SetMsgHandled(GetRoot()->IsMsgHandled());
1110 return lRet;
1111}
1112
1113LRESULT SHostWnd::OnActivateApp(UINT uMsg, WPARAM wParam, LPARAM lParam)
1114{
1115 if (!m_presenter) //防止host.OnDestroy中destroy子窗口可能给host发这个消息
1116 return 0;
1117 return DoFrameEvent(uMsg, wParam, lParam);
1118}
1119
1120BOOL SHostWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
1121{
1122 ScreenToClient(&pt);
1123 return DoFrameEvent(WM_MOUSEWHEEL, MAKEWPARAM(nFlags, zDelta), MAKELPARAM(pt.x, pt.y)) != 0;
1124}
1125
1126void SHostWnd::OnActivate(UINT nState, BOOL bMinimized, HWND wndOther)
1127{
1128 if (nState != WA_INACTIVE)
1129 {
1130 ::SetFocus(m_hWnd);
1131 }
1132 else
1133 {
1134 ::SetFocus(NULL);
1136 }
1137}
1138
1139BOOL SHostWnd::OnFireEvent(IEvtArgs *evt)
1140{
1141 if (m_evtHandler.fun)
1142 {
1143 if (m_evtHandler.fun(evt, m_evtHandler.ctx))
1144 return TRUE;
1145 }
1146 EventCmd *e2 = sobj_cast<EventCmd>(evt);
1147 if (e2)
1148 {
1149 bool bSysBtn = true;
1150 switch (e2->idFrom)
1151 {
1152 case SNcPainter::IDC_SYS_CLOSE:
1153 PostMessage(WM_SYSCOMMAND, SC_CLOSE);
1154 break;
1155 case SNcPainter::IDC_SYS_MIN:
1156 PostMessage(WM_SYSCOMMAND, SC_MINIMIZE);
1157 break;
1158 case SNcPainter::IDC_SYS_MAX:
1159 PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
1160 break;
1161 case SNcPainter::IDC_SYS_RESTORE:
1162 PostMessage(WM_SYSCOMMAND, SC_RESTORE);
1163 break;
1164 default:
1165 bSysBtn = false;
1166 break;
1167 }
1168 if (bSysBtn)
1169 return TRUE;
1170 }
1171 return _HandleEvent(evt);
1172}
1173
1174void SHostWnd::GetContainerRect(RECT *ret) const
1175{
1176 *ret = GetRoot()->GetWindowRect();
1177}
1178
1180{
1181 return m_hWnd;
1182}
1183
1184void SHostWnd::UpdatePresenter(HDC dc, IRenderTarget *pRT, LPCRECT rcInvalid, BYTE byAlpha, UINT uFlag)
1185{
1186 byAlpha = (BYTE)((int)byAlpha * GetRoot()->GetAlpha() / 255);
1187 if (pRT->IsOffscreen() || uFlag != 0)
1188 m_presenter->OnHostPresent(dc, pRT, rcInvalid, byAlpha);
1189}
1190
1191void SHostWnd::OnRedraw(LPCRECT rc, BOOL bClip)
1192{
1193 if (!IsWindow())
1194 return;
1195
1196 m_rgnInvalidate->CombineRect(rc, bClip ? RGN_DIFF : RGN_OR);
1197
1198 m_bNeedRepaint = TRUE;
1199
1200 _Invalidate(rc);
1201}
1202
1204{
1205 CRect rcInvalid;
1206 _RedrawRegion(rgn, rcInvalid);
1207 UpdatePresenter(0, m_memRT, rcInvalid);
1208}
1209
1211{
1213 return FALSE;
1214 if (GetCapture() == m_hWnd)
1215 ReleaseCapture();
1216 CPoint pt;
1217 GetCursorPos(&pt);
1218 ScreenToClient(&pt);
1219 PostMessage(WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
1220 return TRUE;
1221}
1222
1228
1230{
1231 return m_hostAttr.m_bTranslucent;
1232}
1233
1235{
1236 return m_hostAttr.m_bSendWheel2Hover;
1237}
1238
1239BOOL SHostWnd::UpdateWindow(BOOL bForce)
1240{
1241 if (m_bResizing)
1242 return FALSE;
1243 if (!m_bNeedRepaint && !bForce)
1244 return FALSE;
1245 if (m_dummyWnd)
1246 ::UpdateWindow(m_dummyWnd->m_hWnd);
1247 else
1248 ::UpdateWindow(m_hWnd);
1249 return TRUE;
1250}
1251
1253{
1254 if (!m_pTipCtrl)
1255 return;
1256 if (!m_hostAttr.m_bHasMsgLoop && GetCurrentMessage())
1257 {
1258 m_pTipCtrl->RelayEvent(GetCurrentMessage());
1259 }
1261 if (m_msgMouse.message != 0 || !pHover)
1262 {
1263 m_pTipCtrl->ClearTip();
1264 }
1265 else
1266 {
1267 CPoint pt(GET_X_LPARAM(m_msgMouse.lParam), GET_Y_LPARAM(m_msgMouse.lParam));
1268 SwndToolTipInfo tipInfo;
1269 BOOL bOK = pHover->UpdateToolTip(pt, tipInfo);
1270 if (bOK)
1271 {
1272 _SetToolTipInfo(&tipInfo, FALSE);
1273 }
1274 else
1275 { // hide tooltip
1276 _SetToolTipInfo(NULL, FALSE);
1277 }
1278 }
1279}
1280
1281void SHostWnd::SetToolTip(LPCRECT rc, UINT tipAlign, LPCTSTR pszTip)
1282{
1283 if (!m_pTipCtrl)
1284 return;
1285 CRect rc2;
1286 if (rc)
1287 {
1288 rc2 = *rc;
1289 ClientToScreen2(&rc2);
1290 }
1291
1292 m_pTipCtrl->SetToolTip(rc2, tipAlign, pszTip, GetScale());
1293}
1294
1295void SHostWnd::OnGetMinMaxInfo(LPMINMAXINFO lpMMI)
1296{
1297 HMONITOR hMonitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONULL);
1298
1299 if (hMonitor && GetRoot())
1300 {
1301 MONITORINFO mi = { sizeof(MONITORINFO) };
1302 ::GetMonitorInfo(hMonitor, &mi);
1303
1304 CRect rcWork = mi.rcWork, rcMonitor = mi.rcMonitor;
1305 CRect rcMaxInset = m_hostAttr.GetMaxInset(GetScale());
1306 lpMMI->ptMaxPosition.x = abs(rcWork.left - rcMonitor.left) - rcMaxInset.left;
1307 lpMMI->ptMaxPosition.y = abs(rcWork.top - rcMonitor.top) - rcMaxInset.top;
1308 lpMMI->ptMaxSize.x = abs(rcWork.Width()) + rcMaxInset.right + rcMaxInset.left;
1309 lpMMI->ptMaxSize.y = abs(rcWork.Height()) + rcMaxInset.bottom + rcMaxInset.top;
1310 lpMMI->ptMaxTrackSize.x = abs(rcWork.Width()) + rcMaxInset.right + rcMaxInset.left;
1311 lpMMI->ptMaxTrackSize.y = abs(rcWork.Height()) + rcMaxInset.bottom + rcMaxInset.top;
1312 CSize szMin = m_hostAttr.GetMinSize(GetScale());
1313 lpMMI->ptMinTrackSize = CPoint(szMin.cx, szMin.cy);
1314 }
1315 else
1316 {
1317 SetMsgHandled(FALSE);
1318 }
1319}
1320
1321void SHostWnd::OnSetFocus(HWND wndOld)
1322{
1323 DoFrameEvent(WM_SETFOCUS, 0, 0);
1324}
1325
1326void SHostWnd::OnKillFocus(HWND wndFocus)
1327{
1328 DoFrameEvent(WM_KILLFOCUS, 0, 0);
1329}
1330
1331static BOOL _BitBlt(IRenderTarget *pRTDst, IRenderTarget *pRTSrc, CRect rcDst, CPoint ptSrc)
1332{
1333 return S_OK == pRTDst->BitBlt(&rcDst, pRTSrc, ptSrc.x, ptSrc.y, SRCCOPY);
1334}
1335
1336BOOL SHostWnd::AnimateHostWindow(DWORD dwTime, DWORD dwFlags)
1337{
1338 if (!IsTranslucent())
1339 {
1340 return ::AnimateWindow(m_hWnd, dwTime, dwFlags);
1341 }
1342 else
1343 {
1344 CRect rcWnd; //窗口矩形
1346 CRect rcShow(rcWnd); //动画过程中可见部分
1347
1349 GETRENDERFACTORY->CreateRenderTarget(&pRT, rcShow.Width(), rcShow.Height());
1350
1351 _Redraw();
1353
1354 int nSteps = dwTime / 10;
1355 const BYTE byAlpha = GetRoot()->GetAlpha();
1356 if (dwFlags & AW_HIDE)
1357 {
1358 if (dwFlags & AW_SLIDE)
1359 {
1360 LONG x1 = rcShow.left;
1361 LONG x2 = rcShow.left;
1362 LONG y1 = rcShow.top;
1363 LONG y2 = rcShow.top;
1364 LONG *x = &rcShow.left;
1365 LONG *y = &rcShow.top;
1366
1367 if (dwFlags & AW_HOR_POSITIVE)
1368 { // left->right:move left
1369 x1 = rcShow.left, x2 = rcShow.right;
1370 x = &rcShow.left;
1371 }
1372 else if (dwFlags & AW_HOR_NEGATIVE)
1373 { // right->left:move right
1374 x1 = rcShow.right, x2 = rcShow.left;
1375 x = &rcShow.right;
1376 }
1377 if (dwFlags & AW_VER_POSITIVE)
1378 { // top->bottom
1379 y1 = rcShow.top, y2 = rcShow.bottom;
1380 y = &rcShow.top;
1381 }
1382 else if (dwFlags & AW_VER_NEGATIVE)
1383 { // bottom->top
1384 y1 = rcShow.bottom, y2 = rcShow.top;
1385 y = &rcShow.bottom;
1386 }
1387 LONG xStepLen = (x2 - x1) / nSteps;
1388 LONG yStepLen = (y2 - y1) / nSteps;
1389
1390 for (int i = 0; i < nSteps; i++)
1391 {
1392 *x += xStepLen;
1393 *y += yStepLen;
1394 pRT->BeginDraw();
1395 pRT->ClearRect(rcWnd, 0);
1396 CPoint ptAnchor;
1397 if (dwFlags & AW_VER_NEGATIVE)
1398 ptAnchor.y = rcWnd.bottom - rcShow.Height();
1399 if (dwFlags & AW_HOR_NEGATIVE)
1400 ptAnchor.x = rcWnd.right - rcShow.Width();
1401 _BitBlt(pRT, m_memRT, rcShow, ptAnchor);
1402 pRT->EndDraw();
1403 UpdatePresenter(0, pRT, &rcWnd, byAlpha);
1404 Sleep(10);
1405 }
1406 ShowWindow(SW_HIDE);
1407 return TRUE;
1408 }
1409 else if (dwFlags & AW_CENTER)
1410 {
1411 int xStep = rcShow.Width() / (2 * nSteps);
1412 int yStep = rcShow.Height() / (2 * nSteps);
1413 for (int i = 0; i < nSteps; i++)
1414 {
1415 rcShow.DeflateRect(xStep, yStep);
1416 pRT->BeginDraw();
1417 pRT->ClearRect(rcWnd, 0);
1418 _BitBlt(pRT, m_memRT, rcShow, rcShow.TopLeft());
1419 pRT->EndDraw();
1420 UpdatePresenter(0, pRT, rcWnd, byAlpha);
1421 Sleep(10);
1422 }
1423 ShowWindow(SW_HIDE);
1424 return TRUE;
1425 }
1426 else if (dwFlags & AW_BLEND)
1427 {
1428 BYTE byAlpha2 = byAlpha;
1429 for (int i = 0; i < nSteps; i++)
1430 {
1431 byAlpha2 -= 255 / nSteps;
1432 UpdatePresenter(0, m_memRT, &rcWnd, byAlpha2);
1433 Sleep(10);
1434 }
1435 ShowWindow(SW_HIDE);
1436 return TRUE;
1437 }
1438 return FALSE;
1439 }
1440 else
1441 {
1442 pRT->ClearRect(rcWnd, 0);
1443 UpdatePresenter(0, pRT, &rcWnd, byAlpha);
1444 SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | ((dwFlags & AW_ACTIVATE) ? 0 : SWP_NOACTIVATE));
1445
1446 if (dwFlags & AW_SLIDE)
1447 {
1448 LONG x1 = rcShow.left;
1449 LONG x2 = rcShow.left;
1450 LONG y1 = rcShow.top;
1451 LONG y2 = rcShow.top;
1452 LONG *x = &rcShow.left;
1453 LONG *y = &rcShow.top;
1454
1455 if (dwFlags & AW_HOR_POSITIVE)
1456 { // left->right:move right
1457 x1 = rcShow.left, x2 = rcShow.right;
1458 rcShow.right = rcShow.left, x = &rcShow.right;
1459 }
1460 else if (dwFlags & AW_HOR_NEGATIVE)
1461 { // right->left:move left
1462 x1 = rcShow.right, x2 = rcShow.left;
1463 rcShow.left = rcShow.right, x = &rcShow.left;
1464 }
1465 if (dwFlags & AW_VER_POSITIVE)
1466 { // top->bottom
1467 y1 = rcShow.top, y2 = rcShow.bottom;
1468 rcShow.bottom = rcShow.top, y = &rcShow.bottom;
1469 }
1470 else if (dwFlags & AW_VER_NEGATIVE)
1471 { // bottom->top
1472 y1 = rcShow.bottom, y2 = rcShow.top;
1473 rcShow.top = rcShow.bottom, y = &rcShow.top;
1474 }
1475 LONG xStepLen = (x2 - x1) / nSteps;
1476 LONG yStepLen = (y2 - y1) / nSteps;
1477
1478 for (int i = 0; i < nSteps; i++)
1479 {
1480 *x += xStepLen;
1481 *y += yStepLen;
1482 pRT->BeginDraw();
1483 pRT->ClearRect(rcWnd, 0);
1484 CPoint ptAnchor;
1485 if (dwFlags & AW_VER_POSITIVE)
1486 ptAnchor.y = rcWnd.bottom - rcShow.Height();
1487 if (dwFlags & AW_HOR_POSITIVE)
1488 ptAnchor.x = rcWnd.right - rcShow.Width();
1489 _BitBlt(pRT, m_memRT, rcShow, ptAnchor);
1490 pRT->EndDraw();
1491 UpdatePresenter(0, pRT, &rcWnd, byAlpha);
1492 Sleep(10);
1493 }
1494 UpdatePresenter(0, m_memRT, &rcWnd, byAlpha);
1495
1496 return TRUE;
1497 }
1498 else if (dwFlags & AW_CENTER)
1499 {
1500 int xStep = rcShow.Width() / (2 * nSteps);
1501 int yStep = rcShow.Height() / (2 * nSteps);
1502 rcShow.left = rcShow.right = (rcShow.left + rcShow.right) / 2;
1503 rcShow.top = rcShow.bottom = (rcShow.top + rcShow.bottom) / 2;
1504 for (int i = 0; i < nSteps; i++)
1505 {
1506 rcShow.InflateRect(xStep, yStep);
1507 pRT->BeginDraw();
1508 pRT->ClearRect(rcWnd, 0);
1509 _BitBlt(pRT, m_memRT, rcShow, rcShow.TopLeft());
1510 pRT->EndDraw();
1511 UpdatePresenter(0, pRT, &rcWnd, byAlpha);
1512 Sleep(10);
1513 }
1514 UpdatePresenter(0, m_memRT, &rcWnd, byAlpha);
1515 return TRUE;
1516 }
1517 else if (dwFlags & AW_BLEND)
1518 {
1519 BYTE byAlpha2 = 0;
1520 for (int i = 0; i < nSteps; i++)
1521 {
1522 byAlpha2 += byAlpha / nSteps;
1523 UpdatePresenter(0, m_memRT, &rcWnd, byAlpha2);
1524 Sleep(10);
1525 }
1526 UpdatePresenter(0, m_memRT, &rcWnd, byAlpha);
1527 return TRUE;
1528 }
1529 }
1530 return FALSE;
1531 }
1532}
1533
1535{
1536 bool bEmpty1 = m_timelineHandlerMgr.IsEmpty();
1537 BOOL bRet = SwndContainerImpl::RegisterTimelineHandler(pHandler);
1538 bool bEmpty2 = m_timelineHandlerMgr.IsEmpty();
1539 if (bEmpty1 && !bEmpty2)
1540 {
1542 }
1543 return bRet;
1544}
1545
1547{
1548 bool bEmpty1 = m_timelineHandlerMgr.IsEmpty();
1550 bool bEmpty2 = m_timelineHandlerMgr.IsEmpty();
1551 if (!bEmpty1 && bEmpty2)
1552 {
1554 }
1555 return bRet;
1556}
1557
1559{
1560 return m_hostAttr.m_strTrCtx;
1561}
1562
1564{
1565 tid_t tid = m_dwThreadID;
1566 if (tid == 0)
1567 tid = GetCurrentThreadId();
1569}
1570
1571#if (!DISABLE_SWNDSPY)
1572
1573LRESULT SHostWnd::OnSpyMsgSwndEnum(UINT uMsg, WPARAM wParam, LPARAM lParam)
1574{
1576 return 0;
1577 SWND swndCur = (SWND)wParam;
1578 if (swndCur == 0)
1579 swndCur = GetRoot()->m_swnd;
1580 SWindow *pSwnd = SWindowMgr::GetWindow(swndCur);
1581 if (!pSwnd)
1582 return 0;
1583 SWindow *pRet = pSwnd->GetWindow((int)lParam);
1584 if (!pRet)
1585 return 0;
1586 return pRet->GetSwnd();
1587}
1588
1589LRESULT SHostWnd::OnSpyMsgSwndSpy(UINT uMsg, WPARAM wParam, LPARAM lParam)
1590{
1591 if (!m_hostAttr.m_bAllowSpy)
1592 return 0;
1593 SWND swndCur = (SWND)wParam;
1594 if (swndCur == 0)
1595 swndCur = GetRoot()->m_swnd;
1596 SWindow *pSwnd = SWindowMgr::GetWindow(swndCur);
1597 if (!pSwnd)
1598 return 0;
1599
1600 SWNDINFO *pSwndInfo = new SWNDINFO;
1601 COPYDATASTRUCT cds;
1602 cds.dwData = SPYMSG_SWNDINFO;
1603 cds.cbData = sizeof(SWNDINFO);
1604 cds.lpData = pSwndInfo;
1605 memset(pSwndInfo, 0, sizeof(SWNDINFO));
1606
1607 pSwndInfo->swnd = swndCur;
1608 pSwnd->GetWindowRect(&pSwndInfo->rcWnd);
1609 pSwnd->GetClientRect(&pSwndInfo->rcClient);
1610 pSwndInfo->bVisible = pSwnd->IsVisible(TRUE);
1611 pSwndInfo->nID = pSwnd->GetID();
1612
1613 SStringW strTmp = pSwnd->GetName();
1614 if (strTmp.GetLength() <= SWND_MAX_NAME)
1615 wcscpy(pSwndInfo->szName, strTmp);
1616 else
1617 wcscpy(pSwndInfo->szName, L"##buf overflow!");
1618
1619 strTmp = pSwnd->GetObjectClass();
1620 if (strTmp.GetLength() <= SWND_MAX_CLASS)
1621 wcscpy(pSwndInfo->szClassName, strTmp);
1622 else
1623 wcscpy(pSwndInfo->szClassName, L"##buf overflow!");
1624
1625 wcscpy(pSwndInfo->szXmlStr, L"##unavailable!");
1626#ifdef _DEBUG
1627 strTmp = pSwnd->m_strXml;
1628 if (strTmp.GetLength() <= SWND_MAX_XML)
1629 wcscpy(pSwndInfo->szXmlStr, strTmp);
1630 else
1631 wcscpy(pSwndInfo->szXmlStr, L"##buf overflow!");
1632#endif //_DEBUG
1633 ::SendMessage(m_hSpyWnd, WM_COPYDATA, (WPARAM)m_hWnd, (LPARAM)&cds);
1634 delete pSwndInfo;
1635 return 1;
1636}
1637
1638LRESULT SHostWnd::OnSpyMsgSetSpy(UINT uMsg, WPARAM wParam, LPARAM lParam)
1639{
1640 m_hSpyWnd = (HWND)lParam;
1641 if (!::IsWindow(m_hSpyWnd))
1642 {
1643 m_hSpyWnd = 0;
1644 return 0;
1645 }
1646 return 1;
1647}
1648
1649LRESULT SHostWnd::OnSpyMsgHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam)
1650{
1651 CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1652 ScreenToClient(&pt);
1653 return GetRoot()->SwndFromPoint(pt);
1654}
1655#endif // DISABLE_SWNDSPY
1656
1658{
1659 if (wnd == m_hWnd)
1660 return;
1661 if (wnd != NULL)
1662 { //如果当前响应了鼠标按下消息,在lost capture时也应该响应弹起消息
1663#ifdef _WIN32
1664 TCHAR szClassName[30];
1665 ::GetClassName(wnd, szClassName, 30);
1666 if (_tcscmp(szClassName, _T("CLIPBRDWNDCLASS")) == 0)
1667 return; //在窗口内拖动时也可能产生capturechange消息。
1668#endif //_WIN32
1669 }
1671}
1672
1674{
1675 return m_pScriptModule;
1676}
1677
1679{
1680 return GetRoot()->GetScale();
1681}
1682
1683//////////////////////////////////////////////////////////////////////////
1685{
1686 if (m_AniState != Ani_none)
1687 {
1688 if (m_AniState | Ani_win_exit)
1689 return TRUE;
1690
1691 if (m_AniState & Ani_host)
1693 if (m_AniState & Ani_win)
1695 SASSERT(m_AniState == Ani_none);
1696 }
1697 if (m_pRoot->m_aniExit && !IsIconic())
1698 {
1699 m_pRoot->m_aniExit->setUserData(kAni4Destroy); // mark for destroy
1700 GetRoot()->StartAnimation(m_pRoot->m_aniExit);
1701 m_AniState |= Ani_win_exit;
1702 return TRUE;
1703 }
1704 else
1705 {
1707 }
1708}
1709
1711{
1712 CRect rc;
1714 return rc;
1715}
1716
1718{
1719 CRect rc;
1721 return rc;
1722}
1723
1724LRESULT SHostWnd::OnMenuExEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
1725{
1726 return OnFireEvent((IEvtArgs *)lParam);
1727}
1728
1729void SHostWnd::OnWindowPosChanging(LPWINDOWPOS lpWndPos)
1730{ //默认不处理该消息,同时防止系统处理该消息
1731 if (lpWndPos->flags & SWP_SHOWWINDOW && m_bFirstShow)
1732 {
1733 if (m_pRoot->m_aniEnter)
1734 {
1735 m_AniState |= Ani_win_enter;
1736 m_pRoot->StartAnimation(m_pRoot->m_aniEnter);
1737 OnNextFrame();
1738 }
1739 m_bFirstShow = FALSE;
1740 }
1741}
1742
1743void SHostWnd::OnWindowPosChanged(LPWINDOWPOS lpWndPos)
1744{
1745 //下面这一行不能删除,否则显示不正常。
1746 SetMsgHandled(FALSE);
1747 if (!m_dummyWnd)
1748 return;
1749
1750 if (!(lpWndPos->flags & SWP_NOMOVE))
1751 {
1752 HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
1753 MONITORINFO info = { sizeof(MONITORINFO) };
1754 if (GetMonitorInfo(hMonitor, &info))
1755 {
1756 m_dummyWnd->SetWindowPos(NULL, info.rcWork.left, info.rcWork.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
1757 }
1758 }
1759 if ((lpWndPos->flags & SWP_SHOWWINDOW))
1760 {
1761 m_dummyWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
1762 }
1763 else if ((lpWndPos->flags & SWP_HIDEWINDOW))
1764 {
1765 m_dummyWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
1766 }
1767}
1768
1769LRESULT SHostWnd::OnGetObject(UINT uMsg, WPARAM wParam, LPARAM lParam)
1770{
1771#ifdef SOUI_ENABLE_ACC
1772 IAccessible *pAcc = NULL;
1773 DWORD dwObjectId = lParam;
1774 if (dwObjectId == OBJID_CLIENT)
1775 {
1776 pAcc = GetRoot()->GetAccessible();
1777 }
1778 else
1779 {
1780 SWindow *pWnd = SWindowMgr::GetWindow(dwObjectId);
1781 if (pWnd)
1782 pAcc = pWnd->GetAccessible(); // user swnd to identify a swindow.
1783 }
1784
1785 if (pAcc != NULL)
1786 {
1787 return LresultFromObject(IID_IAccessible, wParam, pAcc);
1788 }
1789 else
1790#endif
1791 {
1792 SetMsgHandled(FALSE);
1793 return 0;
1794 }
1795}
1796
1798{
1799 switch (m_msgMouse.message)
1800 {
1801 case WM_LBUTTONDOWN:
1802 case WM_LBUTTONDBLCLK:
1803 SendMessage(WM_LBUTTONUP, m_msgMouse.wParam, m_msgMouse.lParam);
1804 break;
1805 case WM_RBUTTONDOWN:
1806 case WM_RBUTTONDBLCLK:
1807 SendMessage(WM_RBUTTONUP, m_msgMouse.wParam, m_msgMouse.lParam);
1808 break;
1809 case WM_MBUTTONDOWN:
1810 case WM_MBUTTONDBLCLK:
1811 SendMessage(WM_MBUTTONUP, m_msgMouse.wParam, m_msgMouse.lParam);
1812 break;
1813 default:
1814 break;
1815 }
1816}
1817
1818void SHostWnd::_Invalidate(LPCRECT prc)
1819{
1820#ifdef _WIN32
1821 if (!m_hostAttr.m_bTranslucent)
1822 {
1823 if (prc)
1824 SNativeWnd::InvalidateRect(prc, FALSE);
1825 else
1827 }
1828 else if (m_dummyWnd)
1829 {
1830 m_dummyWnd->Invalidate(FALSE);
1831 }
1832#else
1833 if (prc)
1834 SNativeWnd::InvalidateRect(prc, FALSE);
1835 else
1837#endif //_WIN32
1838}
1839
1840bool SHostWnd::StartHostAnimation(IAnimation *pAni)
1841{
1842 SASSERT(pAni);
1843 if (!IsWindow())
1844 return false;
1846
1847 m_AniState |= Ani_host;
1848 m_hostAnimation = pAni;
1849 m_hostAnimation->startNow();
1850
1851 CRect rcWnd;
1852 GetNative()->GetWindowRect(&rcWnd);
1853 CRect rcParent;
1854 HWND hParent = SNativeWnd::GetParent();
1855 if (hParent)
1856 {
1857 ::GetClientRect(hParent, &rcParent);
1858 }
1859 else
1860 {
1861 HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
1862 MONITORINFO info = { sizeof(MONITORINFO) };
1863 GetMonitorInfo(hMonitor, &info);
1864 rcParent = info.rcWork;
1865 }
1866 m_hostAnimation->initialize(rcWnd.Width(), rcWnd.Height(), rcParent.Width(), rcParent.Height(), GetScale());
1867 m_hostAnimationHandler.m_rcInit = rcWnd;
1868 RegisterTimelineHandler(&m_hostAnimationHandler);
1869 return true;
1870}
1871
1873{
1874 if (!m_hostAnimation)
1875 return false;
1876 m_hostAnimation->cancel();
1877 UnregisterTimelineHandler(&m_hostAnimationHandler);
1878 return true;
1879}
1880
1882{
1883 SSLOGD() << "unhandled xml node:" << xmlUser.name();
1884}
1885
1887{
1888 if (bInc)
1889 m_nAutoSizing++;
1890 else
1891 m_nAutoSizing--;
1892}
1893
1894void SHostWnd::EnableIME(BOOL bEnable)
1895{
1896 if (bEnable)
1897 {
1898 HIMC hImc = ImmGetContext(m_hWnd);
1899 if (!hImc)
1900 {
1901 hImc = ImmCreateContext();
1902 ImmAssociateContext(m_hWnd, hImc);
1903 }
1904 }
1905 else
1906 {
1907 HIMC hImc = ImmGetContext(m_hWnd);
1908 ImmAssociateContext(m_hWnd, NULL);
1909 if (hImc)
1910 {
1911 ImmDestroyContext(hImc);
1912 }
1913 }
1914}
1915
1917{
1918 CPoint pt;
1919 GetCursorPos(&pt);
1920 UINT ht = m_pNcPainter->OnNcHitTest(pt);
1921 PostMessage(WM_SETCURSOR, (WPARAM)m_hWnd, MAKELPARAM(ht, WM_MOUSEMOVE));
1922}
1923
1924BOOL SHostWnd::ShowWindow(int nCmdShow)
1925{
1926 UpdateAutoSizeCount(true);
1927 BOOL bRet = SNativeWnd::ShowWindow(nCmdShow);
1928 UpdateAutoSizeCount(false);
1929 return bRet;
1930}
1931
1933{
1934}
1935
1937{
1938 m_AniState &= ~Ani_host;
1939}
1940
1941void SHostWnd::OnSysCommand(UINT nID, CPoint lParam)
1942{
1943 if (nID == SC_RESTORE)
1944 {
1945 UpdateAutoSizeCount(true);
1946 DefWindowProc();
1947 UpdateAutoSizeCount(false);
1948 }
1949 else
1950 {
1951 DefWindowProc();
1952 }
1953 SetMsgHandled(TRUE); // todo: hjx, drag window may result in msgHandled flag been set to 0, fix it later.
1954}
1955
1956void SHostWnd::_SetToolTipInfo(const SwndToolTipInfo *info, BOOL bNcTip)
1957{
1958 if (!m_pTipCtrl)
1959 return;
1960 if (info)
1961 {
1962 TIPID id = { info->swnd, info->dwCookie, bNcTip };
1963 m_pTipCtrl->UpdateTip(&id, info->rcTarget, info->strTip, GetScale());
1964 }
1965 else
1966 {
1967 m_pTipCtrl->ClearTip();
1968 }
1969}
1970
1971void SHostWnd::SetEventHandler(THIS_ FunCallback fun, void *ctx)
1972{
1973 m_evtHandler.fun = fun;
1974 m_evtHandler.ctx = ctx;
1975}
1976
1977EventHandlerInfo *SHostWnd::GetEventHandler(THIS)
1978{
1979 return &m_evtHandler;
1980}
1981
1982BOOL SHostWnd::_HandleEvent(IEvtArgs *pEvt)
1983{
1984 return FALSE;
1985}
1986
1988{
1989 SPOSITION pos = m_lstVideoCanvas.GetHeadPosition();
1990 while (pos)
1991 {
1992 SWND swnd = m_lstVideoCanvas.GetNext(pos);
1993 SWindow *pWnd = SWindowMgr::GetWindow(swnd);
1994 if (pWnd && pWnd->IsVisible(TRUE))
1995 {
1996 CRect rcCanvas;
1997 pWnd->GetVisibleRect(&rcCanvas);
1998 pRT->PushClipRect(&rcCanvas, RGN_DIFF);
1999 }
2000 }
2001}
2002
2004{
2005 SPOSITION pos = m_lstVideoCanvas.GetHeadPosition();
2006 while (pos)
2007 {
2008 SWND swnd = m_lstVideoCanvas.GetNext(pos);
2009 SWindow *pWnd = SWindowMgr::GetWindow(swnd);
2010 if (pWnd && pWnd->IsVisible(TRUE))
2011 {
2012 CRect rcCanvas;
2013 pWnd->GetVisibleRect(&rcCanvas);
2014 if (!rcCanvas.IsRectEmpty())
2015 {
2016 pWnd->SSendMessage(WM_ERASEBKGND, (WPARAM)pRT);
2017 pWnd->SSendMessage(WM_PAINT, (WPARAM)pRT);
2018 pWnd->PaintForeground(pRT, &rcCanvas);
2019 }
2020 }
2021 }
2022}
2023
2024IHostPresenter *SHostWnd::GetPresenter(THIS)
2025{
2026 return m_presenter;
2027}
2028
2029void SHostWnd::SetPresenter(THIS_ IHostPresenter *pPresenter)
2030{
2031 m_presenter = pPresenter;
2032}
2033
2038
2039void SHostWnd::ShowHostWnd(THIS_ int nShowCmd, BOOL bWaitAniDone)
2040{
2041 if (nShowCmd != SW_HIDE)
2042 {
2043 if (IsWindowVisible())
2044 return;
2045 ShowWindow(nShowCmd);
2046 if (m_pRoot->m_aniEnter)
2047 {
2048 m_AniState |= Ani_win_enter;
2049 m_pRoot->StartAnimation(m_pRoot->m_aniEnter);
2050 OnNextFrame();
2051 }
2052 else
2053 {
2054 bWaitAniDone = FALSE;
2055 }
2056 }
2057 else
2058 {
2059 // hide
2060 if (!IsWindowVisible())
2061 return;
2062 if (m_AniState & Ani_win)
2063 m_pRoot->ClearAnimation();
2064 if (m_pRoot->m_aniExit)
2065 {
2066 m_AniState |= Ani_win_exit;
2067 m_pRoot->m_aniExit->setUserData(kAni4Hide); // mark for hide
2068 m_pRoot->StartAnimation(m_pRoot->m_aniExit);
2069 }
2070 else
2071 {
2072 SNativeWnd::SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
2073 bWaitAniDone = FALSE;
2074 }
2075 }
2076 if (bWaitAniDone)
2077 {
2080 for (; m_AniState & Ani_win;)
2081 {
2082 if (!msgLoop->WaitMsg())
2083 break;
2084 msgLoop->HandleMsg();
2085 }
2086 }
2087}
2088
2089void SHostWnd::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
2090{
2091 if (uNotifyCode == 0)
2092 {
2093 // for menu, translate to evt_menu_cmd
2094 m_pRoot->FireMenuCmd(nID);
2095 }
2096 else
2097 {
2098 SetMsgHandled(FALSE);
2099 }
2100}
2101
2102void SHostWnd::SetScale(THIS_ int nScale, LPCRECT desRect)
2103{
2104 EnablePrivateUiDef(TRUE);
2105 GetRoot()->SDispatchMessage(UM_SETSCALE, nScale, 0);
2106 GetNcPainter()->GetRoot()->SDispatchMessage(UM_SETSCALE, nScale, 0);
2107 UpdateAutoSizeCount(true);
2108 SetWindowPos(NULL, desRect->left, desRect->top, desRect->right - desRect->left, desRect->bottom - desRect->top, SWP_NOZORDER | SWP_NOACTIVATE);
2109 UpdateAutoSizeCount(false);
2110 EnablePrivateUiDef(FALSE);
2111}
2112
2113LRESULT SHostWnd::OnUpdateFont(UINT uMsg, WPARAM wp, LPARAM lp)
2114{
2115 GetNcPainter()->GetRoot()->SDispatchMessage(uMsg);
2116 GetRoot()->SDispatchMessage(uMsg);
2118
2119 return 0;
2120}
2121
2122void SHostWnd::EnableHostPrivateUiDef(THIS_ BOOL bEnable)
2123{
2124 EnablePrivateUiDef(bEnable);
2125}
2126
2127BOOL SHostWnd::PostTask(THIS_ IRunnable *runable, BOOL bAsync /*DEF_VAL(TRUE)*/)
2128{
2129 m_cs.Enter();
2130 m_runnables.AddTail(runable->clone());
2131 int tasks = (int)m_runnables.GetCount();
2132 if (!bAsync)
2133 {
2134 m_cs.Leave();
2135 SendMessage(UM_RUN_TASKS);
2136 return TRUE;
2137 }
2138 else if (tasks > s_TaskQueueBufSize)
2139 {
2140 PostMessage(UM_RUN_TASKS);
2141 }
2142 else if (tasks == 1)
2143 {
2144 SetTimer(kTaskTimer, kTaskInterval);
2145 }
2146 m_cs.Leave();
2147 return TRUE;
2148}
2149
2151{
2152 int nRet = 0;
2153 SAutoLock lock(m_cs);
2154 SPOSITION pos = m_runnables.GetHeadPosition();
2155 while (pos)
2156 {
2157 SPOSITION pos2 = pos;
2158 IRunnable *p = m_runnables.GetNext(pos);
2159 if (p->getObject() == pObj)
2160 {
2161 p->Release();
2162 m_runnables.RemoveAt(pos2);
2163 nRet++;
2164 }
2165 }
2167 pos = m_runningQueue.GetHeadPosition();
2168 while (pos)
2169 {
2170 SPOSITION pos2 = pos;
2171 IRunnable *p = m_runningQueue.GetNext(pos);
2172 if (p->getObject() == pObj)
2173 {
2174 p->Release();
2175 m_runningQueue.RemoveAt(pos2);
2176 nRet++;
2177 }
2178 }
2179 return nRet;
2180}
2181
2182LRESULT SHostWnd::OnRunTasks(UINT uMsg, WPARAM wp, LPARAM lp)
2183{
2184 m_cs.Enter();
2185 KillTimer(kTaskTimer);
2187 m_cs.Leave();
2188 for (;;)
2189 {
2191 if (m_runningQueue.IsEmpty())
2192 break;
2193 IRunnable *pRunnable = m_runningQueue.GetHead();
2194 m_runningQueue.RemoveHead();
2195 pRunnable->run();
2196 pRunnable->Release();
2197 }
2198 return 0;
2199}
2200
2201LRESULT SHostWnd::OnSetLanguage(UINT uMsg, WPARAM wp, LPARAM lp)
2202{
2203 GetNcPainter()->GetRoot()->SDispatchMessage(uMsg);
2204 GetNcPainter()->GetRoot()->RequestRelayout();
2205 GetNcPainter()->GetRoot()->Invalidate();
2206 GetRoot()->SDispatchMessage(uMsg);
2208 return 0;
2209}
2210
2211//////////////////////////////////////////////////////////////////
2212// SHostWnd::SHostAnimationHandler
2214{
2215 if (!m_pHostWnd->m_hostAnimation)
2216 return;
2217 IAnimation *pAni = m_pHostWnd->m_hostAnimation;
2218 uint64_t tm = pAni->getStartTime();
2219 if (tm == -1)
2220 {
2221 m_pHostWnd->OnHostAnimationStarted(pAni);
2222 }
2223 STransformation xform;
2224 BOOL bMore = m_pHostWnd->m_hostAnimation->getTransformation(STime::GetCurrentTimeMs(), &xform);
2225 SMatrix mtx = xform.getMatrix();
2226 mtx.preTranslate((int)-m_rcInit.left, (int)-m_rcInit.top);
2227 mtx.postTranslate((int)m_rcInit.left, (int)m_rcInit.top);
2228 if (mtx.rectStaysRect())
2229 {
2230 SRect rc = SRect::IMake(m_rcInit);
2231 mtx.mapRect(&rc);
2232 CRect rc2 = rc.toRect();
2233 ::SetWindowPos(m_pHostWnd->m_hWnd, NULL, rc2.left, rc2.top, rc2.Width(), rc2.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
2234 }
2235 if (xform.hasAlpha())
2236 { // change alpha.
2237 if (m_pHostWnd->IsTranslucent())
2238 {
2239 CRect rcWnd = m_pHostWnd->GetClientRect();
2240 IRenderTarget *pRT = m_pHostWnd->m_memRT;
2241 m_pHostWnd->UpdatePresenter(0, pRT, &rcWnd, xform.GetAlpha());
2242 }
2243 else if (m_pHostWnd->GetExStyle() & WS_EX_LAYERED)
2244 {
2245 m_pHostWnd->SetLayeredWindowAttributes(0, xform.GetAlpha(), LWA_ALPHA);
2246 }
2247 }
2248 if (!bMore)
2249 {
2250 m_pHostWnd->UnregisterTimelineHandler(this);
2251 m_pHostWnd->OnHostAnimationStoped(pAni);
2252 }
2253}
2254
2255SNSEND
Header file for the SAutoBuf class, a smart buffer management class.
IMessageLoop * GetMsgLoop(tid_t tid=::GetCurrentThreadId()) SCONST OVERRIDE
Get the message loop for a specific thread.
Definition SApp.cpp:718
IMsgLoopFactory * GetMsgLoopFactory() OVERRIDE
Get the message loop factory.
Definition SApp.cpp:598
HRESULT CreateScriptModule(IScriptModule **ppScriptModule) OVERRIDE
Create a script module.
Definition SApp.cpp:542
A smart buffer management class that automatically handles memory allocation and deallocation.
Definition SAutoBuf.h:18
Auto-lock class for managing critical sections.
Smart pointer class for managing COM-style reference-counted objects.
BOOL subscribeEvent(DWORD dwEventID, const IEvtSlot &subscriber)
订阅事件
Definition SEventSet.h:151
BOOL addEvent(DWORD dwEventID, LPCWSTR pszEventHandlerName)
添加一个新事件到事件集
bool RemoveHostMsgHandler(HWND hHost)
移除宿主窗口消息处理程序
Definition SHostMgr.cpp:22
bool AddHostMsgHandler(HWND hHost)
添加宿主窗口消息处理程序
Definition SHostMgr.cpp:13
Presenter class for the host window. This class manages the lifecycle and rendering of the host windo...
SHostWnd * m_pHostWnd
Pointer to the host window.
Definition SHostWnd.h:767
void OnNextFrame() OVERRIDE
Called on each frame of the animation.
CRect m_rcInit
Initial rectangle of the host window.
Definition SHostWnd.h:772
void SetSendWheel2Hover(bool value)
Sets whether wheel messages are sent to the hover window.
Definition shostwnd.cpp:135
BOOL m_bResizable
Definition SHostWnd.h:165
SLayoutSize m_rcMaxInset[4]
Definition SHostWnd.h:162
void SetTranslucent(bool bTranslucent)
Sets whether the window is translucent.
Definition shostwnd.cpp:125
CSize GetMinSize(int nScale) const
Gets the minimum size of the window.
Definition shostwnd.cpp:117
SLayoutSize m_rcMargin[4]
Definition SHostWnd.h:160
WndType m_wndType
Definition SHostWnd.h:164
BOOL m_bSendWheel2Hover
Definition SHostWnd.h:171
virtual LPCWSTR GetTrCtx() const
Gets the translation context.
Definition shostwnd.cpp:92
SLayoutSize m_szMin[2]
Definition SHostWnd.h:161
BOOL m_bHasMsgLoop
Definition SHostWnd.h:172
BOOL m_bAllowSpy
Definition SHostWnd.h:170
~SHostWndAttr()
Destructor for SHostWndAttr.
Definition shostwnd.cpp:63
void SetTrCtx(const SStringW &strTrCtx)
Sets the translation context.
Definition shostwnd.cpp:130
BOOL m_bTranslucent
Definition SHostWnd.h:168
CRect GetMaxInset(int nScale) const
Gets the maximum inset size of the window.
Definition shostwnd.cpp:97
void Init()
Initializes the window attributes.
Definition shostwnd.cpp:71
BOOL m_bAutoShape
Definition SHostWnd.h:169
BOOL m_bToolWnd
Definition SHostWnd.h:167
CRect GetMargin(int nScale) const
Gets the margin of the window.
Definition shostwnd.cpp:107
SHostWndAttr(void)
Constructor for SHostWndAttr.
Definition shostwnd.cpp:56
SStringW m_strTrCtx
Definition SHostWnd.h:176
BOOL m_bAppWnd
Definition SHostWnd.h:166
BOOL OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
Handles the WM_SETCURSOR message.
Definition shostwnd.cpp:998
BOOL UnregisterTimelineHandler(ITimelineHandler *pHandler) OVERRIDE
Unregisters a timeline handler.
LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles key events.
BOOL RegisterTimelineHandler(ITimelineHandler *pHandler) OVERRIDE
Registers a timeline handler.
EventHandlerInfo * GetEventHandler() OVERRIDE
Gets the event handler information for the host window.
void OnDestroy()
Handles the WM_DESTROY message.
Definition shostwnd.cpp:901
virtual void OnHostAnimationStoped(IAnimation *pAni)
Called when the host window animation stops.
void _Init()
Initializes the host window.
Definition shostwnd.cpp:327
CRect GetClientRect() const
Gets the client rectangle.
static void SetHideLocalUiDef(BOOL bHide)
Sets whether to hide local UI definitions globally.
Definition shostwnd.cpp:303
BOOL m_bNeedAllRepaint
Definition SHostWnd.h:330
void EnableHostPrivateUiDef(BOOL bEnable) OVERRIDE
Enables or disables host private UI definitions.
void OnRedraw(LPCRECT rc, BOOL bClip) OVERRIDE
Redraws the specified rectangle in the container.
void UpdatePresenter(HDC dc, IRenderTarget *pRT, LPCRECT rc, BYTE byAlpha=255, UINT uFlag=0)
Updates the presenter.
void EnableDragDrop() OVERRIDE
Enables drag-and-drop functionality for the host window.
LRESULT OnActivateApp(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles the WM_ACTIVATEAPP message.
BOOL ShowWindow(int nCmdShow) OVERRIDE
Shows or hides the host window.
EventHandlerInfo m_evtHandler
Definition SHostWnd.h:353
SAutoRefPtr< IUiDefInfo > m_privateUiDefInfo
Definition SHostWnd.h:336
int m_nAutoSizing
Definition SHostWnd.h:344
CSize m_szPrev
Definition SHostWnd.h:343
void OnSysCommand(UINT nID, CPoint lParam)
Handles the WM_SYSCOMMAND message.
BOOL IsTranslucent() SCONST OVERRIDE
Checks if the host window is translucent.
virtual ~SHostWnd()
Destructor for SHostWnd.
Definition shostwnd.cpp:351
void _Invalidate(LPCRECT prc)
Invalidates a specific region of the window.
BOOL m_bTrackFlag
Definition SHostWnd.h:328
BOOL InitFromXml(IXmlNode *pNode) OVERRIDE
Initializes the host window from an XML node.
Definition shostwnd.cpp:440
SNativeWnd * GetNative()
Gets the native window interface.
Definition SHostWnd.h:695
BOOL OnEraseBkgnd(HDC dc)
Handles the WM_ERASEBKGND message.
Definition shostwnd.cpp:812
virtual BOOL onRootResize(IEvtArgs *e)
Handles the resize event of the root window.
Definition shostwnd.cpp:410
virtual IToolTip * CreateTooltip() const
Creates a tooltip for the container.
Definition shostwnd.cpp:817
LRESULT OnGetObject(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles the WM_GETOBJECT message.
void _RedrawRegion(IRegionS *pRgn, CRect &rcInvalid)
Redraws a specific region of the window.
Definition shostwnd.cpp:725
SDummyWnd * m_dummyWnd
Definition SHostWnd.h:324
virtual SRootWindow * CreateRoot()
Creates the root window.
Definition shostwnd.cpp:843
BOOL OnFireEvent(IEvtArgs *evt) OVERRIDE
Fires an event in the container.
BOOL m_bNeedRepaint
Definition SHostWnd.h:329
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the WM_MOUSEWHEEL message.
void SetToolTip(LPCRECT rc, UINT tipAlign, LPCTSTR pszTip) OVERRIDE
Sets the tooltip for the container.
SList< IRunnable * > m_runnables
Definition SHostWnd.h:357
IToolTip * m_pTipCtrl
Definition SHostWnd.h:332
SAutoRefPtr< IRenderTarget > m_memRT
Definition SHostWnd.h:335
void _RestoreClickState()
Restores the click state of the window.
SHostWnd(LPCWSTR pszResName=NULL)
Constructs a SHostWnd object with an optional resource name.
Definition shostwnd.cpp:313
void OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
Handles the WM_COMMAND message.
void SetEventHandler(FunCallback fun, void *ctx) OVERRIDE
Sets the event handler for the host window.
virtual void OnUserXmlNode(SXmlNode xmlUser)
Handles user-defined XML node.
static void SetTaskQueueBufSize(int nBufSize)
Sets the buffer size for asynchronous task queues.
Definition shostwnd.cpp:308
LRESULT OnUpdateFont(UINT uMsg, WPARAM wp, LPARAM lp)
Handles the WM_UPDATEFONT message.
LRESULT OnRunTasks(UINT uMsg, WPARAM wp, LPARAM lp)
Handles the UM_RUN_TASKS message.
tid_t m_dwThreadID
Definition SHostWnd.h:350
HWND Create(HWND hWndParent, int x=0, int y=0, int nWidth=0, int nHeight=0) OVERRIDE
Creates the host window.
Definition shostwnd.cpp:402
void OnSize(UINT nType, CSize size)
Handles the WM_SIZE message.
Definition shostwnd.cpp:948
virtual BOOL _HandleEvent(IEvtArgs *pEvt)
Handles an event.
SCriticalSection m_cs
Definition SHostWnd.h:356
BOOL IsSendWheel2Hover() const OVERRIDE
Checks if wheel messages are sent to the hover window.
SAutoRefPtr< IAnimation > m_hostAnimation
Definition SHostWnd.h:347
friend class SNcPainter
Definition SHostWnd.h:321
void _PaintVideoCanvasForeground(IRenderTarget *pRT)
Paints the video canvas in the foreground.
void OnGetMinMaxInfo(LPMINMAXINFO lpMMI)
Handles the WM_GETMINMAXINFO message.
BOOL OnReleaseSwndCapture() OVERRIDE
Releases the capture from the container.
SAutoRefPtr< IRegionS > m_rgnInvalidate
Definition SHostWnd.h:334
SStringT m_strXmlLayout
Definition SHostWnd.h:326
CSize m_szAppSetted
Definition SHostWnd.h:342
void OnMouseLeave()
Handles the WM_MOUSELEAVE message.
Definition shostwnd.cpp:992
virtual void OnHostAnimationStarted(IAnimation *pAni)
Called when the host window animation starts.
void ShowHostWnd(int uShowCmd, BOOL bWaitAniDone) OVERRIDE
Shows the host window with optional animation.
CRect GetWindowRect() const
Gets the window rectangle.
SCriticalSection m_csRunningQueue
Definition SHostWnd.h:358
LRESULT OnMenuExEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles custom menu events.
void _ExcludeVideoCanvasFromPaint(IRenderTarget *pRT)
Excludes the video canvas from painting.
MSG m_msgMouse
Definition SHostWnd.h:341
void OnUpdateCursor() OVERRIDE
Updates the cursor for the container.
SRootWindow * m_pRoot
Definition SHostWnd.h:351
void UpdateAutoSizeCount(bool bInc)
Updates the auto-size count.
SWND OnSetSwndCapture(SWND swnd) OVERRIDE
Sets the capture to the specified window.
SAutoRefPtr< SNcPainter > m_pNcPainter
Definition SHostWnd.h:339
virtual SXmlNode OnGetInitXmlNode(SXmlDoc &xmlDoc)
Gets the initial XML node.
Definition shostwnd.cpp:827
int RemoveTasksForObject(void *pObj) OVERRIDE
Removes tasks for the specified object.
void SetPresenter(IHostPresenter *pPresenter) OVERRIDE
Sets the presenter for rendering.
void UpdateTooltip() OVERRIDE
Updates the tooltip for the container.
IHostPresenter * GetPresenter() OVERRIDE
Gets the presenter interface for rendering.
void OnWindowPosChanged(LPWINDOWPOS lpWndPos)
Handles the WM_WINDOWPOSCHANGED message.
BOOL UpdateWindow(BOOL bForce=TRUE) OVERRIDE
Updates the window.
int m_cEnableUiDefCount
Definition SHostWnd.h:337
BOOL DestroyWindow() OVERRIDE
Destroys the host window.
BOOL AnimateHostWindow(DWORD dwTime, DWORD dwFlags) OVERRIDE
Animates the host window.
SWindow * GetRoot() const
Gets the root window.
Definition SHostWnd.h:685
bool StartHostAnimation(IAnimation *pAni)
Starts an animation for the host window.
void SetScale(int nScale, LPCRECT pDestRect) OVERRIDE
Sets the scale factor for the host window.
void OnKillFocus(HWND wndFocus)
Handles the WM_KILLFOCUS message.
void UpdateRegion(IRegionS *rgn) OVERRIDE
Updates the specified region in the container.
void OnCaptureChanged(HWND wnd)
Handles the WM_CAPTURECHANGED message.
LRESULT OnSetLanguage(UINT uMsg, WPARAM wp, LPARAM lp)
Handles the WM_SETLANGUAGE message.
@ kPulseInterval
Definition SHostWnd.h:397
@ kTaskTimer
Definition SHostWnd.h:400
@ kTaskInterval
Definition SHostWnd.h:401
@ kPulseTimer
Definition SHostWnd.h:396
SHostWndAttr m_hostAttr
Definition SHostWnd.h:325
SAutoRefPtr< IScriptModule > m_pScriptModule
Definition SHostWnd.h:338
void OnPrint(HDC dc, UINT uFlags=0)
Handles the WM_PRINT message.
Definition shostwnd.cpp:761
void OnPaint(HDC dc)
Handles the WM_PAINT message.
Definition shostwnd.cpp:800
static int s_TaskQueueBufSize
Definition SHostWnd.h:362
static BOOL s_HideLocalUiDef
Definition SHostWnd.h:361
void EnableIME(BOOL bEnable) OVERRIDE
Enables or disables IME (Input Method Editor).
void EnablePrivateUiDef(BOOL bEnable) OVERRIDE
Enables or disables private UI definitions for the host window.
Definition shostwnd.cpp:424
friend class SRootWindow
Definition SHostWnd.h:320
virtual void DestroyTooltip(IToolTip *pTooltip) const
Destroys the specified tooltip.
Definition shostwnd.cpp:822
bool m_bResizing
Definition SHostWnd.h:345
HWND GetHostHwnd() OVERRIDE
Gets the handle to the host window.
void OnSetFocus(HWND wndOld)
Handles the WM_SETFOCUS message.
LPCWSTR GetTranslatorContext() const OVERRIDE
Gets the translator context for the container.
void GetContainerRect(RECT *ret) const OVERRIDE
Gets the rectangle of the container.
void OnMouseMove(UINT nFlags, CPoint point)
Handles the WM_MOUSEMOVE message.
Definition shostwnd.cpp:978
BOOL PostTask(IRunnable *runable, BOOL bAsync=TRUE) OVERRIDE
Posts a task to the container.
LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles mouse events.
virtual BOOL OnLoadLayoutFromResourceID(SXmlDoc &xmlDoc)
Loads the layout from a resource ID.
Definition shostwnd.cpp:833
int GetScale() const OVERRIDE
Gets the scale factor for the container.
void OnTimer(UINT_PTR idEvent)
Handles the WM_TIMER message.
SAutoRefPtr< IHostPresenter > m_presenter
Definition SHostWnd.h:354
void _SetToolTipInfo(const SwndToolTipInfo *info, BOOL bNcTip)
Sets tooltip information for the window.
BOOL m_bFirstShow
Definition SHostWnd.h:349
IScriptModule * GetScriptModule() OVERRIDE
Gets the script module for the container.
DWORD m_AniState
Definition SHostWnd.h:348
int OnCreate(LPCREATESTRUCT lpCreateStruct)
Handles the WM_CREATE message.
Definition shostwnd.cpp:848
bool StopHostAnimation()
Stops the current animation for the host window.
void _Redraw()
Redraws the entire window.
Definition shostwnd.cpp:718
SList< IRunnable * > m_runningQueue
Definition SHostWnd.h:359
IXmlNode * m_xmlInit
Definition SHostWnd.h:360
IMessageLoop * GetMsgLoop() OVERRIDE
Gets the message loop interface.
void OnActivate(UINT nState, BOOL bMinimized, HWND wndOther)
Handles the WM_ACTIVATE message.
INcPainter * GetNcPainter() OVERRIDE
Gets the non-client area painter for the host window.
Definition SHostWnd.h:495
friend class SDummyWnd
Definition SHostWnd.h:319
HWND CreateEx(HWND hWndParent, DWORD dwStyle, DWORD dwExStyle, int x, int y, int nWidth, int nHeight, IXmlNode *xmlInit=NULL) OVERRIDE
Creates the host window with extended styles.
Definition shostwnd.cpp:361
void OnWindowPosChanging(LPWINDOWPOS lpWndPos)
Handles the WM_WINDOWPOSCHANGING message.
int toPixelSize(int scale) const
将大小转换为像素值
The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructo...
Definition SMatrix.h:22
void postTranslate(float dx, float dy)
Post-concats the matrix with the specified translation.
Definition SMatrix.cpp:300
void preTranslate(float dx, float dy)
Pre-concats the matrix with the specified translation.
Definition SMatrix.cpp:274
bool mapRect(SRect *dst, const SRect &src) const
Apply this matrix to the src rectangle, and write the transformed rectangle into dst....
Definition SMatrix.cpp:1216
bool rectStaysRect() const
Returns true if the matrix will map a rectangle to another rectangle. This can be true if the matrix ...
Definition SMatrix.h:249
Class for managing native window operations.
Definition SNativeWnd.h:126
BOOL ScreenToClient(LPPOINT lpPoint) SCONST OVERRIDE
Converts screen coordinates to client coordinates.
HWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
BOOL GetWindowRect(LPRECT lpRect) SCONST OVERRIDE
Retrieves the window rectangle.
BOOL Invalidate(BOOL bErase=TRUE) OVERRIDE
Invalidates the entire window.
BOOL IsWindow() SCONST OVERRIDE
Checks if the handle is a valid window handle.
UINT_PTR SetTimer(UINT_PTR nIDEvent, UINT nElapse, void(CALLBACK *lpfnTimer)(HWND, UINT, UINT_PTR, DWORD)=NULL) OVERRIDE
Sets a timer for the window.
DWORD GetStyle() SCONST OVERRIDE
Retrieves the window style.
HWND GetParent() OVERRIDE
Retrieves the handle to the parent window.
HWND SetFocus() OVERRIDE
Sets the input focus to the window.
DWORD GetExStyle() SCONST OVERRIDE
Retrieves the extended window style.
BOOL ShowWindow(int nCmdShow) OVERRIDE
Sets the show state of the window.
BOOL KillTimer(UINT_PTR nIDEvent) OVERRIDE
Kills a timer for the window.
HWND m_hWnd
Handle to the window.
Definition SNativeWnd.h:744
BOOL GetClientRect(LPRECT lpRect) SCONST OVERRIDE
Retrieves the client rectangle.
HWND CreateNative(LPCTSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, int nID=0, LPVOID lpParam=0) OVERRIDE
Creates a native window.
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags) OVERRIDE
Sets the window position.
LRESULT DefWindowProc()
Calls the default window procedure.
BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase=TRUE) OVERRIDE
Invalidates a specified rectangle of the window.
BOOL DestroyWindow() OVERRIDE
Destroys the window.
static void updateSystemButton(SWindow *pRoot, UINT nResizeMode)
Updates system buttons in the non-client area.
int GetID() SCONST OVERRIDE
Retrieves the object's ID.
Definition Sobject.hpp:134
LPCWSTR GetName() SCONST OVERRIDE
Retrieves the object's name.
Definition Sobject.hpp:108
LPCWSTR GetObjectClass() SCONST OVERRIDE
Retrieves the object's class name.
Definition Sobject.hpp:211
static LPCWSTR GetClassName()
Definition Sobject.hpp:41
Helper class for painting.
Definition SWnd.h:178
SAutoRefPtr< IFontS > oldFont
Definition SWnd.h:185
COLORREF oldTextColor
Definition SWnd.h:186
size_t GetRawBufferSize(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Retrieves the size of the raw buffer for a resource.
BOOL GetRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) OVERRIDE
Retrieves the raw buffer for a resource.
virtual void OnAnimationInvalidate(IAnimation *pAni, bool bErase)
Called when an animation is invalidated.
Definition shostwnd.cpp:168
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Called before painting the window.
Definition shostwnd.cpp:202
SRootWindow(SHostWnd *pHostWnd)
Constructor for SRootWindow.
Definition shostwnd.cpp:160
virtual void OnScaleChanged(int scale)
Called when the scale changes.
Definition shostwnd.cpp:258
void OnAnimationStop(IAnimation *pAni) OVERRIDE
Called when an animation stops.
Definition shostwnd.cpp:182
SHostWnd * GetHostWnd() const
Gets the pointer to the host window.
Definition shostwnd.cpp:284
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Called after painting the window.
Definition shostwnd.cpp:219
void FireMenuCmd(int menuID)
Fires a menu command event.
Definition shostwnd.cpp:289
virtual HRESULT OnLanguageChanged()
Called when the language changes.
Definition shostwnd.cpp:251
void UpdateLayout() OVERRIDE
Updates the layout of the window.
Definition shostwnd.cpp:224
static SHostMgr * getSingletonPtr(void)
Definition SSingleton2.h:70
static SApplication & getSingleton(void)
Definition SSingleton.h:63
static SApplication * getSingletonPtr(void)
Definition SSingleton.h:73
static int GetDefIndex(DWORD dwState, bool checkAsPushdown=false)
Gets the default index for a given state.
A class representing an ASCII string.
Definition sstringa.h:96
int GetLength() SCONST
Retrieves the length of the string.
A class representing an ASCII string.
Definition sstringw.h:96
BOOL IsEmpty() SCONST
Checks if the string is empty.
int GetLength() SCONST
Retrieves the length of the string.
static uint64_t GetCurrentTimeMs()
获取当前时间的毫秒数
Definition stime.cpp:189
Structure representing a timer ID.
Definition SWnd.h:136
DWORD uTimerID
Definition SWnd.h:139
DWORD swnd
Definition SWnd.h:138
DWORD bSwndTimer
Definition SWnd.h:140
Defines the transformation to be applied at one point in time of an Animation.
BYTE GetAlpha() SCONST OVERRIDE
Gets the degree of transparency.
const SMatrix & getMatrix() const
Gets the 3x3 matrix representing the transformation.
bool hasAlpha() const
Checks if the transformation affects the alpha property.
static IUiDefInfo * CreateUiDefInfo()
Creates a new UI definition information object.
Definition SUiDef.cpp:649
Base class for SOUI DUI windows.
Definition SWnd.h:286
void StartAnimation(IAnimation *animation) OVERRIDE
Starts an animation for the window.
Definition Swnd.cpp:2549
virtual void OnAnimationInvalidate(IAnimation *pAni, bool bErase)
Called when an animation requires a redraw.
Definition Swnd.cpp:3381
UINT OnGetDlgCode() SCONST OVERRIDE
Retrieves the dialog code for the window.
Definition Swnd.cpp:1991
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
Definition Swnd.cpp:1540
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Retrieves the desired size of the window.
Definition Swnd.cpp:1839
SWND GetSwnd() SCONST OVERRIDE
Retrieves the window handle.
Definition Swnd.cpp:489
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handle tooltip updates.
Definition Swnd.cpp:277
SWindow * GetParent() const
Retrieves the parent window.
Definition Swnd.cpp:3488
DWORD GetState() SCONST OVERRIDE
Retrieves the current state of the window.
Definition Swnd.cpp:437
void OnAnimationStop(IAnimation *animation)
Called when an animation stops.
Definition Swnd.cpp:3362
SWND SwndFromPoint(POINT *pt, BOOL bIncludeMsgTransparent=FALSE) SCONST OVERRIDE
Retrieves the window handle at a specified point.
void GetClientRect(LPRECT prect) SCONST OVERRIDE
Retrieves the client rectangle of the window.
BOOL IsLayoutDirty() SCONST OVERRIDE
Checks if the layout is dirty.
Definition Swnd.cpp:3451
void SDispatchMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0) OVERRIDE
Dispatches a message to the window.
Definition Swnd.cpp:388
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
Definition Swnd.cpp:3266
void GetVisibleRect(LPRECT prect) SCONST OVERRIDE
Retrieves the visible rectangle of the window.
Definition Swnd.cpp:3636
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
Definition Swnd.cpp:646
void PaintForeground(IRenderTarget *pRT, LPRECT pRc, SWindow *pStartFrom=NULL)
Draws the foreground content of the window.
Definition Swnd.cpp:2694
virtual void OnScaleChanged(int scale)
Called when the scale of the window changes.
Definition Swnd.cpp:3271
BYTE GetAlpha() SCONST OVERRIDE
Retrieves the alpha value of the window.
Definition Swnd.cpp:2602
IAnimation * GetAnimation() SCONST OVERRIDE
Retrieves the animation object associated with the window.
Definition Swnd.cpp:2538
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
Definition Swnd.cpp:243
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 InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
Definition Swnd.cpp:1444
void UpdateLayout() OVERRIDE
Updates the layout of the window.
Definition Swnd.cpp:2251
virtual SStringW tr(const SStringW &strSrc) const
Translation function.
Definition Swnd.cpp:940
LayoutDirtyType m_layoutDirty
Definition SWnd.h:2618
SWindow()
Constructor.
Definition Swnd.cpp:104
virtual BOOL OnRelayout(const CRect &rcWnd)
Handles window position changes during layout updates.
Definition Swnd.cpp:1587
void ClearAnimation() OVERRIDE
Clears the animation for the window.
Definition Swnd.cpp:2559
ILayoutParam * GetLayoutParam() SCONST OVERRIDE
Retrieves the layout parameter object associated with the window.
Definition SWnd.h:405
SWindow * GetWindow(int uCode) const
Retrieves a window based on a given code.
Definition Swnd.cpp:3456
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
Definition SWnd.h:1290
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 GetWindowRect(LPRECT prect) SCONST OVERRIDE
Retrieves the bounding rectangle of the window.
BOOL InitFromXml(IXmlNode *pNode) OVERRIDE
Initializes the window from an XML node.
Definition Swnd.cpp:946
void Update(BOOL bForce=FALSE) OVERRIDE
Updates the window.
Definition Swnd.cpp:1430
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 attribute.
Definition SXml.h:20
const wchar_t * name() const
Gets the attribute name.
Definition SXml.cpp:85
const wchar_t * value() const
Gets the attribute value.
Definition SXml.cpp:90
Implementation of IXmlDoc.
Definition SXml.h:912
SXmlNode root() const
Retrieves the root node of the document.
Definition SXml.cpp:754
Class representing an XML node.
Definition SXml.h:352
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
Definition SXml.cpp:393
SXmlNode first_child() const
Gets the first child node of the node.
Definition SXml.cpp:383
SXmlAttr append_copy(const SXmlAttr &proto)
Adds a copy of the specified attribute.
Definition SXml.cpp:478
const wchar_t * name() const
Gets the name of the node.
Definition SXml.cpp:363
const wchar_t * child_value() const
Gets the child value of the current node.
Definition SXml.cpp:438
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
Definition SXml.cpp:428
int get_userdata() SCONST OVERRIDE
Gets user data for the node.
Definition SXml.cpp:275
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
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
Definition SXml.cpp:270
void BuildWndTreeZorder() OVERRIDE
Rebuilds the window tree's z-order.
STimerlineHandlerMgr m_timelineHandlerMgr
BOOL RegisterTimelineHandler(ITimelineHandler *pHandler) OVERRIDE
Registers a timeline handler.
SFocusManager m_focusMgr
BOOL RegisterDragDrop(SWND swnd, IDropTarget *pDropTarget) OVERRIDE
Registers a drop target for a window.
void SetRoot(SWindow *pRoot)
Sets the root window of the container.
void OnNextFrame() OVERRIDE
Called when the next frame is ready.
SList< SWND > m_lstVideoCanvas
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.
BOOL UnregisterTimelineHandler(ITimelineHandler *pHandler) OVERRIDE
Unregisters a timeline handler.
IDropTarget * GetDropTarget()
Retrieves the drop target.
Manages the style attributes of SOUI windows.
Definition SWndStyle.h:28
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
long AddRef() override
Increments the reference count.
long Release() override
Decrements the reference count and deletes the object if the count reaches zero.
Interface for handling idle time.
Definition SMsgLoop-i.h:29
Interface for message loops.
Definition SMsgLoop-i.h:42
BOOL AddIdleHandler(IIdleHandler *pIdleHandler) PURE
Adds an idle handler.
void Quit(int exitCode=0) PURE
Quits the message loop.
BOOL RemoveMessageFilter(IMsgFilter *pMessageFilter) PURE
Removes a message filter.
BOOL RemoveIdleHandler(IIdleHandler *pIdleHandler) PURE
Removes an idle handler.
BOOL AddMessageFilter(IMsgFilter *pMessageFilter) PURE
Adds a message filter.
HRESULT CreateMsgLoop(IMessageLoop **ppMsgLoop, IMessageLoop *pParentLoop=NULL) PURE
Creates a message loop.
long Release() PURE
Decreases the reference count.
Region object interface.
Definition SRender-i.h:792
BOOL IsEmpty() SCONST PURE
Checks if the region is empty.
void GetRgnBox(LPRECT lprect) SCONST PURE
Retrieves the bounding rectangle of the region.
void CombineRect(LPCRECT lprect, int nCombineMode) PURE
Combines a rectangle with the region.
Base class for all renderable objects.
Definition SRender-i.h:145
Interface for rendering target objects.
Definition SRender-i.h:1440
HRESULT BitBlt(LPCRECT pRcDest, IRenderTarget *pRTSour, int xSrc, int ySrc, DWORD dwRop=kSrcCopy) PURE
Performs a bit-block transfer (BitBlt) operation.
BOOL IsOffscreen() SCONST PURE
Check if the render target is offscreen.
HRESULT SelectObject(IRenderObj *pObj, IRenderObj **pOldObj=NULL) PURE
Selects a new rendering object and optionally retrieves the previous one.
HRESULT PushClipRect(LPCRECT pRect, UINT mode=RGN_AND) PURE
Push a rectangular clip region.
HRESULT SelectDefaultObject(OBJTYPE objType, IRenderObj **pOldObj=NULL) PURE
Resets the specified rendering object to its default state.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.
时间轴处理接口
Interface for Tooltip Objects.
Definition stooltip-i.h:61
Interface for UI definition information.
Definition SUiDef.h:35
virtual UINT Init2(IXmlNode *pNode, BOOL bGlobalDomain, IResProvider *pResProvider=NULL)=0
Initializes the UI definition from an XML node.
Interface for XML nodes.
Definition sxml-i.h:128
BOOL Empty() SCONST PURE
Checks if the node is empty.
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
Identifier for a tooltip.
Definition stooltip-i.h:27