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

Go to the SVN repository for this file.

1 /* $Id: author_affiliation_panel.cpp 42280 2019-01-24 20:12:34Z asztalos $
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>
33 
34 #include <objects/biblio/Affil.hpp>
35 
37 
38 #include <wx/sizer.h>
39 #include <wx/bitmap.h>
40 #include <wx/icon.h>
41 #include <wx/stattext.h>
42 #include <wx/textctrl.h>
43 
44 
46 
49 
50 ////@begin XPM images
51 ////@end XPM images
52 
53 
54 /*
55  * CAuthorAffiliationPanel type definition
56  */
57 
58 IMPLEMENT_DYNAMIC_CLASS( CAuthorAffiliationPanel, wxPanel )
59 
60 
61 /*
62  * CAuthorAffiliationPanel event table definition
63  */
64 
65 BEGIN_EVENT_TABLE( CAuthorAffiliationPanel, wxPanel )
66 
67 ////@begin CAuthorAffiliationPanel event table entries
68 ////@end CAuthorAffiliationPanel event table entries
69 
71 
72 
73 /*
74  * CAuthorAffiliationPanel constructors
75  */
76 
78 {
79  Init();
80 }
81 
82 CAuthorAffiliationPanel::CAuthorAffiliationPanel( wxWindow* parent, const CAffil& affil,
83  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
84 {
85  m_Affil.Reset(new CAffil);
86  m_Affil->Assign(affil);
87  Init();
88  Create(parent, id, pos, size, style);
89 }
90 
91 
92 /*
93  * CAuthorAffiliationPanel creator
94  */
95 
96 bool CAuthorAffiliationPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CAuthorAffiliationPanel creation
99  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
100  wxPanel::Create( parent, id, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CAuthorAffiliationPanel creation
109  return true;
110 }
111 
112 
113 /*
114  * CAuthorAffiliationPanel destructor
115  */
116 
118 {
119 ////@begin CAuthorAffiliationPanel destruction
120 ////@end CAuthorAffiliationPanel destruction
121 }
122 
123 
124 /*
125  * Member initialisation
126  */
127 
129 {
130 ////@begin CAuthorAffiliationPanel member initialisation
131  m_AffilCtrl = NULL;
133  m_StreetCtrl = NULL;
134  m_CityCtrl = NULL;
135  m_SubCtrl = NULL;
136  m_ZipCtrl = NULL;
138 ////@end CAuthorAffiliationPanel member initialisation
139 }
140 
141 
142 /*
143  * Control creation for CAuthorAffiliationPanel
144  */
145 
147 {
148 ////@begin CAuthorAffiliationPanel content construction
149  CAuthorAffiliationPanel* itemPanel1 = this;
150 
151  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
152  itemPanel1->SetSizer(itemBoxSizer2);
153 
154  itemBoxSizer2->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
155 
156  wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
157  itemBoxSizer2->Add(itemFlexGridSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
158 
159  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("Institution"), wxDefaultPosition, wxDefaultSize, 0 );
160  itemFlexGridSizer4->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
161 
162  m_AffilCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_INST, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
163  itemFlexGridSizer4->Add(m_AffilCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
164 
165  wxStaticText* itemStaticText7 = new wxStaticText( itemPanel1, wxID_STATIC, _("Department"), wxDefaultPosition, wxDefaultSize, 0 );
166  itemFlexGridSizer4->Add(itemStaticText7, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
167 
168  m_DepartmentCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_DEPT, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
169  itemFlexGridSizer4->Add(m_DepartmentCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
170 
171  wxStaticText* itemStaticText9 = new wxStaticText( itemPanel1, wxID_STATIC, _("Street Address"), wxDefaultPosition, wxDefaultSize, 0 );
172  itemFlexGridSizer4->Add(itemStaticText9, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  m_StreetCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_ADDRESS, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
175  itemFlexGridSizer4->Add(m_StreetCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
176 
177  wxStaticText* itemStaticText11 = new wxStaticText( itemPanel1, wxID_STATIC, _("City"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemFlexGridSizer4->Add(itemStaticText11, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  m_CityCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_CITY, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
181  itemFlexGridSizer4->Add(m_CityCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
182 
183  wxStaticText* itemStaticText13 = new wxStaticText( itemPanel1, wxID_STATIC, _("State/Province"), wxDefaultPosition, wxDefaultSize, 0 );
184  itemFlexGridSizer4->Add(itemStaticText13, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186  m_SubCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_STATE, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
187  itemFlexGridSizer4->Add(m_SubCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
188 
189  wxStaticText* itemStaticText15 = new wxStaticText( itemPanel1, wxID_STATIC, _("Zip/Postal Code"), wxDefaultPosition, wxDefaultSize, 0 );
190  itemFlexGridSizer4->Add(itemStaticText15, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
191 
192  m_ZipCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_CODE, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
193  itemFlexGridSizer4->Add(m_ZipCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
194 
195  wxStaticText* itemStaticText17 = new wxStaticText( itemPanel1, wxID_STATIC, _("Country"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemFlexGridSizer4->Add(itemStaticText17, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
197 
198  m_CountryCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_AFFIL_COUNTRY, wxEmptyString, wxDefaultPosition, wxSize(300, -1), 0 );
199  itemFlexGridSizer4->Add(m_CountryCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
200 
201 ////@end CAuthorAffiliationPanel content construction
202 
203 }
204 
205 
206 #define AFFILPANEL_SETSTD(Field,Ctrl) \
207  if (m_Affil->GetStd().IsSet##Field()) { \
208  m_##Ctrl->SetValue (ToWxString (m_Affil->SetStd().Set##Field())); \
209  } else { \
210  m_##Ctrl->SetValue (wxEmptyString); \
211  }
212 
214 {
215  if (!wxPanel::TransferDataToWindow())
216  return false;
217 
218  if (m_Affil->IsStd()) {
219  AFFILPANEL_SETSTD(Affil,AffilCtrl);
220  AFFILPANEL_SETSTD(Div,DepartmentCtrl);
221  AFFILPANEL_SETSTD(Street,StreetCtrl);
222  AFFILPANEL_SETSTD(City,CityCtrl);
223  AFFILPANEL_SETSTD(Sub,SubCtrl);
224  AFFILPANEL_SETSTD(Postal_code,ZipCtrl);
225  AFFILPANEL_SETSTD(Country,CountryCtrl);
226  } else if (m_Affil->IsStr()) {
227  m_AffilCtrl->SetValue(ToWxString (m_Affil->GetStr()));
228  m_DepartmentCtrl->SetValue(wxEmptyString);
229  m_StreetCtrl->SetValue(wxEmptyString);
230  m_CityCtrl->SetValue(wxEmptyString);
231  m_SubCtrl->SetValue(wxEmptyString);
232  m_ZipCtrl->SetValue(wxEmptyString);
233  m_CountryCtrl->SetValue(wxEmptyString);
234  } else {
235  m_AffilCtrl->SetValue(wxEmptyString);
236  m_DepartmentCtrl->SetValue(wxEmptyString);
237  m_StreetCtrl->SetValue(wxEmptyString);
238  m_CityCtrl->SetValue(wxEmptyString);
239  m_SubCtrl->SetValue(wxEmptyString);
240  m_ZipCtrl->SetValue(wxEmptyString);
241  m_CountryCtrl->SetValue(wxEmptyString);
242  }
243  return true;
244 }
245 
246 
247 #define AFFILPANEL_RESETBLANK(Field) \
248  if (NStr::IsBlank (m_Affil->GetStd().Get##Field())) { \
249  m_Affil->SetStd().Reset##Field(); \
250  }
251 
253 {
254  if (!wxPanel::TransferDataFromWindow())
255  return false;
256 
257  string affil = ToAsciiStdString (m_AffilCtrl->GetValue());
258  string div = ToAsciiStdString (m_DepartmentCtrl->GetValue());
259  string street = ToAsciiStdString (m_StreetCtrl->GetValue());
260  string city = ToAsciiStdString (m_CityCtrl->GetValue());
261  string sub = ToAsciiStdString (m_SubCtrl->GetValue());
262  string zip = ToAsciiStdString (m_ZipCtrl->GetValue());
263  string country = ToAsciiStdString (m_CountryCtrl->GetValue());
264 
265  if (NStr::IsBlank(div) && NStr::IsBlank(street)
266  && NStr::IsBlank(city) && NStr::IsBlank(sub)
267  && NStr::IsBlank(zip) && NStr::IsBlank(country)) {
268 
269  if (NStr::IsBlank(affil)) {
270  m_Affil.Reset();
271  } else {
272  if (m_Affil.IsNull()) {
273  m_Affil.Reset(new CAffil);
274  }
275  m_Affil->SetStr(affil);
276  }
277  } else {
278  if (m_Affil.IsNull()) {
279  m_Affil.Reset(new CAffil);
280  }
281  m_Affil->SetStd().SetAffil(affil);
282  m_Affil->SetStd().SetDiv(div);
283  m_Affil->SetStd().SetStreet(street);
284  m_Affil->SetStd().SetCity(city);
285  m_Affil->SetStd().SetSub(sub);
286  m_Affil->SetStd().SetPostal_code(zip);
287  m_Affil->SetStd().SetCountry(country);
288  AFFILPANEL_RESETBLANK(Affil)
290  AFFILPANEL_RESETBLANK(Street)
293  AFFILPANEL_RESETBLANK(Postal_code)
294  AFFILPANEL_RESETBLANK(Country)
295  }
296  return true;
297 }
298 
300 {
301  if (affil) {
302  m_Affil = affil;
303  }
304  else {
305  m_Affil.Reset();
306  }
308 }
309 
311 {
312  if (TransferDataFromWindow() && m_Affil) {
313  return m_Affil;
314  }
315 
316  return CRef<CAffil>();
317 }
318 
319 
320 
321 /*
322  * Should we show tooltips?
323  */
324 
326 {
327  return true;
328 }
329 
330 /*
331  * Get bitmap resources
332  */
333 
334 wxBitmap CAuthorAffiliationPanel::GetBitmapResource( const wxString& name )
335 {
336  // Bitmap retrieval
337 ////@begin CAuthorAffiliationPanel bitmap retrieval
338  wxUnusedVar(name);
339  return wxNullBitmap;
340 ////@end CAuthorAffiliationPanel bitmap retrieval
341 }
342 
343 /*
344  * Get icon resources
345  */
346 
347 wxIcon CAuthorAffiliationPanel::GetIconResource( const wxString& name )
348 {
349  // Icon retrieval
350 ////@begin CAuthorAffiliationPanel icon retrieval
351  wxUnusedVar(name);
352  return wxNullIcon;
353 ////@end CAuthorAffiliationPanel icon retrieval
354 }
USING_SCOPE(objects)
#define AFFILPANEL_SETSTD(Field, Ctrl)
#define AFFILPANEL_RESETBLANK(Field)
@Affil.hpp User-defined methods of the data storage class.
Definition: Affil.hpp:56
void SetAffil(CRef< objects::CAffil > affil)
void Init()
Initialises member variables.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CAUTHORAFFILIATIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CRef< objects::CAffil > m_Affil
CRef< objects::CAffil > GetAffil()
static bool ShowToolTips()
Should we show tooltips?
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToAsciiStdString(const wxString &input)
Definition: wx_utils.hpp:166
Modified on Sun Apr 14 05:25:04 2024 by modify_doxy.py rev. 669887