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