/////////////////////////////////////////////////////////////////////////////
// Name:        textviewer.cpp
// Author:      Stefan Liersch
// Contact:		stefan.liersch@ufz.de stefan.liersch@googlemail.com
// Created:     2007-02-05
/////////////////////////////////////////////////////////////////////////////

#include "TextViewer.h"

// A dialog with a stretching text control
CTextViewer::CTextViewer(wxWindow *parent, wxWindowID id, const wxString &title, bool b_msgBox )
						: wxDialog(parent, id, title,
						  wxDefaultPosition, wxDefaultSize,
						  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
	m_bmsgBox = b_msgBox;
	wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
	// Create text ctrl with minimal size 100x60
	topSizer->Add(TextBox = new wxTextCtrl(this, wxID_ANY, "", 
								 wxDefaultPosition, wxSize(450,150), wxTE_MULTILINE),
								 1, // make vertically stretchable
								 wxEXPAND| // make horizontally stretchable
								 wxALL, // and make border all around
								 10 ); // set border width to 10

	wxBoxSizer *buttonSizer = new wxBoxSizer( wxHORIZONTAL );
	buttonSizer->Add(new wxButton(this, wxID_OK, "Execute" ),
								 0, // make horizontally unstretchable
								 wxALL, // make border all around: implicit top alignment
								 10 ); // set border width to 10
	
	buttonSizer->Add(new wxButton(this, wxID_CANCEL, "Cancel" ),
								 0, // make horizontally unstretchable
								 wxALL, // make border all around (implicit top alignment)
								 10 ); // set border width to 10
	
	topSizer->Add(buttonSizer,
				  0, // make vertically unstretchable
				  wxALIGN_CENTER ); // no border and centre horizontally
	if (b_msgBox)
	{
		// create message window
		wxBoxSizer *msgSizer = new wxBoxSizer( wxVERTICAL );
		topSizer->Add(MsgBox = new wxTextCtrl(this, wxID_ANY, "", 
									 wxDefaultPosition, wxSize(450,100), wxTE_MULTILINE),
									 0, // make vertically stretchable
									 wxEXPAND| // make horizontally stretchable
									 wxALL, // and make border all around
									 10 ); // set border width to 10

	}
	SetSizer( topSizer ); // use the sizer for layout
	topSizer->Fit( this ); // fit the dialog to the contents
	topSizer->SetSizeHints( this ); // set hints to honor min size
}
//---------------------------------------------------------------------

CTextViewer::~CTextViewer()
{};
//---------------------------------------------------------------------

wxString CTextViewer::Get_Text()
{
	TextBox->SelectAll();
	return (TextBox->GetStringSelection());
}
//---------------------------------------------------------------------

void CTextViewer::Set_TextBox(wxString msg, bool linefeed)
{
	TextBox->AppendText(msg);
	if (linefeed)
		TextBox->AppendText("\n");
}
//---------------------------------------------------------------------

void CTextViewer::Set_Message(wxString msg)
{
	if (m_bmsgBox)
	{
		MsgBox->AppendText(msg);
		MsgBox->AppendText("\n");
	}
}
//---------------------------------------------------------------------
void CTextViewer::Clear_MsgBox()
{
	if (m_bmsgBox) MsgBox->Clear();
}