#include <wx/string.h>
#include <wx/intl.h>
#include <wx/menu.h>
+ #include <wx/frame.h>
#include <wx/generic/msgdlgg.h>
#include <wx/filedlg.h>
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
// ============================================================================
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, ...)
{
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;
}
// no undisplayed messages whatsoever
- m_bHasMessages =
m_bErrors = FALSE;
m_aMessages.Empty();
}
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;
{
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");
{
public:
// ctor & dtor
- wxLogFrame(wxLogWindow *log, const char *szTitle);
+ wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle);
virtual ~wxLogFrame();
// menu callbacks
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;
// 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;
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
// 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 )
((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;
}
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
// ----------------------------------------------------------------------------
// static variables
// ----------------------------------------------------------------------------
-wxLog *wxLog::ms_pLogger = NULL;
+wxLog *wxLog::ms_pLogger = (wxLog *) NULL;
bool wxLog::ms_bAutoCreate = TRUE;
wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
{
#ifdef __WXMSW__
DebugBreak();
+ #elif defined(__WXSTUBS__)
+ // TODO
#else // Unix
raise(SIGTRAP);
#endif // Win/Unix