X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fe7b115601ec33076852d3881093138a0794a7a1..6f34921d9369a31de14e4b07e4824e2d701710f0:/src/common/log.cpp?ds=sidebyside diff --git a/src/common/log.cpp b/src/common/log.cpp index d1e30401d4..bf1994214f 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -33,6 +33,7 @@ #include #include #include + #include #include #include @@ -66,6 +67,14 @@ static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz); #endif +// ---------------------------------------------------------------------------- +// global variables +// ---------------------------------------------------------------------------- + +// we use a global variable to store the frame pointer for wxLogStatus - bad, +// but it's he easiest way +static wxFrame *gs_pFrame; + // ============================================================================ // implementation // ============================================================================ @@ -117,6 +126,24 @@ IMPLEMENT_LOG_FUNCTION(Message) IMPLEMENT_LOG_FUNCTION(Info) IMPLEMENT_LOG_FUNCTION(Status) +// accepts an additional argument which tells to which frame the output should +// be directed +void wxLogStatus(wxFrame *pFrame, const char *szFormat, ...) +{ + wxLog *pLog = wxLog::GetActiveTarget(); + if ( pLog != NULL ) { + va_list argptr; + va_start(argptr, szFormat); + vsprintf(s_szBuf, szFormat, argptr); + va_end(argptr); + + wxASSERT( gs_pFrame == NULL ); // should be reset! + gs_pFrame = pFrame; + wxLog::OnLog(wxLOG_Status, s_szBuf); + gs_pFrame = (wxFrame *) NULL; + } +} + // same as info, but only if 'verbose' mode is on void wxLogVerbose(const char *szFormat, ...) { @@ -394,17 +421,20 @@ void wxLogGui::Flush() if ( !m_bHasMessages ) return; + // do it right now to block any new calls to Flush() while we're here + m_bHasMessages = FALSE; + // @@@ ugly... // concatenate all strings (but not too many to not overfill the msg box) wxString str; - uint nLines = 0, + size_t nLines = 0, nMsgCount = m_aMessages.Count(); // start from the most recent message - for ( uint n = nMsgCount; n > 0; n-- ) { + for ( size_t n = nMsgCount; n > 0; n-- ) { // for Windows strings longer than this value are wrapped (NT 4.0) - const uint nMsgLineWidth = 156; + const size_t nMsgLineWidth = 156; nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth; @@ -422,7 +452,6 @@ void wxLogGui::Flush() } // no undisplayed messages whatsoever - m_bHasMessages = m_bErrors = FALSE; m_aMessages.Empty(); } @@ -444,11 +473,16 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString) case wxLOG_Status: { // find the top window and set it's status text if it has any - wxWindow *pWin = wxTheApp->GetTopWindow(); - if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) { - wxFrame *pFrame = (wxFrame *)pWin; - pFrame->SetStatusText(szString); + wxFrame *pFrame = gs_pFrame; + if ( pFrame == NULL ) { + wxWindow *pWin = wxTheApp->GetTopWindow(); + if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) { + pFrame = (wxFrame *)pWin; + } } + + if ( pFrame != NULL ) + pFrame->SetStatusText(szString); } break; @@ -458,7 +492,7 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString) { wxString strTime = TimeStamp(); - #ifdef __WIN32__ + #if defined(__WIN32__) && !defined(__WXSTUBS__) // don't prepend debug/trace here: it goes to the debug window // anyhow, but do put a timestamp OutputDebugString(strTime + szString + "\n\r"); @@ -506,7 +540,7 @@ class wxLogFrame : public wxFrame { public: // ctor & dtor - wxLogFrame(wxLogWindow *log, const char *szTitle); + wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle); virtual ~wxLogFrame(); // menu callbacks @@ -544,12 +578,10 @@ BEGIN_EVENT_TABLE(wxLogFrame, wxFrame) EVT_MENU(Menu_Clear, wxLogFrame::OnClear) EVT_CLOSE(wxLogFrame::OnCloseWindow) - - EVT_IDLE(wxLogFrame::OnIdle) END_EVENT_TABLE() -wxLogFrame::wxLogFrame(wxLogWindow *log, const char *szTitle) - : wxFrame(NULL, -1, szTitle) +wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle) + : wxFrame(pParent, -1, szTitle) { m_log = log; @@ -557,14 +589,10 @@ wxLogFrame::wxLogFrame(wxLogWindow *log, const char *szTitle) // a rich edit control instead of a normal one we want in wxMSW m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, - wxSIMPLE_BORDER | + //wxSIMPLE_BORDER | wxTE_MULTILINE | wxHSCROLL | wxTE_READONLY); - /* - m_pTextCtrl->SetEditable(FALSE); - m_pTextCtrl->SetRichEdit(FALSE); - */ // create menu wxMenuBar *pMenuBar = new wxMenuBar; @@ -592,14 +620,6 @@ void wxLogFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) DoClose(); } -void wxLogFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) -{ - // if we're the last frame to stay, delete log frame letting the - // application to close - if ( wxTopLevelWindows.Number() == 1 ) - Destroy(); -} - void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) { // get the file name @@ -679,11 +699,14 @@ wxLogFrame::~wxLogFrame() // wxLogWindow // ----------- -wxLogWindow::wxLogWindow(const char *szTitle, bool bShow, bool bDoPass) +wxLogWindow::wxLogWindow(wxFrame *pParent, + const char *szTitle, + bool bShow, + bool bDoPass) { m_bPassMessages = bDoPass; - m_pLogFrame = new wxLogFrame(this, szTitle); + m_pLogFrame = new wxLogFrame(pParent, this, szTitle); m_pOldLog = wxLog::SetActiveTarget(this); if ( bShow ) @@ -714,8 +737,14 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString) ((wxLogWindow *)m_pOldLog)->DoLog(level, szString); } - // and this will format it nicely and call our DoLogString() - wxLog::DoLog(level, szString); + // 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 + if ( m_pLogFrame && level != wxLOG_Trace ) { + // and this will format it nicely and call our DoLogString() + wxLog::DoLog(level, szString); + } m_bHasMessages = TRUE; } @@ -749,16 +778,13 @@ void wxLogWindow::OnFrameCreate(wxFrame *frame) void wxLogWindow::OnFrameDelete(wxFrame *frame) { - m_pLogFrame = NULL; + m_pLogFrame = (wxLogFrame *) NULL; } wxLogWindow::~wxLogWindow() { // may be NULL if log frame already auto destroyed itself delete m_pLogFrame; - - // delete the old log - delete m_pOldLog; } #endif //WX_TEST_MINIMAL @@ -770,7 +796,7 @@ wxLogWindow::~wxLogWindow() // ---------------------------------------------------------------------------- // static variables // ---------------------------------------------------------------------------- -wxLog *wxLog::ms_pLogger = NULL; +wxLog *wxLog::ms_pLogger = (wxLog *) NULL; bool wxLog::ms_bAutoCreate = TRUE; wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; @@ -882,6 +908,8 @@ void Trap() { #ifdef __WXMSW__ DebugBreak(); + #elif defined(__WXSTUBS__) + // TODO #else // Unix raise(SIGTRAP); #endif // Win/Unix