]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: fontmap.h | |
3 | // Purpose: interface of wxFontMapper | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxFontMapper | |
11 | ||
12 | wxFontMapper manages user-definable correspondence between logical font | |
13 | names and the fonts present on the machine. | |
14 | ||
15 | The default implementations of all functions will ask the user if they are | |
16 | not capable of finding the answer themselves and store the answer in a | |
17 | config file (configurable via SetConfigXXX functions). This behaviour may | |
18 | be disabled by giving the value of @false to "interactive" parameter. | |
19 | ||
20 | However, the functions will always consult the config file to allow the | |
21 | user-defined values override the default logic and there is no way to | |
22 | disable this - which shouldn't be ever needed because if "interactive" was | |
23 | never @true, the config file is never created anyhow. | |
24 | ||
25 | In case everything else fails (i.e. there is no record in config file | |
26 | and "interactive" is @false or user denied to choose any replacement), | |
27 | the class queries wxEncodingConverter | |
28 | for "equivalent" encodings (e.g. iso8859-2 and cp1250) and tries them. | |
29 | ||
30 | @library{wxcore} | |
31 | @category{misc} | |
32 | ||
33 | @see wxEncodingConverter, @ref overview_nonenglishoverview "Writing non-English | |
34 | applications" | |
35 | */ | |
36 | class wxFontMapper | |
37 | { | |
38 | public: | |
39 | /** | |
40 | Default ctor. | |
41 | */ | |
42 | wxFontMapper(); | |
43 | ||
44 | /** | |
45 | Virtual dtor for a base class. | |
46 | */ | |
47 | ~wxFontMapper(); | |
48 | ||
49 | /** | |
50 | Returns the encoding for the given charset (in the form of RFC 2046) or | |
51 | @c wxFONTENCODING_SYSTEM if couldn't decode it. | |
52 | Be careful when using this function with @a interactive set to @true | |
53 | (default value) as the function then may show a dialog box to the user which | |
54 | may lead to unexpected reentrancies and may also take a significantly longer | |
55 | time than a simple function call. For these reasons, it is almost always a bad | |
56 | idea to call this function from the event handlers for repeatedly generated | |
57 | events such as @c EVT_PAINT. | |
58 | */ | |
59 | wxFontEncoding CharsetToEncoding(const wxString& charset, | |
60 | bool interactive = true); | |
61 | ||
62 | /** | |
63 | Get the current font mapper object. If there is no current object, creates | |
64 | one. | |
65 | ||
66 | @see Set() | |
67 | */ | |
68 | static wxFontMapper* Get(); | |
69 | ||
70 | /** | |
71 | Returns the array of all possible names for the given encoding. The array is | |
72 | @NULL-terminated. IF it isn't empty, the first name in it is the canonical | |
73 | encoding name, i.e. the same string as returned by | |
74 | GetEncodingName(). | |
75 | */ | |
76 | static const wxChar** GetAllEncodingNames(wxFontEncoding encoding); | |
77 | ||
78 | //@{ | |
79 | /** | |
80 | Find an alternative for the given encoding (which is supposed to not be | |
81 | available on this system). If successful, return @true and fill info | |
82 | structure with the parameters required to create the font, otherwise | |
83 | return @false. | |
84 | The first form is for wxWidgets' internal use while the second one | |
85 | is better suitable for general use -- it returns wxFontEncoding which | |
86 | can consequently be passed to wxFont constructor. | |
87 | */ | |
88 | bool GetAltForEncoding(wxFontEncoding encoding, | |
89 | wxNativeEncodingInfo* info, | |
90 | const wxString& facename = wxEmptyString, | |
91 | bool interactive = true); | |
92 | bool GetAltForEncoding(wxFontEncoding encoding, | |
93 | wxFontEncoding* alt_encoding, | |
94 | const wxString& facename = wxEmptyString, | |
95 | bool interactive = true); | |
96 | //@} | |
97 | ||
98 | /** | |
99 | Returns the @e n-th supported encoding. Together with | |
100 | GetSupportedEncodingsCount() | |
101 | this method may be used to get all supported encodings. | |
102 | */ | |
103 | static wxFontEncoding GetEncoding(size_t n); | |
104 | ||
105 | /** | |
106 | Return user-readable string describing the given encoding. | |
107 | */ | |
108 | static wxString GetEncodingDescription(wxFontEncoding encoding); | |
109 | ||
110 | /** | |
111 | Return the encoding corresponding to the given internal name. This function is | |
112 | the inverse of GetEncodingName() and is | |
113 | intentionally less general than | |
114 | CharsetToEncoding(), i.e. it doesn't | |
115 | try to make any guesses nor ever asks the user. It is meant just as a way of | |
116 | restoring objects previously serialized using | |
117 | GetEncodingName(). | |
118 | */ | |
119 | static wxFontEncoding GetEncodingFromName(const wxString& encoding); | |
120 | ||
121 | /** | |
122 | Return internal string identifier for the encoding (see also | |
123 | wxFontMapper::GetEncodingDescription) | |
124 | ||
125 | @see GetEncodingFromName() | |
126 | */ | |
127 | static wxString GetEncodingName(wxFontEncoding encoding); | |
128 | ||
129 | /** | |
130 | Returns the number of the font encodings supported by this class. Together with | |
131 | GetEncoding() this method may be used to get | |
132 | all supported encodings. | |
133 | */ | |
134 | static size_t GetSupportedEncodingsCount(); | |
135 | ||
136 | /** | |
137 | Check whether given encoding is available in given face or not. | |
138 | If no facename is given, find @e any font in this encoding. | |
139 | */ | |
140 | bool IsEncodingAvailable(wxFontEncoding encoding, | |
141 | const wxString& facename = wxEmptyString); | |
142 | ||
143 | /** | |
144 | Set the current font mapper object and return previous one (may be @NULL). | |
145 | This method is only useful if you want to plug-in an alternative font mapper | |
146 | into wxWidgets. | |
147 | ||
148 | @see Get() | |
149 | */ | |
150 | static wxFontMapper* Set(wxFontMapper* mapper); | |
151 | ||
152 | /** | |
153 | Set the config object to use (may be @NULL to use default). | |
154 | By default, the global one (from wxConfigBase::Get() will be used) | |
155 | and the default root path for the config settings is the string returned by | |
156 | GetDefaultConfigPath(). | |
157 | */ | |
158 | void SetConfig(wxConfigBase* config); | |
159 | ||
160 | /** | |
161 | Set the root config path to use (should be an absolute path). | |
162 | */ | |
163 | void SetConfigPath(const wxString& prefix); | |
164 | ||
165 | /** | |
166 | The parent window for modal dialogs. | |
167 | */ | |
168 | void SetDialogParent(wxWindow* parent); | |
169 | ||
170 | /** | |
171 | The title for the dialogs (note that default is quite reasonable). | |
172 | */ | |
173 | void SetDialogTitle(const wxString& title); | |
174 | }; | |
175 |