]> git.saurik.com Git - wxWidgets.git/blame - include/wx/encconv.h
change the selection appropriately (and refresh it as needed) after deleting a notebo...
[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
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
f6bcfd97
BP
10#ifndef _WX_ENCCONV_H_
11#define _WX_ENCCONV_H_
c958260b
VS
12
13#ifdef __GNUG__
14#pragma interface "encconv.h"
15#endif
16
17#include "wx/defs.h"
1e6feb95
VZ
18
19#if wxUSE_FONTMAP
20
f6bcfd97
BP
21#include "wx/object.h"
22#include "wx/fontenc.h"
c958260b
VS
23#include "wx/dynarray.h"
24
f6bcfd97
BP
25// ----------------------------------------------------------------------------
26// constants
27// ----------------------------------------------------------------------------
c958260b 28
f6bcfd97
BP
29enum
30{
c958260b
VS
31 wxCONVERT_STRICT,
32 wxCONVERT_SUBSTITUTE
33};
34
35
f6bcfd97
BP
36enum
37{
c958260b 38 wxPLATFORM_CURRENT = -1,
b8f72ded 39
c958260b
VS
40 wxPLATFORM_UNIX = 0,
41 wxPLATFORM_WINDOWS,
42 wxPLATFORM_OS2,
b8f72ded 43 wxPLATFORM_MAC
c958260b
VS
44};
45
f6bcfd97
BP
46// ----------------------------------------------------------------------------
47// types
48// ----------------------------------------------------------------------------
c958260b 49
5a1cad6e 50WX_DEFINE_ARRAY_INT(wxFontEncoding, wxFontEncodingArray);
c958260b
VS
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
58class WXDLLEXPORT wxEncodingConverter : public wxObject
59{
60 public:
b8f72ded 61
c958260b
VS
62 wxEncodingConverter();
63 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
b8f72ded 64
c958260b 65 // Initialize convertion. Both output or input encoding may
f6bcfd97 66 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
c958260b
VS
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 //
b8f72ded 72 // You must call this method before calling Convert. You may call
c958260b
VS
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:
b8f72ded
DW
77 // wxCONVERT_STRICT --
78 // follow behaviour of GNU Recode - just copy unconvertable
79 // characters to output and don't change them (it's integer
c958260b
VS
80 // value will stay the same)
81 // wxCONVERT_SUBSTITUTE --
b8f72ded 82 // try some (lossy) substitutions - e.g. replace
c958260b
VS
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 wxWindows or if input
91 // or output encoding is not supported.)
92 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
b8f72ded 93
c958260b
VS
94 // Convert input string according to settings passed to Init.
95 // Note that you must call Init before using Convert!
5b5d025c
VS
96 void Convert(const char* input, char* output);
97 void Convert(char* str) { Convert(str, str); }
f6bcfd97
BP
98 wxString Convert(const wxString& input);
99
100#if wxUSE_WCHAR_T
101 void Convert(const char* input, wchar_t* output);
102 void Convert(const wchar_t* input, char* output);
103 void Convert(const wchar_t* input, wchar_t* output);
104 void Convert(wchar_t* str) { Convert(str, str); }
b8f72ded 105#endif
c958260b
VS
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).
b8f72ded
DW
123 //
124 // Convert() method is not limited to converting between
c958260b
VS
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
b8f72ded 137 // Similar to GetPlatformEquivalent, but this one will return ALL
c958260b
VS
138 // equivalent encodings, regardless the platform, including itself.
139 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
140
141 private:
b8f72ded 142
f6bcfd97
BP
143#if wxUSE_WCHAR_T
144 wchar_t *m_Table;
145#else
146 char *m_Table;
147#endif
5b5d025c 148 bool m_UnicodeInput, m_UnicodeOutput;
c958260b 149 bool m_JustCopy;
b8f72ded 150
c958260b
VS
151};
152
1e6feb95 153#endif // wxUSE_FONTMAP
c958260b 154
f6bcfd97 155#endif // _WX_ENCCONV_H_