source: git/src/aventreectrl.cc @ a6e8d45

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since a6e8d45 was a6e8d45, checked in by Olly Betts <olly@…>, 13 years ago

src/aventreectrl.cc,src/guicontrol.cc,src/mainfrm.cc: Don't use
deprecated members or methods of wxKeyEvent.

git-svn-id: file:///home/survex-svn/survex/trunk@3641 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[f17e6dc6]1//
2//  aventreectrl.cc
3//
4//  Tree control used for the survey tree.
5//
6//  Copyright (C) 2001, Mark R. Shinwell.
[4e98397]7//  Copyright (C) 2001-2003,2005,2006 Olly Betts
[887c26e]8//  Copyright (C) 2005 Martin Green
[f17e6dc6]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
[ecbc6c18]22//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
[f17e6dc6]23//
24
[cbfa50d]25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
[f17e6dc6]29#include "aventreectrl.h"
30#include "mainfrm.h"
31
32BEGIN_EVENT_TABLE(AvenTreeCtrl, wxTreeCtrl)
33    EVT_MOTION(AvenTreeCtrl::OnMouseMove)
[887c26e]34    EVT_LEAVE_WINDOW(AvenTreeCtrl::OnLeaveWindow)
[f17e6dc6]35    EVT_TREE_SEL_CHANGED(-1, AvenTreeCtrl::OnSelChanged)
[44ed489]36    EVT_TREE_ITEM_ACTIVATED(-1, AvenTreeCtrl::OnItemActivated)
[5901b62]37    EVT_CHAR(AvenTreeCtrl::OnKeyPress)
[f17e6dc6]38END_EVENT_TABLE()
39
40AvenTreeCtrl::AvenTreeCtrl(MainFrm* parent, wxWindow* window_parent) :
[84f1ed1]41    wxTreeCtrl(window_parent, -1),
[b623b3e]42    m_Parent(parent),
[b4fe9fb]43    m_Enabled(false),
[3eddcaf4]44    m_LastItem(),
[efb30c4]45    m_BackgroundColour(),
[b4fe9fb]46    m_SelValid(false)
[f17e6dc6]47{
48}
49
[97dd0d2]50#define TREE_MASK (wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMRIGHT)
51
[f17e6dc6]52void AvenTreeCtrl::OnMouseMove(wxMouseEvent& event)
53{
54    if (m_Enabled) {
[421b7d2]55        int flags;
56        wxTreeItemId pos = HitTest(event.GetPosition(), flags);
[887c26e]57        if (!(flags & TREE_MASK)) {
58            pos = wxTreeItemId();
59        }
[570d62c3]60        if (pos == m_LastItem) return;
61        if (pos.IsOk()) {
62            m_Parent->DisplayTreeInfo(GetItemData(pos));
63        } else {
64            m_Parent->DisplayTreeInfo(NULL);
[f17e6dc6]65        }
66    }
67}
68
[570d62c3]69void AvenTreeCtrl::SetHere(wxTreeItemId pos)
70{
71    if (pos == m_LastItem) return;
72
73    if (m_LastItem.IsOk()) {
74        SetItemBackgroundColour(m_LastItem, m_BackgroundColour);
75    }
76    if (pos.IsOk()) {
77        m_BackgroundColour = GetItemBackgroundColour(pos);
78        SetItemBackgroundColour(pos, wxColour(180, 180, 180));
79    }
80    m_LastItem = pos;
81}
82
[887c26e]83void AvenTreeCtrl::OnLeaveWindow(wxMouseEvent&)
84{
85    if (m_LastItem.IsOk()) {
86        SetItemBackgroundColour(m_LastItem, m_BackgroundColour);
87        m_LastItem = wxTreeItemId();
88    }
89    m_Parent->DisplayTreeInfo(NULL);
90}
91
[f17e6dc6]92void AvenTreeCtrl::SetEnabled(bool enabled)
93{
94    m_Enabled = enabled;
95}
96
[44ed489]97void AvenTreeCtrl::OnSelChanged(wxTreeEvent& e)
[f17e6dc6]98{
99    if (m_Enabled) {
[44ed489]100        m_Parent->TreeItemSelected(GetItemData(e.GetItem()), false);
[f17e6dc6]101    }
[b623b3e]102
103    m_SelValid = true;
[f17e6dc6]104}
105
[44ed489]106void AvenTreeCtrl::OnItemActivated(wxTreeEvent& e)
107{
108    if (m_Enabled) {
109        m_Parent->TreeItemSelected(GetItemData(e.GetItem()), true);
[b23bcf0]110        // Need to skip to allow double-clicking to work on wxMSW >= 2.8.11.
111        e.Skip();
[44ed489]112    }
113}
114
[570d62c3]115bool AvenTreeCtrl::GetSelectionData(wxTreeItemData** data) const
[f17e6dc6]116{
117    assert(m_Enabled);
[26fac5a]118    assert(data);
[b623b3e]119
120    if (!m_SelValid) {
[421b7d2]121        return false;
[b623b3e]122    }
[421b7d2]123
[f17e6dc6]124    wxTreeItemId id = GetSelection();
125    if (id.IsOk()) {
[421b7d2]126        *data = GetItemData(id);
[f17e6dc6]127    }
128
[2d9ed8ad]129    return id.IsOk() && *data;
[f17e6dc6]130}
[b623b3e]131
132void AvenTreeCtrl::UnselectAll()
133{
134    m_SelValid = false;
135    wxTreeCtrl::UnselectAll();
136}
137
[30987bd]138void AvenTreeCtrl::DeleteAllItems()
139{
[887c26e]140    m_Enabled = false;
[3eddcaf4]141    m_LastItem = wxTreeItemId();
[30987bd]142    m_SelValid = false;
[096e56c]143    wxTreeCtrl::DeleteAllItems();
[30987bd]144}
145
[5901b62]146void AvenTreeCtrl::OnKeyPress(wxKeyEvent &e)
147{
[a6e8d45]148    switch (e.GetKeyCode()) {
[26fac5a]149        case WXK_ESCAPE:
150            m_Parent->ClearTreeSelection();
151            break;
152        case WXK_RETURN: {
153            wxTreeItemId id = GetSelection();
154            if (id.IsOk()) {
155                if (ItemHasChildren(id)) {
156                    // If on a branch, expand/contract it.
157                    if (IsExpanded(id)) {
158                        Collapse(id);
159                    } else {
160                        Expand(id);
161                    }
162                } else {
163                    // FIXME if on a station, show information on that station
164                    // or something?
165                }
166            }
167            break;
168        }
169        case WXK_LEFT: case WXK_RIGHT: case WXK_UP: case WXK_DOWN:
170        case WXK_HOME: case WXK_END: case WXK_PAGEUP: case WXK_PAGEDOWN:
[4e98397]171        // On wx 2.6 and earlier, PRIOR/NEXT seem to actually be
[880b954]172        // PAGEUP/PAGEDOWN (on wxGTK at least).  In wx 2.7 and later
[4e98397]173        // they're just compatibility aliases, so either they have the
174        // same value or aren't defined - either way the code won't
175        // compile.
176#if !wxCHECK_VERSION(2,7,0)
[26fac5a]177        case WXK_PRIOR: case WXK_NEXT:
[4e98397]178#endif
[26fac5a]179            e.Skip();
180            break;
181        default:
182            // Pass key event to MainFrm which will pass to GfxCore which will
183            // pass to GUIControl.
184            m_Parent->OnKeyPress(e);
185            break;
[5901b62]186    }
187}
Note: See TracBrowser for help on using the repository browser.