X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e21a504837179fc2be49f72e03664c8d8cc82148..3b49331b7441e091fc5997b830801d76a1243f28:/include/wx/gtk1/treectrl.h diff --git a/include/wx/gtk1/treectrl.h b/include/wx/gtk1/treectrl.h index afdd14c5cc..09ee499296 100644 --- a/include/wx/gtk1/treectrl.h +++ b/include/wx/gtk1/treectrl.h @@ -1,24 +1,18 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: treectrl.h +// Name: wx/gtk1/treectrl.h // Purpose: wxTreeCtrl class // Author: Denis Pershin // Modified by: // Created: 08/08/98 // RCS-ID: $Id$ // Copyright: (c) Denis Pershin -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_TREECTRL_H_ #define _WX_TREECTRL_H_ -#ifdef __GNUG__ -#pragma interface "treectrl.h" -#endif - #include "wx/textctrl.h" -#include "wx/control.h" -#include "wx/event.h" #include "wx/imaglist.h" #include @@ -27,13 +21,13 @@ typedef long wxDataType; // fwd decl -class wxImageList; +class WXDLLIMPEXP_CORE wxImageList; struct wxTreeViewItem; // a callback function used for sorting tree items, it should return -1 if the // first item precedes the second, +1 if the second precedes the first or 0 if // they're equivalent -class wxTreeItemData; +class WXDLLIMPEXP_FWD_CORE wxTreeItemData; typedef int (*wxTreeItemCmpFunc)(wxTreeItemData *item1, wxTreeItemData *item2); // ---------------------------------------------------------------------------- @@ -69,21 +63,13 @@ static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON; -// NB: all the following flags are for compatbility only and will be removed in -// next versions - -// flags for deprecated `Expand(int action)' -enum -{ - wxTREE_EXPAND_EXPAND, - wxTREE_EXPAND_COLLAPSE, - wxTREE_EXPAND_COLLAPSE_RESET, - wxTREE_EXPAND_TOGGLE -}; - -// flags for deprecated InsertItem() variant -#define wxTREE_INSERT_FIRST 0xFFFF0001 -#define wxTREE_INSERT_LAST 0xFFFF0002 +#if WXWIN_COMPATIBILITY_2_6 + // NB: all the following flags are for compatbility only and will be removed in + // next versions + // flags for deprecated InsertItem() variant + #define wxTREE_INSERT_FIRST 0xFFFF0001 + #define wxTREE_INSERT_LAST 0xFFFF0002 +#endif // ---------------------------------------------------------------------------- // wxTreeItemId identifies an element of the tree. In this implementation, it's @@ -103,11 +89,12 @@ public: // conversion to/from either real (system-dependent) tree item id or // to "long" which used to be the type for tree item ids in previous - // versions of wxWindows + // versions of wxWidgets // for wxTreeCtrl usage only wxTreeItemId(GtkTreeItem *itemId) { m_itemId = itemId; } operator GtkTreeItem *() const { return m_itemId; } + void operator =(GtkTreeItem *item) { m_itemId = item; } protected: GtkTreeItem *m_itemId; @@ -126,25 +113,18 @@ protected: // Because the objects of this class are deleted by the tree, they should // always be allocated on the heap! // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxTreeItemData { -friend class wxTreeCtrl; +class WXDLLEXPORT wxTreeItemData : private wxTreeItemId { public: - // creation/destruction - // -------------------- - // default ctor - wxTreeItemData() { } + // default ctor/copy ctor/assignment operator are ok - // default copy ctor/assignment operator are ok - // dtor is virtual and all the items are deleted by the tree control - // when it's deleted, so you normally don't have to care about freeing - // memory allocated in your wxTreeItemData-derived class - virtual ~wxTreeItemData() { } + // dtor is virtual and all the items are deleted by the tree control when + // it's deleted, so you normally don't have to care about freeing memory + // allocated in your wxTreeItemData-derived class + virtual ~wxTreeItemData() { } - // accessor: get the item associated with us - const wxTreeItemId& GetItemId() const { return m_itemId; } - -protected: - wxTreeItemId m_itemId; + // accessors: set/get the item associated with this node + void SetId(const wxTreeItemId& id) { m_itemId = id; } + const wxTreeItemId& GetId() const { return (wxTreeItemId&) m_itemId; } }; class WXDLLEXPORT wxTreeCtrl: public wxControl { @@ -153,7 +133,7 @@ public: // -------- wxTreeCtrl() { Init(); } - wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, + wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, @@ -164,7 +144,7 @@ public: virtual ~wxTreeCtrl(); - bool Create(wxWindow *parent, wxWindowID id = -1, + bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, @@ -175,7 +155,7 @@ public: // --------- // get the total number of items in the control - size_t GetCount() const; + virtual unsigned int GetCount() const; // indent is the number of pixels the children are indented relative to // the parents position. SetIndent() also redraws the control @@ -211,8 +191,6 @@ public: wxString GetItemText(const wxTreeItemId& item) const; // get the normal item image int GetItemImage(const wxTreeItemId& item) const; - // get the selected item image - int GetItemSelectedImage(const wxTreeItemId& item) const; // get the data associated with the item wxTreeItemData *GetItemData(const wxTreeItemId& item) const; @@ -223,8 +201,6 @@ public: void SetItemText(const wxTreeItemId& item, const wxString& text); // set the normal item image void SetItemImage(const wxTreeItemId& item, int image); - // set the selected item image - void SetItemSelectedImage(const wxTreeItemId& item, int image); // associate some data with the item void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); @@ -240,10 +216,17 @@ public: // is this item currently selected (the same as has focus)? bool IsSelected(const wxTreeItemId& item) const; + // number of children + // ------------------ + + // if 'recursively' is false, only immediate children count, otherwise + // the returned number is the number of all items in this branch + size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = true); + // navigation // ---------- - // wxTreeItemId.IsOk() will return FALSE if there is no such item + // wxTreeItemId.IsOk() will return false if there is no such item // get the root tree item wxTreeItemId GetRootItem() const; @@ -252,7 +235,7 @@ public: wxTreeItemId GetSelection() const; // get the parent of this item (may return NULL if root) - wxTreeItemId GetParent(const wxTreeItemId& item) const; + 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 @@ -261,10 +244,8 @@ public: // the "cookie" passed to GetFirstChild() and GetNextChild() should be // the same! - // get the first child of this item - wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; - // get the next child - wxTreeItemId GetNextChild(const wxTreeItemId& item, long& 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; @@ -341,7 +322,7 @@ public: // edited simultaneously) wxTextCtrl* GetEditControl() const; // end editing and accept or discard the changes to item label - void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); + void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false); // sort the children of this item using the specified callback function // (it should return -1, 0 or +1 as usual), if it's not specified @@ -354,134 +335,72 @@ public: // deprecated // ---------- +#if WXWIN_COMPATIBILITY_2_6 // these methods are deprecated and will be removed in future versions of - // wxWindows, they're here for compatibility only, don't use them in new + // wxWidgets, they're here for compatibility only, don't use them in new // code (the comments indicate why these methods are now useless and how to // replace them) // use Expand, Collapse, CollapseAndReset or Toggle - void ExpandItem(const wxTreeItemId& item, int action); + wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) ); - // use AddRoot, PrependItem or AppendItem - wxTreeItemId InsertItem(const wxTreeItemId& parent, - const wxString& text, - int image = -1, int selImage = -1, - long insertAfter = wxTREE_INSERT_LAST); - - // use Set/GetImageList and Set/GetStateImageList - wxImageList *GetImageList(int) const - { return GetImageList(); } - void SetImageList(wxImageList *imageList, int) + // use SetImageList + wxDEPRECATED( void SetImageList(wxImageList *imageList, int) ) { SetImageList(imageList); } - void SendExpanding(const wxTreeItemId& item); - void SendExpanded(const wxTreeItemId& item); - void SendCollapsing(const wxTreeItemId& item); - void SendCollapsed(const wxTreeItemId& item); - void SendSelChanging(const wxTreeItemId& item); - void SendSelChanged(const wxTreeItemId& item); -protected: - GtkTree *m_tree; - GtkTreeItem *m_anchor; - wxTextCtrl* m_textCtrl; - wxImageList* m_imageListNormal; - wxImageList* m_imageListState; + // use Set/GetItemImage directly + wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const ); + wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) ); - long m_curitemId; - -// GtkTreeItem *findGtkTreeItem(wxTreeCtrlId &id) const; + // get the first child of this item + wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const ); + // get the next child (after GetFirstChild or GetNextChild) + wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const ); - // the common part of all ctors - void Init(); - // insert a new item in as the last child of the parent - wxTreeItemId p_InsertItem(GtkTreeItem *p, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data); + // use AddRoot, PrependItem or AppendItem + wxDEPRECATED( wxTreeItemId InsertItem(const wxTreeItemId& parent, + const wxString& text, + int image = -1, int selImage = -1, + long insertAfter = wxTREE_INSERT_LAST) ); +#endif // WXWIN_COMPATIBILITY_2_6 - DECLARE_DYNAMIC_CLASS(wxTreeCtrl) -}; + // use Set/GetImageList and Set/GetStateImageList + wxImageList *GetImageList(int) const + { return GetImageList(); } -// ---------------------------------------------------------------------------- -// wxTreeEvent is a special class for all events associated with tree controls -// -// NB: note that not all accessors make sense for all events, see the event -// descriptions below -// ---------------------------------------------------------------------------- -class WXDLLEXPORT wxTreeEvent : public wxCommandEvent -{ -friend wxTreeCtrl; -public: - wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); + void SendExpanding(const wxTreeItemId& item); + void SendExpanded(const wxTreeItemId& item); + void SendCollapsing(const wxTreeItemId& item); + void SendCollapsed(const wxTreeItemId& item); + void SendSelChanging(const wxTreeItemId& item); + void SendSelChanged(const wxTreeItemId& item); - // accessors - // get the item on which the operation was performed or the newly - // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events - wxTreeItemId GetItem() const { return m_item; } +protected: - // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously - // selected item - wxTreeItemId GetOldItem() const { return m_itemOld; } + wxTreeItemId m_editItem; + GtkTree *m_tree; + GtkTreeItem *m_anchor; + wxTextCtrl* m_textCtrl; + wxImageList* m_imageListNormal; + wxImageList* m_imageListState; - // the point where the mouse was when the drag operation started (for - // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) - wxPoint GetPoint() const { return m_pointDrag; } + long m_curitemId; - // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only) - int GetCode() const { return m_code; } + void SendMessage(wxEventType command, const wxTreeItemId& item); +// GtkTreeItem *findGtkTreeItem(wxTreeCtrlId &id) const; - // set return code for wxEVT_COMMAND_TREE_ITEM_{EXPAND|COLLAPS}ING events - // call this to forbid the change in item status - void Veto() { m_code = TRUE; } + // the common part of all ctors + void Init(); + // insert a new item in as the last child of the parent + wxTreeItemId p_InsertItem(GtkTreeItem *p, + const wxString& text, + int image, int selectedImage, + wxTreeItemData *data); -private: - // @@ we could save some space by using union here - int m_code; - wxTreeItemId m_item, - m_itemOld; - wxPoint m_pointDrag; - DECLARE_DYNAMIC_CLASS(wxTreeEvent) + DECLARE_DYNAMIC_CLASS(wxTreeCtrl) }; -typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); - -// ---------------------------------------------------------------------------- -// macros for handling tree control events -// ---------------------------------------------------------------------------- - -// GetItem() returns the item being dragged, GetPoint() the mouse coords -#define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, - -// GetItem() returns the itme whose label is being edited -#define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, - -// provide/update information about GetItem() item -#define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, - -// GetItem() is the item being expanded/collapsed, the "ING" versions can use -#define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -#define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, - -// GetOldItem() is the item which had the selection previously, GetItem() is -// the item which acquires selection -#define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, -#define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, - -// GetCode() returns the key code -// NB: this is the only message for which GetItem() is invalid (you may get the -// item from GetSelection()) -#define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, - -// GetItem() returns the item being deleted, the associated data (if any) will -// be deleted just after the return of this event handler (if any) -#define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, - #endif // _WX_TREECTRL_H_