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

Go to the SVN repository for this file.

1 /* $Id: macro_error_dlg.cpp 47279 2022-12-09 16:47:59Z 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:
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <wx/sizer.h>
33 #include <wx/button.h>
34 #include <wx/textctrl.h>
35 #include <wx/statline.h>
36 #include <wx/hyperlink.h>
37 #include <wx/stattext.h>
38 
42 
44 
45 using namespace macro;
46 
47 /*!
48  * CMacroErrorDlg type definition
49  */
50 
51 IMPLEMENT_DYNAMIC_CLASS( CMacroErrorDlg, wxDialog )
52 
53 
54 /*!
55  * CMacroErrorDlg event table definition
56  */
57 
58 BEGIN_EVENT_TABLE( CMacroErrorDlg, wxDialog )
59 
60 ////@begin CMacroErrorDlg event table entries
61  EVT_HYPERLINK( ID_ERROR_DETALS_HYPERLINKCTRL, CMacroErrorDlg::OnErrorDetalsClicked )
62  EVT_HYPERLINK( ID_DATA_DETAILS_HYPERLINKCTRL, CMacroErrorDlg::OnDataDetailsClicked )
63  EVT_BUTTON( ID_FEEDBACK_BUTTON, CMacroErrorDlg::OnFeedbackButtonClick )
64 ////@end CMacroErrorDlg event table entries
65 
67 
68 
69 /*!
70  * CMacroErrorDlg constructors
71  */
72 
74 {
75  Init();
76 }
77 
78 CMacroErrorDlg::CMacroErrorDlg(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
79 {
80  Init();
81  Create(parent, id, caption, pos, size, style);
82 }
83 
84 
85 /*!
86  * CMacroErrorDlg creator
87  */
88 
89 bool CMacroErrorDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91 ////@begin CMacroErrorDlg creation
92  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY|wxWS_EX_BLOCK_EVENTS);
93  wxDialog::Create( parent, id, caption, pos, size, style );
94 
95  CreateControls();
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end CMacroErrorDlg creation
102  return true;
103 }
104 
105 
106 /*!
107  * CMacroErrorDlg destructor
108  */
109 
111 {
112 ////@begin CMacroErrorDlg destruction
113 ////@end CMacroErrorDlg destruction
114 }
115 
116 
117 /*!
118  * Member initialisation
119  */
120 
122 {
123 ////@begin CMacroErrorDlg member initialisation
124  m_VSizer = NULL;
125  m_ErrorTextCtrl = NULL;
126  m_ErrorDetailsLink = NULL;
127  m_ErrorDetailsCtrl = NULL;
128  m_DataDetailsLink = NULL;
129  m_DataDetailsCtrl = NULL;
130 ////@end CMacroErrorDlg member initialisation
131 }
132 
133 
134 /*!
135  * Control creation for CMacroErrorDlg
136  */
137 
139 {
140 ////@begin CMacroErrorDlg content construction
141  CMacroErrorDlg* itemDialog1 = this;
142 
143  m_VSizer = new wxBoxSizer(wxVERTICAL);
144  itemDialog1->SetSizer(m_VSizer);
145 
146  m_ErrorTextCtrl = new wxStaticText( itemDialog1, wxID_ERROR_STATIC, _("Static text"), wxDefaultPosition, wxSize(400, -1), 0 );
147  m_VSizer->Add(m_ErrorTextCtrl, 0, wxGROW|wxALL, 5);
148 
149  wxStaticLine* itemStaticLine4 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
150  m_VSizer->Add(itemStaticLine4, 0, wxGROW|wxALL, 5);
151 
152  m_ErrorDetailsLink = new wxHyperlinkCtrl( itemDialog1, ID_ERROR_DETALS_HYPERLINKCTRL, wxGetTranslation(wxString() + (wxChar) 0x02C5 + wxT(" Error Details")), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
153  m_ErrorDetailsLink->Enable(false);
154  m_VSizer->Add(m_ErrorDetailsLink, 0, wxALIGN_LEFT|wxALL, 5);
155 
156  m_ErrorDetailsCtrl = new wxTextCtrl( itemDialog1, ID_ERROR_DETAILS_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE|wxTE_READONLY );
157  m_ErrorDetailsCtrl->Show(false);
158  m_VSizer->Add(m_ErrorDetailsCtrl, 0, wxGROW|wxALL|wxFIXED_MINSIZE, 5);
159 
160  wxStaticLine* itemStaticLine7 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
161  m_VSizer->Add(itemStaticLine7, 0, wxGROW|wxALL, 5);
162 
163  m_DataDetailsLink = new wxHyperlinkCtrl( itemDialog1, ID_DATA_DETAILS_HYPERLINKCTRL, wxGetTranslation(wxString() + (wxChar) 0x02C5 + wxT(" Data Details")), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
164  m_DataDetailsLink->Enable(false);
165  m_VSizer->Add(m_DataDetailsLink, 0, wxALIGN_LEFT|wxALL, 5);
166 
167  m_DataDetailsCtrl = new wxTextCtrl( itemDialog1, ID_DATA_DETAILS_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE|wxTE_READONLY );
168  m_DataDetailsCtrl->Show(false);
169  m_VSizer->Add(m_DataDetailsCtrl, 0, wxGROW|wxALL|wxFIXED_MINSIZE, 5);
170 
171  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
172  m_VSizer->Add(itemStaticLine10, 0, wxGROW|wxALL, 5);
173 
174  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
175  m_VSizer->Add(itemBoxSizer11, 0, wxGROW|wxALL, 5);
176 
177  itemBoxSizer11->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
178 
179  wxButton* itemButton13 = new wxButton( itemDialog1, ID_FEEDBACK_BUTTON, _("Send Feedback..."), wxDefaultPosition, wxDefaultSize, 0 );
180  itemBoxSizer11->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
183  itemButton14->SetDefault();
184  itemBoxSizer11->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186 ////@end CMacroErrorDlg content construction
187 }
188 
189 void CMacroErrorDlg::SetException(const string &message, const CException &error)
190 {
191  string msg(message);
192  msg += '\n';
193  msg += x_MergeExceptionMessages(error);
194  SetMessage(msg);
195 
196  const macro::CMacroDataException *pDataException = x_FindDataException(error);
197 
198  SetReport(error.ReportAll());
199  if (pDataException) {
200  SetData(pDataException->GetDataAsString());
201  }
202 }
203 
204 void CMacroErrorDlg::SetMessage(const string &message)
205 {
206  _ASSERT(m_ErrorTextCtrl);
207  m_ErrorTextCtrl->SetLabelText(message.c_str());
208  m_ErrorTextCtrl->GetContainingSizer()->Fit(m_ErrorTextCtrl);
209  m_VSizer->SetSizeHints(this);
210 }
211 
212 void CMacroErrorDlg::SetReport(const string &report)
213 {
214  _ASSERT(m_ErrorDetailsCtrl);
215  m_ErrorDetailsCtrl->Clear();
216  m_ErrorDetailsCtrl->AppendText(report.c_str());
217  m_ErrorDetailsLink->Enable();
218  m_VSizer->SetSizeHints(this);
219 }
220 
221 void CMacroErrorDlg::SetData(const string &data)
222 {
223  _ASSERT(m_DataDetailsCtrl);
224  m_DataDetailsCtrl->Clear();
225  m_DataDetailsCtrl->AppendText(data.c_str());
226  m_DataDetailsLink->Enable();
227  m_VSizer->SetSizeHints(this);
228 }
229 
230 /*!
231  * Should we show tooltips?
232  */
233 
235 {
236  return true;
237 }
238 
239 /*!
240  * Get bitmap resources
241  */
242 
243 wxBitmap CMacroErrorDlg::GetBitmapResource( const wxString& name )
244 {
245  // Bitmap retrieval
246 ////@begin CMacroErrorDlg bitmap retrieval
247  wxUnusedVar(name);
248  return wxNullBitmap;
249 ////@end CMacroErrorDlg bitmap retrieval
250 }
251 
252 /*!
253  * Get icon resources
254  */
255 
256 wxIcon CMacroErrorDlg::GetIconResource( const wxString& name )
257 {
258  // Icon retrieval
259 ////@begin CMacroErrorDlg icon retrieval
260  wxUnusedVar(name);
261  return wxNullIcon;
262 ////@end CMacroErrorDlg icon retrieval
263 }
264 
265 
266 /*!
267  * wxEVT_COMMAND_HYPERLINK event handler for ID_ERROR_DETALS_HYPERLINKCTRL
268  */
269 
270 void CMacroErrorDlg::OnErrorDetalsClicked( wxHyperlinkEvent& event )
271 {
272  if (m_ErrorDetailsCtrl->IsShown()) {
273  m_ErrorDetailsLink->SetLabel(L"\u02C5 Error Details");
274  m_VSizer->Show(m_ErrorDetailsCtrl, false);
275  }
276  else {
277  m_ErrorDetailsLink->SetLabel(L"\u02C4 Error Details");
278  m_VSizer->Show(m_ErrorDetailsCtrl);
279  }
280  //m_ErrorDetailsCtrl->GetContainingSizer()->Fit(m_ErrorDetailsCtrl);
281  m_VSizer->SetSizeHints(this);
282  m_VSizer->Layout();
283 }
284 
285 
286 /*!
287  * wxEVT_COMMAND_HYPERLINK event handler for ID_DATA_DETAILS_HYPERLINKCTRL
288  */
289 
290 void CMacroErrorDlg::OnDataDetailsClicked( wxHyperlinkEvent& event )
291 {
292  if (m_DataDetailsCtrl->IsShown()) {
293  m_DataDetailsLink->SetLabel(L"\u02C5 Data Details");
294  m_VSizer->Show(m_DataDetailsCtrl, false);
295  }
296  else {
297  m_DataDetailsLink->SetLabel(L"\u02C4 Data Details");
298  m_VSizer->Show(m_DataDetailsCtrl);
299  }
300  //m_DataDetailsCtrl->GetContainingSizer()->Fit(m_DataDetailsCtrl);
301  m_VSizer->SetSizeHints(this);
302  m_VSizer->Layout();
303 }
304 
306 {
307  string result;
308  const CException *current = &error;
309  while (nullptr != current) {
310  result += current->GetMsg();
311  current = current->GetPredecessor();
312  if (current)
313  result += '\n';
314  }
315  return result;
316 }
317 
319 {
320  const CMacroDataException *pDataException = nullptr;
321  const CException *current = &error;
322  while (nullptr != current) {
323  pDataException = dynamic_cast<const CMacroDataException *>(current);
324  if (pDataException)
325  break;
326  current = current->GetPredecessor();
327  }
328  return pDataException;
329 }
330 
331 /*!
332 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FEEDBACK_BUTTON
333 */
334 
335 void CMacroErrorDlg::OnFeedbackButtonClick(wxCommandEvent& event)
336 {
337  string description;
338  description += m_ErrorTextCtrl->GetLabelText().mb_str(wxConvUTF8);
339  description += "\n\n";
340  description += "Error Details:\n";
341  description += m_ErrorDetailsCtrl->GetValue().mb_str(wxConvUTF8);
342 
343  ShowFeedbackDialog(false, description.c_str());
344 }
345 
347 
class CMacroExecException
Definition: macro_ex.hpp:146
void CreateControls()
Creates the controls and sizers.
const macro::CMacroDataException * x_FindDataException(const CException &error) const
void SetData(const string &data)
void OnErrorDetalsClicked(wxHyperlinkEvent &event)
wxEVT_COMMAND_HYPERLINK event handler for ID_ERROR_DETALS_HYPERLINKCTRL
void Init()
Initialises member variables.
void OnFeedbackButtonClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FEEDBACK_BUTTON
~CMacroErrorDlg()
Destructor.
bool Create(wxWindow *parent, wxWindowID id=ID_CMACROERRORDLG, const wxString &caption=_("Macro Error"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static bool ShowToolTips()
Should we show tooltips?
void SetMessage(const string &message)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void SetReport(const string &report)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
string x_MergeExceptionMessages(const CException &error) const
CMacroErrorDlg()
Constructors.
void SetException(const string &message, const CException &error)
void OnDataDetailsClicked(wxHyperlinkEvent &event)
wxEVT_COMMAND_HYPERLINK event handler for ID_DATA_DETAILS_HYPERLINKCTRL
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
void ShowFeedbackDialog(bool opt_out=false, const char *problem_description=nullptr)
single callable function that will show the feedback wizard, collect information, and file a report.
static void Init(void)
Definition: cursor6.c:76
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
const CException * GetPredecessor(void) const
Get "previous" exception from the backlog.
Definition: ncbiexpt.hpp:1041
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
Macro exceptions.
#define wxT(x)
Definition: muParser.cpp:41
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)
#define _ASSERT
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:57:52 2024 by modify_doxy.py rev. 669887