1. renamed wxFontMapper::IsWxFontMapper() to IsDummy() (with reverse semantics)
2. added wxFontMapper::Reset() to only do the cast needed when deleting the font mapper object once 3. reset the dummy font mapper created during the app initialization in wxFontMapperModule and not in init.cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39624 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4e3e485bc8
commit
d5bfbd9ab8
@ -49,8 +49,6 @@ class WXDLLIMPEXP_CORE wxFontMapper;
|
||||
|
||||
class WXDLLIMPEXP_BASE wxFontMapperBase
|
||||
{
|
||||
// For IsWxFontMapper()
|
||||
friend class WXDLLIMPEXP_CORE wxFontMapper;
|
||||
public:
|
||||
// constructtor and such
|
||||
// ---------------------
|
||||
@ -70,6 +68,10 @@ public:
|
||||
// set the singleton to 'mapper' instance and return previous one
|
||||
static wxFontMapper *Set(wxFontMapper *mapper);
|
||||
|
||||
// delete the existing font mapper if any
|
||||
static void Reset();
|
||||
|
||||
|
||||
// translates charset strings to encoding
|
||||
// --------------------------------------
|
||||
|
||||
@ -124,6 +126,10 @@ public:
|
||||
#endif // wxUSE_CONFIG
|
||||
|
||||
|
||||
// returns true for the base class and false for a "real" font mapper object
|
||||
// (implementation-only)
|
||||
virtual bool IsDummy() { return true; }
|
||||
|
||||
protected:
|
||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||
// get the config object we're using -- either the global config object
|
||||
@ -159,9 +165,6 @@ protected:
|
||||
int NonInteractiveCharsetToEncoding(const wxString& charset);
|
||||
|
||||
private:
|
||||
// pseudo-RTTI since we aren't a wxObject.
|
||||
virtual bool IsWxFontMapper();
|
||||
|
||||
// the global fontmapper object or NULL
|
||||
static wxFontMapper *sm_instance;
|
||||
|
||||
@ -239,6 +242,9 @@ public:
|
||||
// are additional methods in the subclass.
|
||||
static wxFontMapper *Get();
|
||||
|
||||
// pseudo-RTTI since we aren't a wxObject.
|
||||
virtual bool IsDummy() { return false; }
|
||||
|
||||
protected:
|
||||
// GetAltForEncoding() helper: tests for the existence of the given
|
||||
// encoding and saves the result in config if ok - this results in the
|
||||
@ -258,9 +264,6 @@ protected:
|
||||
wxWindow *m_windowParent;
|
||||
|
||||
private:
|
||||
// pseudo-RTTI since we aren't a wxObject.
|
||||
virtual bool IsWxFontMapper();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxFontMapper)
|
||||
};
|
||||
|
||||
|
@ -233,8 +233,25 @@ class wxFontMapperModule : public wxModule
|
||||
{
|
||||
public:
|
||||
wxFontMapperModule() : wxModule() { }
|
||||
virtual bool OnInit() { return true; }
|
||||
virtual void OnExit() { delete (wxFontMapperBase*)wxFontMapperBase::Set(NULL); }
|
||||
|
||||
virtual bool OnInit()
|
||||
{
|
||||
// a dummy wxFontMapperBase object could have been created during the
|
||||
// program startup before wxApp was created, we have to delete it to
|
||||
// allow creating the real font mapper next time it is needed now that
|
||||
// we can create it (when the modules are initialized, wxApp object
|
||||
// already exists)
|
||||
wxFontMapperBase *fm = wxFontMapperBase::Get();
|
||||
if ( fm && fm->IsDummy() )
|
||||
wxFontMapperBase::Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnExit()
|
||||
{
|
||||
wxFontMapperBase::Reset();
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxFontMapperModule)
|
||||
};
|
||||
@ -267,9 +284,6 @@ wxFontMapperBase::~wxFontMapperBase()
|
||||
#endif // wxUSE_CONFIG
|
||||
}
|
||||
|
||||
bool wxFontMapperBase::IsWxFontMapper()
|
||||
{ return false; }
|
||||
|
||||
/* static */
|
||||
wxFontMapperBase *wxFontMapperBase::Get()
|
||||
{
|
||||
@ -303,6 +317,19 @@ wxFontMapper *wxFontMapperBase::Set(wxFontMapper *mapper)
|
||||
return old;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void wxFontMapperBase::Reset()
|
||||
{
|
||||
if ( sm_instance )
|
||||
{
|
||||
// we need a cast as wxFontMapper is not fully declared here and so the
|
||||
// compiler can't know that it derives from wxFontMapperBase (but
|
||||
// run-time behaviour will be correct because the dtor is virtual)
|
||||
delete sm_instance;
|
||||
sm_instance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -160,17 +160,17 @@ wxFontMapper::~wxFontMapper()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxFontMapper::IsWxFontMapper()
|
||||
{ return true; }
|
||||
|
||||
/* static */
|
||||
wxFontMapper *wxFontMapper::Get()
|
||||
{
|
||||
wxFontMapperBase *fontmapper = wxFontMapperBase::Get();
|
||||
wxASSERT_MSG(fontmapper->IsWxFontMapper(), wxT("GUI code requested a wxFontMapper but we only have a wxFontMapperBase."));
|
||||
wxASSERT_MSG( !fontmapper->IsDummy(),
|
||||
wxT("GUI code requested a wxFontMapper but we only have a wxFontMapperBase.") );
|
||||
|
||||
// Now return it anyway because there's a chance the GUI code might just
|
||||
// only want to call wxFontMapperBase functions.
|
||||
return (wxFontMapper*)fontmapper;
|
||||
// only want to call wxFontMapperBase functions and it's better than
|
||||
// crashing by returning NULL
|
||||
return (wxFontMapper *)fontmapper;
|
||||
}
|
||||
|
||||
wxFontEncoding
|
||||
|
@ -36,9 +36,6 @@
|
||||
#include "wx/ptr_scpd.h"
|
||||
#include "wx/module.h"
|
||||
#include "wx/except.h"
|
||||
#if wxUSE_FONTMAP
|
||||
#include "wx/fontmap.h"
|
||||
#endif
|
||||
|
||||
#if defined(__WXMSW__) && defined(__WXDEBUG__)
|
||||
#include "wx/msw/msvcrt.h"
|
||||
@ -452,13 +449,6 @@ int wxEntry(int& argc, char **argv)
|
||||
{
|
||||
ConvertArgsToUnicode(argc, argv);
|
||||
|
||||
#if wxUSE_FONTMAP
|
||||
// If we created a font mapper during the above call,
|
||||
// it will only be the base class, so delete it to allow
|
||||
// app traits to create mapper.
|
||||
delete (wxFontMapperBase*) wxFontMapperBase::Set(NULL);
|
||||
#endif
|
||||
|
||||
return wxEntry(argc, gs_initData.argv);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user