]>
Commit | Line | Data |
---|---|---|
3c1866e8 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/fontmap.h | |
3 | // Purpose: wxFontMapper class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 04.11.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
3c1866e8 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_FONTMAPPER_H_ | |
13 | #define _WX_FONTMAPPER_H_ | |
14 | ||
3c1866e8 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_FONTMAP |
20 | ||
f6bcfd97 | 21 | #include "wx/fontenc.h" // for wxFontEncoding |
3c1866e8 | 22 | |
1e6feb95 VZ |
23 | #if wxUSE_GUI |
24 | #include "wx/fontutil.h" // for wxNativeEncodingInfo | |
25 | #endif // wxUSE_GUI | |
26 | ||
f1c75e0f | 27 | #if wxUSE_CONFIG && wxUSE_FILECONFIG |
bddd7a8d | 28 | class WXDLLIMPEXP_BASE wxConfigBase; |
f6bcfd97 BP |
29 | #endif // wxUSE_CONFIG |
30 | ||
73302af6 | 31 | class WXDLLIMPEXP_CORE wxFontMapper; |
e2478fde | 32 | |
f6bcfd97 | 33 | #if wxUSE_GUI |
bddd7a8d | 34 | class WXDLLIMPEXP_CORE wxWindow; |
f6bcfd97 | 35 | #endif // wxUSE_GUI |
3c1866e8 | 36 | |
e2478fde | 37 | // ============================================================================ |
77ffb593 | 38 | // wxFontMapper manages user-definable correspondence between wxWidgets font |
e2478fde | 39 | // encodings and the fonts present on the machine. |
3c1866e8 | 40 | // |
e2478fde VZ |
41 | // This is a singleton class, font mapper objects can only be accessed using |
42 | // wxFontMapper::Get(). | |
43 | // ============================================================================ | |
44 | ||
45 | // ---------------------------------------------------------------------------- | |
46 | // wxFontMapperBase: this is a non-interactive class which just uses its built | |
47 | // in knowledge of the encodings equivalence | |
3c1866e8 VZ |
48 | // ---------------------------------------------------------------------------- |
49 | ||
bddd7a8d | 50 | class WXDLLIMPEXP_BASE wxFontMapperBase |
3c1866e8 | 51 | { |
2a12cc65 DE |
52 | // For IsWxFontMapper() |
53 | friend class WXDLLIMPEXP_CORE wxFontMapper; | |
3c1866e8 | 54 | public: |
e2478fde VZ |
55 | // constructtor and such |
56 | // --------------------- | |
57 | ||
3c1866e8 | 58 | // default ctor |
e2478fde | 59 | wxFontMapperBase(); |
3c1866e8 | 60 | |
e2478fde VZ |
61 | // virtual dtor for any base class |
62 | virtual ~wxFontMapperBase(); | |
3c1866e8 | 63 | |
142b3bc2 | 64 | // return instance of the wxFontMapper singleton |
73302af6 | 65 | // wxBase code only cares that it's a wxFontMapperBase |
2a12cc65 DE |
66 | // In wxBase, wxFontMapper is only forward declared |
67 | // so one cannot implicitly cast from it to wxFontMapperBase. | |
73302af6 | 68 | static wxFontMapperBase *Get(); |
e2478fde | 69 | |
f1c75e0f | 70 | // set the singleton to 'mapper' instance and return previous one |
142b3bc2 VS |
71 | static wxFontMapper *Set(wxFontMapper *mapper); |
72 | ||
e2478fde VZ |
73 | // translates charset strings to encoding |
74 | // -------------------------------------- | |
6648cd46 | 75 | |
3c1866e8 VZ |
76 | // returns the encoding for the given charset (in the form of RFC 2046) or |
77 | // wxFONTENCODING_SYSTEM if couldn't decode it | |
e2478fde VZ |
78 | // |
79 | // interactive parameter is ignored in the base class, we behave as if it | |
80 | // were always false | |
3c1866e8 | 81 | virtual wxFontEncoding CharsetToEncoding(const wxString& charset, |
e2478fde VZ |
82 | bool interactive = true); |
83 | ||
e2478fde VZ |
84 | // information about supported encodings |
85 | // ------------------------------------- | |
3c1866e8 | 86 | |
e2478fde VZ |
87 | // get the number of font encodings we know about |
88 | static size_t GetSupportedEncodingsCount(); | |
89 | ||
90 | // get the n-th supported encoding | |
91 | static wxFontEncoding GetEncoding(size_t n); | |
7beba2fc | 92 | |
8b3eb85d VZ |
93 | // return canonical name of this encoding (this is a short string, |
94 | // GetEncodingDescription() returns a longer one) | |
7beba2fc VZ |
95 | static wxString GetEncodingName(wxFontEncoding encoding); |
96 | ||
8b3eb85d VZ |
97 | // return a list of all names of this encoding (see GetEncodingName) |
98 | static const wxChar** GetAllEncodingNames(wxFontEncoding encoding); | |
99 | ||
7beba2fc VZ |
100 | // return user-readable string describing the given encoding |
101 | // | |
102 | // NB: hard-coded now, but might change later (read it from config?) | |
103 | static wxString GetEncodingDescription(wxFontEncoding encoding); | |
104 | ||
910b9fc5 VZ |
105 | // find the encoding corresponding to the given name, inverse of |
106 | // GetEncodingName() and less general than CharsetToEncoding() | |
107 | // | |
108 | // returns wxFONTENCODING_MAX if the name is not a supported encoding | |
109 | static wxFontEncoding GetEncodingFromName(const wxString& name); | |
110 | ||
3c1866e8 VZ |
111 | |
112 | // functions which allow to configure the config object used: by default, | |
113 | // the global one (from wxConfigBase::Get() will be used) and the default | |
114 | // root path for the config settings is the string returned by | |
115 | // GetDefaultConfigPath() | |
116 | // ---------------------------------------------------------------------- | |
117 | ||
f1c75e0f | 118 | #if wxUSE_CONFIG && wxUSE_FILECONFIG |
3c1866e8 VZ |
119 | // set the config object to use (may be NULL to use default) |
120 | void SetConfig(wxConfigBase *config) { m_config = config; } | |
121 | ||
122 | // set the root config path to use (should be an absolute path) | |
123 | void SetConfigPath(const wxString& prefix); | |
124 | ||
125 | // return default config path | |
126 | static const wxChar *GetDefaultConfigPath(); | |
e2478fde | 127 | #endif // wxUSE_CONFIG |
3c1866e8 | 128 | |
f6bcfd97 | 129 | |
e2478fde | 130 | protected: |
f1c75e0f | 131 | #if wxUSE_CONFIG && wxUSE_FILECONFIG |
e2478fde | 132 | // get the config object we're using -- if it wasn't set explicitly, this |
3c1866e8 VZ |
133 | // function will use wxConfig::Get() to get the global one |
134 | wxConfigBase *GetConfig(); | |
135 | ||
e2478fde | 136 | // gets the root path for our settings -- if it wasn't set explicitly, use |
3c1866e8 VZ |
137 | // GetDefaultConfigPath() |
138 | const wxString& GetConfigPath(); | |
139 | ||
e2478fde VZ |
140 | // change to the given (relative) path in the config, return true if ok |
141 | // (then GetConfig() will return something !NULL), false if no config | |
3c1866e8 VZ |
142 | // object |
143 | // | |
144 | // caller should provide a pointer to the string variable which should be | |
145 | // later passed to RestorePath() | |
146 | bool ChangePath(const wxString& pathNew, wxString *pathOld); | |
147 | ||
148 | // restore the config path after use | |
149 | void RestorePath(const wxString& pathOld); | |
150 | ||
e2478fde VZ |
151 | // config object and path (in it) to use |
152 | wxConfigBase *m_config; | |
153 | bool m_configIsDummy; | |
154 | ||
155 | wxString m_configRootPath; | |
156 | #endif // wxUSE_CONFIG | |
157 | ||
4dc55027 VZ |
158 | // the real implementation of the base class version of CharsetToEncoding() |
159 | // | |
160 | // returns wxFONTENCODING_UNKNOWN if encoding is unknown and we shouldn't | |
161 | // ask the user about it, wxFONTENCODING_SYSTEM if it is unknown but we | |
162 | // should/could ask the user | |
163 | int NonInteractiveCharsetToEncoding(const wxString& charset); | |
164 | ||
e2478fde | 165 | private: |
2a12cc65 DE |
166 | // pseudo-RTTI since we aren't a wxObject. |
167 | virtual bool IsWxFontMapper(); | |
168 | ||
e2478fde VZ |
169 | // the global fontmapper object or NULL |
170 | static wxFontMapper *sm_instance; | |
171 | ||
172 | friend class wxFontMapperPathChanger; | |
173 | ||
174 | DECLARE_NO_COPY_CLASS(wxFontMapperBase) | |
175 | }; | |
176 | ||
177 | // ---------------------------------------------------------------------------- | |
178 | // wxFontMapper: interactive extension of wxFontMapperBase | |
179 | // | |
180 | // The default implementations of all functions will ask the user if they are | |
181 | // not capable of finding the answer themselves and store the answer in a | |
182 | // config file (configurable via SetConfigXXX functions). This behaviour may | |
183 | // be disabled by giving the value of false to "interactive" parameter. | |
184 | // However, the functions will always consult the config file to allow the | |
185 | // user-defined values override the default logic and there is no way to | |
186 | // disable this -- which shouldn't be ever needed because if "interactive" was | |
187 | // never true, the config file is never created anyhow. | |
188 | // ---------------------------------------------------------------------------- | |
189 | ||
f6bcfd97 | 190 | #if wxUSE_GUI |
e2478fde | 191 | |
bddd7a8d | 192 | class WXDLLIMPEXP_CORE wxFontMapper : public wxFontMapperBase |
e2478fde VZ |
193 | { |
194 | public: | |
195 | // default ctor | |
196 | wxFontMapper(); | |
197 | ||
198 | // virtual dtor for a base class | |
199 | virtual ~wxFontMapper(); | |
200 | ||
201 | // working with the encodings | |
202 | // -------------------------- | |
203 | ||
204 | // returns the encoding for the given charset (in the form of RFC 2046) or | |
205 | // wxFONTENCODING_SYSTEM if couldn't decode it | |
206 | virtual wxFontEncoding CharsetToEncoding(const wxString& charset, | |
207 | bool interactive = true); | |
208 | ||
209 | // find an alternative for the given encoding (which is supposed to not be | |
210 | // available on this system). If successful, return true and fill info | |
211 | // structure with the parameters required to create the font, otherwise | |
212 | // return false | |
213 | virtual bool GetAltForEncoding(wxFontEncoding encoding, | |
214 | wxNativeEncodingInfo *info, | |
215 | const wxString& facename = wxEmptyString, | |
216 | bool interactive = true); | |
217 | ||
218 | // version better suitable for 'public' use. Returns wxFontEcoding | |
219 | // that can be used it wxFont ctor | |
220 | bool GetAltForEncoding(wxFontEncoding encoding, | |
221 | wxFontEncoding *alt_encoding, | |
222 | const wxString& facename = wxEmptyString, | |
223 | bool interactive = true); | |
224 | ||
225 | // checks whether given encoding is available in given face or not. | |
910b9fc5 VZ |
226 | // |
227 | // if no facename is given (default), return true if it's available in any | |
228 | // facename at alll. | |
e2478fde VZ |
229 | virtual bool IsEncodingAvailable(wxFontEncoding encoding, |
230 | const wxString& facename = wxEmptyString); | |
231 | ||
232 | ||
233 | // configure the appearance of the dialogs we may popup | |
234 | // ---------------------------------------------------- | |
235 | ||
236 | // the parent window for modal dialogs | |
237 | void SetDialogParent(wxWindow *parent) { m_windowParent = parent; } | |
238 | ||
239 | // the title for the dialogs (note that default is quite reasonable) | |
240 | void SetDialogTitle(const wxString& title) { m_titleDialog = title; } | |
241 | ||
e74d06a3 JS |
242 | // GUI code needs to know it's a wxFontMapper because there |
243 | // are additional methods in the subclass. | |
244 | static wxFontMapper *Get(); | |
e2478fde VZ |
245 | |
246 | protected: | |
7beba2fc VZ |
247 | // GetAltForEncoding() helper: tests for the existence of the given |
248 | // encoding and saves the result in config if ok - this results in the | |
249 | // following (desired) behaviour: when an unknown/unavailable encoding is | |
250 | // requested for the first time, the user is asked about a replacement, | |
251 | // but if he doesn't choose any and the default logic finds one, it will | |
252 | // be saved in the config so that the user won't be asked about it any | |
253 | // more | |
254 | bool TestAltEncoding(const wxString& configEntry, | |
255 | wxFontEncoding encReplacement, | |
256 | wxNativeEncodingInfo *info); | |
257 | ||
3c1866e8 VZ |
258 | // the title for our dialogs |
259 | wxString m_titleDialog; | |
260 | ||
261 | // the parent window for our dialogs | |
262 | wxWindow *m_windowParent; | |
7beba2fc | 263 | |
142b3bc2 | 264 | private: |
2a12cc65 DE |
265 | // pseudo-RTTI since we aren't a wxObject. |
266 | virtual bool IsWxFontMapper(); | |
267 | ||
22f3361e | 268 | DECLARE_NO_COPY_CLASS(wxFontMapper) |
3c1866e8 VZ |
269 | }; |
270 | ||
73302af6 | 271 | #endif // wxUSE_GUI |
e2478fde | 272 | |
7beba2fc VZ |
273 | // ---------------------------------------------------------------------------- |
274 | // global variables | |
275 | // ---------------------------------------------------------------------------- | |
276 | ||
77ffb593 | 277 | // the default font mapper for wxWidgets programs do NOT use! This is for |
e2478fde | 278 | // backward compatibility, use wxFontMapper::Get() instead |
142b3bc2 | 279 | #define wxTheFontMapper (wxFontMapper::Get()) |
7beba2fc | 280 | |
adf9e099 VZ |
281 | #else // !wxUSE_FONTMAP |
282 | ||
283 | #if wxUSE_GUI | |
284 | // wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding | |
392c7148 | 285 | #include "wx/fontutil.h" |
adf9e099 VZ |
286 | #endif |
287 | ||
288 | #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP | |
1e6feb95 | 289 | |
3c1866e8 | 290 | #endif // _WX_FONTMAPPER_H_ |
e2478fde | 291 |