1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <unotools/syslocale.hxx>
29 #include <rtl/tencinfo.h>
30 #include <sal/log.hxx>
31 #include <txenctab.hrc>
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
;
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
++ )
49 rtl_TextEncoding nEnc
= rtl_TextEncoding( aEncs
[j
] );
50 if ( nExcludeInfoFlags
)
52 if ( !rtl_getTextEncodingInfo( nEnc
, &aInfo
) )
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 :-(
69 if ( bExcludeImportSubsets
)
73 // subsets of RTL_TEXTENCODING_GB_18030
74 case RTL_TEXTENCODING_GB_2312
:
75 case RTL_TEXTENCODING_GBK
:
76 case RTL_TEXTENCODING_MS_936
:
81 // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
82 // makes no sense here and would result in an empty string as list
84 if ( bInsert
&& nEnc
!= RTL_TEXTENCODING_DONTKNOW
)
93 void SvxTextEncodingBox::FillFromDbTextEncodingMap(
94 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
97 auto aEncs
= ::FillFromDbTextEncodingMap(bExcludeImportSubsets
, nExcludeInfoFlags
);
98 for (auto nEnc
: aEncs
)
99 InsertTextEncoding(nEnc
);
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
);
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()
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
)
145 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
146 if ( nExcludeInfoFlags
)
148 if ( !rtl_getTextEncodingInfo( nEnc
, &aInfo
) )
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 :-(
163 if ( bExcludeImportSubsets
)
167 // subsets of RTL_TEXTENCODING_GB_18030
168 case RTL_TEXTENCODING_GB_2312
:
169 case RTL_TEXTENCODING_GBK
:
170 case RTL_TEXTENCODING_MS_936
:
182 void SvxTextEncodingBox::FillFromTextEncodingTable(
183 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
185 std::vector
<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets
, nExcludeInfoFlags
));
186 m_xControl
->freeze();
189 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
190 InsertTextEncoding(nEnc
, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE
[j
].first
));
195 void SvxTextEncodingTreeView::FillFromTextEncodingTable(
196 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
198 std::vector
<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets
, nExcludeInfoFlags
));
199 m_xControl
->freeze();
202 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
203 InsertTextEncoding(nEnc
, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE
[j
].first
));
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
);
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
);
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());
242 return rtl_TextEncoding(sId
.toInt32());
244 return RTL_TEXTENCODING_DONTKNOW
;
247 rtl_TextEncoding
SvxTextEncodingTreeView::GetSelectTextEncoding() const
249 OUString
sId(m_xControl
->get_selected_id());
251 return rtl_TextEncoding(sId
.toInt32());
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: */