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 _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX 25 #define _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX 26 27 #include <rtl/ustrbuf.hxx> 28 #include <hash_map> 29 30 namespace accessibility { 31 32 /** This is a color name lookup targeted to be used by the accessibility 33 <type>DescriptionGenerator</type> class (hence the DG prefix). It 34 encapsulates a <type>com.sun.star.drawing.ColorTable</type> and provides 35 an inverse look up of color names for given a numerical color 36 descriptions--the RGB values encoded as integer. 37 38 <p>The class itself is designed as singleton so that the 39 <type>com.sun.star.drawing.ColorTable</type> object needs to be created 40 only once.</p> 41 42 <p>The singleton instance of this class lives at the moment until the 43 application terminates. However, the color table from which it takes 44 its values may change during this time. Reacting to these changes 45 remains a task for the future.</p> 46 */ 47 class DGColorNameLookUp 48 { 49 public: 50 /** Return the single instance of this class. Use this to look up 51 color names with the <member>LookUpColor()</member> method. 52 */ 53 static DGColorNameLookUp& Instance (void); 54 55 /** Return the color name of the color expressed by the given integer. 56 @param nColor 57 This integer is the sum of the 8 Bit red value shifted left 16 58 Bits, the green value shifted left 8 Bits, and the unshifted 59 blue value. 60 @return 61 The returned string is either the color name of the specified 62 color or, when no name exists, a string of the form "#RRGGBB" 63 with two hexadecimal digits for each color component. 64 */ 65 ::rtl::OUString LookUpColor (long int nColor) const; 66 67 private: 68 /// Define hash map type to convert numerical color values to names. 69 typedef std::hash_map<long int, ::rtl::OUString> 70 tColorValueToNameMap; 71 72 /// This ma translates from numerical color values to names. 73 tColorValueToNameMap maColorValueToNameMap; 74 75 /** The pointer to the only instance of this class. It is NULL until 76 the <member>Instance</member> is called for the first time. 77 */ 78 static DGColorNameLookUp* mpInstance; 79 80 /// Create a new (the only) instance of this class. 81 DGColorNameLookUp (void); 82 83 /// The destructor is never called. 84 ~DGColorNameLookUp (void); 85 86 /// The copy constructor is not implemented. 87 DGColorNameLookUp (const DGColorNameLookUp&); 88 89 /// The assignment operator is not implemented. 90 DGColorNameLookUp& operator= (const DGColorNameLookUp&); 91 }; 92 93 } // end of namespace accessibility 94 95 #endif 96