KiCad PCB EDA Suite
Loading...
Searching...
No Matches
filter_combobox.h
Go to the documentation of this file.
1
2/*
3 * This program source code file is part of KiCad, a free EDA CAD application.
4 *
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#pragma once
26
27#include <memory>
28#include <optional>
29
30#include <wx/panel.h>
31#include <wx/combo.h>
32#include <wx/listbox.h>
33
34
35class wxTextValidator;
36class wxTextCtrl;
37class wxListBox;
38
39
40class FILTER_COMBOPOPUP : public wxPanel, public wxComboPopup
41{
42public:
44
45 bool Create( wxWindow* aParent ) override;
46
47 wxWindow* GetControl() override { return this; }
48
49 void SetStringList( const wxArrayString& aStringList );
50
51 wxString GetStringValue() const override;
52 void SetStringValue( const wxString& aNetName ) override;
53
54 void SetSelectedString( const wxString& aString );
55
56 void OnPopup() override;
57
58 void OnStartingKey( wxKeyEvent& aEvent );
59
60 wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override;
61
62 virtual void Accept();
63
64protected:
68 std::optional<wxString> getSelectedValue() const;
69
73 wxString getFilterValue() const;
74
78 virtual void getListContent( wxArrayString& aStringList );
79
83 void rebuildList();
84
85private:
86 wxSize updateSize();
87
88 void onIdle( wxIdleEvent& aEvent );
89
90 // Hot-track the mouse (for focus and listbox selection)
91 void onMouseMoved( const wxPoint aScreenPos );
92 void onMouseClick( wxMouseEvent& aEvent );
93 void onKeyDown( wxKeyEvent& aEvent );
94 void onEnter( wxCommandEvent& aEvent );
95 void onFilterEdit( wxCommandEvent& aEvent );
96 void doStartingKey( wxKeyEvent& aEvent );
97 void doSetFocus( wxWindow* aWindow );
98
99protected:
100 wxTextValidator* m_filterValidator;
101 wxTextCtrl* m_filterCtrl;
102 wxListBox* m_listBox;
105
106 wxEvtHandler* m_focusHandler;
107
109 wxArrayString m_stringList;
110};
111
112
113wxDECLARE_EVENT( FILTERED_ITEM_SELECTED, wxCommandEvent );
114
121class FILTER_COMBOBOX : public wxComboCtrl
122{
123public:
124 // C'tor matching wxFormBuilder's Custom Control
125 FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
126 const wxSize& size = wxDefaultSize, long style = 0 );
127
128 // C'tor matching wxFormBuilder's ComboxBox.
129 FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
130 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
131 int count = 0, wxString strings[] = nullptr, long style = 0 );
132
134
135 virtual void SetStringList( const wxArrayString& aStringList );
136
137 virtual void SetSelectedString( const wxString& aString );
138
139protected:
140 void setFilterPopup( FILTER_COMBOPOPUP* aPopup );
141
142 void onKeyDown( wxKeyEvent& aEvt );
143
145};
A combobox that has a filterable popup.
virtual void SetSelectedString(const wxString &aString)
FILTER_COMBOPOPUP * m_filterPopup
void setFilterPopup(FILTER_COMBOPOPUP *aPopup)
virtual void SetStringList(const wxArrayString &aStringList)
void onKeyDown(wxKeyEvent &aEvt)
void SetSelectedString(const wxString &aString)
void onEnter(wxCommandEvent &aEvent)
wxTextValidator * m_filterValidator
void onFilterEdit(wxCommandEvent &aEvent)
void SetStringValue(const wxString &aNetName) override
virtual void getListContent(wxArrayString &aStringList)
Fill the combobox list.
void onMouseClick(wxMouseEvent &aEvent)
void doStartingKey(wxKeyEvent &aEvent)
void rebuildList()
Call this to rebuild the list from the getListContent() method.
wxString getFilterValue() const
Get the current value of the filter control.
virtual void Accept()
void OnStartingKey(wxKeyEvent &aEvent)
std::optional< wxString > getSelectedValue() const
Get the currently selected value in the list, or std::nullopt.
void onIdle(wxIdleEvent &aEvent)
wxString GetStringValue() const override
wxArrayString m_stringList
wxSize GetAdjustedSize(int aMinWidth, int aPrefHeight, int aMaxHeight) override
wxListBox * m_listBox
wxEvtHandler * m_focusHandler
wxWindow * GetControl() override
bool Create(wxWindow *aParent) override
void OnPopup() override
void doSetFocus(wxWindow *aWindow)
void SetStringList(const wxArrayString &aStringList)
void onKeyDown(wxKeyEvent &aEvent)
void onMouseMoved(const wxPoint aScreenPos)
wxTextCtrl * m_filterCtrl
wxDECLARE_EVENT(FILTERED_ITEM_SELECTED, wxCommandEvent)