1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "charsetlistbox.hxx"
32 /** === begin UNO includes === **/
33 /** === end UNO includes === **/
35 #include <svl/itemset.hxx>
36 #include <svl/stritem.hxx>
37 #include <osl/diagnose.h>
39 //........................................................................
42 //........................................................................
44 /** === begin UNO using === **/
45 /** === end UNO using === **/
47 //====================================================================
49 //====================================================================
50 //--------------------------------------------------------------------
51 CharSetListBox::CharSetListBox( Window
* _pParent
, const ResId
& _rResId
)
52 :ListBox( _pParent
, _rResId
)
54 SetDropDownLineCount( 20 );
56 OCharsetDisplay::const_iterator charSet
= m_aCharSets
.begin();
57 while ( charSet
!= m_aCharSets
.end() )
59 InsertEntry( (*charSet
).getDisplayName() );
64 //--------------------------------------------------------------------
65 CharSetListBox::~CharSetListBox()
69 //--------------------------------------------------------------------
70 void CharSetListBox::SelectEntryByIanaName( const String
& _rIanaName
)
72 OCharsetDisplay::const_iterator aFind
= m_aCharSets
.findIanaName( _rIanaName
);
73 if (aFind
== m_aCharSets
.end())
75 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: unknown charset falling back to system language!" );
76 aFind
= m_aCharSets
.findEncoding( RTL_TEXTENCODING_DONTKNOW
);
79 if ( aFind
== m_aCharSets
.end() )
81 SelectEntry( String() );
85 String sDisplayName
= (*aFind
).getDisplayName();
86 if ( LISTBOX_ENTRY_NOTFOUND
== GetEntryPos( sDisplayName
) )
88 // in our settings, there was an encoding selected which is not valid for the current
90 // This is worth at least an assertion.
91 OSL_FAIL( "CharSetListBox::SelectEntryByIanaName: invalid character set!" );
92 sDisplayName
= String();
95 SelectEntry( sDisplayName
);
99 //--------------------------------------------------------------------
100 bool CharSetListBox::StoreSelectedCharSet( SfxItemSet
& _rSet
, const sal_uInt16 _nItemId
)
102 bool bChangedSomething
= false;
103 if ( GetSelectEntryPos() != GetSavedValue() )
105 OCharsetDisplay::const_iterator aFind
= m_aCharSets
.findDisplayName( GetSelectEntry() );
106 OSL_ENSURE( aFind
!= m_aCharSets
.end(), "CharSetListBox::StoreSelectedCharSet: could not translate the selected character set!" );
107 if ( aFind
!= m_aCharSets
.end() )
109 _rSet
.Put( SfxStringItem( _nItemId
, (*aFind
).getIanaName() ) );
110 bChangedSomething
= true;
113 return bChangedSomething
;
116 //........................................................................
118 //........................................................................
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */