33#include <wx/display.h>
34#include <wx/valtext.h>
35#include <wx/listbox.h>
36#include <wx/stattext.h>
38#include <wx/textctrl.h>
44#if defined( __WXOSX_MAC__ )
45 #define POPUP_PADDING 2
46 #define LIST_ITEM_PADDING 5
47 #define LIST_PADDING 5
48#elif defined( __WXMSW__ )
49 #define POPUP_PADDING 0
50 #define LIST_ITEM_PADDING 2
51 #define LIST_PADDING 5
53 #define POPUP_PADDING 0
54 #define LIST_ITEM_PADDING 6
55 #define LIST_PADDING 5
58#define NO_NET _( "<no net>" )
59#define CREATE_NET _( "<create net>" )
77 bool Create(wxWindow* aParent)
override
79 wxPanel::Create( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
81 wxBoxSizer* mainSizer;
82 mainSizer =
new wxBoxSizer( wxVERTICAL );
84 wxStaticText* filterLabel =
new wxStaticText(
this, wxID_ANY,
_(
"Filter:" ) );
85 mainSizer->Add( filterLabel, 0, wxEXPAND, 0 );
87 m_filterCtrl =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
88 wxDefaultSize, wxTE_PROCESS_ENTER );
94 m_listBox =
new wxListBox(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0,
nullptr,
95 wxLB_SINGLE|wxLB_NEEDED_SB );
96 mainSizer->Add(
m_listBox, 0, wxEXPAND|wxTOP, 2 );
98 SetSizer( mainSizer );
168 return wxEmptyString;
203 wxString selectedNetName;
204 wxString escapedNetName;
205 wxString remainingName;
206 int selection =
m_listBox->GetSelection();
209 selectedNetName =
m_listBox->GetString( (
unsigned) selection );
214 escapedNetName = it->second;
216 escapedNetName = selectedNetName;
225 else if( escapedNetName ==
NO_NET )
228 GetComboCtrl()->SetValue(
NO_NET );
230 else if( escapedNetName.StartsWith(
CREATE_NET, &remainingName ) &&
231 !remainingName.IsEmpty() )
234 remainingName = remainingName.Mid( 1 ).Trim().Trim(
false );
242 board->
Add( newnet );
265 if( netInfo ==
nullptr || netInfo->
GetNetCode() == 0 )
268 GetComboCtrl()->SetValue(
NO_NET );
277 wxCommandEvent changeEvent( NET_SELECTED );
278 wxPostEvent( GetComboCtrl(), changeEvent );
293 for(
size_t i = 0; i <
m_listBox->GetCount(); ++i )
296 listWidth = std::max( listWidth, itemWidth +
LIST_PADDING * 3 );
299 wxSize listSize( listWidth, listHeight );
300 wxSize popupSize( listWidth, listTop + listHeight );
302 SetSize( popupSize );
303 GetParent()->SetSize( popupSize );
313 wxArrayString netNames;
314 wxString netstring =
m_filterCtrl->GetValue().Trim().Trim(
false );
315 wxString
filter = netstring.Lower();
324 if( netinfo->GetNetCode() > 0 && netinfo->IsCurrent() )
328 if(
filter.IsEmpty() || wxString( netname ).MakeLower().Matches(
filter ) )
330 netNames.push_back( netname );
336 std::sort( netNames.begin(), netNames.end(),
337 [](
const wxString& lhs,
const wxString& rhs )
339 return StrNumCmp( lhs, rhs, true ) < 0;
345 netNames.insert( netNames.begin(),
NO_NET );
349 wxString newnet = wxString::Format(
"%s: %s",
CREATE_NET, netstring );
350 netNames.insert( netNames.end(), newnet );
362 static wxPoint lastPos;
365 if( screenPos != lastPos )
381 if(
m_listBox->GetScreenRect().Contains( aScreenPos ) )
385 wxPoint relativePos =
m_listBox->ScreenToClient( aScreenPos );
386 int item =
m_listBox->HitTest( relativePos );
391 else if(
m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
402 if( aEvent.GetEventObject() ==
m_listBox )
409 wxWindow* window =
dynamic_cast<wxWindow*
>( aEvent.GetEventObject() );
413 wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
415 if(
m_listBox->GetScreenRect().Contains( screenPos ) )
417 wxPoint localPos =
m_listBox->ScreenToClient( screenPos );
427 switch( aEvent.GetKeyCode() )
433 m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
434 ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
442 case WXK_NUMPAD_ENTER:
448 case WXK_NUMPAD_DOWN:
499 if( aEvent.GetKeyCode() == WXK_BACK )
507 int ch = aEvent.GetUnicodeKey();
513 ch = aEvent.GetKeyCode();
514 isPrintable = ch > WXK_SPACE && ch < WXK_START;
519 wxString
text(
static_cast<wxChar
>( ch ) );
522 if( !aEvent.ShiftDown() )
557 const wxSize &size,
long style ) :
558 wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER )
577 int key = aEvt.GetKeyCode();
587 else if( ( key == WXK_RETURN || key == WXK_NUMPAD_ENTER ) && aEvt.ShiftDown() )
589 wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
593 else if( key == WXK_RETURN || key == WXK_NUMPAD_ENTER || key == WXK_DOWN
594 || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
600 else if( key > WXK_SPACE && key < WXK_START )
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Handle the data for a net.
const wxString & GetNetname() const
Container for NETINFO_ITEM elements, which are the nets.
BOARD * GetParent() const
NETINFO_ITEM * GetNetItem(int aNetCode) const
void SetNetInfo(const NETINFO_LIST *aNetInfoList)
wxString m_indeterminateString
NET_SELECTOR_COMBOPOPUP * m_netSelectorPopup
NET_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void SetBoard(BOARD *aBoard)
void SetIndeterminateString(const wxString &aString)
void SetSelectedNetcode(int aNetcode)
void onKeyDown(wxKeyEvent &aEvt)
void SetSelectedNet(const wxString &aNetname)
wxString GetSelectedNetname()
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...
wxDEFINE_EVENT(NET_SELECTED, wxCommandEvent)
#define LIST_ITEM_PADDING
wxString UnescapeString(const wxString &aSource)
Functions to provide common constants and other functions to assist in making a consistent UI.