source: git/src/aventreectrl.cc @ ded184e2

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since ded184e2 was efb30c4, checked in by Olly Betts <olly@…>, 18 years ago

Hopefully fix redraw of background colour in survey tree (appears to be
gtk theme dependent as I don't see it myself).

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

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