1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FONTMAPPER_H_
13 #define _WX_FONTMAPPER_H_
16 #pragma interface "fontmap.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/fontenc.h" // for wxFontEncoding
26 class WXDLLEXPORT wxConfigBase
;
27 #endif // wxUSE_CONFIG
30 class WXDLLEXPORT wxWindow
;
33 // ----------------------------------------------------------------------------
34 // wxFontMapper manages user-definable correspondence between logical font
35 // names and the fonts present on the machine.
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 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxFontMapper
53 // virtual dtor for a base class
54 virtual ~wxFontMapper();
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
61 virtual bool GetAltForEncoding(wxFontEncoding encoding
,
62 wxNativeEncodingInfo
*info
,
63 const wxString
& facename
= wxEmptyString
,
64 bool interactive
= TRUE
);
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
);
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
);
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
);
87 // return internal string identifier for the encoding (see also
88 // GetEncodingDescription())
89 static wxString
GetEncodingName(wxFontEncoding encoding
);
91 // return user-readable string describing the given encoding
93 // NB: hard-coded now, but might change later (read it from config?)
94 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
96 // configure the appearance of the dialogs we may popup
97 // ----------------------------------------------------
100 // the parent window for modal dialogs
101 void SetDialogParent(wxWindow
*parent
) { m_windowParent
= parent
; }
103 // the title for the dialogs (note that default is quite reasonable)
104 void SetDialogTitle(const wxString
& title
) { m_titleDialog
= title
; }
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 // ----------------------------------------------------------------------
114 // set the config object to use (may be NULL to use default)
115 void SetConfig(wxConfigBase
*config
) { m_config
= config
; }
117 // set the root config path to use (should be an absolute path)
118 void SetConfigPath(const wxString
& prefix
);
120 // return default config path
121 static const wxChar
*GetDefaultConfigPath();
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();
131 // gets the root path for our settings - if itwasn't set explicitly, use
132 // GetDefaultConfigPath()
133 const wxString
& GetConfigPath();
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
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
);
144 // restore the config path after use
145 void RestorePath(const wxString
& pathOld
);
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
155 bool TestAltEncoding(const wxString
& configEntry
,
156 wxFontEncoding encReplacement
,
157 wxNativeEncodingInfo
*info
);
161 // config object and path (in it) to use
162 wxConfigBase
*m_config
;
165 wxString m_configRootPath
;
168 // the title for our dialogs
169 wxString m_titleDialog
;
171 // the parent window for our dialogs
172 wxWindow
*m_windowParent
;
175 friend class wxFontMapperPathChanger
;
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 // the default font mapper for wxWindows programs
183 WXDLLEXPORT_DATA(extern wxFontMapper
*) wxTheFontMapper
;
185 #endif // _WX_FONTMAPPER_H_