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

Go to the SVN repository for this file.

1 /* $Id: twopartqual_panel.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 ////@begin includes
33 ////@end includes
34 
35 #include "twopartqual_panel.hpp"
36 
37 ////@begin XPM images
38 ////@end XPM images
39 
41 
42 /*!
43  * CTwoPartQualPanel type definition
44  */
45 
46 IMPLEMENT_DYNAMIC_CLASS( CTwoPartQualPanel, CFormattedQualPanel )
47 
48 
49 /*!
50  * CTwoPartQualPanel event table definition
51  */
52 
53 BEGIN_EVENT_TABLE( CTwoPartQualPanel, CFormattedQualPanel )
54 
55 ////@begin CTwoPartQualPanel event table entries
56  EVT_TEXT( ID_TEXTCTRL28, CTwoPartQualPanel::OnTextctrl28TextUpdated )
57 
58 ////@end CTwoPartQualPanel event table entries
59 
61 
62 
63 /*!
64  * CTwoPartQualPanel constructors
65  */
66 
68 {
69  Init();
70 }
71 
72 CTwoPartQualPanel::CTwoPartQualPanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
73 {
74  Init();
75  Create(parent, id, caption, pos, size, style);
76 }
77 
78 
79 /*!
80  * CTwoPartQualPanel creator
81  */
82 
83 bool CTwoPartQualPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
84 {
85 ////@begin CTwoPartQualPanel creation
86  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
87  CFormattedQualPanel::Create( parent, id, pos, size, style );
88 
90  if (GetSizer())
91  {
92  GetSizer()->SetSizeHints(this);
93  }
94  Centre();
95 ////@end CTwoPartQualPanel creation
96  return true;
97 }
98 
99 
100 /*!
101  * CTwoPartQualPanel destructor
102  */
103 
105 {
106 ////@begin CTwoPartQualPanel destruction
107 ////@end CTwoPartQualPanel destruction
108 }
109 
110 
111 /*!
112  * Member initialisation
113  */
114 
116 {
117 ////@begin CTwoPartQualPanel member initialisation
120 ////@end CTwoPartQualPanel member initialisation
121 }
122 
123 
124 /*!
125  * Control creation for CTwoPartQualPanel
126  */
127 
129 {
130 ////@begin CTwoPartQualPanel content construction
131  // Generated by DialogBlocks, 15/12/2011 07:59:08 (unregistered)
132 
133  CTwoPartQualPanel* itemCFormattedQualPanel1 = this;
134 
135  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
136  itemCFormattedQualPanel1->SetSizer(itemBoxSizer2);
137 
138  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
139  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
140 
141  wxArrayString m_ControlledListCtrlStrings;
142  m_ControlledListCtrl = new wxChoice( itemCFormattedQualPanel1, ID_CHOICE12, wxDefaultPosition, wxDefaultSize, m_ControlledListCtrlStrings, 0 );
143  itemBoxSizer3->Add(m_ControlledListCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
144 
145  m_FreeTextCtrl = new wxTextCtrl( itemCFormattedQualPanel1, ID_TEXTCTRL28, wxEmptyString, wxDefaultPosition, wxSize(150, -1), 0 );
146  itemBoxSizer3->Add(m_FreeTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
147 
148 ////@end CTwoPartQualPanel content construction
149 }
150 
151 
153 {
154  if (NStr::IsBlank (val)) {
155  m_ControlledListCtrl->SetStringSelection(wxEmptyString);
156  m_FreeTextCtrl->SetValue (wxEmptyString);
157  } else {
158  auto pos = NStr::Find(val, ":");
159  if (pos == string::npos) {
160  if (m_ControlledListCtrl->SetStringSelection(ToWxString(val))) {
161  m_FreeTextCtrl->SetValue (wxEmptyString);
162  } else {
163  m_ControlledListCtrl->SetStringSelection(wxEmptyString);
164  m_FreeTextCtrl->SetValue(ToWxString(val));
165  }
166  } else {
167  string part1 = val.substr(0, pos);
168  string part2 = val.substr(pos + 1);
169  if (m_ControlledListCtrl->SetStringSelection(ToWxString(part1))) {
170  m_FreeTextCtrl->SetValue(ToWxString(part2));
171  } else {
172  m_ControlledListCtrl->SetStringSelection(wxEmptyString);
173  m_FreeTextCtrl->SetValue(ToWxString(val));
174  }
175  }
176  }
177 }
178 
179 
181 {
182  string part1 = ToStdString (m_ControlledListCtrl->GetStringSelection());
183  string part2 = ToStdString (m_FreeTextCtrl->GetValue());
184 
185  if (NStr::IsBlank (part1)) {
186  return part2;
187  } else if (NStr::IsBlank (part2)) {
188  return part1;
189  } else {
190  string val = part1 + ":" + part2;
191  return val;
192  }
193 }
194 
195 
196 void CTwoPartQualPanel::GetDimensions(int *width, int *height)
197 {
198  int x1, x2, y1, y2;
199  m_ControlledListCtrl->GetSize(&x1, &y1);
200  m_FreeTextCtrl->GetSize(&x2, &y2);
201  if (height != NULL) {
202  if (y1 > y2) {
203  *height = y1;
204  } else {
205  *height = y2;
206  }
207  }
208 
209  if (width != NULL) {
210  *width = x1 + x2;
211  }
212 }
213 
214 
215 void CTwoPartQualPanel::SetControlledList (vector<string> choices)
216 {
217  m_ControlledListCtrl->Clear();
218  m_ControlledListCtrl->Append(wxEmptyString);
219  ITERATE (vector<string>, it, choices) {
220  m_ControlledListCtrl->Append(ToWxString (*it));
221  }
222 }
223 
224 
225 /*!
226  * Should we show tooltips?
227  */
228 
230 {
231  return true;
232 }
233 
234 /*!
235  * Get bitmap resources
236  */
237 
238 wxBitmap CTwoPartQualPanel::GetBitmapResource( const wxString& name )
239 {
240  // Bitmap retrieval
241 ////@begin CTwoPartQualPanel bitmap retrieval
242  wxUnusedVar(name);
243  return wxNullBitmap;
244 ////@end CTwoPartQualPanel bitmap retrieval
245 }
246 
247 /*!
248  * Get icon resources
249  */
250 
251 wxIcon CTwoPartQualPanel::GetIconResource( const wxString& name )
252 {
253  // Icon retrieval
254 ////@begin CTwoPartQualPanel icon retrieval
255  wxUnusedVar(name);
256  return wxNullIcon;
257 ////@end CTwoPartQualPanel icon retrieval
258 }
259 
260 
261 /*!
262  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_TEXTCTRL28
263  */
264 
265 void CTwoPartQualPanel::OnTextctrl28TextUpdated( wxCommandEvent& event )
266 {
267  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
268  if (NStr::IsBlank(ToStdString(item->GetLabel()))) {
269  return;
270  }
272 }
273 
275 
virtual void NotifyParentOfChange()
void OnTextctrl28TextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_TEXTCTRL28
void Init()
Initialises member variables.
virtual void GetDimensions(int *width, int *height)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxTextCtrl * m_FreeTextCtrl
void SetControlledList(vector< string > choices)
void CreateControls()
Creates the controls and sizers.
virtual void SetValue(string val)
virtual string GetValue()
wxChoice * m_ControlledListCtrl
bool Create(wxWindow *parent, wxWindowID id=ID_CTWOPARTQUALPANEL, const wxString &caption=_("TwoPartQualPanel"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static bool ShowToolTips()
Should we show tooltips?
~CTwoPartQualPanel()
Destructor.
CTwoPartQualPanel()
Constructors.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#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
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2887
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 Sat Dec 09 04:48:40 2023 by modify_doxy.py rev. 669887