soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SApp.cpp
1#include "souistd.h"
2#include "SApp.h"
3#include <core/SNativeWnd.h>
4#include "core/SWindowMgr.h"
5
6#include "res.mgr/SFontPool.h"
7#include "res.mgr/SUiDef.h"
8#include "res.mgr/SObjDefAttr.h"
9
10#include "helper/STimerGenerator.h"
11#include "helper/SAutoBuf.h"
12#include "helper/SToolTip.h"
13#include "helper/SAppDir.h"
14#include "helper/SwndFinder.h"
15#include "helper/SHostMgr.h"
16#include "event/SNotifyCenter.h"
17
18#include "control/SMessageBox.h"
19#include "helper/SplitString.h"
20
21#include "core/SSkin.h"
22#include "control/SouiCtrls.h"
23#include "layout/SouiLayout.h"
24#include "layout/SLinearLayout.h"
25#include "layout/SGridLayout.h"
26#include "animation/SInterpolatorImpl.h"
27#include "core/SWndAccessible.h"
28
29#include "msaa/SAccProxyWindow.h"
30#include "msaa/SAccProxyCmnCtrl.h"
31
32#include "animation/SAnimation.h"
33#include "animation/SAnimationSet.h"
34#include "animation/ScaleAnimation.h"
35#include "animation/SRotateAnimation.h"
36#include "animation/SAlphaAnimation.h"
37#include "animation/STranslateAnimation.h"
39#include "core/SHostPresenter.h"
40
41SNSBEGIN
42
43class SNullTranslator : public TObjRefImpl<ITranslatorMgr> {
44 public:
45 STDMETHOD_(BOOL, IsValid)(CTHIS) SCONST
46 {
47 return FALSE;
48 }
49
50 STDMETHOD_(void, SetLanguage)(THIS_ LPCWSTR strLang)
51 {
52 }
53 STDMETHOD_(void, SetLanguageA)(THIS_ LPCSTR strLang)
54 {
55 }
56 STDMETHOD_(void, GetLanguage)(THIS_ wchar_t szOut[TR_MAX_NAME_LEN]) SCONST
57 {
58 szOut[0] = 0;
59 }
60 STDMETHOD_(void, GetLanguageA)(THIS_ IStringA *out) SCONST
61 {
62 }
63
64 STDMETHOD_(BOOL, CreateTranslator)(THIS_ ITranslator **ppTranslator)
65 {
66 return FALSE;
67 }
68 STDMETHOD_(BOOL, InstallTranslator)(THIS_ ITranslator *ppTranslator)
69 {
70 return FALSE;
71 }
72 STDMETHOD_(BOOL, UninstallTranslator)(THIS_ REFGUID id)
73 {
74 return FALSE;
75 }
76 STDMETHOD_(int, tr)
77 (THIS_ const IStringW *strSrc, const IStringW *strCtx, wchar_t *pszOut, int nLen) SCONST
78 {
79 return 0;
80 }
81};
82
83class SDefToolTipFactory : public TObjRefImpl<IToolTipFactory> {
84 public:
85 STDMETHOD_(IToolTip *, CreateToolTip)(THIS_ HWND hHost) OVERRIDE
86 {
87 STipCtrl *pTipCtrl = new STipCtrl;
88 if (!pTipCtrl->Create())
89 {
90 delete pTipCtrl;
91 return NULL;
92 }
93 return pTipCtrl;
94 }
95
96 STDMETHOD_(void, DestroyToolTip)(THIS_ IToolTip *pToolTip) OVERRIDE
97 {
98 if (pToolTip)
99 {
100 STipCtrl *pTipCtrl = (STipCtrl *)pToolTip;
101 pTipCtrl->DestroyWindow();
102 }
103 }
104};
105
106class SDefMsgLoopFactory : public TObjRefImpl<IMsgLoopFactory> {
107 public:
108 STDMETHOD_(HRESULT, CreateMsgLoop)(THIS_ IMessageLoop **ppRet, IMessageLoop *pParentLoop) OVERRIDE
109 {
110 *ppRet = new SMessageLoop(pParentLoop);
111 return S_OK;
112 }
113};
114
116{
117 objFactory->TplRegisterFactory<SWindow>();
118 objFactory->TplRegisterFactory<SPanel>();
119 objFactory->TplRegisterFactory<SStatic>();
120 objFactory->TplRegisterFactory<SButton>();
121 objFactory->TplRegisterFactory<SImageWnd>();
122 objFactory->TplRegisterFactory<SProgress>();
123 objFactory->TplRegisterFactory<SImageButton>();
124 objFactory->TplRegisterFactory<SLine>();
125 objFactory->TplRegisterFactory<SCheckBox>();
126 objFactory->TplRegisterFactory<SIconWnd>();
127 objFactory->TplRegisterFactory<SRadioBox>();
128 objFactory->TplRegisterFactory<SRadioGroup>();
129 objFactory->TplRegisterFactory<SLink>();
130 objFactory->TplRegisterFactory<SGroup>();
131 objFactory->TplRegisterFactory<SAnimateImgWnd>();
132 objFactory->TplRegisterFactory<SScrollView>();
133 objFactory->TplRegisterFactory<SRealWnd>();
134 objFactory->TplRegisterFactory<SToggle>();
135 objFactory->TplRegisterFactory<STabCtrl>();
136 objFactory->TplRegisterFactory<STabPage>();
137
138 objFactory->TplRegisterFactory<SSplitPane>();
139 objFactory->TplRegisterFactory<SSplitWnd>();
140 objFactory->TplRegisterFactory<SSplitWnd_Col>();
141 objFactory->TplRegisterFactory<SSplitWnd_Row>();
142 objFactory->TplRegisterFactory<SSliderBar>();
143 objFactory->TplRegisterFactory<STreeCtrl>();
144 objFactory->TplRegisterFactory<SScrollBar>();
145 objFactory->TplRegisterFactory<SHeaderCtrl>();
146 objFactory->TplRegisterFactory<SListCtrl>();
147 objFactory->TplRegisterFactory<SListBox>();
148 objFactory->TplRegisterFactory<SHotKeyCtrl>();
149 objFactory->TplRegisterFactory<SSpinButtonCtrl>();
150 objFactory->TplRegisterFactory<SListView>();
151 objFactory->TplRegisterFactory<SMCListView>();
152 objFactory->TplRegisterFactory<STileView>();
153 objFactory->TplRegisterFactory<STreeView>();
154 objFactory->TplRegisterFactory<SCalendar>();
155 objFactory->TplRegisterFactory<SDateTimePicker>();
156 objFactory->TplRegisterFactory<SFrame>();
157 objFactory->TplRegisterFactory<SStackView>();
158 objFactory->TplRegisterFactory<SStackPage>();
159 objFactory->TplRegisterFactory<SRichEdit>();
160 objFactory->TplRegisterFactory<SEdit>();
161 objFactory->TplRegisterFactory<SComboEdit>();
162 objFactory->TplRegisterFactory<SComboBox>();
163 objFactory->TplRegisterFactory<SComboView>();
164 objFactory->TplRegisterFactory<SCaption>();
165 objFactory->TplRegisterFactory<SMenuBar>();
166 objFactory->TplRegisterFactory<SSwitch>();
167#if defined(_WIN32) && !defined(__MINGW32__)
168 objFactory->TplRegisterFactory<SActiveX>();
169#endif //_WIN32
170}
171
173{
174 objFactory->TplRegisterFactory<SSkinImgList>();
175 objFactory->TplRegisterFactory<SSkinImgCenter>();
176 objFactory->TplRegisterFactory<SSkinImgFrame>();
177 objFactory->TplRegisterFactory<SSkinImgFrame2>();
178 objFactory->TplRegisterFactory<SSkinButton>();
179 objFactory->TplRegisterFactory<SSkinGradation>();
180 objFactory->TplRegisterFactory<SSkinGradation2>();
181 objFactory->TplRegisterFactory<SSkinScrollbar>();
182 objFactory->TplRegisterFactory<SSkinColorRect>();
183 objFactory->TplRegisterFactory<SSkinShape>();
184 objFactory->TplRegisterFactory<SSKinGroup>();
185}
186
188{
189 objFactory->TplRegisterFactory<SouiLayout>();
190 objFactory->TplRegisterFactory<SLinearLayout>();
191 objFactory->TplRegisterFactory<SHBox>();
192 objFactory->TplRegisterFactory<SVBox>();
193 objFactory->TplRegisterFactory<SGridLayout>();
194}
195
208
227//////////////////////////////////////////////////////////////////////////
228// SApplication
229
230template <>
232
233SApplication::SApplication(IRenderFactory *pRendFactory, HINSTANCE hInst, LPCTSTR pszHostClassName, const ISystemObjectRegister &sysObjRegister, BOOL bImeApp)
234 : m_hInst(hInst)
235 , m_RenderFactory(pRendFactory)
236 , m_hMainWnd(NULL)
237 , m_cbCreateObj(NULL)
238 , m_cbCreateTaskLoop(NULL)
239{
240#ifdef _WIN32
241 SWndSurface::Init();
242#endif //_WIN32
243 SRichEdit::InitTextService();
244 SNativeWnd::InitWndClass(hInst, pszHostClassName, bImeApp);
245 memset(m_pSingletons, 0, sizeof(m_pSingletons));
247
248 m_translator.Attach(new SNullTranslator);
249 m_tooltipFactory.Attach(new SDefToolTipFactory);
250 m_msgLoopFactory.Attach(new SDefMsgLoopFactory);
251
252 SAppDir appDir(hInst);
253 m_strAppDir = appDir.AppDir();
254
256 GetMsgLoopFactory()->CreateMsgLoop(&pMsgLoop);
257 AddMsgLoop(pMsgLoop);
258 sysObjRegister.RegisterLayouts(this);
259 sysObjRegister.RegisterSkins(this);
260 sysObjRegister.RegisterWindows(this);
261 sysObjRegister.RegisterInterpolator(this);
262 sysObjRegister.RegisterAnimation(this);
263 sysObjRegister.RegisterValueAnimator(this);
264}
265
267{
270 SRichEdit::UninitTextService();
271}
272
274{
275 m_pSingletons[SUiDef::GetType()] = new SUiDef(m_RenderFactory);
276 m_pSingletons[SWindowMgr::GetType()] = new SWindowMgr();
277 m_pSingletons[STimerGenerator::GetType()] = new STimerGenerator();
278 m_pSingletons[SWindowFinder::GetType()] = new SWindowFinder();
279 m_pSingletons[SHostMgr::GetType()] = new SHostMgr();
280}
281
282#define DELETE_SINGLETON(x) \
283 delete (x *)m_pSingletons[x::GetType()]; \
284 m_pSingletons[x::GetType()] = NULL;
285
287{
288 if (m_pSingletons[SNotifyCenter::GetType()])
289 DELETE_SINGLETON(SNotifyCenter);
290
291 DELETE_SINGLETON(SHostMgr);
292 DELETE_SINGLETON(SWindowFinder);
293 DELETE_SINGLETON(SUiDef);
294 DELETE_SINGLETON(STimerGenerator);
295 DELETE_SINGLETON(SWindowMgr);
296}
297
298#ifdef _WIN32
299IAccProxy *SApplication::CreateAccProxy(IWindow *pWnd) const
300{
301#ifdef SOUI_ENABLE_ACC
302 if (pWnd->IsClass(SProgress::GetClassName()))
303 {
304 return new SAccProxyProgress(pWnd);
305 }
306 else if (pWnd->IsClass(SSliderBar::GetClassName()))
307 {
308 return new SAccProxySlideBar(pWnd);
309 }
310 else if (pWnd->IsClass(SButton::GetClassName()) || pWnd->IsClass(SImageButton::GetClassName()))
311 {
312 return new SAccProxyButton(pWnd);
313 }
314 else if (pWnd->IsClass(SComboBox::GetClassName()))
315 {
316 return new SAccProxyCombobox(pWnd);
317 }
318 else if (pWnd->IsClass(SRichEdit::GetClassName()))
319 {
320 return new SAccProxyEdit(pWnd);
321 }
322 else if (pWnd->IsClass(SCheckBox::GetClassName()))
323 {
324 return new SAccProxyCheckButton(pWnd);
325 }
326 else if (pWnd->IsClass(SRadioBox::GetClassName()))
327 {
328 return new SAccProxyRadioButton(pWnd);
329 }
330
331 return new SAccProxyWindow(pWnd);
332#else
333 return NULL;
334#endif // SOUI_ENABLE_ACC
335}
336
337IAccessible *SApplication::CreateAccessible(IWindow *pWnd) const
338{
339#ifdef SOUI_ENABLE_ACC
340 return new SAccessible(pWnd);
341#else
342 return NULL;
343#endif // SOUI_ENABLE_ACC
344}
345#endif
346
347void *SApplication::GetInnerSingleton(SingletonType nType)
348{
349 if (nType < 0 || nType >= SINGLETON_COUNT)
350 return NULL;
351 return m_pSingletons[nType];
352}
353
354BOOL SApplication::_LoadXmlDocment(LPCTSTR pszXmlName, LPCTSTR pszType, SXmlDoc &xmlDoc, IResProvider *pResProvider /* = NULL*/)
355{
356 SAutoBuf xmlBuf;
357 if (!LoadRawBuffer(pszType, pszXmlName, pResProvider, xmlBuf))
358 return FALSE;
359 xmlDoc.Reset();
360 bool bLoad = xmlDoc.load_buffer(xmlBuf, xmlBuf.size(), xml_parse_default, enc_auto);
361 if (!bLoad)
362 {
363 XmlParseResult result;
364 xmlDoc.GetParseResult(&result);
365 SStringA strMsg = SStringA().Format("parse xml error! xmlName=%s,desc=%s,offset=%d", S_CT2A(pszXmlName).c_str(), SXmlDoc::GetErrDesc(result.status), (int)result.offset);
366 SASSERT_MSGA(bLoad, strMsg);
367 }
368 return bLoad;
369}
370
372{
373 SXmlDoc *xmlDoc = new SXmlDoc;
374 BOOL bRet = LoadXmlDocment(*xmlDoc, strResId);
375 if (bRet)
376 {
377 return xmlDoc;
378 }
379 else
380 {
381 delete xmlDoc;
382 return NULL;
383 }
384}
385
386BOOL SApplication::LoadXmlDocment(SXmlDoc &xmlDoc, const SStringT &strResId, IResProvider *pResProvider /*=NULL*/)
387{
388 SStringTList strLst;
389 if (2 == ParseResID(strResId, strLst))
390 return _LoadXmlDocment(strLst[1], strLst[0], xmlDoc, pResProvider);
391 else
392 return _LoadXmlDocment(strResId, NULL, xmlDoc, pResProvider);
393}
394
395IAnimation *SApplication::LoadAnimation(LPCTSTR strResId)
396{
397 SXmlDoc xml;
398 if (!LoadXmlDocment(xml, strResId))
399 return NULL;
400 IAnimation *pRet = CreateAnimationByName(xml.root().first_child().name());
401 if (!pRet)
402 return NULL;
403 SXmlNode xmlNode = xml.root().first_child();
404 pRet->InitFromXml(&xmlNode);
405 return pRet;
406}
407
408IValueAnimator *SApplication::LoadValueAnimator(LPCTSTR strResId)
409{
410 SXmlDoc xml;
411 if (!LoadXmlDocment(xml, strResId))
412 return NULL;
413 IValueAnimator *pRet = CreateValueAnimatorByName(xml.root().first_child().name());
414 if (!pRet)
415 return NULL;
416 SXmlNode xmlNode = xml.root().first_child();
417 pRet->InitFromXml(&xmlNode);
418 return pRet;
419}
420
422{
423 if (!GetTranslator())
424 return NULL;
425 SXmlDoc xml;
426 if (!LoadXmlDocment(xml, strResId))
427 return NULL;
428 ITranslator *pRet = NULL;
429 if (!GetTranslator()->CreateTranslator(&pRet))
430 return NULL;
431 SXmlNode xmlNode = xml.root().child(L"language");
432 pRet->Load(&xmlNode, 1); // LD_XML==1
433 return pRet;
434}
435
437{
438 ITranslatorMgr *pTransMgr = GetTranslator();
439 if (!pTransMgr)
440 return FALSE;
441 if (!pTransMgr->InstallTranslator(trModule))
442 return FALSE;
443
444 SStringW strFontInfo;
445 trModule->getFontInfo(&strFontInfo);
446 if (!strFontInfo.IsEmpty())
447 {
448 GETUIDEF->SetDefFontInfo(strFontInfo);
449 }
451 return TRUE;
452}
453
454BOOL SApplication::UnnstallTranslator(THIS_ REFGUID langId)
455{
456 ITranslatorMgr *pTransMgr = GetTranslator();
457 if (!pTransMgr)
458 return FALSE;
459 return pTransMgr->UninstallTranslator(langId);
460}
461
463{
464 UINT uRet = 0;
465 AddResProvider(pResProvider, NULL);
466 // load system skins
467 {
468 SXmlDoc xmlDoc;
469 if (_LoadXmlDocment(_T("SYS_XML_SKIN"), _T("XML"), xmlDoc, pResProvider))
470 {
471 ISkinPool *p = GETUIDEF->GetBuiltinSkinPool();
472 SXmlNode xmlSkin = xmlDoc.root().child(L"skin");
473 p->LoadSkins(&xmlSkin);
474 }
475 else
476 {
477 uRet |= 0x01;
478 }
479 }
480 // load edit context menu
481 {
482 if (!SetEditCtxMenuTemplateResId(_T("XML:SYS_XML_EDITMENU"), pResProvider))
483 {
484 uRet |= 0x02;
485 }
486 }
487 // load messagebox template
488 {
489 if (!SetMessageBoxTemplateResId(_T("XML:SYS_XML_MSGBOX"), pResProvider))
490 {
491 uRet |= 0x04;
492 }
493 }
494 RemoveResProvider(pResProvider);
495 return uRet;
496}
497
498int SApplication::Run(HWND hMainWnd)
499{
500 m_hMainWnd = hMainWnd;
502 SASSERT(pMsgLoop);
503 int nRet = pMsgLoop->Run();
504 if (::IsWindow(m_hMainWnd))
505 {
506 DestroyWindow(m_hMainWnd);
507 }
508 return nRet;
509}
510
511void SApplication::Quit(int nCode)
512{
513 SAutoLock autoLock(m_cs);
514 SPOSITION pos = m_msgLoopMap.GetStartPosition();
515 while (pos)
516 {
517 IMessageLoop *pMsgLoop = m_msgLoopMap.GetNextValue(pos);
518 pMsgLoop->Quit(nCode);
519 }
520}
521
523{
524 return m_hInst;
525}
526
528{
529 m_translator = pTrans;
530}
531
536
537void SApplication::SetScriptFactory(IScriptFactory *pScriptFactory)
538{
539 m_pScriptFactory = pScriptFactory;
540}
541
542HRESULT SApplication::CreateScriptModule(IScriptModule **ppScriptModule)
543{
544 if (!m_pScriptFactory)
545 return E_FAIL;
546 return m_pScriptFactory->CreateScriptModule(ppScriptModule);
547}
548
553
555{
556 if (m_RenderFactory || !renderFac)
557 return FALSE;
558 m_RenderFactory = renderFac;
559 GETUIDEF->SetRenderFactory(renderFac);
560 return TRUE;
561}
562
564{
565 m_pRealWndHandler = pRealHandler;
566}
567
572
577
579{
580 m_tooltipFactory = pToolTipFac;
581}
582
584{
585 return m_hMainWnd;
586}
587
589{
590 m_msgLoopFactory = pMsgLoopFac;
593 m_msgLoopFactory->CreateMsgLoop(&pMsgLoop);
594 AddMsgLoop(pMsgLoop);
595 return TRUE;
596}
597
602
603void SApplication::InitXmlNamedID(const SNamedID::NAMEDVALUE *pNamedValue, int nCount, BOOL bSorted)
604{
605 m_namedID.Init2(pNamedValue, nCount, bSorted);
606}
607
608void SApplication::InitXmlNamedID(const LPCWSTR *pNames, const int *nIds, int nCount)
609{
610 m_namedID.Init3(pNames, nIds, nCount, TRUE);
611}
612
614{
615 return m_namedID.String2Value(str);
616}
617
618SStringW SApplication::tr(const SStringW &strSrc, const SStringW &strCtx) const
619{
620 int nRet = m_translator->tr(&strSrc, &strCtx, NULL, 0);
621 if (nRet == 0)
622 return strSrc;
623 SStringW strRet;
624 wchar_t *pBuf = strRet.GetBufferSetLength(nRet - 1);
625 m_translator->tr(&strSrc, &strCtx, pBuf, nRet);
626 strRet.ReleaseBuffer();
627 return strRet;
628}
629
630IWindow *SApplication::CreateWindowByName(LPCWSTR pszWndClass) const
631{ //支持使用类似button.ok这样的控件名来创建控件,对于这种格式自动应用button.ok为class属性.
632 SStringW strClsName = pszWndClass;
633 int nPos = strClsName.ReverseFind(L'.');
634 if (nPos != -1)
635 strClsName = strClsName.Left(nPos);
636 IWindow *pRet = (IWindow *)CreateObject(strClsName, Window);
637 if (pRet && nPos != -1)
638 {
639 pRet->SetAttribute(L"class", pszWndClass, TRUE);
640 }
641 return pRet;
642}
643
644ISkinObj *SApplication::CreateSkinByName(LPCWSTR pszSkinClass) const
645{
646 return (ISkinObj *)CreateObject(pszSkinClass, Skin);
647}
648
649IInterpolator *SApplication::CreateInterpolatorByName(LPCWSTR pszName) const
650{
651 return (IInterpolator *)CreateObject(pszName, Interpolator);
652}
653
654IAnimation *SApplication::CreateAnimationByName(LPCWSTR pszName) const
655{
656 return (IAnimation *)CreateObject(pszName, Animation);
657}
658
659IValueAnimator *SApplication::CreateValueAnimatorByName(LPCWSTR pszName) const
660{
661 return (IValueAnimator *)CreateObject(pszName, ValueAnimator);
662}
663
664void SApplication::SetLogManager(ILogMgr *pLogMgr)
665{
666 m_logManager = pLogMgr;
667}
668
670{
671 return m_logManager;
672}
673
675{
676 return m_strAppDir;
677}
678
679void SApplication::SetAppDir(const SStringT &strAppDir)
680{
681 m_strAppDir = strAppDir;
682}
683
685{
687}
688
689void SApplication::SetAttrStorageFactory(IAttrStorageFactory *pAttrStorageFactory)
690{
691 m_pAttrStroageFactory = pAttrStorageFactory;
692}
693
694BOOL SApplication::AddMsgLoop(IMessageLoop *pMsgLoop, BOOL bReplace)
695{
696 SAutoLock autoLock(m_cs);
697 SASSERT(pMsgLoop != NULL);
698 tid_t dwThreadID = ::GetCurrentThreadId();
699 if (m_msgLoopMap.Lookup(dwThreadID) != NULL && !bReplace)
700 return false; // in map yet
701
702 m_msgLoopMap[dwThreadID] = pMsgLoop;
703 return true;
704}
705
707{
708 SAutoLock autoLock(m_cs);
709 MsgLoopMap::CPair *p = m_msgLoopMap.Lookup(::GetCurrentThreadId());
710 if (!p)
711 {
712 return FALSE;
713 }
714 m_msgLoopMap.RemoveKey(p->m_key);
715 return TRUE;
716}
717
718IMessageLoop *SApplication::GetMsgLoop(tid_t dwThreadID /*= ::GetCurrentThreadId()*/) const
719{
720 SAutoLock autoLock(m_cs);
721 const MsgLoopMap::CPair *p = m_msgLoopMap.Lookup(dwThreadID);
722 if (!p)
723 return NULL;
724 return p->m_value;
725}
726
728{
729 return this;
730}
731
732void SApplication::EnableNotifyCenter(THIS_ BOOL bEnable, int interval)
733{
734 if (bEnable)
735 {
736 if (m_pSingletons[SINGLETON_NOTIFYCENTER])
737 return;
738 m_pSingletons[SINGLETON_NOTIFYCENTER] = new SNotifyCenter(interval);
739 }
740 else
741 {
742 if (m_pSingletons[SINGLETON_NOTIFYCENTER])
743 {
744 DELETE_SINGLETON(SNotifyCenter);
745 }
746 }
747}
748
749IObject *SApplication::CreateObject(LPCWSTR pszName, SObjectType nType) const
750{
751 if (m_cbCreateObj)
752 {
753 IObject *pRet = m_cbCreateObj(this, pszName, nType);
754 if (pRet)
755 {
756 return pRet;
757 }
758 }
759 SObjectInfo objInfo = ObjInfo_New(pszName, nType);
760 return SObjectFactoryMgr::CreateObject(objInfo);
761}
762
763void SApplication::SetCreateObjectCallback(THIS_ FunCreateObject cbCreateObj)
764{
765 m_cbCreateObj = cbCreateObj;
766}
767
768BOOL SApplication::RegisterObjFactory(THIS_ const IObjectFactory *objFac, BOOL bReplace)
769{
770 return RegisterFactory(objFac, bReplace);
771}
772
773BOOL SApplication::UnregisterObjFactory(THIS_ const IObjectFactory *objFac)
774{
775 return UnregisterFactory(objFac->GetObjectInfo());
776}
777
778void SApplication::SetDefaultFontInfo(THIS_ LPCWSTR pszFontInfo)
779{
780 GETUIDEF->SetDefFontInfo(pszFontInfo);
781}
782
783void SApplication::SetCreateTaskLoopCallback(THIS_ FunCrateTaskLoop cbCreateTaskLoop)
784{
785 m_cbCreateTaskLoop = cbCreateTaskLoop;
786}
787
788BOOL SApplication::CreateTaskLoop(THIS_ int nCount, Priority priority, BOOL bAutoStart)
789{
791 return FALSE;
792 if (!m_lstTaskLoop.IsEmpty())
793 return FALSE;
794 m_lstTaskLoop.SetCount(nCount);
795 for (int i = 0; i < nCount; i++)
796 {
798 if (bAutoStart && m_lstTaskLoop[i])
799 {
800 m_lstTaskLoop[i]->start(SStringA().Format("taskloop_%d", i).c_str(), priority);
801 }
802 }
803 return TRUE;
804}
805
806ITaskLoop *SApplication::GetTaskLoop(THIS_ int iTaskLoop)
807{
808 if (iTaskLoop >= 0 && iTaskLoop < (int)m_lstTaskLoop.GetCount())
809 {
810 return m_lstTaskLoop[iTaskLoop];
811 }
812 else
813 {
814 return NULL;
815 }
816}
817
819{
820 return m_xmlMessageBoxTemplate.root().child(L"soui");
821}
822
824{
825 return m_xmlEditCtxMenuTemplate.root().first_child();
826}
827
828BOOL SApplication::SetEditCtxMenuTemplateResId(THIS_ LPCTSTR resId, IResProvider *pResProvider)
829{
830 return LoadXmlDocment(m_xmlEditCtxMenuTemplate, resId, pResProvider);
831}
832
833BOOL SApplication::SetMessageBoxTemplateResId(THIS_ LPCTSTR resId, IResProvider *pResProvider)
834{
835 if (!LoadXmlDocment(m_xmlMessageBoxTemplate, resId, pResProvider))
836 return FALSE;
837 SXmlNode uiRoot = m_xmlMessageBoxTemplate.root().child(L"soui");
838 if (!uiRoot)
839 return FALSE;
840 if (!uiRoot.attribute(L"minSize").value()[0])
841 {
843 return FALSE;
844 }
845 return TRUE;
846}
847
848SNSEND
Header file for the SAutoBuf class, a smart buffer management class.
SOUI Font Management Module.
Interface and Implementation for Native Window Handling.
SNSBEGIN SOUI_EXP SObjectInfo ObjInfo_New(LPCWSTR name, int type, LPCWSTR alise=NULL)
Creates a new object information structure.
Skin Classes for SOUI.
Provides a simple timing engine for running animations which calculate animated values and set them o...
SOUI系统中的DUI窗口管理模块
An interpolator where the rate of change starts and ends slowly, accelerating in the middle.
An interpolator where the rate of change starts slow and accelerates.
Class for embedding ActiveX controls in SUI windows.
Definition SActiveX.h:17
An animation that controls the alpha level of an object.
动画图片窗口
Definition SCmnCtrl.h:524
Abstraction for an Animation that can be applied to Views, Surfaces, or other objects.
Definition SAnimation.h:67
Represents a group of Animations that should be played together.
An interpolator where the change starts backward before moving forward.
An interpolator where the change starts backward before moving forward and overshoots the target.
应用程序目录管理类
Definition SAppDir.h:10
const SStringT & AppDir()
获取应用程序目录路径
Definition SAppDir.cpp:23
SOUI Application.
Definition SApp.h:151
~SApplication(void)
Destructor for SApplication.
Definition SApp.cpp:266
SAutoRefPtr< IScriptFactory > m_pScriptFactory
Pointer to the script factory.
Definition SApp.h:731
void EnableNotifyCenter(BOOL bEnable, int interval=20) OVERRIDE
Enable or disable the notification center.
Definition SApp.cpp:732
virtual ISkinObj * CreateSkinByName(LPCWSTR pszSkinClass) const
Create a skin by name.
Definition SApp.cpp:644
int Str2ID(const SStringW &str)
Convert a string to an ID.
Definition SApp.cpp:613
ITaskLoop * GetTaskLoop(int iTaskLoop=0) OVERRIDE
Get a task loop by index.
Definition SApp.cpp:806
UINT LoadSystemNamedResource(IResProvider *pResProvider) OVERRIDE
Load system named resources.
Definition SApp.cpp:462
ITranslatorMgr * GetTranslator() OVERRIDE
Get the translator manager.
Definition SApp.cpp:532
virtual IInterpolator * CreateInterpolatorByName(LPCWSTR pszName) const
Create an interpolator by name.
Definition SApp.cpp:649
void Quit(int nCode) OVERRIDE
Quit the application.
Definition SApp.cpp:511
HMODULE m_hInst
Module handle.
Definition SApp.h:776
ITranslator * LoadTranslator(LPCTSTR strResId) OVERRIDE
Load a translator from a resource.
Definition SApp.cpp:421
BOOL UnnstallTranslator(REFGUID langId) OVERRIDE
Uninstall a translator by language ID.
Definition SApp.cpp:454
BOOL AddMsgLoop(IMessageLoop *pMsgLoop, BOOL bReplace=FALSE) OVERRIDE
Add a message loop.
Definition SApp.cpp:694
HWND m_hMainWnd
Handle to the main window.
Definition SApp.h:781
SAutoRefPtr< ITranslatorMgr > m_translator
Pointer to the translator manager.
Definition SApp.h:741
IMessageLoop * GetMsgLoop(tid_t tid=::GetCurrentThreadId()) SCONST OVERRIDE
Get the message loop for a specific thread.
Definition SApp.cpp:718
SApplication(IRenderFactory *pRendFactory, HINSTANCE hInst, LPCTSTR pszHostClassName=_T("SOUIHOST"), const ISystemObjectRegister &sysObjRegister=SObjectDefaultRegister(), BOOL bImeApp=FALSE)
Constructor for SApplication.
Definition SApp.cpp:233
SNamedID m_namedID
Named ID manager.
Definition SApp.h:766
IResProviderMgr * GetResProviderMgr() OVERRIDE
Get the resource provider manager.
Definition SApp.cpp:727
BOOL UnregisterObjFactory(const IObjectFactory *objFac) OVERRIDE
Unregister an object factory.
Definition SApp.cpp:773
SStringW tr(const SStringW &strSrc, const SStringW &strCtx) const
Translate a string with context.
Definition SApp.cpp:618
SXmlDoc m_xmlMessageBoxTemplate
XML document for the message box template.
Definition SApp.h:822
virtual IAnimation * CreateAnimationByName(LPCWSTR pszName) const
Create an animation by name.
Definition SApp.cpp:654
IAttrStorageFactory * GetAttrStorageFactory() OVERRIDE
Get the attribute storage factory.
Definition SApp.cpp:684
BOOL _LoadXmlDocment(LPCTSTR pszXmlName, LPCTSTR pszType, SXmlDoc &xmlDoc, IResProvider *pResProvider=NULL)
Loads an XML document from a resource.
Definition SApp.cpp:354
SXmlNode GetMessageBoxTemplate() const
Get the message box template XML node.
Definition SApp.cpp:818
SXmlNode GetEditCtxMenuTemplate() const
Get the edit context menu template XML node.
Definition SApp.cpp:823
void * m_pSingletons[SINGLETON_COUNT]
Array of singleton pointers.
Definition SApp.h:812
int Run(HWND hMainWnd) OVERRIDE
Run the application message loop.
Definition SApp.cpp:498
SStringT m_strAppDir
Application directory path.
Definition SApp.h:771
SAutoRefPtr< ILogMgr > m_logManager
Pointer to the log manager.
Definition SApp.h:756
void _CreateSingletons()
Creates and initializes all singletons required by the application.
Definition SApp.cpp:273
BOOL SetMessageBoxTemplateResId(LPCTSTR resId, IResProvider *pResProvider=NULL) OVERRIDE
Set the resource ID for the message box template.
Definition SApp.cpp:833
IToolTipFactory * GetToolTipFactory() OVERRIDE
Get the tooltip factory.
Definition SApp.cpp:573
void _DestroySingletons()
Destroys and cleans up all singletons used by the application.
Definition SApp.cpp:286
void * GetInnerSingleton(SingletonType nType) OVERRIDE
Get an inner singleton.
Definition SApp.cpp:347
BOOL SetEditCtxMenuTemplateResId(LPCTSTR resId, IResProvider *pResProvider=NULL) OVERRIDE
Set the resource ID for the edit context menu template.
Definition SApp.cpp:828
void SetCreateTaskLoopCallback(FunCrateTaskLoop cbCreateTaskLoop) OVERRIDE
Set the callback for creating task loops.
Definition SApp.cpp:783
SAutoRefPtr< IRealWndHandler > m_pRealWndHandler
Pointer to the real window handler.
Definition SApp.h:726
void SetCreateObjectCallback(FunCreateObject cbCreateObj) OVERRIDE
Set the callback for creating objects.
Definition SApp.cpp:763
SXmlDoc m_xmlEditCtxMenuTemplate
XML document for the edit context menu template.
Definition SApp.h:817
IMsgLoopFactory * GetMsgLoopFactory() OVERRIDE
Get the message loop factory.
Definition SApp.cpp:598
void SetAttrStorageFactory(IAttrStorageFactory *pAttrStorageFactory) OVERRIDE
Set the attribute storage factory.
Definition SApp.cpp:689
BOOL SetRenderFactory(IRenderFactory *renderFac) OVERRIDE
Set the render factory.
Definition SApp.cpp:554
HWND GetMainWnd() OVERRIDE
Get the main window handle.
Definition SApp.cpp:583
SCriticalSection m_cs
Critical section for thread-safe operations.
Definition SApp.h:786
FunCrateTaskLoop m_cbCreateTaskLoop
Callback function for creating task loops.
Definition SApp.h:802
BOOL RemoveMsgLoop() OVERRIDE
Remove the current message loop.
Definition SApp.cpp:706
BOOL CreateTaskLoop(int nCount, Priority priority, BOOL bAutoStart=TRUE) OVERRIDE
Create task loops.
Definition SApp.cpp:788
SAutoRefPtr< IToolTipFactory > m_tooltipFactory
Pointer to the tooltip factory.
Definition SApp.h:746
FunCreateObject m_cbCreateObj
Callback function for creating objects.
Definition SApp.h:797
void SetLogManager(ILogMgr *pLogMgr) OVERRIDE
Set the log manager.
Definition SApp.cpp:664
IValueAnimator * LoadValueAnimator(LPCTSTR strResId) OVERRIDE
Load a value animator from a resource.
Definition SApp.cpp:408
IXmlDoc * LoadXmlDocment(LPCTSTR strResId) OVERRIDE
Load an XML document from a resource.
Definition SApp.cpp:371
IRealWndHandler * GetRealWndHander() OVERRIDE
Get the real window handler.
Definition SApp.cpp:568
ILogMgr * GetLogManager() OVERRIDE
Get the log manager.
Definition SApp.cpp:669
virtual IWindow * CreateWindowByName(LPCWSTR pszWndClass) const
Create a window by name.
Definition SApp.cpp:630
IRenderFactory * GetRenderFactory() OVERRIDE
Get the render factory.
Definition SApp.cpp:549
void SetDefaultFontInfo(LPCWSTR pszFontInfo) OVERRIDE
Set the default font information.
Definition SApp.cpp:778
BOOL InstallTranslator(ITranslator *trModule) OVERRIDE
Install a translator.
Definition SApp.cpp:436
void SetAppDir(const SStringT &strAppDir)
Set the application directory.
Definition SApp.cpp:679
SAutoRefPtr< IMsgLoopFactory > m_msgLoopFactory
Pointer to the message loop factory.
Definition SApp.h:751
IObject * CreateObject(LPCWSTR pszName, SObjectType nType) SCONST OVERRIDE
Create an object by name and type.
Definition SApp.cpp:749
virtual IValueAnimator * CreateValueAnimatorByName(LPCWSTR pszName) const
Create a value animator by name.
Definition SApp.cpp:659
BOOL RegisterObjFactory(const IObjectFactory *objFac, BOOL bReplace=FALSE) OVERRIDE
Register an object factory.
Definition SApp.cpp:768
void SetScriptFactory(IScriptFactory *pScriptModule) OVERRIDE
Set the script factory.
Definition SApp.cpp:537
void SetToolTipFactory(IToolTipFactory *pToolTipFac) OVERRIDE
Set the tooltip factory.
Definition SApp.cpp:578
SArray< SAutoRefPtr< ITaskLoop > > m_lstTaskLoop
List of task loops.
Definition SApp.h:807
BOOL SetMsgLoopFactory(IMsgLoopFactory *pMsgLoopFac) OVERRIDE
Set the message loop factory.
Definition SApp.cpp:588
HRESULT CreateScriptModule(IScriptModule **ppScriptModule) OVERRIDE
Create a script module.
Definition SApp.cpp:542
SAutoRefPtr< IAttrStorageFactory > m_pAttrStroageFactory
Pointer to the attribute storage factory.
Definition SApp.h:761
void SetRealWndHandler(IRealWndHandler *pRealHandler) OVERRIDE
Set the real window handler.
Definition SApp.cpp:563
void InitXmlNamedID(const LPCWSTR *pNames, const int *nIds, int nCount) OVERRIDE
Initialize XML named IDs from arrays.
Definition SApp.cpp:608
void SetTranslator(ITranslatorMgr *pTrans) OVERRIDE
Set the translator manager.
Definition SApp.cpp:527
IAnimation * LoadAnimation(LPCTSTR strResId) OVERRIDE
Load an animation from a resource.
Definition SApp.cpp:395
SAutoRefPtr< IRenderFactory > m_RenderFactory
Pointer to the render factory.
Definition SApp.h:736
HMODULE GetModule() SCONST OVERRIDE
Get the module handle.
Definition SApp.cpp:522
SStringT GetAppDir() const
Get the application directory.
Definition SApp.cpp:674
A smart buffer management class that automatically handles memory allocation and deallocation.
Definition SAutoBuf.h:18
size_t size()
Returns the size of the managed buffer.
Definition SAutoBuf.cpp:35
Auto-lock class for managing critical sections.
Smart pointer class for managing COM-style reference-counted objects.
An interpolator where the change bounces at the end.
按钮控件类
Definition SCmnCtrl.h:196
Calendar Control Class.
Definition SCalendar.h:135
标题栏控件类
Definition SCaption.h:23
复选框控件类
Definition SCmnCtrl.h:880
Animator for COLORREF values.
Editable ComboBox Control.
Definition SComboBox.h:15
Edit Control Embedded in ComboBox.
Definition SComboBase.h:18
ComboBox Control with ListView.
Definition SComboView.h:14
An interpolator where the change repeats a specified number of cycles.
DateTime Picker Control.
An interpolator where the rate of change starts fast and decelerates.
Simple Edit Control.
Definition SEdit.h:13
Animator for float values.
Frame Control.
Definition SFrame.h:13
网格布局类
组控件
Definition SCmnCtrl.h:1378
水平线性布局类
Header Control.
Definition SHeaderCtrl.h:18
管理宿主窗口消息处理的单例类
Definition SHostMgr.h:12
void DispatchMessage(UINT uMsg, WPARAM wp=0, LPARAM lp=0)
分发消息到宿主窗口
Definition SHostMgr.cpp:28
HotKey Control.
Definition SHotKeyCtrl.h:18
图标控件
Definition SCmnCtrl.h:1027
图片按钮类
Definition SCmnCtrl.h:366
图片控件类
Definition SCmnCtrl.h:391
Animator for integer values.
线条控件
Definition SCmnCtrl.h:810
An interpolator where the rate of change is constant.
线性布局类
List Box Control.
Definition SListbox.h:38
List Control.
Definition SListCtrl.h:83
Multi-Column List View Control.
Definition SMCListView.h:18
Menu Bar Control.
Definition SMenuBar.h:21
static void InitWndClass(HINSTANCE hInst, LPCTSTR pszSimpleWndName, BOOL bImeWnd)
Initializes the window class.
BOOL DestroyWindow() OVERRIDE
Destroys the window.
通知中心类,管理事件的注册、注销和触发
void RegisterValueAnimator(SObjectFactoryMgr *objFactory) const
Register value animator objects into the object factory.
Definition SApp.cpp:218
void RegisterInterpolator(SObjectFactoryMgr *objFactory) const
Register interpolator objects into the object factory.
Definition SApp.cpp:196
void RegisterSkins(SObjectFactoryMgr *objFactory) const
Register skin objects into the object factory.
Definition SApp.cpp:172
void RegisterLayouts(SObjectFactoryMgr *objFactory) const
Register layout objects into the object factory.
Definition SApp.cpp:187
void RegisterWindows(SObjectFactoryMgr *objFactory) const
Register window objects into the object factory.
Definition SApp.cpp:115
void RegisterAnimation(SObjectFactoryMgr *objFactory) const
Register animation objects into the object factory.
Definition SApp.cpp:209
Manager for object factories.
BOOL UnregisterFactory(const SObjectInfo &objInfo)
Unregisters an object factory.
virtual IObject * CreateObject(const SObjectInfo &objInfo) const
Creates an object based on the given object information.
BOOL TplRegisterFactory()
Template method to register a factory for a specific object type.
BOOL RegisterFactory(const IObjectFactory *objFactory, BOOL bReplace=false)
Registers an object factory.
static LPCWSTR GetClassName()
Definition Sobject.hpp:41
An interpolator where the change overshoots the target and then comes back.
Panel with Scrollbar Support.
Definition SPanel.h:32
Animator for POINT values.
进度条类
Definition SCmnCtrl.h:671
单选框控件类
Definition SCmnCtrl.h:1086
单选按钮组控件
Definition SCmnCtrl.h:1264
Real Window Control.
Definition SRealWnd.h:22
Animator for RECT values.
void RemoveResProvider(IResProvider *pResProvider) OVERRIDE
Removes a resource provider.
void AddResProvider(IResProvider *pResProvider, LPCTSTR pszUidef=_T("uidef:xml_init")) OVERRIDE
Adds a resource provider with a specified UI definition.
void RemoveAll() OVERRIDE
Removes all resource providers.
BOOL LoadRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, IResProvider *pResProvider, SAutoBuf &buf)
Loads the raw buffer for a resource using a specified resource provider.
RichEdit Control.
Definition SRichEdit.h:31
An animation that controls the rotation of an object. This rotation takes place in the X-Y plane.
Represents a group of skins for different states.
Definition SSkin.h:1135
An animation that controls the scale of an object. You can specify the point to use for the center of...
Scrollbar control.
Definition SScrollbar.h:29
Scrollable Panel.
Definition SPanel.h:469
static SHostMgr * getSingletonPtr(void)
Definition SSingleton2.h:70
static T * ms_Singleton
Static pointer to the singleton instance.
Definition SSingleton.h:35
Animator for SIZE values.
Button Skin.
Definition SSkin.h:318
Color Rectangle Skin.
Definition SSkin.h:718
Enhanced Gradient Skin.
Definition SSkin.h:544
Gradient Skin.
Definition SSkin.h:410
Centered Image Skin.
Definition SSkin.h:195
Enhanced Image Frame Skin.
Definition SSkin.h:294
Image Frame Skin.
Definition SSkin.h:223
Image List Skin.
Definition SSkin.h:31
Scrollbar Skin.
Definition SSkin.h:637
滑块工具条
Definition SSliderBar.h:24
A spin button control class derived from TWindowProxy<ISpinButtonCtrl>.
A pane within a split window.
Definition SSplitWnd.h:26
A vertical split window.
Definition SSplitWnd.h:284
A horizontal split window.
Definition SSplitWnd.h:304
A split window that can contain multiple panes.
Definition SSplitWnd.h:69
A page within a stack view.
Definition SStackView.h:173
A stack view that can contain multiple pages.
Definition SStackView.h:229
静态文本控件类
Definition SCmnCtrl.h:27
A class representing an ASCII string.
Definition sstringa.h:96
BOOL __cdecl Format(HINSTANCE hInst, UINT nFormatID,...)
Formats a string using a format string and variable arguments.
Definition sstringa.cpp:534
A class representing an ASCII string.
Definition sstringw.h:96
void ReleaseBuffer(int nNewLength=-1)
Releases the buffer and sets the new length of the string.
Definition sstringw.cpp:426
BOOL IsEmpty() SCONST
Checks if the string is empty.
wchar_t * GetBufferSetLength(int nNewLength)
Retrieves a modifiable buffer for the string and sets the new length.
Definition sstringw.cpp:414
SStringW Left(int nCount) const
Extracts the leftmost part of the string.
Definition sstringw.cpp:879
int ReverseFind(wchar_t ch) SCONST
Finds the last occurrence of a character in the string.
Definition sstringw.cpp:542
A switch control class derived from SWindow.
Definition SSwitch.h:28
A tab control for managing multiple tab pages.
Definition STabCtrl.h:117
A tab page within a tab control.
Definition STabCtrl.h:28
A tile view control for displaying items in a grid layout.
Definition STileView.h:33
定时器生成器类,继承自单例映射类
BOOL Create()
创建提示控件
Definition SToolTip.cpp:31
Toggle控件
Definition SCmnCtrl.h:1319
An animation that controls the position of an object.
A tree control for displaying hierarchical data.
Definition STreeCtrl.h:104
Class representing a tree view control.
Definition STreeView.h:265
Manages UI definitions, including skins, styles, templates, gradients, and named values.
Definition SUiDef.h:139
垂直线性布局类
窗口查找器类,继承自单例类
Definition SwndFinder.h:122
Base class for SOUI DUI windows.
Definition SWnd.h:286
Manages DUI windows in the SOUI system.
Definition SWindowMgr.h:33
const wchar_t * value() const
Gets the attribute value.
Definition SXml.cpp:90
Implementation of IXmlDoc.
Definition SXml.h:912
static const char * GetErrDesc(XmlStatus status)
Retrieves the error description for a given XML status.
Definition SXml.cpp:759
void GetParseResult(XmlParseResult *pResult) SCONST OVERRIDE
Retrieves the result of the last parsing operation.
Definition SXml.cpp:684
SXmlNode root() const
Retrieves the root node of the document.
Definition SXml.cpp:754
void Reset() OVERRIDE
Resets the document, removing all nodes.
Definition SXml.cpp:697
bool load_buffer(const void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer.
Definition SXml.cpp:726
Class representing an XML node.
Definition SXml.h:352
SXmlNode first_child() const
Gets the first child node of the node.
Definition SXml.cpp:383
const wchar_t * name() const
Gets the name of the node.
Definition SXml.cpp:363
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
Definition SXml.cpp:428
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
Soui布局类
Definition SouiLayout.h:187
Template class implementing the IObjRef interface.
XmlStatus status
Parsing status (see XmlStatus).
Definition sxml-i.h:452
ptrdiff_t offset
Last parsed offset (in char_t units from the start of input data).
Definition sxml-i.h:457
Interface for message loops.
Definition SMsgLoop-i.h:42
void Quit(int exitCode=0) PURE
Quits the message loop.
Interface for creating message loops.
Definition SMsgLoop-i.h:181
HRESULT CreateMsgLoop(IMessageLoop **ppMsgLoop, IMessageLoop *pParentLoop=NULL) PURE
Creates a message loop.
Interface for handling real window operations.
RenderFactory object.
Definition SRender-i.h:2018
ResProvider对象
Interface for Skin Objects.
Definition SSkinobj-i.h:29
Interface for Tooltip Factory.
Definition stooltip-i.h:112
Language Translation Interface.
BOOL Load(LPVOID pData, UINT uType) PURE
Loads language translation data from a resource.
Language Translation Interface Manager.
BOOL InstallTranslator(ITranslator *ppTranslator) PURE
Installs a language translation object into the manager.
BOOL UninstallTranslator(REFGUID id) PURE
Uninstalls a language translation object from the manager.
Interface for XML Document.
Definition sxml-i.h:472