1 | // |
---|
2 | // aventreectrl.cc |
---|
3 | // |
---|
4 | // Tree control used for the survey tree. |
---|
5 | // |
---|
6 | // Copyright (C) 2001, Mark R. Shinwell. |
---|
7 | // Copyright (C) 2001-2003, Olly Betts |
---|
8 | // |
---|
9 | // This program is free software; you can redistribute it and/or modify |
---|
10 | // it under the terms of the GNU General Public License as published by |
---|
11 | // the Free Software Foundation; either version 2 of the License, or |
---|
12 | // (at your option) any later version. |
---|
13 | // |
---|
14 | // This program is distributed in the hope that it will be useful, |
---|
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | // GNU General Public License for more details. |
---|
18 | // |
---|
19 | // You should have received a copy of the GNU General Public License |
---|
20 | // along with this program; if not, write to the Free Software |
---|
21 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
22 | // |
---|
23 | |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include <config.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | #include "aventreectrl.h" |
---|
29 | #include "mainfrm.h" |
---|
30 | |
---|
31 | BEGIN_EVENT_TABLE(AvenTreeCtrl, wxTreeCtrl) |
---|
32 | EVT_MOTION(AvenTreeCtrl::OnMouseMove) |
---|
33 | EVT_TREE_SEL_CHANGED(-1, AvenTreeCtrl::OnSelChanged) |
---|
34 | EVT_CHAR(AvenTreeCtrl::OnKeyPress) |
---|
35 | END_EVENT_TABLE() |
---|
36 | |
---|
37 | AvenTreeCtrl::AvenTreeCtrl(MainFrm* parent, wxWindow* window_parent) : |
---|
38 | wxTreeCtrl(window_parent, -1, wxDefaultPosition), |
---|
39 | m_Parent(parent), |
---|
40 | m_Enabled(false), |
---|
41 | m_LastItem(wxTreeItemId(-1)), |
---|
42 | m_BackgroundColour(GetBackgroundColour()), |
---|
43 | m_SelValid(false) |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | #define TREE_MASK (wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMRIGHT) |
---|
48 | |
---|
49 | void AvenTreeCtrl::OnMouseMove(wxMouseEvent& event) |
---|
50 | { |
---|
51 | if (m_Enabled) { |
---|
52 | int flags; |
---|
53 | wxTreeItemId pos = HitTest(event.GetPosition(), flags); |
---|
54 | if (pos != m_LastItem) { |
---|
55 | if (m_LastItem != wxTreeItemId(-1)) { |
---|
56 | SetItemBackgroundColour(m_LastItem, m_BackgroundColour); |
---|
57 | } |
---|
58 | if (flags & TREE_MASK) { |
---|
59 | SetItemBackgroundColour(pos, wxColour(180, 180, 180)); |
---|
60 | m_Parent->DisplayTreeInfo(GetItemData(pos)); |
---|
61 | m_LastItem = pos; |
---|
62 | } else { |
---|
63 | m_Parent->DisplayTreeInfo(NULL); |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void AvenTreeCtrl::SetEnabled(bool enabled) |
---|
70 | { |
---|
71 | m_Enabled = enabled; |
---|
72 | } |
---|
73 | |
---|
74 | void AvenTreeCtrl::OnSelChanged(wxTreeEvent&) |
---|
75 | { |
---|
76 | if (m_Enabled) { |
---|
77 | m_Parent->TreeItemSelected(GetItemData(GetSelection())); |
---|
78 | } |
---|
79 | |
---|
80 | m_SelValid = true; |
---|
81 | } |
---|
82 | |
---|
83 | bool AvenTreeCtrl::GetSelectionData(wxTreeItemData** data) |
---|
84 | { |
---|
85 | assert(m_Enabled); |
---|
86 | |
---|
87 | if (!m_SelValid) { |
---|
88 | return false; |
---|
89 | } |
---|
90 | |
---|
91 | wxTreeItemId id = GetSelection(); |
---|
92 | if (id.IsOk()) { |
---|
93 | *data = GetItemData(id); |
---|
94 | } |
---|
95 | |
---|
96 | return id.IsOk() && *data; |
---|
97 | } |
---|
98 | |
---|
99 | void AvenTreeCtrl::UnselectAll() |
---|
100 | { |
---|
101 | m_SelValid = false; |
---|
102 | wxTreeCtrl::UnselectAll(); |
---|
103 | } |
---|
104 | |
---|
105 | void AvenTreeCtrl::DeleteAllItems() |
---|
106 | { |
---|
107 | m_LastItem = -1; |
---|
108 | m_SelValid = false; |
---|
109 | wxTreeCtrl::DeleteAllItems(); |
---|
110 | } |
---|
111 | |
---|
112 | void AvenTreeCtrl::OnKeyPress(wxKeyEvent &e) |
---|
113 | { |
---|
114 | if (e.m_keyCode == WXK_ESCAPE) { |
---|
115 | m_Parent->ClearTreeSelection(); |
---|
116 | } else { |
---|
117 | e.Skip(); |
---|
118 | } |
---|
119 | } |
---|