#include "wx/arrstr.h"
#include "wx/msgout.h"
-#if wxUSE_THREADS
- #include "wx/thread.h"
-#endif // wxUSE_THREADS
-
#ifdef __WXMSW__
// for OutputDebugString()
#include "wx/msw/private.h"
#include "wx/datetime.h"
// the suffix we add to the button to show that the dialog can be expanded
-#define EXPAND_SUFFIX _T(" >>")
+#define EXPAND_SUFFIX wxT(" >>")
#define CAN_SAVE_FILES (wxUSE_FILE && wxUSE_FILEDLG)
if ( !wxStrftime(buf, WXSIZEOF(buf), format, wxLocaltime_r(&t, &tm)) )
{
// buffer is too small?
- wxFAIL_MSG(_T("strftime() failed"));
+ wxFAIL_MSG(wxT("strftime() failed"));
}
return wxString(buf);
#else // !wxUSE_DATETIME
#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)
// ----------------------------------------------------------------------------
void wxLogGui::Flush()
{
+ wxLog::Flush();
+
if ( !m_bHasMessages )
return;
case wxLOG_Status:
#if wxUSE_STATUSBAR
{
+ wxFrame *pFrame = NULL;
+
+ // check if the frame was passed to us explicitly
+ wxUIntPtr ptr = 0;
+ 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)) ) {
#endif // CAN_SAVE_FILES
void OnClear(wxCommandEvent& event);
- // this function is safe to call from any thread (notice that it should be
- // also called from the main thread to ensure that the messages logged from
- // it appear in correct order with the messages from the other threads)
- void AddLogMessage(const wxString& message);
-
- // actually append the messages logged from secondary threads to the text
- // control during idle time in the main thread
- virtual void OnInternalIdle();
+ // do show the message in the text control
+ void ShowLogMessage(const wxString& message)
+ {
+ m_pTextCtrl->AppendText(message + wxS('\n'));
+ }
private:
// use standard ids for our commands!
// common part of OnClose() and OnCloseWindow()
void DoClose();
- // do show the message in the text control
- void DoShowLogMessage(const wxString& message)
- {
- m_pTextCtrl->AppendText(message + wxS('\n'));
- }
-
wxTextCtrl *m_pTextCtrl;
wxLogWindow *m_log;
- // queue of messages logged from other threads which need to be displayed
- wxArrayString m_pendingMessages;
-
-#if wxUSE_THREADS
- // critical section to protect access to m_pendingMessages
- wxCriticalSection m_critSection;
-#endif // wxUSE_THREADS
-
-
DECLARE_EVENT_TABLE()
wxDECLARE_NO_COPY_CLASS(wxLogFrame);
};
m_pTextCtrl->Clear();
}
-void wxLogFrame::OnInternalIdle()
-{
- {
- wxCRIT_SECT_LOCKER(locker, m_critSection);
-
- const size_t count = m_pendingMessages.size();
- for ( size_t n = 0; n < count; n++ )
- {
- DoShowLogMessage(m_pendingMessages[n]);
- }
-
- m_pendingMessages.clear();
- } // release m_critSection
-
- wxFrame::OnInternalIdle();
-}
-
-void wxLogFrame::AddLogMessage(const wxString& message)
-{
- wxCRIT_SECT_LOCKER(locker, m_critSection);
-
-#if wxUSE_THREADS
- if ( !wxThread::IsMain() || !m_pendingMessages.empty() )
- {
- // message needs to be queued for later showing
- m_pendingMessages.Add(message);
-
- wxWakeUpIdle();
- }
- else // we are the main thread and no messages are queued, so we can
- // log the message directly
-#endif // wxUSE_THREADS
- {
- DoShowLogMessage(message);
- }
-}
-
wxLogFrame::~wxLogFrame()
{
m_log->OnFrameDelete(this);
if ( level == wxLOG_Trace )
return;
- m_pLogFrame->AddLogMessage(msg);
+ m_pLogFrame->ShowLogMessage(msg);
}
wxFrame *wxLogWindow::GetFrame() const
// no need to translate these strings as they're not shown to the
// user anyhow (we use wxLC_NO_HEADER style)
- m_listctrl->InsertColumn(0, _T("Message"));
+ m_listctrl->InsertColumn(0, wxT("Message"));
if (hasTimeStamp)
- m_listctrl->InsertColumn(1, _T("Time"));
+ m_listctrl->InsertColumn(1, wxT("Time"));
// prepare the imagelist
static const int ICON_SIZE = 16;
}
if ( !rc || !file.Write(GetLogMessages()) || !file.Close() )
+ {
wxLogError(_("Can't save log contents to file."));
+ }
}
#endif // CAN_SAVE_FILES