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/font.h" // for wxFont and wxFontEncoding
24 #include "wx/fontutil.h" // for wxNativeEncodingInfo
26 class WXDLLEXPORT wxConfigBase
;
27 class WXDLLEXPORT wxWindow
;
29 // ----------------------------------------------------------------------------
30 // wxFontMapper manages user-definable correspondence between logical font
31 // names and the fonts present on the machine.
33 // The default implementations of all functions will ask the user if they are
34 // not capable of finding the answer themselves and store the answer in a
35 // config file (configurable via SetConfigXXX functions). This behaviour may
36 // be disabled by giving the value of FALSE to "interactive" parameter.
37 // However, the functions will always consult the config file to allow the
38 // user-defined values override the default logic and there is no way to
39 // disable this - which shouldn't be ever needed because if "interactive" was
40 // never TRUE, the config file is never created anyhow.
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxFontMapper
49 // virtual dtor for a base class
50 virtual ~wxFontMapper();
52 // find an alternative for the given encoding (which is supposed to not be
53 // available on this system). If successful, return TRUE and fill info
54 // structure with the parameters required to create the font, otherwise
56 virtual bool GetAltForEncoding(wxFontEncoding encoding
,
57 wxNativeEncodingInfo
*info
,
58 const wxString
& facename
= wxEmptyString
,
59 bool interactive
= TRUE
);
61 // version better suitable for 'public' use. Returns wxFontEcoding
62 // that can be used it wxFont ctor
63 bool GetAltForEncoding(wxFontEncoding encoding
,
64 wxFontEncoding
*alt_encoding
,
65 const wxString
& facename
= wxEmptyString
,
66 bool interactive
= TRUE
);
68 // checks whether given encoding is available in given face or not.
69 // If no facename is given,
70 virtual bool IsEncodingAvailable(wxFontEncoding encoding
,
71 const wxString
& facename
= wxEmptyString
);
73 // returns the encoding for the given charset (in the form of RFC 2046) or
74 // wxFONTENCODING_SYSTEM if couldn't decode it
75 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
76 bool interactive
= TRUE
);
81 // return internal string identifier for the encoding (see also
82 // GetEncodingDescription())
83 static wxString
GetEncodingName(wxFontEncoding encoding
);
85 // return user-readable string describing the given encoding
87 // NB: hard-coded now, but might change later (read it from config?)
88 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
90 // configure the appearance of the dialogs we may popup
91 // ----------------------------------------------------
93 // the parent window for modal dialogs
94 void SetDialogParent(wxWindow
*parent
) { m_windowParent
= parent
; }
96 // the title for the dialogs (note that default is quite reasonable)
97 void SetDialogTitle(const wxString
& title
) { m_titleDialog
= title
; }
99 // functions which allow to configure the config object used: by default,
100 // the global one (from wxConfigBase::Get() will be used) and the default
101 // root path for the config settings is the string returned by
102 // GetDefaultConfigPath()
103 // ----------------------------------------------------------------------
105 // set the config object to use (may be NULL to use default)
106 void SetConfig(wxConfigBase
*config
) { m_config
= config
; }
108 // set the root config path to use (should be an absolute path)
109 void SetConfigPath(const wxString
& prefix
);
111 // return default config path
112 static const wxChar
*GetDefaultConfigPath();
115 // get the config object we're using - if it wasn't set explicitly, this
116 // function will use wxConfig::Get() to get the global one
117 wxConfigBase
*GetConfig();
119 // gets the root path for our settings - if itwasn't set explicitly, use
120 // GetDefaultConfigPath()
121 const wxString
& GetConfigPath();
123 // change to the given (relative) path in the config, return TRUE if ok
124 // (then GetConfig() will return something !NULL), FALSE if no config
127 // caller should provide a pointer to the string variable which should be
128 // later passed to RestorePath()
129 bool ChangePath(const wxString
& pathNew
, wxString
*pathOld
);
131 // restore the config path after use
132 void RestorePath(const wxString
& pathOld
);
134 // GetAltForEncoding() helper: tests for the existence of the given
135 // encoding and saves the result in config if ok - this results in the
136 // following (desired) behaviour: when an unknown/unavailable encoding is
137 // requested for the first time, the user is asked about a replacement,
138 // but if he doesn't choose any and the default logic finds one, it will
139 // be saved in the config so that the user won't be asked about it any
141 bool TestAltEncoding(const wxString
& configEntry
,
142 wxFontEncoding encReplacement
,
143 wxNativeEncodingInfo
*info
);
145 // config object and path (in it) to use
146 wxConfigBase
*m_config
;
147 wxString m_configRootPath
;
149 // the title for our dialogs
150 wxString m_titleDialog
;
152 // the parent window for our dialogs
153 wxWindow
*m_windowParent
;
155 friend class wxFontMapperPathChanger
;
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 // the default font mapper for wxWindows programs
163 WXDLLEXPORT_DATA(extern wxFontMapper
*) wxTheFontMapper
;
165 #endif // _WX_FONTMAPPER_H_