SimpleWindow
载入中...
搜索中...
未找到
TreeView.h
1#include "Control.h"
2#include "ImageList.h"
3#include <commctrl.h>
4
5namespace sw
6{
10 enum class TreeViewImageList {
13 };
14
18 class TreeViewNode : public IToString<TreeViewNode>,
19 public IEqualityComparable<TreeViewNode>
20 {
21 private:
25 HWND _hwnd;
26
30 HTREEITEM _hitem;
31
32 public:
36 TreeViewNode() = default;
37
42
47
52
56 std::wstring ToString() const;
57
61 bool Equals(const TreeViewNode &other) const;
62
66 bool IsNull() const;
67
71 explicit operator bool() const;
72
76 std::wstring GetText() const;
77
82 bool SetText(const std::wstring &text);
83
89
95
101
107
112 TreeViewNode InsertAfter(const std::wstring &text);
113
118 TreeViewNode AddChild(const std::wstring &text);
119
124 bool IsSelected() const;
125
130 bool Select();
131
136 bool Delete();
137
142 bool IsExpanded() const;
143
148 bool SetExpand(bool expand);
149
154 bool Expand();
155
160 bool Collapse();
161
165 void *GetUserData() const;
166
171 bool SetUserData(void *data);
172
177 bool IsChecked() const;
178
182 void SetCheck(bool check);
183
188 bool SetImages(int imageIndex, int selectedImageIndex);
189
193 int GetChildCount() const;
194
200 };
201
205 class TreeViewItemExpandingEventArgs : public TypedRoutedEventArgs<TreeView_ItemExpanding, CancelableEventArgs>
206 {
207 public:
209 bool action;
210
213
221 };
222
226 class TreeViewItemExpandedEventArgs : public TypedRoutedEventArgs<TreeView_ItemExpanding>
227 {
228 public:
230 bool action;
231
234
242 };
243
247 class TreeViewCheckStateChangedEventArgs : public TypedRoutedEventArgs<TreeView_CheckStateChanged>
248 {
249 public:
252
255
263 };
264
268 class TreeView : public Control
269 {
270 private:
274 using TBase = Control;
275
276 public:
281
286
291
296
301
306
307 public:
312
313 protected:
319 virtual void OnSetBackColor(Color color, bool redraw) override;
320
326 virtual void OnSetTextColor(Color color, bool redraw) override;
327
334 virtual bool OnNotified(NMHDR *pNMHDR, LRESULT &result) override;
335
339 virtual void OnSelectionChanged();
340
348
356
362
369
375
381
382 public:
386 void Clear();
387
393 TreeViewNode AddItem(const std::wstring &text);
394
400
407
408 private:
412 TreeViewNode _GetRoot();
413
417 TreeViewNode _GetSelectedItem();
418
422 TreeViewNode _InsertItem(HTREEITEM hParent, HTREEITEM hInsertAfter, const std::wstring &text);
423 };
424}
控件
Definition Control.h:12
Control()
初始化控件
相等性比较接口
Definition IComparable.h:14
为支持ToString方法的类提供统一接口
Definition IToString.h:13
值转换器接口
Definition IValueConverter.h:14
Win32图像列表句柄的RAII包装
Definition ImageList.h:15
树视图节点复选框状态改变事件参数类型
Definition TreeView.h:248
int checkState
复选框的新状态,0表示未选中,1表示选中,-1表示无复选框
Definition TreeView.h:251
TreeViewNode node
复选框状态改变的节点
Definition TreeView.h:254
TreeViewCheckStateChangedEventArgs(int checkState, const TreeViewNode &node)
构造函数
Definition TreeView.h:259
树视图节点已展开或折叠事件参数类型
Definition TreeView.h:227
TreeViewNode node
已展开或折叠的节点
Definition TreeView.h:233
TreeViewItemExpandedEventArgs(bool action, const TreeViewNode &node)
构造函数
Definition TreeView.h:238
bool action
true表示展开,false表示折叠
Definition TreeView.h:230
树视图节点正在展开或折叠事件参数类型
Definition TreeView.h:206
TreeViewItemExpandingEventArgs(bool action, const TreeViewNode &node)
构造函数
Definition TreeView.h:217
TreeViewNode node
正在展开或折叠的节点
Definition TreeView.h:212
bool action
true表示展开,false表示折叠
Definition TreeView.h:209
树视图项
Definition TreeView.h:20
bool IsExpanded() const
判断当前节点是否展开
bool IsNull() const
判断当前项是否为空
bool SetExpand(bool expand)
设置当前节点展开或折叠
HTREEITEM GetHandle() const
获取当前项的句柄
bool SetImages(int imageIndex, int selectedImageIndex)
设置当前节点的图像
bool Expand()
展开当前节点
TreeViewNode()=default
默认构造函数
int DeleteAllChildren()
删除当前节点的所有子节点
bool Delete()
删除当前节点
bool SetText(const std::wstring &text)
设置当前项的文本
TreeViewNode GetParent() const
获取父节点
HWND GetOwnerHandle() const
获取所属树视图控件的窗口句柄
bool SetUserData(void *data)
设置与当前节点关联的用户数据
TreeViewNode GetNextNode() const
获取下一个节点
TreeViewNode GetPreviousNode() const
获取上一个节点
int GetChildCount() const
获取当前节点的直接子节点数
bool Collapse()
折叠当前节点
void SetCheck(bool check)
设置当前节点的复选框选中状态
std::wstring ToString() const
获取当前项的文本
void * GetUserData() const
获取与当前节点关联的用户数据
bool Select()
选中当前节点
std::wstring GetText() const
获取当前项的文本
TreeViewNode GetFirstChildNode() const
获取第一个子节点
TreeViewNode AddChild(const std::wstring &text)
添加子节点到当前节点下
bool IsSelected() const
判断当前节点是否被选中
TreeViewNode(HWND hwnd, HTREEITEM hitem)
创建TreeViewItem
bool IsChecked() const
判断当前节点是否被选中复选框
bool Equals(const TreeViewNode &other) const
判断当前项与另一个项是否相等
TreeViewNode InsertAfter(const std::wstring &text)
在当前节点后插入新节点
树视图控件
Definition TreeView.h:269
const Property< double > IndentWidth
缩进宽度
Definition TreeView.h:305
virtual bool OnNotified(NMHDR *pNMHDR, LRESULT &result) override
父窗口接收到WM_NOTIFY后且父窗口OnNotify函数返回false时调用发出通知控件的该函数
virtual void OnGetDispInfo(NMTVDISPINFOW *pNMInfo)
当OnNotified接收到TVN_GETDISPINFO通知时调用该函数
virtual bool OnItemExpanding(NMTREEVIEWW *pNMTV)
节点展开或折叠前调用该函数
virtual void OnSetBackColor(Color color, bool redraw) override
设置背景颜色
const Property< Color > LineColor
线条颜色
Definition TreeView.h:300
virtual bool OnDoubleClicked(NMHDR *pNMHDR, LRESULT &result)
控件被双击时调用该函数
const Property< bool > CheckBoxes
是否在第一列显示复选框
Definition TreeView.h:295
const ReadOnlyProperty< TreeViewNode > SelectedItem
选中的节点,若无选中节点则返回空节点
Definition TreeView.h:285
HIMAGELIST SetImageList(TreeViewImageList imageList, HIMAGELIST value)
设置指定类型的图像列表
TreeViewNode AddItem(const std::wstring &text)
添加新节点到根节点
virtual void OnSelectionChanged()
选中的节点发生改变时调用该函数
ImageList GetImageList(TreeViewImageList imageList)
获取指定类型的图像列表
TreeView()
初始化TreeView
virtual void OnItemChanged(NMTVITEMCHANGE *pNMInfo)
节点某些属性发生变化时调用该函数
void Clear()
清空所有节点
virtual void OnSetTextColor(Color color, bool redraw) override
设置文本颜色
const ReadOnlyProperty< TreeViewNode > Root
根节点
Definition TreeView.h:280
virtual bool OnClicked(NMHDR *pNMHDR, LRESULT &result)
控件被单机时调用该函数
const ReadOnlyProperty< int > AllItemsCount
所有节点数
Definition TreeView.h:290
virtual void OnItemExpanded(NMTREEVIEWW *pNMTV)
节点展开或折叠后调用该函数
表示特定类型路由事件的事件参数类型,继承自该类的类型可以直接作为AddHandler函数的模板参数
Definition RoutedEventArgs.h:19
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4
TreeViewImageList
树视图的图像列表枚举
Definition TreeView.h:10
@ Normal
位图置于BmpBox左上角
@ State
包含状态图像的图像列表
颜色
Definition Color.h:16