]> git.saurik.com Git - wxWidgets.git/blob - include/wx/encconv.h
Add SetFocusIgnoringChildren() to wxControlContainer. This
[wxWidgets.git] / include / wx / encconv.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/encconv.h
3 // Purpose: wxEncodingConverter class for converting between different
4 // font encodings
5 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_ENCCONV_H_
11 #define _WX_ENCCONV_H_
12
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma interface "encconv.h"
15 #endif
16
17 #include "wx/defs.h"
18
19 #if wxUSE_FONTMAP
20
21 #include "wx/object.h"
22 #include "wx/fontenc.h"
23 #include "wx/dynarray.h"
24
25 // ----------------------------------------------------------------------------
26 // constants
27 // ----------------------------------------------------------------------------
28
29 enum
30 {
31 wxCONVERT_STRICT,
32 wxCONVERT_SUBSTITUTE
33 };
34
35
36 enum
37 {
38 wxPLATFORM_CURRENT = -1,
39
40 wxPLATFORM_UNIX = 0,
41 wxPLATFORM_WINDOWS,
42 wxPLATFORM_OS2,
43 wxPLATFORM_MAC
44 };
45
46 // ----------------------------------------------------------------------------
47 // types
48 // ----------------------------------------------------------------------------
49
50 WX_DEFINE_ARRAY_INT(wxFontEncoding, wxFontEncodingArray);
51
52 //--------------------------------------------------------------------------------
53 // wxEncodingConverter
54 // This class is capable of converting strings between any two
55 // 8bit encodings/charsets. It can also convert from/to Unicode
56 //--------------------------------------------------------------------------------
57
58 class WXDLLIMPEXP_BASE wxEncodingConverter : public wxObject
59 {
60 public:
61
62 wxEncodingConverter();
63 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
64
65 // Initialize conversion. Both output or input encoding may
66 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
67 //
68 // All subsequent calls to Convert() will interpret it's argument
69 // as a string in input_enc encoding and will output string in
70 // output_enc encoding.
71 //
72 // You must call this method before calling Convert. You may call
73 // it more than once in order to switch to another conversion
74 //
75 // Method affects behaviour of Convert() in case input character
76 // cannot be converted because it does not exist in output encoding:
77 // wxCONVERT_STRICT --
78 // follow behaviour of GNU Recode - just copy unconvertable
79 // characters to output and don't change them (it's integer
80 // value will stay the same)
81 // wxCONVERT_SUBSTITUTE --
82 // try some (lossy) substitutions - e.g. replace
83 // unconvertable latin capitals with acute by ordinary
84 // capitals, replace en-dash or em-dash by '-' etc.
85 // both modes gurantee that output string will have same length
86 // as input string
87 //
88 // Returns false if given conversion is impossible, true otherwise
89 // (conversion may be impossible either if you try to convert
90 // to Unicode with non-Unicode build of wxWidgets or if input
91 // or output encoding is not supported.)
92 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
93
94 // Convert input string according to settings passed to Init.
95 // Note that you must call Init before using Convert!
96 bool Convert(const char* input, char* output) const;
97 bool Convert(char* str) const { return Convert(str, str); }
98 wxString Convert(const wxString& input) const;
99
100 #if wxUSE_WCHAR_T
101 bool Convert(const char* input, wchar_t* output) const;
102 bool Convert(const wchar_t* input, char* output) const;
103 bool Convert(const wchar_t* input, wchar_t* output) const;
104 bool Convert(wchar_t* str) const { return Convert(str, str); }
105 #endif
106 // Return equivalent(s) for given font that are used
107 // under given platform. wxPLATFORM_CURRENT means the plaform
108 // this binary was compiled for
109 //
110 // Examples:
111 // current platform enc returned value
112 // -----------------------------------------------------
113 // unix CP1250 {ISO8859_2}
114 // unix ISO8859_2 {}
115 // windows ISO8859_2 {CP1250}
116 //
117 // Equivalence is defined in terms of convertibility:
118 // 2 encodings are equivalent if you can convert text between
119 // then without loosing information (it may - and will - happen
120 // that you loose special chars like quotation marks or em-dashes
121 // but you shouldn't loose any diacritics and language-specific
122 // characters when converting between equivalent encodings).
123 //
124 // Convert() method is not limited to converting between
125 // equivalent encodings, it can convert between arbitrary
126 // two encodings!
127 //
128 // Remember that this function does _NOT_ check for presence of
129 // fonts in system. It only tells you what are most suitable
130 // encodings. (It usually returns only one encoding)
131 //
132 // Note that argument enc itself may be present in returned array!
133 // (so that you can -- as a side effect -- detect whether the
134 // encoding is native for this platform or not)
135 static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc, int platform = wxPLATFORM_CURRENT);
136
137 // Similar to GetPlatformEquivalent, but this one will return ALL
138 // equivalent encodings, regardless the platform, including itself.
139 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
140
141 // Return true if [any text in] one multibyte encoding can be
142 // converted to another one losslessly.
143 //
144 // Do not call this with wxFONTENCODING_UNICODE, it doesn't make
145 // sense (always works in one sense and always depends on the text
146 // to convert in the other)
147 static bool CanConvert(wxFontEncoding encIn, wxFontEncoding encOut)
148 {
149 return GetAllEquivalents(encIn).Index(encOut) != wxNOT_FOUND;
150 }
151
152 private:
153
154 #if wxUSE_WCHAR_T
155 wchar_t *m_Table;
156 #else
157 char *m_Table;
158 #endif
159 bool m_UnicodeInput, m_UnicodeOutput;
160 bool m_JustCopy;
161
162 DECLARE_NO_COPY_CLASS(wxEncodingConverter)
163 };
164
165 #endif // wxUSE_FONTMAP
166
167 #endif // _WX_ENCCONV_H_