X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a8c693aea7d83397af67825943e2750f1723628..018e2f1300b726936e8afa41fcc3e2a85d2ed456:/src/generic/logg.cpp diff --git a/src/generic/logg.cpp b/src/generic/logg.cpp index 33849cc160..68555e35e6 100644 --- a/src/generic/logg.cpp +++ b/src/generic/logg.cpp @@ -57,15 +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/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,8 +163,8 @@ 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 -static wxFrame *gs_pFrame; // FIXME MT-unsafe +// but it's the easiest way +static wxFrame *gs_pFrame = NULL; // FIXME MT-unsafe // ============================================================================ // implementation @@ -253,6 +249,10 @@ void wxLogGui::Flush() size_t nMsgCount = m_aMessages.Count(); + // avoid showing other log dialogs until we're done with the dialog we're + // showing right now: nested modal dialogs make for really bad UI! + Suspend(); + wxString str; if ( nMsgCount == 1 ) { @@ -261,6 +261,7 @@ void wxLogGui::Flush() else // more than one message { #if wxUSE_LOG_DIALOG + wxLogDialog dlg(parent, m_aMessages, m_aSeverity, m_aTimes, title, style); @@ -298,6 +299,9 @@ void wxLogGui::Flush() // no undisplayed messages whatsoever Clear(); } + + // allow flushing the logs again + Resume(); } // log all kinds of messages @@ -339,19 +343,21 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) case wxLOG_Debug: #ifdef __WXDEBUG__ { - #ifdef __WXMSW__ + wxString str; + TimeStamp(&str); + str += szString; + + #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; - TimeStamp(&str); - str << szString << wxT("\r\n"); + // debug window anyhow + str += wxT("\r\n"); OutputDebugString(str); #else // send them to stderr - wxFprintf(stderr, wxT("%s: %s\n"), + wxFprintf(stderr, wxT("[%s] %s\n"), level == wxLOG_Trace ? wxT("Trace") : wxT("Debug"), - szString); + str.c_str()); fflush(stderr); #endif } @@ -504,6 +510,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); @@ -532,6 +539,7 @@ void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) else { wxLogStatus(this, _("Log saved to the file '%s'."), filename.c_str()); } +#endif } #endif // wxUSE_FILE @@ -547,15 +555,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); @@ -566,21 +574,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 ) { @@ -653,8 +650,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; } @@ -675,7 +670,9 @@ wxLogDialog::wxLogDialog(wxWindow *parent, const wxArrayLong& times, const wxString& caption, long style) - : wxDialog(parent, -1, caption) + : wxDialog(parent, -1, caption, + wxDefaultPosition, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { if ( ms_details.IsEmpty() ) { @@ -726,20 +723,21 @@ wxLogDialog::wxLogDialog(wxWindow *parent, // to close the log dialog with which wouldn't work otherwise (as it // translates into click on cancel button) wxButton *btnOk = new wxButton(this, wxID_CANCEL, _("OK")); - sizerButtons->Add(btnOk, 0, wxCENTRE|wxBOTTOM, MARGIN/2); + sizerButtons->Add(btnOk, 0, wxCENTRE | wxBOTTOM, MARGIN/2); m_btnDetails = new wxButton(this, wxID_MORE, ms_details + _T(" >>")); - sizerButtons->Add(m_btnDetails, 0, wxCENTRE|wxTOP, MARGIN/2 - 1); + sizerButtons->Add(m_btnDetails, 0, wxCENTRE | wxTOP, MARGIN/2 - 1); #ifndef __WIN16__ wxIcon icon = wxTheApp->GetStdIcon((int)(style & wxICON_MASK)); - sizerAll->Add(new wxStaticBitmap(this, -1, icon), 0, wxCENTRE); + sizerAll->Add(new wxStaticBitmap(this, -1, icon), 0); #endif // !Win16 const wxString& message = messages.Last(); - sizerAll->Add(CreateTextSizer(message), 0, wxCENTRE|wxLEFT|wxRIGHT, MARGIN); - sizerAll->Add(sizerButtons, 0, wxALIGN_RIGHT|wxLEFT, MARGIN); + sizerAll->Add(CreateTextSizer(message), 1, + wxALIGN_CENTRE_VERTICAL | wxLEFT | wxRIGHT, MARGIN); + sizerAll->Add(sizerButtons, 0, wxALIGN_RIGHT | wxLEFT, MARGIN); - sizerTop->Add(sizerAll, 0, wxCENTRE|wxALL, MARGIN); + sizerTop->Add(sizerAll, 0, wxALL | wxEXPAND, MARGIN); SetAutoLayout(TRUE); SetSizer(sizerTop); @@ -891,6 +889,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 ) @@ -925,6 +924,7 @@ void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event)) if ( !ok ) wxLogError(_("Can't save log contents to file.")); +#endif } #endif // wxUSE_FILE @@ -991,7 +991,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),