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 <svl/itemset.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <osl/diagnose.h>
25 :
26 : //........................................................................
27 : namespace dbaui
28 : {
29 : //====================================================================
30 : //= CharSetListBox
31 : //====================================================================
32 : //--------------------------------------------------------------------
33 0 : CharSetListBox::CharSetListBox( Window* _pParent, const ResId& _rResId )
34 0 : :ListBox( _pParent, _rResId )
35 : {
36 0 : SetDropDownLineCount( 20 );
37 :
38 0 : OCharsetDisplay::const_iterator charSet = m_aCharSets.begin();
39 0 : while ( charSet != m_aCharSets.end() )
40 : {
41 0 : InsertEntry( (*charSet).getDisplayName() );
42 0 : ++charSet;
43 0 : }
44 0 : }
45 :
46 : //--------------------------------------------------------------------
47 0 : CharSetListBox::~CharSetListBox()
48 : {
49 0 : }
50 :
51 : //--------------------------------------------------------------------
52 0 : void CharSetListBox::SelectEntryByIanaName( const String& _rIanaName )
53 : {
54 0 : OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
55 0 : if (aFind == m_aCharSets.end())
56 : {
57 : OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
58 0 : aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
59 : }
60 :
61 0 : if ( aFind == m_aCharSets.end() )
62 : {
63 0 : SelectEntry( String() );
64 : }
65 : else
66 : {
67 0 : String sDisplayName = (*aFind).getDisplayName();
68 0 : if ( LISTBOX_ENTRY_NOTFOUND == GetEntryPos( sDisplayName ) )
69 : {
70 : // in our settings, there was an encoding selected which is not valid for the current
71 : // data source type
72 : // This is worth at least an assertion.
73 : OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
74 0 : sDisplayName = String();
75 : }
76 :
77 0 : SelectEntry( sDisplayName );
78 0 : }
79 0 : }
80 :
81 : //--------------------------------------------------------------------
82 0 : bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, const sal_uInt16 _nItemId )
83 : {
84 0 : bool bChangedSomething = false;
85 0 : if ( GetSelectEntryPos() != GetSavedValue() )
86 : {
87 0 : OCharsetDisplay::const_iterator aFind = m_aCharSets.findDisplayName( GetSelectEntry() );
88 : OSL_ENSURE( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
89 0 : if ( aFind != m_aCharSets.end() )
90 : {
91 0 : _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
92 0 : bChangedSomething = true;
93 0 : }
94 : }
95 0 : return bChangedSomething;
96 : }
97 :
98 : //........................................................................
99 12 : } // namespace dbaui
100 : //........................................................................
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|