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