#include "wx/scrolwin.h"
#include "wx/pen.h"
-#include "wx/imaglist.h"
// -----------------------------------------------------------------------------
// forward declaration
// wxGenericTreeCtrl - the tree control
// -----------------------------------------------------------------------------
-class WXDLLEXPORT wxGenericTreeCtrl : public wxScrolledWindow
+class WXDLLEXPORT wxGenericTreeCtrl : public wxTreeCtrlBase,
+ public wxScrollHelper
{
public:
// creation
// --------
- wxGenericTreeCtrl() { Init(); }
+
+ wxGenericTreeCtrl() : wxTreeCtrlBase(), wxScrollHelper(this) { Init(); }
wxGenericTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
long style = wxTR_DEFAULT_STYLE,
const wxValidator &validator = wxDefaultValidator,
const wxString& name = wxTreeCtrlNameStr)
+ : wxTreeCtrlBase(),
+ wxScrollHelper(this)
{
Init();
Create(parent, id, pos, size, style, validator, name);
const wxValidator &validator = wxDefaultValidator,
const wxString& name = wxTreeCtrlNameStr);
- // accessors
- // ---------
-
- // get the total number of items in the control
- size_t GetCount() const;
-
- // indent is the number of pixels the children are indented relative to
- // the parents position. SetIndent() also redraws the control
- // immediately.
- unsigned int GetIndent() const { return m_indent; }
- void SetIndent(unsigned int indent);
-
- // spacing is the number of pixels between the start and the Text
- unsigned int GetSpacing() const { return m_spacing; }
- void SetSpacing(unsigned int spacing);
-
- // image list: these functions allow to associate an image list with
- // the control and retrieve it. Note that when assigned with
- // SetImageList, the control does _not_ delete
- // the associated image list when it's deleted in order to allow image
- // lists to be shared between different controls. If you use
- // AssignImageList, the control _does_ delete the image list.
- //
- // The normal image list is for the icons which correspond to the
- // normal tree item state (whether it is selected or not).
- // Additionally, the application might choose to show a state icon
- // which corresponds to an app-defined item state (for example,
- // checked/unchecked) which are taken from the state image list.
- virtual wxImageList *GetImageList() const;
- virtual wxImageList *GetStateImageList() const;
- virtual wxImageList *GetButtonsImageList() const;
- virtual void SetImageList(wxImageList *imageList);
- virtual void SetStateImageList(wxImageList *imageList);
- virtual void SetButtonsImageList(wxImageList *imageList);
- virtual void AssignImageList(wxImageList *imageList);
- virtual void AssignStateImageList(wxImageList *imageList);
- virtual void AssignButtonsImageList(wxImageList *imageList);
+ // implement base class pure virtuals
+ // ----------------------------------
- virtual void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
- virtual bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
+ virtual size_t GetCount() const;
- // Functions to work with tree ctrl items.
+ virtual unsigned int GetIndent() const { return m_indent; }
+ virtual void SetIndent(unsigned int indent);
- // accessors
- // ---------
- // retrieve item's label
- wxString GetItemText(const wxTreeItemId& item) const;
- // get one of the images associated with the item (normal by default)
+ virtual void SetImageList(wxImageList *imageList);
+ virtual void SetStateImageList(wxImageList *imageList);
+
+ virtual wxString GetItemText(const wxTreeItemId& item) const;
virtual int GetItemImage(const wxTreeItemId& item,
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
- // get the data associated with the item
- wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
-
- // get the item's text colour
- wxColour GetItemTextColour(const wxTreeItemId& item) const;
+ virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
+ virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
+ virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
+ virtual wxFont GetItemFont(const wxTreeItemId& item) const;
+
+ virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
+ virtual void SetItemImage(const wxTreeItemId& item,
+ int image,
+ wxTreeItemIcon which = wxTreeItemIcon_Normal);
+ virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
+
+ virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
+ virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
+ virtual void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
+ virtual void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
+ virtual void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
+ virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
+
+ virtual bool IsVisible(const wxTreeItemId& item) const;
+ virtual bool ItemHasChildren(const wxTreeItemId& item) const;
+ virtual bool IsExpanded(const wxTreeItemId& item) const;
+ virtual bool IsSelected(const wxTreeItemId& item) const;
+ virtual bool IsBold(const wxTreeItemId& item) const;
+
+ virtual size_t GetChildrenCount(const wxTreeItemId& item,
+ bool recursively = true) const;
- // get the item's background colour
- wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
+ // navigation
+ // ----------
- // get the item's font
- wxFont GetItemFont(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetRootItem() const { return m_anchor; }
+ virtual wxTreeItemId GetSelection() const { return m_current; }
+ virtual size_t GetSelections(wxArrayTreeItemIds&) const;
- // modifiers
- // ---------
+ virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const;
+ virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const;
+ virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
- // set item's label
- void SetItemText(const wxTreeItemId& item, const wxString& text);
- // get one of the images associated with the item (normal by default)
- virtual void SetItemImage(const wxTreeItemId& item, int image,
- wxTreeItemIcon which = wxTreeItemIcon_Normal);
- // associate some data with the item
- void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
+ virtual wxTreeItemId GetFirstVisibleItem() const;
+ virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
- // force appearance of [+] button near the item. This is useful to
- // allow the user to expand the items which don't have any children now
- // - but instead add them only when needed, thus minimizing memory
- // usage and loading time.
- void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
- // the item will be shown in bold
- void SetItemBold(const wxTreeItemId& item, bool bold = true);
+ // operations
+ // ----------
- // the item will be shown with a drop highlight
- void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
+ virtual wxTreeItemId AddRoot(const wxString& text,
+ int image = -1, int selectedImage = -1,
+ wxTreeItemData *data = NULL);
- // set the item's text colour
- void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
+ virtual void Delete(const wxTreeItemId& item);
+ virtual void DeleteChildren(const wxTreeItemId& item);
+ virtual void DeleteAllItems();
- // set the item's background colour
- void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
+ virtual void Expand(const wxTreeItemId& item);
+ virtual void Collapse(const wxTreeItemId& item);
+ virtual void CollapseAndReset(const wxTreeItemId& item);
+ virtual void Toggle(const wxTreeItemId& item);
- // set the item's font (should be of the same height for all items)
- void SetItemFont(const wxTreeItemId& item, const wxFont& font);
+ virtual void Unselect();
+ virtual void UnselectAll();
+ virtual void SelectItem(const wxTreeItemId& item, bool select = true);
- // set the window font
- virtual bool SetFont( const wxFont &font );
+ virtual void EnsureVisible(const wxTreeItemId& item);
+ virtual void ScrollTo(const wxTreeItemId& item);
- // set the styles. No need to specify a GetWindowStyle here since
- // the base wxWindow member function will do it for us
- void SetWindowStyle(const long styles);
-
- // item status inquiries
- // ---------------------
-
- // is the item visible (it might be outside the view or not expanded)?
- bool IsVisible(const wxTreeItemId& item) const;
- // does the item has any children?
- bool HasChildren(const wxTreeItemId& item) const
- { return ItemHasChildren(item); }
- bool ItemHasChildren(const wxTreeItemId& item) const;
- // is the item expanded (only makes sense if HasChildren())?
- bool IsExpanded(const wxTreeItemId& item) const;
- // is this item currently selected (the same as has focus)?
- bool IsSelected(const wxTreeItemId& item) const;
- // is item text in bold font?
- bool IsBold(const wxTreeItemId& item) const;
- // does the layout include space for a button?
-
- // number of children
- // ------------------
-
- // if 'recursively' is false, only immediate children count, otherwise
- // the returned number is the number of all items in this branch
- size_t GetChildrenCount(const wxTreeItemId& item,
- bool recursively = true) const;
+ virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
+ wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
+ virtual wxTextCtrl *GetEditControl() const;
+ virtual void EndEditLabel(const wxTreeItemId& item,
+ bool discardChanges = false);
- // navigation
- // ----------
+ virtual void SortChildren(const wxTreeItemId& item);
- // wxTreeItemId.IsOk() will return false if there is no such item
+ // items geometry
+ // --------------
- // get the root tree item
- wxTreeItemId GetRootItem() const { return m_anchor; }
+ virtual bool GetBoundingRect(const wxTreeItemId& item,
+ wxRect& rect,
+ bool textOnly = false) const;
- // get the item currently selected (may return NULL if no selection)
- wxTreeItemId GetSelection() const { return m_current; }
- // get the items currently selected, return the number of such item
- size_t GetSelections(wxArrayTreeItemIds&) const;
+ // this version specific methods
+ // -----------------------------
- // get the parent of this item (may return NULL if root)
- wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
+ wxImageList *GetButtonsImageList() const { return m_imageListButtons; }
+ void SetButtonsImageList(wxImageList *imageList);
+ void AssignButtonsImageList(wxImageList *imageList);
- // for this enumeration function you must pass in a "cookie" parameter
- // which is opaque for the application but is necessary for the library
- // to make these functions reentrant (i.e. allow more than one
- // enumeration on one and the same object simultaneously). Of course,
- // the "cookie" passed to GetFirstChild() and GetNextChild() should be
- // the same!
+ void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
+ bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
- // get the first child of this item
- wxTreeItemId GetFirstChild(const wxTreeItemId& item,
- wxTreeItemIdValue& cookie) const;
- // get the next child
- wxTreeItemId GetNextChild(const wxTreeItemId& item,
- wxTreeItemIdValue& cookie) const;
- // get the last child of this item - this method doesn't use cookies
- wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
-
- // get the next sibling of this item
- wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
- // get the previous sibling
- wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
-
- // get first visible item
- wxTreeItemId GetFirstVisibleItem() const;
- // get the next visible item: item must be visible itself!
- // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
- wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
- // get the previous visible item: item must be visible itself!
- wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
-
- // Only for internal use right now, but should probably be public
wxTreeItemId GetNext(const wxTreeItemId& item) const;
- // operations
- // ----------
-
- // add the root node to the tree
- virtual wxTreeItemId AddRoot(const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // insert a new item in as the first child of the parent
- virtual wxTreeItemId PrependItem(const wxTreeItemId& parent,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // insert a new item after a given one
- virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
- const wxTreeItemId& idPrevious,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // insert a new item before the one with the given index
- virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
- size_t index,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // insert a new item in as the last child of the parent
- virtual wxTreeItemId AppendItem(const wxTreeItemId& parent,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // delete this item and associated data if any
- void Delete(const wxTreeItemId& item);
- // delete all children (but don't delete the item itself)
- // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
- void DeleteChildren(const wxTreeItemId& item);
- // delete all items from the tree
- // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
- void DeleteAllItems();
-
- // expand this item
- void Expand(const wxTreeItemId& item);
- // expand this item and all subitems recursively
void ExpandAll(const wxTreeItemId& item);
- // collapse the item without removing its children
- void Collapse(const wxTreeItemId& item);
- // collapse the item and remove all children
- void CollapseAndReset(const wxTreeItemId& item);
- // toggles the current state
- void Toggle(const wxTreeItemId& item);
-
- // remove the selection from currently selected item (if any)
- void Unselect();
- // or from the given one (multiselect mode only)
- void UnselectItem(const wxTreeItemId& item) { SelectItem(item, false); }
- // or from all
- void UnselectAll();
- // select this item
- void SelectItem(const wxTreeItemId& item, bool select = true);
- // toggle the item selection
- void ToggleItemSelection(const wxTreeItemId& item)
- {
- SelectItem(item, !IsSelected(item));
- }
- // make sure this item is visible (expanding the parent item and/or
- // scrolling to this item if necessary)
- void EnsureVisible(const wxTreeItemId& item);
- // scroll to this item (but don't expand its parent)
- void ScrollTo(const wxTreeItemId& item);
- void AdjustMyScrollbars();
-
- // The first function is more portable (because easier to implement
- // on other platforms), but the second one returns some extra info.
- wxTreeItemId HitTest(const wxPoint& point)
- { int dummy; return HitTest(point, dummy); }
- wxTreeItemId HitTest(const wxPoint& point, int& flags);
-
- // get the bounding rectangle of the item (or of its label only)
- bool GetBoundingRect(const wxTreeItemId& item,
- wxRect& rect,
- bool textOnly = false) const;
-
- // Start editing the item label: this (temporarily) replaces the item
- // with a one line edit control. The item will be selected if it hadn't
- // been before.
- void EditLabel( const wxTreeItemId& item ) { Edit( item ); }
- void Edit( const wxTreeItemId& item );
- // returns a pointer to the text edit control if the item is being
- // edited, NULL otherwise (it's assumed that no more than one item may
- // be edited simultaneously)
- wxTextCtrl* GetEditControl() const;
-
- // sorting
- // this function is called to compare 2 items and should return -1, 0
- // or +1 if the first item is less than, equal to or greater than the
- // second one. The base class version performs alphabetic comparaison
- // of item labels (GetText)
- virtual int OnCompareItems(const wxTreeItemId& item1,
- const wxTreeItemId& item2);
- // sort the children of this item using OnCompareItems
- //
- // NB: this function is not reentrant and not MT-safe (FIXME)!
- void SortChildren(const wxTreeItemId& item);
+#if WXWIN_COMPATIBILITY_2_6
+ // use EditLabel() instead
+ void Edit( const wxTreeItemId& item ) { EditLabel(item); }
+#endif // WXWIN_COMPATIBILITY_2_6
#if WXWIN_COMPATIBILITY_2_4
// deprecated functions: use Set/GetItemImage directly
long& cookie) const;
#endif // WXWIN_COMPATIBILITY_2_4
- virtual bool ShouldInheritColours() const { return false; }
-
// implementation only from now on
// overridden base class virtuals
virtual void Freeze();
virtual void Thaw();
+ virtual bool SetFont( const wxFont &font );
+ virtual void SetWindowStyle(const long styles);
+
// callbacks
void OnPaint( wxPaintEvent &event );
void OnSetFocus( wxFocusEvent &event );
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
// implementation helpers
+ void AdjustMyScrollbars();
+
+ WX_FORWARD_TO_SCROLL_HELPER()
+
protected:
friend class wxGenericTreeItem;
friend class wxTreeRenameTimer;
// A hint to select a parent item after deleting a child
*m_select_me;
unsigned short m_indent;
- unsigned short m_spacing;
int m_lineHeight;
wxPen m_dottedPen;
wxBrush *m_hilightBrush,
*m_hilightUnfocusedBrush;
bool m_hasFocus;
bool m_dirty;
- bool m_ownsImageListNormal,
- m_ownsImageListState,
- m_ownsImageListButtons;
+ bool m_ownsImageListButtons;
bool m_isDragging; // true between BEGIN/END drag events
bool m_lastOnSame; // last click on the same item as prev
- wxImageList *m_imageListNormal,
- *m_imageListState,
- *m_imageListButtons;
+ wxImageList *m_imageListButtons;
int m_freezeCount;
int m_dragCount;
bool unselect_others = true,
bool extended_select = false);
- wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
- size_t previous,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data);
+ virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
+ size_t previous,
+ const wxString& text,
+ int image,
+ int selectedImage,
+ wxTreeItemData *data);
+ virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL);
+ virtual wxTreeItemId DoHitTest(const wxPoint& point, int& flags);
// called by wxTextTreeCtrl when it marks itself for deletion
void ResetTextControl();
// wxTreeCtrl
// ----------------------------------------------------------------------------
-class WXDLLEXPORT wxTreeCtrl : public wxControl
+class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase
{
public:
// creation
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTreeCtrlNameStr);
- // accessors
- // ---------
-
- // get the total number of items in the control
- size_t GetCount() const;
-
- // indent is the number of pixels the children are indented relative to
- // the parents position. SetIndent() also redraws the control
- // immediately.
- unsigned int GetIndent() const;
- void SetIndent(unsigned int indent);
-
- // spacing is the number of pixels between the start and the Text
- // not implemented under wxMSW
- unsigned int GetSpacing() const { return 18; } // return wxGTK default
- void SetSpacing(unsigned int WXUNUSED(spacing)) { }
-
- // image list: these functions allow to associate an image list with
- // the control and retrieve it. Note that the control does _not_ delete
- // the associated image list when it's deleted in order to allow image
- // lists to be shared between different controls.
- //
- // The normal image list is for the icons which correspond to the
- // normal tree item state (whether it is selected or not).
- // Additionally, the application might choose to show a state icon
- // which corresponds to an app-defined item state (for example,
- // checked/unchecked) which are taken from the state image list.
- virtual wxImageList *GetImageList() const;
- virtual wxImageList *GetStateImageList() const;
+ // implement base class pure virtuals
+ // ----------------------------------
- virtual void SetImageList(wxImageList *imageList);
- virtual void SetStateImageList(wxImageList *imageList);
- virtual void AssignImageList(wxImageList *imageList);
- virtual void AssignStateImageList(wxImageList *imageList);
+ virtual size_t GetCount() const;
- // Functions to work with tree ctrl items. Unfortunately, they can _not_ be
- // member functions of wxTreeItem because they must know the tree the item
- // belongs to for Windows implementation and storing the pointer to
- // wxTreeCtrl in each wxTreeItem is just too much waste.
+ virtual unsigned int GetIndent() const;
+ virtual void SetIndent(unsigned int indent);
- // accessors
- // ---------
+ virtual void SetImageList(wxImageList *imageList);
+ virtual void SetStateImageList(wxImageList *imageList);
- // retrieve items label
- wxString GetItemText(const wxTreeItemId& item) const;
- // get one of the images associated with the item (normal by default)
+ virtual wxString GetItemText(const wxTreeItemId& item) const;
virtual int GetItemImage(const wxTreeItemId& item,
- wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
- // get the data associated with the item
- wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
-
- // get the item's text colour
- wxColour GetItemTextColour(const wxTreeItemId& item) const;
-
- // get the item's background colour
- wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
-
- // get the item's font
- wxFont GetItemFont(const wxTreeItemId& item) const;
+ wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
+ virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
+ virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
+ virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
+ virtual wxFont GetItemFont(const wxTreeItemId& item) const;
- // modifiers
- // ---------
-
- // set items label
- void SetItemText(const wxTreeItemId& item, const wxString& text);
- // get one of the images associated with the item (normal by default)
+ virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
virtual void SetItemImage(const wxTreeItemId& item, int image,
wxTreeItemIcon which = wxTreeItemIcon_Normal);
- // associate some data with the item
- void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
-
- // force appearance of [+] button near the item. This is useful to
- // allow the user to expand the items which don't have any children now
- // - but instead add them only when needed, thus minimizing memory
- // usage and loading time.
- void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
-
- // the item will be shown in bold
- void SetItemBold(const wxTreeItemId& item, bool bold = true);
-
- // the item will be shown with a drop highlight
- void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
-
- // set the items text colour
- void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
-
- // set the items background colour
- void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
-
- // set the items font (should be of the same height for all items)
- void SetItemFont(const wxTreeItemId& item, const wxFont& font);
+ virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
+ virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
+ virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
+ virtual void SetItemDropHighlight(const wxTreeItemId& item,
+ bool highlight = true);
+ virtual void SetItemTextColour(const wxTreeItemId& item,
+ const wxColour& col);
+ virtual void SetItemBackgroundColour(const wxTreeItemId& item,
+ const wxColour& col);
+ virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
// item status inquiries
// ---------------------
- // is the item visible (it might be outside the view or not expanded)?
- bool IsVisible(const wxTreeItemId& item) const;
- // does the item has any children?
- bool ItemHasChildren(const wxTreeItemId& item) const;
- // is the item expanded (only makes sense if HasChildren())?
- bool IsExpanded(const wxTreeItemId& item) const;
- // is this item currently selected (the same as has focus)?
- bool IsSelected(const wxTreeItemId& item) const;
- // is item text in bold font?
- bool IsBold(const wxTreeItemId& item) const;
-
- // number of children
- // ------------------
-
- // if 'recursively' is false, only immediate children count, otherwise
- // the returned number is the number of all items in this branch
- size_t GetChildrenCount(const wxTreeItemId& item,
- bool recursively = true) const;
+ virtual bool IsVisible(const wxTreeItemId& item) const;
+ virtual bool ItemHasChildren(const wxTreeItemId& item) const;
+ virtual bool IsExpanded(const wxTreeItemId& item) const;
+ virtual bool IsSelected(const wxTreeItemId& item) const;
+ virtual bool IsBold(const wxTreeItemId& item) const;
+
+ virtual size_t GetChildrenCount(const wxTreeItemId& item,
+ bool recursively = true) const;
// navigation
// ----------
- // wxTreeItemId.IsOk() will return false if there is no such item
-
- // get the root tree item
- wxTreeItemId GetRootItem() const;
-
- // get the item currently selected (may return NULL if no selection)
- wxTreeItemId GetSelection() const;
-
- // get the items currently selected, return the number of such item
- //
- // NB: this operation is expensive and can take a long time for a
- // control with a lot of items (~ O(number of items)).
- size_t GetSelections(wxArrayTreeItemIds& selections) const;
-
- // get the parent of this item (may return NULL if root)
- wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
-
- // for this enumeration function you must pass in a "cookie" parameter
- // which is opaque for the application but is necessary for the library
- // to make these functions reentrant (i.e. allow more than one
- // enumeration on one and the same object simultaneously). Of course,
- // the "cookie" passed to GetFirstChild() and GetNextChild() should be
- // the same!
-
- // get the first child of this item
- wxTreeItemId GetFirstChild(const wxTreeItemId& item,
- wxTreeItemIdValue& cookie) const;
- // get the next child
- wxTreeItemId GetNextChild(const wxTreeItemId& item,
- wxTreeItemIdValue& cookie) const;
- // get the last child of this item - this method doesn't use cookies
- wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
-
- // get the next sibling of this item
- wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
- // get the previous sibling
- wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
-
- // get first visible item
- wxTreeItemId GetFirstVisibleItem() const;
- // get the next visible item: item must be visible itself!
- // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
- wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
- // get the previous visible item: item must be visible itself!
- wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetRootItem() const;
+ virtual wxTreeItemId GetSelection() const;
+ virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
+
+ virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const;
+ virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const;
+ virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
+
+ virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
+
+ virtual wxTreeItemId GetFirstVisibleItem() const;
+ virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
+ virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
// operations
// ----------
- // add the root node to the tree
virtual wxTreeItemId AddRoot(const wxString& text,
int image = -1, int selectedImage = -1,
wxTreeItemData *data = NULL);
+ virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image = -1, int selectedImage = -1,
+ wxTreeItemData *data = NULL);
- // insert a new item in as the first child of the parent
- virtual wxTreeItemId PrependItem(const wxTreeItemId& parent,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
+ virtual void Delete(const wxTreeItemId& item);
+ virtual void DeleteChildren(const wxTreeItemId& item);
+ virtual void DeleteAllItems();
- // insert a new item after a given one
- virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
- const wxTreeItemId& idPrevious,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
+ virtual void Expand(const wxTreeItemId& item);
+ virtual void Collapse(const wxTreeItemId& item);
+ virtual void CollapseAndReset(const wxTreeItemId& item);
+ virtual void Toggle(const wxTreeItemId& item);
- // insert a new item before the one with the given index
- virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
- size_t index,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
+ virtual void Unselect();
+ virtual void UnselectAll();
+ virtual void SelectItem(const wxTreeItemId& item, bool select = true);
- // insert a new item in as the last child of the parent
- virtual wxTreeItemId AppendItem(const wxTreeItemId& parent,
- const wxString& text,
- int image = -1, int selectedImage = -1,
- wxTreeItemData *data = NULL);
-
- // delete this item and associated data if any
- void Delete(const wxTreeItemId& item);
- // delete all children (but don't delete the item itself)
- // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
- void DeleteChildren(const wxTreeItemId& item);
- // delete all items from the tree
- // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
- void DeleteAllItems();
-
- // expand this item
- void Expand(const wxTreeItemId& item);
- // collapse the item without removing its children
- void Collapse(const wxTreeItemId& item);
- // collapse the item and remove all children
- void CollapseAndReset(const wxTreeItemId& item);
- // toggles the current state
- void Toggle(const wxTreeItemId& item);
-
- // remove the selection from currently selected item (if any)
- void Unselect();
- // unselect all items (only makes sense for multiple selection control)
- void UnselectAll();
- // select this item
- void SelectItem(const wxTreeItemId& item, bool select = true);
- // unselect this item
- void UnselectItem(const wxTreeItemId& item);
- // toggle item selection
- void ToggleItemSelection(const wxTreeItemId& item);
-
- // make sure this item is visible (expanding the parent item and/or
- // scrolling to this item if necessary)
- void EnsureVisible(const wxTreeItemId& item);
- // scroll to this item (but don't expand its parent)
- void ScrollTo(const wxTreeItemId& item);
-
- // start editing the item label: this (temporarily) replaces the item
- // with a one line edit control. The item will be selected if it hadn't
- // been before. textCtrlClass parameter allows you to create an edit
- // control of arbitrary user-defined class deriving from wxTextCtrl.
- wxTextCtrl* EditLabel(const wxTreeItemId& item,
+ virtual void EnsureVisible(const wxTreeItemId& item);
+ virtual void ScrollTo(const wxTreeItemId& item);
+
+ virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
- // returns the same pointer as StartEdit() if the item is being edited,
- // NULL otherwise (it's assumed that no more than one item may be
- // edited simultaneously)
- wxTextCtrl* GetEditControl() const;
- // end editing and accept or discard the changes to item label
- void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
- bool discardChanges = false)
+ virtual wxTextCtrl *GetEditControl() const;
+ virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
+ bool discardChanges = false)
{
DoEndEditLabel(discardChanges);
}
- // sorting
- // this function is called to compare 2 items and should return -1, 0
- // or +1 if the first item is less than, equal to or greater than the
- // second one. The base class version performs alphabetic comparaison
- // of item labels (GetText)
- virtual int OnCompareItems(const wxTreeItemId& item1,
- const wxTreeItemId& item2);
- // sort the children of this item using OnCompareItems
- //
- // NB: this function is not reentrant and not MT-safe (FIXME)!
- void SortChildren(const wxTreeItemId& item);
-
- // helpers
- // -------
-
- // determine to which item (if any) belongs the given point (the
- // coordinates specified are relative to the client area of tree ctrl)
- // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx
- // constants.
- //
- // The first function is more portable (because easier to implement
- // on other platforms), but the second one returns some extra info.
- wxTreeItemId HitTest(const wxPoint& point)
- { int dummy; return HitTest(point, dummy); }
- wxTreeItemId HitTest(const wxPoint& point, int& flags);
-
- // get the bounding rectangle of the item (or of its label only)
- bool GetBoundingRect(const wxTreeItemId& item,
- wxRect& rect,
- bool textOnly = false) const;
+ virtual void SortChildren(const wxTreeItemId& item);
+
+ virtual bool GetBoundingRect(const wxTreeItemId& item,
+ wxRect& rect,
+ bool textOnly = false) const;
// deprecated
// ----------
// implementation
// --------------
- virtual bool ShouldInheritColours() const { return false; }
-
virtual wxVisualAttributes GetDefaultAttributes() const
{
return GetClassDefaultAttributes(GetWindowVariant());
int GetState(const wxTreeItemId& node);
protected:
- virtual wxSize DoGetBestSize() const;
-
-
// SetImageList helper
void SetAnyImageList(wxImageList *imageList, int which);
inline void DoExpand(const wxTreeItemId& item, int flag);
- wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
- wxTreeItemId hInsertAfter,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data);
+ virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
+ size_t pos,
+ const wxString& text,
+ int image, int selectedImage,
+ wxTreeItemData *data);
+ virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL);
+ virtual wxTreeItemId DoHitTest(const wxPoint& point, int& flags);
int DoGetItemImageFromData(const wxTreeItemId& item,
wxTreeItemIcon which) const;
#include "wx/treebase.h"
+class WXDLLEXPORT wxImageList;
+
+// ----------------------------------------------------------------------------
+// wxTreeCtrlBase
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxTreeCtrlBase : public wxControl
+{
+public:
+ wxTreeCtrlBase()
+ {
+ m_imageListNormal =
+ m_imageListState = NULL;
+ m_ownsImageListNormal =
+ m_ownsImageListState = false;
+
+ // arbitrary default
+ m_spacing = 18;
+ }
+
+ virtual ~wxTreeCtrlBase();
+
+ // accessors
+ // ---------
+
+ // get the total number of items in the control
+ virtual size_t GetCount() const = 0;
+
+ // indent is the number of pixels the children are indented relative to
+ // the parents position. SetIndent() also redraws the control
+ // immediately.
+ virtual unsigned int GetIndent() const = 0;
+ virtual void SetIndent(unsigned int indent) = 0;
+
+ // spacing is the number of pixels between the start and the Text
+ // (has no effect under wxMSW)
+ unsigned int GetSpacing() const { return m_spacing; }
+ void SetSpacing(unsigned int spacing) { m_spacing = spacing; }
+
+ // image list: these functions allow to associate an image list with
+ // the control and retrieve it. Note that the control does _not_ delete
+ // the associated image list when it's deleted in order to allow image
+ // lists to be shared between different controls.
+ //
+ // The normal image list is for the icons which correspond to the
+ // normal tree item state (whether it is selected or not).
+ // Additionally, the application might choose to show a state icon
+ // which corresponds to an app-defined item state (for example,
+ // checked/unchecked) which are taken from the state image list.
+ wxImageList *GetImageList() const { return m_imageListNormal; }
+ wxImageList *GetStateImageList() const { return m_imageListState; }
+
+ virtual void SetImageList(wxImageList *imageList) = 0;
+ virtual void SetStateImageList(wxImageList *imageList) = 0;
+ void AssignImageList(wxImageList *imageList)
+ {
+ SetImageList(imageList);
+ m_ownsImageListNormal = true;
+ }
+ void AssignStateImageList(wxImageList *imageList)
+ {
+ SetStateImageList(imageList);
+ m_ownsImageListState = true;
+ }
+
+
+ // Functions to work with tree ctrl items. Unfortunately, they can _not_ be
+ // member functions of wxTreeItem because they must know the tree the item
+ // belongs to for Windows implementation and storing the pointer to
+ // wxTreeCtrl in each wxTreeItem is just too much waste.
+
+ // accessors
+ // ---------
+
+ // retrieve items label
+ virtual wxString GetItemText(const wxTreeItemId& item) const = 0;
+ // get one of the images associated with the item (normal by default)
+ virtual int GetItemImage(const wxTreeItemId& item,
+ wxTreeItemIcon which = wxTreeItemIcon_Normal) const = 0;
+ // get the data associated with the item
+ virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const = 0;
+
+ // get the item's text colour
+ virtual wxColour GetItemTextColour(const wxTreeItemId& item) const = 0;
+
+ // get the item's background colour
+ virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const = 0;
+
+ // get the item's font
+ virtual wxFont GetItemFont(const wxTreeItemId& item) const = 0;
+
+ // modifiers
+ // ---------
+
+ // set items label
+ virtual void SetItemText(const wxTreeItemId& item, const wxString& text) = 0;
+ // get one of the images associated with the item (normal by default)
+ virtual void SetItemImage(const wxTreeItemId& item,
+ int image,
+ wxTreeItemIcon which = wxTreeItemIcon_Normal) = 0;
+ // associate some data with the item
+ virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data) = 0;
+
+ // force appearance of [+] button near the item. This is useful to
+ // allow the user to expand the items which don't have any children now
+ // - but instead add them only when needed, thus minimizing memory
+ // usage and loading time.
+ virtual void SetItemHasChildren(const wxTreeItemId& item,
+ bool has = true) = 0;
+
+ // the item will be shown in bold
+ virtual void SetItemBold(const wxTreeItemId& item, bool bold = true) = 0;
+
+ // the item will be shown with a drop highlight
+ virtual void SetItemDropHighlight(const wxTreeItemId& item,
+ bool highlight = true) = 0;
+
+ // set the items text colour
+ virtual void SetItemTextColour(const wxTreeItemId& item,
+ const wxColour& col) = 0;
+
+ // set the items background colour
+ virtual void SetItemBackgroundColour(const wxTreeItemId& item,
+ const wxColour& col) = 0;
+
+ // set the items font (should be of the same height for all items)
+ virtual void SetItemFont(const wxTreeItemId& item,
+ const wxFont& font) = 0;
+
+ // item status inquiries
+ // ---------------------
+
+ // is the item visible (it might be outside the view or not expanded)?
+ virtual bool IsVisible(const wxTreeItemId& item) const = 0;
+ // does the item has any children?
+ virtual bool ItemHasChildren(const wxTreeItemId& item) const = 0;
+ // same as above
+ bool HasChildren(const wxTreeItemId& item) const
+ { return ItemHasChildren(item); }
+ // is the item expanded (only makes sense if HasChildren())?
+ virtual bool IsExpanded(const wxTreeItemId& item) const = 0;
+ // is this item currently selected (the same as has focus)?
+ virtual bool IsSelected(const wxTreeItemId& item) const = 0;
+ // is item text in bold font?
+ virtual bool IsBold(const wxTreeItemId& item) const = 0;
+
+ // number of children
+ // ------------------
+
+ // if 'recursively' is false, only immediate children count, otherwise
+ // the returned number is the number of all items in this branch
+ virtual size_t GetChildrenCount(const wxTreeItemId& item,
+ bool recursively = true) const = 0;
+
+ // navigation
+ // ----------
+
+ // wxTreeItemId.IsOk() will return false if there is no such item
+
+ // get the root tree item
+ virtual wxTreeItemId GetRootItem() const = 0;
+
+ // get the item currently selected (may return NULL if no selection)
+ virtual wxTreeItemId GetSelection() const = 0;
+
+ // get the items currently selected, return the number of such item
+ //
+ // NB: this operation is expensive and can take a long time for a
+ // control with a lot of items (~ O(number of items)).
+ virtual size_t GetSelections(wxArrayTreeItemIds& selections) const = 0;
+
+ // get the parent of this item (may return NULL if root)
+ virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const = 0;
+
+ // for this enumeration function you must pass in a "cookie" parameter
+ // which is opaque for the application but is necessary for the library
+ // to make these functions reentrant (i.e. allow more than one
+ // enumeration on one and the same object simultaneously). Of course,
+ // the "cookie" passed to GetFirstChild() and GetNextChild() should be
+ // the same!
+
+ // get the first child of this item
+ virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const = 0;
+ // get the next child
+ virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
+ wxTreeItemIdValue& cookie) const = 0;
+ // get the last child of this item - this method doesn't use cookies
+ virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const = 0;
+
+ // get the next sibling of this item
+ virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const = 0;
+ // get the previous sibling
+ virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const = 0;
+
+ // get first visible item
+ virtual wxTreeItemId GetFirstVisibleItem() const = 0;
+ // get the next visible item: item must be visible itself!
+ // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
+ virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const = 0;
+ // get the previous visible item: item must be visible itself!
+ virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const = 0;
+
+ // operations
+ // ----------
+
+ // add the root node to the tree
+ virtual wxTreeItemId AddRoot(const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL) = 0;
+
+ // insert a new item in as the first child of the parent
+ wxTreeItemId PrependItem(const wxTreeItemId& parent,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL)
+ {
+ return DoInsertItem(parent, 0u, text, image, selImage, data);
+ }
+
+ // insert a new item after a given one
+ wxTreeItemId InsertItem(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL)
+ {
+ return DoInsertAfter(parent, idPrevious, text, image, selImage, data);
+ }
+
+ // insert a new item before the one with the given index
+ wxTreeItemId InsertItem(const wxTreeItemId& parent,
+ size_t pos,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL)
+ {
+ return DoInsertItem(parent, pos, text, image, selImage, data);
+ }
+
+ // insert a new item in as the last child of the parent
+ wxTreeItemId AppendItem(const wxTreeItemId& parent,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL)
+ {
+ return DoInsertItem(parent, (size_t)-1, text, image, selImage, data);
+ }
+
+ // delete this item and associated data if any
+ virtual void Delete(const wxTreeItemId& item) = 0;
+ // delete all children (but don't delete the item itself)
+ // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
+ virtual void DeleteChildren(const wxTreeItemId& item) = 0;
+ // delete all items from the tree
+ // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
+ virtual void DeleteAllItems() = 0;
+
+ // expand this item
+ virtual void Expand(const wxTreeItemId& item) = 0;
+ // collapse the item without removing its children
+ virtual void Collapse(const wxTreeItemId& item) = 0;
+ // collapse the item and remove all children
+ virtual void CollapseAndReset(const wxTreeItemId& item) = 0;
+ // toggles the current state
+ virtual void Toggle(const wxTreeItemId& item) = 0;
+
+ // remove the selection from currently selected item (if any)
+ virtual void Unselect() = 0;
+ // unselect all items (only makes sense for multiple selection control)
+ virtual void UnselectAll() = 0;
+ // select this item
+ virtual void SelectItem(const wxTreeItemId& item, bool select = true) = 0;
+ // unselect this item
+ void UnselectItem(const wxTreeItemId& item) { SelectItem(item, false); }
+ // toggle item selection
+ void ToggleItemSelection(const wxTreeItemId& item)
+ {
+ SelectItem(item, !IsSelected(item));
+ }
+
+ // make sure this item is visible (expanding the parent item and/or
+ // scrolling to this item if necessary)
+ virtual void EnsureVisible(const wxTreeItemId& item) = 0;
+ // scroll to this item (but don't expand its parent)
+ virtual void ScrollTo(const wxTreeItemId& item) = 0;
+
+ // start editing the item label: this (temporarily) replaces the item
+ // with a one line edit control. The item will be selected if it hadn't
+ // been before. textCtrlClass parameter allows you to create an edit
+ // control of arbitrary user-defined class deriving from wxTextCtrl.
+ virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
+ wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)) = 0;
+ // returns the same pointer as StartEdit() if the item is being edited,
+ // NULL otherwise (it's assumed that no more than one item may be
+ // edited simultaneously)
+ virtual wxTextCtrl *GetEditControl() const = 0;
+ // end editing and accept or discard the changes to item label
+ virtual void EndEditLabel(const wxTreeItemId& item,
+ bool discardChanges = false) = 0;
+
+ // sorting
+ // -------
+
+ // this function is called to compare 2 items and should return -1, 0
+ // or +1 if the first item is less than, equal to or greater than the
+ // second one. The base class version performs alphabetic comparaison
+ // of item labels (GetText)
+ virtual int OnCompareItems(const wxTreeItemId& item1,
+ const wxTreeItemId& item2)
+ {
+ return wxStrcmp(GetItemText(item1), GetItemText(item2));
+ }
+
+ // sort the children of this item using OnCompareItems
+ //
+ // NB: this function is not reentrant and not MT-safe (FIXME)!
+ virtual void SortChildren(const wxTreeItemId& item) = 0;
+
+ // items geometry
+ // --------------
+
+ // determine to which item (if any) belongs the given point (the
+ // coordinates specified are relative to the client area of tree ctrl)
+ // and, in the second variant, fill the flags parameter with a bitmask
+ // of wxTREE_HITTEST_xxx constants.
+ wxTreeItemId HitTest(const wxPoint& point)
+ { int dummy; return DoHitTest(point, dummy); }
+ wxTreeItemId HitTest(const wxPoint& point, int& flags)
+ { return DoHitTest(point, flags); }
+
+ // get the bounding rectangle of the item (or of its label only)
+ virtual bool GetBoundingRect(const wxTreeItemId& item,
+ wxRect& rect,
+ bool textOnly = false) const = 0;
+
+
+ // implementation
+ // --------------
+
+ virtual bool ShouldInheritColours() const { return false; }
+
+protected:
+ virtual wxSize DoGetBestSize() const;
+
+ // common part of Append/Prepend/InsertItem()
+ //
+ // pos is the position at which to insert the item or (size_t)-1 to append
+ // it to the end
+ virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
+ size_t pos,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data) = 0;
+
+ // and this function implements overloaded InsertItem() taking wxTreeItemId
+ // (it can't be called InsertItem() as we'd have virtual function hiding
+ // problem in derived classes then)
+ virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image = -1, int selImage = -1,
+ wxTreeItemData *data = NULL) = 0;
+
+ // real HitTest() implementation: again, can't be called just HitTest()
+ // because it's overloaded and so the non-virtual overload would be hidden
+ virtual wxTreeItemId DoHitTest(const wxPoint& point, int& flags) = 0;
+
+
+ wxImageList *m_imageListNormal, // images for tree elements
+ *m_imageListState; // special images for app defined states
+ bool m_ownsImageListNormal,
+ m_ownsImageListState;
+
+ // spacing between left border and the text
+ unsigned short m_spacing;
+
+
+ DECLARE_NO_COPY_CLASS(wxTreeCtrlBase)
+};
+
// ----------------------------------------------------------------------------
// include the platform-dependent wxTreeCtrl class
// ----------------------------------------------------------------------------
#include "wx/generic/treectlg.h"
#endif
-/*
-#if !defined(__WXMSW__)
-#define wxTreeCtrl wxGenericTreeCtrl
-#endif
-*/
-
#endif // _WX_TREECTRL_H_BASE_
#if wxUSE_TREECTRL
-#include "wx/treebase.h"
-#include "wx/settings.h"
-#include "wx/log.h"
-#include "wx/intl.h"
-#include "wx/dynarray.h"
-#include "wx/arrimpl.cpp"
-#include "wx/dcclient.h"
-
+#include "wx/treectrl.h"
// ----------------------------------------------------------------------------
// events
m_editCancelled = event.m_editCancelled;
}
+// ----------------------------------------------------------------------------
+// wxTreeCtrlBase
+// ----------------------------------------------------------------------------
+
+wxTreeCtrlBase::~wxTreeCtrlBase()
+{
+ if (m_ownsImageListNormal)
+ delete m_imageListNormal;
+ if (m_ownsImageListState)
+ delete m_imageListState;
+}
+
+wxSize wxTreeCtrlBase::DoGetBestSize() const
+{
+ wxSize size;
+
+ // this doesn't really compute the total bounding rectangle of all items
+ // but a not too bad guess of it which has the advantage of not having to
+ // examine all (potentially hundreds or thousands) items in the control
+ for ( wxTreeItemId item = GetRootItem();
+ item.IsOk();
+ item = GetLastChild(item) )
+ {
+ wxRect rect;
+
+ // last parameter is "true" to get only the dimensions of the text
+ // label, we don't want to get the entire item width as it's determined
+ // by the current size
+ if ( GetBoundingRect(item, rect, true) )
+ {
+ if ( size.x < rect.x + rect.width )
+ size.x = rect.x + rect.width;
+ if ( size.y < rect.y + rect.height )
+ size.y = rect.y + rect.height;
+ }
+ }
+
+ // need some minimal size even for empty tree
+ if ( !size.x || !size.y )
+ size = wxControl::DoGetBestSize();
+
+ return size;
+}
+
#endif // wxUSE_TREECTRL
#if wxUSE_TREECTRL
#include "wx/treebase.h"
+#include "wx/treectrl.h"
#include "wx/generic/treectlg.h"
#include "wx/timer.h"
#include "wx/textctrl.h"
public:
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
+ void EndEdit(bool discardChanges = false)
+ {
+ if ( discardChanges )
+ {
+ StopEditing();
+ }
+ else
+ {
+ m_aboutToFinish = true;
+
+ // Notify the owner about the changes
+ AcceptChanges();
+
+ // Even if vetoed, close the control (consistent with MSW)
+ Finish();
+ }
+ }
+
void StopEditing()
{
Finish();
m_finished = true;
- m_owner->SetFocusIgnoringChildren();
+ m_owner->SetFocus();
}
}
switch ( event.m_keyCode )
{
case WXK_RETURN:
- m_aboutToFinish = true;
- // Notify the owner about the changes
- AcceptChanges();
- // Even if vetoed, close the control (consistent with MSW)
- Finish();
+ EndEdit();
break;
case WXK_ESCAPE:
// wxGenericTreeCtrl implementation
// -----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl, wxScrolledWindow)
+IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl, wxControl)
-BEGIN_EVENT_TABLE(wxGenericTreeCtrl,wxScrolledWindow)
+BEGIN_EVENT_TABLE(wxGenericTreeCtrl, wxTreeCtrlBase)
EVT_PAINT (wxGenericTreeCtrl::OnPaint)
EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse)
EVT_CHAR (wxGenericTreeCtrl::OnChar)
void wxGenericTreeCtrl::Init()
{
- m_current = m_key_current = m_anchor = m_select_me = (wxGenericTreeItem *) NULL;
+ m_current =
+ m_key_current =
+ m_anchor =
+ m_select_me = (wxGenericTreeItem *) NULL;
m_hasFocus = false;
m_dirty = false;
wxSOLID
);
- m_imageListNormal = m_imageListButtons =
- m_imageListState = (wxImageList *) NULL;
- m_ownsImageListNormal = m_ownsImageListButtons =
- m_ownsImageListState = false;
+ m_imageListButtons = NULL;
+ m_ownsImageListButtons = false;
m_dragCount = 0;
m_isDragging = false;
const wxPoint& pos,
const wxSize& size,
long style,
- const wxValidator& wxVALIDATOR_PARAM(validator),
+ const wxValidator& validator,
const wxString& name )
{
#ifdef __WXMAC__
style |= wxTR_ROW_LINES;
#endif // __WXMAC__
- wxScrolledWindow::Create( parent, id, pos, size,
- style|wxHSCROLL|wxVSCROLL, name );
+ if ( !wxControl::Create( parent, id, pos, size,
+ style|wxHSCROLL|wxVSCROLL,
+ validator,
+ name ) )
+ return false;
// If the tree display has no buttons, but does have
// connecting lines, we can use a narrower layout.
m_spacing = 10;
}
-#if wxUSE_VALIDATORS
- SetValidator( validator );
-#endif
-
wxVisualAttributes attr = GetDefaultAttributes();
SetOwnForegroundColour( attr.colFg );
SetOwnBackgroundColour( attr.colBg );
if (!m_hasFont)
SetOwnFont(attr.font);
-// m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
m_dottedPen = wxPen( wxT("grey"), 0, 0 );
SetBestSize(size);
delete m_renameTimer;
delete m_findTimer;
- if (m_ownsImageListNormal)
- delete m_imageListNormal;
- if (m_ownsImageListState)
- delete m_imageListState;
if (m_ownsImageListButtons)
delete m_imageListButtons;
}
m_dirty = true;
}
-void wxGenericTreeCtrl::SetSpacing(unsigned int spacing)
-{
- m_spacing = (unsigned short) spacing;
- m_dirty = true;
-}
-
size_t
wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
bool recursively) const
bool wxGenericTreeCtrl::SetFont( const wxFont &font )
{
- wxScrolledWindow::SetFont(font);
+ wxTreeCtrlBase::SetFont(font);
m_normalFont = font ;
m_boldFont = wxFont(m_normalFont.GetPointSize(),
// -----------------------------------------------------------------------------
wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
- size_t previous,
- const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
+ size_t previous,
+ const wxString& text,
+ int image,
+ int selImage,
+ wxTreeItemData *data)
{
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
if ( !parent )
data->m_pItem = item;
}
- parent->Insert( item, previous );
+ parent->Insert( item, previous == (size_t)-1 ? parent->GetChildren().size()
+ : previous );
return item;
}
wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
+ int image,
+ int selImage,
+ wxTreeItemData *data)
{
wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
return m_anchor;
}
-wxTreeItemId wxGenericTreeCtrl::PrependItem(const wxTreeItemId& parent,
- const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, 0u, text, image, selImage, data);
-}
-
-wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
- const wxTreeItemId& idPrevious,
- const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
+wxTreeItemId wxGenericTreeCtrl::DoInsertAfter(const wxTreeItemId& parentId,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
{
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
if ( !parent )
return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data);
}
-wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
- size_t before,
- const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
-{
- wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
- if ( !parent )
- {
- // should we give a warning here?
- return AddRoot(text, image, selImage, data);
- }
-
- return DoInsertItem(parentId, before, text, image, selImage, data);
-}
-
-wxTreeItemId wxGenericTreeCtrl::AppendItem(const wxTreeItemId& parentId,
- const wxString& text,
- int image, int selImage,
- wxTreeItemData *data)
-{
- wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
- if ( !parent )
- {
- // should we give a warning here?
- return AddRoot(text, image, selImage, data);
- }
-
- return DoInsertItem( parent, parent->GetChildren().Count(), text,
- image, selImage, data);
-}
void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
{
return s_treeBeingSorted->OnCompareItems(*item1, *item2);
}
-int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
- const wxTreeItemId& item2)
-{
- return wxStrcmp(GetItemText(item1), GetItemText(item2));
-}
-
void wxGenericTreeCtrl::SortChildren(const wxTreeItemId& itemId)
{
wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") );
//else: don't make the tree dirty as nothing changed
}
-wxImageList *wxGenericTreeCtrl::GetImageList() const
-{
- return m_imageListNormal;
-}
-
-wxImageList *wxGenericTreeCtrl::GetButtonsImageList() const
-{
- return m_imageListButtons;
-}
-
-wxImageList *wxGenericTreeCtrl::GetStateImageList() const
-{
- return m_imageListState;
-}
-
void wxGenericTreeCtrl::CalculateLineHeight()
{
wxClientDC dc(this);
CalculateLineHeight();
}
-void wxGenericTreeCtrl::AssignImageList(wxImageList *imageList)
-{
- SetImageList(imageList);
- m_ownsImageListNormal = true;
-}
-
-void wxGenericTreeCtrl::AssignStateImageList(wxImageList *imageList)
-{
- SetStateImageList(imageList);
- m_ownsImageListState = true;
-}
-
void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList *imageList)
{
SetButtonsImageList(imageList);
}
else
{
- colBg = m_backgroundColour;
+ colBg = GetBackgroundColour();
}
dc.SetBrush(wxBrush(colBg, wxSOLID));
}
}
}
-wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxGenericTreeCtrl::DoHitTest(const wxPoint& point, int& flags)
{
// JACS: removed wxYieldIfNeeded() because it can cause the window
// to be deleted from under us if a close window event is pending
return true;
}
-void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
+wxTextCtrl *wxGenericTreeCtrl::EditLabel(const wxTreeItemId& item,
+ wxClassInfo * WXUNUSED(textCtrlClass))
{
- wxCHECK_RET( item.IsOk(), _T("can't edit an invalid item") );
+ wxCHECK_MSG( item.IsOk(), NULL, _T("can't edit an invalid item") );
wxGenericTreeItem *itemEdit = (wxGenericTreeItem *)item.m_pItem;
if ( GetEventHandler()->ProcessEvent( te ) && !te.IsAllowed() )
{
// vetoed by user
- return;
+ return NULL;
}
// We have to call this here because the label in
wxYieldIfNeeded();
#endif
+ // TODO: use textCtrlClass here to create the control of correct class
m_textCtrl = new wxTreeTextCtrl(this, itemEdit);
m_textCtrl->SetFocus();
+
+ return m_textCtrl;
}
// returns a pointer to the text edit control if the item is being
return m_textCtrl;
}
+void wxGenericTreeCtrl::EndEditLabel(const wxTreeItemId& WXUNUSED(item),
+ bool discardChanges)
+{
+ wxCHECK_RET( m_textCtrl, _T("not editing label") );
+
+ m_textCtrl->EndEdit(discardChanges);
+}
+
bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem *item,
const wxString& value)
{
void wxTreeCtrl::Init()
{
- m_imageListNormal = NULL;
- m_imageListState = NULL;
- m_ownsImageListNormal = m_ownsImageListState = false;
m_textCtrl = NULL;
m_hasAnyAttr = false;
m_dragImage = NULL;
// delete user data to prevent memory leaks
// also deletes hidden root node storage.
DeleteAllItems();
-
- if (m_ownsImageListNormal) delete m_imageListNormal;
- if (m_ownsImageListState) delete m_imageListState;
}
// ----------------------------------------------------------------------------
TreeView_SetIndent(GetHwnd(), indent);
}
-wxImageList *wxTreeCtrl::GetImageList() const
-{
- return m_imageListNormal;
-}
-
-wxImageList *wxTreeCtrl::GetStateImageList() const
-{
- return m_imageListState;
-}
-
void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
{
// no error return
m_ownsImageListState = false;
}
-void wxTreeCtrl::AssignImageList(wxImageList *imageList)
-{
- SetImageList(imageList);
- m_ownsImageListNormal = true;
-}
-
-void wxTreeCtrl::AssignStateImageList(wxImageList *imageList)
-{
- SetStateImageList(imageList);
- m_ownsImageListState = true;
-}
-
size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
bool recursively) const
{
// Usual operations
// ----------------------------------------------------------------------------
-wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
- wxTreeItemId hInsertAfter,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent,
+ const wxTreeItemId& hInsertAfter,
+ const wxString& text,
+ int image, int selectedImage,
+ wxTreeItemData *data)
{
wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
wxTreeItemId(),
int image, int selImage,
long insertAfter)
{
- return DoInsertItem(parent, wxTreeItemId((void *)insertAfter), text,
- image, selImage, NULL);
+ return DoInsertAfter(parent,
+ wxTreeItemId(wxUIntToPtr(insertAfter)),
+ text,
+ image,
+ selImage,
+ NULL);
}
wxImageList *wxTreeCtrl::GetImageList(int) const
return TVI_ROOT;
}
- return DoInsertItem(wxTreeItemId(), wxTreeItemId(),
- text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, TVI_FIRST,
- text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
- const wxTreeItemId& idPrevious,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, idPrevious, text, image, selectedImage, data);
+ return DoInsertAfter(wxTreeItemId(), wxTreeItemId(),
+ text, image, selectedImage, data);
}
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
- size_t index,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
+ size_t index,
+ const wxString& text,
+ int image, int selectedImage,
+ wxTreeItemData *data)
{
- // find the item from index
- wxTreeItemIdValue cookie;
- wxTreeItemId idPrev, idCur = GetFirstChild(parent, cookie);
- while ( index != 0 && idCur.IsOk() )
+ wxTreeItemId idPrev;
+ if ( index == (size_t)-1 )
{
- index--;
-
- idPrev = idCur;
- idCur = GetNextChild(parent, cookie);
+ // special value: append to the end
+ idPrev = TVI_LAST;
}
+ else // find the item from index
+ {
+ wxTreeItemIdValue cookie;
+ wxTreeItemId idCur = GetFirstChild(parent, cookie);
+ while ( index != 0 && idCur.IsOk() )
+ {
+ index--;
- // assert, not check: if the index is invalid, we will append the item
- // to the end
- wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+ idPrev = idCur;
+ idCur = GetNextChild(parent, cookie);
+ }
- return DoInsertItem(parent, idPrev, text, image, selectedImage, data);
-}
+ // assert, not check: if the index is invalid, we will append the item
+ // to the end
+ wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+ }
-wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
- const wxString& text,
- int image, int selectedImage,
- wxTreeItemData *data)
-{
- return DoInsertItem(parent, TVI_LAST,
- text, image, selectedImage, data);
+ return DoInsertAfter(parent, idPrev, text, image, selectedImage, data);
}
void wxTreeCtrl::Delete(const wxTreeItemId& item)
DeleteTextCtrl();
}
-wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxTreeCtrl::DoHitTest(const wxPoint& point, int& flags)
{
TV_HITTESTINFO hitTestInfo;
hitTestInfo.pt.x = (int)point.x;
}
}
-wxSize wxTreeCtrl::DoGetBestSize() const
-{
- wxSize size;
-
- // this doesn't really compute the total bounding rectangle of all items
- // but a not too bad guess of it which has the advantage of not having to
- // examine all (potentially hundreds or thousands) items in the control
- for ( wxTreeItemId item = GetRootItem();
- item.IsOk();
- item = GetLastChild(item) )
- {
- wxRect rect;
-
- // last parameter is "true" to get only the dimensions of the text
- // label, we don't want to get the entire item width as it's determined
- // by the current size
- if ( GetBoundingRect(item, rect, true) )
- {
- if ( size.x < rect.x + rect.width )
- size.x = rect.x + rect.width;
- if ( size.y < rect.y + rect.height )
- size.y = rect.y + rect.height;
- }
- }
-
- // need some minimal size even for empty tree
- if ( !size.x || !size.y )
- size = wxControl::DoGetBestSize();
-
- return size;
-}
-
// ----------------------------------------------------------------------------
// sorting stuff
// ----------------------------------------------------------------------------