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