NCBI C++ ToolKit
wxgrid_table_adapter.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: wxgrid_table_adapter.cpp 47479 2023-05-02 13:24:02Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
35 
37 #include "copy_column_dlg.hpp"
38 
42 
44 
46 
47 static const char* kVisibleColumns = "Visible Columns";
48 static const char* kWidth = ".Width";
49 
51  : IGridTableAdapter(tableData)
52  , m_SortColumn(kInvalidColumn, kAscending)
53  , m_DefaultCellAttr()
54  , m_IntCellAttr()
55  , m_FloatCellAttr()
56  , m_HtmlCellAttrL()
57  , m_HtmlCellAttrR()
58  , m_TextCellAttrEdit()
59  , m_IntCellAttrEdit()
60  , m_FloatCellAttrEdit()
61  , m_CmdProccessor(cmdProccessor)
62  , m_EventHandler(*this)
63 {
64  SetAttrProvider(new wxGridCellAttrProvider);
65 
66  for (size_t i = 0; i < m_TableData->GetColsCount(); ++i) {
67  m_VisibleColumns.push_back(i);
68  }
69 
71 
72  x_ResetRows();
73 
74  static bool registered = false;
75  if (!registered) {
76  registered = true;
77 
80  "Assign Value",
81  "Assign Value to a Column",
84  "Command shows dialog for assigning value to a whole column of a table");
86  "Copy",
87  "Copy values of Column to another Column",
90  "Copy values of Column to another Column");
91  }
92 }
93 
95 {
96  for (size_t i = 0; i < m_VisibleColumns.size(); ++i) {
97  ITableData::ColumnType colType = m_TableData->GetColumnType(m_VisibleColumns[i]);
98 
99  if (m_TableData->IsHtmlColumn(m_VisibleColumns[i])) {
100  if (colType == ITableData::kInt || colType == ITableData::kReal)
101  SetColAttr(x_GetHtmlCellAttrR(), (int)i);
102  else
103  SetColAttr(x_GetHtmlCellAttrL(), (int)i);
104  continue;
105  }
106 
107  bool edit = m_TableData->AllowEdit(m_VisibleColumns[i]);
108 
109  if (colType == ITableData::kInt)
110  SetColAttr(x_GetIntRendererAttr(edit), (int)i);
111  else if (colType == ITableData::kReal)
112  SetColAttr(x_GetFloatRendererAttr(edit), (int)i);
113  else if (colType == ITableData::kString)
114  SetColAttr(x_GetDefaultRendererAttr(edit), (int)i);
115  else if (colType == ITableData::kCommonString) {
116  if (edit) {
117  vector<string> strings = m_TableData->GetColumnCommonStrings(i);
118  wxArrayString strings2;
119  ITERATE(vector<string>, it, strings) {
120  strings2.push_back(wxString::FromUTF8(it->c_str()));
121  }
122 
123  wxGridCellAttr* attr = new wxGridCellAttr();
124  attr->SetEditor(new wxGridCellChoiceEditor(strings2));
125  attr->SetReadOnly(false);
126  SetColAttr(attr, (int)i);
127  }
128  else
129  SetColAttr(x_GetDefaultRendererAttr(false), (int)i);
130  }
131  else
132  SetColAttr(x_GetDefaultRendererAttr(edit), (int)i);
133  }
134 }
135 
137 {
138  wxGrid* oldGrid = GetView();
139  if (oldGrid != 0)
140  oldGrid->PopEventHandler();
141 
142  wxGridTableBase::SetView( grid );
143 
144  if (grid == 0)
145  return;
146 
147  grid->PushEventHandler(&m_EventHandler);
148 
149  if (m_RegPath.empty())
150  return;
151 
153  CRegistryReadView view = gui_reg.GetReadView(m_RegPath + "."
154  + m_TableData->GetTableTypeId());
155 
156  for (size_t i = 0; i < m_VisibleColumns.size(); ++i) {
157  string label = m_TableData->GetColumnLabel(m_VisibleColumns[i]);
158  int width = view.GetInt(label + kWidth, 0);
159  if (width > 0)
160  grid->SetColSize((int)i, width);
161  }
162 }
163 
165 {
166  if (m_IntCellAttr) {
167  m_IntCellAttr->DecRef();
168  m_IntCellAttr = 0;
169  }
170  if (m_FloatCellAttr) {
171  m_FloatCellAttr->DecRef();
172  m_FloatCellAttr = 0;
173  }
174  if (m_DefaultCellAttr) {
175  m_DefaultCellAttr->DecRef();
176  m_DefaultCellAttr = 0;
177  }
178  if (m_HtmlCellAttrL) {
179  m_HtmlCellAttrL->DecRef();
180  m_HtmlCellAttrL = 0;
181  }
182  if (m_HtmlCellAttrR) {
183  m_HtmlCellAttrR->DecRef();
184  m_HtmlCellAttrR = 0;
185  }
186  if (m_TextCellAttrEdit) {
187  m_TextCellAttrEdit->DecRef();
188  m_TextCellAttrEdit = 0;
189  }
190  if (m_IntCellAttrEdit) {
191  m_IntCellAttrEdit->DecRef();
192  m_IntCellAttrEdit = 0;
193  }
194  if (m_FloatCellAttrEdit) {
195  m_FloatCellAttrEdit->DecRef();
197  }
198 }
199 
201 {
202  if (m_HideUnselected)
203  return static_cast<int>(m_Selected.size());
204  else
205  return static_cast<int>(m_RowToTable.size());
206 }
207 
209 {
210  return static_cast<int>(m_VisibleColumns.size());
211 }
212 
214 {
215  if (!x_ColToTableData(col))
216  return wxEmptyString;
217 
218  return ToWxString(m_TableData->GetColumnLabel(col));
219 }
220 
222 {
223  wxString s = wxGridTableBase::GetRowLabelValue(row);
224 
225  if (x_RowToTableData(row)) {
226  string label = m_TableData->GetRowLabel(row);
227  if (!label.empty())
228  s += ToWxString(" " + label);
229  }
230 
231  return s;
232 }
233 
234 wxString CwxGridTableAdapter::GetValue(int row, int col)
235 {
236  if (!x_CoordsToTableData(row, col))
237  return wxEmptyString;
238 
239  string s;
240  m_TableData->GetStringValue(row, col, s);
241  return wxString::FromUTF8(s.c_str());
242 }
243 
244 wxString CwxGridTableAdapter::GetHtmlValue(int row, int col)
245 {
246  if (!x_CoordsToTableData(row, col))
247  return wxEmptyString;
248 
249  string s;
250  if (m_TableData->IsHtmlColumn(col))
251  return wxString::FromUTF8(m_TableData->GetHtmlValue(row, col).c_str());
252  else {
253  m_TableData->GetStringValue(row, col, s);
254  return wxString::FromUTF8(s.c_str());
255  }
256 }
257 
258 bool CwxGridTableAdapter::CanGetValueAs( int row, int col, const wxString& typeName )
259 {
260  if (!x_CoordsToTableData(row, col))
261  return false;
262 
263  ITableData::ColumnType colType = m_TableData->GetColumnType(col);
264 
265  if (wxGRID_VALUE_STRING == typeName)
266  return true;
267 
268  if (wxGRID_VALUE_NUMBER == typeName)
269  return (colType == ITableData::kInt);
270 
271  if (wxGRID_VALUE_FLOAT == typeName)
272  return (colType == ITableData::kReal);
273 
274  return false;
275 }
276 
277 bool CwxGridTableAdapter::CanSetValueAs( int row, int col, const wxString& typeName )
278 {
279  if (!x_CoordsToTableData(row, col))
280  return false;
281 
282  ITableData::ColumnType colType = m_TableData->GetColumnType(col);
283 
284  if (wxGRID_VALUE_STRING == typeName &&
285  colType == ITableData::kString)
286  return true;
287 
288  if (wxGRID_VALUE_NUMBER == typeName &&
289  colType == ITableData::kInt)
290  return true;
291 
292  if (wxGRID_VALUE_FLOAT == typeName &&
293  colType == ITableData::kReal)
294  return true;
295 
296  return false;
297 }
298 
299 long CwxGridTableAdapter::GetValueAsLong( int row, int col )
300 {
301  if (!x_CoordsToTableData(row, col))
302  return 0;
303  return m_TableData->GetIntValue(row, col);
304 }
305 
306 double CwxGridTableAdapter::GetValueAsDouble( int row, int col )
307 {
308  if (!x_CoordsToTableData(row, col))
309  return 0;
310  return m_TableData->GetRealValue(row, col);
311 }
312 
314 {
315  if (row < 0 || col < 0) {
316  row = col = -1;
317  return false;
318  }
319 
320  if (m_HideUnselected) {
321  if (col < (int)m_VisibleColumns.size() && row < (int)m_Selected.size()) {
322  col = static_cast<int>(m_VisibleColumns[col]);
323  row = static_cast<int>(m_SelectedRowToTable[row]);
324  return true;
325  }
326  }
327  else {
328  if (col < (int)m_VisibleColumns.size() && row < (int)m_RowToTable.size()) {
329  col = static_cast<int>(m_VisibleColumns[col]);
330  row = static_cast<int>(m_RowToTable[row]);
331  return true;
332  }
333  }
334  row = col = -1;
335  return false;
336 }
337 
339 {
340  if (col >= 0 && col < (int)m_VisibleColumns.size()) {
341  col = static_cast<int>(m_VisibleColumns[col]);
342  return true;
343  }
344  return false;
345 }
346 
348 {
349  if (m_HideUnselected) {
350  if (row < (int)m_Selected.size()) {
351  row = static_cast<int>(m_SelectedRowToTable[row]);
352  return true;
353  }
354  }
355  else {
356  if (row < (int)m_RowToTable.size()) {
357  row = static_cast<int>(m_RowToTable[row]);
358  return true;
359  }
360  }
361  row = -1;
362  return false;
363 }
364 
365 void CwxGridTableAdapter::SetValue(int row, int col, const wxString& value)
366 {
367  if (!x_CoordsToTableData(row, col))
368  return;
369 
370  if (m_CmdProccessor && m_TableData->AllowEdit(col)) {
373  }
374 }
375 
376 void CwxGridTableAdapter::SetValueAsLong( int row, int col, long value )
377 {
378  if (!x_CoordsToTableData(row, col))
379  return;
380 
381  if (m_CmdProccessor && m_TableData->AllowEdit(col)) {
384  }
385 }
386 
387 void CwxGridTableAdapter::SetValueAsDouble( int row, int col, double value )
388 {
389  if (!x_CoordsToTableData(row, col))
390  return;
391 
392  if (m_CmdProccessor && m_TableData->AllowEdit(col)) {
395  }
396 }
397 
398 /*
399 wxGridCellAttr* CwxGridTableAdapter::GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind )
400 {
401  wxGridCellAttr* attr = wxGridTableBase::GetAttr( row, col, kind );
402 
403  attr->SetReadOnly( !GetTable().AllowEdit( col ) );
404 
405  return attr;
406 }
407 */
408 
409 wxGridCellAttr* CwxGridTableAdapter::x_GetDefaultRendererAttr(bool allowEdit)
410 {
411  if (allowEdit && m_CmdProccessor) {
412  if (m_TextCellAttrEdit == 0) {
413  m_TextCellAttrEdit = new wxGridCellAttr();
414  m_TextCellAttrEdit->SetReadOnly(false);
415  }
416  m_TextCellAttrEdit->IncRef();
417 
418  return m_TextCellAttrEdit;
419  }
420  else {
421  if (m_DefaultCellAttr == 0) {
422  m_DefaultCellAttr = new wxGridCellAttr();
423  m_DefaultCellAttr->SetReadOnly();
424  }
425  m_DefaultCellAttr->IncRef();
426 
427  return m_DefaultCellAttr;
428  }
429 }
430 
431 wxGridCellAttr* CwxGridTableAdapter::x_GetIntRendererAttr(bool allowEdit)
432 {
433  if (allowEdit && m_CmdProccessor) {
434  if (m_IntCellAttrEdit == 0) {
435  m_IntCellAttrEdit = new wxGridCellAttr();
436  m_IntCellAttrEdit->SetRenderer(new wxGridCellNumberRenderer());
437  m_IntCellAttrEdit->SetEditor(new wxGridCellNumberEditor());
438  m_IntCellAttrEdit->SetReadOnly(false);
439  }
440  m_IntCellAttrEdit->IncRef();
441 
442  return m_IntCellAttrEdit;
443  }
444  else {
445  if (m_IntCellAttr == 0) {
446  m_IntCellAttr = new wxGridCellAttr();
447  m_IntCellAttr->SetRenderer(new wxGridCellNumberRenderer());
448  m_IntCellAttr->SetReadOnly();
449  }
450  m_IntCellAttr->IncRef();
451 
452  return m_IntCellAttr;
453  }
454 }
455 
456 wxGridCellAttr* CwxGridTableAdapter::x_GetFloatRendererAttr(bool allowEdit)
457 {
458  if (allowEdit && m_CmdProccessor) {
459  if (m_FloatCellAttrEdit == 0) {
460  m_FloatCellAttrEdit = new wxGridCellAttr();
461  m_FloatCellAttrEdit->SetRenderer(new wxGridCellFloatRenderer());
462  m_FloatCellAttrEdit->SetEditor(new wxGridCellFloatEditor());
463  m_FloatCellAttrEdit->SetReadOnly(false);
464  }
465  m_FloatCellAttrEdit->IncRef();
466 
467  return m_FloatCellAttrEdit;
468  }
469  else {
470  if (m_FloatCellAttr == 0) {
471  m_FloatCellAttr = new wxGridCellAttr();
472  m_FloatCellAttr->SetRenderer(new wxGridCellFloatRenderer());
473  m_FloatCellAttr->SetReadOnly();
474  }
475  m_FloatCellAttr->IncRef();
476 
477  return m_FloatCellAttr;
478  }
479 }
480 
482 {
483  if (m_HtmlCellAttrL == 0) {
484  m_HtmlCellAttrL = new wxGridCellAttr();
485  m_HtmlCellAttrL->SetOverflow(false);
486  m_HtmlCellAttrL->SetRenderer(new CStrWithURLRenderer());
487  m_HtmlCellAttrL->SetReadOnly();
488  }
489  m_HtmlCellAttrL->IncRef();
490 
491  return m_HtmlCellAttrL;
492 }
493 
495 {
496  if (m_HtmlCellAttrR == 0) {
497  m_HtmlCellAttrR = new wxGridCellAttr();
498  m_HtmlCellAttrR->SetOverflow(false);
499  m_HtmlCellAttrR->SetRenderer(new CStrWithURLRenderer());
500  m_HtmlCellAttrR->SetReadOnly();
501  m_HtmlCellAttrR->SetAlignment(wxALIGN_RIGHT, wxALIGN_TOP);
502  }
503  m_HtmlCellAttrR->IncRef();
504 
505  return m_HtmlCellAttrR;
506 }
507 
508 void CwxGridTableAdapter::ShowColumn(size_t col, bool show)
509 {
510  if (col >= m_TableData->GetColsCount())
511  return;
512 
513  if (show) {
514  vector<size_t>::iterator it =
515  lower_bound(m_VisibleColumns.begin(), m_VisibleColumns.end(), col);
516 
517  if (it != m_VisibleColumns.end() && *it == col)
518  return;
519 
520  string label = m_TableData->GetColumnLabel(col);
521 
522  size_t index = it - m_VisibleColumns.begin();
523  m_VisibleColumns.insert(it, col);
524 
525  if (GetView()) {
526  wxGridTableMessage msg( this,
527  wxGRIDTABLE_NOTIFY_COLS_INSERTED,
528  static_cast<int>(index),
529  1);
530 
531  GetView()->ProcessTableMessage( msg );
532 
533  int colWidth = x_LoadColumnWidth(label);
534  if (colWidth > 0)
535  GetView()->SetColSize((int)index, colWidth);
536 
538  }
539  }
540  else {
541  vector<size_t>::iterator it = find(m_VisibleColumns.begin(), m_VisibleColumns.end(), col);
542  if (it == m_VisibleColumns.end())
543  return;
544 
545  size_t index = it - m_VisibleColumns.begin();
546  m_VisibleColumns.erase(it);
547 
548  if (GetView()) {
549  string label = m_TableData->GetColumnLabel(col);
550  x_SaveColumnWidth(label, GetView()->GetColSize((int)index));
551 
552  wxGridTableMessage msg( this,
553  wxGRIDTABLE_NOTIFY_COLS_DELETED,
554  static_cast<int>(index),
555  1);
556 
557  GetView()->ProcessTableMessage( msg );
558 
560  }
561  }
562 }
563 
565 {
566  return (find(m_VisibleColumns.begin(), m_VisibleColumns.end(), col) != m_VisibleColumns.end());
567 }
568 
569 size_t CwxGridTableAdapter::GetOriginalRow(size_t queryRow) const
570 {
571  if (m_HideUnselected) {
572  return queryRow < m_SelectedRowToTable.size() ?
573  m_SelectedRowToTable[queryRow] : (size_t)-1;
574  }
575 
576  return (queryRow < m_RowToTable.size()) ? m_RowToTable[queryRow] : (size_t)-1;
577 }
578 
579 size_t CwxGridTableAdapter::GetCurrentRow(size_t queryRow) const
580 {
581  if (m_HideUnselected) {
582  return queryRow < m_SelectedTableToRow.size() ?
583  m_SelectedTableToRow[queryRow] : (size_t)-1;
584  }
585 
586  return (queryRow < m_TableToRow.size()) ? m_TableToRow[queryRow] : (size_t)-1;
587 }
588 
590 {
591  size_t rows = m_TableData->GetRowsCount();
592  m_RowToTable.resize(rows);
593  m_TableToRow.resize(rows);
594  for (size_t i = 0; i < rows; ++i) {
595  m_RowToTable[i] = i;
596  m_TableToRow[i] = i;
597  }
598 }
599 
600 bool CwxGridTableAdapter::x_ValidateColumns(const vector<size_t>& colums) const
601 {
602  if (colums.empty())
603  return false;
604 
605  set<size_t> col_set;
606 
607  size_t colCount = m_TableData->GetColsCount();
608  if (colums.size() > colCount)
609  return false;
610 
611  for (size_t i = 0; i < colums.size(); ++i) {
612  size_t col = colums[i];
613  if (col >= colCount)
614  return false;
615  if (!col_set.insert(col).second)
616  return false;
617  }
618 
619  return true;
620 }
621 
623 {
624  if (sortColumn.first == kInvalidColumn) {
625  x_ResetRows();
626  m_SortColumn = sortColumn;
627  }
628  else if (sortColumn.first < m_TableData->GetColsCount()) {
629  if (sortColumn.first == m_SortColumn.first) {
630  if (sortColumn.second == m_SortColumn.second)
631  return;
632 
633  reverse(m_RowToTable.begin(), m_RowToTable.end());
634  m_SortColumn = sortColumn;
635  }
636  else {
637  if (!m_RowToTable.empty()) {
638  CTableDataSorter::Sort(*m_TableData, sortColumn.first,
639  &*m_RowToTable.begin(),
640  &*m_RowToTable.begin() + (m_RowToTable.end() - m_RowToTable.begin()),
641  (sortColumn.second == Descending));
642  }
643  m_SortColumn = sortColumn;
644  }
645 
646  m_TableToRow.resize(m_RowToTable.size());
647  for (size_t i = 0; i < m_RowToTable.size(); ++i) {
649  }
650  }
651 
653 }
654 
656 {
657  //
658  // Put the selected entries in their own RowToTable/TableToRow
659  // index arrays so that the user can switch between viewing
660  // all rows and viewing only selected rows quickly.
661  int sel_idx = 0;
662  size_t i;
663  m_SelectedRowToTable.resize(m_Selected.size());
664  m_SelectedTableToRow.resize(m_RowToTable.size());
665 
666  for (i=0; i<m_RowToTable.size(); ++i) {
667  size_t idx = m_RowToTable[i];
668 
669  // We put the set of selected table indices in sorted order
670  // for quicker searching:
671  bool found = std::binary_search(m_Selected.begin(), m_Selected.end(), idx);
672 
673  // If this table row is currently selected:
674  if (found) {
675  m_SelectedRowToTable[sel_idx++] = idx;
676  }
677  }
678 
679  // Unselected rows in the data table do not map to any row in
680  // the grid table, so start by intializing all to -1:
681  for (i = 0; i < m_RowToTable.size(); ++i) {
682  m_SelectedTableToRow[i] = (size_t)-1;
683  }
684 
685  // The selected rows in the data table do map to rows in
686  // the grid table, so updated those here:
687  for (i = 0; i < m_SelectedRowToTable.size(); ++i) {
689  }
690 }
691 
692 void CwxGridTableAdapter::SetSelection(const vector<size_t>& query_sel)
693 {
695 
697 }
698 
700 {
701  if (m_Selected.size() == 0) {
702  m_CurrentSelection = (size_t)-1;
703  }
704  else if (m_Selected.size() == 1) {
706  }
707  else {
708  // select first element (first in display order, not data (table) order).
709  size_t i;
710  if (dir == 0) {
711  size_t min_row_idx = (size_t)-1;
712  size_t selected_idx = (size_t)-1;
713 
714  if (!m_HideUnselected) {
715  for (i=0; i<m_Selected.size(); ++i) {
716  if (m_TableToRow[m_Selected[i]] < min_row_idx) {
717  min_row_idx = m_TableToRow[m_Selected[i]];
718  selected_idx = m_Selected[i];
719  }
720  }
721  m_CurrentSelection = selected_idx;
722  }
723  else {
725  }
726  }
727  else if (dir > 0) {
728  if (!m_HideUnselected) {
729  size_t min_row_idx = m_TableToRow[m_CurrentSelection];
730  size_t next_row_idx = (size_t)-1;
731  size_t selected_idx = (size_t)-1;
732 
733  for (i=0; i<m_Selected.size(); ++i) {
734  if (m_TableToRow[m_Selected[i]] > min_row_idx &&
735  m_TableToRow[m_Selected[i]] < next_row_idx) {
736  next_row_idx = m_TableToRow[m_Selected[i]];
737  selected_idx = m_Selected[i];
738  }
739  }
740  if (selected_idx != (size_t)-1)
741  m_CurrentSelection = selected_idx;
742  }
743  else {
744  size_t cur_row_idx = m_SelectedTableToRow[m_CurrentSelection];
745  if (cur_row_idx < m_Selected.size()-1)
746  m_CurrentSelection = m_SelectedRowToTable[cur_row_idx+1];
747  }
748  }
749  else if (dir < 0) {
750  if (!m_HideUnselected) {
751  size_t min_row_idx = m_TableToRow[m_CurrentSelection];
752  size_t prev_row_idx = 0;
753  size_t selected_idx = (size_t)-1;
754 
755  for (i=0; i<m_Selected.size(); ++i) {
756  if (m_TableToRow[m_Selected[i]] < min_row_idx &&
757  m_TableToRow[m_Selected[i]] >= prev_row_idx) {
758  prev_row_idx = m_TableToRow[m_Selected[i]];
759  selected_idx = m_Selected[i];
760  }
761  }
762  if (selected_idx != (size_t)-1)
763  m_CurrentSelection = selected_idx;
764  }
765  else {
766  size_t cur_row_idx = m_SelectedTableToRow[m_CurrentSelection];
767  if (cur_row_idx > 0)
768  m_CurrentSelection = m_SelectedRowToTable[cur_row_idx-1];
769  }
770  }
771  }
772 }
773 
775 {
776  if (m_RegPath.empty())
777  return NcbiEmptyString;
778 
779  return m_RegPath + "." + m_TableData->GetTableTypeId();
780 }
781 
782 void CwxGridTableAdapter::x_SaveColumnWidth(const string& label, int width)
783 {
784  if (m_RegPath.empty())
785  return;
786 
788  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath + "."
789  + m_TableData->GetTableTypeId());
790  view.Set(label + kWidth , width);
791 }
792 
794 {
795  if (m_RegPath.empty())
796  return 0;
797 
799  CRegistryReadView view = gui_reg.GetReadView(m_RegPath + "."
800  + m_TableData->GetTableTypeId());
801  return view.GetInt(label + kWidth, 0);
802 }
803 
805 {
806  vector<size_t> vis_columns;
807 
808  if (!m_RegPath.empty()) {
810  CRegistryReadView view = gui_reg.GetReadView(m_RegPath + "."
811  + m_TableData->GetTableTypeId());
812 
813  vector<int> vis_columns_i;
814  view.GetIntVec(kVisibleColumns, vis_columns_i);
815 
816  if (!vis_columns_i.empty()) {
817  for (size_t i = 0; i < vis_columns_i.size(); ++i)
818  vis_columns.push_back(vis_columns_i[i]);
819  }
820 
821  if (x_ValidateColumns(vis_columns)) {
822  m_VisibleColumns = vis_columns;
824  }
825  }
826 }
827 
829 {
830  if (m_RegPath.empty())
831  return;
832 
834  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath + "."
835  + m_TableData->GetTableTypeId());
836 
837  vector<int> vis_columns_i;
838  for (size_t i = 0; i < m_VisibleColumns.size(); ++i)
839  vis_columns_i.push_back((int)m_VisibleColumns[i]);
840  view.Set(kVisibleColumns, vis_columns_i);
841 
842  if (GetView()) {
843  for (size_t i = 0; i < m_VisibleColumns.size(); ++i) {
844  string label = m_TableData->GetColumnLabel(m_VisibleColumns[i]);
845  int width = GetView()->GetColSize((int)i);
846  view.Set(label + kWidth , width);
847  }
848  }
849 }
850 
851 static
852 WX_DEFINE_MENU(kTableEditMenu)
853  WX_MENU_SEPARATOR_L("Edit Table")
854  WX_SUBMENU("Column")
858 WX_END_MENU()
859 
861 {
862  if (m_CmdProccessor) {
863  return CUICommandRegistry::GetInstance().CreateMenu(kTableEditMenu);
864  }
865  return 0;
866 }
867 
868 BEGIN_EVENT_TABLE( CwxGridTableAdapter::CEventHandler, wxEvtHandler )
874 
875 void CwxGridTableAdapter::CEventHandler::OnAssignColumnValue(wxCommandEvent&)
876 {
877  CAssignColumnValueDlg dlg(m_Adapter.GetView(), *m_Adapter.m_TableData);
878  if(dlg.ShowModal() == wxID_OK && m_Adapter.m_CmdProccessor) {
880  if (command) {
881  m_Adapter.m_CmdProccessor->Execute(command);
882  }
883  }
884 }
885 
887 {
889 }
890 
891 void CwxGridTableAdapter::CEventHandler::OnCopyColumn(wxCommandEvent& WXUNUSED(event))
892 {
893  CCopyColumnDlg dlg(m_Adapter.GetView(), *m_Adapter.m_TableData);
894  if(dlg.ShowModal() == wxID_OK && m_Adapter.m_CmdProccessor) {
896  if (command) {
897  m_Adapter.m_CmdProccessor->Execute(command);
898  }
899  }
900 }
901 
903 {
904  event.Enable(CCopyColumnDlg::CanCopyColumn(*m_Adapter.m_TableData));
905 }
906 
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
static bool CanAssignColumn(ITableData &table)
static bool CanCopyColumn(ITableData &table)
IEditCommand * GetEditCommand()
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
void GetIntVec(const string &key, vector< int > &val) const
Definition: reg_view.cpp:252
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
static void Sort(ITableData &tableData, size_t column, size_t *begin, size_t *end, bool descending=false)
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenu * CreateMenu(const SwxMenuItemRec *items)
create a menu from a static definition (see WX_*_MENU macros)
Definition: ui_command.cpp:349
int RegisterCommand(CUICommand *cmd)
assumes ownership of the given object returns a command id (useful when registry is used for auto id ...
Definition: ui_command.cpp:198
void OnUpdateCopyColumn(wxUpdateUIEvent &event)
void OnCopyColumn(wxCommandEvent &event)
void OnAssignColumnValue(wxCommandEvent &event)
void OnUpdateAssignColumnValue(wxUpdateUIEvent &event)
int x_LoadColumnWidth(const string &label)
vector< size_t > m_SelectedRowToTable
maps from index in m_Selected to table (ITableData) index
vector< size_t > m_TableToRow
maps from ITableData index to row position in display
wxGridCellAttr * x_GetIntRendererAttr(bool allowEdit)
bool x_CoordsToTableData(int &row, int &col)
wxGridCellAttr * m_HtmlCellAttrR
wxGridCellAttr * x_GetHtmlCellAttrR()
virtual void SetValueAsDouble(int row, int col, double value)
virtual void SetSelection(const vector< size_t > &query_sel)
virtual long GetValueAsLong(int row, int col)
virtual bool IsColumnShown(size_t col) const
void x_SaveColumnWidth(const string &label, int width)
bool x_ValidateColumns(const vector< size_t > &colums) const
virtual void SetValueAsLong(int row, int col, long value)
wxGridCellAttr * x_GetHtmlCellAttrL()
wxGridCellAttr * m_TextCellAttrEdit
wxGridCellAttr * m_FloatCellAttr
virtual void SetValue(int row, int col, const wxString &value)
ICommandProccessor * m_CmdProccessor
wxGridCellAttr * m_IntCellAttr
virtual double GetValueAsDouble(int row, int col)
virtual size_t GetOriginalRow(size_t queryRow) const
virtual void SaveSettings() const
wxGridCellAttr * x_GetFloatRendererAttr(bool allowEdit)
CwxGridTableAdapter(ITableData &tableData, ICommandProccessor *cmdProccessor)
vector< size_t > m_SelectedTableToRow
maps from ITableData index to index in m_Selected array
wxGridCellAttr * m_HtmlCellAttrL
vector< size_t > m_RowToTable
maps from row position in display to table (ITableData) index
wxGridCellAttr * x_GetDefaultRendererAttr(bool allowEdit)
virtual void IterateSelection(int dir)
wxGridCellAttr * m_FloatCellAttrEdit
virtual void SortByColumn(TSortColumn sortColumn)
virtual wxString GetValue(int row, int col)
virtual void SetView(wxGrid *grid)
virtual wxString GetColLabelValue(int col)
virtual bool CanGetValueAs(int row, int col, const wxString &typeName)
virtual bool CanSetValueAs(int row, int col, const wxString &typeName)
virtual wxString GetRowLabelValue(int row)
wxString GetHtmlValue(int row, int col)
wxGridCellAttr * m_DefaultCellAttr
virtual void ShowColumn(size_t col, bool show)
virtual size_t GetCurrentRow(size_t queryRow) const
wxGridCellAttr * m_IntCellAttrEdit
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
vector< size_t > m_Selected
vector< size_t > m_VisibleColumns
CIRef< ITableData > m_TableData
pair< size_t, ESort > TSortColumn
virtual void SetSelection(const vector< size_t > &query_sel)
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
char value[7]
Definition: config.c:431
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define kInvalidColumn
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static const char label[]
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
int i
Definition: fix_pub.hpp:45
const char * command
static const char *const strings[]
Definition: utf8.c:21
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define WX_DEFINE_MENU(name)
New macros for defining menus for use with CUICommandRegistry.
Definition: ui_command.hpp:266
#define WX_SUBMENU(label)
Definition: ui_command.hpp:288
#define WX_END_MENU()
Definition: ui_command.hpp:294
#define WX_MENU_SEPARATOR_L(label)
Definition: ui_command.hpp:285
#define WX_MENU_ITEM(cmd)
Definition: ui_command.hpp:270
#define WX_END_SUBMENU()
Definition: ui_command.hpp:291
wxMenu * CreateMenu(const CMenuItem *item)
Creates a wxMenu object replicating the structure of CMenuItem.
Definition: wx_utils.cpp:365
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
@ eCmdAssignColumnValue
@ eCmdCopyColumn
static const char * kVisibleColumns
static const char * kWidth
Modified on Wed Dec 06 07:13:31 2023 by modify_doxy.py rev. 669887