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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_WX___WXGRID_TABLE_ADAPTER_HPP
2 #define GUI_WIDGETS_WX___WXGRID_TABLE_ADAPTER_HPP
3 
4 /* $Id: wxgrid_table_adapter.hpp 27372 2013-02-04 18:45:24Z katargir $
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/ncbistd.hpp>
36 
37 #include <gui/gui_export.h>
38 
39 #include <wx/grid.h>
40 
44 
46 
47 class ICommandProccessor;
48 
49 ///////////////////////////////////////////////////////////////////////////////
50 /// CGridTableQuery
51 
53  : public wxGridTableBase, public IGridTableAdapter, public IRegSettings
54 {
55 public:
56  CwxGridTableAdapter(ITableData& tableData, ICommandProccessor* cmdProccessor);
58 
59  class CEventHandler : public wxEvtHandler
60  {
61  DECLARE_EVENT_TABLE()
62  public:
63  CEventHandler(CwxGridTableAdapter& adapter) : m_Adapter(adapter) {}
64  private:
65  void OnAssignColumnValue(wxCommandEvent& event);
66  void OnUpdateAssignColumnValue(wxUpdateUIEvent& event);
67 
68  void OnCopyColumn(wxCommandEvent& event);
69  void OnUpdateCopyColumn(wxUpdateUIEvent& event);
70 
72  };
73 
74  /// @name wxGridTableBase interface implementation
75  /// @{
76  virtual int GetNumberRows();
77  virtual int GetNumberCols();
78 
79  virtual wxString GetColLabelValue(int col);
80  virtual wxString GetRowLabelValue(int row);
81  virtual wxString GetValue(int row, int col);
82 
83  virtual void SetValue(int row, int col, const wxString& value);
84  virtual bool IsEmptyCell(int , int) { return false; }
85 
86  virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
87  virtual long GetValueAsLong( int row, int col );
88  virtual double GetValueAsDouble( int row, int col );
89 
90  virtual void SetValueAsLong( int row, int col, long value );
91  virtual void SetValueAsDouble( int row, int col, double value );
92  virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
93 
94  wxString GetHtmlValue(int row, int col);
95 
96 
97  /*
98  virtual wxGridCellAttr* GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind );
99  */
100 
101  virtual void SetView( wxGrid *grid );
102  /// @}
103 
104  /// @name IGridTableAdapter interface implementation
105  /// @{
106  virtual void ShowColumn(size_t col, bool show);
107  virtual bool IsColumnShown(size_t col) const;
108 
109  virtual size_t GetOriginalRow(size_t queryRow) const;
110  virtual size_t GetCurrentRow(size_t queryRow) const;
111 
112  virtual void SortByColumn(TSortColumn sortColumn);
113  virtual TSortColumn GetSortColumn() const { return m_SortColumn; }
114 
115  virtual void SetSelection(const vector<size_t>& query_sel);
116  virtual void IterateSelection(int dir);
117  /// @}
118 
119  /// @name IRegSettings interface implementation
120  /// @{
121  virtual void SetRegistryPath(const string& reg_path) { m_RegPath = reg_path; }
122  virtual void LoadSettings();
123  virtual void SaveSettings() const;
124  /// @}
125 
126  string GetRegPath() const;
127 
128  wxMenu* CreateMenu();
129 
130 protected:
131 
132  /// maps from row position in display to table (ITableData) index
133  vector<size_t> m_RowToTable;
134  /// maps from ITableData index to row position in display
135  vector<size_t> m_TableToRow;
136 
137  /// maps from index in m_Selected to table (ITableData) index
138  vector<size_t> m_SelectedRowToTable;
139  /// maps from ITableData index to index in m_Selected array
140  vector<size_t> m_SelectedTableToRow;
141 
143 
144  bool x_ValidateColumns(const vector<size_t>& colums) const;
145  void x_UpdateSelectedIndices();
146  void x_ResetRows();
147  void x_UpdateRenderers();
148 
149  void x_SaveColumnWidth(const string& label, int width);
150  int x_LoadColumnWidth(const string& label);
151 
152 protected:
153  wxGridCellAttr* x_GetDefaultRendererAttr(bool allowEdit);
154  wxGridCellAttr* x_GetIntRendererAttr(bool allowEdit);
155  wxGridCellAttr* x_GetFloatRendererAttr(bool allowEdit);
156  wxGridCellAttr* x_GetHtmlCellAttrL();
157  wxGridCellAttr* x_GetHtmlCellAttrR();
158 
159  bool x_CoordsToTableData(int& row, int& col);
160  bool x_ColToTableData(int& col);
161  bool x_RowToTableData(int& row);
162 
163  wxGridCellAttr* m_DefaultCellAttr;
164  wxGridCellAttr* m_IntCellAttr;
165  wxGridCellAttr* m_FloatCellAttr;
166 
167  wxGridCellAttr* m_HtmlCellAttrL;
168  wxGridCellAttr* m_HtmlCellAttrR;
169 
170  wxGridCellAttr* m_TextCellAttrEdit;
171  wxGridCellAttr* m_IntCellAttrEdit;
172  wxGridCellAttr* m_FloatCellAttrEdit;
173 
174  string m_RegPath;
175 
177 
179 };
180 
182 
183 #endif // GUI_WIDGETS_WX___WXGRID_TABLE_ADAPTER_HPP
184 
CEventHandler(CwxGridTableAdapter &adapter)
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 * m_HtmlCellAttrR
wxGridCellAttr * m_TextCellAttrEdit
wxGridCellAttr * m_FloatCellAttr
ICommandProccessor * m_CmdProccessor
virtual bool IsEmptyCell(int, int)
wxGridCellAttr * m_IntCellAttr
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 * m_FloatCellAttrEdit
virtual TSortColumn GetSortColumn() const
wxGridCellAttr * m_DefaultCellAttr
virtual void SetRegistryPath(const string &reg_path)
wxGridCellAttr * m_IntCellAttrEdit
Undo/Redo interface for editing operations.
virtual size_t GetOriginalRow(size_t queryRow) const =0
virtual void IterateSelection(int)
virtual bool IsColumnShown(size_t col) const =0
virtual size_t GetCurrentRow(size_t queryRow) const =0
virtual void ShowColumn(size_t col, bool show)=0
virtual void SortByColumn(TSortColumn sortColumn)=0
pair< size_t, ESort > TSortColumn
virtual void SetSelection(const vector< size_t > &query_sel)
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
Include a standard set of the NCBI C++ Toolkit most basic headers.
#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
static const char label[]
Defines to provide correct exporting from DLLs in Windows.
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define row(bind, expected)
Definition: string_bind.c:73
wxMenu * CreateMenu(const CMenuItem *item)
Creates a wxMenu object replicating the structure of CMenuItem.
Definition: wx_utils.cpp:365
Modified on Wed Sep 04 15:01:56 2024 by modify_doxy.py rev. 669887