File: TreeControl.h

package info (click to toggle)
mygui 3.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,224 kB
  • sloc: cpp: 118,031; ansic: 30,202; xml: 15,544; cs: 12,602; tcl: 776; python: 417; makefile: 34
file content (173 lines) | stat: -rw-r--r-- 4,102 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*!
	@file
	@author     Pavel Turin
	@date       08/2009
*/
#ifndef TREE_CONTROL_H_
#define TREE_CONTROL_H_

#include "GenericNode.h"

namespace MyGUI
{
	class TreeControlItem;

	class TreeControl :
		public Widget
	{
		MYGUI_RTTI_DERIVED( TreeControl )

	public:
		class Node;

		typedef delegates::CMultiDelegate2<TreeControl*, Node*> EventHandle_TreeControlPtrNodePtr;
		typedef delegates::CMultiDelegate2<TreeControl*, size_t> EventHandle_TreeControlPtrSizeT;

		class Node :
			public GenericNode<Node, TreeControl>
		{
		public:
			Node();
			Node(TreeControl* pOwner);
			Node(const UString& strText, Node* pParent = nullptr);
			Node(const UString& strText, const UString& strImage, Node* pParent = nullptr);
			virtual ~Node();

			bool isPrepared() const;
			void setPrepared(bool bIsPrepared);
			void prepare();
			size_t prepareChildren();

			bool isExpanded() const;
			void setExpanded(bool bIsExpanded);

			const UString& getImage() const;
			void setImage(const UString& strImage);

			void setData(Any Data);
			template <typename TYPE>
			TYPE* getData() const;

		private:
			bool mbIsPrepared;
			bool mbIsExpanded;
			UString mstrImage;
			Any mData;
		};

		typedef Node::VectorGenericNodePtr VectorNodePtr;

		TreeControl();

		Node* getRoot() const;
		void setRootVisible(bool bValue);
		bool isRootVisible() const;

		Node* getSelection() const;
		void setSelection(Node* pSelection);

		void invalidate();

		virtual void setSize(const IntSize& Size);
		virtual void setCoord(const IntCoord& Bounds);

		EventHandle_TreeControlPtrNodePtr eventTreeNodeMouseSetFocus;
		EventHandle_TreeControlPtrNodePtr eventTreeNodeMouseLostFocus;
		EventHandle_TreeControlPtrNodePtr eventTreeNodeSelected;
		EventHandle_TreeControlPtrNodePtr eventTreeNodeActivated;
		EventHandle_TreeControlPtrNodePtr eventTreeNodeContextMenu;
		EventHandle_TreeControlPtrNodePtr eventTreeNodePrepare;
		EventHandle_TreeControlPtrSizeT eventTreeScrolled;

	protected:
		virtual void initialiseOverride();
		virtual void shutdownOverride();

		void notifyMousePressed(Widget* pSender, int nLeft, int nTop, MouseButton nID);
		void notifyMouseWheel(Widget* pSender, int nValue);
		void notifyMouseDoubleClick(Widget* pSender);
		void notifyMouseSetFocus(Widget* pSender, Widget* pPreviousWidget);
		void notifyMouseLostFocus(Widget* pSender, Widget* pNextWidget);
		void notifyScrollChangePosition(ScrollBar* pSender, size_t nPosition);
		void notifyExpandCollapse(Widget* pSender);
		void notifyFrameEntered(float nTime);

		virtual void onMouseWheel(int nValue);
		virtual void onKeyButtonPressed(KeyCode Key, Char Character);

	private:
		typedef std::vector<TreeControlItem*> VectorTreeItemPtr;

		void validate();

		void updateScroll();
		void updateItems();

		void scrollTo(size_t nPosition);
		void sendScrollingEvents(size_t nPosition);

		ScrollBar* mpWidgetScroll;
		VectorTreeItemPtr mItemWidgets;
		UString mstrSkinLine;
		bool mbScrollAlwaysVisible;
		bool mbInvalidated;
		bool mbRootVisible;
		int mnItemHeight;
		int mnScrollRange;
		int mnTopIndex;
		int mnTopOffset;
		size_t mnFocusIndex;
		Node* mpSelection;
		Node* mpRoot;
		size_t mnExpandedNodes;
		int mnLevelOffset;

		Widget* mClient;
	};


	inline TreeControl::Node::Node() :
		mbIsPrepared(false),
		mbIsExpanded(true)
	{ }
	inline bool TreeControl::Node::isPrepared() const
	{
		return mbIsPrepared;
	}
	inline void TreeControl::Node::setPrepared(bool bIsPrepared)
	{
		mbIsPrepared = bIsPrepared;
	}
	inline bool TreeControl::Node::isExpanded() const
	{
		return mbIsExpanded;
	}
	inline const UString& TreeControl::Node::getImage() const
	{
		return mstrImage;
	}
	inline void TreeControl::Node::setData(Any Data)
	{
		mData = Data;
	}
	template <typename TYPE>
	TYPE* TreeControl::Node::getData() const
	{
		return mData.castType<TYPE>(true);
	}

	inline TreeControl::Node* TreeControl::getRoot() const
	{
		return mpRoot;
	}
	inline bool TreeControl::isRootVisible() const
	{
		return mbRootVisible;
	}
	inline TreeControl::Node* TreeControl::getSelection() const
	{
		return mpSelection;
	}
}

#endif // TREE_CONTROL_H_