1#include "include/souistd.h"
2#include "res.mgr/SUiDef.h"
3#include "helper/SplitString.h"
8const static WCHAR KNodeUidef[] = L
"uidef";
9const static WCHAR KNodeDefUnit[] = L
"unit";
10const static WCHAR KNodeCaret[] = L
"caret";
11const static WCHAR KNodeDefFont[] = L
"deffont";
12const static WCHAR KNodeFont[] = L
"font";
13const static WCHAR KNodeColor[] = L
"color";
14const static WCHAR KNodeDim[] = L
"dim";
15const static WCHAR KNodeSkin[] = L
"skin";
16const static WCHAR KNodeString[] = L
"string";
17const static WCHAR KNodeStyle[] = L
"style";
18const static WCHAR KNodeTemplate[] = L
"template";
19const static WCHAR KNodeObjAttr[] = L
"objattr";
20const static WCHAR KNodeGradient[] = L
"gradient";
48 UINT Init(IResProvider *pResProvide, LPCTSTR pszUidef)
override;
49 UINT Init2(IXmlNode *pNode, BOOL bGlobalDomain, IResProvider *pResProvider = NULL)
override;
50 SSkinPool *GetSkinPool()
override;
51 SStylePool *GetStylePool()
override;
52 STemplatePool *GetTemplatePool()
override;
53 SGradientPool *GetGradientPool()
override;
54 SObjDefAttr *GetObjDefAttr()
override;
55 SNamedColor &GetNamedColor()
override;
56 SNamedString &GetNamedString()
override;
57 SNamedDimension &GetNamedDimension()
override;
58 SNamedFont &GetNamedFont()
override;
59 SStringW GetDefFontInfo()
override;
60 SXmlNode GetCaretInfo()
override;
63 SAutoRefPtr<SSkinPool> pSkinPool;
64 SAutoRefPtr<SStylePool> pStylePool;
65 SAutoRefPtr<SObjDefAttr> objDefAttr;
66 SAutoRefPtr<STemplatePool> templatePool;
67 SAutoRefPtr<SGradientPool> gradientPool;
68 SNamedColor namedColor;
69 SNamedString namedString;
70 SNamedDimension namedDim;
77UINT SUiDefInfo::Init(
IResProvider *pResProvider, LPCTSTR pszUidef)
80 SStringTList strUiDef;
81 if (2 != ParseResID(pszUidef, strUiDef))
83 SSLOGW() <<
"warning!!!! Add ResProvider Error.";
89 SSLOGW() <<
"warning!!!! uidef was not found in the specified resprovider";
97 pResProvider->
GetRawBuffer(strUiDef[0], strUiDef[1], strXml, dwSize);
99 bool bLoad = docInit.
load_buffer(strXml, strXml.
size(), xml_parse_default, enc_auto);
103 SSLOGD() <<
"warning!!! load uidef as xml document failed";
107 SXmlNode root = docInit.
root().
child(KNodeUidef,
false);
110 SSLOGD() <<
"warning!!! \"uidef\" element is not the root element of uidef xml";
114 bRet = Init2(&root, TRUE, pResProvider);
124 GETUIDEF->PushUiDefInfo(
this, TRUE);
126 SXmlNode root(pNode);
131 xmlUnit = root.
child(KNodeDefUnit);
136 if (unit != SLayoutSize::unknow)
137 SLayoutSize::defUnit = unit;
141 SXmlNode xmlCaretNode = root.
child(KNodeCaret);
147 xmlFont = root.
child(KNodeDefFont);
154 xmlFont = root.
child(KNodeFont);
158 if (!defFontInfo.IsEmpty())
160 if (SStringW(attr.
name()).CompareNoCase(L
"face") == 0)
162 defFontInfo += SStringW().Format(L
"face:\'%s\'", attr.
value());
165 defFontInfo += SStringW().Format(L
"%s:%s", attr.
name(), attr.
value());
172 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeObjAttr);
175 objDefAttr.Attach(
new SObjDefAttr);
176 objDefAttr->Init(nodeData);
185 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeString);
188 namedString.Init(nodeData);
197 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeColor);
200 namedColor.Init(nodeData);
209 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeGradient);
212 gradientPool.Attach(
new SGradientPool);
213 gradientPool->Init(nodeData);
215 uRet |= UDI_GRADIENT;
221 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeDim);
224 namedDim.Init(nodeData);
226 uRet |= UDI_DIMENSION;
232 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeFont);
235 namedFont.Init(nodeData);
243 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeSkin);
246 pSkinPool.Attach(
new SSkinPool(TRUE));
247 pSkinPool->LoadSkins(&nodeData);
255 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeStyle);
258 pStylePool.Attach(
new SStylePool);
259 pStylePool->Init(nodeData);
267 SXmlNode nodeData = GetSourceXmlNode(root, docData, pResProvider, KNodeTemplate);
270 templatePool.Attach(
new STemplatePool);
271 templatePool->Init(nodeData);
273 uRet |= UDI_TEMPLATE;
276 GETUIDEF->PopUiDefInfo(
this, TRUE);
311SStringW SUiDefInfo::GetDefFontInfo()
339 m_bulitinSkinPool.Attach(
new SSkinPool(TRUE));
340 m_lstSkinPools.AddTail(m_bulitinSkinPool);
341 m_bulitinSkinPool->AddRef();
348 SPOSITION pos = m_lstUiDefInfo.GetHeadPosition();
351 IObjRef *p = m_lstUiDefInfo.GetNext(pos);
354 m_lstUiDefInfo.RemoveAll();
355 m_defUiDefInfo = NULL;
358 SPOSITION pos = m_lstSkinPools.GetHeadPosition();
361 ISkinPool *p = m_lstSkinPools.GetNext(pos);
364 m_lstSkinPools.RemoveAll();
365 m_bulitinSkinPool = NULL;
372 UINT uRet = pRet->
Init(pResProvider, pszUiDef);
386 return m_defUiDefInfo;
395 SASSERT(m_lstUiDefInfo.GetHead() == m_defUiDefInfo);
396 IUiDefInfo *defUI = m_lstUiDefInfo.RemoveHead();
398 m_defUiDefInfo = NULL;
400 m_defUiDefInfo = pUiDefInfo;
402 m_lstUiDefInfo.AddHead(pUiDefInfo);
411 m_lstUiDefInfo.AddTail(pUiDefInfo);
424 if (m_lstUiDefInfo.IsEmpty())
426 pUiDefInfo = m_lstUiDefInfo.RemoveTail();
432 SPOSITION pos = m_lstUiDefInfo.Find(pUiDefInfo);
435 m_lstUiDefInfo.RemoveAt(pos);
444 if (pSkinPool == m_bulitinSkinPool)
446 m_lstSkinPools.AddTail(pSkinPool);
453 if (pSkinPool == m_bulitinSkinPool)
455 SPOSITION pos = m_lstSkinPools.Find(pSkinPool);
459 m_lstSkinPools.RemoveAt(pos);
460 pSkinPool->Release();
468 SPOSITION pos = m_lstSkinPools.GetTailPosition();
471 ISkinPool *pSkinPool = m_lstSkinPools.GetPrev(pos);
472 if (
ISkinObj *pSkin = pSkinPool->GetSkin(strSkinName, nScale))
479 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
482 IUiDefInfo *pUiInfo = m_lstUiDefInfo.GetPrev(pos);
493 if (wcscmp(strSkinName, L
"") != 0)
495 SSLOGW() << L
"GetSkin[" << strSkinName.
c_str() << L
"] Failed!";
500static const wchar_t *BUILDIN_SKIN_NAMES[] = {
501 L
"_skin.sys.checkbox", L
"_skin.sys.radio", L
"_skin.sys.focuscheckbox", L
"_skin.sys.focusradio", L
"_skin.sys.btn.normal", L
"_skin.sys.scrollbar", L
"_skin.sys.border", L
"_skin.sys.dropbtn", L
"_skin.sys.tree.toggle", L
"_skin.sys.tree.checkbox", L
"_skin.sys.tree.lines", L
"_skin.sys.tab.page", L
"_skin.sys.header", L
"_skin.sys.split.vert", L
"_skin.sys.split.horz", L
"_skin.sys.prog.bkgnd", L
"_skin.sys.prog.bar", L
"_skin.sys.vert.prog.bkgnd", L
"_skin.sys.vert.prog.bar", L
"_skin.sys.slider.thumb", L
"_skin.sys.btn.close", L
"_skin.sys.btn.minimize", L
"_skin.sys.btn.maxmize", L
"_skin.sys.btn.restore", L
"_skin.sys.menu.check", L
"_skin.sys.menu.sep", L
"_skin.sys.menu.arrow", L
"_skin.sys.menu.border", L
"_skin.sys.menu.skin", L
"_skin.sys.icons", L
"_skin.sys.wnd.bkgnd", L
"_skin.sys.btn.prev", L
"_skin.sys.btn.next", L
"_skin.sys.spin.down", L
"_skin.sys.spin.up", L
"_skin.sys.switch", L
"_skin.sys.switch_bg",
513 return m_bulitinSkinPool;
519 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
522 IUiDefInfo *pUiInfo = m_lstUiDefInfo.GetPrev(pos);
536 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
539 IUiDefInfo *pUiInfo = m_lstUiDefInfo.GetPrev(pos);
553 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
556 IUiDefInfo *pUiInfo = m_lstUiDefInfo.GetPrev(pos);
570 COLORREF cr = CR_INVALID;
571 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
574 IUiDefInfo *pUiDefInfo = m_lstUiDefInfo.GetPrev(pos);
591 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
594 IUiDefInfo *pUiDefInfo = m_lstUiDefInfo.GetPrev(pos);
612 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
615 IUiDefInfo *pUiDefInfo = m_lstUiDefInfo.GetPrev(pos);
632 SPOSITION pos = m_lstUiDefInfo.GetTailPosition();
635 IUiDefInfo *pUiDefInfo = m_lstUiDefInfo.GetPrev(pos);
651 return new SUiDefInfo();
Header file for the SAutoBuf class, a smart buffer management class.
char * Allocate(size_t nElements)
Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.
size_t size()
Returns the size of the managed buffer.
Auto-lock class for managing critical sections.
const FontInfo & _GetDefFontInfo() const
Get constant reference to default font information.
SFontPool(IRenderFactory *fac)
Constructor.
IFontPtr _GetFont(const SStringW &strFont, int scale)
Get IFontPtr corresponding to the specified description string.
void _SetDefFontInfo(const SStringW &strFontInfo)
Set default font description string.
Manages the mapping of gradient names to IGradient objects.
IGradient * GetGradient(const SStringW &strName)
Retrieves the gradient object by its name.
static SLayoutSize::Unit unitFromString(const SStringW &strUnit)
从字符串解析单位
BOOL Get(const SStringW &strValue, COLORREF &cr) const
Retrieves a color value by name, automatically converting named colors.
Manages named dimensions.
BOOL Get(const SStringW &strValue, SLayoutSize &ret) const
Retrieves a dimension value by name, automatically converting named dimensions.
BOOL Get(const SStringW &strValue, SStringW &ret) const
Retrieves a font value by name, automatically converting named fonts.
BOOL Get(const SStringW &strValue, SStringW &ret) const
Retrieves a string value by name, automatically converting named strings.
Class for managing default attributes of objects.
static SApplication * getSingletonPtr(void)
Manages the mapping of skin names to ISkinObj objects.
ISkinObj * GetSkin(LPCWSTR strSkinName, int nScale) OVERRIDE
Retrieves a skin object by name and scale.
A class representing an ASCII string.
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
BOOL IsEmpty() SCONST
Checks if the string is empty.
Manages the mapping of style names to XML nodes.
SXmlNode GetStyle(const SStringW &strName)
Retrieves a style XML node by name.
Manages the mapping of template names to template strings.
SStringW GetTemplateString(const SStringW &strName) const
Retrieves a template string by name.
FontInfo GetDefFontInfo() const
Retrieves the default font information.
SUiDef(IRenderFactory *fac)
Constructor.
void PushUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate=FALSE)
Pushes a new UI definition information object onto the stack.
IUiDefInfo * GetUiDef()
Retrieves the default UI definition.
SStringW GetTemplateString(const SStringW &strName)
Retrieves a template string by name.
IGradient * GetGradient(const SStringW &strName)
Retrieves a gradient object by name.
ISkinObj * GetSkin(const SStringW &strSkinName, int nScale)
Retrieves a skin object by name and scale.
static IUiDefInfo * CreateUiDefInfo()
Creates a new UI definition information object.
void SetUiDef(IUiDefInfo *pUiDefInfo, bool bUpdateDefFont)
Sets the default UI definition.
SXmlNode GetStyle(const SStringW &strName)
Retrieves a style XML node by name.
SLayoutSize GetLayoutSize(const SStringW &strSize)
Retrieves a layout size from a string name.
BOOL InitDefUiDef(IResProvider *pResProvider, LPCTSTR pszUiDef)
Initializes the default UI definition.
void SetDefFontInfo(const SStringW &strFontInfo)
Sets the default font information.
SStringW GetFontDesc(const SStringW &strFont)
Retrieves a font description from a string name.
SStringW GetString(const SStringW &strString)
Retrieves a string value from a string name.
ISkinObj * GetBuiltinSkin(SYS_SKIN uID, int nScale)
Retrieves a built-in skin object by ID and scale.
COLORREF GetColor(const SStringW &strColor)
Retrieves a color value from a string.
BOOL PopUiDefInfo(IUiDefInfo *pUiDefInfo, BOOL bPreivate=FALSE)
Pops a UI definition information object from the stack.
void PushSkinPool(ISkinPool *pSkinPool)
Pushes a new skin pool onto the stack.
IFontPtr GetFont(const SStringW &strFont, int scale)
Retrieves a font object by description and scale.
BOOL PopSkinPool(ISkinPool *pSkinPool)
Pops a skin pool from the stack.
static ISkinPool * CreateSkinPool(BOOL bAutoScale=TRUE)
Creates a new skin pool.
ISkinPool * GetBuiltinSkinPool()
Retrieves the built-in skin pool.
Class representing an XML attribute.
SXmlAttr next_attribute() const
Gets the next attribute in the attribute list of the parent node.
const wchar_t * name() const
Gets the attribute name.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
const wchar_t * value() const
Gets the attribute value.
Implementation of IXmlDoc.
SXmlNode root() const
Retrieves the root node of the document.
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.
Class representing an XML node.
SXmlAttr first_attribute() const
Gets the first attribute of the node.
SXmlAttr append_copy(const SXmlAttr &proto)
Adds a copy of the specified attribute.
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
SXmlNode root() const
Gets the root node of the DOM tree this node belongs to.
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
Template class implementing the IObjRef interface.
Font information structure.
Interface for reference counting.
long AddRef() PURE
Increases the reference count.
long Release() PURE
Decreases the reference count.
BOOL GetRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) PURE
获得资源内存块
size_t GetRawBufferSize(LPCTSTR pszType, LPCTSTR pszResName) PURE
获得资源数据大小
Interface for Skin Objects.
Interface for UI definition information.
virtual SSkinPool * GetSkinPool()=0
Retrieves the skin pool.
virtual SNamedString & GetNamedString()=0
Retrieves the named string manager.
virtual SNamedDimension & GetNamedDimension()=0
Retrieves the named dimension manager.
virtual UINT Init(IResProvider *pResProvider, LPCTSTR pszUidef)=0
Initializes the UI definition from a resource provider.
virtual SGradientPool * GetGradientPool()=0
Retrieves the gradient pool.
virtual STemplatePool * GetTemplatePool()=0
Retrieves the template pool.
virtual SStylePool * GetStylePool()=0
Retrieves the style pool.
virtual SNamedColor & GetNamedColor()=0
Retrieves the named color manager.
virtual SNamedFont & GetNamedFont()=0
Retrieves the named font manager.