tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / oox / drawingml / color.hxx
blobdc8be778f6658bd32616372f31a0a946c74c2e41
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OOX_DRAWINGML_COLOR_HXX
21 #define INCLUDED_OOX_DRAWINGML_COLOR_HXX
23 #include <vector>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <oox/helper/helper.hxx>
28 #include <oox/dllapi.h>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
31 #include <tools/color.hxx>
32 #include <docmodel/theme/ThemeColorType.hxx>
33 #include <docmodel/color/ComplexColor.hxx>
35 namespace oox { class GraphicHelper; }
37 namespace oox::drawingml
40 model::ThemeColorType schemeTokenToThemeColorType(sal_uInt32 nToken);
41 model::ThemeColorType schemeNameToThemeColorType(OUString const& rSchemeName);
43 class OOX_DLLPUBLIC Color
45 public:
46 Color();
48 /** Returns the RGB value for the passed DrawingML color token, or nDefaultRgb on error. */
49 static ::Color getDmlPresetColor( sal_Int32 nToken, ::Color nDefaultRgb );
50 /** Returns the RGB value for the passed VML color token, or nDefaultRgb on error. */
51 static ::Color getVmlPresetColor( sal_Int32 nToken, ::Color nDefaultRgb );
52 /** Returns the RGB value for the passed VML color token, or nDefaultRgb on error. */
53 static ::Color getHighlightColor(sal_Int32 nToken, ::Color nDefaultRgb);
55 /** Sets the color to unused state. */
56 void setUnused();
57 /** Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element. */
58 void setSrgbClr( sal_Int32 nRgb );
59 void setSrgbClr( ::Color nRgb );
60 /** Sets the percentual RGB values from the a:scrgbClr element. */
61 void setScrgbClr( sal_Int32 nR, sal_Int32 nG, sal_Int32 nB );
62 /** Sets the HSL values from the a:hslClr element. */
63 void setHslClr( sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum );
64 /** Sets a predefined color from the a:prstClr element. */
65 void setPrstClr( sal_Int32 nToken );
66 /** Sets a predefined color from the w:highlight element. */
67 void setHighlight(sal_Int32 nToken);
68 /** Sets a scheme color from the a:schemeClr element. */
69 void setSchemeClr( sal_Int32 nToken );
70 /** Sets the scheme name from the a:schemeClr element for interoperability purposes */
71 void setSchemeName( const OUString& sSchemeName ) { msSchemeName = sSchemeName; }
72 /** Sets a system color from the a:sysClr element. */
73 void setSysClr( sal_Int32 nToken, sal_Int32 nLastRgb );
74 /** Sets a palette color index. */
75 void setPaletteClr( sal_Int32 nPaletteIdx );
77 /** Inserts the passed color transformation. */
78 void addTransformation( sal_Int32 nElement, sal_Int32 nValue = -1 );
79 /** Inserts Chart specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */
80 void addChartTintTransformation( double fTint );
81 /** Inserts Excel specific color tint (-1.0...0.0 = shade, 0.0...1.0 = tint). */
82 void addExcelTintTransformation( double fTint );
83 /** Removes all color transformations. */
84 void clearTransformations();
85 /** Removes transparence from the color. */
86 void clearTransparence();
88 /** Overwrites this color with the passed color, if it is used. */
89 void assignIfUsed( const Color& rColor ) { if( rColor.isUsed() ) *this = rColor; }
91 /** Returns true, if the color is initialized. */
92 bool isUsed() const { return meMode != COLOR_UNUSED; }
93 /** Returns true, if the color is a placeholder color in theme style lists. */
94 bool isPlaceHolder() const { return meMode == COLOR_PH; }
95 /** Returns the final RGB color value.
96 @param nPhClr Actual color for the phClr placeholder color used in theme style lists. */
97 ::Color getColor( const GraphicHelper& rGraphicHelper, ::Color nPhClr = API_RGB_TRANSPARENT ) const;
99 /** Returns true, if the color is transparent. */
100 bool hasTransparency() const;
101 /** Returns the transparency of the color (0 = opaque, 100 = full transparent). */
102 sal_Int16 getTransparency() const;
104 /** Returns the scheme name from the a:schemeClr element for interoperability purposes */
105 const OUString& getSchemeColorName() const { return msSchemeName; }
106 sal_Int16 getSchemeColorIndex() const;
107 sal_Int16 getTintOrShade() const;
108 sal_Int16 getLumMod() const;
109 sal_Int16 getLumOff() const;
111 model::ThemeColorType getThemeColorType() const
113 return meThemeColorType;
116 model::ComplexColor createComplexColor(const GraphicHelper& rGraphicHelper, sal_Int16 nPhClrTheme) const;
118 /** Returns the unaltered list of transformations for interoperability purposes */
119 const css::uno::Sequence< css::beans::PropertyValue >& getTransformations() const { return maInteropTransformations;}
121 /** Translates between color transformation tokens and their names */
122 static OUString getColorTransformationName( sal_Int32 nElement );
123 /** Translates between color transformation token names and the corresponding token */
124 static sal_Int32 getColorTransformationToken( std::u16string_view sName );
125 /** Translates between ColorMap token names and the corresponding token */
126 static sal_Int32 getColorMapToken(std::u16string_view sName);
128 /// Compares this color with rOther.
129 bool equals(const Color& rOther, const GraphicHelper& rGraphicHelper, ::Color nPhClr) const;
131 model::ComplexColor getComplexColor() const;
133 private:
134 /** Internal helper for getColor(). */
135 void setResolvedRgb( ::Color nRgb ) const;
137 /** Converts the color components to RGB values. */
138 void toRgb() const;
139 /** Converts the color components to CRGB values (gamma corrected percentage). */
140 void toCrgb() const;
141 /** Converts the color components to HSL values. */
142 void toHsl() const;
144 private:
145 enum ColorMode
147 COLOR_UNUSED, /// Color is not used, or undefined.
148 COLOR_RGB, /// Absolute RGB (r/g/b: 0...255).
149 COLOR_CRGB, /// Relative RGB (r/g/b: 0...100000).
150 COLOR_HSL, /// HSL (hue: 0...21600000, sat/lum: 0...100000).
151 COLOR_SCHEME, /// Color from scheme.
152 COLOR_PALETTE, /// Color from application defined palette.
153 COLOR_SYSTEM, /// Color from system palette.
154 COLOR_PH, /// Placeholder color in theme style lists.
155 COLOR_FINAL /// Finalized RGB color.
158 struct Transformation
160 sal_Int32 mnToken;
161 sal_Int32 mnValue;
163 explicit Transformation( sal_Int32 nToken, sal_Int32 nValue ) : mnToken( nToken ), mnValue( nValue ) {}
166 mutable ColorMode meMode; /// Current color mode.
167 mutable std::vector< Transformation >
168 maTransforms; /// Color transformations.
169 mutable sal_Int32 mnC1; /// Red, red%, hue, scheme token, palette index, system token, or final RGB.
170 mutable sal_Int32 mnC2; /// Green, green%, saturation, or system default RGB.
171 mutable sal_Int32 mnC3; /// Blue, blue%, or luminance.
172 sal_Int32 mnAlpha; /// Alpha value (color opacity).
173 OUString msSchemeName; /// Scheme name from the a:schemeClr element for interoperability purposes
174 model::ThemeColorType meThemeColorType;
175 css::uno::Sequence< css::beans::PropertyValue >
176 maInteropTransformations; /// Unaltered list of transformations for interoperability purposes
179 } // namespace oox::drawingml
181 #endif
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */