KiCad PCB EDA Suite
FP_GRID_TRICKS Class Reference
Inheritance diagram for FP_GRID_TRICKS:
GRID_TRICKS

Public Member Functions

 FP_GRID_TRICKS (wxGrid *aGrid)
 

Protected Member Functions

virtual void paste_text (const wxString &cb_text) override
 handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text. More...
 
int getCursorCol () const
 If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based column index. More...
 
int getCursorRow () const
 If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based row index. More...
 
void getSelectedArea ()
 Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. More...
 
void onGridCellRightClick (wxGridEvent &event)
 
void onRightDown (wxMouseEvent &event)
 
virtual void showPopupMenu ()
 
void onPopupSelection (wxCommandEvent &event)
 
void onKeyDown (wxKeyEvent &ev)
 
virtual void paste_clipboard ()
 
virtual void cutcopy (bool doCut)
 

Static Protected Member Functions

static bool isCtl (int aChar, const wxKeyEvent &e)
 

Protected Attributes

wxGrid * m_grid
 I don't own the grid, but he owns me. More...
 
int m_sel_row_start
 
int m_sel_col_start
 
int m_sel_row_count
 
int m_sel_col_count
 

Detailed Description

Definition at line 90 of file dialog_fp_lib_table.cpp.

Constructor & Destructor Documentation

FP_GRID_TRICKS::FP_GRID_TRICKS ( wxGrid *  aGrid)
inline

Definition at line 93 of file dialog_fp_lib_table.cpp.

93  :
94  GRID_TRICKS( aGrid )
95  {
96  }
GRID_TRICKS(wxGrid *aGrid)
Definition: grid_tricks.cpp:52

Member Function Documentation

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtualinherited

Definition at line 258 of file grid_tricks.cpp.

References COL_SEP, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and ROW_SEP.

Referenced by GRID_TRICKS::onKeyDown(), and GRID_TRICKS::onPopupSelection().

259 {
260  if( wxTheClipboard->Open() )
261  {
262  wxGridTableBase* tbl = m_grid->GetTable();
263  wxString txt;
264 
265  // fill txt with a format that is compatible with most spreadsheets
266  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
267  {
268  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
269  {
270  txt += tbl->GetValue( row, col );
271 
272  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
273  txt += COL_SEP;
274 
275  if( doCut )
276  tbl->SetValue( row, col, wxEmptyString );
277  }
278  txt += ROW_SEP;
279  }
280 
281  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
282  wxTheClipboard->Close();
283 
284  if( doCut )
285  {
286  m_grid->AutoSizeColumns( false );
287  m_grid->ForceRefresh();
288  }
289  }
290 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
int m_sel_row_count
Definition: grid_tricks.h:48
int m_sel_col_start
Definition: grid_tricks.h:47
int m_sel_col_count
Definition: grid_tricks.h:49
int m_sel_row_start
Definition: grid_tricks.h:46
#define ROW_SEP
Definition: grid_tricks.cpp:38
#define COL_SEP
Definition: grid_tricks.cpp:37
int GRID_TRICKS::getCursorCol ( ) const
inlineprotectedinherited

If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based column index.

Definition at line 53 of file grid_tricks.h.

Referenced by GRID_TRICKS::paste_text().

54  {
55  return m_grid->GetGridCursorCol();
56  }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
int GRID_TRICKS::getCursorRow ( ) const
inlineprotectedinherited

If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based row index.

Definition at line 60 of file grid_tricks.h.

Referenced by SYMBOL_GRID_TRICKS::paste_text(), GRID_TRICKS::paste_text(), and paste_text().

61  {
62  return m_grid->GetGridCursorRow();
63  }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
void GRID_TRICKS::getSelectedArea ( )
protectedinherited

Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.

Definition at line 67 of file grid_tricks.cpp.

References DBG, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, and GRID_TRICKS::m_sel_row_start.

Referenced by GRID_TRICKS::onKeyDown(), and GRID_TRICKS::showPopupMenu().

68 {
69  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
70  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
71 
72  wxArrayInt cols = m_grid->GetSelectedCols();
73  wxArrayInt rows = m_grid->GetSelectedRows();
74 
75  DBG(printf("topLeft.Count():%d botRight:Count():%d\n", int( topLeft.Count() ), int( botRight.Count() ) );)
76 
77  if( topLeft.Count() && botRight.Count() )
78  {
79  m_sel_row_start = topLeft[0].GetRow();
80  m_sel_col_start = topLeft[0].GetCol();
81 
82  m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
83  m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
84  }
85  else if( cols.Count() )
86  {
87  m_sel_col_start = cols[0];
88  m_sel_col_count = cols.Count();
89  m_sel_row_start = 0;
90  m_sel_row_count = m_grid->GetNumberRows();
91  }
92  else if( rows.Count() )
93  {
94  m_sel_col_start = 0;
95  m_sel_col_count = m_grid->GetNumberCols();
96  m_sel_row_start = rows[0];
97  m_sel_row_count = rows.Count();
98  }
99  else
100  {
101  m_sel_row_start = -1;
102  m_sel_col_start = -1;
103  m_sel_row_count = 0;
104  m_sel_col_count = 0;
105  }
106 
107  //DBG(printf("m_sel_row_start:%d m_sel_col_start:%d m_sel_row_count:%d m_sel_col_count:%d\n", m_sel_row_start, m_sel_col_start, m_sel_row_count, m_sel_col_count );)
108 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
int m_sel_row_count
Definition: grid_tricks.h:48
int m_sel_col_start
Definition: grid_tricks.h:47
int m_sel_col_count
Definition: grid_tricks.h:49
int m_sel_row_start
Definition: grid_tricks.h:46
#define DBG(x)
Definition: fctsys.h:33
static bool GRID_TRICKS::isCtl ( int  aChar,
const wxKeyEvent &  e 
)
inlinestaticprotectedinherited

Definition at line 68 of file grid_tricks.h.

Referenced by GRID_TRICKS::onKeyDown().

69  {
70  return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
71  }
void GRID_TRICKS::onGridCellRightClick ( wxGridEvent &  event)
inlineprotectedinherited

Definition at line 73 of file grid_tricks.h.

References GRID_TRICKS::showPopupMenu().

Referenced by GRID_TRICKS::GRID_TRICKS().

74  {
75  showPopupMenu();
76  }
virtual void showPopupMenu()
void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protectedinherited

Definition at line 176 of file grid_tricks.cpp.

References GRID_TRICKS::cutcopy(), GRID_TRICKS::getSelectedArea(), GRID_TRICKS::isCtl(), GRID_TRICKS::m_grid, and GRID_TRICKS::paste_clipboard().

Referenced by GRID_TRICKS::GRID_TRICKS().

177 {
178  if( isCtl( 'A', ev ) )
179  {
180  m_grid->SelectAll();
181  }
182  else if( isCtl( 'C', ev ) )
183  {
184  getSelectedArea();
185  cutcopy( false );
186  }
187  else if( isCtl( 'V', ev ) )
188  {
189  getSelectedArea();
190  paste_clipboard();
191  }
192  else if( isCtl( 'X', ev ) )
193  {
194  getSelectedArea();
195  cutcopy( true );
196  }
197  else
198  {
199  ev.Skip( true );
200  }
201 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above...
Definition: grid_tricks.cpp:67
static bool isCtl(int aChar, const wxKeyEvent &e)
Definition: grid_tricks.h:68
virtual void paste_clipboard()
virtual void cutcopy(bool doCut)
void GRID_TRICKS::onPopupSelection ( wxCommandEvent &  event)
protectedinherited

Definition at line 148 of file grid_tricks.cpp.

References GRID_TRICKS::cutcopy(), GRID_TRICKS::m_grid, MYID_COPY, MYID_CUT, MYID_PASTE, MYID_SELECT, and GRID_TRICKS::paste_clipboard().

Referenced by GRID_TRICKS::GRID_TRICKS().

149 {
150  int menu_id = event.GetId();
151 
152  // assume getSelectedArea() was called by rightClickPopupMenu() and there's
153  // no way to have gotten here without that having been called.
154 
155  switch( menu_id )
156  {
157  case MYID_CUT:
158  case MYID_COPY:
159  cutcopy( menu_id == MYID_CUT );
160  break;
161 
162  case MYID_PASTE:
163  paste_clipboard();
164  break;
165 
166  case MYID_SELECT:
167  m_grid->SelectAll();
168  break;
169 
170  default:
171  ;
172  }
173 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
virtual void paste_clipboard()
virtual void cutcopy(bool doCut)
void GRID_TRICKS::onRightDown ( wxMouseEvent &  event)
inlineprotectedinherited

Definition at line 78 of file grid_tricks.h.

References GRID_TRICKS::showPopupMenu().

Referenced by GRID_TRICKS::GRID_TRICKS().

79  {
80  showPopupMenu();
81  }
virtual void showPopupMenu()
void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 204 of file grid_tricks.cpp.

References GRID_TRICKS::m_grid, and GRID_TRICKS::paste_text().

Referenced by GRID_TRICKS::onKeyDown(), and GRID_TRICKS::onPopupSelection().

205 {
206  if( wxTheClipboard->Open() )
207  {
208  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
209  {
210  wxTextDataObject data;
211 
212  wxTheClipboard->GetData( data );
213 
214  wxString cb_text = data.GetText();
215 
216  paste_text( cb_text );
217  }
218 
219  wxTheClipboard->Close();
220  m_grid->ForceRefresh();
221  }
222 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
virtual void paste_text(const wxString &cb_text)
virtual void FP_GRID_TRICKS::paste_text ( const wxString &  cb_text)
inlineoverrideprotectedvirtual

handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text.

Reimplemented from GRID_TRICKS.

Definition at line 102 of file dialog_fp_lib_table.cpp.

References LIB_TABLE_GRID::AppendRows(), LIB_TABLE::At(), DisplayError(), LIB_TABLE::GetCount(), GRID_TRICKS::getCursorRow(), LIB_TABLE_GRID::GetNumberRows(), GRID_TRICKS::m_grid, max, FP_LIB_TABLE::Parse(), GRID_TRICKS::paste_text(), LIB_TABLE::rows, TO_UTF8, and IO_ERROR::What().

103  {
104  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
105 
106  size_t ndx = cb_text.find( "(fp_lib_table" );
107 
108  if( ndx != std::string::npos )
109  {
110  // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
111  // at column 0 regardless of current cursor column.
112 
113  STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
114  LIB_TABLE_LEXER lexer( &slr );
115  FP_LIB_TABLE tmp_tbl;
116  bool parsed = true;
117 
118  try
119  {
120  tmp_tbl.Parse( &lexer );
121  }
122  catch( PARSE_ERROR& pe )
123  {
124  DisplayError( NULL, pe.What() );
125  parsed = false;
126  }
127 
128  if( parsed )
129  {
130  const int cur_row = std::max( getCursorRow(), 0 );
131 
132  // if clipboard rows would extend past end of current table size...
133  if( tmp_tbl.GetCount() > tbl->GetNumberRows() - cur_row )
134  {
135  int newRowsNeeded = tmp_tbl.GetCount() - ( tbl->GetNumberRows() - cur_row );
136  tbl->AppendRows( newRowsNeeded );
137  }
138 
139  for( int i = 0; i < tmp_tbl.GetCount(); ++i )
140  {
141  tbl->rows.replace( cur_row+i, tmp_tbl.At( i ) );
142  }
143  }
144 
145  m_grid->AutoSizeColumns( false );
146  }
147  else
148  {
149  // paste spreadsheet formatted text.
150  GRID_TRICKS::paste_text( cb_text );
151  }
152  }
int GetCount()
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
LIB_TABLE_ROW * At(int aIndex)
LIB_TABLE_ROWS rows
int GetNumberRows() override
virtual void paste_text(const wxString &cb_text)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Function Parse.
bool AppendRows(size_t aNumRows=1) override
int getCursorRow() const
If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based row index.
Definition: grid_tricks.h:60
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
#define max(a, b)
Definition: auxiliary.h:86
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
Class LIB_TABLE_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/lib_table.keywords.
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
void GRID_TRICKS::showPopupMenu ( )
protectedvirtualinherited

Definition at line 111 of file grid_tricks.cpp.

References GRID_TRICKS::getSelectedArea(), GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_row_count, MYID_COPY, MYID_CUT, MYID_PASTE, and MYID_SELECT.

Referenced by GRID_TRICKS::onGridCellRightClick(), and GRID_TRICKS::onRightDown().

112 {
113  wxMenu menu;
114 
115  menu.Append( MYID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells pasting original contents to clipboard" ) );
116  menu.Append( MYID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) );
117  menu.Append( MYID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) );
118  menu.Append( MYID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) );
119 
120  getSelectedArea();
121 
122  // if nothing is selected, disable cut and copy.
124  {
125  menu.Enable( MYID_CUT, false );
126  menu.Enable( MYID_COPY, false );
127  }
128 
129  bool have_cb_text = false;
130  if( wxTheClipboard->Open() )
131  {
132  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
133  have_cb_text = true;
134 
135  wxTheClipboard->Close();
136  }
137 
138  if( !have_cb_text )
139  {
140  // if nothing on clipboard, disable paste.
141  menu.Enable( MYID_PASTE, false );
142  }
143 
144  m_grid->PopupMenu( &menu );
145 }
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above...
Definition: grid_tricks.cpp:67
int m_sel_row_count
Definition: grid_tricks.h:48
int m_sel_col_count
Definition: grid_tricks.h:49

Member Data Documentation

int GRID_TRICKS::m_sel_col_count
protectedinherited
int GRID_TRICKS::m_sel_col_start
protectedinherited
int GRID_TRICKS::m_sel_row_count
protectedinherited
int GRID_TRICKS::m_sel_row_start
protectedinherited

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