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

Go to the SVN repository for this file.

1 /* $Id: glinfo_demo_panel.cpp 41267 2018-06-26 17:02:49Z katargir $
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  * File Description:
29  */
30 
31 #include <ncbi_pch.hpp>
32 
33 #include <wx/sizer.h>
34 #include <wx/button.h>
35 #include <wx/textctrl.h>
36 #include <wx/filedlg.h>
37 #include <wx/msgdlg.h>
38 
42 
43 #include "glinfo_demo_panel.hpp"
44 
46 
47 #define ID_SAVE_BTN wxID_HIGHEST + 1
48 #define ID_TEXT_CTRL wxID_HIGHEST + 2
49 
50 BEGIN_EVENT_TABLE(CGlInfoDemoPanel, wxPanel)
53 
55 {
56 }
57 
58 CGlInfoDemoPanel::CGlInfoDemoPanel(wxWindow* parent, wxWindowID id)
59 {
60  Create(parent, id);
61 }
62 
63 bool CGlInfoDemoPanel::Create(wxWindow* parent, wxWindowID id)
64 {
65  wxPanel::Create(parent, id, wxDefaultPosition, wxSize(0,0), 0);
67  return true;
68 }
69 
70 class CGlInfoWindow : public CGLCanvas
71 {
72 public:
73  CGlInfoWindow(wxWindow* parent, wxWindowID id, wxTextCtrl* textCtrl) :
74  CGLCanvas(parent, id, wxDefaultPosition, wxSize(1,16)), m_TextCtrl(textCtrl) {}
75 protected:
76  virtual void x_Render();
77  wxTextCtrl* m_TextCtrl;
78 };
79 
81 {
83 
84  if (m_TextCtrl) {
85  CNcbiOstrstream ostr;
87  string str = CNcbiOstrstreamToString(ostr);
88  m_TextCtrl->AppendText(ToWxString(str));
89  m_TextCtrl->SetInsertionPoint(0);
90  m_TextCtrl = NULL;
91  }
92 }
93 
95 {
96  wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
97  wxBoxSizer *barSizer = new wxBoxSizer(wxHORIZONTAL);
98 
99  topSizer->Add(barSizer, 0, wxALIGN_RIGHT);
100 
101  wxTextCtrl *textCtrl= new wxTextCtrl(this, ID_TEXT_CTRL, wxEmptyString,
102  wxDefaultPosition, wxDefaultSize,
103  wxTE_READONLY|wxTE_MULTILINE);
104 
105  wxFont fixedFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
106  textCtrl->SetFont(fixedFont);
107 
108  topSizer->Add(textCtrl, 1, wxEXPAND);
109 
110  barSizer->Add(new CGlInfoWindow(this, wxID_ANY, textCtrl), 0, wxALIGN_CENTER_VERTICAL);
111  barSizer->Add(new wxButton(this, ID_SAVE_BTN, wxT("Save")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
112 
113  SetSizer(topSizer);
114 }
115 
116 void CGlInfoDemoPanel::OnButtonSave(wxCommandEvent& WXUNUSED(event))
117 {
118  wxFileDialog dialog(this, wxT("Save OpenGL Info"), wxEmptyString, wxEmptyString,
119  wxT("Text files (*.txt)|*.txt|All files (*.*)|*.*"),
120  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
121 
122  if (dialog.ShowModal() != wxID_OK)
123  return;
124 
125  wxTextCtrl *textCtrl= (wxTextCtrl*)FindWindow(ID_TEXT_CTRL);
126  wxString str = textCtrl->GetValue();
127  CNcbiOfstream ostr(dialog.GetPath().fn_str(), ios::out|ios::trunc);
128  if (ostr) {
129  ostr << str.ToUTF8() << endl;
130  ostr.close();
131  }
132 
133  if (ostr.fail()) {
134  wxMessageDialog msgDialog(this, wxT("Failed to save file: ") + dialog.GetFilename(),
135  wxT("Error"), wxICON_ERROR|wxOK);
136  msgDialog.ShowModal();
137  }
138 }
139 
141 
static void DumpSystemInfo(CNcbiOstream &ostr)
Dump a text formatted report of the current system configuration.
CGLCanvas.
Definition: glcanvas.hpp:55
virtual void x_Render()
Definition: glcanvas.cpp:316
bool Create(wxWindow *parent, wxWindowID id)
Creation.
void CreateControls()
Creates the controls and sizers.
CGlInfoDemoPanel()
Constructors.
void OnButtonSave(wxCommandEvent &event)
virtual void x_Render()
virtual void x_Render()
wxTextCtrl * m_TextCtrl
CGlInfoWindow(wxWindow *parent, wxWindowID id, wxTextCtrl *textCtrl)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
std::ofstream out("events_result.xml")
main entry point for tests
static int trunc
Definition: array_out.c:8
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ID_TEXT_CTRL
#define ID_SAVE_BTN
#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
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Wed Apr 17 13:10:18 2024 by modify_doxy.py rev. 669887