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

Go to the SVN repository for this file.

1 /* $Id: ok_cancel_panel.cpp 40191 2018-01-04 21:03:28Z 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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
35 #include <wx/button.h>
36 #include <wx/sizer.h>
37 #include <wx/msgdlg.h>
41 
42 ////@begin XPM images
43 ////@end XPM images
44 
46 
48 
49 /*!
50  * COkCancelPanel type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( COkCancelPanel, wxPanel )
54 
55 
56 /*!
57  * COkCancelPanel event table definition
58  */
59 
60 BEGIN_EVENT_TABLE( COkCancelPanel, wxPanel )
61 
62 ////@begin COkCancelPanel event table entries
63  EVT_BUTTON( ID_ACCEPT_BTN, COkCancelPanel::OnAcceptBtnClick )
64  EVT_BUTTON( wxID_CLOSE, COkCancelPanel::OnClickCancel )
65 ////@end COkCancelPanel event table entries
66 
68 
69 
70 /*!
71  * COkCancelPanel constructors
72  */
73 
75 {
76  Init();
77 }
78 
79 COkCancelPanel::COkCancelPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
80 {
81  Init();
82  Create(parent, id, pos, size, style);
83 }
84 
85 
86 /*!
87  * COkCancelPanel creator
88  */
89 
90 bool COkCancelPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
91 {
92 ////@begin COkCancelPanel creation
93  wxPanel::Create( parent, id, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end COkCancelPanel creation
102  return true;
103 }
104 
105 
106 /*!
107  * COkCancelPanel destructor
108  */
109 
111 {
112 ////@begin COkCancelPanel destruction
113 ////@end COkCancelPanel destruction
114 }
115 
116 
117 /*!
118  * Member initialisation
119  */
120 
122 {
123 ////@begin COkCancelPanel member initialisation
124  m_LeaveUp = NULL;
125 ////@end COkCancelPanel member initialisation
126 }
127 
128 
129 /*!
130  * Control creation for COkCancelPanel
131  */
132 
134 {
135 ////@begin COkCancelPanel content construction
136  COkCancelPanel* itemPanel1 = this;
137 
138  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
139  itemPanel1->SetSizer(itemBoxSizer2);
140 
141  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
142  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
143 
144  wxButton* itemButton4 = new wxButton( itemPanel1, ID_ACCEPT_BTN, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
145  itemBoxSizer3->Add(itemButton4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
146 
147  wxButton* itemButton5 = new wxButton( itemPanel1, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
148  itemBoxSizer3->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
149 
150  m_LeaveUp = new wxCheckBox( itemPanel1, ID_LEAVE_DIALOG_UP_CHKBOX, _("Leave Dialog Up"), wxDefaultPosition, wxDefaultSize, 0 );
151  m_LeaveUp->SetValue(false);
152  itemBoxSizer3->Add(m_LeaveUp, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
153 
154 ////@end COkCancelPanel content construction
155 }
156 
157 
158 /*!
159  * Should we show tooltips?
160  */
161 
163 {
164  return true;
165 }
166 
167 /*!
168  * Get bitmap resources
169  */
170 
171 wxBitmap COkCancelPanel::GetBitmapResource( const wxString& name )
172 {
173  // Bitmap retrieval
174 ////@begin COkCancelPanel bitmap retrieval
175  wxUnusedVar(name);
176  return wxNullBitmap;
177 ////@end COkCancelPanel bitmap retrieval
178 }
179 
180 /*!
181  * Get icon resources
182  */
183 
184 wxIcon COkCancelPanel::GetIconResource( const wxString& name )
185 {
186  // Icon retrieval
187 ////@begin COkCancelPanel icon retrieval
188  wxUnusedVar(name);
189  return wxNullIcon;
190 ////@end COkCancelPanel icon retrieval
191 }
192 
193 
194 /*!
195  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
196  */
197 
198 void COkCancelPanel::OnAcceptBtnClick( wxCommandEvent& event )
199 {
200  x_ReportUsage();
201  wxWindow* w = this->GetParent();
202  while (w != NULL) {
203  CBulkCmdDlg* parent = dynamic_cast<CBulkCmdDlg*>(w);
204  if (parent) {
205  if (parent->GetTopLevelSeqEntryAndProcessor()) {
206  CRef<CCmdComposite> cmd = parent->GetCommand();
207  if (cmd) {
208  parent->ExecuteCmd(cmd);
209  if (!m_LeaveUp->GetValue()) {
210  parent->Destroy();
211  }
212  } else {
213  string error = parent->GetErrorMessage();
214  if (!NStr::IsBlank(error)) {
215  wxMessageBox(ToWxString(error), wxT("Error"),
216  wxOK | wxICON_ERROR, NULL);
217  }
218  }
219  } else {
220  wxMessageBox(ToWxString("No data was selected"),
221  wxT("Error"), wxOK | wxICON_ERROR, NULL);
222  }
223  return;
224  } else {
225  w = w->GetParent();
226  }
227  }
228 }
229 
230 
231 /*!
232  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
233  */
234 
235 void COkCancelPanel::OnClickCancel( wxCommandEvent& event )
236 {
237  wxWindow* w = this->GetParent();
238  while (w != NULL) {
239  CBulkCmdDlg* parent = dynamic_cast<CBulkCmdDlg*>(w);
240  if (parent) {
241  parent->Destroy();
242  return;
243  } else {
244  w = w->GetParent();
245  }
246  }
247 }
248 
250 {
251  wxWindow* win = this->GetParent();
252  while (win != nullptr) {
253  wxDialog* dlg_parent = dynamic_cast<wxDialog*>(win);
254  if (dlg_parent) {
255  NEditingStats::ReportUsage(dlg_parent->GetLabel());
256  break;
257  }
258  else {
259  wxFrame* fr_parent = dynamic_cast<wxFrame*>(win);
260  if (fr_parent) {
261  NEditingStats::ReportUsage(fr_parent->GetLabel());
262  break;
263  }
264  else {
265  win = win->GetParent();
266  }
267  }
268  }
269 }
270 
272 
273 
virtual void ExecuteCmd(CRef< CCmdComposite > cmd)
virtual CRef< CCmdComposite > GetCommand()=0
virtual string GetErrorMessage()=0
bool GetTopLevelSeqEntryAndProcessor()
static bool ShowToolTips()
Should we show tooltips?
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=ID_COKCANCELPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void CreateControls()
Creates the controls and sizers.
void x_ReportUsage(void)
~COkCancelPanel()
Destructor.
COkCancelPanel()
Constructors.
wxCheckBox * m_LeaveUp
void Init()
Initialises member variables.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnAcceptBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ACCEPT_BTN
void OnClickCancel(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#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
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(ncbi::objects)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sun Mar 03 03:13:03 2024 by modify_doxy.py rev. 669887