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