Otclient  14/8/2020
uiwidget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "uiwidget.h"
24 #include "uimanager.h"
25 #include "uianchorlayout.h"
26 #include "uitranslator.h"
27 
35 
37 {
39  m_states = Fw::DefaultState;
42  m_autoRepeatDelay = 500;
43 
44  initBaseStyle();
45  initText();
46  initImage();
47 }
48 
50 {
51 #ifndef NDEBUG
52  assert(!g_app.isTerminated());
53  if(!m_destroyed)
54  g_logger.warning(stdext::format("widget '%s' was not explicitly destroyed", m_id));
55 #endif
56 }
57 
58 void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
59 {
60  Rect oldClipRect;
61  if(m_clipping) {
62  oldClipRect = g_painter->getClipRect();
63  g_painter->setClipRect(visibleRect);
64  }
65 
66  if(m_rotation != 0.0f) {
68  g_painter->rotate(m_rect.center(), m_rotation * (Fw::pi / 180.0));
69  }
70 
71  drawSelf(drawPane);
72 
73  if(!m_children.empty()) {
74  if(m_clipping)
76 
77  drawChildren(visibleRect, drawPane);
78  }
79 
80  if(m_rotation != 0.0f)
82 
83  if(m_clipping) {
84  g_painter->setClipRect(oldClipRect);
85  }
86 }
87 
89 {
90  if((drawPane & Fw::ForegroundPane) == 0)
91  return;
92 
93  // draw style components in order
94  if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
95  Rect backgroundDestRect = m_rect;
98  }
99 
100  drawImage(m_rect);
101  drawIcon(m_rect);
102  drawText(m_rect);
104 }
105 
106 void UIWidget::drawChildren(const Rect& visibleRect, Fw::DrawPane drawPane)
107 {
108  // draw children
109  for(const UIWidgetPtr& child : m_children) {
110  // render only visible children with a valid rect inside parent rect
111  if(!child->isExplicitlyVisible() || !child->getRect().isValid() || child->getOpacity() < Fw::MIN_ALPHA)
112  continue;
113 
114  Rect childVisibleRect = visibleRect.intersection(child->getRect());
115  if(!childVisibleRect.isValid())
116  continue;
117 
118  // store current graphics opacity
119  float oldOpacity = g_painter->getOpacity();
120 
121  // decrease to self opacity
122  if(child->getOpacity() < oldOpacity)
123  g_painter->setOpacity(child->getOpacity());
124 
125  child->draw(childVisibleRect, drawPane);
126 
127  // debug draw box
128  if(g_ui.isDrawingDebugBoxes() && drawPane & Fw::ForegroundPane) {
130  g_painter->drawBoundingRect(child->getRect());
131  }
132  //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Color::red);
133 
134  g_painter->setOpacity(oldOpacity);
135  }
136 }
137 
138 void UIWidget::addChild(const UIWidgetPtr& child)
139 {
140  if(!child) {
141  g_logger.traceWarning("attempt to add a null child into a UIWidget");
142  return;
143  }
144 
145  if(child->isDestroyed()) {
146  g_logger.traceWarning("attemp to add a destroyed child into a UIWidget");
147  return;
148  }
149 
150  if(hasChild(child)) {
151  g_logger.traceWarning("attempt to add a child again into a UIWidget");
152  return;
153  }
154 
155  UIWidgetPtr oldLastChild = getLastChild();
156 
157  m_children.push_back(child);
158  child->setParent(static_self_cast<UIWidget>());
159 
160  // create default layout
161  if(!m_layout)
162  m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
163 
164  // add to layout and updates it
165  m_layout->addWidget(child);
166 
167  // update new child states
168  child->updateStates();
169 
170  // update old child index states
171  if(oldLastChild) {
172  oldLastChild->updateState(Fw::MiddleState);
173  oldLastChild->updateState(Fw::LastState);
174  }
175 
176  g_ui.onWidgetAppear(child);
177 }
178 
179 void UIWidget::insertChild(int index, const UIWidgetPtr& child)
180 {
181  if(!child) {
182  g_logger.traceWarning("attempt to insert a null child into a UIWidget");
183  return;
184  }
185 
186  if(hasChild(child)) {
187  g_logger.traceWarning("attempt to insert a child again into a UIWidget");
188  return;
189  }
190 
191  index = index <= 0 ? (m_children.size() + index) : index-1;
192 
193  if(!(index >= 0 && (uint)index <= m_children.size())) {
194  //g_logger.traceWarning("attempt to insert a child UIWidget into an invalid index, using nearest index...");
195  index = stdext::clamp<int>(index, 0, (int)m_children.size());
196  }
197 
198  // retrieve child by index
199  auto it = m_children.begin() + index;
200  m_children.insert(it, child);
201  child->setParent(static_self_cast<UIWidget>());
202 
203  // create default layout if needed
204  if(!m_layout)
205  m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
206 
207  // add to layout and updates it
208  m_layout->addWidget(child);
209 
210  // update new child states
211  child->updateStates();
212  updateChildrenIndexStates();
213 
214  g_ui.onWidgetAppear(child);
215 }
216 
218 {
219  // remove from children list
220  if(hasChild(child)) {
221  // defocus if needed
222  bool focusAnother = false;
223  if(m_focusedChild == child) {
225  focusAnother = true;
226  }
227 
228  if(isChildLocked(child))
229  unlockChild(child);
230 
231  auto it = std::find(m_children.begin(), m_children.end(), child);
232  m_children.erase(it);
233 
234  // reset child parent
235  assert(child->getParent() == static_self_cast<UIWidget>());
236  child->setParent(nullptr);
237 
238  m_layout->removeWidget(child);
239 
240  // update child states
241  child->updateStates();
242  updateChildrenIndexStates();
243 
244  if(m_autoFocusPolicy != Fw::AutoFocusNone && focusAnother && !m_focusedChild)
246 
247  g_ui.onWidgetDisappear(child);
248  } else
249  g_logger.traceError("attempt to remove an unknown child from a UIWidget");
250 }
251 
252 
254 {
255  if(m_destroyed)
256  return;
257 
258  if(child == m_focusedChild)
259  return;
260 
261  if(child && !hasChild(child)) {
262  g_logger.error("attempt to focus an unknown child in a UIWidget");
263  return;
264  }
265 
266  UIWidgetPtr oldFocused = m_focusedChild;
267  m_focusedChild = child;
268 
269  if(child) {
270  child->setLastFocusReason(reason);
271  child->updateState(Fw::FocusState);
272  child->updateState(Fw::ActiveState);
273 
274  child->onFocusChange(true, reason);
275  }
276 
277  if(oldFocused) {
278  oldFocused->setLastFocusReason(reason);
279  oldFocused->updateState(Fw::FocusState);
280  oldFocused->updateState(Fw::ActiveState);
281 
282  oldFocused->onFocusChange(false, reason);
283  }
284 
285  onChildFocusChange(child, oldFocused, reason);
286 }
287 
288 void UIWidget::focusNextChild(Fw::FocusReason reason, bool rotate)
289 {
290  if(m_destroyed)
291  return;
292 
293  UIWidgetPtr toFocus;
294 
295  if(rotate) {
296  UIWidgetList rotatedChildren(m_children);
297 
298  if(m_focusedChild) {
299  auto focusedIt = std::find(rotatedChildren.begin(), rotatedChildren.end(), m_focusedChild);
300  if(focusedIt != rotatedChildren.end()) {
301  std::rotate(rotatedChildren.begin(), focusedIt, rotatedChildren.end());
302  rotatedChildren.pop_front();
303  }
304  }
305 
306  // finds next child to focus
307  for(const UIWidgetPtr& child : rotatedChildren) {
308  if(child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
309  toFocus = child;
310  break;
311  }
312  }
313  } else {
314  auto it = m_children.begin();
315  if(m_focusedChild)
316  it = std::find(m_children.begin(), m_children.end(), m_focusedChild);
317 
318  for(; it != m_children.end(); ++it) {
319  const UIWidgetPtr& child = *it;
320  if(child != m_focusedChild && child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
321  toFocus = child;
322  break;
323  }
324  }
325  }
326 
327  if(toFocus && toFocus != m_focusedChild)
328  focusChild(toFocus, reason);
329 }
330 
332 {
333  if(m_destroyed)
334  return;
335 
336  UIWidgetPtr toFocus;
337  if(rotate) {
338  UIWidgetList rotatedChildren(m_children);
339  std::reverse(rotatedChildren.begin(), rotatedChildren.end());
340 
341  if(m_focusedChild) {
342  auto focusedIt = std::find(rotatedChildren.begin(), rotatedChildren.end(), m_focusedChild);
343  if(focusedIt != rotatedChildren.end()) {
344  std::rotate(rotatedChildren.begin(), focusedIt, rotatedChildren.end());
345  rotatedChildren.pop_front();
346  }
347  }
348 
349  // finds next child to focus
350  for(const UIWidgetPtr& child : rotatedChildren) {
351  if(child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
352  toFocus = child;
353  break;
354  }
355  }
356  } else {
357  auto it = m_children.rbegin();
358  if(m_focusedChild)
359  it = std::find(m_children.rbegin(), m_children.rend(), m_focusedChild);
360 
361  for(; it != m_children.rend(); ++it) {
362  const UIWidgetPtr& child = *it;
363  if(child != m_focusedChild && child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
364  toFocus = child;
365  break;
366  }
367  }
368  }
369 
370  if(toFocus && toFocus != m_focusedChild)
371  focusChild(toFocus, reason);
372 }
373 
375 {
376  if(m_destroyed)
377  return;
378 
379  if(!child)
380  return;
381 
382  // remove and push child again
383  auto it = std::find(m_children.begin(), m_children.end(), child);
384  if(it == m_children.end()) {
385  g_logger.traceError("cannot find child");
386  return;
387  }
388 
389  m_children.erase(it);
390  m_children.push_front(child);
391  updateChildrenIndexStates();
392 }
393 
395 {
396  if(m_destroyed)
397  return;
398 
399  if(!child)
400  return;
401 
402  // remove and push child again
403  auto it = std::find(m_children.begin(), m_children.end(), child);
404  if(it == m_children.end()) {
405  g_logger.traceError("cannot find child");
406  return;
407  }
408  m_children.erase(it);
409  m_children.push_back(child);
410  updateChildrenIndexStates();
411 }
412 
413 void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
414 {
415  if(m_destroyed)
416  return;
417 
418  if(!child)
419  return;
420 
421  if((uint)index - 1 >= m_children.size()) {
422  g_logger.traceError(stdext::format("moving %s to index %d on %s", child->getId(), index, m_id));
423  return;
424  }
425 
426  // remove and push child again
427  auto it = std::find(m_children.begin(), m_children.end(), child);
428  if(it == m_children.end()) {
429  g_logger.traceError("cannot find child");
430  return;
431  }
432  m_children.erase(it);
433  m_children.insert(m_children.begin() + index - 1, child);
434  updateChildrenIndexStates();
435  updateLayout();
436 }
437 
439 {
440  if(m_destroyed)
441  return;
442 
443  if(!child)
444  return;
445 
446  if(!hasChild(child)) {
447  g_logger.traceError("cannot find child");
448  return;
449  }
450 
451  // prevent double locks
452  if(isChildLocked(child))
453  unlockChild(child);
454 
455  // disable all other children
456  for(const UIWidgetPtr& otherChild : m_children) {
457  if(otherChild == child)
458  child->setEnabled(true);
459  else
460  otherChild->setEnabled(false);
461  }
462 
463  m_lockedChildren.push_front(child);
464 
465  // lock child focus
466  if(child->isFocusable())
468 }
469 
471 {
472  if(m_destroyed)
473  return;
474 
475  if(!child)
476  return;
477 
478  if(!hasChild(child)) {
479  g_logger.traceError("cannot find child");
480  return;
481  }
482 
483  auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child);
484  if(it == m_lockedChildren.end())
485  return;
486 
487  m_lockedChildren.erase(it);
488 
489  // find new child to lock
490  UIWidgetPtr lockedChild;
491  if(!m_lockedChildren.empty()) {
492  lockedChild = m_lockedChildren.front();
493  assert(hasChild(lockedChild));
494  }
495 
496  for(const UIWidgetPtr& otherChild : m_children) {
497  // lock new child
498  if(lockedChild) {
499  if(otherChild == lockedChild)
500  lockedChild->setEnabled(true);
501  else
502  otherChild->setEnabled(false);
503  }
504  // else unlock all
505  else
506  otherChild->setEnabled(true);
507  }
508 
509  if(lockedChild) {
510  if(lockedChild->isFocusable())
511  focusChild(lockedChild, Fw::ActiveFocusReason);
512  }
513 }
514 
515 void UIWidget::mergeStyle(const OTMLNodePtr& styleNode)
516 {
517  applyStyle(styleNode);
518  std::string name = m_style->tag();
519  std::string source = m_style->source();
520  m_style->merge(styleNode);
521  m_style->setTag(name);
522  m_style->setSource(source);
523  updateStyle();
524 }
525 
526 void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
527 {
528  if(m_destroyed)
529  return;
530 
531  if(styleNode->size() == 0)
532  return;
533 
534  m_loadingStyle = true;
535  try {
536  // translate ! style tags
537  for(const OTMLNodePtr& node : styleNode->children()) {
538  if(node->tag()[0] == '!') {
539  std::string tag = node->tag().substr(1);
540  std::string code = stdext::format("tostring(%s)", node->value());
541  std::string origin = "@" + node->source() + ": [" + node->tag() + "]";
542  g_lua.evaluateExpression(code, origin);
543  std::string value = g_lua.popString();
544 
545  node->setTag(tag);
546  node->setValue(value);
547  }
548  }
549 
550  onStyleApply(styleNode->tag(), styleNode);
551  callLuaField("onStyleApply", styleNode->tag(), styleNode);
552 
553  if(m_firstOnStyle) {
554  UIWidgetPtr parent = getParent();
556  parent && ((!parent->getFocusedChild() && parent->getAutoFocusPolicy() == Fw::AutoFocusFirst) ||
557  parent->getAutoFocusPolicy() == Fw::AutoFocusLast)) {
558  focus();
559  }
560  }
561 
562  m_firstOnStyle = false;
563  } catch(stdext::exception& e) {
564  g_logger.traceError(stdext::format("failed to apply style to widget '%s': %s", m_id, e.what()));
565  }
566  m_loadingStyle = false;
567 }
568 
569 void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge)
570 {
571  if(m_destroyed)
572  return;
573 
574  if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
575  anchorLayout->addAnchor(static_self_cast<UIWidget>(), anchoredEdge, hookedWidgetId, hookedEdge);
576  else
577  g_logger.traceError(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
578 }
579 
581 {
582  addAnchor(anchoredEdge, "none", Fw::AnchorNone);
583 }
584 
585 void UIWidget::centerIn(const std::string& hookedWidgetId)
586 {
587  if(m_destroyed)
588  return;
589 
590  if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
591  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
592  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
593  } else
594  g_logger.traceError(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
595 }
596 
597 void UIWidget::fill(const std::string& hookedWidgetId)
598 {
599  if(m_destroyed)
600  return;
601 
602  if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
603  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
604  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
605  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
606  anchorLayout->addAnchor(static_self_cast<UIWidget>(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
607  } else
608  g_logger.traceError(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
609 }
610 
612 {
613  if(m_destroyed)
614  return;
615 
616  if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
617  anchorLayout->removeAnchors(static_self_cast<UIWidget>());
618 }
619 
621 {
622  if(m_destroyed)
623  return;
624 
625  if(UIWidgetPtr parent = getParent())
626  parent->updateLayout();
627  else
628  updateLayout();
629 }
630 
632 {
633  if(m_destroyed)
634  return;
635 
636  if(m_layout)
637  m_layout->update();
638 
639  // children can affect the parent layout
640  if(UIWidgetPtr parent = getParent())
641  if(UILayoutPtr parentLayout = parent->getLayout())
642  parentLayout->updateLater();
643 }
644 
646 {
647  if(m_destroyed)
648  return;
649 
650  if(UIWidgetPtr parent = getParent())
651  parent->lockChild(static_self_cast<UIWidget>());
652 }
653 
655 {
656  if(m_destroyed)
657  return;
658 
659  if(UIWidgetPtr parent = getParent())
660  parent->unlockChild(static_self_cast<UIWidget>());
661 }
662 
664 {
665  if(m_destroyed)
666  return;
667 
668  if(!m_focusable)
669  return;
670 
671  if(UIWidgetPtr parent = getParent())
672  parent->focusChild(static_self_cast<UIWidget>(), Fw::ActiveFocusReason);
673 }
674 
676 {
677  if(m_destroyed)
678  return;
679 
680  if(UIWidgetPtr parent = getParent()) {
681  if(m_focusable)
682  parent->focusChild(static_self_cast<UIWidget>(), reason);
683  parent->recursiveFocus(reason);
684  }
685 }
686 
688 {
689  if(m_destroyed)
690  return;
691 
692  UIWidgetPtr parent = getParent();
693  if(parent)
694  parent->lowerChild(static_self_cast<UIWidget>());
695 }
696 
698 {
699  if(m_destroyed)
700  return;
701 
702  UIWidgetPtr parent = getParent();
703  if(parent)
704  parent->raiseChild(static_self_cast<UIWidget>());
705 }
706 
708 {
709  if(m_destroyed)
710  return;
711 
712  g_ui.setMouseReceiver(static_self_cast<UIWidget>());
713 }
714 
716 {
717  if(g_ui.getMouseReceiver() == static_self_cast<UIWidget>())
719 }
720 
722 {
723  if(m_destroyed)
724  return;
725 
726  g_ui.setKeyboardReceiver(static_self_cast<UIWidget>());
727 }
728 
730 {
731  if(g_ui.getKeyboardReceiver() == static_self_cast<UIWidget>())
733 }
734 
736 {
737  if(m_destroyed)
738  return;
739 
740  Rect boundRect = m_rect;
741  UIWidgetPtr parent = getParent();
742  if(parent) {
743  Rect parentRect = parent->getPaddingRect();
744  boundRect.bind(parentRect);
745  }
746 
747  setRect(boundRect);
748 }
749 
750 void UIWidget::internalDestroy()
751 {
752  m_destroyed = true;
753  m_visible = false;
754  m_enabled = false;
755  m_focusedChild = nullptr;
756  if(m_layout) {
757  m_layout->setParent(nullptr);
758  m_layout = nullptr;
759  }
760  m_parent = nullptr;
761  m_lockedChildren.clear();
762 
763  for(const UIWidgetPtr& child : m_children)
764  child->internalDestroy();
765  m_children.clear();
766 
767  callLuaField("onDestroy");
768 
770 
771  g_ui.onWidgetDestroy(static_self_cast<UIWidget>());
772 }
773 
775 {
776  if(m_destroyed)
777  g_logger.warning(stdext::format("attempt to destroy widget '%s' two times", m_id));
778 
779  // hold itself reference
780  UIWidgetPtr self = static_self_cast<UIWidget>();
781  m_destroyed = true;
782 
783  // remove itself from parent
784  if(UIWidgetPtr parent = getParent())
785  parent->removeChild(self);
786  internalDestroy();
787 }
788 
790 {
791  UILayoutPtr layout = getLayout();
792  if(layout)
793  layout->disableUpdates();
794 
795  m_focusedChild = nullptr;
796  m_lockedChildren.clear();
797  while(!m_children.empty()) {
798  UIWidgetPtr child = m_children.front();
799  m_children.pop_front();
800  child->setParent(nullptr);
801  m_layout->removeWidget(child);
802  child->destroy();
803  }
804 
805  if(layout)
806  layout->enableUpdates();
807 }
808 
809 void UIWidget::setId(const std::string& id)
810 {
811  if(id != m_id) {
812  m_id = id;
813  callLuaField("onIdChange", id);
814  }
815 }
816 
817 void UIWidget::setParent(const UIWidgetPtr& parent)
818 {
819  // remove from old parent
820  UIWidgetPtr oldParent = getParent();
821 
822  // the parent is already the same
823  if(oldParent == parent)
824  return;
825 
826  UIWidgetPtr self = static_self_cast<UIWidget>();
827  if(oldParent && oldParent->hasChild(self))
828  oldParent->removeChild(self);
829 
830  // reset parent
831  m_parent.reset();
832 
833  // set new parent
834  if(parent) {
835  m_parent = parent;
836 
837  // add to parent if needed
838  if(!parent->hasChild(self))
839  parent->addChild(self);
840  }
841 }
842 
843 void UIWidget::setLayout(const UILayoutPtr& layout)
844 {
845  if(!layout)
846  stdext::throw_exception("attempt to set a nil layout to a widget");
847 
848  if(m_layout)
850 
851  layout->setParent(static_self_cast<UIWidget>());
852  layout->disableUpdates();
853 
854  for(const UIWidgetPtr& child : m_children) {
855  if(m_layout)
856  m_layout->removeWidget(child);
857  layout->addWidget(child);
858  }
859 
860  if(m_layout) {
862  m_layout->setParent(nullptr);
863  m_layout->update();
864  }
865 
866  layout->enableUpdates();
867  m_layout = layout;
868 }
869 
870 bool UIWidget::setRect(const Rect& rect)
871 {
872  /*
873  if(rect.width() > 8192 || rect.height() > 8192) {
874  g_logger.error(stdext::format("attempt to set huge rect size (%s) for %s", stdext::to_string(rect), m_id));
875  return false;
876  }
877  */
878  // only update if the rect really changed
879  Rect oldRect = m_rect;
880  if(rect == oldRect)
881  return false;
882 
883  m_rect = rect;
884 
885  // updates own layout
886  updateLayout();
887 
888  // avoid massive update events
889  if(!m_updateEventScheduled) {
890  UIWidgetPtr self = static_self_cast<UIWidget>();
891  g_dispatcher.addEvent([self, oldRect]() {
892  self->m_updateEventScheduled = false;
893  if(oldRect != self->getRect())
894  self->onGeometryChange(oldRect, self->getRect());
895  });
896  m_updateEventScheduled = true;
897  }
898 
899  // update hovered widget when moved behind mouse area
902 
903  return true;
904 }
905 
906 void UIWidget::setStyle(const std::string& styleName)
907 {
908  OTMLNodePtr styleNode = g_ui.getStyle(styleName);
909  if(!styleNode) {
910  g_logger.traceError(stdext::format("unable to retrieve style '%s': not a defined style", styleName));
911  return;
912  }
913  styleNode = styleNode->clone();
914  applyStyle(styleNode);
915  m_style = styleNode;
916  updateStyle();
917 }
918 
920 {
921  applyStyle(styleNode);
922  m_style = styleNode;
923  updateStyle();
924 }
925 
926 void UIWidget::setEnabled(bool enabled)
927 {
928  if(enabled != m_enabled) {
929  m_enabled = enabled;
930 
931  updateState(Fw::DisabledState);
932  updateState(Fw::ActiveState);
933  }
934 }
935 
936 void UIWidget::setVisible(bool visible)
937 {
938  if(m_visible != visible) {
939  m_visible = visible;
940 
941  // hiding a widget make it lose focus
942  if(!visible && isFocused()) {
943  if(UIWidgetPtr parent = getParent())
944  parent->focusPreviousChild(Fw::ActiveFocusReason, true);
945  }
946 
947  // visibility can change change parent layout
949 
950  updateState(Fw::ActiveState);
951  updateState(Fw::HiddenState);
952 
953  // visibility can change the current hovered widget
954  if(visible)
955  g_ui.onWidgetAppear(static_self_cast<UIWidget>());
956  else
957  g_ui.onWidgetDisappear(static_self_cast<UIWidget>());
958  }
959 }
960 
961 void UIWidget::setOn(bool on)
962 {
963  setState(Fw::OnState, on);
964 }
965 
966 void UIWidget::setChecked(bool checked)
967 {
968  if(setState(Fw::CheckedState, checked))
969  callLuaField("onCheckChange", checked);
970 }
971 
972 void UIWidget::setFocusable(bool focusable)
973 {
974  if(m_focusable != focusable) {
975  m_focusable = focusable;
976 
977  // make parent focus another child
978  if(UIWidgetPtr parent = getParent()) {
979  if(!focusable && isFocused()) {
980  parent->focusPreviousChild(Fw::ActiveFocusReason, true);
981  } else if(focusable && !parent->getFocusedChild() && parent->getAutoFocusPolicy() != Fw::AutoFocusNone) {
982  focus();
983  }
984  }
985  }
986 }
987 
988 void UIWidget::setPhantom(bool phantom)
989 {
990  m_phantom = phantom;
991 }
992 
993 void UIWidget::setDraggable(bool draggable)
994 {
995  m_draggable = draggable;
996 }
997 
998 void UIWidget::setFixedSize(bool fixed)
999 {
1000  m_fixedSize = fixed;
1002 }
1003 
1005 {
1006  m_lastFocusReason = reason;
1007 }
1008 
1010 {
1011  m_autoFocusPolicy = policy;
1012 }
1013 
1015 {
1016  m_virtualOffset = offset;
1017  if(m_layout)
1018  m_layout->update();
1019 }
1020 
1022 {
1023  if(UIWidgetPtr parent = getParent())
1024  if(UIAnchorLayoutPtr anchorLayout = parent->getAnchoredLayout())
1025  return anchorLayout->hasAnchors(static_self_cast<UIWidget>());
1026  return false;
1027 }
1028 
1030 {
1031  auto it = std::find(m_lockedChildren.begin(), m_lockedChildren.end(), child);
1032  return it != m_lockedChildren.end();
1033 }
1034 
1036 {
1037  auto it = std::find(m_children.begin(), m_children.end(), child);
1038  if(it != m_children.end())
1039  return true;
1040  return false;
1041 }
1042 
1044 {
1045  int index = 1;
1046  for(auto &it: m_children) {
1047  if(it == child)
1048  return index;
1049  ++index;
1050  }
1051  return -1;
1052 }
1053 
1055 {
1056  Rect rect = m_rect;
1058  return rect;
1059 }
1060 
1062 {
1063  Rect rect = m_rect;
1065  return rect;
1066 }
1067 
1069 {
1070  Rect childrenRect;
1071  for(const UIWidgetPtr& child : m_children) {
1072  if(!child->isExplicitlyVisible() || !child->getRect().isValid())
1073  continue;
1074  Rect marginRect = child->getMarginRect();
1075  if(!childrenRect.isValid())
1076  childrenRect = marginRect;
1077  else
1078  childrenRect = childrenRect.united(marginRect);
1079  }
1080 
1081  Rect myClippingRect = getPaddingRect();
1082  if(!childrenRect.isValid())
1083  childrenRect = myClippingRect;
1084  else {
1085  if(childrenRect.width() < myClippingRect.width())
1086  childrenRect.setWidth(myClippingRect.width());
1087  if(childrenRect.height() < myClippingRect.height())
1088  childrenRect.setHeight(myClippingRect.height());
1089  }
1090  return childrenRect;
1091 }
1092 
1094 {
1095  UIWidgetPtr parent = getParent();
1096  if(!parent)
1097  return nullptr;
1098 
1099  UILayoutPtr layout = parent->getLayout();
1100  if(layout->isUIAnchorLayout())
1101  return layout->static_self_cast<UIAnchorLayout>();
1102  return nullptr;
1103 }
1104 
1106 {
1107  if(UIWidgetPtr parent = getParent())
1108  return parent->getRootParent();
1109  else
1110  return static_self_cast<UIWidget>();
1111 }
1112 
1114 {
1115  auto it = std::find(m_children.begin(), m_children.end(), relativeChild);
1116  if(it != m_children.end() && ++it != m_children.end())
1117  return *it;
1118  return nullptr;
1119 }
1120 
1122 {
1123  auto it = std::find(m_children.rbegin(), m_children.rend(), relativeChild);
1124  if(it != m_children.rend() && ++it != m_children.rend())
1125  return *it;
1126  return nullptr;
1127 }
1128 
1129 UIWidgetPtr UIWidget::getChildById(const std::string& childId)
1130 {
1131  for(const UIWidgetPtr& child : m_children) {
1132  if(child->getId() == childId)
1133  return child;
1134  }
1135  return nullptr;
1136 }
1137 
1139 {
1140  if(!containsPaddingPoint(childPos))
1141  return nullptr;
1142 
1143  for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1144  const UIWidgetPtr& child = (*it);
1145  if(child->isExplicitlyVisible() && child->containsPoint(childPos))
1146  return child;
1147  }
1148 
1149  return nullptr;
1150 }
1151 
1153 {
1154  index = index <= 0 ? (m_children.size() + index) : index-1;
1155  if(index >= 0 && (uint)index < m_children.size())
1156  return m_children.at(index);
1157  return nullptr;
1158 }
1159 
1161 {
1162  UIWidgetPtr widget = getChildById(id);
1163  if(!widget) {
1164  for(const UIWidgetPtr& child : m_children) {
1165  widget = child->recursiveGetChildById(id);
1166  if(widget)
1167  break;
1168  }
1169  }
1170  return widget;
1171 }
1172 
1173 UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom)
1174 {
1175  if(!containsPaddingPoint(childPos))
1176  return nullptr;
1177 
1178  for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1179  const UIWidgetPtr& child = (*it);
1180  if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
1181  UIWidgetPtr subChild = child->recursiveGetChildByPos(childPos, wantsPhantom);
1182  if(subChild)
1183  return subChild;
1184  else if(wantsPhantom || !child->isPhantom())
1185  return child;
1186  }
1187  }
1188  return nullptr;
1189 }
1190 
1192 {
1193  UIWidgetList children;
1194  for(const UIWidgetPtr& child : m_children) {
1195  UIWidgetList subChildren = child->recursiveGetChildren();
1196  if(!subChildren.empty())
1197  children.insert(children.end(), subChildren.begin(), subChildren.end());
1198  children.push_back(child);
1199  }
1200  return children;
1201 }
1202 
1204 {
1205  UIWidgetList children;
1206  if(!containsPaddingPoint(childPos))
1207  return children;
1208 
1209  for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1210  const UIWidgetPtr& child = (*it);
1211  if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
1212  UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos);
1213  if(!subChildren.empty())
1214  children.insert(children.end(), subChildren.begin(), subChildren.end());
1215  children.push_back(child);
1216  }
1217  }
1218  return children;
1219 }
1220 
1222 {
1223  UIWidgetList children;
1224  if(!containsPaddingPoint(childPos))
1225  return children;
1226 
1227  for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1228  const UIWidgetPtr& child = (*it);
1229  if(child->isExplicitlyVisible() && child->containsMarginPoint(childPos)) {
1230  UIWidgetList subChildren = child->recursiveGetChildrenByMarginPos(childPos);
1231  if(!subChildren.empty())
1232  children.insert(children.end(), subChildren.begin(), subChildren.end());
1233  children.push_back(child);
1234  }
1235  }
1236  return children;
1237 }
1238 
1240 {
1241  UIWidgetPtr widget = getChildById(id);
1242  if(!widget) {
1243  if(UIWidgetPtr parent = getParent())
1244  widget = parent->backwardsGetWidgetById(id);
1245  }
1246  return widget;
1247 }
1248 
1250 {
1251  if(state == Fw::InvalidState)
1252  return false;
1253 
1254  int oldStates = m_states;
1255  if(on)
1256  m_states |= state;
1257  else
1258  m_states &= ~state;
1259 
1260  if(oldStates != m_states) {
1261  updateStyle();
1262  return true;
1263  }
1264  return false;
1265 }
1266 
1268 {
1269  if(state == Fw::InvalidState)
1270  return false;
1271  return (m_states & state);
1272 }
1273 
1274 void UIWidget::updateState(Fw::WidgetState state)
1275 {
1276  if(m_destroyed)
1277  return;
1278 
1279  bool newStatus = true;
1280  bool oldStatus = hasState(state);
1281  bool updateChildren = false;
1282 
1283  switch(state) {
1284  case Fw::ActiveState: {
1285  UIWidgetPtr widget = static_self_cast<UIWidget>();
1286  UIWidgetPtr parent;
1287  do {
1288  parent = widget->getParent();
1289  if(!widget->isExplicitlyEnabled() ||
1290  ((parent && parent->getFocusedChild() != widget))) {
1291  newStatus = false;
1292  break;
1293  }
1294  } while((widget = parent));
1295 
1296  updateChildren = newStatus != oldStatus;
1297  break;
1298  }
1299  case Fw::FocusState: {
1300  newStatus = (getParent() && getParent()->getFocusedChild() == static_self_cast<UIWidget>());
1301  break;
1302  }
1303  case Fw::HoverState: {
1304  newStatus = (g_ui.getHoveredWidget() == static_self_cast<UIWidget>() && isEnabled());
1305  break;
1306  }
1307  case Fw::PressedState: {
1308  newStatus = (g_ui.getPressedWidget() == static_self_cast<UIWidget>());
1309  break;
1310  }
1311  case Fw::DraggingState: {
1312  newStatus = (g_ui.getDraggingWidget() == static_self_cast<UIWidget>());
1313  break;
1314  }
1315  case Fw::DisabledState: {
1316  bool enabled = true;
1317  UIWidgetPtr widget = static_self_cast<UIWidget>();
1318  do {
1319  if(!widget->isExplicitlyEnabled()) {
1320  enabled = false;
1321  break;
1322  }
1323  } while((widget = widget->getParent()));
1324  newStatus = !enabled;
1325  updateChildren = newStatus != oldStatus;
1326  break;
1327  }
1328  case Fw::FirstState: {
1329  newStatus = (getParent() && getParent()->getFirstChild() == static_self_cast<UIWidget>());
1330  break;
1331  }
1332  case Fw::MiddleState: {
1333  newStatus = (getParent() && getParent()->getFirstChild() != static_self_cast<UIWidget>() && getParent()->getLastChild() != static_self_cast<UIWidget>());
1334  break;
1335  }
1336  case Fw::LastState: {
1337  newStatus = (getParent() && getParent()->getLastChild() == static_self_cast<UIWidget>());
1338  break;
1339  }
1340  case Fw::AlternateState: {
1341  newStatus = (getParent() && (getParent()->getChildIndex(static_self_cast<UIWidget>()) % 2) == 1);
1342  break;
1343  }
1344  case Fw::HiddenState: {
1345  bool visible = true;
1346  UIWidgetPtr widget = static_self_cast<UIWidget>();
1347  do {
1348  if(!widget->isExplicitlyVisible()) {
1349  visible = false;
1350  break;
1351  }
1352  } while((widget = widget->getParent()));
1353  newStatus = !visible;
1354  updateChildren = newStatus != oldStatus;
1355  break;
1356  }
1357  default:
1358  return;
1359  }
1360 
1361  if(updateChildren) {
1362  // do a backup of children list, because it may change while looping it
1363  UIWidgetList children = m_children;
1364  for(const UIWidgetPtr& child : children)
1365  child->updateState(state);
1366  }
1367 
1368  if(setState(state, newStatus)) {
1369  // disabled widgets cannot have hover state
1370  if(state == Fw::DisabledState && !newStatus && isHovered()) {
1372  } else if(state == Fw::HiddenState) {
1373  onVisibilityChange(!newStatus);
1374  }
1375  }
1376 }
1377 
1378 void UIWidget::updateStates()
1379 {
1380  if(m_destroyed)
1381  return;
1382 
1383  for(int state = 1; state != Fw::LastWidgetState; state <<= 1)
1384  updateState((Fw::WidgetState)state);
1385 }
1386 
1387 void UIWidget::updateChildrenIndexStates()
1388 {
1389  if(m_destroyed)
1390  return;
1391 
1392  for(const UIWidgetPtr& child : m_children) {
1393  child->updateState(Fw::FirstState);
1394  child->updateState(Fw::MiddleState);
1395  child->updateState(Fw::LastState);
1396  child->updateState(Fw::AlternateState);
1397  }
1398 }
1399 
1400 void UIWidget::updateStyle()
1401 {
1402  if(m_destroyed)
1403  return;
1404 
1405  if(m_loadingStyle && !m_updateStyleScheduled) {
1406  UIWidgetPtr self = static_self_cast<UIWidget>();
1407  g_dispatcher.addEvent([self] {
1408  self->m_updateStyleScheduled = false;
1409  self->updateStyle();
1410  });
1411  m_updateStyleScheduled = true;
1412  return;
1413  }
1414 
1415  if(!m_style)
1416  return;
1417 
1418  OTMLNodePtr newStateStyle = OTMLNode::create();
1419 
1420  // copy only the changed styles from default style
1421  if(m_stateStyle) {
1422  for(OTMLNodePtr node : m_stateStyle->children()) {
1423  if(OTMLNodePtr otherNode = m_style->get(node->tag()))
1424  newStateStyle->addChild(otherNode->clone());
1425  }
1426  }
1427 
1428  // checks for states combination
1429  for(const OTMLNodePtr& style : m_style->children()) {
1430  if(stdext::starts_with(style->tag(), "$")) {
1431  std::string statesStr = style->tag().substr(1);
1432  std::vector<std::string> statesSplit = stdext::split(statesStr, " ");
1433 
1434  bool match = true;
1435  for(std::string stateStr : statesSplit) {
1436  if(stateStr.length() == 0)
1437  continue;
1438 
1439  bool notstate = (stateStr[0] == '!');
1440  if(notstate)
1441  stateStr = stateStr.substr(1);
1442 
1443  bool stateOn = hasState(Fw::translateState(stateStr));
1444  if((!notstate && !stateOn) || (notstate && stateOn))
1445  match = false;
1446  }
1447 
1448  // merge states styles
1449  if(match) {
1450  newStateStyle->merge(style);
1451  }
1452  }
1453  }
1454 
1455  //TODO: prevent setting already set proprieties
1456 
1457  applyStyle(newStateStyle);
1458  m_stateStyle = newStateStyle;
1459 }
1460 
1461 void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
1462 {
1463  if(m_destroyed)
1464  return;
1465 
1466  // first set id
1467  if(const OTMLNodePtr& node = styleNode->get("id"))
1468  setId(node->value());
1469 
1470  parseBaseStyle(styleNode);
1471  parseImageStyle(styleNode);
1472  parseTextStyle(styleNode);
1473 
1474  g_app.repaint();
1475 }
1476 
1477 void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
1478 {
1479  if(m_textWrap && oldRect.size() != newRect.size())
1480  updateText();
1481 
1482  // move children that is outside the parent rect to inside again
1483  for(const UIWidgetPtr& child : m_children) {
1484  if(!child->isAnchored() && child->isVisible())
1485  child->bindRectToParent();
1486  }
1487 
1488  callLuaField("onGeometryChange", oldRect, newRect);
1489 
1490  g_app.repaint();
1491 }
1492 
1494 {
1495  callLuaField("onLayoutUpdate");
1496 }
1497 
1498 void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
1499 {
1500  callLuaField("onFocusChange", focused, reason);
1501 }
1502 
1503 void UIWidget::onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason)
1504 {
1505  callLuaField("onChildFocusChange", focusedChild, unfocusedChild, reason);
1506 }
1507 
1508 void UIWidget::onHoverChange(bool hovered)
1509 {
1510  callLuaField("onHoverChange", hovered);
1511 }
1512 
1514 {
1515  if(!isAnchored())
1516  bindRectToParent();
1517  callLuaField("onVisibilityChange", visible);
1518 }
1519 
1520 bool UIWidget::onDragEnter(const Point& mousePos)
1521 {
1522  return callLuaField<bool>("onDragEnter", mousePos);
1523 }
1524 
1525 bool UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
1526 {
1527  return callLuaField<bool>("onDragLeave", droppedWidget, mousePos);
1528 }
1529 
1530 bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
1531 {
1532  return callLuaField<bool>("onDragMove", mousePos, mouseMoved);
1533 }
1534 
1535 bool UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
1536 {
1537  return callLuaField<bool>("onDrop", draggedWidget, mousePos);
1538 }
1539 
1540 bool UIWidget::onKeyText(const std::string& keyText)
1541 {
1542  return callLuaField<bool>("onKeyText", keyText);
1543 }
1544 
1545 bool UIWidget::onKeyDown(uchar keyCode, int keyboardModifiers)
1546 {
1547  return callLuaField<bool>("onKeyDown", keyCode, keyboardModifiers);
1548 }
1549 
1550 bool UIWidget::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
1551 {
1552  return callLuaField<bool>("onKeyPress", keyCode, keyboardModifiers, autoRepeatTicks);
1553 }
1554 
1555 bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
1556 {
1557  return callLuaField<bool>("onKeyUp", keyCode, keyboardModifiers);
1558 }
1559 
1560 bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
1561 {
1562  if(button == Fw::MouseLeftButton) {
1563  if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 200) {
1564  if(onDoubleClick(mousePos))
1565  return true;
1566  m_clickTimer.stop();
1567  } else
1569  m_lastClickPosition = mousePos;
1570  }
1571 
1572  return callLuaField<bool>("onMousePress", mousePos, button);
1573 }
1574 
1575 bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
1576 {
1577  return callLuaField<bool>("onMouseRelease", mousePos, button);
1578 }
1579 
1580 bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
1581 {
1582  return callLuaField<bool>("onMouseMove", mousePos, mouseMoved);
1583 }
1584 
1585 bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
1586 {
1587  return callLuaField<bool>("onMouseWheel", mousePos, direction);
1588 }
1589 
1590 bool UIWidget::onClick(const Point& mousePos)
1591 {
1592  return callLuaField<bool>("onClick", mousePos);
1593 }
1594 
1595 bool UIWidget::onDoubleClick(const Point& mousePos)
1596 {
1597  return callLuaField<bool>("onDoubleClick", mousePos);
1598 }
1599 
1600 bool UIWidget::propagateOnKeyText(const std::string& keyText)
1601 {
1602  // do a backup of children list, because it may change while looping it
1603  UIWidgetList children;
1604  for(const UIWidgetPtr& child : m_children) {
1605  // events on hidden or disabled widgets are discarded
1606  if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
1607  continue;
1608 
1609  // key events go only to containers or focused child
1610  if(child->isFocused())
1611  children.push_back(child);
1612  }
1613 
1614  for(const UIWidgetPtr& child : children) {
1615  if(child->propagateOnKeyText(keyText))
1616  return true;
1617  }
1618 
1619  return onKeyText(keyText);
1620 }
1621 
1622 bool UIWidget::propagateOnKeyDown(uchar keyCode, int keyboardModifiers)
1623 {
1624  // do a backup of children list, because it may change while looping it
1625  UIWidgetList children;
1626  for(const UIWidgetPtr& child : m_children) {
1627  // events on hidden or disabled widgets are discarded
1628  if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
1629  continue;
1630 
1631  // key events go only to containers or focused child
1632  if(child->isFocused())
1633  children.push_back(child);
1634  }
1635 
1636  for(const UIWidgetPtr& child : children) {
1637  if(child->propagateOnKeyDown(keyCode, keyboardModifiers))
1638  return true;
1639  }
1640 
1641  return onKeyDown(keyCode, keyboardModifiers);
1642 }
1643 
1644 bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
1645 {
1646  // do a backup of children list, because it may change while looping it
1647  UIWidgetList children;
1648  for(const UIWidgetPtr& child : m_children) {
1649  // events on hidden or disabled widgets are discarded
1650  if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
1651  continue;
1652 
1653  // key events go only to containers or focused child
1654  if(child->isFocused())
1655  children.push_back(child);
1656  }
1657 
1658  for(const UIWidgetPtr& child : children) {
1659  if(child->propagateOnKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
1660  return true;
1661  }
1662 
1663  if(autoRepeatTicks == 0 || autoRepeatTicks >= m_autoRepeatDelay)
1664  return onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks);
1665  else
1666  return false;
1667 }
1668 
1669 bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers)
1670 {
1671  // do a backup of children list, because it may change while looping it
1672  UIWidgetList children;
1673  for(const UIWidgetPtr& child : m_children) {
1674  // events on hidden or disabled widgets are discarded
1675  if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
1676  continue;
1677 
1678  // key events go only to focused child
1679  if(child->isFocused())
1680  children.push_back(child);
1681  }
1682 
1683  for(const UIWidgetPtr& child : children) {
1684  if(child->propagateOnKeyUp(keyCode, keyboardModifiers))
1685  return true;
1686  }
1687 
1688  return onKeyUp(keyCode, keyboardModifiers);
1689 }
1690 
1691 bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widgetList)
1692 {
1693  bool ret = false;
1694  if(containsPaddingPoint(mousePos)) {
1695  for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
1696  const UIWidgetPtr& child = *it;
1697  if(child->isExplicitlyEnabled() && child->isExplicitlyVisible() && child->containsPoint(mousePos)) {
1698  if(child->propagateOnMouseEvent(mousePos, widgetList)) {
1699  ret = true;
1700  break;
1701  }
1702  }
1703  }
1704  }
1705 
1706  widgetList.push_back(static_self_cast<UIWidget>());
1707 
1708  if(!isPhantom())
1709  ret = true;
1710  return ret;
1711 }
1712 
1713 bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList)
1714 {
1715  if(containsPaddingPoint(mousePos)) {
1716  for(auto &child: m_children) {
1717  if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
1718  child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
1719 
1720  widgetList.push_back(static_self_cast<UIWidget>());
1721  }
1722  }
1723 
1724  return true;
1725 }
UIWidget::onFocusChange
virtual void onFocusChange(bool focused, Fw::FocusReason reason)
Definition: uiwidget.cpp:1498
UIWidget::unlock
void unlock()
Definition: uiwidget.cpp:654
Painter::setColor
virtual void setColor(const Color &color)
Definition: painter.h:77
EdgeGroup::right
T right
Definition: uiwidget.h:41
UIWidget::getPaddingRect
Rect getPaddingRect()
Definition: uiwidget.cpp:1054
OTMLNode::setTag
void setTag(const std::string &tag)
Definition: otmlnode.h:50
UIManager::getHoveredWidget
UIWidgetPtr getHoveredWidget()
Definition: uimanager.h:65
UIManager::onWidgetAppear
void onWidgetAppear(const UIWidgetPtr &widget)
Definition: uimanager.cpp:258
OTMLNode::setSource
void setSource(const std::string &source)
Definition: otmlnode.h:54
UIWidget::m_layout
UILayoutPtr m_layout
Definition: uiwidget.h:72
UIWidget::containsPaddingPoint
bool containsPaddingPoint(const Point &point)
Definition: uiwidget.h:251
OTMLNode::source
std::string source()
Definition: otmlnode.h:38
Fw::FirstState
@ FirstState
Definition: const.h:276
UIWidget::breakAnchors
void breakAnchors()
Definition: uiwidget.cpp:611
Fw::FocusState
@ FocusState
Definition: const.h:270
eventdispatcher.h
UIWidget::setAutoFocusPolicy
void setAutoFocusPolicy(Fw::AutoFocusPolicy policy)
Definition: uiwidget.cpp:1009
graphics.h
UIWidget::fill
void fill(const std::string &hookedWidgetId)
Definition: uiwidget.cpp:597
UIWidget::onDragEnter
virtual bool onDragEnter(const Point &mousePos)
Definition: uiwidget.cpp:1520
UIManager::onWidgetDisappear
void onWidgetDisappear(const UIWidgetPtr &widget)
Definition: uimanager.cpp:264
UIManager::getStyle
OTMLNodePtr getStyle(const std::string &styleName)
Definition: uimanager.cpp:377
UIWidget::isEnabled
bool isEnabled()
Definition: uiwidget.h:226
Painter::rotate
virtual void rotate(float angle)=0
UIWidget::focusChild
void focusChild(const UIWidgetPtr &child, Fw::FocusReason reason)
Definition: uiwidget.cpp:253
Fw::ActiveFocusReason
@ ActiveFocusReason
Definition: const.h:224
UIWidget::m_virtualOffset
Point m_virtualOffset
Definition: uiwidget.h:63
Timer::ticksElapsed
ticks_t ticksElapsed()
Definition: timer.cpp:33
UIWidget::getLayout
UILayoutPtr getLayout()
Definition: uiwidget.h:260
UIWidget::setFocusable
void setFocusable(bool focusable)
Definition: uiwidget.cpp:972
platformwindow.h
TRect< int >
Fw::ActiveState
@ ActiveState
Definition: const.h:269
Fw::WidgetState
WidgetState
Definition: const.h:266
UIWidget::isChildLocked
bool isChildLocked(const UIWidgetPtr &child)
Definition: uiwidget.cpp:1029
UIWidget::m_textWrap
stdext::boolean< false > m_textWrap
Definition: uiwidget.h:485
UILayout::removeWidget
virtual void removeWidget(const UIWidgetPtr &)
Definition: uilayout.h:41
Fw::AnchorRight
@ AnchorRight
Definition: const.h:216
UIWidget::setStyle
void setStyle(const std::string &styleName)
Definition: uiwidget.cpp:906
UIWidget::onStyleApply
virtual void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:1461
Fw::DraggingState
@ DraggingState
Definition: const.h:280
g_dispatcher
EventDispatcher g_dispatcher
Definition: eventdispatcher.cpp:28
UIWidget::centerIn
void centerIn(const std::string &hookedWidgetId)
Definition: uiwidget.cpp:585
UIWidget::m_autoRepeatDelay
int m_autoRepeatDelay
Definition: uiwidget.h:295
UIWidget::onDrop
virtual bool onDrop(UIWidgetPtr draggedWidget, const Point &mousePos)
Definition: uiwidget.cpp:1535
UIWidget::ungrabKeyboard
void ungrabKeyboard()
Definition: uiwidget.cpp:729
UILayout::enableUpdates
void enableUpdates()
Definition: uilayout.h:43
UIWidget::propagateOnMouseMove
bool propagateOnMouseMove(const Point &mousePos, const Point &mouseMoved, UIWidgetList &widgetList)
Definition: uiwidget.cpp:1713
uitranslator.h
UIWidget::propagateOnKeyDown
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers)
Definition: uiwidget.cpp:1622
EdgeGroup::top
T top
Definition: uiwidget.h:40
UIWidget::m_borderWidth
EdgeGroup< int > m_borderWidth
Definition: uiwidget.h:290
UIWidget::recursiveGetChildByPos
UIWidgetPtr recursiveGetChildByPos(const Point &childPos, bool wantsPhantom)
Definition: uiwidget.cpp:1173
UIWidget::containsMarginPoint
bool containsMarginPoint(const Point &point)
Definition: uiwidget.h:250
UIWidget::getId
std::string getId()
Definition: uiwidget.h:254
TRect::bind
void bind(const TRect< T > &r)
Definition: rect.h:273
Fw::AnchorEdge
AnchorEdge
Definition: const.h:211
UIWidget::onHoverChange
virtual void onHoverChange(bool hovered)
Definition: uiwidget.cpp:1508
UIManager::updateHoveredWidget
void updateHoveredWidget(bool now=false)
Definition: uimanager.cpp:219
UILayout::isUIAnchorLayout
virtual bool isUIAnchorLayout()
Definition: uilayout.h:51
luainterface.h
UIAnchorLayout
Definition: uianchorlayout.h:62
UIWidget::drawSelf
virtual void drawSelf(Fw::DrawPane drawPane)
Definition: uiwidget.cpp:88
Logger::error
void error(const std::string &what)
Definition: logger.h:54
UIWidget::m_autoFocusPolicy
Fw::AutoFocusPolicy m_autoFocusPolicy
Definition: uiwidget.h:80
UIWidget::getAnchoredLayout
UIAnchorLayoutPtr getAnchoredLayout()
Definition: uiwidget.cpp:1093
UIWidget::destroy
void destroy()
Definition: uiwidget.cpp:774
UIWidget::propagateOnKeyPress
bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
Definition: uiwidget.cpp:1644
UIWidget::unlockChild
void unlockChild(const UIWidgetPtr &child)
Definition: uiwidget.cpp:470
UIManager::getPressedWidget
UIWidgetPtr getPressedWidget()
Definition: uimanager.h:66
UIWidget::isAnchored
bool isAnchored()
Definition: uiwidget.cpp:1021
texturemanager.h
UIWidget::raise
void raise()
Definition: uiwidget.cpp:697
UIWidget::onMouseWheel
virtual bool onMouseWheel(const Point &mousePos, Fw::MouseWheelDirection direction)
Definition: uiwidget.cpp:1585
UIWidget::addChild
void addChild(const UIWidgetPtr &child)
Definition: uiwidget.cpp:138
UIWidget::isPhantom
bool isPhantom()
Definition: uiwidget.h:243
UIWidget::recursiveGetChildrenByMarginPos
UIWidgetList recursiveGetChildrenByMarginPos(const Point &childPos)
Definition: uiwidget.cpp:1221
UIWidget::containsPoint
bool containsPoint(const Point &point)
Definition: uiwidget.h:252
OTMLNode::children
OTMLNodeList children()
Definition: otmlnode.cpp:170
UIWidget::mergeStyle
void mergeStyle(const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:515
Fw::AnchorLeft
@ AnchorLeft
Definition: const.h:215
UIWidget::m_focusable
stdext::boolean< true > m_focusable
Definition: uiwidget.h:66
Fw::HoverState
@ HoverState
Definition: const.h:271
uiwidget.h
UIWidget::addAnchor
void addAnchor(Fw::AnchorEdge anchoredEdge, const std::string &hookedWidgetId, Fw::AnchorEdge hookedEdge)
Definition: uiwidget.cpp:569
UIWidget::getLastChild
UIWidgetPtr getLastChild()
Definition: uiwidget.h:259
Painter::popTransformMatrix
virtual void popTransformMatrix()=0
Fw::AutoFocusLast
@ AutoFocusLast
Definition: const.h:231
stdext::format
std::string format()
Definition: format.h:82
stdext::starts_with
bool starts_with(const std::string &str, const std::string &test)
Definition: string.cpp:263
UIWidget::bindRectToParent
void bindRectToParent()
Definition: uiwidget.cpp:735
UIWidget::m_lastClickPosition
Point m_lastClickPosition
Definition: uiwidget.h:296
UIWidget::m_rect
Rect m_rect
Definition: uiwidget.h:62
UIWidget::drawBorder
void drawBorder(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:348
UIWidget::focus
void focus()
Definition: uiwidget.cpp:663
Fw::FocusReason
FocusReason
Definition: const.h:221
OTMLNode::addChild
void addChild(const OTMLNodePtr &newChild)
Definition: otmlnode.cpp:91
UIManager::setKeyboardReceiver
void setKeyboardReceiver(const UIWidgetPtr &widget)
Definition: uimanager.h:58
UILayout::setParent
void setParent(UIWidgetPtr parentWidget)
Definition: uilayout.h:45
UIWidget::m_lockedChildren
UIWidgetList m_lockedChildren
Definition: uiwidget.h:75
UIWidget::getChildByIndex
UIWidgetPtr getChildByIndex(int index)
Definition: uiwidget.cpp:1152
Fw::MouseLeftButton
@ MouseLeftButton
Definition: const.h:248
UIWidget::getRootParent
UIWidgetPtr getRootParent()
Definition: uiwidget.cpp:1105
UIWidget::onGeometryChange
virtual void onGeometryChange(const Rect &oldRect, const Rect &newRect)
Definition: uiwidget.cpp:1477
Fw::LastWidgetState
@ LastWidgetState
Definition: const.h:282
UIWidget::getMarginRect
Rect getMarginRect()
Definition: uiwidget.cpp:1061
UIWidget::getChildBefore
UIWidgetPtr getChildBefore(const UIWidgetPtr &relativeChild)
Definition: uiwidget.cpp:1121
Fw::MiddleState
@ MiddleState
Definition: const.h:277
UIWidget::focusPreviousChild
void focusPreviousChild(Fw::FocusReason reason, bool rotate=false)
Definition: uiwidget.cpp:331
UIWidget::getAutoFocusPolicy
Fw::AutoFocusPolicy getAutoFocusPolicy()
Definition: uiwidget.h:264
Color::green
static const Color green
Definition: color.h:105
UIWidget::ungrabMouse
void ungrabMouse()
Definition: uiwidget.cpp:715
Fw::AutoFocusFirst
@ AutoFocusFirst
Definition: const.h:230
UIManager::getDraggingWidget
UIWidgetPtr getDraggingWidget()
Definition: uimanager.h:64
UIWidget::onDragMove
virtual bool onDragMove(const Point &mousePos, const Point &mouseMoved)
Definition: uiwidget.cpp:1530
LuaObject::releaseLuaFieldsTable
void releaseLuaFieldsTable()
Release fields table reference.
Definition: luaobject.cpp:54
LuaInterface::popString
std::string popString()
Definition: luainterface.cpp:1031
g_window
PlatformWindow & g_window
Definition: platformwindow.cpp:37
UIWidget::getChildByPos
UIWidgetPtr getChildByPos(const Point &childPos)
Definition: uiwidget.cpp:1138
UIWidget::updateParentLayout
void updateParentLayout()
Definition: uiwidget.cpp:620
UILayout::addWidget
virtual void addWidget(const UIWidgetPtr &)
Definition: uilayout.h:40
UIWidget::m_id
std::string m_id
Definition: uiwidget.h:61
UIWidget::m_clipping
stdext::boolean< false > m_clipping
Definition: uiwidget.h:71
uint
unsigned int uint
Definition: types.h:31
OTMLNode::tag
std::string tag()
Definition: otmlnode.h:36
UIWidget::m_padding
EdgeGroup< int > m_padding
Definition: uiwidget.h:292
uianchorlayout.h
LuaObject::callLuaField
R callLuaField(const std::string &field, const T &... args)
Definition: luaobject.h:172
TRect::expand
void expand(T top, T right, T bottom, T left)
Definition: rect.h:95
UIWidget::onMouseRelease
virtual bool onMouseRelease(const Point &mousePos, Fw::MouseButton button)
Definition: uiwidget.cpp:1575
UIWidget::updateText
virtual void updateText()
Definition: uiwidgettext.cpp:37
UIWidget::getFirstChild
UIWidgetPtr getFirstChild()
Definition: uiwidget.h:258
g_logger
Logger g_logger
Definition: logger.cpp:35
UIWidget::m_focusedChild
UIWidgetPtr m_focusedChild
Definition: uiwidget.h:76
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
TRect::united
TRect< T > united(const TRect< T > &r) const
Definition: rect.h:222
UIWidget::getChildrenRect
Rect getChildrenRect()
Definition: uiwidget.cpp:1068
stdext::shared_object_ptr::reset
void reset()
Definition: shared_object.h:79
UIWidget::lockChild
void lockChild(const UIWidgetPtr &child)
Definition: uiwidget.cpp:438
stdext::shared_object::static_self_cast
stdext::shared_object_ptr< T > static_self_cast()
Definition: shared_object.h:50
UIWidget::setChecked
void setChecked(bool checked)
Definition: uiwidget.cpp:966
UIWidget::getChildById
UIWidgetPtr getChildById(const std::string &childId)
Definition: uiwidget.cpp:1129
UIWidget::focusNextChild
void focusNextChild(Fw::FocusReason reason, bool rotate=false)
Definition: uiwidget.cpp:288
UIWidget::setOn
void setOn(bool on)
Definition: uiwidget.cpp:961
UIWidget::setDraggable
void setDraggable(bool draggable)
Definition: uiwidget.cpp:993
UIWidget::isFocusable
bool isFocusable()
Definition: uiwidget.h:242
Fw::OnState
@ OnState
Definition: const.h:275
UIWidget::m_lastFocusReason
Fw::FocusReason m_lastFocusReason
Definition: uiwidget.h:79
Fw::AnchorNone
@ AnchorNone
Definition: const.h:212
UIWidget::recursiveGetChildren
UIWidgetList recursiveGetChildren()
Definition: uiwidget.cpp:1191
EventDispatcher::addEvent
EventPtr addEvent(const std::function< void()> &callback, bool pushFront=false)
Definition: eventdispatcher.cpp:104
UIWidget::setState
bool setState(Fw::WidgetState state, bool on)
Definition: uiwidget.cpp:1249
UIWidget::drawChildren
virtual void drawChildren(const Rect &visibleRect, Fw::DrawPane drawPane)
Definition: uiwidget.cpp:106
UIWidget::backwardsGetWidgetById
UIWidgetPtr backwardsGetWidgetById(const std::string &id)
Definition: uiwidget.cpp:1239
UIWidget::m_style
OTMLNodePtr m_style
Definition: uiwidget.h:77
UIManager::resetMouseReceiver
void resetMouseReceiver()
Definition: uimanager.h:60
OTMLNode::clone
OTMLNodePtr clone()
Definition: otmlnode.cpp:179
UIWidget::propagateOnKeyUp
bool propagateOnKeyUp(uchar keyCode, int keyboardModifiers)
Definition: uiwidget.cpp:1669
UIManager::getKeyboardReceiver
UIWidgetPtr getKeyboardReceiver()
Definition: uimanager.h:63
Painter::drawBoundingRect
virtual void drawBoundingRect(const Rect &dest, int innerLineWidth=1)=0
UIWidget::getParent
UIWidgetPtr getParent()
Definition: uiwidget.h:255
Fw::AnchorTop
@ AnchorTop
Definition: const.h:213
Timer::restart
void restart()
Definition: timer.cpp:27
Timer::running
bool running()
Definition: timer.h:40
OTMLNode::size
int size()
Definition: otmlnode.h:37
UIWidget::onMousePress
virtual bool onMousePress(const Point &mousePos, Fw::MouseButton button)
Definition: uiwidget.cpp:1560
UIWidget::onDoubleClick
virtual bool onDoubleClick(const Point &mousePos)
Definition: uiwidget.cpp:1595
OTMLNode::get
OTMLNodePtr get(const std::string &childTag)
Definition: otmlnode.cpp:54
UIWidget::onClick
virtual bool onClick(const Point &mousePos)
Definition: uiwidget.cpp:1590
UIWidget::moveChildToIndex
void moveChildToIndex(const UIWidgetPtr &child, int index)
Definition: uiwidget.cpp:413
UIWidget::setParent
void setParent(const UIWidgetPtr &parent)
Definition: uiwidget.cpp:817
UIWidget::m_draggable
stdext::boolean< false > m_draggable
Definition: uiwidget.h:69
UIManager::resetKeyboardReceiver
void resetKeyboardReceiver()
Definition: uimanager.h:61
UILayout::update
void update()
Definition: uilayout.cpp:28
UIWidget::onChildFocusChange
virtual void onChildFocusChange(const UIWidgetPtr &focusedChild, const UIWidgetPtr &unfocusedChild, Fw::FocusReason reason)
Definition: uiwidget.cpp:1503
Color::aF
float aF() const
Definition: color.h:49
UIWidget::lowerChild
void lowerChild(UIWidgetPtr child)
Definition: uiwidget.cpp:374
UIWidget::propagateOnKeyText
bool propagateOnKeyText(const std::string &keyText)
Definition: uiwidget.cpp:1600
UIWidget::updateLayout
void updateLayout()
Definition: uiwidget.cpp:631
Painter::pushTransformMatrix
virtual void pushTransformMatrix()=0
UIWidget::setPhantom
void setPhantom(bool phantom)
Definition: uiwidget.cpp:988
g_app
ConsoleApplication g_app
Definition: consoleapplication.cpp:32
Fw::PressedState
@ PressedState
Definition: const.h:272
stdext::throw_exception
void throw_exception(const std::string &what)
Throws a generic exception.
Definition: exception.h:43
UIWidget::drawIcon
void drawIcon(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:380
UIWidget::getFocusedChild
UIWidgetPtr getFocusedChild()
Definition: uiwidget.h:256
UIWidget::isExplicitlyEnabled
bool isExplicitlyEnabled()
Definition: uiwidget.h:240
UIWidget::m_margin
EdgeGroup< int > m_margin
Definition: uiwidget.h:291
Painter::setClipRect
virtual void setClipRect(const Rect &clipRect)=0
UIWidget::onLayoutUpdate
virtual void onLayoutUpdate()
Definition: uiwidget.cpp:1493
Fw::AlternateState
@ AlternateState
Definition: const.h:279
UIWidget::setStyleFromNode
void setStyleFromNode(const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:919
stdext::split
std::vector< std::string > split(const std::string &str, const std::string &separators)
Definition: string.cpp:273
Fw::DisabledState
@ DisabledState
Definition: const.h:273
UILayout::disableUpdates
void disableUpdates()
Definition: uilayout.h:42
UIWidget::onKeyDown
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers)
Definition: uiwidget.cpp:1545
Timer::stop
void stop()
Definition: timer.h:34
UIWidget::m_children
UIWidgetList m_children
Definition: uiwidget.h:74
UIWidget::destroyChildren
void destroyChildren()
Definition: uiwidget.cpp:789
UIWidget::drawImage
void drawImage(const Rect &screenCoords)
Definition: uiwidgetimage.cpp:78
stdext::exception::what
virtual const char * what() const
Definition: exception.h:37
UIWidget::m_visible
stdext::boolean< true > m_visible
Definition: uiwidget.h:65
UIWidget::m_rotation
float m_rotation
Definition: uiwidget.h:294
UIWidget::m_phantom
stdext::boolean< false > m_phantom
Definition: uiwidget.h:68
UIWidget::grabKeyboard
void grabKeyboard()
Definition: uiwidget.cpp:721
uchar
unsigned char uchar
Definition: types.h:29
g_ui
UIManager g_ui
Definition: uimanager.cpp:33
UIWidget::isHovered
bool isHovered()
Definition: uiwidget.h:229
UIWidget::m_backgroundColor
Color m_backgroundColor
Definition: uiwidget.h:282
Fw::MouseWheelDirection
MouseWheelDirection
Definition: const.h:253
UIWidget::~UIWidget
virtual ~UIWidget()
Definition: uiwidget.cpp:49
Painter::getOpacity
float getOpacity()
Definition: painter.h:96
UIWidget::lower
void lower()
Definition: uiwidget.cpp:687
TRect::isValid
bool isValid() const
Definition: rect.h:50
TRect::setHeight
void setHeight(T height)
Definition: rect.h:86
otmlnode.h
Fw::DrawPane
DrawPane
Definition: const.h:285
UIWidget::recursiveFocus
void recursiveFocus(Fw::FocusReason reason)
Definition: uiwidget.cpp:675
stdext::shared_object_ptr< UIWidget >
Fw::InvalidState
@ InvalidState
Definition: const.h:267
Painter::getClipRect
Rect getClipRect()
Definition: painter.h:97
UIWidget::draw
virtual void draw(const Rect &visibleRect, Fw::DrawPane drawPane)
Definition: uiwidget.cpp:58
UIWidget::setFixedSize
void setFixedSize(bool fixed)
Definition: uiwidget.cpp:998
OTMLNode::merge
void merge(const OTMLNodePtr &node)
Definition: otmlnode.cpp:157
UIManager::onWidgetDestroy
void onWidgetDestroy(const UIWidgetPtr &widget)
Definition: uimanager.cpp:270
uimanager.h
UIWidget::removeAnchor
void removeAnchor(Fw::AnchorEdge anchoredEdge)
Definition: uiwidget.cpp:580
UIWidget::setLayout
void setLayout(const UILayoutPtr &layout)
Definition: uiwidget.cpp:843
UIWidget::hasState
bool hasState(Fw::WidgetState state)
Definition: uiwidget.cpp:1267
UIWidget::isExplicitlyVisible
bool isExplicitlyVisible()
Definition: uiwidget.h:241
Fw::ForegroundPane
@ ForegroundPane
Definition: const.h:286
UIWidget::m_enabled
stdext::boolean< true > m_enabled
Definition: uiwidget.h:64
UIWidget::UIWidget
UIWidget()
Definition: uiwidget.cpp:36
Application::isTerminated
bool isTerminated()
Definition: application.h:50
g_painter
Painter * g_painter
Definition: painter.cpp:28
UIWidget::setLastFocusReason
void setLastFocusReason(Fw::FocusReason reason)
Definition: uiwidget.cpp:1004
UIWidget::removeChild
void removeChild(UIWidgetPtr child)
Definition: uiwidget.cpp:217
UIWidget::setEnabled
void setEnabled(bool enabled)
Definition: uiwidget.cpp:926
UIWidget::setVisible
void setVisible(bool visible)
Definition: uiwidget.cpp:936
TRect::height
T height() const
Definition: rect.h:70
PlatformWindow::getMousePosition
Point getMousePosition()
Definition: platformwindow.h:83
UIWidget::onKeyText
virtual bool onKeyText(const std::string &keyText)
Definition: uiwidget.cpp:1540
TRect::intersection
TRect< T > intersection(const TRect< T > &r) const
Definition: rect.h:231
UIWidget::onMouseMove
virtual bool onMouseMove(const Point &mousePos, const Point &mouseMoved)
Definition: uiwidget.cpp:1580
UIWidget::m_destroyed
stdext::boolean< false > m_destroyed
Definition: uiwidget.h:70
UIWidget::setVirtualOffset
void setVirtualOffset(const Point &offset)
Definition: uiwidget.cpp:1014
UIWidget::getChildAfter
UIWidgetPtr getChildAfter(const UIWidgetPtr &relativeChild)
Definition: uiwidget.cpp:1113
UIWidget::isDestroyed
bool isDestroyed()
Definition: uiwidget.h:247
UIWidget::recursiveGetChildrenByPos
UIWidgetList recursiveGetChildrenByPos(const Point &childPos)
Definition: uiwidget.cpp:1203
UIAnchorLayoutPtr
stdext::shared_object_ptr< UIAnchorLayout > UIAnchorLayoutPtr
Definition: declarations.h:51
UIWidget::applyStyle
void applyStyle(const OTMLNodePtr &styleNode)
Definition: uiwidget.cpp:526
Fw::CheckedState
@ CheckedState
Definition: const.h:274
Fw::HiddenState
@ HiddenState
Definition: const.h:281
UIManager::isDrawingDebugBoxes
bool isDrawingDebugBoxes()
Definition: uimanager.h:71
Fw::AnchorVerticalCenter
@ AnchorVerticalCenter
Definition: const.h:217
TPoint< int >
TRect::size
TSize< T > size() const
Definition: rect.h:71
Fw::AnchorBottom
@ AnchorBottom
Definition: const.h:214
UIWidget::onDragLeave
virtual bool onDragLeave(UIWidgetPtr droppedWidget, const Point &mousePos)
Definition: uiwidget.cpp:1525
EdgeGroup::bottom
T bottom
Definition: uiwidget.h:42
Fw::translateState
WidgetState translateState(std::string state)
Definition: uitranslator.cpp:71
TRect::setWidth
void setWidth(T width)
Definition: rect.h:85
UIManager::setMouseReceiver
void setMouseReceiver(const UIWidgetPtr &widget)
Definition: uimanager.h:57
EdgeGroup::left
T left
Definition: uiwidget.h:43
UIWidget::onKeyUp
virtual bool onKeyUp(uchar keyCode, int keyboardModifiers)
Definition: uiwidget.cpp:1555
UIWidget::raiseChild
void raiseChild(UIWidgetPtr child)
Definition: uiwidget.cpp:394
UIWidget::setId
void setId(const std::string &id)
Definition: uiwidget.cpp:809
UIWidget::insertChild
void insertChild(int index, const UIWidgetPtr &child)
Definition: uiwidget.cpp:179
TRect::width
T width() const
Definition: rect.h:69
TRect::center
TPoint< T > center() const
Definition: rect.h:68
UIWidget::lock
void lock()
Definition: uiwidget.cpp:645
UIWidget::onKeyPress
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
Definition: uiwidget.cpp:1550
UIWidget::drawText
void drawText(const Rect &screenCoords)
Definition: uiwidgettext.cpp:83
Fw::AutoFocusPolicy
AutoFocusPolicy
Definition: const.h:228
UIWidget::isFocused
bool isFocused()
Definition: uiwidget.h:228
UIWidget::rotate
void rotate(float degrees)
Definition: uiwidget.h:219
UIManager::getMouseReceiver
UIWidgetPtr getMouseReceiver()
Definition: uimanager.h:62
UIWidget::m_clickTimer
Timer m_clickTimer
Definition: uiwidget.h:78
UIWidget::grabMouse
void grabMouse()
Definition: uiwidget.cpp:707
UIWidgetList
std::deque< UIWidgetPtr > UIWidgetList
Definition: declarations.h:53
UIWidget::recursiveGetChildById
UIWidgetPtr recursiveGetChildById(const std::string &id)
Definition: uiwidget.cpp:1160
UIWidget::getChildIndex
int getChildIndex(const UIWidgetPtr &child)
Definition: uiwidget.cpp:1043
Fw::DefaultState
@ DefaultState
Definition: const.h:268
Fw::LastState
@ LastState
Definition: const.h:278
UIWidget::setRect
bool setRect(const Rect &rect)
Definition: uiwidget.cpp:870
Fw::MouseButton
MouseButton
Definition: const.h:246
UIWidget::m_parent
UIWidgetPtr m_parent
Definition: uiwidget.h:73
Painter::setOpacity
virtual void setOpacity(float opacity)
Definition: painter.h:91
LuaInterface::evaluateExpression
void evaluateExpression(const std::string &expression, const std::string &source="lua expression")
Definition: luainterface.cpp:362
UIWidget::hasChild
bool hasChild(const UIWidgetPtr &child)
Definition: uiwidget.cpp:1035
UIWidget::propagateOnMouseEvent
bool propagateOnMouseEvent(const Point &mousePos, UIWidgetList &widgetList)
Definition: uiwidget.cpp:1691
application.h
Fw::AutoFocusNone
@ AutoFocusNone
Definition: const.h:229
Logger::warning
void warning(const std::string &what)
Definition: logger.h:53
UIWidget::drawBackground
void drawBackground(const Rect &screenCoords)
Definition: uiwidgetbasestyle.cpp:336
UIWidget::onVisibilityChange
virtual void onVisibilityChange(bool visible)
Definition: uiwidget.cpp:1513
stdext::exception
Definition: exception.h:31
UIWidget::isVisible
bool isVisible()
Definition: uiwidget.h:238
Fw::AnchorHorizontalCenter
@ AnchorHorizontalCenter
Definition: const.h:218
OTMLNode::create
static OTMLNodePtr create(std::string tag="", bool unique=false)
Definition: otmlnode.cpp:27
UIWidget::m_fixedSize
stdext::boolean< false > m_fixedSize
Definition: uiwidget.h:67