]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontmap.h
Updated version to 2.5.4
[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
bddd7a8d 28 class WXDLLIMPEXP_BASE wxConfigBase;
f6bcfd97
BP
29#endif // wxUSE_CONFIG
30
bddd7a8d 31class WXDLLIMPEXP_BASE wxFontMapper;
e2478fde 32
f6bcfd97 33#if wxUSE_GUI
bddd7a8d 34 class WXDLLIMPEXP_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:
e2478fde
VZ
53 // constructtor and such
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
VS
62 // return instance of the wxFontMapper singleton
63 static wxFontMapper *Get();
e2478fde 64
f1c75e0f 65 // set the singleton to 'mapper' instance and return previous one
142b3bc2
VS
66 static wxFontMapper *Set(wxFontMapper *mapper);
67
e2478fde
VZ
68 // translates charset strings to encoding
69 // --------------------------------------
6648cd46 70
3c1866e8
VZ
71 // returns the encoding for the given charset (in the form of RFC 2046) or
72 // wxFONTENCODING_SYSTEM if couldn't decode it
e2478fde
VZ
73 //
74 // interactive parameter is ignored in the base class, we behave as if it
75 // were always false
3c1866e8 76 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
e2478fde
VZ
77 bool interactive = true);
78
e2478fde
VZ
79 // information about supported encodings
80 // -------------------------------------
3c1866e8 81
e2478fde
VZ
82 // get the number of font encodings we know about
83 static size_t GetSupportedEncodingsCount();
84
85 // get the n-th supported encoding
86 static wxFontEncoding GetEncoding(size_t n);
7beba2fc
VZ
87
88 // return internal string identifier for the encoding (see also
89 // GetEncodingDescription())
90 static wxString GetEncodingName(wxFontEncoding encoding);
91
92 // return user-readable string describing the given encoding
93 //
94 // NB: hard-coded now, but might change later (read it from config?)
95 static wxString GetEncodingDescription(wxFontEncoding encoding);
96
910b9fc5
VZ
97 // find the encoding corresponding to the given name, inverse of
98 // GetEncodingName() and less general than CharsetToEncoding()
99 //
100 // returns wxFONTENCODING_MAX if the name is not a supported encoding
101 static wxFontEncoding GetEncodingFromName(const wxString& name);
102
3c1866e8
VZ
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
f1c75e0f 110#if wxUSE_CONFIG && wxUSE_FILECONFIG
3c1866e8
VZ
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();
e2478fde 119#endif // wxUSE_CONFIG
3c1866e8 120
f6bcfd97 121
e2478fde 122protected:
f1c75e0f 123#if wxUSE_CONFIG && wxUSE_FILECONFIG
e2478fde 124 // get the config object we're using -- if it wasn't set explicitly, this
3c1866e8
VZ
125 // function will use wxConfig::Get() to get the global one
126 wxConfigBase *GetConfig();
127
e2478fde 128 // gets the root path for our settings -- if it wasn't set explicitly, use
3c1866e8
VZ
129 // GetDefaultConfigPath()
130 const wxString& GetConfigPath();
131
e2478fde
VZ
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
3c1866e8
VZ
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
e2478fde
VZ
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
4dc55027
VZ
150 // the real implementation of the base class version of CharsetToEncoding()
151 //
152 // returns wxFONTENCODING_UNKNOWN if encoding is unknown and we shouldn't
153 // ask the user about it, wxFONTENCODING_SYSTEM if it is unknown but we
154 // should/could ask the user
155 int NonInteractiveCharsetToEncoding(const wxString& charset);
156
e2478fde
VZ
157private:
158 // the global fontmapper object or NULL
159 static wxFontMapper *sm_instance;
160
161 friend class wxFontMapperPathChanger;
162
163 DECLARE_NO_COPY_CLASS(wxFontMapperBase)
164};
165
166// ----------------------------------------------------------------------------
167// wxFontMapper: interactive extension of wxFontMapperBase
168//
169// The default implementations of all functions will ask the user if they are
170// not capable of finding the answer themselves and store the answer in a
171// config file (configurable via SetConfigXXX functions). This behaviour may
172// be disabled by giving the value of false to "interactive" parameter.
173// However, the functions will always consult the config file to allow the
174// user-defined values override the default logic and there is no way to
175// disable this -- which shouldn't be ever needed because if "interactive" was
176// never true, the config file is never created anyhow.
177// ----------------------------------------------------------------------------
178
f6bcfd97 179#if wxUSE_GUI
e2478fde 180
bddd7a8d 181class WXDLLIMPEXP_CORE wxFontMapper : public wxFontMapperBase
e2478fde
VZ
182{
183public:
184 // default ctor
185 wxFontMapper();
186
187 // virtual dtor for a base class
188 virtual ~wxFontMapper();
189
190 // working with the encodings
191 // --------------------------
192
193 // returns the encoding for the given charset (in the form of RFC 2046) or
194 // wxFONTENCODING_SYSTEM if couldn't decode it
195 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
196 bool interactive = true);
197
198 // find an alternative for the given encoding (which is supposed to not be
199 // available on this system). If successful, return true and fill info
200 // structure with the parameters required to create the font, otherwise
201 // return false
202 virtual bool GetAltForEncoding(wxFontEncoding encoding,
203 wxNativeEncodingInfo *info,
204 const wxString& facename = wxEmptyString,
205 bool interactive = true);
206
207 // version better suitable for 'public' use. Returns wxFontEcoding
208 // that can be used it wxFont ctor
209 bool GetAltForEncoding(wxFontEncoding encoding,
210 wxFontEncoding *alt_encoding,
211 const wxString& facename = wxEmptyString,
212 bool interactive = true);
213
214 // checks whether given encoding is available in given face or not.
910b9fc5
VZ
215 //
216 // if no facename is given (default), return true if it's available in any
217 // facename at alll.
e2478fde
VZ
218 virtual bool IsEncodingAvailable(wxFontEncoding encoding,
219 const wxString& facename = wxEmptyString);
220
221
222 // configure the appearance of the dialogs we may popup
223 // ----------------------------------------------------
224
225 // the parent window for modal dialogs
226 void SetDialogParent(wxWindow *parent) { m_windowParent = parent; }
227
228 // the title for the dialogs (note that default is quite reasonable)
229 void SetDialogTitle(const wxString& title) { m_titleDialog = title; }
230
231
232protected:
7beba2fc
VZ
233 // GetAltForEncoding() helper: tests for the existence of the given
234 // encoding and saves the result in config if ok - this results in the
235 // following (desired) behaviour: when an unknown/unavailable encoding is
236 // requested for the first time, the user is asked about a replacement,
237 // but if he doesn't choose any and the default logic finds one, it will
238 // be saved in the config so that the user won't be asked about it any
239 // more
240 bool TestAltEncoding(const wxString& configEntry,
241 wxFontEncoding encReplacement,
242 wxNativeEncodingInfo *info);
243
3c1866e8
VZ
244 // the title for our dialogs
245 wxString m_titleDialog;
246
247 // the parent window for our dialogs
248 wxWindow *m_windowParent;
7beba2fc 249
142b3bc2 250private:
22f3361e 251 DECLARE_NO_COPY_CLASS(wxFontMapper)
3c1866e8
VZ
252};
253
e2478fde
VZ
254#else // !wxUSE_GUI
255
bddd7a8d 256class WXDLLIMPEXP_BASE wxFontMapper : public wxFontMapperBase
e2478fde
VZ
257{
258};
259
260#endif // wxUSE_GUI/!wxUSE_GUI
261
7beba2fc
VZ
262// ----------------------------------------------------------------------------
263// global variables
264// ----------------------------------------------------------------------------
265
77ffb593 266// the default font mapper for wxWidgets programs do NOT use! This is for
e2478fde 267// backward compatibility, use wxFontMapper::Get() instead
142b3bc2 268#define wxTheFontMapper (wxFontMapper::Get())
7beba2fc 269
adf9e099
VZ
270#else // !wxUSE_FONTMAP
271
272#if wxUSE_GUI
273 // wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding
392c7148 274 #include "wx/fontutil.h"
adf9e099
VZ
275#endif
276
277#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
1e6feb95 278
3c1866e8 279#endif // _WX_FONTMAPPER_H_
e2478fde 280