]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/generic/treectlg.h | |
3 | // Purpose: wxTreeCtrl class | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997,1998 Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _GENERIC_TREECTRL_H_ | |
13 | #define _GENERIC_TREECTRL_H_ | |
14 | ||
15 | #if wxUSE_TREECTRL | |
16 | ||
17 | #include "wx/scrolwin.h" | |
18 | #include "wx/pen.h" | |
19 | ||
20 | // ----------------------------------------------------------------------------- | |
21 | // forward declaration | |
22 | // ----------------------------------------------------------------------------- | |
23 | ||
24 | class WXDLLIMPEXP_FWD_CORE wxGenericTreeItem; | |
25 | ||
26 | class WXDLLIMPEXP_FWD_CORE wxTreeItemData; | |
27 | ||
28 | class WXDLLIMPEXP_FWD_CORE wxTreeRenameTimer; | |
29 | class WXDLLIMPEXP_FWD_CORE wxTreeFindTimer; | |
30 | class WXDLLIMPEXP_FWD_CORE wxTreeTextCtrl; | |
31 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
32 | ||
33 | // ----------------------------------------------------------------------------- | |
34 | // wxGenericTreeCtrl - the tree control | |
35 | // ----------------------------------------------------------------------------- | |
36 | ||
37 | class WXDLLIMPEXP_CORE wxGenericTreeCtrl : public wxTreeCtrlBase, | |
38 | public wxScrollHelper | |
39 | { | |
40 | public: | |
41 | // creation | |
42 | // -------- | |
43 | ||
44 | wxGenericTreeCtrl() : wxTreeCtrlBase(), wxScrollHelper(this) { Init(); } | |
45 | ||
46 | wxGenericTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, | |
47 | const wxPoint& pos = wxDefaultPosition, | |
48 | const wxSize& size = wxDefaultSize, | |
49 | long style = wxTR_DEFAULT_STYLE, | |
50 | const wxValidator &validator = wxDefaultValidator, | |
51 | const wxString& name = wxTreeCtrlNameStr) | |
52 | : wxTreeCtrlBase(), | |
53 | wxScrollHelper(this) | |
54 | { | |
55 | Init(); | |
56 | Create(parent, id, pos, size, style, validator, name); | |
57 | } | |
58 | ||
59 | virtual ~wxGenericTreeCtrl(); | |
60 | ||
61 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, | |
62 | const wxPoint& pos = wxDefaultPosition, | |
63 | const wxSize& size = wxDefaultSize, | |
64 | long style = wxTR_DEFAULT_STYLE, | |
65 | const wxValidator &validator = wxDefaultValidator, | |
66 | const wxString& name = wxTreeCtrlNameStr); | |
67 | ||
68 | ||
69 | // implement base class pure virtuals | |
70 | // ---------------------------------- | |
71 | ||
72 | virtual unsigned int GetCount() const; | |
73 | ||
74 | virtual unsigned int GetIndent() const { return m_indent; } | |
75 | virtual void SetIndent(unsigned int indent); | |
76 | ||
77 | ||
78 | virtual void SetImageList(wxImageList *imageList); | |
79 | virtual void SetStateImageList(wxImageList *imageList); | |
80 | ||
81 | virtual wxString GetItemText(const wxTreeItemId& item) const; | |
82 | virtual int GetItemImage(const wxTreeItemId& item, | |
83 | wxTreeItemIcon which = wxTreeItemIcon_Normal) const; | |
84 | virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const; | |
85 | virtual wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
86 | virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
87 | virtual wxFont GetItemFont(const wxTreeItemId& item) const; | |
88 | ||
89 | virtual void SetItemText(const wxTreeItemId& item, const wxString& text); | |
90 | virtual void SetItemImage(const wxTreeItemId& item, | |
91 | int image, | |
92 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
93 | virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
94 | ||
95 | virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true); | |
96 | virtual void SetItemBold(const wxTreeItemId& item, bool bold = true); | |
97 | virtual void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true); | |
98 | virtual void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); | |
99 | virtual void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); | |
100 | virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
101 | ||
102 | virtual bool IsVisible(const wxTreeItemId& item) const; | |
103 | virtual bool ItemHasChildren(const wxTreeItemId& item) const; | |
104 | virtual bool IsExpanded(const wxTreeItemId& item) const; | |
105 | virtual bool IsSelected(const wxTreeItemId& item) const; | |
106 | virtual bool IsBold(const wxTreeItemId& item) const; | |
107 | ||
108 | virtual size_t GetChildrenCount(const wxTreeItemId& item, | |
109 | bool recursively = true) const; | |
110 | ||
111 | // navigation | |
112 | // ---------- | |
113 | ||
114 | virtual wxTreeItemId GetRootItem() const { return m_anchor; } | |
115 | virtual wxTreeItemId GetSelection() const | |
116 | { | |
117 | wxASSERT_MSG( !HasFlag(wxTR_MULTIPLE), | |
118 | wxT("must use GetSelections() with this control") ); | |
119 | ||
120 | return m_current; | |
121 | } | |
122 | virtual size_t GetSelections(wxArrayTreeItemIds&) const; | |
123 | ||
124 | virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const; | |
125 | virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, | |
126 | wxTreeItemIdValue& cookie) const; | |
127 | virtual wxTreeItemId GetNextChild(const wxTreeItemId& item, | |
128 | wxTreeItemIdValue& cookie) const; | |
129 | virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
130 | virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
131 | virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
132 | ||
133 | virtual wxTreeItemId GetFirstVisibleItem() const; | |
134 | virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
135 | virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
136 | ||
137 | ||
138 | // operations | |
139 | // ---------- | |
140 | ||
141 | virtual wxTreeItemId AddRoot(const wxString& text, | |
142 | int image = -1, int selectedImage = -1, | |
143 | wxTreeItemData *data = NULL); | |
144 | ||
145 | virtual void Delete(const wxTreeItemId& item); | |
146 | virtual void DeleteChildren(const wxTreeItemId& item); | |
147 | virtual void DeleteAllItems(); | |
148 | ||
149 | virtual void Expand(const wxTreeItemId& item); | |
150 | virtual void Collapse(const wxTreeItemId& item); | |
151 | virtual void CollapseAndReset(const wxTreeItemId& item); | |
152 | virtual void Toggle(const wxTreeItemId& item); | |
153 | ||
154 | virtual void Unselect(); | |
155 | virtual void UnselectAll(); | |
156 | virtual void SelectItem(const wxTreeItemId& item, bool select = true); | |
157 | ||
158 | virtual void EnsureVisible(const wxTreeItemId& item); | |
159 | virtual void ScrollTo(const wxTreeItemId& item); | |
160 | ||
161 | virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, | |
162 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
163 | virtual wxTextCtrl *GetEditControl() const; | |
164 | virtual void EndEditLabel(const wxTreeItemId& item, | |
165 | bool discardChanges = false); | |
166 | ||
167 | virtual void SortChildren(const wxTreeItemId& item); | |
168 | ||
169 | // items geometry | |
170 | // -------------- | |
171 | ||
172 | virtual bool GetBoundingRect(const wxTreeItemId& item, | |
173 | wxRect& rect, | |
174 | bool textOnly = false) const; | |
175 | ||
176 | ||
177 | // this version specific methods | |
178 | // ----------------------------- | |
179 | ||
180 | wxImageList *GetButtonsImageList() const { return m_imageListButtons; } | |
181 | void SetButtonsImageList(wxImageList *imageList); | |
182 | void AssignButtonsImageList(wxImageList *imageList); | |
183 | ||
184 | void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; } | |
185 | bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; } | |
186 | ||
187 | wxTreeItemId GetNext(const wxTreeItemId& item) const; | |
188 | ||
189 | #if WXWIN_COMPATIBILITY_2_6 | |
190 | // use EditLabel() instead | |
191 | void Edit( const wxTreeItemId& item ) { EditLabel(item); } | |
192 | #endif // WXWIN_COMPATIBILITY_2_6 | |
193 | ||
194 | // implementation only from now on | |
195 | ||
196 | // overridden base class virtuals | |
197 | virtual bool SetBackgroundColour(const wxColour& colour); | |
198 | virtual bool SetForegroundColour(const wxColour& colour); | |
199 | ||
200 | virtual void Refresh(bool eraseBackground = true, const wxRect *rect = NULL); | |
201 | ||
202 | virtual bool SetFont( const wxFont &font ); | |
203 | virtual void SetWindowStyle(const long styles); | |
204 | ||
205 | // callbacks | |
206 | void OnPaint( wxPaintEvent &event ); | |
207 | void OnSetFocus( wxFocusEvent &event ); | |
208 | void OnKillFocus( wxFocusEvent &event ); | |
209 | void OnChar( wxKeyEvent &event ); | |
210 | void OnMouse( wxMouseEvent &event ); | |
211 | void OnGetToolTip( wxTreeEvent &event ); | |
212 | void OnSize( wxSizeEvent &event ); | |
213 | void OnInternalIdle( ); | |
214 | ||
215 | virtual wxVisualAttributes GetDefaultAttributes() const | |
216 | { | |
217 | return GetClassDefaultAttributes(GetWindowVariant()); | |
218 | } | |
219 | ||
220 | static wxVisualAttributes | |
221 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
222 | ||
223 | // implementation helpers | |
224 | void AdjustMyScrollbars(); | |
225 | ||
226 | WX_FORWARD_TO_SCROLL_HELPER() | |
227 | ||
228 | protected: | |
229 | friend class wxGenericTreeItem; | |
230 | friend class wxTreeRenameTimer; | |
231 | friend class wxTreeFindTimer; | |
232 | friend class wxTreeTextCtrl; | |
233 | ||
234 | wxFont m_normalFont; | |
235 | wxFont m_boldFont; | |
236 | ||
237 | wxGenericTreeItem *m_anchor; | |
238 | wxGenericTreeItem *m_current, | |
239 | *m_key_current, | |
240 | // A hint to select a parent item after deleting a child | |
241 | *m_select_me; | |
242 | unsigned short m_indent; | |
243 | int m_lineHeight; | |
244 | wxPen m_dottedPen; | |
245 | wxBrush *m_hilightBrush, | |
246 | *m_hilightUnfocusedBrush; | |
247 | bool m_hasFocus; | |
248 | bool m_dirty; | |
249 | bool m_ownsImageListButtons; | |
250 | bool m_isDragging; // true between BEGIN/END drag events | |
251 | bool m_lastOnSame; // last click on the same item as prev | |
252 | wxImageList *m_imageListButtons; | |
253 | ||
254 | int m_dragCount; | |
255 | wxPoint m_dragStart; | |
256 | wxGenericTreeItem *m_dropTarget; | |
257 | wxCursor m_oldCursor; // cursor is changed while dragging | |
258 | wxGenericTreeItem *m_oldSelection; | |
259 | wxGenericTreeItem *m_underMouse; // for visual effects | |
260 | wxTreeTextCtrl *m_textCtrl; | |
261 | ||
262 | wxTimer *m_renameTimer; | |
263 | ||
264 | // incremental search data | |
265 | wxString m_findPrefix; | |
266 | wxTimer *m_findTimer; | |
267 | ||
268 | bool m_dropEffectAboveItem; | |
269 | ||
270 | // the common part of all ctors | |
271 | void Init(); | |
272 | ||
273 | // overridden wxWindow methods | |
274 | virtual void DoThaw(); | |
275 | ||
276 | // misc helpers | |
277 | void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted); | |
278 | ||
279 | void DrawBorder(const wxTreeItemId& item); | |
280 | void DrawLine(const wxTreeItemId& item, bool below); | |
281 | void DrawDropEffect(wxGenericTreeItem *item); | |
282 | ||
283 | void DoSelectItem(const wxTreeItemId& id, | |
284 | bool unselect_others = true, | |
285 | bool extended_select = false); | |
286 | ||
287 | virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent, | |
288 | size_t previous, | |
289 | const wxString& text, | |
290 | int image, | |
291 | int selectedImage, | |
292 | wxTreeItemData *data); | |
293 | virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent, | |
294 | const wxTreeItemId& idPrevious, | |
295 | const wxString& text, | |
296 | int image = -1, int selImage = -1, | |
297 | wxTreeItemData *data = NULL); | |
298 | virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const; | |
299 | ||
300 | // called by wxTextTreeCtrl when it marks itself for deletion | |
301 | void ResetTextControl(); | |
302 | ||
303 | // find the first item starting with the given prefix after the given item | |
304 | wxTreeItemId FindItem(const wxTreeItemId& id, const wxString& prefix) const; | |
305 | ||
306 | bool HasButtons() const { return HasFlag(wxTR_HAS_BUTTONS); } | |
307 | ||
308 | void CalculateLineHeight(); | |
309 | int GetLineHeight(wxGenericTreeItem *item) const; | |
310 | void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y ); | |
311 | void PaintItem( wxGenericTreeItem *item, wxDC& dc); | |
312 | ||
313 | void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y ); | |
314 | void CalculatePositions(); | |
315 | void CalculateSize( wxGenericTreeItem *item, wxDC &dc ); | |
316 | ||
317 | void RefreshSubtree( wxGenericTreeItem *item ); | |
318 | void RefreshLine( wxGenericTreeItem *item ); | |
319 | ||
320 | // redraw all selected items | |
321 | void RefreshSelected(); | |
322 | ||
323 | // RefreshSelected() recursive helper | |
324 | void RefreshSelectedUnder(wxGenericTreeItem *item); | |
325 | ||
326 | void OnRenameTimer(); | |
327 | bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value); | |
328 | void OnRenameCancelled(wxGenericTreeItem *item); | |
329 | ||
330 | void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const; | |
331 | void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 ); | |
332 | bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
333 | bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
334 | void UnselectAllChildren( wxGenericTreeItem *item ); | |
335 | void ChildrenClosing(wxGenericTreeItem* item); | |
336 | ||
337 | void DoDirtyProcessing(); | |
338 | ||
339 | virtual wxSize DoGetBestSize() const; | |
340 | ||
341 | private: | |
342 | DECLARE_EVENT_TABLE() | |
343 | DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl) | |
344 | DECLARE_NO_COPY_CLASS(wxGenericTreeCtrl) | |
345 | }; | |
346 | ||
347 | #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) | |
348 | /* | |
349 | * wxTreeCtrl has to be a real class or we have problems with | |
350 | * the run-time information. | |
351 | */ | |
352 | ||
353 | class WXDLLIMPEXP_CORE wxTreeCtrl: public wxGenericTreeCtrl | |
354 | { | |
355 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
356 | ||
357 | public: | |
358 | wxTreeCtrl() {} | |
359 | ||
360 | wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, | |
361 | const wxPoint& pos = wxDefaultPosition, | |
362 | const wxSize& size = wxDefaultSize, | |
363 | long style = wxTR_DEFAULT_STYLE, | |
364 | const wxValidator &validator = wxDefaultValidator, | |
365 | const wxString& name = wxTreeCtrlNameStr) | |
366 | : wxGenericTreeCtrl(parent, id, pos, size, style, validator, name) | |
367 | { | |
368 | } | |
369 | }; | |
370 | #endif // !__WXMSW__ || __WXUNIVERSAL__ | |
371 | ||
372 | #endif // wxUSE_TREECTRL | |
373 | ||
374 | #endif // _GENERIC_TREECTRL_H_ |