1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #include "charsetlistbox.hxx"
32 
33 /** === begin UNO includes === **/
34 /** === end UNO includes === **/
35 
36 #include <svl/itemset.hxx>
37 #include <svl/stritem.hxx>
38 
39 //........................................................................
40 namespace dbaui
41 {
42 //........................................................................
43 
44 	/** === begin UNO using === **/
45 	/** === end UNO using === **/
46 
47 	//====================================================================
48 	//= CharSetListBox
49 	//====================================================================
50 	//--------------------------------------------------------------------
51     CharSetListBox::CharSetListBox( Window* _pParent, const ResId& _rResId )
52         :ListBox( _pParent, _rResId )
53     {
54         SetDropDownLineCount( 20 );
55 
56         OCharsetDisplay::const_iterator charSet = m_aCharSets.begin();
57         while ( charSet != m_aCharSets.end() )
58         {
59             InsertEntry( (*charSet).getDisplayName() );
60             ++charSet;
61         }
62     }
63 
64 	//--------------------------------------------------------------------
65     CharSetListBox::~CharSetListBox()
66     {
67     }
68 
69     //--------------------------------------------------------------------
70     void CharSetListBox::SelectEntryByIanaName( const String& _rIanaName )
71     {
72         OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
73         if (aFind == m_aCharSets.end())
74         {
75             DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
76             aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
77         }
78 
79         if ( aFind == m_aCharSets.end() )
80         {
81             SelectEntry( String() );
82         }
83         else
84         {
85             String sDisplayName = (*aFind).getDisplayName();
86             if ( LISTBOX_ENTRY_NOTFOUND == GetEntryPos( sDisplayName ) )
87             {
88                 // in our settings, there was an encoding selected which is not valid for the current
89                 // data source type
90                 // This is worth at least an assertion.
91                 DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
92                 sDisplayName = String();
93             }
94 
95             SelectEntry( sDisplayName );
96         }
97     }
98 
99     //--------------------------------------------------------------------
100     bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, const sal_uInt16 _nItemId )
101     {
102         bool bChangedSomething = false;
103         if ( GetSelectEntryPos() != GetSavedValue() )
104         {
105             OCharsetDisplay::const_iterator aFind = m_aCharSets.findDisplayName( GetSelectEntry() );
106             DBG_ASSERT( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
107             if ( aFind != m_aCharSets.end() )
108             {
109                 _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
110                 bChangedSomething = true;
111             }
112         }
113         return bChangedSomething;
114     }
115 
116 //........................................................................
117 } // namespace dbaui
118 //........................................................................
119