]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/treectrl.h
added some wxMSW stuff
[wxWidgets.git] / include / wx / msw / treectrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treectrl.h
3 // Purpose: wxTreeCtrl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __TREECTRLH__
13 #define __TREECTRLH__
14
15 #ifdef __GNUG__
16 #pragma interface "treectrl.h"
17 #endif
18
19 #include "wx/control.h"
20 #include "wx/event.h"
21 #include "wx/imaglist.h"
22
23 // WXDLLEXPORT_DATA(extern const char*) wxTreeNameStr;
24
25 #define wxTREE_MASK_HANDLE 0x0001
26 #define wxTREE_MASK_STATE 0x0002
27 #define wxTREE_MASK_TEXT 0x0004
28 #define wxTREE_MASK_IMAGE 0x0008
29 #define wxTREE_MASK_SELECTED_IMAGE 0x0010
30 #define wxTREE_MASK_CHILDREN 0x0020
31 #define wxTREE_MASK_DATA 0x0040
32
33 #define wxTREE_STATE_BOLD 0x0001
34 #define wxTREE_STATE_DROPHILITED 0x0002
35 #define wxTREE_STATE_EXPANDED 0x0004
36 #define wxTREE_STATE_EXPANDEDONCE 0x0008
37 #define wxTREE_STATE_FOCUSED 0x0010
38 #define wxTREE_STATE_SELECTED 0x0020
39 #define wxTREE_STATE_CUT 0x0040
40
41 #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area.
42 #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area.
43 #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
44 #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item.
45 #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
46 #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item.
47 #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
48 #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
49 #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
50 #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area.
51 #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area.
52
53 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL wxTREE_HITTEST_ONITEMSTATEICON)
54
55 // Flags for GetNextItem
56 enum {
57 wxTREE_NEXT_CARET, // Retrieves the currently selected item.
58 wxTREE_NEXT_CHILD, // Retrieves the first child item. The hItem parameter must be NULL.
59 wxTREE_NEXT_DROPHILITE, // Retrieves the item that is the target of a drag-and-drop operation.
60 wxTREE_NEXT_FIRSTVISIBLE, // Retrieves the first visible item.
61 wxTREE_NEXT_NEXT, // Retrieves the next sibling item.
62 wxTREE_NEXT_NEXTVISIBLE, // Retrieves the next visible item that follows the specified item.
63 wxTREE_NEXT_PARENT, // Retrieves the parent of the specified item.
64 wxTREE_NEXT_PREVIOUS, // Retrieves the previous sibling item.
65 wxTREE_NEXT_PREVIOUSVISIBLE, // Retrieves the first visible item that precedes the specified item.
66 wxTREE_NEXT_ROOT // Retrieves the first child item of the root item of which the specified item is a part.
67 };
68
69 // Flags for ExpandItem
70 enum {
71 wxTREE_EXPAND_EXPAND,
72 wxTREE_EXPAND_COLLAPSE,
73 wxTREE_EXPAND_COLLAPSE_RESET,
74 wxTREE_EXPAND_TOGGLE
75 };
76
77 // Flags for InsertItem
78 enum {
79 wxTREE_INSERT_LAST = -1,
80 wxTREE_INSERT_FIRST = -2,
81 wxTREE_INSERT_SORT = -3
82 };
83
84 class WXDLLEXPORT wxTreeItem: public wxObject
85 {
86 DECLARE_DYNAMIC_CLASS(wxTreeItem)
87 public:
88 long m_mask;
89 long m_itemId;
90 long m_state;
91 long m_stateMask;
92 wxString m_text;
93 int m_image;
94 int m_selectedImage;
95 int m_children;
96 long m_data;
97
98 wxTreeItem(void);
99 };
100
101 class WXDLLEXPORT wxTreeCtrl: public wxControl
102 {
103 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
104 public:
105 /*
106 * Public interface
107 */
108
109 wxTreeCtrl(void);
110
111 inline wxTreeCtrl(wxWindow *parent, const wxWindowID id = -1,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 const long style = wxTR_HAS_BUTTONS,
115 const wxValidator& validator = wxDefaultValidator,
116 const wxString& name = "wxTreeCtrl")
117 {
118 Create(parent, id, pos, size, style, validator, name);
119 }
120 ~wxTreeCtrl(void);
121
122 bool Create(wxWindow *parent, const wxWindowID id = -1,
123 const wxPoint& pos = wxDefaultPosition,
124 const wxSize& size = wxDefaultSize,
125 const long style = wxTR_HAS_BUTTONS,
126 const wxValidator& validator = wxDefaultValidator,
127 const wxString& name = "wxTreeCtrl");
128
129 // Attributes
130 int GetCount(void) const ;
131 int GetIndent(void) const ;
132 void SetIndent(int indent) ;
133 wxImageList *GetImageList(const int which = wxIMAGE_LIST_NORMAL) const ;
134 void SetImageList(wxImageList *imageList, const int which = wxIMAGE_LIST_NORMAL) ;
135 long GetNextItem(const long item, int code) const ;
136 bool ItemHasChildren(const long item) const ;
137 long GetChild(const long item) const ;
138 long GetParent(const long item) const ;
139 long GetFirstVisibleItem(void) const ;
140 long GetNextVisibleItem(const long item) const ;
141 long GetSelection(void) const ;
142 long GetRootItem(void) const ;
143 bool GetItem(wxTreeItem& info) const ;
144 bool SetItem(wxTreeItem& info) ;
145 int GetItemState(const long item, const long stateMask) const ;
146 bool SetItemState(const long item, const long state, const long stateMask) ;
147 bool SetItemImage(const long item, const int image, const int selImage) ;
148 wxString GetItemText(const long item) const ;
149 void SetItemText(const long item, const wxString& str) ;
150 long GetItemData(const long item) const ;
151 bool SetItemData(const long item, long data) ;
152 bool GetItemRect(const long item, wxRectangle& rect, bool textOnly = FALSE) const;
153 wxTextCtrl& GetEditControl(void) const;
154
155 // Operations
156 bool DeleteItem(const long item);
157 bool ExpandItem(const long item, const int action);
158 long InsertItem(const long parent, wxTreeItem& info, const long insertAfter = wxTREE_INSERT_LAST);
159
160 // If image > -1 and selImage == -1, the same image is used for
161 // both selected and unselected items.
162 long InsertItem(const long parent, const wxString& label, const int image = -1, const int selImage = -1, const long insertAfter = wxTREE_INSERT_LAST);
163 bool SelectItem(const long item);
164 bool ScrollTo(const long item);
165 bool DeleteAllItems(void) ;
166 wxTextCtrl& Edit(const long item) ;
167 long HitTest(const wxPoint& point, int& flags);
168 // wxImageList *CreateDragImage(const long item) ;
169 bool SortChildren(const long item) ;
170 bool EnsureVisible(const long item) ;
171
172 void Command(wxCommandEvent& event) { ProcessCommand(event); };
173
174 // IMPLEMENTATION
175 bool MSWCommand(const WXUINT param, const WXWORD id);
176 bool MSWNotify(const WXWPARAM wParam, const WXLPARAM lParam);
177
178 protected:
179 wxTextCtrl m_textCtrl;
180 wxImageList *m_imageListNormal;
181 wxImageList *m_imageListState;
182 };
183
184 /*
185 wxEVT_COMMAND_TREE_BEGIN_DRAG,
186 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
187 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
188 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
189 wxEVT_COMMAND_TREE_DELETE_ITEM,
190 wxEVT_COMMAND_TREE_GET_INFO,
191 wxEVT_COMMAND_TREE_SET_INFO,
192 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
193 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
194 wxEVT_COMMAND_TREE_SEL_CHANGED,
195 wxEVT_COMMAND_TREE_SEL_CHANGING,
196 wxEVT_COMMAND_TREE_KEY_DOWN
197 */
198
199 class WXDLLEXPORT wxTreeEvent: public wxCommandEvent
200 {
201 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
202
203 public:
204 wxTreeEvent(WXTYPE commandType = 0, int id = 0);
205
206 int m_code;
207 wxTreeItem m_item;
208 long m_oldItem;
209 wxPoint m_pointDrag;
210 };
211
212 typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
213
214 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
215 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
216 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
217 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
218 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
219 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
220 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
221 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
222 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
223 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
224 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
225 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn },
226
227 #endif
228 // __TREECTRLH__