]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: treelistctrl.cpp | |
3 | // Purpose: multi column tree control implementation | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Modified: Alberto Griggio, 2002 | |
7 | // 22/10/98 - almost total rewrite, simpler interface (VZ) | |
8 | // Id: $Id$ | |
9 | // Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio, | |
10 | // Vadim Zeitlin, Otto Wyss | |
11 | // Licence: wxWindows licence | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | // =========================================================================== | |
15 | // declarations | |
16 | // =========================================================================== | |
17 | ||
18 | // --------------------------------------------------------------------------- | |
19 | // headers | |
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | #if defined(__GNUG__) && !defined(__APPLE__) | |
23 | #pragma implementation "treelistctrl.h" | |
24 | #endif | |
25 | ||
26 | // For compilers that support precompilation, includes "wx.h". | |
27 | #include "wx/wxprec.h" | |
28 | ||
29 | #ifdef __BORLANDC__ | |
30 | #pragma hdrstop | |
31 | #endif | |
32 | ||
33 | ||
34 | #include <wx/treebase.h> | |
35 | #include <wx/timer.h> | |
36 | #include <wx/textctrl.h> | |
37 | #include <wx/imaglist.h> | |
38 | #include <wx/settings.h> | |
39 | #include <wx/dcclient.h> | |
40 | #include <wx/dcscreen.h> | |
41 | #include <wx/scrolwin.h> | |
42 | #include <wx/renderer.h> | |
43 | #include <wx/dcmemory.h> | |
44 | ||
45 | #include "wx/treelistctrl.h" | |
46 | ||
47 | #ifdef __WXGTK__ | |
48 | #include <gtk/gtk.h> | |
49 | #include <wx/gtk/win_gtk.h> | |
50 | #endif | |
51 | ||
52 | #ifdef __WXMAC__ | |
53 | #include "wx/mac/private.h" | |
54 | #endif | |
55 | ||
56 | ||
57 | // --------------------------------------------------------------------------- | |
58 | // array types | |
59 | // --------------------------------------------------------------------------- | |
60 | ||
61 | class wxTreeListItem; | |
62 | ||
63 | #if !wxCHECK_VERSION(2, 5, 0) | |
64 | WX_DEFINE_ARRAY(wxTreeListItem *, wxArrayTreeListItems); | |
65 | #else | |
66 | WX_DEFINE_ARRAY_PTR(wxTreeListItem *, wxArrayTreeListItems); | |
67 | #endif | |
68 | ||
69 | #include <wx/dynarray.h> | |
70 | WX_DECLARE_OBJARRAY(wxTreeListColumnInfo, wxArrayTreeListColumnInfo); | |
71 | #include <wx/arrimpl.cpp> | |
72 | WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo); | |
73 | ||
74 | #if !wxCHECK_VERSION(2, 3, 3) | |
75 | WX_DEFINE_ARRAY(short, wxArrayShort); | |
76 | #endif | |
77 | ||
78 | ||
79 | // -------------------------------------------------------------------------- | |
80 | // constants | |
81 | // -------------------------------------------------------------------------- | |
82 | ||
83 | static const int NO_IMAGE = -1; | |
84 | ||
85 | const int LINEHEIGHT = 10; | |
86 | const int PIXELS_PER_UNIT = 10; | |
87 | const int LINEATROOT = 5; | |
88 | const int MARGIN = 2; | |
89 | const int MININDENT = 10; | |
90 | const int BTNWIDTH = 9; //11; | |
91 | const int BTNHEIGHT = 9; //11; | |
92 | ||
93 | // extra margins around the text label | |
94 | static const int EXTRA_WIDTH = 4; | |
95 | static const int EXTRA_HEIGHT = 4; | |
96 | ||
97 | // offset for the header window | |
98 | static const int HEADER_OFFSET_X = 1; | |
99 | static const int HEADER_OFFSET_Y = 1; | |
100 | ||
101 | ||
102 | ||
103 | const wxChar* wxTreeListCtrlNameStr = wxT("treelistctrl"); | |
104 | ||
105 | static wxTreeListColumnInfo wxInvalidTreeListColumnInfo; | |
106 | ||
107 | ||
108 | // --------------------------------------------------------------------------- | |
109 | // private classes | |
110 | // --------------------------------------------------------------------------- | |
111 | //----------------------------------------------------------------------------- | |
112 | // wxTreeListHeaderWindow (internal) | |
113 | //----------------------------------------------------------------------------- | |
114 | ||
115 | class wxTreeListHeaderWindow : public wxWindow | |
116 | { | |
117 | protected: | |
118 | wxTreeListMainWindow *m_owner; | |
119 | wxCursor *m_currentCursor; | |
120 | wxCursor *m_resizeCursor; | |
121 | bool m_isDragging; | |
122 | ||
123 | // column being resized | |
124 | int m_column; | |
125 | ||
126 | // divider line position in logical (unscrolled) coords | |
127 | int m_currentX; | |
128 | ||
129 | // minimal position beyond which the divider line can't be dragged in | |
130 | // logical coords | |
131 | int m_minX; | |
132 | ||
133 | wxArrayTreeListColumnInfo m_columns; | |
134 | ||
135 | // total width of the columns | |
136 | int m_total_col_width; | |
137 | ||
138 | ||
139 | public: | |
140 | wxTreeListHeaderWindow(); | |
141 | ||
142 | wxTreeListHeaderWindow( wxWindow *win, | |
143 | wxWindowID id, | |
144 | wxTreeListMainWindow *owner, | |
145 | const wxPoint &pos = wxDefaultPosition, | |
146 | const wxSize &size = wxDefaultSize, | |
147 | long style = 0, | |
148 | const wxString &name = wxT("wxtreelistctrlcolumntitles") ); | |
149 | ||
150 | virtual ~wxTreeListHeaderWindow(); | |
151 | ||
152 | void DoDrawRect( wxDC *dc, int x, int y, int w, int h ); | |
153 | void DrawCurrent(); | |
154 | void AdjustDC(wxDC& dc); | |
155 | ||
156 | void OnEraseBackground( wxEraseEvent& event ); | |
157 | void OnPaint( wxPaintEvent &event ); | |
158 | void OnMouse( wxMouseEvent &event ); | |
159 | void OnSetFocus( wxFocusEvent &event ); | |
160 | ||
161 | ||
162 | // columns manipulation | |
163 | ||
164 | size_t GetColumnCount() const { return m_columns.GetCount(); } | |
165 | ||
166 | void AddColumn(const wxTreeListColumnInfo& col); | |
167 | ||
168 | void InsertColumn(size_t before, const wxTreeListColumnInfo& col); | |
169 | ||
170 | void RemoveColumn(size_t column); | |
171 | ||
172 | void SetColumn(size_t column, const wxTreeListColumnInfo& info); | |
173 | const wxTreeListColumnInfo& GetColumn(size_t column) const | |
174 | { | |
175 | wxCHECK_MSG(column < GetColumnCount(), wxInvalidTreeListColumnInfo, wxT("Invalid column")); | |
176 | return m_columns[column]; | |
177 | } | |
178 | wxTreeListColumnInfo& GetColumn(size_t column) | |
179 | { | |
180 | wxCHECK_MSG(column < GetColumnCount(), wxInvalidTreeListColumnInfo, wxT("Invalid column")); | |
181 | return m_columns[column]; | |
182 | } | |
183 | ||
184 | void SetColumnWidth(size_t column, size_t width); | |
185 | ||
186 | void SetColumnText(size_t column, const wxString& text) | |
187 | { | |
188 | wxCHECK_RET(column < GetColumnCount(), wxT("Invalid column")); | |
189 | m_columns[column].SetText(text); | |
190 | } | |
191 | ||
192 | void SetColumnShown(size_t column, bool shown) | |
193 | { | |
194 | wxCHECK_RET(column < GetColumnCount(), wxT("Invalid column")); | |
195 | m_columns[column].SetShown(shown); | |
196 | } | |
197 | ||
198 | wxString GetColumnText(size_t column) const | |
199 | { | |
200 | wxCHECK_MSG(column < GetColumnCount(), wxEmptyString, wxT("Invalid column")); | |
201 | return m_columns[column].GetText(); | |
202 | } | |
203 | ||
204 | int GetColumnWidth(size_t column) const | |
205 | { | |
206 | wxCHECK_MSG(column < GetColumnCount(), -1, wxT("Invalid column")); | |
207 | return m_columns[column].GetWidth(); | |
208 | } | |
209 | ||
210 | int GetWidth() const { return m_total_col_width; } | |
211 | ||
212 | int GetColumnShown(size_t column) const | |
213 | { | |
214 | wxCHECK_MSG(column < GetColumnCount(), -1, wxT("Invalid column")); | |
215 | return m_columns[column].GetShown(); | |
216 | } | |
217 | ||
218 | // needs refresh | |
219 | bool m_dirty; | |
220 | ||
221 | private: | |
222 | // common part of all ctors | |
223 | void Init(); | |
224 | ||
225 | void SendListEvent(wxEventType type, wxPoint pos); | |
226 | ||
227 | DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow) | |
228 | DECLARE_EVENT_TABLE() | |
229 | }; | |
230 | ||
231 | ||
232 | // this is the "true" control | |
233 | class wxTreeListMainWindow: public wxScrolledWindow | |
234 | { | |
235 | public: | |
236 | // creation | |
237 | // -------- | |
238 | wxTreeListMainWindow() { Init(); } | |
239 | ||
240 | wxTreeListMainWindow(wxTreeListCtrl *parent, wxWindowID id = -1, | |
241 | const wxPoint& pos = wxDefaultPosition, | |
242 | const wxSize& size = wxDefaultSize, | |
243 | long style = wxTR_DEFAULT_STYLE, | |
244 | const wxValidator &validator = wxDefaultValidator, | |
245 | const wxString& name = wxT("wxtreelistmainwindow")) | |
246 | { | |
247 | Init(); | |
248 | Create(parent, id, pos, size, style, validator, name); | |
249 | } | |
250 | ||
251 | virtual ~wxTreeListMainWindow(); | |
252 | ||
253 | bool Create(wxTreeListCtrl *parent, wxWindowID id = -1, | |
254 | const wxPoint& pos = wxDefaultPosition, | |
255 | const wxSize& size = wxDefaultSize, | |
256 | long style = wxTR_DEFAULT_STYLE, | |
257 | const wxValidator &validator = wxDefaultValidator, | |
258 | const wxString& name = wxT("wxtreelistctrl")); | |
259 | ||
260 | // accessors | |
261 | // --------- | |
262 | ||
263 | // get the total number of items in the control | |
264 | size_t GetCount() const; | |
265 | ||
266 | // indent is the number of pixels the children are indented relative to | |
267 | // the parents position. SetIndent() also redraws the control | |
268 | // immediately. | |
269 | unsigned int GetIndent() const { return m_indent; } | |
270 | void SetIndent(unsigned int indent); | |
271 | ||
272 | // see wxTreeListCtrl for the meaning | |
273 | unsigned int GetLineSpacing() const { return m_linespacing; } | |
274 | void SetLineSpacing(unsigned int spacing); | |
275 | ||
276 | // image list: these functions allow to associate an image list with | |
277 | // the control and retrieve it. Note that when assigned with | |
278 | // SetImageList, the control does _not_ delete | |
279 | // the associated image list when it's deleted in order to allow image | |
280 | // lists to be shared between different controls. If you use | |
281 | // AssignImageList, the control _does_ delete the image list. | |
282 | ||
283 | // The normal image list is for the icons which correspond to the | |
284 | // normal tree item state (whether it is selected or not). | |
285 | // Additionally, the application might choose to show a state icon | |
286 | // which corresponds to an app-defined item state (for example, | |
287 | // checked/unchecked) which are taken from the state image list. | |
288 | wxImageList *GetImageList() const; | |
289 | wxImageList *GetStateImageList() const; | |
290 | wxImageList *GetButtonsImageList() const; | |
291 | ||
292 | void SetImageList(wxImageList *imageList); | |
293 | void SetStateImageList(wxImageList *imageList); | |
294 | void SetButtonsImageList(wxImageList *imageList); | |
295 | void AssignImageList(wxImageList *imageList); | |
296 | void AssignStateImageList(wxImageList *imageList); | |
297 | void AssignButtonsImageList(wxImageList *imageList); | |
298 | ||
299 | // Functions to work with tree ctrl items. | |
300 | ||
301 | // accessors | |
302 | // --------- | |
303 | ||
304 | // retrieve item's label | |
305 | wxString GetItemText(const wxTreeItemId& item) const | |
306 | { return GetItemText(item, GetMainColumn()); } | |
307 | // get one of the images associated with the item (normal by default) | |
308 | int GetItemImage(const wxTreeItemId& item, | |
309 | wxTreeItemIcon which = wxTreeItemIcon_Normal) const | |
310 | { return GetItemImage(item, GetMainColumn(), which); } | |
311 | ||
312 | // get the data associated with the item | |
313 | wxTreeItemData *GetItemData(const wxTreeItemId& item) const; | |
314 | ||
315 | bool GetItemBold(const wxTreeItemId& item) const; | |
316 | wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
317 | wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
318 | wxFont GetItemFont(const wxTreeItemId& item) const; | |
319 | ||
320 | // modifiers | |
321 | // --------- | |
322 | ||
323 | // set item's label | |
324 | void SetItemText(const wxTreeItemId& item, const wxString& text) | |
325 | { SetItemText(item, GetMainColumn(), text); } | |
326 | ||
327 | // get one of the images associated with the item (normal by default) | |
328 | void SetItemImage(const wxTreeItemId& item, int image, | |
329 | wxTreeItemIcon which = wxTreeItemIcon_Normal) | |
330 | { SetItemImage(item, GetMainColumn(), image, which); } | |
331 | ||
332 | // associate some data with the item | |
333 | void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
334 | ||
335 | // force appearance of [+] button near the item. This is useful to | |
336 | // allow the user to expand the items which don't have any children now | |
337 | // - but instead add them only when needed, thus minimizing memory | |
338 | // usage and loading time. | |
339 | void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE); | |
340 | ||
341 | // the item will be shown in bold | |
342 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); | |
343 | ||
344 | // set the item's text colour | |
345 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour); | |
346 | ||
347 | // set the item's background colour | |
348 | void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& colour); | |
349 | ||
350 | // set the item's font (should be of the same height for all items) | |
351 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
352 | ||
353 | // set the window font | |
354 | virtual bool SetFont( const wxFont &font ); | |
355 | ||
356 | // set the styles. No need to specify a GetWindowStyle here since | |
357 | // the base wxWindow member function will do it for us | |
358 | void SetWindowStyle(const long styles); | |
359 | ||
360 | // item status inquiries | |
361 | // --------------------- | |
362 | ||
363 | // is the item visible (it might be outside the view or not expanded)? | |
364 | bool IsVisible(const wxTreeItemId& item) const; | |
365 | // does the item has any children? | |
366 | bool HasChildren(const wxTreeItemId& item) const | |
367 | { return ItemHasChildren(item); } | |
368 | bool ItemHasChildren(const wxTreeItemId& item) const; | |
369 | // is the item expanded (only makes sense if HasChildren())? | |
370 | bool IsExpanded(const wxTreeItemId& item) const; | |
371 | // is this item currently selected (the same as has focus)? | |
372 | bool IsSelected(const wxTreeItemId& item) const; | |
373 | // is item text in bold font? | |
374 | bool IsBold(const wxTreeItemId& item) const; | |
375 | // does the layout include space for a button? | |
376 | ||
377 | // number of children | |
378 | // ------------------ | |
379 | ||
380 | // if 'recursively' is FALSE, only immediate children count, otherwise | |
381 | // the returned number is the number of all items in this branch | |
382 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); | |
383 | ||
384 | // navigation | |
385 | // ---------- | |
386 | ||
387 | // wxTreeItemId.IsOk() will return FALSE if there is no such item | |
388 | ||
389 | // get the root tree item | |
390 | wxTreeItemId GetRootItem() const { return m_anchor; } | |
391 | ||
392 | // get the item currently selected (may return NULL if no selection) | |
393 | wxTreeItemId GetSelection() const { return m_current; } | |
394 | ||
395 | // get the items currently selected, return the number of such item | |
396 | size_t GetSelections(wxArrayTreeItemIds&) const; | |
397 | ||
398 | // get the parent of this item (may return NULL if root) | |
399 | wxTreeItemId GetItemParent(const wxTreeItemId& item) const; | |
400 | ||
401 | // for this enumeration function you must pass in a "cookie" parameter | |
402 | // which is opaque for the application but is necessary for the library | |
403 | // to make these functions reentrant (i.e. allow more than one | |
404 | // enumeration on one and the same object simultaneously). Of course, | |
405 | // the "cookie" passed to GetFirstChild() and GetNextChild() should be | |
406 | // the same! | |
407 | ||
408 | // get the first child of this item | |
409 | #if !wxCHECK_VERSION(2, 5, 0) | |
410 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; | |
411 | #else | |
412 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const; | |
413 | #endif | |
414 | // get the next child | |
415 | #if !wxCHECK_VERSION(2, 5, 0) | |
416 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const; | |
417 | #else | |
418 | wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const; | |
419 | #endif | |
420 | // get the prev child | |
421 | #if !wxCHECK_VERSION(2, 5, 0) | |
422 | wxTreeItemId GetPrevChild(const wxTreeItemId& item, long& cookie) const; | |
423 | #else | |
424 | wxTreeItemId GetPrevChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const; | |
425 | #endif | |
426 | // get the last child of this item - this method doesn't use cookies | |
427 | wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
428 | ||
429 | // get the next sibling of this item | |
430 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
431 | // get the previous sibling | |
432 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
433 | ||
434 | // get first visible item | |
435 | wxTreeItemId GetFirstVisibleItem() const; | |
436 | // get the next visible item: item must be visible itself! | |
437 | // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() | |
438 | wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
439 | // get the previous visible item: item must be visible itself! | |
440 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
441 | ||
442 | // Only for internal use right now, but should probably be public | |
443 | wxTreeItemId GetNext(const wxTreeItemId& item) const; | |
444 | ||
445 | // operations | |
446 | // ---------- | |
447 | ||
448 | // add the root node to the tree | |
449 | wxTreeItemId AddRoot(const wxString& text, | |
450 | int image = -1, int selectedImage = -1, | |
451 | wxTreeItemData *data = NULL); | |
452 | ||
453 | // insert a new item in as the first child of the parent | |
454 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
455 | const wxString& text, | |
456 | int image = -1, int selectedImage = -1, | |
457 | wxTreeItemData *data = NULL); | |
458 | ||
459 | // insert a new item after a given one | |
460 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
461 | const wxTreeItemId& idPrevious, | |
462 | const wxString& text, | |
463 | int image = -1, int selectedImage = -1, | |
464 | wxTreeItemData *data = NULL); | |
465 | ||
466 | // insert a new item before the one with the given index | |
467 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
468 | size_t index, | |
469 | const wxString& text, | |
470 | int image = -1, int selectedImage = -1, | |
471 | wxTreeItemData *data = NULL); | |
472 | ||
473 | // insert a new item in as the last child of the parent | |
474 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
475 | const wxString& text, | |
476 | int image = -1, int selectedImage = -1, | |
477 | wxTreeItemData *data = NULL); | |
478 | ||
479 | // delete this item and associated data if any | |
480 | void Delete(const wxTreeItemId& item); | |
481 | // delete all children (but don't delete the item itself) | |
482 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
483 | void DeleteChildren(const wxTreeItemId& item); | |
484 | // delete all items from the tree | |
485 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
486 | void DeleteAllItems(); | |
487 | ||
488 | // expand this item | |
489 | void Expand(const wxTreeItemId& item); | |
490 | // expand this item and all subitems recursively | |
491 | void ExpandAll(const wxTreeItemId& item); | |
492 | // collapse the item without removing its children | |
493 | void Collapse(const wxTreeItemId& item); | |
494 | // collapse the item and remove all children | |
495 | void CollapseAndReset(const wxTreeItemId& item); | |
496 | // toggles the current state | |
497 | void Toggle(const wxTreeItemId& item); | |
498 | ||
499 | // remove the selection from currently selected item (if any) | |
500 | void Unselect(); | |
501 | void UnselectAll(); | |
502 | // select this item | |
503 | void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE, | |
504 | bool extended_select=FALSE); | |
505 | void SelectAll(bool extended_select=FALSE); | |
506 | // make sure this item is visible (expanding the parent item and/or | |
507 | // scrolling to this item if necessary) | |
508 | void EnsureVisible(const wxTreeItemId& item); | |
509 | // scroll to this item (but don't expand its parent) | |
510 | void ScrollTo(const wxTreeItemId& item); | |
511 | void AdjustMyScrollbars(); | |
512 | ||
513 | // The first function is more portable (because easier to implement | |
514 | // on other platforms), but the second one returns some extra info. | |
515 | wxTreeItemId HitTest(const wxPoint& point) | |
516 | { int dummy; return HitTest(point, dummy); } | |
517 | wxTreeItemId HitTest(const wxPoint& point, int& flags) | |
518 | { int col; return HitTest(point, flags, col); } | |
519 | // ALB | |
520 | wxTreeItemId HitTest(const wxPoint& point, int& flags, int& column); | |
521 | ||
522 | ||
523 | // get the bounding rectangle of the item (or of its label only) | |
524 | bool GetBoundingRect(const wxTreeItemId& item, | |
525 | wxRect& rect, | |
526 | bool textOnly = FALSE) const; | |
527 | ||
528 | // Start editing the item label: this (temporarily) replaces the item | |
529 | // with a one line edit control. The item will be selected if it hadn't | |
530 | // been before. | |
531 | void EditLabel( const wxTreeItemId& item ) { Edit( item ); } | |
532 | void Edit( const wxTreeItemId& item ); | |
533 | ||
534 | // sorting | |
535 | // this function is called to compare 2 items and should return -1, 0 | |
536 | // or +1 if the first item is less than, equal to or greater than the | |
537 | // second one. The base class version performs alphabetic comparaison | |
538 | // of item labels (GetText) | |
539 | virtual int OnCompareItems(const wxTreeItemId& item1, | |
540 | const wxTreeItemId& item2); | |
541 | // sort the children of this item using OnCompareItems | |
542 | // | |
543 | // NB: this function is not reentrant and not MT-safe (FIXME)! | |
544 | void SortChildren(const wxTreeItemId& item); | |
545 | ||
546 | // searching | |
547 | wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0); | |
548 | ||
549 | // deprecated functions: use Set/GetItemImage directly | |
550 | // get the selected item image | |
551 | int GetItemSelectedImage(const wxTreeItemId& item) const | |
552 | { return GetItemImage(item, wxTreeItemIcon_Selected); } | |
553 | // set the selected item image | |
554 | void SetItemSelectedImage(const wxTreeItemId& item, int image) | |
555 | { SetItemImage(item, image, wxTreeItemIcon_Selected); } | |
556 | ||
557 | // implementation only from now on | |
558 | ||
559 | // overridden base class virtuals | |
560 | virtual bool SetBackgroundColour(const wxColour& colour); | |
561 | virtual bool SetForegroundColour(const wxColour& colour); | |
562 | ||
563 | // callbacks | |
564 | void OnPaint( wxPaintEvent &event ); | |
565 | void OnSetFocus( wxFocusEvent &event ); | |
566 | void OnKillFocus( wxFocusEvent &event ); | |
567 | void OnChar( wxKeyEvent &event ); | |
568 | void OnMouse( wxMouseEvent &event ); | |
569 | void OnIdle( wxIdleEvent &event ); | |
570 | void OnScroll(wxScrollWinEvent& event); // ALB | |
571 | ||
572 | // implementation helpers | |
573 | void SendDeleteEvent(wxTreeListItem *itemBeingDeleted); | |
574 | ||
575 | void DrawBorder(const wxTreeItemId& item); | |
576 | void DrawLine(const wxTreeItemId& item, bool below); | |
577 | ||
578 | size_t GetColumnCount() const | |
579 | { return m_owner->GetHeaderWindow()->GetColumnCount(); } | |
580 | ||
581 | void SetMainColumn(size_t column) | |
582 | { | |
583 | if(column < GetColumnCount()) | |
584 | m_main_column = column; | |
585 | } | |
586 | size_t GetMainColumn() const { return m_main_column; } | |
587 | ||
588 | void SetItemText(const wxTreeItemId& item, size_t column, | |
589 | const wxString& text); | |
590 | wxString GetItemText(const wxTreeItemId& item, size_t column) const; | |
591 | ||
592 | void SetItemImage(const wxTreeItemId& item, size_t column, int image, | |
593 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
594 | int GetItemImage(const wxTreeItemId& item, size_t column, | |
595 | wxTreeItemIcon which = wxTreeItemIcon_Normal) const; | |
596 | ||
597 | void SetFocus(); | |
598 | ||
599 | protected: | |
600 | wxTreeListCtrl* m_owner; // ALB | |
601 | ||
602 | size_t m_main_column; // ALB | |
603 | ||
604 | friend class wxTreeListItem; | |
605 | friend class wxTreeListRenameTimer; | |
606 | friend class wxTreeListTextCtrl; | |
607 | ||
608 | wxFont m_normalFont; | |
609 | wxFont m_boldFont; | |
610 | ||
611 | wxTreeListItem *m_anchor; | |
612 | wxTreeListItem *m_current, *m_key_current, *m_currentEdit; | |
613 | int m_btnWidth, m_btnWidth2; | |
614 | int m_btnHeight, m_btnHeight2; | |
615 | int m_imgWidth, m_imgWidth2; | |
616 | int m_imgHeight, m_imgHeight2; | |
617 | unsigned short m_indent; | |
618 | int m_lineHeight; | |
619 | unsigned short m_linespacing; | |
620 | wxPen m_dottedPen; | |
621 | wxBrush *m_hilightBrush, | |
622 | *m_hilightUnfocusedBrush; | |
623 | bool m_hasFocus; | |
624 | public: | |
625 | bool m_dirty; | |
626 | protected: | |
627 | bool m_ownsImageListNormal, | |
628 | m_ownsImageListState, | |
629 | m_ownsImageListButtons; | |
630 | bool m_isDragging; // true between BEGIN/END drag events | |
631 | bool m_renameAccept; | |
632 | bool m_lastOnSame; // last click on the same item as prev | |
633 | wxImageList *m_imageListNormal, | |
634 | *m_imageListState, | |
635 | *m_imageListButtons; | |
636 | ||
637 | int m_dragCount; | |
638 | wxPoint m_dragStart; | |
639 | wxTreeListItem *m_dropTarget; | |
640 | wxCursor m_oldCursor; // cursor is changed while dragging | |
641 | wxTreeListItem *m_oldSelection; | |
642 | wxTreeListItem *m_underMouse; // for visual effects | |
643 | ||
644 | wxTimer *m_renameTimer; | |
645 | wxString m_renameRes; | |
646 | ||
647 | // char navigation | |
648 | wxTimer *m_findTimer; | |
649 | wxString m_findStr; | |
650 | ||
651 | // the common part of all ctors | |
652 | void Init(); | |
653 | ||
654 | // misc helpers | |
655 | wxTreeItemId DoInsertItem(const wxTreeItemId& parent, | |
656 | size_t previous, | |
657 | const wxString& text, | |
658 | int image, int selectedImage, | |
659 | wxTreeItemData *data); | |
660 | bool HasButtons(void) const | |
661 | { return (m_imageListButtons != NULL) || | |
662 | HasFlag (wxTR_TWIST_BUTTONS|wxTR_HAS_BUTTONS); } | |
663 | ||
664 | protected: | |
665 | void CalculateLineHeight(); | |
666 | int GetLineHeight(wxTreeListItem *item) const; | |
667 | void PaintLevel( wxTreeListItem *item, wxDC& dc, int level, int &y, | |
668 | int x_colstart); | |
669 | void PaintItem( wxTreeListItem *item, wxDC& dc); | |
670 | ||
671 | void CalculateLevel( wxTreeListItem *item, wxDC &dc, int level, int &y, | |
672 | int x_colstart); | |
673 | void CalculatePositions(); | |
674 | void CalculateSize( wxTreeListItem *item, wxDC &dc ); | |
675 | ||
676 | void RefreshSubtree( wxTreeListItem *item ); | |
677 | void RefreshLine( wxTreeListItem *item ); | |
678 | ||
679 | // redraw all selected items | |
680 | void RefreshSelected(); | |
681 | ||
682 | // RefreshSelected() recursive helper | |
683 | void RefreshSelectedUnder(wxTreeListItem *item); | |
684 | ||
685 | void OnRenameTimer(); | |
686 | void OnRenameAccept(); | |
687 | ||
688 | void FillArray(wxTreeListItem*, wxArrayTreeItemIds&) const; | |
689 | void SelectItemRange( wxTreeListItem *item1, wxTreeListItem *item2 ); | |
690 | bool TagAllChildrenUntilLast(wxTreeListItem *crt_item, | |
691 | wxTreeListItem *last_item, bool select); | |
692 | bool TagNextChildren(wxTreeListItem *crt_item, wxTreeListItem *last_item, | |
693 | bool select); | |
694 | void UnselectAllChildren( wxTreeListItem *item ); | |
695 | ||
696 | void DrawDropEffect(wxTreeListItem *item); | |
697 | ||
698 | private: | |
699 | DECLARE_EVENT_TABLE() | |
700 | DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow) | |
701 | }; | |
702 | ||
703 | ||
704 | // timer used for enabling in-place edit | |
705 | class wxTreeListRenameTimer: public wxTimer | |
706 | { | |
707 | public: | |
708 | wxTreeListRenameTimer( wxTreeListMainWindow *owner ); | |
709 | ||
710 | void Notify(); | |
711 | ||
712 | private: | |
713 | wxTreeListMainWindow *m_owner; | |
714 | }; | |
715 | ||
716 | // control used for in-place edit | |
717 | class wxTreeListTextCtrl: public wxTextCtrl | |
718 | { | |
719 | public: | |
720 | wxTreeListTextCtrl( wxWindow *parent, | |
721 | const wxWindowID id, | |
722 | bool *accept, | |
723 | wxString *res, | |
724 | wxTreeListMainWindow *owner, | |
725 | const wxString &value = wxEmptyString, | |
726 | const wxPoint &pos = wxDefaultPosition, | |
727 | const wxSize &size = wxDefaultSize, | |
728 | int style = wxSIMPLE_BORDER, | |
729 | const wxValidator& validator = wxDefaultValidator, | |
730 | const wxString &name = wxTextCtrlNameStr ); | |
731 | ||
732 | void OnChar( wxKeyEvent &event ); | |
733 | void OnKeyUp( wxKeyEvent &event ); | |
734 | void OnKillFocus( wxFocusEvent &event ); | |
735 | ||
736 | private: | |
737 | bool *m_accept; | |
738 | wxString *m_res; | |
739 | wxTreeListMainWindow *m_owner; | |
740 | wxString m_startValue; | |
741 | bool m_finished; | |
742 | ||
743 | DECLARE_EVENT_TABLE() | |
744 | }; | |
745 | ||
746 | // a tree item | |
747 | class wxTreeListItem | |
748 | { | |
749 | public: | |
750 | // ctors & dtor | |
751 | wxTreeListItem() { m_data = NULL; } | |
752 | wxTreeListItem( wxTreeListMainWindow *owner, | |
753 | wxTreeListItem *parent, | |
754 | const wxArrayString& text, | |
755 | int image, | |
756 | int selImage, | |
757 | wxTreeItemData *data ); | |
758 | ||
759 | ~wxTreeListItem(); | |
760 | ||
761 | // trivial accessors | |
762 | wxArrayTreeListItems& GetChildren() { return m_children; } | |
763 | ||
764 | const wxString GetText() const | |
765 | { | |
766 | if(m_text.GetCount() > 0) return m_text[0]; | |
767 | return wxEmptyString; | |
768 | } | |
769 | const wxString GetText(size_t col) const | |
770 | { | |
771 | if(m_text.GetCount() > col) return m_text[col]; | |
772 | return wxEmptyString; | |
773 | } | |
774 | int GetImage(wxTreeItemIcon which = wxTreeItemIcon_Normal) const | |
775 | { return m_images[which]; } | |
776 | int GetImage(size_t col, wxTreeItemIcon which=wxTreeItemIcon_Normal) const | |
777 | { | |
778 | if(col == m_owner->GetMainColumn()) return m_images[which]; | |
779 | if(col < m_col_images.GetCount()) return m_col_images[col]; | |
780 | return NO_IMAGE; | |
781 | } | |
782 | wxTreeItemData *GetData() const { return m_data; } | |
783 | ||
784 | // returns the current image for the item (depending on its | |
785 | // selected/expanded/whatever state) | |
786 | int GetCurrentImage() const; | |
787 | ||
788 | void SetText( const wxString &text ); | |
789 | void SetText(size_t col, const wxString& text) // ALB | |
790 | { | |
791 | if(col < m_text.GetCount()) | |
792 | m_text[col] = text; | |
793 | else if(col < m_owner->GetColumnCount()) { | |
794 | int howmany = m_owner->GetColumnCount(); | |
795 | for(int i = m_text.GetCount(); i < howmany; ++i) | |
796 | m_text.Add(wxEmptyString); | |
797 | m_text[col] = text; | |
798 | } | |
799 | } | |
800 | void SetImage(int image, wxTreeItemIcon which) { m_images[which] = image; } | |
801 | void SetImage(size_t col, int image, wxTreeItemIcon which) | |
802 | { | |
803 | if(col == m_owner->GetMainColumn()) m_images[which] = image; | |
804 | else if(col < m_col_images.GetCount()) | |
805 | m_col_images[col] = image; | |
806 | else if(col < m_owner->GetColumnCount()) { | |
807 | int howmany = m_owner->GetColumnCount(); | |
808 | for(int i = m_col_images.GetCount(); i < howmany; ++i) | |
809 | m_col_images.Add(NO_IMAGE); | |
810 | m_col_images[col] = image; | |
811 | } | |
812 | } | |
813 | ||
814 | void SetData(wxTreeItemData *data) { m_data = data; } | |
815 | ||
816 | void SetHasPlus(bool has = TRUE) { m_hasPlus = has; } | |
817 | ||
818 | void SetBold(bool bold) { m_isBold = bold; } | |
819 | ||
820 | int GetX() const { return m_x; } | |
821 | int GetY() const { return m_y; } | |
822 | ||
823 | void SetX(int x) { m_x = x; } | |
824 | void SetY(int y) { m_y = y; } | |
825 | ||
826 | int GetHeight() const { return m_height; } | |
827 | int GetWidth() const { return m_width; } | |
828 | ||
829 | void SetHeight(int h) { m_height = h; } | |
830 | void SetWidth(int w) { m_width = w; } | |
831 | ||
832 | wxTreeListItem *GetItemParent() const { return m_parent; } | |
833 | ||
834 | // operations | |
835 | // deletes all children notifying the treectrl about it if !NULL | |
836 | // pointer given | |
837 | void DeleteChildren(wxTreeListMainWindow *tree = NULL); | |
838 | ||
839 | // get count of all children (and grand children if 'recursively') | |
840 | size_t GetChildrenCount(bool recursively = TRUE) const; | |
841 | ||
842 | void Insert(wxTreeListItem *child, size_t index) | |
843 | { m_children.Insert(child, index); } | |
844 | ||
845 | void GetSize( int &x, int &y, const wxTreeListMainWindow* ); | |
846 | ||
847 | // return the item at given position (or NULL if no item), onButton is | |
848 | // TRUE if the point belongs to the item's button, otherwise it lies | |
849 | // on the button's label | |
850 | wxTreeListItem *HitTest( const wxPoint& point, | |
851 | const wxTreeListMainWindow *, | |
852 | int &flags, | |
853 | int level ); | |
854 | wxTreeListItem *HitTest( const wxPoint& point, | |
855 | const wxTreeListMainWindow *, | |
856 | int &flags, int& column /*ALB*/, | |
857 | int level ); | |
858 | ||
859 | void Expand() { m_isCollapsed = FALSE; } | |
860 | void Collapse() { m_isCollapsed = TRUE; } | |
861 | ||
862 | void SetHilight( bool set = TRUE ) { m_hasHilight = set; } | |
863 | ||
864 | // status inquiries | |
865 | bool HasChildren() const { return !m_children.IsEmpty(); } | |
866 | bool IsSelected() const { return m_hasHilight != 0; } | |
867 | bool IsExpanded() const { return !m_isCollapsed; } | |
868 | bool HasPlus() const { return m_hasPlus || HasChildren(); } | |
869 | bool IsBold() const { return m_isBold != 0; } | |
870 | ||
871 | // attributes | |
872 | // get them - may be NULL | |
873 | wxTreeItemAttr *GetAttributes() const { return m_attr; } | |
874 | // get them ensuring that the pointer is not NULL | |
875 | wxTreeItemAttr& Attr() | |
876 | { | |
877 | if ( !m_attr ) | |
878 | { | |
879 | m_attr = new wxTreeItemAttr; | |
880 | m_ownsAttr = TRUE; | |
881 | } | |
882 | return *m_attr; | |
883 | } | |
884 | // set them | |
885 | void SetAttributes(wxTreeItemAttr *attr) | |
886 | { | |
887 | if ( m_ownsAttr ) delete m_attr; | |
888 | m_attr = attr; | |
889 | m_ownsAttr = FALSE; | |
890 | } | |
891 | // set them and delete when done | |
892 | void AssignAttributes(wxTreeItemAttr *attr) | |
893 | { | |
894 | SetAttributes(attr); | |
895 | m_ownsAttr = TRUE; | |
896 | } | |
897 | ||
898 | private: | |
899 | wxTreeListMainWindow *m_owner; // control the item belongs to | |
900 | ||
901 | // since there can be very many of these, we save size by chosing | |
902 | // the smallest representation for the elements and by ordering | |
903 | // the members to avoid padding. | |
904 | wxArrayString m_text; // labels to be rendered for item | |
905 | ||
906 | wxTreeItemData *m_data; // user-provided data | |
907 | ||
908 | wxArrayTreeListItems m_children; // list of children | |
909 | wxTreeListItem *m_parent; // parent of this item | |
910 | ||
911 | wxTreeItemAttr *m_attr; // attributes??? | |
912 | ||
913 | // tree ctrl images for the normal, selected, expanded and | |
914 | // expanded+selected states | |
915 | short m_images[wxTreeItemIcon_Max]; | |
916 | wxArrayShort m_col_images; // images for the various columns (!= main) | |
917 | ||
918 | wxCoord m_x; // (virtual) offset from top | |
919 | wxCoord m_y; // (virtual) offset from left | |
920 | short m_width; // width of this item | |
921 | unsigned char m_height; // height of this item | |
922 | ||
923 | // use bitfields to save size | |
924 | int m_isCollapsed :1; | |
925 | int m_hasHilight :1; // same as focused | |
926 | int m_hasPlus :1; // used for item which doesn't have | |
927 | // children but has a [+] button | |
928 | int m_isBold :1; // render the label in bold font | |
929 | int m_ownsAttr :1; // delete attribute when done | |
930 | }; | |
931 | ||
932 | // =========================================================================== | |
933 | // implementation | |
934 | // =========================================================================== | |
935 | ||
936 | // ---------------------------------------------------------------------------- | |
937 | // private functions | |
938 | // ---------------------------------------------------------------------------- | |
939 | ||
940 | // translate the key or mouse event flags to the type of selection we're | |
941 | // dealing with | |
942 | static void EventFlagsToSelType(long style, | |
943 | bool shiftDown, | |
944 | bool ctrlDown, | |
945 | bool &is_multiple, | |
946 | bool &extended_select, | |
947 | bool &unselect_others) | |
948 | { | |
949 | is_multiple = (style & wxTR_MULTIPLE) != 0; | |
950 | extended_select = shiftDown && is_multiple; | |
951 | unselect_others = !(extended_select || (ctrlDown && is_multiple)); | |
952 | } | |
953 | ||
954 | // --------------------------------------------------------------------------- | |
955 | // wxTreeListRenameTimer (internal) | |
956 | // --------------------------------------------------------------------------- | |
957 | ||
958 | wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow *owner ) | |
959 | { | |
960 | m_owner = owner; | |
961 | } | |
962 | ||
963 | void wxTreeListRenameTimer::Notify() | |
964 | { | |
965 | m_owner->OnRenameTimer(); | |
966 | } | |
967 | ||
968 | //----------------------------------------------------------------------------- | |
969 | // wxTreeListTextCtrl (internal) | |
970 | //----------------------------------------------------------------------------- | |
971 | ||
972 | BEGIN_EVENT_TABLE(wxTreeListTextCtrl,wxTextCtrl) | |
973 | EVT_CHAR (wxTreeListTextCtrl::OnChar) | |
974 | EVT_KEY_UP (wxTreeListTextCtrl::OnKeyUp) | |
975 | EVT_KILL_FOCUS (wxTreeListTextCtrl::OnKillFocus) | |
976 | END_EVENT_TABLE() | |
977 | ||
978 | wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow *parent, | |
979 | const wxWindowID id, | |
980 | bool *accept, | |
981 | wxString *res, | |
982 | wxTreeListMainWindow *owner, | |
983 | const wxString &value, | |
984 | const wxPoint &pos, | |
985 | const wxSize &size, | |
986 | int style, | |
987 | const wxValidator& validator, | |
988 | const wxString &name ) | |
989 | : wxTextCtrl( parent, id, value, pos, size, style, validator, name ) | |
990 | { | |
991 | m_res = res; | |
992 | m_accept = accept; | |
993 | m_owner = owner; | |
994 | (*m_accept) = FALSE; | |
995 | (*m_res) = wxEmptyString; | |
996 | m_startValue = value; | |
997 | m_finished = FALSE; | |
998 | } | |
999 | ||
1000 | void wxTreeListTextCtrl::OnChar( wxKeyEvent &event ) | |
1001 | { | |
1002 | if (event.m_keyCode == WXK_RETURN) | |
1003 | { | |
1004 | (*m_accept) = TRUE; | |
1005 | (*m_res) = GetValue(); | |
1006 | ||
1007 | if ((*m_res) != m_startValue) | |
1008 | m_owner->OnRenameAccept(); | |
1009 | ||
1010 | if (!wxPendingDelete.Member(this)) | |
1011 | wxPendingDelete.Append(this); | |
1012 | ||
1013 | m_finished = TRUE; | |
1014 | m_owner->SetFocus(); // This doesn't work. TODO. | |
1015 | ||
1016 | return; | |
1017 | } | |
1018 | if (event.m_keyCode == WXK_ESCAPE) | |
1019 | { | |
1020 | (*m_accept) = FALSE; | |
1021 | (*m_res) = wxEmptyString; | |
1022 | ||
1023 | if (!wxPendingDelete.Member(this)) | |
1024 | wxPendingDelete.Append(this); | |
1025 | ||
1026 | m_finished = TRUE; | |
1027 | m_owner->SetFocus(); // This doesn't work. TODO. | |
1028 | ||
1029 | return; | |
1030 | } | |
1031 | event.Skip(); | |
1032 | } | |
1033 | ||
1034 | void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent &event ) | |
1035 | { | |
1036 | if (m_finished) | |
1037 | { | |
1038 | event.Skip(); | |
1039 | return; | |
1040 | } | |
1041 | ||
1042 | // auto-grow the textctrl: | |
1043 | wxSize parentSize = m_owner->GetSize(); | |
1044 | wxPoint myPos = GetPosition(); | |
1045 | wxSize mySize = GetSize(); | |
1046 | int sx, sy; | |
1047 | GetTextExtent(GetValue() + _T("M"), &sx, &sy); | |
1048 | if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; | |
1049 | if (mySize.x > sx) sx = mySize.x; | |
1050 | SetSize(sx, -1); | |
1051 | ||
1052 | event.Skip(); | |
1053 | } | |
1054 | ||
1055 | void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent &event ) | |
1056 | { | |
1057 | if (m_finished) | |
1058 | { | |
1059 | event.Skip(); | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | if (!wxPendingDelete.Member(this)) | |
1064 | wxPendingDelete.Append(this); | |
1065 | ||
1066 | (*m_accept) = TRUE; | |
1067 | (*m_res) = GetValue(); | |
1068 | ||
1069 | if ((*m_res) != m_startValue) | |
1070 | m_owner->OnRenameAccept(); | |
1071 | } | |
1072 | ||
1073 | //----------------------------------------------------------------------------- | |
1074 | // wxTreeListHeaderWindow | |
1075 | //----------------------------------------------------------------------------- | |
1076 | ||
1077 | IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow,wxWindow); | |
1078 | ||
1079 | BEGIN_EVENT_TABLE(wxTreeListHeaderWindow,wxWindow) | |
1080 | EVT_ERASE_BACKGROUND (wxTreeListHeaderWindow::OnEraseBackground) | |
1081 | EVT_PAINT (wxTreeListHeaderWindow::OnPaint) | |
1082 | EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse) | |
1083 | EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus) | |
1084 | END_EVENT_TABLE() | |
1085 | ||
1086 | void wxTreeListHeaderWindow::Init() | |
1087 | { | |
1088 | m_currentCursor = (wxCursor *) NULL; | |
1089 | m_isDragging = FALSE; | |
1090 | m_dirty = FALSE; | |
1091 | m_total_col_width = 0; | |
1092 | } | |
1093 | ||
1094 | wxTreeListHeaderWindow::wxTreeListHeaderWindow() | |
1095 | { | |
1096 | Init(); | |
1097 | ||
1098 | m_owner = (wxTreeListMainWindow *) NULL; | |
1099 | m_resizeCursor = (wxCursor *) NULL; | |
1100 | } | |
1101 | ||
1102 | wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow *win, | |
1103 | wxWindowID id, | |
1104 | wxTreeListMainWindow *owner, | |
1105 | const wxPoint& pos, | |
1106 | const wxSize& size, | |
1107 | long style, | |
1108 | const wxString &name ) | |
1109 | : wxWindow( win, id, pos, size, style, name ) | |
1110 | { | |
1111 | Init(); | |
1112 | ||
1113 | m_owner = owner; | |
1114 | m_resizeCursor = new wxCursor(wxCURSOR_SIZEWE); | |
1115 | ||
1116 | SetBackgroundColour(wxSystemSettings::GetSystemColour( | |
1117 | wxSYS_COLOUR_BTNFACE)); | |
1118 | } | |
1119 | ||
1120 | wxTreeListHeaderWindow::~wxTreeListHeaderWindow() | |
1121 | { | |
1122 | delete m_resizeCursor; | |
1123 | } | |
1124 | ||
1125 | void wxTreeListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) | |
1126 | { | |
1127 | #ifdef __WXGTK__ | |
1128 | GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL | |
1129 | : GTK_STATE_INSENSITIVE; | |
1130 | ||
1131 | x = dc->XLOG2DEV( x ); | |
1132 | ||
1133 | gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, | |
1134 | state, GTK_SHADOW_OUT, | |
1135 | (GdkRectangle*) NULL, m_wxwindow, "button", | |
1136 | x-1, y-1, w+2, h+2); | |
1137 | #elif defined( __WXMAC__ ) | |
1138 | const int m_corner = 1; | |
1139 | ||
1140 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1141 | ||
1142 | dc->SetPen( wxPen(wxSystemSettings::GetSystemColour( | |
1143 | wxSYS_COLOUR_BTNSHADOW), 1, wxSOLID)); | |
1144 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
1145 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
1146 | ||
1147 | wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); | |
1148 | ||
1149 | dc->SetPen( pen ); | |
1150 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1151 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
1152 | ||
1153 | dc->SetPen( *wxWHITE_PEN ); | |
1154 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1155 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1156 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1157 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
1158 | #else // !GTK, !Mac | |
1159 | const int m_corner = 1; | |
1160 | ||
1161 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1162 | ||
1163 | dc->SetPen( *wxBLACK_PEN ); | |
1164 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
1165 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
1166 | ||
1167 | wxPen pen(wxSystemSettings::GetSystemColour( | |
1168 | wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID); | |
1169 | ||
1170 | dc->SetPen( pen ); | |
1171 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1172 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
1173 | ||
1174 | dc->SetPen( *wxWHITE_PEN ); | |
1175 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1176 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1177 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1178 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
1179 | #endif | |
1180 | } | |
1181 | ||
1182 | // shift the DC origin to match the position of the main window horz | |
1183 | // scrollbar: this allows us to always use logical coords | |
1184 | void wxTreeListHeaderWindow::AdjustDC(wxDC& dc) | |
1185 | { | |
1186 | int xpix; | |
1187 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1188 | ||
1189 | int x; | |
1190 | m_owner->GetViewStart( &x, NULL ); | |
1191 | ||
1192 | // account for the horz scrollbar offset | |
1193 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
1194 | } | |
1195 | ||
1196 | ||
1197 | void wxTreeListHeaderWindow::OnEraseBackground( wxEraseEvent& event ) | |
1198 | { | |
1199 | } | |
1200 | ||
1201 | void wxTreeListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
1202 | { | |
1203 | #ifdef __WXGTK__ | |
1204 | wxClientDC real_dc( this ); | |
1205 | #else | |
1206 | wxPaintDC real_dc( this ); | |
1207 | #endif | |
1208 | ||
1209 | AdjustDC( real_dc ); | |
1210 | ||
1211 | // width and height of the entire header window | |
1212 | int w, h; | |
1213 | GetClientSize( &w, &h ); | |
1214 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); | |
1215 | ||
1216 | // Setup double buffering to eliminate the flicker | |
1217 | wxMemoryDC dc; | |
1218 | wxBitmap buffer(w, h); | |
1219 | dc.SelectObject(buffer); | |
1220 | dc.SetBackground(wxBrush(GetBackgroundColour())); | |
1221 | dc.Clear(); | |
1222 | ||
1223 | dc.BeginDrawing(); | |
1224 | dc.SetFont( GetFont() ); | |
1225 | dc.SetBackgroundMode(wxTRANSPARENT); | |
1226 | ||
1227 | // do *not* use the listctrl colour for headers - one day we will have a | |
1228 | // function to set it separately | |
1229 | //dc.SetTextForeground( *wxBLACK ); | |
1230 | dc.SetTextForeground(wxSystemSettings:: | |
1231 | GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); | |
1232 | ||
1233 | int x = HEADER_OFFSET_X; | |
1234 | ||
1235 | int numColumns = GetColumnCount(); | |
1236 | for ( int i = 0; i < numColumns && x < w; i++ ) | |
1237 | { | |
1238 | if (!GetColumnShown (i)) continue; | |
1239 | ||
1240 | wxTreeListColumnInfo& column = GetColumn(i); | |
1241 | int wCol = column.GetWidth(); | |
1242 | ||
1243 | // the width of the rect to draw: make it smaller to fit entirely | |
1244 | // inside the column rect | |
1245 | int cw = wCol - 2; | |
1246 | ||
1247 | dc.SetPen( *wxWHITE_PEN ); | |
1248 | ||
1249 | //DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 ); | |
1250 | wxRendererNative::Get().DrawHeaderButton( | |
1251 | this, dc, wxRect(x, HEADER_OFFSET_Y, cw, h - 2), | |
1252 | m_parent->IsEnabled() ? 0 : wxCONTROL_DISABLED); | |
1253 | ||
1254 | ||
1255 | // if we have an image, draw it on the right of the label | |
1256 | int image = column.GetImage(); //item.m_image; | |
1257 | int ix = -2, iy = 0; | |
1258 | wxImageList* imageList = m_owner->GetImageList(); | |
1259 | if(image != -1) { | |
1260 | if(imageList) { | |
1261 | imageList->GetSize(image, ix, iy); | |
1262 | } | |
1263 | //else: ignore the column image | |
1264 | } | |
1265 | ||
1266 | int text_width = 0; | |
1267 | int text_x = x; | |
1268 | int image_offset = cw - ix - 1; | |
1269 | ||
1270 | switch(column.GetAlignment()) { | |
1271 | case wxTL_ALIGN_LEFT: | |
1272 | text_x += EXTRA_WIDTH; | |
1273 | cw -= ix + 2; | |
1274 | break; | |
1275 | case wxTL_ALIGN_RIGHT: | |
1276 | dc.GetTextExtent(column.GetText(), &text_width, NULL); | |
1277 | text_x += cw - text_width - EXTRA_WIDTH; | |
1278 | image_offset = 0; | |
1279 | break; | |
1280 | case wxTL_ALIGN_CENTER: | |
1281 | dc.GetTextExtent(column.GetText(), &text_width, NULL); | |
1282 | text_x += (cw - text_width)/2 + ix + 2; | |
1283 | image_offset = (cw - text_width - ix - 2)/2; | |
1284 | break; | |
1285 | } | |
1286 | ||
1287 | // draw the image | |
1288 | if(image != -1 && imageList) { | |
1289 | imageList->Draw(image, dc, x + image_offset/*cw - ix - 1*/, | |
1290 | HEADER_OFFSET_Y + (h - 4 - iy)/2, | |
1291 | wxIMAGELIST_DRAW_TRANSPARENT); | |
1292 | } | |
1293 | ||
1294 | // draw the text clipping it so that it doesn't overwrite the column | |
1295 | // boundary | |
1296 | wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 ); | |
1297 | ||
1298 | dc.DrawText( column.GetText(), | |
1299 | text_x, HEADER_OFFSET_Y + EXTRA_HEIGHT ); | |
1300 | ||
1301 | x += wCol; | |
1302 | } | |
1303 | ||
1304 | int more_w = m_owner->GetSize().x - x -1; | |
1305 | if (more_w > 0) | |
1306 | { | |
1307 | //DoDrawRect( &dc, x, HEADER_OFFSET_Y, more_w, h-2 ); | |
1308 | wxRendererNative::Get().DrawHeaderButton( | |
1309 | this, dc, wxRect(x, HEADER_OFFSET_Y, more_w, h-2), | |
1310 | m_parent->IsEnabled() ? 0 : wxCONTROL_DISABLED); | |
1311 | } | |
1312 | ||
1313 | // Finish up by drawing the buffer to the real dc | |
1314 | dc.EndDrawing(); | |
1315 | dc.SelectObject(wxNullBitmap); | |
1316 | real_dc.DrawBitmap(buffer, 0, 0, false); | |
1317 | } | |
1318 | ||
1319 | void wxTreeListHeaderWindow::DrawCurrent() | |
1320 | { | |
1321 | int x1 = m_currentX; | |
1322 | int y1 = 0; | |
1323 | ClientToScreen( &x1, &y1 ); | |
1324 | ||
1325 | int x2 = m_currentX-1; | |
1326 | #ifdef __WXMSW__ | |
1327 | ++x2; // but why ? | |
1328 | #endif | |
1329 | int y2 = 0; | |
1330 | m_owner->GetClientSize( NULL, &y2 ); | |
1331 | m_owner->ClientToScreen( &x2, &y2 ); | |
1332 | ||
1333 | wxScreenDC dc; | |
1334 | dc.SetLogicalFunction( wxINVERT ); | |
1335 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); | |
1336 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
1337 | ||
1338 | AdjustDC(dc); | |
1339 | ||
1340 | dc.DrawLine( x1, y1, x2, y2 ); | |
1341 | ||
1342 | dc.SetLogicalFunction( wxCOPY ); | |
1343 | ||
1344 | dc.SetPen( wxNullPen ); | |
1345 | dc.SetBrush( wxNullBrush ); | |
1346 | } | |
1347 | ||
1348 | void wxTreeListHeaderWindow::OnMouse( wxMouseEvent &event ) | |
1349 | { | |
1350 | // we want to work with logical coords | |
1351 | int x; | |
1352 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
1353 | int y = event.GetY(); | |
1354 | ||
1355 | if (m_isDragging) | |
1356 | { | |
1357 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, | |
1358 | event.GetPosition()); | |
1359 | ||
1360 | // we don't draw the line beyond our window, but we allow dragging it | |
1361 | // there | |
1362 | int w = 0; | |
1363 | GetClientSize( &w, NULL ); | |
1364 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); | |
1365 | w -= 6; | |
1366 | ||
1367 | // erase the line if it was drawn | |
1368 | if ( m_currentX < w ) | |
1369 | DrawCurrent(); | |
1370 | ||
1371 | if (event.ButtonUp()) | |
1372 | { | |
1373 | ReleaseMouse(); | |
1374 | m_isDragging = FALSE; | |
1375 | m_dirty = TRUE; | |
1376 | SetColumnWidth( m_column, m_currentX - m_minX ); | |
1377 | Refresh(); | |
1378 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, | |
1379 | event.GetPosition()); | |
1380 | } | |
1381 | else | |
1382 | { | |
1383 | if (x > m_minX + 7) | |
1384 | m_currentX = x; | |
1385 | else | |
1386 | m_currentX = m_minX + 7; | |
1387 | ||
1388 | // draw in the new location | |
1389 | if ( m_currentX < w ) | |
1390 | DrawCurrent(); | |
1391 | } | |
1392 | } | |
1393 | else // not dragging | |
1394 | { | |
1395 | m_minX = 0; | |
1396 | bool hit_border = FALSE; | |
1397 | ||
1398 | // end of the current column | |
1399 | int xpos = 0; | |
1400 | ||
1401 | // find the column where this event occured | |
1402 | int countCol = GetColumnCount(); | |
1403 | for (int col = 0; col < countCol; col++) | |
1404 | { | |
1405 | if (!GetColumnShown (col)) continue; | |
1406 | xpos += GetColumnWidth (col); | |
1407 | m_column = col; | |
1408 | ||
1409 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
1410 | { | |
1411 | // near the column border | |
1412 | hit_border = TRUE; | |
1413 | break; | |
1414 | } | |
1415 | ||
1416 | if ( x < xpos ) | |
1417 | { | |
1418 | // inside the column | |
1419 | break; | |
1420 | } | |
1421 | ||
1422 | m_minX = xpos; | |
1423 | } | |
1424 | ||
1425 | if (event.LeftDown() || event.RightUp()) | |
1426 | { | |
1427 | if (hit_border && event.LeftDown()) | |
1428 | { | |
1429 | m_isDragging = TRUE; | |
1430 | m_currentX = x; | |
1431 | DrawCurrent(); | |
1432 | CaptureMouse(); | |
1433 | SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, | |
1434 | event.GetPosition()); | |
1435 | } | |
1436 | else // click on a column | |
1437 | { | |
1438 | SendListEvent( event.LeftDown() | |
1439 | ? wxEVT_COMMAND_LIST_COL_CLICK | |
1440 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
1441 | event.GetPosition()); | |
1442 | } | |
1443 | } | |
1444 | else if (event.Moving()) | |
1445 | { | |
1446 | bool setCursor; | |
1447 | if (hit_border) | |
1448 | { | |
1449 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
1450 | m_currentCursor = m_resizeCursor; | |
1451 | } | |
1452 | else | |
1453 | { | |
1454 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
1455 | m_currentCursor = wxSTANDARD_CURSOR; | |
1456 | } | |
1457 | ||
1458 | if ( setCursor ) | |
1459 | SetCursor(*m_currentCursor); | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1465 | { | |
1466 | m_owner->SetFocus(); | |
1467 | } | |
1468 | ||
1469 | void wxTreeListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos) | |
1470 | { | |
1471 | wxWindow *parent = GetParent(); | |
1472 | wxListEvent le( type, parent->GetId() ); | |
1473 | le.SetEventObject( parent ); | |
1474 | le.m_pointDrag = pos; | |
1475 | ||
1476 | // the position should be relative to the parent window, not | |
1477 | // this one for compatibility with MSW and common sense: the | |
1478 | // user code doesn't know anything at all about this header | |
1479 | // window, so why should it get positions relative to it? | |
1480 | le.m_pointDrag.y -= GetSize().y; | |
1481 | ||
1482 | le.m_col = m_column; | |
1483 | parent->GetEventHandler()->ProcessEvent( le ); | |
1484 | } | |
1485 | ||
1486 | void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo& col) | |
1487 | { | |
1488 | m_columns.Add(col); | |
1489 | m_total_col_width += col.GetWidth(); | |
1490 | //m_owner->GetHeaderWindow()->Refresh(); | |
1491 | //m_dirty = TRUE; | |
1492 | m_owner->AdjustMyScrollbars(); | |
1493 | m_owner->m_dirty = TRUE; | |
1494 | Refresh(); | |
1495 | } | |
1496 | ||
1497 | void wxTreeListHeaderWindow::SetColumnWidth(size_t column, size_t width) | |
1498 | { | |
1499 | if(column < GetColumnCount()) { | |
1500 | m_total_col_width -= m_columns[column].GetWidth(); | |
1501 | m_columns[column].SetWidth(width); | |
1502 | m_total_col_width += width; | |
1503 | m_owner->AdjustMyScrollbars(); | |
1504 | m_owner->m_dirty = TRUE; | |
1505 | //m_dirty = TRUE; | |
1506 | Refresh(); | |
1507 | } | |
1508 | } | |
1509 | ||
1510 | ||
1511 | void wxTreeListHeaderWindow::InsertColumn(size_t before, | |
1512 | const wxTreeListColumnInfo& col) | |
1513 | { | |
1514 | wxCHECK_RET(before < GetColumnCount(), wxT("Invalid column index")); | |
1515 | m_columns.Insert(col, before); | |
1516 | m_total_col_width += col.GetWidth(); | |
1517 | //m_dirty = TRUE; | |
1518 | //m_owner->GetHeaderWindow()->Refresh(); | |
1519 | m_owner->AdjustMyScrollbars(); | |
1520 | m_owner->m_dirty = TRUE; | |
1521 | Refresh(); | |
1522 | } | |
1523 | ||
1524 | void wxTreeListHeaderWindow::RemoveColumn(size_t column) | |
1525 | { | |
1526 | wxCHECK_RET(column < GetColumnCount(), wxT("Invalid column")); | |
1527 | m_total_col_width -= m_columns[column].GetWidth(); | |
1528 | m_columns.RemoveAt(column); | |
1529 | //m_dirty = TRUE; | |
1530 | m_owner->AdjustMyScrollbars(); | |
1531 | m_owner->m_dirty = TRUE; | |
1532 | Refresh(); | |
1533 | } | |
1534 | ||
1535 | void wxTreeListHeaderWindow::SetColumn(size_t column, | |
1536 | const wxTreeListColumnInfo& info) | |
1537 | { | |
1538 | wxCHECK_RET(column < GetColumnCount(), wxT("Invalid column")); | |
1539 | size_t w = m_columns[column].GetWidth(); | |
1540 | m_columns[column] = info; | |
1541 | //m_owner->GetHeaderWindow()->Refresh(); | |
1542 | //m_dirty = TRUE; | |
1543 | if(w != info.GetWidth()) { | |
1544 | m_total_col_width += info.GetWidth() - w; | |
1545 | m_owner->AdjustMyScrollbars(); | |
1546 | m_owner->m_dirty = TRUE; | |
1547 | } | |
1548 | Refresh(); | |
1549 | } | |
1550 | ||
1551 | // --------------------------------------------------------------------------- | |
1552 | // wxTreeListItem | |
1553 | // --------------------------------------------------------------------------- | |
1554 | ||
1555 | wxTreeListItem::wxTreeListItem(wxTreeListMainWindow *owner, | |
1556 | wxTreeListItem *parent, | |
1557 | const wxArrayString& text, | |
1558 | int image, int selImage, | |
1559 | wxTreeItemData *data) | |
1560 | : m_text(text) | |
1561 | { | |
1562 | m_images[wxTreeItemIcon_Normal] = image; | |
1563 | m_images[wxTreeItemIcon_Selected] = selImage; | |
1564 | m_images[wxTreeItemIcon_Expanded] = NO_IMAGE; | |
1565 | m_images[wxTreeItemIcon_SelectedExpanded] = NO_IMAGE; | |
1566 | ||
1567 | m_data = data; | |
1568 | m_x = m_y = 0; | |
1569 | ||
1570 | m_isCollapsed = TRUE; | |
1571 | m_hasHilight = FALSE; | |
1572 | m_hasPlus = FALSE; | |
1573 | m_isBold = FALSE; | |
1574 | ||
1575 | m_owner = owner; | |
1576 | ||
1577 | m_parent = parent; | |
1578 | ||
1579 | m_attr = (wxTreeItemAttr *)NULL; | |
1580 | m_ownsAttr = FALSE; | |
1581 | ||
1582 | // We don't know the height here yet. | |
1583 | m_width = 0; | |
1584 | m_height = 0; | |
1585 | } | |
1586 | ||
1587 | wxTreeListItem::~wxTreeListItem() | |
1588 | { | |
1589 | delete m_data; | |
1590 | ||
1591 | if (m_ownsAttr) delete m_attr; | |
1592 | ||
1593 | wxASSERT_MSG( m_children.IsEmpty(), | |
1594 | wxT("please call DeleteChildren() before deleting the item") ); | |
1595 | } | |
1596 | ||
1597 | void wxTreeListItem::DeleteChildren(wxTreeListMainWindow *tree) | |
1598 | { | |
1599 | size_t count = m_children.Count(); | |
1600 | for ( size_t n = 0; n < count; n++ ) | |
1601 | { | |
1602 | wxTreeListItem *child = m_children[n]; | |
1603 | if (tree) | |
1604 | tree->SendDeleteEvent(child); | |
1605 | ||
1606 | child->DeleteChildren(tree); | |
1607 | delete child; | |
1608 | } | |
1609 | ||
1610 | m_children.Empty(); | |
1611 | } | |
1612 | ||
1613 | void wxTreeListItem::SetText( const wxString &text ) | |
1614 | { | |
1615 | if(m_text.GetCount() > 0) m_text[0] = text; | |
1616 | else { | |
1617 | m_text.Add(text); | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | size_t wxTreeListItem::GetChildrenCount(bool recursively) const | |
1622 | { | |
1623 | size_t count = m_children.Count(); | |
1624 | if ( !recursively ) | |
1625 | return count; | |
1626 | ||
1627 | size_t total = count; | |
1628 | for (size_t n = 0; n < count; ++n) | |
1629 | { | |
1630 | total += m_children[n]->GetChildrenCount(); | |
1631 | } | |
1632 | ||
1633 | return total; | |
1634 | } | |
1635 | ||
1636 | void wxTreeListItem::GetSize( int &x, int &y, | |
1637 | const wxTreeListMainWindow *theButton ) | |
1638 | { | |
1639 | int bottomY=m_y+theButton->GetLineHeight(this); | |
1640 | if ( y < bottomY ) y = bottomY; | |
1641 | int width = m_x + m_width; | |
1642 | if ( x < width ) x = width; | |
1643 | ||
1644 | if (IsExpanded()) | |
1645 | { | |
1646 | size_t count = m_children.Count(); | |
1647 | for ( size_t n = 0; n < count; ++n ) | |
1648 | { | |
1649 | m_children[n]->GetSize( x, y, theButton ); | |
1650 | } | |
1651 | } | |
1652 | } | |
1653 | ||
1654 | wxTreeListItem *wxTreeListItem::HitTest(const wxPoint& point, | |
1655 | const wxTreeListMainWindow *theCtrl, | |
1656 | int &flags, | |
1657 | int level) | |
1658 | { | |
1659 | // for a hidden root node, don't evaluate it, but do evaluate children | |
1660 | if (!(theCtrl->HasFlag(wxTR_HIDE_ROOT) && (level == 0))) | |
1661 | { | |
1662 | // evaluate the item | |
1663 | int h = theCtrl->GetLineHeight(this); | |
1664 | if ((point.y > m_y) && (point.y <= m_y + h)) | |
1665 | { | |
1666 | // check for above/below middle | |
1667 | int y_mid = m_y + h/2; | |
1668 | if (point.y < y_mid ) | |
1669 | flags |= wxTREE_HITTEST_ONITEMUPPERPART; | |
1670 | else | |
1671 | flags |= wxTREE_HITTEST_ONITEMLOWERPART; | |
1672 | ||
1673 | // check for button hit | |
1674 | int xCross = m_x; // - theCtrl->GetLineSpacing(); | |
1675 | #ifdef __WXMAC__ | |
1676 | // according to the drawing code the triangels are drawn | |
1677 | // at -4 , -4 from the position up to +10/+10 max | |
1678 | if ((point.x > xCross-4) && (point.x < xCross+10) && | |
1679 | (point.y > y_mid-4) && (point.y < y_mid+10) && | |
1680 | HasPlus() && theCtrl->HasButtons() ) | |
1681 | #else | |
1682 | // 5 is the size of the plus sign | |
1683 | if ((point.x > xCross-6) && (point.x < xCross+6) && | |
1684 | (point.y > y_mid-6) && (point.y < y_mid+6) && | |
1685 | HasPlus() && theCtrl->HasButtons() ) | |
1686 | #endif | |
1687 | { | |
1688 | flags |= wxTREE_HITTEST_ONITEMBUTTON; | |
1689 | return this; | |
1690 | } | |
1691 | ||
1692 | // check for image hit | |
1693 | if (theCtrl->m_imgWidth > 0 && GetImage() != NO_IMAGE) { | |
1694 | int imgX = m_x - theCtrl->m_imgWidth2; | |
1695 | if (HasPlus() && theCtrl->HasButtons()) | |
1696 | imgX += theCtrl->m_btnWidth + LINEATROOT; | |
1697 | int imgY = y_mid - theCtrl->m_imgHeight2; | |
1698 | if ((point.x >= imgX) && (point.x <= (imgX + theCtrl->m_imgWidth)) && | |
1699 | (point.y >= imgY) && (point.y <= (imgY + theCtrl->m_imgHeight))) { | |
1700 | flags |= wxTREE_HITTEST_ONITEMICON; | |
1701 | return this; | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | // check for label hit | |
1706 | int lblX = m_x - theCtrl->m_imgWidth2 + theCtrl->m_imgWidth + MARGIN; | |
1707 | if ((point.x >= lblX) && (point.x <= (m_x + m_width)) && | |
1708 | (point.y >= m_y) && (point.y <= (m_y + h))) { | |
1709 | flags |= wxTREE_HITTEST_ONITEMLABEL; | |
1710 | return this; | |
1711 | } | |
1712 | ||
1713 | // else check for indent | |
1714 | if (point.x < m_x) { | |
1715 | flags |= wxTREE_HITTEST_ONITEMINDENT; | |
1716 | return this; | |
1717 | } | |
1718 | ||
1719 | // else check for item right??? | |
1720 | if (point.x > m_x + m_width) { | |
1721 | flags |= wxTREE_HITTEST_ONITEMRIGHT; | |
1722 | return this; | |
1723 | } | |
1724 | ||
1725 | } | |
1726 | ||
1727 | // if children are expanded, fall through to evaluate them | |
1728 | if (m_isCollapsed) return (wxTreeListItem*) NULL; | |
1729 | } | |
1730 | ||
1731 | // evaluate children | |
1732 | size_t count = m_children.Count(); | |
1733 | for ( size_t n = 0; n < count; n++ ) | |
1734 | { | |
1735 | wxTreeListItem *res = m_children[n]->HitTest(point, theCtrl, | |
1736 | flags, level + 1); | |
1737 | if ( res != NULL ) | |
1738 | return res; | |
1739 | } | |
1740 | ||
1741 | return (wxTreeListItem*) NULL; | |
1742 | } | |
1743 | ||
1744 | // ALB | |
1745 | wxTreeListItem *wxTreeListItem::HitTest(const wxPoint& point, | |
1746 | const wxTreeListMainWindow *theCtrl, | |
1747 | int &flags, int& column, int level) | |
1748 | { | |
1749 | column = theCtrl->GetMainColumn(); //-1; | |
1750 | ||
1751 | wxTreeListItem* res = HitTest(point, theCtrl, flags, level); | |
1752 | if(!res) { | |
1753 | column = -1; | |
1754 | return res; | |
1755 | } | |
1756 | ||
1757 | wxTreeListHeaderWindow* header_win = theCtrl->m_owner->GetHeaderWindow(); | |
1758 | if (point.x >= header_win->GetWidth()) | |
1759 | column = -1; | |
1760 | else if(flags & wxTREE_HITTEST_ONITEMINDENT) { | |
1761 | int x = 0; | |
1762 | for(size_t i = 0; i < theCtrl->GetMainColumn(); ++i) { | |
1763 | if (!header_win->GetColumnShown(i)) continue; | |
1764 | int w = header_win->GetColumnWidth(i); | |
1765 | if(point.x >= x && point.x < x+w) { | |
1766 | flags ^= wxTREE_HITTEST_ONITEMINDENT; | |
1767 | flags |= wxTREE_HITTEST_ONITEMCOLUMN; | |
1768 | column = i; | |
1769 | return res; | |
1770 | } | |
1771 | } | |
1772 | } | |
1773 | else if(flags & wxTREE_HITTEST_ONITEMRIGHT) { | |
1774 | int x = 0; | |
1775 | size_t i; | |
1776 | for(i = 0; i < theCtrl->GetMainColumn()+1; ++i) { | |
1777 | if (!header_win->GetColumnShown(i)) continue; | |
1778 | x += header_win->GetColumnWidth(i); | |
1779 | } | |
1780 | for(i = theCtrl->GetMainColumn()+1; i < theCtrl->GetColumnCount(); ++i) { | |
1781 | if (!header_win->GetColumnShown(i)) continue; | |
1782 | int w = header_win->GetColumnWidth(i); | |
1783 | if(point.x >= x && point.x < x+w) { | |
1784 | flags ^= wxTREE_HITTEST_ONITEMRIGHT; | |
1785 | flags |= wxTREE_HITTEST_ONITEMCOLUMN; | |
1786 | column = i; | |
1787 | return res; | |
1788 | } | |
1789 | x += w; | |
1790 | } | |
1791 | } | |
1792 | ||
1793 | return res; | |
1794 | } | |
1795 | ||
1796 | ||
1797 | int wxTreeListItem::GetCurrentImage() const | |
1798 | { | |
1799 | int image = NO_IMAGE; | |
1800 | if ( IsExpanded() ) | |
1801 | { | |
1802 | if ( IsSelected() ) | |
1803 | { | |
1804 | image = GetImage(wxTreeItemIcon_SelectedExpanded); | |
1805 | } | |
1806 | ||
1807 | if ( image == NO_IMAGE ) | |
1808 | { | |
1809 | // we usually fall back to the normal item, but try just the | |
1810 | // expanded one (and not selected) first in this case | |
1811 | image = GetImage(wxTreeItemIcon_Expanded); | |
1812 | } | |
1813 | } | |
1814 | else // not expanded | |
1815 | { | |
1816 | if ( IsSelected() ) | |
1817 | image = GetImage(wxTreeItemIcon_Selected); | |
1818 | } | |
1819 | ||
1820 | // maybe it doesn't have the specific image we want, | |
1821 | // try the default one instead | |
1822 | if ( image == NO_IMAGE ) image = GetImage(); | |
1823 | ||
1824 | return image; | |
1825 | } | |
1826 | ||
1827 | // --------------------------------------------------------------------------- | |
1828 | // wxTreeListMainWindow implementation | |
1829 | // --------------------------------------------------------------------------- | |
1830 | ||
1831 | IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow, wxScrolledWindow) | |
1832 | ||
1833 | BEGIN_EVENT_TABLE(wxTreeListMainWindow, wxScrolledWindow) | |
1834 | EVT_PAINT (wxTreeListMainWindow::OnPaint) | |
1835 | EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse) | |
1836 | EVT_CHAR (wxTreeListMainWindow::OnChar) | |
1837 | EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus) | |
1838 | EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus) | |
1839 | EVT_IDLE (wxTreeListMainWindow::OnIdle) | |
1840 | EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll) | |
1841 | END_EVENT_TABLE() | |
1842 | ||
1843 | ||
1844 | // --------------------------------------------------------------------------- | |
1845 | // construction/destruction | |
1846 | // --------------------------------------------------------------------------- | |
1847 | ||
1848 | void wxTreeListMainWindow::Init() | |
1849 | { | |
1850 | m_current = m_key_current = m_anchor = (wxTreeListItem *) NULL; | |
1851 | m_hasFocus = FALSE; | |
1852 | m_dirty = FALSE; | |
1853 | ||
1854 | m_lineHeight = LINEHEIGHT; | |
1855 | m_indent = MININDENT; // min. indent | |
1856 | m_linespacing = 4; | |
1857 | m_imgWidth = 0, m_imgWidth2 = 0; | |
1858 | m_imgHeight = 0, m_imgHeight2 = 0; | |
1859 | ||
1860 | m_hilightBrush = new wxBrush | |
1861 | ( | |
1862 | wxSystemSettings::GetSystemColour | |
1863 | ( | |
1864 | wxSYS_COLOUR_HIGHLIGHT | |
1865 | ), | |
1866 | wxSOLID | |
1867 | ); | |
1868 | ||
1869 | m_hilightUnfocusedBrush = new wxBrush | |
1870 | ( | |
1871 | wxSystemSettings::GetSystemColour | |
1872 | ( | |
1873 | wxSYS_COLOUR_BTNSHADOW | |
1874 | ), | |
1875 | wxSOLID | |
1876 | ); | |
1877 | ||
1878 | m_imageListNormal = m_imageListButtons = | |
1879 | m_imageListState = (wxImageList *) NULL; | |
1880 | m_ownsImageListNormal = m_ownsImageListButtons = | |
1881 | m_ownsImageListState = FALSE; | |
1882 | ||
1883 | m_dragCount = 0; | |
1884 | m_isDragging = FALSE; | |
1885 | m_dropTarget = m_oldSelection = (wxTreeListItem *)NULL; | |
1886 | ||
1887 | m_renameTimer = new wxTreeListRenameTimer( this ); | |
1888 | m_lastOnSame = FALSE; | |
1889 | ||
1890 | m_findTimer = new wxTimer (this, -1); | |
1891 | ||
1892 | m_underMouse = NULL; | |
1893 | ||
1894 | #if defined( __WXMAC__ ) && defined(__WXMAC_CARBON__) | |
1895 | m_normalFont.MacCreateThemeFont( kThemeViewsFont ) ; | |
1896 | #else | |
1897 | m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); | |
1898 | #endif | |
1899 | m_boldFont = wxFont( m_normalFont.GetPointSize(), | |
1900 | m_normalFont.GetFamily(), | |
1901 | m_normalFont.GetStyle(), | |
1902 | wxBOLD, | |
1903 | m_normalFont.GetUnderlined(), | |
1904 | m_normalFont.GetFaceName(), | |
1905 | m_normalFont.GetEncoding()); | |
1906 | } | |
1907 | ||
1908 | ||
1909 | bool wxTreeListMainWindow::Create(wxTreeListCtrl *parent, | |
1910 | wxWindowID id, | |
1911 | const wxPoint& pos, | |
1912 | const wxSize& size, | |
1913 | long style, | |
1914 | const wxValidator &validator, | |
1915 | const wxString& name ) | |
1916 | { | |
1917 | #ifdef __WXMAC__ | |
1918 | if ( !(style & wxTR_DONT_ADJUST_MAC)) | |
1919 | { | |
1920 | int major,minor; | |
1921 | wxGetOsVersion( &major, &minor ); | |
1922 | ||
1923 | if (style & wxTR_HAS_BUTTONS) style |= wxTR_TWIST_BUTTONS; | |
1924 | if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS; | |
1925 | style &= ~wxTR_LINES_AT_ROOT; | |
1926 | style |= wxTR_NO_LINES; | |
1927 | if (major < 10) | |
1928 | style |= wxTR_ROW_LINES; | |
1929 | } | |
1930 | #endif | |
1931 | ||
1932 | wxScrolledWindow::Create( parent, id, pos, size, | |
1933 | style|wxHSCROLL|wxVSCROLL, name ); | |
1934 | ||
1935 | #if wxUSE_VALIDATORS | |
1936 | SetValidator( validator ); | |
1937 | #endif | |
1938 | ||
1939 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); | |
1940 | ||
1941 | #ifdef __WXMSW__ | |
1942 | { | |
1943 | int i, j; | |
1944 | wxBitmap bmp(8, 8); | |
1945 | wxMemoryDC bdc; | |
1946 | bdc.SelectObject(bmp); | |
1947 | bdc.SetPen(*wxGREY_PEN); | |
1948 | bdc.DrawRectangle(-1, -1, 10, 10); | |
1949 | for (i = 0; i < 8; i++) { | |
1950 | for (j = 0; j < 8; j++) { | |
1951 | if (!((i + j) & 1)) { | |
1952 | bdc.DrawPoint(i, j); | |
1953 | } | |
1954 | } | |
1955 | } | |
1956 | ||
1957 | m_dottedPen = wxPen(bmp, 1); | |
1958 | } | |
1959 | #else | |
1960 | //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT ); // too slow under XFree86 | |
1961 | m_dottedPen = wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK! | |
1962 | #endif | |
1963 | ||
1964 | // ALB | |
1965 | m_owner = parent; | |
1966 | m_main_column = 0; | |
1967 | ||
1968 | return TRUE; | |
1969 | } | |
1970 | ||
1971 | wxTreeListMainWindow::~wxTreeListMainWindow() | |
1972 | { | |
1973 | delete m_hilightBrush; | |
1974 | delete m_hilightUnfocusedBrush; | |
1975 | ||
1976 | DeleteAllItems(); | |
1977 | ||
1978 | delete m_renameTimer; | |
1979 | delete m_findTimer; | |
1980 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
1981 | if (m_ownsImageListState) delete m_imageListState; | |
1982 | if (m_ownsImageListButtons) delete m_imageListButtons; | |
1983 | } | |
1984 | ||
1985 | ||
1986 | ||
1987 | //----------------------------------------------------------------------------- | |
1988 | // accessors | |
1989 | //----------------------------------------------------------------------------- | |
1990 | ||
1991 | size_t wxTreeListMainWindow::GetCount() const | |
1992 | { | |
1993 | return m_anchor == NULL ? 0u : m_anchor->GetChildrenCount(); | |
1994 | } | |
1995 | ||
1996 | void wxTreeListMainWindow::SetIndent(unsigned int indent) | |
1997 | { | |
1998 | m_indent = indent; | |
1999 | m_dirty = TRUE; | |
2000 | } | |
2001 | ||
2002 | void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing) | |
2003 | { | |
2004 | m_linespacing = spacing; | |
2005 | m_dirty = TRUE; | |
2006 | CalculateLineHeight(); | |
2007 | } | |
2008 | ||
2009 | size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId& item, | |
2010 | bool recursively) | |
2011 | { | |
2012 | wxCHECK_MSG( item.IsOk(), 0u, wxT("invalid tree item") ); | |
2013 | ||
2014 | return ((wxTreeListItem*) item.m_pItem)->GetChildrenCount(recursively); | |
2015 | } | |
2016 | ||
2017 | void wxTreeListMainWindow::SetWindowStyle(const long styles) | |
2018 | { | |
2019 | // right now, just sets the styles. Eventually, we may | |
2020 | // want to update the inherited styles, but right now | |
2021 | // none of the parents has updatable styles | |
2022 | m_windowStyle = styles; | |
2023 | m_dirty = TRUE; | |
2024 | } | |
2025 | ||
2026 | //----------------------------------------------------------------------------- | |
2027 | // functions to work with tree items | |
2028 | //----------------------------------------------------------------------------- | |
2029 | ||
2030 | int wxTreeListMainWindow::GetItemImage(const wxTreeItemId& item, size_t column, | |
2031 | wxTreeItemIcon which) const | |
2032 | { | |
2033 | wxCHECK_MSG( item.IsOk(), -1, wxT("invalid tree item") ); | |
2034 | ||
2035 | return ((wxTreeListItem*) item.m_pItem)->GetImage(column, which); | |
2036 | } | |
2037 | ||
2038 | wxTreeItemData *wxTreeListMainWindow::GetItemData(const wxTreeItemId& item) | |
2039 | const | |
2040 | { | |
2041 | wxCHECK_MSG( item.IsOk(), NULL, wxT("invalid tree item") ); | |
2042 | ||
2043 | return ((wxTreeListItem*) item.m_pItem)->GetData(); | |
2044 | } | |
2045 | ||
2046 | bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId& item) const | |
2047 | { | |
2048 | wxCHECK_MSG(item.IsOk(), FALSE, wxT("invalid tree item")); | |
2049 | return ((wxTreeListItem *)item.m_pItem)->IsBold(); | |
2050 | } | |
2051 | ||
2052 | wxColour wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId& item) | |
2053 | const | |
2054 | { | |
2055 | wxCHECK_MSG( item.IsOk(), wxNullColour, wxT("invalid tree item") ); | |
2056 | ||
2057 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2058 | return pItem->Attr().GetTextColour(); | |
2059 | } | |
2060 | ||
2061 | wxColour wxTreeListMainWindow::GetItemBackgroundColour( | |
2062 | const wxTreeItemId& item) const | |
2063 | { | |
2064 | wxCHECK_MSG( item.IsOk(), wxNullColour, wxT("invalid tree item") ); | |
2065 | ||
2066 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2067 | return pItem->Attr().GetBackgroundColour(); | |
2068 | } | |
2069 | ||
2070 | wxFont wxTreeListMainWindow::GetItemFont(const wxTreeItemId& item) const | |
2071 | { | |
2072 | wxCHECK_MSG( item.IsOk(), wxNullFont, wxT("invalid tree item") ); | |
2073 | ||
2074 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2075 | return pItem->Attr().GetFont(); | |
2076 | } | |
2077 | ||
2078 | ||
2079 | ||
2080 | void wxTreeListMainWindow::SetItemImage(const wxTreeItemId& item, | |
2081 | size_t column, | |
2082 | int image, wxTreeItemIcon which) | |
2083 | { | |
2084 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2085 | ||
2086 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2087 | pItem->SetImage(column, image, which); | |
2088 | ||
2089 | wxClientDC dc(this); | |
2090 | CalculateSize(pItem, dc); | |
2091 | RefreshLine(pItem); | |
2092 | } | |
2093 | ||
2094 | void wxTreeListMainWindow::SetItemData(const wxTreeItemId& item, | |
2095 | wxTreeItemData *data) | |
2096 | { | |
2097 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2098 | ||
2099 | ((wxTreeListItem*) item.m_pItem)->SetData(data); | |
2100 | } | |
2101 | ||
2102 | void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId& item, | |
2103 | bool has) | |
2104 | { | |
2105 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2106 | ||
2107 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2108 | pItem->SetHasPlus(has); | |
2109 | RefreshLine(pItem); | |
2110 | } | |
2111 | ||
2112 | void wxTreeListMainWindow::SetItemBold(const wxTreeItemId& item, bool bold) | |
2113 | { | |
2114 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2115 | ||
2116 | // avoid redrawing the tree if no real change | |
2117 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2118 | if ( pItem->IsBold() != bold ) | |
2119 | { | |
2120 | pItem->SetBold(bold); | |
2121 | RefreshLine(pItem); | |
2122 | } | |
2123 | } | |
2124 | ||
2125 | void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId& item, | |
2126 | const wxColour& col) | |
2127 | { | |
2128 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2129 | ||
2130 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2131 | pItem->Attr().SetTextColour(col); | |
2132 | RefreshLine(pItem); | |
2133 | } | |
2134 | ||
2135 | void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId& item, | |
2136 | const wxColour& col) | |
2137 | { | |
2138 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2139 | ||
2140 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2141 | pItem->Attr().SetBackgroundColour(col); | |
2142 | RefreshLine(pItem); | |
2143 | } | |
2144 | ||
2145 | void wxTreeListMainWindow::SetItemFont(const wxTreeItemId& item, | |
2146 | const wxFont& font) | |
2147 | { | |
2148 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
2149 | ||
2150 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2151 | pItem->Attr().SetFont(font); | |
2152 | RefreshLine(pItem); | |
2153 | } | |
2154 | ||
2155 | bool wxTreeListMainWindow::SetFont( const wxFont &font ) | |
2156 | { | |
2157 | wxScrolledWindow::SetFont(font); | |
2158 | ||
2159 | m_normalFont = font ; | |
2160 | m_boldFont = wxFont( m_normalFont.GetPointSize(), | |
2161 | m_normalFont.GetFamily(), | |
2162 | m_normalFont.GetStyle(), | |
2163 | wxBOLD, | |
2164 | m_normalFont.GetUnderlined()); | |
2165 | ||
2166 | return TRUE; | |
2167 | } | |
2168 | ||
2169 | ||
2170 | // ---------------------------------------------------------------------------- | |
2171 | // item status inquiries | |
2172 | // ---------------------------------------------------------------------------- | |
2173 | ||
2174 | bool wxTreeListMainWindow::IsVisible(const wxTreeItemId& item) const | |
2175 | { | |
2176 | wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); | |
2177 | ||
2178 | // An item is only visible if it's not a descendant of a collapsed item | |
2179 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
2180 | wxTreeListItem* parent = pItem->GetItemParent(); | |
2181 | while (parent) | |
2182 | { | |
2183 | if (!parent->IsExpanded()) | |
2184 | return FALSE; | |
2185 | parent = parent->GetItemParent(); | |
2186 | } | |
2187 | ||
2188 | int startX, startY; | |
2189 | GetViewStart(& startX, & startY); | |
2190 | ||
2191 | wxSize clientSize = GetClientSize(); | |
2192 | ||
2193 | wxRect rect; | |
2194 | if (!GetBoundingRect(item, rect)) | |
2195 | return FALSE; | |
2196 | if (rect.GetWidth() == 0 || rect.GetHeight() == 0) | |
2197 | return FALSE; | |
2198 | if (rect.GetBottom() < 0 || rect.GetTop() > clientSize.y) | |
2199 | return FALSE; | |
2200 | if (rect.GetRight() < 0 || rect.GetLeft() > clientSize.x) | |
2201 | return FALSE; | |
2202 | ||
2203 | return TRUE; | |
2204 | } | |
2205 | ||
2206 | bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId& item) const | |
2207 | { | |
2208 | wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); | |
2209 | ||
2210 | // consider that the item does have children if it has the "+" button: it | |
2211 | // might not have them (if it had never been expanded yet) but then it | |
2212 | // could have them as well and it's better to err on this side rather than | |
2213 | // disabling some operations which are restricted to the items with | |
2214 | // children for an item which does have them | |
2215 | return ((wxTreeListItem*) item.m_pItem)->HasPlus(); | |
2216 | } | |
2217 | ||
2218 | bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId& item) const | |
2219 | { | |
2220 | wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); | |
2221 | ||
2222 | return ((wxTreeListItem*) item.m_pItem)->IsExpanded(); | |
2223 | } | |
2224 | ||
2225 | bool wxTreeListMainWindow::IsSelected(const wxTreeItemId& item) const | |
2226 | { | |
2227 | wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); | |
2228 | ||
2229 | return ((wxTreeListItem*) item.m_pItem)->IsSelected(); | |
2230 | } | |
2231 | ||
2232 | bool wxTreeListMainWindow::IsBold(const wxTreeItemId& item) const | |
2233 | { | |
2234 | wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); | |
2235 | ||
2236 | return ((wxTreeListItem*) item.m_pItem)->IsBold(); | |
2237 | } | |
2238 | ||
2239 | // ---------------------------------------------------------------------------- | |
2240 | // navigation | |
2241 | // ---------------------------------------------------------------------------- | |
2242 | ||
2243 | wxTreeItemId wxTreeListMainWindow::GetItemParent(const wxTreeItemId& item) const | |
2244 | { | |
2245 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2246 | ||
2247 | return ((wxTreeListItem*) item.m_pItem)->GetItemParent(); | |
2248 | } | |
2249 | ||
2250 | #if !wxCHECK_VERSION(2, 5, 0) | |
2251 | wxTreeItemId wxTreeListMainWindow::GetFirstChild(const wxTreeItemId& item, | |
2252 | long& cookie) const | |
2253 | #else | |
2254 | wxTreeItemId wxTreeListMainWindow::GetFirstChild(const wxTreeItemId& item, | |
2255 | wxTreeItemIdValue& cookie) const | |
2256 | #endif | |
2257 | { | |
2258 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2259 | ||
2260 | cookie = 0; | |
2261 | return GetNextChild(item, cookie); | |
2262 | } | |
2263 | ||
2264 | #if !wxCHECK_VERSION(2, 5, 0) | |
2265 | wxTreeItemId wxTreeListMainWindow::GetNextChild(const wxTreeItemId& item, | |
2266 | long& cookie) const | |
2267 | #else | |
2268 | wxTreeItemId wxTreeListMainWindow::GetNextChild(const wxTreeItemId& item, | |
2269 | wxTreeItemIdValue& cookie) const | |
2270 | #endif | |
2271 | { | |
2272 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2273 | ||
2274 | wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren(); | |
2275 | ||
2276 | // it's ok to cast cookie to size_t, we never have indices big enough to | |
2277 | // overflow "void *" | |
2278 | size_t *pIndex = (size_t *)&cookie; | |
2279 | if ( *pIndex < children.Count() ) | |
2280 | { | |
2281 | return children.Item((*pIndex)++); | |
2282 | } | |
2283 | else | |
2284 | { | |
2285 | // there are no more of them | |
2286 | return wxTreeItemId(); | |
2287 | } | |
2288 | } | |
2289 | ||
2290 | #if !wxCHECK_VERSION(2, 5, 0) | |
2291 | wxTreeItemId wxTreeListMainWindow::GetPrevChild(const wxTreeItemId& item, | |
2292 | long& cookie) const | |
2293 | #else | |
2294 | wxTreeItemId wxTreeListMainWindow::GetPrevChild(const wxTreeItemId& item, | |
2295 | wxTreeItemIdValue& cookie) const | |
2296 | #endif | |
2297 | { | |
2298 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2299 | ||
2300 | wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren(); | |
2301 | ||
2302 | // it's ok to cast cookie to size_t, we never have indices big enough to | |
2303 | // overflow "void *" | |
2304 | size_t *pIndex = (size_t *)&cookie; | |
2305 | if ( *pIndex > 0 ) | |
2306 | { | |
2307 | return children.Item(--(*pIndex)); | |
2308 | } | |
2309 | else | |
2310 | { | |
2311 | // there are no more of them | |
2312 | return wxTreeItemId(); | |
2313 | } | |
2314 | } | |
2315 | ||
2316 | wxTreeItemId wxTreeListMainWindow::GetLastChild(const wxTreeItemId& item) const | |
2317 | { | |
2318 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2319 | ||
2320 | wxArrayTreeListItems& children = ((wxTreeListItem*) item.m_pItem)->GetChildren(); | |
2321 | return (children.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children.Last())); | |
2322 | } | |
2323 | ||
2324 | wxTreeItemId wxTreeListMainWindow::GetNextSibling(const wxTreeItemId& item) const | |
2325 | { | |
2326 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2327 | ||
2328 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
2329 | wxTreeListItem *parent = i->GetItemParent(); | |
2330 | if ( parent == NULL ) | |
2331 | { | |
2332 | // root item doesn't have any siblings | |
2333 | return wxTreeItemId(); | |
2334 | } | |
2335 | ||
2336 | wxArrayTreeListItems& siblings = parent->GetChildren(); | |
2337 | int index = siblings.Index(i); | |
2338 | wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent? | |
2339 | ||
2340 | size_t n = (size_t)(index + 1); | |
2341 | return n == siblings.Count() ? wxTreeItemId() : wxTreeItemId(siblings[n]); | |
2342 | } | |
2343 | ||
2344 | wxTreeItemId wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId& item) | |
2345 | const | |
2346 | { | |
2347 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2348 | ||
2349 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
2350 | wxTreeListItem *parent = i->GetItemParent(); | |
2351 | if ( parent == NULL ) | |
2352 | { | |
2353 | // root item doesn't have any siblings | |
2354 | return wxTreeItemId(); | |
2355 | } | |
2356 | ||
2357 | wxArrayTreeListItems& siblings = parent->GetChildren(); | |
2358 | int index = siblings.Index(i); | |
2359 | wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent? | |
2360 | ||
2361 | return index == 0 ? wxTreeItemId() | |
2362 | : wxTreeItemId(siblings[(size_t)(index - 1)]); | |
2363 | } | |
2364 | ||
2365 | // Only for internal use right now, but should probably be public | |
2366 | wxTreeItemId wxTreeListMainWindow::GetNext(const wxTreeItemId& item) const | |
2367 | { | |
2368 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2369 | ||
2370 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
2371 | ||
2372 | // First see if there are any children. | |
2373 | wxArrayTreeListItems& children = i->GetChildren(); | |
2374 | if (children.GetCount() > 0) | |
2375 | { | |
2376 | return children.Item(0); | |
2377 | } | |
2378 | else | |
2379 | { | |
2380 | // Try a sibling of this or ancestor instead | |
2381 | wxTreeItemId p = item; | |
2382 | wxTreeItemId toFind; | |
2383 | do | |
2384 | { | |
2385 | toFind = GetNextSibling(p); | |
2386 | p = GetItemParent(p); | |
2387 | } while (p.IsOk() && !toFind.IsOk()); | |
2388 | return toFind; | |
2389 | } | |
2390 | } | |
2391 | ||
2392 | wxTreeItemId wxTreeListMainWindow::GetFirstVisibleItem() const | |
2393 | { | |
2394 | wxTreeItemId id = GetRootItem(); | |
2395 | if (!id.IsOk()) | |
2396 | return id; | |
2397 | ||
2398 | do | |
2399 | { | |
2400 | if (IsVisible(id)) | |
2401 | return id; | |
2402 | id = GetNext(id); | |
2403 | } while (id.IsOk()); | |
2404 | ||
2405 | return wxTreeItemId(); | |
2406 | } | |
2407 | ||
2408 | wxTreeItemId wxTreeListMainWindow::GetNextVisible(const wxTreeItemId& item) | |
2409 | const | |
2410 | { | |
2411 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2412 | ||
2413 | wxTreeItemId id = item; | |
2414 | if (id.IsOk()) | |
2415 | { | |
2416 | while (id = GetNext(id), id.IsOk()) | |
2417 | { | |
2418 | if (IsVisible(id)) | |
2419 | return id; | |
2420 | } | |
2421 | } | |
2422 | return wxTreeItemId(); | |
2423 | } | |
2424 | ||
2425 | wxTreeItemId wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId& item) | |
2426 | const | |
2427 | { | |
2428 | wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); | |
2429 | ||
2430 | wxFAIL_MSG(wxT("not implemented")); | |
2431 | ||
2432 | return wxTreeItemId(); | |
2433 | } | |
2434 | ||
2435 | // ---------------------------------------------------------------------------- | |
2436 | // operations | |
2437 | // ---------------------------------------------------------------------------- | |
2438 | ||
2439 | wxTreeItemId wxTreeListMainWindow::DoInsertItem(const wxTreeItemId& parentId, | |
2440 | size_t previous, | |
2441 | const wxString& text, | |
2442 | int image, int selImage, | |
2443 | wxTreeItemData *data) | |
2444 | { | |
2445 | wxTreeListItem *parent = (wxTreeListItem*) parentId.m_pItem; | |
2446 | if ( !parent ) | |
2447 | { | |
2448 | // should we give a warning here? | |
2449 | return AddRoot(text, image, selImage, data); | |
2450 | } | |
2451 | ||
2452 | m_dirty = TRUE; // do this first so stuff below doesn't cause flicker | |
2453 | ||
2454 | // ALB | |
2455 | wxArrayString arr; | |
2456 | arr.Alloc(GetColumnCount()); | |
2457 | for(size_t i = 0; i < GetColumnCount(); ++i) { | |
2458 | arr.Add(wxEmptyString); | |
2459 | } | |
2460 | arr[m_main_column] = text; | |
2461 | wxTreeListItem *item = | |
2462 | new wxTreeListItem( this, parent, arr, image, selImage, data ); | |
2463 | ||
2464 | if ( data != NULL ) | |
2465 | { | |
2466 | data->SetId((long)item); | |
2467 | } | |
2468 | ||
2469 | parent->Insert( item, previous ); | |
2470 | ||
2471 | return item; | |
2472 | } | |
2473 | ||
2474 | wxTreeItemId wxTreeListMainWindow::AddRoot(const wxString& text, | |
2475 | int image, int selImage, | |
2476 | wxTreeItemData *data) | |
2477 | { | |
2478 | wxCHECK_MSG(!m_anchor, wxTreeItemId(), wxT("tree can have only one root")); | |
2479 | wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item")); | |
2480 | ||
2481 | m_dirty = TRUE; // do this first so stuff below doesn't cause flicker | |
2482 | ||
2483 | // ALB | |
2484 | wxArrayString arr; | |
2485 | arr.Alloc(GetColumnCount()); | |
2486 | for(size_t i = 0; i < GetColumnCount(); ++i) { | |
2487 | arr.Add(wxEmptyString); | |
2488 | } | |
2489 | arr[m_main_column] = text; | |
2490 | m_anchor = new wxTreeListItem( this, (wxTreeListItem *)NULL, arr, | |
2491 | image, selImage, data); | |
2492 | #if 0 | |
2493 | if (HasFlag(wxTR_HIDE_ROOT)) | |
2494 | { | |
2495 | // if root is hidden, make sure we can navigate | |
2496 | // into children | |
2497 | m_anchor->SetHasPlus(); | |
2498 | Expand(m_anchor); | |
2499 | } | |
2500 | #endif | |
2501 | if ( data != NULL ) | |
2502 | { | |
2503 | data->SetId((long)m_anchor); | |
2504 | } | |
2505 | ||
2506 | if (!HasFlag(wxTR_MULTIPLE)) | |
2507 | { | |
2508 | m_current = m_key_current = m_anchor; | |
2509 | m_current->SetHilight( TRUE ); | |
2510 | } | |
2511 | ||
2512 | return m_anchor; | |
2513 | } | |
2514 | ||
2515 | wxTreeItemId wxTreeListMainWindow::PrependItem(const wxTreeItemId& parent, | |
2516 | const wxString& text, | |
2517 | int image, int selImage, | |
2518 | wxTreeItemData *data) | |
2519 | { | |
2520 | return DoInsertItem(parent, 0u, text, image, selImage, data); | |
2521 | } | |
2522 | ||
2523 | wxTreeItemId wxTreeListMainWindow::InsertItem(const wxTreeItemId& parentId, | |
2524 | const wxTreeItemId& idPrevious, | |
2525 | const wxString& text, | |
2526 | int image, int selImage, | |
2527 | wxTreeItemData *data) | |
2528 | { | |
2529 | wxTreeListItem *parent = (wxTreeListItem*) parentId.m_pItem; | |
2530 | if ( !parent ) | |
2531 | { | |
2532 | // should we give a warning here? | |
2533 | return AddRoot(text, image, selImage, data); | |
2534 | } | |
2535 | ||
2536 | int index = parent->GetChildren().Index((wxTreeListItem*) idPrevious.m_pItem); | |
2537 | wxASSERT_MSG( index != wxNOT_FOUND, | |
2538 | wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") ); | |
2539 | ||
2540 | return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data); | |
2541 | } | |
2542 | ||
2543 | wxTreeItemId wxTreeListMainWindow::InsertItem(const wxTreeItemId& parentId, | |
2544 | size_t before, | |
2545 | const wxString& text, | |
2546 | int image, int selImage, | |
2547 | wxTreeItemData *data) | |
2548 | { | |
2549 | wxTreeListItem *parent = (wxTreeListItem*) parentId.m_pItem; | |
2550 | if ( !parent ) | |
2551 | { | |
2552 | // should we give a warning here? | |
2553 | return AddRoot(text, image, selImage, data); | |
2554 | } | |
2555 | ||
2556 | return DoInsertItem(parentId, before, text, image, selImage, data); | |
2557 | } | |
2558 | ||
2559 | wxTreeItemId wxTreeListMainWindow::AppendItem(const wxTreeItemId& parentId, | |
2560 | const wxString& text, | |
2561 | int image, int selImage, | |
2562 | wxTreeItemData *data) | |
2563 | { | |
2564 | wxTreeListItem *parent = (wxTreeListItem*) parentId.m_pItem; | |
2565 | if ( !parent ) | |
2566 | { | |
2567 | // should we give a warning here? | |
2568 | return AddRoot(text, image, selImage, data); | |
2569 | } | |
2570 | ||
2571 | return DoInsertItem( parent, parent->GetChildren().Count(), text, | |
2572 | image, selImage, data); | |
2573 | } | |
2574 | ||
2575 | void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem *item) | |
2576 | { | |
2577 | wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, m_owner->GetId() ); | |
2578 | event.SetItem((long) item); | |
2579 | event.SetEventObject( /*this*/m_owner ); | |
2580 | m_owner->ProcessEvent( event ); | |
2581 | } | |
2582 | ||
2583 | void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId& itemId) | |
2584 | { | |
2585 | m_dirty = TRUE; // do this first so stuff below doesn't cause flicker | |
2586 | ||
2587 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2588 | item->DeleteChildren(this); | |
2589 | } | |
2590 | ||
2591 | void wxTreeListMainWindow::Delete(const wxTreeItemId& itemId) | |
2592 | { | |
2593 | m_dirty = TRUE; // do this first so stuff below doesn't cause flicker | |
2594 | ||
2595 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2596 | ||
2597 | // don't stay with invalid m_key_current or we will crash in | |
2598 | // the next call to OnChar() | |
2599 | bool changeKeyCurrent = FALSE; | |
2600 | wxTreeListItem *itemKey = m_key_current; | |
2601 | while ( itemKey ) | |
2602 | { | |
2603 | if ( itemKey == item ) | |
2604 | { | |
2605 | // m_key_current is a descendant of the item being deleted | |
2606 | changeKeyCurrent = TRUE; | |
2607 | break; | |
2608 | } | |
2609 | itemKey = itemKey->GetItemParent(); | |
2610 | } | |
2611 | ||
2612 | wxTreeListItem *parent = item->GetItemParent(); | |
2613 | if ( parent ) | |
2614 | { | |
2615 | parent->GetChildren().Remove( item ); // remove by value | |
2616 | } | |
2617 | ||
2618 | if ( changeKeyCurrent ) | |
2619 | { | |
2620 | // may be NULL or not | |
2621 | m_key_current = parent; | |
2622 | } | |
2623 | ||
2624 | item->DeleteChildren(this); | |
2625 | SendDeleteEvent(item); | |
2626 | delete item; | |
2627 | } | |
2628 | ||
2629 | void wxTreeListMainWindow::DeleteAllItems() | |
2630 | { | |
2631 | if ( m_anchor ) | |
2632 | { | |
2633 | m_dirty = TRUE; | |
2634 | ||
2635 | m_anchor->DeleteChildren(this); | |
2636 | delete m_anchor; | |
2637 | ||
2638 | m_anchor = NULL; | |
2639 | } | |
2640 | } | |
2641 | ||
2642 | void wxTreeListMainWindow::Expand(const wxTreeItemId& itemId) | |
2643 | { | |
2644 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2645 | ||
2646 | wxCHECK_RET( item, _T("invalid item in wxTreeListMainWindow::Expand") ); | |
2647 | ||
2648 | if ( !item->HasPlus() ) | |
2649 | return; | |
2650 | ||
2651 | if ( item->IsExpanded() ) | |
2652 | return; | |
2653 | ||
2654 | wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, m_owner->GetId() ); | |
2655 | event.SetItem( (long) item ); | |
2656 | event.SetEventObject( /*this*/m_owner ); | |
2657 | ||
2658 | if ( m_owner->ProcessEvent( event ) && !event.IsAllowed() ) | |
2659 | { | |
2660 | // cancelled by program | |
2661 | return; | |
2662 | } | |
2663 | ||
2664 | item->Expand(); | |
2665 | CalculatePositions(); | |
2666 | ||
2667 | RefreshSubtree(item); | |
2668 | ||
2669 | event.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED); | |
2670 | ProcessEvent( event ); | |
2671 | } | |
2672 | ||
2673 | void wxTreeListMainWindow::ExpandAll(const wxTreeItemId& item) | |
2674 | { | |
2675 | Expand(item); | |
2676 | if ( IsExpanded(item) ) | |
2677 | { | |
2678 | #if !wxCHECK_VERSION(2, 5, 0) | |
2679 | long cookie; | |
2680 | #else | |
2681 | wxTreeItemIdValue cookie; | |
2682 | #endif | |
2683 | wxTreeItemId child = GetFirstChild(item, cookie); | |
2684 | while ( child.IsOk() ) | |
2685 | { | |
2686 | ExpandAll(child); | |
2687 | ||
2688 | child = GetNextChild(item, cookie); | |
2689 | } | |
2690 | } | |
2691 | } | |
2692 | ||
2693 | void wxTreeListMainWindow::Collapse(const wxTreeItemId& itemId) | |
2694 | { | |
2695 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2696 | ||
2697 | if ( !item->IsExpanded() ) | |
2698 | return; | |
2699 | ||
2700 | wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, m_owner->GetId() ); | |
2701 | event.SetItem( (long) item ); | |
2702 | event.SetEventObject( /*this*/m_owner ); | |
2703 | if ( m_owner->ProcessEvent( event ) && !event.IsAllowed() ) | |
2704 | { | |
2705 | // cancelled by program | |
2706 | return; | |
2707 | } | |
2708 | ||
2709 | item->Collapse(); | |
2710 | ||
2711 | #if 0 // TODO why should items be collapsed recursively? | |
2712 | wxArrayTreeListItems& children = item->GetChildren(); | |
2713 | size_t count = children.Count(); | |
2714 | for ( size_t n = 0; n < count; n++ ) | |
2715 | { | |
2716 | Collapse(children[n]); | |
2717 | } | |
2718 | #endif | |
2719 | ||
2720 | CalculatePositions(); | |
2721 | ||
2722 | RefreshSubtree(item); | |
2723 | ||
2724 | event.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED); | |
2725 | ProcessEvent( event ); | |
2726 | } | |
2727 | ||
2728 | void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId& item) | |
2729 | { | |
2730 | Collapse(item); | |
2731 | DeleteChildren(item); | |
2732 | } | |
2733 | ||
2734 | void wxTreeListMainWindow::Toggle(const wxTreeItemId& itemId) | |
2735 | { | |
2736 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2737 | ||
2738 | if (item->IsExpanded()) | |
2739 | Collapse(itemId); | |
2740 | else | |
2741 | Expand(itemId); | |
2742 | } | |
2743 | ||
2744 | void wxTreeListMainWindow::Unselect() | |
2745 | { | |
2746 | if (m_current) | |
2747 | { | |
2748 | m_current->SetHilight( FALSE ); | |
2749 | RefreshLine( m_current ); | |
2750 | } | |
2751 | } | |
2752 | ||
2753 | void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem *item) | |
2754 | { | |
2755 | if (item->IsSelected()) | |
2756 | { | |
2757 | item->SetHilight(FALSE); | |
2758 | RefreshLine(item); | |
2759 | } | |
2760 | ||
2761 | if (item->HasChildren()) | |
2762 | { | |
2763 | wxArrayTreeListItems& children = item->GetChildren(); | |
2764 | size_t count = children.Count(); | |
2765 | for ( size_t n = 0; n < count; ++n ) | |
2766 | { | |
2767 | UnselectAllChildren(children[n]); | |
2768 | } | |
2769 | } | |
2770 | } | |
2771 | ||
2772 | void wxTreeListMainWindow::UnselectAll() | |
2773 | { | |
2774 | UnselectAllChildren((wxTreeListItem*)GetRootItem().m_pItem); | |
2775 | } | |
2776 | ||
2777 | // Recursive function ! | |
2778 | // To stop we must have crt_item<last_item | |
2779 | // Algorithm : | |
2780 | // Tag all next children, when no more children, | |
2781 | // Move to parent (not to tag) | |
2782 | // Keep going... if we found last_item, we stop. | |
2783 | bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem *crt_item, wxTreeListItem *last_item, bool select) | |
2784 | { | |
2785 | wxTreeListItem *parent = crt_item->GetItemParent(); | |
2786 | ||
2787 | if (parent == NULL) // This is root item | |
2788 | return TagAllChildrenUntilLast(crt_item, last_item, select); | |
2789 | ||
2790 | wxArrayTreeListItems& children = parent->GetChildren(); | |
2791 | int index = children.Index(crt_item); | |
2792 | wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent? | |
2793 | ||
2794 | size_t count = children.Count(); | |
2795 | for (size_t n=(size_t)(index+1); n<count; ++n) | |
2796 | { | |
2797 | if (TagAllChildrenUntilLast(children[n], last_item, select)) return TRUE; | |
2798 | } | |
2799 | ||
2800 | return TagNextChildren(parent, last_item, select); | |
2801 | } | |
2802 | ||
2803 | bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem *crt_item, wxTreeListItem *last_item, bool select) | |
2804 | { | |
2805 | crt_item->SetHilight(select); | |
2806 | RefreshLine(crt_item); | |
2807 | ||
2808 | if (crt_item==last_item) | |
2809 | return TRUE; | |
2810 | ||
2811 | if (crt_item->HasChildren()) | |
2812 | { | |
2813 | wxArrayTreeListItems& children = crt_item->GetChildren(); | |
2814 | size_t count = children.Count(); | |
2815 | for ( size_t n = 0; n < count; ++n ) | |
2816 | { | |
2817 | if (TagAllChildrenUntilLast(children[n], last_item, select)) | |
2818 | return TRUE; | |
2819 | } | |
2820 | } | |
2821 | ||
2822 | return FALSE; | |
2823 | } | |
2824 | ||
2825 | void wxTreeListMainWindow::SelectItemRange(wxTreeListItem *item1, wxTreeListItem *item2) | |
2826 | { | |
2827 | // item2 is not necessary after item1 | |
2828 | wxTreeListItem *first=NULL, *last=NULL; | |
2829 | ||
2830 | // choice first' and 'last' between item1 and item2 | |
2831 | if (item1->GetY()<item2->GetY()) | |
2832 | { | |
2833 | first=item1; | |
2834 | last=item2; | |
2835 | } | |
2836 | else | |
2837 | { | |
2838 | first=item2; | |
2839 | last=item1; | |
2840 | } | |
2841 | ||
2842 | bool select = m_current->IsSelected(); | |
2843 | ||
2844 | if ( TagAllChildrenUntilLast(first,last,select) ) | |
2845 | return; | |
2846 | ||
2847 | TagNextChildren(first,last,select); | |
2848 | } | |
2849 | ||
2850 | void wxTreeListMainWindow::SelectItem(const wxTreeItemId& itemId, | |
2851 | bool unselect_others, | |
2852 | bool extended_select) | |
2853 | { | |
2854 | wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") ); | |
2855 | ||
2856 | bool is_single=!(GetWindowStyleFlag() & wxTR_MULTIPLE); | |
2857 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
2858 | ||
2859 | //wxCHECK_RET( ( (!unselect_others) && is_single), | |
2860 | // wxT("this is a single selection tree") ); | |
2861 | ||
2862 | // to keep going anyhow !!! | |
2863 | if (is_single) | |
2864 | { | |
2865 | if (item->IsSelected()) | |
2866 | return; // nothing to do | |
2867 | unselect_others = TRUE; | |
2868 | extended_select = FALSE; | |
2869 | } | |
2870 | else if ( unselect_others && item->IsSelected() ) | |
2871 | { | |
2872 | // selection change if there is more than one item currently selected | |
2873 | wxArrayTreeItemIds selected_items; | |
2874 | if ( GetSelections(selected_items) == 1 ) | |
2875 | return; | |
2876 | } | |
2877 | ||
2878 | wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, m_owner->GetId() ); | |
2879 | event.SetItem( (long) item ); | |
2880 | event.SetOldItem( (long) m_current ); | |
2881 | event.SetEventObject( /*this*/m_owner ); | |
2882 | // TODO : Here we don't send any selection mode yet ! | |
2883 | ||
2884 | if(m_owner->GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed()) | |
2885 | return; | |
2886 | ||
2887 | wxTreeItemId parent = GetItemParent( itemId ); | |
2888 | while (parent.IsOk()) | |
2889 | { | |
2890 | if (!IsExpanded(parent)) | |
2891 | Expand( parent ); | |
2892 | ||
2893 | parent = GetItemParent( parent ); | |
2894 | } | |
2895 | ||
2896 | EnsureVisible( itemId ); | |
2897 | ||
2898 | // ctrl press | |
2899 | if (unselect_others) | |
2900 | { | |
2901 | if (is_single) Unselect(); // to speed up thing | |
2902 | else UnselectAll(); | |
2903 | } | |
2904 | ||
2905 | // shift press | |
2906 | if (extended_select) | |
2907 | { | |
2908 | if ( !m_current ) | |
2909 | { | |
2910 | m_current = m_key_current = (wxTreeListItem*)GetRootItem().m_pItem; | |
2911 | } | |
2912 | ||
2913 | // don't change the mark (m_current) | |
2914 | SelectItemRange(m_current, item); | |
2915 | } | |
2916 | else | |
2917 | { | |
2918 | bool select=TRUE; // the default | |
2919 | ||
2920 | // Check if we need to toggle hilight (ctrl mode) | |
2921 | if (!unselect_others) | |
2922 | select=!item->IsSelected(); | |
2923 | ||
2924 | m_current = m_key_current = item; | |
2925 | m_current->SetHilight(select); | |
2926 | RefreshLine( m_current ); | |
2927 | } | |
2928 | ||
2929 | event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED); | |
2930 | GetEventHandler()->ProcessEvent( event ); | |
2931 | } | |
2932 | ||
2933 | void wxTreeListMainWindow::SelectAll(bool extended_select) | |
2934 | { | |
2935 | wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE, wxT("invalid tree style") ); | |
2936 | ||
2937 | wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, m_owner->GetId() ); | |
2938 | event.SetItem( GetRootItem() ); | |
2939 | event.SetOldItem( (long) m_current ); | |
2940 | event.SetEventObject( /*this*/m_owner ); | |
2941 | // TODO : Here we don't send any selection mode yet ! | |
2942 | ||
2943 | if(m_owner->GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed()) | |
2944 | return; | |
2945 | ||
2946 | // shift press | |
2947 | if (!extended_select) | |
2948 | { | |
2949 | ||
2950 | } | |
2951 | else | |
2952 | { | |
2953 | ||
2954 | } | |
2955 | #if !wxCHECK_VERSION(2, 5, 0) | |
2956 | long cookie = 0; | |
2957 | #else | |
2958 | wxTreeItemIdValue cookie = 0; | |
2959 | #endif | |
2960 | wxTreeItemId root = GetRootItem(); | |
2961 | wxTreeListItem *first = (wxTreeListItem *)GetFirstChild (root, cookie).m_pItem; | |
2962 | wxTreeListItem *last = (wxTreeListItem *)GetLastChild (GetRootItem()).m_pItem; | |
2963 | if (TagAllChildrenUntilLast (first, last, true)) return; | |
2964 | TagNextChildren (first, last, true); | |
2965 | ||
2966 | event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED); | |
2967 | GetEventHandler()->ProcessEvent( event ); | |
2968 | } | |
2969 | ||
2970 | void wxTreeListMainWindow::FillArray(wxTreeListItem *item, | |
2971 | wxArrayTreeItemIds &array) const | |
2972 | { | |
2973 | if ( item->IsSelected() ) | |
2974 | array.Add(wxTreeItemId(item)); | |
2975 | ||
2976 | if ( item->HasChildren() ) | |
2977 | { | |
2978 | wxArrayTreeListItems& children = item->GetChildren(); | |
2979 | size_t count = children.GetCount(); | |
2980 | for ( size_t n = 0; n < count; ++n ) | |
2981 | FillArray(children[n], array); | |
2982 | } | |
2983 | } | |
2984 | ||
2985 | size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds &array) const | |
2986 | { | |
2987 | array.Empty(); | |
2988 | wxTreeItemId idRoot = GetRootItem(); | |
2989 | if ( idRoot.IsOk() ) | |
2990 | { | |
2991 | FillArray((wxTreeListItem*) idRoot.m_pItem, array); | |
2992 | } | |
2993 | //else: the tree is empty, so no selections | |
2994 | ||
2995 | return array.Count(); | |
2996 | } | |
2997 | ||
2998 | void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId& item) | |
2999 | { | |
3000 | if (!item.IsOk()) return; | |
3001 | ||
3002 | wxTreeListItem *gitem = (wxTreeListItem*) item.m_pItem; | |
3003 | ||
3004 | // first expand all parent branches | |
3005 | wxTreeListItem *parent = gitem->GetItemParent(); | |
3006 | while ( parent ) | |
3007 | { | |
3008 | Expand(parent); | |
3009 | parent = parent->GetItemParent(); | |
3010 | } | |
3011 | ||
3012 | //if (parent) CalculatePositions(); | |
3013 | ||
3014 | ScrollTo(item); | |
3015 | } | |
3016 | ||
3017 | void wxTreeListMainWindow::ScrollTo(const wxTreeItemId &item) | |
3018 | { | |
3019 | if (!item.IsOk()) return; | |
3020 | ||
3021 | // We have to call this here because the label in | |
3022 | // question might just have been added and no screen | |
3023 | // update taken place. | |
3024 | if (m_dirty) wxYieldIfNeeded(); | |
3025 | ||
3026 | wxTreeListItem *gitem = (wxTreeListItem*) item.m_pItem; | |
3027 | ||
3028 | // now scroll to the item | |
3029 | int item_y = gitem->GetY(); | |
3030 | ||
3031 | int start_x = 0; | |
3032 | int start_y = 0; | |
3033 | GetViewStart( &start_x, &start_y ); | |
3034 | start_y *= PIXELS_PER_UNIT; | |
3035 | ||
3036 | int client_h = 0; | |
3037 | int client_w = 0; | |
3038 | GetClientSize( &client_w, &client_h ); | |
3039 | ||
3040 | if (item_y < start_y+3) | |
3041 | { | |
3042 | // going down | |
3043 | int x = 0; | |
3044 | int y = 0; | |
3045 | m_anchor->GetSize( x, y, this ); | |
3046 | x = m_owner->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB | |
3047 | y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3048 | //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3049 | int x_pos = GetScrollPos( wxHORIZONTAL ); | |
3050 | // Item should appear at top | |
3051 | SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT, x_pos, item_y/PIXELS_PER_UNIT ); | |
3052 | } | |
3053 | else if (item_y+GetLineHeight(gitem) > start_y+client_h) | |
3054 | { | |
3055 | // going up | |
3056 | int x = 0; | |
3057 | int y = 0; | |
3058 | m_anchor->GetSize( x, y, this ); | |
3059 | y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3060 | //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3061 | x = m_owner->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB | |
3062 | item_y += PIXELS_PER_UNIT+2; | |
3063 | int x_pos = GetScrollPos( wxHORIZONTAL ); | |
3064 | // Item should appear at bottom | |
3065 | SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT, x_pos, (item_y+GetLineHeight(gitem)-client_h)/PIXELS_PER_UNIT ); | |
3066 | } | |
3067 | } | |
3068 | ||
3069 | // FIXME: tree sorting functions are not reentrant and not MT-safe! | |
3070 | static wxTreeListMainWindow *s_treeBeingSorted = NULL; | |
3071 | ||
3072 | static int LINKAGEMODE tree_ctrl_compare_func(wxTreeListItem **item1, | |
3073 | wxTreeListItem **item2) | |
3074 | { | |
3075 | wxCHECK_MSG( s_treeBeingSorted, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") ); | |
3076 | ||
3077 | return s_treeBeingSorted->OnCompareItems(*item1, *item2); | |
3078 | } | |
3079 | ||
3080 | int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId& item1, | |
3081 | const wxTreeItemId& item2) | |
3082 | { | |
3083 | // ALB: delegate to m_owner, to let the user overrride the comparison | |
3084 | //return wxStrcmp(GetItemText(item1), GetItemText(item2)); | |
3085 | return m_owner->OnCompareItems(item1, item2); | |
3086 | } | |
3087 | ||
3088 | void wxTreeListMainWindow::SortChildren(const wxTreeItemId& itemId) | |
3089 | { | |
3090 | wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") ); | |
3091 | ||
3092 | wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem; | |
3093 | ||
3094 | wxCHECK_RET( !s_treeBeingSorted, | |
3095 | wxT("wxTreeListMainWindow::SortChildren is not reentrant") ); | |
3096 | ||
3097 | wxArrayTreeListItems& children = item->GetChildren(); | |
3098 | if ( children.Count() > 1 ) | |
3099 | { | |
3100 | m_dirty = TRUE; | |
3101 | ||
3102 | s_treeBeingSorted = this; | |
3103 | children.Sort(tree_ctrl_compare_func); | |
3104 | s_treeBeingSorted = NULL; | |
3105 | } | |
3106 | //else: don't make the tree dirty as nothing changed | |
3107 | } | |
3108 | ||
3109 | wxTreeItemId wxTreeListMainWindow::FindItem (const wxTreeItemId& item, const wxString& str, int flags) { | |
3110 | #if !wxCHECK_VERSION(2, 5, 0) | |
3111 | long cookie = 0; | |
3112 | #else | |
3113 | wxTreeItemIdValue cookie = 0; | |
3114 | #endif | |
3115 | wxTreeItemId next = item; | |
3116 | if (!next.IsOk()) next = GetSelection(); | |
3117 | if (!next.IsOk()) { | |
3118 | if (HasFlag(wxTR_HIDE_ROOT)) { | |
3119 | next = (wxTreeListItem*)GetFirstChild (GetRootItem().m_pItem, cookie).m_pItem; | |
3120 | } else { | |
3121 | next = (wxTreeListItem*)GetRootItem().m_pItem; | |
3122 | } | |
3123 | } | |
3124 | if (!next.IsOk()) return item; | |
3125 | ||
3126 | // start checking the next items | |
3127 | wxString itemText; | |
3128 | while (next.IsOk()) { | |
3129 | itemText = GetItemText (next); | |
3130 | if (flags & wxTL_SEARCH_LEVEL) { | |
3131 | next = GetNextSibling (next); | |
3132 | }else if (flags & wxTL_SEARCH_FULL) { | |
3133 | wxTreeItemId n = GetFirstChild (next, cookie); | |
3134 | if (!n.IsOk()) | |
3135 | n = GetNextSibling (next); | |
3136 | if (!n.IsOk()) | |
3137 | n = GetNextSibling (GetItemParent (next)); | |
3138 | next = n; | |
3139 | }else{ // wxTL_SEARCH_VISIBLE | |
3140 | next = GetNextVisible (next); | |
3141 | } | |
3142 | if (!next.IsOk()) break; // done | |
3143 | if (flags & wxTL_SEARCH_PARTIAL) { | |
3144 | itemText = GetItemText (next).Mid (0, str.Length()); | |
3145 | }else{ | |
3146 | itemText = GetItemText (next); | |
3147 | } | |
3148 | if (flags & wxTL_SEARCH_NOCASE) { | |
3149 | if (itemText.CmpNoCase (str) == 0) return next; | |
3150 | }else{ | |
3151 | if (itemText.Cmp (str) == 0) return next; | |
3152 | } | |
3153 | } | |
3154 | return item; | |
3155 | } | |
3156 | ||
3157 | wxImageList *wxTreeListMainWindow::GetImageList() const | |
3158 | { | |
3159 | return m_imageListNormal; | |
3160 | } | |
3161 | ||
3162 | wxImageList *wxTreeListMainWindow::GetButtonsImageList() const | |
3163 | { | |
3164 | return m_imageListButtons; | |
3165 | } | |
3166 | ||
3167 | wxImageList *wxTreeListMainWindow::GetStateImageList() const | |
3168 | { | |
3169 | return m_imageListState; | |
3170 | } | |
3171 | ||
3172 | void wxTreeListMainWindow::CalculateLineHeight() | |
3173 | { | |
3174 | wxClientDC dc(this); | |
3175 | dc.SetFont( m_normalFont ); | |
3176 | m_lineHeight = (int)(dc.GetCharHeight() + m_linespacing); | |
3177 | ||
3178 | if ( m_imageListNormal ) | |
3179 | { | |
3180 | // Calculate a m_lineHeight value from the normal Image sizes. | |
3181 | // May be toggle off. Then wxTreeListMainWindow will spread when | |
3182 | // necessary (which might look ugly). | |
3183 | int n = m_imageListNormal->GetImageCount(); | |
3184 | for (int i = 0; i < n ; i++) | |
3185 | { | |
3186 | int width = 0, height = 0; | |
3187 | m_imageListNormal->GetSize(i, width, height); | |
3188 | if (height > m_lineHeight) m_lineHeight = height + m_linespacing; | |
3189 | } | |
3190 | } | |
3191 | ||
3192 | if (m_imageListButtons) | |
3193 | { | |
3194 | // Calculate a m_lineHeight value from the Button image sizes. | |
3195 | // May be toggle off. Then wxTreeListMainWindow will spread when | |
3196 | // necessary (which might look ugly). | |
3197 | int n = m_imageListButtons->GetImageCount(); | |
3198 | for (int i = 0; i < n ; i++) | |
3199 | { | |
3200 | int width = 0, height = 0; | |
3201 | m_imageListButtons->GetSize(i, width, height); | |
3202 | if (height > m_lineHeight) m_lineHeight = height + m_linespacing; | |
3203 | } | |
3204 | } | |
3205 | ||
3206 | /*? FIXME: Don't get what this code is for... Adding a line space is already done!!! | |
3207 | if (m_lineHeight < 30) | |
3208 | m_lineHeight += 2; // at least 2 pixels | |
3209 | else | |
3210 | m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing | |
3211 | ?*/ | |
3212 | } | |
3213 | ||
3214 | void wxTreeListMainWindow::SetImageList(wxImageList *imageList) | |
3215 | { | |
3216 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
3217 | m_imageListNormal = imageList; | |
3218 | m_ownsImageListNormal = FALSE; | |
3219 | m_dirty = TRUE; | |
3220 | CalculateLineHeight(); | |
3221 | } | |
3222 | ||
3223 | void wxTreeListMainWindow::SetStateImageList(wxImageList *imageList) | |
3224 | { | |
3225 | if (m_ownsImageListState) delete m_imageListState; | |
3226 | m_imageListState = imageList; | |
3227 | m_ownsImageListState = FALSE; | |
3228 | } | |
3229 | ||
3230 | void wxTreeListMainWindow::SetButtonsImageList(wxImageList *imageList) | |
3231 | { | |
3232 | if (m_ownsImageListButtons) delete m_imageListButtons; | |
3233 | m_imageListButtons = imageList; | |
3234 | m_ownsImageListButtons = FALSE; | |
3235 | m_dirty = TRUE; | |
3236 | CalculateLineHeight(); | |
3237 | } | |
3238 | ||
3239 | void wxTreeListMainWindow::AssignImageList(wxImageList *imageList) | |
3240 | { | |
3241 | SetImageList(imageList); | |
3242 | m_ownsImageListNormal = TRUE; | |
3243 | } | |
3244 | ||
3245 | void wxTreeListMainWindow::AssignStateImageList(wxImageList *imageList) | |
3246 | { | |
3247 | SetStateImageList(imageList); | |
3248 | m_ownsImageListState = TRUE; | |
3249 | } | |
3250 | ||
3251 | void wxTreeListMainWindow::AssignButtonsImageList(wxImageList *imageList) | |
3252 | { | |
3253 | SetButtonsImageList(imageList); | |
3254 | m_ownsImageListButtons = TRUE; | |
3255 | } | |
3256 | ||
3257 | // ---------------------------------------------------------------------------- | |
3258 | // helpers | |
3259 | // ---------------------------------------------------------------------------- | |
3260 | ||
3261 | void wxTreeListMainWindow::AdjustMyScrollbars() | |
3262 | { | |
3263 | if (m_anchor) | |
3264 | { | |
3265 | int x = 0, y = 0; | |
3266 | m_anchor->GetSize( x, y, this ); | |
3267 | y += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3268 | //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels | |
3269 | int x_pos = GetScrollPos( wxHORIZONTAL ); | |
3270 | int y_pos = GetScrollPos( wxVERTICAL ); | |
3271 | x = m_owner->GetHeaderWindow()->GetWidth() + 2; | |
3272 | if(x < GetClientSize().GetWidth()) x_pos = 0; | |
3273 | //m_total_col_width + 2; // ALB | |
3274 | SetScrollbars( PIXELS_PER_UNIT, PIXELS_PER_UNIT, x/PIXELS_PER_UNIT, | |
3275 | y/PIXELS_PER_UNIT, x_pos, y_pos ); | |
3276 | } | |
3277 | else | |
3278 | { | |
3279 | SetScrollbars( 0, 0, 0, 0 ); | |
3280 | } | |
3281 | } | |
3282 | ||
3283 | int wxTreeListMainWindow::GetLineHeight(wxTreeListItem *item) const | |
3284 | { | |
3285 | if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT) | |
3286 | return item->GetHeight(); | |
3287 | else | |
3288 | return m_lineHeight; | |
3289 | } | |
3290 | ||
3291 | void wxTreeListMainWindow::PaintItem(wxTreeListItem *item, wxDC& dc) | |
3292 | { | |
3293 | wxTreeItemAttr *attr = item->GetAttributes(); | |
3294 | if (attr && attr->HasFont()) { | |
3295 | dc.SetFont(attr->GetFont()); | |
3296 | }else if (item->IsBold()) { | |
3297 | dc.SetFont(m_boldFont); | |
3298 | } | |
3299 | wxColour colText; | |
3300 | if (attr && attr->HasTextColour()) { | |
3301 | colText = attr->GetTextColour(); | |
3302 | }else{ | |
3303 | colText = GetForegroundColour(); | |
3304 | } | |
3305 | ||
3306 | dc.SetPen(*wxTRANSPARENT_PEN); | |
3307 | ||
3308 | long text_w = 0, text_h = 0; | |
3309 | ||
3310 | dc.GetTextExtent( item->GetText(GetMainColumn()), &text_w, &text_h ); | |
3311 | ||
3312 | int total_h = GetLineHeight(item); | |
3313 | ||
3314 | if (item->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT)) { | |
3315 | dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush)); | |
3316 | dc.SetPen(*wxBLACK_PEN); | |
3317 | colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
3318 | } else { | |
3319 | wxColour colBg; | |
3320 | if (attr && attr->HasBackgroundColour()) { | |
3321 | colBg = attr->GetBackgroundColour(); | |
3322 | } else { | |
3323 | colBg = GetBackgroundColour(); | |
3324 | } | |
3325 | dc.SetBrush(wxBrush(colBg, wxSOLID)); | |
3326 | } | |
3327 | ||
3328 | int offset = HasFlag(wxTR_ROW_LINES) ? 1 : 0; | |
3329 | dc.DrawRectangle(0, item->GetY() + offset, | |
3330 | m_owner->GetHeaderWindow()->GetWidth(), total_h-offset); | |
3331 | ||
3332 | dc.SetBackgroundMode(wxTRANSPARENT); | |
3333 | int text_extraH = (total_h > text_h) ? (total_h - text_h)/2 : 0; | |
3334 | int img_extraH = (total_h > m_imgHeight)? (total_h-m_imgHeight)/2: 0; | |
3335 | int x_colstart = 0; | |
3336 | for ( size_t i = 0; i < GetColumnCount(); ++i ) { | |
3337 | if (!m_owner->GetHeaderWindow()->GetColumnShown(i)) continue; | |
3338 | int colwidth = m_owner->GetHeaderWindow()->GetColumnWidth(i); | |
3339 | int image; | |
3340 | int image_x = 0; | |
3341 | int image_w = 0; | |
3342 | if (i == GetMainColumn()) { | |
3343 | image = item->GetCurrentImage(); | |
3344 | if (item->HasPlus()) { | |
3345 | image_x = item->GetX() + (m_btnWidth-m_btnWidth2) + LINEATROOT; | |
3346 | }else{ | |
3347 | image_x = item->GetX() - m_imgWidth2; | |
3348 | } | |
3349 | } | |
3350 | else | |
3351 | { | |
3352 | image = item->GetImage(i); | |
3353 | image_x = x_colstart + MARGIN; | |
3354 | } | |
3355 | if (image != NO_IMAGE) image_w = m_imgWidth + MARGIN; | |
3356 | ||
3357 | // honor text alignment | |
3358 | wxString text = item->GetText(i); | |
3359 | switch ( m_owner->GetHeaderWindow()->GetColumn(i).GetAlignment() ) { | |
3360 | case wxTL_ALIGN_LEFT: | |
3361 | // already left aligned | |
3362 | break; | |
3363 | case wxTL_ALIGN_RIGHT: | |
3364 | dc.GetTextExtent(text, &text_w, NULL); | |
3365 | image_x = x_colstart + colwidth - (image_w + text_w + MARGIN); | |
3366 | break; | |
3367 | case wxTL_ALIGN_CENTER: | |
3368 | dc.GetTextExtent(text, &text_w, NULL); | |
3369 | int w = colwidth - image_w - text_w; | |
3370 | image_x = x_colstart + (w > 0)? w: 0; | |
3371 | break; | |
3372 | } | |
3373 | int text_x = image_x + image_w; | |
3374 | ||
3375 | if (item->IsSelected() && (i==GetMainColumn()) && !HasFlag(wxTR_FULL_ROW_HIGHLIGHT)) | |
3376 | { | |
3377 | dc.SetPen(*wxBLACK_PEN); | |
3378 | dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush)); | |
3379 | int offset = HasFlag (wxTR_ROW_LINES) ? 1 : 0; | |
3380 | int width = wxMin(text_w+2, colwidth - text_x - x_colstart); | |
3381 | dc.DrawRectangle(text_x-1, item->GetY() + offset, width, total_h-offset); | |
3382 | dc.SetBackgroundMode(wxTRANSPARENT); | |
3383 | dc.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT)); | |
3384 | }else{ | |
3385 | dc.SetTextForeground(colText); | |
3386 | } | |
3387 | ||
3388 | wxDCClipper clipper (dc, x_colstart, item->GetY(), colwidth, total_h); | |
3389 | if (image != NO_IMAGE) | |
3390 | { | |
3391 | int image_y = item->GetY() + img_extraH; | |
3392 | m_imageListNormal->Draw ( image, dc, image_x, image_y, | |
3393 | wxIMAGELIST_DRAW_TRANSPARENT ); | |
3394 | } | |
3395 | int text_y = item->GetY() + text_extraH; | |
3396 | dc.DrawText ( text, (wxCoord)text_x, (wxCoord)text_y ); | |
3397 | ||
3398 | x_colstart += colwidth; | |
3399 | } | |
3400 | ||
3401 | // restore normal font | |
3402 | dc.SetFont( m_normalFont ); | |
3403 | } | |
3404 | ||
3405 | // Now y stands for the top of the item, whereas it used to stand for middle ! | |
3406 | void wxTreeListMainWindow::PaintLevel (wxTreeListItem *item, wxDC &dc, | |
3407 | int level, int &y, int x_colstart ) | |
3408 | { | |
3409 | // Handle hide root (only level 0) | |
3410 | if (HasFlag(wxTR_HIDE_ROOT) && (level == 0)) { | |
3411 | // always expand hidden root | |
3412 | wxArrayTreeListItems& children = item->GetChildren(); | |
3413 | int n; | |
3414 | for (n = 0; n < (int)children.Count(); n++) { | |
3415 | PaintLevel (children[n], dc, 1, y, x_colstart); | |
3416 | } | |
3417 | // end after expanding root | |
3418 | return; | |
3419 | } | |
3420 | ||
3421 | // calculate position of vertical lines | |
3422 | int x = x_colstart + MARGIN; // start of column | |
3423 | if (HasFlag (wxTR_LINES_AT_ROOT)) x += LINEATROOT; // space for lines at root | |
3424 | if (HasButtons()) { | |
3425 | x += m_btnWidth2; // middle of button | |
3426 | }else{ | |
3427 | if (m_imgWidth > 0) x += m_imgWidth2; // middle of image | |
3428 | } | |
3429 | if (!HasFlag (wxTR_HIDE_ROOT)) { | |
3430 | x += m_indent * level; // indent according to level | |
3431 | }else{ | |
3432 | if (level > 0) x += m_indent * (level-1); // but not level 1 | |
3433 | } | |
3434 | ||
3435 | // handle column text | |
3436 | item->SetX (x); | |
3437 | item->SetY (y); | |
3438 | ||
3439 | int h = GetLineHeight(item); | |
3440 | int y_top = y; | |
3441 | int y_mid = y_top + (h/2); | |
3442 | y += h; | |
3443 | ||
3444 | int exposed_x = dc.LogicalToDeviceX(0); | |
3445 | int exposed_y = dc.LogicalToDeviceY(y_top); | |
3446 | ||
3447 | if (IsExposed(exposed_x, exposed_y, 10000, h)) // 10000 = very much | |
3448 | { | |
3449 | // draw item | |
3450 | PaintItem(item, dc); | |
3451 | ||
3452 | if (HasFlag(wxTR_ROW_LINES)) | |
3453 | { | |
3454 | //dc.DestroyClippingRegion(); | |
3455 | int total_width = m_owner->GetHeaderWindow()->GetWidth(); | |
3456 | // if the background colour is white, choose a | |
3457 | // contrasting color for the lines | |
3458 | dc.SetPen (*((GetBackgroundColour() == *wxWHITE)? | |
3459 | wxMEDIUM_GREY_PEN : wxWHITE_PEN)); | |
3460 | dc.DrawLine(0, y_top, total_width, y_top); | |
3461 | dc.DrawLine(0, y, total_width, y); | |
3462 | } | |
3463 | ||
3464 | // restore DC objects | |
3465 | dc.SetBrush(*wxWHITE_BRUSH); | |
3466 | dc.SetPen(m_dottedPen); | |
3467 | ||
3468 | if (((level == 0) || ((level == 1) && HasFlag(wxTR_HIDE_ROOT))) && | |
3469 | HasFlag(wxTR_LINES_AT_ROOT) && !HasFlag(wxTR_NO_LINES)) { | |
3470 | int rootPos = x_colstart + MARGIN; | |
3471 | dc.DrawLine (rootPos, y_mid, rootPos+LINEATROOT, y_mid); | |
3472 | } | |
3473 | ||
3474 | size_t clip_width = m_owner->GetHeaderWindow()-> | |
3475 | GetColumn(m_main_column).GetWidth(); | |
3476 | ||
3477 | if (item->HasPlus() && HasButtons()) // should the item show a button? | |
3478 | { | |
3479 | // clip to the column width | |
3480 | wxDCClipper clipper(dc, x_colstart, y_top, clip_width, 10000); | |
3481 | ||
3482 | if ( !HasFlag(wxTR_NO_LINES) ) | |
3483 | { | |
3484 | // draw the horizontal line here | |
3485 | int x_start = x; | |
3486 | if (x > (signed)m_indent) | |
3487 | x_start -= m_indent; | |
3488 | else if (HasFlag(wxTR_LINES_AT_ROOT)) | |
3489 | x_start = 3; | |
3490 | dc.DrawLine(x_start, y_mid, x /*+ m_spacing*/, y_mid); | |
3491 | } | |
3492 | ||
3493 | if (m_imageListButtons != NULL) | |
3494 | { | |
3495 | // draw the image button here | |
3496 | int image = wxTreeItemIcon_Normal; | |
3497 | if (item->IsExpanded()) image = wxTreeItemIcon_Expanded; | |
3498 | if (item->IsSelected()) | |
3499 | image += wxTreeItemIcon_Selected - wxTreeItemIcon_Normal; | |
3500 | int xx = x + m_btnWidth2; | |
3501 | int yy = y_mid - m_btnHeight2; | |
3502 | dc.SetClippingRegion(xx, yy, m_btnWidth, m_btnHeight); | |
3503 | m_imageListButtons->Draw(image, dc, xx, yy, | |
3504 | wxIMAGELIST_DRAW_TRANSPARENT); | |
3505 | dc.DestroyClippingRegion(); | |
3506 | } | |
3507 | else // no custom buttons | |
3508 | { | |
3509 | static const int wImage = 9; | |
3510 | static const int hImage = 9; | |
3511 | ||
3512 | int flag = 0; | |
3513 | if (item->IsExpanded()) | |
3514 | flag |= wxCONTROL_EXPANDED; | |
3515 | if (item == m_underMouse) | |
3516 | flag |= wxCONTROL_CURRENT; | |
3517 | ||
3518 | wxRendererNative::Get().DrawTreeItemButton( | |
3519 | this, dc, | |
3520 | wxRect(x - wImage/2, y_mid - hImage/2, wImage, hImage), | |
3521 | flag); | |
3522 | } | |
3523 | ||
3524 | if (!HasFlag(wxTR_NO_LINES)) { | |
3525 | if (/*!(level == 0) &&*/ !((level == 1) && HasFlag(wxTR_HIDE_ROOT))) { | |
3526 | if (m_imgWidth > 0) { | |
3527 | dc.DrawLine(x+m_btnWidth2, y_mid, x+m_indent-m_imgWidth2, y_mid); | |
3528 | }else{ | |
3529 | dc.DrawLine(x+m_btnWidth2, y_mid, x+m_btnWidth2+LINEATROOT-MARGIN, y_mid); | |
3530 | } | |
3531 | } | |
3532 | } | |
3533 | } | |
3534 | else if (!HasFlag(wxTR_NO_LINES)) // no button; maybe a line? | |
3535 | { | |
3536 | // clip to the column width | |
3537 | wxDCClipper clipper(dc, x_colstart, y_top, clip_width, 10000); | |
3538 | ||
3539 | // draw the horizontal line here | |
3540 | if (/*!(level == 0) &&*/ !((level == 1) && HasFlag(wxTR_HIDE_ROOT))) { | |
3541 | int x2 = x - m_indent; | |
3542 | if (m_imgWidth > 0) { | |
3543 | dc.DrawLine(x2, y_mid, x2+m_indent-m_imgWidth2, y_mid); | |
3544 | }else{ | |
3545 | dc.DrawLine(x2, y_mid, x2+m_btnWidth2+LINEATROOT+MARGIN, y_mid); | |
3546 | } | |
3547 | } | |
3548 | } | |
3549 | } | |
3550 | ||
3551 | // restore DC objects | |
3552 | dc.SetBrush(*wxWHITE_BRUSH); | |
3553 | dc.SetPen(m_dottedPen); | |
3554 | dc.SetTextForeground(*wxBLACK); | |
3555 | ||
3556 | if (item->IsExpanded()) | |
3557 | { | |
3558 | wxArrayTreeListItems& children = item->GetChildren(); | |
3559 | int count = children.Count(); | |
3560 | int n, oldY = 0; | |
3561 | ||
3562 | // paint sublevel items first | |
3563 | for (n=0; n<count; ++n) { | |
3564 | oldY = y; | |
3565 | PaintLevel(children[n], dc, level+1, y, x_colstart); | |
3566 | } | |
3567 | ||
3568 | // then draw the connecting lines | |
3569 | if (!HasFlag(wxTR_NO_LINES) && count > 0) | |
3570 | { | |
3571 | // clip to the column width | |
3572 | size_t clip_width = m_owner->GetHeaderWindow()->GetColumn(m_main_column).GetWidth(); | |
3573 | wxDCClipper clipper(dc, x_colstart, y_top, clip_width, 10000); | |
3574 | ||
3575 | // draw line down to last child | |
3576 | oldY += GetLineHeight(children[n-1]) >> 1; | |
3577 | if (HasButtons()) y_mid += 5; | |
3578 | dc.DrawLine(x, y_mid, x, oldY); | |
3579 | } | |
3580 | } | |
3581 | } | |
3582 | ||
3583 | void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem *item) | |
3584 | { | |
3585 | if ( item ) | |
3586 | { | |
3587 | if ( item->HasPlus() ) | |
3588 | { | |
3589 | // it's a folder, indicate it by a border | |
3590 | DrawBorder(item); | |
3591 | } | |
3592 | else | |
3593 | { | |
3594 | // draw a line under the drop target because the item will be | |
3595 | // dropped there | |
3596 | DrawLine(item, TRUE /* below */); | |
3597 | } | |
3598 | ||
3599 | SetCursor(wxCURSOR_BULLSEYE); | |
3600 | } | |
3601 | else | |
3602 | { | |
3603 | // can't drop here | |
3604 | SetCursor(wxCURSOR_NO_ENTRY); | |
3605 | } | |
3606 | } | |
3607 | ||
3608 | void wxTreeListMainWindow::DrawBorder(const wxTreeItemId &item) | |
3609 | { | |
3610 | wxCHECK_RET( item.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") ); | |
3611 | ||
3612 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
3613 | ||
3614 | wxClientDC dc(this); | |
3615 | PrepareDC( dc ); | |
3616 | dc.SetLogicalFunction(wxINVERT); | |
3617 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
3618 | ||
3619 | int w = i->GetWidth() + 2; | |
3620 | int h = GetLineHeight(i) + 2; | |
3621 | ||
3622 | dc.DrawRectangle( i->GetX() - 1, i->GetY() - 1, w, h); | |
3623 | } | |
3624 | ||
3625 | void wxTreeListMainWindow::DrawLine(const wxTreeItemId &item, bool below) | |
3626 | { | |
3627 | wxCHECK_RET( item.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") ); | |
3628 | ||
3629 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
3630 | ||
3631 | wxClientDC dc(this); | |
3632 | PrepareDC( dc ); | |
3633 | dc.SetLogicalFunction(wxINVERT); | |
3634 | ||
3635 | int x = i->GetX(), | |
3636 | y = i->GetY(); | |
3637 | if ( below ) | |
3638 | { | |
3639 | y += GetLineHeight(i) - 1; | |
3640 | } | |
3641 | ||
3642 | dc.DrawLine( x, y, x + i->GetWidth(), y); | |
3643 | } | |
3644 | ||
3645 | // ---------------------------------------------------------------------------- | |
3646 | // wxWindows callbacks | |
3647 | // ---------------------------------------------------------------------------- | |
3648 | ||
3649 | void wxTreeListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
3650 | { | |
3651 | wxPaintDC dc(this); | |
3652 | ||
3653 | PrepareDC( dc ); | |
3654 | ||
3655 | if(!GetColumnCount()) return; // ALB | |
3656 | ||
3657 | if ( !m_anchor) | |
3658 | return; | |
3659 | ||
3660 | // calculate button size | |
3661 | m_btnWidth = 0, m_btnWidth2 = 0; | |
3662 | m_btnHeight = 0, m_btnHeight2 = 0; | |
3663 | if (m_imageListButtons) { | |
3664 | m_imageListButtons->GetSize (0, m_btnWidth, m_btnHeight); | |
3665 | }else if (HasButtons()) { | |
3666 | m_btnWidth = BTNWIDTH; | |
3667 | m_btnHeight = BTNHEIGHT; | |
3668 | } | |
3669 | m_btnWidth2 = m_btnWidth/2; | |
3670 | m_btnHeight2 = m_btnHeight/2; | |
3671 | ||
3672 | // calculate image size | |
3673 | m_imgWidth = 0, m_imgWidth2 = 0; | |
3674 | m_imgHeight = 0, m_imgHeight2 = 0; | |
3675 | if (m_imageListNormal) { | |
3676 | m_imageListNormal->GetSize (0, m_imgWidth, m_imgHeight); | |
3677 | m_imgWidth += 4; //? ToDo: Why + 4? | |
3678 | } | |
3679 | m_imgWidth2 = m_imgWidth/2; | |
3680 | m_imgHeight2 = m_imgHeight/2; | |
3681 | ||
3682 | // calculate indent size | |
3683 | int btnIndent = HasButtons()? m_btnWidth + LINEATROOT: 0; | |
3684 | m_indent = wxMax (MININDENT, wxMax (m_imgWidth, btnIndent)) + MARGIN; | |
3685 | ||
3686 | // set default values | |
3687 | dc.SetFont( m_normalFont ); | |
3688 | dc.SetPen( m_dottedPen ); | |
3689 | ||
3690 | // this is now done dynamically | |
3691 | //if(GetImageList() == NULL) | |
3692 | // m_lineHeight = (int)(dc.GetCharHeight() + 4); | |
3693 | ||
3694 | // calculate column start and paint | |
3695 | int x_colstart = 0; | |
3696 | int i = 0; | |
3697 | for (i = 0; i < (int)GetMainColumn(); ++i) { | |
3698 | if (!m_owner->GetHeaderWindow()->GetColumnShown(i)) continue; | |
3699 | x_colstart += m_owner->GetHeaderWindow()->GetColumnWidth (i); | |
3700 | } | |
3701 | int y = 0; | |
3702 | PaintLevel ( m_anchor, dc, 0, y, x_colstart ); | |
3703 | } | |
3704 | ||
3705 | void wxTreeListMainWindow::OnSetFocus( wxFocusEvent &event ) | |
3706 | { | |
3707 | m_hasFocus = TRUE; | |
3708 | ||
3709 | RefreshSelected(); | |
3710 | ||
3711 | event.Skip(); | |
3712 | } | |
3713 | ||
3714 | void wxTreeListMainWindow::OnKillFocus( wxFocusEvent &event ) | |
3715 | { | |
3716 | m_hasFocus = FALSE; | |
3717 | ||
3718 | RefreshSelected(); | |
3719 | ||
3720 | event.Skip(); | |
3721 | } | |
3722 | ||
3723 | void wxTreeListMainWindow::OnChar( wxKeyEvent &event ) | |
3724 | { | |
3725 | wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, m_owner->GetId() ); | |
3726 | te.SetKeyEvent( event ); | |
3727 | te.SetEventObject( /*this*/m_owner ); | |
3728 | if ( m_owner->GetEventHandler()->ProcessEvent( te ) ) | |
3729 | { | |
3730 | // intercepted by the user code | |
3731 | return; | |
3732 | } | |
3733 | ||
3734 | if ( !m_current ) | |
3735 | { | |
3736 | if (HasFlag(wxTR_HIDE_ROOT)) { | |
3737 | #if !wxCHECK_VERSION(2, 5, 0) | |
3738 | long cookie = 0; | |
3739 | #else | |
3740 | wxTreeItemIdValue cookie = 0; | |
3741 | #endif | |
3742 | m_current = m_key_current = (wxTreeListItem*)GetFirstChild (GetRootItem().m_pItem, cookie).m_pItem; | |
3743 | } | |
3744 | else | |
3745 | { | |
3746 | m_current = m_key_current = (wxTreeListItem*)GetRootItem().m_pItem; | |
3747 | } | |
3748 | } | |
3749 | ||
3750 | // how should the selection work for this event? | |
3751 | bool is_multiple, extended_select, unselect_others; | |
3752 | EventFlagsToSelType(GetWindowStyleFlag(), | |
3753 | event.ShiftDown(), | |
3754 | event.ControlDown(), | |
3755 | is_multiple, extended_select, unselect_others); | |
3756 | ||
3757 | // + : Expand (not on Win32) | |
3758 | // - : Collaspe (not on Win32) | |
3759 | // * : Expand all/Collapse all | |
3760 | // ' ' | return : activate | |
3761 | // up : go up (not last children!) | |
3762 | // down : go down | |
3763 | // left : go to parent (or collapse on Win32) | |
3764 | // right : open if parent and go next (or expand on Win32) | |
3765 | // home : go to root | |
3766 | // end : go to last item without opening parents | |
3767 | switch (event.GetKeyCode()) | |
3768 | { | |
3769 | #ifndef __WXMSW__ // mimic the standard win32 tree ctrl | |
3770 | case '+': | |
3771 | case WXK_ADD: | |
3772 | if (m_current->HasPlus() && !IsExpanded(m_current)) | |
3773 | { | |
3774 | Expand (m_current); | |
3775 | } | |
3776 | break; | |
3777 | #endif // __WXMSW__ | |
3778 | ||
3779 | case '*': | |
3780 | case WXK_MULTIPLY: | |
3781 | if ( !IsExpanded(m_current) ) | |
3782 | { | |
3783 | // expand all | |
3784 | ExpandAll (m_current); | |
3785 | break; | |
3786 | } | |
3787 | //else: fall through to Collapse() it | |
3788 | ||
3789 | #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour | |
3790 | case '-': | |
3791 | case WXK_SUBTRACT: | |
3792 | if (IsExpanded(m_current)) | |
3793 | { | |
3794 | Collapse (m_current); | |
3795 | } | |
3796 | break; | |
3797 | #endif // __WXMSW__ | |
3798 | ||
3799 | case ' ': | |
3800 | case WXK_RETURN: | |
3801 | { | |
3802 | wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, | |
3803 | m_owner->GetId() ); | |
3804 | event.SetItem( (long) m_current); | |
3805 | event.SetEventObject( /*this*/m_owner ); | |
3806 | m_owner->GetEventHandler()->ProcessEvent( event ); | |
3807 | } | |
3808 | break; | |
3809 | ||
3810 | // backspace goes to the parent, sends "root" activation | |
3811 | case WXK_BACK: | |
3812 | { | |
3813 | wxTreeItemId prev = GetItemParent( m_current ); | |
3814 | if ((prev == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) | |
3815 | { | |
3816 | // don't go to root if it is hidden | |
3817 | prev = GetPrevSibling( m_current ); | |
3818 | } | |
3819 | if (prev) | |
3820 | { | |
3821 | SelectItem( prev, unselect_others, extended_select ); | |
3822 | EnsureVisible( prev ); | |
3823 | } | |
3824 | } | |
3825 | break; | |
3826 | ||
3827 | // up goes to the previous sibling or to the last | |
3828 | // of its children if it's expanded | |
3829 | case WXK_UP: | |
3830 | { | |
3831 | wxTreeItemId prev = GetPrevSibling( m_key_current ); | |
3832 | if (!prev) | |
3833 | { | |
3834 | prev = GetItemParent( m_key_current ); | |
3835 | if ((prev == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) | |
3836 | { | |
3837 | break; // don't go to root if it is hidden | |
3838 | } | |
3839 | if (prev) | |
3840 | { | |
3841 | #if !wxCHECK_VERSION(2, 5, 0) | |
3842 | long cookie = 0; | |
3843 | #else | |
3844 | wxTreeItemIdValue cookie = 0; | |
3845 | #endif | |
3846 | wxTreeItemId current = m_key_current; | |
3847 | // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be? | |
3848 | if (current == GetFirstChild( prev, cookie )) | |
3849 | { | |
3850 | // otherwise we return to where we came from | |
3851 | SelectItem( prev, unselect_others, extended_select ); | |
3852 | m_key_current= (wxTreeListItem*) prev.m_pItem; | |
3853 | EnsureVisible( prev ); | |
3854 | break; | |
3855 | } | |
3856 | } | |
3857 | } | |
3858 | if (prev) | |
3859 | { | |
3860 | while ( IsExpanded(prev) && HasChildren(prev) ) | |
3861 | { | |
3862 | wxTreeItemId child = GetLastChild(prev); | |
3863 | if ( !child ) | |
3864 | { | |
3865 | break; | |
3866 | } | |
3867 | prev = child; | |
3868 | } | |
3869 | ||
3870 | SelectItem( prev, unselect_others, extended_select ); | |
3871 | m_key_current=(wxTreeListItem*) prev.m_pItem; | |
3872 | EnsureVisible( prev ); | |
3873 | } | |
3874 | } | |
3875 | break; | |
3876 | ||
3877 | // left arrow goes to the parent | |
3878 | case WXK_LEFT: | |
3879 | if (IsExpanded(m_current)) | |
3880 | { | |
3881 | Collapse(m_current); | |
3882 | } | |
3883 | else | |
3884 | { | |
3885 | wxTreeItemId prev = GetItemParent( m_current ); | |
3886 | if ((prev == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) | |
3887 | { | |
3888 | // don't go to root if it is hidden | |
3889 | prev = GetPrevSibling( m_current ); | |
3890 | } | |
3891 | if (prev) | |
3892 | { | |
3893 | SelectItem( prev, unselect_others, extended_select ); | |
3894 | EnsureVisible( prev ); | |
3895 | } | |
3896 | } | |
3897 | break; | |
3898 | ||
3899 | case WXK_RIGHT: | |
3900 | #if defined(__WXMSW__) // mimic the standard win32 tree ctrl | |
3901 | if (m_current->HasPlus() && !IsExpanded(m_current)) | |
3902 | { | |
3903 | Expand(m_current); | |
3904 | break; | |
3905 | } | |
3906 | #endif // __WXMSW__ | |
3907 | ||
3908 | // this works the same as the down arrow except that we | |
3909 | // also expand the item if it wasn't expanded yet | |
3910 | Expand(m_current); | |
3911 | // fall through | |
3912 | ||
3913 | case WXK_DOWN: | |
3914 | { | |
3915 | if (IsExpanded(m_key_current) && HasChildren(m_key_current)) | |
3916 | { | |
3917 | #if !wxCHECK_VERSION(2, 5, 0) | |
3918 | long cookie = 0; | |
3919 | #else | |
3920 | wxTreeItemIdValue cookie = 0; | |
3921 | #endif | |
3922 | wxTreeItemId child = GetFirstChild( m_key_current, cookie ); | |
3923 | if (child) { | |
3924 | SelectItem( child, unselect_others, extended_select ); | |
3925 | m_key_current=(wxTreeListItem*) child.m_pItem; | |
3926 | EnsureVisible( child ); | |
3927 | break; | |
3928 | } | |
3929 | } | |
3930 | wxTreeItemId next = GetNextSibling( m_key_current ); | |
3931 | if (!next) | |
3932 | { | |
3933 | wxTreeItemId current = m_key_current; | |
3934 | while (current && !next) | |
3935 | { | |
3936 | current = GetItemParent( current ); | |
3937 | if (current) next = GetNextSibling( current ); | |
3938 | } | |
3939 | } | |
3940 | if (next) | |
3941 | { | |
3942 | SelectItem( next, unselect_others, extended_select ); | |
3943 | m_key_current=(wxTreeListItem*) next.m_pItem; | |
3944 | EnsureVisible( next ); | |
3945 | } | |
3946 | } | |
3947 | break; | |
3948 | ||
3949 | // <End> selects the last visible tree item | |
3950 | case WXK_END: | |
3951 | { | |
3952 | wxTreeItemId last = GetRootItem(); | |
3953 | ||
3954 | while ( last.IsOk() && IsExpanded(last) ) | |
3955 | { | |
3956 | wxTreeItemId lastChild = GetLastChild(last); | |
3957 | ||
3958 | // it may happen if the item was expanded but then all of | |
3959 | // its children have been deleted - so IsExpanded() returned | |
3960 | // TRUE, but GetLastChild() returned invalid item | |
3961 | if ( !lastChild ) | |
3962 | break; | |
3963 | ||
3964 | last = lastChild; | |
3965 | } | |
3966 | ||
3967 | if ( last.IsOk() ) | |
3968 | { | |
3969 | SelectItem( last, unselect_others, extended_select ); | |
3970 | EnsureVisible( last ); | |
3971 | } | |
3972 | } | |
3973 | break; | |
3974 | ||
3975 | // <Home> selects the root item | |
3976 | case WXK_HOME: | |
3977 | { | |
3978 | wxTreeItemId prev = GetRootItem(); | |
3979 | if (!prev) break; | |
3980 | if (HasFlag(wxTR_HIDE_ROOT)) | |
3981 | { | |
3982 | #if !wxCHECK_VERSION(2, 5, 0) | |
3983 | long cookie = 0; | |
3984 | #else | |
3985 | wxTreeItemIdValue cookie = 0; | |
3986 | #endif | |
3987 | prev = GetFirstChild(prev, cookie); | |
3988 | if (!prev) break; | |
3989 | } | |
3990 | SelectItem( prev, unselect_others, extended_select ); | |
3991 | EnsureVisible( prev ); | |
3992 | } | |
3993 | break; | |
3994 | ||
3995 | default: | |
3996 | if (event.m_keyCode >= (int)' ') { | |
3997 | if (!m_findTimer->IsRunning()) m_findStr.Clear(); | |
3998 | m_findStr.Append (event.m_keyCode); | |
3999 | m_findTimer->Start (500, wxTIMER_ONE_SHOT); | |
4000 | wxTreeItemId dummy = (wxTreeItemId*)NULL; | |
4001 | wxTreeItemId item = FindItem (dummy, m_findStr, wxTL_SEARCH_VISIBLE | | |
4002 | wxTL_SEARCH_PARTIAL | | |
4003 | wxTL_SEARCH_NOCASE); | |
4004 | if (item.IsOk()) { | |
4005 | EnsureVisible (item); | |
4006 | SelectItem (item); | |
4007 | } | |
4008 | } | |
4009 | event.Skip(); | |
4010 | } | |
4011 | } | |
4012 | ||
4013 | wxTreeItemId wxTreeListMainWindow::HitTest(const wxPoint& point, int& flags, | |
4014 | int& column) | |
4015 | { | |
4016 | // JACS: removed wxYieldIfNeeded() because it can cause the window | |
4017 | // to be deleted from under us if a close window event is pending | |
4018 | ||
4019 | int w, h; | |
4020 | GetSize(&w, &h); | |
4021 | flags=0; | |
4022 | column = -1; | |
4023 | if (point.x<0) flags |= wxTREE_HITTEST_TOLEFT; | |
4024 | if (point.x>w) flags |= wxTREE_HITTEST_TORIGHT; | |
4025 | if (point.y<0) flags |= wxTREE_HITTEST_ABOVE; | |
4026 | if (point.y>h) flags |= wxTREE_HITTEST_BELOW; | |
4027 | if (flags) return wxTreeItemId(); | |
4028 | ||
4029 | if (m_anchor == NULL) | |
4030 | { | |
4031 | flags = wxTREE_HITTEST_NOWHERE; | |
4032 | return wxTreeItemId(); | |
4033 | } | |
4034 | ||
4035 | wxTreeListItem *hit = m_anchor->HitTest(CalcUnscrolledPosition(point), | |
4036 | this, flags, column, 0); | |
4037 | if (hit == NULL) | |
4038 | { | |
4039 | flags = wxTREE_HITTEST_NOWHERE; | |
4040 | return wxTreeItemId(); | |
4041 | } | |
4042 | return hit; | |
4043 | } | |
4044 | ||
4045 | // get the bounding rectangle of the item (or of its label only) | |
4046 | bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId& item, | |
4047 | wxRect& rect, | |
4048 | bool WXUNUSED(textOnly)) const | |
4049 | { | |
4050 | wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") ); | |
4051 | ||
4052 | wxTreeListItem *i = (wxTreeListItem*) item.m_pItem; | |
4053 | ||
4054 | int startX, startY; | |
4055 | GetViewStart(& startX, & startY); | |
4056 | ||
4057 | rect.x = i->GetX() - startX*PIXELS_PER_UNIT; | |
4058 | rect.y = i->GetY() - startY*PIXELS_PER_UNIT; | |
4059 | rect.width = i->GetWidth(); | |
4060 | //rect.height = i->GetHeight(); | |
4061 | rect.height = GetLineHeight(i); | |
4062 | ||
4063 | return TRUE; | |
4064 | } | |
4065 | ||
4066 | /* **** */ | |
4067 | ||
4068 | void wxTreeListMainWindow::Edit( const wxTreeItemId& item ) | |
4069 | { | |
4070 | if (!item.IsOk()) return; | |
4071 | ||
4072 | m_currentEdit = (wxTreeListItem*) item.m_pItem; | |
4073 | ||
4074 | wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, m_owner->GetId() ); | |
4075 | te.SetItem( (long) m_currentEdit); | |
4076 | te.SetEventObject( /*this*/m_owner ); | |
4077 | m_owner->GetEventHandler()->ProcessEvent( te ); | |
4078 | ||
4079 | if (!te.IsAllowed()) return; | |
4080 | ||
4081 | // We have to call this here because the label in | |
4082 | // question might just have been added and no screen | |
4083 | // update taken place. | |
4084 | if (m_dirty) wxYieldIfNeeded(); | |
4085 | ||
4086 | wxString s = m_currentEdit->GetText(/*ALB*/m_main_column); | |
4087 | int x = m_currentEdit->GetX() + m_imgWidth2; | |
4088 | int y = m_currentEdit->GetY(); | |
4089 | int w = wxMin (m_currentEdit->GetWidth(), | |
4090 | m_owner->GetHeaderWindow()->GetWidth()) - m_imgWidth2; | |
4091 | int h = m_currentEdit->GetHeight() + 2; | |
4092 | wxClientDC dc(this); | |
4093 | PrepareDC( dc ); | |
4094 | x = dc.LogicalToDeviceX( x ); | |
4095 | y = dc.LogicalToDeviceY( y ); | |
4096 | ||
4097 | wxTreeListTextCtrl *text = new wxTreeListTextCtrl(this, -1, | |
4098 | &m_renameAccept, | |
4099 | &m_renameRes, | |
4100 | this, | |
4101 | s, | |
4102 | wxPoint (x,y), | |
4103 | wxSize (w,h)); | |
4104 | text->SetFocus(); | |
4105 | } | |
4106 | ||
4107 | void wxTreeListMainWindow::OnRenameTimer() | |
4108 | { | |
4109 | Edit( m_current ); | |
4110 | } | |
4111 | ||
4112 | void wxTreeListMainWindow::OnRenameAccept() | |
4113 | { | |
4114 | // TODO if the validator fails this causes a crash | |
4115 | wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, m_owner->GetId() ); | |
4116 | le.SetItem( (long) m_currentEdit ); | |
4117 | le.SetEventObject( /*this*/m_owner ); | |
4118 | le.SetLabel( m_renameRes ); | |
4119 | m_owner->GetEventHandler()->ProcessEvent( le ); | |
4120 | ||
4121 | if (!le.IsAllowed()) return; | |
4122 | ||
4123 | SetItemText( m_currentEdit, m_renameRes ); | |
4124 | } | |
4125 | ||
4126 | void wxTreeListMainWindow::OnMouse( wxMouseEvent &event ) | |
4127 | { | |
4128 | if ( !m_anchor ) return; | |
4129 | ||
4130 | wxPoint pt = CalcUnscrolledPosition(event.GetPosition()); | |
4131 | ||
4132 | // Is the mouse over a tree item button? | |
4133 | int flags = 0; | |
4134 | wxTreeListItem *item = m_anchor->HitTest(pt, this, flags, 0); | |
4135 | wxTreeListItem *underMouse = item; | |
4136 | ||
4137 | if (underMouse && (flags & wxTREE_HITTEST_ONITEMBUTTON) && | |
4138 | !event.LeftIsDown() && !m_isDragging && | |
4139 | (!m_renameTimer || !m_renameTimer->IsRunning())) | |
4140 | { | |
4141 | } | |
4142 | else | |
4143 | { | |
4144 | underMouse = NULL; | |
4145 | } | |
4146 | ||
4147 | if (underMouse != m_underMouse) | |
4148 | { | |
4149 | if (m_underMouse) | |
4150 | { | |
4151 | // unhighlight old item | |
4152 | wxTreeListItem *tmp = m_underMouse; | |
4153 | m_underMouse = NULL; | |
4154 | RefreshLine( tmp ); | |
4155 | } | |
4156 | ||
4157 | m_underMouse = underMouse; | |
4158 | if (m_underMouse) | |
4159 | RefreshLine( m_underMouse ); | |
4160 | } | |
4161 | ||
4162 | // we process left mouse up event (enables in-place edit), right down | |
4163 | // (pass to the user code), left dbl click (activate item) and | |
4164 | // dragging/moving events for items drag-and-drop | |
4165 | if ( !(event.LeftDown() || | |
4166 | event.LeftUp() || | |
4167 | event.RightDown() || | |
4168 | event.LeftDClick() || | |
4169 | event.Dragging() || | |
4170 | ((event.Moving() || event.RightUp()) && m_isDragging)) ) | |
4171 | { | |
4172 | event.Skip(); | |
4173 | return; | |
4174 | } | |
4175 | ||
4176 | if ( event.LeftDown() ) | |
4177 | SetFocus(); | |
4178 | ||
4179 | // wxClientDC dc(this); | |
4180 | // PrepareDC(dc); | |
4181 | // wxCoord x = dc.DeviceToLogicalX( event.GetX() ); | |
4182 | // wxCoord y = dc.DeviceToLogicalY( event.GetY() ); | |
4183 | wxCoord &x = pt.x; | |
4184 | wxCoord &y = pt.y; | |
4185 | ||
4186 | if ( event.Dragging() && !m_isDragging ) | |
4187 | { | |
4188 | if (m_dragCount == 0) | |
4189 | m_dragStart = wxPoint(x,y); | |
4190 | ||
4191 | m_dragCount++; | |
4192 | ||
4193 | if (m_dragCount != 3) | |
4194 | { | |
4195 | // wait until user drags a bit further... | |
4196 | return; | |
4197 | } | |
4198 | ||
4199 | wxEventType command = event.RightIsDown() | |
4200 | ? wxEVT_COMMAND_TREE_BEGIN_RDRAG | |
4201 | : wxEVT_COMMAND_TREE_BEGIN_DRAG; | |
4202 | ||
4203 | wxTreeEvent nevent( command,/*ALB*/ m_owner->GetId() ); | |
4204 | nevent.SetItem( (long) m_current); | |
4205 | nevent.SetEventObject(/*this*/m_owner); // ALB | |
4206 | ||
4207 | // by default the dragging is not supported, the user code must | |
4208 | // explicitly allow the event for it to take place | |
4209 | nevent.Veto(); | |
4210 | ||
4211 | if ( m_owner->GetEventHandler()->ProcessEvent(nevent) && | |
4212 | nevent.IsAllowed() ) | |
4213 | { | |
4214 | // we're going to drag this item | |
4215 | m_isDragging = TRUE; | |
4216 | ||
4217 | // remember the old cursor because we will change it while | |
4218 | // dragging | |
4219 | m_oldCursor = m_cursor; | |
4220 | ||
4221 | // in a single selection control, hide the selection temporarily | |
4222 | if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE) ) | |
4223 | { | |
4224 | m_oldSelection = (wxTreeListItem*) GetSelection().m_pItem; | |
4225 | ||
4226 | if ( m_oldSelection ) | |
4227 | { | |
4228 | m_oldSelection->SetHilight(FALSE); | |
4229 | RefreshLine(m_oldSelection); | |
4230 | } | |
4231 | } | |
4232 | ||
4233 | CaptureMouse(); | |
4234 | } | |
4235 | } | |
4236 | else if ( event.Moving() ) | |
4237 | { | |
4238 | if ( item != m_dropTarget ) | |
4239 | { | |
4240 | // unhighlight the previous drop target | |
4241 | DrawDropEffect(m_dropTarget); | |
4242 | ||
4243 | m_dropTarget = item; | |
4244 | ||
4245 | // highlight the current drop target if any | |
4246 | DrawDropEffect(m_dropTarget); | |
4247 | ||
4248 | wxYieldIfNeeded(); | |
4249 | } | |
4250 | } | |
4251 | else if ( (event.LeftUp() || event.RightUp()) && m_isDragging ) | |
4252 | { | |
4253 | // erase the highlighting | |
4254 | DrawDropEffect(m_dropTarget); | |
4255 | ||
4256 | if ( m_oldSelection ) | |
4257 | { | |
4258 | m_oldSelection->SetHilight(TRUE); | |
4259 | RefreshLine(m_oldSelection); | |
4260 | m_oldSelection = (wxTreeListItem *)NULL; | |
4261 | } | |
4262 | ||
4263 | // generate the drag end event | |
4264 | wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG,/*ALB*/m_owner->GetId()); | |
4265 | ||
4266 | event.SetItem( (long) item ); | |
4267 | event.SetPoint( wxPoint(x, y) ); | |
4268 | event.SetEventObject(/*this*/m_owner); | |
4269 | ||
4270 | (void)m_owner->GetEventHandler()->ProcessEvent(event); | |
4271 | ||
4272 | m_isDragging = FALSE; | |
4273 | m_dropTarget = (wxTreeListItem *)NULL; | |
4274 | ||
4275 | ReleaseMouse(); | |
4276 | ||
4277 | SetCursor(m_oldCursor); | |
4278 | ||
4279 | wxYieldIfNeeded(); | |
4280 | } | |
4281 | else | |
4282 | { | |
4283 | // here we process only the messages which happen on tree items | |
4284 | ||
4285 | m_dragCount = 0; | |
4286 | ||
4287 | if ( item == NULL ) return; /* we hit the blank area */ | |
4288 | ||
4289 | if ( event.RightDown() ) | |
4290 | { | |
4291 | SetFocus(); | |
4292 | wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, | |
4293 | m_owner->GetId()); | |
4294 | nevent.SetItem( (long) item ); | |
4295 | int nx, ny; | |
4296 | CalcScrolledPosition(x, y, &nx, &ny); | |
4297 | nevent.SetPoint( wxPoint(nx, ny)); | |
4298 | nevent.SetEventObject(/*this*/m_owner); | |
4299 | m_owner->GetEventHandler()->ProcessEvent(nevent); | |
4300 | } | |
4301 | else if ( event.LeftUp() ) | |
4302 | { | |
4303 | if ( m_lastOnSame ) | |
4304 | { | |
4305 | if ( ( item == m_current ) && | |
4306 | ( flags & wxTREE_HITTEST_ONITEMLABEL ) && | |
4307 | HasFlag(wxTR_EDIT_LABELS ) ) | |
4308 | { | |
4309 | if ( m_renameTimer->IsRunning() ) | |
4310 | m_renameTimer->Stop(); | |
4311 | ||
4312 | m_renameTimer->Start( 100, TRUE ); | |
4313 | } | |
4314 | ||
4315 | m_lastOnSame = FALSE; | |
4316 | } | |
4317 | } | |
4318 | else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick() | |
4319 | { | |
4320 | if ( event.LeftDown() ) | |
4321 | { | |
4322 | SetFocus(); | |
4323 | m_lastOnSame = item == m_current; | |
4324 | } | |
4325 | ||
4326 | if ((flags & wxTREE_HITTEST_ONITEMBUTTON) || | |
4327 | ((flags & wxTREE_HITTEST_ONITEMICON)) && | |
4328 | !HasButtons() && item->HasPlus()) | |
4329 | { | |
4330 | // only toggle the item for a single click, double click on | |
4331 | // the button doesn't do anything (it toggles the item twice) | |
4332 | if ( event.LeftDown() ) | |
4333 | { | |
4334 | Toggle( item ); | |
4335 | } | |
4336 | ||
4337 | // don't select the item if the button was clicked | |
4338 | return; | |
4339 | } | |
4340 | ||
4341 | // how should the selection work for this event? | |
4342 | bool is_multiple, extended_select, unselect_others; | |
4343 | EventFlagsToSelType(GetWindowStyleFlag(), | |
4344 | event.ShiftDown(), | |
4345 | event.ControlDown(), | |
4346 | is_multiple, extended_select, unselect_others); | |
4347 | ||
4348 | SelectItem (item, unselect_others, extended_select); | |
4349 | ||
4350 | // For some reason, Windows isn't recognizing a left double-click, | |
4351 | // so we need to simulate it here. Allow 200 milliseconds for now. | |
4352 | if ( event.LeftDClick() ) | |
4353 | { | |
4354 | // double clicking should not start editing the item label | |
4355 | m_renameTimer->Stop(); | |
4356 | m_lastOnSame = FALSE; | |
4357 | ||
4358 | // send activate event first | |
4359 | wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, | |
4360 | m_owner->GetId() ); | |
4361 | nevent.SetItem( (long) item ); | |
4362 | int nx, ny; | |
4363 | CalcScrolledPosition(x, y, &nx, &ny); | |
4364 | nevent.SetPoint( wxPoint(nx, ny) ); | |
4365 | nevent.SetEventObject( /*this*/m_owner ); | |
4366 | if ( !m_owner->GetEventHandler()->ProcessEvent( nevent ) ) | |
4367 | { | |
4368 | // if the user code didn't process the activate event, | |
4369 | // handle it ourselves by toggling the item when it is | |
4370 | // double clicked | |
4371 | if ( item->HasPlus() ) | |
4372 | { | |
4373 | Toggle(item); | |
4374 | } | |
4375 | } | |
4376 | } | |
4377 | } | |
4378 | } | |
4379 | } | |
4380 | ||
4381 | void wxTreeListMainWindow::OnIdle( wxIdleEvent &WXUNUSED(event) ) | |
4382 | { | |
4383 | /* after all changes have been done to the tree control, | |
4384 | * we actually redraw the tree when everything is over */ | |
4385 | ||
4386 | if (!m_dirty) return; | |
4387 | ||
4388 | m_dirty = FALSE; | |
4389 | ||
4390 | CalculatePositions(); | |
4391 | Refresh(); | |
4392 | AdjustMyScrollbars(); | |
4393 | } | |
4394 | ||
4395 | void wxTreeListMainWindow::OnScroll(wxScrollWinEvent& event) | |
4396 | { | |
4397 | // FIXME | |
4398 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) | |
4399 | wxScrolledWindow::OnScroll(event); | |
4400 | #else | |
4401 | HandleOnScroll( event ); | |
4402 | #endif | |
4403 | ||
4404 | if(event.GetOrientation() == wxHORIZONTAL) | |
4405 | { | |
4406 | m_owner->GetHeaderWindow()->Refresh(); | |
4407 | m_owner->GetHeaderWindow()->Update(); | |
4408 | } | |
4409 | } | |
4410 | ||
4411 | ||
4412 | void wxTreeListMainWindow::CalculateSize( wxTreeListItem *item, wxDC &dc ) | |
4413 | { | |
4414 | wxCoord text_w = 0; | |
4415 | wxCoord text_h = 0; | |
4416 | ||
4417 | if (item->IsBold()) | |
4418 | dc.SetFont(m_boldFont); | |
4419 | ||
4420 | dc.GetTextExtent( item->GetText(/*ALB*/m_main_column), &text_w, &text_h ); | |
4421 | text_h+=2; | |
4422 | ||
4423 | // restore normal font | |
4424 | dc.SetFont( m_normalFont ); | |
4425 | ||
4426 | int total_h = (m_imgHeight > text_h) ? m_imgHeight : text_h; | |
4427 | ||
4428 | item->SetHeight(total_h); | |
4429 | if (total_h>m_lineHeight) | |
4430 | m_lineHeight=total_h; | |
4431 | ||
4432 | item->SetWidth(m_imgWidth + text_w+2); | |
4433 | } | |
4434 | ||
4435 | // ----------------------------------------------------------------------------- | |
4436 | // for developper : y is now the top of the level | |
4437 | // not the middle of it ! | |
4438 | void wxTreeListMainWindow::CalculateLevel( wxTreeListItem *item, wxDC &dc, | |
4439 | int level, int &y, int x_colstart ) | |
4440 | { | |
4441 | // calculate position of vertical lines | |
4442 | int x = x_colstart + MARGIN; // start of column | |
4443 | if (HasFlag(wxTR_LINES_AT_ROOT)) x += LINEATROOT; // space for lines at root | |
4444 | if (HasButtons()) x += m_btnWidth2; // space for buttons etc. | |
4445 | if (!HasFlag(wxTR_HIDE_ROOT)) x += m_indent; // indent root as well | |
4446 | x += m_indent * level; // indent according to level | |
4447 | ||
4448 | // a hidden root is not evaluated, but its children are always | |
4449 | if (HasFlag(wxTR_HIDE_ROOT) && (level == 0)) goto Recurse; | |
4450 | ||
4451 | CalculateSize( item, dc ); | |
4452 | ||
4453 | // set its position | |
4454 | item->SetX (x); | |
4455 | item->SetY (y); | |
4456 | y += GetLineHeight(item); | |
4457 | ||
4458 | // we don't need to calculate collapsed branches | |
4459 | if ( !item->IsExpanded() ) return; | |
4460 | ||
4461 | Recurse: | |
4462 | wxArrayTreeListItems& children = item->GetChildren(); | |
4463 | size_t n, count = children.Count(); | |
4464 | ++level; | |
4465 | for (n = 0; n < count; ++n ) | |
4466 | CalculateLevel( children[n], dc, level, y, x_colstart ); // recurse | |
4467 | } | |
4468 | ||
4469 | void wxTreeListMainWindow::CalculatePositions() | |
4470 | { | |
4471 | if ( !m_anchor ) return; | |
4472 | ||
4473 | wxClientDC dc(this); | |
4474 | PrepareDC( dc ); | |
4475 | ||
4476 | dc.SetFont( m_normalFont ); | |
4477 | ||
4478 | dc.SetPen( m_dottedPen ); | |
4479 | //if(GetImageList() == NULL) | |
4480 | // m_lineHeight = (int)(dc.GetCharHeight() + 4); | |
4481 | ||
4482 | int y = 2; | |
4483 | int x_colstart = 0; | |
4484 | for(size_t i = 0; i < GetMainColumn(); ++i) { | |
4485 | if (!m_owner->GetHeaderWindow()->GetColumnShown(i)) continue; | |
4486 | x_colstart += m_owner->GetHeaderWindow()->GetColumnWidth(i); | |
4487 | } | |
4488 | CalculateLevel( m_anchor, dc, 0, y, x_colstart ); // start recursion | |
4489 | } | |
4490 | ||
4491 | void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem *item) | |
4492 | { | |
4493 | if (m_dirty) return; | |
4494 | ||
4495 | wxClientDC dc(this); | |
4496 | PrepareDC(dc); | |
4497 | ||
4498 | int cw = 0; | |
4499 | int ch = 0; | |
4500 | GetVirtualSize( &cw, &ch ); | |
4501 | ||
4502 | wxRect rect; | |
4503 | rect.x = dc.LogicalToDeviceX( 0 ); | |
4504 | rect.width = cw; | |
4505 | rect.y = dc.LogicalToDeviceY( item->GetY() - 2 ); | |
4506 | rect.height = ch; | |
4507 | ||
4508 | Refresh( TRUE, &rect ); | |
4509 | ||
4510 | AdjustMyScrollbars(); | |
4511 | } | |
4512 | ||
4513 | void wxTreeListMainWindow::RefreshLine( wxTreeListItem *item ) | |
4514 | { | |
4515 | if (m_dirty) return; | |
4516 | ||
4517 | wxClientDC dc(this); | |
4518 | PrepareDC( dc ); | |
4519 | ||
4520 | int cw = 0; | |
4521 | int ch = 0; | |
4522 | GetVirtualSize( &cw, &ch ); | |
4523 | ||
4524 | wxRect rect; | |
4525 | rect.x = dc.LogicalToDeviceX( 0 ); | |
4526 | rect.y = dc.LogicalToDeviceY( item->GetY() ); | |
4527 | rect.width = cw; | |
4528 | rect.height = GetLineHeight(item); //dc.GetCharHeight() + 6; | |
4529 | ||
4530 | Refresh( TRUE, &rect ); | |
4531 | } | |
4532 | ||
4533 | void wxTreeListMainWindow::RefreshSelected() | |
4534 | { | |
4535 | // TODO: this is awfully inefficient, we should keep the list of all | |
4536 | // selected items internally, should be much faster | |
4537 | if ( m_anchor ) | |
4538 | RefreshSelectedUnder(m_anchor); | |
4539 | } | |
4540 | ||
4541 | void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem *item) | |
4542 | { | |
4543 | if ( item->IsSelected() ) | |
4544 | RefreshLine(item); | |
4545 | ||
4546 | const wxArrayTreeListItems& children = item->GetChildren(); | |
4547 | size_t count = children.GetCount(); | |
4548 | for ( size_t n = 0; n < count; n++ ) | |
4549 | { | |
4550 | RefreshSelectedUnder(children[n]); | |
4551 | } | |
4552 | } | |
4553 | ||
4554 | // ---------------------------------------------------------------------------- | |
4555 | // changing colours: we need to refresh the tree control | |
4556 | // ---------------------------------------------------------------------------- | |
4557 | ||
4558 | bool wxTreeListMainWindow::SetBackgroundColour(const wxColour& colour) | |
4559 | { | |
4560 | if ( !wxWindow::SetBackgroundColour(colour) ) | |
4561 | return FALSE; | |
4562 | ||
4563 | Refresh(); | |
4564 | ||
4565 | return TRUE; | |
4566 | } | |
4567 | ||
4568 | bool wxTreeListMainWindow::SetForegroundColour(const wxColour& colour) | |
4569 | { | |
4570 | if ( !wxWindow::SetForegroundColour(colour) ) | |
4571 | return FALSE; | |
4572 | ||
4573 | Refresh(); | |
4574 | ||
4575 | return TRUE; | |
4576 | } | |
4577 | ||
4578 | //----------- ALB ------------- | |
4579 | void wxTreeListMainWindow::SetItemText(const wxTreeItemId& item, size_t column, | |
4580 | const wxString& text) | |
4581 | { | |
4582 | wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); | |
4583 | ||
4584 | wxClientDC dc(this); | |
4585 | wxTreeListItem *pItem = (wxTreeListItem*) item.m_pItem; | |
4586 | pItem->SetText(column, text); | |
4587 | CalculateSize(pItem, dc); | |
4588 | RefreshLine(pItem); | |
4589 | } | |
4590 | ||
4591 | wxString wxTreeListMainWindow::GetItemText(const wxTreeItemId& item, | |
4592 | size_t column) const | |
4593 | { | |
4594 | wxCHECK_MSG( item.IsOk(), wxT(""), wxT("invalid tree item") ); | |
4595 | ||
4596 | return ((wxTreeListItem*) item.m_pItem)->GetText(column); | |
4597 | } | |
4598 | ||
4599 | void wxTreeListMainWindow::SetFocus() | |
4600 | { | |
4601 | wxWindow::SetFocus(); | |
4602 | } | |
4603 | ||
4604 | ||
4605 | //----------------------------------------------------------------------------- | |
4606 | // wxTreeListCtrl | |
4607 | //----------------------------------------------------------------------------- | |
4608 | ||
4609 | IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl, wxControl); | |
4610 | ||
4611 | BEGIN_EVENT_TABLE(wxTreeListCtrl, wxControl) | |
4612 | EVT_SIZE(wxTreeListCtrl::OnSize) | |
4613 | END_EVENT_TABLE(); | |
4614 | ||
4615 | bool wxTreeListCtrl::Create(wxWindow *parent, wxWindowID id, | |
4616 | const wxPoint& pos, | |
4617 | const wxSize& size, | |
4618 | long style, const wxValidator &validator, | |
4619 | const wxString& name) | |
4620 | { | |
4621 | long main_style = style & ~(wxRAISED_BORDER|wxSUNKEN_BORDER | |
4622 | |wxSIMPLE_BORDER|wxNO_BORDER|wxDOUBLE_BORDER | |
4623 | |wxSTATIC_BORDER); | |
4624 | long ctrl_style = style & ~(wxVSCROLL|wxHSCROLL); | |
4625 | ||
4626 | if (!wxControl::Create(parent, id, pos, size, ctrl_style, validator, name)) { | |
4627 | return false; | |
4628 | } | |
4629 | m_main_win = new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size, | |
4630 | main_style, validator); | |
4631 | m_header_win = new wxTreeListHeaderWindow(this, -1, m_main_win, | |
4632 | wxPoint(0, 0), wxDefaultSize, | |
4633 | wxTAB_TRAVERSAL); | |
4634 | CalculateAndSetHeaderHeight(); | |
4635 | return TRUE; | |
4636 | } | |
4637 | ||
4638 | void wxTreeListCtrl::CalculateAndSetHeaderHeight() | |
4639 | { | |
4640 | if ( m_header_win ) | |
4641 | { | |
4642 | // we use 'g' to get the descent, too | |
4643 | int w, h, d; | |
4644 | m_header_win->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
4645 | h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
4646 | ||
4647 | // only update if changed | |
4648 | if ( h != (int)m_headerHeight ) | |
4649 | { | |
4650 | m_headerHeight = (size_t)h; | |
4651 | m_header_win->SetSize(m_header_win->GetSize().x, m_headerHeight); | |
4652 | } | |
4653 | } | |
4654 | } | |
4655 | ||
4656 | void wxTreeListCtrl::DoHeaderLayout() | |
4657 | { | |
4658 | int w, h; | |
4659 | GetClientSize(&w, &h); | |
4660 | if (m_header_win) | |
4661 | { | |
4662 | m_header_win->SetSize(0, 0, w, m_headerHeight); | |
4663 | m_header_win->Refresh(false); | |
4664 | } | |
4665 | if (m_main_win) | |
4666 | m_main_win->SetSize(0, m_headerHeight + 1, w, h - m_headerHeight - 1); | |
4667 | } | |
4668 | ||
4669 | void wxTreeListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) | |
4670 | { | |
4671 | DoHeaderLayout(); | |
4672 | } | |
4673 | ||
4674 | ||
4675 | size_t wxTreeListCtrl::GetCount() const { return m_main_win->GetCount(); } | |
4676 | ||
4677 | unsigned int wxTreeListCtrl::GetIndent() const | |
4678 | { return m_main_win->GetIndent(); } | |
4679 | ||
4680 | void wxTreeListCtrl::SetIndent(unsigned int indent) | |
4681 | { m_main_win->SetIndent(indent); } | |
4682 | ||
4683 | unsigned int wxTreeListCtrl::GetLineSpacing() const | |
4684 | { return m_main_win->GetLineSpacing(); } | |
4685 | ||
4686 | void wxTreeListCtrl::SetLineSpacing(unsigned int spacing) | |
4687 | { m_main_win->SetLineSpacing(spacing); } | |
4688 | ||
4689 | wxImageList* wxTreeListCtrl::GetImageList() const | |
4690 | { return m_main_win->GetImageList(); } | |
4691 | ||
4692 | wxImageList* wxTreeListCtrl::GetStateImageList() const | |
4693 | { return m_main_win->GetStateImageList(); } | |
4694 | ||
4695 | wxImageList* wxTreeListCtrl::GetButtonsImageList() const | |
4696 | { return m_main_win->GetButtonsImageList(); } | |
4697 | ||
4698 | void wxTreeListCtrl::SetImageList(wxImageList* imageList) | |
4699 | { m_main_win->SetImageList(imageList); } | |
4700 | ||
4701 | void wxTreeListCtrl::SetStateImageList(wxImageList* imageList) | |
4702 | { m_main_win->SetStateImageList(imageList); } | |
4703 | ||
4704 | void wxTreeListCtrl::SetButtonsImageList(wxImageList* imageList) | |
4705 | { m_main_win->SetButtonsImageList(imageList); } | |
4706 | ||
4707 | void wxTreeListCtrl::AssignImageList(wxImageList* imageList) | |
4708 | { m_main_win->AssignImageList(imageList); } | |
4709 | ||
4710 | void wxTreeListCtrl::AssignStateImageList(wxImageList* imageList) | |
4711 | { m_main_win->AssignStateImageList(imageList); } | |
4712 | ||
4713 | void wxTreeListCtrl::AssignButtonsImageList(wxImageList* imageList) | |
4714 | { m_main_win->AssignButtonsImageList(imageList); } | |
4715 | ||
4716 | wxString wxTreeListCtrl::GetItemText(const wxTreeItemId& item, size_t column) | |
4717 | const | |
4718 | { return m_main_win->GetItemText(item, column); } | |
4719 | ||
4720 | int wxTreeListCtrl::GetItemImage(const wxTreeItemId& item, size_t column, | |
4721 | wxTreeItemIcon which) const | |
4722 | { return m_main_win->GetItemImage(item, column, which); } | |
4723 | ||
4724 | wxTreeItemData* wxTreeListCtrl::GetItemData(const wxTreeItemId& item) const | |
4725 | { return m_main_win->GetItemData(item); } | |
4726 | ||
4727 | bool wxTreeListCtrl::GetItemBold(const wxTreeItemId& item) const | |
4728 | { return m_main_win->GetItemBold(item); } | |
4729 | ||
4730 | wxColour wxTreeListCtrl::GetItemTextColour(const wxTreeItemId& item) const | |
4731 | { return m_main_win->GetItemTextColour(item); } | |
4732 | ||
4733 | wxColour wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId& item) | |
4734 | const | |
4735 | { return m_main_win->GetItemBackgroundColour(item); } | |
4736 | ||
4737 | wxFont wxTreeListCtrl::GetItemFont(const wxTreeItemId& item) const | |
4738 | { return m_main_win->GetItemFont(item); } | |
4739 | ||
4740 | ||
4741 | void wxTreeListCtrl::SetItemText(const wxTreeItemId& item, size_t column, | |
4742 | const wxString& text) | |
4743 | { m_main_win->SetItemText(item, column, text); } | |
4744 | ||
4745 | void wxTreeListCtrl::SetItemImage(const wxTreeItemId& item, | |
4746 | size_t column, | |
4747 | int image, | |
4748 | wxTreeItemIcon which) | |
4749 | { m_main_win->SetItemImage(item, column, image, which); } | |
4750 | ||
4751 | void wxTreeListCtrl::SetItemData(const wxTreeItemId& item, | |
4752 | wxTreeItemData* data) | |
4753 | { m_main_win->SetItemData(item, data); } | |
4754 | ||
4755 | void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has) | |
4756 | { m_main_win->SetItemHasChildren(item, has); } | |
4757 | ||
4758 | void wxTreeListCtrl::SetItemBold(const wxTreeItemId& item, bool bold) | |
4759 | { m_main_win->SetItemBold(item, bold); } | |
4760 | ||
4761 | void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId& item, | |
4762 | const wxColour& col) | |
4763 | { m_main_win->SetItemTextColour(item, col); } | |
4764 | ||
4765 | void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId& item, | |
4766 | const wxColour& col) | |
4767 | { m_main_win->SetItemBackgroundColour(item, col); } | |
4768 | ||
4769 | void wxTreeListCtrl::SetItemFont(const wxTreeItemId& item, | |
4770 | const wxFont& font) | |
4771 | { m_main_win->SetItemFont(item, font); } | |
4772 | ||
4773 | bool wxTreeListCtrl::SetFont(const wxFont& font) | |
4774 | { | |
4775 | if (m_header_win) | |
4776 | { | |
4777 | m_header_win->SetFont(font); | |
4778 | CalculateAndSetHeaderHeight(); | |
4779 | } | |
4780 | if (m_main_win) | |
4781 | return m_main_win->SetFont(font); | |
4782 | else return FALSE; | |
4783 | } | |
4784 | ||
4785 | void wxTreeListCtrl::SetWindowStyle(const long style) | |
4786 | { | |
4787 | if(m_main_win) | |
4788 | m_main_win->SetWindowStyle(style); | |
4789 | // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win | |
4790 | } | |
4791 | ||
4792 | long wxTreeListCtrl::GetWindowStyle() const | |
4793 | { | |
4794 | long style = m_windowStyle; | |
4795 | if(m_main_win) | |
4796 | style |= m_main_win->GetWindowStyle(); | |
4797 | return style; | |
4798 | } | |
4799 | ||
4800 | bool wxTreeListCtrl::IsVisible(const wxTreeItemId& item) const | |
4801 | { return m_main_win->IsVisible(item); } | |
4802 | ||
4803 | bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId& item) const | |
4804 | { return m_main_win->ItemHasChildren(item); } | |
4805 | ||
4806 | bool wxTreeListCtrl::IsExpanded(const wxTreeItemId& item) const | |
4807 | { return m_main_win->IsExpanded(item); } | |
4808 | ||
4809 | bool wxTreeListCtrl::IsSelected(const wxTreeItemId& item) const | |
4810 | { return m_main_win->IsSelected(item); } | |
4811 | ||
4812 | bool wxTreeListCtrl::IsBold(const wxTreeItemId& item) const | |
4813 | { return m_main_win->IsBold(item); } | |
4814 | ||
4815 | size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId& item, bool rec) | |
4816 | { return m_main_win->GetChildrenCount(item, rec); } | |
4817 | ||
4818 | wxTreeItemId wxTreeListCtrl::GetRootItem() const | |
4819 | { return m_main_win->GetRootItem(); } | |
4820 | ||
4821 | wxTreeItemId wxTreeListCtrl::GetSelection() const | |
4822 | { return m_main_win->GetSelection(); } | |
4823 | ||
4824 | size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds& arr) const | |
4825 | { return m_main_win->GetSelections(arr); } | |
4826 | ||
4827 | wxTreeItemId wxTreeListCtrl::GetItemParent(const wxTreeItemId& item) const | |
4828 | { return m_main_win->GetItemParent(item); } | |
4829 | ||
4830 | #if !wxCHECK_VERSION(2, 5, 0) | |
4831 | wxTreeItemId wxTreeListCtrl::GetFirstChild(const wxTreeItemId& item, | |
4832 | long& cookie) const | |
4833 | #else | |
4834 | wxTreeItemId wxTreeListCtrl::GetFirstChild(const wxTreeItemId& item, | |
4835 | wxTreeItemIdValue& cookie) const | |
4836 | #endif | |
4837 | { return m_main_win->GetFirstChild(item, cookie); } | |
4838 | ||
4839 | #if !wxCHECK_VERSION(2, 5, 0) | |
4840 | wxTreeItemId wxTreeListCtrl::GetNextChild(const wxTreeItemId& item, | |
4841 | long& cookie) const | |
4842 | #else | |
4843 | wxTreeItemId wxTreeListCtrl::GetNextChild(const wxTreeItemId& item, | |
4844 | wxTreeItemIdValue& cookie) const | |
4845 | #endif | |
4846 | { return m_main_win->GetNextChild(item, cookie); } | |
4847 | ||
4848 | #if !wxCHECK_VERSION(2, 5, 0) | |
4849 | wxTreeItemId wxTreeListCtrl::GetPrevChild(const wxTreeItemId& item, | |
4850 | long& cookie) const | |
4851 | #else | |
4852 | wxTreeItemId wxTreeListCtrl::GetPrevChild(const wxTreeItemId& item, | |
4853 | wxTreeItemIdValue& cookie) const | |
4854 | #endif | |
4855 | { return m_main_win->GetPrevChild(item, cookie); } | |
4856 | ||
4857 | wxTreeItemId wxTreeListCtrl::GetLastChild(const wxTreeItemId& item) const | |
4858 | { return m_main_win->GetLastChild(item); } | |
4859 | ||
4860 | wxTreeItemId wxTreeListCtrl::GetNextSibling(const wxTreeItemId& item) const | |
4861 | { return m_main_win->GetNextSibling(item); } | |
4862 | ||
4863 | wxTreeItemId wxTreeListCtrl::GetPrevSibling(const wxTreeItemId& item) const | |
4864 | { return m_main_win->GetPrevSibling(item); } | |
4865 | ||
4866 | wxTreeItemId wxTreeListCtrl::GetFirstVisibleItem() const | |
4867 | { return m_main_win->GetFirstVisibleItem(); } | |
4868 | ||
4869 | wxTreeItemId wxTreeListCtrl::GetNextVisible(const wxTreeItemId& item) const | |
4870 | { return m_main_win->GetNextVisible(item); } | |
4871 | ||
4872 | wxTreeItemId wxTreeListCtrl::GetPrevVisible(const wxTreeItemId& item) const | |
4873 | { return m_main_win->GetPrevVisible(item); } | |
4874 | ||
4875 | wxTreeItemId wxTreeListCtrl::GetNext(const wxTreeItemId& item) const | |
4876 | { return m_main_win->GetNext(item); } | |
4877 | ||
4878 | wxTreeItemId wxTreeListCtrl::AddRoot(const wxString& text, int image, | |
4879 | int selectedImage, wxTreeItemData* data) | |
4880 | { return m_main_win->AddRoot(text, image, selectedImage, data); } | |
4881 | ||
4882 | wxTreeItemId wxTreeListCtrl::PrependItem(const wxTreeItemId& parent, | |
4883 | const wxString& text, int image, | |
4884 | int selectedImage, | |
4885 | wxTreeItemData* data) | |
4886 | { return m_main_win->PrependItem(parent, text, image, selectedImage, data); } | |
4887 | ||
4888 | wxTreeItemId wxTreeListCtrl::InsertItem(const wxTreeItemId& parent, | |
4889 | const wxTreeItemId& previous, | |
4890 | const wxString& text, int image, | |
4891 | int selectedImage, | |
4892 | wxTreeItemData* data) | |
4893 | { | |
4894 | return m_main_win->InsertItem(parent, previous, text, image, | |
4895 | selectedImage, data); | |
4896 | } | |
4897 | ||
4898 | wxTreeItemId wxTreeListCtrl::InsertItem(const wxTreeItemId& parent, | |
4899 | size_t index, | |
4900 | const wxString& text, int image, | |
4901 | int selectedImage, | |
4902 | wxTreeItemData* data) | |
4903 | { | |
4904 | return m_main_win->InsertItem(parent, index, text, image, | |
4905 | selectedImage, data); | |
4906 | } | |
4907 | ||
4908 | wxTreeItemId wxTreeListCtrl::AppendItem(const wxTreeItemId& parent, | |
4909 | const wxString& text, int image, | |
4910 | int selectedImage, | |
4911 | wxTreeItemData* data) | |
4912 | { return m_main_win->AppendItem(parent, text, image, selectedImage, data); } | |
4913 | ||
4914 | void wxTreeListCtrl::Delete(const wxTreeItemId& item) | |
4915 | { m_main_win->Delete(item); } | |
4916 | ||
4917 | void wxTreeListCtrl::DeleteChildren(const wxTreeItemId& item) | |
4918 | { m_main_win->DeleteChildren(item); } | |
4919 | ||
4920 | void wxTreeListCtrl::DeleteAllItems() | |
4921 | { m_main_win->DeleteAllItems(); } | |
4922 | ||
4923 | void wxTreeListCtrl::Expand(const wxTreeItemId& item) | |
4924 | { m_main_win->Expand(item); } | |
4925 | ||
4926 | void wxTreeListCtrl::ExpandAll(const wxTreeItemId& item) | |
4927 | { m_main_win->ExpandAll(item); } | |
4928 | ||
4929 | void wxTreeListCtrl::Collapse(const wxTreeItemId& item) | |
4930 | { m_main_win->Collapse(item); } | |
4931 | ||
4932 | void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId& item) | |
4933 | { m_main_win->CollapseAndReset(item); } | |
4934 | ||
4935 | void wxTreeListCtrl::Toggle(const wxTreeItemId& item) | |
4936 | { m_main_win->Toggle(item); } | |
4937 | ||
4938 | void wxTreeListCtrl::Unselect() | |
4939 | { m_main_win->Unselect(); } | |
4940 | ||
4941 | void wxTreeListCtrl::UnselectAll() | |
4942 | { m_main_win->UnselectAll(); } | |
4943 | ||
4944 | void wxTreeListCtrl::SelectItem(const wxTreeItemId& item, bool unselect_others, | |
4945 | bool extended_select) | |
4946 | { m_main_win->SelectItem(item, unselect_others, extended_select); } | |
4947 | ||
4948 | void wxTreeListCtrl::SelectAll(bool extended_select) | |
4949 | { m_main_win->SelectAll(extended_select); } | |
4950 | ||
4951 | void wxTreeListCtrl::EnsureVisible(const wxTreeItemId& item) | |
4952 | { m_main_win->EnsureVisible(item); } | |
4953 | ||
4954 | void wxTreeListCtrl::ScrollTo(const wxTreeItemId& item) | |
4955 | { m_main_win->ScrollTo(item); } | |
4956 | ||
4957 | wxTreeItemId wxTreeListCtrl::HitTest(const wxPoint& pos, int& flags, | |
4958 | int& column) | |
4959 | { | |
4960 | return m_main_win->HitTest(pos, flags, column); | |
4961 | } | |
4962 | ||
4963 | bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId& item, wxRect& rect, | |
4964 | bool textOnly) const | |
4965 | { return m_main_win->GetBoundingRect(item, rect, textOnly); } | |
4966 | ||
4967 | void wxTreeListCtrl::Edit(const wxTreeItemId& item) | |
4968 | { m_main_win->Edit(item); } | |
4969 | ||
4970 | int wxTreeListCtrl::OnCompareItems(const wxTreeItemId& item1, | |
4971 | const wxTreeItemId& item2) | |
4972 | { | |
4973 | // ALB: do the comparison here, and not delegate to m_main_win, in order | |
4974 | // to let the user override it | |
4975 | //return m_main_win->OnCompareItems(item1, item2); | |
4976 | return wxStrcmp(GetItemText(item1), GetItemText(item2)); | |
4977 | } | |
4978 | ||
4979 | void wxTreeListCtrl::SortChildren(const wxTreeItemId& item) | |
4980 | { m_main_win->SortChildren(item); } | |
4981 | ||
4982 | wxTreeItemId wxTreeListCtrl::FindItem (const wxTreeItemId& item, const wxString& str, int flags) | |
4983 | { return m_main_win->FindItem (item, str, flags); } | |
4984 | ||
4985 | bool wxTreeListCtrl::SetBackgroundColour(const wxColour& colour) | |
4986 | { | |
4987 | if (!m_main_win) return false; | |
4988 | return m_main_win->SetBackgroundColour(colour); | |
4989 | } | |
4990 | ||
4991 | bool wxTreeListCtrl::SetForegroundColour(const wxColour& colour) | |
4992 | { | |
4993 | if (!m_main_win) return false; | |
4994 | return m_main_win->SetForegroundColour(colour); | |
4995 | } | |
4996 | ||
4997 | size_t wxTreeListCtrl::GetColumnCount() const | |
4998 | { return m_main_win->GetColumnCount(); } | |
4999 | ||
5000 | void wxTreeListCtrl::SetColumnWidth(size_t column, size_t width) | |
5001 | { m_header_win->SetColumnWidth(column, width); } | |
5002 | ||
5003 | int wxTreeListCtrl::GetColumnWidth(size_t column) const | |
5004 | { return m_header_win->GetColumnWidth(column); } | |
5005 | ||
5006 | void wxTreeListCtrl::SetMainColumn(size_t column) | |
5007 | { m_main_win->SetMainColumn(column); } | |
5008 | ||
5009 | size_t wxTreeListCtrl::GetMainColumn() const | |
5010 | { return m_main_win->GetMainColumn(); } | |
5011 | ||
5012 | void wxTreeListCtrl::SetColumnText(size_t column, const wxString& text) | |
5013 | { | |
5014 | m_header_win->SetColumnText(column, text); | |
5015 | m_header_win->Refresh(); | |
5016 | } | |
5017 | ||
5018 | wxString wxTreeListCtrl::GetColumnText(size_t column) const | |
5019 | { return m_header_win->GetColumnText(column); } | |
5020 | ||
5021 | void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo& col) | |
5022 | { | |
5023 | m_header_win->AddColumn(col); | |
5024 | DoHeaderLayout(); | |
5025 | } | |
5026 | ||
5027 | void wxTreeListCtrl::InsertColumn(size_t before, | |
5028 | const wxTreeListColumnInfo& col) | |
5029 | { m_header_win->InsertColumn(before, col); } | |
5030 | ||
5031 | void wxTreeListCtrl::RemoveColumn(size_t column) | |
5032 | { m_header_win->RemoveColumn(column); } | |
5033 | ||
5034 | void wxTreeListCtrl::SetColumn(size_t column, const wxTreeListColumnInfo& col) | |
5035 | { m_header_win->SetColumn(column, col); } | |
5036 | ||
5037 | const wxTreeListColumnInfo& wxTreeListCtrl::GetColumn(size_t column) const | |
5038 | { return m_header_win->GetColumn(column); } | |
5039 | ||
5040 | wxTreeListColumnInfo& wxTreeListCtrl::GetColumn(size_t column) | |
5041 | { return m_header_win->GetColumn(column); } | |
5042 | ||
5043 | void wxTreeListCtrl::SetColumnImage(size_t column, int image) | |
5044 | { | |
5045 | m_header_win->SetColumn(column, GetColumn(column).SetImage(image)); | |
5046 | } | |
5047 | ||
5048 | int wxTreeListCtrl::GetColumnImage(size_t column) const | |
5049 | { | |
5050 | return m_header_win->GetColumn(column).GetImage(); | |
5051 | } | |
5052 | ||
5053 | void wxTreeListCtrl::ShowColumn(size_t column, bool shown) | |
5054 | { | |
5055 | wxASSERT_MSG( column != GetMainColumn(), | |
5056 | wxT("The main column may not be hidden") ); | |
5057 | m_header_win->SetColumn(column, GetColumn(column).SetShown(GetMainColumn()? true: shown)); | |
5058 | } | |
5059 | ||
5060 | bool wxTreeListCtrl::IsColumnShown(size_t column) const | |
5061 | { | |
5062 | return m_header_win->GetColumn(column).GetShown(); | |
5063 | } | |
5064 | ||
5065 | void wxTreeListCtrl::SetColumnAlignment(size_t column, | |
5066 | wxTreeListColumnAlign align) | |
5067 | { | |
5068 | m_header_win->SetColumn(column, GetColumn(column).SetAlignment(align)); | |
5069 | } | |
5070 | ||
5071 | wxTreeListColumnAlign wxTreeListCtrl::GetColumnAlignment(size_t column) const | |
5072 | { | |
5073 | return m_header_win->GetColumn(column).GetAlignment(); | |
5074 | } | |
5075 | ||
5076 | void wxTreeListCtrl::Refresh(bool erase, const wxRect* rect) | |
5077 | { | |
5078 | m_main_win->Refresh(erase, rect); | |
5079 | m_header_win->Refresh(erase, rect); | |
5080 | } | |
5081 | ||
5082 | void wxTreeListCtrl::SetFocus() | |
5083 | { m_main_win->SetFocus(); } | |
5084 | ||
5085 | ||
5086 | wxSize wxTreeListCtrl::DoGetBestSize() const | |
5087 | { | |
5088 | // something is better than nothing... | |
5089 | return wxSize(100,80); | |
5090 | } |