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 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
30 #include <wx/treebase.h>
32 #include <wx/textctrl.h>
33 #include <wx/imaglist.h>
34 #include <wx/settings.h>
35 #include <wx/dcclient.h>
36 #include <wx/dcscreen.h>
37 #include <wx/scrolwin.h>
38 #include <wx/renderer.h>
39 #include <wx/dcmemory.h>
41 #include "wx/treelistctrl.h"
45 #include <wx/gtk/win_gtk.h>
49 #include "wx/mac/private.h"
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
59 #if !wxCHECK_VERSION(2, 5, 0)
60 WX_DEFINE_ARRAY(wxTreeListItem
*, wxArrayTreeListItems
);
62 WX_DEFINE_ARRAY_PTR(wxTreeListItem
*, wxArrayTreeListItems
);
65 #include <wx/dynarray.h>
66 WX_DECLARE_OBJARRAY(wxTreeListColumnInfo
, wxArrayTreeListColumnInfo
);
67 #include <wx/arrimpl.cpp>
68 WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo
);
70 #if !wxCHECK_VERSION(2, 3, 3)
71 WX_DEFINE_ARRAY(short, wxArrayShort
);
75 // --------------------------------------------------------------------------
77 // --------------------------------------------------------------------------
79 static const int NO_IMAGE
= -1;
81 const int LINEHEIGHT
= 10;
82 const int PIXELS_PER_UNIT
= 10;
83 const int LINEATROOT
= 5;
85 const int MININDENT
= 10;
86 const int BTNWIDTH
= 9; //11;
87 const int BTNHEIGHT
= 9; //11;
89 // extra margins around the text label
90 static const int EXTRA_WIDTH
= 4;
91 static const int EXTRA_HEIGHT
= 4;
93 // offset for the header window
94 static const int HEADER_OFFSET_X
= 1;
95 static const int HEADER_OFFSET_Y
= 1;
99 const wxChar
* wxTreeListCtrlNameStr
= wxT("treelistctrl");
101 static wxTreeListColumnInfo wxInvalidTreeListColumnInfo
;
104 // ---------------------------------------------------------------------------
106 // ---------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
108 // wxTreeListHeaderWindow (internal)
109 //-----------------------------------------------------------------------------
111 class wxTreeListHeaderWindow
: public wxWindow
114 wxTreeListMainWindow
*m_owner
;
115 const wxCursor
*m_currentCursor
;
116 wxCursor
*m_resizeCursor
;
119 // column being resized
122 // divider line position in logical (unscrolled) coords
125 // minimal position beyond which the divider line can't be dragged in
129 wxArrayTreeListColumnInfo m_columns
;
131 // total width of the columns
132 int m_total_col_width
;
136 wxTreeListHeaderWindow();
138 wxTreeListHeaderWindow( wxWindow
*win
,
140 wxTreeListMainWindow
*owner
,
141 const wxPoint
&pos
= wxDefaultPosition
,
142 const wxSize
&size
= wxDefaultSize
,
144 const wxString
&name
= wxT("wxtreelistctrlcolumntitles") );
146 virtual ~wxTreeListHeaderWindow();
148 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
150 void AdjustDC(wxDC
& dc
);
152 void OnEraseBackground( wxEraseEvent
& event
);
153 void OnPaint( wxPaintEvent
&event
);
154 void OnMouse( wxMouseEvent
&event
);
155 void OnSetFocus( wxFocusEvent
&event
);
158 // columns manipulation
160 size_t GetColumnCount() const { return m_columns
.GetCount(); }
162 void AddColumn(const wxTreeListColumnInfo
& col
);
164 void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
);
166 void RemoveColumn(size_t column
);
168 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
169 const wxTreeListColumnInfo
& GetColumn(size_t column
) const
171 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
172 return m_columns
[column
];
174 wxTreeListColumnInfo
& GetColumn(size_t column
)
176 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
177 return m_columns
[column
];
180 void SetColumnWidth(size_t column
, size_t width
);
182 void SetColumnText(size_t column
, const wxString
& text
)
184 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
185 m_columns
[column
].SetText(text
);
188 void SetColumnShown(size_t column
, bool shown
)
190 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
191 m_columns
[column
].SetShown(shown
);
194 wxString
GetColumnText(size_t column
) const
196 wxCHECK_MSG(column
< GetColumnCount(), wxEmptyString
, wxT("Invalid column"));
197 return m_columns
[column
].GetText();
200 int GetColumnWidth(size_t column
) const
202 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
203 return m_columns
[column
].GetWidth();
206 int GetWidth() const { return m_total_col_width
; }
208 int GetColumnShown(size_t column
) const
210 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
211 return m_columns
[column
].GetShown();
218 // common part of all ctors
221 void SendListEvent(wxEventType type
, wxPoint pos
);
223 DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow
)
224 DECLARE_EVENT_TABLE()
228 // this is the "true" control
229 class wxTreeListMainWindow
: public wxScrolledWindow
234 wxTreeListMainWindow() { Init(); }
236 wxTreeListMainWindow(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
237 const wxPoint
& pos
= wxDefaultPosition
,
238 const wxSize
& size
= wxDefaultSize
,
239 long style
= wxTR_DEFAULT_STYLE
,
240 const wxValidator
&validator
= wxDefaultValidator
,
241 const wxString
& name
= wxT("wxtreelistmainwindow"))
244 Create(parent
, id
, pos
, size
, style
, validator
, name
);
247 virtual ~wxTreeListMainWindow();
249 bool Create(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
250 const wxPoint
& pos
= wxDefaultPosition
,
251 const wxSize
& size
= wxDefaultSize
,
252 long style
= wxTR_DEFAULT_STYLE
,
253 const wxValidator
&validator
= wxDefaultValidator
,
254 const wxString
& name
= wxT("wxtreelistctrl"));
259 // get the total number of items in the control
260 size_t GetCount() const;
262 // indent is the number of pixels the children are indented relative to
263 // the parents position. SetIndent() also redraws the control
265 unsigned int GetIndent() const { return m_indent
; }
266 void SetIndent(unsigned int indent
);
268 // see wxTreeListCtrl for the meaning
269 unsigned int GetLineSpacing() const { return m_linespacing
; }
270 void SetLineSpacing(unsigned int spacing
);
272 // image list: these functions allow to associate an image list with
273 // the control and retrieve it. Note that when assigned with
274 // SetImageList, the control does _not_ delete
275 // the associated image list when it's deleted in order to allow image
276 // lists to be shared between different controls. If you use
277 // AssignImageList, the control _does_ delete the image list.
279 // The normal image list is for the icons which correspond to the
280 // normal tree item state (whether it is selected or not).
281 // Additionally, the application might choose to show a state icon
282 // which corresponds to an app-defined item state (for example,
283 // checked/unchecked) which are taken from the state image list.
284 wxImageList
*GetImageList() const;
285 wxImageList
*GetStateImageList() const;
286 wxImageList
*GetButtonsImageList() const;
288 void SetImageList(wxImageList
*imageList
);
289 void SetStateImageList(wxImageList
*imageList
);
290 void SetButtonsImageList(wxImageList
*imageList
);
291 void AssignImageList(wxImageList
*imageList
);
292 void AssignStateImageList(wxImageList
*imageList
);
293 void AssignButtonsImageList(wxImageList
*imageList
);
295 // Functions to work with tree ctrl items.
300 // retrieve item's label
301 wxString
GetItemText(const wxTreeItemId
& item
) const
302 { return GetItemText(item
, GetMainColumn()); }
303 // get one of the images associated with the item (normal by default)
304 int GetItemImage(const wxTreeItemId
& item
,
305 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
306 { return GetItemImage(item
, GetMainColumn(), which
); }
308 // get the data associated with the item
309 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
311 bool GetItemBold(const wxTreeItemId
& item
) const;
312 wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
313 wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
314 wxFont
GetItemFont(const wxTreeItemId
& item
) const;
320 void SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
321 { SetItemText(item
, GetMainColumn(), text
); }
323 // get one of the images associated with the item (normal by default)
324 void SetItemImage(const wxTreeItemId
& item
, int image
,
325 wxTreeItemIcon which
= wxTreeItemIcon_Normal
)
326 { SetItemImage(item
, GetMainColumn(), image
, which
); }
328 // associate some data with the item
329 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
331 // force appearance of [+] button near the item. This is useful to
332 // allow the user to expand the items which don't have any children now
333 // - but instead add them only when needed, thus minimizing memory
334 // usage and loading time.
335 void SetItemHasChildren(const wxTreeItemId
& item
, bool has
= TRUE
);
337 // the item will be shown in bold
338 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
340 // set the item's text colour
341 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
343 // set the item's background colour
344 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
346 // set the item's font (should be of the same height for all items)
347 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
349 // set the window font
350 virtual bool SetFont( const wxFont
&font
);
352 // set the styles. No need to specify a GetWindowStyle here since
353 // the base wxWindow member function will do it for us
354 void SetWindowStyle(const long styles
);
356 // item status inquiries
357 // ---------------------
359 // is the item visible (it might be outside the view or not expanded)?
360 bool IsVisible(const wxTreeItemId
& item
) const;
361 // does the item has any children?
362 bool HasChildren(const wxTreeItemId
& item
) const
363 { return ItemHasChildren(item
); }
364 bool ItemHasChildren(const wxTreeItemId
& item
) const;
365 // is the item expanded (only makes sense if HasChildren())?
366 bool IsExpanded(const wxTreeItemId
& item
) const;
367 // is this item currently selected (the same as has focus)?
368 bool IsSelected(const wxTreeItemId
& item
) const;
369 // is item text in bold font?
370 bool IsBold(const wxTreeItemId
& item
) const;
371 // does the layout include space for a button?
373 // number of children
374 // ------------------
376 // if 'recursively' is FALSE, only immediate children count, otherwise
377 // the returned number is the number of all items in this branch
378 size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively
= TRUE
);
383 // wxTreeItemId.IsOk() will return FALSE if there is no such item
385 // get the root tree item
386 wxTreeItemId
GetRootItem() const { return m_anchor
; }
388 // get the item currently selected (may return NULL if no selection)
389 wxTreeItemId
GetSelection() const { return m_current
; }
391 // get the items currently selected, return the number of such item
392 size_t GetSelections(wxArrayTreeItemIds
&) const;
394 // get the parent of this item (may return NULL if root)
395 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
397 // for this enumeration function you must pass in a "cookie" parameter
398 // which is opaque for the application but is necessary for the library
399 // to make these functions reentrant (i.e. allow more than one
400 // enumeration on one and the same object simultaneously). Of course,
401 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
404 // get the first child of this item
405 #if !wxCHECK_VERSION(2, 5, 0)
406 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
408 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
410 // get the next child
411 #if !wxCHECK_VERSION(2, 5, 0)
412 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
414 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
416 // get the prev child
417 #if !wxCHECK_VERSION(2, 5, 0)
418 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, long& cookie
) const;
420 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
422 // get the last child of this item - this method doesn't use cookies
423 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
425 // get the next sibling of this item
426 wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
427 // get the previous sibling
428 wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
430 // get first visible item
431 wxTreeItemId
GetFirstVisibleItem() const;
432 // get the next visible item: item must be visible itself!
433 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
434 wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
435 // get the previous visible item: item must be visible itself!
436 wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
438 // Only for internal use right now, but should probably be public
439 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
444 // add the root node to the tree
445 wxTreeItemId
AddRoot(const wxString
& text
,
446 int image
= -1, int selectedImage
= -1,
447 wxTreeItemData
*data
= NULL
);
449 // insert a new item in as the first child of the parent
450 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
451 const wxString
& text
,
452 int image
= -1, int selectedImage
= -1,
453 wxTreeItemData
*data
= NULL
);
455 // insert a new item after a given one
456 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
457 const wxTreeItemId
& idPrevious
,
458 const wxString
& text
,
459 int image
= -1, int selectedImage
= -1,
460 wxTreeItemData
*data
= NULL
);
462 // insert a new item before the one with the given index
463 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
465 const wxString
& text
,
466 int image
= -1, int selectedImage
= -1,
467 wxTreeItemData
*data
= NULL
);
469 // insert a new item in as the last child of the parent
470 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
471 const wxString
& text
,
472 int image
= -1, int selectedImage
= -1,
473 wxTreeItemData
*data
= NULL
);
475 // delete this item and associated data if any
476 void Delete(const wxTreeItemId
& item
);
477 // delete all children (but don't delete the item itself)
478 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
479 void DeleteChildren(const wxTreeItemId
& item
);
480 // delete all items from the tree
481 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
482 void DeleteAllItems();
485 void Expand(const wxTreeItemId
& item
);
486 // expand this item and all subitems recursively
487 void ExpandAll(const wxTreeItemId
& item
);
488 // collapse the item without removing its children
489 void Collapse(const wxTreeItemId
& item
);
490 // collapse the item and remove all children
491 void CollapseAndReset(const wxTreeItemId
& item
);
492 // toggles the current state
493 void Toggle(const wxTreeItemId
& item
);
495 // remove the selection from currently selected item (if any)
499 void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
,
500 bool extended_select
=FALSE
);
501 void SelectAll(bool extended_select
=FALSE
);
502 // make sure this item is visible (expanding the parent item and/or
503 // scrolling to this item if necessary)
504 void EnsureVisible(const wxTreeItemId
& item
);
505 // scroll to this item (but don't expand its parent)
506 void ScrollTo(const wxTreeItemId
& item
);
507 void AdjustMyScrollbars();
509 // The first function is more portable (because easier to implement
510 // on other platforms), but the second one returns some extra info.
511 wxTreeItemId
HitTest(const wxPoint
& point
)
512 { int dummy
; return HitTest(point
, dummy
); }
513 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
)
514 { int col
; return HitTest(point
, flags
, col
); }
516 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
, int& column
);
519 // get the bounding rectangle of the item (or of its label only)
520 bool GetBoundingRect(const wxTreeItemId
& item
,
522 bool textOnly
= FALSE
) const;
524 // Start editing the item label: this (temporarily) replaces the item
525 // with a one line edit control. The item will be selected if it hadn't
527 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
528 void Edit( const wxTreeItemId
& item
);
531 // this function is called to compare 2 items and should return -1, 0
532 // or +1 if the first item is less than, equal to or greater than the
533 // second one. The base class version performs alphabetic comparaison
534 // of item labels (GetText)
535 virtual int OnCompareItems(const wxTreeItemId
& item1
,
536 const wxTreeItemId
& item2
);
537 // sort the children of this item using OnCompareItems
539 // NB: this function is not reentrant and not MT-safe (FIXME)!
540 void SortChildren(const wxTreeItemId
& item
);
543 wxTreeItemId
FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
= 0);
545 // deprecated functions: use Set/GetItemImage directly
546 // get the selected item image
547 int GetItemSelectedImage(const wxTreeItemId
& item
) const
548 { return GetItemImage(item
, wxTreeItemIcon_Selected
); }
549 // set the selected item image
550 void SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
551 { SetItemImage(item
, image
, wxTreeItemIcon_Selected
); }
553 // implementation only from now on
555 // overridden base class virtuals
556 virtual bool SetBackgroundColour(const wxColour
& colour
);
557 virtual bool SetForegroundColour(const wxColour
& colour
);
560 void OnPaint( wxPaintEvent
&event
);
561 void OnSetFocus( wxFocusEvent
&event
);
562 void OnKillFocus( wxFocusEvent
&event
);
563 void OnChar( wxKeyEvent
&event
);
564 void OnMouse( wxMouseEvent
&event
);
565 void OnIdle( wxIdleEvent
&event
);
566 void OnScroll(wxScrollWinEvent
& event
); // ALB
568 // implementation helpers
569 void SendDeleteEvent(wxTreeListItem
*itemBeingDeleted
);
571 void DoDirtyProcessing();
573 void DrawBorder(const wxTreeItemId
& item
);
574 void DrawLine(const wxTreeItemId
& item
, bool below
);
576 size_t GetColumnCount() const
577 { return m_owner
->GetHeaderWindow()->GetColumnCount(); }
579 void SetMainColumn(size_t column
)
581 if(column
< GetColumnCount())
582 m_main_column
= column
;
584 size_t GetMainColumn() const { return m_main_column
; }
586 void SetItemText(const wxTreeItemId
& item
, size_t column
,
587 const wxString
& text
);
588 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
590 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
591 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
592 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
593 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
598 wxTreeListCtrl
* m_owner
; // ALB
600 size_t m_main_column
; // ALB
602 friend class wxTreeListItem
;
603 friend class wxTreeListRenameTimer
;
604 friend class wxTreeListTextCtrl
;
609 wxTreeListItem
*m_anchor
;
610 wxTreeListItem
*m_current
, *m_key_current
, *m_currentEdit
;
611 int m_btnWidth
, m_btnWidth2
;
612 int m_btnHeight
, m_btnHeight2
;
613 int m_imgWidth
, m_imgWidth2
;
614 int m_imgHeight
, m_imgHeight2
;
615 unsigned short m_indent
;
617 unsigned short m_linespacing
;
619 wxBrush
*m_hilightBrush
,
620 *m_hilightUnfocusedBrush
;
625 bool m_ownsImageListNormal
,
626 m_ownsImageListState
,
627 m_ownsImageListButtons
;
628 bool m_isDragging
; // true between BEGIN/END drag events
630 bool m_lastOnSame
; // last click on the same item as prev
631 wxImageList
*m_imageListNormal
,
637 wxTreeListItem
*m_dropTarget
;
638 wxCursor m_oldCursor
; // cursor is changed while dragging
639 wxTreeListItem
*m_oldSelection
;
640 wxTreeListItem
*m_underMouse
; // for visual effects
642 wxTimer
*m_renameTimer
;
643 wxString m_renameRes
;
646 wxTimer
*m_findTimer
;
649 // the common part of all ctors
653 wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
655 const wxString
& text
,
656 int image
, int selectedImage
,
657 wxTreeItemData
*data
);
658 bool HasButtons(void) const
659 { return (m_imageListButtons
!= NULL
) ||
660 HasFlag (wxTR_TWIST_BUTTONS
|wxTR_HAS_BUTTONS
); }
663 void CalculateLineHeight();
664 int GetLineHeight(wxTreeListItem
*item
) const;
665 void PaintLevel( wxTreeListItem
*item
, wxDC
& dc
, int level
, int &y
,
667 void PaintItem( wxTreeListItem
*item
, wxDC
& dc
);
669 void CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
, int level
, int &y
,
671 void CalculatePositions();
672 void CalculateSize( wxTreeListItem
*item
, wxDC
&dc
);
674 void RefreshSubtree( wxTreeListItem
*item
);
675 void RefreshLine( wxTreeListItem
*item
);
677 // redraw all selected items
678 void RefreshSelected();
680 // RefreshSelected() recursive helper
681 void RefreshSelectedUnder(wxTreeListItem
*item
);
683 void OnRenameTimer();
684 void OnRenameAccept();
686 void FillArray(wxTreeListItem
*, wxArrayTreeItemIds
&) const;
687 void SelectItemRange( wxTreeListItem
*item1
, wxTreeListItem
*item2
);
688 bool TagAllChildrenUntilLast(wxTreeListItem
*crt_item
,
689 wxTreeListItem
*last_item
, bool select
);
690 bool TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
,
692 void UnselectAllChildren( wxTreeListItem
*item
);
694 void DrawDropEffect(wxTreeListItem
*item
);
697 DECLARE_EVENT_TABLE()
698 DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow
)
702 // timer used for enabling in-place edit
703 class wxTreeListRenameTimer
: public wxTimer
706 wxTreeListRenameTimer( wxTreeListMainWindow
*owner
);
711 wxTreeListMainWindow
*m_owner
;
714 // control used for in-place edit
715 class wxTreeListTextCtrl
: public wxTextCtrl
718 wxTreeListTextCtrl( wxWindow
*parent
,
722 wxTreeListMainWindow
*owner
,
723 const wxString
&value
= wxEmptyString
,
724 const wxPoint
&pos
= wxDefaultPosition
,
725 const wxSize
&size
= wxDefaultSize
,
726 int style
= wxSIMPLE_BORDER
,
727 const wxValidator
& validator
= wxDefaultValidator
,
728 const wxString
&name
= wxTextCtrlNameStr
);
730 void OnChar( wxKeyEvent
&event
);
731 void OnKeyUp( wxKeyEvent
&event
);
732 void OnKillFocus( wxFocusEvent
&event
);
737 wxTreeListMainWindow
*m_owner
;
738 wxString m_startValue
;
741 DECLARE_EVENT_TABLE()
749 wxTreeListItem() { m_data
= NULL
; }
750 wxTreeListItem( wxTreeListMainWindow
*owner
,
751 wxTreeListItem
*parent
,
752 const wxArrayString
& text
,
755 wxTreeItemData
*data
);
760 wxArrayTreeListItems
& GetChildren() { return m_children
; }
762 const wxString
GetText() const
764 if(m_text
.GetCount() > 0) return m_text
[0];
765 return wxEmptyString
;
767 const wxString
GetText(size_t col
) const
769 if(m_text
.GetCount() > col
) return m_text
[col
];
770 return wxEmptyString
;
772 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
773 { return m_images
[which
]; }
774 int GetImage(size_t col
, wxTreeItemIcon which
=wxTreeItemIcon_Normal
) const
776 if(col
== m_owner
->GetMainColumn()) return m_images
[which
];
777 if(col
< m_col_images
.GetCount()) return m_col_images
[col
];
780 wxTreeItemData
*GetData() const { return m_data
; }
782 // returns the current image for the item (depending on its
783 // selected/expanded/whatever state)
784 int GetCurrentImage() const;
786 void SetText( const wxString
&text
);
787 void SetText(size_t col
, const wxString
& text
) // ALB
789 if(col
< m_text
.GetCount())
791 else if(col
< m_owner
->GetColumnCount()) {
792 int howmany
= m_owner
->GetColumnCount();
793 for(int i
= m_text
.GetCount(); i
< howmany
; ++i
)
794 m_text
.Add(wxEmptyString
);
798 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
799 void SetImage(size_t col
, int image
, wxTreeItemIcon which
)
801 if(col
== m_owner
->GetMainColumn()) m_images
[which
] = image
;
802 else if(col
< m_col_images
.GetCount())
803 m_col_images
[col
] = image
;
804 else if(col
< m_owner
->GetColumnCount()) {
805 int howmany
= m_owner
->GetColumnCount();
806 for(int i
= m_col_images
.GetCount(); i
< howmany
; ++i
)
807 m_col_images
.Add(NO_IMAGE
);
808 m_col_images
[col
] = image
;
812 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
814 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
816 void SetBold(bool bold
) { m_isBold
= bold
; }
818 int GetX() const { return m_x
; }
819 int GetY() const { return m_y
; }
821 void SetX(int x
) { m_x
= x
; }
822 void SetY(int y
) { m_y
= y
; }
824 int GetHeight() const { return m_height
; }
825 int GetWidth() const { return m_width
; }
827 void SetHeight(int h
) { m_height
= h
; }
828 void SetWidth(int w
) { m_width
= w
; }
830 wxTreeListItem
*GetItemParent() const { return m_parent
; }
833 // deletes all children notifying the treectrl about it if !NULL
835 void DeleteChildren(wxTreeListMainWindow
*tree
= NULL
);
837 // get count of all children (and grand children if 'recursively')
838 size_t GetChildrenCount(bool recursively
= TRUE
) const;
840 void Insert(wxTreeListItem
*child
, size_t index
)
841 { m_children
.Insert(child
, index
); }
843 void GetSize( int &x
, int &y
, const wxTreeListMainWindow
* );
845 // return the item at given position (or NULL if no item), onButton is
846 // TRUE if the point belongs to the item's button, otherwise it lies
847 // on the button's label
848 wxTreeListItem
*HitTest( const wxPoint
& point
,
849 const wxTreeListMainWindow
*,
852 wxTreeListItem
*HitTest( const wxPoint
& point
,
853 const wxTreeListMainWindow
*,
854 int &flags
, int& column
/*ALB*/,
857 void Expand() { m_isCollapsed
= FALSE
; }
858 void Collapse() { m_isCollapsed
= TRUE
; }
860 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
863 bool HasChildren() const { return !m_children
.IsEmpty(); }
864 bool IsSelected() const { return m_hasHilight
!= 0; }
865 bool IsExpanded() const { return !m_isCollapsed
; }
866 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
867 bool IsBold() const { return m_isBold
!= 0; }
870 // get them - may be NULL
871 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
872 // get them ensuring that the pointer is not NULL
873 wxTreeItemAttr
& Attr()
877 m_attr
= new wxTreeItemAttr
;
883 void SetAttributes(wxTreeItemAttr
*attr
)
885 if ( m_ownsAttr
) delete m_attr
;
889 // set them and delete when done
890 void AssignAttributes(wxTreeItemAttr
*attr
)
897 wxTreeListMainWindow
*m_owner
; // control the item belongs to
899 // since there can be very many of these, we save size by chosing
900 // the smallest representation for the elements and by ordering
901 // the members to avoid padding.
902 wxArrayString m_text
; // labels to be rendered for item
904 wxTreeItemData
*m_data
; // user-provided data
906 wxArrayTreeListItems m_children
; // list of children
907 wxTreeListItem
*m_parent
; // parent of this item
909 wxTreeItemAttr
*m_attr
; // attributes???
911 // tree ctrl images for the normal, selected, expanded and
912 // expanded+selected states
913 short m_images
[wxTreeItemIcon_Max
];
914 wxArrayShort m_col_images
; // images for the various columns (!= main)
916 wxCoord m_x
; // (virtual) offset from top
917 wxCoord m_y
; // (virtual) offset from left
918 short m_width
; // width of this item
919 unsigned char m_height
; // height of this item
921 // use bitfields to save size
922 int m_isCollapsed
:1;
923 int m_hasHilight
:1; // same as focused
924 int m_hasPlus
:1; // used for item which doesn't have
925 // children but has a [+] button
926 int m_isBold
:1; // render the label in bold font
927 int m_ownsAttr
:1; // delete attribute when done
930 // ===========================================================================
932 // ===========================================================================
934 // ----------------------------------------------------------------------------
936 // ----------------------------------------------------------------------------
938 // translate the key or mouse event flags to the type of selection we're
940 static void EventFlagsToSelType(long style
,
944 bool &extended_select
,
945 bool &unselect_others
)
947 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
948 extended_select
= shiftDown
&& is_multiple
;
949 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
952 // ---------------------------------------------------------------------------
953 // wxTreeListRenameTimer (internal)
954 // ---------------------------------------------------------------------------
956 wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow
*owner
)
961 void wxTreeListRenameTimer::Notify()
963 m_owner
->OnRenameTimer();
966 //-----------------------------------------------------------------------------
967 // wxTreeListTextCtrl (internal)
968 //-----------------------------------------------------------------------------
970 BEGIN_EVENT_TABLE(wxTreeListTextCtrl
,wxTextCtrl
)
971 EVT_CHAR (wxTreeListTextCtrl::OnChar
)
972 EVT_KEY_UP (wxTreeListTextCtrl::OnKeyUp
)
973 EVT_KILL_FOCUS (wxTreeListTextCtrl::OnKillFocus
)
976 wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow
*parent
,
980 wxTreeListMainWindow
*owner
,
981 const wxString
&value
,
985 const wxValidator
& validator
,
986 const wxString
&name
)
987 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
993 (*m_res
) = wxEmptyString
;
994 m_startValue
= value
;
998 void wxTreeListTextCtrl::OnChar( wxKeyEvent
&event
)
1000 if (event
.m_keyCode
== WXK_RETURN
)
1003 (*m_res
) = GetValue();
1005 if ((*m_res
) != m_startValue
)
1006 m_owner
->OnRenameAccept();
1008 if (!wxPendingDelete
.Member(this))
1009 wxPendingDelete
.Append(this);
1012 m_owner
->SetFocus(); // This doesn't work. TODO.
1016 if (event
.m_keyCode
== WXK_ESCAPE
)
1018 (*m_accept
) = FALSE
;
1019 (*m_res
) = wxEmptyString
;
1021 if (!wxPendingDelete
.Member(this))
1022 wxPendingDelete
.Append(this);
1025 m_owner
->SetFocus(); // This doesn't work. TODO.
1032 void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1040 // auto-grow the textctrl:
1041 wxSize parentSize
= m_owner
->GetSize();
1042 wxPoint myPos
= GetPosition();
1043 wxSize mySize
= GetSize();
1045 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
1046 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1047 if (mySize
.x
> sx
) sx
= mySize
.x
;
1053 void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
1061 if (!wxPendingDelete
.Member(this))
1062 wxPendingDelete
.Append(this);
1065 (*m_res
) = GetValue();
1067 if ((*m_res
) != m_startValue
)
1068 m_owner
->OnRenameAccept();
1071 //-----------------------------------------------------------------------------
1072 // wxTreeListHeaderWindow
1073 //-----------------------------------------------------------------------------
1075 IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow
,wxWindow
)
1077 BEGIN_EVENT_TABLE(wxTreeListHeaderWindow
,wxWindow
)
1078 EVT_ERASE_BACKGROUND (wxTreeListHeaderWindow::OnEraseBackground
)
1079 EVT_PAINT (wxTreeListHeaderWindow::OnPaint
)
1080 EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse
)
1081 EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus
)
1084 void wxTreeListHeaderWindow::Init()
1086 m_currentCursor
= (wxCursor
*) NULL
;
1087 m_isDragging
= FALSE
;
1089 m_total_col_width
= 0;
1092 wxTreeListHeaderWindow::wxTreeListHeaderWindow()
1096 m_owner
= (wxTreeListMainWindow
*) NULL
;
1097 m_resizeCursor
= (wxCursor
*) NULL
;
1100 wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow
*win
,
1102 wxTreeListMainWindow
*owner
,
1106 const wxString
&name
)
1107 : wxWindow( win
, id
, pos
, size
, style
, name
)
1112 m_resizeCursor
= new wxCursor(wxCURSOR_SIZEWE
);
1114 SetBackgroundColour(wxSystemSettings::GetColour(
1115 wxSYS_COLOUR_BTNFACE
));
1118 wxTreeListHeaderWindow::~wxTreeListHeaderWindow()
1120 delete m_resizeCursor
;
1123 void wxTreeListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1126 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1127 : GTK_STATE_INSENSITIVE
;
1129 x
= dc
->XLOG2DEV( x
);
1131 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1132 state
, GTK_SHADOW_OUT
,
1133 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1134 x
-1, y
-1, w
+2, h
+2);
1135 #elif defined( __WXMAC__ )
1136 const int m_corner
= 1;
1138 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1140 dc
->SetPen( wxPen(wxSystemSettings::GetColour(
1141 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
));
1142 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1143 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1145 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1148 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1149 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1151 dc
->SetPen( *wxWHITE_PEN
);
1152 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1153 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1154 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1155 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1157 const int m_corner
= 1;
1159 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1161 dc
->SetPen( *wxBLACK_PEN
);
1162 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1163 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1165 wxPen
pen(wxSystemSettings::GetColour(
1166 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1169 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1170 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1172 dc
->SetPen( *wxWHITE_PEN
);
1173 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1174 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1175 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1176 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1180 // shift the DC origin to match the position of the main window horz
1181 // scrollbar: this allows us to always use logical coords
1182 void wxTreeListHeaderWindow::AdjustDC(wxDC
& dc
)
1185 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1188 m_owner
->GetViewStart( &x
, NULL
);
1190 // account for the horz scrollbar offset
1191 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1195 void wxTreeListHeaderWindow::OnEraseBackground( wxEraseEvent
& event
)
1199 void wxTreeListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1202 wxClientDC
dc( this );
1204 wxPaintDC
dc( this );
1209 // width and height of the entire header window
1211 GetClientSize( &w
, &h
);
1212 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1214 dc
.SetBackground(wxBrush(GetBackgroundColour()));
1217 dc
.SetFont( GetFont() );
1218 dc
.SetBackgroundMode(wxTRANSPARENT
);
1220 // do *not* use the listctrl colour for headers - one day we will have a
1221 // function to set it separately
1222 //dc.SetTextForeground( *wxBLACK );
1223 dc
.SetTextForeground(wxSystemSettings::
1224 GetColour( wxSYS_COLOUR_WINDOWTEXT
));
1226 int x
= HEADER_OFFSET_X
;
1228 int numColumns
= GetColumnCount();
1229 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1231 if (!GetColumnShown (i
)) continue;
1233 wxTreeListColumnInfo
& column
= GetColumn(i
);
1234 int wCol
= column
.GetWidth();
1236 // the width of the rect to draw: make it smaller to fit entirely
1237 // inside the column rect
1240 dc
.SetPen( *wxWHITE_PEN
);
1242 //DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
1243 wxRendererNative::Get().DrawHeaderButton(
1244 this, dc
, wxRect(x
, HEADER_OFFSET_Y
, cw
, h
- 2),
1245 m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
);
1248 // if we have an image, draw it on the right of the label
1249 int image
= column
.GetImage(); //item.m_image;
1250 int ix
= -2, iy
= 0;
1251 wxImageList
* imageList
= m_owner
->GetImageList();
1254 imageList
->GetSize(image
, ix
, iy
);
1256 //else: ignore the column image
1261 int image_offset
= cw
- ix
- 1;
1263 switch(column
.GetAlignment()) {
1264 case wxTL_ALIGN_LEFT
:
1265 text_x
+= EXTRA_WIDTH
;
1268 case wxTL_ALIGN_RIGHT
:
1269 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1270 text_x
+= cw
- text_width
- EXTRA_WIDTH
;
1273 case wxTL_ALIGN_CENTER
:
1274 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1275 text_x
+= (cw
- text_width
)/2 + ix
+ 2;
1276 image_offset
= (cw
- text_width
- ix
- 2)/2;
1281 if(image
!= -1 && imageList
) {
1282 imageList
->Draw(image
, dc
, x
+ image_offset
/*cw - ix - 1*/,
1283 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1284 wxIMAGELIST_DRAW_TRANSPARENT
);
1287 // draw the text clipping it so that it doesn't overwrite the column
1289 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1291 dc
.DrawText( column
.GetText(),
1292 text_x
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1297 int more_w
= m_owner
->GetSize().x
- x
-1;
1300 //DoDrawRect( &dc, x, HEADER_OFFSET_Y, more_w, h-2 );
1301 wxRendererNative::Get().DrawHeaderButton(
1302 this, dc
, wxRect(x
, HEADER_OFFSET_Y
, more_w
, h
-2),
1303 m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
);
1307 void wxTreeListHeaderWindow::DrawCurrent()
1309 int x1
= m_currentX
;
1311 ClientToScreen( &x1
, &y1
);
1313 int x2
= m_currentX
-1;
1318 m_owner
->GetClientSize( NULL
, &y2
);
1319 m_owner
->ClientToScreen( &x2
, &y2
);
1322 dc
.SetLogicalFunction( wxINVERT
);
1323 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1324 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1328 dc
.DrawLine( x1
, y1
, x2
, y2
);
1330 dc
.SetLogicalFunction( wxCOPY
);
1332 dc
.SetPen( wxNullPen
);
1333 dc
.SetBrush( wxNullBrush
);
1336 void wxTreeListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1338 // we want to work with logical coords
1340 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1341 int y
= event
.GetY();
1345 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
,
1346 event
.GetPosition());
1348 // we don't draw the line beyond our window, but we allow dragging it
1351 GetClientSize( &w
, NULL
);
1352 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1355 // erase the line if it was drawn
1356 if ( m_currentX
< w
)
1359 if (event
.ButtonUp())
1362 m_isDragging
= FALSE
;
1364 SetColumnWidth( m_column
, m_currentX
- m_minX
);
1366 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
,
1367 event
.GetPosition());
1374 m_currentX
= m_minX
+ 7;
1376 // draw in the new location
1377 if ( m_currentX
< w
)
1381 else // not dragging
1384 bool hit_border
= FALSE
;
1386 // end of the current column
1389 // find the column where this event occurred
1390 int countCol
= GetColumnCount();
1391 for (int col
= 0; col
< countCol
; col
++)
1393 if (!GetColumnShown (col
)) continue;
1394 xpos
+= GetColumnWidth (col
);
1397 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1399 // near the column border
1406 // inside the column
1413 if (event
.LeftDown() || event
.RightUp())
1415 if (hit_border
&& event
.LeftDown())
1417 m_isDragging
= TRUE
;
1421 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1422 event
.GetPosition());
1424 else // click on a column
1426 SendListEvent( event
.LeftDown()
1427 ? wxEVT_COMMAND_LIST_COL_CLICK
1428 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1429 event
.GetPosition());
1432 else if (event
.Moving())
1437 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1438 m_currentCursor
= m_resizeCursor
;
1442 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1443 m_currentCursor
= wxSTANDARD_CURSOR
;
1447 SetCursor(*m_currentCursor
);
1452 void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1454 m_owner
->SetFocus();
1457 void wxTreeListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1459 wxWindow
*parent
= GetParent();
1460 wxListEvent
le( type
, parent
->GetId() );
1461 le
.SetEventObject( parent
);
1462 le
.m_pointDrag
= pos
;
1464 // the position should be relative to the parent window, not
1465 // this one for compatibility with MSW and common sense: the
1466 // user code doesn't know anything at all about this header
1467 // window, so why should it get positions relative to it?
1468 le
.m_pointDrag
.y
-= GetSize().y
;
1470 le
.m_col
= m_column
;
1471 parent
->GetEventHandler()->ProcessEvent( le
);
1474 void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo
& col
)
1477 m_total_col_width
+= col
.GetWidth();
1478 //m_owner->GetHeaderWindow()->Refresh();
1480 m_owner
->AdjustMyScrollbars();
1481 m_owner
->m_dirty
= TRUE
;
1485 void wxTreeListHeaderWindow::SetColumnWidth(size_t column
, size_t width
)
1487 if(column
< GetColumnCount()) {
1488 m_total_col_width
-= m_columns
[column
].GetWidth();
1489 m_columns
[column
].SetWidth(width
);
1490 m_total_col_width
+= width
;
1491 m_owner
->AdjustMyScrollbars();
1492 m_owner
->m_dirty
= TRUE
;
1499 void wxTreeListHeaderWindow::InsertColumn(size_t before
,
1500 const wxTreeListColumnInfo
& col
)
1502 wxCHECK_RET(before
< GetColumnCount(), wxT("Invalid column index"));
1503 m_columns
.Insert(col
, before
);
1504 m_total_col_width
+= col
.GetWidth();
1506 //m_owner->GetHeaderWindow()->Refresh();
1507 m_owner
->AdjustMyScrollbars();
1508 m_owner
->m_dirty
= TRUE
;
1512 void wxTreeListHeaderWindow::RemoveColumn(size_t column
)
1514 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1515 m_total_col_width
-= m_columns
[column
].GetWidth();
1516 m_columns
.RemoveAt(column
);
1518 m_owner
->AdjustMyScrollbars();
1519 m_owner
->m_dirty
= TRUE
;
1523 void wxTreeListHeaderWindow::SetColumn(size_t column
,
1524 const wxTreeListColumnInfo
& info
)
1526 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1527 size_t w
= m_columns
[column
].GetWidth();
1528 m_columns
[column
] = info
;
1529 //m_owner->GetHeaderWindow()->Refresh();
1531 if(w
!= info
.GetWidth()) {
1532 m_total_col_width
+= info
.GetWidth() - w
;
1533 m_owner
->AdjustMyScrollbars();
1534 m_owner
->m_dirty
= TRUE
;
1539 // ---------------------------------------------------------------------------
1541 // ---------------------------------------------------------------------------
1543 wxTreeListItem::wxTreeListItem(wxTreeListMainWindow
*owner
,
1544 wxTreeListItem
*parent
,
1545 const wxArrayString
& text
,
1546 int image
, int selImage
,
1547 wxTreeItemData
*data
)
1550 m_images
[wxTreeItemIcon_Normal
] = image
;
1551 m_images
[wxTreeItemIcon_Selected
] = selImage
;
1552 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
1553 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
1558 m_isCollapsed
= TRUE
;
1559 m_hasHilight
= FALSE
;
1567 m_attr
= (wxTreeItemAttr
*)NULL
;
1570 // We don't know the height here yet.
1575 wxTreeListItem::~wxTreeListItem()
1579 if (m_ownsAttr
) delete m_attr
;
1581 wxASSERT_MSG( m_children
.IsEmpty(),
1582 wxT("please call DeleteChildren() before deleting the item") );
1585 void wxTreeListItem::DeleteChildren(wxTreeListMainWindow
*tree
)
1587 size_t count
= m_children
.Count();
1588 for ( size_t n
= 0; n
< count
; n
++ )
1590 wxTreeListItem
*child
= m_children
[n
];
1592 tree
->SendDeleteEvent(child
);
1594 child
->DeleteChildren(tree
);
1601 void wxTreeListItem::SetText( const wxString
&text
)
1603 if(m_text
.GetCount() > 0) m_text
[0] = text
;
1609 size_t wxTreeListItem::GetChildrenCount(bool recursively
) const
1611 size_t count
= m_children
.Count();
1615 size_t total
= count
;
1616 for (size_t n
= 0; n
< count
; ++n
)
1618 total
+= m_children
[n
]->GetChildrenCount();
1624 void wxTreeListItem::GetSize( int &x
, int &y
,
1625 const wxTreeListMainWindow
*theButton
)
1627 int bottomY
=m_y
+theButton
->GetLineHeight(this);
1628 if ( y
< bottomY
) y
= bottomY
;
1629 int width
= m_x
+ m_width
;
1630 if ( x
< width
) x
= width
;
1634 size_t count
= m_children
.Count();
1635 for ( size_t n
= 0; n
< count
; ++n
)
1637 m_children
[n
]->GetSize( x
, y
, theButton
);
1642 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1643 const wxTreeListMainWindow
*theCtrl
,
1647 // for a hidden root node, don't evaluate it, but do evaluate children
1648 if (!(theCtrl
->HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)))
1650 // evaluate the item
1651 int h
= theCtrl
->GetLineHeight(this);
1652 if ((point
.y
> m_y
) && (point
.y
<= m_y
+ h
))
1654 // check for above/below middle
1655 int y_mid
= m_y
+ h
/2;
1656 if (point
.y
< y_mid
)
1657 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
1659 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
1661 // check for button hit
1662 int xCross
= m_x
; // - theCtrl->GetLineSpacing();
1664 // according to the drawing code the triangels are drawn
1665 // at -4 , -4 from the position up to +10/+10 max
1666 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
1667 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
1668 HasPlus() && theCtrl
->HasButtons() )
1670 // 5 is the size of the plus sign
1671 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
1672 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
1673 HasPlus() && theCtrl
->HasButtons() )
1676 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
1680 // check for image hit
1681 if (theCtrl
->m_imgWidth
> 0 && GetImage() != NO_IMAGE
) {
1682 int imgX
= m_x
- theCtrl
->m_imgWidth2
;
1683 if (HasPlus() && theCtrl
->HasButtons())
1684 imgX
+= theCtrl
->m_btnWidth
+ LINEATROOT
;
1685 int imgY
= y_mid
- theCtrl
->m_imgHeight2
;
1686 if ((point
.x
>= imgX
) && (point
.x
<= (imgX
+ theCtrl
->m_imgWidth
)) &&
1687 (point
.y
>= imgY
) && (point
.y
<= (imgY
+ theCtrl
->m_imgHeight
))) {
1688 flags
|= wxTREE_HITTEST_ONITEMICON
;
1693 // check for label hit
1694 int lblX
= m_x
- theCtrl
->m_imgWidth2
+ theCtrl
->m_imgWidth
+ MARGIN
;
1695 if ((point
.x
>= lblX
) && (point
.x
<= (m_x
+ m_width
)) &&
1696 (point
.y
>= m_y
) && (point
.y
<= (m_y
+ h
))) {
1697 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
1701 // else check for indent
1702 if (point
.x
< m_x
) {
1703 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
1707 // else check for item right???
1708 if (point
.x
> m_x
+ m_width
) {
1709 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
1715 // if children are expanded, fall through to evaluate them
1716 if (m_isCollapsed
) return (wxTreeListItem
*) NULL
;
1719 // evaluate children
1720 size_t count
= m_children
.Count();
1721 for ( size_t n
= 0; n
< count
; n
++ )
1723 wxTreeListItem
*res
= m_children
[n
]->HitTest(point
, theCtrl
,
1729 return (wxTreeListItem
*) NULL
;
1733 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1734 const wxTreeListMainWindow
*theCtrl
,
1735 int &flags
, int& column
, int level
)
1737 column
= theCtrl
->GetMainColumn(); //-1;
1739 wxTreeListItem
* res
= HitTest(point
, theCtrl
, flags
, level
);
1745 wxTreeListHeaderWindow
* header_win
= theCtrl
->m_owner
->GetHeaderWindow();
1746 if (point
.x
>= header_win
->GetWidth())
1748 else if(flags
& wxTREE_HITTEST_ONITEMINDENT
) {
1750 for(size_t i
= 0; i
< theCtrl
->GetMainColumn(); ++i
) {
1751 if (!header_win
->GetColumnShown(i
)) continue;
1752 int w
= header_win
->GetColumnWidth(i
);
1753 if(point
.x
>= x
&& point
.x
< x
+w
) {
1754 flags
^= wxTREE_HITTEST_ONITEMINDENT
;
1755 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1761 else if(flags
& wxTREE_HITTEST_ONITEMRIGHT
) {
1764 for(i
= 0; i
< theCtrl
->GetMainColumn()+1; ++i
) {
1765 if (!header_win
->GetColumnShown(i
)) continue;
1766 x
+= header_win
->GetColumnWidth(i
);
1768 for(i
= theCtrl
->GetMainColumn()+1; i
< theCtrl
->GetColumnCount(); ++i
) {
1769 if (!header_win
->GetColumnShown(i
)) continue;
1770 int w
= header_win
->GetColumnWidth(i
);
1771 if(point
.x
>= x
&& point
.x
< x
+w
) {
1772 flags
^= wxTREE_HITTEST_ONITEMRIGHT
;
1773 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1785 int wxTreeListItem::GetCurrentImage() const
1787 int image
= NO_IMAGE
;
1792 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
1795 if ( image
== NO_IMAGE
)
1797 // we usually fall back to the normal item, but try just the
1798 // expanded one (and not selected) first in this case
1799 image
= GetImage(wxTreeItemIcon_Expanded
);
1802 else // not expanded
1805 image
= GetImage(wxTreeItemIcon_Selected
);
1808 // maybe it doesn't have the specific image we want,
1809 // try the default one instead
1810 if ( image
== NO_IMAGE
) image
= GetImage();
1815 // ---------------------------------------------------------------------------
1816 // wxTreeListMainWindow implementation
1817 // ---------------------------------------------------------------------------
1819 IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow
, wxScrolledWindow
)
1821 BEGIN_EVENT_TABLE(wxTreeListMainWindow
, wxScrolledWindow
)
1822 EVT_PAINT (wxTreeListMainWindow::OnPaint
)
1823 EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse
)
1824 EVT_CHAR (wxTreeListMainWindow::OnChar
)
1825 EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus
)
1826 EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus
)
1827 EVT_IDLE (wxTreeListMainWindow::OnIdle
)
1828 EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll
)
1832 // ---------------------------------------------------------------------------
1833 // construction/destruction
1834 // ---------------------------------------------------------------------------
1836 void wxTreeListMainWindow::Init()
1838 m_current
= m_key_current
= m_anchor
= (wxTreeListItem
*) NULL
;
1842 m_lineHeight
= LINEHEIGHT
;
1843 m_indent
= MININDENT
; // min. indent
1845 m_imgWidth
= 0, m_imgWidth2
= 0;
1846 m_imgHeight
= 0, m_imgHeight2
= 0;
1848 m_hilightBrush
= new wxBrush
1850 wxSystemSettings::GetColour
1852 wxSYS_COLOUR_HIGHLIGHT
1857 m_hilightUnfocusedBrush
= new wxBrush
1859 wxSystemSettings::GetColour
1861 wxSYS_COLOUR_BTNSHADOW
1866 m_imageListNormal
= m_imageListButtons
=
1867 m_imageListState
= (wxImageList
*) NULL
;
1868 m_ownsImageListNormal
= m_ownsImageListButtons
=
1869 m_ownsImageListState
= FALSE
;
1872 m_isDragging
= FALSE
;
1873 m_dropTarget
= m_oldSelection
= (wxTreeListItem
*)NULL
;
1875 m_renameTimer
= new wxTreeListRenameTimer( this );
1876 m_lastOnSame
= FALSE
;
1878 m_findTimer
= new wxTimer (this, -1);
1880 m_underMouse
= NULL
;
1882 #ifdef __WXMAC_CARBON__
1883 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
1885 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
1887 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
1888 m_normalFont
.GetFamily(),
1889 m_normalFont
.GetStyle(),
1891 m_normalFont
.GetUnderlined(),
1892 m_normalFont
.GetFaceName(),
1893 m_normalFont
.GetEncoding());
1897 bool wxTreeListMainWindow::Create(wxTreeListCtrl
*parent
,
1902 const wxValidator
&validator
,
1903 const wxString
& name
)
1906 if ( !(style
& wxTR_DONT_ADJUST_MAC
))
1909 wxGetOsVersion( &major
, &minor
);
1911 if (style
& wxTR_HAS_BUTTONS
) style
|= wxTR_TWIST_BUTTONS
;
1912 if (style
& wxTR_HAS_BUTTONS
) style
&= ~wxTR_HAS_BUTTONS
;
1913 style
&= ~wxTR_LINES_AT_ROOT
;
1914 style
|= wxTR_NO_LINES
;
1916 style
|= wxTR_ROW_LINES
;
1920 wxScrolledWindow::Create( parent
, id
, pos
, size
,
1921 style
|wxHSCROLL
|wxVSCROLL
, name
);
1923 #if wxUSE_VALIDATORS
1924 SetValidator( validator
);
1927 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
) );
1934 bdc
.SelectObject(bmp
);
1935 bdc
.SetPen(*wxGREY_PEN
);
1936 bdc
.DrawRectangle(-1, -1, 10, 10);
1937 for (i
= 0; i
< 8; i
++) {
1938 for (j
= 0; j
< 8; j
++) {
1939 if (!((i
+ j
) & 1)) {
1940 bdc
.DrawPoint(i
, j
);
1945 m_dottedPen
= wxPen(bmp
, 1);
1948 //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT ); // too slow under XFree86
1949 m_dottedPen
= wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK!
1959 wxTreeListMainWindow::~wxTreeListMainWindow()
1961 delete m_hilightBrush
;
1962 delete m_hilightUnfocusedBrush
;
1966 delete m_renameTimer
;
1968 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1969 if (m_ownsImageListState
) delete m_imageListState
;
1970 if (m_ownsImageListButtons
) delete m_imageListButtons
;
1975 //-----------------------------------------------------------------------------
1977 //-----------------------------------------------------------------------------
1979 size_t wxTreeListMainWindow::GetCount() const
1981 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
1984 void wxTreeListMainWindow::SetIndent(unsigned int indent
)
1990 void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing
)
1992 m_linespacing
= spacing
;
1994 CalculateLineHeight();
1997 size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId
& item
,
2000 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
2002 return ((wxTreeListItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
2005 void wxTreeListMainWindow::SetWindowStyle(const long styles
)
2007 // right now, just sets the styles. Eventually, we may
2008 // want to update the inherited styles, but right now
2009 // none of the parents has updatable styles
2010 m_windowStyle
= styles
;
2014 //-----------------------------------------------------------------------------
2015 // functions to work with tree items
2016 //-----------------------------------------------------------------------------
2018 int wxTreeListMainWindow::GetItemImage(const wxTreeItemId
& item
, size_t column
,
2019 wxTreeItemIcon which
) const
2021 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
2023 return ((wxTreeListItem
*) item
.m_pItem
)->GetImage(column
, which
);
2026 wxTreeItemData
*wxTreeListMainWindow::GetItemData(const wxTreeItemId
& item
)
2029 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
2031 return ((wxTreeListItem
*) item
.m_pItem
)->GetData();
2034 bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId
& item
) const
2036 wxCHECK_MSG(item
.IsOk(), FALSE
, wxT("invalid tree item"));
2037 return ((wxTreeListItem
*)item
.m_pItem
)->IsBold();
2040 wxColour
wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId
& item
)
2043 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2045 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2046 return pItem
->Attr().GetTextColour();
2049 wxColour
wxTreeListMainWindow::GetItemBackgroundColour(
2050 const wxTreeItemId
& item
) const
2052 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2054 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2055 return pItem
->Attr().GetBackgroundColour();
2058 wxFont
wxTreeListMainWindow::GetItemFont(const wxTreeItemId
& item
) const
2060 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
2062 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2063 return pItem
->Attr().GetFont();
2068 void wxTreeListMainWindow::SetItemImage(const wxTreeItemId
& item
,
2070 int image
, wxTreeItemIcon which
)
2072 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2074 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2075 pItem
->SetImage(column
, image
, which
);
2077 wxClientDC
dc(this);
2078 CalculateSize(pItem
, dc
);
2082 void wxTreeListMainWindow::SetItemData(const wxTreeItemId
& item
,
2083 wxTreeItemData
*data
)
2085 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2087 ((wxTreeListItem
*) item
.m_pItem
)->SetData(data
);
2090 void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId
& item
,
2093 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2095 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2096 pItem
->SetHasPlus(has
);
2100 void wxTreeListMainWindow::SetItemBold(const wxTreeItemId
& item
, bool bold
)
2102 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2104 // avoid redrawing the tree if no real change
2105 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2106 if ( pItem
->IsBold() != bold
)
2108 pItem
->SetBold(bold
);
2113 void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId
& item
,
2114 const wxColour
& col
)
2116 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2118 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2119 pItem
->Attr().SetTextColour(col
);
2123 void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId
& item
,
2124 const wxColour
& col
)
2126 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2128 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2129 pItem
->Attr().SetBackgroundColour(col
);
2133 void wxTreeListMainWindow::SetItemFont(const wxTreeItemId
& item
,
2136 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2138 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2139 pItem
->Attr().SetFont(font
);
2143 bool wxTreeListMainWindow::SetFont( const wxFont
&font
)
2145 wxScrolledWindow::SetFont(font
);
2147 m_normalFont
= font
;
2148 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
2149 m_normalFont
.GetFamily(),
2150 m_normalFont
.GetStyle(),
2152 m_normalFont
.GetUnderlined());
2158 // ----------------------------------------------------------------------------
2159 // item status inquiries
2160 // ----------------------------------------------------------------------------
2162 bool wxTreeListMainWindow::IsVisible(const wxTreeItemId
& item
) const
2164 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2166 // An item is only visible if it's not a descendant of a collapsed item
2167 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2168 wxTreeListItem
* parent
= pItem
->GetItemParent();
2171 if (!parent
->IsExpanded())
2173 parent
= parent
->GetItemParent();
2177 GetViewStart(& startX
, & startY
);
2179 wxSize clientSize
= GetClientSize();
2182 if (!GetBoundingRect(item
, rect
))
2184 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
2186 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
2188 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
2194 bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId
& item
) const
2196 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2198 // consider that the item does have children if it has the "+" button: it
2199 // might not have them (if it had never been expanded yet) but then it
2200 // could have them as well and it's better to err on this side rather than
2201 // disabling some operations which are restricted to the items with
2202 // children for an item which does have them
2203 return ((wxTreeListItem
*) item
.m_pItem
)->HasPlus();
2206 bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId
& item
) const
2208 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2210 return ((wxTreeListItem
*) item
.m_pItem
)->IsExpanded();
2213 bool wxTreeListMainWindow::IsSelected(const wxTreeItemId
& item
) const
2215 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2217 return ((wxTreeListItem
*) item
.m_pItem
)->IsSelected();
2220 bool wxTreeListMainWindow::IsBold(const wxTreeItemId
& item
) const
2222 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2224 return ((wxTreeListItem
*) item
.m_pItem
)->IsBold();
2227 // ----------------------------------------------------------------------------
2229 // ----------------------------------------------------------------------------
2231 wxTreeItemId
wxTreeListMainWindow::GetItemParent(const wxTreeItemId
& item
) const
2233 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2235 return ((wxTreeListItem
*) item
.m_pItem
)->GetItemParent();
2238 #if !wxCHECK_VERSION(2, 5, 0)
2239 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2242 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2243 wxTreeItemIdValue
& cookie
) const
2246 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2249 return GetNextChild(item
, cookie
);
2252 #if !wxCHECK_VERSION(2, 5, 0)
2253 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2256 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2257 wxTreeItemIdValue
& cookie
) const
2260 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2262 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2264 // it's ok to cast cookie to size_t, we never have indices big enough to
2265 // overflow "void *"
2266 size_t *pIndex
= (size_t *)&cookie
;
2267 if ( *pIndex
< children
.Count() )
2269 return children
.Item((*pIndex
)++);
2273 // there are no more of them
2274 return wxTreeItemId();
2278 #if !wxCHECK_VERSION(2, 5, 0)
2279 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2282 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2283 wxTreeItemIdValue
& cookie
) const
2286 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2288 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2290 // it's ok to cast cookie to size_t, we never have indices big enough to
2291 // overflow "void *"
2292 size_t *pIndex
= (size_t *)&cookie
;
2295 return children
.Item(--(*pIndex
));
2299 // there are no more of them
2300 return wxTreeItemId();
2304 wxTreeItemId
wxTreeListMainWindow::GetLastChild(const wxTreeItemId
& item
) const
2306 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2308 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2309 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
2312 wxTreeItemId
wxTreeListMainWindow::GetNextSibling(const wxTreeItemId
& item
) const
2314 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2316 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2317 wxTreeListItem
*parent
= i
->GetItemParent();
2318 if ( parent
== NULL
)
2320 // root item doesn't have any siblings
2321 return wxTreeItemId();
2324 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2325 int index
= siblings
.Index(i
);
2326 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2328 size_t n
= (size_t)(index
+ 1);
2329 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
2332 wxTreeItemId
wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId
& item
)
2335 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2337 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2338 wxTreeListItem
*parent
= i
->GetItemParent();
2339 if ( parent
== NULL
)
2341 // root item doesn't have any siblings
2342 return wxTreeItemId();
2345 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2346 int index
= siblings
.Index(i
);
2347 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2349 return index
== 0 ? wxTreeItemId()
2350 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
2353 // Only for internal use right now, but should probably be public
2354 wxTreeItemId
wxTreeListMainWindow::GetNext(const wxTreeItemId
& item
) const
2356 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2358 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2360 // First see if there are any children.
2361 wxArrayTreeListItems
& children
= i
->GetChildren();
2362 if (children
.GetCount() > 0)
2364 return children
.Item(0);
2368 // Try a sibling of this or ancestor instead
2369 wxTreeItemId p
= item
;
2370 wxTreeItemId toFind
;
2373 toFind
= GetNextSibling(p
);
2374 p
= GetItemParent(p
);
2375 } while (p
.IsOk() && !toFind
.IsOk());
2380 wxTreeItemId
wxTreeListMainWindow::GetFirstVisibleItem() const
2382 wxTreeItemId id
= GetRootItem();
2391 } while (id
.IsOk());
2393 return wxTreeItemId();
2396 wxTreeItemId
wxTreeListMainWindow::GetNextVisible(const wxTreeItemId
& item
)
2399 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2401 wxTreeItemId id
= item
;
2404 while (id
= GetNext(id
), id
.IsOk())
2410 return wxTreeItemId();
2413 wxTreeItemId
wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId
& item
)
2416 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2418 wxFAIL_MSG(wxT("not implemented"));
2420 return wxTreeItemId();
2423 // ----------------------------------------------------------------------------
2425 // ----------------------------------------------------------------------------
2427 wxTreeItemId
wxTreeListMainWindow::DoInsertItem(const wxTreeItemId
& parentId
,
2429 const wxString
& text
,
2430 int image
, int selImage
,
2431 wxTreeItemData
*data
)
2433 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2436 // should we give a warning here?
2437 return AddRoot(text
, image
, selImage
, data
);
2440 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2444 arr
.Alloc(GetColumnCount());
2445 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2446 arr
.Add(wxEmptyString
);
2448 arr
[m_main_column
] = text
;
2449 wxTreeListItem
*item
=
2450 new wxTreeListItem( this, parent
, arr
, image
, selImage
, data
);
2454 data
->SetId((void*)item
);
2457 parent
->Insert( item
, previous
);
2462 wxTreeItemId
wxTreeListMainWindow::AddRoot(const wxString
& text
,
2463 int image
, int selImage
,
2464 wxTreeItemData
*data
)
2466 wxCHECK_MSG(!m_anchor
, wxTreeItemId(), wxT("tree can have only one root"));
2467 wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item"));
2469 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2473 arr
.Alloc(GetColumnCount());
2474 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2475 arr
.Add(wxEmptyString
);
2477 arr
[m_main_column
] = text
;
2478 m_anchor
= new wxTreeListItem( this, (wxTreeListItem
*)NULL
, arr
,
2479 image
, selImage
, data
);
2481 if (HasFlag(wxTR_HIDE_ROOT
))
2483 // if root is hidden, make sure we can navigate
2485 m_anchor
->SetHasPlus();
2491 data
->SetId((void*)m_anchor
);
2494 if (!HasFlag(wxTR_MULTIPLE
))
2496 m_current
= m_key_current
= m_anchor
;
2497 m_current
->SetHilight( TRUE
);
2503 wxTreeItemId
wxTreeListMainWindow::PrependItem(const wxTreeItemId
& parent
,
2504 const wxString
& text
,
2505 int image
, int selImage
,
2506 wxTreeItemData
*data
)
2508 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
2511 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2512 const wxTreeItemId
& idPrevious
,
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 int index
= parent
->GetChildren().Index((wxTreeListItem
*) idPrevious
.m_pItem
);
2525 wxASSERT_MSG( index
!= wxNOT_FOUND
,
2526 wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") );
2528 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
2531 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2533 const wxString
& text
,
2534 int image
, int selImage
,
2535 wxTreeItemData
*data
)
2537 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2540 // should we give a warning here?
2541 return AddRoot(text
, image
, selImage
, data
);
2544 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
2547 wxTreeItemId
wxTreeListMainWindow::AppendItem(const wxTreeItemId
& parentId
,
2548 const wxString
& text
,
2549 int image
, int selImage
,
2550 wxTreeItemData
*data
)
2552 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2555 // should we give a warning here?
2556 return AddRoot(text
, image
, selImage
, data
);
2559 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
2560 image
, selImage
, data
);
2563 void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem
*item
)
2565 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, m_owner
->GetId() );
2566 event
.SetItem((void*)item
);
2567 event
.SetEventObject( /*this*/m_owner
);
2568 m_owner
->ProcessEvent( event
);
2571 void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId
& itemId
)
2573 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2575 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2576 item
->DeleteChildren(this);
2579 void wxTreeListMainWindow::Delete(const wxTreeItemId
& itemId
)
2581 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2583 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2585 // don't stay with invalid m_key_current or we will crash in
2586 // the next call to OnChar()
2587 bool changeKeyCurrent
= FALSE
;
2588 wxTreeListItem
*itemKey
= m_key_current
;
2591 if ( itemKey
== item
)
2593 // m_key_current is a descendant of the item being deleted
2594 changeKeyCurrent
= TRUE
;
2597 itemKey
= itemKey
->GetItemParent();
2600 wxTreeListItem
*parent
= item
->GetItemParent();
2603 parent
->GetChildren().Remove( item
); // remove by value
2606 if ( changeKeyCurrent
)
2608 // may be NULL or not
2609 m_key_current
= parent
;
2612 item
->DeleteChildren(this);
2613 SendDeleteEvent(item
);
2617 void wxTreeListMainWindow::DeleteAllItems()
2623 m_anchor
->DeleteChildren(this);
2630 void wxTreeListMainWindow::Expand(const wxTreeItemId
& itemId
)
2632 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2634 wxCHECK_RET( item
, _T("invalid item in wxTreeListMainWindow::Expand") );
2636 if ( !item
->HasPlus() )
2639 if ( item
->IsExpanded() )
2642 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, m_owner
->GetId() );
2643 event
.SetItem( (void*)item
);
2644 event
.SetEventObject( /*this*/m_owner
);
2646 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2648 // cancelled by program
2653 CalculatePositions();
2655 RefreshSubtree(item
);
2657 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
2658 ProcessEvent( event
);
2661 void wxTreeListMainWindow::ExpandAll(const wxTreeItemId
& item
)
2664 if ( IsExpanded(item
) )
2666 #if !wxCHECK_VERSION(2, 5, 0)
2669 wxTreeItemIdValue cookie
;
2671 wxTreeItemId child
= GetFirstChild(item
, cookie
);
2672 while ( child
.IsOk() )
2676 child
= GetNextChild(item
, cookie
);
2681 void wxTreeListMainWindow::Collapse(const wxTreeItemId
& itemId
)
2683 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2685 if ( !item
->IsExpanded() )
2688 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, m_owner
->GetId() );
2689 event
.SetItem( (void*)item
);
2690 event
.SetEventObject( /*this*/m_owner
);
2691 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2693 // cancelled by program
2699 #if 0 // TODO why should items be collapsed recursively?
2700 wxArrayTreeListItems
& children
= item
->GetChildren();
2701 size_t count
= children
.Count();
2702 for ( size_t n
= 0; n
< count
; n
++ )
2704 Collapse(children
[n
]);
2708 CalculatePositions();
2710 RefreshSubtree(item
);
2712 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
2713 ProcessEvent( event
);
2716 void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId
& item
)
2719 DeleteChildren(item
);
2722 void wxTreeListMainWindow::Toggle(const wxTreeItemId
& itemId
)
2724 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2726 if (item
->IsExpanded())
2732 void wxTreeListMainWindow::Unselect()
2736 m_current
->SetHilight( FALSE
);
2737 RefreshLine( m_current
);
2741 void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem
*item
)
2743 if (item
->IsSelected())
2745 item
->SetHilight(FALSE
);
2749 if (item
->HasChildren())
2751 wxArrayTreeListItems
& children
= item
->GetChildren();
2752 size_t count
= children
.Count();
2753 for ( size_t n
= 0; n
< count
; ++n
)
2755 UnselectAllChildren(children
[n
]);
2760 void wxTreeListMainWindow::UnselectAll()
2762 UnselectAllChildren((wxTreeListItem
*)GetRootItem().m_pItem
);
2765 // Recursive function !
2766 // To stop we must have crt_item<last_item
2768 // Tag all next children, when no more children,
2769 // Move to parent (not to tag)
2770 // Keep going... if we found last_item, we stop.
2771 bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2773 wxTreeListItem
*parent
= crt_item
->GetItemParent();
2775 if (parent
== NULL
) // This is root item
2776 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
2778 wxArrayTreeListItems
& children
= parent
->GetChildren();
2779 int index
= children
.Index(crt_item
);
2780 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2782 size_t count
= children
.Count();
2783 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
2785 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
2788 return TagNextChildren(parent
, last_item
, select
);
2791 bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2793 crt_item
->SetHilight(select
);
2794 RefreshLine(crt_item
);
2796 if (crt_item
==last_item
)
2799 if (crt_item
->HasChildren())
2801 wxArrayTreeListItems
& children
= crt_item
->GetChildren();
2802 size_t count
= children
.Count();
2803 for ( size_t n
= 0; n
< count
; ++n
)
2805 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
2813 void wxTreeListMainWindow::SelectItemRange(wxTreeListItem
*item1
, wxTreeListItem
*item2
)
2815 // item2 is not necessary after item1
2816 wxTreeListItem
*first
=NULL
, *last
=NULL
;
2818 // choice first' and 'last' between item1 and item2
2819 if (item1
->GetY()<item2
->GetY())
2830 bool select
= m_current
->IsSelected();
2832 if ( TagAllChildrenUntilLast(first
,last
,select
) )
2835 TagNextChildren(first
,last
,select
);
2838 void wxTreeListMainWindow::SelectItem(const wxTreeItemId
& itemId
,
2839 bool unselect_others
,
2840 bool extended_select
)
2842 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2844 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
2845 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2847 //wxCHECK_RET( ( (!unselect_others) && is_single),
2848 // wxT("this is a single selection tree") );
2850 // to keep going anyhow !!!
2853 if (item
->IsSelected())
2854 return; // nothing to do
2855 unselect_others
= TRUE
;
2856 extended_select
= FALSE
;
2858 else if ( unselect_others
&& item
->IsSelected() )
2860 // selection change if there is more than one item currently selected
2861 wxArrayTreeItemIds selected_items
;
2862 if ( GetSelections(selected_items
) == 1 )
2866 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2867 event
.SetItem( (void*)item
);
2868 event
.SetOldItem( (void*)m_current
);
2869 event
.SetEventObject( /*this*/m_owner
);
2870 // TODO : Here we don't send any selection mode yet !
2872 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2875 wxTreeItemId parent
= GetItemParent( itemId
);
2876 while (parent
.IsOk())
2878 if (!IsExpanded(parent
))
2881 parent
= GetItemParent( parent
);
2884 EnsureVisible( itemId
);
2887 if (unselect_others
)
2889 if (is_single
) Unselect(); // to speed up thing
2894 if (extended_select
)
2898 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
2901 // don't change the mark (m_current)
2902 SelectItemRange(m_current
, item
);
2906 bool select
=TRUE
; // the default
2908 // Check if we need to toggle hilight (ctrl mode)
2909 if (!unselect_others
)
2910 select
=!item
->IsSelected();
2912 m_current
= m_key_current
= item
;
2913 m_current
->SetHilight(select
);
2914 RefreshLine( m_current
);
2917 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2918 GetEventHandler()->ProcessEvent( event
);
2921 void wxTreeListMainWindow::SelectAll(bool extended_select
)
2923 wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE
, wxT("invalid tree style, must have wxTR_MULTIPLE style to select all items") );
2925 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2926 event
.SetItem( GetRootItem() );
2927 event
.SetOldItem( (void*) m_current
);
2928 event
.SetEventObject( /*this*/m_owner
);
2929 // TODO : Here we don't send any selection mode yet !
2931 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2935 if (!extended_select
)
2943 #if !wxCHECK_VERSION(2, 5, 0)
2946 wxTreeItemIdValue cookie
= 0;
2948 wxTreeItemId root
= GetRootItem();
2949 wxTreeListItem
*first
= (wxTreeListItem
*)GetFirstChild (root
, cookie
).m_pItem
;
2950 wxTreeListItem
*last
= (wxTreeListItem
*)GetLastChild (GetRootItem()).m_pItem
;
2951 if (!first
|| !last
) return;
2952 if (TagAllChildrenUntilLast (first
, last
, true)) return;
2953 TagNextChildren (first
, last
, true);
2955 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2956 GetEventHandler()->ProcessEvent( event
);
2959 void wxTreeListMainWindow::FillArray(wxTreeListItem
*item
,
2960 wxArrayTreeItemIds
&array
) const
2962 if ( item
->IsSelected() )
2963 array
.Add(wxTreeItemId(item
));
2965 if ( item
->HasChildren() )
2967 wxArrayTreeListItems
& children
= item
->GetChildren();
2968 size_t count
= children
.GetCount();
2969 for ( size_t n
= 0; n
< count
; ++n
)
2970 FillArray(children
[n
], array
);
2974 size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds
&array
) const
2977 wxTreeItemId idRoot
= GetRootItem();
2978 if ( idRoot
.IsOk() )
2980 FillArray((wxTreeListItem
*) idRoot
.m_pItem
, array
);
2982 //else: the tree is empty, so no selections
2984 return array
.Count();
2987 void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId
& item
)
2989 if (!item
.IsOk()) return;
2991 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2993 // first expand all parent branches
2994 wxTreeListItem
*parent
= gitem
->GetItemParent();
2998 parent
= parent
->GetItemParent();
3001 //if (parent) CalculatePositions();
3006 void wxTreeListMainWindow::ScrollTo(const wxTreeItemId
&item
)
3008 if (!item
.IsOk()) return;
3010 // We have to call this here because the label in
3011 // question might just have been added and no screen
3012 // update taken place.
3014 DoDirtyProcessing();
3016 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
3018 // now scroll to the item
3019 int item_y
= gitem
->GetY();
3023 GetViewStart( &start_x
, &start_y
);
3024 start_y
*= PIXELS_PER_UNIT
;
3028 GetClientSize( &client_w
, &client_h
);
3030 if (item_y
< start_y
+3)
3035 m_anchor
->GetSize( x
, y
, this );
3036 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3037 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3038 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3039 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3040 // Item should appear at top
3041 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
3043 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
3048 m_anchor
->GetSize( x
, y
, this );
3049 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3050 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3051 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3052 item_y
+= PIXELS_PER_UNIT
+2;
3053 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3054 // Item should appear at bottom
3055 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
);
3059 // FIXME: tree sorting functions are not reentrant and not MT-safe!
3060 static wxTreeListMainWindow
*s_treeBeingSorted
= NULL
;
3062 static int LINKAGEMODE
tree_ctrl_compare_func(wxTreeListItem
**item1
,
3063 wxTreeListItem
**item2
)
3065 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") );
3067 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
3070 int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId
& item1
,
3071 const wxTreeItemId
& item2
)
3073 // ALB: delegate to m_owner, to let the user overrride the comparison
3074 //return wxStrcmp(GetItemText(item1), GetItemText(item2));
3075 return m_owner
->OnCompareItems(item1
, item2
);
3078 void wxTreeListMainWindow::SortChildren(const wxTreeItemId
& itemId
)
3080 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
3082 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
3084 wxCHECK_RET( !s_treeBeingSorted
,
3085 wxT("wxTreeListMainWindow::SortChildren is not reentrant") );
3087 wxArrayTreeListItems
& children
= item
->GetChildren();
3088 if ( children
.Count() > 1 )
3092 s_treeBeingSorted
= this;
3093 children
.Sort(tree_ctrl_compare_func
);
3094 s_treeBeingSorted
= NULL
;
3096 //else: don't make the tree dirty as nothing changed
3099 wxTreeItemId
wxTreeListMainWindow::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
) {
3100 #if !wxCHECK_VERSION(2, 5, 0)
3103 wxTreeItemIdValue cookie
= 0;
3105 wxTreeItemId next
= item
;
3106 if (!next
.IsOk()) next
= GetSelection();
3108 if (HasFlag(wxTR_HIDE_ROOT
)) {
3109 next
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3111 next
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3114 if (!next
.IsOk()) return item
;
3116 // start checking the next items
3118 while (next
.IsOk()) {
3119 itemText
= GetItemText (next
);
3120 if (flags
& wxTL_SEARCH_LEVEL
) {
3121 next
= GetNextSibling (next
);
3122 }else if (flags
& wxTL_SEARCH_FULL
) {
3123 wxTreeItemId n
= GetFirstChild (next
, cookie
);
3125 n
= GetNextSibling (next
);
3127 n
= GetNextSibling (GetItemParent (next
));
3129 }else{ // wxTL_SEARCH_VISIBLE
3130 next
= GetNextVisible (next
);
3132 if (!next
.IsOk()) break; // done
3133 if (flags
& wxTL_SEARCH_PARTIAL
) {
3134 itemText
= GetItemText (next
).Mid (0, str
.Length());
3136 itemText
= GetItemText (next
);
3138 if (flags
& wxTL_SEARCH_NOCASE
) {
3139 if (itemText
.CmpNoCase (str
) == 0) return next
;
3141 if (itemText
.Cmp (str
) == 0) return next
;
3147 wxImageList
*wxTreeListMainWindow::GetImageList() const
3149 return m_imageListNormal
;
3152 wxImageList
*wxTreeListMainWindow::GetButtonsImageList() const
3154 return m_imageListButtons
;
3157 wxImageList
*wxTreeListMainWindow::GetStateImageList() const
3159 return m_imageListState
;
3162 void wxTreeListMainWindow::CalculateLineHeight()
3164 wxClientDC
dc(this);
3165 dc
.SetFont( m_normalFont
);
3166 m_lineHeight
= (int)(dc
.GetCharHeight() + m_linespacing
);
3168 if ( m_imageListNormal
)
3170 // Calculate a m_lineHeight value from the normal Image sizes.
3171 // May be toggle off. Then wxTreeListMainWindow will spread when
3172 // necessary (which might look ugly).
3173 int n
= m_imageListNormal
->GetImageCount();
3174 for (int i
= 0; i
< n
; i
++)
3176 int width
= 0, height
= 0;
3177 m_imageListNormal
->GetSize(i
, width
, height
);
3178 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3182 if (m_imageListButtons
)
3184 // Calculate a m_lineHeight value from the Button image sizes.
3185 // May be toggle off. Then wxTreeListMainWindow will spread when
3186 // necessary (which might look ugly).
3187 int n
= m_imageListButtons
->GetImageCount();
3188 for (int i
= 0; i
< n
; i
++)
3190 int width
= 0, height
= 0;
3191 m_imageListButtons
->GetSize(i
, width
, height
);
3192 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3196 /*? FIXME: Don't get what this code is for... Adding a line space is already done!!!
3197 if (m_lineHeight < 30)
3198 m_lineHeight += 2; // at least 2 pixels
3200 m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing
3204 void wxTreeListMainWindow::SetImageList(wxImageList
*imageList
)
3206 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3207 m_imageListNormal
= imageList
;
3208 m_ownsImageListNormal
= FALSE
;
3210 CalculateLineHeight();
3213 void wxTreeListMainWindow::SetStateImageList(wxImageList
*imageList
)
3215 if (m_ownsImageListState
) delete m_imageListState
;
3216 m_imageListState
= imageList
;
3217 m_ownsImageListState
= FALSE
;
3220 void wxTreeListMainWindow::SetButtonsImageList(wxImageList
*imageList
)
3222 if (m_ownsImageListButtons
) delete m_imageListButtons
;
3223 m_imageListButtons
= imageList
;
3224 m_ownsImageListButtons
= FALSE
;
3226 CalculateLineHeight();
3229 void wxTreeListMainWindow::AssignImageList(wxImageList
*imageList
)
3231 SetImageList(imageList
);
3232 m_ownsImageListNormal
= TRUE
;
3235 void wxTreeListMainWindow::AssignStateImageList(wxImageList
*imageList
)
3237 SetStateImageList(imageList
);
3238 m_ownsImageListState
= TRUE
;
3241 void wxTreeListMainWindow::AssignButtonsImageList(wxImageList
*imageList
)
3243 SetButtonsImageList(imageList
);
3244 m_ownsImageListButtons
= TRUE
;
3247 // ----------------------------------------------------------------------------
3249 // ----------------------------------------------------------------------------
3251 void wxTreeListMainWindow::AdjustMyScrollbars()
3256 m_anchor
->GetSize( x
, y
, this );
3257 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3258 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3259 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3260 int y_pos
= GetScrollPos( wxVERTICAL
);
3261 x
= m_owner
->GetHeaderWindow()->GetWidth() + 2;
3262 if(x
< GetClientSize().GetWidth()) x_pos
= 0;
3263 //m_total_col_width + 2; // ALB
3264 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
,
3265 y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
3269 SetScrollbars( 0, 0, 0, 0 );
3273 int wxTreeListMainWindow::GetLineHeight(wxTreeListItem
*item
) const
3275 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
3276 return item
->GetHeight();
3278 return m_lineHeight
;
3281 void wxTreeListMainWindow::PaintItem(wxTreeListItem
*item
, wxDC
& dc
)
3283 wxTreeItemAttr
*attr
= item
->GetAttributes();
3284 if (attr
&& attr
->HasFont()) {
3285 dc
.SetFont(attr
->GetFont());
3286 }else if (item
->IsBold()) {
3287 dc
.SetFont(m_boldFont
);
3290 if (attr
&& attr
->HasTextColour()) {
3291 colText
= attr
->GetTextColour();
3293 colText
= GetForegroundColour();
3296 dc
.SetPen(*wxTRANSPARENT_PEN
);
3298 long text_w
= 0, text_h
= 0;
3300 dc
.GetTextExtent( item
->GetText(GetMainColumn()), &text_w
, &text_h
);
3302 int total_h
= GetLineHeight(item
);
3304 if (item
->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT
)) {
3305 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3306 dc
.SetPen(*wxBLACK_PEN
);
3307 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3310 if (attr
&& attr
->HasBackgroundColour()) {
3311 colBg
= attr
->GetBackgroundColour();
3313 colBg
= GetBackgroundColour();
3315 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
3318 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
3319 dc
.DrawRectangle(0, item
->GetY() + offset
,
3320 m_owner
->GetHeaderWindow()->GetWidth(), total_h
-offset
);
3322 dc
.SetBackgroundMode(wxTRANSPARENT
);
3323 int text_extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
3324 int img_extraH
= (total_h
> m_imgHeight
)? (total_h
-m_imgHeight
)/2: 0;
3326 for ( size_t i
= 0; i
< GetColumnCount(); ++i
) {
3327 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3328 int colwidth
= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
3332 if (i
== GetMainColumn()) {
3333 image
= item
->GetCurrentImage();
3334 if (item
->HasPlus()) {
3335 image_x
= item
->GetX() + (m_btnWidth
-m_btnWidth2
) + LINEATROOT
;
3337 image_x
= item
->GetX() - m_imgWidth2
;
3342 image
= item
->GetImage(i
);
3343 image_x
= x_colstart
+ MARGIN
;
3345 if (image
!= NO_IMAGE
) image_w
= m_imgWidth
+ MARGIN
;
3347 // honor text alignment
3348 wxString text
= item
->GetText(i
);
3349 switch ( m_owner
->GetHeaderWindow()->GetColumn(i
).GetAlignment() ) {
3350 case wxTL_ALIGN_LEFT
:
3351 // already left aligned
3353 case wxTL_ALIGN_RIGHT
:
3354 dc
.GetTextExtent(text
, &text_w
, NULL
);
3355 image_x
= x_colstart
+ colwidth
- (image_w
+ text_w
+ MARGIN
);
3357 case wxTL_ALIGN_CENTER
:
3358 dc
.GetTextExtent(text
, &text_w
, NULL
);
3359 int w
= colwidth
- image_w
- text_w
;
3360 image_x
= x_colstart
+ (w
> 0)? w
: 0;
3363 int text_x
= image_x
+ image_w
;
3365 if (item
->IsSelected() && (i
==GetMainColumn()) && !HasFlag(wxTR_FULL_ROW_HIGHLIGHT
))
3367 dc
.SetPen(*wxBLACK_PEN
);
3368 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3369 int offset
= HasFlag (wxTR_ROW_LINES
) ? 1 : 0;
3370 int width
= wxMin(text_w
+2, colwidth
- text_x
- x_colstart
);
3371 dc
.DrawRectangle(text_x
-1, item
->GetY() + offset
, width
, total_h
-offset
);
3372 dc
.SetBackgroundMode(wxTRANSPARENT
);
3373 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
3375 dc
.SetTextForeground(colText
);
3378 wxDCClipper
clipper (dc
, x_colstart
, item
->GetY(), colwidth
, total_h
);
3379 if (image
!= NO_IMAGE
)
3381 int image_y
= item
->GetY() + img_extraH
;
3382 m_imageListNormal
->Draw ( image
, dc
, image_x
, image_y
,
3383 wxIMAGELIST_DRAW_TRANSPARENT
);
3385 int text_y
= item
->GetY() + text_extraH
;
3386 dc
.DrawText ( text
, (wxCoord
)text_x
, (wxCoord
)text_y
);
3388 x_colstart
+= colwidth
;
3391 // restore normal font
3392 dc
.SetFont( m_normalFont
);
3395 // Now y stands for the top of the item, whereas it used to stand for middle !
3396 void wxTreeListMainWindow::PaintLevel (wxTreeListItem
*item
, wxDC
&dc
,
3397 int level
, int &y
, int x_colstart
)
3399 // Handle hide root (only level 0)
3400 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) {
3401 // always expand hidden root
3402 wxArrayTreeListItems
& children
= item
->GetChildren();
3404 for (n
= 0; n
< (int)children
.Count(); n
++) {
3405 PaintLevel (children
[n
], dc
, 1, y
, x_colstart
);
3407 // end after expanding root
3411 // calculate position of vertical lines
3412 int x
= x_colstart
+ MARGIN
; // start of column
3413 if (HasFlag (wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
3415 x
+= m_btnWidth2
; // middle of button
3417 if (m_imgWidth
> 0) x
+= m_imgWidth2
; // middle of image
3419 if (!HasFlag (wxTR_HIDE_ROOT
)) {
3420 x
+= m_indent
* level
; // indent according to level
3422 if (level
> 0) x
+= m_indent
* (level
-1); // but not level 1
3425 // handle column text
3429 int h
= GetLineHeight(item
);
3431 int y_mid
= y_top
+ (h
/2);
3434 int exposed_x
= dc
.LogicalToDeviceX(0);
3435 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
3437 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
3440 PaintItem(item
, dc
);
3442 if (HasFlag(wxTR_ROW_LINES
))
3444 //dc.DestroyClippingRegion();
3445 int total_width
= m_owner
->GetHeaderWindow()->GetWidth();
3446 // if the background colour is white, choose a
3447 // contrasting color for the lines
3448 dc
.SetPen(((GetBackgroundColour() == *wxWHITE
) ?
3449 wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
) : *wxWHITE_PEN
));
3450 dc
.DrawLine(0, y_top
, total_width
, y_top
);
3451 dc
.DrawLine(0, y
, total_width
, y
);
3454 // restore DC objects
3455 dc
.SetBrush(*wxWHITE_BRUSH
);
3456 dc
.SetPen(m_dottedPen
);
3458 if (((level
== 0) || ((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) &&
3459 HasFlag(wxTR_LINES_AT_ROOT
) && !HasFlag(wxTR_NO_LINES
)) {
3460 int rootPos
= x_colstart
+ MARGIN
;
3461 dc
.DrawLine (rootPos
, y_mid
, rootPos
+LINEATROOT
, y_mid
);
3464 size_t clip_width
= m_owner
->GetHeaderWindow()->
3465 GetColumn(m_main_column
).GetWidth();
3467 if (item
->HasPlus() && HasButtons()) // should the item show a button?
3469 // clip to the column width
3470 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3472 if ( !HasFlag(wxTR_NO_LINES
) )
3474 // draw the horizontal line here
3476 if (x
> (signed)m_indent
)
3477 x_start
-= m_indent
;
3478 else if (HasFlag(wxTR_LINES_AT_ROOT
))
3480 dc
.DrawLine(x_start
, y_mid
, x
/*+ m_spacing*/, y_mid
);
3483 if (m_imageListButtons
!= NULL
)
3485 // draw the image button here
3486 int image
= wxTreeItemIcon_Normal
;
3487 if (item
->IsExpanded()) image
= wxTreeItemIcon_Expanded
;
3488 if (item
->IsSelected())
3489 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
3490 int xx
= x
+ m_btnWidth2
;
3491 int yy
= y_mid
- m_btnHeight2
;
3492 dc
.SetClippingRegion(xx
, yy
, m_btnWidth
, m_btnHeight
);
3493 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
3494 wxIMAGELIST_DRAW_TRANSPARENT
);
3495 dc
.DestroyClippingRegion();
3497 else // no custom buttons
3499 static const int wImage
= 9;
3500 static const int hImage
= 9;
3503 if (item
->IsExpanded())
3504 flag
|= wxCONTROL_EXPANDED
;
3505 if (item
== m_underMouse
)
3506 flag
|= wxCONTROL_CURRENT
;
3508 wxRendererNative::Get().DrawTreeItemButton(
3510 wxRect(x
- wImage
/2, y_mid
- hImage
/2, wImage
, hImage
),
3514 if (!HasFlag(wxTR_NO_LINES
)) {
3515 if (/*!(level == 0) &&*/ !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3516 if (m_imgWidth
> 0) {
3517 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_indent
-m_imgWidth2
, y_mid
);
3519 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_btnWidth2
+LINEATROOT
-MARGIN
, y_mid
);
3524 else if (!HasFlag(wxTR_NO_LINES
)) // no button; maybe a line?
3526 // clip to the column width
3527 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3529 // draw the horizontal line here
3530 if (/*!(level == 0) &&*/ !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3531 int x2
= x
- m_indent
;
3532 if (m_imgWidth
> 0) {
3533 dc
.DrawLine(x2
, y_mid
, x2
+m_indent
-m_imgWidth2
, y_mid
);
3535 dc
.DrawLine(x2
, y_mid
, x2
+m_btnWidth2
+LINEATROOT
+MARGIN
, y_mid
);
3541 // restore DC objects
3542 dc
.SetBrush(*wxWHITE_BRUSH
);
3543 dc
.SetPen(m_dottedPen
);
3544 dc
.SetTextForeground(*wxBLACK
);
3546 if (item
->IsExpanded())
3548 wxArrayTreeListItems
& children
= item
->GetChildren();
3549 int count
= children
.Count();
3552 // paint sublevel items first
3553 for (n
=0; n
<count
; ++n
) {
3555 PaintLevel(children
[n
], dc
, level
+1, y
, x_colstart
);
3558 // then draw the connecting lines
3559 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
3561 // clip to the column width
3562 size_t clip_width
= m_owner
->GetHeaderWindow()->GetColumn(m_main_column
).GetWidth();
3563 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3565 // draw line down to last child
3566 oldY
+= GetLineHeight(children
[n
-1]) >> 1;
3567 if (HasButtons()) y_mid
+= 5;
3568 dc
.DrawLine(x
, y_mid
, x
, oldY
);
3573 void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem
*item
)
3577 if ( item
->HasPlus() )
3579 // it's a folder, indicate it by a border
3584 // draw a line under the drop target because the item will be
3586 DrawLine(item
, TRUE
/* below */);
3589 SetCursor(wxCURSOR_BULLSEYE
);
3594 SetCursor(wxCURSOR_NO_ENTRY
);
3598 void wxTreeListMainWindow::DrawBorder(const wxTreeItemId
&item
)
3600 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3602 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3604 wxClientDC
dc(this);
3606 dc
.SetLogicalFunction(wxINVERT
);
3607 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3609 int w
= i
->GetWidth() + 2;
3610 int h
= GetLineHeight(i
) + 2;
3612 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
3615 void wxTreeListMainWindow::DrawLine(const wxTreeItemId
&item
, bool below
)
3617 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3619 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3621 wxClientDC
dc(this);
3623 dc
.SetLogicalFunction(wxINVERT
);
3629 y
+= GetLineHeight(i
) - 1;
3632 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
3635 // ----------------------------------------------------------------------------
3636 // wxWindows callbacks
3637 // ----------------------------------------------------------------------------
3639 void wxTreeListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3645 if(!GetColumnCount()) return; // ALB
3650 // calculate button size
3651 m_btnWidth
= 0, m_btnWidth2
= 0;
3652 m_btnHeight
= 0, m_btnHeight2
= 0;
3653 if (m_imageListButtons
) {
3654 m_imageListButtons
->GetSize (0, m_btnWidth
, m_btnHeight
);
3655 }else if (HasButtons()) {
3656 m_btnWidth
= BTNWIDTH
;
3657 m_btnHeight
= BTNHEIGHT
;
3659 m_btnWidth2
= m_btnWidth
/2;
3660 m_btnHeight2
= m_btnHeight
/2;
3662 // calculate image size
3663 m_imgWidth
= 0, m_imgWidth2
= 0;
3664 m_imgHeight
= 0, m_imgHeight2
= 0;
3665 if (m_imageListNormal
) {
3666 m_imageListNormal
->GetSize (0, m_imgWidth
, m_imgHeight
);
3667 m_imgWidth
+= 4; //? ToDo: Why + 4?
3669 m_imgWidth2
= m_imgWidth
/2;
3670 m_imgHeight2
= m_imgHeight
/2;
3672 // calculate indent size
3673 int btnIndent
= HasButtons()? m_btnWidth
+ LINEATROOT
: 0;
3674 m_indent
= wxMax (MININDENT
, wxMax (m_imgWidth
, btnIndent
)) + MARGIN
;
3676 // set default values
3677 dc
.SetFont( m_normalFont
);
3678 dc
.SetPen( m_dottedPen
);
3680 // this is now done dynamically
3681 //if(GetImageList() == NULL)
3682 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3684 // calculate column start and paint
3687 for (i
= 0; i
< (int)GetMainColumn(); ++i
) {
3688 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3689 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth (i
);
3692 PaintLevel ( m_anchor
, dc
, 0, y
, x_colstart
);
3695 void wxTreeListMainWindow::OnSetFocus( wxFocusEvent
&event
)
3704 void wxTreeListMainWindow::OnKillFocus( wxFocusEvent
&event
)
3713 void wxTreeListMainWindow::OnChar( wxKeyEvent
&event
)
3715 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, m_owner
->GetId() );
3716 te
.SetKeyEvent( event
);
3717 te
.SetEventObject( /*this*/m_owner
);
3718 if ( m_owner
->GetEventHandler()->ProcessEvent( te
) )
3720 // intercepted by the user code
3726 if (HasFlag(wxTR_HIDE_ROOT
)) {
3727 #if !wxCHECK_VERSION(2, 5, 0)
3730 wxTreeItemIdValue cookie
= 0;
3732 m_current
= m_key_current
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3736 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3740 // how should the selection work for this event?
3741 bool is_multiple
, extended_select
, unselect_others
;
3742 EventFlagsToSelType(GetWindowStyleFlag(),
3744 event
.ControlDown(),
3745 is_multiple
, extended_select
, unselect_others
);
3747 // + : Expand (not on Win32)
3748 // - : Collaspe (not on Win32)
3749 // * : Expand all/Collapse all
3750 // ' ' | return : activate
3751 // up : go up (not last children!)
3753 // left : go to parent (or collapse on Win32)
3754 // right : open if parent and go next (or expand on Win32)
3755 // home : go to root
3756 // end : go to last item without opening parents
3757 switch (event
.GetKeyCode())
3759 #ifndef __WXMSW__ // mimic the standard win32 tree ctrl
3762 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3771 if ( !IsExpanded(m_current
) )
3774 ExpandAll (m_current
);
3777 //else: fall through to Collapse() it
3779 #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour
3782 if (IsExpanded(m_current
))
3784 Collapse (m_current
);
3792 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
3794 event
.SetItem( (void*) m_current
);
3795 event
.SetEventObject( /*this*/m_owner
);
3796 m_owner
->GetEventHandler()->ProcessEvent( event
);
3800 // backspace goes to the parent, sends "root" activation
3803 wxTreeItemId prev
= GetItemParent( m_current
);
3804 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3806 // don't go to root if it is hidden
3807 prev
= GetPrevSibling( m_current
);
3811 SelectItem( prev
, unselect_others
, extended_select
);
3812 EnsureVisible( prev
);
3817 // up goes to the previous sibling or to the last
3818 // of its children if it's expanded
3821 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
3824 prev
= GetItemParent( m_key_current
);
3825 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3827 break; // don't go to root if it is hidden
3831 #if !wxCHECK_VERSION(2, 5, 0)
3834 wxTreeItemIdValue cookie
= 0;
3836 wxTreeItemId current
= m_key_current
;
3837 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
3838 if (current
== GetFirstChild( prev
, cookie
))
3840 // otherwise we return to where we came from
3841 SelectItem( prev
, unselect_others
, extended_select
);
3842 m_key_current
= (wxTreeListItem
*) prev
.m_pItem
;
3843 EnsureVisible( prev
);
3850 while ( IsExpanded(prev
) && HasChildren(prev
) )
3852 wxTreeItemId child
= GetLastChild(prev
);
3860 SelectItem( prev
, unselect_others
, extended_select
);
3861 m_key_current
=(wxTreeListItem
*) prev
.m_pItem
;
3862 EnsureVisible( prev
);
3867 // left arrow goes to the parent
3869 if (IsExpanded(m_current
))
3871 Collapse(m_current
);
3875 wxTreeItemId prev
= GetItemParent( m_current
);
3876 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3878 // don't go to root if it is hidden
3879 prev
= GetPrevSibling( m_current
);
3883 SelectItem( prev
, unselect_others
, extended_select
);
3884 EnsureVisible( prev
);
3890 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl
3891 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3898 // this works the same as the down arrow except that we
3899 // also expand the item if it wasn't expanded yet
3905 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
3907 #if !wxCHECK_VERSION(2, 5, 0)
3910 wxTreeItemIdValue cookie
= 0;
3912 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
3914 SelectItem( child
, unselect_others
, extended_select
);
3915 m_key_current
=(wxTreeListItem
*) child
.m_pItem
;
3916 EnsureVisible( child
);
3920 wxTreeItemId next
= GetNextSibling( m_key_current
);
3923 wxTreeItemId current
= m_key_current
;
3924 while (current
&& !next
)
3926 current
= GetItemParent( current
);
3927 if (current
) next
= GetNextSibling( current
);
3932 SelectItem( next
, unselect_others
, extended_select
);
3933 m_key_current
=(wxTreeListItem
*) next
.m_pItem
;
3934 EnsureVisible( next
);
3939 // <End> selects the last visible tree item
3942 wxTreeItemId last
= GetRootItem();
3944 while ( last
.IsOk() && IsExpanded(last
) )
3946 wxTreeItemId lastChild
= GetLastChild(last
);
3948 // it may happen if the item was expanded but then all of
3949 // its children have been deleted - so IsExpanded() returned
3950 // TRUE, but GetLastChild() returned invalid item
3959 SelectItem( last
, unselect_others
, extended_select
);
3960 EnsureVisible( last
);
3965 // <Home> selects the root item
3968 wxTreeItemId prev
= GetRootItem();
3970 if (HasFlag(wxTR_HIDE_ROOT
))
3972 #if !wxCHECK_VERSION(2, 5, 0)
3975 wxTreeItemIdValue cookie
= 0;
3977 prev
= GetFirstChild(prev
, cookie
);
3980 SelectItem( prev
, unselect_others
, extended_select
);
3981 EnsureVisible( prev
);
3986 if (event
.m_keyCode
>= (int)' ') {
3987 if (!m_findTimer
->IsRunning()) m_findStr
.Clear();
3988 m_findStr
.Append (event
.m_keyCode
);
3989 m_findTimer
->Start (500, wxTIMER_ONE_SHOT
);
3990 wxTreeItemId dummy
= (wxTreeItemId
*)NULL
;
3991 wxTreeItemId item
= FindItem (dummy
, m_findStr
, wxTL_SEARCH_VISIBLE
|
3992 wxTL_SEARCH_PARTIAL
|
3993 wxTL_SEARCH_NOCASE
);
3995 EnsureVisible (item
);
4003 wxTreeItemId
wxTreeListMainWindow::HitTest(const wxPoint
& point
, int& flags
,
4006 // JACS: removed wxYieldIfNeeded() because it can cause the window
4007 // to be deleted from under us if a close window event is pending
4013 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
4014 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
4015 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
4016 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
4017 if (flags
) return wxTreeItemId();
4019 if (m_anchor
== NULL
)
4021 flags
= wxTREE_HITTEST_NOWHERE
;
4022 return wxTreeItemId();
4025 wxTreeListItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
4026 this, flags
, column
, 0);
4029 flags
= wxTREE_HITTEST_NOWHERE
;
4030 return wxTreeItemId();
4035 // get the bounding rectangle of the item (or of its label only)
4036 bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId
& item
,
4038 bool WXUNUSED(textOnly
)) const
4040 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") );
4042 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
4045 GetViewStart(& startX
, & startY
);
4047 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
4048 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
4049 rect
.width
= i
->GetWidth();
4050 //rect.height = i->GetHeight();
4051 rect
.height
= GetLineHeight(i
);
4058 void wxTreeListMainWindow::Edit( const wxTreeItemId
& item
)
4060 if (!item
.IsOk()) return;
4062 m_currentEdit
= (wxTreeListItem
*) item
.m_pItem
;
4064 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, m_owner
->GetId() );
4065 te
.SetItem( (void*) m_currentEdit
);
4066 te
.SetEventObject( /*this*/m_owner
);
4067 m_owner
->GetEventHandler()->ProcessEvent( te
);
4069 if (!te
.IsAllowed()) return;
4071 // We have to call this here because the label in
4072 // question might just have been added and no screen
4073 // update taken place.
4075 DoDirtyProcessing();
4077 wxString s
= m_currentEdit
->GetText(/*ALB*/m_main_column
);
4078 int x
= m_currentEdit
->GetX() + m_imgWidth2
;
4079 int y
= m_currentEdit
->GetY();
4080 int w
= wxMin (m_currentEdit
->GetWidth(),
4081 m_owner
->GetHeaderWindow()->GetWidth()) - m_imgWidth2
;
4082 int h
= m_currentEdit
->GetHeight() + 2;
4083 wxClientDC
dc(this);
4085 x
= dc
.LogicalToDeviceX( x
);
4086 y
= dc
.LogicalToDeviceY( y
);
4088 wxTreeListTextCtrl
*text
= new wxTreeListTextCtrl(this, -1,
4098 void wxTreeListMainWindow::OnRenameTimer()
4103 void wxTreeListMainWindow::OnRenameAccept()
4105 // TODO if the validator fails this causes a crash
4106 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, m_owner
->GetId() );
4107 le
.SetItem( (void*)m_currentEdit
);
4108 le
.SetEventObject( /*this*/m_owner
);
4109 le
.SetLabel( m_renameRes
);
4110 m_owner
->GetEventHandler()->ProcessEvent( le
);
4112 if (!le
.IsAllowed()) return;
4114 SetItemText( m_currentEdit
, m_renameRes
);
4117 void wxTreeListMainWindow::OnMouse( wxMouseEvent
&event
)
4119 if ( !m_anchor
) return;
4121 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
4123 // Is the mouse over a tree item button?
4125 wxTreeListItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
4126 wxTreeListItem
*underMouse
= item
;
4128 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
4129 #endif // wxUSE_TOOLTIPS
4131 if (underMouse
&& (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
4132 !event
.LeftIsDown() && !m_isDragging
&&
4133 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
4141 if (underMouse
!= m_underMouse
)
4145 // unhighlight old item
4146 wxTreeListItem
*tmp
= m_underMouse
;
4147 m_underMouse
= NULL
;
4151 m_underMouse
= underMouse
;
4153 RefreshLine( m_underMouse
);
4157 // Determines what item we are hovering over and need a tooltip for
4158 wxTreeItemId hoverItem
= item
;
4160 // We do not want a tooltip if we are dragging, or if the rename timer is running
4161 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
4163 // Ask the tree control what tooltip (if any) should be shown
4164 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
4165 hevent
.SetItem(hoverItem
);
4166 hevent
.SetEventObject(this);
4168 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
4170 SetToolTip(hevent
.GetLabel());
4175 // we process left mouse up event (enables in-place edit), right down
4176 // (pass to the user code), left dbl click (activate item) and
4177 // dragging/moving events for items drag-and-drop
4178 if ( !(event
.LeftDown() ||
4180 event
.RightDown() ||
4181 event
.LeftDClick() ||
4183 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
4189 if ( event
.LeftDown() )
4192 // wxClientDC dc(this);
4194 // wxCoord x = dc.DeviceToLogicalX( event.GetX() );
4195 // wxCoord y = dc.DeviceToLogicalY( event.GetY() );
4199 if ( event
.Dragging() && !m_isDragging
)
4201 if (m_dragCount
== 0)
4202 m_dragStart
= wxPoint(x
,y
);
4206 if (m_dragCount
!= 3)
4208 // wait until user drags a bit further...
4212 wxEventType command
= event
.RightIsDown()
4213 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
4214 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
4216 wxTreeEvent
nevent( command
,/*ALB*/ m_owner
->GetId() );
4217 nevent
.SetItem( (void*)m_current
);
4218 nevent
.SetEventObject(/*this*/m_owner
); // ALB
4219 nevent
.SetPoint(pt
);
4221 // by default the dragging is not supported, the user code must
4222 // explicitly allow the event for it to take place
4225 if ( m_owner
->GetEventHandler()->ProcessEvent(nevent
) &&
4226 nevent
.IsAllowed() )
4228 // we're going to drag this item
4229 m_isDragging
= TRUE
;
4231 // remember the old cursor because we will change it while
4233 m_oldCursor
= m_cursor
;
4235 // in a single selection control, hide the selection temporarily
4236 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
4238 m_oldSelection
= (wxTreeListItem
*) GetSelection().m_pItem
;
4240 if ( m_oldSelection
)
4242 m_oldSelection
->SetHilight(FALSE
);
4243 RefreshLine(m_oldSelection
);
4250 else if ( event
.Moving() )
4252 if ( item
!= m_dropTarget
)
4254 // unhighlight the previous drop target
4255 DrawDropEffect(m_dropTarget
);
4257 m_dropTarget
= item
;
4259 // highlight the current drop target if any
4260 DrawDropEffect(m_dropTarget
);
4262 DoDirtyProcessing();
4265 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
4267 // erase the highlighting
4268 DrawDropEffect(m_dropTarget
);
4270 if ( m_oldSelection
)
4272 m_oldSelection
->SetHilight(TRUE
);
4273 RefreshLine(m_oldSelection
);
4274 m_oldSelection
= (wxTreeListItem
*)NULL
;
4277 // generate the drag end event
4278 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
,/*ALB*/m_owner
->GetId());
4280 event
.SetItem( (void*)item
);
4281 event
.SetPoint( wxPoint(x
, y
) );
4282 event
.SetEventObject(/*this*/m_owner
);
4284 (void)m_owner
->GetEventHandler()->ProcessEvent(event
);
4286 m_isDragging
= FALSE
;
4287 m_dropTarget
= (wxTreeListItem
*)NULL
;
4291 SetCursor(m_oldCursor
);
4293 DoDirtyProcessing();
4297 // here we process only the messages which happen on tree items
4301 if ( item
== NULL
) return; /* we hit the blank area */
4303 if ( event
.RightDown() )
4306 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
,
4308 nevent
.SetItem( (void*)item
);
4310 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4311 nevent
.SetPoint( wxPoint(nx
, ny
));
4312 nevent
.SetEventObject(/*this*/m_owner
);
4313 m_owner
->GetEventHandler()->ProcessEvent(nevent
);
4315 else if ( event
.LeftUp() )
4319 if ( ( item
== m_current
) &&
4320 ( flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
4321 HasFlag(wxTR_EDIT_LABELS
) )
4323 if ( m_renameTimer
->IsRunning() )
4324 m_renameTimer
->Stop();
4326 m_renameTimer
->Start( 100, TRUE
);
4329 m_lastOnSame
= FALSE
;
4332 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
4334 if ( event
.LeftDown() )
4337 m_lastOnSame
= item
== m_current
;
4340 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
4341 ((flags
& wxTREE_HITTEST_ONITEMICON
)) &&
4342 !HasButtons() && item
->HasPlus())
4344 // only toggle the item for a single click, double click on
4345 // the button doesn't do anything (it toggles the item twice)
4346 if ( event
.LeftDown() )
4351 // don't select the item if the button was clicked
4355 // how should the selection work for this event?
4356 bool is_multiple
, extended_select
, unselect_others
;
4357 EventFlagsToSelType(GetWindowStyleFlag(),
4359 event
.ControlDown(),
4360 is_multiple
, extended_select
, unselect_others
);
4362 SelectItem (item
, unselect_others
, extended_select
);
4364 // For some reason, Windows isn't recognizing a left double-click,
4365 // so we need to simulate it here. Allow 200 milliseconds for now.
4366 if ( event
.LeftDClick() )
4368 // double clicking should not start editing the item label
4369 m_renameTimer
->Stop();
4370 m_lastOnSame
= FALSE
;
4372 // send activate event first
4373 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
4375 nevent
.SetItem( (void*)item
);
4377 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4378 nevent
.SetPoint( wxPoint(nx
, ny
) );
4379 nevent
.SetEventObject( /*this*/m_owner
);
4380 if ( !m_owner
->GetEventHandler()->ProcessEvent( nevent
) )
4382 // if the user code didn't process the activate event,
4383 // handle it ourselves by toggling the item when it is
4385 if ( item
->HasPlus() )
4395 void wxTreeListMainWindow::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
4397 DoDirtyProcessing();
4400 void wxTreeListMainWindow::DoDirtyProcessing()
4402 /* after all changes have been done to the tree control,
4403 * we actually redraw the tree when everything is over */
4405 if (!m_dirty
) return;
4409 CalculatePositions();
4411 AdjustMyScrollbars();
4414 void wxTreeListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4417 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4418 wxScrolledWindow::OnScroll(event
);
4420 HandleOnScroll( event
);
4423 if(event
.GetOrientation() == wxHORIZONTAL
)
4425 m_owner
->GetHeaderWindow()->Refresh();
4426 m_owner
->GetHeaderWindow()->Update();
4431 void wxTreeListMainWindow::CalculateSize( wxTreeListItem
*item
, wxDC
&dc
)
4437 dc
.SetFont(m_boldFont
);
4439 dc
.GetTextExtent( item
->GetText(/*ALB*/m_main_column
), &text_w
, &text_h
);
4442 // restore normal font
4443 dc
.SetFont( m_normalFont
);
4445 int total_h
= (m_imgHeight
> text_h
) ? m_imgHeight
: text_h
;
4447 item
->SetHeight(total_h
);
4448 if (total_h
>m_lineHeight
)
4449 m_lineHeight
=total_h
;
4451 item
->SetWidth(m_imgWidth
+ text_w
+2);
4454 // -----------------------------------------------------------------------------
4455 // for developper : y is now the top of the level
4456 // not the middle of it !
4457 void wxTreeListMainWindow::CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
,
4458 int level
, int &y
, int x_colstart
)
4460 // calculate position of vertical lines
4461 int x
= x_colstart
+ MARGIN
; // start of column
4462 if (HasFlag(wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
4463 if (HasButtons()) x
+= m_btnWidth2
; // space for buttons etc.
4464 if (!HasFlag(wxTR_HIDE_ROOT
)) x
+= m_indent
; // indent root as well
4465 x
+= m_indent
* level
; // indent according to level
4467 // a hidden root is not evaluated, but its children are always
4468 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) goto Recurse
;
4470 CalculateSize( item
, dc
);
4475 y
+= GetLineHeight(item
);
4477 // we don't need to calculate collapsed branches
4478 if ( !item
->IsExpanded() ) return;
4481 wxArrayTreeListItems
& children
= item
->GetChildren();
4482 size_t n
, count
= children
.Count();
4484 for (n
= 0; n
< count
; ++n
)
4485 CalculateLevel( children
[n
], dc
, level
, y
, x_colstart
); // recurse
4488 void wxTreeListMainWindow::CalculatePositions()
4490 if ( !m_anchor
) return;
4492 wxClientDC
dc(this);
4495 dc
.SetFont( m_normalFont
);
4497 dc
.SetPen( m_dottedPen
);
4498 //if(GetImageList() == NULL)
4499 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
4503 for(size_t i
= 0; i
< GetMainColumn(); ++i
) {
4504 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
4505 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
4507 CalculateLevel( m_anchor
, dc
, 0, y
, x_colstart
); // start recursion
4510 void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem
*item
)
4512 if (m_dirty
) return;
4514 wxClientDC
dc(this);
4519 GetVirtualSize( &cw
, &ch
);
4522 rect
.x
= dc
.LogicalToDeviceX( 0 );
4524 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() - 2 );
4527 Refresh( TRUE
, &rect
);
4529 AdjustMyScrollbars();
4532 void wxTreeListMainWindow::RefreshLine( wxTreeListItem
*item
)
4534 if (m_dirty
) return;
4536 wxClientDC
dc(this);
4541 GetVirtualSize( &cw
, &ch
);
4544 rect
.x
= dc
.LogicalToDeviceX( 0 );
4545 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
4547 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
4549 Refresh( TRUE
, &rect
);
4552 void wxTreeListMainWindow::RefreshSelected()
4554 // TODO: this is awfully inefficient, we should keep the list of all
4555 // selected items internally, should be much faster
4557 RefreshSelectedUnder(m_anchor
);
4560 void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem
*item
)
4562 if ( item
->IsSelected() )
4565 const wxArrayTreeListItems
& children
= item
->GetChildren();
4566 size_t count
= children
.GetCount();
4567 for ( size_t n
= 0; n
< count
; n
++ )
4569 RefreshSelectedUnder(children
[n
]);
4573 // ----------------------------------------------------------------------------
4574 // changing colours: we need to refresh the tree control
4575 // ----------------------------------------------------------------------------
4577 bool wxTreeListMainWindow::SetBackgroundColour(const wxColour
& colour
)
4579 if ( !wxWindow::SetBackgroundColour(colour
) )
4587 bool wxTreeListMainWindow::SetForegroundColour(const wxColour
& colour
)
4589 if ( !wxWindow::SetForegroundColour(colour
) )
4597 //----------- ALB -------------
4598 void wxTreeListMainWindow::SetItemText(const wxTreeItemId
& item
, size_t column
,
4599 const wxString
& text
)
4601 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
4603 wxClientDC
dc(this);
4604 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
4605 pItem
->SetText(column
, text
);
4606 CalculateSize(pItem
, dc
);
4610 wxString
wxTreeListMainWindow::GetItemText(const wxTreeItemId
& item
,
4611 size_t column
) const
4613 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
4615 return ((wxTreeListItem
*) item
.m_pItem
)->GetText(column
);
4618 void wxTreeListMainWindow::SetFocus()
4620 wxWindow::SetFocus();
4624 //-----------------------------------------------------------------------------
4626 //-----------------------------------------------------------------------------
4628 IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl
, wxControl
)
4630 BEGIN_EVENT_TABLE(wxTreeListCtrl
, wxControl
)
4631 EVT_SIZE(wxTreeListCtrl::OnSize
)
4632 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxTreeListCtrl::OnGetToolTip
)
4635 bool wxTreeListCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4638 long style
, const wxValidator
&validator
,
4639 const wxString
& name
)
4641 long main_style
= style
& ~(wxRAISED_BORDER
|wxSUNKEN_BORDER
4642 |wxSIMPLE_BORDER
|wxNO_BORDER
|wxDOUBLE_BORDER
4644 long ctrl_style
= style
& ~(wxVSCROLL
|wxHSCROLL
);
4646 if (!wxControl::Create(parent
, id
, pos
, size
, ctrl_style
, validator
, name
)) {
4649 m_main_win
= new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size
,
4650 main_style
, validator
);
4651 m_header_win
= new wxTreeListHeaderWindow(this, -1, m_main_win
,
4652 wxPoint(0, 0), wxDefaultSize
,
4654 CalculateAndSetHeaderHeight();
4658 void wxTreeListCtrl::CalculateAndSetHeaderHeight()
4662 // we use 'g' to get the descent, too
4664 m_header_win
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4665 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4667 // only update if changed
4668 if ( h
!= (int)m_headerHeight
)
4670 m_headerHeight
= (size_t)h
;
4671 m_header_win
->SetSize(m_header_win
->GetSize().x
, m_headerHeight
);
4676 void wxTreeListCtrl::DoHeaderLayout()
4679 GetClientSize(&w
, &h
);
4682 m_header_win
->SetSize(0, 0, w
, m_headerHeight
);
4683 m_header_win
->Refresh(false);
4686 m_main_win
->SetSize(0, m_headerHeight
+ 1, w
, h
- m_headerHeight
- 1);
4689 void wxTreeListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
4695 size_t wxTreeListCtrl::GetCount() const { return m_main_win
->GetCount(); }
4697 unsigned int wxTreeListCtrl::GetIndent() const
4698 { return m_main_win
->GetIndent(); }
4700 void wxTreeListCtrl::SetIndent(unsigned int indent
)
4701 { m_main_win
->SetIndent(indent
); }
4703 unsigned int wxTreeListCtrl::GetLineSpacing() const
4704 { return m_main_win
->GetLineSpacing(); }
4706 void wxTreeListCtrl::SetLineSpacing(unsigned int spacing
)
4707 { m_main_win
->SetLineSpacing(spacing
); }
4709 wxImageList
* wxTreeListCtrl::GetImageList() const
4710 { return m_main_win
->GetImageList(); }
4712 wxImageList
* wxTreeListCtrl::GetStateImageList() const
4713 { return m_main_win
->GetStateImageList(); }
4715 wxImageList
* wxTreeListCtrl::GetButtonsImageList() const
4716 { return m_main_win
->GetButtonsImageList(); }
4718 void wxTreeListCtrl::SetImageList(wxImageList
* imageList
)
4719 { m_main_win
->SetImageList(imageList
); }
4721 void wxTreeListCtrl::SetStateImageList(wxImageList
* imageList
)
4722 { m_main_win
->SetStateImageList(imageList
); }
4724 void wxTreeListCtrl::SetButtonsImageList(wxImageList
* imageList
)
4725 { m_main_win
->SetButtonsImageList(imageList
); }
4727 void wxTreeListCtrl::AssignImageList(wxImageList
* imageList
)
4728 { m_main_win
->AssignImageList(imageList
); }
4730 void wxTreeListCtrl::AssignStateImageList(wxImageList
* imageList
)
4731 { m_main_win
->AssignStateImageList(imageList
); }
4733 void wxTreeListCtrl::AssignButtonsImageList(wxImageList
* imageList
)
4734 { m_main_win
->AssignButtonsImageList(imageList
); }
4736 wxString
wxTreeListCtrl::GetItemText(const wxTreeItemId
& item
, size_t column
)
4738 { return m_main_win
->GetItemText(item
, column
); }
4740 int wxTreeListCtrl::GetItemImage(const wxTreeItemId
& item
, size_t column
,
4741 wxTreeItemIcon which
) const
4742 { return m_main_win
->GetItemImage(item
, column
, which
); }
4744 wxTreeItemData
* wxTreeListCtrl::GetItemData(const wxTreeItemId
& item
) const
4745 { return m_main_win
->GetItemData(item
); }
4747 bool wxTreeListCtrl::GetItemBold(const wxTreeItemId
& item
) const
4748 { return m_main_win
->GetItemBold(item
); }
4750 wxColour
wxTreeListCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
4751 { return m_main_win
->GetItemTextColour(item
); }
4753 wxColour
wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
)
4755 { return m_main_win
->GetItemBackgroundColour(item
); }
4757 wxFont
wxTreeListCtrl::GetItemFont(const wxTreeItemId
& item
) const
4758 { return m_main_win
->GetItemFont(item
); }
4761 void wxTreeListCtrl::SetItemText(const wxTreeItemId
& item
, size_t column
,
4762 const wxString
& text
)
4763 { m_main_win
->SetItemText(item
, column
, text
); }
4765 void wxTreeListCtrl::SetItemImage(const wxTreeItemId
& item
,
4768 wxTreeItemIcon which
)
4769 { m_main_win
->SetItemImage(item
, column
, image
, which
); }
4771 void wxTreeListCtrl::SetItemData(const wxTreeItemId
& item
,
4772 wxTreeItemData
* data
)
4773 { m_main_win
->SetItemData(item
, data
); }
4775 void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
4776 { m_main_win
->SetItemHasChildren(item
, has
); }
4778 void wxTreeListCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
4779 { m_main_win
->SetItemBold(item
, bold
); }
4781 void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId
& item
,
4782 const wxColour
& col
)
4783 { m_main_win
->SetItemTextColour(item
, col
); }
4785 void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
4786 const wxColour
& col
)
4787 { m_main_win
->SetItemBackgroundColour(item
, col
); }
4789 void wxTreeListCtrl::SetItemFont(const wxTreeItemId
& item
,
4791 { m_main_win
->SetItemFont(item
, font
); }
4793 bool wxTreeListCtrl::SetFont(const wxFont
& font
)
4797 m_header_win
->SetFont(font
);
4798 CalculateAndSetHeaderHeight();
4801 return m_main_win
->SetFont(font
);
4805 void wxTreeListCtrl::SetWindowStyle(const long style
)
4808 m_main_win
->SetWindowStyle(style
);
4809 // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win
4812 long wxTreeListCtrl::GetWindowStyle() const
4814 long style
= m_windowStyle
;
4816 style
|= m_main_win
->GetWindowStyle();
4820 bool wxTreeListCtrl::IsVisible(const wxTreeItemId
& item
) const
4821 { return m_main_win
->IsVisible(item
); }
4823 bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
4824 { return m_main_win
->ItemHasChildren(item
); }
4826 bool wxTreeListCtrl::IsExpanded(const wxTreeItemId
& item
) const
4827 { return m_main_win
->IsExpanded(item
); }
4829 bool wxTreeListCtrl::IsSelected(const wxTreeItemId
& item
) const
4830 { return m_main_win
->IsSelected(item
); }
4832 bool wxTreeListCtrl::IsBold(const wxTreeItemId
& item
) const
4833 { return m_main_win
->IsBold(item
); }
4835 size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool rec
)
4836 { return m_main_win
->GetChildrenCount(item
, rec
); }
4838 wxTreeItemId
wxTreeListCtrl::GetRootItem() const
4839 { return m_main_win
->GetRootItem(); }
4841 wxTreeItemId
wxTreeListCtrl::GetSelection() const
4842 { return m_main_win
->GetSelection(); }
4844 size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds
& arr
) const
4845 { return m_main_win
->GetSelections(arr
); }
4847 wxTreeItemId
wxTreeListCtrl::GetItemParent(const wxTreeItemId
& item
) const
4848 { return m_main_win
->GetItemParent(item
); }
4850 #if !wxCHECK_VERSION(2, 5, 0)
4851 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4854 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4855 wxTreeItemIdValue
& cookie
) const
4857 { return m_main_win
->GetFirstChild(item
, cookie
); }
4859 #if !wxCHECK_VERSION(2, 5, 0)
4860 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4863 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4864 wxTreeItemIdValue
& cookie
) const
4866 { return m_main_win
->GetNextChild(item
, cookie
); }
4868 #if !wxCHECK_VERSION(2, 5, 0)
4869 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4872 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4873 wxTreeItemIdValue
& cookie
) const
4875 { return m_main_win
->GetPrevChild(item
, cookie
); }
4877 wxTreeItemId
wxTreeListCtrl::GetLastChild(const wxTreeItemId
& item
) const
4878 { return m_main_win
->GetLastChild(item
); }
4880 wxTreeItemId
wxTreeListCtrl::GetNextSibling(const wxTreeItemId
& item
) const
4881 { return m_main_win
->GetNextSibling(item
); }
4883 wxTreeItemId
wxTreeListCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
4884 { return m_main_win
->GetPrevSibling(item
); }
4886 wxTreeItemId
wxTreeListCtrl::GetFirstVisibleItem() const
4887 { return m_main_win
->GetFirstVisibleItem(); }
4889 wxTreeItemId
wxTreeListCtrl::GetNextVisible(const wxTreeItemId
& item
) const
4890 { return m_main_win
->GetNextVisible(item
); }
4892 wxTreeItemId
wxTreeListCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
4893 { return m_main_win
->GetPrevVisible(item
); }
4895 wxTreeItemId
wxTreeListCtrl::GetNext(const wxTreeItemId
& item
) const
4896 { return m_main_win
->GetNext(item
); }
4898 wxTreeItemId
wxTreeListCtrl::AddRoot(const wxString
& text
, int image
,
4899 int selectedImage
, wxTreeItemData
* data
)
4900 { return m_main_win
->AddRoot(text
, image
, selectedImage
, data
); }
4902 wxTreeItemId
wxTreeListCtrl::PrependItem(const wxTreeItemId
& parent
,
4903 const wxString
& text
, int image
,
4905 wxTreeItemData
* data
)
4906 { return m_main_win
->PrependItem(parent
, text
, image
, selectedImage
, data
); }
4908 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4909 const wxTreeItemId
& previous
,
4910 const wxString
& text
, int image
,
4912 wxTreeItemData
* data
)
4914 return m_main_win
->InsertItem(parent
, previous
, text
, image
,
4915 selectedImage
, data
);
4918 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4920 const wxString
& text
, int image
,
4922 wxTreeItemData
* data
)
4924 return m_main_win
->InsertItem(parent
, index
, text
, image
,
4925 selectedImage
, data
);
4928 wxTreeItemId
wxTreeListCtrl::AppendItem(const wxTreeItemId
& parent
,
4929 const wxString
& text
, int image
,
4931 wxTreeItemData
* data
)
4932 { return m_main_win
->AppendItem(parent
, text
, image
, selectedImage
, data
); }
4934 void wxTreeListCtrl::Delete(const wxTreeItemId
& item
)
4935 { m_main_win
->Delete(item
); }
4937 void wxTreeListCtrl::DeleteChildren(const wxTreeItemId
& item
)
4938 { m_main_win
->DeleteChildren(item
); }
4940 void wxTreeListCtrl::DeleteAllItems()
4941 { m_main_win
->DeleteAllItems(); }
4943 void wxTreeListCtrl::Expand(const wxTreeItemId
& item
)
4944 { m_main_win
->Expand(item
); }
4946 void wxTreeListCtrl::ExpandAll(const wxTreeItemId
& item
)
4947 { m_main_win
->ExpandAll(item
); }
4949 void wxTreeListCtrl::Collapse(const wxTreeItemId
& item
)
4950 { m_main_win
->Collapse(item
); }
4952 void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId
& item
)
4953 { m_main_win
->CollapseAndReset(item
); }
4955 void wxTreeListCtrl::Toggle(const wxTreeItemId
& item
)
4956 { m_main_win
->Toggle(item
); }
4958 void wxTreeListCtrl::Unselect()
4959 { m_main_win
->Unselect(); }
4961 void wxTreeListCtrl::UnselectAll()
4962 { m_main_win
->UnselectAll(); }
4964 void wxTreeListCtrl::SelectItem(const wxTreeItemId
& item
, bool unselect_others
,
4965 bool extended_select
)
4966 { m_main_win
->SelectItem(item
, unselect_others
, extended_select
); }
4968 void wxTreeListCtrl::SelectAll(bool extended_select
)
4969 { m_main_win
->SelectAll(extended_select
); }
4971 void wxTreeListCtrl::EnsureVisible(const wxTreeItemId
& item
)
4972 { m_main_win
->EnsureVisible(item
); }
4974 void wxTreeListCtrl::ScrollTo(const wxTreeItemId
& item
)
4975 { m_main_win
->ScrollTo(item
); }
4977 wxTreeItemId
wxTreeListCtrl::HitTest(const wxPoint
& pos
, int& flags
,
4980 return m_main_win
->HitTest(pos
, flags
, column
);
4983 bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
4984 bool textOnly
) const
4985 { return m_main_win
->GetBoundingRect(item
, rect
, textOnly
); }
4987 void wxTreeListCtrl::Edit(const wxTreeItemId
& item
)
4988 { m_main_win
->Edit(item
); }
4990 int wxTreeListCtrl::OnCompareItems(const wxTreeItemId
& item1
,
4991 const wxTreeItemId
& item2
)
4993 // ALB: do the comparison here, and not delegate to m_main_win, in order
4994 // to let the user override it
4995 //return m_main_win->OnCompareItems(item1, item2);
4996 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
4999 void wxTreeListCtrl::SortChildren(const wxTreeItemId
& item
)
5000 { m_main_win
->SortChildren(item
); }
5002 wxTreeItemId
wxTreeListCtrl::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
)
5003 { return m_main_win
->FindItem (item
, str
, flags
); }
5005 bool wxTreeListCtrl::SetBackgroundColour(const wxColour
& colour
)
5007 if (!m_main_win
) return false;
5008 return m_main_win
->SetBackgroundColour(colour
);
5011 bool wxTreeListCtrl::SetForegroundColour(const wxColour
& colour
)
5013 if (!m_main_win
) return false;
5014 return m_main_win
->SetForegroundColour(colour
);
5017 size_t wxTreeListCtrl::GetColumnCount() const
5018 { return m_main_win
->GetColumnCount(); }
5020 void wxTreeListCtrl::SetColumnWidth(size_t column
, size_t width
)
5021 { m_header_win
->SetColumnWidth(column
, width
); }
5023 int wxTreeListCtrl::GetColumnWidth(size_t column
) const
5024 { return m_header_win
->GetColumnWidth(column
); }
5026 void wxTreeListCtrl::SetMainColumn(size_t column
)
5027 { m_main_win
->SetMainColumn(column
); }
5029 size_t wxTreeListCtrl::GetMainColumn() const
5030 { return m_main_win
->GetMainColumn(); }
5032 void wxTreeListCtrl::SetColumnText(size_t column
, const wxString
& text
)
5034 m_header_win
->SetColumnText(column
, text
);
5035 m_header_win
->Refresh();
5038 wxString
wxTreeListCtrl::GetColumnText(size_t column
) const
5039 { return m_header_win
->GetColumnText(column
); }
5041 void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo
& col
)
5043 m_header_win
->AddColumn(col
);
5047 void wxTreeListCtrl::InsertColumn(size_t before
,
5048 const wxTreeListColumnInfo
& col
)
5049 { m_header_win
->InsertColumn(before
, col
); }
5051 void wxTreeListCtrl::RemoveColumn(size_t column
)
5052 { m_header_win
->RemoveColumn(column
); }
5054 void wxTreeListCtrl::SetColumn(size_t column
, const wxTreeListColumnInfo
& col
)
5055 { m_header_win
->SetColumn(column
, col
); }
5057 const wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) const
5058 { return m_header_win
->GetColumn(column
); }
5060 wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
)
5061 { return m_header_win
->GetColumn(column
); }
5063 void wxTreeListCtrl::SetColumnImage(size_t column
, int image
)
5065 m_header_win
->SetColumn(column
, GetColumn(column
).SetImage(image
));
5068 int wxTreeListCtrl::GetColumnImage(size_t column
) const
5070 return m_header_win
->GetColumn(column
).GetImage();
5073 void wxTreeListCtrl::ShowColumn(size_t column
, bool shown
)
5075 wxASSERT_MSG( column
!= GetMainColumn(),
5076 wxT("The main column may not be hidden") );
5077 m_header_win
->SetColumn(column
, GetColumn(column
).SetShown(GetMainColumn()? true: shown
));
5080 bool wxTreeListCtrl::IsColumnShown(size_t column
) const
5082 return m_header_win
->GetColumn(column
).GetShown();
5085 void wxTreeListCtrl::SetColumnAlignment(size_t column
,
5086 wxTreeListColumnAlign align
)
5088 m_header_win
->SetColumn(column
, GetColumn(column
).SetAlignment(align
));
5091 wxTreeListColumnAlign
wxTreeListCtrl::GetColumnAlignment(size_t column
) const
5093 return m_header_win
->GetColumn(column
).GetAlignment();
5096 void wxTreeListCtrl::Refresh(bool erase
, const wxRect
* rect
)
5098 m_main_win
->Refresh(erase
, rect
);
5099 m_header_win
->Refresh(erase
, rect
);
5102 void wxTreeListCtrl::SetFocus()
5103 { m_main_win
->SetFocus(); }
5106 wxSize
wxTreeListCtrl::DoGetBestSize() const
5108 // something is better than nothing...
5109 return wxSize(100,80);
5112 // Process the tooltip event, to speed up event processing.
5113 // Doesn't actually get a tooltip.
5114 void wxTreeListCtrl::OnGetToolTip( wxTreeEvent
&event
)