1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: charsetlistbox.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "charsetlistbox.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
39 #include <svtools/itemset.hxx>
40 #include <svtools/stritem.hxx>
42 //........................................................................
45 //........................................................................
47 /** === begin UNO using === **/
48 /** === end UNO using === **/
50 //====================================================================
52 //====================================================================
53 //--------------------------------------------------------------------
54 CharSetListBox::CharSetListBox( Window
* _pParent
, const ResId
& _rResId
)
55 :ListBox( _pParent
, _rResId
)
57 SetDropDownLineCount( 20 );
59 OCharsetDisplay::const_iterator charSet
= m_aCharSets
.begin();
60 while ( charSet
!= m_aCharSets
.end() )
62 InsertEntry( (*charSet
).getDisplayName() );
67 //--------------------------------------------------------------------
68 CharSetListBox::~CharSetListBox()
72 //--------------------------------------------------------------------
73 void CharSetListBox::SelectEntryByIanaName( const String
& _rIanaName
)
75 OCharsetDisplay::const_iterator aFind
= m_aCharSets
.findIanaName( _rIanaName
);
76 if (aFind
== m_aCharSets
.end())
78 DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
79 aFind
= m_aCharSets
.findEncoding( RTL_TEXTENCODING_DONTKNOW
);
82 if ( aFind
== m_aCharSets
.end() )
84 SelectEntry( String() );
88 String sDisplayName
= (*aFind
).getDisplayName();
89 if ( LISTBOX_ENTRY_NOTFOUND
== GetEntryPos( sDisplayName
) )
91 // in our settings, there was an encoding selected which is not valid for the current
93 // This is worth at least an assertion.
94 DBG_ERROR( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
95 sDisplayName
= String();
98 SelectEntry( sDisplayName
);
102 //--------------------------------------------------------------------
103 bool CharSetListBox::StoreSelectedCharSet( SfxItemSet
& _rSet
, const USHORT _nItemId
)
105 bool bChangedSomething
= false;
106 if ( GetSelectEntryPos() != GetSavedValue() )
108 OCharsetDisplay::const_iterator aFind
= m_aCharSets
.findDisplayName( GetSelectEntry() );
109 DBG_ASSERT( aFind
!= m_aCharSets
.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
110 if ( aFind
!= m_aCharSets
.end() )
112 _rSet
.Put( SfxStringItem( _nItemId
, (*aFind
).getIanaName() ) );
113 bChangedSomething
= true;
116 return bChangedSomething
;
119 //........................................................................
121 //........................................................................