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