source: git/src/aventreectrl.cc @ 880b954

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 880b954 was 880b954, checked in by Olly Betts <olly@…>, 14 years ago

doc/manual.sgml,src/aventreectrl.cc,src/gfxcore.cc,src/mainfrm.h:
Correctly capitalise "GTK".

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

  • Property mode set to 100644
File size: 4.5 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);
110    }
111}
112
[570d62c3]113bool AvenTreeCtrl::GetSelectionData(wxTreeItemData** data) const
[f17e6dc6]114{
115    assert(m_Enabled);
[26fac5a]116    assert(data);
[b623b3e]117
118    if (!m_SelValid) {
[421b7d2]119        return false;
[b623b3e]120    }
[421b7d2]121
[f17e6dc6]122    wxTreeItemId id = GetSelection();
123    if (id.IsOk()) {
[421b7d2]124        *data = GetItemData(id);
[f17e6dc6]125    }
126
[2d9ed8ad]127    return id.IsOk() && *data;
[f17e6dc6]128}
[b623b3e]129
130void AvenTreeCtrl::UnselectAll()
131{
132    m_SelValid = false;
133    wxTreeCtrl::UnselectAll();
134}
135
[30987bd]136void AvenTreeCtrl::DeleteAllItems()
137{
[887c26e]138    m_Enabled = false;
[3eddcaf4]139    m_LastItem = wxTreeItemId();
[30987bd]140    m_SelValid = false;
[096e56c]141    wxTreeCtrl::DeleteAllItems();
[30987bd]142}
143
[5901b62]144void AvenTreeCtrl::OnKeyPress(wxKeyEvent &e)
145{
[26fac5a]146    switch (e.m_keyCode) {
147        case WXK_ESCAPE:
148            m_Parent->ClearTreeSelection();
149            break;
150        case WXK_RETURN: {
151            wxTreeItemId id = GetSelection();
152            if (id.IsOk()) {
153                if (ItemHasChildren(id)) {
154                    // If on a branch, expand/contract it.
155                    if (IsExpanded(id)) {
156                        Collapse(id);
157                    } else {
158                        Expand(id);
159                    }
160                } else {
161                    // FIXME if on a station, show information on that station
162                    // or something?
163                }
164            }
165            break;
166        }
167        case WXK_LEFT: case WXK_RIGHT: case WXK_UP: case WXK_DOWN:
168        case WXK_HOME: case WXK_END: case WXK_PAGEUP: case WXK_PAGEDOWN:
[4e98397]169        // On wx 2.6 and earlier, PRIOR/NEXT seem to actually be
[880b954]170        // PAGEUP/PAGEDOWN (on wxGTK at least).  In wx 2.7 and later
[4e98397]171        // they're just compatibility aliases, so either they have the
172        // same value or aren't defined - either way the code won't
173        // compile.
174#if !wxCHECK_VERSION(2,7,0)
[26fac5a]175        case WXK_PRIOR: case WXK_NEXT:
[4e98397]176#endif
[26fac5a]177            e.Skip();
178            break;
179        default:
180            // Pass key event to MainFrm which will pass to GfxCore which will
181            // pass to GUIControl.
182            m_Parent->OnKeyPress(e);
183            break;
[5901b62]184    }
185}
Note: See TracBrowser for help on using the repository browser.