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