source: git/src/aventreectrl.cc @ c00c6713

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since c00c6713 was 44ed489, checked in by Olly Betts <olly@…>, 18 years ago
  • aven: Clicking on a survey name in the survey tree now highlights it in the map view. Double-clicking zooms the view to show the clicked survey highlighted. Clicking the root clears the highlighting and double-clicking the root restores the default view. To expand/collapse a branch, click on the "[+]" or "[-]" icon to the left of the survey name.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3269 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 4.4 KB
Line 
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,2005,2006 Olly Betts
8//  Copyright (C) 2005 Martin Green
9//
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.
14//
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.
19//
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23//
24
25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
29#include "aventreectrl.h"
30#include "mainfrm.h"
31
32BEGIN_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)
38END_EVENT_TABLE()
39
40AvenTreeCtrl::AvenTreeCtrl(MainFrm* parent, wxWindow* window_parent) :
41    wxTreeCtrl(window_parent, -1),
42    m_Parent(parent),
43    m_Enabled(false),
44    m_LastItem(),
45    m_BackgroundColour(),
46    m_SelValid(false)
47{
48}
49
50#define TREE_MASK (wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMRIGHT)
51
52void AvenTreeCtrl::OnMouseMove(wxMouseEvent& event)
53{
54    if (m_Enabled) {
55        int flags;
56        wxTreeItemId pos = HitTest(event.GetPosition(), flags);
57        if (!(flags & TREE_MASK)) {
58            pos = wxTreeItemId();
59        }
60        if (pos != m_LastItem) {
61            if (m_LastItem.IsOk()) {
62                SetItemBackgroundColour(m_LastItem, m_BackgroundColour);
63            }
64            if (pos.IsOk()) {
65                m_BackgroundColour = GetItemBackgroundColour(pos);
66                SetItemBackgroundColour(pos, wxColour(180, 180, 180));
67                m_Parent->DisplayTreeInfo(GetItemData(pos));
68            } else {
69                m_Parent->DisplayTreeInfo(NULL);
70            }
71            m_LastItem = pos;
72        }
73    }
74}
75
76void AvenTreeCtrl::OnLeaveWindow(wxMouseEvent&)
77{
78    if (m_LastItem.IsOk()) {
79        SetItemBackgroundColour(m_LastItem, m_BackgroundColour);
80        m_LastItem = wxTreeItemId();
81    }
82    m_Parent->DisplayTreeInfo(NULL);
83}
84
85void AvenTreeCtrl::SetEnabled(bool enabled)
86{
87    m_Enabled = enabled;
88}
89
90void AvenTreeCtrl::OnSelChanged(wxTreeEvent& e)
91{
92    if (m_Enabled) {
93        m_Parent->TreeItemSelected(GetItemData(e.GetItem()), false);
94    }
95
96    m_SelValid = true;
97}
98
99void AvenTreeCtrl::OnItemActivated(wxTreeEvent& e)
100{
101    if (m_Enabled) {
102        m_Parent->TreeItemSelected(GetItemData(e.GetItem()), true);
103    }
104}
105
106bool AvenTreeCtrl::GetSelectionData(wxTreeItemData** data)
107{
108    assert(m_Enabled);
109    assert(data);
110
111    if (!m_SelValid) {
112        return false;
113    }
114
115    wxTreeItemId id = GetSelection();
116    if (id.IsOk()) {
117        *data = GetItemData(id);
118    }
119
120    return id.IsOk() && *data;
121}
122
123void AvenTreeCtrl::UnselectAll()
124{
125    m_SelValid = false;
126    wxTreeCtrl::UnselectAll();
127}
128
129void AvenTreeCtrl::DeleteAllItems()
130{
131    m_Enabled = false;
132    m_LastItem = wxTreeItemId();
133    m_SelValid = false;
134    wxTreeCtrl::DeleteAllItems();
135}
136
137void AvenTreeCtrl::OnKeyPress(wxKeyEvent &e)
138{
139    switch (e.m_keyCode) {
140        case WXK_ESCAPE:
141            m_Parent->ClearTreeSelection();
142            break;
143        case WXK_RETURN: {
144            wxTreeItemId id = GetSelection();
145            if (id.IsOk()) {
146                if (ItemHasChildren(id)) {
147                    // If on a branch, expand/contract it.
148                    if (IsExpanded(id)) {
149                        Collapse(id);
150                    } else {
151                        Expand(id);
152                    }
153                } else {
154                    // FIXME if on a station, show information on that station
155                    // or something?
156                }
157            }
158            break;
159        }
160        case WXK_LEFT: case WXK_RIGHT: case WXK_UP: case WXK_DOWN:
161        case WXK_HOME: case WXK_END: case WXK_PAGEUP: case WXK_PAGEDOWN:
162        // On wx 2.6 and earlier, PRIOR/NEXT seem to actually be
163        // PAGEUP/PAGEDOWN (on wxGtk at least).  In wx 2.7 and later
164        // they're just compatibility aliases, so either they have the
165        // same value or aren't defined - either way the code won't
166        // compile.
167#if !wxCHECK_VERSION(2,7,0)
168        case WXK_PRIOR: case WXK_NEXT:
169#endif
170            e.Skip();
171            break;
172        default:
173            // Pass key event to MainFrm which will pass to GfxCore which will
174            // pass to GUIControl.
175            m_Parent->OnKeyPress(e);
176            break;
177    }
178}
Note: See TracBrowser for help on using the repository browser.