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 5
42 #define LIST_PADDING 5
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, 0, wxEXPAND | wxTOP, 2 );
86 SetSizer( mainSizer );
101 m_listBox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,
120 m_listBox->SetStringSelection( GetStringValue() );
149 wxArrayString newList;
158 int selection =
m_listBox->GetSelection();
161 return m_listBox->GetString( selection );
169 return m_filterCtrl->GetValue().Trim(
true ).Trim(
false );
184 for(
size_t i = 0; i <
m_listBox->GetCount(); ++i )
187 listWidth = std::max( listWidth, itemWidth +
LIST_PADDING * 3 );
190 wxSize listSize( listWidth, listHeight );
191 wxSize popupSize( listWidth, listTop + listHeight );
193 SetSize( popupSize );
194 GetParent()->SetSize( popupSize );
206 static wxPoint lastPos;
209 if( screenPos != lastPos )
226 if(
m_listBox->GetScreenRect().Contains( aScreenPos ) )
230 wxPoint relativePos =
m_listBox->ScreenToClient( aScreenPos );
231 int item =
m_listBox->HitTest( relativePos );
236 else if(
m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
248 if( aEvent.GetEventObject() ==
m_listBox )
255 wxWindow* window =
dynamic_cast<wxWindow*
>( aEvent.GetEventObject() );
259 wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
261 if(
m_listBox->GetScreenRect().Contains( screenPos ) )
263 wxPoint localPos =
m_listBox->ScreenToClient( screenPos );
274 switch( aEvent.GetKeyCode() )
280 m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
281 ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
289 case WXK_NUMPAD_ENTER:
295 case WXK_NUMPAD_DOWN:
349 if( aEvent.GetKeyCode() == WXK_BACK )
357 int ch = aEvent.GetUnicodeKey();
363 ch = aEvent.GetKeyCode();
364 isPrintable = ch > WXK_SPACE && ch < WXK_START;
369 wxString
text(
static_cast<wxChar
>( ch ) );
372 if( !aEvent.ShiftDown() )
390 const wxSize &size,
long style ) :
391 wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER )
396 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
409 SetPopupControl( aPopup.release() );
415 int key = aEvt.GetKeyCode();
425 else if( ( key == WXK_RETURN || key == WXK_NUMPAD_ENTER ) && aEvt.ShiftDown() )
427 wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
431 else if( key == WXK_RETURN || key == WXK_NUMPAD_ENTER || key == WXK_DOWN
432 || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
438 else if( key > WXK_SPACE && key < WXK_START )
FILTER_COMBOPOPUP * m_filterPopup
FILTER_COMBOBOX(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void onKeyDown(wxKeyEvent &aEvt)
void setFilterPopup(std::unique_ptr< FILTER_COMBOPOPUP > aPopup)
#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.