]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/treectrl.h
added Acceptsfocus() { return FALSE; }
[wxWidgets.git] / include / wx / msw / treectrl.h
CommitLineData
2bda0e17
KB
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
4efd7443 53#define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
2bda0e17
KB
54
55// Flags for GetNextItem
56enum {
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
70enum {
71 wxTREE_EXPAND_EXPAND,
72 wxTREE_EXPAND_COLLAPSE,
73 wxTREE_EXPAND_COLLAPSE_RESET,
74 wxTREE_EXPAND_TOGGLE
75};
76
77// Flags for InsertItem
78enum {
79 wxTREE_INSERT_LAST = -1,
80 wxTREE_INSERT_FIRST = -2,
81 wxTREE_INSERT_SORT = -3
82};
83
84class WXDLLEXPORT wxTreeItem: public wxObject
85{
86 DECLARE_DYNAMIC_CLASS(wxTreeItem)
87public:
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);
64693098
JS
99
100// Accessors
101 inline long GetMask() const { return m_mask; }
102 inline long GetItemId() const { return m_itemId; }
103 inline long GetState() const { return m_state; }
104 inline long GetStateMask() const { return m_stateMask; }
105 inline wxString GetText() const { return m_text; }
106 inline int GetImage() const { return m_image; }
107 inline int GetSelectedImage() const { return m_selectedImage; }
108 inline int GetChildren() const { return m_children; }
109 inline long GetData() const { return m_data; }
110
111 inline void SetMask(long mask) { m_mask = mask; }
112 inline void SetItemId(long id) { m_itemId = m_itemId = id; }
113 inline void GetState(long state) { m_state = state; }
114 inline void SetStateMask(long stateMask) { m_stateMask = stateMask; }
115 inline void GetText(const wxString& text) { m_text = text; }
116 inline void SetImage(int image) { m_image = image; }
117 inline void GetSelectedImage(int selImage) { m_selectedImage = selImage; }
118 inline void SetChildren(int children) { m_children = children; }
119 inline void SetData(long data) { m_data = data; }
2bda0e17
KB
120};
121
122class WXDLLEXPORT wxTreeCtrl: public wxControl
123{
124 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
125 public:
126 /*
127 * Public interface
128 */
129
130 wxTreeCtrl(void);
131
debe6624 132 inline wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
2bda0e17
KB
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
debe6624 135 long style = wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT,
2bda0e17
KB
136 const wxValidator& validator = wxDefaultValidator,
137 const wxString& name = "wxTreeCtrl")
138 {
139 Create(parent, id, pos, size, style, validator, name);
140 }
141 ~wxTreeCtrl(void);
142
debe6624 143 bool Create(wxWindow *parent, wxWindowID id = -1,
2bda0e17
KB
144 const wxPoint& pos = wxDefaultPosition,
145 const wxSize& size = wxDefaultSize,
debe6624 146 long style = wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT,
2bda0e17
KB
147 const wxValidator& validator = wxDefaultValidator,
148 const wxString& name = "wxTreeCtrl");
149
150 // Attributes
151 int GetCount(void) const ;
152 int GetIndent(void) const ;
153 void SetIndent(int indent) ;
debe6624
JS
154 wxImageList *GetImageList(int which = wxIMAGE_LIST_NORMAL) const ;
155 void SetImageList(wxImageList *imageList, int which = wxIMAGE_LIST_NORMAL) ;
156 long GetNextItem(long item, int code) const ;
157 bool ItemHasChildren(long item) const ;
158 long GetChild(long item) const ;
159 long GetParent(long item) const ;
2bda0e17 160 long GetFirstVisibleItem(void) const ;
debe6624 161 long GetNextVisibleItem(long item) const ;
2bda0e17
KB
162 long GetSelection(void) const ;
163 long GetRootItem(void) const ;
164 bool GetItem(wxTreeItem& info) const ;
165 bool SetItem(wxTreeItem& info) ;
debe6624
JS
166 int GetItemState(long item, long stateMask) const ;
167 bool SetItemState(long item, long state, long stateMask) ;
168 bool SetItemImage(long item, int image, int selImage) ;
169 wxString GetItemText(long item) const ;
170 void SetItemText(long item, const wxString& str) ;
171 long GetItemData(long item) const ;
172 bool SetItemData(long item, long data) ;
173 bool GetItemRect(long item, wxRectangle& rect, bool textOnly = FALSE) const;
2bda0e17
KB
174 wxTextCtrl& GetEditControl(void) const;
175
176 // Operations
debe6624
JS
177 bool DeleteItem(long item);
178 bool ExpandItem(long item, int action);
179 long InsertItem(long parent, wxTreeItem& info, long insertAfter = wxTREE_INSERT_LAST);
2bda0e17
KB
180
181 // If image > -1 and selImage == -1, the same image is used for
182 // both selected and unselected items.
debe6624
JS
183 long InsertItem(long parent, const wxString& label, int image = -1, int selImage = -1, long insertAfter = wxTREE_INSERT_LAST);
184 bool SelectItem(long item);
185 bool ScrollTo(long item);
2bda0e17 186 bool DeleteAllItems(void) ;
debe6624 187 wxTextCtrl& Edit(long item) ;
2bda0e17 188 long HitTest(const wxPoint& point, int& flags);
debe6624
JS
189// wxImageList *CreateDragImage(long item) ;
190 bool SortChildren(long item) ;
191 bool EnsureVisible(long item) ;
2bda0e17
KB
192
193 void Command(wxCommandEvent& event) { ProcessCommand(event); };
194
195 // IMPLEMENTATION
debe6624
JS
196 bool MSWCommand(WXUINT param, WXWORD id);
197 bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam);
2bda0e17
KB
198
199protected:
200 wxTextCtrl m_textCtrl;
201 wxImageList *m_imageListNormal;
202 wxImageList *m_imageListState;
203};
204
205/*
206 wxEVT_COMMAND_TREE_BEGIN_DRAG,
207 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
208 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
209 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
210 wxEVT_COMMAND_TREE_DELETE_ITEM,
211 wxEVT_COMMAND_TREE_GET_INFO,
212 wxEVT_COMMAND_TREE_SET_INFO,
213 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
214 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
215 wxEVT_COMMAND_TREE_SEL_CHANGED,
216 wxEVT_COMMAND_TREE_SEL_CHANGING,
217 wxEVT_COMMAND_TREE_KEY_DOWN
218*/
219
220class WXDLLEXPORT wxTreeEvent: public wxCommandEvent
221{
222 DECLARE_DYNAMIC_CLASS(wxTreeEvent)
223
224 public:
64693098 225 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
2bda0e17
KB
226
227 int m_code;
228 wxTreeItem m_item;
229 long m_oldItem;
230 wxPoint m_pointDrag;
64693098
JS
231
232 inline long GetOldItem() const { return m_oldItem; }
233 inline wxTreeItem& GetItem() const { return (wxTreeItem&) m_item; }
234 inline wxPoint GetPoint() const { return m_pointDrag; }
235 inline int GetCode() const { return m_code; }
2bda0e17
KB
236};
237
238typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&);
239
fe71f65c
RR
240#define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
241#define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
242#define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
243#define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
244#define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
245#define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
246#define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
247#define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
248#define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
249#define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
250#define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
251#define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
2bda0e17
KB
252
253#endif
254 // __TREECTRLH__