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