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

Go to the SVN repository for this file.

1 /* $Id: table_cols_more_dlg.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 
32 ////@begin includes
33 #include "wx/imaglist.h"
34 ////@end includes
35 
37 
38 ////@begin XPM images
39 ////@end XPM images
40 
42 
43 /*!
44  * CMoreTableColsDlg type definition
45  */
46 
47 IMPLEMENT_DYNAMIC_CLASS( CMoreTableColsDlg, CDialog )
48 
49 
50 /*!
51  * CMoreTableColsDlg event table definition
52  */
53 
54 BEGIN_EVENT_TABLE( CMoreTableColsDlg, CDialog )
55 
56 ////@begin CMoreTableColsDlg event table entries
57  EVT_LIST_ITEM_SELECTED( ID_COLTABLE, CMoreTableColsDlg::OnColTableSelected )
58  EVT_LIST_ITEM_DESELECTED( ID_COLTABLE, CMoreTableColsDlg::OnColTableDeselected )
59  EVT_LIST_ITEM_FOCUSED( ID_COLTABLE, CMoreTableColsDlg::OnColTableRowFocused )
60  EVT_LIST_KEY_DOWN( ID_COLTABLE, CMoreTableColsDlg::OnColTableKeyDown )
61  EVT_LIST_COL_RIGHT_CLICK( ID_COLTABLE, CMoreTableColsDlg::OnColTableHeaderMenu )
62 
63  EVT_BUTTON( ID_SHOW, CMoreTableColsDlg::OnShowClick )
64 
65  EVT_BUTTON( ID_HIDE, CMoreTableColsDlg::OnSortingClick )
66 
67  EVT_BUTTON( ID_CLEAR_SORT, CMoreTableColsDlg::OnClearSortClick )
68 
69 ////@end CMoreTableColsDlg event table entries
70 
72 
73 
74 /*!
75  * CMoreTableColsDlg constructors
76  */
77 
79 {
80  Init();
81 }
82 
83 CMoreTableColsDlg::CMoreTableColsDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
84 {
85  Init();
86  Create(parent, id, caption, pos, size, style);
87 }
88 
89 
90 /*!
91  * CMoreTableColsDlg creator
92  */
93 
94 bool CMoreTableColsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
95 {
96  CwxTableListCtrl* parent_table = dynamic_cast<CwxTableListCtrl*>(parent);
97  _ASSERT(parent_table);
98 
99  SetTable( parent_table );
100  x_UpdateModel();
101 
102 ////@begin CMoreTableColsDlg creation
103  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
104  CDialog::Create( parent, id, caption, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CMoreTableColsDlg creation
113 
114  x_UpdateButtons();
115  return true;
116 }
117 
118 
119 /*!
120  * CMoreTableColsDlg destructor
121  */
122 
124 {
125 ////@begin CMoreTableColsDlg destruction
126 ////@end CMoreTableColsDlg destruction
127 
129 }
130 
131 
132 /*!
133  * Member initialisation
134  */
135 
137 {
138  static vector<wxString> s_ColNames;
139 
140  if( s_ColNames.empty() ){
141  s_ColNames.push_back( wxT("Column") );
142  s_ColNames.push_back( wxT("Sorting") );
143  s_ColNames.push_back( wxT("Sort order") );
144  }
145 
146 ////@begin CMoreTableColsDlg member initialisation
147  m_ColTable = NULL;
148  m_ShowBtn = NULL;
149  m_SortBtn = NULL;
150  m_ClearBtn = NULL;
151 ////@end CMoreTableColsDlg member initialisation
152 
153  m_Model.Init( s_ColNames, 0 );
154 }
155 
156 
157 /*!
158  * Control creation for CMoreTableColsDlg
159  */
160 
162 {
163 ////@begin CMoreTableColsDlg content construction
164  CMoreTableColsDlg* itemCDialog1 = this;
165 
166  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
167  itemCDialog1->SetSizer(itemBoxSizer2);
168 
169  m_ColTable = new CwxTableListCtrl( itemCDialog1, ID_COLTABLE, wxDefaultPosition, wxSize(250, 150), wxLC_REPORT|wxLC_VIRTUAL|wxLC_SINGLE_SEL );
170  itemBoxSizer2->Add(m_ColTable, 1, wxGROW|wxALL, 5);
171 
172  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
173  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);
174 
175  m_ShowBtn = new wxButton( itemCDialog1, ID_SHOW, _("&Show"), wxDefaultPosition, wxDefaultSize, 0 );
176  m_ShowBtn->SetHelpText(_("Make column visible"));
178  m_ShowBtn->SetToolTip(_("Make column visible"));
179  itemBoxSizer4->Add(m_ShowBtn, 0, wxGROW|wxALL, 5);
180 
181  m_SortBtn = new wxButton( itemCDialog1, ID_HIDE, _("&Sorting"), wxDefaultPosition, wxDefaultSize, 0 );
182  m_SortBtn->SetHelpText(_("Roll sorting state"));
184  m_SortBtn->SetToolTip(_("Roll sorting state"));
185  itemBoxSizer4->Add(m_SortBtn, 0, wxGROW|wxALL, 5);
186 
187  m_ClearBtn = new wxButton( itemCDialog1, ID_CLEAR_SORT, _("&Clear Sort"), wxDefaultPosition, wxDefaultSize, 0 );
188  m_ClearBtn->SetHelpText(_("Clear Sort State"));
190  m_ClearBtn->SetToolTip(_("Clear Sort State"));
191  itemBoxSizer4->Add(m_ClearBtn, 0, wxGROW|wxALL, 5);
192 
193  itemBoxSizer4->Add(4, 19, 1, wxGROW|wxALL, 5);
194 
195  wxButton* itemButton9 = new wxButton( itemCDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemButton9->SetDefault();
197  itemBoxSizer4->Add(itemButton9, 0, wxGROW|wxALL, 5);
198 
199  wxButton* itemButton10 = new wxButton( itemCDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
200  itemBoxSizer4->Add(itemButton10, 0, wxGROW|wxALL, 5);
201 
202 ////@end CMoreTableColsDlg content construction
203 
204  // Connect events and objects
205  //! It is out of DialogBlocks because of Table ID Linux issue [YV]
206  m_ColTable->Connect(
207  wxID_ANY, wxEVT_LEFT_DOWN,
208  wxMouseEventHandler( CMoreTableColsDlg::OnColTableLeftDown ),
209  NULL, this
210  );
211 
213 }
214 
216 {
217  _ASSERT(table);
218  if( !table ) return;
219 
220  m_BaseTable = table;
221 
222  int cols_num = m_BaseTable->GetColumnCount();
223  m_Model.SetNumRows( cols_num );
224  m_Shown.resize( cols_num, false );
225 
226  for( int ix = 0; ix < cols_num; ix++ ){
229  }
230 
232 }
233 
234 
236 {
237  for( int ix = 0; ix < m_Model.GetNumRows(); ix++ ){
238  m_Model.SetIcon(
239  ix,
240  m_Shown[ix] ? wxT("tlc_checked") : wxT("tlc_unchecked")
241  );
242 
243  m_Model.SetStringValueAt( ix, 1, wxString() );
244  m_Model.SetStringValueAt( ix, 2, wxString() );
245  }
246 
247  size_t sx = 0;
248  for( size_t jx = 0; jx < m_Sorted.size(); jx++ ){
249 
250  if( m_Sorted[jx].second == CwxTableListCtrl::eNoSort ){
251  continue;
252 
253  } else {
254  int ix = m_Sorted[jx].first;
255 
256  if( m_Sorted[jx].second == CwxTableListCtrl::eAscSort ){
257  m_Model.SetStringValueAt( ix, 1, wxT("Ascending") );
258  } else {
259  m_Model.SetStringValueAt( ix, 1, wxT("Descending") );
260  }
261 
262  m_Model.SetStringValueAt( ix, 2, wxString() << ++sx );
263  }
264  }
265 
267 }
268 
270 {
271  auto focus = m_ColTable->GetFocusRow();
272  if( focus >= 0 ){
273  if( m_Shown[focus] ){
274  m_ShowBtn->SetLabel( wxT("&Hide") );
275  } else {
276  m_ShowBtn->SetLabel( wxT("&Show") );
277  }
278  m_ShowBtn->Enable();
279 
280  } else {
281  m_ShowBtn->Disable();
282  }
283 
284  m_ClearBtn->Enable( !m_Sorted.empty() );
285 }
286 
287 /*!
288  * wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_COLTABLE
289  */
290 
291 void CMoreTableColsDlg::OnColTableSelected( wxListEvent& event )
292 {
293 ////@begin wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_COLTABLE in CMoreTableColsDlg.
294  // Before editing this code, remove the block markers.
295  event.Skip();
296 ////@end wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_COLTABLE in CMoreTableColsDlg.
297 }
298 
299 
300 /*!
301  * wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_COLTABLE
302  */
303 
304 void CMoreTableColsDlg::OnColTableDeselected( wxListEvent& event )
305 {
306 ////@begin wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_COLTABLE in CMoreTableColsDlg.
307  // Before editing this code, remove the block markers.
308  event.Skip();
309 ////@end wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_COLTABLE in CMoreTableColsDlg.
310 }
311 
312 /*!
313  * wxEVT_LEFT_DOWN event handler for ID_COLTABLE
314  */
315 
316 void CMoreTableColsDlg::OnColTableLeftDown( wxMouseEvent& event )
317 {
318  int flags;
319  long row = m_ColTable->HitTest( event.GetPosition(), flags );
320 
321  if( row >=0 && row < m_ColTable->GetItemCount() ){
322  if( flags & wxLIST_HITTEST_ONITEMICON ){
323  m_Shown[row] = !m_Shown[row];
324 
325  if( !m_Shown[row] ){
326  for( size_t ix = 0; ix < m_Sorted.size(); ix++ ){
327  if( m_Sorted[ix].first == row ){
328  m_Sorted[ix].second = CwxTableListCtrl::eNoSort;
329  m_Sorted.erase( m_Sorted.begin() + ix );
330 
331  break;
332  }
333  }
334  }
335 
336  } else if( flags & wxLIST_HITTEST_ONITEMLABEL ){
337  bool found = false;
338  for( size_t ix = 0; ix < m_Sorted.size(); ix++ ){
339  if( m_Sorted[ix].first == row ){
340  found = true;
341 
342  switch( m_Sorted[ix].second ){
345  break;
346 
348  m_Sorted[ix].second = CwxTableListCtrl::eNoSort;
349  m_Sorted.erase( m_Sorted.begin() + ix );
350  break;
351 
353  m_Shown[row] = true;
355  break;
356  }
357 
358  break;
359  }
360  }
361 
362  if( !found ){
363  m_Shown[row] = true;
365  }
366  }
367 
368 # ifdef _WX_GENERIC_LISTCTRL_H_
369  m_ColTable->Select( row );
370 # endif
371  x_UpdateModel();
372  x_UpdateButtons();
373  }
374 
375  event.Skip();
376 }
377 
378 /*!
379  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SHOW
380  */
381 
382 void CMoreTableColsDlg::OnShowClick( wxCommandEvent& event )
383 {
384  auto focus = m_ColTable->GetFocusRow();
385  if( focus >= 0 ){
386  m_Shown[focus] = !m_Shown[focus];
387 
388  if( !m_Shown[focus] ){
389  for( size_t ix = 0; ix < m_Sorted.size(); ix++ ){
390  if( m_Sorted[ix].first == focus ){
391  m_Sorted[ix].second = CwxTableListCtrl::eNoSort;
392  m_Sorted.erase( m_Sorted.begin() + ix );
393 
394  break;
395  }
396  }
397  }
398 
399  x_UpdateModel();
400  x_UpdateButtons();
401  }
402 }
403 
404 /*!
405  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_HIDE
406  */
407 
408 void CMoreTableColsDlg::OnSortingClick( wxCommandEvent& event )
409 {
410  auto focus = m_ColTable->GetFocusRow();
411  if( focus >= 0 ){
412  bool found = false;
413  for( size_t ix = 0; ix < m_Sorted.size(); ix++ ){
414  if( m_Sorted[ix].first == focus ){
415  found = true;
416 
417  switch( m_Sorted[ix].second ){
420  break;
421 
423  m_Sorted[ix].second = CwxTableListCtrl::eNoSort;
424  m_Sorted.erase( m_Sorted.begin() + ix );
425  break;
426 
428  m_Shown[focus] = true;
430  break;
431  }
432 
433  break;
434  }
435  }
436 
437  if( !found ){
439  }
440 
441  x_UpdateModel();
442  x_UpdateButtons();
443  }
444 }
445 
446 /*!
447  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_SORT
448  */
449 
450 void CMoreTableColsDlg::OnClearSortClick( wxCommandEvent& event )
451 {
452  m_Sorted.clear();
453 
454  x_UpdateModel();
455  x_UpdateButtons();
456 }
457 
458 /*!
459  * wxEVT_COMMAND_LIST_ITEM_FOCUSED event handler for ID_COLTABLE
460  */
461 
462 void CMoreTableColsDlg::OnColTableRowFocused( wxListEvent& event )
463 {
464  x_UpdateButtons();
465 }
466 
467 /*!
468  * wxEVT_COMMAND_LIST_KEY_DOWN event handler for ID_COLTABLE
469  */
470 
471 void CMoreTableColsDlg::OnColTableKeyDown( wxListEvent& event )
472 {
473  if( event.GetKeyCode() == WXK_SPACE ){
474  wxCommandEvent evt;
475  OnShowClick( evt );
476  }
477 }
478 
479 /*!
480  * wxEVT_COMMAND_LIST_COL_RIGHT_CLICK event handler for ID_COLTABLE
481  */
482 
483 void CMoreTableColsDlg::OnColTableHeaderMenu( wxListEvent& event )
484 {
485  //! Suppress header menu in this dialog
486 }
487 
488 void CMoreTableColsDlg::EndModal( int retCode )
489 {
490  if( retCode == wxID_OK ){
491  for( size_t ix = 0; ix < m_Shown.size(); ix++ ){
492  if( m_Shown[ix] ){
493  m_BaseTable->ShowColumn( (int)ix );
494  } else {
495  m_BaseTable->HideColumn( (int)ix );
496  }
497  }
498 
501 
502  for( size_t ix = 0; ix < m_Sorted.size(); ix++ ){
504  m_Sorted[ix].first, m_Sorted[ix].second
505  );
506  }
508 
509  m_BaseTable->ApplySorting( false );
510 
511  m_BaseTable->Refresh();
512  }
513 
514  CDialog::EndModal( retCode );
515 }
516 
517 /*!
518  * Should we show tooltips?
519  */
520 
522 {
523  return true;
524 }
525 
526 /*!
527  * Get bitmap resources
528  */
529 
530 wxBitmap CMoreTableColsDlg::GetBitmapResource( const wxString& name )
531 {
532  // Bitmap retrieval
533 ////@begin CMoreTableColsDlg bitmap retrieval
534  wxUnusedVar(name);
535  return wxNullBitmap;
536 ////@end CMoreTableColsDlg bitmap retrieval
537 }
538 
539 /*!
540  * Get icon resources
541  */
542 
543 wxIcon CMoreTableColsDlg::GetIconResource( const wxString& name )
544 {
545  // Icon retrieval
546 ////@begin CMoreTableColsDlg icon retrieval
547  wxUnusedVar(name);
548  return wxNullIcon;
549 ////@end CMoreTableColsDlg icon retrieval
550 }
551 
553 
554 
CDialog.
Definition: dialog.hpp:47
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
void CreateControls()
Creates the controls and sizers.
vector< CwxTableListCtrl::TSortedCol > m_Sorted
void OnSortingClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_HIDE
void EndModal(int retCode)
void SetTable(CwxTableListCtrl *table)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnColTableRowFocused(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_FOCUSED event handler for ID_COLTABLE
CMoreTableColsDlg()
Constructors.
void OnShowClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SHOW
CwxTableListCtrl * m_ColTable
void OnColTableSelected(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_COLTABLE
static bool ShowToolTips()
Should we show tooltips?
bool Create(wxWindow *parent, wxWindowID id=ID_MORECOLDLG, const wxString &caption=_("More on Table Columns"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(399, 299), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
void OnColTableLeftDown(wxMouseEvent &event)
wxEVT_LEFT_DOWN event handler for ID_COLTABLE It is out of DialogBlocks because of Table ID Linux iss...
void OnColTableHeaderMenu(wxListEvent &event)
wxEVT_COMMAND_LIST_COL_RIGHT_CLICK event handler for ID_COLTABLE
CwxTableListCtrl * m_BaseTable
~CMoreTableColsDlg()
Destructor.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void Init()
Initialises member variables.
void OnColTableDeselected(wxListEvent &event)
wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_COLTABLE
void OnClearSortClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_SORT
void OnColTableKeyDown(wxListEvent &event)
wxEVT_COMMAND_LIST_KEY_DOWN event handler for ID_COLTABLE
virtual void Init(int n_cols, int n_rows)
void SetNumRows(int n_rows)
virtual void SetIcon(int row, const wxString &icon_alias)
virtual void SetStringValueAt(int row, int col, const wxString &value)
virtual void FireRowsUpdated(int first_row, int last_row=-1)
virtual int GetNumRows() const
Returns the number of rows in the model.
CwxTableListCtrl - generic wxListCtrl-based Table Control.
void ApplySorting(bool preserve_state=true)
const vector< TSortedCol > & GetSortedCols() const
void ShowColumn(int col_ix)
int GetFocusRow() const
void SetSortedState(ESortedState sorted)
void AddSorterIndex(size_t col, ESortedState state)
wxString GetColumnNameByIndex(int col) const
bool IsColumnVisibleByIndex(int col) const
pair< int, ESortedState > TSortedCol
void SetModel(IwxTableModel *data_model, bool own=false)
void HideColumn(int col_ix)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static uch flags
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
static const string s_ColNames[CTableDataAlnSummary::eMaxColNum]
#define _ASSERT
Modified on Sun May 19 04:46:21 2024 by modify_doxy.py rev. 669887