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