removed wxApp::DoInit(); added wxApp::CreateMessageOutput(); fixed wxMsgOutput memory leak

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16859 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-08-30 00:58:34 +00:00
parent 98020767fd
commit a69be60b0f
4 changed files with 71 additions and 58 deletions

View File

@@ -121,7 +121,10 @@ wxMSW:
the include path in your make/project files appropriately. Furthermore,
xpm.lib is no longer used by wxMSW, it was superseded by the wxXPMDecoder
class. You'll need to remove all references to xpm.lib from your
make/project files.
make/project files. Finally, the library names have changed as well and now
use the following consistent naming convention: wxmsw[u][d][ver].(lib|dll)
where 'u' appears for Unicode version, 'd' -- for the debug one and version
is only present for the DLLs builds.
- child frames appear in the taskbar by default now, use wxFRAME_NO_TASKBAR
style to avoid it
@@ -226,12 +229,12 @@ All (GUI):
- Added wxMouseCaptureChangedEvent
- Added custom character filtering to wxTextValidator
- wxTreeCtrl now supports incremental keyboard search
- wxMessageOutput class added
- wxHelpProvider::RemoveHelp added and called from ~wxWindowBase
so that erroneous help strings are no longer found as the hash
table fills up
- updated libpng from 1.0.3 to 1.2.4
- Added wxView::OnClosingDocument so the application can do
cleanup.
- Added wxView::OnClosingDocument so the application can do cleanup.
- generic wxListCtrl renamed to wxGenericListCtrl, wxImageList
renamed to wxGenericImageList, so they can be used on wxMSW
(Rene Rivera).

View File

@@ -43,16 +43,15 @@ class WXDLLEXPORT wxCmdLineParser;
#include "wx/window.h" // for wxTopLevelWindows
#endif // wxUSE_GUI
#if wxUSE_LOG
#include "wx/log.h"
#endif
#if WXWIN_COMPATIBILITY_2_2
#include "wx/icon.h"
#endif
#include "wx/build.h"
class WXDLLEXPORT wxLog;
class WXDLLEXPORT wxMessageOutput;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
@@ -108,10 +107,6 @@ public:
// Override: always in GUI application, rarely in console ones.
virtual bool OnInit();
// initializes wxMessageOutput; other responsibilities
// may be added later
virtual void DoInit();
#if wxUSE_GUI
// a platform-dependent version of OnInit(): the code here is likely to
// depend on the toolkit. default version does nothing.
@@ -282,14 +277,13 @@ public:
// user-defined class (default implementation creates a wxLogGui
// object) - this log object is used by default by all wxLogXXX()
// functions.
virtual wxLog *CreateLogTarget()
#if wxUSE_GUI && wxUSE_LOGGUI && !defined(__WXMICROWIN__)
{ return new wxLogGui; }
#else // !GUI
{ return new wxLogStderr; }
#endif // wxUSE_GUI
virtual wxLog *CreateLogTarget();
#endif // wxUSE_LOG
// similar to CreateLogTarget() but for the global wxMessageOutput
// object
virtual wxMessageOutput *CreateMessageOutput();
#if wxUSE_GUI
#if WXWIN_COMPATIBILITY_2_2

View File

@@ -32,6 +32,9 @@
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/list.h"
#if wxUSE_LOG
#include "wx/log.h"
#endif // wxUSE_LOG
#if wxUSE_GUI
#include "wx/msgdlg.h"
#endif // wxUSE_GUI
@@ -153,9 +156,49 @@ int wxAppBase::OnExit()
delete wxTheme::Set(NULL);
#endif // __WXUNIVERSAL__
// use Set(NULL) and not Get() to avoid creating a message output object on
// demand when we just want to delete it
delete wxMessageOutput::Set(NULL);
return 0;
}
// ----------------------------------------------------------------------------
// customization hooks
// ----------------------------------------------------------------------------
#if wxUSE_LOG
wxLog *wxAppBase::CreateLogTarget()
{
#if wxUSE_GUI && wxUSE_LOGGUI && !defined(__WXMICROWIN__)
return new wxLogGui;
#else // !GUI
return new wxLogStderr;
#endif // wxUSE_GUI
}
#endif // wxUSE_LOG
wxMessageOutput *wxAppBase::CreateMessageOutput()
{
// The standard way of printing help on command line arguments (app --help)
// is (according to common practice):
// - console apps: to stderr (on any platform)
// - GUI apps: stderr on Unix platforms (!)
// message box under Windows and others
#if wxUSE_GUI && !defined(__UNIX__)
// wxMessageOutputMessageBox doesn't work under Motif
#ifdef __WXMOTIF__
return new wxMessageOutputLog;
#else
return new wxMessageOutputMessageBox;
#endif
#else // !wxUSE_GUI || __UNIX__
return new wxMessageOutputStderr;
#endif
}
// ---------------------------------------------------------------------------
// wxAppBase
// ----------------------------------------------------------------------------
@@ -217,34 +260,12 @@ int wxAppBase::FilterEvent(wxEvent& WXUNUSED(event))
return -1;
}
void wxAppBase::DoInit()
{
if (wxMessageOutput::Get())
return;
// NB: The standard way of printing help on command line arguments (app --help)
// is (according to common practice):
// - console apps: to stderr (on any platform)
// - GUI apps: stderr on Unix platforms (!)
// message box under Windows and others
#if wxUSE_GUI && !defined(__UNIX__)
#ifdef __WXMOTIF__
wxMessageOutput::Set(new wxMessageOutputLog);
#else
wxMessageOutput::Set(new wxMessageOutputMessageBox);
#endif
#else
wxMessageOutput::Set(new wxMessageOutputStderr);
#endif
}
// ----------------------------------------------------------------------------
// cmd line parsing
// ----------------------------------------------------------------------------
bool wxAppBase::OnInit()
{
DoInit();
#if wxUSE_CMDLINE_PARSER
wxCmdLineParser parser(argc, argv);

View File

@@ -50,16 +50,11 @@ wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
wxMessageOutput* wxMessageOutput::Get()
{
// FIXME this is an hack
static bool inGet = FALSE;
if(!ms_msgOut && wxTheApp && !inGet)
if ( !ms_msgOut && wxTheApp )
{
inGet = TRUE;
wxTheApp->DoInit();
ms_msgOut = wxTheApp->CreateMessageOutput();
}
inGet = FALSE;
return ms_msgOut;
}
@@ -115,15 +110,15 @@ void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
void wxMessageOutputLog::Printf(const wxChar* format, ...)
{
wxString out;
va_list args;
va_start(args, format);
wxString out;
out.PrintfV(format, args);
va_end(args);
out.Replace(wxT("\t"),wxT(" "));
// under Motif, wxMessageDialog needs a parent window, so we use
// wxLog, which is better than nothing
::wxLogMessage(wxT("%s"), out.c_str());
}