NCBI C++ ToolKit
grid_widget.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_GRID_WIDGET___GRID_WIDGET__HPP
2 #define GUI_WIDGETS_GRID_WIDGET___GRID_WIDGET__HPP
3 
4 /* $Id: grid_widget.hpp 45881 2021-01-05 03:10:02Z rudnev $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Roman Katargin
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/gui_export.h>
37 
38 #include <wx/panel.h>
39 #include <wx/timer.h>
40 #include <wx/statline.h>
41 
44 
50 
52 
53 class wxGridEvent;
54 class wxGridRangeSelectEvent;
55 class wxHyperlinkEvent;
56 class wxBoxSizer;
57 
59 
60 class CGrid;
62 class CQueryParsePanel;
63 struct SCSVExportParams;
64 class ICommandProccessor;
65 class CGridWidget;
66 class CMacroQueryExec;
67 
68 // event handler interface for events desired to be handled in a custom way
69 // originally designed for handling custom menu commands
70 class IGridEvtExt : public wxEvtHandler
71 {
72 protected:
73  friend class CGridWidget;
74  void x_SetGridWidget(CGridWidget* pGridWidget) { m_pGridWidget = pGridWidget; }
76 
77 private:
79 };
80 
81 
83  : public wxPanel, public CEventHandler, public IRegSettings, public IQueryWidget
84 {
85 public:
86  CGridWidget();
87  CGridWidget(wxWindow* parent, wxWindowID id = wxID_ANY,
88  const wxPoint& pos = wxDefaultPosition,
89  const wxSize& size = wxDefaultSize,
90  long style = wxBORDER_NONE);
91  ~CGridWidget();
92 
93  bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
94  const wxPoint& pos = wxDefaultPosition,
95  const wxSize& size = wxDefaultSize,
96  long style = wxBORDER_NONE);
97 
98  /// Creates the controls and sizers
99  void CreateControls();
100 
101  void Init(ITableData& table_data, ICommandProccessor* cmdProccessor);
102 
103  void SetTableSelection(ITableSelection* tableSelection) { m_TableSelection.Reset(tableSelection); }
104 
105  void UseFixedFont();
106  void ShowGridLines(bool show) { m_isShowGridLines = show; }
107 
108  void SetUseCursorSelection(bool useCursorSelection) { m_UseCursorSelection = useCursorSelection; }
109 
110  // returns first selected row
111  size_t SetSelection(CSelectionEvent& evt);
112 
113  /// Get all selected objects
114  void GetSelection(CSelectionEvent& evt) const;
115  void GetSelectedObjects (TConstScopedObjects& objects) const;
116  void GetSelectedRows(set<int> &rows) const;
117 
118  /// Get objects in a priority order (favor row selections)
119  void GetSelectedObjectsOrdered (TConstScopedObjects& objects);
120 
121  void OnGridCellRightClick(wxGridEvent& evt);
122  void OnGridCellLeftDClick(wxGridEvent& evt);
123  void OnGridLabelLeftDClick(wxGridEvent& evt);
124  void OnGridSelectCell(wxGridEvent& evt);
125  void OnGridRangeSelect(wxGridRangeSelectEvent& evt);
126  void OnExportToCSV(wxCommandEvent& event);
127  void OnSearchIncludeCellValue(wxCommandEvent& event);
128  void OnSearchExcludeCellValue(wxCommandEvent& event);
129  void OnTimer(wxTimerEvent& event);
130  void OnHyperlinkHover(wxHyperlinkEvent& event);
131  void OnCopy(wxCommandEvent& event);
132  void OnUpdateCopy(wxUpdateUIEvent& event);
133  void OnRefreshClick(wxCommandEvent& event);
134 
135  /// @name IRegSettings interface implementation
136  /// @{
137  virtual void SetRegistryPath(const string& reg_path);
138  virtual void LoadSettings();
139  virtual void SaveSettings() const;
140  /// @}
141 
142  /// @name IQueryWidget interface implementation
143  /// @{
144  virtual string GetSearchHelpAddr() const
145  { return string(""); }
146 
147  /// Disable any widgets that the user should not use during the query
148  virtual void QueryStart();
149  /// Re-enable any widgets disabled during the query.
150  virtual void QueryEnd(CMacroQueryExec* exec);
151 
152  /// Advance to previous/next selected row from query (in current sort order)
153  void IterateSelection(int dir);
154  /// Set to true to show all rows selected by most recent query as selected
155  virtual void SetSelectAll(bool b);
156 
157  /// If true, only rows that were selected by prevous query will be shown
158  virtual void SetHideUnselected(bool b);
159  /// @}
160 
161  void ShowRefreshButton(bool show) { m_isShowRefreshButton = show; }
162  /// Hide the Select All checkbox from the user
163  void HideSelectAll(void) { m_ShowSelectAll = false; }
164  void SetEventExt(IGridEvtExt* evtExt);
165 
166  void ScrollToRow(int row_idx) { x_ScrollToRow(row_idx); }
167 
168  CGrid* GetGrid() { return m_Grid; }
169 
170 protected:
171  DECLARE_EVENT_TABLE()
172 
173  void x_InitGrid(ICommandProccessor* cmdProccessor);
174  void x_GetSelectedRows(set<int>& rows) const;
175  void x_CompleteQuery();
176  void x_ScrollToRow(int row_idx);
177  void x_UpdateRowsToSelection(bool b);
178  void x_LeftClick(int Row, int modifiers);
179  void x_LeftDClick(int Row);
180 
181  bool x_GetRectSelection(vector<int>& rows, vector<int>&cols);
182 
183  /// the grid widget
184  CGrid* m_Grid;
185  /// interface to the table data (unsorted)
186  CIRef<ITableData> m_TableData;
187  /// adapter that matches the grid cells to sorted entries from m_TableData
188  CwxGridTableAdapter* m_GridAdapter;
189  /// post-cell select timer
190 
191  CIRef<ITableSelection> m_TableSelection;
192 
193  wxTimer m_Timer;
194 
195  /// toolbar that contains the query toolbar and additional buttons
196  /// added by AddControl() (Refresh)
197  wxBoxSizer* m_ToolbarSizer;
198 
199  /// controls assigned to the toolbar:
200  CQueryParsePanel* m_QueryPanel;
201  wxStaticLine* m_StaticLine;
202  wxButton* m_RefreshButton;
203 
204  string m_RegPath;
205  /// when true, rows selected from query panel are all shown as selected
206  bool m_SelectAll;
207  /// when true (by default) the Select All checkbox is shown
208  bool m_ShowSelectAll;
209 
210  /// Remember location of cell from popup (right click) so we can use that
211  /// location (potentially) in function called by popup
212  int m_PopupGridX;
213  int m_PopupGridY;
214 
216 
217  CIRef<IGridEvtExt> m_GridEvtExt;
218  bool m_isShowRefreshButton;
219  bool m_isShowGridLines;
220 
221 private:
222  enum {
223  //!! how do the numbers get assigned so they do not clash?
224  ID_REFRESH_BUTTON = 13027,
225  };
226 
228 };
229 
231 
232 #endif // GUI_WIDGETS_GRID_WIDGET___GRID_WIDGET__HPP
CEventHandler.
void ShowRefreshButton(bool show)
bool m_UseCursorSelection
virtual string GetSearchHelpAddr() const
Return web-address for the help page that disusses help for the specific widget.
void ScrollToRow(int row_idx)
void SetUseCursorSelection(bool useCursorSelection)
void HideSelectAll(void)
Hide the Select All checkbox from the user.
CGrid * GetGrid()
void ShowGridLines(bool show)
void SetTableSelection(ITableSelection *tableSelection)
CGrid.
Definition: grid.hpp:50
class CMacroQueryExec
CQueryParsePanel.
CRef –.
Definition: ncbiobj.hpp:618
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
class IQueryDataSource
Undo/Redo interface for editing operations.
void x_SetGridWidget(CGridWidget *pGridWidget)
Definition: grid_widget.hpp:74
CGridWidget * m_pGridWidget
Definition: grid_widget.hpp:78
CGridWidget * x_GetGridWidget()
Definition: grid_widget.hpp:75
IQueryWidget.
virtual void SetHideUnselected(bool)
set to true to hide/obscure elements not selected by most recent query
virtual void IterateSelection(int)
go to next(1), previous(-1) or first(0) element from most recent query
virtual void SetSelectAll(bool)
set to yes to show all queried elements as selected
virtual void QueryStart()
Disable any widgets and/or set cursor/scroll as needed when query starts.
virtual void QueryEnd(CMacroQueryExec *exec)
Re-enable widgets and/or set cursor/scroll as needed when query ends.
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
static void Init(void)
Definition: cursor6.c:76
string
Definition: cgiapp.hpp:687
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#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 NCBI_GUIWIDGETS_GRID_WIDGET_EXPORT
Definition: gui_export.h:533
Defines to provide correct exporting from DLLs in Windows.
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static static static wxID_ANY
#define const
Definition: zconf.h:232
Modified on Sun May 19 04:42:00 2024 by modify_doxy.py rev. 669887