X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f94dfb3897b96c8884210f9dc0a2cf225ab12898..2985ad5deecdcb48611ea71ac43e3c2f256c4c08:/src/generic/logg.cpp diff --git a/src/generic/logg.cpp b/src/generic/logg.cpp index 0891c8de9a..911c39c5a7 100644 --- a/src/generic/logg.cpp +++ b/src/generic/logg.cpp @@ -46,26 +46,22 @@ #include "wx/button.h" #endif // WX_PRECOMP +#if wxUSE_LOGGUI || wxUSE_LOGWINDOW + #include "wx/file.h" #include "wx/textfile.h" #include "wx/statline.h" -#if wxUSE_LOG - #ifdef __WXMSW__ // for OutputDebugString() #include "wx/msw/private.h" #endif // Windows -// may be defined to 0 for old behavior (using wxMessageBox) - shouldn't be -// changed normally (that's why it's here and not in setup.h) -#define wxUSE_LOG_DIALOG 1 - #if wxUSE_LOG_DIALOG #include "wx/listctrl.h" #include "wx/imaglist.h" #include "wx/image.h" -#else // !wxUSE_TEXTFILE +#else // !wxUSE_LOG_DIALOG #include "wx/msgdlg.h" #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG @@ -152,7 +148,7 @@ END_EVENT_TABLE() // private functions // ---------------------------------------------------------------------------- -#if wxUSE_FILE +#if wxUSE_FILE && wxUSE_FILEDLG // pass an uninitialized file object, the function will ask the user for the // filename and try to open it, returns TRUE on success (file was opened), @@ -167,7 +163,7 @@ static int OpenLogFile(wxFile& file, wxString *filename = NULL); // ---------------------------------------------------------------------------- // we use a global variable to store the frame pointer for wxLogStatus - bad, -// but it's he easiest way +// but it's the easiest way static wxFrame *gs_pFrame; // FIXME MT-unsafe // ============================================================================ @@ -198,28 +194,6 @@ void wxLogStatus(wxFrame *pFrame, const wxChar *szFormat, ...) } } -// ---------------------------------------------------------------------------- -// wxLogTextCtrl implementation -// ---------------------------------------------------------------------------- - -wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) -{ - m_pTextCtrl = pTextCtrl; -} - -void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) -{ - wxString msg; - TimeStamp(&msg); -#ifdef __WXMAC__ - msg << szString << wxT('\r'); -#else - msg << szString << wxT('\n'); -#endif - - m_pTextCtrl->AppendText(msg); -} - // ---------------------------------------------------------------------------- // wxLogGui implementation (FIXME MT-unsafe) // ---------------------------------------------------------------------------- @@ -266,7 +240,7 @@ void wxLogGui::Flush() titleFormat = _("%s Information"); style = wxICON_INFORMATION; } - + wxString title; title.Printf(titleFormat, appName.c_str()); @@ -283,6 +257,7 @@ void wxLogGui::Flush() else // more than one message { #if wxUSE_LOG_DIALOG + wxLogDialog dlg(parent, m_aMessages, m_aSeverity, m_aTimes, title, style); @@ -361,7 +336,7 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) case wxLOG_Debug: #ifdef __WXDEBUG__ { - #ifdef __WXMSW__ + #if defined(__WXMSW__) && !defined(__WXMICROWIN__) // don't prepend debug/trace here: it goes to the // debug window anyhow, but do put a timestamp wxString str; @@ -481,6 +456,7 @@ wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const wxChar *szTitle wxHSCROLL | wxTE_READONLY); +#if wxUSE_MENUS // create menu wxMenuBar *pMenuBar = new wxMenuBar; wxMenu *pMenu = new wxMenu; @@ -492,6 +468,7 @@ wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const wxChar *szTitle pMenu->Append(Menu_Close, _("&Close"), _("Close this window")); pMenuBar->Append(pMenu, _("&Log")); SetMenuBar(pMenuBar); +#endif // wxUSE_MENUS #if wxUSE_STATUSBAR // status bar for menu prompts @@ -524,6 +501,7 @@ void wxLogFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) #if wxUSE_FILE void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) { +#if wxUSE_FILEDLG wxString filename; wxFile file; int rc = OpenLogFile(file, &filename); @@ -552,6 +530,7 @@ void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) else { wxLogStatus(this, _("Log saved to the file '%s'."), filename.c_str()); } +#endif } #endif // wxUSE_FILE @@ -567,15 +546,15 @@ wxLogFrame::~wxLogFrame() // wxLogWindow // ----------- + wxLogWindow::wxLogWindow(wxFrame *pParent, const wxChar *szTitle, bool bShow, bool bDoPass) { - m_bPassMessages = bDoPass; + PassMessages(bDoPass); m_pLogFrame = new wxLogFrame(pParent, this, szTitle); - m_pOldLog = wxLog::SetActiveTarget(this); if ( bShow ) m_pLogFrame->Show(TRUE); @@ -586,21 +565,10 @@ 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 wxChar *szString, time_t t) { // first let the previous logger show it - if ( m_pOldLog != NULL && m_bPassMessages ) { - // bogus cast just to access protected DoLog - ((wxLogWindow *)m_pOldLog)->DoLog(level, szString, t); - } + wxLogPassThrough::DoLog(level, szString, t); if ( m_pLogFrame ) { switch ( level ) { @@ -673,8 +641,6 @@ void wxLogWindow::OnFrameDelete(wxFrame * WXUNUSED(frame)) wxLogWindow::~wxLogWindow() { - delete m_pOldLog; - // may be NULL if log frame already auto destroyed itself delete m_pLogFrame; } @@ -911,6 +877,7 @@ void wxLogDialog::OnOk(wxCommandEvent& WXUNUSED(event)) void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event)) { +#if wxUSE_FILEDLG wxFile file; int rc = OpenLogFile(file); if ( rc == -1 ) @@ -945,6 +912,7 @@ void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event)) if ( !ok ) wxLogError(_("Can't save log contents to file.")); +#endif } #endif // wxUSE_FILE @@ -1011,7 +979,7 @@ wxLogDialog::~wxLogDialog() #endif // wxUSE_LOG_DIALOG -#if wxUSE_FILE +#if wxUSE_FILE && wxUSE_FILEDLG // pass an uninitialized file object, the function will ask the user for the // filename and try to open it, returns TRUE on success (file was opened), @@ -1071,4 +1039,34 @@ static int OpenLogFile(wxFile& file, wxString *pFilename) #endif // wxUSE_FILE -#endif // wxUSE_LOG +#endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW) + +#if wxUSE_TEXTCTRL + +// ---------------------------------------------------------------------------- +// wxLogTextCtrl implementation +// ---------------------------------------------------------------------------- + +wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) +{ + m_pTextCtrl = pTextCtrl; +} + +void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) +{ + wxString msg; + TimeStamp(&msg); + +#ifdef __WXMAC__ + // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the + // translation must be done in wxTextCtrl, not here! (FIXME) + msg << szString << wxT('\r'); +#else + msg << szString << wxT('\n'); +#endif + + m_pTextCtrl->AppendText(msg); +} + +#endif // wxUSE_TEXTCTRL +