-// log frame class
-class wxLogFrame : public wxFrame
-{
-public:
- // ctor
- wxLogFrame(const char *szTitle);
-
- // menu callbacks
- void OnClose(wxCommandEvent& event);
- void OnCloseWindow(wxCloseEvent& event);
- void OnSave (wxCommandEvent& event);
- void OnClear(wxCommandEvent& event);
-
- // accessors
- wxTextCtrl *TextCtrl() const { return m_pTextCtrl; }
-
-private:
- enum
- {
- Menu_Close = 100,
- Menu_Save,
- Menu_Clear
- };
-
- wxTextCtrl *m_pTextCtrl;
-
- DECLARE_EVENT_TABLE()
-};
-
-BEGIN_EVENT_TABLE(wxLogFrame, wxFrame)
- // wxLogWindow menu events
- EVT_MENU(Menu_Close, wxLogFrame::OnClose)
- EVT_MENU(Menu_Save, wxLogFrame::OnSave)
- EVT_MENU(Menu_Clear, wxLogFrame::OnClear)
-
- EVT_CLOSE(wxLogFrame::OnCloseWindow)
-END_EVENT_TABLE()
-
-wxLogFrame::wxLogFrame(const char *szTitle)
- : wxFrame(NULL, -1, szTitle)
-{
- // we don't want to be a top-level frame because it would prevent the
- // application termination when all other frames are closed
- wxTopLevelWindows.DeleteObject(this);
-
- // @@ kludge: wxSIMPLE_BORDER is simply to prevent wxWindows from creating
- // a rich edit control instead of a normal one we want
- m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition,
- wxDefaultSize,
- wxSIMPLE_BORDER |
- wxTE_MULTILINE |
- wxHSCROLL |
- wxTE_READONLY);
- /*
- m_pTextCtrl->SetEditable(FALSE);
- m_pTextCtrl->SetRichEdit(FALSE);
- */
-
- // create menu
- wxMenuBar *pMenuBar = new wxMenuBar;
- wxMenu *pMenu = new wxMenu;
- pMenu->Append(Menu_Save, "&Save...");
- pMenu->Append(Menu_Clear, "C&lear");
- pMenu->AppendSeparator();
- pMenu->Append(Menu_Close, "&Close");
- pMenuBar->Append(pMenu, "&Log");
- SetMenuBar(pMenuBar);
-
- // @@ what about status bar? needed (for menu prompts)?
-}
-
-void wxLogFrame::OnClose(wxCommandEvent& event)
-{
- // just hide the window
- Show(FALSE);
-}
-
-void wxLogFrame::OnCloseWindow(wxCloseEvent& event)
-{
- // just hide the window
- Show(FALSE);
-}
-
-void wxLogFrame::OnSave(wxCommandEvent& event)
-{
- // get the file name
- // -----------------
- const char *szFileName = wxSaveFileSelector("log", "txt", "log.txt");
- if ( szFileName == NULL ) {
- // cancelled
- return;
- }
-
- // open file
- // ---------
- wxFile file;
- bool bOk;
- if ( wxFile::Exists(szFileName) ) {
- bool bAppend;
- wxString strMsg;
- strMsg.Printf(_("Append log to file '%s' "
- "(choosing [No] will overwrite it)?"), szFileName);
- switch ( wxMessageBox(strMsg, "Question", wxYES_NO | wxCANCEL) ) {
- case wxYES:
- bAppend = TRUE;
- break;
-
- case wxNO:
- bAppend = FALSE;
- break;
-
- case wxCANCEL:
- return;
-
- default:
- wxFAIL_MSG("invalid message box return value");
- }
-
- if ( bAppend ) {
- bOk = file.Open(szFileName, wxFile::write_append);
- }
- else {
- bOk = file.Create(szFileName, TRUE /* overwrite */);
- }
- }
- else {
- bOk = file.Create(szFileName);
- }
-
- // retrieve text and save it
- // -------------------------
-
-#ifdef __WXGTK__
- // @@@@ TODO: no GetNumberOfLines and GetLineText in wxGTK yet
- wxLogError("Sorry, this function is not implemented under GTK");
-#else
- int nLines = m_pTextCtrl->GetNumberOfLines();
- for ( int nLine = 0; bOk && nLine < nLines; nLine++ ) {
- bOk = file.Write(m_pTextCtrl->GetLineText(nLine) + wxTextFile::GetEOL());
- }
-#endif //GTK
-
- if ( bOk )
- bOk = file.Close();
-
- if ( !bOk ) {
- wxLogError("Can't save log contents to file.");
- return;
- }
-}
-
-void wxLogFrame::OnClear(wxCommandEvent& event)
-{
- m_pTextCtrl->Clear();
-}
-
-wxLogWindow::wxLogWindow(const wxTString& strTitle, bool bShow)