tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / dbaccess / source / ui / control / charsetlistbox.cxx
blobba2f2943fcdbc01301bb53e8d0f470bf4c1d639e
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 <charsetlistbox.hxx>
22 #include <svl/itemset.hxx>
23 #include <svl/stritem.hxx>
24 #include <osl/diagnose.h>
26 namespace dbaui
28 CharSetListBox::CharSetListBox(std::unique_ptr<weld::ComboBox> xControl)
29 : m_xControl(std::move(xControl))
31 for (auto const charset : m_aCharSets)
33 m_xControl->append_text(charset.getDisplayName());
37 void CharSetListBox::SelectEntryByIanaName( std::u16string_view _rIanaName )
39 OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
40 if (aFind == m_aCharSets.end())
42 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
43 aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
46 if (aFind == m_aCharSets.end())
47 m_xControl->set_active(-1);
48 else
49 m_xControl->set_active_text((*aFind).getDisplayName());
52 bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, TypedWhichId<SfxStringItem> _nItemId )
54 bool bChangedSomething = false;
55 if (m_xControl->get_value_changed_from_saved())
57 OCharsetDisplay::const_iterator aFind = m_aCharSets.findDisplayName(m_xControl->get_active_text());
58 OSL_ENSURE( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
59 if ( aFind != m_aCharSets.end() )
61 _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
62 bChangedSomething = true;
65 return bChangedSomething;
67 } // namespace dbaui
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */