1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2011 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//---------------------------------------------------------------------------------------
21
#include "lenmus_dlg_debug.h"
23
#include <wx/wxprec.h>
26
#include <wx/html/htmlwin.h>
27
#include <wx/gdicmn.h>
29
#include <wx/colour.h>
30
#include <wx/settings.h>
31
#include <wx/string.h>
32
#include <wx/button.h>
34
#include <wx/dialog.h>
49
BEGIN_EVENT_TABLE(DlgDebug, wxDialog)
50
EVT_BUTTON(wxID_OK, DlgDebug::OnOK)
51
EVT_BUTTON(lmID_SAVE, DlgDebug::OnSave)
54
IMPLEMENT_CLASS(DlgDebug, wxDialog)
56
DlgDebug::DlgDebug(wxWindow * parent, wxString sTitle, wxString sData, bool fSave)
57
: wxDialog(parent, -1, sTitle, wxDefaultPosition, wxSize(800, 430),
58
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
63
wxBoxSizer* pMainSizer = new wxBoxSizer(wxVERTICAL);
65
// use wxTE_RICH2 style to avoid 64kB limit under MSW and display big files
66
// faster than with wxTE_RICH
67
m_pTxtData = new wxTextCtrl(this, wxID_ANY, sData,
68
wxPoint(0, 0), wxDefaultSize,
69
wxTE_MULTILINE | wxTE_READONLY | wxTE_NOHIDESEL
72
// use fixed-width font
73
m_pTxtData->SetFont(wxFont(10, wxFONTFAMILY_TELETYPE,
74
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
76
pMainSizer->Add(m_pTxtData,
77
1, //vertically stretchable
78
wxEXPAND | //horizontally stretchable
79
wxALL, //some space border all around
80
5 ); //set border width to 5 px
82
wxBoxSizer* pButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
84
wxButton *cmdOK = new wxButton(this, wxID_OK, _("OK"));
85
pButtonsSizer->Add(cmdOK, 0, 0, 1);
91
wxButton *cmdSave = new wxButton(this, lmID_SAVE, _("Save"));
93
pButtonsSizer->Add(cmdSave, 0, 0, 1);
96
pMainSizer->Add(pButtonsSizer, 0, wxALIGN_CENTER | wxALL, 5);
98
// set autolayout based on sizers
100
SetSizer(pMainSizer);
103
DlgDebug::~DlgDebug()
107
void DlgDebug::OnOK(wxCommandEvent& WXUNUSED(event))
112
void DlgDebug::AppendText(wxString sText)
114
m_pTxtData->AppendText(sText);
117
void DlgDebug::OnSave(wxCommandEvent& WXUNUSED(event))
119
wxString sFilename = wxFileSelector(_("File to save"));
120
if ( !sFilename.empty() )
123
m_pTxtData->SaveFile(sFilename);
125
//else: cancelled by user
131
//-------------------------------------------------------------------------------------------
132
// lmHtmlDlg implementation
133
//-------------------------------------------------------------------------------------------
135
BEGIN_EVENT_TABLE(lmHtmlDlg, wxDialog)
136
EVT_BUTTON(lmID_ACCEPT, lmHtmlDlg::OnAcceptClicked )
137
EVT_BUTTON(lmID_SAVE, lmHtmlDlg::OnSaveClicked )
143
lmHtmlDlg::lmHtmlDlg(wxWindow* pParent, const wxString& sTitle, bool fSaveButton)
144
: wxDialog(pParent, wxID_ANY, sTitle, wxDefaultPosition, wxSize(600,400),
145
wxDEFAULT_DIALOG_STYLE)
147
// create the dialog controls
148
CreateControls(fSaveButton);
152
void lmHtmlDlg::CreateControls(bool fSaveButton)
154
//AWARE: Code created with wxFormBuilder and copied here.
156
// - near line 178: add 'if' to hide Save button
158
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
160
wxBoxSizer* pMainSizer;
161
pMainSizer = new wxBoxSizer( wxVERTICAL );
163
m_pHtmlWnd = new wxHtmlWindow( this, lmID_HTML_WND, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
164
pMainSizer->Add( m_pHtmlWnd, 1, wxALL|wxEXPAND, 5 );
166
wxBoxSizer* pButtonsSizer;
167
pButtonsSizer = new wxBoxSizer( wxHORIZONTAL );
169
m_pBtnAccept = new wxButton( this, lmID_ACCEPT, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
170
pButtonsSizer->Add( m_pBtnAccept, 0, wxALL, 5 );
173
pButtonsSizer->Add( 0, 0, 1, wxEXPAND, 5 );
177
m_pBtnSave = new wxButton( this, lmID_SAVE, _("Save"), wxDefaultPosition, wxDefaultSize, 0 );
178
pButtonsSizer->Add( m_pBtnSave, 0, wxALL, 5 );
181
pMainSizer->Add( pButtonsSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
183
this->SetSizer( pMainSizer );
187
lmHtmlDlg::~lmHtmlDlg()
191
void lmHtmlDlg::OnAcceptClicked(wxCommandEvent& WXUNUSED(event))
196
void lmHtmlDlg::OnSaveClicked(wxCommandEvent& WXUNUSED(event))
198
wxString sFilename = wxFileSelector(_("File to save"));
199
if ( !sFilename.empty() )
202
//m_pTxtData->SaveFile(sFilename);
204
//else: cancelled by user
208
void lmHtmlDlg::SetContent(const wxString& sContent)
210
m_pHtmlWnd->SetPage(sContent);
214
} // namespace lenmus