KiCad PCB EDA Suite
NET_SELECTOR_COMBOPOPUP Class Reference
Inheritance diagram for NET_SELECTOR_COMBOPOPUP:

Public Member Functions

 NET_SELECTOR_COMBOPOPUP ()
 
bool Create (wxWindow *aParent) override
 
wxWindow * GetControl () override
 
void SetStringValue (const wxString &aNetName) override
 
wxString GetStringValue () const override
 
void SetNetInfo (NETINFO_LIST *aNetInfoList)
 
void SetIndeterminate ()
 
bool IsIndeterminate ()
 
void SetSelectedNetcode (int aNetcode)
 
int GetSelectedNetcode ()
 
void SetSelectedNet (const wxString &aNetname)
 
wxString GetSelectedNetname ()
 
wxSize GetAdjustedSize (int aMinWidth, int aPrefHeight, int aMaxHeight) override
 
void OnPopup () override
 
void OnStartingKey (wxKeyEvent &aEvent)
 
void Accept ()
 

Protected Member Functions

wxSize updateSize ()
 
void rebuildList ()
 
void onIdle (wxIdleEvent &aEvent)
 
void onMouseMoved (const wxPoint aScreenPos)
 
void onMouseClick (wxMouseEvent &aEvent)
 
void onKeyDown (wxKeyEvent &aEvent)
 
void onEnter (wxCommandEvent &aEvent)
 
void onFilterEdit (wxCommandEvent &aEvent)
 
void doStartingKey (wxKeyEvent &aEvent)
 
void doSetFocus (wxWindow *aWindow)
 

Protected Attributes

wxTextValidator * m_filterValidator
 
wxTextCtrl * m_filterCtrl
 
wxListBox * m_listBox
 
int m_minPopupWidth
 
int m_maxPopupHeight
 
NETINFO_LISTm_netinfoList
 
int m_selectedNetcode
 
wxEvtHandler * m_focusHandler
 

Detailed Description

Definition at line 51 of file net_selector.cpp.

Constructor & Destructor Documentation

NET_SELECTOR_COMBOPOPUP::NET_SELECTOR_COMBOPOPUP ( )
inline

Definition at line 54 of file net_selector.cpp.

54  :
55  m_minPopupWidth( -1 ),
56  m_maxPopupHeight( 1000 ),
57  m_netinfoList( nullptr ),
58  m_selectedNetcode( 0 ),
59  m_focusHandler( nullptr )
60  { }
wxEvtHandler * m_focusHandler
NETINFO_LIST * m_netinfoList

Member Function Documentation

void NET_SELECTOR_COMBOPOPUP::Accept ( )
inline

Definition at line 169 of file net_selector.cpp.

References NETINFO_ITEM::GetNet(), NETINFO_LIST::GetNetItem(), INDETERMINATE, m_listBox, m_netinfoList, m_selectedNetcode, and NO_NET.

Referenced by onEnter(), onKeyDown(), and onMouseClick().

170  {
171  wxString selectedNetName;
172  int selection = m_listBox->GetSelection();
173 
174  if( selection >= 0 )
175  selectedNetName = m_listBox->GetString( (unsigned) selection );
176 
177  if( selectedNetName.IsEmpty() )
178  {
179  m_selectedNetcode = -1;
180  GetComboCtrl()->SetValue( INDETERMINATE );
181  }
182  else if( selectedNetName == NO_NET )
183  {
184  m_selectedNetcode = 0;
185  GetComboCtrl()->SetValue( NO_NET );
186  }
187  else
188  {
189  m_selectedNetcode = m_netinfoList->GetNetItem( selectedNetName )->GetNet();
190  GetComboCtrl()->SetValue( selectedNetName );
191  }
192 
193  wxCommandEvent changeEvent( NET_SELECTED );
194  wxPostEvent( GetComboCtrl(), changeEvent );
195 
196  Dismiss();
197  }
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
NETINFO_LIST * m_netinfoList
#define INDETERMINATE
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
#define NO_NET
bool NET_SELECTOR_COMBOPOPUP::Create ( wxWindow *  aParent)
inlineoverride

Definition at line 62 of file net_selector.cpp.

References m_filterCtrl, m_filterValidator, m_listBox, onEnter(), onFilterEdit(), onIdle(), onKeyDown(), and onMouseClick().

63  {
64  wxPanel::Create( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
65 
66  wxBoxSizer* mainSizer;
67  mainSizer = new wxBoxSizer( wxVERTICAL );
68 
69  wxStaticText* filterLabel = new wxStaticText( this, wxID_ANY, _( "Filter:" ) );
70  mainSizer->Add( filterLabel, 0, wxEXPAND, 0 );
71 
72  m_filterCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
73  wxDefaultSize, wxTE_PROCESS_ENTER );
74  m_filterValidator = new wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST );
75  m_filterValidator->SetCharExcludes( " " );
76  m_filterCtrl->SetValidator( *m_filterValidator );
77  mainSizer->Add( m_filterCtrl, 0, wxEXPAND, 0 );
78 
79  m_listBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, 0,
80  wxLB_SINGLE|wxLB_NEEDED_SB );
81  mainSizer->Add( m_listBox, 0, wxEXPAND|wxTOP, 2 );
82 
83  SetSizer( mainSizer );
84  Layout();
85 
86  Connect( wxEVT_IDLE, wxIdleEventHandler( NET_SELECTOR_COMBOPOPUP::onIdle ), NULL, this );
87  Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( NET_SELECTOR_COMBOPOPUP::onKeyDown ), NULL, this );
88  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this );
89  m_listBox->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( NET_SELECTOR_COMBOPOPUP::onMouseClick ), NULL, this );
90  m_filterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onFilterEdit ), NULL, this );
91  m_filterCtrl->Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onEnter ), NULL, this );
92 
93  // <enter> in a ListBox comes in as a double-click on GTK
94  m_listBox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( NET_SELECTOR_COMBOPOPUP::onEnter ), NULL, this );
95 
96  return true;
97  }
void onIdle(wxIdleEvent &aEvent)
void onFilterEdit(wxCommandEvent &aEvent)
wxTextValidator * m_filterValidator
void onKeyDown(wxKeyEvent &aEvent)
void onEnter(wxCommandEvent &aEvent)
void onMouseClick(wxMouseEvent &aEvent)
void NET_SELECTOR_COMBOPOPUP::doSetFocus ( wxWindow *  aWindow)
inlineprotected

Definition at line 424 of file net_selector.cpp.

Referenced by onKeyDown(), onMouseMoved(), and OnStartingKey().

425  {
426 #ifdef __WXOSX_MAC__
427  aWindow->OSXForceFocus();
428 #else
429  aWindow->SetFocus();
430 #endif
431  }
void NET_SELECTOR_COMBOPOPUP::doStartingKey ( wxKeyEvent &  aEvent)
inlineprotected

Definition at line 391 of file net_selector.cpp.

References m_filterCtrl.

Referenced by onKeyDown(), and OnStartingKey().

392  {
393  if( aEvent.GetKeyCode() == WXK_BACK )
394  {
395  const long pos = m_filterCtrl->GetLastPosition();
396  m_filterCtrl->Remove( pos - 1, pos );
397  }
398  else
399  {
400  bool isPrintable;
401  int ch = aEvent.GetUnicodeKey();
402 
403  if( ch != WXK_NONE )
404  isPrintable = true;
405  else
406  {
407  ch = aEvent.GetKeyCode();
408  isPrintable = ch > WXK_SPACE && ch < WXK_START;
409  }
410 
411  if( isPrintable )
412  {
413  wxString text( static_cast<wxChar>( ch ) );
414 
415  // wxCHAR_HOOK chars have been converted to uppercase.
416  if( !aEvent.ShiftDown() )
417  text.MakeLower();
418 
419  m_filterCtrl->AppendText( text );
420  }
421  }
422  }
wxSize NET_SELECTOR_COMBOPOPUP::GetAdjustedSize ( int  aMinWidth,
int  aPrefHeight,
int  aMaxHeight 
)
inlineoverride

Definition at line 142 of file net_selector.cpp.

References m_maxPopupHeight, m_minPopupWidth, and updateSize().

143  {
144  // Called when the popup is first shown. Stash the minWidth and maxHeight so we
145  // can use them later when refreshing the sizes after filter changes.
146  m_minPopupWidth = aMinWidth;
147  m_maxPopupHeight = aMaxHeight;
148 
149  return updateSize();
150  }
wxWindow* NET_SELECTOR_COMBOPOPUP::GetControl ( )
inlineoverride

Definition at line 99 of file net_selector.cpp.

99 { return this; }
int NET_SELECTOR_COMBOPOPUP::GetSelectedNetcode ( )
inline

Definition at line 126 of file net_selector.cpp.

References m_selectedNetcode.

Referenced by NET_SELECTOR::GetSelectedNetcode().

wxString NET_SELECTOR_COMBOPOPUP::GetSelectedNetname ( )
inline

Definition at line 134 of file net_selector.cpp.

References NETINFO_LIST::GetNetItem(), NETINFO_ITEM::GetNetname(), m_netinfoList, and m_selectedNetcode.

Referenced by NET_SELECTOR::GetSelectedNetname().

135  {
138  else
139  return wxEmptyString;
140  }
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
NETINFO_LIST * m_netinfoList
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
wxString NET_SELECTOR_COMBOPOPUP::GetStringValue ( ) const
inlineoverride

Definition at line 106 of file net_selector.cpp.

References NETINFO_ITEM::GetNet(), NETINFO_LIST::GetNetItem(), NETINFO_ITEM::GetNetname(), m_netinfoList, m_selectedNetcode, and NO_NET.

Referenced by NET_SELECTOR::SetSelectedNet(), and NET_SELECTOR::SetSelectedNetcode().

107  {
109 
110  if( netInfo && netInfo->GetNet() > 0 )
111  return netInfo->GetNetname();
112 
113  return NO_NET;
114  }
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
NETINFO_LIST * m_netinfoList
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
#define NO_NET
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
bool NET_SELECTOR_COMBOPOPUP::IsIndeterminate ( )
inline

Definition at line 123 of file net_selector.cpp.

References m_selectedNetcode.

Referenced by NET_SELECTOR::IsIndeterminate().

123 { return m_selectedNetcode == -1; }
void NET_SELECTOR_COMBOPOPUP::onEnter ( wxCommandEvent &  aEvent)
inlineprotected

Definition at line 377 of file net_selector.cpp.

References Accept().

Referenced by Create().

378  {
379  Accept();
380  }
void NET_SELECTOR_COMBOPOPUP::onFilterEdit ( wxCommandEvent &  aEvent)
inlineprotected

Definition at line 382 of file net_selector.cpp.

References m_listBox, rebuildList(), and updateSize().

Referenced by Create().

383  {
384  rebuildList();
385  updateSize();
386 
387  if( m_listBox->GetCount() > 0 )
388  m_listBox->SetSelection( 0 );
389  }
void NET_SELECTOR_COMBOPOPUP::onIdle ( wxIdleEvent &  aEvent)
inlineprotected

Definition at line 254 of file net_selector.cpp.

References m_filterCtrl, m_focusHandler, and onMouseMoved().

Referenced by Create().

255  {
256  // Generate synthetic (but reliable) MouseMoved events
257  static wxPoint lastPos;
258  wxPoint screenPos = wxGetMousePosition();
259 
260  if( screenPos != lastPos )
261  {
262  lastPos = screenPos;
263  onMouseMoved( screenPos );
264  }
265 
266  if( m_focusHandler )
267  {
268  m_filterCtrl->PushEventHandler( m_focusHandler );
269  m_focusHandler = nullptr;
270  }
271  }
wxEvtHandler * m_focusHandler
void onMouseMoved(const wxPoint aScreenPos)
void NET_SELECTOR_COMBOPOPUP::onKeyDown ( wxKeyEvent &  aEvent)
inlineprotected

Definition at line 320 of file net_selector.cpp.

References Accept(), doSetFocus(), doStartingKey(), m_filterCtrl, m_focusHandler, m_listBox, max, and min.

Referenced by Create().

321  {
322  switch( aEvent.GetKeyCode() )
323  {
324  // Control keys go to the parent combobox
325  case WXK_TAB:
326  Dismiss();
327 
328  m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
329  ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
330  break;
331 
332  case WXK_ESCAPE:
333  Dismiss();
334  break;
335 
336  case WXK_RETURN:
337  Accept();
338  break;
339 
340  // Arrows go to the list box
341  case WXK_DOWN:
342  case WXK_NUMPAD_DOWN:
344  m_listBox->SetSelection( std::min( m_listBox->GetSelection() + 1, (int) m_listBox->GetCount() - 1 ) );
345  break;
346 
347  case WXK_UP:
348  case WXK_NUMPAD_UP:
350  m_listBox->SetSelection( std::max( m_listBox->GetSelection() - 1, 0 ) );
351  break;
352 
353  // Everything else goes to the filter textbox
354  default:
355  if( !m_filterCtrl->HasFocus() )
356  {
358 
359  // Because we didn't have focus we missed our chance to have the native widget
360  // handle the keystroke. We'll have to do the first character ourselves.
361  doStartingKey( aEvent );
362  }
363  else
364  {
365  // On some platforms a wxComboFocusHandler will have been pushed which
366  // unhelpfully gives the event right back to the popup. Make sure the filter
367  // control is going to get the event.
368  if( m_filterCtrl->GetEventHandler() != m_filterCtrl )
369  m_focusHandler = m_filterCtrl->PopEventHandler();
370 
371  aEvent.Skip();
372  }
373  break;
374  }
375  }
wxEvtHandler * m_focusHandler
void doStartingKey(wxKeyEvent &aEvent)
#define max(a, b)
Definition: auxiliary.h:86
void doSetFocus(wxWindow *aWindow)
#define min(a, b)
Definition: auxiliary.h:85
void NET_SELECTOR_COMBOPOPUP::onMouseClick ( wxMouseEvent &  aEvent)
inlineprotected

Definition at line 292 of file net_selector.cpp.

References Accept(), and m_listBox.

Referenced by Create().

293  {
294  // Accept a click event from anywhere. Different platform implementations have
295  // different foibles with regard to transient popups and their children.
296 
297  if( aEvent.GetEventObject() == m_listBox )
298  {
299  m_listBox->SetSelection( m_listBox->HitTest( aEvent.GetPosition() ) );
300  Accept();
301  return;
302  }
303 
304  wxWindow* window = dynamic_cast<wxWindow*>( aEvent.GetEventObject() );
305 
306  if( window )
307  {
308  wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
309 
310  if( m_listBox->GetScreenRect().Contains( screenPos ) )
311  {
312  wxPoint localPos = m_listBox->ScreenToClient( screenPos );
313 
314  m_listBox->SetSelection( m_listBox->HitTest( localPos ) );
315  Accept();
316  }
317  }
318  }
void NET_SELECTOR_COMBOPOPUP::onMouseMoved ( const wxPoint  aScreenPos)
inlineprotected

Definition at line 274 of file net_selector.cpp.

References doSetFocus(), m_filterCtrl, and m_listBox.

Referenced by onIdle().

275  {
276  if( m_listBox->GetScreenRect().Contains( aScreenPos ) )
277  {
279 
280  wxPoint relativePos = m_listBox->ScreenToClient( aScreenPos );
281  int item = m_listBox->HitTest( relativePos );
282 
283  if( item >= 0 )
284  m_listBox->SetSelection( item );
285  }
286  else if( m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
287  {
289  }
290  }
void doSetFocus(wxWindow *aWindow)
void NET_SELECTOR_COMBOPOPUP::OnPopup ( )
inlineoverride

Definition at line 152 of file net_selector.cpp.

References m_filterCtrl, and updateSize().

153  {
154  // While it can sometimes be useful to keep the filter, it's always expected.
155  // Better to clear it.
156  m_filterCtrl->Clear();
157 
158  // The updateSize() call in GetAdjustedSize() leaves the height off-by-one for
159  // some reason, so do it again.
160  updateSize();
161  }
void NET_SELECTOR_COMBOPOPUP::OnStartingKey ( wxKeyEvent &  aEvent)
inline

Definition at line 163 of file net_selector.cpp.

References doSetFocus(), doStartingKey(), and m_filterCtrl.

Referenced by NET_SELECTOR::onKeyDown().

164  {
166  doStartingKey( aEvent );
167  }
void doStartingKey(wxKeyEvent &aEvent)
void doSetFocus(wxWindow *aWindow)
void NET_SELECTOR_COMBOPOPUP::rebuildList ( )
inlineprotected

Definition at line 229 of file net_selector.cpp.

References m_filterCtrl, m_listBox, m_netinfoList, and NO_NET.

Referenced by onFilterEdit(), and SetNetInfo().

230  {
231  wxArrayString netNames;
232  wxString filter = m_filterCtrl->GetValue().MakeLower();
233 
234  if( !filter.IsEmpty() )
235  filter = wxT( "*" ) + filter + wxT( "*" );
236 
237  for( NETINFO_ITEM* netinfo : *m_netinfoList )
238  {
239  if( netinfo->GetNet() > 0 && netinfo->IsCurrent() )
240  {
241  if( filter.IsEmpty() || wxString( netinfo->GetNetname() ).MakeLower().Matches( filter ) )
242  netNames.push_back( netinfo->GetNetname() );
243  }
244  }
245  std::sort( netNames.begin(), netNames.end() );
246 
247  // Special handling for <no net>
248  if( filter.IsEmpty() || wxString( NO_NET ).MakeLower().Matches( filter ) )
249  netNames.insert( netNames.begin(), NO_NET );
250 
251  m_listBox->Set( netNames );
252  }
NETINFO_LIST * m_netinfoList
#define NO_NET
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
void NET_SELECTOR_COMBOPOPUP::SetIndeterminate ( )
inline

Definition at line 122 of file net_selector.cpp.

References m_selectedNetcode.

Referenced by NET_SELECTOR::SetIndeterminate().

void NET_SELECTOR_COMBOPOPUP::SetNetInfo ( NETINFO_LIST aNetInfoList)
inline

Definition at line 116 of file net_selector.cpp.

References m_netinfoList, and rebuildList().

Referenced by NET_SELECTOR::SetNetInfo().

117  {
118  m_netinfoList = aNetInfoList;
119  rebuildList();
120  }
NETINFO_LIST * m_netinfoList
void NET_SELECTOR_COMBOPOPUP::SetSelectedNet ( const wxString &  aNetname)
inline

Definition at line 128 of file net_selector.cpp.

References NETINFO_ITEM::GetNet(), NETINFO_LIST::GetNetItem(), m_netinfoList, and m_selectedNetcode.

Referenced by NET_SELECTOR::SetSelectedNet().

129  {
130  if( m_netinfoList && m_netinfoList->GetNetItem( aNetname ) )
132  }
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
NETINFO_LIST * m_netinfoList
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
void NET_SELECTOR_COMBOPOPUP::SetSelectedNetcode ( int  aNetcode)
inline

Definition at line 125 of file net_selector.cpp.

References m_selectedNetcode.

Referenced by NET_SELECTOR::SetSelectedNetcode().

125 { m_selectedNetcode = aNetcode; }
void NET_SELECTOR_COMBOPOPUP::SetStringValue ( const wxString &  aNetName)
inlineoverride

Definition at line 101 of file net_selector.cpp.

102  {
103  // shouldn't be here (combo is read-only)
104  }
wxSize NET_SELECTOR_COMBOPOPUP::updateSize ( )
inlineprotected

Definition at line 200 of file net_selector.cpp.

References GetTextSize(), i, LIST_ITEM_PADDING, LIST_PADDING, m_listBox, m_maxPopupHeight, m_minPopupWidth, and max.

Referenced by GetAdjustedSize(), onFilterEdit(), and OnPopup().

201  {
202  int listTop = m_listBox->GetRect().y;
203  int itemHeight = GetTextSize( wxT( "Xy" ), this ).y + LIST_ITEM_PADDING;
204  int listHeight = m_listBox->GetCount() * itemHeight + LIST_PADDING;
205 
206  if( listTop + listHeight >= m_maxPopupHeight )
207  listHeight = m_maxPopupHeight - listTop - 1;
208 
209  int listWidth = m_minPopupWidth;
210 
211  for( size_t i = 0; i < m_listBox->GetCount(); ++i )
212  {
213  int itemWidth = GetTextSize( m_listBox->GetString( i ), m_listBox ).x;
214  listWidth = std::max( listWidth, itemWidth + LIST_PADDING * 3 );
215  }
216 
217  wxSize listSize( listWidth, listHeight );
218  wxSize popupSize( listWidth, listTop + listHeight );
219 
220  SetSize( popupSize ); // us
221  GetParent()->SetSize( popupSize ); // the window that wxComboCtrl put us in
222 
223  m_listBox->SetMinSize( listSize );
224  m_listBox->SetSize( listSize );
225 
226  return popupSize;
227  }
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...
Definition: common.cpp:111
#define LIST_ITEM_PADDING
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
#define LIST_PADDING

Member Data Documentation

wxTextCtrl* NET_SELECTOR_COMBOPOPUP::m_filterCtrl
protected
wxTextValidator* NET_SELECTOR_COMBOPOPUP::m_filterValidator
protected

Definition at line 434 of file net_selector.cpp.

Referenced by Create().

wxEvtHandler* NET_SELECTOR_COMBOPOPUP::m_focusHandler
protected

Definition at line 444 of file net_selector.cpp.

Referenced by onIdle(), and onKeyDown().

wxListBox* NET_SELECTOR_COMBOPOPUP::m_listBox
protected
int NET_SELECTOR_COMBOPOPUP::m_maxPopupHeight
protected

Definition at line 438 of file net_selector.cpp.

Referenced by GetAdjustedSize(), and updateSize().

int NET_SELECTOR_COMBOPOPUP::m_minPopupWidth
protected

Definition at line 437 of file net_selector.cpp.

Referenced by GetAdjustedSize(), and updateSize().

NETINFO_LIST* NET_SELECTOR_COMBOPOPUP::m_netinfoList
protected
int NET_SELECTOR_COMBOPOPUP::m_selectedNetcode
protected

The documentation for this class was generated from the following file: