196de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 596de5490SAndrew Rist * distributed with this work for additional information 696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 896de5490SAndrew Rist * "License"); you may not use this file except in compliance 996de5490SAndrew Rist * with the License. You may obtain a copy of the License at 1096de5490SAndrew Rist * 1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1296de5490SAndrew Rist * 1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 1496de5490SAndrew Rist * software distributed under the License is distributed on an 1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1696de5490SAndrew Rist * KIND, either express or implied. See the License for the 1796de5490SAndrew Rist * specific language governing permissions and limitations 1896de5490SAndrew Rist * under the License. 1996de5490SAndrew Rist * 2096de5490SAndrew Rist *************************************************************/ 2196de5490SAndrew Rist 2296de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25*b63233d8Sdamjan #include "precompiled_dbui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _DBAUI_CHARSETS_HXX_ 28cdf0e10cSrcweir #include "charsets.hxx" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX 31cdf0e10cSrcweir #include <tools/debug.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_ 34cdf0e10cSrcweir #include "dbu_misc.hrc" 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #ifndef _RTL_TENCINFO_H 37cdf0e10cSrcweir #include <rtl/tencinfo.h> 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #ifndef _TOOLS_RCID_H 40cdf0e10cSrcweir #include <tools/rcid.h> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #ifndef _DBAUI_LOCALRESACCESS_HXX_ 43cdf0e10cSrcweir #include "localresaccess.hxx" 44cdf0e10cSrcweir #endif 45cdf0e10cSrcweir 46cdf0e10cSrcweir //......................................................................... 47cdf0e10cSrcweir namespace dbaui 48cdf0e10cSrcweir { 49cdf0e10cSrcweir //......................................................................... 50cdf0e10cSrcweir using namespace ::dbtools; 51cdf0e10cSrcweir 52cdf0e10cSrcweir //========================================================================= 53cdf0e10cSrcweir //= OCharsetDisplay 54cdf0e10cSrcweir //========================================================================= 55cdf0e10cSrcweir //------------------------------------------------------------------------- OCharsetDisplay()56cdf0e10cSrcweir OCharsetDisplay::OCharsetDisplay() 57cdf0e10cSrcweir :OCharsetMap() 58cdf0e10cSrcweir ,SvxTextEncodingTable() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir { 61cdf0e10cSrcweir LocalResourceAccess aCharsetStrings( RSC_CHARSETS, RSC_RESOURCE ); 62cdf0e10cSrcweir m_aSystemDisplayName = String( ModuleRes( 1 ) ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir //------------------------------------------------------------------------- approveEncoding(const rtl_TextEncoding _eEncoding,const rtl_TextEncodingInfo & _rInfo) const67cdf0e10cSrcweir sal_Bool OCharsetDisplay::approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const 68cdf0e10cSrcweir { 69cdf0e10cSrcweir if ( !OCharsetMap::approveEncoding( _eEncoding, _rInfo ) ) 70cdf0e10cSrcweir return sal_False; 71cdf0e10cSrcweir 72cdf0e10cSrcweir if ( RTL_TEXTENCODING_DONTKNOW == _eEncoding ) 73cdf0e10cSrcweir return sal_True; 74cdf0e10cSrcweir 75cdf0e10cSrcweir return 0 != GetTextString( _eEncoding ).Len(); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir //------------------------------------------------------------------------- begin() const79cdf0e10cSrcweir OCharsetDisplay::const_iterator OCharsetDisplay::begin() const 80cdf0e10cSrcweir { 81cdf0e10cSrcweir return const_iterator( this, OCharsetMap::begin() ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir //------------------------------------------------------------------------- end() const85cdf0e10cSrcweir OCharsetDisplay::const_iterator OCharsetDisplay::end() const 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return const_iterator( this, OCharsetMap::end() ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir //------------------------------------------------------------------------- findEncoding(const rtl_TextEncoding _eEncoding) const91cdf0e10cSrcweir OCharsetDisplay::const_iterator OCharsetDisplay::findEncoding(const rtl_TextEncoding _eEncoding) const 92cdf0e10cSrcweir { 93cdf0e10cSrcweir OCharsetMap::const_iterator aBaseIter = OCharsetMap::find(_eEncoding); 94cdf0e10cSrcweir return const_iterator( this, aBaseIter ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir //------------------------------------------------------------------------- findIanaName(const::rtl::OUString & _rIanaName) const98cdf0e10cSrcweir OCharsetDisplay::const_iterator OCharsetDisplay::findIanaName(const ::rtl::OUString& _rIanaName) const 99cdf0e10cSrcweir { 100cdf0e10cSrcweir OCharsetMap::const_iterator aBaseIter = OCharsetMap::find(_rIanaName, OCharsetMap::IANA()); 101cdf0e10cSrcweir return const_iterator( this, aBaseIter ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir //------------------------------------------------------------------------- findDisplayName(const::rtl::OUString & _rDisplayName) const105cdf0e10cSrcweir OCharsetDisplay::const_iterator OCharsetDisplay::findDisplayName(const ::rtl::OUString& _rDisplayName) const 106cdf0e10cSrcweir { 107cdf0e10cSrcweir rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW; 108cdf0e10cSrcweir if ( _rDisplayName != m_aSystemDisplayName ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir eEncoding = GetTextEncoding( _rDisplayName ); 111cdf0e10cSrcweir OSL_ENSURE( RTL_TEXTENCODING_DONTKNOW != eEncoding, 112cdf0e10cSrcweir "OCharsetDisplay::find: non-empty display name, but DONTKNOW!" ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir return const_iterator( this, OCharsetMap::find( eEncoding ) ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir //========================================================================= 118cdf0e10cSrcweir //= CharsetDisplayDerefHelper 119cdf0e10cSrcweir //========================================================================= 120cdf0e10cSrcweir //------------------------------------------------------------------------- CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper & _rSource)121cdf0e10cSrcweir CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper& _rSource) 122cdf0e10cSrcweir :CharsetDisplayDerefHelper_Base(_rSource) 123cdf0e10cSrcweir ,m_sDisplayName(m_sDisplayName) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir //------------------------------------------------------------------------- CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper_Base & _rBase,const::rtl::OUString & _rDisplayName)128cdf0e10cSrcweir CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper_Base& _rBase, const ::rtl::OUString& _rDisplayName) 129cdf0e10cSrcweir :CharsetDisplayDerefHelper_Base(_rBase) 130cdf0e10cSrcweir ,m_sDisplayName(_rDisplayName) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir DBG_ASSERT( m_sDisplayName.getLength(), "CharsetDisplayDerefHelper::CharsetDisplayDerefHelper: invalid display name!" ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir //========================================================================= 136cdf0e10cSrcweir //= OCharsetDisplay::ExtendedCharsetIterator 137cdf0e10cSrcweir //========================================================================= 138cdf0e10cSrcweir //------------------------------------------------------------------------- ExtendedCharsetIterator(const OCharsetDisplay * _pContainer,const base_iterator & _rPosition)139cdf0e10cSrcweir OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator( const OCharsetDisplay* _pContainer, const base_iterator& _rPosition ) 140cdf0e10cSrcweir :m_pContainer(_pContainer) 141cdf0e10cSrcweir ,m_aPosition(_rPosition) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir DBG_ASSERT(m_pContainer, "OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator : invalid container!"); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir //------------------------------------------------------------------------- ExtendedCharsetIterator(const ExtendedCharsetIterator & _rSource)147cdf0e10cSrcweir OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator(const ExtendedCharsetIterator& _rSource) 148cdf0e10cSrcweir :m_pContainer( _rSource.m_pContainer ) 149cdf0e10cSrcweir ,m_aPosition( _rSource.m_aPosition ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir //------------------------------------------------------------------------- operator *() const154cdf0e10cSrcweir CharsetDisplayDerefHelper OCharsetDisplay::ExtendedCharsetIterator::operator*() const 155cdf0e10cSrcweir { 156cdf0e10cSrcweir DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator* : invalid position!"); 157cdf0e10cSrcweir 158cdf0e10cSrcweir rtl_TextEncoding eEncoding = (*m_aPosition).getEncoding(); 159cdf0e10cSrcweir return CharsetDisplayDerefHelper( 160cdf0e10cSrcweir *m_aPosition, 161cdf0e10cSrcweir RTL_TEXTENCODING_DONTKNOW == eEncoding ? m_pContainer->m_aSystemDisplayName : (::rtl::OUString)m_pContainer->GetTextString( eEncoding ) 162cdf0e10cSrcweir ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir //------------------------------------------------------------------------- operator ++()166cdf0e10cSrcweir const OCharsetDisplay::ExtendedCharsetIterator& OCharsetDisplay::ExtendedCharsetIterator::operator++() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator++ : invalid position!"); 169cdf0e10cSrcweir if ( m_aPosition != m_pContainer->OCharsetDisplay_Base::end() ) 170cdf0e10cSrcweir ++m_aPosition; 171cdf0e10cSrcweir return *this; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir //------------------------------------------------------------------------- operator --()175cdf0e10cSrcweir const OCharsetDisplay::ExtendedCharsetIterator& OCharsetDisplay::ExtendedCharsetIterator::operator--() 176cdf0e10cSrcweir { 177cdf0e10cSrcweir DBG_ASSERT( m_aPosition != m_pContainer->OCharsetDisplay_Base::begin(), "OCharsetDisplay::ExtendedCharsetIterator::operator-- : invalid position!"); 178cdf0e10cSrcweir if ( m_aPosition != m_pContainer->OCharsetDisplay_Base::begin() ) 179cdf0e10cSrcweir --m_aPosition; 180cdf0e10cSrcweir return *this; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir //------------------------------------------------------------------------- operator ==(const OCharsetDisplay::ExtendedCharsetIterator & lhs,const OCharsetDisplay::ExtendedCharsetIterator & rhs)184cdf0e10cSrcweir bool operator==(const OCharsetDisplay::ExtendedCharsetIterator& lhs, const OCharsetDisplay::ExtendedCharsetIterator& rhs) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_aPosition == rhs.m_aPosition); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir //......................................................................... 190cdf0e10cSrcweir } // namespace dbaui 191cdf0e10cSrcweir //......................................................................... 192cdf0e10cSrcweir 193