typedef unsigned long wxTraceMask;
typedef unsigned long wxLogLevel;
+// ----------------------------------------------------------------------------
+// forward declarations
+// ----------------------------------------------------------------------------
+class wxTextCtrl;
+class wxLogFrame;
+class wxFrame;
+class ostream;
+
// ----------------------------------------------------------------------------
// derive from this class to redirect (or suppress, or ...) log messages
// normally, only a single instance of this class exists but it's not enforced
};
// log everything to a text window (GUI only of course)
-class wxTextCtrl;
class WXDLLEXPORT wxLogTextCtrl : public wxLogStream
{
public:
// to the log window. This window has it's own menu which allows the user to
// close it, clear the log contents or save it to the file.
// ----------------------------------------------------------------------------
-class wxLogFrame;
-class wxFrame;
class WXDLLEXPORT wxLogWindow : public wxLog
{
public:
- wxLogWindow(const char *szTitle, // the title of the frame
+ wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
+ const char *szTitle, // the title of the frame
bool bShow = TRUE, // show window immediately?
bool bPassToOld = TRUE); // pass log messages to the old target?
~wxLogWindow();
DECLARE_LOG_FUNCTION(Warning);
DECLARE_LOG_FUNCTION(Message);
DECLARE_LOG_FUNCTION(Info);
-DECLARE_LOG_FUNCTION(Status);
DECLARE_LOG_FUNCTION(Verbose);
+// this function sends the log message to the status line of the top level
+// application frame, if any
+DECLARE_LOG_FUNCTION(Status);
+
+// this one is the same as previous except that it allows to explicitly
+// specify the frame to which the output should go
+DECLARE_LOG_FUNCTION2(Status, wxFrame *pFrame);
+
// additional one: as wxLogError, but also logs last system call error code
// and the corresponding error message if available
DECLARE_LOG_FUNCTION(SysError);
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 = NULL;
+ }
+}
+
// same as info, but only if 'verbose' mode is on
void wxLogVerbose(const char *szFormat, ...)
{
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;
{
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 )