1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/generic/treectlg.h 
   3 // Purpose:     wxTreeCtrl class 
   4 // Author:      Robert Roebling 
   8 // Copyright:   (c) 1997,1998 Robert Roebling 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #ifndef _GENERIC_TREECTRL_H_ 
  13 #define _GENERIC_TREECTRL_H_ 
  17 #include "wx/scrolwin.h" 
  20 // ----------------------------------------------------------------------------- 
  21 // forward declaration 
  22 // ----------------------------------------------------------------------------- 
  24 class WXDLLIMPEXP_FWD_CORE wxGenericTreeItem
; 
  26 class WXDLLIMPEXP_FWD_CORE wxTreeItemData
; 
  28 class WXDLLIMPEXP_FWD_CORE wxTreeRenameTimer
; 
  29 class WXDLLIMPEXP_FWD_CORE wxTreeFindTimer
; 
  30 class WXDLLIMPEXP_FWD_CORE wxTreeTextCtrl
; 
  31 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
; 
  33 // ----------------------------------------------------------------------------- 
  34 // wxGenericTreeCtrl - the tree control 
  35 // ----------------------------------------------------------------------------- 
  37 class WXDLLIMPEXP_CORE wxGenericTreeCtrl 
: public wxTreeCtrlBase
, 
  44     wxGenericTreeCtrl() : wxTreeCtrlBase(), wxScrollHelper(this) { Init(); } 
  46     wxGenericTreeCtrl(wxWindow 
*parent
, wxWindowID id 
= wxID_ANY
, 
  47                const wxPoint
& pos 
= wxDefaultPosition
, 
  48                const wxSize
& size 
= wxDefaultSize
, 
  49                long style 
= wxTR_DEFAULT_STYLE
, 
  50                const wxValidator 
&validator 
= wxDefaultValidator
, 
  51                const wxString
& name 
= wxTreeCtrlNameStr
) 
  56         Create(parent
, id
, pos
, size
, style
, validator
, name
); 
  59     virtual ~wxGenericTreeCtrl(); 
  61     bool Create(wxWindow 
*parent
, wxWindowID id 
= wxID_ANY
, 
  62                 const wxPoint
& pos 
= wxDefaultPosition
, 
  63                 const wxSize
& size 
= wxDefaultSize
, 
  64                 long style 
= wxTR_DEFAULT_STYLE
, 
  65                 const wxValidator 
&validator 
= wxDefaultValidator
, 
  66                 const wxString
& name 
= wxTreeCtrlNameStr
); 
  69     // implement base class pure virtuals 
  70     // ---------------------------------- 
  72     virtual unsigned int GetCount() const; 
  74     virtual unsigned int GetIndent() const { return m_indent
; } 
  75     virtual void SetIndent(unsigned int indent
); 
  78     virtual void SetImageList(wxImageList 
*imageList
); 
  79     virtual void SetStateImageList(wxImageList 
*imageList
); 
  81     virtual wxString 
GetItemText(const wxTreeItemId
& item
) const; 
  82     virtual int GetItemImage(const wxTreeItemId
& item
, 
  83                      wxTreeItemIcon which 
= wxTreeItemIcon_Normal
) const; 
  84     virtual wxTreeItemData 
*GetItemData(const wxTreeItemId
& item
) const; 
  85     virtual wxColour 
GetItemTextColour(const wxTreeItemId
& item
) const; 
  86     virtual wxColour 
GetItemBackgroundColour(const wxTreeItemId
& item
) const; 
  87     virtual wxFont 
GetItemFont(const wxTreeItemId
& item
) const; 
  89     virtual void SetItemText(const wxTreeItemId
& item
, const wxString
& text
); 
  90     virtual void SetItemImage(const wxTreeItemId
& item
, 
  92                               wxTreeItemIcon which 
= wxTreeItemIcon_Normal
); 
  93     virtual void SetItemData(const wxTreeItemId
& item
, wxTreeItemData 
*data
); 
  95     virtual void SetItemHasChildren(const wxTreeItemId
& item
, bool has 
= true); 
  96     virtual void SetItemBold(const wxTreeItemId
& item
, bool bold 
= true); 
  97     virtual void SetItemDropHighlight(const wxTreeItemId
& item
, bool highlight 
= true); 
  98     virtual void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& col
); 
  99     virtual void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& col
); 
 100     virtual void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
); 
 102     virtual bool IsVisible(const wxTreeItemId
& item
) const; 
 103     virtual bool ItemHasChildren(const wxTreeItemId
& item
) const; 
 104     virtual bool IsExpanded(const wxTreeItemId
& item
) const; 
 105     virtual bool IsSelected(const wxTreeItemId
& item
) const; 
 106     virtual bool IsBold(const wxTreeItemId
& item
) const; 
 108     virtual size_t GetChildrenCount(const wxTreeItemId
& item
, 
 109                                     bool recursively 
= true) const; 
 114     virtual wxTreeItemId 
GetRootItem() const { return m_anchor
; } 
 115     virtual wxTreeItemId 
GetSelection() const 
 117         wxASSERT_MSG( !HasFlag(wxTR_MULTIPLE
), 
 118                        wxT("must use GetSelections() with this control") ); 
 122     virtual size_t GetSelections(wxArrayTreeItemIds
&) const; 
 123     virtual wxTreeItemId 
GetFocusedItem() const { return m_current
; } 
 125     virtual void ClearFocusedItem(); 
 126     virtual void SetFocusedItem(const wxTreeItemId
& item
); 
 128     virtual wxTreeItemId 
GetItemParent(const wxTreeItemId
& item
) const; 
 129     virtual wxTreeItemId 
GetFirstChild(const wxTreeItemId
& item
, 
 130                                        wxTreeItemIdValue
& cookie
) const; 
 131     virtual wxTreeItemId 
GetNextChild(const wxTreeItemId
& item
, 
 132                                       wxTreeItemIdValue
& cookie
) const; 
 133     virtual wxTreeItemId 
GetLastChild(const wxTreeItemId
& item
) const; 
 134     virtual wxTreeItemId 
GetNextSibling(const wxTreeItemId
& item
) const; 
 135     virtual wxTreeItemId 
GetPrevSibling(const wxTreeItemId
& item
) const; 
 137     virtual wxTreeItemId 
GetFirstVisibleItem() const; 
 138     virtual wxTreeItemId 
GetNextVisible(const wxTreeItemId
& item
) const; 
 139     virtual wxTreeItemId 
GetPrevVisible(const wxTreeItemId
& item
) const; 
 145     virtual wxTreeItemId 
AddRoot(const wxString
& text
, 
 146                          int image 
= -1, int selectedImage 
= -1, 
 147                          wxTreeItemData 
*data 
= NULL
); 
 149     virtual void Delete(const wxTreeItemId
& item
); 
 150     virtual void DeleteChildren(const wxTreeItemId
& item
); 
 151     virtual void DeleteAllItems(); 
 153     virtual void Expand(const wxTreeItemId
& item
); 
 154     virtual void Collapse(const wxTreeItemId
& item
); 
 155     virtual void CollapseAndReset(const wxTreeItemId
& item
); 
 156     virtual void Toggle(const wxTreeItemId
& item
); 
 158     virtual void Unselect(); 
 159     virtual void UnselectAll(); 
 160     virtual void SelectItem(const wxTreeItemId
& item
, bool select 
= true); 
 161     virtual void SelectChildren(const wxTreeItemId
& parent
); 
 163     virtual void EnsureVisible(const wxTreeItemId
& item
); 
 164     virtual void ScrollTo(const wxTreeItemId
& item
); 
 166     virtual wxTextCtrl 
*EditLabel(const wxTreeItemId
& item
, 
 167                           wxClassInfo
* textCtrlClass 
= wxCLASSINFO(wxTextCtrl
)); 
 168     virtual wxTextCtrl 
*GetEditControl() const; 
 169     virtual void EndEditLabel(const wxTreeItemId
& item
, 
 170                               bool discardChanges 
= false); 
 172     virtual void SortChildren(const wxTreeItemId
& item
); 
 177     virtual bool GetBoundingRect(const wxTreeItemId
& item
, 
 179                                  bool textOnly 
= false) const; 
 182     // this version specific methods 
 183     // ----------------------------- 
 185     wxImageList 
*GetButtonsImageList() const { return m_imageListButtons
; } 
 186     void SetButtonsImageList(wxImageList 
*imageList
); 
 187     void AssignButtonsImageList(wxImageList 
*imageList
); 
 189     void SetDropEffectAboveItem( bool above 
= false ) { m_dropEffectAboveItem 
= above
; } 
 190     bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem
; } 
 192     wxTreeItemId 
GetNext(const wxTreeItemId
& item
) const; 
 194 #if WXWIN_COMPATIBILITY_2_6 
 195     // use EditLabel() instead 
 196     void Edit( const wxTreeItemId
& item 
) { EditLabel(item
); } 
 197 #endif // WXWIN_COMPATIBILITY_2_6 
 199     // implementation only from now on 
 201     // overridden base class virtuals 
 202     virtual bool SetBackgroundColour(const wxColour
& colour
); 
 203     virtual bool SetForegroundColour(const wxColour
& colour
); 
 205     virtual void Refresh(bool eraseBackground 
= true, const wxRect 
*rect 
= NULL
); 
 207     virtual bool SetFont( const wxFont 
&font 
); 
 208     virtual void SetWindowStyle(const long styles
); 
 211     void OnPaint( wxPaintEvent 
&event 
); 
 212     void OnSetFocus( wxFocusEvent 
&event 
); 
 213     void OnKillFocus( wxFocusEvent 
&event 
); 
 214     void OnKeyDown( wxKeyEvent 
&event 
); 
 215     void OnChar( wxKeyEvent 
&event 
); 
 216     void OnMouse( wxMouseEvent 
&event 
); 
 217     void OnGetToolTip( wxTreeEvent 
&event 
); 
 218     void OnSize( wxSizeEvent 
&event 
); 
 219     void OnInternalIdle( ); 
 221     virtual wxVisualAttributes 
GetDefaultAttributes() const 
 223         return GetClassDefaultAttributes(GetWindowVariant()); 
 226     static wxVisualAttributes
 
 227     GetClassDefaultAttributes(wxWindowVariant variant 
= wxWINDOW_VARIANT_NORMAL
); 
 229     // implementation helpers 
 230     void AdjustMyScrollbars(); 
 232     WX_FORWARD_TO_SCROLL_HELPER() 
 235     friend class wxGenericTreeItem
; 
 236     friend class wxTreeRenameTimer
; 
 237     friend class wxTreeFindTimer
; 
 238     friend class wxTreeTextCtrl
; 
 243     wxGenericTreeItem   
*m_anchor
; 
 244     wxGenericTreeItem   
*m_current
, 
 246                         // A hint to select a parent item after deleting a child 
 248     unsigned short       m_indent
; 
 251     wxBrush             
*m_hilightBrush
, 
 252                         *m_hilightUnfocusedBrush
; 
 255     bool                 m_ownsImageListButtons
; 
 256     bool                 m_isDragging
; // true between BEGIN/END drag events 
 257     bool                 m_lastOnSame
;  // last click on the same item as prev 
 258     wxImageList         
*m_imageListButtons
; 
 262     wxGenericTreeItem   
*m_dropTarget
; 
 263     wxCursor             m_oldCursor
;  // cursor is changed while dragging 
 264     wxGenericTreeItem   
*m_oldSelection
; 
 265     wxGenericTreeItem   
*m_underMouse
; // for visual effects 
 267     enum { NoEffect
, BorderEffect
, AboveEffect
, BelowEffect 
} m_dndEffect
; 
 268     wxGenericTreeItem   
*m_dndEffectItem
; 
 270     wxTreeTextCtrl      
*m_textCtrl
; 
 273     wxTimer             
*m_renameTimer
; 
 275     // incremental search data 
 276     wxString             m_findPrefix
; 
 277     wxTimer             
*m_findTimer
; 
 279     bool                 m_dropEffectAboveItem
; 
 281     // the common part of all ctors 
 284     // overridden wxWindow methods 
 285     virtual void DoThaw(); 
 288     void SendDeleteEvent(wxGenericTreeItem 
*itemBeingDeleted
); 
 290     void DrawBorder(const wxTreeItemId
& item
); 
 291     void DrawLine(const wxTreeItemId
& item
, bool below
); 
 292     void DrawDropEffect(wxGenericTreeItem 
*item
); 
 294     void DoSelectItem(const wxTreeItemId
& id
, 
 295                       bool unselect_others 
= true, 
 296                       bool extended_select 
= false); 
 298     virtual int DoGetItemState(const wxTreeItemId
& item
) const; 
 299     virtual void DoSetItemState(const wxTreeItemId
& item
, int state
); 
 301     virtual wxTreeItemId 
DoInsertItem(const wxTreeItemId
& parent
, 
 303                                       const wxString
& text
, 
 306                                       wxTreeItemData 
*data
); 
 307     virtual wxTreeItemId 
DoInsertAfter(const wxTreeItemId
& parent
, 
 308                                        const wxTreeItemId
& idPrevious
, 
 309                                        const wxString
& text
, 
 310                                        int image 
= -1, int selImage 
= -1, 
 311                                        wxTreeItemData 
*data 
= NULL
); 
 312     virtual wxTreeItemId 
DoTreeHitTest(const wxPoint
& point
, int& flags
) const; 
 314     // called by wxTextTreeCtrl when it marks itself for deletion 
 315     void ResetTextControl(); 
 317     // find the first item starting with the given prefix after the given item 
 318     wxTreeItemId 
FindItem(const wxTreeItemId
& id
, const wxString
& prefix
) const; 
 320     bool HasButtons() const { return HasFlag(wxTR_HAS_BUTTONS
); } 
 322     void CalculateLineHeight(); 
 323     int  GetLineHeight(wxGenericTreeItem 
*item
) const; 
 324     void PaintLevel( wxGenericTreeItem 
*item
, wxDC
& dc
, int level
, int &y 
); 
 325     void PaintItem( wxGenericTreeItem 
*item
, wxDC
& dc
); 
 327     void CalculateLevel( wxGenericTreeItem 
*item
, wxDC 
&dc
, int level
, int &y 
); 
 328     void CalculatePositions(); 
 330     void RefreshSubtree( wxGenericTreeItem 
*item 
); 
 331     void RefreshLine( wxGenericTreeItem 
*item 
); 
 333     // redraw all selected items 
 334     void RefreshSelected(); 
 336     // RefreshSelected() recursive helper 
 337     void RefreshSelectedUnder(wxGenericTreeItem 
*item
); 
 339     void OnRenameTimer(); 
 340     bool OnRenameAccept(wxGenericTreeItem 
*item
, const wxString
& value
); 
 341     void OnRenameCancelled(wxGenericTreeItem 
*item
); 
 343     void FillArray(wxGenericTreeItem
*, wxArrayTreeItemIds
&) const; 
 344     void SelectItemRange( wxGenericTreeItem 
*item1
, wxGenericTreeItem 
*item2 
); 
 345     bool TagAllChildrenUntilLast(wxGenericTreeItem 
*crt_item
, wxGenericTreeItem 
*last_item
, bool select
); 
 346     bool TagNextChildren(wxGenericTreeItem 
*crt_item
, wxGenericTreeItem 
*last_item
, bool select
); 
 347     void UnselectAllChildren( wxGenericTreeItem 
*item 
); 
 348     void ChildrenClosing(wxGenericTreeItem
* item
); 
 350     void DoDirtyProcessing(); 
 352     virtual wxSize 
DoGetBestSize() const; 
 355     DECLARE_EVENT_TABLE() 
 356     DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl
) 
 357     wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl
); 
 360 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) 
 362  * wxTreeCtrl has to be a real class or we have problems with 
 363  * the run-time information. 
 366 class WXDLLIMPEXP_CORE wxTreeCtrl
: public wxGenericTreeCtrl
 
 368     DECLARE_DYNAMIC_CLASS(wxTreeCtrl
) 
 373     wxTreeCtrl(wxWindow 
*parent
, wxWindowID id 
= wxID_ANY
, 
 374                const wxPoint
& pos 
= wxDefaultPosition
, 
 375                const wxSize
& size 
= wxDefaultSize
, 
 376                long style 
= wxTR_DEFAULT_STYLE
, 
 377                const wxValidator 
&validator 
= wxDefaultValidator
, 
 378                const wxString
& name 
= wxTreeCtrlNameStr
) 
 379     : wxGenericTreeCtrl(parent
, id
, pos
, size
, style
, validator
, name
) 
 383 #endif // !__WXMSW__ || __WXUNIVERSAL__ 
 385 #endif // wxUSE_TREECTRL 
 387 #endif // _GENERIC_TREECTRL_H_