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