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 <kicommon.h>
27#include <wx/dataview.h>
28
36class WX_ENSURE_VISIBLE_CANCELLER : public wxDataViewModelNotifier
37{
38public:
39 explicit WX_ENSURE_VISIBLE_CANCELLER( std::function<void()> aOnItemsRemoved ) :
40 m_onItemsRemoved( std::move( aOnItemsRemoved ) )
41 {
42 }
43
44 bool ItemAdded( const wxDataViewItem&, const wxDataViewItem& ) override { return true; }
45 bool ItemChanged( const wxDataViewItem& ) override { return true; }
46 bool ValueChanged( const wxDataViewItem&, unsigned int ) override { return true; }
47 void Resort() override {}
48
49 bool ItemDeleted( const wxDataViewItem&, const wxDataViewItem& ) override
50 {
52 return true;
53 }
54
55 bool ItemsDeleted( const wxDataViewItem&, const wxDataViewItemArray& ) override
56 {
58 return true;
59 }
60
61 // BeforeReset fires while items are still live; Cleared covers AfterReset and direct clears.
62 bool BeforeReset() override
63 {
65 return true;
66 }
67
68 bool Cleared() override
69 {
71 return true;
72 }
73
74private:
75 std::function<void()> m_onItemsRemoved;
76};
77
78
85class KICOMMON_API WX_DATAVIEWCTRL : public wxDataViewCtrl
86{
87public:
88 // Just take all constructors
89 using wxDataViewCtrl::wxDataViewCtrl;
90
91 ~WX_DATAVIEWCTRL() override;
92
97 bool AssociateModel( wxDataViewModel* aModel ) override;
98
105 wxDataViewItem GetPrevItem( wxDataViewItem const& aItem );
106
113 wxDataViewItem GetNextItem( wxDataViewItem const& aItem );
114
121 wxDataViewItem GetPrevSibling( wxDataViewItem const& aItem );
122
129 wxDataViewItem GetNextSibling( wxDataViewItem const& aItem );
130
131 void DoSetToolTipText( const wxString &tip ) override {}
132
133 void ExpandAll();
134 void CollapseAll();
135
146 void CancelPendingEnsureVisible();
147
148private:
149 // Owned by the associated model; null when no model is associated.
150 wxDataViewModelNotifier* m_ensureVisibleCanceller = nullptr;
151};
152
153
164inline void EnsureVisibleIfEnabled( wxDataViewCtrl* aWidget, const wxDataViewItem& aItem )
165{
166 if( aItem.IsOk() && aWidget->IsEnabled() )
167 aWidget->EnsureVisible( aItem );
168}
169
170#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.
void DoSetToolTipText(const wxString &tip) override
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
#define KICOMMON_API
Definition kicommon.h:27
STL namespace.
void EnsureVisibleIfEnabled(wxDataViewCtrl *aWidget, const wxDataViewItem &aItem)
Scroll aItem into view only when aWidget is currently enabled.