2018-08-19 16:11:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <widgets/net_selector.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <netinfo.h>
|
|
|
|
#include <wx/arrstr.h>
|
2018-09-21 19:39:28 +00:00
|
|
|
#include <wx/display.h>
|
2018-08-19 16:11:58 +00:00
|
|
|
|
|
|
|
wxDEFINE_EVENT( NET_SELECTED, wxCommandEvent );
|
|
|
|
|
2018-09-27 12:50:06 +00:00
|
|
|
#if defined( __WXOSX_MAC__ )
|
|
|
|
#define POPUP_PADDING 2
|
|
|
|
#define LIST_ITEM_PADDING 5
|
|
|
|
#define LIST_PADDING 5
|
|
|
|
#elif defined( __WXMSW__ )
|
|
|
|
#define POPUP_PADDING 0
|
|
|
|
#define LIST_ITEM_PADDING 2
|
|
|
|
#define LIST_PADDING 5
|
2018-09-26 21:50:27 +00:00
|
|
|
#else
|
2018-09-27 12:50:06 +00:00
|
|
|
#define POPUP_PADDING 0
|
2018-10-11 17:51:48 +00:00
|
|
|
#define LIST_ITEM_PADDING 6
|
2018-09-27 12:50:06 +00:00
|
|
|
#define LIST_PADDING 5
|
2018-09-26 21:50:27 +00:00
|
|
|
#endif
|
2018-08-19 16:11:58 +00:00
|
|
|
|
|
|
|
#define NO_NET _( "<no net>" )
|
|
|
|
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
class NET_SELECTOR_COMBOPOPUP : public wxPanel, public wxComboPopup
|
2018-09-27 19:42:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-09-29 21:04:32 +00:00
|
|
|
NET_SELECTOR_COMBOPOPUP() :
|
|
|
|
m_minPopupWidth( -1 ),
|
|
|
|
m_maxPopupHeight( 1000 ),
|
|
|
|
m_netinfoList( nullptr ),
|
2018-09-29 22:05:43 +00:00
|
|
|
m_selectedNetcode( 0 ),
|
|
|
|
m_focusHandler( nullptr )
|
2018-09-29 21:04:32 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
bool Create(wxWindow* aParent) override
|
2018-09-27 19:42:59 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
wxPanel::Create( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
|
2018-09-27 19:42:59 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxBoxSizer* mainSizer;
|
|
|
|
mainSizer = new wxBoxSizer( wxVERTICAL );
|
2018-09-27 19:42:59 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxStaticText* filterLabel = new wxStaticText( this, wxID_ANY, _( "Filter:" ) );
|
|
|
|
mainSizer->Add( filterLabel, 0, wxEXPAND, 0 );
|
2018-09-27 19:42:59 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
m_filterCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
2018-09-29 00:21:52 +00:00
|
|
|
wxDefaultSize, wxTE_PROCESS_ENTER );
|
2018-10-10 17:58:19 +00:00
|
|
|
m_filterValidator = new wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
2018-10-10 18:48:34 +00:00
|
|
|
m_filterValidator->SetCharExcludes( " " );
|
2018-10-10 17:58:19 +00:00
|
|
|
m_filterCtrl->SetValidator( *m_filterValidator );
|
2018-09-29 21:04:32 +00:00
|
|
|
mainSizer->Add( m_filterCtrl, 0, wxEXPAND, 0 );
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
m_listBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, 0,
|
|
|
|
wxLB_SINGLE|wxLB_NEEDED_SB );
|
|
|
|
mainSizer->Add( m_listBox, 0, wxEXPAND|wxTOP, 2 );
|
2018-09-28 21:39:08 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
SetSizer( mainSizer );
|
2018-08-19 16:11:58 +00:00
|
|
|
Layout();
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
Connect( wxEVT_IDLE, wxIdleEventHandler( NET_SELECTOR_COMBOPOPUP::onIdle ), NULL, this );
|
|
|
|
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( NET_SELECTOR_COMBOPOPUP::onKeyDown ), NULL, this );
|
|
|
|
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this );
|
|
|
|
m_listBox->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this );
|
|
|
|
m_filterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onFilterEdit ), NULL, this );
|
|
|
|
m_filterCtrl->Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onEnter ), NULL, this );
|
2018-09-29 00:21:52 +00:00
|
|
|
|
|
|
|
// <enter> in a ListBox comes in as a double-click on GTK
|
2018-09-29 21:04:32 +00:00
|
|
|
m_listBox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onEnter ), NULL, this );
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
return true;
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxWindow *GetControl() override { return this; }
|
2018-09-29 00:21:52 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void SetStringValue( const wxString& aNetName ) override
|
|
|
|
{
|
|
|
|
// shouldn't be here (combo is read-only)
|
2018-09-22 10:51:18 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxString GetStringValue() const override
|
2018-08-19 16:11:58 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
NETINFO_ITEM* netInfo = m_netinfoList->GetNetItem( m_selectedNetcode );
|
|
|
|
|
|
|
|
if( netInfo && netInfo->GetNet() > 0 )
|
|
|
|
return netInfo->GetNetname();
|
|
|
|
|
|
|
|
return NO_NET;
|
2018-09-26 20:25:27 +00:00
|
|
|
}
|
2018-09-25 16:53:04 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void SetNetInfo( NETINFO_LIST* aNetInfoList )
|
2018-09-26 20:25:27 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
m_netinfoList = aNetInfoList;
|
|
|
|
rebuildList();
|
2018-09-26 20:25:27 +00:00
|
|
|
}
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void SetIndeterminate() { m_selectedNetcode = -1; }
|
|
|
|
bool IsIndeterminate() { return m_selectedNetcode == -1; }
|
2018-09-27 19:42:59 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void SetSelectedNetcode( int aNetcode ) { m_selectedNetcode = aNetcode; }
|
|
|
|
int GetSelectedNetcode() { return m_selectedNetcode; }
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-10-10 17:42:27 +00:00
|
|
|
void SetSelectedNet( const wxString& aNetname )
|
|
|
|
{
|
|
|
|
if( m_netinfoList && m_netinfoList->GetNetItem( aNetname ) )
|
|
|
|
m_selectedNetcode = m_netinfoList->GetNetItem( aNetname )->GetNet();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetSelectedNetname()
|
|
|
|
{
|
|
|
|
if( m_netinfoList && m_netinfoList->GetNetItem( m_selectedNetcode ) )
|
|
|
|
return m_netinfoList->GetNetItem( m_selectedNetcode )->GetNetname();
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override
|
|
|
|
{
|
|
|
|
// Called when the popup is first shown. Stash the minWidth and maxHeight so we
|
|
|
|
// can use them later when refreshing the sizes after filter changes.
|
|
|
|
m_minPopupWidth = aMinWidth;
|
|
|
|
m_maxPopupHeight = aMaxHeight;
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
return updateSize();
|
2018-09-26 20:25:27 +00:00
|
|
|
}
|
2018-09-21 19:39:28 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void OnPopup() override
|
2018-09-26 20:25:27 +00:00
|
|
|
{
|
2018-10-11 10:21:28 +00:00
|
|
|
// While it can sometimes be useful to keep the filter, it's always expected.
|
|
|
|
// Better to clear it.
|
|
|
|
m_filterCtrl->Clear();
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
// The updateSize() call in GetAdjustedSize() leaves the height off-by-one for
|
|
|
|
// some reason, so do it again.
|
|
|
|
updateSize();
|
|
|
|
}
|
2018-09-21 19:39:28 +00:00
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
void OnStartingKey( wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
doSetFocus( m_filterCtrl );
|
|
|
|
doStartingKey( aEvent );
|
|
|
|
}
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
void Accept()
|
|
|
|
{
|
|
|
|
wxString selectedNetName;
|
|
|
|
int selection = m_listBox->GetSelection();
|
|
|
|
|
|
|
|
if( selection >= 0 )
|
|
|
|
selectedNetName = m_listBox->GetString( (unsigned) selection );
|
2018-09-28 21:39:08 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
if( selectedNetName.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_selectedNetcode = -1;
|
|
|
|
GetComboCtrl()->SetValue( INDETERMINATE );
|
|
|
|
}
|
|
|
|
else if( selectedNetName == NO_NET )
|
|
|
|
{
|
|
|
|
m_selectedNetcode = 0;
|
|
|
|
GetComboCtrl()->SetValue( NO_NET );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selectedNetcode = m_netinfoList->GetNetItem( selectedNetName )->GetNet();
|
|
|
|
GetComboCtrl()->SetValue( selectedNetName );
|
2018-09-28 18:36:31 +00:00
|
|
|
}
|
2018-09-29 21:04:32 +00:00
|
|
|
|
|
|
|
wxCommandEvent changeEvent( NET_SELECTED );
|
|
|
|
wxPostEvent( GetComboCtrl(), changeEvent );
|
|
|
|
|
|
|
|
Dismiss();
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-09-29 21:04:32 +00:00
|
|
|
wxSize updateSize()
|
2018-08-19 16:11:58 +00:00
|
|
|
{
|
2018-09-28 21:39:08 +00:00
|
|
|
int listTop = m_listBox->GetRect().y;
|
2018-08-19 16:11:58 +00:00
|
|
|
int itemHeight = GetTextSize( wxT( "Xy" ), this ).y + LIST_ITEM_PADDING;
|
2018-09-28 21:39:08 +00:00
|
|
|
int listHeight = m_listBox->GetCount() * itemHeight + LIST_PADDING;
|
2018-08-19 16:11:58 +00:00
|
|
|
|
|
|
|
if( listTop + listHeight >= m_maxPopupHeight )
|
|
|
|
listHeight = m_maxPopupHeight - listTop - 1;
|
|
|
|
|
2018-09-28 21:39:08 +00:00
|
|
|
int listWidth = m_minPopupWidth;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_listBox->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
int itemWidth = GetTextSize( m_listBox->GetString( i ), m_listBox ).x;
|
|
|
|
listWidth = std::max( listWidth, itemWidth + LIST_PADDING * 3 );
|
|
|
|
}
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
wxSize listSize( listWidth, listHeight );
|
|
|
|
wxSize popupSize( listWidth, listTop + listHeight );
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
SetSize( popupSize ); // us
|
|
|
|
GetParent()->SetSize( popupSize ); // the window that wxComboCtrl put us in
|
|
|
|
|
|
|
|
m_listBox->SetMinSize( listSize );
|
|
|
|
m_listBox->SetSize( listSize );
|
|
|
|
|
|
|
|
return popupSize;
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rebuildList()
|
|
|
|
{
|
|
|
|
wxArrayString netNames;
|
|
|
|
wxString filter = m_filterCtrl->GetValue().MakeLower();
|
|
|
|
|
|
|
|
if( !filter.IsEmpty() )
|
|
|
|
filter = wxT( "*" ) + filter + wxT( "*" );
|
|
|
|
|
|
|
|
for( NETINFO_ITEM* netinfo : *m_netinfoList )
|
|
|
|
{
|
|
|
|
if( netinfo->GetNet() == 0 )
|
|
|
|
continue; // we'll insert NO_NET after sorting
|
|
|
|
|
|
|
|
if( filter.IsEmpty() || wxString( netinfo->GetNetname() ).MakeLower().Matches( filter ) )
|
|
|
|
netNames.push_back( netinfo->GetNetname() );
|
|
|
|
}
|
|
|
|
std::sort( netNames.begin(), netNames.end() );
|
|
|
|
|
|
|
|
if( filter.IsEmpty() || wxString( NO_NET ).MakeLower().Matches( filter ) )
|
|
|
|
netNames.insert( netNames.begin(), NO_NET );
|
|
|
|
|
2018-09-28 21:39:08 +00:00
|
|
|
m_listBox->Set( netNames );
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 20:25:27 +00:00
|
|
|
void onIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
2018-09-27 10:52:58 +00:00
|
|
|
// Generate synthetic (but reliable) MouseMoved events
|
2018-09-26 20:25:27 +00:00
|
|
|
static wxPoint lastPos;
|
|
|
|
wxPoint screenPos = wxGetMousePosition();
|
|
|
|
|
2018-09-27 10:52:58 +00:00
|
|
|
if( screenPos != lastPos )
|
|
|
|
{
|
2018-09-26 20:25:27 +00:00
|
|
|
lastPos = screenPos;
|
2018-09-27 10:52:58 +00:00
|
|
|
onMouseMoved( screenPos );
|
|
|
|
}
|
2018-09-29 22:05:43 +00:00
|
|
|
|
|
|
|
if( m_focusHandler )
|
|
|
|
{
|
|
|
|
m_filterCtrl->PushEventHandler( m_focusHandler );
|
|
|
|
m_focusHandler = nullptr;
|
|
|
|
}
|
2018-09-27 10:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hot-track the mouse (for focus and listbox selection)
|
|
|
|
void onMouseMoved( const wxPoint aScreenPos )
|
2018-09-27 19:42:59 +00:00
|
|
|
{
|
2018-09-28 21:39:08 +00:00
|
|
|
if( m_listBox->GetScreenRect().Contains( aScreenPos ) )
|
2018-09-26 20:25:27 +00:00
|
|
|
{
|
2018-09-28 21:39:08 +00:00
|
|
|
doSetFocus( m_listBox );
|
2018-09-26 20:25:27 +00:00
|
|
|
|
2018-09-28 21:39:08 +00:00
|
|
|
wxPoint relativePos = m_listBox->ScreenToClient( aScreenPos );
|
|
|
|
int item = m_listBox->HitTest( relativePos );
|
2018-09-26 20:25:27 +00:00
|
|
|
|
|
|
|
if( item >= 0 )
|
2018-09-28 21:39:08 +00:00
|
|
|
m_listBox->SetSelection( item );
|
2018-09-26 20:25:27 +00:00
|
|
|
}
|
2018-09-27 10:52:58 +00:00
|
|
|
else if( m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
|
2018-09-26 20:25:27 +00:00
|
|
|
{
|
|
|
|
doSetFocus( m_filterCtrl );
|
|
|
|
}
|
2018-09-29 21:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onMouseClick( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
// Accept a click event from anywhere. Different platform implementations have
|
|
|
|
// different foibles with regard to transient popups and their children.
|
|
|
|
|
|
|
|
if( aEvent.GetEventObject() == m_listBox )
|
2018-09-27 19:42:59 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
m_listBox->SetSelection( m_listBox->HitTest( aEvent.GetPosition() ) );
|
|
|
|
Accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxWindow* window = dynamic_cast<wxWindow*>( aEvent.GetEventObject() );
|
|
|
|
|
|
|
|
if( window )
|
|
|
|
{
|
|
|
|
wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
|
|
|
|
|
|
|
|
if( m_listBox->GetScreenRect().Contains( screenPos ) )
|
|
|
|
{
|
|
|
|
wxPoint localPos = m_listBox->ScreenToClient( screenPos );
|
|
|
|
|
|
|
|
m_listBox->SetSelection( m_listBox->HitTest( localPos ) );
|
|
|
|
Accept();
|
|
|
|
}
|
2018-09-27 19:42:59 +00:00
|
|
|
}
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 10:51:18 +00:00
|
|
|
void onKeyDown( wxKeyEvent& aEvent )
|
|
|
|
{
|
2018-09-26 20:25:27 +00:00
|
|
|
switch( aEvent.GetKeyCode() )
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
// Control keys go to the parent combobox
|
2018-09-27 23:23:22 +00:00
|
|
|
case WXK_TAB:
|
2018-09-29 21:04:32 +00:00
|
|
|
Dismiss();
|
2018-09-27 23:23:22 +00:00
|
|
|
|
|
|
|
m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
|
|
|
|
( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
|
|
|
|
break;
|
|
|
|
|
2018-09-26 20:25:27 +00:00
|
|
|
case WXK_ESCAPE:
|
2018-09-29 21:04:32 +00:00
|
|
|
Dismiss();
|
2018-09-26 20:25:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_RETURN:
|
2018-09-29 21:04:32 +00:00
|
|
|
Accept();
|
2018-09-26 20:25:27 +00:00
|
|
|
break;
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
// Arrows go to the list box
|
2018-09-26 20:25:27 +00:00
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_NUMPAD_DOWN:
|
2018-09-28 21:39:08 +00:00
|
|
|
doSetFocus( m_listBox );
|
|
|
|
m_listBox->SetSelection( std::min( m_listBox->GetSelection() + 1, (int) m_listBox->GetCount() - 1 ) );
|
2018-09-26 20:25:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_NUMPAD_UP:
|
2018-09-28 21:39:08 +00:00
|
|
|
doSetFocus( m_listBox );
|
|
|
|
m_listBox->SetSelection( std::max( m_listBox->GetSelection() - 1, 0 ) );
|
2018-09-26 20:25:27 +00:00
|
|
|
break;
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
// Everything else goes to the filter textbox
|
2018-09-26 20:25:27 +00:00
|
|
|
default:
|
2018-09-29 21:04:32 +00:00
|
|
|
if( !m_filterCtrl->HasFocus() )
|
|
|
|
{
|
|
|
|
doSetFocus( m_filterCtrl );
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
// Because we didn't have focus we missed our chance to have the native widget
|
|
|
|
// handle the keystroke. We'll have to do the first character ourselves.
|
|
|
|
doStartingKey( aEvent );
|
2018-09-29 21:04:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// On some platforms a wxComboFocusHandler will have been pushed which
|
|
|
|
// unhelpfully gives the event right back to the popup. Make sure the filter
|
|
|
|
// control is going to get the event.
|
|
|
|
if( m_filterCtrl->GetEventHandler() != m_filterCtrl )
|
2018-09-29 22:05:43 +00:00
|
|
|
m_focusHandler = m_filterCtrl->PopEventHandler();
|
2018-09-29 21:04:32 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
2018-09-27 10:02:23 +00:00
|
|
|
break;
|
2018-09-27 19:42:59 +00:00
|
|
|
}
|
2018-09-26 20:25:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 00:21:52 +00:00
|
|
|
void onEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
Accept();
|
2018-09-29 00:21:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
void onFilterEdit( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
rebuildList();
|
|
|
|
updateSize();
|
|
|
|
|
|
|
|
if( m_listBox->GetCount() > 0 )
|
|
|
|
m_listBox->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void doStartingKey( wxKeyEvent& aEvent )
|
2018-09-27 10:52:58 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
if( aEvent.GetKeyCode() == WXK_BACK )
|
|
|
|
{
|
|
|
|
const long pos = m_filterCtrl->GetLastPosition();
|
|
|
|
m_filterCtrl->Remove( pos - 1, pos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool isPrintable;
|
|
|
|
int ch = aEvent.GetUnicodeKey();
|
|
|
|
|
|
|
|
if( ch != WXK_NONE )
|
|
|
|
isPrintable = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ch = aEvent.GetKeyCode();
|
2018-10-10 17:58:19 +00:00
|
|
|
isPrintable = ch > WXK_SPACE && ch < WXK_START;
|
2018-09-29 21:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isPrintable )
|
|
|
|
{
|
|
|
|
wxString text( static_cast<wxChar>( ch ) );
|
|
|
|
|
|
|
|
// wxCHAR_HOOK chars have been converted to uppercase.
|
|
|
|
if( !aEvent.ShiftDown() )
|
|
|
|
text.MakeLower();
|
|
|
|
|
2018-10-09 12:17:17 +00:00
|
|
|
m_filterCtrl->AppendText( text );
|
2018-09-29 21:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-27 10:52:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 20:25:27 +00:00
|
|
|
void doSetFocus( wxWindow* aWindow )
|
|
|
|
{
|
|
|
|
#ifdef __WXOSX_MAC__
|
|
|
|
aWindow->OSXForceFocus();
|
|
|
|
#else
|
|
|
|
aWindow->SetFocus();
|
|
|
|
#endif
|
2018-09-22 10:51:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
protected:
|
2018-10-10 17:58:19 +00:00
|
|
|
wxTextValidator* m_filterValidator;
|
|
|
|
wxTextCtrl* m_filterCtrl;
|
|
|
|
wxListBox* m_listBox;
|
|
|
|
int m_minPopupWidth;
|
|
|
|
int m_maxPopupHeight;
|
2018-08-19 16:11:58 +00:00
|
|
|
|
2018-10-10 17:58:19 +00:00
|
|
|
NETINFO_LIST* m_netinfoList;
|
2018-09-21 19:39:28 +00:00
|
|
|
|
2018-10-10 17:58:19 +00:00
|
|
|
int m_selectedNetcode;
|
2018-09-29 22:05:43 +00:00
|
|
|
|
2018-10-10 17:58:19 +00:00
|
|
|
wxEvtHandler* m_focusHandler;
|
2018-08-19 16:11:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
NET_SELECTOR::NET_SELECTOR( wxWindow *parent, wxWindowID id, const wxPoint &pos,
|
|
|
|
const wxSize &size, long style ) :
|
2018-10-10 11:51:08 +00:00
|
|
|
wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER )
|
2018-09-27 10:52:58 +00:00
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
UseAltPopupWindow();
|
2018-09-27 10:52:58 +00:00
|
|
|
|
2018-09-29 21:04:32 +00:00
|
|
|
m_netSelectorPopup = new NET_SELECTOR_COMBOPOPUP();
|
|
|
|
SetPopupControl( m_netSelectorPopup );
|
2018-10-10 11:51:08 +00:00
|
|
|
|
|
|
|
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( NET_SELECTOR::onKeyDown ), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NET_SELECTOR::~NET_SELECTOR()
|
|
|
|
{
|
|
|
|
Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( NET_SELECTOR::onKeyDown ), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NET_SELECTOR::onKeyDown( wxKeyEvent& aEvt )
|
|
|
|
{
|
|
|
|
int key = aEvt.GetKeyCode();
|
|
|
|
|
|
|
|
if( IsPopupShown() )
|
|
|
|
{
|
|
|
|
// If the popup is shown then it's CHAR_HOOK should be eating these before they
|
|
|
|
// even get to us. But just to be safe, we go ahead and skip.
|
|
|
|
aEvt.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shift-return accepts dialog
|
|
|
|
else if( key == WXK_RETURN && aEvt.ShiftDown() )
|
|
|
|
{
|
|
|
|
wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return, arrow-down and space-bar all open popup
|
|
|
|
else if( key == WXK_RETURN || key == WXK_DOWN || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
|
|
|
|
{
|
|
|
|
Popup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-control characters go to filterbox in popup
|
|
|
|
else if( key > WXK_SPACE && key < WXK_START )
|
|
|
|
{
|
|
|
|
Popup();
|
|
|
|
m_netSelectorPopup->OnStartingKey( aEvt );
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aEvt.Skip();
|
|
|
|
}
|
2018-09-21 19:39:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
void NET_SELECTOR::SetNetInfo( NETINFO_LIST* aNetInfoList )
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
m_netSelectorPopup->SetNetInfo( aNetInfoList );
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
void NET_SELECTOR::SetSelectedNetcode( int aNetcode )
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
m_netSelectorPopup->SetSelectedNetcode( aNetcode );
|
|
|
|
SetValue( m_netSelectorPopup->GetStringValue() );
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
|
2018-10-10 17:42:27 +00:00
|
|
|
void NET_SELECTOR::SetSelectedNet( const wxString& aNetname )
|
|
|
|
{
|
|
|
|
m_netSelectorPopup->SetSelectedNet( aNetname );
|
|
|
|
SetValue( m_netSelectorPopup->GetStringValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString NET_SELECTOR::GetSelectedNetname()
|
|
|
|
{
|
|
|
|
return m_netSelectorPopup->GetSelectedNetname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
void NET_SELECTOR::SetIndeterminate()
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
m_netSelectorPopup->SetIndeterminate();
|
2018-08-19 16:11:58 +00:00
|
|
|
SetValue( INDETERMINATE );
|
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
bool NET_SELECTOR::IsIndeterminate()
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
return m_netSelectorPopup->IsIndeterminate();
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 11:51:08 +00:00
|
|
|
|
2018-08-19 16:11:58 +00:00
|
|
|
int NET_SELECTOR::GetSelectedNetcode()
|
|
|
|
{
|
2018-09-29 21:04:32 +00:00
|
|
|
return m_netSelectorPopup->GetSelectedNetcode();
|
2018-08-19 16:11:58 +00:00
|
|
|
}
|
|
|
|
|