UI.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "BaseUIElementFactory.h"
  25. #include "Cursor.h"
  26. #include "Font.h"
  27. #include "InputEvents.h"
  28. #include "Log.h"
  29. #include "Matrix4.h"
  30. #include "PixelShader.h"
  31. #include "Profiler.h"
  32. #include "Renderer.h"
  33. #include "RendererEvents.h"
  34. #include "RendererImpl.h"
  35. #include "ResourceCache.h"
  36. #include "StringUtils.h"
  37. #include "Texture2D.h"
  38. #include "UI.h"
  39. #include "UIEvents.h"
  40. #include "VertexShader.h"
  41. #include <algorithm>
  42. #include "DebugNew.h"
  43. static bool compareUIElements(const UIElement* lhs, const UIElement* rhs)
  44. {
  45. return lhs->getPriority() < rhs->getPriority();
  46. }
  47. UI::UI(Renderer* renderer, ResourceCache* cache) :
  48. mRenderer(renderer),
  49. mCache(cache),
  50. mMouseDrag(false),
  51. mMouseDragElement(0),
  52. mDefocusElement(0),
  53. mMouseButtons(0),
  54. mQualifiers(0)
  55. {
  56. if (!mRenderer)
  57. EXCEPTION("Null renderer for UI");
  58. if (!mCache)
  59. EXCEPTION("Null resource cache for UI");
  60. LOGINFO("UI created");
  61. mRootElement = new UIElement();
  62. mRootElement->setSize(mRenderer->getWidth(), mRenderer->getHeight());
  63. subscribeToEvent(EVENT_WINDOWRESIZED, EVENT_HANDLER(UI, handleWindowResized));
  64. subscribeToEvent(EVENT_MOUSEMOVE, EVENT_HANDLER(UI, handleMouseMove));
  65. subscribeToEvent(EVENT_MOUSEBUTTONDOWN, EVENT_HANDLER(UI, handleMouseButtonDown));
  66. subscribeToEvent(EVENT_MOUSEBUTTONUP, EVENT_HANDLER(UI, handleMouseButtonUp));
  67. subscribeToEvent(EVENT_MOUSEWHEEL, EVENT_HANDLER(UI, handleMouseWheel));
  68. subscribeToEvent(EVENT_KEYDOWN, EVENT_HANDLER(UI, handleKeyDown));
  69. subscribeToEvent(EVENT_CHAR, EVENT_HANDLER(UI, handleChar));
  70. mNoTextureVS = mCache->getResource<VertexShader>("Shaders/SM2/Basic_VCol.vs2");
  71. mDiffTextureVS = mCache->getResource<VertexShader>("Shaders/SM2/Basic_DiffVCol.vs2");
  72. mNoTexturePS = mCache->getResource<PixelShader>("Shaders/SM2/Basic_VCol.ps2");
  73. mDiffTexturePS = mCache->getResource<PixelShader>("Shaders/SM2/Basic_DiffVCol.ps2");
  74. mAlphaTexturePS = mCache->getResource<PixelShader>("Shaders/SM2/Basic_AlphaVCol.ps2");
  75. // Add the base element factory
  76. addElementFactory(new BaseUIElementFactory());
  77. }
  78. UI::~UI()
  79. {
  80. LOGINFO("UI shut down");
  81. }
  82. void UI::setCursor(Cursor* cursor)
  83. {
  84. // Remove old cursor (if any) and set new
  85. if (mCursor)
  86. {
  87. mRootElement->removeChild(mCursor);
  88. mCursor.reset();
  89. }
  90. if (cursor)
  91. {
  92. mRootElement->addChild(cursor);
  93. mCursor = cursor;
  94. IntVector2 pos = mCursor->getPosition();
  95. const IntVector2& rootSize = mRootElement->getSize();
  96. pos.mX = clamp(pos.mX, 0, rootSize.mX - 1);
  97. pos.mY = clamp(pos.mY, 0, rootSize.mY - 1);
  98. mCursor->setPosition(pos);
  99. }
  100. }
  101. void UI::setFocusElement(UIElement* element)
  102. {
  103. if (element)
  104. {
  105. // Return if already has focus
  106. if (element->hasFocus())
  107. return;
  108. // If element can not be focused, and does not reset the focus either, search toward the parent
  109. for (;;)
  110. {
  111. if (element->getFocusMode() != FM_NOTFOCUSABLE)
  112. break;
  113. element = element->getParent();
  114. // Return if did not find any parent element that changes the focus
  115. if (!element)
  116. return;
  117. }
  118. }
  119. std::vector<UIElement*> allChildren = mRootElement->getChildren(true);
  120. // Go through all elements to clear the old focus
  121. for (std::vector<UIElement*>::iterator i = allChildren.begin(); i != allChildren.end(); ++i)
  122. {
  123. UIElement* other = *i;
  124. if ((other != element) && (other->hasFocus()))
  125. other->setFocus(false);
  126. }
  127. if (element)
  128. element->setFocus(true);
  129. }
  130. void UI::clear()
  131. {
  132. mRootElement->removeAllChildren();
  133. if (mCursor)
  134. mRootElement->addChild(mCursor);
  135. }
  136. void UI::update(float timeStep)
  137. {
  138. PROFILE(UI_Update);
  139. // If device lost, do not perform update
  140. if (mRenderer->isDeviceLost())
  141. return;
  142. if ((mCursor) && (mCursor->isVisible()))
  143. {
  144. IntVector2 pos = mCursor->getPosition();
  145. UIElement* element = getElementAt(pos);
  146. if (element)
  147. {
  148. // If a drag is going on, transmit hover only to the element being dragged
  149. if ((!mMouseDragElement) || (mMouseDragElement == element))
  150. element->onHover(element->screenToElement(pos), pos, mMouseButtons, mQualifiers);
  151. }
  152. }
  153. // Defocus element now if should
  154. if (mDefocusElement)
  155. {
  156. // Do nothing if the focus element changed in the meanwhile
  157. if (mDefocusElement == getFocusElement())
  158. setFocusElement(0);
  159. mDefocusElement = 0;
  160. }
  161. {
  162. PROFILE(UI_UpdateElements);
  163. update(timeStep, mRootElement);
  164. }
  165. {
  166. PROFILE(UI_GetBatches);
  167. mBatches.clear();
  168. mQuads.clear();
  169. const IntVector2& rootSize = mRootElement->getSize();
  170. getBatches(mRootElement, IntRect(0, 0, rootSize.mX, rootSize.mY));
  171. }
  172. }
  173. void UI::render()
  174. {
  175. PROFILE(UI_Render);
  176. static const Vector2 scale(2.0f, -2.0f);
  177. static const Vector2 offset(-1.0f, 1.0f);
  178. Matrix4 projection;
  179. memset(&projection, 0, sizeof(projection));
  180. projection.m00 = scale.mX;
  181. projection.m03 = offset.mX;
  182. projection.m11 = scale.mY;
  183. projection.m13 = offset.mY;
  184. projection.m22 = 1.0f;
  185. projection.m23 = 0.0f;
  186. projection.m33 = 1.0f;
  187. mRenderer->resetRenderTargets();
  188. mRenderer->setCullMode(CULL_CCW);
  189. mRenderer->setDepthTest(CMP_ALWAYS);
  190. mRenderer->setDepthWrite(false);
  191. mRenderer->setFillMode(FILL_SOLID);
  192. mRenderer->setStencilTest(false);
  193. mRenderer->setVertexShaderConstant(getVSRegister(VSP_MODELVIEWPROJ), projection);
  194. mRenderer->setPixelShaderConstant(getPSRegister(PSP_MATDIFFCOLOR), Color(1.0f, 1.0f, 1.0f, 1.0f));
  195. PixelShader* ps = 0;
  196. VertexShader* vs = 0;
  197. for (unsigned i = 0; i < mBatches.size(); ++i)
  198. {
  199. // Choose shaders here so that UIBatch does not need to look up shaders each time
  200. if (!mBatches[i].mTexture)
  201. {
  202. ps = mNoTexturePS;
  203. vs = mNoTextureVS;
  204. }
  205. else
  206. {
  207. // If texture contains only an alpha channel, use the alpha pixel shader
  208. vs = mDiffTextureVS;
  209. if (mBatches[i].mTexture->getFormat() == D3DFMT_A8)
  210. ps = mAlphaTexturePS;
  211. else
  212. ps = mDiffTexturePS;
  213. }
  214. mBatches[i].draw(mRenderer, vs, ps);
  215. }
  216. }
  217. void UI::addElementFactory(UIElementFactory* factory)
  218. {
  219. if (!factory)
  220. return;
  221. mFactories.push_back(SharedPtr<UIElementFactory>(factory));
  222. }
  223. SharedPtr<UIElement> UI::createElement(ShortStringHash type, const std::string& name)
  224. {
  225. SharedPtr<UIElement> element;
  226. for (unsigned i = 0; i < mFactories.size(); ++i)
  227. {
  228. element = mFactories[i]->createElement(type, name);
  229. if (element)
  230. return element;
  231. }
  232. EXCEPTION("Could not create unknown UI element type " + toString(type));
  233. }
  234. SharedPtr<UIElement> UI::loadLayout(XMLFile* file, XMLFile* styleFile)
  235. {
  236. PROFILE(UI_LoadLayout);
  237. SharedPtr<UIElement> root;
  238. if (!file)
  239. {
  240. LOGERROR("Null UI layout XML file");
  241. return root;
  242. }
  243. LOGDEBUG("Loading UI layout " + file->getName());
  244. XMLElement rootElem = file->getRootElement("element");
  245. if (!rootElem)
  246. {
  247. LOGERROR("No root UI element in " + file->getName());
  248. return root;
  249. }
  250. root = createElement(ShortStringHash(rootElem.getString("type")), rootElem.getString("name"));
  251. // First set the base style from the style file if exists, then apply UI layout overrides
  252. if (styleFile)
  253. root->setStyleAuto(styleFile, mCache);
  254. root->setStyle(rootElem, mCache);
  255. // Load rest of the elements recursively
  256. loadLayout(root, rootElem, styleFile);
  257. return root;
  258. }
  259. UIElement* UI::getElementAt(const IntVector2& position, bool enabledOnly)
  260. {
  261. UIElement* result = 0;
  262. getElementAt(result, mRootElement, position, enabledOnly);
  263. return result;
  264. }
  265. UIElement* UI::getElementAt(int x, int y, bool enabledOnly)
  266. {
  267. UIElement* result = 0;
  268. getElementAt(result, mRootElement, IntVector2(x, y), enabledOnly);
  269. return result;
  270. }
  271. UIElement* UI::getFocusElement()
  272. {
  273. std::vector<UIElement*> allChildren = mRootElement->getChildren(true);
  274. for (std::vector<UIElement*>::iterator i = allChildren.begin(); i != allChildren.end(); ++i)
  275. {
  276. if ((*i)->hasFocus())
  277. return *i;
  278. }
  279. return 0;
  280. }
  281. IntVector2 UI::getCursorPosition()
  282. {
  283. if (!mCursor)
  284. return IntVector2::sZero;
  285. else
  286. return mCursor->getPosition();
  287. }
  288. void UI::update(float timeStep, UIElement* element)
  289. {
  290. element->update(timeStep);
  291. const std::vector<UIElement*> children = element->getChildren();
  292. for (std::vector<UIElement*>::const_iterator i = children.begin(); i != children.end(); ++i)
  293. update(timeStep, *i);
  294. }
  295. void UI::getBatches(UIElement* element, IntRect currentScissor)
  296. {
  297. // Set clipping scissor for child elements. No need to draw if zero size
  298. element->adjustScissor(currentScissor);
  299. if ((currentScissor.mLeft == currentScissor.mRight) || (currentScissor.mTop == currentScissor.mBottom))
  300. return;
  301. std::vector<UIElement*> children = element->getChildren();
  302. if (children.empty())
  303. return;
  304. std::sort(children.begin(), children.end(), compareUIElements);
  305. // For non-root elements draw all children of same priority before recursing into their children: assumption is that they have
  306. // same renderstate
  307. std::vector<UIElement*>::const_iterator i = children.begin();
  308. if (element != mRootElement)
  309. {
  310. std::vector<UIElement*>::const_iterator j = i;
  311. int currentPriority = children.front()->getPriority();
  312. while (i != children.end())
  313. {
  314. while ((j != children.end()) && ((*j)->getPriority() == currentPriority))
  315. {
  316. if ((*j)->isVisible())
  317. (*j)->getBatches(mBatches, mQuads, currentScissor);
  318. ++j;
  319. }
  320. // Now recurse into the children
  321. while (i != j)
  322. {
  323. if ((*i)->isVisible())
  324. getBatches(*i, currentScissor);
  325. ++i;
  326. }
  327. if (i != children.end())
  328. currentPriority = (*i)->getPriority();
  329. }
  330. }
  331. // On the root level draw each element and its children immediately after to avoid artifacts
  332. else
  333. {
  334. while (i != children.end())
  335. {
  336. if ((*i)->isVisible())
  337. {
  338. (*i)->getBatches(mBatches, mQuads, currentScissor);
  339. getBatches(*i, currentScissor);
  340. }
  341. ++i;
  342. }
  343. }
  344. }
  345. void UI::getElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool enabledOnly)
  346. {
  347. if (!current)
  348. return;
  349. // Get children from lowest priority to highest
  350. std::vector<UIElement*> children = current->getChildren(false);
  351. std::sort(children.begin(), children.end(), compareUIElements);
  352. for (std::vector<UIElement*>::const_iterator i = children.begin(); i != children.end(); ++i)
  353. {
  354. UIElement* element = *i;
  355. if ((element != mCursor.getPtr()) && (element->isVisible()))
  356. {
  357. if (element->isInside(position, true))
  358. {
  359. // Store the current result, then recurse into its children. Because children
  360. // are sorted from lowest to highest priority, we should be left with the topmost match
  361. if ((element->isEnabled()) || (!enabledOnly))
  362. result = element;
  363. }
  364. if (element->isInsideCombined(position, true))
  365. getElementAt(result, element, position, enabledOnly);
  366. }
  367. }
  368. }
  369. UIElement* UI::verifyElement(UIElement* element)
  370. {
  371. std::vector<UIElement*> allChildren = mRootElement->getChildren(true);
  372. for (std::vector<UIElement*>::iterator i = allChildren.begin(); i != allChildren.end(); ++i)
  373. {
  374. if ((*i) == element)
  375. return *i;
  376. }
  377. return 0;
  378. }
  379. void UI::handleWindowResized(StringHash eventType, VariantMap& eventData)
  380. {
  381. using namespace WindowResized;
  382. mRootElement->setSize(eventData[P_WIDTH].getInt(), eventData[P_HEIGHT].getInt());
  383. }
  384. void UI::handleMouseMove(StringHash eventType, VariantMap& eventData)
  385. {
  386. using namespace MouseMove;
  387. mMouseButtons = eventData[P_BUTTONS].getInt();
  388. mQualifiers = eventData[P_QUALIFIERS].getInt();
  389. if ((mCursor) && (mCursor->isVisible()))
  390. {
  391. IntVector2 pos = mCursor->getPosition();
  392. pos.mX += eventData[P_X].getInt();
  393. pos.mY += eventData[P_Y].getInt();
  394. const IntVector2& rootSize = mRootElement->getSize();
  395. pos.mX = clamp(pos.mX, 0, rootSize.mX - 1);
  396. pos.mY = clamp(pos.mY, 0, rootSize.mY - 1);
  397. mCursor->setPosition(pos);
  398. if ((mMouseDrag) && (mMouseButtons))
  399. {
  400. UIElement* element = verifyElement(mMouseDragElement);
  401. if ((element) && (element->isEnabled()) && (element->isVisible()))
  402. element->onDragMove(element->screenToElement(pos), pos, mMouseButtons, mQualifiers);
  403. else
  404. {
  405. mMouseDrag = false;
  406. mMouseDragElement = 0;
  407. }
  408. }
  409. }
  410. }
  411. void UI::handleMouseButtonDown(StringHash eventType, VariantMap& eventData)
  412. {
  413. mMouseButtons = eventData[MouseButtonDown::P_BUTTONS].getInt();
  414. mQualifiers = eventData[MouseButtonDown::P_QUALIFIERS].getInt();
  415. int button = eventData[MouseButtonDown::P_BUTTON].getInt();
  416. if ((mCursor) && (mCursor->isVisible()))
  417. {
  418. IntVector2 pos = mCursor->getPosition();
  419. WeakPtr<UIElement> element(getElementAt(pos));
  420. // First send global click event, with or without an element
  421. using namespace UIMouseClick;
  422. VariantMap eventData;
  423. eventData[UIMouseClick::P_ELEMENT] = (void*)element.getPtr();
  424. eventData[UIMouseClick::P_X] = pos.mX;
  425. eventData[UIMouseClick::P_Y] = pos.mY;
  426. eventData[UIMouseClick::P_BUTTON] = button;
  427. eventData[UIMouseClick::P_BUTTONS] = mMouseButtons;
  428. eventData[UIMouseClick::P_QUALIFIERS] = mQualifiers;
  429. sendEvent(EVENT_UIMOUSECLICK, eventData);
  430. if (element)
  431. {
  432. // Handle focusing & bringing to front
  433. if (button == MOUSEB_LEFT)
  434. {
  435. setFocusElement(element);
  436. // Must check the pointer after each operation, because any UI event may trigger its destruction
  437. if (element)
  438. element->bringToFront();
  439. }
  440. // Handle click
  441. if (element)
  442. element->onClick(element->screenToElement(pos), pos, mMouseButtons, mQualifiers);
  443. // Handle start of drag
  444. if ((element) && (!mMouseDrag))
  445. {
  446. mMouseDrag = true;
  447. mMouseDragElement = element;
  448. element->onDragStart(element->screenToElement(pos), pos, mMouseButtons, mQualifiers);
  449. }
  450. }
  451. else
  452. {
  453. // If clicked over no element, or a disabled element, try to lose focus
  454. mDefocusElement = getFocusElement();
  455. }
  456. }
  457. }
  458. void UI::handleMouseButtonUp(StringHash eventType, VariantMap& eventData)
  459. {
  460. using namespace MouseButtonUp;
  461. mMouseButtons = eventData[P_BUTTONS].getInt();
  462. mQualifiers = eventData[P_QUALIFIERS].getInt();
  463. if ((mCursor) && (mCursor->isVisible()))
  464. {
  465. IntVector2 pos = mCursor->getPosition();
  466. if ((mMouseDrag) && (!mMouseButtons))
  467. {
  468. UIElement* element = verifyElement(mMouseDragElement);
  469. if ((element) && (element->isEnabled()) && (element->isVisible()))
  470. element->onDragEnd(element->screenToElement(pos), pos);
  471. mMouseDrag = false;
  472. mMouseDragElement = 0;
  473. }
  474. }
  475. }
  476. void UI::handleMouseWheel(StringHash eventType, VariantMap& eventData)
  477. {
  478. using namespace MouseWheel;
  479. mMouseButtons = eventData[P_BUTTONS].getInt();
  480. mQualifiers = eventData[P_QUALIFIERS].getInt();
  481. int delta = eventData[P_WHEEL].getInt();
  482. UIElement* element = getFocusElement();
  483. if (element)
  484. element->onWheel(delta, mMouseButtons, mQualifiers);
  485. }
  486. void UI::handleKeyDown(StringHash eventType, VariantMap& eventData)
  487. {
  488. using namespace KeyDown;
  489. mMouseButtons = eventData[P_BUTTONS].getInt();
  490. mQualifiers = eventData[P_QUALIFIERS].getInt();
  491. int key = eventData[P_KEY].getInt();
  492. UIElement* element = getFocusElement();
  493. if (element)
  494. {
  495. // Switch focus between focusable elements in the same top level window
  496. if (key == KEY_TAB)
  497. {
  498. UIElement* topLevel = element->getParent();
  499. while ((topLevel) && (topLevel->getParent() != mRootElement))
  500. topLevel = topLevel->getParent();
  501. if (topLevel)
  502. {
  503. std::vector<UIElement*> children = topLevel->getChildren(true);
  504. for (std::vector<UIElement*>::iterator i = children.begin(); i != children.end();)
  505. {
  506. if ((*i)->getFocusMode() < FM_FOCUSABLE)
  507. i = children.erase(i);
  508. else
  509. ++i;
  510. }
  511. for (unsigned i = 0; i < children.size(); ++i)
  512. {
  513. if (children[i] == element)
  514. {
  515. UIElement* next = children[(i + 1) % children.size()];
  516. setFocusElement(next);
  517. return;
  518. }
  519. }
  520. }
  521. }
  522. // Defocus the element
  523. else if ((key == KEY_ESC) && (element->getFocusMode() == FM_FOCUSABLE_DEFOCUSABLE))
  524. mDefocusElement = element;
  525. // If none of the special keys, pass the key to the focused element
  526. else
  527. element->onKey(key, mMouseButtons, mQualifiers);
  528. }
  529. }
  530. void UI::handleChar(StringHash eventType, VariantMap& eventData)
  531. {
  532. using namespace Char;
  533. mMouseButtons = eventData[P_BUTTONS].getInt();
  534. mQualifiers = eventData[P_QUALIFIERS].getInt();
  535. UIElement* element = getFocusElement();
  536. if (element)
  537. element->onChar(eventData[P_CHAR].getInt(), mMouseButtons, mQualifiers);
  538. }
  539. void UI::loadLayout(UIElement* current, const XMLElement& elem, XMLFile* styleFile)
  540. {
  541. XMLElement childElem = elem.getChildElement("element");
  542. while (childElem)
  543. {
  544. // Create and add to the hierarchy
  545. SharedPtr<UIElement> child = createElement(ShortStringHash(childElem.getString("type")), childElem.getString("name"));
  546. current->addChild(child);
  547. // First set the base style from the style file if exists, then apply UI layout overrides
  548. if (styleFile)
  549. child->setStyleAuto(styleFile, mCache);
  550. child->setStyle(childElem, mCache);
  551. // Load the children recursively
  552. loadLayout(child, childElem, styleFile);
  553. childElem = childElem.getNextElement("element");
  554. }
  555. }