KiCad PCB EDA Suite
GRID_CELL_LAYER_SELECTOR Class Reference

#include <grid_layer_box_helpers.h>

Inheritance diagram for GRID_CELL_LAYER_SELECTOR:

Public Member Functions

 GRID_CELL_LAYER_SELECTOR (PCB_BASE_FRAME *aFrame, LSET forbiddenLayers)
 
wxGridCellEditor * Clone () const override
 
void Create (wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
 
wxString GetValue () const override
 
void SetSize (const wxRect &aRect) override
 
void BeginEdit (int aRow, int aCol, wxGrid *aGrid) override
 
bool EndEdit (int, int, const wxGrid *, const wxString &, wxString *newval) override
 
void ApplyEdit (int aRow, int aCol, wxGrid *aGrid) override
 
void Reset () override
 

Protected Member Functions

void onComboDropDown (wxCommandEvent &aEvent)
 
void onComboCloseUp (wxCommandEvent &aEvent)
 
PCB_LAYER_BOX_SELECTORLayerBox () const
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_LAYER_SELECTOR)
 

Protected Attributes

PCB_BASE_FRAMEm_frame
 
LSET m_mask
 
LAYER_NUM m_value
 

Detailed Description

Definition at line 55 of file grid_layer_box_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_LAYER_SELECTOR()

GRID_CELL_LAYER_SELECTOR::GRID_CELL_LAYER_SELECTOR ( PCB_BASE_FRAME aFrame,
LSET  forbiddenLayers 
)

Definition at line 81 of file grid_layer_box_helpers.cpp.

81  :
82  m_frame( aFrame ), m_mask( aMask ), m_value( 0 )
83 {
84 }

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

void GRID_CELL_LAYER_SELECTOR::ApplyEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 190 of file grid_layer_box_helpers.cpp.

191 {
192  aGrid->GetTable()->SetValueAsLong( aRow, aCol, (long) m_value );
193 }

References m_value.

◆ BeginEdit()

void GRID_CELL_LAYER_SELECTOR::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 134 of file grid_layer_box_helpers.cpp.

135 {
136  auto* evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
137 
138  // Don't immediately end if we get a kill focus event within BeginEdit
139  evtHandler->SetInSetFocus( true );
140 
141  // These event handlers are needed to properly dismiss the editor when the popup is closed
142  m_control->Bind(wxEVT_COMBOBOX_DROPDOWN, &GRID_CELL_LAYER_SELECTOR::onComboDropDown, this);
143  m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &GRID_CELL_LAYER_SELECTOR::onComboCloseUp, this);
144 
145  m_value = (LAYER_NUM) aGrid->GetTable()->GetValueAsLong( aRow, aCol );
146 
147  // Footprints are defined in a global context and may contain layers not enabled
148  // on the current board. Check and display all layers if so.
149  bool currentLayerEnabled = m_frame->GetBoard()->IsLayerEnabled( ToLAYER_ID( m_value ) );
150  LayerBox()->ShowNonActivatedLayers( !currentLayerEnabled );
151  LayerBox()->Resync();
152 
154  LayerBox()->SetFocus();
155 
156 #ifdef __WXOSX_COCOA__
157  // This is a work around for the combobox being simply dismissed when a
158  // choice is made in it under OS X. The bug is almost certainly due to a
159  // problem in focus events generation logic but it's not obvious to fix and
160  // for now this at least allows to use wxGrid.
161  if( !LayerBox()->IsPopupShown() )
162  LayerBox()->Popup();
163 #endif
164 
165  // When dropping down the menu, a kill focus event
166  // happens after this point, so we can't reset the flag yet.
167 #if !defined(__WXGTK20__)
168  evtHandler->SetInSetFocus( false );
169 #endif
170 }
void onComboCloseUp(wxCommandEvent &aEvent)
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.h:513
void onComboDropDown(wxCommandEvent &aEvent)
PCB_LAYER_BOX_SELECTOR * LayerBox() const
void ShowNonActivatedLayers(bool aShow)
int SetLayerSelection(LAYER_NUM layer)
int LAYER_NUM
This can be replaced with int and removed.
BOARD * GetBoard() const
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905

References PCB_BASE_FRAME::GetBoard(), BOARD::IsLayerEnabled(), LayerBox(), m_frame, m_value, onComboCloseUp(), onComboDropDown(), PCB_LAYER_BOX_SELECTOR::Resync(), LAYER_BOX_SELECTOR::SetLayerSelection(), PCB_LAYER_BOX_SELECTOR::ShowNonActivatedLayers(), and ToLAYER_ID().

◆ Clone()

wxGridCellEditor * GRID_CELL_LAYER_SELECTOR::Clone ( ) const
override

Definition at line 87 of file grid_layer_box_helpers.cpp.

88 {
90 }
GRID_CELL_LAYER_SELECTOR(PCB_BASE_FRAME *aFrame, LSET forbiddenLayers)

References GRID_CELL_LAYER_SELECTOR(), m_frame, and m_mask.

◆ Create()

void GRID_CELL_LAYER_SELECTOR::Create ( wxWindow *  aParent,
wxWindowID  aId,
wxEvtHandler *  aEventHandler 
)
override

Definition at line 93 of file grid_layer_box_helpers.cpp.

95 {
96  m_control = new PCB_LAYER_BOX_SELECTOR( aParent, aId, wxEmptyString,
97  wxDefaultPosition, wxDefaultSize, 0, nullptr,
98  wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
99 
102 
103  wxGridCellEditor::Create(aParent, aId, aEventHandler);
104 }
void SetNotAllowedLayerSet(LSET aMask)
Class to display a pcb layer list in a wxBitmapComboBox.
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
PCB_LAYER_BOX_SELECTOR * LayerBox() const

References LayerBox(), m_frame, m_mask, PCB_LAYER_BOX_SELECTOR::SetBoardFrame(), and PCB_LAYER_BOX_SELECTOR::SetNotAllowedLayerSet().

◆ EndEdit()

bool GRID_CELL_LAYER_SELECTOR::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  newval 
)
override

Definition at line 173 of file grid_layer_box_helpers.cpp.

175 {
176  const LAYER_NUM value = LayerBox()->GetLayerSelection();
177 
178  if ( value == m_value )
179  return false;
180 
181  m_value = value;
182 
183  if ( newval )
184  *newval = GetValue();
185 
186  return true;
187 }
wxString GetValue() const override
PCB_LAYER_BOX_SELECTOR * LayerBox() const
LAYER_NUM GetLayerSelection() const
int LAYER_NUM
This can be replaced with int and removed.

References LAYER_BOX_SELECTOR::GetLayerSelection(), GetValue(), LayerBox(), and m_value.

◆ GetValue()

wxString GRID_CELL_LAYER_SELECTOR::GetValue ( ) const
override

Definition at line 107 of file grid_layer_box_helpers.cpp.

108 {
109  if( LayerBox()->GetLayerSelection() != UNDEFINED_LAYER )
110  return m_frame->GetBoard()->GetLayerName( ToLAYER_ID( LayerBox()->GetLayerSelection() ) );
111 
112  return wxEmptyString;
113 }
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
PCB_LAYER_BOX_SELECTOR * LayerBox() const
BOARD * GetBoard() const
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905

References PCB_BASE_FRAME::GetBoard(), BOARD::GetLayerName(), LayerBox(), m_frame, ToLAYER_ID(), and UNDEFINED_LAYER.

Referenced by EndEdit().

◆ LayerBox()

PCB_LAYER_BOX_SELECTOR* GRID_CELL_LAYER_SELECTOR::LayerBox ( ) const
inlineprotected

Definition at line 77 of file grid_layer_box_helpers.h.

78  {
79  return static_cast<PCB_LAYER_BOX_SELECTOR*>( m_control );
80  }

Referenced by BeginEdit(), Create(), EndEdit(), GetValue(), Reset(), and SetSize().

◆ onComboCloseUp()

void GRID_CELL_LAYER_SELECTOR::onComboCloseUp ( wxCommandEvent &  aEvent)
protected

Definition at line 215 of file grid_layer_box_helpers.cpp.

216 {
217  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
218 
219  // Forward the combobox close up event to the cell event handler as a focus kill event
220  // so that the grid editor is dismissed when the combox closes, otherwise it leaves the
221  // dropdown arrow visible in the cell.
222  wxFocusEvent event( wxEVT_KILL_FOCUS, m_control->GetId() );
223  event.SetEventObject( m_control );
224  evtHandler->ProcessEvent( event );
225 }

Referenced by BeginEdit().

◆ onComboDropDown()

void GRID_CELL_LAYER_SELECTOR::onComboDropDown ( wxCommandEvent &  aEvent)
protected

Definition at line 202 of file grid_layer_box_helpers.cpp.

203 {
204  // On other platforms this is done in BeginEdit()
205 #if defined(__WXGTK20__)
206  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
207 
208  // Once the combobox is dropped, reset the flag to allow the focus-loss handler
209  // to function and close the editor.
210  evtHandler->SetInSetFocus( false );
211 #endif
212 }

Referenced by BeginEdit().

◆ Reset()

void GRID_CELL_LAYER_SELECTOR::Reset ( )
override

Definition at line 196 of file grid_layer_box_helpers.cpp.

197 {
199 }
PCB_LAYER_BOX_SELECTOR * LayerBox() const
int SetLayerSelection(LAYER_NUM layer)

References LayerBox(), m_value, and LAYER_BOX_SELECTOR::SetLayerSelection().

◆ SetSize()

void GRID_CELL_LAYER_SELECTOR::SetSize ( const wxRect &  aRect)
override

Definition at line 116 of file grid_layer_box_helpers.cpp.

117 {
118  wxRect rect( aRect );
119  rect.Inflate( -1 );
120 
121 #if !defined( __WXMSW__ ) && !defined( __WXGTK20__ )
122  // Only implemented in generic wxBitmapComboBox; MSW and GTK use native controls
123  LayerBox()->SetButtonPosition( 0, 0, wxRIGHT, 0 );
124 #endif
125 
126 #if defined( __WXMAC__ )
127  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
128 #endif
129 
130  LayerBox()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
131 }
PCB_LAYER_BOX_SELECTOR * LayerBox() const

References LayerBox().

◆ wxDECLARE_NO_COPY_CLASS()

GRID_CELL_LAYER_SELECTOR::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_LAYER_SELECTOR  )
protected

Member Data Documentation

◆ m_frame

PCB_BASE_FRAME* GRID_CELL_LAYER_SELECTOR::m_frame
protected

Definition at line 82 of file grid_layer_box_helpers.h.

Referenced by BeginEdit(), Clone(), Create(), and GetValue().

◆ m_mask

LSET GRID_CELL_LAYER_SELECTOR::m_mask
protected

Definition at line 83 of file grid_layer_box_helpers.h.

Referenced by Clone(), and Create().

◆ m_value

LAYER_NUM GRID_CELL_LAYER_SELECTOR::m_value
protected

Definition at line 84 of file grid_layer_box_helpers.h.

Referenced by ApplyEdit(), BeginEdit(), EndEdit(), and Reset().


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