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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <memory>
24#include <optional>
25
26#include <wx/panel.h>
27#include <wx/combo.h>
28#include <wx/listbox.h>
29
30
31class wxTextValidator;
32class wxTextCtrl;
33class wxListBox;
34
35
36class FILTER_COMBOPOPUP : public wxPanel, public wxComboPopup
37{
38public:
40
41 bool Create( wxWindow* aParent ) override;
42
43 wxWindow* GetControl() override { return this; }
44
45 void SetStringList( const wxArrayString& aStringList );
46
47 wxString GetStringValue() const override;
48 void SetStringValue( const wxString& aNetName ) override;
49
50 void SetSelectedString( const wxString& aString );
51
52 void OnPopup() override;
53
54 void OnStartingKey( wxKeyEvent& aEvent );
55
56 wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override;
57
58 virtual void Accept();
59
60protected:
64 std::optional<wxString> getSelectedValue() const;
65
69 wxString getFilterValue() const;
70
74 virtual void getListContent( wxArrayString& aStringList );
75
79 void rebuildList();
80
81private:
82 wxSize updateSize();
83
84 void onIdle( wxIdleEvent& aEvent );
85
86 // Hot-track the mouse (for focus and listbox selection)
87 void onMouseMoved( const wxPoint aScreenPos );
88 void onMouseClick( wxMouseEvent& aEvent );
89 void onKeyDown( wxKeyEvent& aEvent );
90 void onEnter( wxCommandEvent& aEvent );
91 void onFilterEdit( wxCommandEvent& aEvent );
92 void doStartingKey( wxKeyEvent& aEvent );
93 void doSetFocus( wxWindow* aWindow );
94
95protected:
96 wxTextValidator* m_filterValidator;
97 wxTextCtrl* m_filterCtrl;
98 wxListBox* m_listBox;
101
102 wxEvtHandler* m_focusHandler;
103
105 wxArrayString m_stringList;
106};
107
108
109wxDECLARE_EVENT( FILTERED_ITEM_SELECTED, wxCommandEvent );
110
117class FILTER_COMBOBOX : public wxComboCtrl
118{
119public:
120 // C'tor matching wxFormBuilder's Custom Control
121 FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
122 const wxSize& size = wxDefaultSize, long style = 0 );
123
124 // C'tor matching wxFormBuilder's ComboxBox.
125 FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
126 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
127 int count = 0, wxString strings[] = nullptr, long style = 0 );
128
130
131 virtual void SetStringList( const wxArrayString& aStringList );
132
133 virtual void SetSelectedString( const wxString& aString );
134
135protected:
136 void setFilterPopup( FILTER_COMBOPOPUP* aPopup );
137
138 void onKeyDown( wxKeyEvent& aEvt );
139
141};
virtual void SetSelectedString(const wxString &aString)
FILTER_COMBOPOPUP * m_filterPopup
void setFilterPopup(FILTER_COMBOPOPUP *aPopup)
virtual void SetStringList(const wxArrayString &aStringList)
FILTER_COMBOBOX(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
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)