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