class WXDLLIMPEXP_BASE wxFontMapperBase
{
- // For IsWxFontMapper()
- friend class WXDLLIMPEXP_CORE wxFontMapper;
public:
// constructtor and such
// ---------------------
// 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
// --------------------------------------
#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
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;
// 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
wxWindow *m_windowParent;
private:
- // pseudo-RTTI since we aren't a wxObject.
- virtual bool IsWxFontMapper();
-
DECLARE_NO_COPY_CLASS(wxFontMapper)
};
{
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)
};
#endif // wxUSE_CONFIG
}
-bool wxFontMapperBase::IsWxFontMapper()
-{ return false; }
-
/* static */
wxFontMapperBase *wxFontMapperBase::Get()
{
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
// ----------------------------------------------------------------------------
{
}
-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
#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"
{
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);
}