32 #include <wx/arrstr.h> 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;
200 wxString selectedNetName;
201 wxString escapedNetName;
202 wxString remainingName;
203 int selection =
m_listBox->GetSelection();
207 selectedNetName =
m_listBox->GetString( (
unsigned) selection );
212 escapedNetName = it->second;
214 escapedNetName = selectedNetName;
223 else if( escapedNetName ==
NO_NET )
226 GetComboCtrl()->SetValue(
NO_NET );
228 else if( escapedNetName.StartsWith(
CREATE_NET, &remainingName ) &&
229 !remainingName.IsEmpty() )
232 remainingName = remainingName.Mid( 1 ).Trim().Trim(
false );
239 if( board !=
nullptr )
240 board->
Add( newnet );
255 if( board !=
nullptr )
267 if( netInfo ==
nullptr || netInfo->
GetNetCode() == 0 )
270 GetComboCtrl()->SetValue(
NO_NET );
279 wxCommandEvent changeEvent( NET_SELECTED );
280 wxPostEvent( GetComboCtrl(), changeEvent );
295 for(
size_t i = 0; i <
m_listBox->GetCount(); ++i )
298 listWidth = std::max( listWidth, itemWidth +
LIST_PADDING * 3 );
301 wxSize listSize( listWidth, listHeight );
302 wxSize popupSize( listWidth, listTop + listHeight );
304 SetSize( popupSize );
305 GetParent()->SetSize( popupSize );
315 wxArrayString netNames;
316 wxString netstring =
m_filterCtrl->GetValue().Trim().Trim(
false );
317 wxString
filter = netstring.Lower();
326 if( netinfo->GetNetCode() > 0 && netinfo->IsCurrent() )
330 if(
filter.IsEmpty() || wxString( netname ).MakeLower().Matches(
filter ) )
332 netNames.push_back( netname );
338 std::sort( netNames.begin(), netNames.end(),
339 [](
const wxString& lhs,
const wxString& rhs )
347 netNames.insert( netNames.begin(),
NO_NET );
352 netNames.insert( netNames.end(), newnet );
364 static wxPoint lastPos;
365 wxPoint screenPos = wxGetMousePosition();
367 if( screenPos != lastPos )
383 if(
m_listBox->GetScreenRect().Contains( aScreenPos ) )
387 wxPoint relativePos =
m_listBox->ScreenToClient( aScreenPos );
388 int item =
m_listBox->HitTest( relativePos );
393 else if(
m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
404 if( aEvent.GetEventObject() ==
m_listBox )
411 wxWindow* window = dynamic_cast<wxWindow*>( aEvent.GetEventObject() );
415 wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
417 if(
m_listBox->GetScreenRect().Contains( screenPos ) )
419 wxPoint localPos =
m_listBox->ScreenToClient( screenPos );
429 switch( aEvent.GetKeyCode() )
435 m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
436 ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
449 case WXK_NUMPAD_DOWN:
500 if( aEvent.GetKeyCode() == WXK_BACK )
508 int ch = aEvent.GetUnicodeKey();
514 ch = aEvent.GetKeyCode();
515 isPrintable = ch > WXK_SPACE && ch < WXK_START;
520 wxString
text( static_cast<wxChar>( ch ) );
523 if( !aEvent.ShiftDown() )
556 const wxSize &size,
long style ) :
557 wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER )
576 int key = aEvt.GetKeyCode();
586 else if( key == WXK_RETURN && aEvt.ShiftDown() )
588 wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
592 else if( key == WXK_RETURN || key == WXK_DOWN || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
598 else if( key > WXK_SPACE && key < WXK_START )
void SetIndeterminateString(const wxString &aString)
BOARD * GetParent() const
void SetBoard(BOARD *aBoard)
NET_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
wxString GetSelectedNetname()
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
wxDEFINE_EVENT(NET_SELECTED, wxCommandEvent)
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...
void onKeyDown(wxKeyEvent &aEvt)
Container for NETINFO_ITEM elements, which are the nets.
void SetSelectedNetcode(int aNetcode)
const wxString & GetNetname() const
Functions to provide common constants and other functions to assist in making a consistent UI.
#define LIST_ITEM_PADDING
void SetNetInfo(NETINFO_LIST *aNetInfoList)
wxString UnescapeString(const wxString &aSource)
wxString m_indeterminateString
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Handle the data for a net.
Information pertinent to a Pcbnew printed circuit board.
void SetSelectedNet(const wxString &aNetname)
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
NETINFO_ITEM * GetNetItem(int aNetCode) const
NET_SELECTOR_COMBOPOPUP * m_netSelectorPopup