KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_dataviewctrl.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef WX_DATAVIEWCTRL_H_
21#define WX_DATAVIEWCTRL_H_
22
23#include <functional>
24#include <utility>
25
26#include <wx/dataview.h>
27
35class WX_ENSURE_VISIBLE_CANCELLER : public wxDataViewModelNotifier
36{
37public:
38 explicit WX_ENSURE_VISIBLE_CANCELLER( std::function<void()> aOnItemsRemoved ) :
39 m_onItemsRemoved( std::move( aOnItemsRemoved ) )
40 {
41 }
42
43 bool ItemAdded( const wxDataViewItem&, const wxDataViewItem& ) override { return true; }
44 bool ItemChanged( const wxDataViewItem& ) override { return true; }
45 bool ValueChanged( const wxDataViewItem&, unsigned int ) override { return true; }
46 void Resort() override {}
47
48 bool ItemDeleted( const wxDataViewItem&, const wxDataViewItem& ) override
49 {
51 return true;
52 }
53
54 bool ItemsDeleted( const wxDataViewItem&, const wxDataViewItemArray& ) override
55 {
57 return true;
58 }
59
60 // BeforeReset fires while items are still live; Cleared covers AfterReset and direct clears.
61 bool BeforeReset() override
62 {
64 return true;
65 }
66
67 bool Cleared() override
68 {
70 return true;
71 }
72
73private:
74 std::function<void()> m_onItemsRemoved;
75};
76
77
84class WX_DATAVIEWCTRL : public wxDataViewCtrl
85{
86public:
87 // Just take all constructors
88 using wxDataViewCtrl::wxDataViewCtrl;
89
90 ~WX_DATAVIEWCTRL() override;
91
96 bool AssociateModel( wxDataViewModel* aModel ) override;
97
104 wxDataViewItem GetPrevItem( wxDataViewItem const& aItem );
105
112 wxDataViewItem GetNextItem( wxDataViewItem const& aItem );
113
120 wxDataViewItem GetPrevSibling( wxDataViewItem const& aItem );
121
128 wxDataViewItem GetNextSibling( wxDataViewItem const& aItem );
129
130 void DoSetToolTipText( const wxString &tip ) override {}
131
132 void ExpandAll();
133 void CollapseAll();
134
146
147private:
148 // Owned by the associated model; null when no model is associated.
149 wxDataViewModelNotifier* m_ensureVisibleCanceller = nullptr;
150};
151
152
163inline void EnsureVisibleIfEnabled( wxDataViewCtrl* aWidget, const wxDataViewItem& aItem )
164{
165 if( aItem.IsOk() && aWidget->IsEnabled() )
166 aWidget->EnsureVisible( aItem );
167}
168
169#endif // WX_DATAVIEWCTRL_H_
Extension of the wxDataViewCtrl to include some helper functions for working with items.
bool AssociateModel(wxDataViewModel *aModel) override
Install a WX_ENSURE_VISIBLE_CANCELLER on aModel so deferred scrolls are dropped automatically when it...
wxDataViewItem GetPrevSibling(wxDataViewItem const &aItem)
Get the previous sibling of an item.
~WX_DATAVIEWCTRL() override
void DoSetToolTipText(const wxString &tip) override
void CancelPendingEnsureVisible()
Cancel any pending deferred EnsureVisible request.
wxDataViewItem GetNextSibling(wxDataViewItem const &aItem)
Get the next sibling of an item.
wxDataViewItem GetNextItem(wxDataViewItem const &aItem)
Get the next item in list order.
wxDataViewItem GetPrevItem(wxDataViewItem const &aItem)
Get the previous item in list order.
wxDataViewModelNotifier * m_ensureVisibleCanceller
bool ValueChanged(const wxDataViewItem &, unsigned int) override
bool ItemDeleted(const wxDataViewItem &, const wxDataViewItem &) override
std::function< void()> m_onItemsRemoved
WX_ENSURE_VISIBLE_CANCELLER(std::function< void()> aOnItemsRemoved)
bool ItemAdded(const wxDataViewItem &, const wxDataViewItem &) override
bool ItemChanged(const wxDataViewItem &) override
bool ItemsDeleted(const wxDataViewItem &, const wxDataViewItemArray &) override
STL namespace.
void EnsureVisibleIfEnabled(wxDataViewCtrl *aWidget, const wxDataViewItem &aItem)
Scroll aItem into view only when aWidget is currently enabled.