1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3334a7e6SAndrew Rist  * distributed with this work for additional information
6*3334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3334a7e6SAndrew Rist  *
11*3334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist  *
13*3334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist  * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3334a7e6SAndrew Rist  * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist  * under the License.
19*3334a7e6SAndrew Rist  *
20*3334a7e6SAndrew Rist  *************************************************************/
21*3334a7e6SAndrew Rist 
22*3334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX
25cdf0e10cSrcweir #define _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
28cdf0e10cSrcweir #include <hash_map>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace accessibility {
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /** This is a color name lookup targeted to be used by the accessibility
33cdf0e10cSrcweir     <type>DescriptionGenerator</type> class (hence the DG prefix).  It
34cdf0e10cSrcweir     encapsulates a <type>com.sun.star.drawing.ColorTable</type> and provides
35cdf0e10cSrcweir     an inverse look up of color names for given a numerical color
36cdf0e10cSrcweir     descriptions--the RGB values encoded as integer.
37cdf0e10cSrcweir 
38cdf0e10cSrcweir     <p>The class itself is designed as singleton so that the
39cdf0e10cSrcweir     <type>com.sun.star.drawing.ColorTable</type> object needs to be created
40cdf0e10cSrcweir     only once.</p>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     <p>The singleton instance of this class lives at the moment until the
43cdf0e10cSrcweir     application terminates.  However, the color table from which it takes
44cdf0e10cSrcweir     its values may change during this time.  Reacting to these changes
45cdf0e10cSrcweir     remains a task for the future.</p>
46cdf0e10cSrcweir */
47cdf0e10cSrcweir class DGColorNameLookUp
48cdf0e10cSrcweir {
49cdf0e10cSrcweir public:
50cdf0e10cSrcweir     /** Return the single instance of this class.  Use this to look up
51cdf0e10cSrcweir         color names with the <member>LookUpColor()</member> method.
52cdf0e10cSrcweir     */
53cdf0e10cSrcweir     static DGColorNameLookUp& Instance (void);
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** Return the color name of the color expressed by the given integer.
56cdf0e10cSrcweir         @param nColor
57cdf0e10cSrcweir             This integer is the sum of the 8 Bit red value shifted left 16
58cdf0e10cSrcweir             Bits, the green value shifted left 8 Bits, and the unshifted
59cdf0e10cSrcweir             blue value.
60cdf0e10cSrcweir         @return
61cdf0e10cSrcweir             The returned string is either the color name of the specified
62cdf0e10cSrcweir             color or, when no name exists, a string of the form "#RRGGBB"
63cdf0e10cSrcweir             with two hexadecimal digits for each color component.
64cdf0e10cSrcweir     */
65cdf0e10cSrcweir     ::rtl::OUString LookUpColor (long int nColor) const;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir private:
68cdf0e10cSrcweir     /// Define hash map type to convert numerical color values to names.
69cdf0e10cSrcweir     typedef std::hash_map<long int, ::rtl::OUString>
70cdf0e10cSrcweir         tColorValueToNameMap;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /// This ma translates from numerical color values to names.
73cdf0e10cSrcweir     tColorValueToNameMap maColorValueToNameMap;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /** The pointer to the only instance of this class.  It is NULL until
76cdf0e10cSrcweir         the <member>Instance</member> is called for the first time.
77cdf0e10cSrcweir     */
78cdf0e10cSrcweir     static DGColorNameLookUp* mpInstance;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /// Create a new (the only) instance of this class.
81cdf0e10cSrcweir     DGColorNameLookUp (void);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /// The destructor is never called.
84cdf0e10cSrcweir     ~DGColorNameLookUp (void);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /// The copy constructor is not implemented.
87cdf0e10cSrcweir     DGColorNameLookUp (const DGColorNameLookUp&);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /// The assignment operator is not implemented.
90cdf0e10cSrcweir     DGColorNameLookUp& operator= (const DGColorNameLookUp&);
91cdf0e10cSrcweir };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir } // end of namespace accessibility
94cdf0e10cSrcweir 
95cdf0e10cSrcweir #endif
96