- 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& WXUNUSED(event))
-{
- m_pTextCtrl->Clear();
-}
-
-wxLogFrame::~wxLogFrame()
-{
- m_log->OnFrameDelete(this);
-}
-
-// wxLogWindow
-// -----------
-wxLogWindow::wxLogWindow(wxFrame *pParent,
- const char *szTitle,
- bool bShow,
- bool bDoPass)
-{
- m_bPassMessages = bDoPass;
-
- m_pLogFrame = new wxLogFrame(pParent, this, szTitle);
- m_pOldLog = wxLog::SetActiveTarget(this);
-
- if ( bShow )
- m_pLogFrame->Show(TRUE);
-}
-
-void wxLogWindow::Show(bool bShow)
-{
- m_pLogFrame->Show(bShow);
-}
-
-void wxLogWindow::Flush()
-{
- if ( m_pOldLog != NULL )
- m_pOldLog->Flush();
-
- m_bHasMessages = FALSE;
-}
-
-void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
-{
- // first let the previous logger show it
- if ( m_pOldLog != NULL && m_bPassMessages ) {
- // @@@ why can't we access protected wxLog method from here (we derive
- // from wxLog)? gcc gives "DoLog is protected in this context", what
- // does this mean? Anyhow, the cast is harmless and let's us do what
- // we want.
- ((wxLogWindow *)m_pOldLog)->DoLog(level, szString);
- }
-
- if ( m_pLogFrame ) {
- switch ( level ) {
- case wxLOG_Status:
- // by default, these messages are ignored by wxLog, so process
- // them ourselves
- {
- wxString str = TimeStamp();
- str << _("Status: ") << szString;
- DoLogString(str);
- }
- break;
-
- // don't put trace messages in the text window for 2 reasons:
- // 1) there are too many of them
- // 2) they may provoke other trace messages thus sending a program
- // into an infinite loop
- case wxLOG_Trace:
- break;
-
- default:
- // and this will format it nicely and call our DoLogString()
- wxLog::DoLog(level, szString);
- }
- }
-
- m_bHasMessages = TRUE;
-}
-
-void wxLogWindow::DoLogString(const char *szString)
-{
- // put the text into our window
- wxTextCtrl *pText = m_pLogFrame->TextCtrl();
-
- // remove selection (WriteText is in fact ReplaceSelection)
- #ifdef __WXMSW__
- long nLen = pText->GetLastPosition();
- pText->SetSelection(nLen, nLen);
- #endif // Windows
-
- pText->WriteText(szString);
- pText->WriteText("\n"); // "\n" ok here (_not_ "\r\n")
-
- // TODO ensure that the line can be seen
-}
-
-wxFrame *wxLogWindow::GetFrame() const
-{
- return m_pLogFrame;
-}
-
-void wxLogWindow::OnFrameCreate(wxFrame *WXUNUSED(frame))
-{
-}
-
-void wxLogWindow::OnFrameDelete(wxFrame *WXUNUSED(frame))
-{
- m_pLogFrame = (wxLogFrame *)NULL;
-}
-
-wxLogWindow::~wxLogWindow()
-{
- delete m_pOldLog;
-
- // may be NULL if log frame already auto destroyed itself
- delete m_pLogFrame;
-}
-
-#endif //wxUSE_NOGUI