wxLogWindoe changed again: now takes a parent frame in ctor

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@537 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1998-08-14 21:49:27 +00:00
parent 1845330624
commit 470b7da353
2 changed files with 62 additions and 29 deletions

View File

@ -49,6 +49,14 @@ enum
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
@ -166,7 +174,6 @@ protected:
};
// log everything to a text window (GUI only of course)
class wxTextCtrl;
class WXDLLEXPORT wxLogTextCtrl : public wxLogStream
{
public:
@ -200,12 +207,11 @@ protected:
// 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();
@ -302,9 +308,16 @@ DECLARE_LOG_FUNCTION(Error);
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);

View File

@ -66,6 +66,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 +125,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 = NULL;
}
}
// same as info, but only if 'verbose' mode is on
void wxLogVerbose(const char *szFormat, ...)
{
@ -444,11 +470,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;
@ -506,7 +537,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 +575,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 +586,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 +617,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 +696,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 )