1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-02-28 20:47:34 -05:00
|
|
|
// Name: wx/msw/treectrl.h
|
1998-05-20 10:12:05 -04:00
|
|
|
// Purpose: wxTreeCtrl class
|
|
|
|
// Author: Julian Smart
|
1998-10-18 18:46:23 -04:00
|
|
|
// Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98
|
1998-05-20 10:12:05 -04:00
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 05:34:04 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-08-26 18:26:53 -04:00
|
|
|
#ifndef _WX_MSW_TREECTRL_H_
|
|
|
|
#define _WX_MSW_TREECTRL_H_
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-06-13 18:54:04 -04:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_TREECTRL
|
|
|
|
|
1999-01-08 16:09:46 -05:00
|
|
|
#include "wx/textctrl.h"
|
1999-07-31 13:24:28 -04:00
|
|
|
#include "wx/dynarray.h"
|
2000-08-04 09:59:45 -04:00
|
|
|
#include "wx/treebase.h"
|
2003-07-19 17:06:59 -04:00
|
|
|
#include "wx/hashmap.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-06-13 18:54:04 -04:00
|
|
|
#ifdef __GNUWIN32__
|
|
|
|
// Cygwin windows.h defines these identifiers
|
|
|
|
#undef GetFirstChild
|
|
|
|
#undef GetNextSibling
|
|
|
|
#endif // Cygwin
|
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// fwd decl
|
1998-10-22 06:43:16 -04:00
|
|
|
class WXDLLEXPORT wxImageList;
|
2000-02-14 19:05:36 -05:00
|
|
|
class WXDLLEXPORT wxDragImage;
|
1998-10-22 06:43:16 -04:00
|
|
|
struct WXDLLEXPORT wxTreeViewItem;
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2006-03-28 08:11:20 -05:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6
|
|
|
|
// NB: all the following flags are for compatbility only and will be removed in the
|
|
|
|
// next versions
|
|
|
|
// flags for deprecated InsertItem() variant (their values are the same as of
|
|
|
|
// TVI_FIRST and TVI_LAST)
|
|
|
|
#define wxTREE_INSERT_FIRST 0xFFFF0001
|
|
|
|
#define wxTREE_INSERT_LAST 0xFFFF0002
|
|
|
|
#endif
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-07-19 17:06:59 -04:00
|
|
|
// hash storing attributes for our items
|
2006-01-18 11:45:41 -05:00
|
|
|
WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
|
2003-07-19 17:06:59 -04:00
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTreeCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
2003-07-19 17:06:59 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
class WXDLLEXPORT wxTreeCtrl : public wxTreeCtrlBase
|
1998-05-20 10:12:05 -04:00
|
|
|
{
|
1998-07-12 18:50:32 -04:00
|
|
|
public:
|
|
|
|
// creation
|
|
|
|
// --------
|
1998-10-18 18:46:23 -04:00
|
|
|
wxTreeCtrl() { Init(); }
|
|
|
|
|
2004-06-12 19:44:08 -04:00
|
|
|
wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
|
1998-10-18 18:46:23 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2002-12-04 09:11:26 -05:00
|
|
|
const wxString& name = wxTreeCtrlNameStr)
|
1998-07-12 18:50:32 -04:00
|
|
|
{
|
|
|
|
Create(parent, id, pos, size, style, validator, name);
|
|
|
|
}
|
1998-10-18 18:46:23 -04:00
|
|
|
|
|
|
|
virtual ~wxTreeCtrl();
|
|
|
|
|
2004-06-12 19:44:08 -04:00
|
|
|
bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
|
1998-07-12 18:50:32 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
1998-10-18 18:46:23 -04:00
|
|
|
long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
|
1998-07-12 18:50:32 -04:00
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2002-12-04 09:11:26 -05:00
|
|
|
const wxString& name = wxTreeCtrlNameStr);
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
// implement base class pure virtuals
|
|
|
|
// ----------------------------------
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2006-03-24 18:46:43 -05:00
|
|
|
virtual unsigned int GetCount() const;
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual unsigned int GetIndent() const;
|
|
|
|
virtual void SetIndent(unsigned int indent);
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void SetImageList(wxImageList *imageList);
|
|
|
|
virtual void SetStateImageList(wxImageList *imageList);
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual wxString GetItemText(const wxTreeItemId& item) const;
|
2004-11-03 18:01:57 -05:00
|
|
|
virtual int GetItemImage(const wxTreeItemId& item,
|
2005-10-10 16:25:02 -04:00
|
|
|
wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
|
|
|
|
virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
|
|
|
|
virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
|
|
|
|
virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
|
|
|
|
virtual wxFont GetItemFont(const wxTreeItemId& item) const;
|
2002-12-04 09:11:26 -05:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
|
2004-11-03 18:01:57 -05:00
|
|
|
virtual void SetItemImage(const wxTreeItemId& item, int image,
|
1999-09-29 18:47:56 -04:00
|
|
|
wxTreeItemIcon which = wxTreeItemIcon_Normal);
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
|
|
|
|
virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
|
|
|
|
virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
|
|
|
|
virtual void SetItemDropHighlight(const wxTreeItemId& item,
|
|
|
|
bool highlight = true);
|
|
|
|
virtual void SetItemTextColour(const wxTreeItemId& item,
|
|
|
|
const wxColour& col);
|
|
|
|
virtual void SetItemBackgroundColour(const wxTreeItemId& item,
|
|
|
|
const wxColour& col);
|
|
|
|
virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
|
1999-12-06 08:18:14 -05:00
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// item status inquiries
|
|
|
|
// ---------------------
|
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual bool IsVisible(const wxTreeItemId& item) const;
|
|
|
|
virtual bool ItemHasChildren(const wxTreeItemId& item) const;
|
|
|
|
virtual bool IsExpanded(const wxTreeItemId& item) const;
|
|
|
|
virtual bool IsSelected(const wxTreeItemId& item) const;
|
|
|
|
virtual bool IsBold(const wxTreeItemId& item) const;
|
|
|
|
|
|
|
|
virtual size_t GetChildrenCount(const wxTreeItemId& item,
|
|
|
|
bool recursively = true) const;
|
1998-11-13 15:47:22 -05:00
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// navigation
|
|
|
|
// ----------
|
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual wxTreeItemId GetRootItem() const;
|
|
|
|
virtual wxTreeItemId GetSelection() const;
|
|
|
|
virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
|
|
|
|
|
|
|
|
virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
|
|
|
|
virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
|
|
|
wxTreeItemIdValue& cookie) const;
|
|
|
|
virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
|
|
|
|
wxTreeItemIdValue& cookie) const;
|
|
|
|
virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
|
|
|
|
|
|
|
|
virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
|
|
|
|
virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
|
|
|
|
|
|
|
|
virtual wxTreeItemId GetFirstVisibleItem() const;
|
|
|
|
virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
|
|
|
|
virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
|
1998-10-18 18:46:23 -04:00
|
|
|
|
1998-07-12 18:50:32 -04:00
|
|
|
// operations
|
|
|
|
// ----------
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2004-11-03 18:01:57 -05:00
|
|
|
virtual wxTreeItemId AddRoot(const wxString& text,
|
1998-10-18 18:46:23 -04:00
|
|
|
int image = -1, int selectedImage = -1,
|
|
|
|
wxTreeItemData *data = NULL);
|
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void Delete(const wxTreeItemId& item);
|
|
|
|
virtual void DeleteChildren(const wxTreeItemId& item);
|
|
|
|
virtual void DeleteAllItems();
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void Expand(const wxTreeItemId& item);
|
|
|
|
virtual void Collapse(const wxTreeItemId& item);
|
|
|
|
virtual void CollapseAndReset(const wxTreeItemId& item);
|
|
|
|
virtual void Toggle(const wxTreeItemId& item);
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void Unselect();
|
|
|
|
virtual void UnselectAll();
|
|
|
|
virtual void SelectItem(const wxTreeItemId& item, bool select = true);
|
1999-12-29 05:28:20 -05:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void EnsureVisible(const wxTreeItemId& item);
|
|
|
|
virtual void ScrollTo(const wxTreeItemId& item);
|
|
|
|
|
|
|
|
virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
|
1998-10-18 18:46:23 -04:00
|
|
|
wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual wxTextCtrl *GetEditControl() const;
|
|
|
|
virtual void EndEditLabel(const wxTreeItemId& WXUNUSED(item),
|
|
|
|
bool discardChanges = false)
|
2004-12-19 20:23:52 -05:00
|
|
|
{
|
|
|
|
DoEndEditLabel(discardChanges);
|
|
|
|
}
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual void SortChildren(const wxTreeItemId& item);
|
|
|
|
|
|
|
|
virtual bool GetBoundingRect(const wxTreeItemId& item,
|
|
|
|
wxRect& rect,
|
|
|
|
bool textOnly = false) const;
|
1998-10-18 18:46:23 -04:00
|
|
|
|
|
|
|
// deprecated
|
|
|
|
// ----------
|
|
|
|
|
2003-07-19 17:06:59 -04:00
|
|
|
#if WXWIN_COMPATIBILITY_2_4
|
1998-10-18 18:46:23 -04:00
|
|
|
// these methods are deprecated and will be removed in future versions of
|
2004-05-23 10:56:36 -04:00
|
|
|
// wxWidgets, they're here for compatibility only, don't use them in new
|
1998-10-18 18:46:23 -04:00
|
|
|
// code (the comments indicate why these methods are now useless and how to
|
|
|
|
// replace them)
|
|
|
|
|
|
|
|
// use Expand, Collapse, CollapseAndReset or Toggle
|
2003-07-19 17:06:59 -04:00
|
|
|
wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) );
|
1998-10-18 18:46:23 -04:00
|
|
|
|
|
|
|
// use Set/GetImageList and Set/GetStateImageList
|
2005-10-28 10:05:49 -04:00
|
|
|
// Use base class GetImageList()
|
2005-01-11 16:17:16 -05:00
|
|
|
wxDEPRECATED( void SetImageList(wxImageList *imageList, int) );
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2006-03-28 08:11:20 -05:00
|
|
|
// use Set/GetItemImage directly
|
2005-01-11 16:17:16 -05:00
|
|
|
wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const );
|
|
|
|
wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) );
|
1999-09-29 18:47:56 -04:00
|
|
|
|
2003-07-19 17:06:59 -04:00
|
|
|
// use the versions taking wxTreeItemIdValue cookies
|
|
|
|
wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item,
|
|
|
|
long& cookie) const );
|
|
|
|
wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item,
|
|
|
|
long& cookie) const );
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2_4
|
|
|
|
|
2003-10-16 06:00:12 -04:00
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
// implementation
|
|
|
|
// --------------
|
2000-02-28 20:47:34 -05:00
|
|
|
|
2004-03-31 19:14:42 -05:00
|
|
|
virtual wxVisualAttributes GetDefaultAttributes() const
|
|
|
|
{
|
|
|
|
return GetClassDefaultAttributes(GetWindowVariant());
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxVisualAttributes
|
|
|
|
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
|
|
|
|
|
|
|
|
|
2004-02-25 05:45:02 -05:00
|
|
|
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
|
2005-04-05 18:59:22 -04:00
|
|
|
virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
|
1998-11-24 18:30:50 -05:00
|
|
|
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
1999-05-13 17:21:04 -04:00
|
|
|
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
|
2006-07-31 18:06:24 -04:00
|
|
|
virtual bool MSWShouldPreProcessMessage(WXMSG* msg);
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2000-01-03 18:38:57 -05:00
|
|
|
// override some base class virtuals
|
|
|
|
virtual bool SetBackgroundColour(const wxColour &colour);
|
|
|
|
virtual bool SetForegroundColour(const wxColour &colour);
|
|
|
|
|
1999-07-30 18:45:55 -04:00
|
|
|
// get/set the check state for the item (only for wxTR_MULTIPLE)
|
|
|
|
bool IsItemChecked(const wxTreeItemId& item) const;
|
2004-06-12 19:44:08 -04:00
|
|
|
void SetItemCheck(const wxTreeItemId& item, bool check = true);
|
1999-07-30 18:45:55 -04:00
|
|
|
|
2003-07-10 07:16:34 -04:00
|
|
|
// set/get the item state.image (state == -1 means cycle to the next one)
|
|
|
|
void SetState(const wxTreeItemId& node, int state);
|
|
|
|
int GetState(const wxTreeItemId& node);
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
protected:
|
1998-10-18 18:46:23 -04:00
|
|
|
// SetImageList helper
|
|
|
|
void SetAnyImageList(wxImageList *imageList, int which);
|
|
|
|
|
2001-12-15 17:20:54 -05:00
|
|
|
// refresh a single item
|
|
|
|
void RefreshItem(const wxTreeItemId& item);
|
|
|
|
|
2004-12-19 20:23:52 -05:00
|
|
|
// end edit label
|
|
|
|
void DoEndEditLabel(bool discardChanges = false);
|
|
|
|
|
2005-10-10 16:25:02 -04:00
|
|
|
virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
|
|
|
|
size_t pos,
|
|
|
|
const wxString& text,
|
|
|
|
int image, int selectedImage,
|
|
|
|
wxTreeItemData *data);
|
|
|
|
virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
|
|
|
|
const wxTreeItemId& idPrevious,
|
|
|
|
const wxString& text,
|
|
|
|
int image = -1, int selImage = -1,
|
|
|
|
wxTreeItemData *data = NULL);
|
2006-06-14 08:00:57 -04:00
|
|
|
virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
|
1998-10-18 18:46:23 -04:00
|
|
|
|
2006-05-06 15:17:22 -04:00
|
|
|
// obtain the user data for the lParam member of TV_ITEM
|
|
|
|
class wxTreeItemParam *GetItemParam(const wxTreeItemId& item) const;
|
|
|
|
|
|
|
|
|
|
|
|
// data used only while editing the item label:
|
|
|
|
wxTextCtrl *m_textCtrl; // text control in which it is edited
|
|
|
|
wxTreeItemId m_idEdited; // the item being edited
|
|
|
|
|
2006-02-08 16:47:09 -05:00
|
|
|
private:
|
|
|
|
// the common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
// helper functions
|
|
|
|
inline bool DoGetItem(wxTreeViewItem *tvItem) const;
|
|
|
|
inline void DoSetItem(wxTreeViewItem *tvItem);
|
|
|
|
|
|
|
|
inline void DoExpand(const wxTreeItemId& item, int flag);
|
|
|
|
|
1998-10-18 18:46:23 -04:00
|
|
|
void DeleteTextCtrl();
|
1998-07-12 18:50:32 -04:00
|
|
|
|
2006-08-26 18:26:53 -04:00
|
|
|
// return true if the item is the hidden root one (i.e. it's the root item
|
|
|
|
// and the tree has wxTR_HIDE_ROOT style)
|
|
|
|
bool IsHiddenRoot(const wxTreeItemId& item) const;
|
|
|
|
|
|
|
|
|
2003-07-19 17:06:59 -04:00
|
|
|
// the hash storing the items attributes (indexed by item ids)
|
|
|
|
wxMapTreeAttr m_attrs;
|
1999-12-06 19:09:40 -05:00
|
|
|
|
2004-06-12 19:44:08 -04:00
|
|
|
// true if the hash above is not empty
|
1999-12-06 19:09:40 -05:00
|
|
|
bool m_hasAnyAttr;
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
// used for dragging
|
|
|
|
wxDragImage *m_dragImage;
|
|
|
|
|
2002-03-16 10:08:20 -05:00
|
|
|
// Virtual root item, if wxTR_HIDE_ROOT is set.
|
|
|
|
void* m_pVirtualRoot;
|
|
|
|
|
2000-02-28 20:47:34 -05:00
|
|
|
// the starting item for selection with Shift
|
2005-06-16 13:01:19 -04:00
|
|
|
wxTreeItemId m_htSelStart, m_htClickedItem;
|
|
|
|
wxPoint m_ptClick;
|
2000-02-28 20:47:34 -05:00
|
|
|
|
2001-12-22 20:00:32 -05:00
|
|
|
friend class wxTreeItemIndirectData;
|
|
|
|
friend class wxTreeSortHelper;
|
|
|
|
|
1998-07-12 18:50:32 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
|
2003-01-02 18:38:11 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(wxTreeCtrl)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_TREECTRL
|
|
|
|
|
2006-08-26 18:26:53 -04:00
|
|
|
#endif // _WX_MSW_TREECTRL_H_
|