1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        treelistctrl.cpp 
   3 // Purpose:     multi column tree control implementation 
   4 // Author:      Robert Roebling 
   6 // Modified:    Alberto Griggio, 2002 
   7 //              22/10/98 - almost total rewrite, simpler interface (VZ) 
   9 // Copyright:   (c) Robert Roebling, Julian Smart, Alberto Griggio, 
  10 //              Vadim Zeitlin, Otto Wyss 
  11 // Licence:     wxWindows licence 
  12 ///////////////////////////////////////////////////////////////////////////// 
  14 // =========================================================================== 
  16 // =========================================================================== 
  18 // --------------------------------------------------------------------------- 
  20 // --------------------------------------------------------------------------- 
  22 #if defined(__GNUG__) && !defined(__APPLE__) 
  23   #pragma implementation "treelistctrl.h" 
  26 // For compilers that support precompilation, includes "wx.h". 
  27 #include "wx/wxprec.h" 
  34 #include <wx/treebase.h> 
  36 #include <wx/textctrl.h> 
  37 #include <wx/imaglist.h> 
  38 #include <wx/settings.h> 
  39 #include <wx/dcclient.h> 
  40 #include <wx/dcscreen.h> 
  41 #include <wx/scrolwin.h> 
  42 #include <wx/renderer.h> 
  44 #include "wx/treelistctrl.h" 
  48     #include <wx/gtk/win_gtk.h> 
  52     #include "wx/mac/private.h" 
  56 // --------------------------------------------------------------------------- 
  58 // --------------------------------------------------------------------------- 
  62 #if !wxCHECK_VERSION(2, 5, 0) 
  63 WX_DEFINE_ARRAY(wxTreeListItem 
*, wxArrayTreeListItems
); 
  65 WX_DEFINE_ARRAY_PTR(wxTreeListItem 
*, wxArrayTreeListItems
); 
  68 #include <wx/dynarray.h> 
  69 WX_DECLARE_OBJARRAY(wxTreeListColumnInfo
, wxArrayTreeListColumnInfo
); 
  70 #include <wx/arrimpl.cpp> 
  71 WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo
); 
  73 #if !wxCHECK_VERSION(2, 3, 3) 
  74 WX_DEFINE_ARRAY(short, wxArrayShort
); 
  78 // -------------------------------------------------------------------------- 
  80 // -------------------------------------------------------------------------- 
  82 static const int NO_IMAGE 
= -1; 
  84 const int LINEHEIGHT 
= 10; 
  85 const int PIXELS_PER_UNIT 
= 10; 
  86 const int LINEATROOT 
= 5; 
  88 const int MININDENT 
= 10; 
  89 const int BTNWIDTH 
= 9; //11; 
  90 const int BTNHEIGHT 
= 9; //11; 
  92 // extra margins around the text label 
  93 static const int EXTRA_WIDTH 
= 4; 
  94 static const int EXTRA_HEIGHT 
= 4; 
  96 // offset for the header window 
  97 static const int HEADER_OFFSET_X 
= 1; 
  98 static const int HEADER_OFFSET_Y 
= 1; 
 102 const wxChar
* wxTreeListCtrlNameStr 
= wxT("treelistctrl"); 
 104 static wxTreeListColumnInfo wxInvalidTreeListColumnInfo
; 
 107 // --------------------------------------------------------------------------- 
 109 // --------------------------------------------------------------------------- 
 110 //----------------------------------------------------------------------------- 
 111 //  wxTreeListHeaderWindow (internal) 
 112 //----------------------------------------------------------------------------- 
 114 class  wxTreeListHeaderWindow 
: public wxWindow
 
 117     wxTreeListMainWindow 
*m_owner
; 
 118     wxCursor             
*m_currentCursor
; 
 119     wxCursor             
*m_resizeCursor
; 
 122     // column being resized 
 125     // divider line position in logical (unscrolled) coords 
 128     // minimal position beyond which the divider line can't be dragged in 
 132     wxArrayTreeListColumnInfo m_columns
; 
 134     // total width of the columns 
 135     int m_total_col_width
; 
 139     wxTreeListHeaderWindow(); 
 141     wxTreeListHeaderWindow( wxWindow 
*win
, 
 143                             wxTreeListMainWindow 
*owner
, 
 144                             const wxPoint 
&pos 
= wxDefaultPosition
, 
 145                             const wxSize 
&size 
= wxDefaultSize
, 
 147                             const wxString 
&name 
= wxT("wxtreelistctrlcolumntitles") ); 
 149     virtual ~wxTreeListHeaderWindow(); 
 151     void DoDrawRect( wxDC 
*dc
, int x
, int y
, int w
, int h 
); 
 153     void AdjustDC(wxDC
& dc
); 
 155     void OnPaint( wxPaintEvent 
&event 
); 
 156     void OnMouse( wxMouseEvent 
&event 
); 
 157     void OnSetFocus( wxFocusEvent 
&event 
); 
 160     // columns manipulation 
 162     size_t GetColumnCount() const { return m_columns
.GetCount(); } 
 164     void AddColumn(const wxTreeListColumnInfo
& col
); 
 166     void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
); 
 168     void RemoveColumn(size_t column
); 
 170     void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
); 
 171     const wxTreeListColumnInfo
& GetColumn(size_t column
) const 
 173         wxCHECK_MSG(column 
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column")); 
 174         return m_columns
[column
]; 
 176     wxTreeListColumnInfo
& GetColumn(size_t column
) 
 178         wxCHECK_MSG(column 
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column")); 
 179         return m_columns
[column
]; 
 182     void SetColumnWidth(size_t column
, size_t width
); 
 184     void SetColumnText(size_t column
, const wxString
& text
) 
 186         wxCHECK_RET(column 
< GetColumnCount(), wxT("Invalid column")); 
 187         m_columns
[column
].SetText(text
); 
 190     void SetColumnShown(size_t column
, bool shown
) 
 192         wxCHECK_RET(column 
< GetColumnCount(), wxT("Invalid column")); 
 193         m_columns
[column
].SetShown(shown
); 
 196     wxString 
GetColumnText(size_t column
) const 
 198         wxCHECK_MSG(column 
< GetColumnCount(), wxEmptyString
, wxT("Invalid column")); 
 199         return m_columns
[column
].GetText(); 
 202     int GetColumnWidth(size_t column
) const 
 204         wxCHECK_MSG(column 
< GetColumnCount(), -1, wxT("Invalid column")); 
 205         return m_columns
[column
].GetWidth(); 
 208     int GetWidth() const { return m_total_col_width
; } 
 210     int GetColumnShown(size_t column
) const 
 212         wxCHECK_MSG(column 
< GetColumnCount(), -1, wxT("Invalid column")); 
 213         return m_columns
[column
].GetShown(); 
 220     // common part of all ctors 
 223     void SendListEvent(wxEventType type
, wxPoint pos
); 
 225     DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow
) 
 226     DECLARE_EVENT_TABLE() 
 230 // this is the "true" control 
 231 class  wxTreeListMainWindow
: public wxScrolledWindow
 
 236     wxTreeListMainWindow() { Init(); } 
 238     wxTreeListMainWindow(wxTreeListCtrl 
*parent
, wxWindowID id 
= -1, 
 239                const wxPoint
& pos 
= wxDefaultPosition
, 
 240                const wxSize
& size 
= wxDefaultSize
, 
 241                long style 
= wxTR_DEFAULT_STYLE
, 
 242                const wxValidator 
&validator 
= wxDefaultValidator
, 
 243                const wxString
& name 
= wxT("wxtreelistmainwindow")) 
 246         Create(parent
, id
, pos
, size
, style
, validator
, name
); 
 249     virtual ~wxTreeListMainWindow(); 
 251     bool Create(wxTreeListCtrl 
*parent
, wxWindowID id 
= -1, 
 252                 const wxPoint
& pos 
= wxDefaultPosition
, 
 253                 const wxSize
& size 
= wxDefaultSize
, 
 254                 long style 
= wxTR_DEFAULT_STYLE
, 
 255                 const wxValidator 
&validator 
= wxDefaultValidator
, 
 256                 const wxString
& name 
= wxT("wxtreelistctrl")); 
 261     // get the total number of items in the control 
 262     size_t GetCount() const; 
 264     // indent is the number of pixels the children are indented relative to 
 265     // the parents position. SetIndent() also redraws the control 
 267     unsigned int GetIndent() const { return m_indent
; } 
 268     void SetIndent(unsigned int indent
); 
 270     // see wxTreeListCtrl for the meaning 
 271     unsigned int GetLineSpacing() const { return m_linespacing
; } 
 272     void SetLineSpacing(unsigned int spacing
); 
 274     // image list: these functions allow to associate an image list with 
 275     // the control and retrieve it. Note that when assigned with 
 276     // SetImageList, the control does _not_ delete 
 277     // the associated image list when it's deleted in order to allow image 
 278     // lists to be shared between different controls. If you use 
 279     // AssignImageList, the control _does_ delete the image list. 
 281     // The normal image list is for the icons which correspond to the 
 282     // normal tree item state (whether it is selected or not). 
 283     // Additionally, the application might choose to show a state icon 
 284     // which corresponds to an app-defined item state (for example, 
 285     // checked/unchecked) which are taken from the state image list. 
 286     wxImageList 
*GetImageList() const; 
 287     wxImageList 
*GetStateImageList() const; 
 288     wxImageList 
*GetButtonsImageList() const; 
 290     void SetImageList(wxImageList 
*imageList
); 
 291     void SetStateImageList(wxImageList 
*imageList
); 
 292     void SetButtonsImageList(wxImageList 
*imageList
); 
 293     void AssignImageList(wxImageList 
*imageList
); 
 294     void AssignStateImageList(wxImageList 
*imageList
); 
 295     void AssignButtonsImageList(wxImageList 
*imageList
); 
 297     // Functions to work with tree ctrl items. 
 302     // retrieve item's label 
 303     wxString 
GetItemText(const wxTreeItemId
& item
) const 
 304     { return GetItemText(item
, GetMainColumn()); } 
 305     // get one of the images associated with the item (normal by default) 
 306     int GetItemImage(const wxTreeItemId
& item
, 
 307                      wxTreeItemIcon which 
= wxTreeItemIcon_Normal
) const 
 308     { return GetItemImage(item
, GetMainColumn(), which
); } 
 310     // get the data associated with the item 
 311     wxTreeItemData 
*GetItemData(const wxTreeItemId
& item
) const; 
 313     bool GetItemBold(const wxTreeItemId
& item
) const; 
 314     wxColour 
GetItemTextColour(const wxTreeItemId
& item
) const; 
 315     wxColour 
GetItemBackgroundColour(const wxTreeItemId
& item
) const; 
 316     wxFont 
GetItemFont(const wxTreeItemId
& item
) const; 
 322     void SetItemText(const wxTreeItemId
& item
, const wxString
& text
) 
 323     { SetItemText(item
, GetMainColumn(), text
); } 
 325     // get one of the images associated with the item (normal by default) 
 326     void SetItemImage(const wxTreeItemId
& item
, int image
, 
 327                       wxTreeItemIcon which 
= wxTreeItemIcon_Normal
) 
 328     { SetItemImage(item
, GetMainColumn(), image
, which
); } 
 330     // associate some data with the item 
 331     void SetItemData(const wxTreeItemId
& item
, wxTreeItemData 
*data
); 
 333     // force appearance of [+] button near the item. This is useful to 
 334     // allow the user to expand the items which don't have any children now 
 335     // - but instead add them only when needed, thus minimizing memory 
 336     // usage and loading time. 
 337     void SetItemHasChildren(const wxTreeItemId
& item
, bool has 
= TRUE
); 
 339     // the item will be shown in bold 
 340     void SetItemBold(const wxTreeItemId
& item
, bool bold 
= TRUE
); 
 342     // set the item's text colour 
 343     void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
); 
 345     // set the item's background colour 
 346     void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
); 
 348     // set the item's font (should be of the same height for all items) 
 349     void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
); 
 351     // set the window font 
 352     virtual bool SetFont( const wxFont 
&font 
); 
 354     // set the styles.  No need to specify a GetWindowStyle here since 
 355     // the base wxWindow member function will do it for us 
 356     void SetWindowStyle(const long styles
); 
 358     // item status inquiries 
 359     // --------------------- 
 361     // is the item visible (it might be outside the view or not expanded)? 
 362     bool IsVisible(const wxTreeItemId
& item
) const; 
 363     // does the item has any children? 
 364     bool HasChildren(const wxTreeItemId
& item
) const 
 365     { return ItemHasChildren(item
); } 
 366     bool ItemHasChildren(const wxTreeItemId
& item
) const; 
 367     // is the item expanded (only makes sense if HasChildren())? 
 368     bool IsExpanded(const wxTreeItemId
& item
) const; 
 369     // is this item currently selected (the same as has focus)? 
 370     bool IsSelected(const wxTreeItemId
& item
) const; 
 371     // is item text in bold font? 
 372     bool IsBold(const wxTreeItemId
& item
) const; 
 373         // does the layout include space for a button? 
 375     // number of children 
 376     // ------------------ 
 378     // if 'recursively' is FALSE, only immediate children count, otherwise 
 379     // the returned number is the number of all items in this branch 
 380     size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively 
= TRUE
); 
 385     // wxTreeItemId.IsOk() will return FALSE if there is no such item 
 387     // get the root tree item 
 388     wxTreeItemId 
GetRootItem() const { return m_anchor
; } 
 390     // get the item currently selected (may return NULL if no selection) 
 391     wxTreeItemId 
GetSelection() const { return m_current
; } 
 393     // get the items currently selected, return the number of such item 
 394     size_t GetSelections(wxArrayTreeItemIds
&) const; 
 396     // get the parent of this item (may return NULL if root) 
 397     wxTreeItemId 
GetItemParent(const wxTreeItemId
& item
) const; 
 399     // for this enumeration function you must pass in a "cookie" parameter 
 400     // which is opaque for the application but is necessary for the library 
 401     // to make these functions reentrant (i.e. allow more than one 
 402     // enumeration on one and the same object simultaneously). Of course, 
 403     // the "cookie" passed to GetFirstChild() and GetNextChild() should be 
 406     // get the first child of this item 
 407 #if !wxCHECK_VERSION(2, 5, 0) 
 408     wxTreeItemId 
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const; 
 410     wxTreeItemId 
GetFirstChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const; 
 412     // get the next child 
 413 #if !wxCHECK_VERSION(2, 5, 0) 
 414     wxTreeItemId 
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const; 
 416     wxTreeItemId 
GetNextChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const; 
 418     // get the prev child 
 419 #if !wxCHECK_VERSION(2, 5, 0) 
 420     wxTreeItemId 
GetPrevChild(const wxTreeItemId
& item
, long& cookie
) const; 
 422     wxTreeItemId 
GetPrevChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const; 
 424     // get the last child of this item - this method doesn't use cookies 
 425     wxTreeItemId 
GetLastChild(const wxTreeItemId
& item
) const; 
 427     // get the next sibling of this item 
 428     wxTreeItemId 
GetNextSibling(const wxTreeItemId
& item
) const; 
 429     // get the previous sibling 
 430     wxTreeItemId 
GetPrevSibling(const wxTreeItemId
& item
) const; 
 432     // get first visible item 
 433     wxTreeItemId 
GetFirstVisibleItem() const; 
 434     // get the next visible item: item must be visible itself! 
 435     // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() 
 436     wxTreeItemId 
GetNextVisible(const wxTreeItemId
& item
) const; 
 437     // get the previous visible item: item must be visible itself! 
 438     wxTreeItemId 
GetPrevVisible(const wxTreeItemId
& item
) const; 
 440     // Only for internal use right now, but should probably be public 
 441     wxTreeItemId 
GetNext(const wxTreeItemId
& item
) const; 
 446     // add the root node to the tree 
 447     wxTreeItemId 
AddRoot(const wxString
& text
, 
 448                          int image 
= -1, int selectedImage 
= -1, 
 449                          wxTreeItemData 
*data 
= NULL
); 
 451     // insert a new item in as the first child of the parent 
 452     wxTreeItemId 
PrependItem(const wxTreeItemId
& parent
, 
 453                              const wxString
& text
, 
 454                              int image 
= -1, int selectedImage 
= -1, 
 455                              wxTreeItemData 
*data 
= NULL
); 
 457     // insert a new item after a given one 
 458     wxTreeItemId 
InsertItem(const wxTreeItemId
& parent
, 
 459                             const wxTreeItemId
& idPrevious
, 
 460                             const wxString
& text
, 
 461                             int image 
= -1, int selectedImage 
= -1, 
 462                             wxTreeItemData 
*data 
= NULL
); 
 464     // insert a new item before the one with the given index 
 465     wxTreeItemId 
InsertItem(const wxTreeItemId
& parent
, 
 467                             const wxString
& text
, 
 468                             int image 
= -1, int selectedImage 
= -1, 
 469                             wxTreeItemData 
*data 
= NULL
); 
 471     // insert a new item in as the last child of the parent 
 472     wxTreeItemId 
AppendItem(const wxTreeItemId
& parent
, 
 473                             const wxString
& text
, 
 474                             int image 
= -1, int selectedImage 
= -1, 
 475                             wxTreeItemData 
*data 
= NULL
); 
 477     // delete this item and associated data if any 
 478     void Delete(const wxTreeItemId
& item
); 
 479     // delete all children (but don't delete the item itself) 
 480     // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events 
 481     void DeleteChildren(const wxTreeItemId
& item
); 
 482     // delete all items from the tree 
 483     // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events 
 484     void DeleteAllItems(); 
 487     void Expand(const wxTreeItemId
& item
); 
 488     // expand this item and all subitems recursively 
 489     void ExpandAll(const wxTreeItemId
& item
); 
 490     // collapse the item without removing its children 
 491     void Collapse(const wxTreeItemId
& item
); 
 492     // collapse the item and remove all children 
 493     void CollapseAndReset(const wxTreeItemId
& item
); 
 494     // toggles the current state 
 495     void Toggle(const wxTreeItemId
& item
); 
 497     // remove the selection from currently selected item (if any) 
 501     void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
, 
 502                     bool extended_select
=FALSE
); 
 503     void SelectAll(bool extended_select
=FALSE
); 
 504     // make sure this item is visible (expanding the parent item and/or 
 505     // scrolling to this item if necessary) 
 506     void EnsureVisible(const wxTreeItemId
& item
); 
 507     // scroll to this item (but don't expand its parent) 
 508     void ScrollTo(const wxTreeItemId
& item
); 
 509     void AdjustMyScrollbars(); 
 511     // The first function is more portable (because easier to implement 
 512     // on other platforms), but the second one returns some extra info. 
 513     wxTreeItemId 
HitTest(const wxPoint
& point
) 
 514         { int dummy
; return HitTest(point
, dummy
); } 
 515     wxTreeItemId 
HitTest(const wxPoint
& point
, int& flags
) 
 516     { int col
; return HitTest(point
, flags
, col
); } 
 518     wxTreeItemId 
HitTest(const wxPoint
& point
, int& flags
, int& column
); 
 521     // get the bounding rectangle of the item (or of its label only) 
 522     bool GetBoundingRect(const wxTreeItemId
& item
, 
 524                          bool textOnly 
= FALSE
) const; 
 526     // Start editing the item label: this (temporarily) replaces the item 
 527     // with a one line edit control. The item will be selected if it hadn't 
 529     void EditLabel( const wxTreeItemId
& item 
) { Edit( item 
); } 
 530     void Edit( const wxTreeItemId
& item 
); 
 533     // this function is called to compare 2 items and should return -1, 0 
 534     // or +1 if the first item is less than, equal to or greater than the 
 535     // second one. The base class version performs alphabetic comparaison 
 536     // of item labels (GetText) 
 537     virtual int OnCompareItems(const wxTreeItemId
& item1
, 
 538                                const wxTreeItemId
& item2
); 
 539     // sort the children of this item using OnCompareItems 
 541     // NB: this function is not reentrant and not MT-safe (FIXME)! 
 542     void SortChildren(const wxTreeItemId
& item
); 
 545     wxTreeItemId 
FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags 
= 0); 
 547     // deprecated functions: use Set/GetItemImage directly 
 548     // get the selected item image 
 549     int GetItemSelectedImage(const wxTreeItemId
& item
) const 
 550         { return GetItemImage(item
, wxTreeItemIcon_Selected
); } 
 551     // set the selected item image 
 552     void SetItemSelectedImage(const wxTreeItemId
& item
, int image
) 
 553         { SetItemImage(item
, image
, wxTreeItemIcon_Selected
); } 
 555     // implementation only from now on 
 557     // overridden base class virtuals 
 558     virtual bool SetBackgroundColour(const wxColour
& colour
); 
 559     virtual bool SetForegroundColour(const wxColour
& colour
); 
 562     void OnPaint( wxPaintEvent 
&event 
); 
 563     void OnSetFocus( wxFocusEvent 
&event 
); 
 564     void OnKillFocus( wxFocusEvent 
&event 
); 
 565     void OnChar( wxKeyEvent 
&event 
); 
 566     void OnMouse( wxMouseEvent 
&event 
); 
 567     void OnIdle( wxIdleEvent 
&event 
); 
 568     void OnScroll(wxScrollWinEvent
& event
); // ALB 
 570     // implementation helpers 
 571     void SendDeleteEvent(wxTreeListItem 
*itemBeingDeleted
); 
 573     void DrawBorder(const wxTreeItemId
& item
); 
 574     void DrawLine(const wxTreeItemId
& item
, bool below
); 
 576     size_t GetColumnCount() const 
 577     { return m_owner
->GetHeaderWindow()->GetColumnCount(); } 
 579     void SetMainColumn(size_t column
) 
 581         if(column 
< GetColumnCount()) 
 582             m_main_column 
= column
; 
 584     size_t GetMainColumn() const { return m_main_column
; } 
 586     void SetItemText(const wxTreeItemId
& item
, size_t column
, 
 587                      const wxString
& text
); 
 588     wxString 
GetItemText(const wxTreeItemId
& item
, size_t column
) const; 
 590     void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
, 
 591                       wxTreeItemIcon which 
= wxTreeItemIcon_Normal
); 
 592     int GetItemImage(const wxTreeItemId
& item
, size_t column
, 
 593                      wxTreeItemIcon which 
= wxTreeItemIcon_Normal
) const; 
 598     wxTreeListCtrl
* m_owner
; // ALB 
 600     size_t m_main_column
; // ALB 
 602     friend class wxTreeListItem
; 
 603     friend class wxTreeListRenameTimer
; 
 604     friend class wxTreeListTextCtrl
; 
 609     wxTreeListItem   
*m_anchor
; 
 610     wxTreeListItem   
*m_current
, *m_key_current
, *m_currentEdit
; 
 611     int                  m_btnWidth
, m_btnWidth2
; 
 612     int                  m_btnHeight
, m_btnHeight2
; 
 613     int                  m_imgWidth
, m_imgWidth2
; 
 614     int                  m_imgHeight
, m_imgHeight2
; 
 615     unsigned short       m_indent
; 
 617     unsigned short       m_linespacing
; 
 619     wxBrush             
*m_hilightBrush
, 
 620                         *m_hilightUnfocusedBrush
; 
 625     bool                 m_ownsImageListNormal
, 
 626                          m_ownsImageListState
, 
 627                          m_ownsImageListButtons
; 
 628     bool                 m_isDragging
; // true between BEGIN/END drag events 
 630     bool                 m_lastOnSame
;  // last click on the same item as prev 
 631     wxImageList         
*m_imageListNormal
, 
 637     wxTreeListItem   
*m_dropTarget
; 
 638     wxCursor             m_oldCursor
;  // cursor is changed while dragging 
 639     wxTreeListItem   
*m_oldSelection
; 
 640     wxTreeListItem   
*m_underMouse
; // for visual effects 
 642     wxTimer             
*m_renameTimer
; 
 643     wxString             m_renameRes
; 
 646     wxTimer             
*m_findTimer
; 
 649     // the common part of all ctors 
 653     wxTreeItemId 
DoInsertItem(const wxTreeItemId
& parent
, 
 655                               const wxString
& text
, 
 656                               int image
, int selectedImage
, 
 657                               wxTreeItemData 
*data
); 
 658     bool HasButtons(void) const 
 659         { return (m_imageListButtons 
!= NULL
) || 
 660                   HasFlag (wxTR_TWIST_BUTTONS
|wxTR_HAS_BUTTONS
); } 
 663     void CalculateLineHeight(); 
 664     int  GetLineHeight(wxTreeListItem 
*item
) const; 
 665     void PaintLevel( wxTreeListItem 
*item
, wxDC
& dc
, int level
, int &y
, 
 667     void PaintItem( wxTreeListItem 
*item
, wxDC
& dc
); 
 669     void CalculateLevel( wxTreeListItem 
*item
, wxDC 
&dc
, int level
, int &y
, 
 671     void CalculatePositions(); 
 672     void CalculateSize( wxTreeListItem 
*item
, wxDC 
&dc 
); 
 674     void RefreshSubtree( wxTreeListItem 
*item 
); 
 675     void RefreshLine( wxTreeListItem 
*item 
); 
 677     // redraw all selected items 
 678     void RefreshSelected(); 
 680     // RefreshSelected() recursive helper 
 681     void RefreshSelectedUnder(wxTreeListItem 
*item
); 
 683     void OnRenameTimer(); 
 684     void OnRenameAccept(); 
 686     void FillArray(wxTreeListItem
*, wxArrayTreeItemIds
&) const; 
 687     void SelectItemRange( wxTreeListItem 
*item1
, wxTreeListItem 
*item2 
); 
 688     bool TagAllChildrenUntilLast(wxTreeListItem 
*crt_item
, 
 689                                  wxTreeListItem 
*last_item
, bool select
); 
 690     bool TagNextChildren(wxTreeListItem 
*crt_item
, wxTreeListItem 
*last_item
, 
 692     void UnselectAllChildren( wxTreeListItem 
*item 
); 
 694     void DrawDropEffect(wxTreeListItem 
*item
); 
 697     DECLARE_EVENT_TABLE() 
 698     DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow
) 
 702 // timer used for enabling in-place edit 
 703 class  wxTreeListRenameTimer
: public wxTimer
 
 706     wxTreeListRenameTimer( wxTreeListMainWindow 
*owner 
); 
 711     wxTreeListMainWindow   
*m_owner
; 
 714 // control used for in-place edit 
 715 class  wxTreeListTextCtrl
: public wxTextCtrl
 
 718     wxTreeListTextCtrl( wxWindow 
*parent
, 
 722                         wxTreeListMainWindow 
*owner
, 
 723                         const wxString 
&value 
= wxEmptyString
, 
 724                         const wxPoint 
&pos 
= wxDefaultPosition
, 
 725                         const wxSize 
&size 
= wxDefaultSize
, 
 726                         int style 
= wxSIMPLE_BORDER
, 
 727                         const wxValidator
& validator 
= wxDefaultValidator
, 
 728                         const wxString 
&name 
= wxTextCtrlNameStr 
); 
 730     void OnChar( wxKeyEvent 
&event 
); 
 731     void OnKeyUp( wxKeyEvent 
&event 
); 
 732     void OnKillFocus( wxFocusEvent 
&event 
); 
 737     wxTreeListMainWindow  
*m_owner
; 
 738     wxString            m_startValue
; 
 741     DECLARE_EVENT_TABLE() 
 749     wxTreeListItem() { m_data 
= NULL
; } 
 750     wxTreeListItem( wxTreeListMainWindow 
*owner
, 
 751                     wxTreeListItem 
*parent
, 
 752                     const wxArrayString
& text
, 
 755                     wxTreeItemData 
*data 
); 
 760     wxArrayTreeListItems
& GetChildren() { return m_children
; } 
 762     const wxString 
GetText() const 
 764         if(m_text
.GetCount() > 0) return m_text
[0]; 
 765         return wxEmptyString
; 
 767     const wxString 
GetText(size_t col
) const 
 769         if(m_text
.GetCount() > col
) return m_text
[col
]; 
 770         return wxEmptyString
; 
 772     int GetImage(wxTreeItemIcon which 
= wxTreeItemIcon_Normal
) const 
 773         { return m_images
[which
]; } 
 774     int GetImage(size_t col
, wxTreeItemIcon which
=wxTreeItemIcon_Normal
) const 
 776         if(col 
== m_owner
->GetMainColumn()) return m_images
[which
]; 
 777         if(col 
< m_col_images
.GetCount()) return m_col_images
[col
]; 
 780     wxTreeItemData 
*GetData() const { return m_data
; } 
 782     // returns the current image for the item (depending on its 
 783     // selected/expanded/whatever state) 
 784     int GetCurrentImage() const; 
 786     void SetText( const wxString 
&text 
); 
 787     void SetText(size_t col
, const wxString
& text
) // ALB 
 789         if(col 
< m_text
.GetCount()) 
 791         else if(col 
< m_owner
->GetColumnCount()) { 
 792             int howmany 
= m_owner
->GetColumnCount(); 
 793             for(int i 
= m_text
.GetCount(); i 
< howmany
; ++i
) 
 794                 m_text
.Add(wxEmptyString
); 
 798     void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; } 
 799     void SetImage(size_t col
, int image
, wxTreeItemIcon which
) 
 801         if(col 
== m_owner
->GetMainColumn()) m_images
[which
] = image
; 
 802         else if(col 
< m_col_images
.GetCount()) 
 803             m_col_images
[col
] = image
; 
 804         else if(col 
< m_owner
->GetColumnCount()) { 
 805             int howmany 
= m_owner
->GetColumnCount(); 
 806             for(int i 
= m_col_images
.GetCount(); i 
< howmany
; ++i
) 
 807                 m_col_images
.Add(NO_IMAGE
); 
 808             m_col_images
[col
] = image
; 
 812     void SetData(wxTreeItemData 
*data
) { m_data 
= data
; } 
 814     void SetHasPlus(bool has 
= TRUE
) { m_hasPlus 
= has
; } 
 816     void SetBold(bool bold
) { m_isBold 
= bold
; } 
 818     int GetX() const { return m_x
; } 
 819     int GetY() const { return m_y
; } 
 821     void SetX(int x
) { m_x 
= x
; } 
 822     void SetY(int y
) { m_y 
= y
; } 
 824     int  GetHeight() const { return m_height
; } 
 825     int  GetWidth()  const { return m_width
; } 
 827     void SetHeight(int h
) { m_height 
= h
; } 
 828     void SetWidth(int w
) { m_width 
= w
; } 
 830     wxTreeListItem 
*GetItemParent() const { return m_parent
; } 
 833     // deletes all children notifying the treectrl about it if !NULL 
 835     void DeleteChildren(wxTreeListMainWindow 
*tree 
= NULL
); 
 837     // get count of all children (and grand children if 'recursively') 
 838     size_t GetChildrenCount(bool recursively 
= TRUE
) const; 
 840     void Insert(wxTreeListItem 
*child
, size_t index
) 
 841     { m_children
.Insert(child
, index
); } 
 843     void GetSize( int &x
, int &y
, const wxTreeListMainWindow
* ); 
 845     // return the item at given position (or NULL if no item), onButton is 
 846     // TRUE if the point belongs to the item's button, otherwise it lies 
 847     // on the button's label 
 848     wxTreeListItem 
*HitTest( const wxPoint
& point
, 
 849                              const wxTreeListMainWindow 
*, 
 852     wxTreeListItem 
*HitTest( const wxPoint
& point
, 
 853                              const wxTreeListMainWindow 
*, 
 854                              int &flags
, int& column 
/*ALB*/, 
 857     void Expand() { m_isCollapsed 
= FALSE
; } 
 858     void Collapse() { m_isCollapsed 
= TRUE
; } 
 860     void SetHilight( bool set 
= TRUE 
) { m_hasHilight 
= set
; } 
 863     bool HasChildren() const { return !m_children
.IsEmpty(); } 
 864     bool IsSelected()  const { return m_hasHilight 
!= 0; } 
 865     bool IsExpanded()  const { return !m_isCollapsed
; } 
 866     bool HasPlus()     const { return m_hasPlus 
|| HasChildren(); } 
 867     bool IsBold()      const { return m_isBold 
!= 0; } 
 870     // get them - may be NULL 
 871     wxTreeItemAttr 
*GetAttributes() const { return m_attr
; } 
 872     // get them ensuring that the pointer is not NULL 
 873     wxTreeItemAttr
& Attr() 
 877             m_attr 
= new wxTreeItemAttr
; 
 883     void SetAttributes(wxTreeItemAttr 
*attr
) 
 885         if ( m_ownsAttr 
) delete m_attr
; 
 889     // set them and delete when done 
 890     void AssignAttributes(wxTreeItemAttr 
*attr
) 
 897     wxTreeListMainWindow  
*m_owner
;        // control the item belongs to 
 899     // since there can be very many of these, we save size by chosing 
 900     // the smallest representation for the elements and by ordering 
 901     // the members to avoid padding. 
 902     wxArrayString      m_text
;    // labels to be rendered for item 
 904     wxTreeItemData     
*m_data
;         // user-provided data 
 906     wxArrayTreeListItems m_children
; // list of children 
 907     wxTreeListItem  
*m_parent
;       // parent of this item 
 909     wxTreeItemAttr     
*m_attr
;         // attributes??? 
 911     // tree ctrl images for the normal, selected, expanded and 
 912     // expanded+selected states 
 913     short               m_images
[wxTreeItemIcon_Max
]; 
 914     wxArrayShort m_col_images
; // images for the various columns (!= main) 
 916     wxCoord             m_x
;            // (virtual) offset from top 
 917     wxCoord             m_y
;            // (virtual) offset from left 
 918     short               m_width
;        // width of this item 
 919     unsigned char       m_height
;       // height of this item 
 921     // use bitfields to save size 
 922     int                 m_isCollapsed 
:1; 
 923     int                 m_hasHilight  
:1; // same as focused 
 924     int                 m_hasPlus     
:1; // used for item which doesn't have 
 925                                           // children but has a [+] button 
 926     int                 m_isBold      
:1; // render the label in bold font 
 927     int                 m_ownsAttr    
:1; // delete attribute when done 
 930 // =========================================================================== 
 932 // =========================================================================== 
 934 // ---------------------------------------------------------------------------- 
 936 // ---------------------------------------------------------------------------- 
 938 // translate the key or mouse event flags to the type of selection we're 
 940 static void EventFlagsToSelType(long style
, 
 944                                 bool &extended_select
, 
 945                                 bool &unselect_others
) 
 947     is_multiple 
= (style 
& wxTR_MULTIPLE
) != 0; 
 948     extended_select 
= shiftDown 
&& is_multiple
; 
 949     unselect_others 
= !(extended_select 
|| (ctrlDown 
&& is_multiple
)); 
 952 // --------------------------------------------------------------------------- 
 953 // wxTreeListRenameTimer (internal) 
 954 // --------------------------------------------------------------------------- 
 956 wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow 
*owner 
) 
 961 void wxTreeListRenameTimer::Notify() 
 963     m_owner
->OnRenameTimer(); 
 966 //----------------------------------------------------------------------------- 
 967 // wxTreeListTextCtrl (internal) 
 968 //----------------------------------------------------------------------------- 
 970 BEGIN_EVENT_TABLE(wxTreeListTextCtrl
,wxTextCtrl
) 
 971     EVT_CHAR           (wxTreeListTextCtrl::OnChar
) 
 972     EVT_KEY_UP         (wxTreeListTextCtrl::OnKeyUp
) 
 973     EVT_KILL_FOCUS     (wxTreeListTextCtrl::OnKillFocus
) 
 976 wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow 
*parent
, 
 980                                         wxTreeListMainWindow 
*owner
, 
 981                                         const wxString 
&value
, 
 985                                         const wxValidator
& validator
, 
 986                                         const wxString 
&name 
) 
 987     : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name 
) 
 993     (*m_res
) = wxEmptyString
; 
 994     m_startValue 
= value
; 
 998 void wxTreeListTextCtrl::OnChar( wxKeyEvent 
&event 
) 
1000     if (event
.m_keyCode 
== WXK_RETURN
) 
1003         (*m_res
) = GetValue(); 
1005         if ((*m_res
) != m_startValue
) 
1006             m_owner
->OnRenameAccept(); 
1008         if (!wxPendingDelete
.Member(this)) 
1009             wxPendingDelete
.Append(this); 
1012         m_owner
->SetFocus(); // This doesn't work. TODO. 
1016     if (event
.m_keyCode 
== WXK_ESCAPE
) 
1018         (*m_accept
) = FALSE
; 
1019         (*m_res
) = wxEmptyString
; 
1021         if (!wxPendingDelete
.Member(this)) 
1022             wxPendingDelete
.Append(this); 
1025         m_owner
->SetFocus(); // This doesn't work. TODO. 
1032 void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent 
&event 
) 
1040     // auto-grow the textctrl: 
1041     wxSize parentSize 
= m_owner
->GetSize(); 
1042     wxPoint myPos 
= GetPosition(); 
1043     wxSize mySize 
= GetSize(); 
1045     GetTextExtent(GetValue() + _T("M"), &sx
, &sy
); 
1046     if (myPos
.x 
+ sx 
> parentSize
.x
) sx 
= parentSize
.x 
- myPos
.x
; 
1047     if (mySize
.x 
> sx
) sx 
= mySize
.x
; 
1053 void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent 
&event 
) 
1061     if (!wxPendingDelete
.Member(this)) 
1062         wxPendingDelete
.Append(this); 
1065     (*m_res
) = GetValue(); 
1067     if ((*m_res
) != m_startValue
) 
1068         m_owner
->OnRenameAccept(); 
1071 //----------------------------------------------------------------------------- 
1072 //  wxTreeListHeaderWindow 
1073 //----------------------------------------------------------------------------- 
1075 IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow
,wxWindow
); 
1077 BEGIN_EVENT_TABLE(wxTreeListHeaderWindow
,wxWindow
) 
1078     EVT_PAINT         (wxTreeListHeaderWindow::OnPaint
) 
1079     EVT_MOUSE_EVENTS  (wxTreeListHeaderWindow::OnMouse
) 
1080     EVT_SET_FOCUS     (wxTreeListHeaderWindow::OnSetFocus
) 
1083 void wxTreeListHeaderWindow::Init() 
1085     m_currentCursor 
= (wxCursor 
*) NULL
; 
1086     m_isDragging 
= FALSE
; 
1088     m_total_col_width 
= 0; 
1091 wxTreeListHeaderWindow::wxTreeListHeaderWindow() 
1095     m_owner 
= (wxTreeListMainWindow 
*) NULL
; 
1096     m_resizeCursor 
= (wxCursor 
*) NULL
; 
1099 wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow 
*win
, 
1101                                                 wxTreeListMainWindow 
*owner
, 
1105                                                 const wxString 
&name 
) 
1106     : wxWindow( win
, id
, pos
, size
, style
, name 
) 
1111     m_resizeCursor 
= new wxCursor(wxCURSOR_SIZEWE
); 
1113     SetBackgroundColour(wxSystemSettings::GetSystemColour( 
1114                             wxSYS_COLOUR_BTNFACE
)); 
1117 wxTreeListHeaderWindow::~wxTreeListHeaderWindow() 
1119     delete m_resizeCursor
; 
1122 void wxTreeListHeaderWindow::DoDrawRect( wxDC 
*dc
, int x
, int y
, int w
, int h 
) 
1125     GtkStateType state 
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
 
1126                                                : GTK_STATE_INSENSITIVE
; 
1128     x 
= dc
->XLOG2DEV( x 
); 
1130     gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, 
1131                    state
, GTK_SHADOW_OUT
, 
1132                    (GdkRectangle
*) NULL
, m_wxwindow
, "button", 
1133                    x
-1, y
-1, w
+2, h
+2); 
1134 #elif defined( __WXMAC__  ) 
1135     const int m_corner 
= 1; 
1137     dc
->SetBrush( *wxTRANSPARENT_BRUSH 
); 
1139     dc
->SetPen( wxPen(wxSystemSettings::GetSystemColour( 
1140                           wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
)); 
1141     dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h 
);  // right (outer) 
1142     dc
->DrawRectangle( x
, y
+h
, w
+1, 1 );          // bottom (outer) 
1144     wxPen 
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID 
); 
1147     dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h 
);  // right (inner) 
1148     dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 );      // bottom (inner) 
1150     dc
->SetPen( *wxWHITE_PEN 
); 
1151     dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 );   // top (outer) 
1152     dc
->DrawRectangle( x
, y
, 1, h 
);              // left (outer) 
1153     dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 ); 
1154     dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 ); 
1156     const int m_corner 
= 1; 
1158     dc
->SetBrush( *wxTRANSPARENT_BRUSH 
); 
1160     dc
->SetPen( *wxBLACK_PEN 
); 
1161     dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h 
);  // right (outer) 
1162     dc
->DrawRectangle( x
, y
+h
, w
+1, 1 );          // bottom (outer) 
1164     wxPen 
pen(wxSystemSettings::GetSystemColour( 
1165                   wxSYS_COLOUR_BTNSHADOW 
), 1, wxSOLID
); 
1168     dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h 
);  // right (inner) 
1169     dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 );      // bottom (inner) 
1171     dc
->SetPen( *wxWHITE_PEN 
); 
1172     dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 );   // top (outer) 
1173     dc
->DrawRectangle( x
, y
, 1, h 
);              // left (outer) 
1174     dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 ); 
1175     dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 ); 
1179 // shift the DC origin to match the position of the main window horz 
1180 // scrollbar: this allows us to always use logical coords 
1181 void wxTreeListHeaderWindow::AdjustDC(wxDC
& dc
) 
1184     m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL 
); 
1187     m_owner
->GetViewStart( &x
, NULL 
); 
1189     // account for the horz scrollbar offset 
1190     dc
.SetDeviceOrigin( -x 
* xpix
, 0 ); 
1193 void wxTreeListHeaderWindow::OnPaint( wxPaintEvent 
&WXUNUSED(event
) ) 
1196     wxClientDC 
dc( this ); 
1198     wxPaintDC 
dc( this ); 
1206     dc
.SetFont( GetFont() ); 
1208     // width and height of the entire header window 
1210     GetClientSize( &w
, &h 
); 
1211     m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
); 
1213     dc
.SetBackgroundMode(wxTRANSPARENT
); 
1215     // do *not* use the listctrl colour for headers - one day we will have a 
1216     // function to set it separately 
1217     //dc.SetTextForeground( *wxBLACK ); 
1218     dc
.SetTextForeground(wxSystemSettings:: 
1219                             GetSystemColour( wxSYS_COLOUR_WINDOWTEXT 
)); 
1221     int x 
= HEADER_OFFSET_X
; 
1223     int numColumns 
= GetColumnCount(); 
1224     for ( int i 
= 0; i 
< numColumns 
&& x 
< w
; i
++ ) 
1226         if (!GetColumnShown (i
)) continue; 
1228         wxTreeListColumnInfo
& column 
= GetColumn(i
); 
1229         int wCol 
= column
.GetWidth(); 
1231         // the width of the rect to draw: make it smaller to fit entirely 
1232         // inside the column rect 
1235         dc
.SetPen( *wxWHITE_PEN 
); 
1237         //DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 ); 
1238         wxRendererNative::Get().DrawHeaderButton( 
1239             this, dc
, wxRect(x
, HEADER_OFFSET_Y
, cw
, h 
- 2), 
1240             m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
); 
1243         // if we have an image, draw it on the right of the label 
1244         int image 
= column
.GetImage(); //item.m_image; 
1245         int ix 
= -2, iy 
= 0; 
1246         wxImageList
* imageList 
= m_owner
->GetImageList(); 
1249                 imageList
->GetSize(image
, ix
, iy
); 
1251         //else: ignore the column image 
1256         int image_offset 
= cw 
- ix 
- 1; 
1258         switch(column
.GetAlignment()) { 
1259         case wxTL_ALIGN_LEFT
: 
1260             text_x 
+= EXTRA_WIDTH
; 
1263         case wxTL_ALIGN_RIGHT
: 
1264             dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
); 
1265             text_x 
+= cw 
- text_width 
- EXTRA_WIDTH
; 
1268         case wxTL_ALIGN_CENTER
: 
1269             dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
); 
1270             text_x 
+= (cw 
- text_width
)/2 + ix 
+ 2; 
1271             image_offset 
= (cw 
- text_width 
- ix 
- 2)/2; 
1276         if(image 
!= -1 && imageList
) { 
1277             imageList
->Draw(image
, dc
, x 
+ image_offset
/*cw - ix - 1*/, 
1278                             HEADER_OFFSET_Y 
+ (h 
- 4 - iy
)/2, 
1279                             wxIMAGELIST_DRAW_TRANSPARENT
); 
1282         // draw the text clipping it so that it doesn't overwrite the column 
1284         wxDCClipper 
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h 
- 4 ); 
1286         dc
.DrawText( column
.GetText(), 
1287                      text_x
, HEADER_OFFSET_Y 
+ EXTRA_HEIGHT 
); 
1292     int more_w 
= m_owner
->GetSize().x 
- x 
-1; 
1295         //DoDrawRect( &dc, x, HEADER_OFFSET_Y, more_w, h-2 ); 
1296         wxRendererNative::Get().DrawHeaderButton( 
1297             this, dc
, wxRect(x
, HEADER_OFFSET_Y
, more_w
, h
-2), 
1298             m_parent
->IsEnabled() ? 0 : wxCONTROL_DISABLED
); 
1305 void wxTreeListHeaderWindow::DrawCurrent() 
1307     int x1 
= m_currentX
; 
1309     ClientToScreen( &x1
, &y1 
); 
1311     int x2 
= m_currentX
-1; 
1316     m_owner
->GetClientSize( NULL
, &y2 
); 
1317     m_owner
->ClientToScreen( &x2
, &y2 
); 
1320     dc
.SetLogicalFunction( wxINVERT 
); 
1321     dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID 
) ); 
1322     dc
.SetBrush( *wxTRANSPARENT_BRUSH 
); 
1326     dc
.DrawLine( x1
, y1
, x2
, y2 
); 
1328     dc
.SetLogicalFunction( wxCOPY 
); 
1330     dc
.SetPen( wxNullPen 
); 
1331     dc
.SetBrush( wxNullBrush 
); 
1334 void wxTreeListHeaderWindow::OnMouse( wxMouseEvent 
&event 
) 
1336     // we want to work with logical coords 
1338     m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
); 
1339     int y 
= event
.GetY(); 
1343         SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
, 
1344                       event
.GetPosition()); 
1346         // we don't draw the line beyond our window, but we allow dragging it 
1349         GetClientSize( &w
, NULL 
); 
1350         m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
); 
1353         // erase the line if it was drawn 
1354         if ( m_currentX 
< w 
) 
1357         if (event
.ButtonUp()) 
1360             m_isDragging 
= FALSE
; 
1362             SetColumnWidth( m_column
, m_currentX 
- m_minX 
); 
1364             SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
, 
1365                           event
.GetPosition()); 
1372                 m_currentX 
= m_minX 
+ 7; 
1374             // draw in the new location 
1375             if ( m_currentX 
< w 
) 
1379     else // not dragging 
1382         bool hit_border 
= FALSE
; 
1384         // end of the current column 
1387         // find the column where this event occured 
1388         int countCol 
= GetColumnCount(); 
1389         for (int col 
= 0; col 
< countCol
; col
++) 
1391             if (!GetColumnShown (col
)) continue; 
1392             xpos 
+= GetColumnWidth (col
); 
1395             if ( (abs(x
-xpos
) < 3) && (y 
< 22) ) 
1397                 // near the column border 
1404                 // inside the column 
1411         if (event
.LeftDown() || event
.RightUp()) 
1413             if (hit_border 
&& event
.LeftDown()) 
1415                 m_isDragging 
= TRUE
; 
1419                 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 
1420                               event
.GetPosition()); 
1422             else // click on a column 
1424                 SendListEvent( event
.LeftDown() 
1425                                ? wxEVT_COMMAND_LIST_COL_CLICK
 
1426                                : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 
1427                                event
.GetPosition()); 
1430         else if (event
.Moving()) 
1435                 setCursor 
= m_currentCursor 
== wxSTANDARD_CURSOR
; 
1436                 m_currentCursor 
= m_resizeCursor
; 
1440                 setCursor 
= m_currentCursor 
!= wxSTANDARD_CURSOR
; 
1441                 m_currentCursor 
= wxSTANDARD_CURSOR
; 
1445                 SetCursor(*m_currentCursor
); 
1450 void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent 
&WXUNUSED(event
) ) 
1452     m_owner
->SetFocus(); 
1455 void wxTreeListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
) 
1457     wxWindow 
*parent 
= GetParent(); 
1458     wxListEvent 
le( type
, parent
->GetId() ); 
1459     le
.SetEventObject( parent 
); 
1460     le
.m_pointDrag 
= pos
; 
1462     // the position should be relative to the parent window, not 
1463     // this one for compatibility with MSW and common sense: the 
1464     // user code doesn't know anything at all about this header 
1465     // window, so why should it get positions relative to it? 
1466     le
.m_pointDrag
.y 
-= GetSize().y
; 
1468     le
.m_col 
= m_column
; 
1469     parent
->GetEventHandler()->ProcessEvent( le 
); 
1472 void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo
& col
) 
1475     m_total_col_width 
+= col
.GetWidth(); 
1476     //m_owner->GetHeaderWindow()->Refresh(); 
1478     m_owner
->AdjustMyScrollbars(); 
1479     m_owner
->m_dirty 
= TRUE
; 
1483 void wxTreeListHeaderWindow::SetColumnWidth(size_t column
, size_t width
) 
1485     if(column 
< GetColumnCount()) { 
1486         m_total_col_width 
-= m_columns
[column
].GetWidth(); 
1487         m_columns
[column
].SetWidth(width
); 
1488         m_total_col_width 
+= width
; 
1489         m_owner
->AdjustMyScrollbars(); 
1490         m_owner
->m_dirty 
= TRUE
; 
1497 void wxTreeListHeaderWindow::InsertColumn(size_t before
, 
1498                                           const wxTreeListColumnInfo
& col
) 
1500     wxCHECK_RET(before 
< GetColumnCount(), wxT("Invalid column index")); 
1501     m_columns
.Insert(col
, before
); 
1502     m_total_col_width 
+= col
.GetWidth(); 
1504     //m_owner->GetHeaderWindow()->Refresh(); 
1505     m_owner
->AdjustMyScrollbars(); 
1506     m_owner
->m_dirty 
= TRUE
; 
1510 void wxTreeListHeaderWindow::RemoveColumn(size_t column
) 
1512     wxCHECK_RET(column 
< GetColumnCount(), wxT("Invalid column")); 
1513     m_total_col_width 
-= m_columns
[column
].GetWidth(); 
1514     m_columns
.RemoveAt(column
); 
1516     m_owner
->AdjustMyScrollbars(); 
1517     m_owner
->m_dirty 
= TRUE
; 
1521 void wxTreeListHeaderWindow::SetColumn(size_t column
, 
1522                                        const wxTreeListColumnInfo
& info
) 
1524     wxCHECK_RET(column 
< GetColumnCount(), wxT("Invalid column")); 
1525     size_t w 
= m_columns
[column
].GetWidth(); 
1526     m_columns
[column
] = info
; 
1527     //m_owner->GetHeaderWindow()->Refresh(); 
1529     if(w 
!= info
.GetWidth()) { 
1530         m_total_col_width 
+= info
.GetWidth() - w
; 
1531         m_owner
->AdjustMyScrollbars(); 
1532         m_owner
->m_dirty 
= TRUE
; 
1537 // --------------------------------------------------------------------------- 
1539 // --------------------------------------------------------------------------- 
1541 wxTreeListItem::wxTreeListItem(wxTreeListMainWindow 
*owner
, 
1542                                      wxTreeListItem 
*parent
, 
1543                                      const wxArrayString
& text
, 
1544                                      int image
, int selImage
, 
1545                                      wxTreeItemData 
*data
) 
1548     m_images
[wxTreeItemIcon_Normal
] = image
; 
1549     m_images
[wxTreeItemIcon_Selected
] = selImage
; 
1550     m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
; 
1551     m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
; 
1556     m_isCollapsed 
= TRUE
; 
1557     m_hasHilight 
= FALSE
; 
1565     m_attr 
= (wxTreeItemAttr 
*)NULL
; 
1568     // We don't know the height here yet. 
1573 wxTreeListItem::~wxTreeListItem() 
1577     if (m_ownsAttr
) delete m_attr
; 
1579     wxASSERT_MSG( m_children
.IsEmpty(), 
1580                   wxT("please call DeleteChildren() before deleting the item") ); 
1583 void wxTreeListItem::DeleteChildren(wxTreeListMainWindow 
*tree
) 
1585     size_t count 
= m_children
.Count(); 
1586     for ( size_t n 
= 0; n 
< count
; n
++ ) 
1588         wxTreeListItem 
*child 
= m_children
[n
]; 
1590             tree
->SendDeleteEvent(child
); 
1592         child
->DeleteChildren(tree
); 
1599 void wxTreeListItem::SetText( const wxString 
&text 
) 
1601     if(m_text
.GetCount() > 0) m_text
[0] = text
; 
1607 size_t wxTreeListItem::GetChildrenCount(bool recursively
) const 
1609     size_t count 
= m_children
.Count(); 
1613     size_t total 
= count
; 
1614     for (size_t n 
= 0; n 
< count
; ++n
) 
1616         total 
+= m_children
[n
]->GetChildrenCount(); 
1622 void wxTreeListItem::GetSize( int &x
, int &y
, 
1623                                  const wxTreeListMainWindow 
*theButton 
) 
1625     int bottomY
=m_y
+theButton
->GetLineHeight(this); 
1626     if ( y 
< bottomY 
) y 
= bottomY
; 
1627     int width 
= m_x 
+  m_width
; 
1628     if ( x 
< width 
) x 
= width
; 
1632         size_t count 
= m_children
.Count(); 
1633         for ( size_t n 
= 0; n 
< count
; ++n 
) 
1635             m_children
[n
]->GetSize( x
, y
, theButton 
); 
1640 wxTreeListItem 
*wxTreeListItem::HitTest(const wxPoint
& point
, 
1641                                         const wxTreeListMainWindow 
*theCtrl
, 
1645     // for a hidden root node, don't evaluate it, but do evaluate children 
1646     if (!(theCtrl
->HasFlag(wxTR_HIDE_ROOT
) && (level 
== 0))) 
1648         // evaluate the item 
1649         int h 
= theCtrl
->GetLineHeight(this); 
1650         if ((point
.y 
> m_y
) && (point
.y 
<= m_y 
+ h
)) 
1652             // check for above/below middle 
1653             int y_mid 
= m_y 
+ h
/2; 
1654             if (point
.y 
< y_mid 
) 
1655                 flags 
|= wxTREE_HITTEST_ONITEMUPPERPART
; 
1657                 flags 
|= wxTREE_HITTEST_ONITEMLOWERPART
; 
1659             // check for button hit 
1660             int xCross 
= m_x
; // - theCtrl->GetLineSpacing(); 
1662             // according to the drawing code the triangels are drawn 
1663             // at -4 , -4  from the position up to +10/+10 max 
1664             if ((point
.x 
> xCross
-4) && (point
.x 
< xCross
+10) && 
1665                 (point
.y 
> y_mid
-4) && (point
.y 
< y_mid
+10) && 
1666                 HasPlus() && theCtrl
->HasButtons() ) 
1668             // 5 is the size of the plus sign 
1669             if ((point
.x 
> xCross
-6) && (point
.x 
< xCross
+6) && 
1670                 (point
.y 
> y_mid
-6) && (point
.y 
< y_mid
+6) && 
1671                 HasPlus() && theCtrl
->HasButtons() ) 
1674                 flags 
|= wxTREE_HITTEST_ONITEMBUTTON
; 
1678             // check for image hit 
1679             if (theCtrl
->m_imgWidth 
> 0 && GetImage() != NO_IMAGE
) { 
1680                 int imgX 
= m_x 
- theCtrl
->m_imgWidth2
; 
1681                 if (HasPlus() && theCtrl
->HasButtons()) 
1682                     imgX 
+= theCtrl
->m_btnWidth 
+ LINEATROOT
; 
1683                 int imgY 
= y_mid 
- theCtrl
->m_imgHeight2
; 
1684                 if ((point
.x 
>= imgX
) && (point
.x 
<= (imgX 
+ theCtrl
->m_imgWidth
)) && 
1685                     (point
.y 
>= imgY
) && (point
.y 
<= (imgY 
+ theCtrl
->m_imgHeight
))) { 
1686                     flags 
|= wxTREE_HITTEST_ONITEMICON
; 
1691             // check for label hit 
1692             int lblX 
= m_x 
- theCtrl
->m_imgWidth2 
+ theCtrl
->m_imgWidth 
+ MARGIN
; 
1693             if ((point
.x 
>= lblX
) && (point
.x 
<= (m_x 
+ m_width
)) && 
1694                 (point
.y 
>= m_y
) && (point
.y 
<= (m_y 
+ h
))) { 
1695                 flags 
|= wxTREE_HITTEST_ONITEMLABEL
; 
1699             // else check for indent 
1700             if (point
.x 
< m_x
) { 
1701                 flags 
|= wxTREE_HITTEST_ONITEMINDENT
; 
1705             // else check for item right??? 
1706             if (point
.x 
> m_x 
+ m_width
) { 
1707                 flags 
|= wxTREE_HITTEST_ONITEMRIGHT
; 
1713         // if children are expanded, fall through to evaluate them 
1714         if (m_isCollapsed
) return (wxTreeListItem
*) NULL
; 
1717     // evaluate children 
1718     size_t count 
= m_children
.Count(); 
1719     for ( size_t n 
= 0; n 
< count
; n
++ ) 
1721         wxTreeListItem 
*res 
= m_children
[n
]->HitTest(point
, theCtrl
, 
1727     return (wxTreeListItem
*) NULL
; 
1731 wxTreeListItem 
*wxTreeListItem::HitTest(const wxPoint
& point
, 
1732                                         const wxTreeListMainWindow 
*theCtrl
, 
1733                                         int &flags
, int& column
, int level
) 
1735     column 
= theCtrl
->GetMainColumn(); //-1; 
1737     wxTreeListItem
* res 
= HitTest(point
, theCtrl
, flags
, level
); 
1743     wxTreeListHeaderWindow
* header_win 
= theCtrl
->m_owner
->GetHeaderWindow(); 
1744     if (point
.x 
>= header_win
->GetWidth()) 
1746     else if(flags 
& wxTREE_HITTEST_ONITEMINDENT
) { 
1748         for(size_t i 
= 0; i 
< theCtrl
->GetMainColumn(); ++i
) { 
1749             if (!header_win
->GetColumnShown(i
)) continue; 
1750             int w 
= header_win
->GetColumnWidth(i
); 
1751             if(point
.x 
>= x 
&& point
.x 
< x
+w
) { 
1752                 flags 
^= wxTREE_HITTEST_ONITEMINDENT
; 
1753                 flags 
|= wxTREE_HITTEST_ONITEMCOLUMN
; 
1759     else if(flags 
& wxTREE_HITTEST_ONITEMRIGHT
) { 
1762         for(i 
= 0; i 
< theCtrl
->GetMainColumn()+1; ++i
) { 
1763             if (!header_win
->GetColumnShown(i
)) continue; 
1764             x 
+= header_win
->GetColumnWidth(i
); 
1766         for(i 
= theCtrl
->GetMainColumn()+1; i 
< theCtrl
->GetColumnCount(); ++i
) { 
1767             if (!header_win
->GetColumnShown(i
)) continue; 
1768             int w 
= header_win
->GetColumnWidth(i
); 
1769             if(point
.x 
>= x 
&& point
.x 
< x
+w
) { 
1770                 flags 
^= wxTREE_HITTEST_ONITEMRIGHT
; 
1771                 flags 
|= wxTREE_HITTEST_ONITEMCOLUMN
; 
1783 int wxTreeListItem::GetCurrentImage() const 
1785     int image 
= NO_IMAGE
; 
1790             image 
= GetImage(wxTreeItemIcon_SelectedExpanded
); 
1793         if ( image 
== NO_IMAGE 
) 
1795             // we usually fall back to the normal item, but try just the 
1796             // expanded one (and not selected) first in this case 
1797             image 
= GetImage(wxTreeItemIcon_Expanded
); 
1800     else // not expanded 
1803             image 
= GetImage(wxTreeItemIcon_Selected
); 
1806     // maybe it doesn't have the specific image we want, 
1807     // try the default one instead 
1808     if ( image 
== NO_IMAGE 
) image 
= GetImage(); 
1813 // --------------------------------------------------------------------------- 
1814 // wxTreeListMainWindow implementation 
1815 // --------------------------------------------------------------------------- 
1817 IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow
, wxScrolledWindow
) 
1819 BEGIN_EVENT_TABLE(wxTreeListMainWindow
, wxScrolledWindow
) 
1820     EVT_PAINT          (wxTreeListMainWindow::OnPaint
) 
1821     EVT_MOUSE_EVENTS   (wxTreeListMainWindow::OnMouse
) 
1822     EVT_CHAR           (wxTreeListMainWindow::OnChar
) 
1823     EVT_SET_FOCUS      (wxTreeListMainWindow::OnSetFocus
) 
1824     EVT_KILL_FOCUS     (wxTreeListMainWindow::OnKillFocus
) 
1825     EVT_IDLE           (wxTreeListMainWindow::OnIdle
) 
1826     EVT_SCROLLWIN      (wxTreeListMainWindow::OnScroll
) 
1830 // --------------------------------------------------------------------------- 
1831 // construction/destruction 
1832 // --------------------------------------------------------------------------- 
1834 void wxTreeListMainWindow::Init() 
1836     m_current 
= m_key_current 
= m_anchor 
= (wxTreeListItem 
*) NULL
; 
1840     m_lineHeight 
= LINEHEIGHT
; 
1841     m_indent 
= MININDENT
; // min. indent 
1843     m_imgWidth 
= 0, m_imgWidth2 
= 0; 
1844     m_imgHeight 
= 0, m_imgHeight2 
= 0; 
1846     m_hilightBrush 
= new wxBrush
 
1848                             wxSystemSettings::GetSystemColour
 
1850                                 wxSYS_COLOUR_HIGHLIGHT
 
1855     m_hilightUnfocusedBrush 
= new wxBrush
 
1857                                  wxSystemSettings::GetSystemColour
 
1859                                      wxSYS_COLOUR_BTNSHADOW
 
1864     m_imageListNormal 
= m_imageListButtons 
= 
1865     m_imageListState 
= (wxImageList 
*) NULL
; 
1866     m_ownsImageListNormal 
= m_ownsImageListButtons 
= 
1867     m_ownsImageListState 
= FALSE
; 
1870     m_isDragging 
= FALSE
; 
1871     m_dropTarget 
= m_oldSelection 
= (wxTreeListItem 
*)NULL
; 
1873     m_renameTimer 
= new wxTreeListRenameTimer( this ); 
1874     m_lastOnSame 
= FALSE
; 
1876     m_findTimer 
= new wxTimer (this, -1); 
1878     m_underMouse 
= NULL
; 
1880 #if defined( __WXMAC__ ) && __WXMAC_CARBON__ 
1881     m_normalFont
.MacCreateThemeFont( kThemeViewsFont 
) ; 
1883     m_normalFont 
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT 
); 
1885     m_boldFont 
= wxFont( m_normalFont
.GetPointSize(), 
1886                          m_normalFont
.GetFamily(), 
1887                          m_normalFont
.GetStyle(), 
1889                          m_normalFont
.GetUnderlined(), 
1890                          m_normalFont
.GetFaceName(), 
1891                          m_normalFont
.GetEncoding()); 
1895 bool wxTreeListMainWindow::Create(wxTreeListCtrl 
*parent
, 
1900                                   const wxValidator 
&validator
, 
1901                                   const wxString
& name 
) 
1904     if ( !(style 
& wxTR_DONT_ADJUST_MAC
)) 
1907         wxGetOsVersion( &major
, &minor 
); 
1909         if (style 
& wxTR_HAS_BUTTONS
) style 
|= wxTR_TWIST_BUTTONS
; 
1910         if (style 
& wxTR_HAS_BUTTONS
) style 
&= ~wxTR_HAS_BUTTONS
; 
1911         style 
&= ~wxTR_LINES_AT_ROOT
; 
1912         style 
|= wxTR_NO_LINES
; 
1914             style 
|= wxTR_ROW_LINES
; 
1918     wxScrolledWindow::Create( parent
, id
, pos
, size
, 
1919                               style
|wxHSCROLL
|wxVSCROLL
, name 
); 
1921 #if wxUSE_VALIDATORS 
1922     SetValidator( validator 
); 
1925     SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX 
) ); 
1932         bdc
.SelectObject(bmp
); 
1933         bdc
.SetPen(*wxGREY_PEN
); 
1934         bdc
.DrawRectangle(-1, -1, 10, 10); 
1935         for (i 
= 0; i 
< 8; i
++) { 
1936             for (j 
= 0; j 
< 8; j
++) { 
1937                 if (!((i 
+ j
) & 1)) { 
1938                     bdc
.DrawPoint(i
, j
); 
1943         m_dottedPen 
= wxPen(bmp
, 1); 
1946     //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT );  // too slow under XFree86 
1947     m_dottedPen 
= wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK! 
1957 wxTreeListMainWindow::~wxTreeListMainWindow() 
1959     delete m_hilightBrush
; 
1960     delete m_hilightUnfocusedBrush
; 
1964     delete m_renameTimer
; 
1966     if (m_ownsImageListNormal
) delete m_imageListNormal
; 
1967     if (m_ownsImageListState
) delete m_imageListState
; 
1968     if (m_ownsImageListButtons
) delete m_imageListButtons
; 
1973 //----------------------------------------------------------------------------- 
1975 //----------------------------------------------------------------------------- 
1977 size_t wxTreeListMainWindow::GetCount() const 
1979     return m_anchor 
== NULL 
? 0u : m_anchor
->GetChildrenCount(); 
1982 void wxTreeListMainWindow::SetIndent(unsigned int indent
) 
1988 void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing
) 
1990     m_linespacing 
= spacing
; 
1992     CalculateLineHeight(); 
1995 size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId
& item
, 
1998     wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") ); 
2000     return ((wxTreeListItem
*) item
.m_pItem
)->GetChildrenCount(recursively
); 
2003 void wxTreeListMainWindow::SetWindowStyle(const long styles
) 
2005     // right now, just sets the styles.  Eventually, we may 
2006     // want to update the inherited styles, but right now 
2007     // none of the parents has updatable styles 
2008     m_windowStyle 
= styles
; 
2012 //----------------------------------------------------------------------------- 
2013 // functions to work with tree items 
2014 //----------------------------------------------------------------------------- 
2016 int wxTreeListMainWindow::GetItemImage(const wxTreeItemId
& item
, size_t column
, 
2017                                        wxTreeItemIcon which
) const 
2019     wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") ); 
2021     return ((wxTreeListItem
*) item
.m_pItem
)->GetImage(column
, which
); 
2024 wxTreeItemData 
*wxTreeListMainWindow::GetItemData(const wxTreeItemId
& item
) 
2027     wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") ); 
2029     return ((wxTreeListItem
*) item
.m_pItem
)->GetData(); 
2032 bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId
& item
) const 
2034     wxCHECK_MSG(item
.IsOk(), FALSE
, wxT("invalid tree item")); 
2035     return ((wxTreeListItem 
*)item
.m_pItem
)->IsBold(); 
2038 wxColour 
wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId
& item
) 
2041     wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") ); 
2043     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2044     return pItem
->Attr().GetTextColour(); 
2047 wxColour 
wxTreeListMainWindow::GetItemBackgroundColour( 
2048     const wxTreeItemId
& item
) const 
2050     wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") ); 
2052     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2053     return pItem
->Attr().GetBackgroundColour(); 
2056 wxFont 
wxTreeListMainWindow::GetItemFont(const wxTreeItemId
& item
) const 
2058     wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") ); 
2060     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2061     return pItem
->Attr().GetFont(); 
2066 void wxTreeListMainWindow::SetItemImage(const wxTreeItemId
& item
, 
2068                                         int image
, wxTreeItemIcon which
) 
2070     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2072     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2073     pItem
->SetImage(column
, image
, which
); 
2075     wxClientDC 
dc(this); 
2076     CalculateSize(pItem
, dc
); 
2080 void wxTreeListMainWindow::SetItemData(const wxTreeItemId
& item
, 
2081                                        wxTreeItemData 
*data
) 
2083     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2085     ((wxTreeListItem
*) item
.m_pItem
)->SetData(data
); 
2088 void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId
& item
, 
2091     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2093     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2094     pItem
->SetHasPlus(has
); 
2098 void wxTreeListMainWindow::SetItemBold(const wxTreeItemId
& item
, bool bold
) 
2100     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2102     // avoid redrawing the tree if no real change 
2103     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2104     if ( pItem
->IsBold() != bold 
) 
2106         pItem
->SetBold(bold
); 
2111 void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId
& item
, 
2112                                              const wxColour
& col
) 
2114     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2116     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2117     pItem
->Attr().SetTextColour(col
); 
2121 void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId
& item
, 
2122                                                    const wxColour
& col
) 
2124     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2126     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2127     pItem
->Attr().SetBackgroundColour(col
); 
2131 void wxTreeListMainWindow::SetItemFont(const wxTreeItemId
& item
, 
2134     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
2136     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2137     pItem
->Attr().SetFont(font
); 
2141 bool wxTreeListMainWindow::SetFont( const wxFont 
&font 
) 
2143     wxScrolledWindow::SetFont(font
); 
2145     m_normalFont 
= font 
; 
2146     m_boldFont 
= wxFont( m_normalFont
.GetPointSize(), 
2147                             m_normalFont
.GetFamily(), 
2148                             m_normalFont
.GetStyle(), 
2150                             m_normalFont
.GetUnderlined()); 
2156 // ---------------------------------------------------------------------------- 
2157 // item status inquiries 
2158 // ---------------------------------------------------------------------------- 
2160 bool wxTreeListMainWindow::IsVisible(const wxTreeItemId
& item
) const 
2162     wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") ); 
2164     // An item is only visible if it's not a descendant of a collapsed item 
2165     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
2166     wxTreeListItem
* parent 
= pItem
->GetItemParent(); 
2169         if (!parent
->IsExpanded()) 
2171         parent 
= parent
->GetItemParent(); 
2175     GetViewStart(& startX
, & startY
); 
2177     wxSize clientSize 
= GetClientSize(); 
2180     if (!GetBoundingRect(item
, rect
)) 
2182     if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0) 
2184     if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
) 
2186     if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
) 
2192 bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId
& item
) const 
2194     wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") ); 
2196     // consider that the item does have children if it has the "+" button: it 
2197     // might not have them (if it had never been expanded yet) but then it 
2198     // could have them as well and it's better to err on this side rather than 
2199     // disabling some operations which are restricted to the items with 
2200     // children for an item which does have them 
2201     return ((wxTreeListItem
*) item
.m_pItem
)->HasPlus(); 
2204 bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId
& item
) const 
2206     wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") ); 
2208     return ((wxTreeListItem
*) item
.m_pItem
)->IsExpanded(); 
2211 bool wxTreeListMainWindow::IsSelected(const wxTreeItemId
& item
) const 
2213     wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") ); 
2215     return ((wxTreeListItem
*) item
.m_pItem
)->IsSelected(); 
2218 bool wxTreeListMainWindow::IsBold(const wxTreeItemId
& item
) const 
2220     wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") ); 
2222     return ((wxTreeListItem
*) item
.m_pItem
)->IsBold(); 
2225 // ---------------------------------------------------------------------------- 
2227 // ---------------------------------------------------------------------------- 
2229 wxTreeItemId 
wxTreeListMainWindow::GetItemParent(const wxTreeItemId
& item
) const 
2231     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2233     return ((wxTreeListItem
*) item
.m_pItem
)->GetItemParent(); 
2236 #if !wxCHECK_VERSION(2, 5, 0) 
2237 wxTreeItemId 
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
, 
2240 wxTreeItemId 
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
, 
2241                                                  wxTreeItemIdValue
& cookie
) const 
2244     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2247     return GetNextChild(item
, cookie
); 
2250 #if !wxCHECK_VERSION(2, 5, 0) 
2251 wxTreeItemId 
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
, 
2254 wxTreeItemId 
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
, 
2255                                                 wxTreeItemIdValue
& cookie
) const 
2258     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2260     wxArrayTreeListItems
& children 
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren(); 
2262     // it's ok to cast cookie to size_t, we never have indices big enough to 
2263     // overflow "void *" 
2264     size_t *pIndex 
= (size_t *)&cookie
; 
2265     if ( *pIndex 
< children
.Count() ) 
2267         return children
.Item((*pIndex
)++); 
2271         // there are no more of them 
2272         return wxTreeItemId(); 
2276 #if !wxCHECK_VERSION(2, 5, 0) 
2277 wxTreeItemId 
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
, 
2280 wxTreeItemId 
wxTreeListMainWindow::GetPrevChild(const wxTreeItemId
& item
, 
2281                                                 wxTreeItemIdValue
& cookie
) const 
2284     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2286     wxArrayTreeListItems
& children 
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren(); 
2288     // it's ok to cast cookie to size_t, we never have indices big enough to 
2289     // overflow "void *" 
2290     size_t *pIndex 
= (size_t *)&cookie
; 
2293         return children
.Item(--(*pIndex
)); 
2297         // there are no more of them 
2298         return wxTreeItemId(); 
2302 wxTreeItemId 
wxTreeListMainWindow::GetLastChild(const wxTreeItemId
& item
) const 
2304     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2306     wxArrayTreeListItems
& children 
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren(); 
2307     return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last())); 
2310 wxTreeItemId 
wxTreeListMainWindow::GetNextSibling(const wxTreeItemId
& item
) const 
2312     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2314     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
2315     wxTreeListItem 
*parent 
= i
->GetItemParent(); 
2316     if ( parent 
== NULL 
) 
2318         // root item doesn't have any siblings 
2319         return wxTreeItemId(); 
2322     wxArrayTreeListItems
& siblings 
= parent
->GetChildren(); 
2323     int index 
= siblings
.Index(i
); 
2324     wxASSERT( index 
!= wxNOT_FOUND 
); // I'm not a child of my parent? 
2326     size_t n 
= (size_t)(index 
+ 1); 
2327     return n 
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]); 
2330 wxTreeItemId 
wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId
& item
) 
2333     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2335     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
2336     wxTreeListItem 
*parent 
= i
->GetItemParent(); 
2337     if ( parent 
== NULL 
) 
2339         // root item doesn't have any siblings 
2340         return wxTreeItemId(); 
2343     wxArrayTreeListItems
& siblings 
= parent
->GetChildren(); 
2344     int index 
= siblings
.Index(i
); 
2345     wxASSERT( index 
!= wxNOT_FOUND 
); // I'm not a child of my parent? 
2347     return index 
== 0 ? wxTreeItemId() 
2348                       : wxTreeItemId(siblings
[(size_t)(index 
- 1)]); 
2351 // Only for internal use right now, but should probably be public 
2352 wxTreeItemId 
wxTreeListMainWindow::GetNext(const wxTreeItemId
& item
) const 
2354     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2356     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
2358     // First see if there are any children. 
2359     wxArrayTreeListItems
& children 
= i
->GetChildren(); 
2360     if (children
.GetCount() > 0) 
2362          return children
.Item(0); 
2366          // Try a sibling of this or ancestor instead 
2367          wxTreeItemId p 
= item
; 
2368          wxTreeItemId toFind
; 
2371               toFind 
= GetNextSibling(p
); 
2372               p 
= GetItemParent(p
); 
2373          } while (p
.IsOk() && !toFind
.IsOk()); 
2378 wxTreeItemId 
wxTreeListMainWindow::GetFirstVisibleItem() const 
2380     wxTreeItemId id 
= GetRootItem(); 
2389     } while (id
.IsOk()); 
2391     return wxTreeItemId(); 
2394 wxTreeItemId 
wxTreeListMainWindow::GetNextVisible(const wxTreeItemId
& item
) 
2397     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2399     wxTreeItemId id 
= item
; 
2402         while (id 
= GetNext(id
), id
.IsOk()) 
2408     return wxTreeItemId(); 
2411 wxTreeItemId 
wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId
& item
) 
2414     wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); 
2416     wxFAIL_MSG(wxT("not implemented")); 
2418     return wxTreeItemId(); 
2421 // ---------------------------------------------------------------------------- 
2423 // ---------------------------------------------------------------------------- 
2425 wxTreeItemId 
wxTreeListMainWindow::DoInsertItem(const wxTreeItemId
& parentId
, 
2427                                       const wxString
& text
, 
2428                                       int image
, int selImage
, 
2429                                       wxTreeItemData 
*data
) 
2431     wxTreeListItem 
*parent 
= (wxTreeListItem
*) parentId
.m_pItem
; 
2434         // should we give a warning here? 
2435         return AddRoot(text
, image
, selImage
, data
); 
2438     m_dirty 
= TRUE
;     // do this first so stuff below doesn't cause flicker 
2442     arr
.Alloc(GetColumnCount()); 
2443     for(size_t i 
= 0; i 
< GetColumnCount(); ++i
) { 
2444         arr
.Add(wxEmptyString
); 
2446     arr
[m_main_column
] = text
; 
2447     wxTreeListItem 
*item 
= 
2448         new wxTreeListItem( this, parent
, arr
, image
, selImage
, data 
); 
2452         data
->SetId((long)item
); 
2455     parent
->Insert( item
, previous 
); 
2460 wxTreeItemId 
wxTreeListMainWindow::AddRoot(const wxString
& text
, 
2461                                  int image
, int selImage
, 
2462                                  wxTreeItemData 
*data
) 
2464     wxCHECK_MSG(!m_anchor
, wxTreeItemId(), wxT("tree can have only one root")); 
2465     wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item")); 
2467     m_dirty 
= TRUE
;     // do this first so stuff below doesn't cause flicker 
2471     arr
.Alloc(GetColumnCount()); 
2472     for(size_t i 
= 0; i 
< GetColumnCount(); ++i
) { 
2473         arr
.Add(wxEmptyString
); 
2475     arr
[m_main_column
] = text
; 
2476     m_anchor 
= new wxTreeListItem( this, (wxTreeListItem 
*)NULL
, arr
, 
2477                                       image
, selImage
, data
); 
2479     if (HasFlag(wxTR_HIDE_ROOT
)) 
2481         // if root is hidden, make sure we can navigate 
2483         m_anchor
->SetHasPlus(); 
2489         data
->SetId((long)m_anchor
); 
2492     if (!HasFlag(wxTR_MULTIPLE
)) 
2494         m_current 
= m_key_current 
= m_anchor
; 
2495         m_current
->SetHilight( TRUE 
); 
2501 wxTreeItemId 
wxTreeListMainWindow::PrependItem(const wxTreeItemId
& parent
, 
2502                                      const wxString
& text
, 
2503                                      int image
, int selImage
, 
2504                                      wxTreeItemData 
*data
) 
2506     return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
); 
2509 wxTreeItemId 
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
, 
2510                                     const wxTreeItemId
& idPrevious
, 
2511                                     const wxString
& text
, 
2512                                     int image
, int selImage
, 
2513                                     wxTreeItemData 
*data
) 
2515     wxTreeListItem 
*parent 
= (wxTreeListItem
*) parentId
.m_pItem
; 
2518         // should we give a warning here? 
2519         return AddRoot(text
, image
, selImage
, data
); 
2522     int index 
= parent
->GetChildren().Index((wxTreeListItem
*) idPrevious
.m_pItem
); 
2523     wxASSERT_MSG( index 
!= wxNOT_FOUND
, 
2524                   wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") ); 
2526     return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
); 
2529 wxTreeItemId 
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
, 
2531                                     const wxString
& text
, 
2532                                     int image
, int selImage
, 
2533                                     wxTreeItemData 
*data
) 
2535     wxTreeListItem 
*parent 
= (wxTreeListItem
*) parentId
.m_pItem
; 
2538         // should we give a warning here? 
2539         return AddRoot(text
, image
, selImage
, data
); 
2542     return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
); 
2545 wxTreeItemId 
wxTreeListMainWindow::AppendItem(const wxTreeItemId
& parentId
, 
2546                                     const wxString
& text
, 
2547                                     int image
, int selImage
, 
2548                                     wxTreeItemData 
*data
) 
2550     wxTreeListItem 
*parent 
= (wxTreeListItem
*) parentId
.m_pItem
; 
2553         // should we give a warning here? 
2554         return AddRoot(text
, image
, selImage
, data
); 
2557     return DoInsertItem( parent
, parent
->GetChildren().Count(), text
, 
2558                          image
, selImage
, data
); 
2561 void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem 
*item
) 
2563     wxTreeEvent 
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, m_owner
->GetId() ); 
2564     event
.SetItem((long) item
); 
2565     event
.SetEventObject( /*this*/m_owner 
); 
2566     m_owner
->ProcessEvent( event 
); 
2569 void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId
& itemId
) 
2571     m_dirty 
= TRUE
;     // do this first so stuff below doesn't cause flicker 
2573     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2574     item
->DeleteChildren(this); 
2577 void wxTreeListMainWindow::Delete(const wxTreeItemId
& itemId
) 
2579     m_dirty 
= TRUE
;     // do this first so stuff below doesn't cause flicker 
2581     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2583     // don't stay with invalid m_key_current or we will crash in 
2584     // the next call to OnChar() 
2585     bool changeKeyCurrent 
= FALSE
; 
2586     wxTreeListItem 
*itemKey 
= m_key_current
; 
2589         if ( itemKey 
== item 
) 
2591             // m_key_current is a descendant of the item being deleted 
2592             changeKeyCurrent 
= TRUE
; 
2595         itemKey 
= itemKey
->GetItemParent(); 
2598     wxTreeListItem 
*parent 
= item
->GetItemParent(); 
2601         parent
->GetChildren().Remove( item 
);  // remove by value 
2604     if ( changeKeyCurrent 
) 
2606         // may be NULL or not 
2607         m_key_current 
= parent
; 
2610     item
->DeleteChildren(this); 
2611     SendDeleteEvent(item
); 
2615 void wxTreeListMainWindow::DeleteAllItems() 
2621         m_anchor
->DeleteChildren(this); 
2628 void wxTreeListMainWindow::Expand(const wxTreeItemId
& itemId
) 
2630     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2632     wxCHECK_RET( item
, _T("invalid item in wxTreeListMainWindow::Expand") ); 
2634     if ( !item
->HasPlus() ) 
2637     if ( item
->IsExpanded() ) 
2640     wxTreeEvent 
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, m_owner
->GetId() ); 
2641     event
.SetItem( (long) item 
); 
2642     event
.SetEventObject( /*this*/m_owner 
); 
2644     if ( m_owner
->ProcessEvent( event 
) && !event
.IsAllowed() ) 
2646         // cancelled by program 
2651     CalculatePositions(); 
2653     RefreshSubtree(item
); 
2655     event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
); 
2656     ProcessEvent( event 
); 
2659 void wxTreeListMainWindow::ExpandAll(const wxTreeItemId
& item
) 
2662     if ( IsExpanded(item
) ) 
2664 #if !wxCHECK_VERSION(2, 5, 0) 
2667         wxTreeItemIdValue cookie
; 
2669         wxTreeItemId child 
= GetFirstChild(item
, cookie
); 
2670         while ( child
.IsOk() ) 
2674             child 
= GetNextChild(item
, cookie
); 
2679 void wxTreeListMainWindow::Collapse(const wxTreeItemId
& itemId
) 
2681     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2683     if ( !item
->IsExpanded() ) 
2686     wxTreeEvent 
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, m_owner
->GetId() ); 
2687     event
.SetItem( (long) item 
); 
2688     event
.SetEventObject( /*this*/m_owner 
); 
2689     if ( m_owner
->ProcessEvent( event 
) && !event
.IsAllowed() ) 
2691         // cancelled by program 
2697 #if 0  // TODO why should items be collapsed recursively? 
2698     wxArrayTreeListItems
& children 
= item
->GetChildren(); 
2699     size_t count 
= children
.Count(); 
2700     for ( size_t n 
= 0; n 
< count
; n
++ ) 
2702         Collapse(children
[n
]); 
2706     CalculatePositions(); 
2708     RefreshSubtree(item
); 
2710     event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
); 
2711     ProcessEvent( event 
); 
2714 void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId
& item
) 
2717     DeleteChildren(item
); 
2720 void wxTreeListMainWindow::Toggle(const wxTreeItemId
& itemId
) 
2722     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2724     if (item
->IsExpanded()) 
2730 void wxTreeListMainWindow::Unselect() 
2734         m_current
->SetHilight( FALSE 
); 
2735         RefreshLine( m_current 
); 
2739 void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem 
*item
) 
2741     if (item
->IsSelected()) 
2743         item
->SetHilight(FALSE
); 
2747     if (item
->HasChildren()) 
2749         wxArrayTreeListItems
& children 
= item
->GetChildren(); 
2750         size_t count 
= children
.Count(); 
2751         for ( size_t n 
= 0; n 
< count
; ++n 
) 
2753             UnselectAllChildren(children
[n
]); 
2758 void wxTreeListMainWindow::UnselectAll() 
2760     UnselectAllChildren((wxTreeListItem
*)GetRootItem().m_pItem
); 
2763 // Recursive function ! 
2764 // To stop we must have crt_item<last_item 
2766 // Tag all next children, when no more children, 
2767 // Move to parent (not to tag) 
2768 // Keep going... if we found last_item, we stop. 
2769 bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem 
*crt_item
, wxTreeListItem 
*last_item
, bool select
) 
2771     wxTreeListItem 
*parent 
= crt_item
->GetItemParent(); 
2773     if (parent 
== NULL
) // This is root item 
2774         return TagAllChildrenUntilLast(crt_item
, last_item
, select
); 
2776     wxArrayTreeListItems
& children 
= parent
->GetChildren(); 
2777     int index 
= children
.Index(crt_item
); 
2778     wxASSERT( index 
!= wxNOT_FOUND 
); // I'm not a child of my parent? 
2780     size_t count 
= children
.Count(); 
2781     for (size_t n
=(size_t)(index
+1); n
<count
; ++n
) 
2783         if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
; 
2786     return TagNextChildren(parent
, last_item
, select
); 
2789 bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem 
*crt_item
, wxTreeListItem 
*last_item
, bool select
) 
2791     crt_item
->SetHilight(select
); 
2792     RefreshLine(crt_item
); 
2794     if (crt_item
==last_item
) 
2797     if (crt_item
->HasChildren()) 
2799         wxArrayTreeListItems
& children 
= crt_item
->GetChildren(); 
2800         size_t count 
= children
.Count(); 
2801         for ( size_t n 
= 0; n 
< count
; ++n 
) 
2803             if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) 
2811 void wxTreeListMainWindow::SelectItemRange(wxTreeListItem 
*item1
, wxTreeListItem 
*item2
) 
2813     // item2 is not necessary after item1 
2814     wxTreeListItem 
*first
=NULL
, *last
=NULL
; 
2816     // choice first' and 'last' between item1 and item2 
2817     if (item1
->GetY()<item2
->GetY()) 
2828     bool select 
= m_current
->IsSelected(); 
2830     if ( TagAllChildrenUntilLast(first
,last
,select
) ) 
2833     TagNextChildren(first
,last
,select
); 
2836 void wxTreeListMainWindow::SelectItem(const wxTreeItemId
& itemId
, 
2837                             bool unselect_others
, 
2838                             bool extended_select
) 
2840     wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") ); 
2842     bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
); 
2843     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
2845     //wxCHECK_RET( ( (!unselect_others) && is_single), 
2846     //           wxT("this is a single selection tree") ); 
2848     // to keep going anyhow !!! 
2851         if (item
->IsSelected()) 
2852             return; // nothing to do 
2853         unselect_others 
= TRUE
; 
2854         extended_select 
= FALSE
; 
2856     else if ( unselect_others 
&& item
->IsSelected() ) 
2858         // selection change if there is more than one item currently selected 
2859         wxArrayTreeItemIds selected_items
; 
2860         if ( GetSelections(selected_items
) == 1 ) 
2864     wxTreeEvent 
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() ); 
2865     event
.SetItem( (long) item 
); 
2866     event
.SetOldItem( (long) m_current 
); 
2867     event
.SetEventObject( /*this*/m_owner 
); 
2868     // TODO : Here we don't send any selection mode yet ! 
2870     if(m_owner
->GetEventHandler()->ProcessEvent( event 
) && !event
.IsAllowed()) 
2873     wxTreeItemId parent 
= GetItemParent( itemId 
); 
2874     while (parent
.IsOk()) 
2876         if (!IsExpanded(parent
)) 
2879         parent 
= GetItemParent( parent 
); 
2882     EnsureVisible( itemId 
); 
2885     if (unselect_others
) 
2887         if (is_single
) Unselect(); // to speed up thing 
2892     if (extended_select
) 
2896             m_current 
= m_key_current 
= (wxTreeListItem
*)GetRootItem().m_pItem
; 
2899         // don't change the mark (m_current) 
2900         SelectItemRange(m_current
, item
); 
2904         bool select
=TRUE
; // the default 
2906         // Check if we need to toggle hilight (ctrl mode) 
2907         if (!unselect_others
) 
2908             select
=!item
->IsSelected(); 
2910         m_current 
= m_key_current 
= item
; 
2911         m_current
->SetHilight(select
); 
2912         RefreshLine( m_current 
); 
2915     event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
); 
2916     GetEventHandler()->ProcessEvent( event 
); 
2919 void wxTreeListMainWindow::SelectAll(bool extended_select
) 
2921     wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE
, wxT("invalid tree style") ); 
2923     wxTreeEvent 
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() ); 
2924     event
.SetItem( GetRootItem() ); 
2925     event
.SetOldItem( (long) m_current 
); 
2926     event
.SetEventObject( /*this*/m_owner 
); 
2927     // TODO : Here we don't send any selection mode yet ! 
2929     if(m_owner
->GetEventHandler()->ProcessEvent( event 
) && !event
.IsAllowed()) 
2933     if (!extended_select
) 
2941 #if !wxCHECK_VERSION(2, 5, 0) 
2944     wxTreeItemIdValue cookie 
= 0; 
2946     wxTreeItemId root 
= GetRootItem(); 
2947     wxTreeListItem 
*first 
= (wxTreeListItem 
*)GetFirstChild (root
, cookie
).m_pItem
; 
2948     wxTreeListItem 
*last 
= (wxTreeListItem 
*)GetLastChild (GetRootItem()).m_pItem
; 
2949     if (TagAllChildrenUntilLast (first
, last
, true)) return; 
2950     TagNextChildren (first
, last
, true); 
2952     event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
); 
2953     GetEventHandler()->ProcessEvent( event 
); 
2956 void wxTreeListMainWindow::FillArray(wxTreeListItem 
*item
, 
2957                            wxArrayTreeItemIds 
&array
) const 
2959     if ( item
->IsSelected() ) 
2960         array
.Add(wxTreeItemId(item
)); 
2962     if ( item
->HasChildren() ) 
2964         wxArrayTreeListItems
& children 
= item
->GetChildren(); 
2965         size_t count 
= children
.GetCount(); 
2966         for ( size_t n 
= 0; n 
< count
; ++n 
) 
2967             FillArray(children
[n
], array
); 
2971 size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds 
&array
) const 
2974     wxTreeItemId idRoot 
= GetRootItem(); 
2975     if ( idRoot
.IsOk() ) 
2977         FillArray((wxTreeListItem
*) idRoot
.m_pItem
, array
); 
2979     //else: the tree is empty, so no selections 
2981     return array
.Count(); 
2984 void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId
& item
) 
2986     if (!item
.IsOk()) return; 
2988     wxTreeListItem 
*gitem 
= (wxTreeListItem
*) item
.m_pItem
; 
2990     // first expand all parent branches 
2991     wxTreeListItem 
*parent 
= gitem
->GetItemParent(); 
2995         parent 
= parent
->GetItemParent(); 
2998     //if (parent) CalculatePositions(); 
3003 void wxTreeListMainWindow::ScrollTo(const wxTreeItemId 
&item
) 
3005     if (!item
.IsOk()) return; 
3007     // We have to call this here because the label in 
3008     // question might just have been added and no screen 
3009     // update taken place. 
3010     if (m_dirty
) wxYieldIfNeeded(); 
3012     wxTreeListItem 
*gitem 
= (wxTreeListItem
*) item
.m_pItem
; 
3014     // now scroll to the item 
3015     int item_y 
= gitem
->GetY(); 
3019     GetViewStart( &start_x
, &start_y 
); 
3020     start_y 
*= PIXELS_PER_UNIT
; 
3024     GetClientSize( &client_w
, &client_h 
); 
3026     if (item_y 
< start_y
+3) 
3031         m_anchor
->GetSize( x
, y
, this ); 
3032         x 
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB 
3033         y 
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels 
3034         //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels 
3035         int x_pos 
= GetScrollPos( wxHORIZONTAL 
); 
3036         // Item should appear at top 
3037         SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT 
); 
3039     else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
) 
3044         m_anchor
->GetSize( x
, y
, this ); 
3045         y 
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels 
3046         //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels 
3047         x 
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB 
3048         item_y 
+= PIXELS_PER_UNIT
+2; 
3049         int x_pos 
= GetScrollPos( wxHORIZONTAL 
); 
3050         // Item should appear at bottom 
3051         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 
); 
3055 // FIXME: tree sorting functions are not reentrant and not MT-safe! 
3056 static wxTreeListMainWindow 
*s_treeBeingSorted 
= NULL
; 
3058 static int LINKAGEMODE 
tree_ctrl_compare_func(wxTreeListItem 
**item1
, 
3059                                   wxTreeListItem 
**item2
) 
3061     wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") ); 
3063     return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
); 
3066 int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId
& item1
, 
3067                                const wxTreeItemId
& item2
) 
3069     // ALB: delegate to m_owner, to let the user overrride the comparison 
3070     //return wxStrcmp(GetItemText(item1), GetItemText(item2)); 
3071     return m_owner
->OnCompareItems(item1
, item2
); 
3074 void wxTreeListMainWindow::SortChildren(const wxTreeItemId
& itemId
) 
3076     wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") ); 
3078     wxTreeListItem 
*item 
= (wxTreeListItem
*) itemId
.m_pItem
; 
3080     wxCHECK_RET( !s_treeBeingSorted
, 
3081                  wxT("wxTreeListMainWindow::SortChildren is not reentrant") ); 
3083     wxArrayTreeListItems
& children 
= item
->GetChildren(); 
3084     if ( children
.Count() > 1 ) 
3088         s_treeBeingSorted 
= this; 
3089         children
.Sort(tree_ctrl_compare_func
); 
3090         s_treeBeingSorted 
= NULL
; 
3092     //else: don't make the tree dirty as nothing changed 
3095 wxTreeItemId 
wxTreeListMainWindow::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
) { 
3096 #if !wxCHECK_VERSION(2, 5, 0) 
3099     wxTreeItemIdValue cookie 
= 0; 
3101     wxTreeItemId next 
= item
; 
3102     if (!next
.IsOk()) next 
= GetSelection(); 
3104         if (HasFlag(wxTR_HIDE_ROOT
)) { 
3105             next 
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
; 
3107             next 
= (wxTreeListItem
*)GetRootItem().m_pItem
; 
3110     if (!next
.IsOk()) return item
; 
3112     // start checking the next items 
3114     while (next
.IsOk()) { 
3115         itemText 
= GetItemText (next
); 
3116         if (flags 
& wxTL_SEARCH_LEVEL
) { 
3117             next 
= GetNextSibling (next
); 
3118         }else if (flags 
& wxTL_SEARCH_FULL
) { 
3119             wxTreeItemId n 
= GetFirstChild (next
, cookie
); 
3121                 n 
= GetNextSibling (next
); 
3123                 n 
= GetNextSibling (GetItemParent (next
)); 
3125         }else{ // wxTL_SEARCH_VISIBLE 
3126             next 
= GetNextVisible (next
); 
3128         if (!next
.IsOk()) break; // done 
3129         if (flags 
& wxTL_SEARCH_PARTIAL
) { 
3130             itemText 
= GetItemText (next
).Mid (0, str
.Length()); 
3132             itemText 
= GetItemText (next
); 
3134         if (flags 
& wxTL_SEARCH_NOCASE
) { 
3135             if (itemText
.CmpNoCase (str
) == 0) return next
; 
3137             if (itemText
.Cmp (str
) == 0) return next
; 
3143 wxImageList 
*wxTreeListMainWindow::GetImageList() const 
3145     return m_imageListNormal
; 
3148 wxImageList 
*wxTreeListMainWindow::GetButtonsImageList() const 
3150     return m_imageListButtons
; 
3153 wxImageList 
*wxTreeListMainWindow::GetStateImageList() const 
3155     return m_imageListState
; 
3158 void wxTreeListMainWindow::CalculateLineHeight() 
3160     wxClientDC 
dc(this); 
3161     dc
.SetFont( m_normalFont 
); 
3162     m_lineHeight 
= (int)(dc
.GetCharHeight() + m_linespacing
); 
3164     if ( m_imageListNormal 
) 
3166         // Calculate a m_lineHeight value from the normal Image sizes. 
3167         // May be toggle off. Then wxTreeListMainWindow will spread when 
3168         // necessary (which might look ugly). 
3169         int n 
= m_imageListNormal
->GetImageCount(); 
3170         for (int i 
= 0; i 
< n 
; i
++) 
3172             int width 
= 0, height 
= 0; 
3173             m_imageListNormal
->GetSize(i
, width
, height
); 
3174             if (height 
> m_lineHeight
) m_lineHeight 
= height 
+ m_linespacing
; 
3178     if (m_imageListButtons
) 
3180         // Calculate a m_lineHeight value from the Button image sizes. 
3181         // May be toggle off. Then wxTreeListMainWindow will spread when 
3182         // necessary (which might look ugly). 
3183         int n 
= m_imageListButtons
->GetImageCount(); 
3184         for (int i 
= 0; i 
< n 
; i
++) 
3186             int width 
= 0, height 
= 0; 
3187             m_imageListButtons
->GetSize(i
, width
, height
); 
3188             if (height 
> m_lineHeight
) m_lineHeight 
= height 
+ m_linespacing
; 
3192 /*? FIXME: Don't get what this code is for... Adding a line space is already done!!! 
3193     if (m_lineHeight < 30) 
3194         m_lineHeight += 2;                 // at least 2 pixels 
3196         m_lineHeight += m_lineHeight/10;   // otherwise 10% extra spacing 
3200 void wxTreeListMainWindow::SetImageList(wxImageList 
*imageList
) 
3202     if (m_ownsImageListNormal
) delete m_imageListNormal
; 
3203     m_imageListNormal 
= imageList
; 
3204     m_ownsImageListNormal 
= FALSE
; 
3206     CalculateLineHeight(); 
3209 void wxTreeListMainWindow::SetStateImageList(wxImageList 
*imageList
) 
3211     if (m_ownsImageListState
) delete m_imageListState
; 
3212     m_imageListState 
= imageList
; 
3213     m_ownsImageListState 
= FALSE
; 
3216 void wxTreeListMainWindow::SetButtonsImageList(wxImageList 
*imageList
) 
3218     if (m_ownsImageListButtons
) delete m_imageListButtons
; 
3219     m_imageListButtons 
= imageList
; 
3220     m_ownsImageListButtons 
= FALSE
; 
3222     CalculateLineHeight(); 
3225 void wxTreeListMainWindow::AssignImageList(wxImageList 
*imageList
) 
3227     SetImageList(imageList
); 
3228     m_ownsImageListNormal 
= TRUE
; 
3231 void wxTreeListMainWindow::AssignStateImageList(wxImageList 
*imageList
) 
3233     SetStateImageList(imageList
); 
3234     m_ownsImageListState 
= TRUE
; 
3237 void wxTreeListMainWindow::AssignButtonsImageList(wxImageList 
*imageList
) 
3239     SetButtonsImageList(imageList
); 
3240     m_ownsImageListButtons 
= TRUE
; 
3243 // ---------------------------------------------------------------------------- 
3245 // ---------------------------------------------------------------------------- 
3247 void wxTreeListMainWindow::AdjustMyScrollbars() 
3252         m_anchor
->GetSize( x
, y
, this ); 
3253         y 
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels 
3254         //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels 
3255         int x_pos 
= GetScrollPos( wxHORIZONTAL 
); 
3256         int y_pos 
= GetScrollPos( wxVERTICAL 
); 
3257         x 
= m_owner
->GetHeaderWindow()->GetWidth() + 2; 
3258         if(x 
< GetClientSize().GetWidth()) x_pos 
= 0; 
3259         //m_total_col_width + 2; // ALB 
3260         SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, 
3261                        y
/PIXELS_PER_UNIT
, x_pos
, y_pos 
); 
3265         SetScrollbars( 0, 0, 0, 0 ); 
3269 int wxTreeListMainWindow::GetLineHeight(wxTreeListItem 
*item
) const 
3271     if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
) 
3272         return item
->GetHeight(); 
3274         return m_lineHeight
; 
3277 void wxTreeListMainWindow::PaintItem(wxTreeListItem 
*item
, wxDC
& dc
) 
3279     wxTreeItemAttr 
*attr 
= item
->GetAttributes(); 
3280     if (attr 
&& attr
->HasFont()) { 
3281         dc
.SetFont(attr
->GetFont()); 
3282     }else if (item
->IsBold()) { 
3283         dc
.SetFont(m_boldFont
); 
3286     if (attr 
&& attr
->HasTextColour()) { 
3287         colText 
= attr
->GetTextColour(); 
3289         colText 
= GetForegroundColour(); 
3292     dc
.SetPen(*wxTRANSPARENT_PEN
); 
3294     long text_w 
= 0, text_h 
= 0; 
3296     dc
.GetTextExtent( item
->GetText(GetMainColumn()), &text_w
, &text_h 
); 
3298     int total_h 
= GetLineHeight(item
); 
3300     if (item
->IsSelected() && HasFlag(wxTR_FULL_ROW_HIGHLIGHT
)) { 
3301             dc
.SetBrush(*(m_hasFocus 
? m_hilightBrush 
: m_hilightUnfocusedBrush
)); 
3302             dc
.SetPen(*wxBLACK_PEN
); 
3303             colText 
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
); 
3306         if (attr 
&& attr
->HasBackgroundColour()) { 
3307             colBg 
= attr
->GetBackgroundColour(); 
3309             colBg 
= GetBackgroundColour(); 
3311         dc
.SetBrush(wxBrush(colBg
, wxSOLID
)); 
3314     int offset 
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0; 
3315     dc
.DrawRectangle(0, item
->GetY() + offset
, 
3316                      m_owner
->GetHeaderWindow()->GetWidth(), total_h
-offset
); 
3318     dc
.SetBackgroundMode(wxTRANSPARENT
); 
3319     int text_extraH 
= (total_h 
> text_h
) ? (total_h 
- text_h
)/2 : 0; 
3320     int img_extraH 
= (total_h 
> m_imgHeight
)? (total_h
-m_imgHeight
)/2: 0; 
3322     for ( size_t i 
= 0; i 
< GetColumnCount(); ++i 
) { 
3323         if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue; 
3324         int colwidth 
= m_owner
->GetHeaderWindow()->GetColumnWidth(i
); 
3328         if (i 
== GetMainColumn()) { 
3329             image 
= item
->GetCurrentImage(); 
3330             if (item
->HasPlus()) { 
3331                  image_x 
= item
->GetX() + (m_btnWidth
-m_btnWidth2
) + LINEATROOT
; 
3333                  image_x 
= item
->GetX() - m_imgWidth2
; 
3338             image 
= item
->GetImage(i
); 
3339             image_x 
= x_colstart 
+ MARGIN
; 
3341         if (image 
!= NO_IMAGE
) image_w 
= m_imgWidth 
+ MARGIN
; 
3343         // honor text alignment 
3344         wxString text 
= item
->GetText(i
); 
3345         switch ( m_owner
->GetHeaderWindow()->GetColumn(i
).GetAlignment() ) { 
3346         case wxTL_ALIGN_LEFT
: 
3347             // already left aligned 
3349         case wxTL_ALIGN_RIGHT
: 
3350             dc
.GetTextExtent(text
, &text_w
, NULL
); 
3351             image_x 
= x_colstart 
+ colwidth 
- (image_w 
+ text_w 
+ MARGIN
); 
3353         case wxTL_ALIGN_CENTER
: 
3354             dc
.GetTextExtent(text
, &text_w
, NULL
); 
3355             int w 
= colwidth 
- image_w 
- text_w
; 
3356             image_x 
= x_colstart 
+ (w 
> 0)? w
: 0; 
3359         int text_x 
= image_x 
+ image_w
; 
3361         if (item
->IsSelected() && (i
==GetMainColumn()) && !HasFlag(wxTR_FULL_ROW_HIGHLIGHT
)) 
3363             dc
.SetPen(*wxBLACK_PEN
); 
3364             dc
.SetBrush(*(m_hasFocus 
? m_hilightBrush 
: m_hilightUnfocusedBrush
)); 
3365             int offset 
= HasFlag (wxTR_ROW_LINES
) ? 1 : 0; 
3366             int width 
= wxMin(text_w
+2, colwidth 
- text_x 
- x_colstart
); 
3367             dc
.DrawRectangle(text_x
-1, item
->GetY() + offset
, width
, total_h
-offset
); 
3368             dc
.SetBackgroundMode(wxTRANSPARENT
); 
3369             dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
)); 
3371             dc
.SetTextForeground(colText
); 
3374         wxDCClipper 
clipper (dc
, x_colstart
, item
->GetY(), colwidth
, total_h
); 
3375         if (image 
!= NO_IMAGE
) 
3377             int image_y 
= item
->GetY() + img_extraH
; 
3378             m_imageListNormal
->Draw ( image
, dc
, image_x
, image_y
, 
3379                                       wxIMAGELIST_DRAW_TRANSPARENT 
); 
3381         int text_y 
= item
->GetY() + text_extraH
; 
3382         dc
.DrawText ( text
, (wxCoord
)text_x
, (wxCoord
)text_y 
); 
3384         x_colstart 
+= colwidth
; 
3387     // restore normal font 
3388     dc
.SetFont( m_normalFont 
); 
3391 // Now y stands for the top of the item, whereas it used to stand for middle ! 
3392 void wxTreeListMainWindow::PaintLevel (wxTreeListItem 
*item
, wxDC 
&dc
, 
3393                                        int level
, int &y
, int x_colstart 
) 
3395     // Handle hide root (only level 0) 
3396     if (HasFlag(wxTR_HIDE_ROOT
) && (level 
== 0)) { 
3397         // always expand hidden root 
3398         wxArrayTreeListItems
& children 
= item
->GetChildren(); 
3400         for (n 
= 0; n 
< (int)children
.Count(); n
++) { 
3401             PaintLevel (children
[n
], dc
, 1, y
, x_colstart
); 
3403         // end after expanding root 
3407     // calculate position of vertical lines 
3408     int x 
= x_colstart 
+ MARGIN
; // start of column 
3409     if (HasFlag (wxTR_LINES_AT_ROOT
)) x 
+= LINEATROOT
; // space for lines at root 
3411         x 
+= m_btnWidth2
; // middle of button 
3413         if (m_imgWidth 
> 0) x 
+= m_imgWidth2
; // middle of image 
3415     if (!HasFlag (wxTR_HIDE_ROOT
)) { 
3416         x 
+= m_indent 
* level
; // indent according to level 
3418         if (level 
> 0) x 
+= m_indent 
* (level
-1); // but not level 1 
3421     // handle column text 
3425     int h 
= GetLineHeight(item
); 
3427     int y_mid 
= y_top 
+ (h
/2); 
3430     int exposed_x 
= dc
.LogicalToDeviceX(0); 
3431     int exposed_y 
= dc
.LogicalToDeviceY(y_top
); 
3433     if (IsExposed(exposed_x
, exposed_y
, 10000, h
))  // 10000 = very much 
3436         PaintItem(item
, dc
); 
3438         if (HasFlag(wxTR_ROW_LINES
)) 
3440             //dc.DestroyClippingRegion(); 
3441             int total_width 
= m_owner
->GetHeaderWindow()->GetWidth(); 
3442             // if the background colour is white, choose a 
3443             // contrasting color for the lines 
3444             dc
.SetPen (*((GetBackgroundColour() == *wxWHITE
)? 
3445                         wxMEDIUM_GREY_PEN 
: wxWHITE_PEN
)); 
3446             dc
.DrawLine(0, y_top
, total_width
, y_top
); 
3447             dc
.DrawLine(0, y
, total_width
, y
); 
3450         // restore DC objects 
3451         dc
.SetBrush(*wxWHITE_BRUSH
); 
3452         dc
.SetPen(m_dottedPen
); 
3454         if (((level 
== 0) || ((level 
== 1) && HasFlag(wxTR_HIDE_ROOT
))) && 
3455             HasFlag(wxTR_LINES_AT_ROOT
) && !HasFlag(wxTR_NO_LINES
)) { 
3456             int rootPos 
= x_colstart 
+ MARGIN
; 
3457             dc
.DrawLine (rootPos
, y_mid
, rootPos
+LINEATROOT
, y_mid
); 
3460         size_t clip_width 
= m_owner
->GetHeaderWindow()-> 
3461                             GetColumn(m_main_column
).GetWidth(); 
3463         if (item
->HasPlus() && HasButtons())  // should the item show a button? 
3465             // clip to the column width 
3466             wxDCClipper 
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000); 
3468             if ( !HasFlag(wxTR_NO_LINES
) ) 
3470                 // draw the horizontal line here 
3472                 if (x 
> (signed)m_indent
) 
3473                     x_start 
-= m_indent
; 
3474                 else if (HasFlag(wxTR_LINES_AT_ROOT
)) 
3476                 dc
.DrawLine(x_start
, y_mid
, x 
/*+ m_spacing*/, y_mid
); 
3479             if (m_imageListButtons 
!= NULL
) 
3481                 // draw the image button here 
3482                 int image 
= wxTreeItemIcon_Normal
; 
3483                 if (item
->IsExpanded()) image 
= wxTreeItemIcon_Expanded
; 
3484                 if (item
->IsSelected()) 
3485                     image 
+= wxTreeItemIcon_Selected 
- wxTreeItemIcon_Normal
; 
3486                 int xx 
= x 
+ m_btnWidth2
; 
3487                 int yy 
= y_mid 
- m_btnHeight2
; 
3488                 dc
.SetClippingRegion(xx
, yy
, m_btnWidth
, m_btnHeight
); 
3489                 m_imageListButtons
->Draw(image
, dc
, xx
, yy
, 
3490                                          wxIMAGELIST_DRAW_TRANSPARENT
); 
3491                 dc
.DestroyClippingRegion(); 
3493             else // no custom buttons 
3495                 static const int wImage 
= 9; 
3496                 static const int hImage 
= 9; 
3499                 if (item
->IsExpanded()) 
3500                     flag 
|= wxCONTROL_EXPANDED
; 
3501                 if (item 
== m_underMouse
) 
3502                     flag 
|= wxCONTROL_CURRENT
; 
3504                 wxRendererNative::Get().DrawTreeItemButton( 
3506                     wxRect(x 
- wImage
/2, y_mid 
- hImage
/2, wImage
, hImage
), 
3510             if (!HasFlag(wxTR_NO_LINES
)) { 
3511                 if (/*!(level == 0) &&*/ !((level 
== 1) && HasFlag(wxTR_HIDE_ROOT
))) { 
3512                     if (m_imgWidth 
> 0) { 
3513                         dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_indent
-m_imgWidth2
, y_mid
); 
3515                         dc
.DrawLine(x
+m_btnWidth2
, y_mid
, x
+m_btnWidth2
+LINEATROOT
-MARGIN
, y_mid
); 
3520         else if (!HasFlag(wxTR_NO_LINES
))  // no button; maybe a line? 
3522             // clip to the column width 
3523             wxDCClipper 
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000); 
3525             // draw the horizontal line here 
3526             if (/*!(level == 0) &&*/ !((level 
== 1) && HasFlag(wxTR_HIDE_ROOT
))) { 
3527                 int x2 
= x 
- m_indent
; 
3528                 if (m_imgWidth 
> 0) { 
3529                     dc
.DrawLine(x2
, y_mid
, x2
+m_indent
-m_imgWidth2
, y_mid
); 
3531                     dc
.DrawLine(x2
, y_mid
, x2
+m_btnWidth2
+LINEATROOT
+MARGIN
, y_mid
); 
3537     // restore DC objects 
3538     dc
.SetBrush(*wxWHITE_BRUSH
); 
3539     dc
.SetPen(m_dottedPen
); 
3540     dc
.SetTextForeground(*wxBLACK
); 
3542     if (item
->IsExpanded()) 
3544         wxArrayTreeListItems
& children 
= item
->GetChildren(); 
3545         int count 
= children
.Count(); 
3548         // paint sublevel items first 
3549         for (n
=0; n
<count
; ++n
) { 
3551             PaintLevel(children
[n
], dc
, level
+1, y
, x_colstart
); 
3554         // then draw the connecting lines 
3555         if (!HasFlag(wxTR_NO_LINES
) && count 
> 0) 
3557             // clip to the column width 
3558             size_t clip_width 
= m_owner
->GetHeaderWindow()->GetColumn(m_main_column
).GetWidth(); 
3559             wxDCClipper 
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000); 
3561             // draw line down to last child 
3562             oldY 
+= GetLineHeight(children
[n
-1]) >> 1; 
3563             if (HasButtons()) y_mid 
+= 5; 
3564             dc
.DrawLine(x
, y_mid
, x
, oldY
); 
3569 void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem 
*item
) 
3573         if ( item
->HasPlus() ) 
3575             // it's a folder, indicate it by a border 
3580             // draw a line under the drop target because the item will be 
3582             DrawLine(item
, TRUE 
/* below */); 
3585         SetCursor(wxCURSOR_BULLSEYE
); 
3590         SetCursor(wxCURSOR_NO_ENTRY
); 
3594 void wxTreeListMainWindow::DrawBorder(const wxTreeItemId 
&item
) 
3596     wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") ); 
3598     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
3600     wxClientDC 
dc(this); 
3602     dc
.SetLogicalFunction(wxINVERT
); 
3603     dc
.SetBrush(*wxTRANSPARENT_BRUSH
); 
3605     int w 
= i
->GetWidth() + 2; 
3606     int h 
= GetLineHeight(i
) + 2; 
3608     dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
); 
3611 void wxTreeListMainWindow::DrawLine(const wxTreeItemId 
&item
, bool below
) 
3613     wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") ); 
3615     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
3617     wxClientDC 
dc(this); 
3619     dc
.SetLogicalFunction(wxINVERT
); 
3625         y 
+= GetLineHeight(i
) - 1; 
3628     dc
.DrawLine( x
, y
, x 
+ i
->GetWidth(), y
); 
3631 // ---------------------------------------------------------------------------- 
3632 // wxWindows callbacks 
3633 // ---------------------------------------------------------------------------- 
3635 void wxTreeListMainWindow::OnPaint( wxPaintEvent 
&WXUNUSED(event
) ) 
3641     if(!GetColumnCount()) return; // ALB 
3646     // calculate button size 
3647     m_btnWidth 
= 0, m_btnWidth2 
= 0; 
3648     m_btnHeight 
= 0, m_btnHeight2 
= 0; 
3649     if (m_imageListButtons
) { 
3650         m_imageListButtons
->GetSize (0, m_btnWidth
, m_btnHeight
); 
3651     }else if (HasButtons()) { 
3652         m_btnWidth 
= BTNWIDTH
; 
3653         m_btnHeight 
= BTNHEIGHT
; 
3655     m_btnWidth2 
= m_btnWidth
/2; 
3656     m_btnHeight2 
= m_btnHeight
/2; 
3658     // calculate image size 
3659     m_imgWidth 
= 0, m_imgWidth2 
= 0; 
3660     m_imgHeight 
= 0, m_imgHeight2 
= 0; 
3661     if (m_imageListNormal
) { 
3662         m_imageListNormal
->GetSize (0, m_imgWidth
, m_imgHeight
); 
3663         m_imgWidth 
+= 4; //? ToDo: Why + 4? 
3665     m_imgWidth2 
= m_imgWidth
/2; 
3666     m_imgHeight2 
= m_imgHeight
/2; 
3668     // calculate indent size 
3669     int btnIndent 
= HasButtons()? m_btnWidth 
+ LINEATROOT
: 0; 
3670     m_indent 
= wxMax (MININDENT
, wxMax (m_imgWidth
, btnIndent
)) + MARGIN
; 
3672     // set default values 
3673     dc
.SetFont( m_normalFont 
); 
3674     dc
.SetPen( m_dottedPen 
); 
3676     // this is now done dynamically 
3677     //if(GetImageList() == NULL) 
3678     // m_lineHeight = (int)(dc.GetCharHeight() + 4); 
3680     // calculate column start and paint 
3683     for (i 
= 0; i 
< (int)GetMainColumn(); ++i
) { 
3684         if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue; 
3685         x_colstart 
+= m_owner
->GetHeaderWindow()->GetColumnWidth (i
); 
3688     PaintLevel ( m_anchor
, dc
, 0, y
, x_colstart 
); 
3691 void wxTreeListMainWindow::OnSetFocus( wxFocusEvent 
&event 
) 
3700 void wxTreeListMainWindow::OnKillFocus( wxFocusEvent 
&event 
) 
3709 void wxTreeListMainWindow::OnChar( wxKeyEvent 
&event 
) 
3711     wxTreeEvent 
te( wxEVT_COMMAND_TREE_KEY_DOWN
, m_owner
->GetId() ); 
3712     te
.SetKeyEvent( event 
); 
3713     te
.SetEventObject( /*this*/m_owner 
); 
3714     if ( m_owner
->GetEventHandler()->ProcessEvent( te 
) ) 
3716         // intercepted by the user code 
3722         if (HasFlag(wxTR_HIDE_ROOT
)) { 
3723 #if !wxCHECK_VERSION(2, 5, 0) 
3726             wxTreeItemIdValue cookie 
= 0; 
3728             m_current 
= m_key_current 
= (wxTreeListItem
*)GetFirstChild (GetRootItem().m_pItem
, cookie
).m_pItem
; 
3732             m_current 
= m_key_current 
= (wxTreeListItem
*)GetRootItem().m_pItem
; 
3736     // how should the selection work for this event? 
3737     bool is_multiple
, extended_select
, unselect_others
; 
3738     EventFlagsToSelType(GetWindowStyleFlag(), 
3740                         event
.ControlDown(), 
3741                         is_multiple
, extended_select
, unselect_others
); 
3743     // + : Expand (not on Win32) 
3744     // - : Collaspe (not on Win32) 
3745     // * : Expand all/Collapse all 
3746     // ' ' | return : activate 
3747     // up    : go up (not last children!) 
3749     // left  : go to parent (or collapse on Win32) 
3750     // right : open if parent and go next (or expand on Win32) 
3751     // home  : go to root 
3752     // end   : go to last item without opening parents 
3753     switch (event
.GetKeyCode()) 
3755 #ifndef __WXMSW__ // mimic the standard win32 tree ctrl 
3758             if (m_current
->HasPlus() && !IsExpanded(m_current
)) 
3767             if ( !IsExpanded(m_current
) ) 
3770                 ExpandAll (m_current
); 
3773             //else: fall through to Collapse() it 
3775 #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour 
3778             if (IsExpanded(m_current
)) 
3780                 Collapse (m_current
); 
3788                 wxTreeEvent 
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, 
3790                 event
.SetItem( (long) m_current
); 
3791                 event
.SetEventObject( /*this*/m_owner 
); 
3792                 m_owner
->GetEventHandler()->ProcessEvent( event 
); 
3796         // backspace goes to the parent, sends "root" activation 
3799                 wxTreeItemId prev 
= GetItemParent( m_current 
); 
3800                 if ((prev 
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
)) 
3802                     // don't go to root if it is hidden 
3803                     prev 
= GetPrevSibling( m_current 
); 
3807                     SelectItem( prev
, unselect_others
, extended_select 
); 
3808                     EnsureVisible( prev 
); 
3813         // up goes to the previous sibling or to the last 
3814         // of its children if it's expanded 
3817                 wxTreeItemId prev 
= GetPrevSibling( m_key_current 
); 
3820                     prev 
= GetItemParent( m_key_current 
); 
3821                     if ((prev 
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
)) 
3823                         break;  // don't go to root if it is hidden 
3827 #if !wxCHECK_VERSION(2, 5, 0) 
3830                         wxTreeItemIdValue cookie 
= 0; 
3832                         wxTreeItemId current 
= m_key_current
; 
3833                         // TODO: Huh?  If we get here, we'd better be the first child of our parent.  How else could it be? 
3834                         if (current 
== GetFirstChild( prev
, cookie 
)) 
3836                             // otherwise we return to where we came from 
3837                             SelectItem( prev
, unselect_others
, extended_select 
); 
3838                             m_key_current
= (wxTreeListItem
*) prev
.m_pItem
; 
3839                             EnsureVisible( prev 
); 
3846                     while ( IsExpanded(prev
) && HasChildren(prev
) ) 
3848                         wxTreeItemId child 
= GetLastChild(prev
); 
3856                     SelectItem( prev
, unselect_others
, extended_select 
); 
3857                     m_key_current
=(wxTreeListItem
*) prev
.m_pItem
; 
3858                     EnsureVisible( prev 
); 
3863         // left arrow goes to the parent 
3865             if (IsExpanded(m_current
)) 
3867                 Collapse(m_current
); 
3871                 wxTreeItemId prev 
= GetItemParent( m_current 
); 
3872                 if ((prev 
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
)) 
3874                     // don't go to root if it is hidden 
3875                     prev 
= GetPrevSibling( m_current 
); 
3879                     SelectItem( prev
, unselect_others
, extended_select 
); 
3880                     EnsureVisible( prev 
); 
3886 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl 
3887             if (m_current
->HasPlus() && !IsExpanded(m_current
)) 
3894             // this works the same as the down arrow except that we 
3895             // also expand the item if it wasn't expanded yet 
3901                 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
)) 
3903 #if !wxCHECK_VERSION(2, 5, 0) 
3906                     wxTreeItemIdValue cookie 
= 0; 
3908                     wxTreeItemId child 
= GetFirstChild( m_key_current
, cookie 
); 
3910                         SelectItem( child
, unselect_others
, extended_select 
); 
3911                         m_key_current
=(wxTreeListItem
*) child
.m_pItem
; 
3912                         EnsureVisible( child 
); 
3916                 wxTreeItemId next 
= GetNextSibling( m_key_current 
); 
3919                     wxTreeItemId current 
= m_key_current
; 
3920                     while (current 
&& !next
) 
3922                         current 
= GetItemParent( current 
); 
3923                         if (current
) next 
= GetNextSibling( current 
); 
3928                     SelectItem( next
, unselect_others
, extended_select 
); 
3929                     m_key_current
=(wxTreeListItem
*) next
.m_pItem
; 
3930                     EnsureVisible( next 
); 
3935         // <End> selects the last visible tree item 
3938                 wxTreeItemId last 
= GetRootItem(); 
3940                 while ( last
.IsOk() && IsExpanded(last
) ) 
3942                     wxTreeItemId lastChild 
= GetLastChild(last
); 
3944                     // it may happen if the item was expanded but then all of 
3945                     // its children have been deleted - so IsExpanded() returned 
3946                     // TRUE, but GetLastChild() returned invalid item 
3955                     SelectItem( last
, unselect_others
, extended_select 
); 
3956                     EnsureVisible( last 
); 
3961         // <Home> selects the root item 
3964                 wxTreeItemId prev 
= GetRootItem(); 
3966                 if (HasFlag(wxTR_HIDE_ROOT
)) 
3968 #if !wxCHECK_VERSION(2, 5, 0) 
3971                     wxTreeItemIdValue cookie 
= 0; 
3973                     prev 
= GetFirstChild(prev
, cookie
); 
3976                 SelectItem( prev
, unselect_others
, extended_select 
); 
3977                 EnsureVisible( prev 
); 
3982             if (event
.m_keyCode 
>= (int)' ') { 
3983                 if (!m_findTimer
->IsRunning()) m_findStr
.Clear(); 
3984                 m_findStr
.Append (event
.m_keyCode
); 
3985                 m_findTimer
->Start (500, wxTIMER_ONE_SHOT
); 
3986                 wxTreeItemId dummy 
= (wxTreeItemId
*)NULL
; 
3987                 wxTreeItemId item 
= FindItem (dummy
, m_findStr
, wxTL_SEARCH_VISIBLE 
| 
3988                                                                 wxTL_SEARCH_PARTIAL 
| 
3989                                                                 wxTL_SEARCH_NOCASE
); 
3991                     EnsureVisible (item
); 
3999 wxTreeItemId 
wxTreeListMainWindow::HitTest(const wxPoint
& point
, int& flags
, 
4002     // JACS: removed wxYieldIfNeeded() because it can cause the window 
4003     // to be deleted from under us if a close window event is pending 
4009     if (point
.x
<0) flags 
|= wxTREE_HITTEST_TOLEFT
; 
4010     if (point
.x
>w
) flags 
|= wxTREE_HITTEST_TORIGHT
; 
4011     if (point
.y
<0) flags 
|= wxTREE_HITTEST_ABOVE
; 
4012     if (point
.y
>h
) flags 
|= wxTREE_HITTEST_BELOW
; 
4013     if (flags
) return wxTreeItemId(); 
4015     if (m_anchor 
== NULL
) 
4017         flags 
= wxTREE_HITTEST_NOWHERE
; 
4018         return wxTreeItemId(); 
4021     wxTreeListItem 
*hit 
= m_anchor
->HitTest(CalcUnscrolledPosition(point
), 
4022                                             this, flags
, column
, 0); 
4025         flags 
= wxTREE_HITTEST_NOWHERE
; 
4026         return wxTreeItemId(); 
4031 // get the bounding rectangle of the item (or of its label only) 
4032 bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId
& item
, 
4034                          bool WXUNUSED(textOnly
)) const 
4036     wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") ); 
4038     wxTreeListItem 
*i 
= (wxTreeListItem
*) item
.m_pItem
; 
4041     GetViewStart(& startX
, & startY
); 
4043     rect
.x 
= i
->GetX() - startX
*PIXELS_PER_UNIT
; 
4044     rect
.y 
= i
->GetY() - startY
*PIXELS_PER_UNIT
; 
4045     rect
.width 
= i
->GetWidth(); 
4046     //rect.height = i->GetHeight(); 
4047     rect
.height 
= GetLineHeight(i
); 
4054 void wxTreeListMainWindow::Edit( const wxTreeItemId
& item 
) 
4056     if (!item
.IsOk()) return; 
4058     m_currentEdit 
= (wxTreeListItem
*) item
.m_pItem
; 
4060     wxTreeEvent 
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, m_owner
->GetId() ); 
4061     te
.SetItem( (long) m_currentEdit
); 
4062     te
.SetEventObject( /*this*/m_owner 
); 
4063     m_owner
->GetEventHandler()->ProcessEvent( te 
); 
4065     if (!te
.IsAllowed()) return; 
4067     // We have to call this here because the label in 
4068     // question might just have been added and no screen 
4069     // update taken place. 
4070     if (m_dirty
) wxYieldIfNeeded(); 
4072     wxString s 
= m_currentEdit
->GetText(/*ALB*/m_main_column
); 
4073     int x 
= m_currentEdit
->GetX() + m_imgWidth2
; 
4074     int y 
= m_currentEdit
->GetY(); 
4075     int w 
= wxMin (m_currentEdit
->GetWidth(), 
4076                    m_owner
->GetHeaderWindow()->GetWidth()) - m_imgWidth2
; 
4077     int h 
= m_currentEdit
->GetHeight() + 2; 
4078     wxClientDC 
dc(this); 
4080     x 
= dc
.LogicalToDeviceX( x 
); 
4081     y 
= dc
.LogicalToDeviceY( y 
); 
4083     wxTreeListTextCtrl 
*text 
= new wxTreeListTextCtrl(this, -1, 
4093 void wxTreeListMainWindow::OnRenameTimer() 
4098 void wxTreeListMainWindow::OnRenameAccept() 
4100     // TODO if the validator fails this causes a crash 
4101     wxTreeEvent 
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, m_owner
->GetId() ); 
4102     le
.SetItem( (long) m_currentEdit 
); 
4103     le
.SetEventObject( /*this*/m_owner 
); 
4104     le
.SetLabel( m_renameRes 
); 
4105     m_owner
->GetEventHandler()->ProcessEvent( le 
); 
4107     if (!le
.IsAllowed()) return; 
4109     SetItemText( m_currentEdit
, m_renameRes 
); 
4112 void wxTreeListMainWindow::OnMouse( wxMouseEvent 
&event 
) 
4114     if ( !m_anchor 
) return; 
4116     wxPoint pt 
= CalcUnscrolledPosition(event
.GetPosition()); 
4118     // Is the mouse over a tree item button? 
4120     wxTreeListItem 
*item 
= m_anchor
->HitTest(pt
, this, flags
, 0); 
4121     wxTreeListItem 
*underMouse 
= item
; 
4123     if (underMouse 
&& (flags 
& wxTREE_HITTEST_ONITEMBUTTON
) && 
4124         !event
.LeftIsDown() && !m_isDragging 
&& 
4125         (!m_renameTimer 
|| !m_renameTimer
->IsRunning())) 
4133     if (underMouse 
!= m_underMouse
) 
4137             // unhighlight old item 
4138             wxTreeListItem 
*tmp 
= m_underMouse
; 
4139             m_underMouse 
= NULL
; 
4143          m_underMouse 
= underMouse
; 
4145             RefreshLine( m_underMouse 
); 
4148     // we process left mouse up event (enables in-place edit), right down 
4149     // (pass to the user code), left dbl click (activate item) and 
4150     // dragging/moving events for items drag-and-drop 
4151     if ( !(event
.LeftDown() || 
4153            event
.RightDown() || 
4154            event
.LeftDClick() || 
4156            ((event
.Moving() || event
.RightUp()) && m_isDragging
)) ) 
4162     if ( event
.LeftDown() ) 
4165 //     wxClientDC dc(this); 
4167 //     wxCoord x = dc.DeviceToLogicalX( event.GetX() ); 
4168 //     wxCoord y = dc.DeviceToLogicalY( event.GetY() ); 
4172     if ( event
.Dragging() && !m_isDragging 
) 
4174         if (m_dragCount 
== 0) 
4175             m_dragStart 
= wxPoint(x
,y
); 
4179         if (m_dragCount 
!= 3) 
4181             // wait until user drags a bit further... 
4185         wxEventType command 
= event
.RightIsDown() 
4186                               ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
 
4187                               : wxEVT_COMMAND_TREE_BEGIN_DRAG
; 
4189         wxTreeEvent 
nevent( command
,/*ALB*/ m_owner
->GetId() ); 
4190         nevent
.SetItem( (long) m_current
); 
4191         nevent
.SetEventObject(/*this*/m_owner
); // ALB 
4193         // by default the dragging is not supported, the user code must 
4194         // explicitly allow the event for it to take place 
4197         if ( m_owner
->GetEventHandler()->ProcessEvent(nevent
) && 
4198              nevent
.IsAllowed() ) 
4200             // we're going to drag this item 
4201             m_isDragging 
= TRUE
; 
4203             // remember the old cursor because we will change it while 
4205             m_oldCursor 
= m_cursor
; 
4207             // in a single selection control, hide the selection temporarily 
4208             if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) ) 
4210                 m_oldSelection 
= (wxTreeListItem
*) GetSelection().m_pItem
; 
4212                 if ( m_oldSelection 
) 
4214                     m_oldSelection
->SetHilight(FALSE
); 
4215                     RefreshLine(m_oldSelection
); 
4222     else if ( event
.Moving() ) 
4224         if ( item 
!= m_dropTarget 
) 
4226             // unhighlight the previous drop target 
4227             DrawDropEffect(m_dropTarget
); 
4229             m_dropTarget 
= item
; 
4231             // highlight the current drop target if any 
4232             DrawDropEffect(m_dropTarget
); 
4237     else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging 
) 
4239         // erase the highlighting 
4240         DrawDropEffect(m_dropTarget
); 
4242         if ( m_oldSelection 
) 
4244             m_oldSelection
->SetHilight(TRUE
); 
4245             RefreshLine(m_oldSelection
); 
4246             m_oldSelection 
= (wxTreeListItem 
*)NULL
; 
4249         // generate the drag end event 
4250         wxTreeEvent 
event(wxEVT_COMMAND_TREE_END_DRAG
,/*ALB*/m_owner
->GetId()); 
4252         event
.SetItem( (long) item 
); 
4253         event
.SetPoint( wxPoint(x
, y
) ); 
4254         event
.SetEventObject(/*this*/m_owner
); 
4256         (void)m_owner
->GetEventHandler()->ProcessEvent(event
); 
4258         m_isDragging 
= FALSE
; 
4259         m_dropTarget 
= (wxTreeListItem 
*)NULL
; 
4263         SetCursor(m_oldCursor
); 
4269         // here we process only the messages which happen on tree items 
4273         if ( item 
== NULL 
) return;  /* we hit the blank area */ 
4275         if ( event
.RightDown() ) 
4278             wxTreeEvent 
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, 
4280             nevent
.SetItem( (long) item 
); 
4282             CalcScrolledPosition(x
, y
, &nx
, &ny
); 
4283             nevent
.SetPoint( wxPoint(nx
, ny
)); 
4284             nevent
.SetEventObject(/*this*/m_owner
); 
4285             m_owner
->GetEventHandler()->ProcessEvent(nevent
); 
4287         else if ( event
.LeftUp() ) 
4291                 if ( ( item 
== m_current 
) && 
4292                      ( flags 
& wxTREE_HITTEST_ONITEMLABEL 
) && 
4293                      HasFlag(wxTR_EDIT_LABELS 
) ) 
4295                     if ( m_renameTimer
->IsRunning() ) 
4296                         m_renameTimer
->Stop(); 
4298                     m_renameTimer
->Start( 100, TRUE 
); 
4301                 m_lastOnSame 
= FALSE
; 
4304         else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick() 
4306             if ( event
.LeftDown() ) 
4309                 m_lastOnSame 
= item 
== m_current
; 
4312             if ((flags 
& wxTREE_HITTEST_ONITEMBUTTON
) || 
4313                 ((flags 
& wxTREE_HITTEST_ONITEMICON
)) && 
4314                  !HasButtons() && item
->HasPlus()) 
4316                 // only toggle the item for a single click, double click on 
4317                 // the button doesn't do anything (it toggles the item twice) 
4318                 if ( event
.LeftDown() ) 
4323                 // don't select the item if the button was clicked 
4327             // how should the selection work for this event? 
4328             bool is_multiple
, extended_select
, unselect_others
; 
4329             EventFlagsToSelType(GetWindowStyleFlag(), 
4331                                 event
.ControlDown(), 
4332                                 is_multiple
, extended_select
, unselect_others
); 
4334             SelectItem (item
, unselect_others
, extended_select
); 
4336             // For some reason, Windows isn't recognizing a left double-click, 
4337             // so we need to simulate it here.  Allow 200 milliseconds for now. 
4338             if ( event
.LeftDClick() ) 
4340                 // double clicking should not start editing the item label 
4341                 m_renameTimer
->Stop(); 
4342                 m_lastOnSame 
= FALSE
; 
4344                 // send activate event first 
4345                 wxTreeEvent 
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, 
4347                 nevent
.SetItem( (long) item 
); 
4349                 CalcScrolledPosition(x
, y
, &nx
, &ny
); 
4350                 nevent
.SetPoint( wxPoint(nx
, ny
) ); 
4351                 nevent
.SetEventObject( /*this*/m_owner 
); 
4352                 if ( !m_owner
->GetEventHandler()->ProcessEvent( nevent 
) ) 
4354                     // if the user code didn't process the activate event, 
4355                     // handle it ourselves by toggling the item when it is 
4357                     if ( item
->HasPlus() ) 
4367 void wxTreeListMainWindow::OnIdle( wxIdleEvent 
&WXUNUSED(event
) ) 
4369     /* after all changes have been done to the tree control, 
4370      * we actually redraw the tree when everything is over */ 
4372     if (!m_dirty
) return; 
4376     CalculatePositions(); 
4378     AdjustMyScrollbars(); 
4381 void wxTreeListMainWindow::OnScroll(wxScrollWinEvent
& event
) 
4384 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) 
4385     wxScrolledWindow::OnScroll(event
); 
4387     HandleOnScroll( event 
); 
4390     if(event
.GetOrientation() == wxHORIZONTAL
) 
4392         m_owner
->GetHeaderWindow()->Refresh(); 
4393         m_owner
->GetHeaderWindow()->Update(); 
4398 void wxTreeListMainWindow::CalculateSize( wxTreeListItem 
*item
, wxDC 
&dc 
) 
4404         dc
.SetFont(m_boldFont
); 
4406     dc
.GetTextExtent( item
->GetText(/*ALB*/m_main_column
), &text_w
, &text_h 
); 
4409     // restore normal font 
4410     dc
.SetFont( m_normalFont 
); 
4412     int total_h 
= (m_imgHeight 
> text_h
) ? m_imgHeight 
: text_h
; 
4414     item
->SetHeight(total_h
); 
4415     if (total_h
>m_lineHeight
) 
4416         m_lineHeight
=total_h
; 
4418     item
->SetWidth(m_imgWidth 
+ text_w
+2); 
4421 // ----------------------------------------------------------------------------- 
4422 // for developper : y is now the top of the level 
4423 // not the middle of it ! 
4424 void wxTreeListMainWindow::CalculateLevel( wxTreeListItem 
*item
, wxDC 
&dc
, 
4425                                         int level
, int &y
, int x_colstart 
) 
4427     // calculate position of vertical lines 
4428     int x 
= x_colstart 
+ MARGIN
; // start of column 
4429     if (HasFlag(wxTR_LINES_AT_ROOT
)) x 
+= LINEATROOT
; // space for lines at root 
4430     if (HasButtons()) x 
+= m_btnWidth2
; // space for buttons etc. 
4431     if (!HasFlag(wxTR_HIDE_ROOT
)) x 
+= m_indent
; // indent root as well 
4432     x 
+= m_indent 
* level
; // indent according to level 
4434     // a hidden root is not evaluated, but its children are always 
4435     if (HasFlag(wxTR_HIDE_ROOT
) && (level 
== 0)) goto Recurse
; 
4437     CalculateSize( item
, dc 
); 
4442     y 
+= GetLineHeight(item
); 
4444     // we don't need to calculate collapsed branches 
4445     if ( !item
->IsExpanded() ) return; 
4448     wxArrayTreeListItems
& children 
= item
->GetChildren(); 
4449     size_t n
, count 
= children
.Count(); 
4451     for (n 
= 0; n 
< count
; ++n 
) 
4452         CalculateLevel( children
[n
], dc
, level
, y
, x_colstart 
);  // recurse 
4455 void wxTreeListMainWindow::CalculatePositions() 
4457     if ( !m_anchor 
) return; 
4459     wxClientDC 
dc(this); 
4462     dc
.SetFont( m_normalFont 
); 
4464     dc
.SetPen( m_dottedPen 
); 
4465     //if(GetImageList() == NULL) 
4466     // m_lineHeight = (int)(dc.GetCharHeight() + 4); 
4470     for(size_t i 
= 0; i 
< GetMainColumn(); ++i
) { 
4471         if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue; 
4472         x_colstart 
+= m_owner
->GetHeaderWindow()->GetColumnWidth(i
); 
4474     CalculateLevel( m_anchor
, dc
, 0, y
, x_colstart 
); // start recursion 
4477 void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem 
*item
) 
4479     if (m_dirty
) return; 
4481     wxClientDC 
dc(this); 
4486     GetVirtualSize( &cw
, &ch 
);  
4489     rect
.x 
= dc
.LogicalToDeviceX( 0 ); 
4491     rect
.y 
= dc
.LogicalToDeviceY( item
->GetY() - 2 ); 
4494     Refresh( TRUE
, &rect 
); 
4496     AdjustMyScrollbars(); 
4499 void wxTreeListMainWindow::RefreshLine( wxTreeListItem 
*item 
) 
4501     if (m_dirty
) return; 
4503     wxClientDC 
dc(this); 
4508     GetVirtualSize( &cw
, &ch 
);   
4511     rect
.x 
= dc
.LogicalToDeviceX( 0 ); 
4512     rect
.y 
= dc
.LogicalToDeviceY( item
->GetY() ); 
4514     rect
.height 
= GetLineHeight(item
); //dc.GetCharHeight() + 6; 
4516     Refresh( TRUE
, &rect 
); 
4519 void wxTreeListMainWindow::RefreshSelected() 
4521     // TODO: this is awfully inefficient, we should keep the list of all 
4522     //       selected items internally, should be much faster 
4524         RefreshSelectedUnder(m_anchor
); 
4527 void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem 
*item
) 
4529     if ( item
->IsSelected() ) 
4532     const wxArrayTreeListItems
& children 
= item
->GetChildren(); 
4533     size_t count 
= children
.GetCount(); 
4534     for ( size_t n 
= 0; n 
< count
; n
++ ) 
4536         RefreshSelectedUnder(children
[n
]); 
4540 // ---------------------------------------------------------------------------- 
4541 // changing colours: we need to refresh the tree control 
4542 // ---------------------------------------------------------------------------- 
4544 bool wxTreeListMainWindow::SetBackgroundColour(const wxColour
& colour
) 
4546     if ( !wxWindow::SetBackgroundColour(colour
) ) 
4554 bool wxTreeListMainWindow::SetForegroundColour(const wxColour
& colour
) 
4556     if ( !wxWindow::SetForegroundColour(colour
) ) 
4564 //----------- ALB ------------- 
4565 void wxTreeListMainWindow::SetItemText(const wxTreeItemId
& item
, size_t column
, 
4566                                     const wxString
& text
) 
4568     wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") ); 
4570     wxClientDC 
dc(this); 
4571     wxTreeListItem 
*pItem 
= (wxTreeListItem
*) item
.m_pItem
; 
4572     pItem
->SetText(column
, text
); 
4573     CalculateSize(pItem
, dc
); 
4577 wxString 
wxTreeListMainWindow::GetItemText(const wxTreeItemId
& item
, 
4578                                      size_t column
) const 
4580     wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") ); 
4582     return ((wxTreeListItem
*) item
.m_pItem
)->GetText(column
); 
4585 void wxTreeListMainWindow::SetFocus() 
4587     wxWindow::SetFocus(); 
4591 //----------------------------------------------------------------------------- 
4593 //----------------------------------------------------------------------------- 
4595 IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl
, wxControl
); 
4597 BEGIN_EVENT_TABLE(wxTreeListCtrl
, wxControl
) 
4598     EVT_SIZE(wxTreeListCtrl::OnSize
) 
4601 bool wxTreeListCtrl::Create(wxWindow 
*parent
, wxWindowID id
, 
4604                             long style
, const wxValidator 
&validator
, 
4605                             const wxString
& name
) 
4607     long main_style 
= style 
& ~(wxRAISED_BORDER
|wxSUNKEN_BORDER
 
4608                                 |wxSIMPLE_BORDER
|wxNO_BORDER
|wxDOUBLE_BORDER
 
4610     long ctrl_style 
= style 
& ~(wxVSCROLL
|wxHSCROLL
); 
4612     if (!wxControl::Create(parent
, id
, pos
, size
, ctrl_style
, validator
, name
)) { 
4615     m_main_win 
= new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size
, 
4616                                           main_style
, validator
); 
4617     m_header_win 
= new wxTreeListHeaderWindow(this, -1, m_main_win
, 
4618                                               wxPoint(0, 0), wxDefaultSize
, 
4620     CalculateAndSetHeaderHeight(); 
4624 void wxTreeListCtrl::CalculateAndSetHeaderHeight() 
4628         // we use 'g' to get the descent, too 
4630         m_header_win
->GetTextExtent(wxT("Hg"), &w
, &h
, &d
); 
4631         h 
+= d 
+ 2 * HEADER_OFFSET_Y 
+ EXTRA_HEIGHT
; 
4633         // only update if changed 
4634         if ( h 
!= (int)m_headerHeight 
) 
4636             m_headerHeight 
= (size_t)h
; 
4637             m_header_win
->SetSize(m_header_win
->GetSize().x
, m_headerHeight
); 
4643 void wxTreeListCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
)) 
4646     GetClientSize(&w
, &h
); 
4648         m_header_win
->SetSize(0, 0, w
, m_headerHeight
); 
4650         m_main_win
->SetSize(0, m_headerHeight 
+ 1, w
, h 
- m_headerHeight 
- 1); 
4654 size_t wxTreeListCtrl::GetCount() const { return m_main_win
->GetCount(); } 
4656 unsigned int wxTreeListCtrl::GetIndent() const 
4657 { return m_main_win
->GetIndent(); } 
4659 void wxTreeListCtrl::SetIndent(unsigned int indent
) 
4660 { m_main_win
->SetIndent(indent
); } 
4662 unsigned int wxTreeListCtrl::GetLineSpacing() const 
4663 { return m_main_win
->GetLineSpacing(); } 
4665 void wxTreeListCtrl::SetLineSpacing(unsigned int spacing
) 
4666 { m_main_win
->SetLineSpacing(spacing
); } 
4668 wxImageList
* wxTreeListCtrl::GetImageList() const 
4669 { return m_main_win
->GetImageList(); } 
4671 wxImageList
* wxTreeListCtrl::GetStateImageList() const 
4672 { return m_main_win
->GetStateImageList(); } 
4674 wxImageList
* wxTreeListCtrl::GetButtonsImageList() const 
4675 { return m_main_win
->GetButtonsImageList(); } 
4677 void wxTreeListCtrl::SetImageList(wxImageList
* imageList
) 
4678 { m_main_win
->SetImageList(imageList
); } 
4680 void wxTreeListCtrl::SetStateImageList(wxImageList
* imageList
) 
4681 { m_main_win
->SetStateImageList(imageList
); } 
4683 void wxTreeListCtrl::SetButtonsImageList(wxImageList
* imageList
) 
4684 { m_main_win
->SetButtonsImageList(imageList
); } 
4686 void wxTreeListCtrl::AssignImageList(wxImageList
* imageList
) 
4687 { m_main_win
->AssignImageList(imageList
); } 
4689 void wxTreeListCtrl::AssignStateImageList(wxImageList
* imageList
) 
4690 { m_main_win
->AssignStateImageList(imageList
); } 
4692 void wxTreeListCtrl::AssignButtonsImageList(wxImageList
* imageList
) 
4693 { m_main_win
->AssignButtonsImageList(imageList
); } 
4695 wxString 
wxTreeListCtrl::GetItemText(const wxTreeItemId
& item
, size_t column
) 
4697 { return m_main_win
->GetItemText(item
, column
); } 
4699 int wxTreeListCtrl::GetItemImage(const wxTreeItemId
& item
, size_t column
, 
4700                                  wxTreeItemIcon which
) const 
4701 { return m_main_win
->GetItemImage(item
, column
, which
); } 
4703 wxTreeItemData
* wxTreeListCtrl::GetItemData(const wxTreeItemId
& item
) const 
4704 { return m_main_win
->GetItemData(item
); } 
4706 bool wxTreeListCtrl::GetItemBold(const wxTreeItemId
& item
) const 
4707 { return m_main_win
->GetItemBold(item
); } 
4709 wxColour 
wxTreeListCtrl::GetItemTextColour(const wxTreeItemId
& item
) const 
4710 { return m_main_win
->GetItemTextColour(item
); } 
4712 wxColour 
wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) 
4714 { return m_main_win
->GetItemBackgroundColour(item
); } 
4716 wxFont 
wxTreeListCtrl::GetItemFont(const wxTreeItemId
& item
) const 
4717 { return m_main_win
->GetItemFont(item
); } 
4720 void wxTreeListCtrl::SetItemText(const wxTreeItemId
& item
, size_t column
, 
4721                                  const wxString
& text
) 
4722 { m_main_win
->SetItemText(item
, column
, text
); } 
4724 void wxTreeListCtrl::SetItemImage(const wxTreeItemId
& item
, 
4727                                   wxTreeItemIcon which
) 
4728 { m_main_win
->SetItemImage(item
, column
, image
, which
); } 
4730 void wxTreeListCtrl::SetItemData(const wxTreeItemId
& item
, 
4731                                  wxTreeItemData
* data
) 
4732 { m_main_win
->SetItemData(item
, data
); } 
4734 void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
) 
4735 { m_main_win
->SetItemHasChildren(item
, has
); } 
4737 void wxTreeListCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
) 
4738 { m_main_win
->SetItemBold(item
, bold
); } 
4740 void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId
& item
, 
4741                                        const wxColour
& col
) 
4742 { m_main_win
->SetItemTextColour(item
, col
); } 
4744 void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
, 
4745                                              const wxColour
& col
) 
4746 { m_main_win
->SetItemBackgroundColour(item
, col
); } 
4748 void wxTreeListCtrl::SetItemFont(const wxTreeItemId
& item
, 
4750 { m_main_win
->SetItemFont(item
, font
); } 
4752 bool wxTreeListCtrl::SetFont(const wxFont
& font
) 
4756         m_header_win
->SetFont(font
); 
4757         CalculateAndSetHeaderHeight(); 
4760         return m_main_win
->SetFont(font
); 
4764 void wxTreeListCtrl::SetWindowStyle(const long style
) 
4767         m_main_win
->SetWindowStyle(style
); 
4768     // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win 
4771 long wxTreeListCtrl::GetWindowStyle() const 
4773     long style 
= m_windowStyle
; 
4775         style 
|= m_main_win
->GetWindowStyle(); 
4779 bool wxTreeListCtrl::IsVisible(const wxTreeItemId
& item
) const 
4780 { return m_main_win
->IsVisible(item
); } 
4782 bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId
& item
) const 
4783 { return m_main_win
->ItemHasChildren(item
); } 
4785 bool wxTreeListCtrl::IsExpanded(const wxTreeItemId
& item
) const 
4786 { return m_main_win
->IsExpanded(item
); } 
4788 bool wxTreeListCtrl::IsSelected(const wxTreeItemId
& item
) const 
4789 { return m_main_win
->IsSelected(item
); } 
4791 bool wxTreeListCtrl::IsBold(const wxTreeItemId
& item
) const 
4792 { return m_main_win
->IsBold(item
); } 
4794 size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool rec
) 
4795 { return m_main_win
->GetChildrenCount(item
, rec
); } 
4797 wxTreeItemId 
wxTreeListCtrl::GetRootItem() const 
4798 { return m_main_win
->GetRootItem(); } 
4800 wxTreeItemId 
wxTreeListCtrl::GetSelection() const 
4801 { return m_main_win
->GetSelection(); } 
4803 size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds
& arr
) const 
4804 { return m_main_win
->GetSelections(arr
); } 
4806 wxTreeItemId 
wxTreeListCtrl::GetItemParent(const wxTreeItemId
& item
) const 
4807 { return m_main_win
->GetItemParent(item
); } 
4809 #if !wxCHECK_VERSION(2, 5, 0) 
4810 wxTreeItemId 
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
, 
4813 wxTreeItemId 
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
, 
4814                                            wxTreeItemIdValue
& cookie
) const 
4816 { return m_main_win
->GetFirstChild(item
, cookie
); } 
4818 #if !wxCHECK_VERSION(2, 5, 0) 
4819 wxTreeItemId 
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
, 
4822 wxTreeItemId 
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
, 
4823                                           wxTreeItemIdValue
& cookie
) const 
4825 { return m_main_win
->GetNextChild(item
, cookie
); } 
4827 #if !wxCHECK_VERSION(2, 5, 0) 
4828 wxTreeItemId 
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
, 
4831 wxTreeItemId 
wxTreeListCtrl::GetPrevChild(const wxTreeItemId
& item
, 
4832                                           wxTreeItemIdValue
& cookie
) const 
4834 { return m_main_win
->GetPrevChild(item
, cookie
); } 
4836 wxTreeItemId 
wxTreeListCtrl::GetLastChild(const wxTreeItemId
& item
) const 
4837 { return m_main_win
->GetLastChild(item
); } 
4839 wxTreeItemId 
wxTreeListCtrl::GetNextSibling(const wxTreeItemId
& item
) const 
4840 { return m_main_win
->GetNextSibling(item
); } 
4842 wxTreeItemId 
wxTreeListCtrl::GetPrevSibling(const wxTreeItemId
& item
) const 
4843 { return m_main_win
->GetPrevSibling(item
); } 
4845 wxTreeItemId 
wxTreeListCtrl::GetFirstVisibleItem() const 
4846 { return m_main_win
->GetFirstVisibleItem(); } 
4848 wxTreeItemId 
wxTreeListCtrl::GetNextVisible(const wxTreeItemId
& item
) const 
4849 { return m_main_win
->GetNextVisible(item
); } 
4851 wxTreeItemId 
wxTreeListCtrl::GetPrevVisible(const wxTreeItemId
& item
) const 
4852 { return m_main_win
->GetPrevVisible(item
); } 
4854 wxTreeItemId 
wxTreeListCtrl::GetNext(const wxTreeItemId
& item
) const 
4855 { return m_main_win
->GetNext(item
); } 
4857 wxTreeItemId 
wxTreeListCtrl::AddRoot(const wxString
& text
, int image
, 
4858                                      int selectedImage
, wxTreeItemData
* data
) 
4859 { return m_main_win
->AddRoot(text
, image
, selectedImage
, data
); } 
4861 wxTreeItemId 
wxTreeListCtrl::PrependItem(const wxTreeItemId
& parent
, 
4862                                          const wxString
& text
, int image
, 
4864                                          wxTreeItemData
* data
) 
4865 { return m_main_win
->PrependItem(parent
, text
, image
, selectedImage
, data
); } 
4867 wxTreeItemId 
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
, 
4868                                         const wxTreeItemId
& previous
, 
4869                                         const wxString
& text
, int image
, 
4871                                         wxTreeItemData
* data
) 
4873     return m_main_win
->InsertItem(parent
, previous
, text
, image
, 
4874                                   selectedImage
, data
); 
4877 wxTreeItemId 
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
, 
4879                                         const wxString
& text
, int image
, 
4881                                         wxTreeItemData
* data
) 
4883     return m_main_win
->InsertItem(parent
, index
, text
, image
, 
4884                                   selectedImage
, data
); 
4887 wxTreeItemId 
wxTreeListCtrl::AppendItem(const wxTreeItemId
& parent
, 
4888                                         const wxString
& text
, int image
, 
4890                                         wxTreeItemData
* data
) 
4891 { return m_main_win
->AppendItem(parent
, text
, image
, selectedImage
, data
); } 
4893 void wxTreeListCtrl::Delete(const wxTreeItemId
& item
) 
4894 { m_main_win
->Delete(item
); } 
4896 void wxTreeListCtrl::DeleteChildren(const wxTreeItemId
& item
) 
4897 { m_main_win
->DeleteChildren(item
); } 
4899 void wxTreeListCtrl::DeleteAllItems() 
4900 { m_main_win
->DeleteAllItems(); } 
4902 void wxTreeListCtrl::Expand(const wxTreeItemId
& item
) 
4903 { m_main_win
->Expand(item
); } 
4905 void wxTreeListCtrl::ExpandAll(const wxTreeItemId
& item
) 
4906 { m_main_win
->ExpandAll(item
); } 
4908 void wxTreeListCtrl::Collapse(const wxTreeItemId
& item
) 
4909 { m_main_win
->Collapse(item
); } 
4911 void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId
& item
) 
4912 { m_main_win
->CollapseAndReset(item
); } 
4914 void wxTreeListCtrl::Toggle(const wxTreeItemId
& item
) 
4915 { m_main_win
->Toggle(item
); } 
4917 void wxTreeListCtrl::Unselect() 
4918 { m_main_win
->Unselect(); } 
4920 void wxTreeListCtrl::UnselectAll() 
4921 { m_main_win
->UnselectAll(); } 
4923 void wxTreeListCtrl::SelectItem(const wxTreeItemId
& item
, bool unselect_others
, 
4924                                 bool extended_select
) 
4925 { m_main_win
->SelectItem(item
, unselect_others
, extended_select
); } 
4927 void wxTreeListCtrl::SelectAll(bool extended_select
) 
4928 { m_main_win
->SelectAll(extended_select
); } 
4930 void wxTreeListCtrl::EnsureVisible(const wxTreeItemId
& item
) 
4931 { m_main_win
->EnsureVisible(item
); } 
4933 void wxTreeListCtrl::ScrollTo(const wxTreeItemId
& item
) 
4934 { m_main_win
->ScrollTo(item
); } 
4936 wxTreeItemId 
wxTreeListCtrl::HitTest(const wxPoint
& pos
, int& flags
, 
4939     return m_main_win
->HitTest(pos
, flags
, column
); 
4942 bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
, 
4943                                      bool textOnly
) const 
4944 { return m_main_win
->GetBoundingRect(item
, rect
, textOnly
); } 
4946 void wxTreeListCtrl::Edit(const wxTreeItemId
& item
) 
4947 { m_main_win
->Edit(item
); } 
4949 int wxTreeListCtrl::OnCompareItems(const wxTreeItemId
& item1
, 
4950                                    const wxTreeItemId
& item2
) 
4952     // ALB: do the comparison here, and not delegate to m_main_win, in order 
4953     // to let the user override it 
4954     //return m_main_win->OnCompareItems(item1, item2); 
4955     return wxStrcmp(GetItemText(item1
), GetItemText(item2
)); 
4958 void wxTreeListCtrl::SortChildren(const wxTreeItemId
& item
) 
4959 { m_main_win
->SortChildren(item
); } 
4961 wxTreeItemId 
wxTreeListCtrl::FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
) 
4962 { return m_main_win
->FindItem (item
, str
, flags
); } 
4964 bool wxTreeListCtrl::SetBackgroundColour(const wxColour
& colour
) 
4966     if (!m_main_win
) return false; 
4967     return m_main_win
->SetBackgroundColour(colour
);  
4970 bool wxTreeListCtrl::SetForegroundColour(const wxColour
& colour
) 
4972     if (!m_main_win
) return false; 
4973     return m_main_win
->SetForegroundColour(colour
);  
4976 size_t wxTreeListCtrl::GetColumnCount() const 
4977 { return m_main_win
->GetColumnCount(); } 
4979 void wxTreeListCtrl::SetColumnWidth(size_t column
, size_t width
) 
4980 { m_header_win
->SetColumnWidth(column
, width
); } 
4982 int wxTreeListCtrl::GetColumnWidth(size_t column
) const 
4983 { return m_header_win
->GetColumnWidth(column
); } 
4985 void wxTreeListCtrl::SetMainColumn(size_t column
) 
4986 { m_main_win
->SetMainColumn(column
); } 
4988 size_t wxTreeListCtrl::GetMainColumn() const 
4989 { return m_main_win
->GetMainColumn(); } 
4991 void wxTreeListCtrl::SetColumnText(size_t column
, const wxString
& text
) 
4993     m_header_win
->SetColumnText(column
, text
); 
4994     m_header_win
->Refresh(); 
4997 wxString 
wxTreeListCtrl::GetColumnText(size_t column
) const 
4998 { return m_header_win
->GetColumnText(column
); } 
5000 void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo
& col
) 
5001 { m_header_win
->AddColumn(col
); } 
5003 void wxTreeListCtrl::InsertColumn(size_t before
, 
5004                                   const wxTreeListColumnInfo
& col
) 
5005 { m_header_win
->InsertColumn(before
, col
); } 
5007 void wxTreeListCtrl::RemoveColumn(size_t column
) 
5008 { m_header_win
->RemoveColumn(column
); } 
5010 void wxTreeListCtrl::SetColumn(size_t column
, const wxTreeListColumnInfo
& col
) 
5011 { m_header_win
->SetColumn(column
, col
); } 
5013 const wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) const 
5014 { return m_header_win
->GetColumn(column
); } 
5016 wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) 
5017 { return m_header_win
->GetColumn(column
); } 
5019 void wxTreeListCtrl::SetColumnImage(size_t column
, int image
) 
5021     m_header_win
->SetColumn(column
, GetColumn(column
).SetImage(image
)); 
5024 int wxTreeListCtrl::GetColumnImage(size_t column
) const 
5026     return m_header_win
->GetColumn(column
).GetImage(); 
5029 void wxTreeListCtrl::ShowColumn(size_t column
, bool shown
) 
5031     wxASSERT_MSG( column 
!= GetMainColumn(), 
5032                   wxT("The main column may not be hidden") ); 
5033     m_header_win
->SetColumn(column
, GetColumn(column
).SetShown(GetMainColumn()? true: shown
)); 
5036 bool wxTreeListCtrl::IsColumnShown(size_t column
) const 
5038     return m_header_win
->GetColumn(column
).GetShown(); 
5041 void wxTreeListCtrl::SetColumnAlignment(size_t column
, 
5042                                         wxTreeListColumnAlign align
) 
5044     m_header_win
->SetColumn(column
, GetColumn(column
).SetAlignment(align
)); 
5047 wxTreeListColumnAlign 
wxTreeListCtrl::GetColumnAlignment(size_t column
) const 
5049     return m_header_win
->GetColumn(column
).GetAlignment(); 
5052 void wxTreeListCtrl::Refresh(bool erase
, const wxRect
* rect
) 
5054     m_main_win
->Refresh(erase
, rect
); 
5055     m_header_win
->Refresh(erase
, rect
); 
5058 void wxTreeListCtrl::SetFocus() 
5059 { m_main_win
->SetFocus(); } 
5062 wxSize 
wxTreeListCtrl::DoGetBestSize() const 
5064     // something is better than nothing... 
5065     return wxSize(100,80);