4 // Tree control used for the survey tree.
6 // Copyright (C) 2001, Mark R. Shinwell.
7 // Copyright (C) 2001-2003,2005,2006,2016 Olly Betts
8 // Copyright (C) 2005 Martin Green
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "aventreectrl.h"
32 BEGIN_EVENT_TABLE(AvenTreeCtrl
, wxTreeCtrl
)
33 EVT_MOTION(AvenTreeCtrl::OnMouseMove
)
34 EVT_LEAVE_WINDOW(AvenTreeCtrl::OnLeaveWindow
)
35 EVT_TREE_SEL_CHANGED(-1, AvenTreeCtrl::OnSelChanged
)
36 EVT_TREE_ITEM_ACTIVATED(-1, AvenTreeCtrl::OnItemActivated
)
37 EVT_CHAR(AvenTreeCtrl::OnKeyPress
)
38 EVT_TREE_ITEM_MENU(-1, AvenTreeCtrl::OnMenu
)
39 EVT_MENU(menu_SURVEY_SHOW_ALL
, AvenTreeCtrl::OnRestrict
)
40 EVT_MENU(menu_SURVEY_RESTRICT
, AvenTreeCtrl::OnRestrict
)
43 AvenTreeCtrl::AvenTreeCtrl(MainFrm
* parent
, wxWindow
* window_parent
) :
44 wxTreeCtrl(window_parent
, -1),
54 #define TREE_MASK (wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMRIGHT)
56 void AvenTreeCtrl::OnMouseMove(wxMouseEvent
& event
)
58 if (m_Enabled
&& !m_Parent
->Animating()) {
60 wxTreeItemId pos
= HitTest(event
.GetPosition(), flags
);
61 if (!(flags
& TREE_MASK
)) {
64 if (pos
== m_LastItem
) return;
66 m_Parent
->DisplayTreeInfo(GetItemData(pos
));
68 m_Parent
->DisplayTreeInfo();
73 void AvenTreeCtrl::SetHere(wxTreeItemId pos
)
75 if (pos
== m_LastItem
) return;
77 if (m_LastItem
.IsOk()) {
78 SetItemBackgroundColour(m_LastItem
, m_BackgroundColour
);
81 m_BackgroundColour
= GetItemBackgroundColour(pos
);
82 SetItemBackgroundColour(pos
, wxColour(180, 180, 180));
87 void AvenTreeCtrl::OnLeaveWindow(wxMouseEvent
&)
89 if (m_LastItem
.IsOk()) {
90 SetItemBackgroundColour(m_LastItem
, m_BackgroundColour
);
91 m_LastItem
= wxTreeItemId();
93 m_Parent
->DisplayTreeInfo();
96 void AvenTreeCtrl::SetEnabled(bool enabled
)
101 void AvenTreeCtrl::OnSelChanged(wxTreeEvent
& e
)
104 m_Parent
->TreeItemSelected(GetItemData(e
.GetItem()), false);
110 void AvenTreeCtrl::OnItemActivated(wxTreeEvent
& e
)
113 m_Parent
->TreeItemSelected(GetItemData(e
.GetItem()), true);
114 // Need to skip to allow double-clicking to work on wxMSW >= 2.8.11.
119 void AvenTreeCtrl::OnMenu(wxTreeEvent
& e
)
122 const TreeData
* data
= static_cast<const TreeData
*>(GetItemData(e
.GetItem()));
127 /* TRANSLATORS: In aven's survey tree, right-clicking on a survey
128 * name gives a pop-up menu and this is an option. It reloads the
129 * current survey file with the view restricted to the survey
132 menu
.Append(menu_SURVEY_SHOW_ALL
, wmsg(/*Show all*/245));
133 if (m_Parent
->GetSurvey().empty())
134 menu
.Enable(menu_SURVEY_SHOW_ALL
, false);
136 } else if (data
->GetLabel()) {
137 // Station: name is data->GetLabel()->GetText()
141 /* TRANSLATORS: In aven's survey tree, right-clicking on a survey
142 * name gives a pop-up menu and this is an option. It reloads the
143 * current survey file with the view restricted to the survey
146 menu
.Append(menu_SURVEY_RESTRICT
, wmsg(/*Hide others*/246));
154 bool AvenTreeCtrl::GetSelectionData(wxTreeItemData
** data
) const
163 wxTreeItemId id
= GetSelection();
165 *data
= GetItemData(id
);
168 return id
.IsOk() && *data
;
171 void AvenTreeCtrl::UnselectAll()
174 wxTreeCtrl::UnselectAll();
177 void AvenTreeCtrl::DeleteAllItems()
180 m_LastItem
= wxTreeItemId();
182 wxTreeCtrl::DeleteAllItems();
185 void AvenTreeCtrl::OnKeyPress(wxKeyEvent
&e
)
187 switch (e
.GetKeyCode()) {
189 m_Parent
->ClearTreeSelection();
192 wxTreeItemId id
= GetSelection();
194 if (ItemHasChildren(id
)) {
195 // If on a branch, expand/contract it.
196 if (IsExpanded(id
)) {
202 // If on a station, centre on it.
203 m_Parent
->TreeItemSelected(GetItemData(id
), true);
208 case WXK_LEFT
: case WXK_RIGHT
: case WXK_UP
: case WXK_DOWN
:
209 case WXK_HOME
: case WXK_END
: case WXK_PAGEUP
: case WXK_PAGEDOWN
:
213 // Pass key event to MainFrm which will pass to GfxCore which will
214 // pass to GUIControl.
215 m_Parent
->OnKeyPress(e
);
220 void AvenTreeCtrl::OnRestrict(wxCommandEvent
& e
)
222 m_Parent
->RestrictTo(menu_data
? menu_data
->GetSurvey() : wxString());