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 DrawBorder(const wxTreeItemId
& item
);
572 void DrawLine(const wxTreeItemId
& item
, bool below
);
574 size_t GetColumnCount() const
575 { return m_owner
->GetHeaderWindow()->GetColumnCount(); }
577 void SetMainColumn(size_t column
)
579 if(column
< GetColumnCount())
580 m_main_column
= column
;
582 size_t GetMainColumn() const { return m_main_column
; }
584 void SetItemText(const wxTreeItemId
& item
, size_t column
,
585 const wxString
& text
);
586 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
588 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
589 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
590 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
591 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
596 wxTreeListCtrl
* m_owner
; // ALB
598 size_t m_main_column
; // ALB
600 friend class wxTreeListItem
;
601 friend class wxTreeListRenameTimer
;
602 friend class wxTreeListTextCtrl
;
607 wxTreeListItem
*m_anchor
;
608 wxTreeListItem
*m_current
, *m_key_current
, *m_currentEdit
;
609 int m_btnWidth
, m_btnWidth2
;
610 int m_btnHeight
, m_btnHeight2
;
611 int m_imgWidth
, m_imgWidth2
;
612 int m_imgHeight
, m_imgHeight2
;
613 unsigned short m_indent
;
615 unsigned short m_linespacing
;
617 wxBrush
*m_hilightBrush
,
618 *m_hilightUnfocusedBrush
;
623 bool m_ownsImageListNormal
,
624 m_ownsImageListState
,
625 m_ownsImageListButtons
;
626 bool m_isDragging
; // true between BEGIN/END drag events
628 bool m_lastOnSame
; // last click on the same item as prev
629 wxImageList
*m_imageListNormal
,
635 wxTreeListItem
*m_dropTarget
;
636 wxCursor m_oldCursor
; // cursor is changed while dragging
637 wxTreeListItem
*m_oldSelection
;
638 wxTreeListItem
*m_underMouse
; // for visual effects
640 wxTimer
*m_renameTimer
;
641 wxString m_renameRes
;
644 wxTimer
*m_findTimer
;
647 // the common part of all ctors
651 wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
653 const wxString
& text
,
654 int image
, int selectedImage
,
655 wxTreeItemData
*data
);
656 bool HasButtons(void) const
657 { return (m_imageListButtons
!= NULL
) ||
658 HasFlag (wxTR_TWIST_BUTTONS
|wxTR_HAS_BUTTONS
); }
661 void CalculateLineHeight();
662 int GetLineHeight(wxTreeListItem
*item
) const;
663 void PaintLevel( wxTreeListItem
*item
, wxDC
& dc
, int level
, int &y
,
665 void PaintItem( wxTreeListItem
*item
, wxDC
& dc
);
667 void CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
, int level
, int &y
,
669 void CalculatePositions();
670 void CalculateSize( wxTreeListItem
*item
, wxDC
&dc
);
672 void RefreshSubtree( wxTreeListItem
*item
);
673 void RefreshLine( wxTreeListItem
*item
);
675 // redraw all selected items
676 void RefreshSelected();
678 // RefreshSelected() recursive helper
679 void RefreshSelectedUnder(wxTreeListItem
*item
);
681 void OnRenameTimer();
682 void OnRenameAccept();
684 void FillArray(wxTreeListItem
*, wxArrayTreeItemIds
&) const;
685 void SelectItemRange( wxTreeListItem
*item1
, wxTreeListItem
*item2
);
686 bool TagAllChildrenUntilLast(wxTreeListItem
*crt_item
,
687 wxTreeListItem
*last_item
, bool select
);
688 bool TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
,
690 void UnselectAllChildren( wxTreeListItem
*item
);
692 void DrawDropEffect(wxTreeListItem
*item
);
695 DECLARE_EVENT_TABLE()
696 DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow
)
700 // timer used for enabling in-place edit
701 class wxTreeListRenameTimer
: public wxTimer
704 wxTreeListRenameTimer( wxTreeListMainWindow
*owner
);
709 wxTreeListMainWindow
*m_owner
;
712 // control used for in-place edit
713 class wxTreeListTextCtrl
: public wxTextCtrl
716 wxTreeListTextCtrl( wxWindow
*parent
,
720 wxTreeListMainWindow
*owner
,
721 const wxString
&value
= wxEmptyString
,
722 const wxPoint
&pos
= wxDefaultPosition
,
723 const wxSize
&size
= wxDefaultSize
,
724 int style
= wxSIMPLE_BORDER
,
725 const wxValidator
& validator
= wxDefaultValidator
,
726 const wxString
&name
= wxTextCtrlNameStr
);
728 void OnChar( wxKeyEvent
&event
);
729 void OnKeyUp( wxKeyEvent
&event
);
730 void OnKillFocus( wxFocusEvent
&event
);
735 wxTreeListMainWindow
*m_owner
;
736 wxString m_startValue
;
739 DECLARE_EVENT_TABLE()
747 wxTreeListItem() { m_data
= NULL
; }
748 wxTreeListItem( wxTreeListMainWindow
*owner
,
749 wxTreeListItem
*parent
,
750 const wxArrayString
& text
,
753 wxTreeItemData
*data
);
758 wxArrayTreeListItems
& GetChildren() { return m_children
; }
760 const wxString
GetText() const
762 if(m_text
.GetCount() > 0) return m_text
[0];
763 return wxEmptyString
;
765 const wxString
GetText(size_t col
) const
767 if(m_text
.GetCount() > col
) return m_text
[col
];
768 return wxEmptyString
;
770 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
771 { return m_images
[which
]; }
772 int GetImage(size_t col
, wxTreeItemIcon which
=wxTreeItemIcon_Normal
) const
774 if(col
== m_owner
->GetMainColumn()) return m_images
[which
];
775 if(col
< m_col_images
.GetCount()) return m_col_images
[col
];
778 wxTreeItemData
*GetData() const { return m_data
; }
780 // returns the current image for the item (depending on its
781 // selected/expanded/whatever state)
782 int GetCurrentImage() const;
784 void SetText( const wxString
&text
);
785 void SetText(size_t col
, const wxString
& text
) // ALB
787 if(col
< m_text
.GetCount())
789 else if(col
< m_owner
->GetColumnCount()) {
790 int howmany
= m_owner
->GetColumnCount();
791 for(int i
= m_text
.GetCount(); i
< howmany
; ++i
)
792 m_text
.Add(wxEmptyString
);
796 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
797 void SetImage(size_t col
, int image
, wxTreeItemIcon which
)
799 if(col
== m_owner
->GetMainColumn()) m_images
[which
] = image
;
800 else if(col
< m_col_images
.GetCount())
801 m_col_images
[col
] = image
;
802 else if(col
< m_owner
->GetColumnCount()) {
803 int howmany
= m_owner
->GetColumnCount();
804 for(int i
= m_col_images
.GetCount(); i
< howmany
; ++i
)
805 m_col_images
.Add(NO_IMAGE
);
806 m_col_images
[col
] = image
;
810 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
812 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
814 void SetBold(bool bold
) { m_isBold
= bold
; }
816 int GetX() const { return m_x
; }
817 int GetY() const { return m_y
; }
819 void SetX(int x
) { m_x
= x
; }
820 void SetY(int y
) { m_y
= y
; }
822 int GetHeight() const { return m_height
; }
823 int GetWidth() const { return m_width
; }
825 void SetHeight(int h
) { m_height
= h
; }
826 void SetWidth(int w
) { m_width
= w
; }
828 wxTreeListItem
*GetItemParent() const { return m_parent
; }
831 // deletes all children notifying the treectrl about it if !NULL
833 void DeleteChildren(wxTreeListMainWindow
*tree
= NULL
);
835 // get count of all children (and grand children if 'recursively')
836 size_t GetChildrenCount(bool recursively
= TRUE
) const;
838 void Insert(wxTreeListItem
*child
, size_t index
)
839 { m_children
.Insert(child
, index
); }
841 void GetSize( int &x
, int &y
, const wxTreeListMainWindow
* );
843 // return the item at given position (or NULL if no item), onButton is
844 // TRUE if the point belongs to the item's button, otherwise it lies
845 // on the button's label
846 wxTreeListItem
*HitTest( const wxPoint
& point
,
847 const wxTreeListMainWindow
*,
850 wxTreeListItem
*HitTest( const wxPoint
& point
,
851 const wxTreeListMainWindow
*,
852 int &flags
, int& column
/*ALB*/,
855 void Expand() { m_isCollapsed
= FALSE
; }
856 void Collapse() { m_isCollapsed
= TRUE
; }
858 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
861 bool HasChildren() const { return !m_children
.IsEmpty(); }
862 bool IsSelected() const { return m_hasHilight
!= 0; }
863 bool IsExpanded() const { return !m_isCollapsed
; }
864 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
865 bool IsBold() const { return m_isBold
!= 0; }
868 // get them - may be NULL
869 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
870 // get them ensuring that the pointer is not NULL
871 wxTreeItemAttr
& Attr()
875 m_attr
= new wxTreeItemAttr
;
881 void SetAttributes(wxTreeItemAttr
*attr
)
883 if ( m_ownsAttr
) delete m_attr
;
887 // set them and delete when done
888 void AssignAttributes(wxTreeItemAttr
*attr
)
895 wxTreeListMainWindow
*m_owner
; // control the item belongs to
897 // since there can be very many of these, we save size by chosing
898 // the smallest representation for the elements and by ordering
899 // the members to avoid padding.
900 wxArrayString m_text
; // labels to be rendered for item
902 wxTreeItemData
*m_data
; // user-provided data
904 wxArrayTreeListItems m_children
; // list of children
905 wxTreeListItem
*m_parent
; // parent of this item
907 wxTreeItemAttr
*m_attr
; // attributes???
909 // tree ctrl images for the normal, selected, expanded and
910 // expanded+selected states
911 short m_images
[wxTreeItemIcon_Max
];
912 wxArrayShort m_col_images
; // images for the various columns (!= main)
914 wxCoord m_x
; // (virtual) offset from top
915 wxCoord m_y
; // (virtual) offset from left
916 short m_width
; // width of this item
917 unsigned char m_height
; // height of this item
919 // use bitfields to save size
920 int m_isCollapsed
:1;
921 int m_hasHilight
:1; // same as focused
922 int m_hasPlus
:1; // used for item which doesn't have
923 // children but has a [+] button
924 int m_isBold
:1; // render the label in bold font
925 int m_ownsAttr
:1; // delete attribute when done
928 // ===========================================================================
930 // ===========================================================================
932 // ----------------------------------------------------------------------------
934 // ----------------------------------------------------------------------------
936 // translate the key or mouse event flags to the type of selection we're
938 static void EventFlagsToSelType(long style
,
942 bool &extended_select
,
943 bool &unselect_others
)
945 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
946 extended_select
= shiftDown
&& is_multiple
;
947 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
950 // ---------------------------------------------------------------------------
951 // wxTreeListRenameTimer (internal)
952 // ---------------------------------------------------------------------------
954 wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow
*owner
)
959 void wxTreeListRenameTimer::Notify()
961 m_owner
->OnRenameTimer();
964 //-----------------------------------------------------------------------------
965 // wxTreeListTextCtrl (internal)
966 //-----------------------------------------------------------------------------
968 BEGIN_EVENT_TABLE(wxTreeListTextCtrl
,wxTextCtrl
)
969 EVT_CHAR (wxTreeListTextCtrl::OnChar
)
970 EVT_KEY_UP (wxTreeListTextCtrl::OnKeyUp
)
971 EVT_KILL_FOCUS (wxTreeListTextCtrl::OnKillFocus
)
974 wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow
*parent
,
978 wxTreeListMainWindow
*owner
,
979 const wxString
&value
,
983 const wxValidator
& validator
,
984 const wxString
&name
)
985 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
991 (*m_res
) = wxEmptyString
;
992 m_startValue
= value
;
996 void wxTreeListTextCtrl::OnChar( wxKeyEvent
&event
)
998 if (event
.m_keyCode
== WXK_RETURN
)
1001 (*m_res
) = GetValue();
1003 if ((*m_res
) != m_startValue
)
1004 m_owner
->OnRenameAccept();
1006 if (!wxPendingDelete
.Member(this))
1007 wxPendingDelete
.Append(this);
1010 m_owner
->SetFocus(); // This doesn't work. TODO.
1014 if (event
.m_keyCode
== WXK_ESCAPE
)
1016 (*m_accept
) = FALSE
;
1017 (*m_res
) = wxEmptyString
;
1019 if (!wxPendingDelete
.Member(this))
1020 wxPendingDelete
.Append(this);
1023 m_owner
->SetFocus(); // This doesn't work. TODO.
1030 void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1038 // auto-grow the textctrl:
1039 wxSize parentSize
= m_owner
->GetSize();
1040 wxPoint myPos
= GetPosition();
1041 wxSize mySize
= GetSize();
1043 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
1044 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1045 if (mySize
.x
> sx
) sx
= mySize
.x
;
1051 void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
1059 if (!wxPendingDelete
.Member(this))
1060 wxPendingDelete
.Append(this);
1063 (*m_res
) = GetValue();
1065 if ((*m_res
) != m_startValue
)
1066 m_owner
->OnRenameAccept();
1069 //-----------------------------------------------------------------------------
1070 // wxTreeListHeaderWindow
1071 //-----------------------------------------------------------------------------
1073 IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow
,wxWindow
)
1075 BEGIN_EVENT_TABLE(wxTreeListHeaderWindow
,wxWindow
)
1076 EVT_ERASE_BACKGROUND (wxTreeListHeaderWindow::OnEraseBackground
)
1077 EVT_PAINT (wxTreeListHeaderWindow::OnPaint
)
1078 EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse
)
1079 EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus
)
1082 void wxTreeListHeaderWindow::Init()
1084 m_currentCursor
= (wxCursor
*) NULL
;
1085 m_isDragging
= FALSE
;
1087 m_total_col_width
= 0;
1090 wxTreeListHeaderWindow::wxTreeListHeaderWindow()
1094 m_owner
= (wxTreeListMainWindow
*) NULL
;
1095 m_resizeCursor
= (wxCursor
*) NULL
;
1098 wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow
*win
,
1100 wxTreeListMainWindow
*owner
,
1104 const wxString
&name
)
1105 : wxWindow( win
, id
, pos
, size
, style
, name
)
1110 m_resizeCursor
= new wxCursor(wxCURSOR_SIZEWE
);
1112 SetBackgroundColour(wxSystemSettings::GetColour(
1113 wxSYS_COLOUR_BTNFACE
));
1116 wxTreeListHeaderWindow::~wxTreeListHeaderWindow()
1118 delete m_resizeCursor
;
1121 void wxTreeListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1124 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1125 : GTK_STATE_INSENSITIVE
;
1127 x
= dc
->XLOG2DEV( x
);
1129 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1130 state
, GTK_SHADOW_OUT
,
1131 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1132 x
-1, y
-1, w
+2, h
+2);
1133 #elif defined( __WXMAC__ )
1134 const int m_corner
= 1;
1136 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1138 dc
->SetPen( wxPen(wxSystemSettings::GetColour(
1139 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
));
1140 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1141 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1143 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1146 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1147 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1149 dc
->SetPen( *wxWHITE_PEN
);
1150 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1151 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1152 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1153 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1155 const int m_corner
= 1;
1157 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1159 dc
->SetPen( *wxBLACK_PEN
);
1160 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1161 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1163 wxPen
pen(wxSystemSettings::GetColour(
1164 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1167 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1168 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1170 dc
->SetPen( *wxWHITE_PEN
);
1171 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1172 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1173 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1174 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1178 // shift the DC origin to match the position of the main window horz
1179 // scrollbar: this allows us to always use logical coords
1180 void wxTreeListHeaderWindow::AdjustDC(wxDC
& dc
)
1183 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1186 m_owner
->GetViewStart( &x
, NULL
);
1188 // account for the horz scrollbar offset
1189 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1193 void wxTreeListHeaderWindow::OnEraseBackground( wxEraseEvent
& event
)
1197 void wxTreeListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1200 wxClientDC
real_dc( this );
1202 wxPaintDC
real_dc( this );
1205 AdjustDC( real_dc
);
1207 // width and height of the entire header window
1209 GetClientSize( &w
, &h
);
1210 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1212 // Setup double buffering to eliminate the flicker
1214 wxBitmap
buffer(w
, h
);
1215 dc
.SelectObject(buffer
);
1216 dc
.SetBackground(wxBrush(GetBackgroundColour()));
1219 dc
.SetFont( GetFont() );
1220 dc
.SetBackgroundMode(wxTRANSPARENT
);
1222 // do *not* use the listctrl colour for headers - one day we will have a
1223 // function to set it separately
1224 //dc.SetTextForeground( *wxBLACK );
1225 dc
.SetTextForeground(wxSystemSettings::
1226 GetColour( wxSYS_COLOUR_WINDOWTEXT
));
1228 int x
= HEADER_OFFSET_X
;
1230 int numColumns
= GetColumnCount();
1231 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1233 if (!GetColumnShown (i
)) continue;
1235 wxTreeListColumnInfo
& column
= GetColumn(i
);
1236 int wCol
= column
.GetWidth();
1238 // the width of the rect to draw: make it smaller to fit entirely
1239 // inside the column rect
1242 dc
.SetPen( *wxWHITE_PEN
);
1244 //DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
1245 wxRendererNative::Get().DrawHeaderButton(
1246 this, dc
, wxRect(x
, HEADER_OFFSET_Y
, cw
, h
- 2),
1247 m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
);
1250 // if we have an image, draw it on the right of the label
1251 int image
= column
.GetImage(); //item.m_image;
1252 int ix
= -2, iy
= 0;
1253 wxImageList
* imageList
= m_owner
->GetImageList();
1256 imageList
->GetSize(image
, ix
, iy
);
1258 //else: ignore the column image
1263 int image_offset
= cw
- ix
- 1;
1265 switch(column
.GetAlignment()) {
1266 case wxTL_ALIGN_LEFT
:
1267 text_x
+= EXTRA_WIDTH
;
1270 case wxTL_ALIGN_RIGHT
:
1271 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1272 text_x
+= cw
- text_width
- EXTRA_WIDTH
;
1275 case wxTL_ALIGN_CENTER
:
1276 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1277 text_x
+= (cw
- text_width
)/2 + ix
+ 2;
1278 image_offset
= (cw
- text_width
- ix
- 2)/2;
1283 if(image
!= -1 && imageList
) {
1284 imageList
->Draw(image
, dc
, x
+ image_offset
/*cw - ix - 1*/,
1285 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1286 wxIMAGELIST_DRAW_TRANSPARENT
);
1289 // draw the text clipping it so that it doesn't overwrite the column
1291 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1293 dc
.DrawText( column
.GetText(),
1294 text_x
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1299 int more_w
= m_owner
->GetSize().x
- x
-1;
1302 //DoDrawRect( &dc, x, HEADER_OFFSET_Y, more_w, h-2 );
1303 wxRendererNative::Get().DrawHeaderButton(
1304 this, dc
, wxRect(x
, HEADER_OFFSET_Y
, more_w
, h
-2),
1305 m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
);
1308 // Finish up by drawing the buffer to the real dc
1309 dc
.SelectObject(wxNullBitmap
);
1310 real_dc
.DrawBitmap(buffer
, 0, 0, false);
1313 void wxTreeListHeaderWindow::DrawCurrent()
1315 int x1
= m_currentX
;
1317 ClientToScreen( &x1
, &y1
);
1319 int x2
= m_currentX
-1;
1324 m_owner
->GetClientSize( NULL
, &y2
);
1325 m_owner
->ClientToScreen( &x2
, &y2
);
1328 dc
.SetLogicalFunction( wxINVERT
);
1329 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1330 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1334 dc
.DrawLine( x1
, y1
, x2
, y2
);
1336 dc
.SetLogicalFunction( wxCOPY
);
1338 dc
.SetPen( wxNullPen
);
1339 dc
.SetBrush( wxNullBrush
);
1342 void wxTreeListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1344 // we want to work with logical coords
1346 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1347 int y
= event
.GetY();
1351 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
,
1352 event
.GetPosition());
1354 // we don't draw the line beyond our window, but we allow dragging it
1357 GetClientSize( &w
, NULL
);
1358 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1361 // erase the line if it was drawn
1362 if ( m_currentX
< w
)
1365 if (event
.ButtonUp())
1368 m_isDragging
= FALSE
;
1370 SetColumnWidth( m_column
, m_currentX
- m_minX
);
1372 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
,
1373 event
.GetPosition());
1380 m_currentX
= m_minX
+ 7;
1382 // draw in the new location
1383 if ( m_currentX
< w
)
1387 else // not dragging
1390 bool hit_border
= FALSE
;
1392 // end of the current column
1395 // find the column where this event occurred
1396 int countCol
= GetColumnCount();
1397 for (int col
= 0; col
< countCol
; col
++)
1399 if (!GetColumnShown (col
)) continue;
1400 xpos
+= GetColumnWidth (col
);
1403 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1405 // near the column border
1412 // inside the column
1419 if (event
.LeftDown() || event
.RightUp())
1421 if (hit_border
&& event
.LeftDown())
1423 m_isDragging
= TRUE
;
1427 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1428 event
.GetPosition());
1430 else // click on a column
1432 SendListEvent( event
.LeftDown()
1433 ? wxEVT_COMMAND_LIST_COL_CLICK
1434 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1435 event
.GetPosition());
1438 else if (event
.Moving())
1443 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1444 m_currentCursor
= m_resizeCursor
;
1448 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1449 m_currentCursor
= wxSTANDARD_CURSOR
;
1453 SetCursor(*m_currentCursor
);
1458 void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1460 m_owner
->SetFocus();
1463 void wxTreeListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1465 wxWindow
*parent
= GetParent();
1466 wxListEvent
le( type
, parent
->GetId() );
1467 le
.SetEventObject( parent
);
1468 le
.m_pointDrag
= pos
;
1470 // the position should be relative to the parent window, not
1471 // this one for compatibility with MSW and common sense: the
1472 // user code doesn't know anything at all about this header
1473 // window, so why should it get positions relative to it?
1474 le
.m_pointDrag
.y
-= GetSize().y
;
1476 le
.m_col
= m_column
;
1477 parent
->GetEventHandler()->ProcessEvent( le
);
1480 void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo
& col
)
1483 m_total_col_width
+= col
.GetWidth();
1484 //m_owner->GetHeaderWindow()->Refresh();
1486 m_owner
->AdjustMyScrollbars();
1487 m_owner
->m_dirty
= TRUE
;
1491 void wxTreeListHeaderWindow::SetColumnWidth(size_t column
, size_t width
)
1493 if(column
< GetColumnCount()) {
1494 m_total_col_width
-= m_columns
[column
].GetWidth();
1495 m_columns
[column
].SetWidth(width
);
1496 m_total_col_width
+= width
;
1497 m_owner
->AdjustMyScrollbars();
1498 m_owner
->m_dirty
= TRUE
;
1505 void wxTreeListHeaderWindow::InsertColumn(size_t before
,
1506 const wxTreeListColumnInfo
& col
)
1508 wxCHECK_RET(before
< GetColumnCount(), wxT("Invalid column index"));
1509 m_columns
.Insert(col
, before
);
1510 m_total_col_width
+= col
.GetWidth();
1512 //m_owner->GetHeaderWindow()->Refresh();
1513 m_owner
->AdjustMyScrollbars();
1514 m_owner
->m_dirty
= TRUE
;
1518 void wxTreeListHeaderWindow::RemoveColumn(size_t column
)
1520 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1521 m_total_col_width
-= m_columns
[column
].GetWidth();
1522 m_columns
.RemoveAt(column
);
1524 m_owner
->AdjustMyScrollbars();
1525 m_owner
->m_dirty
= TRUE
;
1529 void wxTreeListHeaderWindow::SetColumn(size_t column
,
1530 const wxTreeListColumnInfo
& info
)
1532 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1533 size_t w
= m_columns
[column
].GetWidth();
1534 m_columns
[column
] = info
;
1535 //m_owner->GetHeaderWindow()->Refresh();
1537 if(w
!= info
.GetWidth()) {
1538 m_total_col_width
+= info
.GetWidth() - w
;
1539 m_owner
->AdjustMyScrollbars();
1540 m_owner
->m_dirty
= TRUE
;
1545 // ---------------------------------------------------------------------------
1547 // ---------------------------------------------------------------------------
1549 wxTreeListItem::wxTreeListItem(wxTreeListMainWindow
*owner
,
1550 wxTreeListItem
*parent
,
1551 const wxArrayString
& text
,
1552 int image
, int selImage
,
1553 wxTreeItemData
*data
)
1556 m_images
[wxTreeItemIcon_Normal
] = image
;
1557 m_images
[wxTreeItemIcon_Selected
] = selImage
;
1558 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
1559 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
1564 m_isCollapsed
= TRUE
;
1565 m_hasHilight
= FALSE
;
1573 m_attr
= (wxTreeItemAttr
*)NULL
;
1576 // We don't know the height here yet.
1581 wxTreeListItem::~wxTreeListItem()
1585 if (m_ownsAttr
) delete m_attr
;
1587 wxASSERT_MSG( m_children
.IsEmpty(),
1588 wxT("please call DeleteChildren() before deleting the item") );
1591 void wxTreeListItem::DeleteChildren(wxTreeListMainWindow
*tree
)
1593 size_t count
= m_children
.Count();
1594 for ( size_t n
= 0; n
< count
; n
++ )
1596 wxTreeListItem
*child
= m_children
[n
];
1598 tree
->SendDeleteEvent(child
);
1600 child
->DeleteChildren(tree
);
1607 void wxTreeListItem::SetText( const wxString
&text
)
1609 if(m_text
.GetCount() > 0) m_text
[0] = text
;
1615 size_t wxTreeListItem::GetChildrenCount(bool recursively
) const
1617 size_t count
= m_children
.Count();
1621 size_t total
= count
;
1622 for (size_t n
= 0; n
< count
; ++n
)
1624 total
+= m_children
[n
]->GetChildrenCount();
1630 void wxTreeListItem::GetSize( int &x
, int &y
,
1631 const wxTreeListMainWindow
*theButton
)
1633 int bottomY
=m_y
+theButton
->GetLineHeight(this);
1634 if ( y
< bottomY
) y
= bottomY
;
1635 int width
= m_x
+ m_width
;
1636 if ( x
< width
) x
= width
;
1640 size_t count
= m_children
.Count();
1641 for ( size_t n
= 0; n
< count
; ++n
)
1643 m_children
[n
]->GetSize( x
, y
, theButton
);
1648 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1649 const wxTreeListMainWindow
*theCtrl
,
1653 // for a hidden root node, don't evaluate it, but do evaluate children
1654 if (!(theCtrl
->HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)))
1656 // evaluate the item
1657 int h
= theCtrl
->GetLineHeight(this);
1658 if ((point
.y
> m_y
) && (point
.y
<= m_y
+ h
))
1660 // check for above/below middle
1661 int y_mid
= m_y
+ h
/2;
1662 if (point
.y
< y_mid
)
1663 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
1665 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
1667 // check for button hit
1668 int xCross
= m_x
; // - theCtrl->GetLineSpacing();
1670 // according to the drawing code the triangels are drawn
1671 // at -4 , -4 from the position up to +10/+10 max
1672 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
1673 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
1674 HasPlus() && theCtrl
->HasButtons() )
1676 // 5 is the size of the plus sign
1677 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
1678 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
1679 HasPlus() && theCtrl
->HasButtons() )
1682 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
1686 // check for image hit
1687 if (theCtrl
->m_imgWidth
> 0 && GetImage() != NO_IMAGE
) {
1688 int imgX
= m_x
- theCtrl
->m_imgWidth2
;
1689 if (HasPlus() && theCtrl
->HasButtons())
1690 imgX
+= theCtrl
->m_btnWidth
+ LINEATROOT
;
1691 int imgY
= y_mid
- theCtrl
->m_imgHeight2
;
1692 if ((point
.x
>= imgX
) && (point
.x
<= (imgX
+ theCtrl
->m_imgWidth
)) &&
1693 (point
.y
>= imgY
) && (point
.y
<= (imgY
+ theCtrl
->m_imgHeight
))) {
1694 flags
|= wxTREE_HITTEST_ONITEMICON
;
1699 // check for label hit
1700 int lblX
= m_x
- theCtrl
->m_imgWidth2
+ theCtrl
->m_imgWidth
+ MARGIN
;
1701 if ((point
.x
>= lblX
) && (point
.x
<= (m_x
+ m_width
)) &&
1702 (point
.y
>= m_y
) && (point
.y
<= (m_y
+ h
))) {
1703 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
1707 // else check for indent
1708 if (point
.x
< m_x
) {
1709 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
1713 // else check for item right???
1714 if (point
.x
> m_x
+ m_width
) {
1715 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
1721 // if children are expanded, fall through to evaluate them
1722 if (m_isCollapsed
) return (wxTreeListItem
*) NULL
;
1725 // evaluate children
1726 size_t count
= m_children
.Count();
1727 for ( size_t n
= 0; n
< count
; n
++ )
1729 wxTreeListItem
*res
= m_children
[n
]->HitTest(point
, theCtrl
,
1735 return (wxTreeListItem
*) NULL
;
1739 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1740 const wxTreeListMainWindow
*theCtrl
,
1741 int &flags
, int& column
, int level
)
1743 column
= theCtrl
->GetMainColumn(); //-1;
1745 wxTreeListItem
* res
= HitTest(point
, theCtrl
, flags
, level
);
1751 wxTreeListHeaderWindow
* header_win
= theCtrl
->m_owner
->GetHeaderWindow();
1752 if (point
.x
>= header_win
->GetWidth())
1754 else if(flags
& wxTREE_HITTEST_ONITEMINDENT
) {
1756 for(size_t i
= 0; i
< theCtrl
->GetMainColumn(); ++i
) {
1757 if (!header_win
->GetColumnShown(i
)) continue;
1758 int w
= header_win
->GetColumnWidth(i
);
1759 if(point
.x
>= x
&& point
.x
< x
+w
) {
1760 flags
^= wxTREE_HITTEST_ONITEMINDENT
;
1761 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1767 else if(flags
& wxTREE_HITTEST_ONITEMRIGHT
) {
1770 for(i
= 0; i
< theCtrl
->GetMainColumn()+1; ++i
) {
1771 if (!header_win
->GetColumnShown(i
)) continue;
1772 x
+= header_win
->GetColumnWidth(i
);
1774 for(i
= theCtrl
->GetMainColumn()+1; i
< theCtrl
->GetColumnCount(); ++i
) {
1775 if (!header_win
->GetColumnShown(i
)) continue;
1776 int w
= header_win
->GetColumnWidth(i
);
1777 if(point
.x
>= x
&& point
.x
< x
+w
) {
1778 flags
^= wxTREE_HITTEST_ONITEMRIGHT
;
1779 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1791 int wxTreeListItem::GetCurrentImage() const
1793 int image
= NO_IMAGE
;
1798 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
1801 if ( image
== NO_IMAGE
)
1803 // we usually fall back to the normal item, but try just the
1804 // expanded one (and not selected) first in this case
1805 image
= GetImage(wxTreeItemIcon_Expanded
);
1808 else // not expanded
1811 image
= GetImage(wxTreeItemIcon_Selected
);
1814 // maybe it doesn't have the specific image we want,
1815 // try the default one instead
1816 if ( image
== NO_IMAGE
) image
= GetImage();
1821 // ---------------------------------------------------------------------------
1822 // wxTreeListMainWindow implementation
1823 // ---------------------------------------------------------------------------
1825 IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow
, wxScrolledWindow
)
1827 BEGIN_EVENT_TABLE(wxTreeListMainWindow
, wxScrolledWindow
)
1828 EVT_PAINT (wxTreeListMainWindow::OnPaint
)
1829 EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse
)
1830 EVT_CHAR (wxTreeListMainWindow::OnChar
)
1831 EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus
)
1832 EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus
)
1833 EVT_IDLE (wxTreeListMainWindow::OnIdle
)
1834 EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll
)
1838 // ---------------------------------------------------------------------------
1839 // construction/destruction
1840 // ---------------------------------------------------------------------------
1842 void wxTreeListMainWindow::Init()
1844 m_current
= m_key_current
= m_anchor
= (wxTreeListItem
*) NULL
;
1848 m_lineHeight
= LINEHEIGHT
;
1849 m_indent
= MININDENT
; // min. indent
1851 m_imgWidth
= 0, m_imgWidth2
= 0;
1852 m_imgHeight
= 0, m_imgHeight2
= 0;
1854 m_hilightBrush
= new wxBrush
1856 wxSystemSettings::GetColour
1858 wxSYS_COLOUR_HIGHLIGHT
1863 m_hilightUnfocusedBrush
= new wxBrush
1865 wxSystemSettings::GetColour
1867 wxSYS_COLOUR_BTNSHADOW
1872 m_imageListNormal
= m_imageListButtons
=
1873 m_imageListState
= (wxImageList
*) NULL
;
1874 m_ownsImageListNormal
= m_ownsImageListButtons
=
1875 m_ownsImageListState
= FALSE
;
1878 m_isDragging
= FALSE
;
1879 m_dropTarget
= m_oldSelection
= (wxTreeListItem
*)NULL
;
1881 m_renameTimer
= new wxTreeListRenameTimer( this );
1882 m_lastOnSame
= FALSE
;
1884 m_findTimer
= new wxTimer (this, -1);
1886 m_underMouse
= NULL
;
1888 #ifdef __WXMAC_CARBON__
1889 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
1891 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
1893 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
1894 m_normalFont
.GetFamily(),
1895 m_normalFont
.GetStyle(),
1897 m_normalFont
.GetUnderlined(),
1898 m_normalFont
.GetFaceName(),
1899 m_normalFont
.GetEncoding());
1903 bool wxTreeListMainWindow::Create(wxTreeListCtrl
*parent
,
1908 const wxValidator
&validator
,
1909 const wxString
& name
)
1912 if ( !(style
& wxTR_DONT_ADJUST_MAC
))
1915 wxGetOsVersion( &major
, &minor
);
1917 if (style
& wxTR_HAS_BUTTONS
) style
|= wxTR_TWIST_BUTTONS
;
1918 if (style
& wxTR_HAS_BUTTONS
) style
&= ~wxTR_HAS_BUTTONS
;
1919 style
&= ~wxTR_LINES_AT_ROOT
;
1920 style
|= wxTR_NO_LINES
;
1922 style
|= wxTR_ROW_LINES
;
1926 wxScrolledWindow::Create( parent
, id
, pos
, size
,
1927 style
|wxHSCROLL
|wxVSCROLL
, name
);
1929 #if wxUSE_VALIDATORS
1930 SetValidator( validator
);
1933 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
) );
1940 bdc
.SelectObject(bmp
);
1941 bdc
.SetPen(*wxGREY_PEN
);
1942 bdc
.DrawRectangle(-1, -1, 10, 10);
1943 for (i
= 0; i
< 8; i
++) {
1944 for (j
= 0; j
< 8; j
++) {
1945 if (!((i
+ j
) & 1)) {
1946 bdc
.DrawPoint(i
, j
);
1951 m_dottedPen
= wxPen(bmp
, 1);
1954 //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT ); // too slow under XFree86
1955 m_dottedPen
= wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK!
1965 wxTreeListMainWindow::~wxTreeListMainWindow()
1967 delete m_hilightBrush
;
1968 delete m_hilightUnfocusedBrush
;
1972 delete m_renameTimer
;
1974 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1975 if (m_ownsImageListState
) delete m_imageListState
;
1976 if (m_ownsImageListButtons
) delete m_imageListButtons
;
1981 //-----------------------------------------------------------------------------
1983 //-----------------------------------------------------------------------------
1985 size_t wxTreeListMainWindow::GetCount() const
1987 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
1990 void wxTreeListMainWindow::SetIndent(unsigned int indent
)
1996 void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing
)
1998 m_linespacing
= spacing
;
2000 CalculateLineHeight();
2003 size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId
& item
,
2006 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
2008 return ((wxTreeListItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
2011 void wxTreeListMainWindow::SetWindowStyle(const long styles
)
2013 // right now, just sets the styles. Eventually, we may
2014 // want to update the inherited styles, but right now
2015 // none of the parents has updatable styles
2016 m_windowStyle
= styles
;
2020 //-----------------------------------------------------------------------------
2021 // functions to work with tree items
2022 //-----------------------------------------------------------------------------
2024 int wxTreeListMainWindow::GetItemImage(const wxTreeItemId
& item
, size_t column
,
2025 wxTreeItemIcon which
) const
2027 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
2029 return ((wxTreeListItem
*) item
.m_pItem
)->GetImage(column
, which
);
2032 wxTreeItemData
*wxTreeListMainWindow::GetItemData(const wxTreeItemId
& item
)
2035 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
2037 return ((wxTreeListItem
*) item
.m_pItem
)->GetData();
2040 bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId
& item
) const
2042 wxCHECK_MSG(item
.IsOk(), FALSE
, wxT("invalid tree item"));
2043 return ((wxTreeListItem
*)item
.m_pItem
)->IsBold();
2046 wxColour
wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId
& item
)
2049 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2051 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2052 return pItem
->Attr().GetTextColour();
2055 wxColour
wxTreeListMainWindow::GetItemBackgroundColour(
2056 const wxTreeItemId
& item
) const
2058 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
2060 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2061 return pItem
->Attr().GetBackgroundColour();
2064 wxFont
wxTreeListMainWindow::GetItemFont(const wxTreeItemId
& item
) const
2066 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
2068 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2069 return pItem
->Attr().GetFont();
2074 void wxTreeListMainWindow::SetItemImage(const wxTreeItemId
& item
,
2076 int image
, wxTreeItemIcon which
)
2078 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2080 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2081 pItem
->SetImage(column
, image
, which
);
2083 wxClientDC
dc(this);
2084 CalculateSize(pItem
, dc
);
2088 void wxTreeListMainWindow::SetItemData(const wxTreeItemId
& item
,
2089 wxTreeItemData
*data
)
2091 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2093 ((wxTreeListItem
*) item
.m_pItem
)->SetData(data
);
2096 void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId
& item
,
2099 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2101 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2102 pItem
->SetHasPlus(has
);
2106 void wxTreeListMainWindow::SetItemBold(const wxTreeItemId
& item
, bool bold
)
2108 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2110 // avoid redrawing the tree if no real change
2111 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2112 if ( pItem
->IsBold() != bold
)
2114 pItem
->SetBold(bold
);
2119 void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId
& item
,
2120 const wxColour
& col
)
2122 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2124 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2125 pItem
->Attr().SetTextColour(col
);
2129 void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId
& item
,
2130 const wxColour
& col
)
2132 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2134 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2135 pItem
->Attr().SetBackgroundColour(col
);
2139 void wxTreeListMainWindow::SetItemFont(const wxTreeItemId
& item
,
2142 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2144 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2145 pItem
->Attr().SetFont(font
);
2149 bool wxTreeListMainWindow::SetFont( const wxFont
&font
)
2151 wxScrolledWindow::SetFont(font
);
2153 m_normalFont
= font
;
2154 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
2155 m_normalFont
.GetFamily(),
2156 m_normalFont
.GetStyle(),
2158 m_normalFont
.GetUnderlined());
2164 // ----------------------------------------------------------------------------
2165 // item status inquiries
2166 // ----------------------------------------------------------------------------
2168 bool wxTreeListMainWindow::IsVisible(const wxTreeItemId
& item
) const
2170 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2172 // An item is only visible if it's not a descendant of a collapsed item
2173 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2174 wxTreeListItem
* parent
= pItem
->GetItemParent();
2177 if (!parent
->IsExpanded())
2179 parent
= parent
->GetItemParent();
2183 GetViewStart(& startX
, & startY
);
2185 wxSize clientSize
= GetClientSize();
2188 if (!GetBoundingRect(item
, rect
))
2190 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
2192 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
2194 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
2200 bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId
& item
) const
2202 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2204 // consider that the item does have children if it has the "+" button: it
2205 // might not have them (if it had never been expanded yet) but then it
2206 // could have them as well and it's better to err on this side rather than
2207 // disabling some operations which are restricted to the items with
2208 // children for an item which does have them
2209 return ((wxTreeListItem
*) item
.m_pItem
)->HasPlus();
2212 bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId
& item
) const
2214 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2216 return ((wxTreeListItem
*) item
.m_pItem
)->IsExpanded();
2219 bool wxTreeListMainWindow::IsSelected(const wxTreeItemId
& item
) const
2221 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2223 return ((wxTreeListItem
*) item
.m_pItem
)->IsSelected();
2226 bool wxTreeListMainWindow::IsBold(const wxTreeItemId
& item
) const
2228 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2230 return ((wxTreeListItem
*) item
.m_pItem
)->IsBold();
2233 // ----------------------------------------------------------------------------
2235 // ----------------------------------------------------------------------------
2237 wxTreeItemId
wxTreeListMainWindow::GetItemParent(const wxTreeItemId
& item
) const
2239 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2241 return ((wxTreeListItem
*) item
.m_pItem
)->GetItemParent();
2244 #if !wxCHECK_VERSION(2, 5, 0)
2245 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2248 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2249 wxTreeItemIdValue
& cookie
) const
2252 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2255 return GetNextChild(item
, cookie
);
2258 #if !wxCHECK_VERSION(2, 5, 0)
2259 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2262 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2263 wxTreeItemIdValue
& cookie
) const
2266 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2268 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2270 // it's ok to cast cookie to size_t, we never have indices big enough to
2271 // overflow "void *"
2272 size_t *pIndex
= (size_t *)&cookie
;
2273 if ( *pIndex
< children
.Count() )
2275 return children
.Item((*pIndex
)++);
2279 // there are no more of them
2280 return wxTreeItemId();
2284 #if !wxCHECK_VERSION(2, 5, 0)
2285 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2288 wxTreeItemId
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
,
2289 wxTreeItemIdValue
& cookie
) const
2292 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2294 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2296 // it's ok to cast cookie to size_t, we never have indices big enough to
2297 // overflow "void *"
2298 size_t *pIndex
= (size_t *)&cookie
;
2301 return children
.Item(--(*pIndex
));
2305 // there are no more of them
2306 return wxTreeItemId();
2310 wxTreeItemId
wxTreeListMainWindow::GetLastChild(const wxTreeItemId
& item
) const
2312 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2314 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2315 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
2318 wxTreeItemId
wxTreeListMainWindow::GetNextSibling(const wxTreeItemId
& item
) const
2320 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2322 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2323 wxTreeListItem
*parent
= i
->GetItemParent();
2324 if ( parent
== NULL
)
2326 // root item doesn't have any siblings
2327 return wxTreeItemId();
2330 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2331 int index
= siblings
.Index(i
);
2332 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2334 size_t n
= (size_t)(index
+ 1);
2335 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
2338 wxTreeItemId
wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId
& item
)
2341 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2343 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2344 wxTreeListItem
*parent
= i
->GetItemParent();
2345 if ( parent
== NULL
)
2347 // root item doesn't have any siblings
2348 return wxTreeItemId();
2351 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2352 int index
= siblings
.Index(i
);
2353 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2355 return index
== 0 ? wxTreeItemId()
2356 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
2359 // Only for internal use right now, but should probably be public
2360 wxTreeItemId
wxTreeListMainWindow::GetNext(const wxTreeItemId
& item
) const
2362 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2364 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2366 // First see if there are any children.
2367 wxArrayTreeListItems
& children
= i
->GetChildren();
2368 if (children
.GetCount() > 0)
2370 return children
.Item(0);
2374 // Try a sibling of this or ancestor instead
2375 wxTreeItemId p
= item
;
2376 wxTreeItemId toFind
;
2379 toFind
= GetNextSibling(p
);
2380 p
= GetItemParent(p
);
2381 } while (p
.IsOk() && !toFind
.IsOk());
2386 wxTreeItemId
wxTreeListMainWindow::GetFirstVisibleItem() const
2388 wxTreeItemId id
= GetRootItem();
2397 } while (id
.IsOk());
2399 return wxTreeItemId();
2402 wxTreeItemId
wxTreeListMainWindow::GetNextVisible(const wxTreeItemId
& item
)
2405 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2407 wxTreeItemId id
= item
;
2410 while (id
= GetNext(id
), id
.IsOk())
2416 return wxTreeItemId();
2419 wxTreeItemId
wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId
& item
)
2422 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2424 wxFAIL_MSG(wxT("not implemented"));
2426 return wxTreeItemId();
2429 // ----------------------------------------------------------------------------
2431 // ----------------------------------------------------------------------------
2433 wxTreeItemId
wxTreeListMainWindow::DoInsertItem(const wxTreeItemId
& parentId
,
2435 const wxString
& text
,
2436 int image
, int selImage
,
2437 wxTreeItemData
*data
)
2439 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2442 // should we give a warning here?
2443 return AddRoot(text
, image
, selImage
, data
);
2446 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2450 arr
.Alloc(GetColumnCount());
2451 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2452 arr
.Add(wxEmptyString
);
2454 arr
[m_main_column
] = text
;
2455 wxTreeListItem
*item
=
2456 new wxTreeListItem( this, parent
, arr
, image
, selImage
, data
);
2460 data
->SetId((void*)item
);
2463 parent
->Insert( item
, previous
);
2468 wxTreeItemId
wxTreeListMainWindow::AddRoot(const wxString
& text
,
2469 int image
, int selImage
,
2470 wxTreeItemData
*data
)
2472 wxCHECK_MSG(!m_anchor
, wxTreeItemId(), wxT("tree can have only one root"));
2473 wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item"));
2475 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2479 arr
.Alloc(GetColumnCount());
2480 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2481 arr
.Add(wxEmptyString
);
2483 arr
[m_main_column
] = text
;
2484 m_anchor
= new wxTreeListItem( this, (wxTreeListItem
*)NULL
, arr
,
2485 image
, selImage
, data
);
2487 if (HasFlag(wxTR_HIDE_ROOT
))
2489 // if root is hidden, make sure we can navigate
2491 m_anchor
->SetHasPlus();
2497 data
->SetId((void*)m_anchor
);
2500 if (!HasFlag(wxTR_MULTIPLE
))
2502 m_current
= m_key_current
= m_anchor
;
2503 m_current
->SetHilight( TRUE
);
2509 wxTreeItemId
wxTreeListMainWindow::PrependItem(const wxTreeItemId
& parent
,
2510 const wxString
& text
,
2511 int image
, int selImage
,
2512 wxTreeItemData
*data
)
2514 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
2517 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2518 const wxTreeItemId
& idPrevious
,
2519 const wxString
& text
,
2520 int image
, int selImage
,
2521 wxTreeItemData
*data
)
2523 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2526 // should we give a warning here?
2527 return AddRoot(text
, image
, selImage
, data
);
2530 int index
= parent
->GetChildren().Index((wxTreeListItem
*) idPrevious
.m_pItem
);
2531 wxASSERT_MSG( index
!= wxNOT_FOUND
,
2532 wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") );
2534 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
2537 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2539 const wxString
& text
,
2540 int image
, int selImage
,
2541 wxTreeItemData
*data
)
2543 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2546 // should we give a warning here?
2547 return AddRoot(text
, image
, selImage
, data
);
2550 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
2553 wxTreeItemId
wxTreeListMainWindow::AppendItem(const wxTreeItemId
& parentId
,
2554 const wxString
& text
,
2555 int image
, int selImage
,
2556 wxTreeItemData
*data
)
2558 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2561 // should we give a warning here?
2562 return AddRoot(text
, image
, selImage
, data
);
2565 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
2566 image
, selImage
, data
);
2569 void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem
*item
)
2571 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, m_owner
->GetId() );
2572 event
.SetItem((void*)item
);
2573 event
.SetEventObject( /*this*/m_owner
);
2574 m_owner
->ProcessEvent( event
);
2577 void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId
& itemId
)
2579 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2581 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2582 item
->DeleteChildren(this);
2585 void wxTreeListMainWindow::Delete(const wxTreeItemId
& itemId
)
2587 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2589 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2591 // don't stay with invalid m_key_current or we will crash in
2592 // the next call to OnChar()
2593 bool changeKeyCurrent
= FALSE
;
2594 wxTreeListItem
*itemKey
= m_key_current
;
2597 if ( itemKey
== item
)
2599 // m_key_current is a descendant of the item being deleted
2600 changeKeyCurrent
= TRUE
;
2603 itemKey
= itemKey
->GetItemParent();
2606 wxTreeListItem
*parent
= item
->GetItemParent();
2609 parent
->GetChildren().Remove( item
); // remove by value
2612 if ( changeKeyCurrent
)
2614 // may be NULL or not
2615 m_key_current
= parent
;
2618 item
->DeleteChildren(this);
2619 SendDeleteEvent(item
);
2623 void wxTreeListMainWindow::DeleteAllItems()
2629 m_anchor
->DeleteChildren(this);
2636 void wxTreeListMainWindow::Expand(const wxTreeItemId
& itemId
)
2638 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2640 wxCHECK_RET( item
, _T("invalid item in wxTreeListMainWindow::Expand") );
2642 if ( !item
->HasPlus() )
2645 if ( item
->IsExpanded() )
2648 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, m_owner
->GetId() );
2649 event
.SetItem( (void*)item
);
2650 event
.SetEventObject( /*this*/m_owner
);
2652 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2654 // cancelled by program
2659 CalculatePositions();
2661 RefreshSubtree(item
);
2663 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
2664 ProcessEvent( event
);
2667 void wxTreeListMainWindow::ExpandAll(const wxTreeItemId
& item
)
2670 if ( IsExpanded(item
) )
2672 #if !wxCHECK_VERSION(2, 5, 0)
2675 wxTreeItemIdValue cookie
;
2677 wxTreeItemId child
= GetFirstChild(item
, cookie
);
2678 while ( child
.IsOk() )
2682 child
= GetNextChild(item
, cookie
);
2687 void wxTreeListMainWindow::Collapse(const wxTreeItemId
& itemId
)
2689 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2691 if ( !item
->IsExpanded() )
2694 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, m_owner
->GetId() );
2695 event
.SetItem( (void*)item
);
2696 event
.SetEventObject( /*this*/m_owner
);
2697 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2699 // cancelled by program
2705 #if 0 // TODO why should items be collapsed recursively?
2706 wxArrayTreeListItems
& children
= item
->GetChildren();
2707 size_t count
= children
.Count();
2708 for ( size_t n
= 0; n
< count
; n
++ )
2710 Collapse(children
[n
]);
2714 CalculatePositions();
2716 RefreshSubtree(item
);
2718 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
2719 ProcessEvent( event
);
2722 void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId
& item
)
2725 DeleteChildren(item
);
2728 void wxTreeListMainWindow::Toggle(const wxTreeItemId
& itemId
)
2730 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2732 if (item
->IsExpanded())
2738 void wxTreeListMainWindow::Unselect()
2742 m_current
->SetHilight( FALSE
);
2743 RefreshLine( m_current
);
2747 void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem
*item
)
2749 if (item
->IsSelected())
2751 item
->SetHilight(FALSE
);
2755 if (item
->HasChildren())
2757 wxArrayTreeListItems
& children
= item
->GetChildren();
2758 size_t count
= children
.Count();
2759 for ( size_t n
= 0; n
< count
; ++n
)
2761 UnselectAllChildren(children
[n
]);
2766 void wxTreeListMainWindow::UnselectAll()
2768 UnselectAllChildren((wxTreeListItem
*)GetRootItem().m_pItem
);
2771 // Recursive function !
2772 // To stop we must have crt_item<last_item
2774 // Tag all next children, when no more children,
2775 // Move to parent (not to tag)
2776 // Keep going... if we found last_item, we stop.
2777 bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2779 wxTreeListItem
*parent
= crt_item
->GetItemParent();
2781 if (parent
== NULL
) // This is root item
2782 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
2784 wxArrayTreeListItems
& children
= parent
->GetChildren();
2785 int index
= children
.Index(crt_item
);
2786 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2788 size_t count
= children
.Count();
2789 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
2791 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
2794 return TagNextChildren(parent
, last_item
, select
);
2797 bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2799 crt_item
->SetHilight(select
);
2800 RefreshLine(crt_item
);
2802 if (crt_item
==last_item
)
2805 if (crt_item
->HasChildren())
2807 wxArrayTreeListItems
& children
= crt_item
->GetChildren();
2808 size_t count
= children
.Count();
2809 for ( size_t n
= 0; n
< count
; ++n
)
2811 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
2819 void wxTreeListMainWindow::SelectItemRange(wxTreeListItem
*item1
, wxTreeListItem
*item2
)
2821 // item2 is not necessary after item1
2822 wxTreeListItem
*first
=NULL
, *last
=NULL
;
2824 // choice first' and 'last' between item1 and item2
2825 if (item1
->GetY()<item2
->GetY())
2836 bool select
= m_current
->IsSelected();
2838 if ( TagAllChildrenUntilLast(first
,last
,select
) )
2841 TagNextChildren(first
,last
,select
);
2844 void wxTreeListMainWindow::SelectItem(const wxTreeItemId
& itemId
,
2845 bool unselect_others
,
2846 bool extended_select
)
2848 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2850 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
2851 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2853 //wxCHECK_RET( ( (!unselect_others) && is_single),
2854 // wxT("this is a single selection tree") );
2856 // to keep going anyhow !!!
2859 if (item
->IsSelected())
2860 return; // nothing to do
2861 unselect_others
= TRUE
;
2862 extended_select
= FALSE
;
2864 else if ( unselect_others
&& item
->IsSelected() )
2866 // selection change if there is more than one item currently selected
2867 wxArrayTreeItemIds selected_items
;
2868 if ( GetSelections(selected_items
) == 1 )
2872 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2873 event
.SetItem( (void*)item
);
2874 event
.SetOldItem( (void*)m_current
);
2875 event
.SetEventObject( /*this*/m_owner
);
2876 // TODO : Here we don't send any selection mode yet !
2878 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2881 wxTreeItemId parent
= GetItemParent( itemId
);
2882 while (parent
.IsOk())
2884 if (!IsExpanded(parent
))
2887 parent
= GetItemParent( parent
);
2890 EnsureVisible( itemId
);
2893 if (unselect_others
)
2895 if (is_single
) Unselect(); // to speed up thing
2900 if (extended_select
)
2904 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
2907 // don't change the mark (m_current)
2908 SelectItemRange(m_current
, item
);
2912 bool select
=TRUE
; // the default
2914 // Check if we need to toggle hilight (ctrl mode)
2915 if (!unselect_others
)
2916 select
=!item
->IsSelected();
2918 m_current
= m_key_current
= item
;
2919 m_current
->SetHilight(select
);
2920 RefreshLine( m_current
);
2923 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2924 GetEventHandler()->ProcessEvent( event
);
2927 void wxTreeListMainWindow::SelectAll(bool extended_select
)
2929 wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE
, wxT("invalid tree style, must have wxTR_MULTIPLE style to select all items") );
2931 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2932 event
.SetItem( GetRootItem() );
2933 event
.SetOldItem( (void*) m_current
);
2934 event
.SetEventObject( /*this*/m_owner
);
2935 // TODO : Here we don't send any selection mode yet !
2937 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2941 if (!extended_select
)
2949 #if !wxCHECK_VERSION(2, 5, 0)
2952 wxTreeItemIdValue cookie
= 0;
2954 wxTreeItemId root
= GetRootItem();
2955 wxTreeListItem
*first
= (wxTreeListItem
*)GetFirstChild (root
, cookie
).m_pItem
;
2956 wxTreeListItem
*last
= (wxTreeListItem
*)GetLastChild (GetRootItem()).m_pItem
;
2957 if (!first
|| !last
) return;
2958 if (TagAllChildrenUntilLast (first
, last
, true)) return;
2959 TagNextChildren (first
, last
, true);
2961 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2962 GetEventHandler()->ProcessEvent( event
);
2965 void wxTreeListMainWindow::FillArray(wxTreeListItem
*item
,
2966 wxArrayTreeItemIds
&array
) const
2968 if ( item
->IsSelected() )
2969 array
.Add(wxTreeItemId(item
));
2971 if ( item
->HasChildren() )
2973 wxArrayTreeListItems
& children
= item
->GetChildren();
2974 size_t count
= children
.GetCount();
2975 for ( size_t n
= 0; n
< count
; ++n
)
2976 FillArray(children
[n
], array
);
2980 size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds
&array
) const
2983 wxTreeItemId idRoot
= GetRootItem();
2984 if ( idRoot
.IsOk() )
2986 FillArray((wxTreeListItem
*) idRoot
.m_pItem
, array
);
2988 //else: the tree is empty, so no selections
2990 return array
.Count();
2993 void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId
& item
)
2995 if (!item
.IsOk()) return;
2997 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2999 // first expand all parent branches
3000 wxTreeListItem
*parent
= gitem
->GetItemParent();
3004 parent
= parent
->GetItemParent();
3007 //if (parent) CalculatePositions();
3012 void wxTreeListMainWindow::ScrollTo(const wxTreeItemId
&item
)
3014 if (!item
.IsOk()) return;
3016 // We have to call this here because the label in
3017 // question might just have been added and no screen
3018 // update taken place.
3019 if (m_dirty
) wxYieldIfNeeded();
3021 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
3023 // now scroll to the item
3024 int item_y
= gitem
->GetY();
3028 GetViewStart( &start_x
, &start_y
);
3029 start_y
*= PIXELS_PER_UNIT
;
3033 GetClientSize( &client_w
, &client_h
);
3035 if (item_y
< start_y
+3)
3040 m_anchor
->GetSize( x
, y
, this );
3041 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3042 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3043 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3044 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3045 // Item should appear at top
3046 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
3048 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
3053 m_anchor
->GetSize( x
, y
, this );
3054 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3055 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3056 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
3057 item_y
+= PIXELS_PER_UNIT
+2;
3058 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3059 // Item should appear at bottom
3060 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
);
3064 // FIXME: tree sorting functions are not reentrant and not MT-safe!
3065 static wxTreeListMainWindow
*s_treeBeingSorted
= NULL
;
3067 static int LINKAGEMODE
tree_ctrl_compare_func(wxTreeListItem
**item1
,
3068 wxTreeListItem
**item2
)
3070 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") );
3072 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
3075 int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId
& item1
,
3076 const wxTreeItemId
& item2
)
3078 // ALB: delegate to m_owner, to let the user overrride the comparison
3079 //return wxStrcmp(GetItemText(item1), GetItemText(item2));
3080 return m_owner
->OnCompareItems(item1
, item2
);
3083 void wxTreeListMainWindow::SortChildren(const wxTreeItemId
& itemId
)
3085 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
3087 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
3089 wxCHECK_RET( !s_treeBeingSorted
,
3090 wxT("wxTreeListMainWindow::SortChildren is not reentrant") );
3092 wxArrayTreeListItems
& children
= item
->GetChildren();
3093 if ( children
.Count() > 1 )
3097 s_treeBeingSorted
= this;
3098 children
.Sort(tree_ctrl_compare_func
);
3099 s_treeBeingSorted
= NULL
;
3101 //else: don't make the tree dirty as nothing changed
3104 wxTreeItemId
wxTreeListMainWindow::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
) {
3105 #if !wxCHECK_VERSION(2, 5, 0)
3108 wxTreeItemIdValue cookie
= 0;
3110 wxTreeItemId next
= item
;
3111 if (!next
.IsOk()) next
= GetSelection();
3113 if (HasFlag(wxTR_HIDE_ROOT
)) {
3114 next
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3116 next
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3119 if (!next
.IsOk()) return item
;
3121 // start checking the next items
3123 while (next
.IsOk()) {
3124 itemText
= GetItemText (next
);
3125 if (flags
& wxTL_SEARCH_LEVEL
) {
3126 next
= GetNextSibling (next
);
3127 }else if (flags
& wxTL_SEARCH_FULL
) {
3128 wxTreeItemId n
= GetFirstChild (next
, cookie
);
3130 n
= GetNextSibling (next
);
3132 n
= GetNextSibling (GetItemParent (next
));
3134 }else{ // wxTL_SEARCH_VISIBLE
3135 next
= GetNextVisible (next
);
3137 if (!next
.IsOk()) break; // done
3138 if (flags
& wxTL_SEARCH_PARTIAL
) {
3139 itemText
= GetItemText (next
).Mid (0, str
.Length());
3141 itemText
= GetItemText (next
);
3143 if (flags
& wxTL_SEARCH_NOCASE
) {
3144 if (itemText
.CmpNoCase (str
) == 0) return next
;
3146 if (itemText
.Cmp (str
) == 0) return next
;
3152 wxImageList
*wxTreeListMainWindow::GetImageList() const
3154 return m_imageListNormal
;
3157 wxImageList
*wxTreeListMainWindow::GetButtonsImageList() const
3159 return m_imageListButtons
;
3162 wxImageList
*wxTreeListMainWindow::GetStateImageList() const
3164 return m_imageListState
;
3167 void wxTreeListMainWindow::CalculateLineHeight()
3169 wxClientDC
dc(this);
3170 dc
.SetFont( m_normalFont
);
3171 m_lineHeight
= (int)(dc
.GetCharHeight() + m_linespacing
);
3173 if ( m_imageListNormal
)
3175 // Calculate a m_lineHeight value from the normal Image sizes.
3176 // May be toggle off. Then wxTreeListMainWindow will spread when
3177 // necessary (which might look ugly).
3178 int n
= m_imageListNormal
->GetImageCount();
3179 for (int i
= 0; i
< n
; i
++)
3181 int width
= 0, height
= 0;
3182 m_imageListNormal
->GetSize(i
, width
, height
);
3183 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3187 if (m_imageListButtons
)
3189 // Calculate a m_lineHeight value from the Button image sizes.
3190 // May be toggle off. Then wxTreeListMainWindow will spread when
3191 // necessary (which might look ugly).
3192 int n
= m_imageListButtons
->GetImageCount();
3193 for (int i
= 0; i
< n
; i
++)
3195 int width
= 0, height
= 0;
3196 m_imageListButtons
->GetSize(i
, width
, height
);
3197 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3201 /*? FIXME: Don't get what this code is for... Adding a line space is already done!!!
3202 if (m_lineHeight < 30)
3203 m_lineHeight += 2; // at least 2 pixels
3205 m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing
3209 void wxTreeListMainWindow::SetImageList(wxImageList
*imageList
)
3211 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3212 m_imageListNormal
= imageList
;
3213 m_ownsImageListNormal
= FALSE
;
3215 CalculateLineHeight();
3218 void wxTreeListMainWindow::SetStateImageList(wxImageList
*imageList
)
3220 if (m_ownsImageListState
) delete m_imageListState
;
3221 m_imageListState
= imageList
;
3222 m_ownsImageListState
= FALSE
;
3225 void wxTreeListMainWindow::SetButtonsImageList(wxImageList
*imageList
)
3227 if (m_ownsImageListButtons
) delete m_imageListButtons
;
3228 m_imageListButtons
= imageList
;
3229 m_ownsImageListButtons
= FALSE
;
3231 CalculateLineHeight();
3234 void wxTreeListMainWindow::AssignImageList(wxImageList
*imageList
)
3236 SetImageList(imageList
);
3237 m_ownsImageListNormal
= TRUE
;
3240 void wxTreeListMainWindow::AssignStateImageList(wxImageList
*imageList
)
3242 SetStateImageList(imageList
);
3243 m_ownsImageListState
= TRUE
;
3246 void wxTreeListMainWindow::AssignButtonsImageList(wxImageList
*imageList
)
3248 SetButtonsImageList(imageList
);
3249 m_ownsImageListButtons
= TRUE
;
3252 // ----------------------------------------------------------------------------
3254 // ----------------------------------------------------------------------------
3256 void wxTreeListMainWindow::AdjustMyScrollbars()
3261 m_anchor
->GetSize( x
, y
, this );
3262 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3263 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3264 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3265 int y_pos
= GetScrollPos( wxVERTICAL
);
3266 x
= m_owner
->GetHeaderWindow()->GetWidth() + 2;
3267 if(x
< GetClientSize().GetWidth()) x_pos
= 0;
3268 //m_total_col_width + 2; // ALB
3269 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
,
3270 y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
3274 SetScrollbars( 0, 0, 0, 0 );
3278 int wxTreeListMainWindow::GetLineHeight(wxTreeListItem
*item
) const
3280 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
3281 return item
->GetHeight();
3283 return m_lineHeight
;
3286 void wxTreeListMainWindow::PaintItem(wxTreeListItem
*item
, wxDC
& dc
)
3288 wxTreeItemAttr
*attr
= item
->GetAttributes();
3289 if (attr
&& attr
->HasFont()) {
3290 dc
.SetFont(attr
->GetFont());
3291 }else if (item
->IsBold()) {
3292 dc
.SetFont(m_boldFont
);
3295 if (attr
&& attr
->HasTextColour()) {
3296 colText
= attr
->GetTextColour();
3298 colText
= GetForegroundColour();
3301 dc
.SetPen(*wxTRANSPARENT_PEN
);
3303 long text_w
= 0, text_h
= 0;
3305 dc
.GetTextExtent( item
->GetText(GetMainColumn()), &text_w
, &text_h
);
3307 int total_h
= GetLineHeight(item
);
3309 if (item
->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT
)) {
3310 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3311 dc
.SetPen(*wxBLACK_PEN
);
3312 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3315 if (attr
&& attr
->HasBackgroundColour()) {
3316 colBg
= attr
->GetBackgroundColour();
3318 colBg
= GetBackgroundColour();
3320 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
3323 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
3324 dc
.DrawRectangle(0, item
->GetY() + offset
,
3325 m_owner
->GetHeaderWindow()->GetWidth(), total_h
-offset
);
3327 dc
.SetBackgroundMode(wxTRANSPARENT
);
3328 int text_extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
3329 int img_extraH
= (total_h
> m_imgHeight
)? (total_h
-m_imgHeight
)/2: 0;
3331 for ( size_t i
= 0; i
< GetColumnCount(); ++i
) {
3332 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3333 int colwidth
= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
3337 if (i
== GetMainColumn()) {
3338 image
= item
->GetCurrentImage();
3339 if (item
->HasPlus()) {
3340 image_x
= item
->GetX() + (m_btnWidth
-m_btnWidth2
) + LINEATROOT
;
3342 image_x
= item
->GetX() - m_imgWidth2
;
3347 image
= item
->GetImage(i
);
3348 image_x
= x_colstart
+ MARGIN
;
3350 if (image
!= NO_IMAGE
) image_w
= m_imgWidth
+ MARGIN
;
3352 // honor text alignment
3353 wxString text
= item
->GetText(i
);
3354 switch ( m_owner
->GetHeaderWindow()->GetColumn(i
).GetAlignment() ) {
3355 case wxTL_ALIGN_LEFT
:
3356 // already left aligned
3358 case wxTL_ALIGN_RIGHT
:
3359 dc
.GetTextExtent(text
, &text_w
, NULL
);
3360 image_x
= x_colstart
+ colwidth
- (image_w
+ text_w
+ MARGIN
);
3362 case wxTL_ALIGN_CENTER
:
3363 dc
.GetTextExtent(text
, &text_w
, NULL
);
3364 int w
= colwidth
- image_w
- text_w
;
3365 image_x
= x_colstart
+ (w
> 0)? w
: 0;
3368 int text_x
= image_x
+ image_w
;
3370 if (item
->IsSelected() && (i
==GetMainColumn()) && !HasFlag(wxTR_FULL_ROW_HIGHLIGHT
))
3372 dc
.SetPen(*wxBLACK_PEN
);
3373 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3374 int offset
= HasFlag (wxTR_ROW_LINES
) ? 1 : 0;
3375 int width
= wxMin(text_w
+2, colwidth
- text_x
- x_colstart
);
3376 dc
.DrawRectangle(text_x
-1, item
->GetY() + offset
, width
, total_h
-offset
);
3377 dc
.SetBackgroundMode(wxTRANSPARENT
);
3378 dc
.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
3380 dc
.SetTextForeground(colText
);
3383 wxDCClipper
clipper (dc
, x_colstart
, item
->GetY(), colwidth
, total_h
);
3384 if (image
!= NO_IMAGE
)
3386 int image_y
= item
->GetY() + img_extraH
;
3387 m_imageListNormal
->Draw ( image
, dc
, image_x
, image_y
,
3388 wxIMAGELIST_DRAW_TRANSPARENT
);
3390 int text_y
= item
->GetY() + text_extraH
;
3391 dc
.DrawText ( text
, (wxCoord
)text_x
, (wxCoord
)text_y
);
3393 x_colstart
+= colwidth
;
3396 // restore normal font
3397 dc
.SetFont( m_normalFont
);
3400 // Now y stands for the top of the item, whereas it used to stand for middle !
3401 void wxTreeListMainWindow::PaintLevel (wxTreeListItem
*item
, wxDC
&dc
,
3402 int level
, int &y
, int x_colstart
)
3404 // Handle hide root (only level 0)
3405 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) {
3406 // always expand hidden root
3407 wxArrayTreeListItems
& children
= item
->GetChildren();
3409 for (n
= 0; n
< (int)children
.Count(); n
++) {
3410 PaintLevel (children
[n
], dc
, 1, y
, x_colstart
);
3412 // end after expanding root
3416 // calculate position of vertical lines
3417 int x
= x_colstart
+ MARGIN
; // start of column
3418 if (HasFlag (wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
3420 x
+= m_btnWidth2
; // middle of button
3422 if (m_imgWidth
> 0) x
+= m_imgWidth2
; // middle of image
3424 if (!HasFlag (wxTR_HIDE_ROOT
)) {
3425 x
+= m_indent
* level
; // indent according to level
3427 if (level
> 0) x
+= m_indent
* (level
-1); // but not level 1
3430 // handle column text
3434 int h
= GetLineHeight(item
);
3436 int y_mid
= y_top
+ (h
/2);
3439 int exposed_x
= dc
.LogicalToDeviceX(0);
3440 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
3442 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
3445 PaintItem(item
, dc
);
3447 if (HasFlag(wxTR_ROW_LINES
))
3449 //dc.DestroyClippingRegion();
3450 int total_width
= m_owner
->GetHeaderWindow()->GetWidth();
3451 // if the background colour is white, choose a
3452 // contrasting color for the lines
3453 dc
.SetPen(((GetBackgroundColour() == *wxWHITE
) ?
3454 wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
) : *wxWHITE_PEN
));
3455 dc
.DrawLine(0, y_top
, total_width
, y_top
);
3456 dc
.DrawLine(0, y
, total_width
, y
);
3459 // restore DC objects
3460 dc
.SetBrush(*wxWHITE_BRUSH
);
3461 dc
.SetPen(m_dottedPen
);
3463 if (((level
== 0) || ((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) &&
3464 HasFlag(wxTR_LINES_AT_ROOT
) && !HasFlag(wxTR_NO_LINES
)) {
3465 int rootPos
= x_colstart
+ MARGIN
;
3466 dc
.DrawLine (rootPos
, y_mid
, rootPos
+LINEATROOT
, y_mid
);
3469 size_t clip_width
= m_owner
->GetHeaderWindow()->
3470 GetColumn(m_main_column
).GetWidth();
3472 if (item
->HasPlus() && HasButtons()) // should the item show a button?
3474 // clip to the column width
3475 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3477 if ( !HasFlag(wxTR_NO_LINES
) )
3479 // draw the horizontal line here
3481 if (x
> (signed)m_indent
)
3482 x_start
-= m_indent
;
3483 else if (HasFlag(wxTR_LINES_AT_ROOT
))
3485 dc
.DrawLine(x_start
, y_mid
, x
/*+ m_spacing*/, y_mid
);
3488 if (m_imageListButtons
!= NULL
)
3490 // draw the image button here
3491 int image
= wxTreeItemIcon_Normal
;
3492 if (item
->IsExpanded()) image
= wxTreeItemIcon_Expanded
;
3493 if (item
->IsSelected())
3494 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
3495 int xx
= x
+ m_btnWidth2
;
3496 int yy
= y_mid
- m_btnHeight2
;
3497 dc
.SetClippingRegion(xx
, yy
, m_btnWidth
, m_btnHeight
);
3498 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
3499 wxIMAGELIST_DRAW_TRANSPARENT
);
3500 dc
.DestroyClippingRegion();
3502 else // no custom buttons
3504 static const int wImage
= 9;
3505 static const int hImage
= 9;
3508 if (item
->IsExpanded())
3509 flag
|= wxCONTROL_EXPANDED
;
3510 if (item
== m_underMouse
)
3511 flag
|= wxCONTROL_CURRENT
;
3513 wxRendererNative::Get().DrawTreeItemButton(
3515 wxRect(x
- wImage
/2, y_mid
- hImage
/2, wImage
, hImage
),
3519 if (!HasFlag(wxTR_NO_LINES
)) {
3520 if (/*!(level == 0) &&*/ !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3521 if (m_imgWidth
> 0) {
3522 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_indent
-m_imgWidth2
, y_mid
);
3524 dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_btnWidth2
+LINEATROOT
-MARGIN
, y_mid
);
3529 else if (!HasFlag(wxTR_NO_LINES
)) // no button; maybe a line?
3531 // clip to the column width
3532 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3534 // draw the horizontal line here
3535 if (/*!(level == 0) &&*/ !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3536 int x2
= x
- m_indent
;
3537 if (m_imgWidth
> 0) {
3538 dc
.DrawLine(x2
, y_mid
, x2
+m_indent
-m_imgWidth2
, y_mid
);
3540 dc
.DrawLine(x2
, y_mid
, x2
+m_btnWidth2
+LINEATROOT
+MARGIN
, y_mid
);
3546 // restore DC objects
3547 dc
.SetBrush(*wxWHITE_BRUSH
);
3548 dc
.SetPen(m_dottedPen
);
3549 dc
.SetTextForeground(*wxBLACK
);
3551 if (item
->IsExpanded())
3553 wxArrayTreeListItems
& children
= item
->GetChildren();
3554 int count
= children
.Count();
3557 // paint sublevel items first
3558 for (n
=0; n
<count
; ++n
) {
3560 PaintLevel(children
[n
], dc
, level
+1, y
, x_colstart
);
3563 // then draw the connecting lines
3564 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
3566 // clip to the column width
3567 size_t clip_width
= m_owner
->GetHeaderWindow()->GetColumn(m_main_column
).GetWidth();
3568 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3570 // draw line down to last child
3571 oldY
+= GetLineHeight(children
[n
-1]) >> 1;
3572 if (HasButtons()) y_mid
+= 5;
3573 dc
.DrawLine(x
, y_mid
, x
, oldY
);
3578 void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem
*item
)
3582 if ( item
->HasPlus() )
3584 // it's a folder, indicate it by a border
3589 // draw a line under the drop target because the item will be
3591 DrawLine(item
, TRUE
/* below */);
3594 SetCursor(wxCURSOR_BULLSEYE
);
3599 SetCursor(wxCURSOR_NO_ENTRY
);
3603 void wxTreeListMainWindow::DrawBorder(const wxTreeItemId
&item
)
3605 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3607 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3609 wxClientDC
dc(this);
3611 dc
.SetLogicalFunction(wxINVERT
);
3612 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3614 int w
= i
->GetWidth() + 2;
3615 int h
= GetLineHeight(i
) + 2;
3617 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
3620 void wxTreeListMainWindow::DrawLine(const wxTreeItemId
&item
, bool below
)
3622 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3624 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3626 wxClientDC
dc(this);
3628 dc
.SetLogicalFunction(wxINVERT
);
3634 y
+= GetLineHeight(i
) - 1;
3637 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
3640 // ----------------------------------------------------------------------------
3641 // wxWindows callbacks
3642 // ----------------------------------------------------------------------------
3644 void wxTreeListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3650 if(!GetColumnCount()) return; // ALB
3655 // calculate button size
3656 m_btnWidth
= 0, m_btnWidth2
= 0;
3657 m_btnHeight
= 0, m_btnHeight2
= 0;
3658 if (m_imageListButtons
) {
3659 m_imageListButtons
->GetSize (0, m_btnWidth
, m_btnHeight
);
3660 }else if (HasButtons()) {
3661 m_btnWidth
= BTNWIDTH
;
3662 m_btnHeight
= BTNHEIGHT
;
3664 m_btnWidth2
= m_btnWidth
/2;
3665 m_btnHeight2
= m_btnHeight
/2;
3667 // calculate image size
3668 m_imgWidth
= 0, m_imgWidth2
= 0;
3669 m_imgHeight
= 0, m_imgHeight2
= 0;
3670 if (m_imageListNormal
) {
3671 m_imageListNormal
->GetSize (0, m_imgWidth
, m_imgHeight
);
3672 m_imgWidth
+= 4; //? ToDo: Why + 4?
3674 m_imgWidth2
= m_imgWidth
/2;
3675 m_imgHeight2
= m_imgHeight
/2;
3677 // calculate indent size
3678 int btnIndent
= HasButtons()? m_btnWidth
+ LINEATROOT
: 0;
3679 m_indent
= wxMax (MININDENT
, wxMax (m_imgWidth
, btnIndent
)) + MARGIN
;
3681 // set default values
3682 dc
.SetFont( m_normalFont
);
3683 dc
.SetPen( m_dottedPen
);
3685 // this is now done dynamically
3686 //if(GetImageList() == NULL)
3687 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3689 // calculate column start and paint
3692 for (i
= 0; i
< (int)GetMainColumn(); ++i
) {
3693 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3694 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth (i
);
3697 PaintLevel ( m_anchor
, dc
, 0, y
, x_colstart
);
3700 void wxTreeListMainWindow::OnSetFocus( wxFocusEvent
&event
)
3709 void wxTreeListMainWindow::OnKillFocus( wxFocusEvent
&event
)
3718 void wxTreeListMainWindow::OnChar( wxKeyEvent
&event
)
3720 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, m_owner
->GetId() );
3721 te
.SetKeyEvent( event
);
3722 te
.SetEventObject( /*this*/m_owner
);
3723 if ( m_owner
->GetEventHandler()->ProcessEvent( te
) )
3725 // intercepted by the user code
3731 if (HasFlag(wxTR_HIDE_ROOT
)) {
3732 #if !wxCHECK_VERSION(2, 5, 0)
3735 wxTreeItemIdValue cookie
= 0;
3737 m_current
= m_key_current
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
;
3741 m_current
= m_key_current
= (wxTreeListItem
*)GetRootItem().m_pItem
;
3745 // how should the selection work for this event?
3746 bool is_multiple
, extended_select
, unselect_others
;
3747 EventFlagsToSelType(GetWindowStyleFlag(),
3749 event
.ControlDown(),
3750 is_multiple
, extended_select
, unselect_others
);
3752 // + : Expand (not on Win32)
3753 // - : Collaspe (not on Win32)
3754 // * : Expand all/Collapse all
3755 // ' ' | return : activate
3756 // up : go up (not last children!)
3758 // left : go to parent (or collapse on Win32)
3759 // right : open if parent and go next (or expand on Win32)
3760 // home : go to root
3761 // end : go to last item without opening parents
3762 switch (event
.GetKeyCode())
3764 #ifndef __WXMSW__ // mimic the standard win32 tree ctrl
3767 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3776 if ( !IsExpanded(m_current
) )
3779 ExpandAll (m_current
);
3782 //else: fall through to Collapse() it
3784 #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour
3787 if (IsExpanded(m_current
))
3789 Collapse (m_current
);
3797 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
3799 event
.SetItem( (void*) m_current
);
3800 event
.SetEventObject( /*this*/m_owner
);
3801 m_owner
->GetEventHandler()->ProcessEvent( event
);
3805 // backspace goes to the parent, sends "root" activation
3808 wxTreeItemId prev
= GetItemParent( m_current
);
3809 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3811 // don't go to root if it is hidden
3812 prev
= GetPrevSibling( m_current
);
3816 SelectItem( prev
, unselect_others
, extended_select
);
3817 EnsureVisible( prev
);
3822 // up goes to the previous sibling or to the last
3823 // of its children if it's expanded
3826 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
3829 prev
= GetItemParent( m_key_current
);
3830 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3832 break; // don't go to root if it is hidden
3836 #if !wxCHECK_VERSION(2, 5, 0)
3839 wxTreeItemIdValue cookie
= 0;
3841 wxTreeItemId current
= m_key_current
;
3842 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
3843 if (current
== GetFirstChild( prev
, cookie
))
3845 // otherwise we return to where we came from
3846 SelectItem( prev
, unselect_others
, extended_select
);
3847 m_key_current
= (wxTreeListItem
*) prev
.m_pItem
;
3848 EnsureVisible( prev
);
3855 while ( IsExpanded(prev
) && HasChildren(prev
) )
3857 wxTreeItemId child
= GetLastChild(prev
);
3865 SelectItem( prev
, unselect_others
, extended_select
);
3866 m_key_current
=(wxTreeListItem
*) prev
.m_pItem
;
3867 EnsureVisible( prev
);
3872 // left arrow goes to the parent
3874 if (IsExpanded(m_current
))
3876 Collapse(m_current
);
3880 wxTreeItemId prev
= GetItemParent( m_current
);
3881 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3883 // don't go to root if it is hidden
3884 prev
= GetPrevSibling( m_current
);
3888 SelectItem( prev
, unselect_others
, extended_select
);
3889 EnsureVisible( prev
);
3895 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl
3896 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3903 // this works the same as the down arrow except that we
3904 // also expand the item if it wasn't expanded yet
3910 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
3912 #if !wxCHECK_VERSION(2, 5, 0)
3915 wxTreeItemIdValue cookie
= 0;
3917 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
3919 SelectItem( child
, unselect_others
, extended_select
);
3920 m_key_current
=(wxTreeListItem
*) child
.m_pItem
;
3921 EnsureVisible( child
);
3925 wxTreeItemId next
= GetNextSibling( m_key_current
);
3928 wxTreeItemId current
= m_key_current
;
3929 while (current
&& !next
)
3931 current
= GetItemParent( current
);
3932 if (current
) next
= GetNextSibling( current
);
3937 SelectItem( next
, unselect_others
, extended_select
);
3938 m_key_current
=(wxTreeListItem
*) next
.m_pItem
;
3939 EnsureVisible( next
);
3944 // <End> selects the last visible tree item
3947 wxTreeItemId last
= GetRootItem();
3949 while ( last
.IsOk() && IsExpanded(last
) )
3951 wxTreeItemId lastChild
= GetLastChild(last
);
3953 // it may happen if the item was expanded but then all of
3954 // its children have been deleted - so IsExpanded() returned
3955 // TRUE, but GetLastChild() returned invalid item
3964 SelectItem( last
, unselect_others
, extended_select
);
3965 EnsureVisible( last
);
3970 // <Home> selects the root item
3973 wxTreeItemId prev
= GetRootItem();
3975 if (HasFlag(wxTR_HIDE_ROOT
))
3977 #if !wxCHECK_VERSION(2, 5, 0)
3980 wxTreeItemIdValue cookie
= 0;
3982 prev
= GetFirstChild(prev
, cookie
);
3985 SelectItem( prev
, unselect_others
, extended_select
);
3986 EnsureVisible( prev
);
3991 if (event
.m_keyCode
>= (int)' ') {
3992 if (!m_findTimer
->IsRunning()) m_findStr
.Clear();
3993 m_findStr
.Append (event
.m_keyCode
);
3994 m_findTimer
->Start (500, wxTIMER_ONE_SHOT
);
3995 wxTreeItemId dummy
= (wxTreeItemId
*)NULL
;
3996 wxTreeItemId item
= FindItem (dummy
, m_findStr
, wxTL_SEARCH_VISIBLE
|
3997 wxTL_SEARCH_PARTIAL
|
3998 wxTL_SEARCH_NOCASE
);
4000 EnsureVisible (item
);
4008 wxTreeItemId
wxTreeListMainWindow::HitTest(const wxPoint
& point
, int& flags
,
4011 // JACS: removed wxYieldIfNeeded() because it can cause the window
4012 // to be deleted from under us if a close window event is pending
4018 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
4019 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
4020 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
4021 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
4022 if (flags
) return wxTreeItemId();
4024 if (m_anchor
== NULL
)
4026 flags
= wxTREE_HITTEST_NOWHERE
;
4027 return wxTreeItemId();
4030 wxTreeListItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
4031 this, flags
, column
, 0);
4034 flags
= wxTREE_HITTEST_NOWHERE
;
4035 return wxTreeItemId();
4040 // get the bounding rectangle of the item (or of its label only)
4041 bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId
& item
,
4043 bool WXUNUSED(textOnly
)) const
4045 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") );
4047 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
4050 GetViewStart(& startX
, & startY
);
4052 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
4053 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
4054 rect
.width
= i
->GetWidth();
4055 //rect.height = i->GetHeight();
4056 rect
.height
= GetLineHeight(i
);
4063 void wxTreeListMainWindow::Edit( const wxTreeItemId
& item
)
4065 if (!item
.IsOk()) return;
4067 m_currentEdit
= (wxTreeListItem
*) item
.m_pItem
;
4069 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, m_owner
->GetId() );
4070 te
.SetItem( (void*) m_currentEdit
);
4071 te
.SetEventObject( /*this*/m_owner
);
4072 m_owner
->GetEventHandler()->ProcessEvent( te
);
4074 if (!te
.IsAllowed()) return;
4076 // We have to call this here because the label in
4077 // question might just have been added and no screen
4078 // update taken place.
4079 if (m_dirty
) wxYieldIfNeeded();
4081 wxString s
= m_currentEdit
->GetText(/*ALB*/m_main_column
);
4082 int x
= m_currentEdit
->GetX() + m_imgWidth2
;
4083 int y
= m_currentEdit
->GetY();
4084 int w
= wxMin (m_currentEdit
->GetWidth(),
4085 m_owner
->GetHeaderWindow()->GetWidth()) - m_imgWidth2
;
4086 int h
= m_currentEdit
->GetHeight() + 2;
4087 wxClientDC
dc(this);
4089 x
= dc
.LogicalToDeviceX( x
);
4090 y
= dc
.LogicalToDeviceY( y
);
4092 wxTreeListTextCtrl
*text
= new wxTreeListTextCtrl(this, -1,
4102 void wxTreeListMainWindow::OnRenameTimer()
4107 void wxTreeListMainWindow::OnRenameAccept()
4109 // TODO if the validator fails this causes a crash
4110 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, m_owner
->GetId() );
4111 le
.SetItem( (void*)m_currentEdit
);
4112 le
.SetEventObject( /*this*/m_owner
);
4113 le
.SetLabel( m_renameRes
);
4114 m_owner
->GetEventHandler()->ProcessEvent( le
);
4116 if (!le
.IsAllowed()) return;
4118 SetItemText( m_currentEdit
, m_renameRes
);
4121 void wxTreeListMainWindow::OnMouse( wxMouseEvent
&event
)
4123 if ( !m_anchor
) return;
4125 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
4127 // Is the mouse over a tree item button?
4129 wxTreeListItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
4130 wxTreeListItem
*underMouse
= item
;
4132 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
4133 #endif // wxUSE_TOOLTIPS
4135 if (underMouse
&& (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
4136 !event
.LeftIsDown() && !m_isDragging
&&
4137 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
4145 if (underMouse
!= m_underMouse
)
4149 // unhighlight old item
4150 wxTreeListItem
*tmp
= m_underMouse
;
4151 m_underMouse
= NULL
;
4155 m_underMouse
= underMouse
;
4157 RefreshLine( m_underMouse
);
4161 // Determines what item we are hovering over and need a tooltip for
4162 wxTreeItemId hoverItem
= item
;
4164 // We do not want a tooltip if we are dragging, or if the rename timer is running
4165 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
4167 // Ask the tree control what tooltip (if any) should be shown
4168 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
4169 hevent
.SetItem(hoverItem
);
4170 hevent
.SetEventObject(this);
4172 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
4174 SetToolTip(hevent
.GetLabel());
4179 // we process left mouse up event (enables in-place edit), right down
4180 // (pass to the user code), left dbl click (activate item) and
4181 // dragging/moving events for items drag-and-drop
4182 if ( !(event
.LeftDown() ||
4184 event
.RightDown() ||
4185 event
.LeftDClick() ||
4187 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
4193 if ( event
.LeftDown() )
4196 // wxClientDC dc(this);
4198 // wxCoord x = dc.DeviceToLogicalX( event.GetX() );
4199 // wxCoord y = dc.DeviceToLogicalY( event.GetY() );
4203 if ( event
.Dragging() && !m_isDragging
)
4205 if (m_dragCount
== 0)
4206 m_dragStart
= wxPoint(x
,y
);
4210 if (m_dragCount
!= 3)
4212 // wait until user drags a bit further...
4216 wxEventType command
= event
.RightIsDown()
4217 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
4218 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
4220 wxTreeEvent
nevent( command
,/*ALB*/ m_owner
->GetId() );
4221 nevent
.SetItem( (void*)m_current
);
4222 nevent
.SetEventObject(/*this*/m_owner
); // ALB
4223 nevent
.SetPoint(pt
);
4225 // by default the dragging is not supported, the user code must
4226 // explicitly allow the event for it to take place
4229 if ( m_owner
->GetEventHandler()->ProcessEvent(nevent
) &&
4230 nevent
.IsAllowed() )
4232 // we're going to drag this item
4233 m_isDragging
= TRUE
;
4235 // remember the old cursor because we will change it while
4237 m_oldCursor
= m_cursor
;
4239 // in a single selection control, hide the selection temporarily
4240 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
4242 m_oldSelection
= (wxTreeListItem
*) GetSelection().m_pItem
;
4244 if ( m_oldSelection
)
4246 m_oldSelection
->SetHilight(FALSE
);
4247 RefreshLine(m_oldSelection
);
4254 else if ( event
.Moving() )
4256 if ( item
!= m_dropTarget
)
4258 // unhighlight the previous drop target
4259 DrawDropEffect(m_dropTarget
);
4261 m_dropTarget
= item
;
4263 // highlight the current drop target if any
4264 DrawDropEffect(m_dropTarget
);
4269 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
4271 // erase the highlighting
4272 DrawDropEffect(m_dropTarget
);
4274 if ( m_oldSelection
)
4276 m_oldSelection
->SetHilight(TRUE
);
4277 RefreshLine(m_oldSelection
);
4278 m_oldSelection
= (wxTreeListItem
*)NULL
;
4281 // generate the drag end event
4282 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
,/*ALB*/m_owner
->GetId());
4284 event
.SetItem( (void*)item
);
4285 event
.SetPoint( wxPoint(x
, y
) );
4286 event
.SetEventObject(/*this*/m_owner
);
4288 (void)m_owner
->GetEventHandler()->ProcessEvent(event
);
4290 m_isDragging
= FALSE
;
4291 m_dropTarget
= (wxTreeListItem
*)NULL
;
4295 SetCursor(m_oldCursor
);
4301 // here we process only the messages which happen on tree items
4305 if ( item
== NULL
) return; /* we hit the blank area */
4307 if ( event
.RightDown() )
4310 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
,
4312 nevent
.SetItem( (void*)item
);
4314 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4315 nevent
.SetPoint( wxPoint(nx
, ny
));
4316 nevent
.SetEventObject(/*this*/m_owner
);
4317 m_owner
->GetEventHandler()->ProcessEvent(nevent
);
4319 else if ( event
.LeftUp() )
4323 if ( ( item
== m_current
) &&
4324 ( flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
4325 HasFlag(wxTR_EDIT_LABELS
) )
4327 if ( m_renameTimer
->IsRunning() )
4328 m_renameTimer
->Stop();
4330 m_renameTimer
->Start( 100, TRUE
);
4333 m_lastOnSame
= FALSE
;
4336 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
4338 if ( event
.LeftDown() )
4341 m_lastOnSame
= item
== m_current
;
4344 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
4345 ((flags
& wxTREE_HITTEST_ONITEMICON
)) &&
4346 !HasButtons() && item
->HasPlus())
4348 // only toggle the item for a single click, double click on
4349 // the button doesn't do anything (it toggles the item twice)
4350 if ( event
.LeftDown() )
4355 // don't select the item if the button was clicked
4359 // how should the selection work for this event?
4360 bool is_multiple
, extended_select
, unselect_others
;
4361 EventFlagsToSelType(GetWindowStyleFlag(),
4363 event
.ControlDown(),
4364 is_multiple
, extended_select
, unselect_others
);
4366 SelectItem (item
, unselect_others
, extended_select
);
4368 // For some reason, Windows isn't recognizing a left double-click,
4369 // so we need to simulate it here. Allow 200 milliseconds for now.
4370 if ( event
.LeftDClick() )
4372 // double clicking should not start editing the item label
4373 m_renameTimer
->Stop();
4374 m_lastOnSame
= FALSE
;
4376 // send activate event first
4377 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
4379 nevent
.SetItem( (void*)item
);
4381 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4382 nevent
.SetPoint( wxPoint(nx
, ny
) );
4383 nevent
.SetEventObject( /*this*/m_owner
);
4384 if ( !m_owner
->GetEventHandler()->ProcessEvent( nevent
) )
4386 // if the user code didn't process the activate event,
4387 // handle it ourselves by toggling the item when it is
4389 if ( item
->HasPlus() )
4399 void wxTreeListMainWindow::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
4401 /* after all changes have been done to the tree control,
4402 * we actually redraw the tree when everything is over */
4404 if (!m_dirty
) return;
4408 CalculatePositions();
4410 AdjustMyScrollbars();
4413 void wxTreeListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4416 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4417 wxScrolledWindow::OnScroll(event
);
4419 HandleOnScroll( event
);
4422 if(event
.GetOrientation() == wxHORIZONTAL
)
4424 m_owner
->GetHeaderWindow()->Refresh();
4425 m_owner
->GetHeaderWindow()->Update();
4430 void wxTreeListMainWindow::CalculateSize( wxTreeListItem
*item
, wxDC
&dc
)
4436 dc
.SetFont(m_boldFont
);
4438 dc
.GetTextExtent( item
->GetText(/*ALB*/m_main_column
), &text_w
, &text_h
);
4441 // restore normal font
4442 dc
.SetFont( m_normalFont
);
4444 int total_h
= (m_imgHeight
> text_h
) ? m_imgHeight
: text_h
;
4446 item
->SetHeight(total_h
);
4447 if (total_h
>m_lineHeight
)
4448 m_lineHeight
=total_h
;
4450 item
->SetWidth(m_imgWidth
+ text_w
+2);
4453 // -----------------------------------------------------------------------------
4454 // for developper : y is now the top of the level
4455 // not the middle of it !
4456 void wxTreeListMainWindow::CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
,
4457 int level
, int &y
, int x_colstart
)
4459 // calculate position of vertical lines
4460 int x
= x_colstart
+ MARGIN
; // start of column
4461 if (HasFlag(wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
4462 if (HasButtons()) x
+= m_btnWidth2
; // space for buttons etc.
4463 if (!HasFlag(wxTR_HIDE_ROOT
)) x
+= m_indent
; // indent root as well
4464 x
+= m_indent
* level
; // indent according to level
4466 // a hidden root is not evaluated, but its children are always
4467 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) goto Recurse
;
4469 CalculateSize( item
, dc
);
4474 y
+= GetLineHeight(item
);
4476 // we don't need to calculate collapsed branches
4477 if ( !item
->IsExpanded() ) return;
4480 wxArrayTreeListItems
& children
= item
->GetChildren();
4481 size_t n
, count
= children
.Count();
4483 for (n
= 0; n
< count
; ++n
)
4484 CalculateLevel( children
[n
], dc
, level
, y
, x_colstart
); // recurse
4487 void wxTreeListMainWindow::CalculatePositions()
4489 if ( !m_anchor
) return;
4491 wxClientDC
dc(this);
4494 dc
.SetFont( m_normalFont
);
4496 dc
.SetPen( m_dottedPen
);
4497 //if(GetImageList() == NULL)
4498 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
4502 for(size_t i
= 0; i
< GetMainColumn(); ++i
) {
4503 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
4504 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
4506 CalculateLevel( m_anchor
, dc
, 0, y
, x_colstart
); // start recursion
4509 void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem
*item
)
4511 if (m_dirty
) return;
4513 wxClientDC
dc(this);
4518 GetVirtualSize( &cw
, &ch
);
4521 rect
.x
= dc
.LogicalToDeviceX( 0 );
4523 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() - 2 );
4526 Refresh( TRUE
, &rect
);
4528 AdjustMyScrollbars();
4531 void wxTreeListMainWindow::RefreshLine( wxTreeListItem
*item
)
4533 if (m_dirty
) return;
4535 wxClientDC
dc(this);
4540 GetVirtualSize( &cw
, &ch
);
4543 rect
.x
= dc
.LogicalToDeviceX( 0 );
4544 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
4546 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
4548 Refresh( TRUE
, &rect
);
4551 void wxTreeListMainWindow::RefreshSelected()
4553 // TODO: this is awfully inefficient, we should keep the list of all
4554 // selected items internally, should be much faster
4556 RefreshSelectedUnder(m_anchor
);
4559 void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem
*item
)
4561 if ( item
->IsSelected() )
4564 const wxArrayTreeListItems
& children
= item
->GetChildren();
4565 size_t count
= children
.GetCount();
4566 for ( size_t n
= 0; n
< count
; n
++ )
4568 RefreshSelectedUnder(children
[n
]);
4572 // ----------------------------------------------------------------------------
4573 // changing colours: we need to refresh the tree control
4574 // ----------------------------------------------------------------------------
4576 bool wxTreeListMainWindow::SetBackgroundColour(const wxColour
& colour
)
4578 if ( !wxWindow::SetBackgroundColour(colour
) )
4586 bool wxTreeListMainWindow::SetForegroundColour(const wxColour
& colour
)
4588 if ( !wxWindow::SetForegroundColour(colour
) )
4596 //----------- ALB -------------
4597 void wxTreeListMainWindow::SetItemText(const wxTreeItemId
& item
, size_t column
,
4598 const wxString
& text
)
4600 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
4602 wxClientDC
dc(this);
4603 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
4604 pItem
->SetText(column
, text
);
4605 CalculateSize(pItem
, dc
);
4609 wxString
wxTreeListMainWindow::GetItemText(const wxTreeItemId
& item
,
4610 size_t column
) const
4612 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
4614 return ((wxTreeListItem
*) item
.m_pItem
)->GetText(column
);
4617 void wxTreeListMainWindow::SetFocus()
4619 wxWindow::SetFocus();
4623 //-----------------------------------------------------------------------------
4625 //-----------------------------------------------------------------------------
4627 IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl
, wxControl
)
4629 BEGIN_EVENT_TABLE(wxTreeListCtrl
, wxControl
)
4630 EVT_SIZE(wxTreeListCtrl::OnSize
)
4631 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxTreeListCtrl::OnGetToolTip
)
4634 bool wxTreeListCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4637 long style
, const wxValidator
&validator
,
4638 const wxString
& name
)
4640 long main_style
= style
& ~(wxRAISED_BORDER
|wxSUNKEN_BORDER
4641 |wxSIMPLE_BORDER
|wxNO_BORDER
|wxDOUBLE_BORDER
4643 long ctrl_style
= style
& ~(wxVSCROLL
|wxHSCROLL
);
4645 if (!wxControl::Create(parent
, id
, pos
, size
, ctrl_style
, validator
, name
)) {
4648 m_main_win
= new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size
,
4649 main_style
, validator
);
4650 m_header_win
= new wxTreeListHeaderWindow(this, -1, m_main_win
,
4651 wxPoint(0, 0), wxDefaultSize
,
4653 CalculateAndSetHeaderHeight();
4657 void wxTreeListCtrl::CalculateAndSetHeaderHeight()
4661 // we use 'g' to get the descent, too
4663 m_header_win
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
);
4664 h
+= d
+ 2 * HEADER_OFFSET_Y
+ EXTRA_HEIGHT
;
4666 // only update if changed
4667 if ( h
!= (int)m_headerHeight
)
4669 m_headerHeight
= (size_t)h
;
4670 m_header_win
->SetSize(m_header_win
->GetSize().x
, m_headerHeight
);
4675 void wxTreeListCtrl::DoHeaderLayout()
4678 GetClientSize(&w
, &h
);
4681 m_header_win
->SetSize(0, 0, w
, m_headerHeight
);
4682 m_header_win
->Refresh(false);
4685 m_main_win
->SetSize(0, m_headerHeight
+ 1, w
, h
- m_headerHeight
- 1);
4688 void wxTreeListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
4694 size_t wxTreeListCtrl::GetCount() const { return m_main_win
->GetCount(); }
4696 unsigned int wxTreeListCtrl::GetIndent() const
4697 { return m_main_win
->GetIndent(); }
4699 void wxTreeListCtrl::SetIndent(unsigned int indent
)
4700 { m_main_win
->SetIndent(indent
); }
4702 unsigned int wxTreeListCtrl::GetLineSpacing() const
4703 { return m_main_win
->GetLineSpacing(); }
4705 void wxTreeListCtrl::SetLineSpacing(unsigned int spacing
)
4706 { m_main_win
->SetLineSpacing(spacing
); }
4708 wxImageList
* wxTreeListCtrl::GetImageList() const
4709 { return m_main_win
->GetImageList(); }
4711 wxImageList
* wxTreeListCtrl::GetStateImageList() const
4712 { return m_main_win
->GetStateImageList(); }
4714 wxImageList
* wxTreeListCtrl::GetButtonsImageList() const
4715 { return m_main_win
->GetButtonsImageList(); }
4717 void wxTreeListCtrl::SetImageList(wxImageList
* imageList
)
4718 { m_main_win
->SetImageList(imageList
); }
4720 void wxTreeListCtrl::SetStateImageList(wxImageList
* imageList
)
4721 { m_main_win
->SetStateImageList(imageList
); }
4723 void wxTreeListCtrl::SetButtonsImageList(wxImageList
* imageList
)
4724 { m_main_win
->SetButtonsImageList(imageList
); }
4726 void wxTreeListCtrl::AssignImageList(wxImageList
* imageList
)
4727 { m_main_win
->AssignImageList(imageList
); }
4729 void wxTreeListCtrl::AssignStateImageList(wxImageList
* imageList
)
4730 { m_main_win
->AssignStateImageList(imageList
); }
4732 void wxTreeListCtrl::AssignButtonsImageList(wxImageList
* imageList
)
4733 { m_main_win
->AssignButtonsImageList(imageList
); }
4735 wxString
wxTreeListCtrl::GetItemText(const wxTreeItemId
& item
, size_t column
)
4737 { return m_main_win
->GetItemText(item
, column
); }
4739 int wxTreeListCtrl::GetItemImage(const wxTreeItemId
& item
, size_t column
,
4740 wxTreeItemIcon which
) const
4741 { return m_main_win
->GetItemImage(item
, column
, which
); }
4743 wxTreeItemData
* wxTreeListCtrl::GetItemData(const wxTreeItemId
& item
) const
4744 { return m_main_win
->GetItemData(item
); }
4746 bool wxTreeListCtrl::GetItemBold(const wxTreeItemId
& item
) const
4747 { return m_main_win
->GetItemBold(item
); }
4749 wxColour
wxTreeListCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
4750 { return m_main_win
->GetItemTextColour(item
); }
4752 wxColour
wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
)
4754 { return m_main_win
->GetItemBackgroundColour(item
); }
4756 wxFont
wxTreeListCtrl::GetItemFont(const wxTreeItemId
& item
) const
4757 { return m_main_win
->GetItemFont(item
); }
4760 void wxTreeListCtrl::SetItemText(const wxTreeItemId
& item
, size_t column
,
4761 const wxString
& text
)
4762 { m_main_win
->SetItemText(item
, column
, text
); }
4764 void wxTreeListCtrl::SetItemImage(const wxTreeItemId
& item
,
4767 wxTreeItemIcon which
)
4768 { m_main_win
->SetItemImage(item
, column
, image
, which
); }
4770 void wxTreeListCtrl::SetItemData(const wxTreeItemId
& item
,
4771 wxTreeItemData
* data
)
4772 { m_main_win
->SetItemData(item
, data
); }
4774 void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
4775 { m_main_win
->SetItemHasChildren(item
, has
); }
4777 void wxTreeListCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
4778 { m_main_win
->SetItemBold(item
, bold
); }
4780 void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId
& item
,
4781 const wxColour
& col
)
4782 { m_main_win
->SetItemTextColour(item
, col
); }
4784 void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
4785 const wxColour
& col
)
4786 { m_main_win
->SetItemBackgroundColour(item
, col
); }
4788 void wxTreeListCtrl::SetItemFont(const wxTreeItemId
& item
,
4790 { m_main_win
->SetItemFont(item
, font
); }
4792 bool wxTreeListCtrl::SetFont(const wxFont
& font
)
4796 m_header_win
->SetFont(font
);
4797 CalculateAndSetHeaderHeight();
4800 return m_main_win
->SetFont(font
);
4804 void wxTreeListCtrl::SetWindowStyle(const long style
)
4807 m_main_win
->SetWindowStyle(style
);
4808 // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win
4811 long wxTreeListCtrl::GetWindowStyle() const
4813 long style
= m_windowStyle
;
4815 style
|= m_main_win
->GetWindowStyle();
4819 bool wxTreeListCtrl::IsVisible(const wxTreeItemId
& item
) const
4820 { return m_main_win
->IsVisible(item
); }
4822 bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
4823 { return m_main_win
->ItemHasChildren(item
); }
4825 bool wxTreeListCtrl::IsExpanded(const wxTreeItemId
& item
) const
4826 { return m_main_win
->IsExpanded(item
); }
4828 bool wxTreeListCtrl::IsSelected(const wxTreeItemId
& item
) const
4829 { return m_main_win
->IsSelected(item
); }
4831 bool wxTreeListCtrl::IsBold(const wxTreeItemId
& item
) const
4832 { return m_main_win
->IsBold(item
); }
4834 size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool rec
)
4835 { return m_main_win
->GetChildrenCount(item
, rec
); }
4837 wxTreeItemId
wxTreeListCtrl::GetRootItem() const
4838 { return m_main_win
->GetRootItem(); }
4840 wxTreeItemId
wxTreeListCtrl::GetSelection() const
4841 { return m_main_win
->GetSelection(); }
4843 size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds
& arr
) const
4844 { return m_main_win
->GetSelections(arr
); }
4846 wxTreeItemId
wxTreeListCtrl::GetItemParent(const wxTreeItemId
& item
) const
4847 { return m_main_win
->GetItemParent(item
); }
4849 #if !wxCHECK_VERSION(2, 5, 0)
4850 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4853 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4854 wxTreeItemIdValue
& cookie
) const
4856 { return m_main_win
->GetFirstChild(item
, cookie
); }
4858 #if !wxCHECK_VERSION(2, 5, 0)
4859 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4862 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4863 wxTreeItemIdValue
& cookie
) const
4865 { return m_main_win
->GetNextChild(item
, cookie
); }
4867 #if !wxCHECK_VERSION(2, 5, 0)
4868 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4871 wxTreeItemId
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
,
4872 wxTreeItemIdValue
& cookie
) const
4874 { return m_main_win
->GetPrevChild(item
, cookie
); }
4876 wxTreeItemId
wxTreeListCtrl::GetLastChild(const wxTreeItemId
& item
) const
4877 { return m_main_win
->GetLastChild(item
); }
4879 wxTreeItemId
wxTreeListCtrl::GetNextSibling(const wxTreeItemId
& item
) const
4880 { return m_main_win
->GetNextSibling(item
); }
4882 wxTreeItemId
wxTreeListCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
4883 { return m_main_win
->GetPrevSibling(item
); }
4885 wxTreeItemId
wxTreeListCtrl::GetFirstVisibleItem() const
4886 { return m_main_win
->GetFirstVisibleItem(); }
4888 wxTreeItemId
wxTreeListCtrl::GetNextVisible(const wxTreeItemId
& item
) const
4889 { return m_main_win
->GetNextVisible(item
); }
4891 wxTreeItemId
wxTreeListCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
4892 { return m_main_win
->GetPrevVisible(item
); }
4894 wxTreeItemId
wxTreeListCtrl::GetNext(const wxTreeItemId
& item
) const
4895 { return m_main_win
->GetNext(item
); }
4897 wxTreeItemId
wxTreeListCtrl::AddRoot(const wxString
& text
, int image
,
4898 int selectedImage
, wxTreeItemData
* data
)
4899 { return m_main_win
->AddRoot(text
, image
, selectedImage
, data
); }
4901 wxTreeItemId
wxTreeListCtrl::PrependItem(const wxTreeItemId
& parent
,
4902 const wxString
& text
, int image
,
4904 wxTreeItemData
* data
)
4905 { return m_main_win
->PrependItem(parent
, text
, image
, selectedImage
, data
); }
4907 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4908 const wxTreeItemId
& previous
,
4909 const wxString
& text
, int image
,
4911 wxTreeItemData
* data
)
4913 return m_main_win
->InsertItem(parent
, previous
, text
, image
,
4914 selectedImage
, data
);
4917 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4919 const wxString
& text
, int image
,
4921 wxTreeItemData
* data
)
4923 return m_main_win
->InsertItem(parent
, index
, text
, image
,
4924 selectedImage
, data
);
4927 wxTreeItemId
wxTreeListCtrl::AppendItem(const wxTreeItemId
& parent
,
4928 const wxString
& text
, int image
,
4930 wxTreeItemData
* data
)
4931 { return m_main_win
->AppendItem(parent
, text
, image
, selectedImage
, data
); }
4933 void wxTreeListCtrl::Delete(const wxTreeItemId
& item
)
4934 { m_main_win
->Delete(item
); }
4936 void wxTreeListCtrl::DeleteChildren(const wxTreeItemId
& item
)
4937 { m_main_win
->DeleteChildren(item
); }
4939 void wxTreeListCtrl::DeleteAllItems()
4940 { m_main_win
->DeleteAllItems(); }
4942 void wxTreeListCtrl::Expand(const wxTreeItemId
& item
)
4943 { m_main_win
->Expand(item
); }
4945 void wxTreeListCtrl::ExpandAll(const wxTreeItemId
& item
)
4946 { m_main_win
->ExpandAll(item
); }
4948 void wxTreeListCtrl::Collapse(const wxTreeItemId
& item
)
4949 { m_main_win
->Collapse(item
); }
4951 void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId
& item
)
4952 { m_main_win
->CollapseAndReset(item
); }
4954 void wxTreeListCtrl::Toggle(const wxTreeItemId
& item
)
4955 { m_main_win
->Toggle(item
); }
4957 void wxTreeListCtrl::Unselect()
4958 { m_main_win
->Unselect(); }
4960 void wxTreeListCtrl::UnselectAll()
4961 { m_main_win
->UnselectAll(); }
4963 void wxTreeListCtrl::SelectItem(const wxTreeItemId
& item
, bool unselect_others
,
4964 bool extended_select
)
4965 { m_main_win
->SelectItem(item
, unselect_others
, extended_select
); }
4967 void wxTreeListCtrl::SelectAll(bool extended_select
)
4968 { m_main_win
->SelectAll(extended_select
); }
4970 void wxTreeListCtrl::EnsureVisible(const wxTreeItemId
& item
)
4971 { m_main_win
->EnsureVisible(item
); }
4973 void wxTreeListCtrl::ScrollTo(const wxTreeItemId
& item
)
4974 { m_main_win
->ScrollTo(item
); }
4976 wxTreeItemId
wxTreeListCtrl::HitTest(const wxPoint
& pos
, int& flags
,
4979 return m_main_win
->HitTest(pos
, flags
, column
);
4982 bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
4983 bool textOnly
) const
4984 { return m_main_win
->GetBoundingRect(item
, rect
, textOnly
); }
4986 void wxTreeListCtrl::Edit(const wxTreeItemId
& item
)
4987 { m_main_win
->Edit(item
); }
4989 int wxTreeListCtrl::OnCompareItems(const wxTreeItemId
& item1
,
4990 const wxTreeItemId
& item2
)
4992 // ALB: do the comparison here, and not delegate to m_main_win, in order
4993 // to let the user override it
4994 //return m_main_win->OnCompareItems(item1, item2);
4995 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
4998 void wxTreeListCtrl::SortChildren(const wxTreeItemId
& item
)
4999 { m_main_win
->SortChildren(item
); }
5001 wxTreeItemId
wxTreeListCtrl::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
)
5002 { return m_main_win
->FindItem (item
, str
, flags
); }
5004 bool wxTreeListCtrl::SetBackgroundColour(const wxColour
& colour
)
5006 if (!m_main_win
) return false;
5007 return m_main_win
->SetBackgroundColour(colour
);
5010 bool wxTreeListCtrl::SetForegroundColour(const wxColour
& colour
)
5012 if (!m_main_win
) return false;
5013 return m_main_win
->SetForegroundColour(colour
);
5016 size_t wxTreeListCtrl::GetColumnCount() const
5017 { return m_main_win
->GetColumnCount(); }
5019 void wxTreeListCtrl::SetColumnWidth(size_t column
, size_t width
)
5020 { m_header_win
->SetColumnWidth(column
, width
); }
5022 int wxTreeListCtrl::GetColumnWidth(size_t column
) const
5023 { return m_header_win
->GetColumnWidth(column
); }
5025 void wxTreeListCtrl::SetMainColumn(size_t column
)
5026 { m_main_win
->SetMainColumn(column
); }
5028 size_t wxTreeListCtrl::GetMainColumn() const
5029 { return m_main_win
->GetMainColumn(); }
5031 void wxTreeListCtrl::SetColumnText(size_t column
, const wxString
& text
)
5033 m_header_win
->SetColumnText(column
, text
);
5034 m_header_win
->Refresh();
5037 wxString
wxTreeListCtrl::GetColumnText(size_t column
) const
5038 { return m_header_win
->GetColumnText(column
); }
5040 void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo
& col
)
5042 m_header_win
->AddColumn(col
);
5046 void wxTreeListCtrl::InsertColumn(size_t before
,
5047 const wxTreeListColumnInfo
& col
)
5048 { m_header_win
->InsertColumn(before
, col
); }
5050 void wxTreeListCtrl::RemoveColumn(size_t column
)
5051 { m_header_win
->RemoveColumn(column
); }
5053 void wxTreeListCtrl::SetColumn(size_t column
, const wxTreeListColumnInfo
& col
)
5054 { m_header_win
->SetColumn(column
, col
); }
5056 const wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) const
5057 { return m_header_win
->GetColumn(column
); }
5059 wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
)
5060 { return m_header_win
->GetColumn(column
); }
5062 void wxTreeListCtrl::SetColumnImage(size_t column
, int image
)
5064 m_header_win
->SetColumn(column
, GetColumn(column
).SetImage(image
));
5067 int wxTreeListCtrl::GetColumnImage(size_t column
) const
5069 return m_header_win
->GetColumn(column
).GetImage();
5072 void wxTreeListCtrl::ShowColumn(size_t column
, bool shown
)
5074 wxASSERT_MSG( column
!= GetMainColumn(),
5075 wxT("The main column may not be hidden") );
5076 m_header_win
->SetColumn(column
, GetColumn(column
).SetShown(GetMainColumn()? true: shown
));
5079 bool wxTreeListCtrl::IsColumnShown(size_t column
) const
5081 return m_header_win
->GetColumn(column
).GetShown();
5084 void wxTreeListCtrl::SetColumnAlignment(size_t column
,
5085 wxTreeListColumnAlign align
)
5087 m_header_win
->SetColumn(column
, GetColumn(column
).SetAlignment(align
));
5090 wxTreeListColumnAlign
wxTreeListCtrl::GetColumnAlignment(size_t column
) const
5092 return m_header_win
->GetColumn(column
).GetAlignment();
5095 void wxTreeListCtrl::Refresh(bool erase
, const wxRect
* rect
)
5097 m_main_win
->Refresh(erase
, rect
);
5098 m_header_win
->Refresh(erase
, rect
);
5101 void wxTreeListCtrl::SetFocus()
5102 { m_main_win
->SetFocus(); }
5105 wxSize
wxTreeListCtrl::DoGetBestSize() const
5107 // something is better than nothing...
5108 return wxSize(100,80);
5111 // Process the tooltip event, to speed up event processing.
5112 // Doesn't actually get a tooltip.
5113 void wxTreeListCtrl::OnGetToolTip( wxTreeEvent
&event
)