soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SStylePool.cpp
1#include "souistd.h"
3
4SNSBEGIN
5
6//////////////////////////////////////////////////////////////////////////
7// SStylePool
8
9// Get style object from pool by class name
11{
12 if (!HasKey(strName))
13 return SXmlNode();
14 return GetKeyObject(strName);
15}
16
17// Load style-pool from xml tree
18BOOL SStylePool::Init(SXmlNode xmlStyleRoot)
19{
20 if (!xmlStyleRoot)
21 return FALSE;
22
23 xmlStyleRoot = m_xmlDoc.root().append_copy(xmlStyleRoot);
24
25 for (SXmlNode xmlChild = xmlStyleRoot.first_child(); xmlChild; xmlChild = xmlChild.next_sibling())
26 {
27 SStringW strClsName = xmlChild.name();
28 if (strClsName.CompareNoCase(L"class") == 0)
29 {
30 strClsName = xmlChild.attribute(L"name").value();
31 if (strClsName.IsEmpty())
32 continue;
33 xmlChild.remove_attribute(L"name"); //删除name属性,防止该属性被处理
34 }
35 SASSERT(!xmlChild.attribute(L"name"));
36 AddKeyObject(strClsName, xmlChild);
37 }
38
39 return TRUE;
40}
41
42/////////////////////////////////////////////////////////////////////
44{
45 if (!xmlNode)
46 return FALSE;
47 for (SXmlNode xmlChild = xmlNode.first_child(); xmlChild; xmlChild = xmlChild.next_sibling())
48 {
49 SStringW strTempName = xmlChild.name();
50 SXmlNode xmlNode = xmlChild.first_child();
51 SStringW strValue;
52 while (xmlNode)
53 {
54 SStringW strXml;
55 xmlNode.ToString(&strXml);
56 strValue += strXml;
57 xmlNode = xmlNode.next_sibling();
58 }
59 AddKeyObject(strTempName, strValue);
60 }
61 return TRUE;
62}
63
65{
66 SStringW strRet;
67 GetKeyObject(strName, strRet);
68 return strRet;
69}
70
71SNSEND
Style Pool Management.
bool GetKeyObject(const SStringW &key, SXmlNode &obj) const
Definition SCmnMap.h:65
bool AddKeyObject(const SStringW &key, const SXmlNode &obj)
Definition SCmnMap.h:94
bool HasKey(const SStringW &key) const
Definition SCmnMap.h:52
A class representing an ASCII string.
Definition sstringw.h:96
int CompareNoCase(const wchar_t *psz) SCONST
Compares the string with another string, ignoring case.
Definition sstringw.cpp:929
BOOL IsEmpty() SCONST
Checks if the string is empty.
SXmlNode GetStyle(const SStringW &strName)
Retrieves a style XML node by name.
BOOL Init(SXmlNode xmlNode)
Initializes the style pool from an XML node.
BOOL Init(SXmlNode xmlNode)
Initializes the template pool from an XML node.
SStringW GetTemplateString(const SStringW &strName) const
Retrieves a template string by name.
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
void ToString(IStringW *out) SCONST OVERRIDE
Converts the node to a string representation.
Definition SXml.cpp:238
SXmlNode root() const
Gets the root node of the DOM tree this node belongs to.
Definition SXml.cpp:418