X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df4b7d9894cccf1d3221e07d6a98be670706ae5d..328bfc22243e3d4672ddf626db4f78e4269c7275:/src/generic/logg.cpp diff --git a/src/generic/logg.cpp b/src/generic/logg.cpp index d52e34447d..c5e260c9b2 100644 --- a/src/generic/logg.cpp +++ b/src/generic/logg.cpp @@ -46,6 +46,8 @@ #include "wx/button.h" #endif // WX_PRECOMP +#if wxUSE_LOGGUI || wxUSE_LOGWINDOW + #include "wx/file.h" #include "wx/textfile.h" #include "wx/statline.h" @@ -55,16 +57,11 @@ #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/datetime.h" #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 @@ -74,6 +71,20 @@ #if wxUSE_LOG_DIALOG +// this function is a wrapper around strftime(3) +// allows to exclude the usage of wxDateTime +static wxString TimeStamp(const wxChar *format, time_t t) +{ + wxChar buf[4096]; + if ( !wxStrftime(buf, WXSIZEOF(buf), format, localtime(&t)) ) + { + // buffer is too small? + wxFAIL_MSG(_T("strftime() failed")); + } + return wxString(buf); +} + + class wxLogDialog : public wxDialog { public: @@ -137,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), @@ -152,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 // ============================================================================ @@ -183,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) // ---------------------------------------------------------------------------- @@ -251,7 +240,7 @@ void wxLogGui::Flush() titleFormat = _("%s Information"); style = wxICON_INFORMATION; } - + wxString title; title.Printf(titleFormat, appName.c_str()); @@ -268,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); @@ -346,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; @@ -466,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; @@ -477,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 @@ -509,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); @@ -537,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 @@ -861,7 +855,7 @@ void wxLogDialog::CreateDetailsControls() m_listctrl->InsertItem(n, m_messages[n]); m_listctrl->SetItem(n, 1, - wxDateTime((time_t)m_times[n]).Format(fmt)); + TimeStamp(fmt, (time_t)m_times[n])); } // let the columns size themselves @@ -896,6 +890,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 ) @@ -917,7 +912,7 @@ void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event)) for ( size_t n = 0; ok && (n < count); n++ ) { wxString line; - line << wxDateTime((time_t)m_times[n]).Format(fmt) + line << TimeStamp(fmt, (time_t)m_times[n]) << _T(": ") << m_messages[n] << wxTextFile::GetEOL(); @@ -930,6 +925,7 @@ void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event)) if ( !ok ) wxLogError(_("Can't save log contents to file.")); +#endif } #endif // wxUSE_FILE @@ -996,7 +992,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), @@ -1056,3 +1052,34 @@ static int OpenLogFile(wxFile& file, wxString *pFilename) #endif // wxUSE_FILE +#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 +