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

@@ -91,7 +91,7 @@ All (GUI):
- wxGridCellAttrProvider class API changed, you will need to update your code - wxGridCellAttrProvider class API changed, you will need to update your code
if you derived any classes from it if you derived any classes from it
- wxImage::ComputeHistogram()'s signature changed to - wxImage::ComputeHistogram()'s signature changed to
unsigned long ComputeHistogram(wxImageHistogram&) const unsigned long ComputeHistogram(wxImageHistogram&) const
- wxEvtHandler cannot be copied/assigned any longer - this never worked but - wxEvtHandler cannot be copied/assigned any longer - this never worked but
@@ -120,8 +120,11 @@ wxMSW:
where <toolkit> is of the form (msw|univ)[dll][u][d]. You'll need to update where <toolkit> is of the form (msw|univ)[dll][u][d]. You'll need to update
the include path in your make/project files appropriately. Furthermore, the include path in your make/project files appropriately. Furthermore,
xpm.lib is no longer used by wxMSW, it was superseded by the wxXPMDecoder 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 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 - child frames appear in the taskbar by default now, use wxFRAME_NO_TASKBAR
style to avoid it style to avoid it
@@ -226,12 +229,12 @@ All (GUI):
- Added wxMouseCaptureChangedEvent - Added wxMouseCaptureChangedEvent
- Added custom character filtering to wxTextValidator - Added custom character filtering to wxTextValidator
- wxTreeCtrl now supports incremental keyboard search - wxTreeCtrl now supports incremental keyboard search
- wxMessageOutput class added
- wxHelpProvider::RemoveHelp added and called from ~wxWindowBase - wxHelpProvider::RemoveHelp added and called from ~wxWindowBase
so that erroneous help strings are no longer found as the hash so that erroneous help strings are no longer found as the hash
table fills up table fills up
- updated libpng from 1.0.3 to 1.2.4 - updated libpng from 1.0.3 to 1.2.4
- Added wxView::OnClosingDocument so the application can do - Added wxView::OnClosingDocument so the application can do cleanup.
cleanup.
- generic wxListCtrl renamed to wxGenericListCtrl, wxImageList - generic wxListCtrl renamed to wxGenericListCtrl, wxImageList
renamed to wxGenericImageList, so they can be used on wxMSW renamed to wxGenericImageList, so they can be used on wxMSW
(Rene Rivera). (Rene Rivera).
@@ -280,7 +283,7 @@ wxGTK:
- wxButton now honours wxBU_EXACTFIT - wxButton now honours wxBU_EXACTFIT
- wxStaticBox now honours wxALIGN_XXX styles - wxStaticBox now honours wxALIGN_XXX styles
- added support for non alphanumeric simple character accelerators ('-', '=') - added support for non alphanumeric simple character accelerators ('-', '=')
- new behaviour for wxWindow::Refresh() as it now produces a delayed refresh. - new behaviour for wxWindow::Refresh() as it now produces a delayed refresh.
Call the new wxWindow::Update() to force an immediate update Call the new wxWindow::Update() to force an immediate update
- support for more SGI hardware (12-bit mode among others) - support for more SGI hardware (12-bit mode among others)
- fixed wxDC::Blit() to honour source DC's logical coordinates - fixed wxDC::Blit() to honour source DC's logical coordinates

View File

@@ -43,16 +43,15 @@ class WXDLLEXPORT wxCmdLineParser;
#include "wx/window.h" // for wxTopLevelWindows #include "wx/window.h" // for wxTopLevelWindows
#endif // wxUSE_GUI #endif // wxUSE_GUI
#if wxUSE_LOG
#include "wx/log.h"
#endif
#if WXWIN_COMPATIBILITY_2_2 #if WXWIN_COMPATIBILITY_2_2
#include "wx/icon.h" #include "wx/icon.h"
#endif #endif
#include "wx/build.h" #include "wx/build.h"
class WXDLLEXPORT wxLog;
class WXDLLEXPORT wxMessageOutput;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -72,9 +71,9 @@ class WXDLLEXPORT wxDisplayModeInfo
{ {
public: public:
wxDisplayModeInfo() : m_ok(FALSE) {} wxDisplayModeInfo() : m_ok(FALSE) {}
wxDisplayModeInfo(unsigned width, unsigned height, unsigned depth) wxDisplayModeInfo(unsigned width, unsigned height, unsigned depth)
: m_width(width), m_height(height), m_depth(depth), m_ok(TRUE) {} : m_width(width), m_height(height), m_depth(depth), m_ok(TRUE) {}
unsigned GetWidth() const { return m_width; } unsigned GetWidth() const { return m_width; }
unsigned GetHeight() const { return m_height; } unsigned GetHeight() const { return m_height; }
unsigned GetDepth() const { return m_depth; } unsigned GetDepth() const { return m_depth; }
@@ -93,7 +92,7 @@ private:
class WXDLLEXPORT wxAppBase : public wxEvtHandler class WXDLLEXPORT wxAppBase : public wxEvtHandler
{ {
DECLARE_NO_COPY_CLASS(wxAppBase) DECLARE_NO_COPY_CLASS(wxAppBase)
public: public:
wxAppBase(); wxAppBase();
virtual ~wxAppBase(); virtual ~wxAppBase();
@@ -108,10 +107,6 @@ public:
// Override: always in GUI application, rarely in console ones. // Override: always in GUI application, rarely in console ones.
virtual bool OnInit(); virtual bool OnInit();
// initializes wxMessageOutput; other responsibilities
// may be added later
virtual void DoInit();
#if wxUSE_GUI #if wxUSE_GUI
// a platform-dependent version of OnInit(): the code here is likely to // a platform-dependent version of OnInit(): the code here is likely to
// depend on the toolkit. default version does nothing. // depend on the toolkit. default version does nothing.
@@ -282,22 +277,21 @@ public:
// user-defined class (default implementation creates a wxLogGui // user-defined class (default implementation creates a wxLogGui
// object) - this log object is used by default by all wxLogXXX() // object) - this log object is used by default by all wxLogXXX()
// functions. // functions.
virtual wxLog *CreateLogTarget() virtual wxLog *CreateLogTarget();
#if wxUSE_GUI && wxUSE_LOGGUI && !defined(__WXMICROWIN__)
{ return new wxLogGui; }
#else // !GUI
{ return new wxLogStderr; }
#endif // wxUSE_GUI
#endif // wxUSE_LOG #endif // wxUSE_LOG
// similar to CreateLogTarget() but for the global wxMessageOutput
// object
virtual wxMessageOutput *CreateMessageOutput();
#if wxUSE_GUI #if wxUSE_GUI
#if WXWIN_COMPATIBILITY_2_2 #if WXWIN_COMPATIBILITY_2_2
// get the standard icon used by wxWin dialogs - this allows the user // get the standard icon used by wxWin dialogs - this allows the user
// to customize the standard dialogs. The 'which' parameter is one of // to customize the standard dialogs. The 'which' parameter is one of
// wxICON_XXX values // wxICON_XXX values
virtual wxIcon GetStdIcon(int WXUNUSED(which)) const { return wxNullIcon; } virtual wxIcon GetStdIcon(int WXUNUSED(which)) const { return wxNullIcon; }
#endif #endif
// Get display mode that is used use. This is only used in framebuffer wxWin ports // Get display mode that is used use. This is only used in framebuffer wxWin ports
// (such as wxMGL). // (such as wxMGL).
@@ -389,7 +383,7 @@ protected:
wxString m_vendorName, // vendor name (ACME Inc) wxString m_vendorName, // vendor name (ACME Inc)
m_appName, // app name m_appName, // app name
m_className; // class name m_className; // class name
#if wxUSE_GUI #if wxUSE_GUI
// the main top level window - may be NULL // the main top level window - may be NULL
wxWindow *m_topWindow; wxWindow *m_topWindow;

View File

@@ -32,6 +32,9 @@
#include "wx/app.h" #include "wx/app.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/list.h" #include "wx/list.h"
#if wxUSE_LOG
#include "wx/log.h"
#endif // wxUSE_LOG
#if wxUSE_GUI #if wxUSE_GUI
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#endif // wxUSE_GUI #endif // wxUSE_GUI
@@ -153,9 +156,49 @@ int wxAppBase::OnExit()
delete wxTheme::Set(NULL); delete wxTheme::Set(NULL);
#endif // __WXUNIVERSAL__ #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; 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 // wxAppBase
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -217,34 +260,12 @@ int wxAppBase::FilterEvent(wxEvent& WXUNUSED(event))
return -1; 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 // cmd line parsing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxAppBase::OnInit() bool wxAppBase::OnInit()
{ {
DoInit();
#if wxUSE_CMDLINE_PARSER #if wxUSE_CMDLINE_PARSER
wxCmdLineParser parser(argc, argv); wxCmdLineParser parser(argc, argv);

View File

@@ -50,16 +50,11 @@ wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
wxMessageOutput* wxMessageOutput::Get() wxMessageOutput* wxMessageOutput::Get()
{ {
// FIXME this is an hack if ( !ms_msgOut && wxTheApp )
static bool inGet = FALSE;
if(!ms_msgOut && wxTheApp && !inGet)
{ {
inGet = TRUE; ms_msgOut = wxTheApp->CreateMessageOutput();
wxTheApp->DoInit();
} }
inGet = FALSE;
return ms_msgOut; return ms_msgOut;
} }
@@ -115,15 +110,15 @@ void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
void wxMessageOutputLog::Printf(const wxChar* format, ...) void wxMessageOutputLog::Printf(const wxChar* format, ...)
{ {
wxString out;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
wxString out;
out.PrintfV(format, args); out.PrintfV(format, args);
va_end(args); va_end(args);
out.Replace(wxT("\t"),wxT(" ")); 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()); ::wxLogMessage(wxT("%s"), out.c_str());
} }