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

Go to the SVN repository for this file.

1 /* $Id: singleauthor_panel.cpp 43930 2019-09-20 18:43:51Z 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>
36 
40 
43 
44 #include <wx/sizer.h>
45 #include <wx/bitmap.h>
46 #include <wx/icon.h>
47 #include <wx/choice.h>
48 #include <wx/textctrl.h>
49 #include <wx/stattext.h>
50 #include <wx/valtext.h>
51 
52 
55 
56 static const char *arrows_xpm[] = {
57 /* columns rows colors chars-per-pixel */
58 "8 14 2 1 ",
59 " c black",
60 ". c None",
61 /* pixels */
62 "........",
63 "........",
64 ".. .....",
65 ". .....",
66 " .",
67 ". .....",
68 ".. .....",
69 "..... ..",
70 "..... .",
71 ". ",
72 "..... .",
73 "..... ..",
74 "........",
75 "........"
76 };
77 
78 /*
79  * CSingleAuthorPanel type definition
80  */
81 
82 IMPLEMENT_DYNAMIC_CLASS( CSingleAuthorPanel, wxPanel )
83 
84 
85 /*
86  * CSingleAuthorPanel event table definition
87  */
88 
89 BEGIN_EVENT_TABLE( CSingleAuthorPanel, wxPanel )
90 
91  EVT_COMMAND(wxID_ANY, wxEVT_LARGE_SPIN_CTRL_EVENT, CSingleAuthorPanel::OnMoveAuthorUpdated)
94 
95 
96 /*
97  * CSingleAuthorPanel constructors
98  */
99 
101 {
102  Init();
103 }
104 
105 CSingleAuthorPanel::CSingleAuthorPanel( wxWindow* parent, CAuthor& author,
106  wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
107  m_Author(0)
108 {
109  Init();
110  m_Author.Reset(new CAuthor());
111  m_Author->Assign(author);
112  m_Author->SetName().SetName();
113  Create(parent, id, pos, size, style);
114 }
115 
116 
117 /*
118  * CSingleAuthorPanel creator
119  */
120 
121 bool CSingleAuthorPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
122 {
123 ////@begin CSingleAuthorPanel creation
124  wxPanel::Create( parent, id, pos, size, style );
125 
126  CreateControls();
127  if (GetSizer())
128  {
129  GetSizer()->SetSizeHints(this);
130  }
131  Centre();
132 ////@end CSingleAuthorPanel creation
133  return true;
134 }
135 
136 
137 /*
138  * CSingleAuthorPanel destructor
139  */
140 
142 {
143 ////@begin CSingleAuthorPanel destruction
144 ////@end CSingleAuthorPanel destruction
145 }
146 
147 
148 /*
149  * Member initialisation
150  */
151 
153 {
154 ////@begin CSingleAuthorPanel member initialisation
158  m_Suffix = NULL;
159 ////@end CSingleAuthorPanel member initialisation
160 }
161 
162 
163 /*
164  * Control creation for CSingleAuthorPanel
165  */
166 
168 {
169 ////@begin CSingleAuthorPanel content construction
170  CSingleAuthorPanel* itemPanel1 = this;
171 
172  wxFlexGridSizer* itemFlexGridSizer2 = new wxFlexGridSizer(2, 7, 0, 0);
173  itemPanel1->SetSizer(itemFlexGridSizer2);
174 
175  m_FirstNameCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_FIRST, wxEmptyString, wxDefaultPosition, wxSize(100, -1), wxTE_PROCESS_ENTER );
176  itemFlexGridSizer2->Add(m_FirstNameCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
177  m_FirstNameCtrl->SetToolTip(wxEmptyString);
178 
179  m_MiddleInitial = new wxTextCtrl( itemPanel1, ID_AUTH_MI, wxEmptyString, wxDefaultPosition, wxSize(100, -1), wxTE_PROCESS_ENTER );
180  itemFlexGridSizer2->Add(m_MiddleInitial, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
181  m_MiddleInitial->SetToolTip(wxEmptyString);
182 
183  m_LastNameCtrl = new wxTextCtrl( itemPanel1, ID_AUTH_LAST, wxEmptyString, wxDefaultPosition, wxSize(100, -1), wxTE_PROCESS_ENTER );
184  itemFlexGridSizer2->Add(m_LastNameCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
185  m_LastNameCtrl->SetToolTip(wxEmptyString);
186 
187  m_FirstNameCtrl->Connect(ID_AUTH_FIRST, wxEVT_KILL_FOCUS, wxFocusEventHandler(CSingleAuthorPanel::OnFirstNameKillFocus), NULL, this);
188 
189  m_SuffixStrings.Add(wxEmptyString);
190  m_SuffixStrings.Add(_("Jr."));
191  m_SuffixStrings.Add(_("Sr."));
192  m_SuffixStrings.Add(_("II"));
193  m_SuffixStrings.Add(_("III"));
194  m_SuffixStrings.Add(_("IV"));
195  m_SuffixStrings.Add(_("V"));
196  m_SuffixStrings.Add(_("VI"));
197  m_Suffix = new CNoTabChoice( itemPanel1, ID_AUTH_SUFFIX, wxDefaultPosition, wxSize(50, -1), m_SuffixStrings, 0 );
198  itemFlexGridSizer2->Add(m_Suffix, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
199  m_Suffix->SetToolTip(wxEmptyString);
200 
201 ////@end CSingleAuthorPanel content construction
203  m_FirstNameCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & m_FirstName ));
204  m_LastNameCtrl->SetValidator( wxTextValidator(wxFILTER_NONE, & m_LastName ));
205 
206  // add spinner for inserting a new author
207  m_InsertSpinCtrl = new CLargeNoTabSpinControl(itemPanel1, wxID_ANY, wxDefaultPosition);
209  itemFlexGridSizer2->Add(m_InsertSpinCtrl, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 0);
210 
211  // add spinner for moving authors up and down
212  m_MoveSpinCtrl = new CLargeNoTabSpinControl(itemPanel1, wxID_ANY, wxDefaultPosition);
213  itemFlexGridSizer2->Add(m_MoveSpinCtrl, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 0);
214 
215  wxBitmap bmp(arrows_xpm);
216  m_SwapButton = new CNoTabBitmapButton(itemPanel1, ID_AUTH_SWAP_NAME, bmp, wxDefaultPosition, wxSize(CLargeSpinControl::kWidth / 2 + 4, CLargeSpinControl::kHeight + 4));
217  itemFlexGridSizer2->Add(m_SwapButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 0);
218  m_SwapButton->SetCanFocus(false);
219 }
220 
222 {
223  if (!wxPanel::TransferDataFromWindow())
224  return false;
225 
226  macro::CMacroFunction_AuthorFix::s_BuildName(ToAsciiStdString(m_FirstName),
227  ToAsciiStdString(m_MiddleInitial->GetValue()),
229  ToAsciiStdString(m_Suffix->GetStringSelection()),
230  m_Author->SetName().SetName());
231  return true;
232 }
233 
235 {
236  if (m_Author->GetName().GetName().IsSetFirst()) {
237  m_FirstName = ToWxString (m_Author->GetName().GetName().GetFirst());
238  } else {
239  m_FirstName = wxEmptyString;
240  }
241  if (m_Author->GetName().GetName().IsSetLast()) {
242  m_LastName = ToWxString (m_Author->GetName().GetName().GetLast());
243  } else {
244  m_LastName = wxEmptyString;
245  }
246 
247  string middle_init = x_ParseInitialsFromAuthor();
248  m_MiddleInitial->ChangeValue(ToWxString(middle_init));
249 
250  m_Suffix->SetSelection(1);
251  string suffix = (m_Author->SetName().SetName().IsSetSuffix()) ? m_Author->GetName().GetName().GetSuffix() : kEmptyStr;
252  unsigned int i;
253  for (i = 0; i < m_SuffixStrings.size(); i++) {
255  m_Suffix->SetSelection (i);
256  break;
257  }
258  }
259  return wxPanel::TransferDataToWindow();
260 }
261 
262 void CSingleAuthorPanel::SetAuthor(const objects::CAuthor &author)
263 {
264  m_Author.Reset(new CAuthor());
265  m_Author->Assign(author);
266  m_Author->SetName().SetName();
268  Refresh();
269 }
270 
272 {
273  if (!name.IsSetInitials())
274  return kEmptyStr;
275 
276  string first_init = (name.IsSetFirst()) ? macro::CMacroFunction_AuthorFix::s_GetFirstNameInitials(name.GetFirst()) : kEmptyStr;
277  string middle_init = (name.IsSetInitials()) ? name.GetInitials(): kEmptyStr;
278 
279  if (NStr::StartsWith(middle_init, first_init, NStr::eNocase)) {
280  middle_init = middle_init.substr(first_init.length());
281  }
282  if (NStr::EndsWith(middle_init, ".")) {
283  middle_init = middle_init.substr(0, middle_init.length() - 1);
284  }
285 
286  return middle_init;
287 }
288 
290 {
291  if (m_Author->GetName().IsName()) {
292  return s_ParseInitialsFromName(m_Author->GetName().GetName());
293  }
294 
295  return kEmptyStr;
296 }
297 
299 {
300  if (m_Author)
301  return m_Author;
302 
303  return CRef<CAuthor>();
304 }
305 
306 /*
307  * Should we show tooltips?
308  */
309 
311 {
312  return true;
313 }
314 
315 /*
316  * Get bitmap resources
317  */
318 
319 wxBitmap CSingleAuthorPanel::GetBitmapResource( const wxString& name )
320 {
321  // Bitmap retrieval
322 ////@begin CSingleAuthorPanel bitmap retrieval
323  wxUnusedVar(name);
324  return wxNullBitmap;
325 ////@end CSingleAuthorPanel bitmap retrieval
326 }
327 
328 /*
329  * Get icon resources
330  */
331 
332 wxIcon CSingleAuthorPanel::GetIconResource( const wxString& name )
333 {
334  // Icon retrieval
335 ////@begin CSingleAuthorPanel icon retrieval
336  wxUnusedVar(name);
337  return wxNullIcon;
338 ////@end CSingleAuthorPanel icon retrieval
339 }
340 
342 {
343  m_InsertSpinCtrl->Hide();
344  m_MoveSpinCtrl->Hide();
345  m_SwapButton->Hide();
346  GetSizer()->SetSizeHints(this);
347 }
348 
349 
351 {
352  CAuthorNamesContainer* authlistpanel = dynamic_cast<CAuthorNamesContainer*>(parent);
353  while (parent && !authlistpanel) {
354  parent = parent->GetParent();
355  authlistpanel = dynamic_cast<CAuthorNamesContainer*>(parent);
356  }
357  return authlistpanel;
358 }
359 
360 
362 {
363  event.Skip();
364  CAuthorNamesContainer* parent = s_FindListPanel(this->GetParent());
365  if (parent) {
366  parent->AddLastAuthor((wxWindow*)this);
367  }
368 }
369 
370 /*
371  * wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_MOVE_AUTHOR
372  */
373 
374 void CSingleAuthorPanel::OnMoveAuthorUpdated( wxCommandEvent& evt )
375 {
376  CAuthorNamesContainer* parent = s_FindListPanel(this->GetParent());
377  if (!parent) {
378  return;
379  }
380 
381  switch (evt.GetId()) {
383  parent->ShiftAuthorUp((wxWindow*)this);
384  break;
386  parent->ShiftAuthorDown((wxWindow*)this);
387  break;
388  case 2 + CLargeSpinControl::kBtnUp:
389  parent->InsertAuthorBefore((wxWindow*)this);
390  break;
391  case 2 + CLargeSpinControl::kBtnDn:
392  parent->InsertAuthorAfter((wxWindow*)this);
393  break;
394  }
395 }
396 
397 void CSingleAuthorPanel::OnSwapName( wxCommandEvent& evt )
398 {
399  wxString first = m_FirstNameCtrl->GetValue();
400  wxString last = m_LastNameCtrl->GetValue();
401  m_FirstNameCtrl->SetValue(last);
402  m_LastNameCtrl->SetValue(first);
403 }
404 
405 
407 {
408  if (!author.IsSetName()) {
409  return false;
410  }
411  bool rval = false;
412  const auto& p = author.GetName();
413  if (p.IsName()) {
414  const auto& person = p.GetName();
415  if (person.IsSetLast() && person.GetLast() == "?" &&
416  (!person.IsSetFirst() || NStr::IsBlank(person.GetFirst())) &&
417  (!person.IsSetInitials() || NStr::IsBlank(person.GetInitials())) &&
418  (!person.IsSetSuffix() || NStr::IsBlank(person.GetSuffix()))) {
419  rval = true;
420  }
421  }
422  else if (p.IsStr() && p.GetStr() == "?") {
423  rval = true;
424  }
425  return rval;
426 }
427 
428 
429 
430 
432 
433 
virtual void AddLastAuthor(wxWindow *link)=0
virtual void InsertAuthorBefore(wxWindow *link)=0
virtual void InsertAuthorAfter(wxWindow *link)=0
void ShiftAuthorUp(wxWindow *link)
void ShiftAuthorDown(wxWindow *link)
CAuthor –.
Definition: Author.hpp:59
void UseImageSet(int set)
static const int kHeight
static const int kWidth
@Name_std.hpp User-defined methods of the data storage class.
Definition: Name_std.hpp:56
bool Create(wxWindow *parent, wxWindowID id=10025, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxArrayString m_SuffixStrings
virtual bool TransferDataFromWindow()
CRef< objects::CAuthor > GetAuthor() const
~CSingleAuthorPanel()
Destructor.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
virtual bool TransferDataToWindow()
CSingleAuthorPanel()
Constructors.
CNoTabBitmapButton * m_SwapButton
CLargeNoTabSpinControl * m_MoveSpinCtrl
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SetAuthor(const objects::CAuthor &author)
static bool ShowToolTips()
Should we show tooltips?
static string s_ParseInitialsFromName(const objects::CName_std &name)
void CreateControls()
Creates the controls and sizers.
void OnMoveAuthorUpdated(wxCommandEvent &evt)
void OnFirstNameKillFocus(wxFocusEvent &event)
CLargeNoTabSpinControl * m_InsertSpinCtrl
CRef< objects::CAuthor > m_Author
void OnSwapName(wxCommandEvent &evt)
static bool IsPlaceholder(const objects::CAuthor &author)
#define _(proto)
Definition: ct_nlmzip_i.h:78
thread_local unique_ptr< FtaMsgPost > bmp
Definition: ftaerr.cpp:120
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 kEmptyStr
Definition: ncbistr.hpp:123
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
const TName & GetName(void) const
Get the Name member data.
Definition: Author_.hpp:352
bool IsSetName(void) const
Author, Primary or Secondary Check if a value has been assigned to Name data member.
Definition: Author_.hpp:340
const TInitials & GetInitials(void) const
Get the Initials member data.
Definition: Name_std_.hpp:610
bool IsSetInitials(void) const
first + middle initials Check if a value has been assigned to Initials data member.
Definition: Name_std_.hpp:598
const TFirst & GetFirst(void) const
Get the First member data.
Definition: Name_std_.hpp:469
const TName & GetName(void) const
Get the variant data.
Definition: Person_id_.cpp:137
bool IsSetFirst(void) const
Check if a value has been assigned to First data member.
Definition: Name_std_.hpp:457
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char * suffix[]
Definition: pcregrep.c:408
static static static wxID_ANY
USING_SCOPE(objects)
static const char * arrows_xpm[]
CAuthorNamesContainer * s_FindListPanel(wxWindow *parent)
#define ID_AUTH_FIRST
#define ID_AUTH_SWAP_NAME
#define ID_AUTH_LAST
#define ID_AUTH_SUFFIX
#define ID_AUTH_MI
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToAsciiStdString(const wxString &input)
Definition: wx_utils.hpp:166
Modified on Sat May 25 14:18:19 2024 by modify_doxy.py rev. 669887