tb_tab_container.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_TAB_CONTAINER_H
  6. #define TB_TAB_CONTAINER_H
  7. #include "tb_widgets_common.h"
  8. namespace tb {
  9. class TBTabContainer;
  10. /** TBTabLayout is a TBLayout used in TBTabContainer to apply
  11. some default properties on any TBButton added to it. */
  12. class TBTabLayout : public TBLayout
  13. {
  14. public:
  15. // For safe typecasting
  16. TBOBJECT_SUBCLASS(TBTabLayout, TBLayout);
  17. TBTabLayout(TBTabContainer *tabContainer)
  18. : tabContainer_(tabContainer) {}
  19. virtual void OnChildAdded(TBWidget *child);
  20. virtual void OnChildRemove(TBWidget *child);
  21. virtual PreferredSize OnCalculatePreferredContentSize(const SizeConstraints &constraints);
  22. private:
  23. TBTabContainer *tabContainer_;
  24. };
  25. /** TBTabContainer - A container with tabs for multiple pages. */
  26. class TBTabContainer : public TBWidget
  27. {
  28. friend class TBTabLayout;
  29. public:
  30. // For safe typecasting
  31. TBOBJECT_SUBCLASS(TBTabContainer, TBWidget);
  32. TBTabContainer();
  33. ~TBTabContainer();
  34. /** Set along which axis the content should layouted.
  35. Use SetAlignment instead for more choice! Also, calling
  36. SetAxis directly does not update the current alignment. */
  37. virtual void SetAxis(AXIS axis);
  38. virtual AXIS GetAxis() const { return m_root_layout.GetAxis(); }
  39. /** Set alignment of the tabs. */
  40. void SetAlignment(TB_ALIGN align);
  41. TB_ALIGN GetAlignment() const { return m_align; }
  42. /** Set which page should be selected and visible. */
  43. virtual void SetValue(int value);
  44. virtual int GetValue() { return m_current_page; }
  45. /** Set which page should be selected and visible. */
  46. void SetCurrentPage(int index) { SetValue(index); }
  47. int GetCurrentPage() { return GetValue(); }
  48. int GetNumPages();
  49. /** Return the widget that is the current page, or nullptr if none is active. */
  50. TBWidget *GetCurrentPageWidget() const;
  51. virtual void OnInflate(const INFLATE_INFO &info);
  52. virtual bool OnEvent(const TBWidgetEvent &ev);
  53. virtual void OnProcess();
  54. virtual TBWidget *GetContentRoot() { return &m_content_root; }
  55. TBLayout *GetTabLayout() { return &m_tab_layout; }
  56. // ATOMIC BEGIN
  57. virtual void UndockPage ( int page ); /// undocks the page into a window with the tab name, and removes the tab
  58. virtual bool DockFromWindow ( TBStr windowTitle ); /// takes the contents of a DockWindow into a tab in a tabcontainer
  59. // ATOMIC END
  60. protected:
  61. TBLayout m_root_layout;
  62. TBTabLayout m_tab_layout;
  63. TBWidget m_content_root;
  64. bool m_need_page_update;
  65. int m_current_page;
  66. TB_ALIGN m_align;
  67. };
  68. };
  69. #endif // TB_TAB_CONTAINER_H