]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontmap.h
Fix/hack 1.
[wxWidgets.git] / include / wx / fontmap.h
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 license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONTMAPPER_H_
13 #define _WX_FONTMAPPER_H_
14
15 #ifdef __GNUG__
16 #pragma interface "fontmap.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22
23 #include "wx/fontenc.h" // for wxFontEncoding
24
25 #if wxUSE_CONFIG
26 class WXDLLEXPORT wxConfigBase;
27 #endif // wxUSE_CONFIG
28
29 #if wxUSE_GUI
30 class WXDLLEXPORT wxWindow;
31 #endif // wxUSE_GUI
32
33 // ----------------------------------------------------------------------------
34 // wxFontMapper manages user-definable correspondence between logical font
35 // names and the fonts present on the machine.
36 //
37 // The default implementations of all functions will ask the user if they are
38 // not capable of finding the answer themselves and store the answer in a
39 // config file (configurable via SetConfigXXX functions). This behaviour may
40 // be disabled by giving the value of FALSE to "interactive" parameter.
41 // However, the functions will always consult the config file to allow the
42 // user-defined values override the default logic and there is no way to
43 // disable this - which shouldn't be ever needed because if "interactive" was
44 // never TRUE, the config file is never created anyhow.
45 // ----------------------------------------------------------------------------
46
47 class WXDLLEXPORT wxFontMapper
48 {
49 public:
50 // default ctor
51 wxFontMapper();
52
53 // virtual dtor for a base class
54 virtual ~wxFontMapper();
55
56 #if wxUSE_GUI
57 // find an alternative for the given encoding (which is supposed to not be
58 // available on this system). If successful, return TRUE and fill info
59 // structure with the parameters required to create the font, otherwise
60 // return FALSE
61 virtual bool GetAltForEncoding(wxFontEncoding encoding,
62 wxNativeEncodingInfo *info,
63 const wxString& facename = wxEmptyString,
64 bool interactive = TRUE);
65
66 // version better suitable for 'public' use. Returns wxFontEcoding
67 // that can be used it wxFont ctor
68 bool GetAltForEncoding(wxFontEncoding encoding,
69 wxFontEncoding *alt_encoding,
70 const wxString& facename = wxEmptyString,
71 bool interactive = TRUE);
72
73 // checks whether given encoding is available in given face or not.
74 // If no facename is given,
75 virtual bool IsEncodingAvailable(wxFontEncoding encoding,
76 const wxString& facename = wxEmptyString);
77 #endif // wxUSE_GUI
78
79 // returns the encoding for the given charset (in the form of RFC 2046) or
80 // wxFONTENCODING_SYSTEM if couldn't decode it
81 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
82 bool interactive = TRUE);
83
84 // encoding names
85 // --------------
86
87 // return internal string identifier for the encoding (see also
88 // GetEncodingDescription())
89 static wxString GetEncodingName(wxFontEncoding encoding);
90
91 // return user-readable string describing the given encoding
92 //
93 // NB: hard-coded now, but might change later (read it from config?)
94 static wxString GetEncodingDescription(wxFontEncoding encoding);
95
96 // configure the appearance of the dialogs we may popup
97 // ----------------------------------------------------
98
99 #if wxUSE_GUI
100 // the parent window for modal dialogs
101 void SetDialogParent(wxWindow *parent) { m_windowParent = parent; }
102
103 // the title for the dialogs (note that default is quite reasonable)
104 void SetDialogTitle(const wxString& title) { m_titleDialog = title; }
105 #endif // wxUSE_GUI
106
107 // functions which allow to configure the config object used: by default,
108 // the global one (from wxConfigBase::Get() will be used) and the default
109 // root path for the config settings is the string returned by
110 // GetDefaultConfigPath()
111 // ----------------------------------------------------------------------
112
113 #if wxUSE_CONFIG
114 // set the config object to use (may be NULL to use default)
115 void SetConfig(wxConfigBase *config) { m_config = config; }
116
117 // set the root config path to use (should be an absolute path)
118 void SetConfigPath(const wxString& prefix);
119
120 // return default config path
121 static const wxChar *GetDefaultConfigPath();
122 #endif
123
124 protected:
125
126 #if wxUSE_CONFIG
127 // get the config object we're using - if it wasn't set explicitly, this
128 // function will use wxConfig::Get() to get the global one
129 wxConfigBase *GetConfig();
130
131 // gets the root path for our settings - if itwasn't set explicitly, use
132 // GetDefaultConfigPath()
133 const wxString& GetConfigPath();
134 #endif
135
136 // change to the given (relative) path in the config, return TRUE if ok
137 // (then GetConfig() will return something !NULL), FALSE if no config
138 // object
139 //
140 // caller should provide a pointer to the string variable which should be
141 // later passed to RestorePath()
142 bool ChangePath(const wxString& pathNew, wxString *pathOld);
143
144 // restore the config path after use
145 void RestorePath(const wxString& pathOld);
146
147 #if wxUSE_GUI
148 // GetAltForEncoding() helper: tests for the existence of the given
149 // encoding and saves the result in config if ok - this results in the
150 // following (desired) behaviour: when an unknown/unavailable encoding is
151 // requested for the first time, the user is asked about a replacement,
152 // but if he doesn't choose any and the default logic finds one, it will
153 // be saved in the config so that the user won't be asked about it any
154 // more
155 bool TestAltEncoding(const wxString& configEntry,
156 wxFontEncoding encReplacement,
157 wxNativeEncodingInfo *info);
158 #endif // wxUSE_GUI
159
160 #if wxUSE_CONFIG
161 // config object and path (in it) to use
162 wxConfigBase *m_config;
163 #endif
164
165 wxString m_configRootPath;
166
167 #if wxUSE_GUI
168 // the title for our dialogs
169 wxString m_titleDialog;
170
171 // the parent window for our dialogs
172 wxWindow *m_windowParent;
173 #endif // wxUSE_GUI
174
175 friend class wxFontMapperPathChanger;
176 };
177
178 // ----------------------------------------------------------------------------
179 // global variables
180 // ----------------------------------------------------------------------------
181
182 // the default font mapper for wxWindows programs
183 WXDLLEXPORT_DATA(extern wxFontMapper *) wxTheFontMapper;
184
185 #endif // _WX_FONTMAPPER_H_