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 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
21 #include "wx/fontenc.h" // for wxFontEncoding
24 #include "wx/fontutil.h" // for wxNativeEncodingInfo
27 #if wxUSE_CONFIG && wxUSE_FILECONFIG
28 class WXDLLIMPEXP_BASE wxConfigBase
;
29 #endif // wxUSE_CONFIG
31 class WXDLLIMPEXP_BASE wxFontMapper
;
34 class WXDLLIMPEXP_CORE wxWindow
;
37 // ============================================================================
38 // wxFontMapper manages user-definable correspondence between wxWindows font
39 // encodings and the fonts present on the machine.
41 // This is a singleton class, font mapper objects can only be accessed using
42 // wxFontMapper::Get().
43 // ============================================================================
45 // ----------------------------------------------------------------------------
46 // wxFontMapperBase: this is a non-interactive class which just uses its built
47 // in knowledge of the encodings equivalence
48 // ----------------------------------------------------------------------------
50 class WXDLLIMPEXP_BASE wxFontMapperBase
53 // constructtor and such
54 // ---------------------
59 // virtual dtor for any base class
60 virtual ~wxFontMapperBase();
62 // return instance of the wxFontMapper singleton
63 static wxFontMapper
*Get();
65 // set the singleton to 'mapper' instance and return previous one
66 static wxFontMapper
*Set(wxFontMapper
*mapper
);
68 // translates charset strings to encoding
69 // --------------------------------------
71 // returns the encoding for the given charset (in the form of RFC 2046) or
72 // wxFONTENCODING_SYSTEM if couldn't decode it
74 // interactive parameter is ignored in the base class, we behave as if it
76 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
77 bool interactive
= true);
79 // information about supported encodings
80 // -------------------------------------
82 // get the number of font encodings we know about
83 static size_t GetSupportedEncodingsCount();
85 // get the n-th supported encoding
86 static wxFontEncoding
GetEncoding(size_t n
);
88 // return internal string identifier for the encoding (see also
89 // GetEncodingDescription())
90 static wxString
GetEncodingName(wxFontEncoding encoding
);
92 // return user-readable string describing the given encoding
94 // NB: hard-coded now, but might change later (read it from config?)
95 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
98 // functions which allow to configure the config object used: by default,
99 // the global one (from wxConfigBase::Get() will be used) and the default
100 // root path for the config settings is the string returned by
101 // GetDefaultConfigPath()
102 // ----------------------------------------------------------------------
104 #if wxUSE_CONFIG && wxUSE_FILECONFIG
105 // set the config object to use (may be NULL to use default)
106 void SetConfig(wxConfigBase
*config
) { m_config
= config
; }
108 // set the root config path to use (should be an absolute path)
109 void SetConfigPath(const wxString
& prefix
);
111 // return default config path
112 static const wxChar
*GetDefaultConfigPath();
113 #endif // wxUSE_CONFIG
117 #if wxUSE_CONFIG && wxUSE_FILECONFIG
118 // get the config object we're using -- if it wasn't set explicitly, this
119 // function will use wxConfig::Get() to get the global one
120 wxConfigBase
*GetConfig();
122 // gets the root path for our settings -- if it wasn't set explicitly, use
123 // GetDefaultConfigPath()
124 const wxString
& GetConfigPath();
126 // change to the given (relative) path in the config, return true if ok
127 // (then GetConfig() will return something !NULL), false if no config
130 // caller should provide a pointer to the string variable which should be
131 // later passed to RestorePath()
132 bool ChangePath(const wxString
& pathNew
, wxString
*pathOld
);
134 // restore the config path after use
135 void RestorePath(const wxString
& pathOld
);
137 // config object and path (in it) to use
138 wxConfigBase
*m_config
;
139 bool m_configIsDummy
;
141 wxString m_configRootPath
;
142 #endif // wxUSE_CONFIG
145 // the global fontmapper object or NULL
146 static wxFontMapper
*sm_instance
;
148 friend class wxFontMapperPathChanger
;
150 DECLARE_NO_COPY_CLASS(wxFontMapperBase
)
153 // ----------------------------------------------------------------------------
154 // wxFontMapper: interactive extension of wxFontMapperBase
156 // The default implementations of all functions will ask the user if they are
157 // not capable of finding the answer themselves and store the answer in a
158 // config file (configurable via SetConfigXXX functions). This behaviour may
159 // be disabled by giving the value of false to "interactive" parameter.
160 // However, the functions will always consult the config file to allow the
161 // user-defined values override the default logic and there is no way to
162 // disable this -- which shouldn't be ever needed because if "interactive" was
163 // never true, the config file is never created anyhow.
164 // ----------------------------------------------------------------------------
168 class WXDLLIMPEXP_CORE wxFontMapper
: public wxFontMapperBase
174 // virtual dtor for a base class
175 virtual ~wxFontMapper();
177 // working with the encodings
178 // --------------------------
180 // returns the encoding for the given charset (in the form of RFC 2046) or
181 // wxFONTENCODING_SYSTEM if couldn't decode it
182 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
183 bool interactive
= true);
185 // find an alternative for the given encoding (which is supposed to not be
186 // available on this system). If successful, return true and fill info
187 // structure with the parameters required to create the font, otherwise
189 virtual bool GetAltForEncoding(wxFontEncoding encoding
,
190 wxNativeEncodingInfo
*info
,
191 const wxString
& facename
= wxEmptyString
,
192 bool interactive
= true);
194 // version better suitable for 'public' use. Returns wxFontEcoding
195 // that can be used it wxFont ctor
196 bool GetAltForEncoding(wxFontEncoding encoding
,
197 wxFontEncoding
*alt_encoding
,
198 const wxString
& facename
= wxEmptyString
,
199 bool interactive
= true);
201 // checks whether given encoding is available in given face or not.
202 // If no facename is given,
203 virtual bool IsEncodingAvailable(wxFontEncoding encoding
,
204 const wxString
& facename
= wxEmptyString
);
207 // configure the appearance of the dialogs we may popup
208 // ----------------------------------------------------
210 // the parent window for modal dialogs
211 void SetDialogParent(wxWindow
*parent
) { m_windowParent
= parent
; }
213 // the title for the dialogs (note that default is quite reasonable)
214 void SetDialogTitle(const wxString
& title
) { m_titleDialog
= title
; }
218 // GetAltForEncoding() helper: tests for the existence of the given
219 // encoding and saves the result in config if ok - this results in the
220 // following (desired) behaviour: when an unknown/unavailable encoding is
221 // requested for the first time, the user is asked about a replacement,
222 // but if he doesn't choose any and the default logic finds one, it will
223 // be saved in the config so that the user won't be asked about it any
225 bool TestAltEncoding(const wxString
& configEntry
,
226 wxFontEncoding encReplacement
,
227 wxNativeEncodingInfo
*info
);
229 // the title for our dialogs
230 wxString m_titleDialog
;
232 // the parent window for our dialogs
233 wxWindow
*m_windowParent
;
236 DECLARE_NO_COPY_CLASS(wxFontMapper
)
241 class WXDLLIMPEXP_BASE wxFontMapper
: public wxFontMapperBase
245 #endif // wxUSE_GUI/!wxUSE_GUI
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 // the default font mapper for wxWindows programs do NOT use! This is for
252 // backward compatibility, use wxFontMapper::Get() instead
253 #define wxTheFontMapper (wxFontMapper::Get())
255 #else // !wxUSE_FONTMAP
258 // wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding
259 #include "wx/fontutil.h"
262 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
264 #endif // _WX_FONTMAPPER_H_