ElementTabSet.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCONTROLSELEMENTTABSET_H
  28. #define ROCKETCONTROLSELEMENTTABSET_H
  29. #include <Rocket/Core/Element.h>
  30. #include <Rocket/Core/EventListener.h>
  31. #include <Rocket/Controls/Header.h>
  32. namespace Rocket {
  33. namespace Controls {
  34. /**
  35. A tabulated set of panels.
  36. @author Lloyd Weehuizen
  37. */
  38. class ROCKETCONTROLS_API ElementTabSet : public Core::Element, public Core::EventListener
  39. {
  40. public:
  41. ElementTabSet(const Rocket::Core::String& tag);
  42. ~ElementTabSet();
  43. /// Sets the specifed tab index's tab title RML.
  44. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  45. /// @param[in] rml The RML to set on the tab title.
  46. void SetTab(int tab_index, const Rocket::Core::String& rml);
  47. /// Sets the specifed tab index's tab panel RML.
  48. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  49. /// @param[in] rml The RML to set on the tab panel.
  50. void SetPanel(int tab_index, const Rocket::Core::String& rml);
  51. /// Set the specifed tab index's title element.
  52. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  53. /// @param[in] element The root of the element tree to set as the tab title.
  54. void SetTab(int tab_index, Core::Element* element);
  55. /// Set the specified tab index's body element.
  56. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  57. /// @param[in] element The root of the element tree to set as the window.
  58. void SetPanel(int tab_index, Core::Element* element);
  59. /// Remove one of the tab set's panels and its corresponding tab.
  60. /// @param[in] tab_index The tab index to remove. If no tab matches this index, nothing will be removed.
  61. void RemoveTab(int tab_index);
  62. /// Retrieve the number of tabs in the tabset.
  63. /// @return The number of tabs.
  64. int GetNumTabs();
  65. /// Sets the currently active (visible) tab index.
  66. /// @param[in] tab_index Index of the tab to display.
  67. void SetActiveTab(int tab_index);
  68. /// Get the current active tab index.
  69. /// @return The index of the active tab.
  70. int GetActiveTab() const;
  71. /// Process the incoming event.
  72. void ProcessEvent(Core::Event& event);
  73. protected:
  74. // Catch child add/removes so we can correctly set up their events.
  75. virtual void OnChildAdd(Core::Element* child);
  76. virtual void OnChildRemove(Core::Element* child);
  77. private:
  78. Core::Element* GetChildByTag(const Rocket::Core::String& tag);
  79. int active_tab;
  80. };
  81. }
  82. }
  83. #endif