1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treelistctrl.cpp
3 // Purpose: multi column tree control implementation
4 // Author: Robert Roebling
6 // Modified: Alberto Griggio, 2002
7 // 22/10/98 - almost total rewrite, simpler interface (VZ)
9 // Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio,
10 // Vadim Zeitlin, Otto Wyss
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 // ===========================================================================
16 // ===========================================================================
18 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 #if defined(__GNUG__) && !defined(__APPLE__)
23 #pragma implementation "treelistctrl.h"
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
34 #include <wx/treebase.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>
43 #include "wx/treelistctrl.h"
47 #include <wx/gtk/win_gtk.h>
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
56 #if !wxCHECK_VERSION(2, 5, 0)
57 WX_DEFINE_ARRAY(wxTreeListItem
*, wxArrayTreeListItems
);
59 WX_DEFINE_ARRAY_PTR(wxTreeListItem
*, wxArrayTreeListItems
);
62 #include <wx/dynarray.h>
63 WX_DECLARE_OBJARRAY(wxTreeListColumnInfo
, wxArrayTreeListColumnInfo
);
64 #include <wx/arrimpl.cpp>
65 WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo
);
67 #if !wxCHECK_VERSION(2, 3, 3)
68 WX_DEFINE_ARRAY(short, wxArrayShort
);
72 // --------------------------------------------------------------------------
74 // --------------------------------------------------------------------------
76 static const int NO_IMAGE
= -1;
78 const int LINEHEIGHT
= 10;
79 const int PIXELS_PER_UNIT
= 10;
80 const int LINEATROOT
= 5;
82 const int MININDENT
= 10;
83 const int BTNWIDTH
= 11;
84 const int BTNHEIGHT
= 11;
86 const wxChar
* wxTreeListCtrlNameStr
= wxT("treelistctrl");
88 static wxTreeListColumnInfo wxInvalidTreeListColumnInfo
;
91 // ---------------------------------------------------------------------------
93 // ---------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 // wxTreeListHeaderWindow (internal)
96 //-----------------------------------------------------------------------------
98 class wxTreeListHeaderWindow
: public wxWindow
101 wxTreeListMainWindow
*m_owner
;
102 wxCursor
*m_currentCursor
;
103 wxCursor
*m_resizeCursor
;
106 // column being resized
109 // divider line position in logical (unscrolled) coords
112 // minimal position beyond which the divider line can't be dragged in
116 wxArrayTreeListColumnInfo m_columns
;
118 // total width of the columns
119 int m_total_col_width
;
123 wxTreeListHeaderWindow();
125 wxTreeListHeaderWindow( wxWindow
*win
,
127 wxTreeListMainWindow
*owner
,
128 const wxPoint
&pos
= wxDefaultPosition
,
129 const wxSize
&size
= wxDefaultSize
,
131 const wxString
&name
= wxT("wxtreelistctrlcolumntitles") );
133 virtual ~wxTreeListHeaderWindow();
135 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
137 void AdjustDC(wxDC
& dc
);
139 void OnPaint( wxPaintEvent
&event
);
140 void OnMouse( wxMouseEvent
&event
);
141 void OnSetFocus( wxFocusEvent
&event
);
144 // columns manipulation
146 size_t GetColumnCount() const { return m_columns
.GetCount(); }
148 void AddColumn(const wxTreeListColumnInfo
& col
);
150 void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
);
152 void RemoveColumn(size_t column
);
154 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
155 const wxTreeListColumnInfo
& GetColumn(size_t column
) const
157 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
158 return m_columns
[column
];
160 wxTreeListColumnInfo
& GetColumn(size_t column
)
162 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
163 return m_columns
[column
];
166 void SetColumnWidth(size_t column
, size_t width
);
168 void SetColumnText(size_t column
, const wxString
& text
)
170 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
171 m_columns
[column
].SetText(text
);
174 void SetColumnShown(size_t column
, bool shown
)
176 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
177 m_columns
[column
].SetShown(shown
);
180 wxString
GetColumnText(size_t column
) const
182 wxCHECK_MSG(column
< GetColumnCount(), wxEmptyString
, wxT("Invalid column"));
183 return m_columns
[column
].GetText();
186 int GetColumnWidth(size_t column
) const
188 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
189 return m_columns
[column
].GetWidth();
192 int GetWidth() const { return m_total_col_width
; }
194 int GetColumnShown(size_t column
) const
196 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
197 return m_columns
[column
].GetShown();
204 // common part of all ctors
207 void SendListEvent(wxEventType type
, wxPoint pos
);
209 DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow
)
210 DECLARE_EVENT_TABLE()
214 // this is the "true" control
215 class wxTreeListMainWindow
: public wxScrolledWindow
220 wxTreeListMainWindow() { Init(); }
222 wxTreeListMainWindow(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
223 const wxPoint
& pos
= wxDefaultPosition
,
224 const wxSize
& size
= wxDefaultSize
,
225 long style
= wxTR_DEFAULT_STYLE
,
226 const wxValidator
&validator
= wxDefaultValidator
,
227 const wxString
& name
= wxT("wxtreelistmainwindow"))
230 Create(parent
, id
, pos
, size
, style
, validator
, name
);
233 virtual ~wxTreeListMainWindow();
235 bool Create(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
236 const wxPoint
& pos
= wxDefaultPosition
,
237 const wxSize
& size
= wxDefaultSize
,
238 long style
= wxTR_DEFAULT_STYLE
,
239 const wxValidator
&validator
= wxDefaultValidator
,
240 const wxString
& name
= wxT("wxtreelistctrl"));
245 // get the total number of items in the control
246 size_t GetCount() const;
248 // indent is the number of pixels the children are indented relative to
249 // the parents position. SetIndent() also redraws the control
251 unsigned int GetIndent() const { return m_indent
; }
252 void SetIndent(unsigned int indent
);
254 // see wxTreeListCtrl for the meaning
255 unsigned int GetLineSpacing() const { return m_linespacing
; }
256 void SetLineSpacing(unsigned int spacing
);
258 // image list: these functions allow to associate an image list with
259 // the control and retrieve it. Note that when assigned with
260 // SetImageList, the control does _not_ delete
261 // the associated image list when it's deleted in order to allow image
262 // lists to be shared between different controls. If you use
263 // AssignImageList, the control _does_ delete the image list.
265 // The normal image list is for the icons which correspond to the
266 // normal tree item state (whether it is selected or not).
267 // Additionally, the application might choose to show a state icon
268 // which corresponds to an app-defined item state (for example,
269 // checked/unchecked) which are taken from the state image list.
270 wxImageList
*GetImageList() const;
271 wxImageList
*GetStateImageList() const;
272 wxImageList
*GetButtonsImageList() const;
274 void SetImageList(wxImageList
*imageList
);
275 void SetStateImageList(wxImageList
*imageList
);
276 void SetButtonsImageList(wxImageList
*imageList
);
277 void AssignImageList(wxImageList
*imageList
);
278 void AssignStateImageList(wxImageList
*imageList
);
279 void AssignButtonsImageList(wxImageList
*imageList
);
281 // Functions to work with tree ctrl items.
286 // retrieve item's label
287 wxString
GetItemText(const wxTreeItemId
& item
) const
288 { return GetItemText(item
, GetMainColumn()); }
289 // get one of the images associated with the item (normal by default)
290 int GetItemImage(const wxTreeItemId
& item
,
291 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
292 { return GetItemImage(item
, GetMainColumn(), which
); }
294 // get the data associated with the item
295 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
297 bool GetItemBold(const wxTreeItemId
& item
) const;
298 wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
299 wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
300 wxFont
GetItemFont(const wxTreeItemId
& item
) const;
306 void SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
307 { SetItemText(item
, GetMainColumn(), text
); }
309 // get one of the images associated with the item (normal by default)
310 void SetItemImage(const wxTreeItemId
& item
, int image
,
311 wxTreeItemIcon which
= wxTreeItemIcon_Normal
)
312 { SetItemImage(item
, GetMainColumn(), image
, which
); }
314 // associate some data with the item
315 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
317 // force appearance of [+] button near the item. This is useful to
318 // allow the user to expand the items which don't have any children now
319 // - but instead add them only when needed, thus minimizing memory
320 // usage and loading time.
321 void SetItemHasChildren(const wxTreeItemId
& item
, bool has
= TRUE
);
323 // the item will be shown in bold
324 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
326 // set the item's text colour
327 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
329 // set the item's background colour
330 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
332 // set the item's font (should be of the same height for all items)
333 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
335 // set the window font
336 virtual bool SetFont( const wxFont
&font
);
338 // set the styles. No need to specify a GetWindowStyle here since
339 // the base wxWindow member function will do it for us
340 void SetWindowStyle(const long styles
);
342 // item status inquiries
343 // ---------------------
345 // is the item visible (it might be outside the view or not expanded)?
346 bool IsVisible(const wxTreeItemId
& item
) const;
347 // does the item has any children?
348 bool HasChildren(const wxTreeItemId
& item
) const
349 { return ItemHasChildren(item
); }
350 bool ItemHasChildren(const wxTreeItemId
& item
) const;
351 // is the item expanded (only makes sense if HasChildren())?
352 bool IsExpanded(const wxTreeItemId
& item
) const;
353 // is this item currently selected (the same as has focus)?
354 bool IsSelected(const wxTreeItemId
& item
) const;
355 // is item text in bold font?
356 bool IsBold(const wxTreeItemId
& item
) const;
357 // does the layout include space for a button?
359 // number of children
360 // ------------------
362 // if 'recursively' is FALSE, only immediate children count, otherwise
363 // the returned number is the number of all items in this branch
364 size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively
= TRUE
);
369 // wxTreeItemId.IsOk() will return FALSE if there is no such item
371 // get the root tree item
372 wxTreeItemId
GetRootItem() const { return m_anchor
; }
374 // get the item currently selected (may return NULL if no selection)
375 wxTreeItemId
GetSelection() const { return m_current
; }
377 // get the items currently selected, return the number of such item
378 size_t GetSelections(wxArrayTreeItemIds
&) const;
380 // get the parent of this item (may return NULL if root)
381 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
383 // for this enumeration function you must pass in a "cookie" parameter
384 // which is opaque for the application but is necessary for the library
385 // to make these functions reentrant (i.e. allow more than one
386 // enumeration on one and the same object simultaneously). Of course,
387 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
390 // get the first child of this item
391 #if !wxCHECK_VERSION(2, 5, 0)
392 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
394 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
396 // get the next child
397 #if !wxCHECK_VERSION(2, 5, 0)
398 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
400 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
402 // get the prev child
403 #if !wxCHECK_VERSION(2, 5, 0)
404 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, long& cookie
) const;
406 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
408 // get the last child of this item - this method doesn't use cookies
409 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
411 // get the next sibling of this item
412 wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
413 // get the previous sibling
414 wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
416 // get first visible item
417 wxTreeItemId
GetFirstVisibleItem() const;
418 // get the next visible item: item must be visible itself!
419 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
420 wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
421 // get the previous visible item: item must be visible itself!
422 wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
424 // Only for internal use right now, but should probably be public
425 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
430 // add the root node to the tree
431 wxTreeItemId
AddRoot(const wxString
& text
,
432 int image
= -1, int selectedImage
= -1,
433 wxTreeItemData
*data
= NULL
);
435 // insert a new item in as the first child of the parent
436 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
437 const wxString
& text
,
438 int image
= -1, int selectedImage
= -1,
439 wxTreeItemData
*data
= NULL
);
441 // insert a new item after a given one
442 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
443 const wxTreeItemId
& idPrevious
,
444 const wxString
& text
,
445 int image
= -1, int selectedImage
= -1,
446 wxTreeItemData
*data
= NULL
);
448 // insert a new item before the one with the given index
449 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
451 const wxString
& text
,
452 int image
= -1, int selectedImage
= -1,
453 wxTreeItemData
*data
= NULL
);
455 // insert a new item in as the last child of the parent
456 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
457 const wxString
& text
,
458 int image
= -1, int selectedImage
= -1,
459 wxTreeItemData
*data
= NULL
);
461 // delete this item and associated data if any
462 void Delete(const wxTreeItemId
& item
);
463 // delete all children (but don't delete the item itself)
464 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
465 void DeleteChildren(const wxTreeItemId
& item
);
466 // delete all items from the tree
467 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
468 void DeleteAllItems();
471 void Expand(const wxTreeItemId
& item
);
472 // expand this item and all subitems recursively
473 void ExpandAll(const wxTreeItemId
& item
);
474 // collapse the item without removing its children
475 void Collapse(const wxTreeItemId
& item
);
476 // collapse the item and remove all children
477 void CollapseAndReset(const wxTreeItemId
& item
);
478 // toggles the current state
479 void Toggle(const wxTreeItemId
& item
);
481 // remove the selection from currently selected item (if any)
485 void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
,
486 bool extended_select
=FALSE
);
487 void SelectAll(bool extended_select
=FALSE
);
488 // make sure this item is visible (expanding the parent item and/or
489 // scrolling to this item if necessary)
490 void EnsureVisible(const wxTreeItemId
& item
);
491 // scroll to this item (but don't expand its parent)
492 void ScrollTo(const wxTreeItemId
& item
);
493 void AdjustMyScrollbars();
495 // The first function is more portable (because easier to implement
496 // on other platforms), but the second one returns some extra info.
497 wxTreeItemId
HitTest(const wxPoint
& point
)
498 { int dummy
; return HitTest(point
, dummy
); }
499 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
)
500 { int col
; return HitTest(point
, flags
, col
); }
502 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
, int& column
);
505 // get the bounding rectangle of the item (or of its label only)
506 bool GetBoundingRect(const wxTreeItemId
& item
,
508 bool textOnly
= FALSE
) const;
510 // Start editing the item label: this (temporarily) replaces the item
511 // with a one line edit control. The item will be selected if it hadn't
513 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
514 void Edit( const wxTreeItemId
& item
);
517 // this function is called to compare 2 items and should return -1, 0
518 // or +1 if the first item is less than, equal to or greater than the
519 // second one. The base class version performs alphabetic comparaison
520 // of item labels (GetText)
521 virtual int OnCompareItems(const wxTreeItemId
& item1
,
522 const wxTreeItemId
& item2
);
523 // sort the children of this item using OnCompareItems
525 // NB: this function is not reentrant and not MT-safe (FIXME)!
526 void SortChildren(const wxTreeItemId
& item
);
529 wxTreeItemId
FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
= 0);
531 // deprecated functions: use Set/GetItemImage directly
532 // get the selected item image
533 int GetItemSelectedImage(const wxTreeItemId
& item
) const
534 { return GetItemImage(item
, wxTreeItemIcon_Selected
); }
535 // set the selected item image
536 void SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
537 { SetItemImage(item
, image
, wxTreeItemIcon_Selected
); }
539 // implementation only from now on
541 // overridden base class virtuals
542 virtual bool SetBackgroundColour(const wxColour
& colour
);
543 virtual bool SetForegroundColour(const wxColour
& colour
);
546 void OnPaint( wxPaintEvent
&event
);
547 void OnSetFocus( wxFocusEvent
&event
);
548 void OnKillFocus( wxFocusEvent
&event
);
549 void OnChar( wxKeyEvent
&event
);
550 void OnMouse( wxMouseEvent
&event
);
551 void OnIdle( wxIdleEvent
&event
);
552 void OnSize(wxSizeEvent
& event
); // ALB
553 void OnScroll(wxScrollWinEvent
& event
); // ALB
555 // implementation helpers
556 void SendDeleteEvent(wxTreeListItem
*itemBeingDeleted
);
558 void DrawBorder(const wxTreeItemId
& item
);
559 void DrawLine(const wxTreeItemId
& item
, bool below
);
561 size_t GetColumnCount() const
562 { return m_owner
->GetHeaderWindow()->GetColumnCount(); }
564 void SetMainColumn(size_t column
)
566 if(column
< GetColumnCount())
567 m_main_column
= column
;
569 size_t GetMainColumn() const { return m_main_column
; }
571 void SetItemText(const wxTreeItemId
& item
, size_t column
,
572 const wxString
& text
);
573 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
575 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
576 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
577 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
578 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
583 wxTreeListCtrl
* m_owner
; // ALB
585 size_t m_main_column
; // ALB
587 friend class wxTreeListItem
;
588 friend class wxTreeListRenameTimer
;
589 friend class wxTreeListTextCtrl
;
594 wxTreeListItem
*m_anchor
;
595 wxTreeListItem
*m_current
, *m_key_current
, *m_currentEdit
;
596 int m_btnWidth
, m_btnWidth2
;
597 int m_btnHeight
, m_btnHeight2
;
598 int m_imgWidth
, m_imgWidth2
;
599 int m_imgHeight
, m_imgHeight2
;
600 unsigned short m_indent
;
602 unsigned short m_linespacing
;
604 wxBrush
*m_hilightBrush
,
605 *m_hilightUnfocusedBrush
;
610 bool m_ownsImageListNormal
,
611 m_ownsImageListState
,
612 m_ownsImageListButtons
;
613 bool m_isDragging
; // true between BEGIN/END drag events
615 bool m_lastOnSame
; // last click on the same item as prev
616 wxImageList
*m_imageListNormal
,
622 wxTreeListItem
*m_dropTarget
;
623 wxCursor m_oldCursor
; // cursor is changed while dragging
624 wxTreeListItem
*m_oldSelection
;
626 wxTimer
*m_renameTimer
;
627 wxString m_renameRes
;
630 wxTimer
*m_findTimer
;
633 // the common part of all ctors
637 wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
639 const wxString
& text
,
640 int image
, int selectedImage
,
641 wxTreeItemData
*data
);
642 bool HasButtons(void) const
643 { return (m_imageListButtons
!= NULL
) ||
644 HasFlag (wxTR_TWIST_BUTTONS
|wxTR_HAS_BUTTONS
); }
647 void CalculateLineHeight();
648 int GetLineHeight(wxTreeListItem
*item
) const;
649 void PaintLevel( wxTreeListItem
*item
, wxDC
& dc
, int level
, int &y
,
651 void PaintItem( wxTreeListItem
*item
, wxDC
& dc
);
653 void CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
, int level
, int &y
,
655 void CalculatePositions();
656 void CalculateSize( wxTreeListItem
*item
, wxDC
&dc
);
658 void RefreshSubtree( wxTreeListItem
*item
);
659 void RefreshLine( wxTreeListItem
*item
);
661 // redraw all selected items
662 void RefreshSelected();
664 // RefreshSelected() recursive helper
665 void RefreshSelectedUnder(wxTreeListItem
*item
);
667 void OnRenameTimer();
668 void OnRenameAccept();
670 void FillArray(wxTreeListItem
*, wxArrayTreeItemIds
&) const;
671 void SelectItemRange( wxTreeListItem
*item1
, wxTreeListItem
*item2
);
672 bool TagAllChildrenUntilLast(wxTreeListItem
*crt_item
,
673 wxTreeListItem
*last_item
, bool select
);
674 bool TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
,
676 void UnselectAllChildren( wxTreeListItem
*item
);
678 void DrawDropEffect(wxTreeListItem
*item
);
681 DECLARE_EVENT_TABLE()
682 DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow
)
686 // timer used for enabling in-place edit
687 class wxTreeListRenameTimer
: public wxTimer
690 wxTreeListRenameTimer( wxTreeListMainWindow
*owner
);
695 wxTreeListMainWindow
*m_owner
;
698 // control used for in-place edit
699 class wxTreeListTextCtrl
: public wxTextCtrl
702 wxTreeListTextCtrl( wxWindow
*parent
,
706 wxTreeListMainWindow
*owner
,
707 const wxString
&value
= wxEmptyString
,
708 const wxPoint
&pos
= wxDefaultPosition
,
709 const wxSize
&size
= wxDefaultSize
,
710 int style
= wxSIMPLE_BORDER
,
711 const wxValidator
& validator
= wxDefaultValidator
,
712 const wxString
&name
= wxTextCtrlNameStr
);
714 void OnChar( wxKeyEvent
&event
);
715 void OnKeyUp( wxKeyEvent
&event
);
716 void OnKillFocus( wxFocusEvent
&event
);
721 wxTreeListMainWindow
*m_owner
;
722 wxString m_startValue
;
725 DECLARE_EVENT_TABLE()
733 wxTreeListItem() { m_data
= NULL
; }
734 wxTreeListItem( wxTreeListMainWindow
*owner
,
735 wxTreeListItem
*parent
,
736 const wxArrayString
& text
,
739 wxTreeItemData
*data
);
744 wxArrayTreeListItems
& GetChildren() { return m_children
; }
746 const wxString
GetText() const
748 if(m_text
.GetCount() > 0) return m_text
[0];
749 return wxEmptyString
;
751 const wxString
GetText(size_t col
) const
753 if(m_text
.GetCount() > col
) return m_text
[col
];
754 return wxEmptyString
;
756 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
757 { return m_images
[which
]; }
758 int GetImage(size_t col
, wxTreeItemIcon which
=wxTreeItemIcon_Normal
) const
760 if(col
== m_owner
->GetMainColumn()) return m_images
[which
];
761 if(col
< m_col_images
.GetCount()) return m_col_images
[col
];
764 wxTreeItemData
*GetData() const { return m_data
; }
766 // returns the current image for the item (depending on its
767 // selected/expanded/whatever state)
768 int GetCurrentImage() const;
770 void SetText( const wxString
&text
);
771 void SetText(size_t col
, const wxString
& text
) // ALB
773 if(col
< m_text
.GetCount())
775 else if(col
< m_owner
->GetColumnCount()) {
776 int howmany
= m_owner
->GetColumnCount();
777 for(int i
= m_text
.GetCount(); i
< howmany
; ++i
)
778 m_text
.Add(wxEmptyString
);
782 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
783 void SetImage(size_t col
, int image
, wxTreeItemIcon which
)
785 if(col
== m_owner
->GetMainColumn()) m_images
[which
] = image
;
786 else if(col
< m_col_images
.GetCount())
787 m_col_images
[col
] = image
;
788 else if(col
< m_owner
->GetColumnCount()) {
789 int howmany
= m_owner
->GetColumnCount();
790 for(int i
= m_col_images
.GetCount(); i
< howmany
; ++i
)
791 m_col_images
.Add(NO_IMAGE
);
792 m_col_images
[col
] = image
;
796 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
798 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
800 void SetBold(bool bold
) { m_isBold
= bold
; }
802 int GetX() const { return m_x
; }
803 int GetY() const { return m_y
; }
805 void SetX(int x
) { m_x
= x
; }
806 void SetY(int y
) { m_y
= y
; }
808 int GetHeight() const { return m_height
; }
809 int GetWidth() const { return m_width
; }
811 void SetHeight(int h
) { m_height
= h
; }
812 void SetWidth(int w
) { m_width
= w
; }
814 wxTreeListItem
*GetItemParent() const { return m_parent
; }
817 // deletes all children notifying the treectrl about it if !NULL
819 void DeleteChildren(wxTreeListMainWindow
*tree
= NULL
);
821 // get count of all children (and grand children if 'recursively')
822 size_t GetChildrenCount(bool recursively
= TRUE
) const;
824 void Insert(wxTreeListItem
*child
, size_t index
)
825 { m_children
.Insert(child
, index
); }
827 void GetSize( int &x
, int &y
, const wxTreeListMainWindow
* );
829 // return the item at given position (or NULL if no item), onButton is
830 // TRUE if the point belongs to the item's button, otherwise it lies
831 // on the button's label
832 wxTreeListItem
*HitTest( const wxPoint
& point
,
833 const wxTreeListMainWindow
*,
836 wxTreeListItem
*HitTest( const wxPoint
& point
,
837 const wxTreeListMainWindow
*,
838 int &flags
, int& column
/*ALB*/,
841 void Expand() { m_isCollapsed
= FALSE
; }
842 void Collapse() { m_isCollapsed
= TRUE
; }
844 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
847 bool HasChildren() const { return !m_children
.IsEmpty(); }
848 bool IsSelected() const { return m_hasHilight
!= 0; }
849 bool IsExpanded() const { return !m_isCollapsed
; }
850 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
851 bool IsBold() const { return m_isBold
!= 0; }
854 // get them - may be NULL
855 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
856 // get them ensuring that the pointer is not NULL
857 wxTreeItemAttr
& Attr()
861 m_attr
= new wxTreeItemAttr
;
867 void SetAttributes(wxTreeItemAttr
*attr
)
869 if ( m_ownsAttr
) delete m_attr
;
873 // set them and delete when done
874 void AssignAttributes(wxTreeItemAttr
*attr
)
881 wxTreeListMainWindow
*m_owner
; // control the item belongs to
883 // since there can be very many of these, we save size by chosing
884 // the smallest representation for the elements and by ordering
885 // the members to avoid padding.
886 wxArrayString m_text
; // labels to be rendered for item
888 wxTreeItemData
*m_data
; // user-provided data
890 wxArrayTreeListItems m_children
; // list of children
891 wxTreeListItem
*m_parent
; // parent of this item
893 wxTreeItemAttr
*m_attr
; // attributes???
895 // tree ctrl images for the normal, selected, expanded and
896 // expanded+selected states
897 short m_images
[wxTreeItemIcon_Max
];
898 wxArrayShort m_col_images
; // images for the various columns (!= main)
900 wxCoord m_x
; // (virtual) offset from top
901 wxCoord m_y
; // (virtual) offset from left
902 short m_width
; // width of this item
903 unsigned char m_height
; // height of this item
905 // use bitfields to save size
906 int m_isCollapsed
:1;
907 int m_hasHilight
:1; // same as focused
908 int m_hasPlus
:1; // used for item which doesn't have
909 // children but has a [+] button
910 int m_isBold
:1; // render the label in bold font
911 int m_ownsAttr
:1; // delete attribute when done
914 // ===========================================================================
916 // ===========================================================================
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
922 // translate the key or mouse event flags to the type of selection we're
924 static void EventFlagsToSelType(long style
,
928 bool &extended_select
,
929 bool &unselect_others
)
931 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
932 extended_select
= shiftDown
&& is_multiple
;
933 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
936 // ---------------------------------------------------------------------------
937 // wxTreeListRenameTimer (internal)
938 // ---------------------------------------------------------------------------
940 wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow
*owner
)
945 void wxTreeListRenameTimer::Notify()
947 m_owner
->OnRenameTimer();
950 //-----------------------------------------------------------------------------
951 // wxTreeListTextCtrl (internal)
952 //-----------------------------------------------------------------------------
954 BEGIN_EVENT_TABLE(wxTreeListTextCtrl
,wxTextCtrl
)
955 EVT_CHAR (wxTreeListTextCtrl::OnChar
)
956 EVT_KEY_UP (wxTreeListTextCtrl::OnKeyUp
)
957 EVT_KILL_FOCUS (wxTreeListTextCtrl::OnKillFocus
)
960 wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow
*parent
,
964 wxTreeListMainWindow
*owner
,
965 const wxString
&value
,
969 const wxValidator
& validator
,
970 const wxString
&name
)
971 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
977 (*m_res
) = wxEmptyString
;
978 m_startValue
= value
;
982 void wxTreeListTextCtrl::OnChar( wxKeyEvent
&event
)
984 if (event
.m_keyCode
== WXK_RETURN
)
987 (*m_res
) = GetValue();
989 if ((*m_res
) != m_startValue
)
990 m_owner
->OnRenameAccept();
992 if (!wxPendingDelete
.Member(this))
993 wxPendingDelete
.Append(this);
996 m_owner
->SetFocus(); // This doesn't work. TODO.
1000 if (event
.m_keyCode
== WXK_ESCAPE
)
1002 (*m_accept
) = FALSE
;
1003 (*m_res
) = wxEmptyString
;
1005 if (!wxPendingDelete
.Member(this))
1006 wxPendingDelete
.Append(this);
1009 m_owner
->SetFocus(); // This doesn't work. TODO.
1016 void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1024 // auto-grow the textctrl:
1025 wxSize parentSize
= m_owner
->GetSize();
1026 wxPoint myPos
= GetPosition();
1027 wxSize mySize
= GetSize();
1029 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
1030 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1031 if (mySize
.x
> sx
) sx
= mySize
.x
;
1037 void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
1045 if (!wxPendingDelete
.Member(this))
1046 wxPendingDelete
.Append(this);
1049 (*m_res
) = GetValue();
1051 if ((*m_res
) != m_startValue
)
1052 m_owner
->OnRenameAccept();
1055 //-----------------------------------------------------------------------------
1056 // wxTreeListHeaderWindow
1057 //-----------------------------------------------------------------------------
1059 IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow
,wxWindow
);
1061 BEGIN_EVENT_TABLE(wxTreeListHeaderWindow
,wxWindow
)
1062 EVT_PAINT (wxTreeListHeaderWindow::OnPaint
)
1063 EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse
)
1064 EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus
)
1067 void wxTreeListHeaderWindow::Init()
1069 m_currentCursor
= (wxCursor
*) NULL
;
1070 m_isDragging
= FALSE
;
1072 m_total_col_width
= 0;
1075 wxTreeListHeaderWindow::wxTreeListHeaderWindow()
1079 m_owner
= (wxTreeListMainWindow
*) NULL
;
1080 m_resizeCursor
= (wxCursor
*) NULL
;
1083 wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow
*win
,
1085 wxTreeListMainWindow
*owner
,
1089 const wxString
&name
)
1090 : wxWindow( win
, id
, pos
, size
, style
, name
)
1095 m_resizeCursor
= new wxCursor(wxCURSOR_SIZEWE
);
1097 SetBackgroundColour(wxSystemSettings::GetSystemColour(
1098 wxSYS_COLOUR_BTNFACE
));
1101 wxTreeListHeaderWindow::~wxTreeListHeaderWindow()
1103 delete m_resizeCursor
;
1106 void wxTreeListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1109 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1110 : GTK_STATE_INSENSITIVE
;
1112 x
= dc
->XLOG2DEV( x
);
1114 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1115 state
, GTK_SHADOW_OUT
,
1116 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1117 x
-1, y
-1, w
+2, h
+2);
1118 #elif defined( __WXMAC__ )
1119 const int m_corner
= 1;
1121 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1123 dc
->SetPen( wxPen(wxSystemSettings::GetSystemColour(
1124 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
));
1125 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1126 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1128 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1131 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1132 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1134 dc
->SetPen( *wxWHITE_PEN
);
1135 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1136 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1137 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1138 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1140 const int m_corner
= 1;
1142 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1144 dc
->SetPen( *wxBLACK_PEN
);
1145 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1146 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1148 wxPen
pen(wxSystemSettings::GetSystemColour(
1149 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1152 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1153 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1155 dc
->SetPen( *wxWHITE_PEN
);
1156 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1157 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1158 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1159 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1163 // shift the DC origin to match the position of the main window horz
1164 // scrollbar: this allows us to always use logical coords
1165 void wxTreeListHeaderWindow::AdjustDC(wxDC
& dc
)
1168 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1171 m_owner
->GetViewStart( &x
, NULL
);
1173 // account for the horz scrollbar offset
1174 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1177 void wxTreeListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1179 static const int HEADER_OFFSET_X
= 1, HEADER_OFFSET_Y
= 1;
1181 wxClientDC
dc( this );
1183 wxPaintDC
dc( this );
1191 dc
.SetFont( GetFont() );
1193 // width and height of the entire header window
1195 GetClientSize( &w
, &h
);
1196 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1198 dc
.SetBackgroundMode(wxTRANSPARENT
);
1200 // do *not* use the listctrl colour for headers - one day we will have a
1201 // function to set it separately
1202 //dc.SetTextForeground( *wxBLACK );
1203 dc
.SetTextForeground(wxSystemSettings::
1204 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1206 int x
= HEADER_OFFSET_X
;
1208 int numColumns
= GetColumnCount();
1209 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1211 if (!GetColumnShown (i
)) continue;
1213 wxTreeListColumnInfo
& column
= GetColumn(i
);
1214 int wCol
= column
.GetWidth();
1216 // the width of the rect to draw: make it smaller to fit entirely
1217 // inside the column rect
1220 dc
.SetPen( *wxWHITE_PEN
);
1222 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1224 // if we have an image, draw it on the right of the label
1225 int image
= column
.GetImage(); //item.m_image;
1226 int ix
= -2, iy
= 0;
1227 wxImageList
* imageList
= m_owner
->GetImageList();
1230 imageList
->GetSize(image
, ix
, iy
);
1232 //else: ignore the column image
1235 // extra margins around the text label
1236 static const int EXTRA_WIDTH
= 3;
1237 static const int EXTRA_HEIGHT
= 4;
1241 int image_offset
= cw
- ix
- 1;
1243 switch(column
.GetAlignment()) {
1244 case wxTL_ALIGN_LEFT
:
1245 text_x
+= EXTRA_WIDTH
;
1248 case wxTL_ALIGN_RIGHT
:
1249 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1250 text_x
+= cw
- text_width
- EXTRA_WIDTH
;
1253 case wxTL_ALIGN_CENTER
:
1254 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1255 text_x
+= (cw
- text_width
)/2 + ix
+ 2;
1256 image_offset
= (cw
- text_width
- ix
- 2)/2;
1261 if(image
!= -1 && imageList
) {
1262 imageList
->Draw(image
, dc
, x
+ image_offset
/*cw - ix - 1*/,
1263 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1264 wxIMAGELIST_DRAW_TRANSPARENT
);
1267 // draw the text clipping it so that it doesn't overwrite the column
1269 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1271 dc
.DrawText( column
.GetText(),
1272 text_x
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1277 int more_w
= m_owner
->GetSize().x
- x
;
1280 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, more_w
, h
-2 );
1287 void wxTreeListHeaderWindow::DrawCurrent()
1289 int x1
= m_currentX
;
1291 ClientToScreen( &x1
, &y1
);
1293 int x2
= m_currentX
-1;
1298 m_owner
->GetClientSize( NULL
, &y2
);
1299 m_owner
->ClientToScreen( &x2
, &y2
);
1302 dc
.SetLogicalFunction( wxINVERT
);
1303 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1304 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1308 dc
.DrawLine( x1
, y1
, x2
, y2
);
1310 dc
.SetLogicalFunction( wxCOPY
);
1312 dc
.SetPen( wxNullPen
);
1313 dc
.SetBrush( wxNullBrush
);
1316 void wxTreeListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1318 // we want to work with logical coords
1320 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1321 int y
= event
.GetY();
1325 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
,
1326 event
.GetPosition());
1328 // we don't draw the line beyond our window, but we allow dragging it
1331 GetClientSize( &w
, NULL
);
1332 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1335 // erase the line if it was drawn
1336 if ( m_currentX
< w
)
1339 if (event
.ButtonUp())
1342 m_isDragging
= FALSE
;
1344 SetColumnWidth( m_column
, m_currentX
- m_minX
);
1346 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
,
1347 event
.GetPosition());
1354 m_currentX
= m_minX
+ 7;
1356 // draw in the new location
1357 if ( m_currentX
< w
)
1361 else // not dragging
1364 bool hit_border
= FALSE
;
1366 // end of the current column
1369 // find the column where this event occured
1370 int countCol
= GetColumnCount();
1371 for (int col
= 0; col
< countCol
; col
++)
1373 if (!GetColumnShown (col
)) continue;
1374 xpos
+= GetColumnWidth (col
);
1377 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1379 // near the column border
1386 // inside the column
1393 if (event
.LeftDown() || event
.RightUp())
1395 if (hit_border
&& event
.LeftDown())
1397 m_isDragging
= TRUE
;
1401 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1402 event
.GetPosition());
1404 else // click on a column
1406 SendListEvent( event
.LeftDown()
1407 ? wxEVT_COMMAND_LIST_COL_CLICK
1408 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1409 event
.GetPosition());
1412 else if (event
.Moving())
1417 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1418 m_currentCursor
= m_resizeCursor
;
1422 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1423 m_currentCursor
= wxSTANDARD_CURSOR
;
1427 SetCursor(*m_currentCursor
);
1432 void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1434 m_owner
->SetFocus();
1437 void wxTreeListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1439 wxWindow
*parent
= GetParent();
1440 wxListEvent
le( type
, parent
->GetId() );
1441 le
.SetEventObject( parent
);
1442 le
.m_pointDrag
= pos
;
1444 // the position should be relative to the parent window, not
1445 // this one for compatibility with MSW and common sense: the
1446 // user code doesn't know anything at all about this header
1447 // window, so why should it get positions relative to it?
1448 le
.m_pointDrag
.y
-= GetSize().y
;
1450 le
.m_col
= m_column
;
1451 parent
->GetEventHandler()->ProcessEvent( le
);
1454 void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo
& col
)
1457 m_total_col_width
+= col
.GetWidth();
1458 //m_owner->GetHeaderWindow()->Refresh();
1460 m_owner
->AdjustMyScrollbars();
1461 m_owner
->m_dirty
= TRUE
;
1465 void wxTreeListHeaderWindow::SetColumnWidth(size_t column
, size_t width
)
1467 if(column
< GetColumnCount()) {
1468 m_total_col_width
-= m_columns
[column
].GetWidth();
1469 m_columns
[column
].SetWidth(width
);
1470 m_total_col_width
+= width
;
1471 m_owner
->AdjustMyScrollbars();
1472 m_owner
->m_dirty
= TRUE
;
1479 void wxTreeListHeaderWindow::InsertColumn(size_t before
,
1480 const wxTreeListColumnInfo
& col
)
1482 wxCHECK_RET(before
< GetColumnCount(), wxT("Invalid column index"));
1483 m_columns
.Insert(col
, before
);
1484 m_total_col_width
+= col
.GetWidth();
1486 //m_owner->GetHeaderWindow()->Refresh();
1487 m_owner
->AdjustMyScrollbars();
1488 m_owner
->m_dirty
= TRUE
;
1492 void wxTreeListHeaderWindow::RemoveColumn(size_t column
)
1494 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1495 m_total_col_width
-= m_columns
[column
].GetWidth();
1496 m_columns
.RemoveAt(column
);
1498 m_owner
->AdjustMyScrollbars();
1499 m_owner
->m_dirty
= TRUE
;
1503 void wxTreeListHeaderWindow::SetColumn(size_t column
,
1504 const wxTreeListColumnInfo
& info
)
1506 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1507 size_t w
= m_columns
[column
].GetWidth();
1508 m_columns
[column
] = info
;
1509 //m_owner->GetHeaderWindow()->Refresh();
1511 if(w
!= info
.GetWidth()) {
1512 m_total_col_width
+= info
.GetWidth() - w
;
1513 m_owner
->AdjustMyScrollbars();
1514 m_owner
->m_dirty
= TRUE
;
1519 // ---------------------------------------------------------------------------
1521 // ---------------------------------------------------------------------------
1523 wxTreeListItem::wxTreeListItem(wxTreeListMainWindow
*owner
,
1524 wxTreeListItem
*parent
,
1525 const wxArrayString
& text
,
1526 int image
, int selImage
,
1527 wxTreeItemData
*data
)
1530 m_images
[wxTreeItemIcon_Normal
] = image
;
1531 m_images
[wxTreeItemIcon_Selected
] = selImage
;
1532 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
1533 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
1538 m_isCollapsed
= TRUE
;
1539 m_hasHilight
= FALSE
;
1547 m_attr
= (wxTreeItemAttr
*)NULL
;
1550 // We don't know the height here yet.
1555 wxTreeListItem::~wxTreeListItem()
1559 if (m_ownsAttr
) delete m_attr
;
1561 wxASSERT_MSG( m_children
.IsEmpty(),
1562 wxT("please call DeleteChildren() before deleting the item") );
1565 void wxTreeListItem::DeleteChildren(wxTreeListMainWindow
*tree
)
1567 size_t count
= m_children
.Count();
1568 for ( size_t n
= 0; n
< count
; n
++ )
1570 wxTreeListItem
*child
= m_children
[n
];
1572 tree
->SendDeleteEvent(child
);
1574 child
->DeleteChildren(tree
);
1581 void wxTreeListItem::SetText( const wxString
&text
)
1583 if(m_text
.GetCount() > 0) m_text
[0] = text
;
1589 size_t wxTreeListItem::GetChildrenCount(bool recursively
) const
1591 size_t count
= m_children
.Count();
1595 size_t total
= count
;
1596 for (size_t n
= 0; n
< count
; ++n
)
1598 total
+= m_children
[n
]->GetChildrenCount();
1604 void wxTreeListItem::GetSize( int &x
, int &y
,
1605 const wxTreeListMainWindow
*theButton
)
1607 int bottomY
=m_y
+theButton
->GetLineHeight(this);
1608 if ( y
< bottomY
) y
= bottomY
;
1609 int width
= m_x
+ m_width
;
1610 if ( x
< width
) x
= width
;
1614 size_t count
= m_children
.Count();
1615 for ( size_t n
= 0; n
< count
; ++n
)
1617 m_children
[n
]->GetSize( x
, y
, theButton
);
1622 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1623 const wxTreeListMainWindow
*theCtrl
,
1627 // for a hidden root node, don't evaluate it, but do evaluate children
1628 if (!(theCtrl
->HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)))
1630 // evaluate the item
1631 int h
= theCtrl
->GetLineHeight(this);
1632 if ((point
.y
> m_y
) && (point
.y
<= m_y
+ h
))
1634 // check for above/below middle
1635 int y_mid
= m_y
+ h
/2;
1636 if (point
.y
< y_mid
)
1637 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
1639 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
1641 // check for button hit
1642 if (HasPlus() && theCtrl
->HasButtons()) {
1643 int bntX
= m_x
- theCtrl
->m_btnWidth2
;
1644 int bntY
= y_mid
- theCtrl
->m_btnHeight2
;
1645 if ((point
.x
> bntX
) && (point
.x
< (bntX
+ theCtrl
->m_btnWidth
)) &&
1646 (point
.y
> bntY
) && (point
.y
< (bntY
+ theCtrl
->m_btnHeight
))) {
1647 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
1652 // check for image hit
1653 if (theCtrl
->m_imgWidth
> 0) {
1654 int imgX
= m_x
- theCtrl
->m_imgWidth2
;
1655 int imgY
= y_mid
- theCtrl
->m_imgHeight2
;
1656 if ((point
.x
>= imgX
) && (point
.x
<= (imgX
+ theCtrl
->m_imgWidth
)) &&
1657 (point
.y
>= imgY
) && (point
.y
<= (imgY
+ theCtrl
->m_imgHeight
))) {
1658 flags
|= wxTREE_HITTEST_ONITEMICON
;
1663 // check for label hit
1664 int lblX
= m_x
- theCtrl
->m_imgWidth2
+ theCtrl
->m_imgWidth
+ MARGIN
;
1665 if ((point
.x
>= lblX
) && (point
.x
<= (m_x
+ m_width
)) &&
1666 (point
.y
>= m_y
) && (point
.y
<= (m_y
+ h
))) {
1667 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
1671 // else check for indent
1672 if (point
.x
< m_x
) {
1673 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
1677 // else check for item right???
1678 if (point
.x
> m_x
+ m_width
) {
1679 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
1685 // if children are expanded, fall through to evaluate them
1686 if (m_isCollapsed
) return (wxTreeListItem
*) NULL
;
1689 // evaluate children
1690 size_t count
= m_children
.Count();
1691 for ( size_t n
= 0; n
< count
; n
++ )
1693 wxTreeListItem
*res
= m_children
[n
]->HitTest(point
, theCtrl
,
1699 return (wxTreeListItem
*) NULL
;
1703 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1704 const wxTreeListMainWindow
*theCtrl
,
1705 int &flags
, int& column
, int level
)
1707 column
= theCtrl
->GetMainColumn(); //-1;
1709 wxTreeListItem
* res
= HitTest(point
, theCtrl
, flags
, level
);
1715 wxTreeListHeaderWindow
* header_win
= theCtrl
->m_owner
->GetHeaderWindow();
1716 if (point
.x
>= header_win
->GetWidth())
1718 else if(flags
& wxTREE_HITTEST_ONITEMINDENT
) {
1720 for(size_t i
= 0; i
< theCtrl
->GetMainColumn(); ++i
) {
1721 if (!header_win
->GetColumnShown(i
)) continue;
1722 int w
= header_win
->GetColumnWidth(i
);
1723 if(point
.x
>= x
&& point
.x
< x
+w
) {
1724 flags
^= wxTREE_HITTEST_ONITEMINDENT
;
1725 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1731 else if(flags
& wxTREE_HITTEST_ONITEMRIGHT
) {
1734 for(i
= 0; i
< theCtrl
->GetMainColumn()+1; ++i
) {
1735 if (!header_win
->GetColumnShown(i
)) continue;
1736 x
+= header_win
->GetColumnWidth(i
);
1738 for(i
= theCtrl
->GetMainColumn()+1; i
< theCtrl
->GetColumnCount(); ++i
) {
1739 if (!header_win
->GetColumnShown(i
)) continue;
1740 int w
= header_win
->GetColumnWidth(i
);
1741 if(point
.x
>= x
&& point
.x
< x
+w
) {
1742 flags
^= wxTREE_HITTEST_ONITEMRIGHT
;
1743 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1755 int wxTreeListItem::GetCurrentImage() const
1757 int image
= NO_IMAGE
;
1762 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
1765 if ( image
== NO_IMAGE
)
1767 // we usually fall back to the normal item, but try just the
1768 // expanded one (and not selected) first in this case
1769 image
= GetImage(wxTreeItemIcon_Expanded
);
1772 else // not expanded
1775 image
= GetImage(wxTreeItemIcon_Selected
);
1778 // maybe it doesn't have the specific image we want,
1779 // try the default one instead
1780 if ( image
== NO_IMAGE
) image
= GetImage();
1785 // ---------------------------------------------------------------------------
1786 // wxTreeListMainWindow implementation
1787 // ---------------------------------------------------------------------------
1789 IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow
, wxScrolledWindow
)
1791 BEGIN_EVENT_TABLE(wxTreeListMainWindow
, wxScrolledWindow
)
1792 EVT_PAINT (wxTreeListMainWindow::OnPaint
)
1793 EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse
)
1794 EVT_CHAR (wxTreeListMainWindow::OnChar
)
1795 EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus
)
1796 EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus
)
1797 EVT_IDLE (wxTreeListMainWindow::OnIdle
)
1798 //? EVT_SIZE (wxTreeListMainWindow::OnSize)
1799 EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll
)
1803 // ---------------------------------------------------------------------------
1804 // construction/destruction
1805 // ---------------------------------------------------------------------------
1807 void wxTreeListMainWindow::Init()
1809 m_current
= m_key_current
= m_anchor
= (wxTreeListItem
*) NULL
;
1813 m_lineHeight
= LINEHEIGHT
;
1814 m_indent
= MININDENT
; // min. indent
1816 m_imgWidth
= 0, m_imgWidth2
= 0;
1817 m_imgHeight
= 0, m_imgHeight2
= 0;
1819 m_hilightBrush
= new wxBrush
1821 wxSystemSettings::GetSystemColour
1823 wxSYS_COLOUR_HIGHLIGHT
1828 m_hilightUnfocusedBrush
= new wxBrush
1830 wxSystemSettings::GetSystemColour
1832 wxSYS_COLOUR_BTNSHADOW
1837 m_imageListNormal
= m_imageListButtons
=
1838 m_imageListState
= (wxImageList
*) NULL
;
1839 m_ownsImageListNormal
= m_ownsImageListButtons
=
1840 m_ownsImageListState
= FALSE
;
1843 m_isDragging
= FALSE
;
1844 m_dropTarget
= m_oldSelection
= (wxTreeListItem
*)NULL
;
1846 m_renameTimer
= new wxTreeListRenameTimer( this );
1847 m_lastOnSame
= FALSE
;
1849 m_findTimer
= new wxTimer (this, -1);
1851 m_normalFont
= wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT
);
1852 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
1853 m_normalFont
.GetFamily(),
1854 m_normalFont
.GetStyle(),
1856 m_normalFont
.GetUnderlined());
1860 static const int HEADER_HEIGHT
= 23;
1862 bool wxTreeListMainWindow::Create(wxTreeListCtrl
*parent
,
1867 const wxValidator
&validator
,
1868 const wxString
& name
)
1871 if ( !(style
& wxTR_DONT_ADJUST_MAC
))
1874 wxGetOsVersion( &major
, &minor
);
1876 if (style
& wxTR_HAS_BUTTONS
) style
|= wxTR_TWIST_BUTTONS
;
1877 if (style
& wxTR_HAS_BUTTONS
) style
&= ~wxTR_HAS_BUTTONS
;
1878 style
&= ~wxTR_LINES_AT_ROOT
;
1879 style
|= wxTR_NO_LINES
;
1881 style
|= wxTR_ROW_LINES
;
1885 wxScrolledWindow::Create( parent
, id
, pos
, size
,
1886 style
|wxHSCROLL
|wxVSCROLL
, name
);
1888 #if wxUSE_VALIDATORS
1889 SetValidator( validator
);
1892 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1899 bdc
.SelectObject(bmp
);
1900 bdc
.SetPen(*wxGREY_PEN
);
1901 bdc
.DrawRectangle(-1, -1, 10, 10);
1902 for (i
= 0; i
< 8; i
++) {
1903 for (j
= 0; j
< 8; j
++) {
1904 if (!((i
+ j
) & 1)) {
1905 bdc
.DrawPoint(i
, j
);
1910 m_dottedPen
= wxPen(bmp
, 1);
1913 //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT ); // too slow under XFree86
1914 m_dottedPen
= wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK!
1924 wxTreeListMainWindow::~wxTreeListMainWindow()
1926 delete m_hilightBrush
;
1927 delete m_hilightUnfocusedBrush
;
1931 delete m_renameTimer
;
1933 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1934 if (m_ownsImageListState
) delete m_imageListState
;
1935 if (m_ownsImageListButtons
) delete m_imageListButtons
;
1940 //-----------------------------------------------------------------------------
1942 //-----------------------------------------------------------------------------
1944 size_t wxTreeListMainWindow::GetCount() const
1946 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
1949 void wxTreeListMainWindow::SetIndent(unsigned int indent
)
1955 void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing
)
1957 m_linespacing
= spacing
;
1959 CalculateLineHeight();
1962 size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId
& item
,
1965 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
1967 return ((wxTreeListItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
1970 void wxTreeListMainWindow::SetWindowStyle(const long styles
)
1972 // right now, just sets the styles. Eventually, we may
1973 // want to update the inherited styles, but right now
1974 // none of the parents has updatable styles
1975 m_windowStyle
= styles
;
1979 //-----------------------------------------------------------------------------
1980 // functions to work with tree items
1981 //-----------------------------------------------------------------------------
1983 int wxTreeListMainWindow::GetItemImage(const wxTreeItemId
& item
, size_t column
,
1984 wxTreeItemIcon which
) const
1986 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
1988 return ((wxTreeListItem
*) item
.m_pItem
)->GetImage(column
, which
);
1991 wxTreeItemData
*wxTreeListMainWindow::GetItemData(const wxTreeItemId
& item
)
1994 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
1996 return ((wxTreeListItem
*) item
.m_pItem
)->GetData();
1999 bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId
& item
) const
2001 wxCHECK_MSG(item
.IsOk(), FALSE
, wxT("invalid tree item"));
2002 return ((wxTreeListItem
*)item
.m_pItem
)->IsBold();
2005 wxColour
wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId
& item
)
2008 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2010 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2011 return pItem
->Attr().GetTextColour();
2014 wxColour
wxTreeListMainWindow::GetItemBackgroundColour(
2015 const wxTreeItemId
& item
) const
2017 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2019 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2020 return pItem
->Attr().GetBackgroundColour();
2023 wxFont
wxTreeListMainWindow::GetItemFont(const wxTreeItemId
& item
) const
2025 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
2027 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2028 return pItem
->Attr().GetFont();
2033 void wxTreeListMainWindow::SetItemImage(const wxTreeItemId
& item
,
2035 int image
, wxTreeItemIcon which
)
2037 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2039 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2040 pItem
->SetImage(column
, image
, which
);
2042 wxClientDC
dc(this);
2043 CalculateSize(pItem
, dc
);
2047 void wxTreeListMainWindow::SetItemData(const wxTreeItemId
& item
,
2048 wxTreeItemData
*data
)
2050 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2052 ((wxTreeListItem
*) item
.m_pItem
)->SetData(data
);
2055 void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId
& item
,
2058 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2060 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2061 pItem
->SetHasPlus(has
);
2065 void wxTreeListMainWindow::SetItemBold(const wxTreeItemId
& item
, bool bold
)
2067 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2069 // avoid redrawing the tree if no real change
2070 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2071 if ( pItem
->IsBold() != bold
)
2073 pItem
->SetBold(bold
);
2078 void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId
& item
,
2079 const wxColour
& col
)
2081 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2083 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2084 pItem
->Attr().SetTextColour(col
);
2088 void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId
& item
,
2089 const wxColour
& col
)
2091 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2093 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2094 pItem
->Attr().SetBackgroundColour(col
);
2098 void wxTreeListMainWindow::SetItemFont(const wxTreeItemId
& item
,
2101 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2103 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2104 pItem
->Attr().SetFont(font
);
2108 bool wxTreeListMainWindow::SetFont( const wxFont
&font
)
2110 wxScrolledWindow::SetFont(font
);
2112 m_normalFont
= font
;
2113 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
2114 m_normalFont
.GetFamily(),
2115 m_normalFont
.GetStyle(),
2117 m_normalFont
.GetUnderlined());
2123 // ----------------------------------------------------------------------------
2124 // item status inquiries
2125 // ----------------------------------------------------------------------------
2127 bool wxTreeListMainWindow::IsVisible(const wxTreeItemId
& item
) const
2129 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2131 // An item is only visible if it's not a descendant of a collapsed item
2132 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2133 wxTreeListItem
* parent
= pItem
->GetItemParent();
2136 if (!parent
->IsExpanded())
2138 parent
= parent
->GetItemParent();
2142 GetViewStart(& startX
, & startY
);
2144 wxSize clientSize
= GetClientSize();
2147 if (!GetBoundingRect(item
, rect
))
2149 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
2151 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
2153 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
2159 bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId
& item
) const
2161 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2163 // consider that the item does have children if it has the "+" button: it
2164 // might not have them (if it had never been expanded yet) but then it
2165 // could have them as well and it's better to err on this side rather than
2166 // disabling some operations which are restricted to the items with
2167 // children for an item which does have them
2168 return ((wxTreeListItem
*) item
.m_pItem
)->HasPlus();
2171 bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId
& item
) const
2173 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2175 return ((wxTreeListItem
*) item
.m_pItem
)->IsExpanded();
2178 bool wxTreeListMainWindow::IsSelected(const wxTreeItemId
& item
) const
2180 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2182 return ((wxTreeListItem
*) item
.m_pItem
)->IsSelected();
2185 bool wxTreeListMainWindow::IsBold(const wxTreeItemId
& item
) const
2187 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2189 return ((wxTreeListItem
*) item
.m_pItem
)->IsBold();
2192 // ----------------------------------------------------------------------------
2194 // ----------------------------------------------------------------------------
2196 wxTreeItemId
wxTreeListMainWindow::GetItemParent(const wxTreeItemId
& item
) const
2198 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2200 return ((wxTreeListItem
*) item
.m_pItem
)->GetItemParent();
2203 #if !wxCHECK_VERSION(2, 5, 0)
2204 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2207 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2208 wxTreeItemIdValue
& cookie
) const
2211 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2214 return GetNextChild(item
, cookie
);
2217 #if !wxCHECK_VERSION(2, 5, 0)
2218 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2221 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2222 wxTreeItemIdValue
& cookie
) const
2225 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2227 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2229 // it's ok to cast cookie to size_t, we never have indices big enough to
2230 // overflow "void *"
2231 size_t *pIndex
= (size_t *)&cookie
;
2232 if ( *pIndex
< children
.Count() )
2234 return children
.Item((*pIndex
)++);
2238 // there are no more of them
2239 return wxTreeItemId();
2243 #if !wxCHECK_VERSION(2, 5, 0)
2244 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2247 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2248 wxTreeItemIdValue
& cookie
) const
2251 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2253 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2255 // it's ok to cast cookie to size_t, we never have indices big enough to
2256 // overflow "void *"
2257 size_t *pIndex
= (size_t *)&cookie
;
2260 return children
.Item(--(*pIndex
));
2264 // there are no more of them
2265 return wxTreeItemId();
2269 wxTreeItemId
wxTreeListMainWindow::GetLastChild(const wxTreeItemId
& item
) const
2271 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2273 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2274 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
2277 wxTreeItemId
wxTreeListMainWindow::GetNextSibling(const wxTreeItemId
& item
) const
2279 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2281 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2282 wxTreeListItem
*parent
= i
->GetItemParent();
2283 if ( parent
== NULL
)
2285 // root item doesn't have any siblings
2286 return wxTreeItemId();
2289 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2290 int index
= siblings
.Index(i
);
2291 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2293 size_t n
= (size_t)(index
+ 1);
2294 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
2297 wxTreeItemId
wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId
& item
)
2300 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2302 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2303 wxTreeListItem
*parent
= i
->GetItemParent();
2304 if ( parent
== NULL
)
2306 // root item doesn't have any siblings
2307 return wxTreeItemId();
2310 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2311 int index
= siblings
.Index(i
);
2312 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2314 return index
== 0 ? wxTreeItemId()
2315 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
2318 // Only for internal use right now, but should probably be public
2319 wxTreeItemId
wxTreeListMainWindow::GetNext(const wxTreeItemId
& item
) const
2321 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2323 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2325 // First see if there are any children.
2326 wxArrayTreeListItems
& children
= i
->GetChildren();
2327 if (children
.GetCount() > 0)
2329 return children
.Item(0);
2333 // Try a sibling of this or ancestor instead
2334 wxTreeItemId p
= item
;
2335 wxTreeItemId toFind
;
2338 toFind
= GetNextSibling(p
);
2339 p
= GetItemParent(p
);
2340 } while (p
.IsOk() && !toFind
.IsOk());
2345 wxTreeItemId
wxTreeListMainWindow::GetFirstVisibleItem() const
2347 wxTreeItemId id
= GetRootItem();
2356 } while (id
.IsOk());
2358 return wxTreeItemId();
2361 wxTreeItemId
wxTreeListMainWindow::GetNextVisible(const wxTreeItemId
& item
)
2364 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2366 wxTreeItemId id
= item
;
2369 while (id
= GetNext(id
), id
.IsOk())
2375 return wxTreeItemId();
2378 wxTreeItemId
wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId
& item
)
2381 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2383 wxFAIL_MSG(wxT("not implemented"));
2385 return wxTreeItemId();
2388 // ----------------------------------------------------------------------------
2390 // ----------------------------------------------------------------------------
2392 wxTreeItemId
wxTreeListMainWindow::DoInsertItem(const wxTreeItemId
& parentId
,
2394 const wxString
& text
,
2395 int image
, int selImage
,
2396 wxTreeItemData
*data
)
2398 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2401 // should we give a warning here?
2402 return AddRoot(text
, image
, selImage
, data
);
2405 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2409 arr
.Alloc(GetColumnCount());
2410 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2411 arr
.Add(wxEmptyString
);
2413 arr
[m_main_column
] = text
;
2414 wxTreeListItem
*item
=
2415 new wxTreeListItem( this, parent
, arr
, image
, selImage
, data
);
2419 data
->SetId((long)item
);
2422 parent
->Insert( item
, previous
);
2427 wxTreeItemId
wxTreeListMainWindow::AddRoot(const wxString
& text
,
2428 int image
, int selImage
,
2429 wxTreeItemData
*data
)
2431 wxCHECK_MSG(!m_anchor
, wxTreeItemId(), wxT("tree can have only one root"));
2432 wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item"));
2434 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2438 arr
.Alloc(GetColumnCount());
2439 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2440 arr
.Add(wxEmptyString
);
2442 arr
[m_main_column
] = text
;
2443 m_anchor
= new wxTreeListItem( this, (wxTreeListItem
*)NULL
, arr
,
2444 image
, selImage
, data
);
2446 if (HasFlag(wxTR_HIDE_ROOT
))
2448 // if root is hidden, make sure we can navigate
2450 m_anchor
->SetHasPlus();
2456 data
->SetId((long)m_anchor
);
2459 if (!HasFlag(wxTR_MULTIPLE
))
2461 m_current
= m_key_current
= m_anchor
;
2462 m_current
->SetHilight( TRUE
);
2468 wxTreeItemId
wxTreeListMainWindow::PrependItem(const wxTreeItemId
& parent
,
2469 const wxString
& text
,
2470 int image
, int selImage
,
2471 wxTreeItemData
*data
)
2473 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
2476 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2477 const wxTreeItemId
& idPrevious
,
2478 const wxString
& text
,
2479 int image
, int selImage
,
2480 wxTreeItemData
*data
)
2482 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2485 // should we give a warning here?
2486 return AddRoot(text
, image
, selImage
, data
);
2489 int index
= parent
->GetChildren().Index((wxTreeListItem
*) idPrevious
.m_pItem
);
2490 wxASSERT_MSG( index
!= wxNOT_FOUND
,
2491 wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") );
2493 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
2496 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2498 const wxString
& text
,
2499 int image
, int selImage
,
2500 wxTreeItemData
*data
)
2502 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2505 // should we give a warning here?
2506 return AddRoot(text
, image
, selImage
, data
);
2509 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
2512 wxTreeItemId
wxTreeListMainWindow::AppendItem(const wxTreeItemId
& parentId
,
2513 const wxString
& text
,
2514 int image
, int selImage
,
2515 wxTreeItemData
*data
)
2517 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2520 // should we give a warning here?
2521 return AddRoot(text
, image
, selImage
, data
);
2524 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
2525 image
, selImage
, data
);
2528 void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem
*item
)
2530 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, m_owner
->GetId() );
2531 event
.SetItem((long) item
);
2532 event
.SetEventObject( /*this*/m_owner
);
2533 m_owner
->ProcessEvent( event
);
2536 void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId
& itemId
)
2538 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2540 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2541 item
->DeleteChildren(this);
2544 void wxTreeListMainWindow::Delete(const wxTreeItemId
& itemId
)
2546 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2548 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2550 // don't stay with invalid m_key_current or we will crash in
2551 // the next call to OnChar()
2552 bool changeKeyCurrent
= FALSE
;
2553 wxTreeListItem
*itemKey
= m_key_current
;
2556 if ( itemKey
== item
)
2558 // m_key_current is a descendant of the item being deleted
2559 changeKeyCurrent
= TRUE
;
2562 itemKey
= itemKey
->GetItemParent();
2565 wxTreeListItem
*parent
= item
->GetItemParent();
2568 parent
->GetChildren().Remove( item
); // remove by value
2571 if ( changeKeyCurrent
)
2573 // may be NULL or not
2574 m_key_current
= parent
;
2577 item
->DeleteChildren(this);
2578 SendDeleteEvent(item
);
2582 void wxTreeListMainWindow::DeleteAllItems()
2588 m_anchor
->DeleteChildren(this);
2595 void wxTreeListMainWindow::Expand(const wxTreeItemId
& itemId
)
2597 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2599 wxCHECK_RET( item
, _T("invalid item in wxTreeListMainWindow::Expand") );
2601 if ( !item
->HasPlus() )
2604 if ( item
->IsExpanded() )
2607 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, m_owner
->GetId() );
2608 event
.SetItem( (long) item
);
2609 event
.SetEventObject( /*this*/m_owner
);
2611 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2613 // cancelled by program
2618 CalculatePositions();
2620 RefreshSubtree(item
);
2622 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
2623 ProcessEvent( event
);
2626 void wxTreeListMainWindow::ExpandAll(const wxTreeItemId
& item
)
2629 if ( IsExpanded(item
) )
2631 #if !wxCHECK_VERSION(2, 5, 0)
2634 wxTreeItemIdValue cookie
;
2636 wxTreeItemId child
= GetFirstChild(item
, cookie
);
2637 while ( child
.IsOk() )
2641 child
= GetNextChild(item
, cookie
);
2646 void wxTreeListMainWindow::Collapse(const wxTreeItemId
& itemId
)
2648 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2650 if ( !item
->IsExpanded() )
2653 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, m_owner
->GetId() );
2654 event
.SetItem( (long) item
);
2655 event
.SetEventObject( /*this*/m_owner
);
2656 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2658 // cancelled by program
2664 #if 0 // TODO why should items be collapsed recursively?
2665 wxArrayTreeListItems
& children
= item
->GetChildren();
2666 size_t count
= children
.Count();
2667 for ( size_t n
= 0; n
< count
; n
++ )
2669 Collapse(children
[n
]);
2673 CalculatePositions();
2675 RefreshSubtree(item
);
2677 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
2678 ProcessEvent( event
);
2681 void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId
& item
)
2684 DeleteChildren(item
);
2687 void wxTreeListMainWindow::Toggle(const wxTreeItemId
& itemId
)
2689 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2691 if (item
->IsExpanded())
2697 void wxTreeListMainWindow::Unselect()
2701 m_current
->SetHilight( FALSE
);
2702 RefreshLine( m_current
);
2706 void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem
*item
)
2708 if (item
->IsSelected())
2710 item
->SetHilight(FALSE
);
2714 if (item
->HasChildren())
2716 wxArrayTreeListItems
& children
= item
->GetChildren();
2717 size_t count
= children
.Count();
2718 for ( size_t n
= 0; n
< count
; ++n
)
2720 UnselectAllChildren(children
[n
]);
2725 void wxTreeListMainWindow::UnselectAll()
2727 UnselectAllChildren((wxTreeListItem
*)GetRootItem().m_pItem
);
2730 // Recursive function !
2731 // To stop we must have crt_item<last_item
2733 // Tag all next children, when no more children,
2734 // Move to parent (not to tag)
2735 // Keep going... if we found last_item, we stop.
2736 bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2738 wxTreeListItem
*parent
= crt_item
->GetItemParent();
2740 if (parent
== NULL
) // This is root item
2741 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
2743 wxArrayTreeListItems
& children
= parent
->GetChildren();
2744 int index
= children
.Index(crt_item
);
2745 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2747 size_t count
= children
.Count();
2748 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
2750 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
2753 return TagNextChildren(parent
, last_item
, select
);
2756 bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2758 crt_item
->SetHilight(select
);
2759 RefreshLine(crt_item
);
2761 if (crt_item
==last_item
)
2764 if (crt_item
->HasChildren())
2766 wxArrayTreeListItems
& children
= crt_item
->GetChildren();
2767 size_t count
= children
.Count();
2768 for ( size_t n
= 0; n
< count
; ++n
)
2770 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
2778 void wxTreeListMainWindow::SelectItemRange(wxTreeListItem
*item1
, wxTreeListItem
*item2
)
2780 // item2 is not necessary after item1
2781 wxTreeListItem
*first
=NULL
, *last
=NULL
;
2783 // choice first' and 'last' between item1 and item2
2784 if (item1
->GetY()<item2
->GetY())
2795 bool select
= m_current
->IsSelected();
2797 if ( TagAllChildrenUntilLast(first
,last
,select
) )
2800 TagNextChildren(first
,last
,select
);
2803 void wxTreeListMainWindow::SelectItem(const wxTreeItemId
& itemId
,
2804 bool unselect_others
,
2805 bool extended_select
)
2807 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2809 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
2810 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2812 //wxCHECK_RET( ( (!unselect_others) && is_single),
2813 // wxT("this is a single selection tree") );
2815 // to keep going anyhow !!!
2818 if (item
->IsSelected())
2819 return; // nothing to do
2820 unselect_others
= TRUE
;
2821 extended_select
= FALSE
;
2823 else if ( unselect_others
&& item
->IsSelected() )
2825 // selection change if there is more than one item currently selected
2826 wxArrayTreeItemIds selected_items
;
2827 if ( GetSelections(selected_items
) == 1 )
2831 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2832 event
.SetItem( (long) item
);
2833 event
.SetOldItem( (long) m_current
);
2834 event
.SetEventObject( /*this*/m_owner
);
2835 // TODO : Here we don't send any selection mode yet !
2837 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2840 wxTreeItemId parent
= GetItemParent( itemId
);
2841 while (parent
.IsOk())
2843 if (!IsExpanded(parent
))
2846 parent
= GetItemParent( parent
);
2849 EnsureVisible( itemId
);
2852 if (unselect_others
)
2854 if (is_single
) Unselect(); // to speed up thing
2859 if (extended_select
)
2863 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
2866 // don't change the mark (m_current)
2867 SelectItemRange(m_current
, item
);
2871 bool select
=TRUE
; // the default
2873 // Check if we need to toggle hilight (ctrl mode)
2874 if (!unselect_others
)
2875 select
=!item
->IsSelected();
2877 m_current
= m_key_current
= item
;
2878 m_current
->SetHilight(select
);
2879 RefreshLine( m_current
);
2882 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2883 GetEventHandler()->ProcessEvent( event
);
2886 void wxTreeListMainWindow::SelectAll(bool extended_select
)
2888 wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE
, wxT("invalid tree style") );
2890 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2891 event
.SetItem( GetRootItem() );
2892 event
.SetOldItem( (long) m_current
);
2893 event
.SetEventObject( /*this*/m_owner
);
2894 // TODO : Here we don't send any selection mode yet !
2896 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2900 if (!extended_select
)
2908 #if !wxCHECK_VERSION(2, 5, 0)
2911 wxTreeItemIdValue cookie
= 0;
2913 wxTreeItemId root
= GetRootItem();
2914 wxTreeListItem
*first
= (wxTreeListItem
*)GetFirstChild (root
, cookie
).m_pItem
;
2915 wxTreeListItem
*last
= (wxTreeListItem
*)GetLastChild (GetRootItem()).m_pItem
;
2916 if (TagAllChildrenUntilLast (first
, last
, true)) return;
2917 TagNextChildren (first
, last
, true);
2919 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2920 GetEventHandler()->ProcessEvent( event
);
2923 void wxTreeListMainWindow::FillArray(wxTreeListItem
*item
,
2924 wxArrayTreeItemIds
&array
) const
2926 if ( item
->IsSelected() )
2927 array
.Add(wxTreeItemId(item
));
2929 if ( item
->HasChildren() )
2931 wxArrayTreeListItems
& children
= item
->GetChildren();
2932 size_t count
= children
.GetCount();
2933 for ( size_t n
= 0; n
< count
; ++n
)
2934 FillArray(children
[n
], array
);
2938 size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds
&array
) const
2941 wxTreeItemId idRoot
= GetRootItem();
2942 if ( idRoot
.IsOk() )
2944 FillArray((wxTreeListItem
*) idRoot
.m_pItem
, array
);
2946 //else: the tree is empty, so no selections
2948 return array
.Count();
2951 void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId
& item
)
2953 if (!item
.IsOk()) return;
2955 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2957 // first expand all parent branches
2958 wxTreeListItem
*parent
= gitem
->GetItemParent();
2962 parent
= parent
->GetItemParent();
2965 //if (parent) CalculatePositions();
2970 void wxTreeListMainWindow::ScrollTo(const wxTreeItemId
&item
)
2972 if (!item
.IsOk()) return;
2974 // We have to call this here because the label in
2975 // question might just have been added and no screen
2976 // update taken place.
2977 if (m_dirty
) wxYieldIfNeeded();
2979 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2981 // now scroll to the item
2982 int item_y
= gitem
->GetY();
2986 GetViewStart( &start_x
, &start_y
);
2987 start_y
*= PIXELS_PER_UNIT
;
2991 GetClientSize( &client_w
, &client_h
);
2993 if (item_y
< start_y
+3)
2998 m_anchor
->GetSize( x
, y
, this );
2999 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3000 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3001 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3002 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3003 // Item should appear at top
3004 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
3006 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
3011 m_anchor
->GetSize( x
, y
, this );
3012 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3013 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3014 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3015 item_y
+= PIXELS_PER_UNIT
+2;
3016 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3017 // Item should appear at bottom
3018 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
);
3022 // FIXME: tree sorting functions are not reentrant and not MT-safe!
3023 static wxTreeListMainWindow
*s_treeBeingSorted
= NULL
;
3025 static int LINKAGEMODE
tree_ctrl_compare_func(wxTreeListItem
**item1
,
3026 wxTreeListItem
**item2
)
3028 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") );
3030 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
3033 int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId
& item1
,
3034 const wxTreeItemId
& item2
)
3036 // ALB: delegate to m_owner, to let the user overrride the comparison
3037 //return wxStrcmp(GetItemText(item1), GetItemText(item2));
3038 return m_owner
->OnCompareItems(item1
, item2
);
3041 void wxTreeListMainWindow::SortChildren(const wxTreeItemId
& itemId
)
3043 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
3045 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
3047 wxCHECK_RET( !s_treeBeingSorted
,
3048 wxT("wxTreeListMainWindow::SortChildren is not reentrant") );
3050 wxArrayTreeListItems
& children
= item
->GetChildren();
3051 if ( children
.Count() > 1 )
3055 s_treeBeingSorted
= this;
3056 children
.Sort(tree_ctrl_compare_func
);
3057 s_treeBeingSorted
= NULL
;
3059 //else: don't make the tree dirty as nothing changed
3062 wxTreeItemId
wxTreeListMainWindow::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
) {
3063 #if !wxCHECK_VERSION(2, 5, 0)
3066 wxTreeItemIdValue cookie
= 0;
3068 wxTreeItemId next
= item
;
3069 if (!next
.IsOk()) next
= GetSelection();
3071 if (HasFlag(wxTR_HIDE_ROOT
)) {
3072 next
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3074 next
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3077 if (!next
.IsOk()) return item
;
3079 // start checking the next items
3081 while (next
.IsOk()) {
3082 itemText
= GetItemText (next
);
3083 if (flags
& wxTL_SEARCH_LEVEL
) {
3084 next
= GetNextSibling (next
);
3085 }else if (flags
& wxTL_SEARCH_FULL
) {
3086 wxTreeItemId n
= GetFirstChild (next
, cookie
);
3088 n
= GetNextSibling (next
);
3090 n
= GetNextSibling (GetItemParent (next
));
3092 }else{ // wxTL_SEARCH_VISIBLE
3093 next
= GetNextVisible (next
);
3095 if (!next
.IsOk()) break; // done
3096 if (flags
& wxTL_SEARCH_PARTIAL
) {
3097 itemText
= GetItemText (next
).Mid (0, str
.Length());
3099 itemText
= GetItemText (next
);
3101 if (flags
& wxTL_SEARCH_NOCASE
) {
3102 if (itemText
.CmpNoCase (str
) == 0) return next
;
3104 if (itemText
.Cmp (str
) == 0) return next
;
3110 wxImageList
*wxTreeListMainWindow::GetImageList() const
3112 return m_imageListNormal
;
3115 wxImageList
*wxTreeListMainWindow::GetButtonsImageList() const
3117 return m_imageListButtons
;
3120 wxImageList
*wxTreeListMainWindow::GetStateImageList() const
3122 return m_imageListState
;
3125 void wxTreeListMainWindow::CalculateLineHeight()
3127 wxClientDC
dc(this);
3128 dc
.SetFont( m_normalFont
);
3129 m_lineHeight
= (int)(dc
.GetCharHeight() + m_linespacing
);
3131 if ( m_imageListNormal
)
3133 // Calculate a m_lineHeight value from the normal Image sizes.
3134 // May be toggle off. Then wxTreeListMainWindow will spread when
3135 // necessary (which might look ugly).
3136 int n
= m_imageListNormal
->GetImageCount();
3137 for (int i
= 0; i
< n
; i
++)
3139 int width
= 0, height
= 0;
3140 m_imageListNormal
->GetSize(i
, width
, height
);
3141 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3145 if (m_imageListButtons
)
3147 // Calculate a m_lineHeight value from the Button image sizes.
3148 // May be toggle off. Then wxTreeListMainWindow will spread when
3149 // necessary (which might look ugly).
3150 int n
= m_imageListButtons
->GetImageCount();
3151 for (int i
= 0; i
< n
; i
++)
3153 int width
= 0, height
= 0;
3154 m_imageListButtons
->GetSize(i
, width
, height
);
3155 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3159 /*? FIXME: Don't get what this code is for... Adding a line space is already done!!!
3160 if (m_lineHeight < 30)
3161 m_lineHeight += 2; // at least 2 pixels
3163 m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing
3167 void wxTreeListMainWindow::SetImageList(wxImageList
*imageList
)
3169 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3170 m_imageListNormal
= imageList
;
3171 m_ownsImageListNormal
= FALSE
;
3173 CalculateLineHeight();
3176 void wxTreeListMainWindow::SetStateImageList(wxImageList
*imageList
)
3178 if (m_ownsImageListState
) delete m_imageListState
;
3179 m_imageListState
= imageList
;
3180 m_ownsImageListState
= FALSE
;
3183 void wxTreeListMainWindow::SetButtonsImageList(wxImageList
*imageList
)
3185 if (m_ownsImageListButtons
) delete m_imageListButtons
;
3186 m_imageListButtons
= imageList
;
3187 m_ownsImageListButtons
= FALSE
;
3189 CalculateLineHeight();
3192 void wxTreeListMainWindow::AssignImageList(wxImageList
*imageList
)
3194 SetImageList(imageList
);
3195 m_ownsImageListNormal
= TRUE
;
3198 void wxTreeListMainWindow::AssignStateImageList(wxImageList
*imageList
)
3200 SetStateImageList(imageList
);
3201 m_ownsImageListState
= TRUE
;
3204 void wxTreeListMainWindow::AssignButtonsImageList(wxImageList
*imageList
)
3206 SetButtonsImageList(imageList
);
3207 m_ownsImageListButtons
= TRUE
;
3210 // ----------------------------------------------------------------------------
3212 // ----------------------------------------------------------------------------
3214 void wxTreeListMainWindow::AdjustMyScrollbars()
3219 m_anchor
->GetSize( x
, y
, this );
3220 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3221 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3222 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3223 int y_pos
= GetScrollPos( wxVERTICAL
);
3224 x
= m_owner
->GetHeaderWindow()->GetWidth() + 2;
3225 if(x
< GetClientSize().GetWidth()) x_pos
= 0;
3226 //m_total_col_width + 2; // ALB
3227 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
,
3228 y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
3232 SetScrollbars( 0, 0, 0, 0 );
3236 int wxTreeListMainWindow::GetLineHeight(wxTreeListItem
*item
) const
3238 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
3239 return item
->GetHeight();
3241 return m_lineHeight
;
3244 void wxTreeListMainWindow::PaintItem(wxTreeListItem
*item
, wxDC
& dc
)
3246 wxTreeItemAttr
*attr
= item
->GetAttributes();
3247 if (attr
&& attr
->HasFont()) {
3248 dc
.SetFont(attr
->GetFont());
3249 }else if (item
->IsBold()) {
3250 dc
.SetFont(m_boldFont
);
3253 if (attr
&& attr
->HasTextColour()) {
3254 colText
= attr
->GetTextColour();
3256 colText
= GetForegroundColour();
3259 dc
.SetPen(*wxTRANSPARENT_PEN
);
3261 long text_w
= 0, text_h
= 0;
3263 dc
.GetTextExtent( item
->GetText(GetMainColumn()), &text_w
, &text_h
);
3265 int total_h
= GetLineHeight(item
);
3267 if (item
->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT
)) {
3268 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3269 dc
.SetPen(*wxBLACK_PEN
);
3270 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3273 if (attr
&& attr
->HasBackgroundColour()) {
3274 colBg
= attr
->GetBackgroundColour();
3276 colBg
= GetBackgroundColour();
3278 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
3281 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
3282 dc
.DrawRectangle(0, item
->GetY() + offset
,
3283 m_owner
->GetHeaderWindow()->GetWidth(), total_h
-offset
);
3285 dc
.SetBackgroundMode(wxTRANSPARENT
);
3286 int text_extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
3287 int img_extraH
= (total_h
> m_imgHeight
)? (total_h
-m_imgHeight
)/2: 0;
3289 for ( size_t i
= 0; i
< GetColumnCount(); ++i
) {
3290 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3291 int colwidth
= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
3295 if (i
== GetMainColumn()) {
3296 image
= item
->GetCurrentImage();
3297 if (item
->HasPlus()) {
3298 image_x
= item
->GetX() + (m_btnWidth
-m_btnWidth2
) + LINEATROOT
;
3300 image_x
= item
->GetX() - m_imgWidth2
;
3305 image
= item
->GetImage(i
);
3306 image_x
= x_colstart
+ MARGIN
;
3308 if (image
!= NO_IMAGE
) image_w
= m_imgWidth
+ MARGIN
;
3310 // honor text alignment
3311 wxString text
= item
->GetText(i
);
3312 switch ( m_owner
->GetHeaderWindow()->GetColumn(i
).GetAlignment() ) {
3313 case wxTL_ALIGN_LEFT
:
3314 // already left aligned
3316 case wxTL_ALIGN_RIGHT
:
3317 dc
.GetTextExtent(text
, &text_w
, NULL
);
3318 image_x
= x_colstart
+ colwidth
- (image_w
+ text_w
+ MARGIN
);
3320 case wxTL_ALIGN_CENTER
:
3321 dc
.GetTextExtent(text
, &text_w
, NULL
);
3322 int w
= colwidth
- image_w
- text_w
;
3323 image_x
= x_colstart
+ (w
> 0)? w
: 0;
3326 int text_x
= image_x
+ image_w
;
3328 if (item
->IsSelected() && (i
==GetMainColumn()) && !HasFlag(wxTR_FULL_ROW_HIGHLIGHT
))
3330 dc
.SetPen(*wxBLACK_PEN
);
3331 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3332 int offset
= HasFlag (wxTR_ROW_LINES
) ? 1 : 0;
3333 int width
= wxMin(text_w
+2, colwidth
- text_x
- x_colstart
);
3334 dc
.DrawRectangle(text_x
-1, item
->GetY() + offset
, width
, total_h
-offset
);
3335 dc
.SetBackgroundMode(wxTRANSPARENT
);
3336 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
3338 dc
.SetTextForeground(colText
);
3341 wxDCClipper
clipper (dc
, x_colstart
, item
->GetY(), colwidth
, total_h
);
3342 if (image
!= NO_IMAGE
)
3344 int image_y
= item
->GetY() + img_extraH
;
3345 m_imageListNormal
->Draw ( image
, dc
, image_x
, image_y
,
3346 wxIMAGELIST_DRAW_TRANSPARENT
);
3348 int text_y
= item
->GetY() + text_extraH
;
3349 dc
.DrawText ( text
, (wxCoord
)text_x
, (wxCoord
)text_y
);
3351 x_colstart
+= colwidth
;
3354 // restore normal font
3355 dc
.SetFont( m_normalFont
);
3358 // Now y stands for the top of the item, whereas it used to stand for middle !
3359 void wxTreeListMainWindow::PaintLevel (wxTreeListItem
*item
, wxDC
&dc
,
3360 int level
, int &y
, int x_colstart
)
3362 // Handle hide root (only level 0)
3363 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) {
3364 // always expand hidden root
3365 wxArrayTreeListItems
& children
= item
->GetChildren();
3367 for (n
= 0; n
< (int)children
.Count(); n
++) {
3368 PaintLevel (children
[n
], dc
, 1, y
, x_colstart
);
3370 // end after expanding root
3374 // calculate position of vertical lines
3375 int x
= x_colstart
+ MARGIN
; // start of column
3376 if (HasFlag (wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
3378 x
+= m_btnWidth2
; // middle of button
3380 if (m_imgWidth
> 0) x
+= m_imgWidth2
; // middle of image
3382 if (!HasFlag (wxTR_HIDE_ROOT
)) {
3383 x
+= m_indent
* level
; // indent according to level
3385 if (level
> 0) x
+= m_indent
* (level
-1); // but not level 1
3388 // handle column text
3392 int h
= GetLineHeight(item
);
3394 int y_mid
= y_top
+ (h
/2);
3397 int exposed_x
= dc
.LogicalToDeviceX(0);
3398 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
3400 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
3403 PaintItem(item
, dc
);
3405 if (HasFlag(wxTR_ROW_LINES
))
3407 //dc.DestroyClippingRegion();
3408 int total_width
= m_owner
->GetHeaderWindow()->GetWidth();
3409 // if the background colour is white, choose a
3410 // contrasting color for the lines
3411 dc
.SetPen (*((GetBackgroundColour() == *wxWHITE
)?
3412 wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
3413 dc
.DrawLine(0, y_top
, total_width
, y_top
);
3414 dc
.DrawLine(0, y
, total_width
, y
);
3417 // restore DC objects
3418 dc
.SetBrush(*wxWHITE_BRUSH
);
3419 dc
.SetPen(m_dottedPen
);
3421 if (((level
== 0) || ((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) &&
3422 HasFlag(wxTR_LINES_AT_ROOT
) && !HasFlag(wxTR_NO_LINES
)) {
3423 int rootPos
= x_colstart
+ MARGIN
;
3424 dc
.DrawLine (rootPos
, y_mid
, rootPos
+LINEATROOT
, y_mid
);
3427 size_t clip_width
= m_owner
->GetHeaderWindow()->
3428 GetColumn(m_main_column
).GetWidth();
3430 if (item
->HasPlus() && HasButtons()) // should the item show a button?
3432 // clip to the column width
3433 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3435 if (!HasFlag(wxTR_NO_LINES
))
3438 dc
.DrawLine(x
- m_indent
, y_mid
, x
- m_btnWidth2
, y_mid
);
3439 else if (HasFlag(wxTR_LINES_AT_ROOT
))
3440 dc
.DrawLine(m_btnWidth2
-2, y_mid
,
3441 x
- m_btnWidth2
, y_mid
);
3442 dc
.DrawLine(x
+ m_btnWidth2
, y_mid
, x
/*+ m_spacing*/, y_mid
);
3445 if (m_imageListButtons
!= NULL
)
3447 // draw the image button here
3448 int image
= wxTreeItemIcon_Normal
;
3449 if (item
->IsExpanded()) image
= wxTreeItemIcon_Expanded
;
3450 if (item
->IsSelected())
3451 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
3452 int xx
= x
+ m_btnWidth2
;
3453 int yy
= y_mid
- m_btnHeight2
;
3454 dc
.SetClippingRegion(xx
, yy
, m_btnWidth
, m_btnHeight
);
3455 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
3456 wxIMAGELIST_DRAW_TRANSPARENT
);
3457 dc
.DestroyClippingRegion();
3459 else if (HasFlag(wxTR_TWIST_BUTTONS
))
3461 // draw the twisty button here
3462 dc
.SetPen(*wxBLACK_PEN
);
3463 dc
.SetBrush(*m_hilightBrush
);
3467 if (item
->IsExpanded())
3469 button
[0].x
= x
- (m_btnWidth2
+1);
3470 button
[0].y
= y_mid
- (m_btnHeight
/3);
3471 button
[1].x
= x
+ (m_btnWidth2
+1);
3472 button
[1].y
= button
[0].y
;
3474 button
[2].y
= button
[0].y
+ (m_btnHeight2
+1);
3478 button
[0].x
= x
- (m_btnWidth
/3);
3479 button
[0].y
= y_mid
- (m_btnHeight2
+1);
3480 button
[1].x
= button
[0].x
;
3481 button
[1].y
= y_mid
+ (m_btnHeight2
+1);
3482 button
[2].x
= button
[0].x
+ (m_btnWidth2
+1);
3483 button
[2].y
= y_mid
;
3485 dc
.DrawPolygon(3, button
);
3487 dc
.SetPen(m_dottedPen
);
3489 else // if (HasFlag(wxTR_HAS_BUTTONS))
3491 // draw the plus sign here
3492 dc
.SetPen(*wxGREY_PEN
);
3493 dc
.SetBrush(*wxWHITE_BRUSH
);
3494 dc
.DrawRectangle (x
-m_btnWidth2
, y_mid
-m_btnHeight2
,
3495 m_btnWidth
, m_btnHeight
);
3496 dc
.SetPen(*wxBLACK_PEN
);
3497 dc
.DrawLine (x
-(m_btnWidth2
-3), y_mid
,
3498 x
+(m_btnWidth2
-2), y_mid
);
3499 if (!item
->IsExpanded())
3500 dc
.DrawLine (x
, y_mid
-(m_btnHeight2
-2),
3501 x
, y_mid
+(m_btnHeight2
-1));
3502 dc
.SetPen(m_dottedPen
);
3505 if (!HasFlag(wxTR_NO_LINES
)) {
3506 if (!(level
== 0) && !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3507 if (m_imgWidth
> 0) {
3508 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_indent
-m_imgWidth2
, y_mid
);
3510 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_btnWidth2
+LINEATROOT
-MARGIN
, y_mid
);
3515 else if (!HasFlag(wxTR_NO_LINES
)) // no button; maybe a line?
3517 // clip to the column width
3518 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3520 // draw the horizontal line here
3521 if (!(level
== 0) && !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3522 int x2
= x
- m_indent
;
3523 if (m_imgWidth
> 0) {
3524 dc
.DrawLine(x2
, y_mid
, x2
+m_indent
-m_imgWidth2
, y_mid
);
3526 dc
.DrawLine(x2
, y_mid
, x2
+m_btnWidth2
+LINEATROOT
+MARGIN
, y_mid
);
3532 // restore DC objects
3533 dc
.SetBrush(*wxWHITE_BRUSH
);
3534 dc
.SetPen(m_dottedPen
);
3535 dc
.SetTextForeground(*wxBLACK
);
3537 if (item
->IsExpanded())
3539 wxArrayTreeListItems
& children
= item
->GetChildren();
3540 int count
= children
.Count();
3543 // paint sublevel items first
3544 for (n
=0; n
<count
; ++n
) {
3546 PaintLevel(children
[n
], dc
, level
+1, y
, x_colstart
);
3549 // then draw the connecting lines
3550 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
3552 // clip to the column width
3553 size_t clip_width
= m_owner
->GetHeaderWindow()->GetColumn(m_main_column
).GetWidth();
3554 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3556 // draw line down to last child
3557 oldY
+= GetLineHeight(children
[n
-1]) >> 1;
3558 if (HasButtons()) y_mid
+= 5;
3559 dc
.DrawLine(x
, y_mid
, x
, oldY
);
3564 void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem
*item
)
3568 if ( item
->HasPlus() )
3570 // it's a folder, indicate it by a border
3575 // draw a line under the drop target because the item will be
3577 DrawLine(item
, TRUE
/* below */);
3580 SetCursor(wxCURSOR_BULLSEYE
);
3585 SetCursor(wxCURSOR_NO_ENTRY
);
3589 void wxTreeListMainWindow::DrawBorder(const wxTreeItemId
&item
)
3591 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3593 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3595 wxClientDC
dc(this);
3597 dc
.SetLogicalFunction(wxINVERT
);
3598 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3600 int w
= i
->GetWidth() + 2;
3601 int h
= GetLineHeight(i
) + 2;
3603 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
3606 void wxTreeListMainWindow::DrawLine(const wxTreeItemId
&item
, bool below
)
3608 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3610 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3612 wxClientDC
dc(this);
3614 dc
.SetLogicalFunction(wxINVERT
);
3620 y
+= GetLineHeight(i
) - 1;
3623 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
3626 // ----------------------------------------------------------------------------
3627 // wxWindows callbacks
3628 // ----------------------------------------------------------------------------
3630 void wxTreeListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3636 if(!GetColumnCount()) return; // ALB
3641 // calculate button size
3642 m_btnWidth
= 0, m_btnWidth2
= 0;
3643 m_btnHeight
= 0, m_btnHeight2
= 0;
3644 if (m_imageListButtons
) {
3645 m_imageListButtons
->GetSize (0, m_btnWidth
, m_btnHeight
);
3646 }else if (HasButtons()) {
3647 m_btnWidth
= BTNWIDTH
;
3648 m_btnHeight
= BTNHEIGHT
;
3650 m_btnWidth2
= m_btnWidth
/2;
3651 m_btnHeight2
= m_btnHeight
/2;
3653 // calculate image size
3654 m_imgWidth
= 0, m_imgWidth2
= 0;
3655 m_imgHeight
= 0, m_imgHeight2
= 0;
3656 if (m_imageListNormal
) {
3657 m_imageListNormal
->GetSize (0, m_imgWidth
, m_imgHeight
);
3658 m_imgWidth
+= 4; //? ToDo: Why + 4?
3660 m_imgWidth2
= m_imgWidth
/2;
3661 m_imgHeight2
= m_imgHeight
/2;
3663 // calculate indent size
3664 int btnIndent
= HasButtons()? m_btnWidth
+ LINEATROOT
: 0;
3665 m_indent
= wxMax (MININDENT
, wxMax (m_imgWidth
, btnIndent
)) + MARGIN
;
3667 // set default values
3668 dc
.SetFont( m_normalFont
);
3669 dc
.SetPen( m_dottedPen
);
3671 // this is now done dynamically
3672 //if(GetImageList() == NULL)
3673 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3675 // calculate column start and paint
3678 for (i
= 0; i
< (int)GetMainColumn(); ++i
) {
3679 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3680 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth (i
);
3683 PaintLevel ( m_anchor
, dc
, 0, y
, x_colstart
);
3686 void wxTreeListMainWindow::OnSetFocus( wxFocusEvent
&event
)
3695 void wxTreeListMainWindow::OnKillFocus( wxFocusEvent
&event
)
3704 void wxTreeListMainWindow::OnChar( wxKeyEvent
&event
)
3706 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, m_owner
->GetId() );
3707 te
.SetKeyEvent( event
);
3708 te
.SetEventObject( /*this*/m_owner
);
3709 if ( m_owner
->GetEventHandler()->ProcessEvent( te
) )
3711 // intercepted by the user code
3717 if (HasFlag(wxTR_HIDE_ROOT
)) {
3718 #if !wxCHECK_VERSION(2, 5, 0)
3721 wxTreeItemIdValue cookie
= 0;
3723 m_current
= m_key_current
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3727 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3731 // how should the selection work for this event?
3732 bool is_multiple
, extended_select
, unselect_others
;
3733 EventFlagsToSelType(GetWindowStyleFlag(),
3735 event
.ControlDown(),
3736 is_multiple
, extended_select
, unselect_others
);
3738 // + : Expand (not on Win32)
3739 // - : Collaspe (not on Win32)
3740 // * : Expand all/Collapse all
3741 // ' ' | return : activate
3742 // up : go up (not last children!)
3744 // left : go to parent (or collapse on Win32)
3745 // right : open if parent and go next (or expand on Win32)
3746 // home : go to root
3747 // end : go to last item without opening parents
3748 switch (event
.GetKeyCode())
3750 #ifndef __WXMSW__ // mimic the standard win32 tree ctrl
3753 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3762 if ( !IsExpanded(m_current
) )
3765 ExpandAll (m_current
);
3768 //else: fall through to Collapse() it
3770 #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour
3773 if (IsExpanded(m_current
))
3775 Collapse (m_current
);
3783 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
3785 event
.SetItem( (long) m_current
);
3786 event
.SetEventObject( /*this*/m_owner
);
3787 m_owner
->GetEventHandler()->ProcessEvent( event
);
3791 // backspace goes to the parent, sends "root" activation
3794 wxTreeItemId prev
= GetItemParent( m_current
);
3795 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3797 // don't go to root if it is hidden
3798 prev
= GetPrevSibling( m_current
);
3802 SelectItem( prev
, unselect_others
, extended_select
);
3803 EnsureVisible( prev
);
3808 // up goes to the previous sibling or to the last
3809 // of its children if it's expanded
3812 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
3815 prev
= GetItemParent( m_key_current
);
3816 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3818 break; // don't go to root if it is hidden
3822 #if !wxCHECK_VERSION(2, 5, 0)
3825 wxTreeItemIdValue cookie
= 0;
3827 wxTreeItemId current
= m_key_current
;
3828 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
3829 if (current
== GetFirstChild( prev
, cookie
))
3831 // otherwise we return to where we came from
3832 SelectItem( prev
, unselect_others
, extended_select
);
3833 m_key_current
= (wxTreeListItem
*) prev
.m_pItem
;
3834 EnsureVisible( prev
);
3841 while ( IsExpanded(prev
) && HasChildren(prev
) )
3843 wxTreeItemId child
= GetLastChild(prev
);
3851 SelectItem( prev
, unselect_others
, extended_select
);
3852 m_key_current
=(wxTreeListItem
*) prev
.m_pItem
;
3853 EnsureVisible( prev
);
3858 // left arrow goes to the parent
3860 if (IsExpanded(m_current
))
3862 Collapse(m_current
);
3866 wxTreeItemId prev
= GetItemParent( m_current
);
3867 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3869 // don't go to root if it is hidden
3870 prev
= GetPrevSibling( m_current
);
3874 SelectItem( prev
, unselect_others
, extended_select
);
3875 EnsureVisible( prev
);
3881 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl
3882 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3889 // this works the same as the down arrow except that we
3890 // also expand the item if it wasn't expanded yet
3896 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
3898 #if !wxCHECK_VERSION(2, 5, 0)
3901 wxTreeItemIdValue cookie
= 0;
3903 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
3905 SelectItem( child
, unselect_others
, extended_select
);
3906 m_key_current
=(wxTreeListItem
*) child
.m_pItem
;
3907 EnsureVisible( child
);
3911 wxTreeItemId next
= GetNextSibling( m_key_current
);
3914 wxTreeItemId current
= m_key_current
;
3915 while (current
&& !next
)
3917 current
= GetItemParent( current
);
3918 if (current
) next
= GetNextSibling( current
);
3923 SelectItem( next
, unselect_others
, extended_select
);
3924 m_key_current
=(wxTreeListItem
*) next
.m_pItem
;
3925 EnsureVisible( next
);
3930 // <End> selects the last visible tree item
3933 wxTreeItemId last
= GetRootItem();
3935 while ( last
.IsOk() && IsExpanded(last
) )
3937 wxTreeItemId lastChild
= GetLastChild(last
);
3939 // it may happen if the item was expanded but then all of
3940 // its children have been deleted - so IsExpanded() returned
3941 // TRUE, but GetLastChild() returned invalid item
3950 SelectItem( last
, unselect_others
, extended_select
);
3951 EnsureVisible( last
);
3956 // <Home> selects the root item
3959 wxTreeItemId prev
= GetRootItem();
3961 if (HasFlag(wxTR_HIDE_ROOT
))
3963 #if !wxCHECK_VERSION(2, 5, 0)
3966 wxTreeItemIdValue cookie
= 0;
3968 prev
= GetFirstChild(prev
, cookie
);
3971 SelectItem( prev
, unselect_others
, extended_select
);
3972 EnsureVisible( prev
);
3977 if (event
.m_keyCode
>= (int)' ') {
3978 if (!m_findTimer
->IsRunning()) m_findStr
.Clear();
3979 m_findStr
.Append (event
.m_keyCode
);
3980 m_findTimer
->Start (500, wxTIMER_ONE_SHOT
);
3981 wxTreeItemId dummy
= (wxTreeItemId
*)NULL
;
3982 wxTreeItemId item
= FindItem (dummy
, m_findStr
, wxTL_SEARCH_VISIBLE
|
3983 wxTL_SEARCH_PARTIAL
|
3984 wxTL_SEARCH_NOCASE
);
3986 EnsureVisible (item
);
3994 wxTreeItemId
wxTreeListMainWindow::HitTest(const wxPoint
& point
, int& flags
,
3997 // JACS: removed wxYieldIfNeeded() because it can cause the window
3998 // to be deleted from under us if a close window event is pending
4004 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
4005 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
4006 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
4007 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
4008 if (flags
) return wxTreeItemId();
4010 if (m_anchor
== NULL
)
4012 flags
= wxTREE_HITTEST_NOWHERE
;
4013 return wxTreeItemId();
4016 wxTreeListItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
4017 this, flags
, column
, 0);
4020 flags
= wxTREE_HITTEST_NOWHERE
;
4021 return wxTreeItemId();
4026 // get the bounding rectangle of the item (or of its label only)
4027 bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId
& item
,
4029 bool WXUNUSED(textOnly
)) const
4031 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") );
4033 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
4036 GetViewStart(& startX
, & startY
);
4038 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
4039 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
4040 rect
.width
= i
->GetWidth();
4041 //rect.height = i->GetHeight();
4042 rect
.height
= GetLineHeight(i
);
4049 void wxTreeListMainWindow::Edit( const wxTreeItemId
& item
)
4051 if (!item
.IsOk()) return;
4053 m_currentEdit
= (wxTreeListItem
*) item
.m_pItem
;
4055 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, m_owner
->GetId() );
4056 te
.SetItem( (long) m_currentEdit
);
4057 te
.SetEventObject( /*this*/m_owner
);
4058 m_owner
->GetEventHandler()->ProcessEvent( te
);
4060 if (!te
.IsAllowed()) return;
4062 // We have to call this here because the label in
4063 // question might just have been added and no screen
4064 // update taken place.
4065 if (m_dirty
) wxYieldIfNeeded();
4067 wxString s
= m_currentEdit
->GetText(/*ALB*/m_main_column
);
4068 int x
= m_currentEdit
->GetX() + m_imgWidth2
;
4069 int y
= m_currentEdit
->GetY();
4070 int w
= wxMin (m_currentEdit
->GetWidth(),
4071 m_owner
->GetHeaderWindow()->GetWidth()) - m_imgWidth2
;
4072 int h
= m_currentEdit
->GetHeight() + 2;
4073 wxClientDC
dc(this);
4075 x
= dc
.LogicalToDeviceX( x
);
4076 y
= dc
.LogicalToDeviceY( y
);
4078 wxTreeListTextCtrl
*text
= new wxTreeListTextCtrl(this, -1,
4088 void wxTreeListMainWindow::OnRenameTimer()
4093 void wxTreeListMainWindow::OnRenameAccept()
4095 // TODO if the validator fails this causes a crash
4096 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, m_owner
->GetId() );
4097 le
.SetItem( (long) m_currentEdit
);
4098 le
.SetEventObject( /*this*/m_owner
);
4099 le
.SetLabel( m_renameRes
);
4100 m_owner
->GetEventHandler()->ProcessEvent( le
);
4102 if (!le
.IsAllowed()) return;
4104 SetItemText( m_currentEdit
, m_renameRes
);
4107 void wxTreeListMainWindow::OnMouse( wxMouseEvent
&event
)
4109 if ( !m_anchor
) return;
4111 // we process left mouse up event (enables in-place edit), right down
4112 // (pass to the user code), left dbl click (activate item) and
4113 // dragging/moving events for items drag-and-drop
4114 if ( !(event
.LeftDown() ||
4116 event
.RightDown() ||
4117 event
.LeftDClick() ||
4119 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
4125 if ( event
.LeftDown() )
4128 wxClientDC
dc(this);
4130 wxCoord x
= dc
.DeviceToLogicalX( event
.GetX() );
4131 wxCoord y
= dc
.DeviceToLogicalY( event
.GetY() );
4134 wxTreeListItem
*item
= m_anchor
->HitTest(wxPoint(x
,y
), this, flags
, 0);
4136 if ( event
.Dragging() && !m_isDragging
)
4138 if (m_dragCount
== 0)
4139 m_dragStart
= wxPoint(x
,y
);
4143 if (m_dragCount
!= 3)
4145 // wait until user drags a bit further...
4149 wxEventType command
= event
.RightIsDown()
4150 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
4151 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
4153 wxTreeEvent
nevent( command
,/*ALB*/ m_owner
->GetId() );
4154 nevent
.SetItem( (long) m_current
);
4155 nevent
.SetEventObject(/*this*/m_owner
); // ALB
4157 // by default the dragging is not supported, the user code must
4158 // explicitly allow the event for it to take place
4161 if ( m_owner
->GetEventHandler()->ProcessEvent(nevent
) &&
4162 nevent
.IsAllowed() )
4164 // we're going to drag this item
4165 m_isDragging
= TRUE
;
4167 // remember the old cursor because we will change it while
4169 m_oldCursor
= m_cursor
;
4171 // in a single selection control, hide the selection temporarily
4172 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
4174 m_oldSelection
= (wxTreeListItem
*) GetSelection().m_pItem
;
4176 if ( m_oldSelection
)
4178 m_oldSelection
->SetHilight(FALSE
);
4179 RefreshLine(m_oldSelection
);
4186 else if ( event
.Moving() )
4188 if ( item
!= m_dropTarget
)
4190 // unhighlight the previous drop target
4191 DrawDropEffect(m_dropTarget
);
4193 m_dropTarget
= item
;
4195 // highlight the current drop target if any
4196 DrawDropEffect(m_dropTarget
);
4201 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
4203 // erase the highlighting
4204 DrawDropEffect(m_dropTarget
);
4206 if ( m_oldSelection
)
4208 m_oldSelection
->SetHilight(TRUE
);
4209 RefreshLine(m_oldSelection
);
4210 m_oldSelection
= (wxTreeListItem
*)NULL
;
4213 // generate the drag end event
4214 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
,/*ALB*/m_owner
->GetId());
4216 event
.SetItem( (long) item
);
4217 event
.SetPoint( wxPoint(x
, y
) );
4218 event
.SetEventObject(/*this*/m_owner
);
4220 (void)m_owner
->GetEventHandler()->ProcessEvent(event
);
4222 m_isDragging
= FALSE
;
4223 m_dropTarget
= (wxTreeListItem
*)NULL
;
4227 SetCursor(m_oldCursor
);
4233 // here we process only the messages which happen on tree items
4237 if ( item
== NULL
) return; /* we hit the blank area */
4239 if ( event
.RightDown() )
4242 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
,
4244 nevent
.SetItem( (long) item
);
4246 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4247 nevent
.SetPoint( wxPoint(nx
, ny
));
4248 nevent
.SetEventObject(/*this*/m_owner
);
4249 m_owner
->GetEventHandler()->ProcessEvent(nevent
);
4251 else if ( event
.LeftUp() )
4255 if ( ( item
== m_current
) &&
4256 ( flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
4257 HasFlag(wxTR_EDIT_LABELS
) )
4259 if ( m_renameTimer
->IsRunning() )
4260 m_renameTimer
->Stop();
4262 m_renameTimer
->Start( 100, TRUE
);
4265 m_lastOnSame
= FALSE
;
4268 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
4270 if ( event
.LeftDown() )
4273 m_lastOnSame
= item
== m_current
;
4276 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
4277 ((flags
& wxTREE_HITTEST_ONITEMICON
)) &&
4278 !HasButtons() && item
->HasPlus())
4280 // only toggle the item for a single click, double click on
4281 // the button doesn't do anything (it toggles the item twice)
4282 if ( event
.LeftDown() )
4287 // don't select the item if the button was clicked
4291 // how should the selection work for this event?
4292 bool is_multiple
, extended_select
, unselect_others
;
4293 EventFlagsToSelType(GetWindowStyleFlag(),
4295 event
.ControlDown(),
4296 is_multiple
, extended_select
, unselect_others
);
4298 SelectItem (item
, unselect_others
, extended_select
);
4300 // For some reason, Windows isn't recognizing a left double-click,
4301 // so we need to simulate it here. Allow 200 milliseconds for now.
4302 if ( event
.LeftDClick() )
4304 // double clicking should not start editing the item label
4305 m_renameTimer
->Stop();
4306 m_lastOnSame
= FALSE
;
4308 // send activate event first
4309 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
4311 nevent
.SetItem( (long) item
);
4313 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4314 nevent
.SetPoint( wxPoint(nx
, ny
) );
4315 nevent
.SetEventObject( /*this*/m_owner
);
4316 if ( !m_owner
->GetEventHandler()->ProcessEvent( nevent
) )
4318 // if the user code didn't process the activate event,
4319 // handle it ourselves by toggling the item when it is
4321 if ( item
->HasPlus() )
4331 void wxTreeListMainWindow::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
4333 /* after all changes have been done to the tree control,
4334 * we actually redraw the tree when everything is over */
4336 if (!m_dirty
) return;
4340 CalculatePositions();
4342 AdjustMyScrollbars();
4345 void wxTreeListMainWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
4348 // GetClientSize(&w, &h);
4349 // m_header_win->SetSize(0, 0, w, HEADER_HEIGHT);
4352 void wxTreeListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4355 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4356 wxScrolledWindow::OnScroll(event
);
4358 HandleOnScroll( event
);
4361 if(event
.GetOrientation() == wxHORIZONTAL
)
4363 m_owner
->GetHeaderWindow()->Refresh();
4364 m_owner
->GetHeaderWindow()->Update();
4369 void wxTreeListMainWindow::CalculateSize( wxTreeListItem
*item
, wxDC
&dc
)
4375 dc
.SetFont(m_boldFont
);
4377 dc
.GetTextExtent( item
->GetText(/*ALB*/m_main_column
), &text_w
, &text_h
);
4380 // restore normal font
4381 dc
.SetFont( m_normalFont
);
4383 int total_h
= (m_imgHeight
> text_h
) ? m_imgHeight
: text_h
;
4385 item
->SetHeight(total_h
);
4386 if (total_h
>m_lineHeight
)
4387 m_lineHeight
=total_h
;
4389 item
->SetWidth(m_imgWidth
+ text_w
+2);
4392 // -----------------------------------------------------------------------------
4393 // for developper : y is now the top of the level
4394 // not the middle of it !
4395 void wxTreeListMainWindow::CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
,
4396 int level
, int &y
, int x_colstart
)
4398 // calculate position of vertical lines
4399 int x
= x_colstart
+ MARGIN
; // start of column
4400 if (HasFlag(wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
4401 if (HasButtons()) x
+= m_btnWidth2
; // space for buttons etc.
4402 if (!HasFlag(wxTR_HIDE_ROOT
)) x
+= m_indent
; // indent root as well
4403 x
+= m_indent
* level
; // indent according to level
4405 // a hidden root is not evaluated, but its children are always
4406 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) goto Recurse
;
4408 CalculateSize( item
, dc
);
4413 y
+= GetLineHeight(item
);
4415 // we don't need to calculate collapsed branches
4416 if ( !item
->IsExpanded() ) return;
4419 wxArrayTreeListItems
& children
= item
->GetChildren();
4420 size_t n
, count
= children
.Count();
4422 for (n
= 0; n
< count
; ++n
)
4423 CalculateLevel( children
[n
], dc
, level
, y
, x_colstart
); // recurse
4426 void wxTreeListMainWindow::CalculatePositions()
4428 if ( !m_anchor
) return;
4430 wxClientDC
dc(this);
4433 dc
.SetFont( m_normalFont
);
4435 dc
.SetPen( m_dottedPen
);
4436 //if(GetImageList() == NULL)
4437 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
4441 for(size_t i
= 0; i
< GetMainColumn(); ++i
) {
4442 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
4443 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
4445 CalculateLevel( m_anchor
, dc
, 0, y
, x_colstart
); // start recursion
4448 void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem
*item
)
4450 if (m_dirty
) return;
4452 wxClientDC
dc(this);
4457 GetVirtualSize( &cw
, &ch
);
4460 rect
.x
= dc
.LogicalToDeviceX( 0 );
4462 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() - 2 );
4465 Refresh( TRUE
, &rect
);
4467 AdjustMyScrollbars();
4470 void wxTreeListMainWindow::RefreshLine( wxTreeListItem
*item
)
4472 if (m_dirty
) return;
4474 wxClientDC
dc(this);
4479 GetVirtualSize( &cw
, &ch
);
4482 rect
.x
= dc
.LogicalToDeviceX( 0 );
4483 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
4485 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
4487 Refresh( TRUE
, &rect
);
4490 void wxTreeListMainWindow::RefreshSelected()
4492 // TODO: this is awfully inefficient, we should keep the list of all
4493 // selected items internally, should be much faster
4495 RefreshSelectedUnder(m_anchor
);
4498 void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem
*item
)
4500 if ( item
->IsSelected() )
4503 const wxArrayTreeListItems
& children
= item
->GetChildren();
4504 size_t count
= children
.GetCount();
4505 for ( size_t n
= 0; n
< count
; n
++ )
4507 RefreshSelectedUnder(children
[n
]);
4511 // ----------------------------------------------------------------------------
4512 // changing colours: we need to refresh the tree control
4513 // ----------------------------------------------------------------------------
4515 bool wxTreeListMainWindow::SetBackgroundColour(const wxColour
& colour
)
4517 if ( !wxWindow::SetBackgroundColour(colour
) )
4525 bool wxTreeListMainWindow::SetForegroundColour(const wxColour
& colour
)
4527 if ( !wxWindow::SetForegroundColour(colour
) )
4535 //----------- ALB -------------
4536 void wxTreeListMainWindow::SetItemText(const wxTreeItemId
& item
, size_t column
,
4537 const wxString
& text
)
4539 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
4541 wxClientDC
dc(this);
4542 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
4543 pItem
->SetText(column
, text
);
4544 CalculateSize(pItem
, dc
);
4548 wxString
wxTreeListMainWindow::GetItemText(const wxTreeItemId
& item
,
4549 size_t column
) const
4551 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
4553 return ((wxTreeListItem
*) item
.m_pItem
)->GetText(column
);
4556 void wxTreeListMainWindow::SetFocus()
4558 wxWindow::SetFocus();
4562 //-----------------------------------------------------------------------------
4564 //-----------------------------------------------------------------------------
4566 IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl
, wxControl
);
4568 BEGIN_EVENT_TABLE(wxTreeListCtrl
, wxControl
)
4569 EVT_SIZE(wxTreeListCtrl::OnSize
)
4572 bool wxTreeListCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4575 long style
, const wxValidator
&validator
,
4576 const wxString
& name
)
4578 long main_style
= style
& ~(wxRAISED_BORDER
|wxSUNKEN_BORDER
4579 |wxSIMPLE_BORDER
|wxNO_BORDER
|wxDOUBLE_BORDER
4581 long ctrl_style
= style
& ~(wxVSCROLL
|wxHSCROLL
);
4583 if (!wxControl::Create(parent
, id
, pos
, size
, ctrl_style
, validator
, name
)) {
4586 m_main_win
= new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size
,
4587 main_style
, validator
);
4588 m_header_win
= new wxTreeListHeaderWindow(this, -1, m_main_win
,
4589 wxPoint(0, 0), wxDefaultSize
,
4594 void wxTreeListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
4597 GetClientSize(&w
, &h
);
4599 m_header_win
->SetSize(0, 0, w
, HEADER_HEIGHT
);
4601 m_main_win
->SetSize(0, HEADER_HEIGHT
+ 1, w
, h
- HEADER_HEIGHT
- 1);
4605 size_t wxTreeListCtrl::GetCount() const { return m_main_win
->GetCount(); }
4607 unsigned int wxTreeListCtrl::GetIndent() const
4608 { return m_main_win
->GetIndent(); }
4610 void wxTreeListCtrl::SetIndent(unsigned int indent
)
4611 { m_main_win
->SetIndent(indent
); }
4613 unsigned int wxTreeListCtrl::GetLineSpacing() const
4614 { return m_main_win
->GetLineSpacing(); }
4616 void wxTreeListCtrl::SetLineSpacing(unsigned int spacing
)
4617 { m_main_win
->SetLineSpacing(spacing
); }
4619 wxImageList
* wxTreeListCtrl::GetImageList() const
4620 { return m_main_win
->GetImageList(); }
4622 wxImageList
* wxTreeListCtrl::GetStateImageList() const
4623 { return m_main_win
->GetStateImageList(); }
4625 wxImageList
* wxTreeListCtrl::GetButtonsImageList() const
4626 { return m_main_win
->GetButtonsImageList(); }
4628 void wxTreeListCtrl::SetImageList(wxImageList
* imageList
)
4629 { m_main_win
->SetImageList(imageList
); }
4631 void wxTreeListCtrl::SetStateImageList(wxImageList
* imageList
)
4632 { m_main_win
->SetStateImageList(imageList
); }
4634 void wxTreeListCtrl::SetButtonsImageList(wxImageList
* imageList
)
4635 { m_main_win
->SetButtonsImageList(imageList
); }
4637 void wxTreeListCtrl::AssignImageList(wxImageList
* imageList
)
4638 { m_main_win
->AssignImageList(imageList
); }
4640 void wxTreeListCtrl::AssignStateImageList(wxImageList
* imageList
)
4641 { m_main_win
->AssignStateImageList(imageList
); }
4643 void wxTreeListCtrl::AssignButtonsImageList(wxImageList
* imageList
)
4644 { m_main_win
->AssignButtonsImageList(imageList
); }
4646 wxString
wxTreeListCtrl::GetItemText(const wxTreeItemId
& item
, size_t column
)
4648 { return m_main_win
->GetItemText(item
, column
); }
4650 int wxTreeListCtrl::GetItemImage(const wxTreeItemId
& item
, size_t column
,
4651 wxTreeItemIcon which
) const
4652 { return m_main_win
->GetItemImage(item
, column
, which
); }
4654 wxTreeItemData
* wxTreeListCtrl::GetItemData(const wxTreeItemId
& item
) const
4655 { return m_main_win
->GetItemData(item
); }
4657 bool wxTreeListCtrl::GetItemBold(const wxTreeItemId
& item
) const
4658 { return m_main_win
->GetItemBold(item
); }
4660 wxColour
wxTreeListCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
4661 { return m_main_win
->GetItemTextColour(item
); }
4663 wxColour
wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
)
4665 { return m_main_win
->GetItemBackgroundColour(item
); }
4667 wxFont
wxTreeListCtrl::GetItemFont(const wxTreeItemId
& item
) const
4668 { return m_main_win
->GetItemFont(item
); }
4671 void wxTreeListCtrl::SetItemText(const wxTreeItemId
& item
, size_t column
,
4672 const wxString
& text
)
4673 { m_main_win
->SetItemText(item
, column
, text
); }
4675 void wxTreeListCtrl::SetItemImage(const wxTreeItemId
& item
,
4678 wxTreeItemIcon which
)
4679 { m_main_win
->SetItemImage(item
, column
, image
, which
); }
4681 void wxTreeListCtrl::SetItemData(const wxTreeItemId
& item
,
4682 wxTreeItemData
* data
)
4683 { m_main_win
->SetItemData(item
, data
); }
4685 void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
4686 { m_main_win
->SetItemHasChildren(item
, has
); }
4688 void wxTreeListCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
4689 { m_main_win
->SetItemBold(item
, bold
); }
4691 void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId
& item
,
4692 const wxColour
& col
)
4693 { m_main_win
->SetItemTextColour(item
, col
); }
4695 void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
4696 const wxColour
& col
)
4697 { m_main_win
->SetItemBackgroundColour(item
, col
); }
4699 void wxTreeListCtrl::SetItemFont(const wxTreeItemId
& item
,
4701 { m_main_win
->SetItemFont(item
, font
); }
4703 bool wxTreeListCtrl::SetFont(const wxFont
& font
)
4705 if(m_header_win
) m_header_win
->SetFont(font
);
4707 return m_main_win
->SetFont(font
);
4711 void wxTreeListCtrl::SetWindowStyle(const long style
)
4714 m_main_win
->SetWindowStyle(style
);
4715 // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win
4718 long wxTreeListCtrl::GetWindowStyle() const
4720 long style
= m_windowStyle
;
4722 style
|= m_main_win
->GetWindowStyle();
4726 bool wxTreeListCtrl::IsVisible(const wxTreeItemId
& item
) const
4727 { return m_main_win
->IsVisible(item
); }
4729 bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
4730 { return m_main_win
->ItemHasChildren(item
); }
4732 bool wxTreeListCtrl::IsExpanded(const wxTreeItemId
& item
) const
4733 { return m_main_win
->IsExpanded(item
); }
4735 bool wxTreeListCtrl::IsSelected(const wxTreeItemId
& item
) const
4736 { return m_main_win
->IsSelected(item
); }
4738 bool wxTreeListCtrl::IsBold(const wxTreeItemId
& item
) const
4739 { return m_main_win
->IsBold(item
); }
4741 size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool rec
)
4742 { return m_main_win
->GetChildrenCount(item
, rec
); }
4744 wxTreeItemId
wxTreeListCtrl::GetRootItem() const
4745 { return m_main_win
->GetRootItem(); }
4747 wxTreeItemId
wxTreeListCtrl::GetSelection() const
4748 { return m_main_win
->GetSelection(); }
4750 size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds
& arr
) const
4751 { return m_main_win
->GetSelections(arr
); }
4753 wxTreeItemId
wxTreeListCtrl::GetItemParent(const wxTreeItemId
& item
) const
4754 { return m_main_win
->GetItemParent(item
); }
4756 #if !wxCHECK_VERSION(2, 5, 0)
4757 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4760 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4761 wxTreeItemIdValue
& cookie
) const
4763 { return m_main_win
->GetFirstChild(item
, cookie
); }
4765 #if !wxCHECK_VERSION(2, 5, 0)
4766 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4769 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4770 wxTreeItemIdValue
& cookie
) const
4772 { return m_main_win
->GetNextChild(item
, cookie
); }
4774 #if !wxCHECK_VERSION(2, 5, 0)
4775 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4778 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4779 wxTreeItemIdValue
& cookie
) const
4781 { return m_main_win
->GetPrevChild(item
, cookie
); }
4783 wxTreeItemId
wxTreeListCtrl::GetLastChild(const wxTreeItemId
& item
) const
4784 { return m_main_win
->GetLastChild(item
); }
4786 wxTreeItemId
wxTreeListCtrl::GetNextSibling(const wxTreeItemId
& item
) const
4787 { return m_main_win
->GetNextSibling(item
); }
4789 wxTreeItemId
wxTreeListCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
4790 { return m_main_win
->GetPrevSibling(item
); }
4792 wxTreeItemId
wxTreeListCtrl::GetFirstVisibleItem() const
4793 { return m_main_win
->GetFirstVisibleItem(); }
4795 wxTreeItemId
wxTreeListCtrl::GetNextVisible(const wxTreeItemId
& item
) const
4796 { return m_main_win
->GetNextVisible(item
); }
4798 wxTreeItemId
wxTreeListCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
4799 { return m_main_win
->GetPrevVisible(item
); }
4801 wxTreeItemId
wxTreeListCtrl::GetNext(const wxTreeItemId
& item
) const
4802 { return m_main_win
->GetNext(item
); }
4804 wxTreeItemId
wxTreeListCtrl::AddRoot(const wxString
& text
, int image
,
4805 int selectedImage
, wxTreeItemData
* data
)
4806 { return m_main_win
->AddRoot(text
, image
, selectedImage
, data
); }
4808 wxTreeItemId
wxTreeListCtrl::PrependItem(const wxTreeItemId
& parent
,
4809 const wxString
& text
, int image
,
4811 wxTreeItemData
* data
)
4812 { return m_main_win
->PrependItem(parent
, text
, image
, selectedImage
, data
); }
4814 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4815 const wxTreeItemId
& previous
,
4816 const wxString
& text
, int image
,
4818 wxTreeItemData
* data
)
4820 return m_main_win
->InsertItem(parent
, previous
, text
, image
,
4821 selectedImage
, data
);
4824 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4826 const wxString
& text
, int image
,
4828 wxTreeItemData
* data
)
4830 return m_main_win
->InsertItem(parent
, index
, text
, image
,
4831 selectedImage
, data
);
4834 wxTreeItemId
wxTreeListCtrl::AppendItem(const wxTreeItemId
& parent
,
4835 const wxString
& text
, int image
,
4837 wxTreeItemData
* data
)
4838 { return m_main_win
->AppendItem(parent
, text
, image
, selectedImage
, data
); }
4840 void wxTreeListCtrl::Delete(const wxTreeItemId
& item
)
4841 { m_main_win
->Delete(item
); }
4843 void wxTreeListCtrl::DeleteChildren(const wxTreeItemId
& item
)
4844 { m_main_win
->DeleteChildren(item
); }
4846 void wxTreeListCtrl::DeleteAllItems()
4847 { m_main_win
->DeleteAllItems(); }
4849 void wxTreeListCtrl::Expand(const wxTreeItemId
& item
)
4850 { m_main_win
->Expand(item
); }
4852 void wxTreeListCtrl::ExpandAll(const wxTreeItemId
& item
)
4853 { m_main_win
->ExpandAll(item
); }
4855 void wxTreeListCtrl::Collapse(const wxTreeItemId
& item
)
4856 { m_main_win
->Collapse(item
); }
4858 void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId
& item
)
4859 { m_main_win
->CollapseAndReset(item
); }
4861 void wxTreeListCtrl::Toggle(const wxTreeItemId
& item
)
4862 { m_main_win
->Toggle(item
); }
4864 void wxTreeListCtrl::Unselect()
4865 { m_main_win
->Unselect(); }
4867 void wxTreeListCtrl::UnselectAll()
4868 { m_main_win
->UnselectAll(); }
4870 void wxTreeListCtrl::SelectItem(const wxTreeItemId
& item
, bool unselect_others
,
4871 bool extended_select
)
4872 { m_main_win
->SelectItem(item
, unselect_others
, extended_select
); }
4874 void wxTreeListCtrl::SelectAll(bool extended_select
)
4875 { m_main_win
->SelectAll(extended_select
); }
4877 void wxTreeListCtrl::EnsureVisible(const wxTreeItemId
& item
)
4878 { m_main_win
->EnsureVisible(item
); }
4880 void wxTreeListCtrl::ScrollTo(const wxTreeItemId
& item
)
4881 { m_main_win
->ScrollTo(item
); }
4883 wxTreeItemId
wxTreeListCtrl::HitTest(const wxPoint
& pos
, int& flags
,
4886 return m_main_win
->HitTest(pos
, flags
, column
);
4889 bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
4890 bool textOnly
) const
4891 { return m_main_win
->GetBoundingRect(item
, rect
, textOnly
); }
4893 void wxTreeListCtrl::Edit(const wxTreeItemId
& item
)
4894 { m_main_win
->Edit(item
); }
4896 int wxTreeListCtrl::OnCompareItems(const wxTreeItemId
& item1
,
4897 const wxTreeItemId
& item2
)
4899 // ALB: do the comparison here, and not delegate to m_main_win, in order
4900 // to let the user override it
4901 //return m_main_win->OnCompareItems(item1, item2);
4902 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
4905 void wxTreeListCtrl::SortChildren(const wxTreeItemId
& item
)
4906 { m_main_win
->SortChildren(item
); }
4908 wxTreeItemId
wxTreeListCtrl::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
)
4909 { return m_main_win
->FindItem (item
, str
, flags
); }
4911 bool wxTreeListCtrl::SetBackgroundColour(const wxColour
& colour
)
4913 if (!m_main_win
) return false;
4914 return m_main_win
->SetBackgroundColour(colour
);
4917 bool wxTreeListCtrl::SetForegroundColour(const wxColour
& colour
)
4919 if (!m_main_win
) return false;
4920 return m_main_win
->SetForegroundColour(colour
);
4923 size_t wxTreeListCtrl::GetColumnCount() const
4924 { return m_main_win
->GetColumnCount(); }
4926 void wxTreeListCtrl::SetColumnWidth(size_t column
, size_t width
)
4927 { m_header_win
->SetColumnWidth(column
, width
); }
4929 int wxTreeListCtrl::GetColumnWidth(size_t column
) const
4930 { return m_header_win
->GetColumnWidth(column
); }
4932 void wxTreeListCtrl::SetMainColumn(size_t column
)
4933 { m_main_win
->SetMainColumn(column
); }
4935 size_t wxTreeListCtrl::GetMainColumn() const
4936 { return m_main_win
->GetMainColumn(); }
4938 void wxTreeListCtrl::SetColumnText(size_t column
, const wxString
& text
)
4940 m_header_win
->SetColumnText(column
, text
);
4941 m_header_win
->Refresh();
4944 wxString
wxTreeListCtrl::GetColumnText(size_t column
) const
4945 { return m_header_win
->GetColumnText(column
); }
4947 void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo
& col
)
4948 { m_header_win
->AddColumn(col
); }
4950 void wxTreeListCtrl::InsertColumn(size_t before
,
4951 const wxTreeListColumnInfo
& col
)
4952 { m_header_win
->InsertColumn(before
, col
); }
4954 void wxTreeListCtrl::RemoveColumn(size_t column
)
4955 { m_header_win
->RemoveColumn(column
); }
4957 void wxTreeListCtrl::SetColumn(size_t column
, const wxTreeListColumnInfo
& col
)
4958 { m_header_win
->SetColumn(column
, col
); }
4960 const wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) const
4961 { return m_header_win
->GetColumn(column
); }
4963 wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
)
4964 { return m_header_win
->GetColumn(column
); }
4966 void wxTreeListCtrl::SetColumnImage(size_t column
, int image
)
4968 m_header_win
->SetColumn(column
, GetColumn(column
).SetImage(image
));
4971 int wxTreeListCtrl::GetColumnImage(size_t column
) const
4973 return m_header_win
->GetColumn(column
).GetImage();
4976 void wxTreeListCtrl::ShowColumn(size_t column
, bool shown
)
4978 wxASSERT_MSG( column
!= GetMainColumn(),
4979 wxT("The main column may not be hidden") );
4980 m_header_win
->SetColumn(column
, GetColumn(column
).SetShown(GetMainColumn()? true: shown
));
4983 bool wxTreeListCtrl::IsColumnShown(size_t column
) const
4985 return m_header_win
->GetColumn(column
).GetShown();
4988 void wxTreeListCtrl::SetColumnAlignment(size_t column
,
4989 wxTreeListColumnAlign align
)
4991 m_header_win
->SetColumn(column
, GetColumn(column
).SetAlignment(align
));
4994 wxTreeListColumnAlign
wxTreeListCtrl::GetColumnAlignment(size_t column
) const
4996 return m_header_win
->GetColumn(column
).GetAlignment();
4999 void wxTreeListCtrl::Refresh(bool erase
, const wxRect
* rect
)
5001 m_main_win
->Refresh(erase
, rect
);
5002 m_header_win
->Refresh(erase
, rect
);
5005 void wxTreeListCtrl::SetFocus()
5006 { m_main_win
->SetFocus(); }
5009 wxSize
wxTreeListCtrl::DoGetBestSize() const
5011 // something is better than nothing...
5012 return wxSize(100,80);