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

Go to the SVN repository for this file.

1 /* $Id: copy_column_dlg.cpp 39666 2017-10-25 16:01:13Z katargir $
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:
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
35 #include "copy_column_dlg.hpp"
39 
40 #include <wx/sizer.h>
41 #include <wx/stattext.h>
42 #include <wx/combobox.h>
43 #include <wx/button.h>
44 #include <wx/radiobox.h>
45 
46 ////@begin XPM images
47 ////@end XPM images
48 
50 
51 /*!
52  * CCopyColumnDlg type definition
53  */
54 
55 IMPLEMENT_DYNAMIC_CLASS( CCopyColumnDlg, CDialog )
56 
57 
58 /*!
59  * CCopyColumnDlg event table definition
60  */
61 
62 BEGIN_EVENT_TABLE( CCopyColumnDlg, CDialog )
63 
64 ////@begin CCopyColumnDlg event table entries
65 ////@end CCopyColumnDlg event table entries
66 
68 
69 
70 /*!
71  * CCopyColumnDlg constructors
72  */
73 
75 : m_Table()
76 {
77  Init();
78 }
79 
81 : m_Table(&table)
82 {
83  Init();
84  Create(parent,
90 }
91 
92 
93 /*!
94  * CCopyColumnDlg creator
95  */
96 
97 bool CCopyColumnDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
98 {
99 ////@begin CCopyColumnDlg creation
100  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
101  CDialog::Create( parent, id, caption, pos, size, style );
102 
103  CreateControls();
104  if (GetSizer())
105  {
106  GetSizer()->SetSizeHints(this);
107  }
108  Centre();
109 ////@end CCopyColumnDlg creation
110  return true;
111 }
112 
113 
114 /*!
115  * CCopyColumnDlg destructor
116  */
117 
119 {
120 ////@begin CCopyColumnDlg destruction
121 ////@end CCopyColumnDlg destruction
122 }
123 
124 
125 /*!
126  * Member initialisation
127  */
128 
130 {
131  if (m_Table) {
132  m_RegPath = "Dialogs.CCopyColumnDlg." + m_Table->GetTableTypeId();
133  }
134 
135 ////@begin CCopyColumnDlg member initialisation
136  m_Op = 0;
137  m_ColumnFrom = -1;
138  m_ColumnTo = -1;
141 ////@end CCopyColumnDlg member initialisation
142 }
143 
144 
145 /*!
146  * Control creation for CCopyColumnDlg
147  */
148 
150 {
151 ////@begin CCopyColumnDlg content construction
152  CCopyColumnDlg* itemCDialog1 = this;
153 
154  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
155  itemCDialog1->SetSizer(itemBoxSizer2);
156 
157  wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
158  itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxGROW|wxALL, 5);
159 
160  wxStaticText* itemStaticText4 = new wxStaticText( itemCDialog1, wxID_STATIC, _("From Column:"), wxDefaultPosition, wxDefaultSize, 0 );
161  itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  wxArrayString m_ColumnFromCtrlStrings;
164  m_ColumnFromCtrl = new wxComboBox( itemCDialog1, ID_COMBOBOX2, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ColumnFromCtrlStrings, wxCB_READONLY );
165  itemFlexGridSizer3->Add(m_ColumnFromCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  wxStaticText* itemStaticText6 = new wxStaticText( itemCDialog1, wxID_STATIC, _("To Column:"), wxDefaultPosition, wxDefaultSize, 0 );
168  itemFlexGridSizer3->Add(itemStaticText6, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
169 
170  wxArrayString m_ColumnToCtrlStrings;
171  m_ColumnToCtrl = new wxComboBox( itemCDialog1, ID_COMBOBOX3, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ColumnToCtrlStrings, wxCB_READONLY );
172  itemFlexGridSizer3->Add(m_ColumnToCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  itemFlexGridSizer3->AddGrowableCol(1);
175 
176  wxArrayString itemRadioBox8Strings;
177  itemRadioBox8Strings.Add(_("&Copy"));
178  itemRadioBox8Strings.Add(_("&Append"));
179  itemRadioBox8Strings.Add(_("&Prepend"));
180  wxRadioBox* itemRadioBox8 = new wxRadioBox( itemCDialog1, ID_RADIOBOX, _("What to Do"), wxDefaultPosition, wxDefaultSize, itemRadioBox8Strings, 1, wxRA_SPECIFY_ROWS );
181  itemRadioBox8->SetSelection(0);
182  itemBoxSizer2->Add(itemRadioBox8, 0, wxALIGN_LEFT|wxALL, 5);
183 
184  itemBoxSizer2->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
185 
186  wxStdDialogButtonSizer* itemStdDialogButtonSizer10 = new wxStdDialogButtonSizer;
187 
188  itemBoxSizer2->Add(itemStdDialogButtonSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
189  wxButton* itemButton11 = new wxButton( itemCDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
190  itemStdDialogButtonSizer10->AddButton(itemButton11);
191 
192  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
193  itemStdDialogButtonSizer10->AddButton(itemButton12);
194 
195  itemStdDialogButtonSizer10->Realize();
196 
197  // Set validators
198  itemRadioBox8->SetValidator( wxGenericValidator(& m_Op) );
199 ////@end CCopyColumnDlg content construction
200 
201  if (m_Table) {
202  size_t cols = m_Table->GetColsCount();
203  for (size_t i = 0 ; i < cols; ++i) {
204  string label = m_Table->GetColumnLabel(i);
206  m_ColumnToCtrl->Append(wxString::FromUTF8(label.c_str()), (void*)i);
207  }
208  m_ColumnFromCtrl->Append(wxString::FromUTF8(label.c_str()), (void*)i);
209  }
210  if (m_ColumnToCtrl->GetCount() > 0) {
211  m_ColumnToCtrl->Select(0);
212  }
213  if (m_ColumnFromCtrl->GetCount() > 0) {
214  m_ColumnFromCtrl->Select(0);
215  }
216  }
217 }
218 
220 {
221  if (!CDialog::TransferDataFromWindow())
222  return false;
223 
224  int sel = m_ColumnFromCtrl->GetSelection();
225  if (sel != wxNOT_FOUND) {
226  m_ColumnFrom = (int)(intptr_t)m_ColumnFromCtrl->GetClientData(sel);
227  }
228  else
229  m_ColumnFrom = -1;
230 
231  sel = m_ColumnToCtrl->GetSelection();
232  if (sel != wxNOT_FOUND) {
233  m_ColumnTo = (int)(intptr_t)m_ColumnToCtrl->GetClientData(sel);
234  }
235  else
236  m_ColumnTo = -1;
237 
238  return true;
239 }
240 
242 {
243  size_t cols = table.GetColsCount();
244  for (size_t i = 0 ; i < cols; ++i) {
245  if (table.GetColumnType(i) == ITableData::kString && table.AllowEdit(i)) {
246  return true;
247  }
248  }
249  return false;
250 }
251 
253 {
254  if (m_ColumnFrom < 0 || m_ColumnTo < 0)
255  return 0;
256 
258  if (m_Op == 1)
260  else if (m_Op == 2)
262 
264 }
265 
266 
267 /*!
268  * Should we show tooltips?
269  */
270 
272 {
273  return true;
274 }
275 
276 /*!
277  * Get bitmap resources
278  */
279 
280 wxBitmap CCopyColumnDlg::GetBitmapResource( const wxString& name )
281 {
282  // Bitmap retrieval
283 ////@begin CCopyColumnDlg bitmap retrieval
284  wxUnusedVar(name);
285  return wxNullBitmap;
286 ////@end CCopyColumnDlg bitmap retrieval
287 }
288 
289 /*!
290  * Get icon resources
291  */
292 
293 wxIcon CCopyColumnDlg::GetIconResource( const wxString& name )
294 {
295  // Icon retrieval
296 ////@begin CCopyColumnDlg icon retrieval
297  wxUnusedVar(name);
298  return wxNullIcon;
299 ////@end CCopyColumnDlg icon retrieval
300 }
301 
302 static const char* kColumnFrom = "ColumnFrom";
303 static const char* kColumnTo = "ColumnTo";
304 static const char* kOp = "Op";
305 
306 
308 {
310 
311  if (m_Table && !m_RegPath.empty()) {
313 
315  m_ColumnToCtrl->SetValue(ToWxString(view.GetString(kColumnTo)));
316 
317  m_Op = view.GetInt(kOp, m_Op);
318  if (m_Op < 0 || m_Op > 2)
319  m_Op = 0;
320  }
321 }
322 
324 {
326 
327  if (m_Table && !m_RegPath.empty()) {
329  view.Set(kColumnFrom, ToStdString(m_ColumnFromCtrl->GetValue()));
330  view.Set(kColumnTo, ToStdString(m_ColumnToCtrl->GetValue()));
331  view.Set(kOp, m_Op);
332  }
333 }
334 
virtual bool TransferDataFromWindow()
virtual void LoadSettings()
static bool ShowToolTips()
Should we show tooltips?
virtual void SaveSettings() const
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
wxComboBox * m_ColumnToCtrl
ITableData * m_Table
~CCopyColumnDlg()
Destructor.
wxComboBox * m_ColumnFromCtrl
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
static bool CanCopyColumn(ITableData &table)
CCopyColumnDlg()
Constructors.
bool Create(wxWindow *parent, wxWindowID id=10006, const wxString &caption=_("Copy column"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
IEditCommand * GetEditCommand()
CDialog.
Definition: dialog.hpp:47
virtual void SaveSettings() const
Definition: dialog.cpp:67
virtual void LoadSettings()
Definition: dialog.cpp:112
string m_RegPath
Definition: dialog.hpp:70
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
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
Interface (functor) for object editing.
virtual string GetTableTypeId() const =0
virtual bool AllowEdit(size_t)
Definition: table_data.hpp:81
virtual string GetColumnLabel(size_t col) const =0
virtual ColumnType GetColumnType(size_t col) const =0
virtual size_t GetColsCount() const =0
static const char * kOp
static const char * kColumnTo
static const char * kColumnFrom
#define SYMBOL_CCOPYCOLUMNDLG_STYLE
#define SYMBOL_CCOPYCOLUMNDLG_TITLE
#define SYMBOL_CCOPYCOLUMNDLG_SIZE
#define SYMBOL_CCOPYCOLUMNDLG_POSITION
#define SYMBOL_CCOPYCOLUMNDLG_IDNAME
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
int intptr_t
Definition: ncbitype.h:185
#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 const char label[]
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_COMBOBOX3
#define ID_COMBOBOX2
#define ID_RADIOBOX
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Tue Jun 18 13:40:54 2024 by modify_doxy.py rev. 669887