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

Go to the SVN repository for this file.

1 /* $Id: table_import_listctrl.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: Bob Falk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
37 #include <wx/settings.h>
38 
39 #include <algorithm>
40 
41 
43 
44 static const long kDefStyle = wxLC_REPORT | wxLC_VIRTUAL | wxLC_HRULES | wxLC_VRULES | wxLC_SINGLE_SEL;
45 
47  wxWindow* parent,
48  wxWindowID id,
49  const wxPoint& pos,
50  const wxSize& size,
51  long style,
52  const wxValidator& validator,
53  const wxString& name)
54  : wxListCtrl(
55  parent, id, pos, size,
56  (style & ~wxLC_MASK_TYPE) | kDefStyle, validator, name)
57  , m_ViewType(eMultiColumn)
58  , m_FixedWidthUseFields(false)
59  , m_ImageList(16, 16, TRUE)
60  , m_FontWidth(0)
61  , m_IgnoreWidthEvent(false)
62  , m_DisplayTypeHeader(false)
63 {
64  // courier new looks bad on mac - light/hard to see. Fixedsys looks bad
65  // on windows - old style computer type with sharp edges.
66 #ifdef __WXOSX_COCOA__
67  SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
68  false, wxT("Fixedsys")));
69  m_FirstRowAttr.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC,
70  wxFONTWEIGHT_NORMAL, false, wxT("Fixedsys")));
71 #else
72  SetFont(wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
73  false, wxT("Courier New")));
74  m_FirstRowAttr.SetFont(wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC,
75  wxFONTWEIGHT_NORMAL, false, wxT("Courier New")));
76 #endif
77 
78  // for a brighter blue (stand out more): wxSYS_COLOUR_HIGHLIGHT
79  m_FirstRowAttr.SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_MENU));
80 
81  // Image list adds some (blank) spacing to the left of the first column,
82  // at least on windows even thought I only want images in the column headers.
83  // Anyway, I only specify wxLC_ALIGN_LEFT for the list boxes that need those
84  // column images, so I know when I need to compensate for them in terms of
85  // column width.
86  if (style & wxLC_ALIGN_LEFT) {
88  provider->RegisterFileAlias(wxT("tablelist_import::checked"), wxT("check.png"));
89  provider->RegisterFileAlias(wxT("tablelist_import::skipped"), wxT("track_close.png"));
90  provider->RegisterFileAlias(wxT("tablelist_import::id"), wxT("sequence_symbol.png"));
91 
92  SetImageList(&m_ImageList, wxIMAGE_LIST_SMALL);
93 
94  wxIcon ico = provider->GetIcon(wxT("tablelist_import::checked"));
95  if( ico.IsOk() ){
96  m_ImageList.Add(ico);
97  }
98 
99  ico = provider->GetIcon(wxT("tablelist_import::skipped"));
100  if( ico.IsOk() ){
101  m_ImageList.Add(ico);
102  }
103 
104  ico = provider->GetIcon(wxT("tablelist_import::id"));
105  if( ico.IsOk() ){
106  m_ImageList.Add(ico);
107  }
108  }
109 }
110 
111 
112 // wxWidgets RTTI information
113 IMPLEMENT_DYNAMIC_CLASS( CTableImportListCtrl, wxListCtrl )
114 
116 {
117  m_ImportedTableData = ds;
118 
119  // Clear current list info
120  ClearAll();
121 
122  if (m_ImportedTableData.IsNull() ||
123  m_ImportedTableData->GetColumns().size() == 0) {
124  SetItemCount(0);
125  }
126  else {
127 
128  auto num_rows = m_ImportedTableData->GetNumRows();
129  // First column is a 1-based row number. Its width is based on the
130  // character length of num_rows, so compute that here:
131  int first_column_char_width = (int)log10((double)num_rows+1) + 1;
132 
133  wxFont f = GetFont();
134  wxClientDC dc(this);
135  dc.SetFont(f);
136  m_FontWidth = dc.GetCharWidth();
137 
138  // If the view type is eSingleColumn, we display all rows including headers
139  // and comments (if there are any). In eMultiColumn mode, we ignore headers
140  // and comments so we set the number of rows accordingly
141  if (m_ViewType == eSingleColumn) {
142  SetItemCount(m_ImportedTableData->GetNumRows());
143  }
144  else {
145  SetItemCount(m_ImportedTableData->GetNumImportedRows() +
146  (m_DisplayTypeHeader ? 1 : 0));
147  }
148 
149 
150  first_column_char_width = (first_column_char_width+2) * m_FontWidth;
151 
152  // When I have an image list, even if images are not used in
153  // cells, the first cell column seems to make room for it, messing
154  // up my cell sizes. So I pass the option wxLC_ALIGN_LEFT only
155  // to lists that need images (for the column headers) and add
156  // extra pixels to the first column to compensate.
157  if (GetImageList(wxIMAGE_LIST_SMALL) != NULL)
158  first_column_char_width += 16;
159 
160  if (GetColumnCount() == 0) {
161  InsertColumn(0,
162  wxString(wxT("#")),
163  wxLIST_FORMAT_LEFT,
164  first_column_char_width);
165  }
166 
167 
168  if (m_ImportedTableData->GetTableType() == CTableImportDataSource::eDelimitedTable) {
169  if (m_ImportedTableData->GetDelimiters().size() == 0 ||
170  m_ViewType == eSingleColumn) {
171  // Get column width in pixels
172  int width = static_cast<int>(std::max(m_ImportedTableData->GetMaxRowLength(),
173  m_ImportedTableData->GetMaxNonImportedRowLength()));
174 
175  // Get column width (and add 2 chars to make sure all the
176  // characters show)
177  width = (width+2) * m_FontWidth;
178 
179  // Add a new column or update existing column (if table already has a
180  // column 1):
181  if (GetColumnCount() == 1) {
182  InsertColumn(1,
183  wxString(ToWxString(m_ImportedTableData->GetColumnName(0))),
184  wxLIST_FORMAT_LEFT,
185  width);
186  }
187  else {
188  wxListItem item;
189  GetColumn(1, item);
190  item.SetWidth(width);
191  item.SetText(ToWxString(m_ImportedTableData->GetColumnName(0)));
192  SetColumn(1, item);
193  }
194  }
195  else {
196  // First column is line number - already inserted.
197  for (size_t i=1; i<m_ImportedTableData->GetColumns().size(); ++i) {
198 
199  CTableImportColumn c = m_ImportedTableData->GetColumns()[i];
200  // Get column width in characters and convert to pixels.
201  int width = m_ImportedTableData->GetColumnWidth(i);
202 
203  // Leave some room for type headers if this list includes them
204  if (m_DisplayTypeHeader)
205  width = std::max(6, width);
206 
207  // Get column width (and add 2 chars to make sure all the
208  // characters show)
209  width = (width+2) * m_FontWidth;
210 
211  // Add a new column or update existing column (if table already has a
212  // column i)
213  if (GetColumnCount() <= (int)i) {
214  InsertColumn(i,
215  wxString(ToWxString(m_ImportedTableData->GetColumnName(i))),
216  wxLIST_FORMAT_LEFT,
217  width);
218  }
219  else {
220  wxListItem item;
221  GetColumn(static_cast<int>(i), item);
222  item.SetWidth(width);
223  item.SetText(wxString(m_ImportedTableData->GetColumnName(i)));
224  SetColumn(static_cast<int>(i), item);
225  }
226  }
227  }
228  }
229  else {
230  // Get column width in pixels
231  int width = static_cast<int>(m_ImportedTableData->GetMaxRowLength());
232 
233  // Get column width (and add 2 chars to make sure all the
234  // characters show)
235  width = (width+2) * m_FontWidth;
236 
237  // Synchronize datasource and listcontrol columns. User
238  // may go back and forth to/from fixed width panel so have
239  // to handle different combinations.
240 
241  // Default (initial) case: one (non-row-number) col in data:
242  if (m_ImportedTableData->GetColumns().size() == 2) {
243 
244  m_ImportedTableData->GetColumns()[1].SetWidth(static_cast<int>(m_ImportedTableData->GetMaxRowLength()));
245 
246  if (GetColumnCount() == 1) {
247  InsertColumn(1,
248  wxString(wxString(m_ImportedTableData->GetColumnName(1))),
249  wxLIST_FORMAT_LEFT,
250  width);
251  }
252  else if (GetColumnCount() == 2) {
253  wxListItem item;
254  GetColumn(1, item);
255  item.SetWidth(width);
256  item.SetText(wxString(m_ImportedTableData->GetColumnName(1)));
257  SetColumn(1, item);
258  }
259  // Delete any columns in listcontrol beyond second column:
260  while (GetColumnCount() > 2)
261  DeleteColumn(GetColumnCount()-1);
262  }
263  else {
264  // Start by getting rid of listcontrol columns:
265  while (GetColumnCount() > 1)
266  DeleteColumn(GetColumnCount()-1);
267 
268  int full_width = static_cast<int>(m_ImportedTableData->GetMaxRowLength());
269 
270  // Now add them back using whatever widths are in the data source:
271  for (size_t i=1; i< m_ImportedTableData->GetColumns().size(); ++i) {
272  int w = m_ImportedTableData->GetColumns()[i].GetWidth();
273 
274  // Allocate enough space in listctrl for all characters,
275  // padding the last column if needed
276  if (i == m_ImportedTableData->GetColumns().size()-1) {
277  w = full_width;
278  m_ImportedTableData->GetColumns()[i].SetWidth(w);
279  }
280 
281  int char_width = (w+2)*m_FontWidth;
282  InsertColumn(i,
283  wxString(wxString(m_ImportedTableData->GetColumnName(i))),
284  wxLIST_FORMAT_LEFT,
285  char_width);
286 
287  full_width -= w;
288  }
289  }
290  }
291  }
292 
293  // After updating, list may need to add a horizontal scroll bar. Before
294  // adding ScrollList() (in windows) it would not add the horizontal scroll
295  // until I resized the window or manually scrolled vertically. That's why
296  // the ScrollList() hack was added. I also tried SendSizeEvent() but that
297  // didn't work.
298  ScrollList(1, 1);
299  ScrollList(-1, -1);
300 
301  // Select the first row by default
302  if (GetItemCount() > 0)
303  SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
304  Refresh();
305 }
306 
307 int CTableImportListCtrl::GetColumnImageID(int col, bool checkbox_only) const
308 {
309  // If a column meets more than one of these (e.g. current and skipped)
310  // then the first one takes priority (is returned)
311  if (!m_ImportedTableData.IsNull()) {
312  if ((size_t)col < m_ImportedTableData->GetColumns().size()) {
313  if (checkbox_only) {
314  if (m_ImportedTableData->GetColumns()[col].GetIsCurrent())
315  return 0;
316  else
317  return -1;
318  }
319  else {
320  if (m_ImportedTableData->GetColumns()[col].GetSkipped())
321  return 1;
322  else if (m_ImportedTableData->GetColumns()[col].GetType() ==
324  m_ImportedTableData->GetColumns()[col].GetMatchColumn())
325  return 2;
326  else if (m_ImportedTableData->GetColumns()[col].GetIsCurrent())
327  return 0;
328  }
329  }
330  }
331 
332  return -1;
333 }
334 
336 {
337  /// Can't divide first column - it is the row number.
338  if (col == 0)
339  return;
340 
341  vector<CTableImportColumn>& data_cols = m_ImportedTableData->GetColumns();
342 
343  /// Can't divide a column with width <2
344  if (data_cols[col].GetWidth() < 2)
345  return;
346 
347  if (col < GetColumnCount()) {
348  // Prevent updates to column data in column resize handler
349  m_IgnoreWidthEvent = true;
350 
351  wxListItem item;
352  GetColumn(col, item);
353  int col_width = item.GetWidth();
354  item.SetWidth(col_width/2);
355  SetColumn(col, item);
356 
357  // Get width of divided column in characters (from data source)
358  int width1 = data_cols[col].GetWidth()/2;
359  int width2 = data_cols[col].GetWidth() - width1;
360 
361  data_cols[col].SetWidth(width1);
362 
363  // Add column to data source
365  c.SetName("Column " + NStr::NumericToString(col));
366  c.SetWidth(width2);
367  data_cols.insert(data_cols.begin()+col, c);
369 
370  // Get width of new and old column in pixels based on
371  // previous character length of entire column (always
372  // add 2 characters for padding)
373  int pixel_width1 = (width1+2) * m_FontWidth;
374  int pixel_width2 = (width2+2) * m_FontWidth;
375 
376  // update pixel width of current column
377  GetColumn(col, item);
378  item.SetWidth(pixel_width1);
379  SetColumn(col, item);
380 
381  // Add column to the right of current column in datasource object
382  InsertColumn(col,
383  wxString(ToWxString(data_cols[col].GetName())),
384  wxLIST_FORMAT_LEFT,
385  pixel_width2);
386 
387  // Update column names
389 
390  m_IgnoreWidthEvent = false;
391  }
392 }
393 
395 {
396  // Can't merge first column - it is the row number.
397  // And if there are 2 columns, then all the data goes
398  // in column 2 and it can't be deleted/merged.
399  if (col == 0 || GetColumnCount() <= 2)
400  return;
401 
402  // We merge with column to the right unless its the last column, then
403  // we merge with the column to the left (unless there are only 2 cos - the
404  // row number and the col we clicked on)
405  if (col == GetColumnCount()-1)
406  col = col-1;
407 
408  if (col < GetColumnCount()-1) {
409  // Prevent updates to column data in column resize handler
410  m_IgnoreWidthEvent = true;
411 
412  // Get first column from listcontrol and its width:
413  wxListItem item1;
414  GetColumn(col, item1);
415 
416  // Set width of merged column based on character (data source)
417  // widths of the two columns being merged.
418  int merged_width = m_ImportedTableData->GetColumnWidth(col) +
420  int pixel_width = (merged_width+2)*m_FontWidth;
421  item1.SetWidth(pixel_width);
422  SetColumn(col, item1);
423 
424  // Delete column from list widget
425  DeleteColumn(col+1);
426 
427  // Delete column info from data source.
428  vector<CTableImportColumn>& data_cols = m_ImportedTableData->GetColumns();
429  data_cols[col].SetWidth(data_cols[col].GetWidth() + data_cols[col+1].GetWidth());
430  data_cols.erase(data_cols.begin() + col + 1);
431 
433 
434  m_IgnoreWidthEvent = false;
435  }
436 }
437 
439 {
440  vector<CTableImportColumn>& data_cols = m_ImportedTableData->GetColumns();
441 
442  // Update column names which have not been updated by the user manually
443  // in third (column ID) panel. This would only be the case if the
444  // user went there and came back.
445  for (size_t i=1; i<data_cols.size(); ++i) {
446  string col_name = data_cols[i].GetName();
447 
448  // If the column name is in dafault name format: "Col #" then
449  // update it to the current number. If it is not, leave it alone.
450  vector<string> str_arr;
451  NStr::Split(col_name, " ", str_arr);
452  if (str_arr.size() == 2 &&
453  str_arr[0] == "Col" &&
454  NStr::StringToInt(str_arr[1], NStr::fConvErr_NoThrow) != 0) {
455  // Update name in data source:
456  col_name = "Col " + NStr::NumericToString(i);
457  data_cols[i].SetName(col_name);
458  }
459 
460  // Update the name in the list control
461  wxListItem item;
462  GetColumn(static_cast<int>(i), item);
463  item.SetText(ToWxString(col_name));
464  SetColumn(static_cast<int>(i), item);
465  }
466 }
467 
469 {
470  for (size_t i=1; i<GetColumnCount(); ++i) {
471  wxListItem item;
472  GetColumn(static_cast<int>(i), item);
473 
474  // Get number of characters that can fit in the column
475  // This is based on number of pixels and then we subtract 2
476  // charactes for padding.
477  int col_char_width = static_cast<int>(item.GetWidth()/m_FontWidth);
478 
479  // Don't let col_char_width go below 0.
480  col_char_width -= std::min(col_char_width, 2);
481 
482  /// Should have same number if this is called, but double check:
483  if (i < m_ImportedTableData->GetColumns().size())
484  m_ImportedTableData->GetColumns()[i].SetWidth(col_char_width);
485  }
486 }
487 
489 {
490  int width = 0;
491 
492  for (int i=1; i<GetColumnCount(); ++i) {
493  wxListItem item;
494  GetColumn(i, item);
495 
496  // Get number of characters that can fit in the column
497  // This is based on number of pixels and then we subtract 2
498  // charactes for padding.
499  size_t col_char_width = (size_t)(item.GetWidth()/m_FontWidth);
500 
501  col_char_width -= std::min(col_char_width, (size_t)2);
502  width += col_char_width;
503  }
504 
505  return width;
506 }
507 
509 {
510  m_ColumnWidths.clear();
511 
512  for (size_t i=0; i<(size_t)GetColumnCount(); ++i) {
513  wxListItem item;
514  GetColumn(static_cast<int>(i), item);
515  m_ColumnWidths.push_back(item.GetWidth());
516 
517  // Get number of characters that can fit in the column
518  // This is based on number of pixels and then we subtract 2
519  // characters for padding.
520  int col_char_width = static_cast<int>(item.GetWidth()/m_FontWidth);
521  // Don't let col_char_width go below 0.
522  col_char_width -= std::min(col_char_width, 2);
523 
524  // Update column character width in data source (keep the pixel widths
525  // in the control synchronized with the character field widths in
526  // the table data source)
527  m_ImportedTableData->GetColumns()[i].SetWidth(col_char_width);
528 
529  //int char_width = m_ImportedTableData->GetColumn(i).GetWidth();
530  //_TRACE("Column: " << i << " width: (char, pix): (" << char_width << ", " << item.GetWidth() << ")");
531  }
532 }
533 
535 {
536  for (size_t i=0; i<(size_t)GetColumnCount(); ++i) {
537  wxListItem item;
538  GetColumn(static_cast<int>(i), item);
539 
540  int img_idx = GetColumnImageID(static_cast<int>(i), checkbox_only);
541 
542  // Set the image to indicate column status
543  item.SetImage(img_idx);
544  int width = (m_ImportedTableData->GetColumns()[i].GetWidth()+3) * m_FontWidth;
545  item.SetWidth(width + 24); // wide enough to also show the image
546  item.SetText(m_ImportedTableData->GetColumns()[i].GetName());
547  SetColumn(static_cast<int>(i), item);
548  }
549 }
550 
551 
553 {
554  string widths;
555 
556  for (size_t i=0; i<(size_t)GetColumnCount(); ++i) {
557  wxListItem item;
558  GetColumn(static_cast<int>(i), item);
559  widths += NStr::IntToString(item.GetWidth()) + ", ";
560  }
561 
562  _TRACE(prefix << " Column Widths: (" << widths << ")");
563 }
564 
565 
567 {
568  if (m_ColumnWidths.size() != (size_t)GetColumnCount())
570 
571  return m_ColumnWidths;
572 }
573 
575 {
576  vector<int> current_widths;
577 
578  for (size_t i=0; i<(size_t)GetColumnCount(); ++i) {
579  wxListItem item;
580  GetColumn(static_cast<int>(i), item);
581  current_widths.push_back(item.GetWidth());
582 
583  // Get number of characters that can fit in the column
584  // This is based on number of pixels and then we subtract 2
585  // charactes for padding.
586  int col_char_width = static_cast<int>(item.GetWidth()/m_FontWidth);
587  // Don't let col_char_width go below 0.
588  col_char_width -= std::min(col_char_width, 2);
589 
590  // Update column character width in data source (keep the pixel widths
591  // in the control synchronized with the character field widths in
592  // the table data source)
593  m_ImportedTableData->GetColumns()[i].SetWidth(col_char_width);
594  }
595 
596  return !(current_widths == m_ColumnWidths);
597 }
598 
600 {
601  if (col >= GetColumnCount())
602  return;
603 
604  m_IgnoreWidthEvent = true;
605  SetColumnWidth(col, width);
606  m_IgnoreWidthEvent = false;
607 }
608 
610 {
611  // On windows, replace all tabs with 4 spaces to fake the tabs.
612  // On other platforms wxListCtrl shows tabs so there is no need
613  // to do this.
614 #ifdef __WXMSW__
615  wxString tabstr(" ", 1);
616  wxString result;
617  for (size_t i=0; i<str.size(); ++i) {
618  if (str[i] != '\t') {
619  result.append(wxUniChar(str[i]));
620  }
621  else result.append(tabstr);
622  }
623 
624  return result;
625 #else
626  return ToWxString(str);
627 #endif
628 }
629 
630 
631 wxString CTableImportListCtrl::OnGetItemText( long row, long col ) const
632 {
633  if (m_ImportedTableData.IsNull()) {
634  return wxT("");
635  }
636  else {
637  // In 'eSingleColum' view mode we show all rows, but in eMultiColumn
638  // we ignore header rows and comment rows in the dataset. This requires
639  // that we compute the correct row number in the dataset that corresponds
640  // to 'row' in the list box (the dataset row will be same or larger).
641  auto adjusted_row_num = row;
642  if (m_ViewType != eSingleColumn) {
643  adjusted_row_num = row + m_ImportedTableData->GetFirstImportRow();
644  for (; adjusted_row_num < (int)m_ImportedTableData->GetNumRows() &&
645  m_ImportedTableData->GetRow(adjusted_row_num).GetRowNum() < row;
646  ++adjusted_row_num) {}
647 
649  --adjusted_row_num;
650  }
651 
652  // We display a row number (starting at first non-header row)
653  int row_num = -1;
654  if (adjusted_row_num >= 0)
655  row_num = m_ImportedTableData->GetRow(adjusted_row_num).GetRowNum();
656 
657  if (col == 0) {
658  if (row_num == -1) {
659  return wxT("-");
660  }
661  else {
662  wxString s;
663  // 1-based on output
664  s << row_num + 1;
665  return s;
666  }
667  }
668  if (m_ViewType == eSingleColumn) {
670  }
671  else {
672 
675 
676  // Get field values
677  if (!m_DisplayTypeHeader || row > 0) {
678  string field = m_ImportedTableData->GetField(adjusted_row_num, col-1);
679  return x_ToWxStringWithTabs(field);
680  }
681  // Display type information for columns instead of field
682  // value for row 0 (and blank if column is to be skipped)
683  else {
684  if (m_ImportedTableData->GetColumn(col).GetType() ==
686  return "";
687  }
688  else {
689  return m_ImportedTableData->GetColumn(col).
690  GetShortDataTypeString();
691  }
692  }
693  }
694  else {
695  // Ignore parsing for columns (just fit them in from left to right)
696  string str = m_ImportedTableData->GetRow(adjusted_row_num).GetValue();
697 
698  size_t col_start_char = 0;
699  for (int i=1; i<GetColumnCount() && col_start_char<str.length(); ++i) {
700  wxListItem item;
701  GetColumn(i, item);
702 
703  // Get number of characters that can fit in the column
704  // This is based on number of pixels and then we subtract 2
705  // charactes for padding.
706  size_t col_char_width = (size_t)(item.GetWidth()/m_FontWidth);
707 
708  // Don't let col_char_width go below 0.
709  col_char_width -= std::min(col_char_width, (size_t)2);
710 
711  if (i == col) {
712  if (i == GetColumnCount() - 1) {
713  string substr = str.substr(col_start_char,
714  str.size()-col_start_char);
715  return x_ToWxStringWithTabs(substr);
716  }
717  else {
718  string substr = str.substr(col_start_char,
719  std::min(col_char_width, str.size()-col_start_char));
720  return x_ToWxStringWithTabs(substr);
721  }
722  }
723 
724  col_start_char += col_char_width;
725  }
726  return wxT("");
727  }
728  }
729  }
730 }
731 
732 wxListItemAttr* CTableImportListCtrl::OnGetItemAttr(long item) const
733 {
734 
735  if (!m_DisplayTypeHeader || item != 0)
736  return NULL;
737  else
738  return (wxListItemAttr*)&m_FirstRowAttr;
739 }
740 
741 
743 
CRef –.
Definition: ncbiobj.hpp:618
CTableImportColumn -.
eColumnType GetType() const
void SetName(const string &n)
CTableImportDataSource -.
const CTableImportRow & GetRow(size_t row) const
Return a specific row.
vector< CTableImportColumn > & GetColumns()
return the array of column data
EFieldSeparatorType GetTableType() const
const CTableImportColumn & GetColumn(size_t col) const
Return the specified column.
string GetField(size_t row, size_t col) const
return a specific field from a specific row, based on current table type and delimiter
size_t GetNumRows() const
return total number of rows read
int GetColumnWidth(size_t col) const
Get width of specified column.
void RecomputeHeaders()
Update columns to genereated names or names parsed from row m_ColumnHeaderRow.
CRef< CTableImportDataSource > m_ImportedTableData
Data table to be rendered in the list.
void WriteWidths(const string &prefix)
bool m_FixedWidthUseFields
If fixed-length columns are not being actively adjusted, this is set to true so that they can be disp...
void SetColumnWidthIgnoreEvent(int col, int width)
Calls SetColumnWidth after setting m_IgnoreWidthEvent.
void DivideColumn(int col)
Creates a new column by dividing the specified column.
void SynchDataSourceColumnWidths()
Synch widths of datasource to updated colums.
wxImageList m_ImageList
Holds column icons (shows whether column currently selected or not)
bool m_IgnoreWidthEvent
If true, this flag can be used in column-resize event handlers to ignore resize events being generate...
int GetColumnImageID(int col, bool checkbox_only=false) const
Returns image ID for column headers.
int m_FontWidth
Need font width for calculating how many chars fit in a column.
vector< int > GetColumnWidths()
Get the most-recently set column widths (ignores first col)
bool m_DisplayTypeHeader
If true, type information will be displayed in first row.
eDataViewType m_ViewType
Do we show all columns seaprated or show as one field.
static wxString x_ToWxStringWithTabs(const string &str)
Convert strings with tab characters to wxStrings with 4 spaces for each tab.
vector< int > m_ColumnWidths
Widths of columns as updated by UpdateColumnWidths()
void UpdateColumnNames()
Update numbered column names to match current number of columns and sync column names to names in dat...
bool ColumnWidthsUpdated()
Returns true if current column widths do not match m_ColumnWidths.
void MergeColumns(int col)
Removes a column by merging the specified column with the column to its right (or does nothing if it ...
void UpdateColumnImages(bool checkbox_only=false)
Update images on column headers.
int GetColumnsCombinedCharWidth()
Add up the number of characters all the columns together can hold (ignores first column)
wxString OnGetItemText(long row, long col) const
Get the requested field (or full row if m_ViewType == eSingleColumn)
wxListItemAttr m_FirstRowAttr
First row holds type info.
wxListItemAttr * OnGetItemAttr(long item) const
Get attribute override for a specified row (allows special appearance for first row)
void UpdateColumnWidths()
Update m_ColumnWidths for use when resizing columns (ignores first col)
const string & GetValue() const
Get the entire row.
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
#define _TRACE(message)
Definition: ncbidbg.hpp:122
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define TRUE
bool replacment for C indicating true.
Definition: ncbi_std.h:97
T max(T x_, T y_)
T log10(T x_)
T min(T x_, T y_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static const char * prefix[]
Definition: pcregrep.c:405
#define row(bind, expected)
Definition: string_bind.c:73
static const long kDefStyle
else result
Definition: token2.c:20
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Mon May 20 05:05:16 2024 by modify_doxy.py rev. 669887