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

Go to the SVN repository for this file.

1 /* $Id: var_resolver_dlg.cpp 37718 2017-02-10 14:20:50Z 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: Anatoly Osipov
27  */
28 
29 #include <ncbi_pch.hpp>
30 
33 #include <wx/propgrid/propgrid.h>
34 
35 #include <wx/stattext.h>
36 #include <wx/sizer.h>
37 
39 USING_SCOPE(macro);
40 
41 /*!
42  * CVarResolverDlg type definition
43  */
44 
45 IMPLEMENT_DYNAMIC_CLASS( CVarResolverDlg, CDialog )
46 
47 
48 /*!
49  * CVarResolverDlg event table definition
50  */
51 
52 BEGIN_EVENT_TABLE( CVarResolverDlg, CDialog )
53 
54 ////@begin CVarResolverDlg event table entries
55  EVT_BUTTON( ID_BUTTON_DONE, CVarResolverDlg::OnButtonDoneClick )
56  EVT_BUTTON( ID_BUTTON_CANCEL, CVarResolverDlg::OnButtonCancelClick )
57  EVT_BUTTON( ID_BUTTON_RESET, CVarResolverDlg::OnButtonResetClick )
58 ////@end CVarResolverDlg event table entries
59 
61 
62 /*!
63  * CVarResolverDlg constructors
64  */
65 
67 {
68  Init();
69 }
70 
71 CVarResolverDlg::CVarResolverDlg( CMacroRep& macro_rep, wxWindow* parent, wxWindowID id,
72  const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
73  : m_MacroRep(&macro_rep)
74 {
75  Init();
76  Create(parent, id, caption, pos, size, style);
77 }
78 
79 
80 /*!
81  * CVarResolverDlg creator
82  */
83 
84 bool CVarResolverDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
85 {
86 ////@begin CVarResolverDlg creation
87  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
88  CDialog::Create( parent, id, caption, pos, size, style );
89 
91  if (GetSizer()) {
92  GetSizer()->SetSizeHints(this);
93  }
94  Centre();
95 ////@end CVarResolverDlg creation
96  return true;
97 }
98 
99 
100 /*!
101  * CVarResolverDlg destructor
102  */
103 
105 {
106 ////@begin CVarResolverDlg destruction
107  TPropPairsList::iterator it = m_PropPairsList.begin();
108  for ( ; it != m_PropPairsList.end(); it++ )
109  delete *it;
110 ////@end CVarResolverDlg destruction
111 }
112 
113 
114 /*!
115  * Member initialisation
116  */
117 
119 {
120 ////@begin CVarResolverDlg member initialisation
121  m_Status = false;
122  m_PropPairsList.clear();
123 
125 ////@end CVarResolverDlg member initialisation
126 
127  SetRegistryPath( "Workbench.Dialogs.VarResolver" );
128 }
129 
130 /*!
131  * Control creation for CVarResolverDlg
132  */
133 
135 {
136 ////@begin CVarResolverDlg content construction
137  wxBoxSizer* bs_vertical = new wxBoxSizer(wxVERTICAL);
138  SetSizer(bs_vertical);
139 
140  const int width = 350;
141  string msg = "Please choose values for variables for the macro:\n";
142  msg += m_MacroRep->GetTitle();
143  wxStaticText* label = new wxStaticText(this, wxID_STATIC, ToWxString(msg), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
144  label->Wrap(width);
145  bs_vertical->Add(label, 0, wxALL, 5);
146 
147  m_PropGridCtrl = new wxPropertyGrid ( this, ID_PROPERTY_GRID_CTRL, wxDefaultPosition, wxSize(width, 250), wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE );
148  wxBoxSizer* bs_horizontal = new wxBoxSizer(wxHORIZONTAL);
149 
150  bs_vertical->Add(m_PropGridCtrl, 1, wxEXPAND | wxALL, 5);
151  bs_vertical->Add(bs_horizontal, 0, wxALIGN_CENTER | wxALL, 5);
152 
153  wxButton* ResetButton = new wxButton( this, ID_BUTTON_RESET, _("Reset"), wxDefaultPosition, wxDefaultSize, 0 );
154  bs_horizontal->Add(ResetButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
155 
156  wxButton* CancelButton = new wxButton( this, ID_BUTTON_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
157  bs_horizontal->Add(CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
158 
159  wxButton* DoneButton = new wxButton( this, ID_BUTTON_DONE, _("Done"), wxDefaultPosition, wxDefaultSize, 0 );
160  bs_horizontal->Add(DoneButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
161 
162  if (!m_MacroRep)
163  return;
164  int blk; // var block number in macro
165  IMacroVar* var = m_MacroRep->GetFirstVar(blk);
166  wxPGProperty* property;
167  while (var) {
168  if (var->IsGUIResolvable()) {
169  CMacroVarAsk* pAsk = dynamic_cast<CMacroVarAsk*>(var);
170  if (pAsk) {
171  property = new wxStringProperty ( pAsk->GetName(), wxPG_LABEL, pAsk->GetDefaultValue() );
172  } else {
173  CMacroVarChoice* pChoice = dynamic_cast<CMacroVarChoice*>(var);
174  if (pChoice) {
175  wxArrayString tchoices;
176  const string* stored_value = pChoice->GetFirstChoice();
177  while (stored_value) {
178  tchoices.Add(ToWxString(*stored_value));
179  stored_value = pChoice->GetNextChoice();
180  }
181  property = new wxEnumProperty ( ToWxString(pChoice->GetName()), wxPG_LABEL, tchoices );
182  }
183  }
184  wxVariant variant = property->GetValue();
185  m_PropPairsList.push_back(new SPropPair(property, var, property->ValueToString(variant)));
186  m_PropGridCtrl->Append(property);
187  }
188  var = m_MacroRep->GetNextVar(blk);
189  }
190 ////@end CVarResolverDlg content construction
191 }
192 
193 void CVarResolverDlg::OnButtonDoneClick( wxCommandEvent& event )
194 {
195  TPropPairsList::iterator it = m_PropPairsList.begin();
196  for (; it != m_PropPairsList.end(); ++it) {
197  SPropPair* pair = *it;
198  if (pair && pair->m_MacroVar && pair->m_WxProp) {
199  pair->m_MacroVar->SetGUIResolvedValue(ToStdString(pair->m_WxProp->GetValueAsString()));
200  }
201  }
202  m_Status = true;
203  Close();
204 }
205 
206 void CVarResolverDlg::OnButtonCancelClick( wxCommandEvent& event )
207 {
208  Close();
209 }
210 
211 void CVarResolverDlg::OnButtonResetClick( wxCommandEvent& event )
212 {
213  TPropPairsList::iterator it = m_PropPairsList.begin();
214  for (; it != m_PropPairsList.end(); ++it) {
215  SPropPair* pair = *it;
216  if (pair && pair->m_WxProp) {
217  pair->m_WxProp->SetValue(pair->m_DefaultVisible);
218  }
219  }
220 }
221 
CDialog.
Definition: dialog.hpp:47
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
Class for parsed macro representation.
Definition: macro_rep.hpp:254
Class for "ask" variable representation (i.e.
Definition: macro_rep.hpp:170
Class for "choice" variable representation (i.e.
Definition: macro_rep.hpp:205
wxPropertyGrid * m_PropGridCtrl
void OnButtonCancelClick(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=ID_CVARRESOLVERDLG, const wxString &caption=_("Variable Resolver"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CVarResolverDlg()
Constructor for DYNAMIC CLASS.
CRef< macro::CMacroRep > m_MacroRep
void OnButtonResetClick(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
~CVarResolverDlg()
Destructor.
TPropPairsList m_PropPairsList
void OnButtonDoneClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
void Init()
Initialises member variables.
Abstract interface for variable representation.
Definition: macro_rep.hpp:57
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
const string & GetName() const
Get the name of stored variable.
Definition: macro_rep.hpp:67
virtual bool IsGUIResolvable() const =0
Returns true is the variable can be resolved via GUI.
const string * GetFirstChoice()
Get functions for stored choices.
Definition: macro_rep.cpp:214
const string & GetDefaultValue() const
Get default value.
Definition: macro_rep.hpp:185
const string * GetNextChoice()
Definition: macro_rep.cpp:219
#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[]
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Private types and data members.
USING_SCOPE(macro)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:58:19 2024 by modify_doxy.py rev. 669887