Line data Source code
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 <vcl/builderfactory.hxx>
23 : #include <svl/itemset.hxx>
24 : #include <svl/stritem.hxx>
25 : #include <osl/diagnose.h>
26 :
27 : namespace dbaui
28 : {
29 0 : CharSetListBox::CharSetListBox( vcl::Window* _pParent, WinBits _nBits = WB_DROPDOWN )
30 0 : : ListBox( _pParent, _nBits )
31 : {
32 0 : SetDropDownLineCount( 20 );
33 :
34 0 : OCharsetDisplay::const_iterator charSet = m_aCharSets.begin();
35 0 : while ( charSet != m_aCharSets.end() )
36 : {
37 0 : InsertEntry( (*charSet).getDisplayName() );
38 0 : ++charSet;
39 0 : }
40 0 : }
41 :
42 0 : VCL_BUILDER_FACTORY(CharSetListBox)
43 :
44 0 : void CharSetListBox::SelectEntryByIanaName( const OUString& _rIanaName )
45 : {
46 0 : OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
47 0 : if (aFind == m_aCharSets.end())
48 : {
49 : OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
50 0 : aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
51 : }
52 :
53 0 : if ( aFind == m_aCharSets.end() )
54 : {
55 0 : SelectEntry( OUString() );
56 : }
57 : else
58 : {
59 0 : OUString sDisplayName = (*aFind).getDisplayName();
60 0 : if ( LISTBOX_ENTRY_NOTFOUND == GetEntryPos( sDisplayName ) )
61 : {
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 0 : sDisplayName.clear();
67 : }
68 :
69 0 : SelectEntry( sDisplayName );
70 0 : }
71 0 : }
72 :
73 0 : bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, const sal_uInt16 _nItemId )
74 : {
75 0 : bool bChangedSomething = false;
76 0 : if ( IsValueChangedFromSaved() )
77 : {
78 0 : 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 0 : if ( aFind != m_aCharSets.end() )
81 : {
82 0 : _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
83 0 : bChangedSomething = true;
84 0 : }
85 : }
86 0 : return bChangedSomething;
87 : }
88 :
89 : } // namespace dbaui
90 :
91 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|