1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #include "charsetlistbox.hxx"
28 
29 /** === begin UNO includes === **/
30 /** === end UNO includes === **/
31 
32 #include <svl/itemset.hxx>
33 #include <svl/stritem.hxx>
34 
35 //........................................................................
36 namespace dbaui
37 {
38 //........................................................................
39 
40 	/** === begin UNO using === **/
41 	/** === end UNO using === **/
42 
43 	//====================================================================
44 	//= CharSetListBox
45 	//====================================================================
46 	//--------------------------------------------------------------------
CharSetListBox(Window * _pParent,const ResId & _rResId)47     CharSetListBox::CharSetListBox( Window* _pParent, const ResId& _rResId )
48         :ListBox( _pParent, _rResId )
49     {
50         SetDropDownLineCount( 20 );
51 
52         OCharsetDisplay::const_iterator charSet = m_aCharSets.begin();
53         while ( charSet != m_aCharSets.end() )
54         {
55             InsertEntry( (*charSet).getDisplayName() );
56             ++charSet;
57         }
58     }
59 
60 	//--------------------------------------------------------------------
~CharSetListBox()61     CharSetListBox::~CharSetListBox()
62     {
63     }
64 
65     //--------------------------------------------------------------------
SelectEntryByIanaName(const String & _rIanaName)66     void CharSetListBox::SelectEntryByIanaName( const String& _rIanaName )
67     {
68         OCharsetDisplay::const_iterator aFind = m_aCharSets.findIanaName( _rIanaName );
69         if (aFind == m_aCharSets.end())
70         {
71             DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
72             aFind = m_aCharSets.findEncoding( RTL_TEXTENCODING_DONTKNOW );
73         }
74 
75         if ( aFind == m_aCharSets.end() )
76         {
77             SelectEntry( String() );
78         }
79         else
80         {
81             String sDisplayName = (*aFind).getDisplayName();
82             if ( LISTBOX_ENTRY_NOTFOUND == GetEntryPos( sDisplayName ) )
83             {
84                 // in our settings, there was an encoding selected which is not valid for the current
85                 // data source type
86                 // This is worth at least an assertion.
87                 DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
88                 sDisplayName = String();
89             }
90 
91             SelectEntry( sDisplayName );
92         }
93     }
94 
95     //--------------------------------------------------------------------
StoreSelectedCharSet(SfxItemSet & _rSet,const sal_uInt16 _nItemId)96     bool CharSetListBox::StoreSelectedCharSet( SfxItemSet& _rSet, const sal_uInt16 _nItemId )
97     {
98         bool bChangedSomething = false;
99         if ( GetSelectEntryPos() != GetSavedValue() )
100         {
101             OCharsetDisplay::const_iterator aFind = m_aCharSets.findDisplayName( GetSelectEntry() );
102             DBG_ASSERT( aFind != m_aCharSets.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
103             if ( aFind != m_aCharSets.end() )
104             {
105                 _rSet.Put( SfxStringItem( _nItemId, (*aFind).getIanaName() ) );
106                 bChangedSomething = true;
107             }
108         }
109         return bChangedSomething;
110     }
111 
112 //........................................................................
113 } // namespace dbaui
114 //........................................................................
115