]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontmap.h
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / include / wx / fontmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontmap.h
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.11.99
7 // Copyright: (c) Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_FONTMAPPER_H_
12 #define _WX_FONTMAPPER_H_
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 #if wxUSE_FONTMAP
19
20 #include "wx/fontenc.h" // for wxFontEncoding
21
22 #if wxUSE_GUI
23 #include "wx/fontutil.h" // for wxNativeEncodingInfo
24 #endif // wxUSE_GUI
25
26 #if wxUSE_CONFIG && wxUSE_FILECONFIG
27 class WXDLLIMPEXP_FWD_BASE wxConfigBase;
28 #endif // wxUSE_CONFIG
29
30 class WXDLLIMPEXP_FWD_CORE wxFontMapper;
31
32 #if wxUSE_GUI
33 class WXDLLIMPEXP_FWD_CORE wxWindow;
34 #endif // wxUSE_GUI
35
36 // ============================================================================
37 // wxFontMapper manages user-definable correspondence between wxWidgets font
38 // encodings and the fonts present on the machine.
39 //
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
47 // ----------------------------------------------------------------------------
48
49 class WXDLLIMPEXP_BASE wxFontMapperBase
50 {
51 public:
52 // constructor and such
53 // ---------------------
54
55 // default ctor
56 wxFontMapperBase();
57
58 // virtual dtor for any base class
59 virtual ~wxFontMapperBase();
60
61 // return instance of the wxFontMapper singleton
62 // wxBase code only cares that it's a wxFontMapperBase
63 // In wxBase, wxFontMapper is only forward declared
64 // so one cannot implicitly cast from it to wxFontMapperBase.
65 static wxFontMapperBase *Get();
66
67 // set the singleton to 'mapper' instance and return previous one
68 static wxFontMapper *Set(wxFontMapper *mapper);
69
70 // delete the existing font mapper if any
71 static void Reset();
72
73
74 // translates charset strings to encoding
75 // --------------------------------------
76
77 // returns the encoding for the given charset (in the form of RFC 2046) or
78 // wxFONTENCODING_SYSTEM if couldn't decode it
79 //
80 // interactive parameter is ignored in the base class, we behave as if it
81 // were always false
82 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
83 bool interactive = true);
84
85 // information about supported encodings
86 // -------------------------------------
87
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);
93
94 // return canonical name of this encoding (this is a short string,
95 // GetEncodingDescription() returns a longer one)
96 static wxString GetEncodingName(wxFontEncoding encoding);
97
98 // return a list of all names of this encoding (see GetEncodingName)
99 static const wxChar** GetAllEncodingNames(wxFontEncoding encoding);
100
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
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
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
119 #if wxUSE_CONFIG && wxUSE_FILECONFIG
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
124 static const wxString& GetDefaultConfigPath();
125 #endif // wxUSE_CONFIG
126
127
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
132 protected:
133 #if wxUSE_CONFIG && wxUSE_FILECONFIG
134 // get the config object we're using -- either the global config object
135 // or a wxMemoryConfig object created by this class otherwise
136 wxConfigBase *GetConfig();
137
138 // gets the root path for our settings -- if it wasn't set explicitly, use
139 // GetDefaultConfigPath()
140 const wxString& GetConfigPath();
141
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
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
153 // config object and path (in it) to use
154 wxConfigBase *m_configDummy;
155
156 wxString m_configRootPath;
157 #endif // wxUSE_CONFIG
158
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
166 private:
167 // the global fontmapper object or NULL
168 static wxFontMapper *sm_instance;
169
170 friend class wxFontMapperPathChanger;
171
172 wxDECLARE_NO_COPY_CLASS(wxFontMapperBase);
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
188 #if wxUSE_GUI
189
190 class WXDLLIMPEXP_CORE wxFontMapper : public wxFontMapperBase
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.
224 //
225 // if no facename is given (default), return true if it's available in any
226 // facename at alll.
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
240 // GUI code needs to know it's a wxFontMapper because there
241 // are additional methods in the subclass.
242 static wxFontMapper *Get();
243
244 // pseudo-RTTI since we aren't a wxObject.
245 virtual bool IsDummy() { return false; }
246
247 protected:
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
259 // the title for our dialogs
260 wxString m_titleDialog;
261
262 // the parent window for our dialogs
263 wxWindow *m_windowParent;
264
265 private:
266 wxDECLARE_NO_COPY_CLASS(wxFontMapper);
267 };
268
269 #endif // wxUSE_GUI
270
271 // ----------------------------------------------------------------------------
272 // global variables
273 // ----------------------------------------------------------------------------
274
275 // the default font mapper for wxWidgets programs do NOT use! This is for
276 // backward compatibility, use wxFontMapper::Get() instead
277 #define wxTheFontMapper (wxFontMapper::Get())
278
279 #else // !wxUSE_FONTMAP
280
281 #if wxUSE_GUI
282 // wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding
283 #include "wx/fontutil.h"
284 #endif
285
286 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
287
288 #endif // _WX_FONTMAPPER_H_
289