update dev300-m58
[ooovba.git] / dbaccess / source / ui / misc / charsets.cxx
blobde06d61f23facc20bba7f8ff04f63ec8065701b6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: charsets.cxx,v $
10 * $Revision: 1.14.68.1 $
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 #ifndef _DBAUI_CHARSETS_HXX_
35 #include "charsets.hxx"
36 #endif
37 #ifndef _TOOLS_DEBUG_HXX
38 #include <tools/debug.hxx>
39 #endif
40 #ifndef _DBU_MISC_HRC_
41 #include "dbu_misc.hrc"
42 #endif
43 #ifndef _RTL_TENCINFO_H
44 #include <rtl/tencinfo.h>
45 #endif
46 #ifndef _TOOLS_RCID_H
47 #include <tools/rcid.h>
48 #endif
49 #ifndef _DBAUI_LOCALRESACCESS_HXX_
50 #include "localresaccess.hxx"
51 #endif
53 //.........................................................................
54 namespace dbaui
56 //.........................................................................
57 using namespace ::dbtools;
59 //=========================================================================
60 //= OCharsetDisplay
61 //=========================================================================
62 //-------------------------------------------------------------------------
63 OCharsetDisplay::OCharsetDisplay()
64 :OCharsetMap()
65 ,SvxTextEncodingTable()
68 LocalResourceAccess aCharsetStrings( RSC_CHARSETS, RSC_RESOURCE );
69 m_aSystemDisplayName = String( ModuleRes( 1 ) );
73 //-------------------------------------------------------------------------
74 sal_Bool OCharsetDisplay::approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const
76 if ( !OCharsetMap::approveEncoding( _eEncoding, _rInfo ) )
77 return sal_False;
79 if ( RTL_TEXTENCODING_DONTKNOW == _eEncoding )
80 return sal_True;
82 return 0 != GetTextString( _eEncoding ).Len();
85 //-------------------------------------------------------------------------
86 OCharsetDisplay::const_iterator OCharsetDisplay::begin() const
88 return const_iterator( this, OCharsetMap::begin() );
91 //-------------------------------------------------------------------------
92 OCharsetDisplay::const_iterator OCharsetDisplay::end() const
94 return const_iterator( this, OCharsetMap::end() );
97 //-------------------------------------------------------------------------
98 OCharsetDisplay::const_iterator OCharsetDisplay::findEncoding(const rtl_TextEncoding _eEncoding) const
100 OCharsetMap::const_iterator aBaseIter = OCharsetMap::find(_eEncoding);
101 return const_iterator( this, aBaseIter );
104 //-------------------------------------------------------------------------
105 OCharsetDisplay::const_iterator OCharsetDisplay::findIanaName(const ::rtl::OUString& _rIanaName) const
107 OCharsetMap::const_iterator aBaseIter = OCharsetMap::find(_rIanaName, OCharsetMap::IANA());
108 return const_iterator( this, aBaseIter );
111 //-------------------------------------------------------------------------
112 OCharsetDisplay::const_iterator OCharsetDisplay::findDisplayName(const ::rtl::OUString& _rDisplayName) const
114 rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
115 if ( _rDisplayName != m_aSystemDisplayName )
117 eEncoding = GetTextEncoding( _rDisplayName );
118 OSL_ENSURE( RTL_TEXTENCODING_DONTKNOW != eEncoding,
119 "OCharsetDisplay::find: non-empty display name, but DONTKNOW!" );
121 return const_iterator( this, OCharsetMap::find( eEncoding ) );
124 //=========================================================================
125 //= CharsetDisplayDerefHelper
126 //=========================================================================
127 //-------------------------------------------------------------------------
128 CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper& _rSource)
129 :CharsetDisplayDerefHelper_Base(_rSource)
130 ,m_sDisplayName(m_sDisplayName)
134 //-------------------------------------------------------------------------
135 CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper_Base& _rBase, const ::rtl::OUString& _rDisplayName)
136 :CharsetDisplayDerefHelper_Base(_rBase)
137 ,m_sDisplayName(_rDisplayName)
139 DBG_ASSERT( m_sDisplayName.getLength(), "CharsetDisplayDerefHelper::CharsetDisplayDerefHelper: invalid display name!" );
142 //=========================================================================
143 //= OCharsetDisplay::ExtendedCharsetIterator
144 //=========================================================================
145 //-------------------------------------------------------------------------
146 OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator( const OCharsetDisplay* _pContainer, const base_iterator& _rPosition )
147 :m_pContainer(_pContainer)
148 ,m_aPosition(_rPosition)
150 DBG_ASSERT(m_pContainer, "OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator : invalid container!");
153 //-------------------------------------------------------------------------
154 OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator(const ExtendedCharsetIterator& _rSource)
155 :m_pContainer( _rSource.m_pContainer )
156 ,m_aPosition( _rSource.m_aPosition )
160 //-------------------------------------------------------------------------
161 CharsetDisplayDerefHelper OCharsetDisplay::ExtendedCharsetIterator::operator*() const
163 DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator* : invalid position!");
165 rtl_TextEncoding eEncoding = (*m_aPosition).getEncoding();
166 return CharsetDisplayDerefHelper(
167 *m_aPosition,
168 RTL_TEXTENCODING_DONTKNOW == eEncoding ? m_pContainer->m_aSystemDisplayName : (::rtl::OUString)m_pContainer->GetTextString( eEncoding )
172 //-------------------------------------------------------------------------
173 const OCharsetDisplay::ExtendedCharsetIterator& OCharsetDisplay::ExtendedCharsetIterator::operator++()
175 DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator++ : invalid position!");
176 if ( m_aPosition != m_pContainer->OCharsetDisplay_Base::end() )
177 ++m_aPosition;
178 return *this;
181 //-------------------------------------------------------------------------
182 const OCharsetDisplay::ExtendedCharsetIterator& OCharsetDisplay::ExtendedCharsetIterator::operator--()
184 DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::begin(), "OCharsetDisplay::ExtendedCharsetIterator::operator-- : invalid position!");
185 if ( m_aPosition != m_pContainer->OCharsetDisplay_Base::begin() )
186 --m_aPosition;
187 return *this;
190 //-------------------------------------------------------------------------
191 bool operator==(const OCharsetDisplay::ExtendedCharsetIterator& lhs, const OCharsetDisplay::ExtendedCharsetIterator& rhs)
193 return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_aPosition == rhs.m_aPosition);
196 //.........................................................................
197 } // namespace dbaui
198 //.........................................................................