Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ui / control / charsetlistbox.cxx
blobe7f427bcc89a32feb8dde54ad32a227fe58b8ef5
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 <vcl/builderfactory.hxx>
23 #include <svl/itemset.hxx>
24 #include <svl/stritem.hxx>
25 #include <osl/diagnose.h>
27 namespace dbaui
29 CharSetListBox::CharSetListBox( vcl::Window* _pParent, WinBits _nBits = WB_DROPDOWN )
30 : ListBox( _pParent, _nBits )
32 SetDropDownLineCount( 20 );
34 OCharsetDisplay::const_iterator charSet = m_aCharSets.begin();
35 while ( charSet != m_aCharSets.end() )
37 InsertEntry( (*charSet).getDisplayName() );
38 ++charSet;
42 VCL_BUILDER_FACTORY(CharSetListBox)
44 void CharSetListBox::SelectEntryByIanaName( const OUString& _rIanaName )
46 OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
47 if (aFind == m_aCharSets.end())
49 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
50 aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
53 if ( aFind == m_aCharSets.end() )
55 SelectEntry( OUString() );
57 else
59 OUString sDisplayName = (*aFind).getDisplayName();
60 if ( LISTBOX_ENTRY_NOTFOUND == GetEntryPos( sDisplayName ) )
62 // in our settings, there was an encoding selected which is not valid for the current
63 // data source type
64 // This is worth at least an assertion.
65 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
66 sDisplayName.clear();
69 SelectEntry( sDisplayName );
73 bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, const sal_uInt16 _nItemId )
75 bool bChangedSomething = false;
76 if ( IsValueChangedFromSaved() )
78 OCharsetDisplay::const_iterator aFind = m_aCharSets.findDisplayName( GetSelectEntry() );
79 OSL_ENSURE( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
80 if ( aFind != m_aCharSets.end() )
82 _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
83 bChangedSomething = true;
86 return bChangedSomething;
89 } // namespace dbaui
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */