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