27#include <wx/textctrl.h>
28#include <wx/listbox.h>
29#include <wx/settings.h>
31#include <wx/stattext.h>
32#include <wx/valtext.h>
39#if defined( __WXOSX_MAC__ )
40 #define POPUP_PADDING 2
41 #define LIST_ITEM_PADDING 2
42 #define LIST_PADDING 7
43#elif defined( __WXMSW__ )
44 #define POPUP_PADDING 0
45 #define LIST_ITEM_PADDING 2
46 #define LIST_PADDING 5
48 #define POPUP_PADDING 0
49 #define LIST_ITEM_PADDING 6
50 #define LIST_PADDING 5
55 m_filterValidator( nullptr ),
56 m_filterCtrl( nullptr ),
58 m_minPopupWidth( -1 ),
59 m_maxPopupHeight( 1000 ),
60 m_focusHandler( nullptr )
67 wxPanel::Create( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
69 wxBoxSizer* mainSizer;
70 mainSizer =
new wxBoxSizer( wxVERTICAL );
72 wxStaticText* filterLabel =
new wxStaticText(
this, wxID_ANY,
_(
"Filter:" ) );
73 mainSizer->Add( filterLabel, 0, wxEXPAND, 0 );
75 m_filterCtrl =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
82 m_listBox =
new wxListBox(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0,
nullptr,
83 wxLB_SINGLE | wxLB_NEEDED_SB );
84 mainSizer->Add(
m_listBox, 1, wxEXPAND | wxTOP, 2 );
86 SetSizer( mainSizer );
120 if( GetWindowStyleFlag() & wxCB_READONLY )
123 wxComboPopup::SetStringValue( aNetName );
168 wxCommandEvent changeEvent( FILTERED_ITEM_SELECTED );
169 wxPostEvent( GetComboCtrl(), changeEvent );
192 if( filterString.IsEmpty() || str.Lower().Contains( filterString.Lower() ) )
193 aListContent.push_back( str );
200 wxArrayString newList;
209 int selection =
m_listBox->GetSelection();
212 return m_listBox->GetString( selection );
220 return m_filterCtrl->GetValue().Trim(
true ).Trim(
false );
235 for(
size_t i = 0; i <
m_listBox->GetCount(); ++i )
238 listWidth = std::max( listWidth, itemWidth +
LIST_PADDING * 2 );
241 wxSize listSize( listWidth, listHeight );
242 wxSize popupSize( listWidth, listTop + listHeight );
244 SetSize( popupSize );
245 GetParent()->SetSize( popupSize );
257 static wxPoint lastPos;
260 if( screenPos != lastPos )
277 if(
m_listBox->GetScreenRect().Contains( aScreenPos ) )
281 wxPoint relativePos =
m_listBox->ScreenToClient( aScreenPos );
282 int item =
m_listBox->HitTest( relativePos );
287 else if(
m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
298 if( aEvent.GetEventObject() ==
m_listBox )
305 wxWindow* window =
dynamic_cast<wxWindow*
>( aEvent.GetEventObject() );
309 wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
311 if(
m_listBox->GetScreenRect().Contains( screenPos ) )
313 wxPoint localPos =
m_listBox->ScreenToClient( screenPos );
324 switch( aEvent.GetKeyCode() )
330 m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
331 ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
339 case WXK_NUMPAD_ENTER:
345 case WXK_NUMPAD_DOWN:
400 if( aEvent.GetKeyCode() == WXK_BACK )
408 int ch = aEvent.GetUnicodeKey();
414 ch = aEvent.GetKeyCode();
415 isPrintable = ch > WXK_SPACE && ch < WXK_START;
420 wxString
text(
static_cast<wxChar
>( ch ) );
423 if( !aEvent.ShiftDown() )
441 const wxSize &size,
long style ) :
442 wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxTE_PROCESS_ENTER ),
443 m_filterPopup( nullptr )
448 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
453 const wxPoint& pos,
const wxSize& size,
454 int count, wxString strings[],
long style ) :
458 wxASSERT( value.IsEmpty() && count == 0 && strings ==
nullptr );
486 SetPopupControl( aPopup );
492 int key = aEvt.GetKeyCode();
501 else if( ( key == WXK_RETURN || key == WXK_NUMPAD_ENTER ) && aEvt.ShiftDown() )
503 wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
506 else if( key == WXK_RETURN || key == WXK_NUMPAD_ENTER || key == WXK_DOWN
507 || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
512 else if( key > WXK_SPACE && key < WXK_START && ( GetWindowStyleFlag() & wxCB_READONLY ) )
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)
FILTER_COMBOBOX(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void onKeyDown(wxKeyEvent &aEvt)
#define LIST_ITEM_PADDING
wxDEFINE_EVENT(FILTERED_ITEM_SELECTED, wxCommandEvent)
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Functions to provide common constants and other functions to assist in making a consistent UI.