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

Go to the SVN repository for this file.

1 /* $Id: folder_edit_dlg.cpp 34244 2015-12-03 16:46:55Z 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  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 ////@end includes
36 
39 
42 
45 #include <gui/objutils/label.hpp>
47 
48 #include <serial/iterator.hpp>
49 
50 #include <wx/textctrl.h>
51 #include <wx/stattext.h>
52 #include <wx/sizer.h>
53 #include <wx/button.h>
54 
55 
57 
58 IMPLEMENT_DYNAMIC_CLASS( CFolderEditDlg, CDialog )
59 
60 BEGIN_EVENT_TABLE( CFolderEditDlg, CDialog )
61 
62 ////@begin CFolderEditDlg event table entries
63  EVT_INIT_DIALOG( CFolderEditDlg::OnInitDialog )
64 
65  EVT_BUTTON( ID_RESTORE, CFolderEditDlg::OnRestoreBtn )
66 
67  EVT_BUTTON( wxID_OK, CFolderEditDlg::OnOkClick )
68 
69 ////@end CFolderEditDlg event table entries
70 
72 
74 {
75  Init();
76 }
77 
78 CFolderEditDlg::CFolderEditDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
79 {
80  Init();
81  Create(parent, id, caption, pos, size, style);
82 }
83 
84 bool CFolderEditDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
85 {
86 ////@begin CFolderEditDlg creation
87  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
88  CDialog::Create( parent, id, caption, pos, size, style );
89 
91  if (GetSizer())
92  {
93  GetSizer()->SetSizeHints(this);
94  }
95  Centre();
96 ////@end CFolderEditDlg creation
97  return true;
98 }
99 
100 
102 {
103 ////@begin CFolderEditDlg destruction
104 ////@end CFolderEditDlg destruction
105 }
106 
107 
109 {
110 ////@begin CFolderEditDlg member initialisation
111  m_NameCtrl = NULL;
112  m_RestoreBtn = NULL;
113  m_DescrCtrl = NULL;
114 ////@end CFolderEditDlg member initialisation
115  m_Object = NULL;
116  m_Scope = NULL;
118  m_ReadOnly = false;
119 }
120 
121 
123 {
124 ////@begin CFolderEditDlg content construction
125  CFolderEditDlg* itemCDialog1 = this;
126 
127  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
128  itemCDialog1->SetSizer(itemBoxSizer2);
129 
130  wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
131  itemBoxSizer2->Add(itemFlexGridSizer3, 1, wxGROW|wxALL, 5);
132 
133  wxStaticText* itemStaticText4 = new wxStaticText( itemCDialog1, wxID_STATIC, _("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
134  itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_LEFT|wxALIGN_TOP|wxALL, 5);
135 
136  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
137  itemFlexGridSizer3->Add(itemBoxSizer5, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5);
138 
139  m_NameCtrl = new wxTextCtrl( itemCDialog1, ID_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
140  itemBoxSizer5->Add(m_NameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
141 
142  m_RestoreBtn = new wxButton( itemCDialog1, ID_RESTORE, _("Restore from Data"), wxDefaultPosition, wxDefaultSize, 0 );
143  itemBoxSizer5->Add(m_RestoreBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
144 
145  wxStaticText* itemStaticText8 = new wxStaticText( itemCDialog1, wxID_STATIC, _("Description:"), wxDefaultPosition, wxDefaultSize, 0 );
146  itemFlexGridSizer3->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_TOP|wxALL, 5);
147 
148  m_DescrCtrl = new wxTextCtrl( itemCDialog1, ID_DESCR, wxEmptyString, wxDefaultPosition, itemCDialog1->ConvertDialogToPixels(wxSize(160, 60)), wxTE_MULTILINE );
149  itemFlexGridSizer3->Add(m_DescrCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
150 
151  itemFlexGridSizer3->AddGrowableRow(1);
152  itemFlexGridSizer3->AddGrowableCol(1);
153 
154  wxStdDialogButtonSizer* itemStdDialogButtonSizer10 = new wxStdDialogButtonSizer;
155 
156  itemBoxSizer2->Add(itemStdDialogButtonSizer10, 0, wxALIGN_RIGHT|wxALL, 5);
157  wxButton* itemButton11 = new wxButton( itemCDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
158  itemButton11->SetDefault();
159  itemStdDialogButtonSizer10->AddButton(itemButton11);
160 
161  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
162  itemStdDialogButtonSizer10->AddButton(itemButton12);
163 
164  itemStdDialogButtonSizer10->Realize();
165 
166  // Set validators
167  m_NameCtrl->SetValidator( wxGenericValidator(& m_Name) );
168  m_DescrCtrl->SetValidator( wxGenericValidator(& m_Descr) );
169 ////@end CFolderEditDlg content construction
170 }
171 
172 
173 void CFolderEditDlg::OnOkClick( wxCommandEvent& WXUNUSED(event) )
174 {
175  if(TransferDataFromWindow()) {
176  if(m_NameValidator) {
177  string err;
178  if( ! m_NameValidator->IsValid(ToStdString(m_Name), err)) {
179  NcbiErrorBox(err);
180  return;
181  }
182  }
183  EndModal(wxID_OK);
184  }
185 }
186 
187 
188 void CFolderEditDlg::OnRestoreBtn( wxCommandEvent& WXUNUSED(event) )
189 {
190  if (m_Object && m_Scope) {
191  string str;
193  m_Name = ToWxString(str);
194  m_NameCtrl->SetValue(m_Name);
195  }
196 }
197 
198 
199 void CFolderEditDlg::OnInitDialog( wxInitDialogEvent& event )
200 {
201  CDialog::OnInitDialog(event);
202 
203  if(m_ReadOnly) {
204  m_NameCtrl->Enable(false);
205  m_DescrCtrl->Enable(false);
206  }
207 
208  if (m_ReadOnly || m_Scope == NULL || m_Object == NULL ||
209  dynamic_cast<const objects::CSeq_annot*>(m_Object)) {
210  m_RestoreBtn->Enable(false);
211  m_RestoreBtn->Hide();
212  }
213 }
214 
215 
216 void CFolderEditDlg::SetDataObject(const CSerialObject* object, objects::CScope* scope)
217 {
218  m_Object = object;
219  m_Scope = scope;
220 }
221 
222 
224 {
225  m_NameValidator = validator;
226 }
227 
228 
229 
231 {
232  return true;
233 }
234 
235 
236 wxBitmap CFolderEditDlg::GetBitmapResource( const wxString& name )
237 {
238  // Bitmap retrieval
239 ////@begin CFolderEditDlg bitmap retrieval
240  wxUnusedVar(name);
241  return wxNullBitmap;
242 ////@end CFolderEditDlg bitmap retrieval
243 }
244 
245 
246 wxIcon CFolderEditDlg::GetIconResource( const wxString& name )
247 {
248  // Icon retrieval
249 ////@begin CFolderEditDlg icon retrieval
250  wxUnusedVar(name);
251  return wxNullIcon;
252 ////@end CFolderEditDlg icon retrieval
253 }
254 
255 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CDialog.
Definition: dialog.hpp:47
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
objects::CScope * m_Scope
static bool ShowToolTips()
wxTextCtrl * m_DescrCtrl
wxTextCtrl * m_NameCtrl
IFNameValidator * m_NameValidator
const CSerialObject * m_Object
void OnRestoreBtn(wxCommandEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
void SetNameValidator(IFNameValidator *validator)
bool Create(wxWindow *parent, wxWindowID id=ID_CFOLDEREDITDLG, const wxString &caption=_("Dialog"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxCLIP_CHILDREN|wxTAB_TRAVERSAL)
void OnOkClick(wxCommandEvent &event)
void OnInitDialog(wxInitDialogEvent &event)
wxButton * m_RestoreBtn
wxIcon GetIconResource(const wxString &name)
void SetDataObject(const CSerialObject *object, objects::CScope *scope)
Base class for all serializable objects.
Definition: serialbase.hpp:150
virtual bool IsValid(const string &name, string &err)=0
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
@ eDefault
Definition: label.hpp:73
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Jul 12 16:19:08 2024 by modify_doxy.py rev. 669887