LibreOffice Module dbaccess (master) 1
charsetlistbox.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <charsetlistbox.hxx>
21
22#include <svl/itemset.hxx>
23#include <svl/stritem.hxx>
24#include <osl/diagnose.h>
25
26namespace dbaui
27{
28 CharSetListBox::CharSetListBox(std::unique_ptr<weld::ComboBox> xControl)
29 : m_xControl(std::move(xControl))
30 {
31 for (auto const& charset : m_aCharSets)
32 {
33 m_xControl->append_text(charset.getDisplayName());
34 }
35 }
36
37 void CharSetListBox::SelectEntryByIanaName( std::u16string_view _rIanaName )
38 {
40 if (aFind == m_aCharSets.end())
41 {
42 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
43 aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
44 }
45
46 if (aFind == m_aCharSets.end())
47 m_xControl->set_active(-1);
48 else
49 m_xControl->set_active_text((*aFind).getDisplayName());
50 }
51
53 {
54 bool bChangedSomething = false;
55 if (m_xControl->get_value_changed_from_saved())
56 {
58 OSL_ENSURE( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
59 if ( aFind != m_aCharSets.end() )
60 {
61 _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
62 bChangedSomething = true;
63 }
64 }
65 return bChangedSomething;
66 }
67} // namespace dbaui
68
69/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::ComboBox > m_xControl
OCharsetDisplay m_aCharSets
void SelectEntryByIanaName(std::u16string_view _rIanaName)
CharSetListBox(std::unique_ptr< weld::ComboBox > xControl)
bool StoreSelectedCharSet(SfxItemSet &_rSet, TypedWhichId< SfxStringItem > _nItemId)
const_iterator findIanaName(std::u16string_view _rIanaName) const
Definition: charsets.cxx:65
const_iterator findEncoding(const rtl_TextEncoding _eEncoding) const
Definition: charsets.cxx:59
const_iterator findDisplayName(const OUString &_rDisplayName) const
Definition: charsets.cxx:71
const_iterator end() const
get access to the (last + 1st) element of the charset collection
Definition: charsets.cxx:54
Reference< XControl > m_xControl