UIWidget.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #pragma once
  2. #include <ThirdParty/TurboBadger/tb_widgets.h>
  3. #include <ThirdParty/TurboBadger/tb_widgets_common.h>
  4. #include "../Core/Object.h"
  5. #include "UIPreferredSize.h"
  6. #include "UIDragObject.h"
  7. namespace Atomic
  8. {
  9. /// Defines widget visibility, used with UIWidget::SetVisibility.
  10. enum UI_WIDGET_VISIBILITY
  11. {
  12. /// Visible (default)
  13. UI_WIDGET_VISIBILITY_VISIBLE = tb:: WIDGET_VISIBILITY_VISIBLE,
  14. /// Invisible, but layouted. Interaction disabled.
  15. UI_WIDGET_VISIBILITY_INVISIBLE = tb::WIDGET_VISIBILITY_INVISIBLE,
  16. /// Invisible and no layout. Interaction disabled.
  17. UI_WIDGET_VISIBILITY_GONE = tb::WIDGET_VISIBILITY_GONE
  18. };
  19. /// TBWidget gravity (may be combined).
  20. /// Gravity gives hints about positioning and sizing preferences.
  21. enum UI_GRAVITY {
  22. UI_GRAVITY_NONE = tb::WIDGET_GRAVITY_NONE,
  23. UI_GRAVITY_LEFT = tb::WIDGET_GRAVITY_LEFT,
  24. UI_GRAVITY_RIGHT = tb::WIDGET_GRAVITY_RIGHT,
  25. UI_GRAVITY_TOP = tb::WIDGET_GRAVITY_TOP,
  26. UI_GRAVITY_BOTTOM = tb::WIDGET_GRAVITY_BOTTOM,
  27. UI_GRAVITY_LEFT_RIGHT = tb::WIDGET_GRAVITY_LEFT_RIGHT,
  28. UI_GRAVITY_TOP_BOTTOM = tb::WIDGET_GRAVITY_TOP_BOTTOM,
  29. UI_GRAVITY_ALL = tb::WIDGET_GRAVITY_ALL,
  30. UI_GRAVITY_DEFAULT = tb::WIDGET_GRAVITY_DEFAULT
  31. };
  32. enum UI_EVENT_TYPE {
  33. /** Click event is what should be used to trig actions in almost all cases.
  34. It is invoked on a widget after POINTER_UP if the pointer is still inside
  35. its hit area. It can also be invoked by keyboard on some clickable widgets
  36. (see TBWidget::SetClickByKey).
  37. If panning of scrollable widgets start while the pointer is down, CLICK
  38. won't be invoked when releasing the pointer (since that should stop panning). */
  39. UI_EVENT_TYPE_CLICK = tb::EVENT_TYPE_CLICK,
  40. /** Long click event is sent when the pointer has been down for some time
  41. without moving much.
  42. It is invoked on a widget that has enabled it (TBWidget::SetWantLongClick
  43. If this event isn't handled, the widget will invoke a CONTEXT_MENU event.
  44. If any of those are handled, the CLICK event that would normally be
  45. invoked after the pending POINTER_UP will be suppressed. */
  46. UI_EVENT_TYPE_LONG_CLICK = tb::EVENT_TYPE_LONG_CLICK,
  47. UI_EVENT_TYPE_POINTER_DOWN = tb::EVENT_TYPE_POINTER_DOWN,
  48. UI_EVENT_TYPE_POINTER_UP = tb::EVENT_TYPE_POINTER_UP,
  49. UI_EVENT_TYPE_POINTER_MOVE = tb::EVENT_TYPE_POINTER_MOVE,
  50. UI_EVENT_TYPE_RIGHT_POINTER_DOWN = tb::EVENT_TYPE_RIGHT_POINTER_DOWN,
  51. UI_EVENT_TYPE_RIGHT_POINTER_UP = tb::EVENT_TYPE_RIGHT_POINTER_UP,
  52. UI_EVENT_TYPE_WHEEL = tb::EVENT_TYPE_WHEEL,
  53. /** Invoked after changing text in a TBTextField, changing selected item
  54. in a TBSelectList etc. Invoking this event trigs synchronization with
  55. connected TBWidgetValue and other widgets connected to it. */
  56. UI_EVENT_TYPE_CHANGED = tb::EVENT_TYPE_CHANGED,
  57. UI_EVENT_TYPE_KEY_DOWN = tb::EVENT_TYPE_KEY_DOWN,
  58. UI_EVENT_TYPE_KEY_UP = tb::EVENT_TYPE_KEY_UP,
  59. /** Invoked by the platform when a standard keyboard shortcut is pressed.
  60. It's called before InvokeKeyDown (EVENT_TYPE_KEY_DOWN) and if the event
  61. is handled (returns true), the KeyDown is canceled.
  62. The ref_id will be set to one of the following:
  63. "cut", "copy", "paste", "selectall", "undo", "redo", "new", "open", "save". */
  64. UI_EVENT_TYPE_SHORTCUT = tb::EVENT_TYPE_SHORTCUT,
  65. /** Invoked when a context menu should be opened at the event x and y coordinates.
  66. It may be invoked automatically for a widget on long click, if nothing handles
  67. the long click event. */
  68. UI_EVENT_TYPE_CONTEXT_MENU = tb::EVENT_TYPE_CONTEXT_MENU,
  69. /** Invoked by the platform when one or multiple files has been dropped on
  70. the widget. The event is guaranteed to be a TBWidgetEventFileDrop. */
  71. UI_EVENT_TYPE_FILE_DROP = tb::EVENT_TYPE_FILE_DROP,
  72. /** Invoked by the platform when a tab container's tab changed */
  73. UI_EVENT_TYPE_TAB_CHANGED = tb::EVENT_TYPE_TAB_CHANGED,
  74. /** Custom event. Not used internally. ref_id may be used for additional type info. */
  75. UI_EVENT_TYPE_CUSTOM = tb::EVENT_TYPE_CUSTOM
  76. };
  77. class UILayoutParams;
  78. class UIFontDescription;
  79. /// Wraps a TurboBadger widget in our Object model
  80. class UIWidget : public Object, public tb::TBWidgetDelegate
  81. {
  82. friend class UI;
  83. OBJECT(UIWidget)
  84. public:
  85. UIWidget(Context* context, bool createWidget = true);
  86. virtual ~UIWidget();
  87. bool Load(const String& filename);
  88. const String& GetId();
  89. UIWidget* GetParent();
  90. UIWidget* GetContentRoot();
  91. IntRect GetRect();
  92. UIPreferredSize* GetPreferredSize();
  93. void SetRect(IntRect r);
  94. void SetSize(int width, int height);
  95. void SetPosition(int x, int y);
  96. void SetText(const String& text);
  97. void SetSkinBg(const String& id);
  98. void SetLayoutParams(UILayoutParams* params);
  99. void SetFontDescription(UIFontDescription* fd);
  100. void RemoveChild(UIWidget* child, bool cleanup = true);
  101. void DeleteAllChildren();
  102. // String ID
  103. virtual void SetId(const String& id);
  104. void Center();
  105. void SetGravity(UI_GRAVITY gravity);
  106. void SetValue(double value);
  107. double GetValue();
  108. void SetFocus();
  109. void SetState(/*WIDGET_STATE*/ unsigned state, bool on);
  110. bool GetState(/*WIDGET_STATE*/ unsigned state);
  111. void SetVisibility(UI_WIDGET_VISIBILITY visibility);
  112. UI_WIDGET_VISIBILITY GetVisibility();
  113. void SetStateRaw(/*WIDGET_STATE*/ unsigned state);
  114. /*WIDGET_STATE*/ unsigned GetStateRaw();
  115. void Invalidate();
  116. void Die();
  117. void SetDragObject(UIDragObject* object) { dragObject_ = object; }
  118. UIDragObject* GetDragObject() { return dragObject_; }
  119. UIWidget* GetFirstChild();
  120. UIWidget* GetNext();
  121. bool IsAncestorOf(UIWidget* widget);
  122. void SetIsFocusable(bool value);
  123. // get this or child widget with id
  124. UIWidget* GetWidget(const String& id);
  125. virtual void AddChild(UIWidget* child);
  126. tb::TBWidget* GetInternalWidget() { return widget_; }
  127. protected:
  128. void ConvertEvent(UIWidget* handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data);
  129. void SetWidget(tb::TBWidget* widget);
  130. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  131. virtual void OnDelete();
  132. String id_;
  133. tb::TBWidget* widget_;
  134. SharedPtr<UIPreferredSize> preferredSize_;
  135. SharedPtr<UIDragObject> dragObject_;
  136. };
  137. }