introduced a common base class for both MSW and generic wxTreeCtrl implementations
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/scrolwin.h"
|
||||||
#include "wx/pen.h"
|
#include "wx/pen.h"
|
||||||
#include "wx/imaglist.h"
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// forward declaration
|
// forward declaration
|
||||||
@@ -35,12 +34,14 @@ class WXDLLEXPORT wxTextCtrl;
|
|||||||
// wxGenericTreeCtrl - the tree control
|
// wxGenericTreeCtrl - the tree control
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxGenericTreeCtrl : public wxScrolledWindow
|
class WXDLLEXPORT wxGenericTreeCtrl : public wxTreeCtrlBase,
|
||||||
|
public wxScrollHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// creation
|
// creation
|
||||||
// --------
|
// --------
|
||||||
wxGenericTreeCtrl() { Init(); }
|
|
||||||
|
wxGenericTreeCtrl() : wxTreeCtrlBase(), wxScrollHelper(this) { Init(); }
|
||||||
|
|
||||||
wxGenericTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
|
wxGenericTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
@@ -48,6 +49,8 @@ public:
|
|||||||
long style = wxTR_DEFAULT_STYLE,
|
long style = wxTR_DEFAULT_STYLE,
|
||||||
const wxValidator &validator = wxDefaultValidator,
|
const wxValidator &validator = wxDefaultValidator,
|
||||||
const wxString& name = wxTreeCtrlNameStr)
|
const wxString& name = wxTreeCtrlNameStr)
|
||||||
|
: wxTreeCtrlBase(),
|
||||||
|
wxScrollHelper(this)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
Create(parent, id, pos, size, style, validator, name);
|
Create(parent, id, pos, size, style, validator, name);
|
||||||
@@ -62,290 +65,127 @@ public:
|
|||||||
const wxValidator &validator = wxDefaultValidator,
|
const wxValidator &validator = wxDefaultValidator,
|
||||||
const wxString& name = wxTreeCtrlNameStr);
|
const wxString& name = wxTreeCtrlNameStr);
|
||||||
|
|
||||||
// accessors
|
|
||||||
// ---------
|
|
||||||
|
|
||||||
// get the total number of items in the control
|
// implement base class pure virtuals
|
||||||
size_t GetCount() const;
|
// ----------------------------------
|
||||||
|
|
||||||
// indent is the number of pixels the children are indented relative to
|
virtual size_t GetCount() const;
|
||||||
// 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
|
virtual unsigned int GetIndent() const { return m_indent; }
|
||||||
unsigned int GetSpacing() const { return m_spacing; }
|
virtual void SetIndent(unsigned int indent);
|
||||||
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 SetImageList(wxImageList *imageList);
|
||||||
virtual void SetStateImageList(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);
|
|
||||||
|
|
||||||
virtual void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
|
virtual wxString GetItemText(const wxTreeItemId& item) const;
|
||||||
virtual bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
|
|
||||||
|
|
||||||
// Functions to work with tree ctrl items.
|
|
||||||
|
|
||||||
// accessors
|
|
||||||
// ---------
|
|
||||||
|
|
||||||
// retrieve item's label
|
|
||||||
wxString GetItemText(const wxTreeItemId& item) const;
|
|
||||||
// get one of the images associated with the item (normal by default)
|
|
||||||
virtual int GetItemImage(const wxTreeItemId& item,
|
virtual int GetItemImage(const wxTreeItemId& item,
|
||||||
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
|
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
|
||||||
// get the data associated with the item
|
virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
|
||||||
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;
|
||||||
|
|
||||||
// get the item's text colour
|
virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
|
||||||
wxColour GetItemTextColour(const wxTreeItemId& item) const;
|
virtual void SetItemImage(const wxTreeItemId& item,
|
||||||
|
int image,
|
||||||
|
wxTreeItemIcon which = wxTreeItemIcon_Normal);
|
||||||
|
virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
|
||||||
|
|
||||||
// get the item's background colour
|
virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
|
||||||
wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
|
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);
|
||||||
|
|
||||||
// get the item's font
|
virtual bool IsVisible(const wxTreeItemId& item) const;
|
||||||
wxFont GetItemFont(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;
|
||||||
|
|
||||||
// modifiers
|
virtual size_t GetChildrenCount(const wxTreeItemId& item,
|
||||||
// ---------
|
bool recursively = true) 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);
|
|
||||||
|
|
||||||
// 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 item's text colour
|
|
||||||
void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
|
|
||||||
|
|
||||||
// set the item's background colour
|
|
||||||
void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
|
|
||||||
|
|
||||||
// set the item's font (should be of the same height for all items)
|
|
||||||
void SetItemFont(const wxTreeItemId& item, const wxFont& font);
|
|
||||||
|
|
||||||
// set the window font
|
|
||||||
virtual bool SetFont( const wxFont &font );
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
// wxTreeItemId.IsOk() will return false if there is no such item
|
virtual wxTreeItemId GetRootItem() const { return m_anchor; }
|
||||||
|
virtual wxTreeItemId GetSelection() const { return m_current; }
|
||||||
|
virtual size_t GetSelections(wxArrayTreeItemIds&) const;
|
||||||
|
|
||||||
// get the root tree item
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
||||||
wxTreeItemId GetRootItem() const { return m_anchor; }
|
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;
|
||||||
|
|
||||||
// get the item currently selected (may return NULL if no selection)
|
virtual wxTreeItemId GetFirstVisibleItem() const;
|
||||||
wxTreeItemId GetSelection() const { return m_current; }
|
virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
|
||||||
|
virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
|
||||||
|
|
||||||
// get the items currently selected, return the number of such item
|
|
||||||
size_t GetSelections(wxArrayTreeItemIds&) 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;
|
|
||||||
|
|
||||||
// Only for internal use right now, but should probably be public
|
|
||||||
wxTreeItemId GetNext(const wxTreeItemId& item) const;
|
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
// add the root node to the tree
|
|
||||||
virtual wxTreeItemId AddRoot(const wxString& text,
|
virtual wxTreeItemId AddRoot(const wxString& text,
|
||||||
int image = -1, int selectedImage = -1,
|
int image = -1, int selectedImage = -1,
|
||||||
wxTreeItemData *data = NULL);
|
wxTreeItemData *data = NULL);
|
||||||
|
|
||||||
// insert a new item in as the first child of the parent
|
virtual void Delete(const wxTreeItemId& item);
|
||||||
virtual wxTreeItemId PrependItem(const wxTreeItemId& parent,
|
virtual void DeleteChildren(const wxTreeItemId& item);
|
||||||
const wxString& text,
|
virtual void DeleteAllItems();
|
||||||
int image = -1, int selectedImage = -1,
|
|
||||||
wxTreeItemData *data = NULL);
|
|
||||||
|
|
||||||
// insert a new item after a given one
|
virtual void Expand(const wxTreeItemId& item);
|
||||||
virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
|
virtual void Collapse(const wxTreeItemId& item);
|
||||||
const wxTreeItemId& idPrevious,
|
virtual void CollapseAndReset(const wxTreeItemId& item);
|
||||||
const wxString& text,
|
virtual void Toggle(const wxTreeItemId& item);
|
||||||
int image = -1, int selectedImage = -1,
|
|
||||||
wxTreeItemData *data = NULL);
|
|
||||||
|
|
||||||
// insert a new item before the one with the given index
|
virtual void Unselect();
|
||||||
virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
|
virtual void UnselectAll();
|
||||||
size_t index,
|
virtual void SelectItem(const wxTreeItemId& item, bool select = true);
|
||||||
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 void EnsureVisible(const wxTreeItemId& item);
|
||||||
virtual wxTreeItemId AppendItem(const wxTreeItemId& parent,
|
virtual void ScrollTo(const wxTreeItemId& item);
|
||||||
const wxString& text,
|
|
||||||
int image = -1, int selectedImage = -1,
|
|
||||||
wxTreeItemData *data = NULL);
|
|
||||||
|
|
||||||
// delete this item and associated data if any
|
virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
|
||||||
void Delete(const wxTreeItemId& item);
|
wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
|
||||||
// delete all children (but don't delete the item itself)
|
virtual wxTextCtrl *GetEditControl() const;
|
||||||
// NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
|
virtual void EndEditLabel(const wxTreeItemId& item,
|
||||||
void DeleteChildren(const wxTreeItemId& item);
|
bool discardChanges = false);
|
||||||
// delete all items from the tree
|
|
||||||
// NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
|
virtual void SortChildren(const wxTreeItemId& item);
|
||||||
void DeleteAllItems();
|
|
||||||
|
// items geometry
|
||||||
|
// --------------
|
||||||
|
|
||||||
|
virtual bool GetBoundingRect(const wxTreeItemId& item,
|
||||||
|
wxRect& rect,
|
||||||
|
bool textOnly = false) const;
|
||||||
|
|
||||||
|
|
||||||
|
// this version specific methods
|
||||||
|
// -----------------------------
|
||||||
|
|
||||||
|
wxImageList *GetButtonsImageList() const { return m_imageListButtons; }
|
||||||
|
void SetButtonsImageList(wxImageList *imageList);
|
||||||
|
void AssignButtonsImageList(wxImageList *imageList);
|
||||||
|
|
||||||
|
void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
|
||||||
|
bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
|
||||||
|
|
||||||
|
wxTreeItemId GetNext(const wxTreeItemId& item) const;
|
||||||
|
|
||||||
// expand this item
|
|
||||||
void Expand(const wxTreeItemId& item);
|
|
||||||
// expand this item and all subitems recursively
|
|
||||||
void ExpandAll(const wxTreeItemId& item);
|
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)
|
#if WXWIN_COMPATIBILITY_2_6
|
||||||
void Unselect();
|
// use EditLabel() instead
|
||||||
// or from the given one (multiselect mode only)
|
void Edit( const wxTreeItemId& item ) { EditLabel(item); }
|
||||||
void UnselectItem(const wxTreeItemId& item) { SelectItem(item, false); }
|
#endif // WXWIN_COMPATIBILITY_2_6
|
||||||
// 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_4
|
#if WXWIN_COMPATIBILITY_2_4
|
||||||
// deprecated functions: use Set/GetItemImage directly
|
// deprecated functions: use Set/GetItemImage directly
|
||||||
@@ -362,8 +202,6 @@ public:
|
|||||||
long& cookie) const;
|
long& cookie) const;
|
||||||
#endif // WXWIN_COMPATIBILITY_2_4
|
#endif // WXWIN_COMPATIBILITY_2_4
|
||||||
|
|
||||||
virtual bool ShouldInheritColours() const { return false; }
|
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
|
|
||||||
// overridden base class virtuals
|
// overridden base class virtuals
|
||||||
@@ -373,6 +211,9 @@ public:
|
|||||||
virtual void Freeze();
|
virtual void Freeze();
|
||||||
virtual void Thaw();
|
virtual void Thaw();
|
||||||
|
|
||||||
|
virtual bool SetFont( const wxFont &font );
|
||||||
|
virtual void SetWindowStyle(const long styles);
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
void OnPaint( wxPaintEvent &event );
|
void OnPaint( wxPaintEvent &event );
|
||||||
void OnSetFocus( wxFocusEvent &event );
|
void OnSetFocus( wxFocusEvent &event );
|
||||||
@@ -393,6 +234,10 @@ public:
|
|||||||
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
|
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
|
||||||
|
|
||||||
// implementation helpers
|
// implementation helpers
|
||||||
|
void AdjustMyScrollbars();
|
||||||
|
|
||||||
|
WX_FORWARD_TO_SCROLL_HELPER()
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class wxGenericTreeItem;
|
friend class wxGenericTreeItem;
|
||||||
friend class wxTreeRenameTimer;
|
friend class wxTreeRenameTimer;
|
||||||
@@ -408,21 +253,16 @@ protected:
|
|||||||
// A hint to select a parent item after deleting a child
|
// A hint to select a parent item after deleting a child
|
||||||
*m_select_me;
|
*m_select_me;
|
||||||
unsigned short m_indent;
|
unsigned short m_indent;
|
||||||
unsigned short m_spacing;
|
|
||||||
int m_lineHeight;
|
int m_lineHeight;
|
||||||
wxPen m_dottedPen;
|
wxPen m_dottedPen;
|
||||||
wxBrush *m_hilightBrush,
|
wxBrush *m_hilightBrush,
|
||||||
*m_hilightUnfocusedBrush;
|
*m_hilightUnfocusedBrush;
|
||||||
bool m_hasFocus;
|
bool m_hasFocus;
|
||||||
bool m_dirty;
|
bool m_dirty;
|
||||||
bool m_ownsImageListNormal,
|
bool m_ownsImageListButtons;
|
||||||
m_ownsImageListState,
|
|
||||||
m_ownsImageListButtons;
|
|
||||||
bool m_isDragging; // true between BEGIN/END drag events
|
bool m_isDragging; // true between BEGIN/END drag events
|
||||||
bool m_lastOnSame; // last click on the same item as prev
|
bool m_lastOnSame; // last click on the same item as prev
|
||||||
wxImageList *m_imageListNormal,
|
wxImageList *m_imageListButtons;
|
||||||
*m_imageListState,
|
|
||||||
*m_imageListButtons;
|
|
||||||
|
|
||||||
int m_freezeCount;
|
int m_freezeCount;
|
||||||
int m_dragCount;
|
int m_dragCount;
|
||||||
@@ -455,11 +295,18 @@ protected:
|
|||||||
bool unselect_others = true,
|
bool unselect_others = true,
|
||||||
bool extended_select = false);
|
bool extended_select = false);
|
||||||
|
|
||||||
wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
|
virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
|
||||||
size_t previous,
|
size_t previous,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int image, int selectedImage,
|
int image,
|
||||||
wxTreeItemData *data);
|
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
|
// called by wxTextTreeCtrl when it marks itself for deletion
|
||||||
void ResetTextControl();
|
void ResetTextControl();
|
||||||
|
@@ -49,7 +49,7 @@ WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
|
|||||||
// wxTreeCtrl
|
// wxTreeCtrl
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxTreeCtrl : public wxControl
|
class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// creation
|
// creation
|
||||||
@@ -75,285 +75,114 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxTreeCtrlNameStr);
|
const wxString& name = wxTreeCtrlNameStr);
|
||||||
|
|
||||||
// accessors
|
// implement base class pure virtuals
|
||||||
// ---------
|
// ----------------------------------
|
||||||
|
|
||||||
// get the total number of items in the control
|
virtual size_t GetCount() const;
|
||||||
size_t GetCount() const;
|
|
||||||
|
|
||||||
// indent is the number of pixels the children are indented relative to
|
virtual unsigned int GetIndent() const;
|
||||||
// the parents position. SetIndent() also redraws the control
|
virtual void SetIndent(unsigned int indent);
|
||||||
// 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;
|
|
||||||
|
|
||||||
virtual void SetImageList(wxImageList *imageList);
|
virtual void SetImageList(wxImageList *imageList);
|
||||||
virtual void SetStateImageList(wxImageList *imageList);
|
virtual void SetStateImageList(wxImageList *imageList);
|
||||||
virtual void AssignImageList(wxImageList *imageList);
|
|
||||||
virtual void AssignStateImageList(wxImageList *imageList);
|
|
||||||
|
|
||||||
// Functions to work with tree ctrl items. Unfortunately, they can _not_ be
|
virtual wxString GetItemText(const wxTreeItemId& item) const;
|
||||||
// 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
|
|
||||||
wxString GetItemText(const wxTreeItemId& item) const;
|
|
||||||
// get one of the images associated with the item (normal by default)
|
|
||||||
virtual int GetItemImage(const wxTreeItemId& item,
|
virtual int GetItemImage(const wxTreeItemId& item,
|
||||||
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
|
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
|
||||||
// get the data associated with the item
|
virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
|
||||||
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;
|
||||||
|
|
||||||
// get the item's text colour
|
virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
|
||||||
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;
|
|
||||||
|
|
||||||
// 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 SetItemImage(const wxTreeItemId& item, int image,
|
virtual void SetItemImage(const wxTreeItemId& item, int image,
|
||||||
wxTreeItemIcon which = wxTreeItemIcon_Normal);
|
wxTreeItemIcon which = wxTreeItemIcon_Normal);
|
||||||
// associate some data with the item
|
virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
|
||||||
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);
|
||||||
// force appearance of [+] button near the item. This is useful to
|
virtual void SetItemDropHighlight(const wxTreeItemId& item,
|
||||||
// allow the user to expand the items which don't have any children now
|
bool highlight = true);
|
||||||
// - but instead add them only when needed, thus minimizing memory
|
virtual void SetItemTextColour(const wxTreeItemId& item,
|
||||||
// usage and loading time.
|
const wxColour& col);
|
||||||
void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
|
virtual void SetItemBackgroundColour(const wxTreeItemId& item,
|
||||||
|
const wxColour& col);
|
||||||
// the item will be shown in bold
|
virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
|
||||||
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);
|
|
||||||
|
|
||||||
// item status inquiries
|
// item status inquiries
|
||||||
// ---------------------
|
// ---------------------
|
||||||
|
|
||||||
// is the item visible (it might be outside the view or not expanded)?
|
virtual bool IsVisible(const wxTreeItemId& item) const;
|
||||||
bool IsVisible(const wxTreeItemId& item) const;
|
virtual bool ItemHasChildren(const wxTreeItemId& item) const;
|
||||||
// does the item has any children?
|
virtual bool IsExpanded(const wxTreeItemId& item) const;
|
||||||
bool ItemHasChildren(const wxTreeItemId& item) const;
|
virtual bool IsSelected(const wxTreeItemId& item) const;
|
||||||
// is the item expanded (only makes sense if HasChildren())?
|
virtual bool IsBold(const wxTreeItemId& item) const;
|
||||||
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
|
virtual size_t GetChildrenCount(const wxTreeItemId& item,
|
||||||
// ------------------
|
bool recursively = true) const;
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
// wxTreeItemId.IsOk() will return false if there is no such item
|
virtual wxTreeItemId GetRootItem() const;
|
||||||
|
virtual wxTreeItemId GetSelection() const;
|
||||||
|
virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
|
||||||
|
|
||||||
// get the root tree item
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
||||||
wxTreeItemId GetRootItem() 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;
|
||||||
|
|
||||||
// get the item currently selected (may return NULL if no selection)
|
virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
||||||
wxTreeItemId GetSelection() const;
|
virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
|
||||||
|
|
||||||
// get the items currently selected, return the number of such item
|
virtual wxTreeItemId GetFirstVisibleItem() const;
|
||||||
//
|
virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
|
||||||
// NB: this operation is expensive and can take a long time for a
|
virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
|
||||||
// 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;
|
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
// add the root node to the tree
|
|
||||||
virtual wxTreeItemId AddRoot(const wxString& text,
|
virtual wxTreeItemId AddRoot(const wxString& text,
|
||||||
int image = -1, int selectedImage = -1,
|
int image = -1, int selectedImage = -1,
|
||||||
wxTreeItemData *data = NULL);
|
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,
|
virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
|
||||||
const wxTreeItemId& idPrevious,
|
const wxTreeItemId& idPrevious,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int image = -1, int selectedImage = -1,
|
int image = -1, int selectedImage = -1,
|
||||||
wxTreeItemData *data = NULL);
|
wxTreeItemData *data = NULL);
|
||||||
|
|
||||||
// insert a new item before the one with the given index
|
virtual void Delete(const wxTreeItemId& item);
|
||||||
virtual wxTreeItemId InsertItem(const wxTreeItemId& parent,
|
virtual void DeleteChildren(const wxTreeItemId& item);
|
||||||
size_t index,
|
virtual void DeleteAllItems();
|
||||||
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 void Expand(const wxTreeItemId& item);
|
||||||
virtual wxTreeItemId AppendItem(const wxTreeItemId& parent,
|
virtual void Collapse(const wxTreeItemId& item);
|
||||||
const wxString& text,
|
virtual void CollapseAndReset(const wxTreeItemId& item);
|
||||||
int image = -1, int selectedImage = -1,
|
virtual void Toggle(const wxTreeItemId& item);
|
||||||
wxTreeItemData *data = NULL);
|
|
||||||
|
|
||||||
// delete this item and associated data if any
|
virtual void Unselect();
|
||||||
void Delete(const wxTreeItemId& item);
|
virtual void UnselectAll();
|
||||||
// delete all children (but don't delete the item itself)
|
virtual void SelectItem(const wxTreeItemId& item, bool select = true);
|
||||||
// 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
|
virtual void EnsureVisible(const wxTreeItemId& item);
|
||||||
void Expand(const wxTreeItemId& item);
|
virtual void ScrollTo(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)
|
virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
|
||||||
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,
|
|
||||||
wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
|
wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
|
||||||
// returns the same pointer as StartEdit() if the item is being edited,
|
virtual wxTextCtrl *GetEditControl() const;
|
||||||
// NULL otherwise (it's assumed that no more than one item may be
|
virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
|
||||||
// edited simultaneously)
|
bool discardChanges = false)
|
||||||
wxTextCtrl* GetEditControl() const;
|
|
||||||
// end editing and accept or discard the changes to item label
|
|
||||||
void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
|
|
||||||
bool discardChanges = false)
|
|
||||||
{
|
{
|
||||||
DoEndEditLabel(discardChanges);
|
DoEndEditLabel(discardChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sorting
|
virtual void SortChildren(const wxTreeItemId& item);
|
||||||
// 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
|
virtual bool GetBoundingRect(const wxTreeItemId& item,
|
||||||
// -------
|
wxRect& rect,
|
||||||
|
bool textOnly = false) const;
|
||||||
// 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;
|
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
// ----------
|
// ----------
|
||||||
@@ -392,8 +221,6 @@ public:
|
|||||||
// implementation
|
// implementation
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
virtual bool ShouldInheritColours() const { return false; }
|
|
||||||
|
|
||||||
virtual wxVisualAttributes GetDefaultAttributes() const
|
virtual wxVisualAttributes GetDefaultAttributes() const
|
||||||
{
|
{
|
||||||
return GetClassDefaultAttributes(GetWindowVariant());
|
return GetClassDefaultAttributes(GetWindowVariant());
|
||||||
@@ -421,9 +248,6 @@ public:
|
|||||||
int GetState(const wxTreeItemId& node);
|
int GetState(const wxTreeItemId& node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const;
|
|
||||||
|
|
||||||
|
|
||||||
// SetImageList helper
|
// SetImageList helper
|
||||||
void SetAnyImageList(wxImageList *imageList, int which);
|
void SetAnyImageList(wxImageList *imageList, int which);
|
||||||
|
|
||||||
@@ -453,11 +277,17 @@ private:
|
|||||||
|
|
||||||
inline void DoExpand(const wxTreeItemId& item, int flag);
|
inline void DoExpand(const wxTreeItemId& item, int flag);
|
||||||
|
|
||||||
wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
|
virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
|
||||||
wxTreeItemId hInsertAfter,
|
size_t pos,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int image, int selectedImage,
|
int image, int selectedImage,
|
||||||
wxTreeItemData *data);
|
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,
|
int DoGetItemImageFromData(const wxTreeItemId& item,
|
||||||
wxTreeItemIcon which) const;
|
wxTreeItemIcon which) const;
|
||||||
|
@@ -14,6 +14,387 @@
|
|||||||
|
|
||||||
#include "wx/treebase.h"
|
#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 the platform-dependent wxTreeCtrl class
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -36,11 +417,5 @@
|
|||||||
#include "wx/generic/treectlg.h"
|
#include "wx/generic/treectlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
#if !defined(__WXMSW__)
|
|
||||||
#define wxTreeCtrl wxGenericTreeCtrl
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif // _WX_TREECTRL_H_BASE_
|
#endif // _WX_TREECTRL_H_BASE_
|
||||||
|
|
||||||
|
@@ -26,14 +26,7 @@
|
|||||||
|
|
||||||
#if wxUSE_TREECTRL
|
#if wxUSE_TREECTRL
|
||||||
|
|
||||||
#include "wx/treebase.h"
|
#include "wx/treectrl.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"
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// events
|
// events
|
||||||
@@ -86,5 +79,49 @@ wxTreeEvent::wxTreeEvent(const wxTreeEvent & event)
|
|||||||
m_editCancelled = event.m_editCancelled;
|
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
|
#endif // wxUSE_TREECTRL
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#if wxUSE_TREECTRL
|
#if wxUSE_TREECTRL
|
||||||
|
|
||||||
#include "wx/treebase.h"
|
#include "wx/treebase.h"
|
||||||
|
#include "wx/treectrl.h"
|
||||||
#include "wx/generic/treectlg.h"
|
#include "wx/generic/treectlg.h"
|
||||||
#include "wx/timer.h"
|
#include "wx/timer.h"
|
||||||
#include "wx/textctrl.h"
|
#include "wx/textctrl.h"
|
||||||
@@ -84,6 +85,24 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
|
|||||||
public:
|
public:
|
||||||
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
|
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()
|
void StopEditing()
|
||||||
{
|
{
|
||||||
Finish();
|
Finish();
|
||||||
@@ -419,7 +438,7 @@ void wxTreeTextCtrl::Finish()
|
|||||||
|
|
||||||
m_finished = true;
|
m_finished = true;
|
||||||
|
|
||||||
m_owner->SetFocusIgnoringChildren();
|
m_owner->SetFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,11 +447,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
|
|||||||
switch ( event.m_keyCode )
|
switch ( event.m_keyCode )
|
||||||
{
|
{
|
||||||
case WXK_RETURN:
|
case WXK_RETURN:
|
||||||
m_aboutToFinish = true;
|
EndEdit();
|
||||||
// Notify the owner about the changes
|
|
||||||
AcceptChanges();
|
|
||||||
// Even if vetoed, close the control (consistent with MSW)
|
|
||||||
Finish();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_ESCAPE:
|
case WXK_ESCAPE:
|
||||||
@@ -695,9 +710,9 @@ int wxGenericTreeItem::GetCurrentImage() const
|
|||||||
// wxGenericTreeCtrl implementation
|
// 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_PAINT (wxGenericTreeCtrl::OnPaint)
|
||||||
EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse)
|
EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse)
|
||||||
EVT_CHAR (wxGenericTreeCtrl::OnChar)
|
EVT_CHAR (wxGenericTreeCtrl::OnChar)
|
||||||
@@ -721,7 +736,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxGenericTreeCtrl)
|
|||||||
|
|
||||||
void wxGenericTreeCtrl::Init()
|
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_hasFocus = false;
|
||||||
m_dirty = false;
|
m_dirty = false;
|
||||||
|
|
||||||
@@ -747,10 +765,8 @@ void wxGenericTreeCtrl::Init()
|
|||||||
wxSOLID
|
wxSOLID
|
||||||
);
|
);
|
||||||
|
|
||||||
m_imageListNormal = m_imageListButtons =
|
m_imageListButtons = NULL;
|
||||||
m_imageListState = (wxImageList *) NULL;
|
m_ownsImageListButtons = false;
|
||||||
m_ownsImageListNormal = m_ownsImageListButtons =
|
|
||||||
m_ownsImageListState = false;
|
|
||||||
|
|
||||||
m_dragCount = 0;
|
m_dragCount = 0;
|
||||||
m_isDragging = false;
|
m_isDragging = false;
|
||||||
@@ -786,7 +802,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
|
|||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
long style,
|
long style,
|
||||||
const wxValidator& wxVALIDATOR_PARAM(validator),
|
const wxValidator& validator,
|
||||||
const wxString& name )
|
const wxString& name )
|
||||||
{
|
{
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
@@ -799,8 +815,11 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
|
|||||||
style |= wxTR_ROW_LINES;
|
style |= wxTR_ROW_LINES;
|
||||||
#endif // __WXMAC__
|
#endif // __WXMAC__
|
||||||
|
|
||||||
wxScrolledWindow::Create( parent, id, pos, size,
|
if ( !wxControl::Create( parent, id, pos, size,
|
||||||
style|wxHSCROLL|wxVSCROLL, name );
|
style|wxHSCROLL|wxVSCROLL,
|
||||||
|
validator,
|
||||||
|
name ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
// If the tree display has no buttons, but does have
|
// If the tree display has no buttons, but does have
|
||||||
// connecting lines, we can use a narrower layout.
|
// connecting lines, we can use a narrower layout.
|
||||||
@@ -811,17 +830,12 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
|
|||||||
m_spacing = 10;
|
m_spacing = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_VALIDATORS
|
|
||||||
SetValidator( validator );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wxVisualAttributes attr = GetDefaultAttributes();
|
wxVisualAttributes attr = GetDefaultAttributes();
|
||||||
SetOwnForegroundColour( attr.colFg );
|
SetOwnForegroundColour( attr.colFg );
|
||||||
SetOwnBackgroundColour( attr.colBg );
|
SetOwnBackgroundColour( attr.colBg );
|
||||||
if (!m_hasFont)
|
if (!m_hasFont)
|
||||||
SetOwnFont(attr.font);
|
SetOwnFont(attr.font);
|
||||||
|
|
||||||
// m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
|
|
||||||
m_dottedPen = wxPen( wxT("grey"), 0, 0 );
|
m_dottedPen = wxPen( wxT("grey"), 0, 0 );
|
||||||
|
|
||||||
SetBestSize(size);
|
SetBestSize(size);
|
||||||
@@ -839,10 +853,6 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
|
|||||||
delete m_renameTimer;
|
delete m_renameTimer;
|
||||||
delete m_findTimer;
|
delete m_findTimer;
|
||||||
|
|
||||||
if (m_ownsImageListNormal)
|
|
||||||
delete m_imageListNormal;
|
|
||||||
if (m_ownsImageListState)
|
|
||||||
delete m_imageListState;
|
|
||||||
if (m_ownsImageListButtons)
|
if (m_ownsImageListButtons)
|
||||||
delete m_imageListButtons;
|
delete m_imageListButtons;
|
||||||
}
|
}
|
||||||
@@ -875,12 +885,6 @@ void wxGenericTreeCtrl::SetIndent(unsigned int indent)
|
|||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGenericTreeCtrl::SetSpacing(unsigned int spacing)
|
|
||||||
{
|
|
||||||
m_spacing = (unsigned short) spacing;
|
|
||||||
m_dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
|
wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
|
||||||
bool recursively) const
|
bool recursively) const
|
||||||
@@ -1065,7 +1069,7 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font
|
|||||||
|
|
||||||
bool wxGenericTreeCtrl::SetFont( const wxFont &font )
|
bool wxGenericTreeCtrl::SetFont( const wxFont &font )
|
||||||
{
|
{
|
||||||
wxScrolledWindow::SetFont(font);
|
wxTreeCtrlBase::SetFont(font);
|
||||||
|
|
||||||
m_normalFont = font ;
|
m_normalFont = font ;
|
||||||
m_boldFont = wxFont(m_normalFont.GetPointSize(),
|
m_boldFont = wxFont(m_normalFont.GetPointSize(),
|
||||||
@@ -1393,10 +1397,11 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent,
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
|
wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
|
||||||
size_t previous,
|
size_t previous,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int image, int selImage,
|
int image,
|
||||||
wxTreeItemData *data)
|
int selImage,
|
||||||
|
wxTreeItemData *data)
|
||||||
{
|
{
|
||||||
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
|
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
|
||||||
if ( !parent )
|
if ( !parent )
|
||||||
@@ -1415,14 +1420,16 @@ wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
|
|||||||
data->m_pItem = item;
|
data->m_pItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent->Insert( item, previous );
|
parent->Insert( item, previous == (size_t)-1 ? parent->GetChildren().size()
|
||||||
|
: previous );
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
|
wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
|
||||||
int image, int selImage,
|
int image,
|
||||||
wxTreeItemData *data)
|
int selImage,
|
||||||
|
wxTreeItemData *data)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
|
wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
|
||||||
|
|
||||||
@@ -1453,19 +1460,11 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
|
|||||||
return m_anchor;
|
return m_anchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemId wxGenericTreeCtrl::PrependItem(const wxTreeItemId& parent,
|
wxTreeItemId wxGenericTreeCtrl::DoInsertAfter(const wxTreeItemId& parentId,
|
||||||
const wxString& text,
|
const wxTreeItemId& idPrevious,
|
||||||
int image, int selImage,
|
const wxString& text,
|
||||||
wxTreeItemData *data)
|
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)
|
|
||||||
{
|
{
|
||||||
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
|
wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
|
||||||
if ( !parent )
|
if ( !parent )
|
||||||
@@ -1485,37 +1484,6 @@ wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
|
|||||||
return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data);
|
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)
|
void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
|
||||||
{
|
{
|
||||||
@@ -2066,12 +2034,6 @@ static int LINKAGEMODE tree_ctrl_compare_func(wxGenericTreeItem **item1,
|
|||||||
return s_treeBeingSorted->OnCompareItems(*item1, *item2);
|
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)
|
void wxGenericTreeCtrl::SortChildren(const wxTreeItemId& itemId)
|
||||||
{
|
{
|
||||||
wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") );
|
wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") );
|
||||||
@@ -2093,21 +2055,6 @@ void wxGenericTreeCtrl::SortChildren(const wxTreeItemId& itemId)
|
|||||||
//else: don't make the tree dirty as nothing changed
|
//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()
|
void wxGenericTreeCtrl::CalculateLineHeight()
|
||||||
{
|
{
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
@@ -2175,18 +2122,6 @@ void wxGenericTreeCtrl::SetButtonsImageList(wxImageList *imageList)
|
|||||||
CalculateLineHeight();
|
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)
|
void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList *imageList)
|
||||||
{
|
{
|
||||||
SetButtonsImageList(imageList);
|
SetButtonsImageList(imageList);
|
||||||
@@ -2282,7 +2217,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colBg = m_backgroundColour;
|
colBg = GetBackgroundColour();
|
||||||
}
|
}
|
||||||
dc.SetBrush(wxBrush(colBg, wxSOLID));
|
dc.SetBrush(wxBrush(colBg, wxSOLID));
|
||||||
}
|
}
|
||||||
@@ -2900,7 +2835,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// JACS: removed wxYieldIfNeeded() because it can cause the window
|
||||||
// to be deleted from under us if a close window event is pending
|
// to be deleted from under us if a close window event is pending
|
||||||
@@ -2951,9 +2886,10 @@ bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
|
|||||||
return true;
|
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;
|
wxGenericTreeItem *itemEdit = (wxGenericTreeItem *)item.m_pItem;
|
||||||
|
|
||||||
@@ -2963,7 +2899,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
|
|||||||
if ( GetEventHandler()->ProcessEvent( te ) && !te.IsAllowed() )
|
if ( GetEventHandler()->ProcessEvent( te ) && !te.IsAllowed() )
|
||||||
{
|
{
|
||||||
// vetoed by user
|
// vetoed by user
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to call this here because the label in
|
// We have to call this here because the label in
|
||||||
@@ -2976,9 +2912,12 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
|
|||||||
wxYieldIfNeeded();
|
wxYieldIfNeeded();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO: use textCtrlClass here to create the control of correct class
|
||||||
m_textCtrl = new wxTreeTextCtrl(this, itemEdit);
|
m_textCtrl = new wxTreeTextCtrl(this, itemEdit);
|
||||||
|
|
||||||
m_textCtrl->SetFocus();
|
m_textCtrl->SetFocus();
|
||||||
|
|
||||||
|
return m_textCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a pointer to the text edit control if the item is being
|
// returns a pointer to the text edit control if the item is being
|
||||||
@@ -2989,6 +2928,14 @@ wxTextCtrl* wxGenericTreeCtrl::GetEditControl() const
|
|||||||
return m_textCtrl;
|
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,
|
bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem *item,
|
||||||
const wxString& value)
|
const wxString& value)
|
||||||
{
|
{
|
||||||
|
@@ -606,9 +606,6 @@ bool wxTreeTraversal::Traverse(const wxTreeItemId& root, bool recursively)
|
|||||||
|
|
||||||
void wxTreeCtrl::Init()
|
void wxTreeCtrl::Init()
|
||||||
{
|
{
|
||||||
m_imageListNormal = NULL;
|
|
||||||
m_imageListState = NULL;
|
|
||||||
m_ownsImageListNormal = m_ownsImageListState = false;
|
|
||||||
m_textCtrl = NULL;
|
m_textCtrl = NULL;
|
||||||
m_hasAnyAttr = false;
|
m_hasAnyAttr = false;
|
||||||
m_dragImage = NULL;
|
m_dragImage = NULL;
|
||||||
@@ -772,9 +769,6 @@ wxTreeCtrl::~wxTreeCtrl()
|
|||||||
// delete user data to prevent memory leaks
|
// delete user data to prevent memory leaks
|
||||||
// also deletes hidden root node storage.
|
// also deletes hidden root node storage.
|
||||||
DeleteAllItems();
|
DeleteAllItems();
|
||||||
|
|
||||||
if (m_ownsImageListNormal) delete m_imageListNormal;
|
|
||||||
if (m_ownsImageListState) delete m_imageListState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -833,16 +827,6 @@ void wxTreeCtrl::SetIndent(unsigned int indent)
|
|||||||
TreeView_SetIndent(GetHwnd(), indent);
|
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)
|
void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
|
||||||
{
|
{
|
||||||
// no error return
|
// no error return
|
||||||
@@ -867,18 +851,6 @@ void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
|
|||||||
m_ownsImageListState = false;
|
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,
|
size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
|
||||||
bool recursively) const
|
bool recursively) const
|
||||||
{
|
{
|
||||||
@@ -1629,11 +1601,11 @@ size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds& selections) const
|
|||||||
// Usual operations
|
// Usual operations
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
|
wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent,
|
||||||
wxTreeItemId hInsertAfter,
|
const wxTreeItemId& hInsertAfter,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int image, int selectedImage,
|
int image, int selectedImage,
|
||||||
wxTreeItemData *data)
|
wxTreeItemData *data)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
|
wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
|
||||||
wxTreeItemId(),
|
wxTreeItemId(),
|
||||||
@@ -1711,8 +1683,12 @@ wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
|
|||||||
int image, int selImage,
|
int image, int selImage,
|
||||||
long insertAfter)
|
long insertAfter)
|
||||||
{
|
{
|
||||||
return DoInsertItem(parent, wxTreeItemId((void *)insertAfter), text,
|
return DoInsertAfter(parent,
|
||||||
image, selImage, NULL);
|
wxTreeItemId(wxUIntToPtr(insertAfter)),
|
||||||
|
text,
|
||||||
|
image,
|
||||||
|
selImage,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImageList *wxTreeCtrl::GetImageList(int) const
|
wxImageList *wxTreeCtrl::GetImageList(int) const
|
||||||
@@ -1750,59 +1726,40 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
|
|||||||
return TVI_ROOT;
|
return TVI_ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DoInsertItem(wxTreeItemId(), wxTreeItemId(),
|
return DoInsertAfter(wxTreeItemId(), wxTreeItemId(),
|
||||||
text, image, selectedImage, data);
|
text, image, selectedImage, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
|
wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
|
||||||
const wxString& text,
|
size_t index,
|
||||||
int image, int selectedImage,
|
const wxString& text,
|
||||||
wxTreeItemData *data)
|
int image, int selectedImage,
|
||||||
|
wxTreeItemData *data)
|
||||||
{
|
{
|
||||||
return DoInsertItem(parent, TVI_FIRST,
|
wxTreeItemId idPrev;
|
||||||
text, image, selectedImage, data);
|
if ( index == (size_t)-1 )
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxTreeItemId wxTreeCtrl::InsertItem(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() )
|
|
||||||
{
|
{
|
||||||
index--;
|
// 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--;
|
||||||
|
|
||||||
idPrev = idCur;
|
idPrev = idCur;
|
||||||
idCur = GetNextChild(parent, cookie);
|
idCur = GetNextChild(parent, cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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") );
|
||||||
}
|
}
|
||||||
|
|
||||||
// assert, not check: if the index is invalid, we will append the item
|
return DoInsertAfter(parent, idPrev, text, image, selectedImage, data);
|
||||||
// to the end
|
|
||||||
wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
|
|
||||||
|
|
||||||
return DoInsertItem(parent, idPrev, text, image, selectedImage, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
|
|
||||||
const wxString& text,
|
|
||||||
int image, int selectedImage,
|
|
||||||
wxTreeItemData *data)
|
|
||||||
{
|
|
||||||
return DoInsertItem(parent, TVI_LAST,
|
|
||||||
text, image, selectedImage, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTreeCtrl::Delete(const wxTreeItemId& item)
|
void wxTreeCtrl::Delete(const wxTreeItemId& item)
|
||||||
@@ -2080,7 +2037,7 @@ void wxTreeCtrl::DoEndEditLabel(bool discardChanges)
|
|||||||
DeleteTextCtrl();
|
DeleteTextCtrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
|
wxTreeItemId wxTreeCtrl::DoHitTest(const wxPoint& point, int& flags)
|
||||||
{
|
{
|
||||||
TV_HITTESTINFO hitTestInfo;
|
TV_HITTESTINFO hitTestInfo;
|
||||||
hitTestInfo.pt.x = (int)point.x;
|
hitTestInfo.pt.x = (int)point.x;
|
||||||
@@ -2137,38 +2094,6 @@ bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// sorting stuff
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user