MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / setXmlSource

Method setXmlSource

Source/UIComponents/CtrlrTextEditor.cpp:100–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void CtrlrTextEditor::setXmlSource (const String &xmlSource)
101{
102 ScopedPointer <XmlElement> xml (XmlDocument::parse(xmlSource).release());
103 if (xml)
104 {
105 forEachXmlChildElement (*xml, el)
106 {
107 if (el->hasTagName ("font"))
108 {
109 Font font;
110 font = el->hasAttribute("bold") ? font.withStyle (Font::bold) : font;
111 font = el->hasAttribute("italic") ? font.withStyle (Font::italic) : font;
112 font = el->hasAttribute("underline") ? font.withStyle (Font::underlined) : font;
113
114 font = el->hasAttribute("height") ? font.withHeight (el->getDoubleAttribute("height")) : font;
115
116 if (el->hasAttribute("name"))
117 {
118 if (el->getStringAttribute("name").startsWith(":"))
119 {
120 if (el->getStringAttribute("name") == ":Monospaced")
121 font.setTypefaceName (Font::getDefaultMonospacedFontName());
122 if (el->getStringAttribute("name") == ":Sans")
123 font.setTypefaceName (Font::getDefaultSansSerifFontName());
124 if (el->getStringAttribute("name") == ":Serif")
125 font.setTypefaceName (Font::getDefaultSerifFontName());
126 }
127 else
128 {
129 font.setTypefaceName (el->getStringAttribute("name"));
130 }
131 }
132
133 const Colour fgColour = Colour::fromString (el->hasAttribute("colour") ? el->getStringAttribute("colour") : "0xff000000");
134 const Colour bgColour = Colour::fromString (el->hasAttribute("background") ? el->getStringAttribute("background") : findColour (TextEditor::backgroundColourId).toString());
135
136 setFont (font);
137 setColour (TextEditor::textColourId, fgColour);
138 setColour (TextEditor::backgroundColourId, bgColour);
139
140 TextEditor::insertTextAtCaret (el->getAllSubText());
141 }
142
143 if (el->hasTagName("br"))
144 {
145 TextEditor::insertTextAtCaret ("\n");
146 }
147 }
148 }
149}

Callers 1

readOnlyMultilineMethod · 0.80

Calls 15

fromStringFunction · 0.85
hasTagNameMethod · 0.80
hasAttributeMethod · 0.80
withStyleMethod · 0.80
getDoubleAttributeMethod · 0.80
getStringAttributeMethod · 0.80
getAllSubTextMethod · 0.80
forEachXmlChildElementFunction · 0.50
setFontFunction · 0.50
setColourFunction · 0.50
releaseMethod · 0.45
withHeightMethod · 0.45

Tested by

no test coverage detected