]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/treebase.cpp
don't use old name for wxTE_PROCESS_ENTER unavailable when compatibility is off
[wxWidgets.git] / src / common / treebase.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: treebase.cpp
3// Purpose: Base wxTreeCtrl classes
4// Author: Julian Smart
5// Created: 01/02/97
6// Modified:
7// Id: $Id$
8// Copyright: (c) 1998 Robert Roebling, Julian Smart et al
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// =============================================================================
13// declarations
14// =============================================================================
15
16// -----------------------------------------------------------------------------
17// headers
18// -----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_TREECTRL
28
29#include "wx/treectrl.h"
30#include "wx/imaglist.h"
31
32// ----------------------------------------------------------------------------
33// events
34// ----------------------------------------------------------------------------
35
36DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_DRAG)
37DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_RDRAG)
38DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT)
39DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_LABEL_EDIT)
40DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_DELETE_ITEM)
41DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_GET_INFO)
42DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SET_INFO)
43DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDED)
44DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_EXPANDING)
45DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSED)
46DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_COLLAPSING)
47DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGED)
48DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_SEL_CHANGING)
49DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_KEY_DOWN)
50DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_ACTIVATED)
51DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK)
52DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK)
53DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG)
54DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK)
55DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP)
56DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MENU)
57
58// ----------------------------------------------------------------------------
59// Tree event
60// ----------------------------------------------------------------------------
61
62IMPLEMENT_ABSTRACT_CLASS(wxTreeEvent, wxNotifyEvent)
63
64
65wxTreeEvent::wxTreeEvent(wxEventType commandType,
66 wxTreeCtrlBase *tree,
67 const wxTreeItemId& item)
68 : wxNotifyEvent(commandType, tree->GetId()),
69 m_item(item)
70{
71 m_editCancelled = false;
72
73 SetEventObject(tree);
74
75 if ( item.IsOk() )
76 SetClientObject(tree->GetItemData(item));
77}
78
79wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
80 : wxNotifyEvent(commandType, id)
81{
82 m_itemOld = 0l;
83 m_editCancelled = false;
84}
85
86wxTreeEvent::wxTreeEvent(const wxTreeEvent & event)
87 : wxNotifyEvent(event)
88{
89 m_evtKey = event.m_evtKey;
90 m_item = event.m_item;
91 m_itemOld = event.m_itemOld;
92 m_pointDrag = event.m_pointDrag;
93 m_label = event.m_label;
94 m_editCancelled = event.m_editCancelled;
95}
96
97// ----------------------------------------------------------------------------
98// wxTreeCtrlBase
99// ----------------------------------------------------------------------------
100
101wxTreeCtrlBase::~wxTreeCtrlBase()
102{
103 if (m_ownsImageListNormal)
104 delete m_imageListNormal;
105 if (m_ownsImageListState)
106 delete m_imageListState;
107}
108
109static void wxGetBestTreeSize(const wxTreeCtrlBase* treeCtrl, const wxTreeItemId& id, wxSize& size)
110{
111 wxRect rect;
112
113 if ( treeCtrl->GetBoundingRect(id, rect, true) )
114 {
115 if ( size.x < rect.x + rect.width )
116 size.x = rect.x + rect.width;
117 if ( size.y < rect.y + rect.height )
118 size.y = rect.y + rect.height;
119 }
120
121 wxTreeItemIdValue cookie;
122 for ( wxTreeItemId item = treeCtrl->GetFirstChild(id, cookie);
123 item.IsOk();
124 item = treeCtrl->GetNextChild(item, cookie) )
125 {
126 wxGetBestTreeSize(treeCtrl, item, size);
127 }
128}
129
130wxSize wxTreeCtrlBase::DoGetBestSize() const
131{
132 wxSize size;
133
134 // this doesn't really compute the total bounding rectangle of all items
135 // but a not too bad guess of it which has the advantage of not having to
136 // examine all (potentially hundreds or thousands) items in the control
137
138 if (GetQuickBestSize())
139 {
140 for ( wxTreeItemId item = GetRootItem();
141 item.IsOk();
142 item = GetLastChild(item) )
143 {
144 wxRect rect;
145
146 // last parameter is "true" to get only the dimensions of the text
147 // label, we don't want to get the entire item width as it's determined
148 // by the current size
149 if ( GetBoundingRect(item, rect, true) )
150 {
151 if ( size.x < rect.x + rect.width )
152 size.x = rect.x + rect.width;
153 if ( size.y < rect.y + rect.height )
154 size.y = rect.y + rect.height;
155 }
156 }
157 }
158 else
159 wxGetBestTreeSize(this, GetRootItem(), size);
160
161 // need some minimal size even for empty tree
162 if ( !size.x || !size.y )
163 size = wxControl::DoGetBestSize();
164 else
165 CacheBestSize(size);
166
167 return size;
168}
169
170#endif // wxUSE_TREECTRL
171