1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FONTMAPPER_H_
13 #define _WX_FONTMAPPER_H_
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "fontmap.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
25 #include "wx/fontenc.h" // for wxFontEncoding
28 #include "wx/fontutil.h" // for wxNativeEncodingInfo
32 class WXDLLEXPORT wxConfigBase
;
33 #endif // wxUSE_CONFIG
35 class WXDLLEXPORT wxFontMapper
;
38 class WXDLLEXPORT wxWindow
;
41 // ============================================================================
42 // wxFontMapper manages user-definable correspondence between wxWindows font
43 // encodings and the fonts present on the machine.
45 // This is a singleton class, font mapper objects can only be accessed using
46 // wxFontMapper::Get().
47 // ============================================================================
49 // ----------------------------------------------------------------------------
50 // wxFontMapperBase: this is a non-interactive class which just uses its built
51 // in knowledge of the encodings equivalence
52 // ----------------------------------------------------------------------------
54 class WXDLLEXPORT wxFontMapperBase
57 // constructtor and such
58 // ---------------------
63 // virtual dtor for any base class
64 virtual ~wxFontMapperBase();
66 // return instance of the wxFontMapper singleton
67 static wxFontMapper
*Get();
69 // set the sigleton to 'mapper' instance and return previous one
70 static wxFontMapper
*Set(wxFontMapper
*mapper
);
73 // translates charset strings to encoding
74 // --------------------------------------
76 // returns the encoding for the given charset (in the form of RFC 2046) or
77 // wxFONTENCODING_SYSTEM if couldn't decode it
79 // interactive parameter is ignored in the base class, we behave as if it
81 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
82 bool interactive
= true);
85 // information about supported encodings
86 // -------------------------------------
88 // get the number of font encodings we know about
89 static size_t GetSupportedEncodingsCount();
91 // get the n-th supported encoding
92 static wxFontEncoding
GetEncoding(size_t n
);
94 // return internal string identifier for the encoding (see also
95 // GetEncodingDescription())
96 static wxString
GetEncodingName(wxFontEncoding encoding
);
98 // return user-readable string describing the given encoding
100 // NB: hard-coded now, but might change later (read it from config?)
101 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
104 // functions which allow to configure the config object used: by default,
105 // the global one (from wxConfigBase::Get() will be used) and the default
106 // root path for the config settings is the string returned by
107 // GetDefaultConfigPath()
108 // ----------------------------------------------------------------------
111 // set the config object to use (may be NULL to use default)
112 void SetConfig(wxConfigBase
*config
) { m_config
= config
; }
114 // set the root config path to use (should be an absolute path)
115 void SetConfigPath(const wxString
& prefix
);
117 // return default config path
118 static const wxChar
*GetDefaultConfigPath();
119 #endif // wxUSE_CONFIG
124 // get the config object we're using -- if it wasn't set explicitly, this
125 // function will use wxConfig::Get() to get the global one
126 wxConfigBase
*GetConfig();
128 // gets the root path for our settings -- if it wasn't set explicitly, use
129 // GetDefaultConfigPath()
130 const wxString
& GetConfigPath();
132 // change to the given (relative) path in the config, return true if ok
133 // (then GetConfig() will return something !NULL), false if no config
136 // caller should provide a pointer to the string variable which should be
137 // later passed to RestorePath()
138 bool ChangePath(const wxString
& pathNew
, wxString
*pathOld
);
140 // restore the config path after use
141 void RestorePath(const wxString
& pathOld
);
143 // config object and path (in it) to use
144 wxConfigBase
*m_config
;
145 bool m_configIsDummy
;
147 wxString m_configRootPath
;
148 #endif // wxUSE_CONFIG
151 // the global fontmapper object or NULL
152 static wxFontMapper
*sm_instance
;
154 friend class wxFontMapperPathChanger
;
156 DECLARE_NO_COPY_CLASS(wxFontMapperBase
)
159 // ----------------------------------------------------------------------------
160 // wxFontMapper: interactive extension of wxFontMapperBase
162 // The default implementations of all functions will ask the user if they are
163 // not capable of finding the answer themselves and store the answer in a
164 // config file (configurable via SetConfigXXX functions). This behaviour may
165 // be disabled by giving the value of false to "interactive" parameter.
166 // However, the functions will always consult the config file to allow the
167 // user-defined values override the default logic and there is no way to
168 // disable this -- which shouldn't be ever needed because if "interactive" was
169 // never true, the config file is never created anyhow.
170 // ----------------------------------------------------------------------------
174 class WXDLLEXPORT wxFontMapper
: public wxFontMapperBase
180 // virtual dtor for a base class
181 virtual ~wxFontMapper();
183 // working with the encodings
184 // --------------------------
186 // returns the encoding for the given charset (in the form of RFC 2046) or
187 // wxFONTENCODING_SYSTEM if couldn't decode it
188 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
189 bool interactive
= true);
191 // find an alternative for the given encoding (which is supposed to not be
192 // available on this system). If successful, return true and fill info
193 // structure with the parameters required to create the font, otherwise
195 virtual bool GetAltForEncoding(wxFontEncoding encoding
,
196 wxNativeEncodingInfo
*info
,
197 const wxString
& facename
= wxEmptyString
,
198 bool interactive
= true);
200 // version better suitable for 'public' use. Returns wxFontEcoding
201 // that can be used it wxFont ctor
202 bool GetAltForEncoding(wxFontEncoding encoding
,
203 wxFontEncoding
*alt_encoding
,
204 const wxString
& facename
= wxEmptyString
,
205 bool interactive
= true);
207 // checks whether given encoding is available in given face or not.
208 // If no facename is given,
209 virtual bool IsEncodingAvailable(wxFontEncoding encoding
,
210 const wxString
& facename
= wxEmptyString
);
213 // configure the appearance of the dialogs we may popup
214 // ----------------------------------------------------
216 // the parent window for modal dialogs
217 void SetDialogParent(wxWindow
*parent
) { m_windowParent
= parent
; }
219 // the title for the dialogs (note that default is quite reasonable)
220 void SetDialogTitle(const wxString
& title
) { m_titleDialog
= title
; }
224 // GetAltForEncoding() helper: tests for the existence of the given
225 // encoding and saves the result in config if ok - this results in the
226 // following (desired) behaviour: when an unknown/unavailable encoding is
227 // requested for the first time, the user is asked about a replacement,
228 // but if he doesn't choose any and the default logic finds one, it will
229 // be saved in the config so that the user won't be asked about it any
231 bool TestAltEncoding(const wxString
& configEntry
,
232 wxFontEncoding encReplacement
,
233 wxNativeEncodingInfo
*info
);
235 // the title for our dialogs
236 wxString m_titleDialog
;
238 // the parent window for our dialogs
239 wxWindow
*m_windowParent
;
242 DECLARE_NO_COPY_CLASS(wxFontMapper
)
247 class WXDLLEXPORT wxFontMapper
: public wxFontMapperBase
251 #endif // wxUSE_GUI/!wxUSE_GUI
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
257 // the default font mapper for wxWindows programs do NOT use! This is for
258 // backward compatibility, use wxFontMapper::Get() instead
259 #define wxTheFontMapper (wxFontMapper::Get())
261 #else // !wxUSE_FONTMAP
264 // wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding
265 #include "wx/fontutil.h"
268 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
270 #endif // _WX_FONTMAPPER_H_