DropDownList.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  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. #pragma once
  23. #include "Menu.h"
  24. namespace Atomic
  25. {
  26. namespace SystemUI
  27. {
  28. class ListView;
  29. /// %Menu %UI element that displays a popup list view.
  30. class ATOMIC_API DropDownList : public Menu
  31. {
  32. OBJECT(DropDownList)
  33. public:
  34. /// Construct.
  35. DropDownList(Context* context);
  36. /// Destruct.
  37. ~DropDownList();
  38. /// Register object factory.
  39. static void RegisterObject(Context* context);
  40. /// Apply attribute changes that can not be applied immediately.
  41. virtual void ApplyAttributes();
  42. /// Return UI rendering batches.
  43. virtual void GetBatches(PODVector<SystemUIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
  44. /// React to the popup being shown.
  45. virtual void OnShowPopup();
  46. /// React to the popup being hidden.
  47. virtual void OnHidePopup();
  48. /// React to editable status change.
  49. virtual void OnSetEditable();
  50. /// Add item to the end of the list.
  51. void AddItem(UIElement* item);
  52. /// Insert item to a specific position.
  53. void InsertItem(unsigned index, UIElement* item);
  54. /// Remove specific item.
  55. void RemoveItem(UIElement* item);
  56. /// Remove item at index.
  57. void RemoveItem(unsigned index);
  58. /// Remove all items.
  59. void RemoveAllItems();
  60. /// Set selection.
  61. void SetSelection(unsigned index);
  62. /// Set place holder text. This is the text shown when there is no selection in drop down list.
  63. void SetPlaceholderText(const String& text);
  64. /// Set whether popup should be automatically resized to match the dropdown button width.
  65. void SetResizePopup(bool enable);
  66. /// Return number of items.
  67. unsigned GetNumItems() const;
  68. /// Return item at index.
  69. UIElement* GetItem(unsigned index) const;
  70. /// Return all items.
  71. PODVector<UIElement*> GetItems() const;
  72. /// Return selection index, or M_MAX_UNSIGNED if none selected.
  73. unsigned GetSelection() const;
  74. /// Return selected item, or null if none selected.
  75. UIElement* GetSelectedItem() const;
  76. /// Return listview element.
  77. ListView* GetListView() const { return listView_; }
  78. /// Return selected item placeholder element.
  79. UIElement* GetPlaceholder() const { return placeholder_; }
  80. /// Return place holder text.
  81. const String& GetPlaceholderText() const;
  82. /// Return whether popup should be automatically resized.
  83. bool GetResizePopup() const { return resizePopup_; }
  84. /// Set selection attribute.
  85. void SetSelectionAttr(unsigned index);
  86. protected:
  87. /// Filter implicit attributes in serialization process.
  88. virtual bool FilterImplicitAttributes(XMLElement& dest) const;
  89. /// Filter implicit attributes in serialization process.
  90. virtual bool FilterPopupImplicitAttributes(XMLElement& dest) const;
  91. /// Listview element.
  92. SharedPtr<ListView> listView_;
  93. /// Selected item placeholder element.
  94. SharedPtr<UIElement> placeholder_;
  95. /// Resize popup flag.
  96. bool resizePopup_;
  97. private:
  98. /// Handle listview item click event.
  99. void HandleItemClicked(StringHash eventType, VariantMap& eventData);
  100. /// Handle a key press from the listview
  101. void HandleListViewKey(StringHash eventType, VariantMap& eventData);
  102. /// Selected item index attribute.
  103. unsigned selectionAttr_;
  104. };
  105. }
  106. }