Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / dialog / txencbox.cxx
blobf6bc5fa72919e7908a782cf977c2de9187390457
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include <svx/txencbox.hxx>
23 #include <svx/dialmgr.hxx>
24 #include <svx/txenctab.hxx>
25 #if HAVE_FEATURE_DBCONNECTIVITY
26 #include <dbcharsethelper.hxx>
27 #endif
28 #include <unotools/syslocale.hxx>
29 #include <rtl/tencinfo.h>
30 #include <sal/log.hxx>
31 #include <txenctab.hrc>
33 namespace
35 std::vector<rtl_TextEncoding> FillFromDbTextEncodingMap(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
37 std::vector<rtl_TextEncoding> aRet;
38 #if !HAVE_FEATURE_DBCONNECTIVITY
39 (void)bExcludeImportSubsets;
40 (void)nExcludeInfoFlags;
41 #else
42 rtl_TextEncodingInfo aInfo;
43 aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
44 ::std::vector< rtl_TextEncoding > aEncs;
45 sal_Int32 nCount = svxform::charset_helper::getSupportedTextEncodings( aEncs );
46 for ( sal_Int32 j=0; j<nCount; j++ )
48 bool bInsert = true;
49 rtl_TextEncoding nEnc = rtl_TextEncoding( aEncs[j] );
50 if ( nExcludeInfoFlags )
52 if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
53 bInsert = false;
54 else
56 if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
58 if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
59 ((nEnc == RTL_TEXTENCODING_UCS2) ||
60 nEnc == RTL_TEXTENCODING_UCS4) )
61 bInsert = false; // InfoFlags don't work for Unicode :-(
63 else
64 bInsert = false;
67 if ( bInsert )
69 if ( bExcludeImportSubsets )
71 switch ( nEnc )
73 // subsets of RTL_TEXTENCODING_GB_18030
74 case RTL_TEXTENCODING_GB_2312 :
75 case RTL_TEXTENCODING_GBK :
76 case RTL_TEXTENCODING_MS_936 :
77 bInsert = false;
78 break;
81 // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
82 // makes no sense here and would result in an empty string as list
83 // entry.
84 if ( bInsert && nEnc != RTL_TEXTENCODING_DONTKNOW )
85 aRet.push_back(nEnc);
88 #endif
89 return aRet;
93 void SvxTextEncodingBox::FillFromDbTextEncodingMap(
94 bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
96 m_xControl->freeze();
97 auto aEncs = ::FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
98 for (auto nEnc : aEncs)
99 InsertTextEncoding(nEnc);
100 m_xControl->thaw();
103 void SvxTextEncodingTreeView::FillFromDbTextEncodingMap(
104 bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
106 m_xControl->freeze();
107 auto aEncs = ::FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
108 for (auto nEnc : aEncs)
109 InsertTextEncoding(nEnc);
110 m_xControl->thaw();
113 SvxTextEncodingBox::SvxTextEncodingBox(std::unique_ptr<weld::ComboBox> pControl)
114 : m_xControl(std::move(pControl))
116 m_xControl->make_sorted();
119 SvxTextEncodingTreeView::SvxTextEncodingTreeView(std::unique_ptr<weld::TreeView> pControl)
120 : m_xControl(std::move(pControl))
122 m_xControl->make_sorted();
125 SvxTextEncodingBox::~SvxTextEncodingBox()
129 SvxTextEncodingTreeView::~SvxTextEncodingTreeView()
133 namespace
135 std::vector<int> FillFromTextEncodingTable(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
137 std::vector<int> aRet;
139 rtl_TextEncodingInfo aInfo;
140 aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
141 const sal_uInt32 nCount = SAL_N_ELEMENTS(RID_SVXSTR_TEXTENCODING_TABLE);
142 for (sal_uInt32 j = 0; j < nCount; ++j)
144 bool bInsert = true;
145 rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
146 if ( nExcludeInfoFlags )
148 if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
149 bInsert = false;
150 else
152 if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
154 if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
155 ((nEnc == RTL_TEXTENCODING_UCS2) ||
156 nEnc == RTL_TEXTENCODING_UCS4) )
157 bInsert = false; // InfoFlags don't work for Unicode :-(
159 else
160 bInsert = false;
163 if ( bExcludeImportSubsets )
165 switch ( nEnc )
167 // subsets of RTL_TEXTENCODING_GB_18030
168 case RTL_TEXTENCODING_GB_2312 :
169 case RTL_TEXTENCODING_GBK :
170 case RTL_TEXTENCODING_MS_936 :
171 bInsert = false;
172 break;
175 if ( bInsert )
176 aRet.push_back(j);
178 return aRet;
182 void SvxTextEncodingBox::FillFromTextEncodingTable(
183 bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
185 std::vector<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags));
186 m_xControl->freeze();
187 for (auto j : aRet)
189 rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
190 InsertTextEncoding(nEnc, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE[j].first));
192 m_xControl->thaw();
195 void SvxTextEncodingTreeView::FillFromTextEncodingTable(
196 bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
198 std::vector<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags));
199 m_xControl->freeze();
200 for (auto j : aRet)
202 rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
203 InsertTextEncoding(nEnc, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE[j].first));
205 m_xControl->thaw();
208 void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc,
209 const OUString& rEntry )
211 m_xControl->append(OUString::number(nEnc), rEntry);
214 void SvxTextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc,
215 const OUString& rEntry )
217 m_xControl->append(OUString::number(nEnc), rEntry);
220 void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc )
222 const OUString& rEntry = SvxTextEncodingTable::GetTextString(nEnc);
223 if (!rEntry.isEmpty())
224 InsertTextEncoding( nEnc, rEntry );
225 else
226 SAL_WARN( "svx.dialog", "SvxTextEncodingBox::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
229 void SvxTextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc )
231 const OUString& rEntry = SvxTextEncodingTable::GetTextString(nEnc);
232 if (!rEntry.isEmpty())
233 InsertTextEncoding( nEnc, rEntry );
234 else
235 SAL_WARN( "svx.dialog", "SvxTextEncodingTreeView::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
238 rtl_TextEncoding SvxTextEncodingBox::GetSelectTextEncoding() const
240 OUString sId(m_xControl->get_active_id());
241 if (!sId.isEmpty())
242 return rtl_TextEncoding(sId.toInt32());
243 else
244 return RTL_TEXTENCODING_DONTKNOW;
247 rtl_TextEncoding SvxTextEncodingTreeView::GetSelectTextEncoding() const
249 OUString sId(m_xControl->get_selected_id());
250 if (!sId.isEmpty())
251 return rtl_TextEncoding(sId.toInt32());
252 else
253 return RTL_TEXTENCODING_DONTKNOW;
256 void SvxTextEncodingBox::SelectTextEncoding( const rtl_TextEncoding nEnc )
258 m_xControl->set_active_id(OUString::number(nEnc));
261 void SvxTextEncodingTreeView::SelectTextEncoding( const rtl_TextEncoding nEnc )
263 m_xControl->select_id(OUString::number(nEnc));
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */