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