xref: /AOO41X/main/dbaccess/source/ui/inc/charsets.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
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 #ifndef _DBAUI_CHARSETS_HXX_
25 #define _DBAUI_CHARSETS_HXX_
26 
27 #ifndef _STRING_HXX
28 #include <tools/string.hxx>
29 #endif
30 #ifndef _TOOLS_RC_HXX
31 #include <tools/rc.hxx>
32 #endif
33 #ifndef _DBHELPER_DBCHARSET_HXX_
34 #include <connectivity/dbcharset.hxx>
35 #endif
36 #ifndef _SVX_TXENCTAB_HXX
37 #include <svx/txenctab.hxx>
38 #endif
39 
40 //.........................................................................
41 namespace dbaui
42 {
43 //.........................................................................
44 
45     //=========================================================================
46     //= OCharsetDisplay
47     //=========================================================================
48     typedef ::dbtools::OCharsetMap OCharsetDisplay_Base;
49     class OCharsetDisplay
50             :protected OCharsetDisplay_Base
51             ,protected SvxTextEncodingTable
52     {
53     protected:
54         ::rtl::OUString m_aSystemDisplayName;
55 
56     public:
57         class ExtendedCharsetIterator;
58         friend class OCharsetDisplay::ExtendedCharsetIterator;
59 
60         typedef ExtendedCharsetIterator iterator;
61         typedef ExtendedCharsetIterator const_iterator;
62 
63         OCharsetDisplay();
64 
65         // various find operations
66         const_iterator findEncoding(const rtl_TextEncoding _eEncoding) const;
67         const_iterator findIanaName(const ::rtl::OUString& _rIanaName) const;
68         const_iterator findDisplayName(const ::rtl::OUString& _rDisplayName) const;
69 
70         /// get access to the first element of the charset collection
71         const_iterator  begin() const;
72         /// get access to the (last + 1st) element of the charset collection
73         const_iterator  end() const;
74         // size of the map
size() const75         sal_Int32   size() const { return OCharsetDisplay_Base::size(); }
76 
77     protected:
78         virtual sal_Bool approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const;
79 
80     private:
81         using OCharsetDisplay_Base::find;
82     };
83 
84     //-------------------------------------------------------------------------
85     //- CharsetDisplayDerefHelper
86     //-------------------------------------------------------------------------
87     typedef ::dbtools::CharsetIteratorDerefHelper CharsetDisplayDerefHelper_Base;
88     class CharsetDisplayDerefHelper : protected CharsetDisplayDerefHelper_Base
89     {
90         friend class OCharsetDisplay::ExtendedCharsetIterator;
91 
92         ::rtl::OUString                         m_sDisplayName;
93 
94     public:
95         CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper& _rSource);
96 
getEncoding() const97         rtl_TextEncoding    getEncoding() const         { return CharsetDisplayDerefHelper_Base::getEncoding(); }
getIanaName() const98         ::rtl::OUString     getIanaName() const         { return CharsetDisplayDerefHelper_Base::getIanaName(); }
getDisplayName() const99         ::rtl::OUString     getDisplayName() const      { return m_sDisplayName; }
100 
101     protected:
102         CharsetDisplayDerefHelper(const ::dbtools::CharsetIteratorDerefHelper& _rBase, const ::rtl::OUString& _rDisplayName);
103     };
104 
105     //-------------------------------------------------------------------------
106     //- OCharsetDisplay::ExtendedCharsetIterator
107     //-------------------------------------------------------------------------
108     class OCharsetDisplay::ExtendedCharsetIterator
109     {
110         friend class OCharsetDisplay;
111 
112         friend bool operator==(const ExtendedCharsetIterator& lhs, const ExtendedCharsetIterator& rhs);
operator !=(const ExtendedCharsetIterator & lhs,const ExtendedCharsetIterator & rhs)113         friend bool operator!=(const ExtendedCharsetIterator& lhs, const ExtendedCharsetIterator& rhs) { return !(lhs == rhs); }
114 
115         typedef ::dbtools::OCharsetMap      container;
116         typedef container::CharsetIterator  base_iterator;
117 
118     protected:
119         const OCharsetDisplay*      m_pContainer;
120         base_iterator               m_aPosition;
121 
122     public:
123         ExtendedCharsetIterator(const ExtendedCharsetIterator& _rSource);
124 
125         CharsetDisplayDerefHelper operator*() const;
126 
127         /// prefix increment
128         const ExtendedCharsetIterator&  operator++();
129         /// postfix increment
operator ++(int)130         const ExtendedCharsetIterator   operator++(int) { ExtendedCharsetIterator hold(*this); ++*this; return hold; }
131 
132         /// prefix decrement
133         const ExtendedCharsetIterator&  operator--();
134         /// postfix decrement
operator --(int)135         const ExtendedCharsetIterator   operator--(int) { ExtendedCharsetIterator hold(*this); --*this; return hold; }
136 
137     protected:
138         ExtendedCharsetIterator( const OCharsetDisplay* _pContainer, const base_iterator& _rPosition );
139     };
140 
141 //.........................................................................
142 }   // namespace dbaui
143 //.........................................................................
144 
145 #endif // _DBAUI_CHARSETS_HXX_
146 
147