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