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