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 <rtl/tencinfo.h>
29 #include <sal/log.hxx>
30 #include <txenctab.hrc>
34 std::vector
<rtl_TextEncoding
> FillFromDbTextEncodingMap(bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
36 std::vector
<rtl_TextEncoding
> aRet
;
37 #if !HAVE_FEATURE_DBCONNECTIVITY
38 (void)bExcludeImportSubsets
;
39 (void)nExcludeInfoFlags
;
41 rtl_TextEncodingInfo aInfo
;
42 aInfo
.StructSize
= sizeof(rtl_TextEncodingInfo
);
43 ::std::vector
< rtl_TextEncoding
> aEncs
;
44 sal_Int32 nCount
= svxform::charset_helper::getSupportedTextEncodings( aEncs
);
45 for ( sal_Int32 j
=0; j
<nCount
; j
++ )
48 rtl_TextEncoding nEnc
= rtl_TextEncoding( aEncs
[j
] );
49 if ( nExcludeInfoFlags
)
51 if ( !rtl_getTextEncodingInfo( nEnc
, &aInfo
) )
55 if ( (aInfo
.Flags
& nExcludeInfoFlags
) == 0 )
57 if ( (nExcludeInfoFlags
& RTL_TEXTENCODING_INFO_UNICODE
) &&
58 ((nEnc
== RTL_TEXTENCODING_UCS2
) ||
59 nEnc
== RTL_TEXTENCODING_UCS4
) )
60 bInsert
= false; // InfoFlags don't work for Unicode :-(
68 if ( bExcludeImportSubsets
)
72 // subsets of RTL_TEXTENCODING_GB_18030
73 case RTL_TEXTENCODING_GB_2312
:
74 case RTL_TEXTENCODING_GBK
:
75 case RTL_TEXTENCODING_MS_936
:
80 // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
81 // makes no sense here and would result in an empty string as list
83 if ( bInsert
&& nEnc
!= RTL_TEXTENCODING_DONTKNOW
)
92 void SvxTextEncodingBox::FillFromDbTextEncodingMap(
93 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
96 auto aEncs
= ::FillFromDbTextEncodingMap(bExcludeImportSubsets
, nExcludeInfoFlags
);
97 for (auto nEnc
: aEncs
)
98 InsertTextEncoding(nEnc
);
102 void SvxTextEncodingTreeView::FillFromDbTextEncodingMap(
103 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
105 m_xControl
->freeze();
106 auto aEncs
= ::FillFromDbTextEncodingMap(bExcludeImportSubsets
, nExcludeInfoFlags
);
107 for (auto nEnc
: aEncs
)
108 InsertTextEncoding(nEnc
);
112 SvxTextEncodingBox::SvxTextEncodingBox(std::unique_ptr
<weld::ComboBox
> pControl
)
113 : m_xControl(std::move(pControl
))
115 m_xControl
->make_sorted();
118 SvxTextEncodingTreeView::SvxTextEncodingTreeView(std::unique_ptr
<weld::TreeView
> pControl
)
119 : m_xControl(std::move(pControl
))
121 m_xControl
->make_sorted();
124 SvxTextEncodingBox::~SvxTextEncodingBox()
128 SvxTextEncodingTreeView::~SvxTextEncodingTreeView()
134 std::vector
<int> FillFromTextEncodingTable(bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
136 std::vector
<int> aRet
;
138 rtl_TextEncodingInfo aInfo
;
139 aInfo
.StructSize
= sizeof(rtl_TextEncodingInfo
);
140 const sal_uInt32 nCount
= SAL_N_ELEMENTS(RID_SVXSTR_TEXTENCODING_TABLE
);
141 for (sal_uInt32 j
= 0; j
< nCount
; ++j
)
144 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
145 if ( nExcludeInfoFlags
)
147 if ( !rtl_getTextEncodingInfo( nEnc
, &aInfo
) )
151 if ( (aInfo
.Flags
& nExcludeInfoFlags
) == 0 )
153 if ( (nExcludeInfoFlags
& RTL_TEXTENCODING_INFO_UNICODE
) &&
154 ((nEnc
== RTL_TEXTENCODING_UCS2
) ||
155 nEnc
== RTL_TEXTENCODING_UCS4
) )
156 bInsert
= false; // InfoFlags don't work for Unicode :-(
162 if ( bExcludeImportSubsets
)
166 // subsets of RTL_TEXTENCODING_GB_18030
167 case RTL_TEXTENCODING_GB_2312
:
168 case RTL_TEXTENCODING_GBK
:
169 case RTL_TEXTENCODING_MS_936
:
181 void SvxTextEncodingBox::FillFromTextEncodingTable(
182 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
184 std::vector
<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets
, nExcludeInfoFlags
));
185 m_xControl
->freeze();
188 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
189 InsertTextEncoding(nEnc
, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE
[j
].first
));
194 void SvxTextEncodingTreeView::FillFromTextEncodingTable(
195 bool bExcludeImportSubsets
, sal_uInt32 nExcludeInfoFlags
)
197 std::vector
<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets
, nExcludeInfoFlags
));
198 m_xControl
->freeze();
201 rtl_TextEncoding nEnc
= RID_SVXSTR_TEXTENCODING_TABLE
[j
].second
;
202 InsertTextEncoding(nEnc
, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE
[j
].first
));
207 void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc
,
208 const OUString
& rEntry
)
210 m_xControl
->append(OUString::number(nEnc
), rEntry
);
213 void SvxTextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc
,
214 const OUString
& rEntry
)
216 m_xControl
->append(OUString::number(nEnc
), rEntry
);
219 void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc
)
221 const OUString aEntry
= SvxTextEncodingTable::GetTextString(nEnc
);
222 if (!aEntry
.isEmpty())
223 InsertTextEncoding( nEnc
, aEntry
);
225 SAL_WARN( "svx.dialog", "SvxTextEncodingBox::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32
>( nEnc
) );
228 void SvxTextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc
)
230 const OUString aEntry
= SvxTextEncodingTable::GetTextString(nEnc
);
231 if (!aEntry
.isEmpty())
232 InsertTextEncoding( nEnc
, aEntry
);
234 SAL_WARN( "svx.dialog", "SvxTextEncodingTreeView::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32
>( nEnc
) );
237 rtl_TextEncoding
SvxTextEncodingBox::GetSelectTextEncoding() const
239 OUString
sId(m_xControl
->get_active_id());
241 return rtl_TextEncoding(sId
.toInt32());
243 return RTL_TEXTENCODING_DONTKNOW
;
246 rtl_TextEncoding
SvxTextEncodingTreeView::GetSelectTextEncoding() const
248 OUString
sId(m_xControl
->get_selected_id());
250 return rtl_TextEncoding(sId
.toInt32());
252 return RTL_TEXTENCODING_DONTKNOW
;
255 void SvxTextEncodingBox::SelectTextEncoding( const rtl_TextEncoding nEnc
)
257 m_xControl
->set_active_id(OUString::number(nEnc
));
260 void SvxTextEncodingTreeView::SelectTextEncoding( const rtl_TextEncoding nEnc
)
262 m_xControl
->select_id(OUString::number(nEnc
));
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */