TreeNode.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. GWEN
  3. Copyright (c) 2011 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_TREENODE_H
  8. #define GWEN_CONTROLS_TREENODE_H
  9. #include "Gwen/Controls/Base.h"
  10. #include "Gwen/Controls/Button.h"
  11. #include "Gwen/Controls/ScrollControl.h"
  12. enum
  13. {
  14. ITERATE_ACTION_OPEN=1,
  15. ITERATE_ACTION_CLOSE,
  16. ITERATE_ACTION_FIND_SELECTED_INDEX,
  17. ITERATE_ACTION_DESELECT_INDEX,
  18. ITERATE_ACTION_SELECT,
  19. };
  20. namespace Gwen
  21. {
  22. namespace Controls
  23. {
  24. class TreeControl;
  25. class GWEN_EXPORT TreeNode : public Base
  26. {
  27. public:
  28. GWEN_CONTROL( TreeNode, Base );
  29. virtual TreeNode* AddNode( const UnicodeString& strLabel );
  30. virtual TreeNode* AddNode( const String& strLabel );
  31. virtual void SetText( const UnicodeString& text );
  32. virtual void SetText( const String& text );
  33. UnicodeString GetText() const;
  34. virtual void Open();
  35. virtual void Close();
  36. virtual void ExpandAll();
  37. virtual Button* GetButton();
  38. virtual void Render( Skin::Base* skin );
  39. virtual void Layout( Skin::Base* skin );
  40. virtual void PostLayout( Skin::Base* skin );
  41. virtual void SetRoot( bool b ){ m_bRoot = b; }
  42. virtual void SetTreeControl( TreeControl* pCtrl ){ m_TreeControl = pCtrl; }
  43. virtual void SetSelectable( bool b ){ m_bSelectable = b; }
  44. virtual bool IsSelected(){ return m_bSelected; }
  45. virtual void SetSelected( bool b );
  46. virtual void DeselectAll();
  47. virtual void iterate(int action, int* curIndex, int* resultIndex);
  48. virtual bool OnKeyReturn(bool bDown)
  49. {
  50. static bool prevDown = false;
  51. if (!prevDown && bDown)
  52. {
  53. onReturnKeyDown.Call(this);
  54. }
  55. prevDown = bDown;
  56. return Base::OnKeyReturn(bDown);
  57. }
  58. Event::Caller onReturnKeyDown;
  59. Event::Caller onNamePress;
  60. Event::Caller onSelectChange;
  61. Event::Caller onSelect;
  62. Event::Caller onUnselect;
  63. protected:
  64. void OnToggleButtonPress( Base* control );
  65. void OnDoubleClickName( Base* control );
  66. void OnClickName( Base* control );
  67. TreeControl* m_TreeControl;
  68. Button* m_ToggleButton;
  69. Button* m_Title;
  70. bool m_bRoot;
  71. bool m_bSelected;
  72. bool m_bSelectable;
  73. int m_bUpdateScrollBar;
  74. };
  75. }
  76. }
  77. #endif