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 (C) 2024 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 SetStringValue( const wxString& aNetName ) override;
50
51 void OnPopup() override;
52
53 void OnStartingKey( wxKeyEvent& aEvent );
54
55 wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override;
56
57 virtual void Accept() = 0;
58
59protected:
63 std::optional<wxString> getSelectedValue() const;
64
68 wxString getFilterValue() const;
69
73 void rebuildList();
74
75private:
79 virtual void getListContent( wxArrayString& aListToFill ) = 0;
80
81 wxSize updateSize();
82
83 void onIdle( wxIdleEvent& aEvent );
84
85 // Hot-track the mouse (for focus and listbox selection)
86 void onMouseMoved( const wxPoint aScreenPos );
87 void onMouseClick( wxMouseEvent& aEvent );
88 void onKeyDown( wxKeyEvent& aEvent );
89 void onEnter( wxCommandEvent& aEvent );
90 void onFilterEdit( wxCommandEvent& aEvent );
91 void doStartingKey( wxKeyEvent& aEvent );
92 void doSetFocus( wxWindow* aWindow );
93
94protected:
95 wxTextValidator* m_filterValidator;
96 wxTextCtrl* m_filterCtrl;
97 wxListBox* m_listBox;
100
101 wxEvtHandler* m_focusHandler;
102};
103
104
105wxDECLARE_EVENT( FILTERED_ITEM_SELECTED, wxCommandEvent );
106
113class FILTER_COMBOBOX : public wxComboCtrl
114{
115public:
116 FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
117 const wxSize& size = wxDefaultSize, long style = 0 );
118
120
121protected:
122 void setFilterPopup( std::unique_ptr<FILTER_COMBOPOPUP> aPopup );
123
124 void onKeyDown( wxKeyEvent& aEvt );
125
127};
A combobox that has a filterable popup.
FILTER_COMBOPOPUP * m_filterPopup
void onKeyDown(wxKeyEvent &aEvt)
void setFilterPopup(std::unique_ptr< FILTER_COMBOPOPUP > aPopup)
void onEnter(wxCommandEvent &aEvent)
wxTextValidator * m_filterValidator
void onFilterEdit(wxCommandEvent &aEvent)
void SetStringValue(const wxString &aNetName) override
void onMouseClick(wxMouseEvent &aEvent)
void doStartingKey(wxKeyEvent &aEvent)
virtual void getListContent(wxArrayString &aListToFill)=0
Implement this to fill in the given list.
void rebuildList()
Call this to rebuild the list from the getListContent() method.
wxString getFilterValue() const
Get the current value of the filter control.
void OnStartingKey(wxKeyEvent &aEvent)
std::optional< wxString > getSelectedValue() const
Get the currently selected value in the list, or std::nullopt.
void onIdle(wxIdleEvent &aEvent)
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)
virtual void Accept()=0
void onKeyDown(wxKeyEvent &aEvent)
void onMouseMoved(const wxPoint aScreenPos)
wxTextCtrl * m_filterCtrl
wxDECLARE_EVENT(FILTERED_ITEM_SELECTED, wxCommandEvent)