]> git.saurik.com Git - wxWidgets.git/blame - src/common/treebase.cpp
call gtk_toolbar_set_tooltips() from GtkSetStyle(); removed erroneous wxTB_TOOLTIPS
[wxWidgets.git] / src / common / treebase.cpp
CommitLineData
484523cf
JS
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
65571936 9// Licence: wxWindows licence
484523cf
JS
10/////////////////////////////////////////////////////////////////////////////
11
12// =============================================================================
13// declarations
14// =============================================================================
15
16// -----------------------------------------------------------------------------
17// headers
18// -----------------------------------------------------------------------------
19
484523cf
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
1e6feb95 24 #pragma hdrstop
484523cf
JS
25#endif
26
1e6feb95
VZ
27#if wxUSE_TREECTRL
28
8cee4a30 29#include "wx/treectrl.h"
42e53e77 30#include "wx/imaglist.h"
ed2ec17c
GT
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)
ae8c4b33 54DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK)
156194e1 55DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP)
f7c6f947 56DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MENU)
ed2ec17c 57
484523cf
JS
58// ----------------------------------------------------------------------------
59// Tree event
60// ----------------------------------------------------------------------------
61
b8fbf1a0
RD
62IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxNotifyEvent)
63
64
484523cf
JS
65wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
66 : wxNotifyEvent(commandType, id)
67{
51d67338 68 m_itemOld = 0l;
cb719f2e 69 m_editCancelled = false;
484523cf
JS
70}
71
0cd936a4
WS
72wxTreeEvent::wxTreeEvent(const wxTreeEvent & event)
73 : wxNotifyEvent(event)
74{
75 m_evtKey = event.m_evtKey;
76 m_item = event.m_item;
77 m_itemOld = event.m_itemOld;
78 m_pointDrag = event.m_pointDrag;
79 m_label = event.m_label;
80 m_editCancelled = event.m_editCancelled;
81}
82
8cee4a30
VZ
83// ----------------------------------------------------------------------------
84// wxTreeCtrlBase
85// ----------------------------------------------------------------------------
86
87wxTreeCtrlBase::~wxTreeCtrlBase()
88{
89 if (m_ownsImageListNormal)
90 delete m_imageListNormal;
91 if (m_ownsImageListState)
92 delete m_imageListState;
93}
94
7c384067
JS
95static void wxGetBestTreeSize(const wxTreeCtrlBase* treeCtrl, const wxTreeItemId& id, wxSize& size)
96{
97 wxRect rect;
98
99 if ( treeCtrl->GetBoundingRect(id, rect, true) )
100 {
101 if ( size.x < rect.x + rect.width )
102 size.x = rect.x + rect.width;
103 if ( size.y < rect.y + rect.height )
104 size.y = rect.y + rect.height;
105 }
106
107 wxTreeItemIdValue cookie;
108 for ( wxTreeItemId item = treeCtrl->GetFirstChild(id, cookie);
109 item.IsOk();
110 item = treeCtrl->GetNextChild(item, cookie) )
111 {
112 wxGetBestTreeSize(treeCtrl, item, size);
113 }
114}
115
8cee4a30
VZ
116wxSize wxTreeCtrlBase::DoGetBestSize() const
117{
118 wxSize size;
119
120 // this doesn't really compute the total bounding rectangle of all items
121 // but a not too bad guess of it which has the advantage of not having to
122 // examine all (potentially hundreds or thousands) items in the control
7c384067
JS
123
124 if (GetQuickBestSize())
8cee4a30 125 {
7c384067
JS
126 for ( wxTreeItemId item = GetRootItem();
127 item.IsOk();
128 item = GetLastChild(item) )
8cee4a30 129 {
7c384067
JS
130 wxRect rect;
131
132 // last parameter is "true" to get only the dimensions of the text
133 // label, we don't want to get the entire item width as it's determined
134 // by the current size
135 if ( GetBoundingRect(item, rect, true) )
136 {
137 if ( size.x < rect.x + rect.width )
138 size.x = rect.x + rect.width;
139 if ( size.y < rect.y + rect.height )
140 size.y = rect.y + rect.height;
141 }
8cee4a30
VZ
142 }
143 }
7c384067
JS
144 else
145 wxGetBestTreeSize(this, GetRootItem(), size);
8cee4a30
VZ
146
147 // need some minimal size even for empty tree
148 if ( !size.x || !size.y )
149 size = wxControl::DoGetBestSize();
b24069f2
VZ
150 else
151 CacheBestSize(size);
8cee4a30
VZ
152
153 return size;
154}
155
1e6feb95
VZ
156#endif // wxUSE_TREECTRL
157