Add information about the log message generation location to wxLog.

This means that wxLog::DoLogRecord() can now retrieve the file name, line
number and the function where the message was logged.

An unfortunate consequence of this change is that now

	if ( condition )
		wxLogError("Whatever");

results in a warning from g++ 4.x with -Wparentehses, so extra parentheses had
to be added in many places.

Finally, also allow storing arbitrary attributes in wxLogRecordInfo. This had
to be added to implement our own overloaded wxLogStatus() and wxLogSysError()
and will probably be useful for the others as well.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61363 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-07-09 20:26:34 +00:00
parent ca21a4e729
commit af58844636
27 changed files with 883 additions and 630 deletions

View File

@@ -201,60 +201,10 @@ static int OpenLogFile(wxFile& file, wxString *filename = NULL, wxWindow *parent
#endif // CAN_SAVE_FILES
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
// we use a global variable to store the frame pointer for wxLogStatus - bad,
// but it's the easiest way
static wxFrame *gs_pFrame = NULL; // FIXME MT-unsafe
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// global functions
// ----------------------------------------------------------------------------
// accepts an additional argument which tells to which frame the output should
// be directed
void wxVLogStatus(wxFrame *pFrame, const wxString& format, va_list argptr)
{
wxString msg;
wxLog *pLog = wxLog::GetActiveTarget();
if ( pLog != NULL )
{
msg.PrintfV(format, argptr);
wxASSERT( gs_pFrame == NULL ); // should be reset!
gs_pFrame = pFrame;
wxLog::OnLog(wxLOG_Status, msg);
gs_pFrame = NULL;
}
}
#if !wxUSE_UTF8_LOCALE_ONLY
void wxDoLogStatusWchar(wxFrame *pFrame, const wxChar *format, ...)
{
va_list argptr;
va_start(argptr, format);
wxVLogStatus(pFrame, format, argptr);
va_end(argptr);
}
#endif // !wxUSE_UTF8_LOCALE_ONLY
#if wxUSE_UNICODE_UTF8
void wxDoLogStatusUtf8(wxFrame *pFrame, const char *format, ...)
{
va_list argptr;
va_start(argptr, format);
wxVLogStatus(pFrame, format, argptr);
va_end(argptr);
}
#endif // wxUSE_UNICODE_UTF8
// ----------------------------------------------------------------------------
// wxLogGui implementation (FIXME MT-unsafe)
// ----------------------------------------------------------------------------
@@ -420,8 +370,16 @@ void wxLogGui::DoLogRecord(wxLogLevel level,
case wxLOG_Status:
#if wxUSE_STATUSBAR
{
wxFrame *pFrame = NULL;
// check if the frame was passed to us explicitly
wxUIntPtr ptr;
if ( info.GetNumValue(wxLOG_KEY_FRAME, &ptr) )
{
pFrame = static_cast<wxFrame *>(wxUIntToPtr(ptr));
}
// find the top window and set it's status text if it has any
wxFrame *pFrame = gs_pFrame;
if ( pFrame == NULL ) {
wxWindow *pWin = wxTheApp->GetTopWindow();
if ( pWin != NULL && pWin->IsKindOf(CLASSINFO(wxFrame)) ) {
@@ -1080,7 +1038,9 @@ void wxLogDialog::OnSave(wxCommandEvent& WXUNUSED(event))
}
if ( !rc || !file.Write(GetLogMessages()) || !file.Close() )
{
wxLogError(_("Can't save log contents to file."));
}
}
#endif // CAN_SAVE_FILES