Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "svx/txencbox.hxx"
31 : : #include "svx/txenctab.hxx"
32 : : #include <svx/dialogs.hrc>
33 : : #ifndef DISABLE_DBCONNECTIVITY
34 : : #include "svx/dbcharsethelper.hxx"
35 : : #endif
36 : : #include <vcl/svapp.hxx>
37 : : #include <rtl/tencinfo.h>
38 : : #include <rtl/locale.h>
39 : : #include <rtl/strbuf.hxx>
40 : : #include <osl/nlsupport.h>
41 : :
42 : : //========================================================================
43 : : // class SvxTextEncodingBox
44 : : //========================================================================
45 : :
46 : 0 : SvxTextEncodingBox::SvxTextEncodingBox( Window* pParent, const ResId& rResId )
47 : : :
48 : 0 : ListBox( pParent, rResId )
49 : : {
50 [ # # ][ # # ]: 0 : m_pEncTable = new SvxTextEncodingTable;
51 : 0 : }
52 : :
53 : : //------------------------------------------------------------------------
54 : :
55 : 0 : SvxTextEncodingBox::~SvxTextEncodingBox()
56 : : {
57 [ # # ][ # # ]: 0 : delete m_pEncTable;
58 [ # # ]: 0 : }
59 : :
60 : : //------------------------------------------------------------------------
61 : :
62 : 0 : sal_uInt16 SvxTextEncodingBox::EncodingToPos_Impl( rtl_TextEncoding nEnc ) const
63 : : {
64 : 0 : sal_uInt16 nCount = GetEntryCount();
65 [ # # ]: 0 : for ( sal_uInt16 i=0; i<nCount; i++ )
66 : : {
67 [ # # ]: 0 : if ( nEnc == rtl_TextEncoding( (sal_uIntPtr)GetEntryData(i) ) )
68 : 0 : return i;
69 : : }
70 : 0 : return LISTBOX_ENTRY_NOTFOUND;
71 : : }
72 : :
73 : : //------------------------------------------------------------------------
74 : :
75 : 0 : void SvxTextEncodingBox::FillFromTextEncodingTable(
76 : : sal_Bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
77 : : sal_uInt32 nButIncludeInfoFlags )
78 : : {
79 : : rtl_TextEncodingInfo aInfo;
80 : 0 : aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
81 : 0 : sal_uInt32 nCount = m_pEncTable->Count();
82 [ # # ]: 0 : for ( sal_uInt32 j=0; j<nCount; j++ )
83 : : {
84 : 0 : sal_Bool bInsert = sal_True;
85 [ # # ]: 0 : rtl_TextEncoding nEnc = rtl_TextEncoding( m_pEncTable->GetValue( j ) );
86 [ # # ]: 0 : if ( nExcludeInfoFlags )
87 : : {
88 [ # # ][ # # ]: 0 : if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
89 : 0 : bInsert = sal_False;
90 : : else
91 : : {
92 [ # # ]: 0 : if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
93 : : {
94 [ # # ][ # # ]: 0 : if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
[ # # ]
95 : : ((nEnc == RTL_TEXTENCODING_UCS2) ||
96 : : nEnc == RTL_TEXTENCODING_UCS4) )
97 : 0 : bInsert = sal_False; // InfoFlags don't work for Unicode :-(
98 : : }
99 [ # # ]: 0 : else if ( (aInfo.Flags & nButIncludeInfoFlags) == 0 )
100 : 0 : bInsert = sal_False;
101 : : }
102 : : }
103 [ # # ]: 0 : if ( bInsert )
104 : : {
105 [ # # ]: 0 : if ( bExcludeImportSubsets )
106 : : {
107 [ # # ]: 0 : switch ( nEnc )
108 : : {
109 : : // subsets of RTL_TEXTENCODING_GB_18030
110 : : case RTL_TEXTENCODING_GB_2312 :
111 : : case RTL_TEXTENCODING_GBK :
112 : : case RTL_TEXTENCODING_MS_936 :
113 : 0 : bInsert = sal_False;
114 : 0 : break;
115 : : }
116 : : }
117 [ # # ]: 0 : if ( bInsert )
118 [ # # ][ # # ]: 0 : InsertTextEncoding( nEnc, m_pEncTable->GetString( j ) );
[ # # ][ # # ]
119 : : }
120 : : }
121 : 0 : }
122 : :
123 : : //------------------------------------------------------------------------
124 : :
125 : 0 : void SvxTextEncodingBox::FillFromDbTextEncodingMap(
126 : : sal_Bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
127 : : sal_uInt32 nButIncludeInfoFlags )
128 : : {
129 : : #ifdef DISABLE_DBCONNECTIVITY
130 : : (void)bExcludeImportSubsets;
131 : : (void)nExcludeInfoFlags;
132 : : (void)nButIncludeInfoFlags;
133 : : #else
134 : : rtl_TextEncodingInfo aInfo;
135 : 0 : aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
136 [ # # ]: 0 : svxform::ODataAccessCharsetHelper aCSH;
137 [ # # ]: 0 : ::std::vector< rtl_TextEncoding > aEncs;
138 [ # # ]: 0 : sal_Int32 nCount = aCSH.getSupportedTextEncodings( aEncs );
139 [ # # ]: 0 : for ( sal_uInt16 j=0; j<nCount; j++ )
140 : : {
141 : 0 : sal_Bool bInsert = sal_True;
142 [ # # ]: 0 : rtl_TextEncoding nEnc = rtl_TextEncoding( aEncs[j] );
143 [ # # ]: 0 : if ( nExcludeInfoFlags )
144 : : {
145 [ # # ][ # # ]: 0 : if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
146 : 0 : bInsert = sal_False;
147 : : else
148 : : {
149 [ # # ]: 0 : if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
150 : : {
151 [ # # ][ # # ]: 0 : if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
[ # # ]
152 : : ((nEnc == RTL_TEXTENCODING_UCS2) ||
153 : : nEnc == RTL_TEXTENCODING_UCS4) )
154 : 0 : bInsert = sal_False; // InfoFlags don't work for Unicode :-(
155 : : }
156 [ # # ]: 0 : else if ( (aInfo.Flags & nButIncludeInfoFlags) == 0 )
157 : 0 : bInsert = sal_False;
158 : : }
159 : : }
160 [ # # ]: 0 : if ( bInsert )
161 : : {
162 [ # # ]: 0 : if ( bExcludeImportSubsets )
163 : : {
164 [ # # ]: 0 : switch ( nEnc )
165 : : {
166 : : // subsets of RTL_TEXTENCODING_GB_18030
167 : : case RTL_TEXTENCODING_GB_2312 :
168 : : case RTL_TEXTENCODING_GBK :
169 : : case RTL_TEXTENCODING_MS_936 :
170 : 0 : bInsert = sal_False;
171 : 0 : break;
172 : : }
173 : : }
174 : : // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
175 : : // makes no sense here and would result in an empty string as list
176 : : // entry.
177 [ # # ][ # # ]: 0 : if ( bInsert && nEnc != RTL_TEXTENCODING_DONTKNOW )
178 [ # # ]: 0 : InsertTextEncoding( nEnc );
179 : : }
180 [ # # ]: 0 : }
181 : : #endif
182 : 0 : }
183 : :
184 : : //------------------------------------------------------------------------
185 : :
186 : 0 : void SvxTextEncodingBox::FillWithMimeAndSelectBest()
187 : : {
188 : 0 : FillFromTextEncodingTable( sal_False, 0xffffffff, RTL_TEXTENCODING_INFO_MIME );
189 : 0 : rtl_TextEncoding nEnc = SvtSysLocale::GetBestMimeEncoding();
190 : 0 : SelectTextEncoding( nEnc );
191 : 0 : }
192 : :
193 : : //------------------------------------------------------------------------
194 : :
195 : 0 : void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc,
196 : : const String& rEntry, sal_uInt16 nPos )
197 : : {
198 : 0 : sal_uInt16 nAt = InsertEntry( rEntry, nPos );
199 : 0 : SetEntryData( nAt, (void*)(sal_uIntPtr)nEnc );
200 : 0 : }
201 : :
202 : : //------------------------------------------------------------------------
203 : :
204 : 0 : void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc, sal_uInt16 nPos )
205 : : {
206 [ # # ]: 0 : const String& rEntry = m_pEncTable->GetTextString( nEnc );
207 [ # # ]: 0 : if ( rEntry.Len() )
208 [ # # ]: 0 : InsertTextEncoding( nEnc, rEntry, nPos );
209 : : else
210 : 0 : SAL_WARN( "svx.dialog", "SvxTextEncodingBox::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
211 : 0 : }
212 : :
213 : : //------------------------------------------------------------------------
214 : :
215 : 0 : rtl_TextEncoding SvxTextEncodingBox::GetSelectTextEncoding() const
216 : : {
217 : 0 : sal_uInt16 nPos = GetSelectEntryPos();
218 : :
219 [ # # ]: 0 : if ( nPos != LISTBOX_ENTRY_NOTFOUND )
220 : 0 : return rtl_TextEncoding( (sal_uIntPtr)GetEntryData(nPos) );
221 : : else
222 : 0 : return RTL_TEXTENCODING_DONTKNOW;
223 : : }
224 : :
225 : : //------------------------------------------------------------------------
226 : :
227 : 0 : void SvxTextEncodingBox::SelectTextEncoding( const rtl_TextEncoding nEnc, sal_Bool bSelect )
228 : : {
229 : 0 : sal_uInt16 nAt = EncodingToPos_Impl( nEnc );
230 : :
231 [ # # ]: 0 : if ( nAt != LISTBOX_ENTRY_NOTFOUND )
232 : 0 : SelectEntryPos( nAt, bSelect );
233 : 0 : }
234 : :
235 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|