diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-01-15 14:49:12 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-01-16 10:07:07 +0100 |
commit | 63a68064bb33f180b8a231f7524d99405d910226 (patch) | |
tree | 7ecf05b057c5ca4d80a48af045998a4b34484561 /toolkit | |
parent | d534a4c7b45ff254b339e806c6a11f13d9ff0043 (diff) |
make the Color constructors explicitly specify transparency
to reduce the churn, we leave the existing constructor in place,
and add a clang plugin to detect when the value passed to the
existing constructor may contain transparency/alpha data.
i.e. we leave expressions like Color(0xffffff) alone, but
warn about any non-constant expression, and any expression
like Color(0xff000000)
Change-Id: Id2ce58e08882d9b7bd0b9f88eca97359dcdbcc8c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109362
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/source/awt/stylesettings.cxx | 2 | ||||
-rw-r--r-- | toolkit/source/awt/vclxgraphics.cxx | 10 | ||||
-rw-r--r-- | toolkit/source/awt/vclxwindow.cxx | 39 | ||||
-rw-r--r-- | toolkit/source/awt/vclxwindows.cxx | 31 |
4 files changed, 34 insertions, 48 deletions
diff --git a/toolkit/source/awt/stylesettings.cxx b/toolkit/source/awt/stylesettings.cxx index 65218b33aa32..6d6419090c38 100644 --- a/toolkit/source/awt/stylesettings.cxx +++ b/toolkit/source/awt/stylesettings.cxx @@ -145,7 +145,7 @@ namespace toolkit VclPtr<vcl::Window> pWindow = i_rData.pOwningWindow->GetWindow(); AllSettings aAllSettings = pWindow->GetSettings(); StyleSettings aStyleSettings = aAllSettings.GetStyleSettings(); - (aStyleSettings.*i_pSetter)( Color(i_nColor) ); + (aStyleSettings.*i_pSetter)( Color(ColorTransparency, i_nColor) ); aAllSettings.SetStyleSettings( aStyleSettings ); pWindow->SetSettings( aAllSettings ); } diff --git a/toolkit/source/awt/vclxgraphics.cxx b/toolkit/source/awt/vclxgraphics.cxx index 54f6286b8993..3125a0341030 100644 --- a/toolkit/source/awt/vclxgraphics.cxx +++ b/toolkit/source/awt/vclxgraphics.cxx @@ -168,28 +168,28 @@ void VCLXGraphics::setTextColor( sal_Int32 nColor ) { SolarMutexGuard aGuard; - maTextColor = Color( nColor ); + maTextColor = Color( ColorTransparency, nColor ); } void VCLXGraphics::setTextFillColor( sal_Int32 nColor ) { SolarMutexGuard aGuard; - maTextFillColor = Color( nColor ); + maTextFillColor = Color( ColorTransparency, nColor ); } void VCLXGraphics::setLineColor( sal_Int32 nColor ) { SolarMutexGuard aGuard; - maLineColor = Color( nColor ); + maLineColor = Color( ColorTransparency, nColor ); } void VCLXGraphics::setFillColor( sal_Int32 nColor ) { SolarMutexGuard aGuard; - maFillColor = Color( nColor ); + maFillColor = Color( ColorTransparency, nColor ); } void VCLXGraphics::setRasterOp( awt::RasterOperation eROP ) @@ -436,7 +436,7 @@ void VCLXGraphics::drawGradient( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_ return; InitOutputDevice( InitOutDevFlags::COLORS ); - Gradient aGradient(static_cast<GradientStyle>(rGradient.Style), Color(rGradient.StartColor), Color(rGradient.EndColor)); + Gradient aGradient(static_cast<GradientStyle>(rGradient.Style), Color(ColorTransparency, rGradient.StartColor), Color(ColorTransparency, rGradient.EndColor)); aGradient.SetAngle(Degree10(rGradient.Angle)); aGradient.SetBorder(rGradient.Border); aGradient.SetOfsX(rGradient.XOffset); diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx index 18ce820ab417..1e7c15918ab4 100644 --- a/toolkit/source/awt/vclxwindow.cxx +++ b/toolkit/source/awt/vclxwindow.cxx @@ -1126,7 +1126,7 @@ void VCLXWindow::setBackground( sal_Int32 nColor ) if ( !GetWindow() ) return; - Color aColor(nColor); + Color aColor(ColorTransparency, nColor); GetWindow()->SetBackground( aColor ); GetWindow()->SetControlBackground( aColor ); @@ -1199,7 +1199,7 @@ void VCLXWindow::setForeground( sal_Int32 nColor ) if ( GetWindow() ) { - GetWindow()->SetControlForeground( Color(nColor) ); + GetWindow()->SetControlForeground( Color(ColorTransparency, nColor) ); } } @@ -1252,7 +1252,7 @@ namespace toolkit AllSettings aSettings = _pWindow->GetSettings(); StyleSettings aStyleSettings = aSettings.GetStyleSettings(); - (aStyleSettings.*pSetter)( Color( nColor ) ); + (aStyleSettings.*pSetter)( Color( ColorTransparency, nColor ) ); aSettings.SetStyleSettings( aStyleSettings ); _pWindow->SetSettings( aSettings, true ); @@ -1597,10 +1597,9 @@ void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& } else { - sal_Int32 nColor = 0; - if ( Value >>= nColor ) + Color aColor; + if ( Value >>= aColor ) { - Color aColor( nColor ); pWindow->SetControlBackground( aColor ); pWindow->SetBackground( aColor ); switch ( eWinType ) @@ -1627,12 +1626,11 @@ void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& } else { - sal_Int32 nColor = 0; + Color nColor ; if ( Value >>= nColor ) { - Color aColor( nColor ); - pWindow->SetTextColor( aColor ); - pWindow->SetControlForeground( aColor ); + pWindow->SetTextColor( nColor ); + pWindow->SetControlForeground( nColor ); } } break; @@ -1643,12 +1641,9 @@ void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& } else { - sal_Int32 nColor = 0; + Color nColor; if ( Value >>= nColor ) - { - Color aColor( nColor ); - pWindow->SetTextLineColor( aColor ); - } + pWindow->SetTextLineColor( nColor ); } break; case BASEPROPERTY_FILLCOLOR: @@ -1656,12 +1651,9 @@ void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& pWindow->SetFillColor(); else { - sal_Int32 nColor = 0; + Color nColor; if ( Value >>= nColor ) - { - Color aColor( nColor ); - pWindow->SetFillColor( aColor ); - } + pWindow->SetFillColor( nColor ); } break; case BASEPROPERTY_LINECOLOR: @@ -1669,12 +1661,9 @@ void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& pWindow->SetLineColor(); else { - sal_Int32 nColor = 0; + Color nColor; if ( Value >>= nColor ) - { - Color aColor( nColor ); - pWindow->SetLineColor( aColor ); - } + pWindow->SetLineColor( nColor ); } break; case BASEPROPERTY_BORDER: diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index d7404132d545..a589db2cd3a1 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -118,20 +118,20 @@ namespace toolkit } else { - sal_Int32 nBackgroundColor = 0; + Color nBackgroundColor; _rColorValue >>= nBackgroundColor; - aStyleSettings.SetFaceColor( Color(nBackgroundColor) ); + aStyleSettings.SetFaceColor( nBackgroundColor ); // for the real background (everything except the buttons and the thumb), // use an average between the desired color and "white" Color aWhite( COL_WHITE ); - Color aBackground( nBackgroundColor ); - aBackground.SetRed( ( aBackground.GetRed() + aWhite.GetRed() ) / 2 ); - aBackground.SetGreen( ( aBackground.GetGreen() + aWhite.GetGreen() ) / 2 ); - aBackground.SetBlue( ( aBackground.GetBlue() + aWhite.GetBlue() ) / 2 ); - aStyleSettings.SetCheckedColor( aBackground ); + Color aCheckedBackground( nBackgroundColor ); + aCheckedBackground.SetRed( ( aCheckedBackground.GetRed() + aWhite.GetRed() ) / 2 ); + aCheckedBackground.SetGreen( ( aCheckedBackground.GetGreen() + aWhite.GetGreen() ) / 2 ); + aCheckedBackground.SetBlue( ( aCheckedBackground.GetBlue() + aWhite.GetBlue() ) / 2 ); + aStyleSettings.SetCheckedColor( aCheckedBackground ); - sal_Int32 nBackgroundLuminance = Color( nBackgroundColor ).GetLuminance(); + sal_Int32 nBackgroundLuminance = nBackgroundColor.GetLuminance(); sal_Int32 nWhiteLuminance = COL_WHITE.GetLuminance(); Color aLightShadow( nBackgroundColor ); @@ -6354,7 +6354,7 @@ void VCLXProgressBar::setForegroundColor( sal_Int32 nColor ) VclPtr<vcl::Window> pWindow = GetWindow(); if ( pWindow ) { - pWindow->SetControlForeground( Color(nColor) ); + pWindow->SetControlForeground( Color(ColorTransparency, nColor) ); } } @@ -6365,7 +6365,7 @@ void VCLXProgressBar::setBackgroundColor( sal_Int32 nColor ) VclPtr<vcl::Window> pWindow = GetWindow(); if ( pWindow ) { - Color aColor( nColor ); + Color aColor( ColorTransparency, nColor ); pWindow->SetBackground( aColor ); pWindow->SetControlBackground( aColor ); pWindow->Invalidate(); @@ -6450,12 +6450,9 @@ void VCLXProgressBar::setProperty( const OUString& PropertyName, const css::uno: } else { - sal_Int32 nColor = 0; + Color nColor; if ( Value >>= nColor ) - { - Color aColor( nColor ); - pWindow->SetControlForeground( aColor ); - } + pWindow->SetControlForeground( nColor ); } } } @@ -7834,9 +7831,9 @@ void SAL_CALL SVTXDateField::setProperty( const OUString& PropertyName, const cs pSubEdit->SetTextLineColor(); else { - sal_Int32 nColor = 0; + Color nColor; if ( Value >>= nColor ) - pSubEdit->SetTextLineColor( Color( nColor ) ); + pSubEdit->SetTextLineColor( nColor ); } break; } |