/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "vclxwindows_internal.hxx" #include using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::lang::EventObject; using ::com::sun::star::awt::ItemListEvent; using ::com::sun::star::awt::XItemList; using ::com::sun::star::graphic::XGraphic; using ::com::sun::star::graphic::XGraphicProvider; using namespace ::com::sun::star; using namespace ::com::sun::star::awt::VisualEffect; namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; static double ImplCalcLongValue( double nValue, sal_uInt16 nDigits ) { double n = nValue; for ( sal_uInt16 d = 0; d < nDigits; d++ ) n *= 10; return n; } static double ImplCalcDoubleValue( double nValue, sal_uInt16 nDigits ) { double n = nValue; for ( sal_uInt16 d = 0; d < nDigits; d++ ) n /= 10; return n; } namespace toolkit { /** sets the "face color" for button like controls (scroll bar, spin button) */ void setButtonLikeFaceColor( vcl::Window* _pWindow, const css::uno::Any& _rColorValue ) { AllSettings aSettings = _pWindow->GetSettings(); StyleSettings aStyleSettings = aSettings.GetStyleSettings(); if ( !_rColorValue.hasValue() ) { const StyleSettings& aAppStyle = Application::GetSettings().GetStyleSettings(); aStyleSettings.SetFaceColor( aAppStyle.GetFaceColor( ) ); aStyleSettings.SetCheckedColor( aAppStyle.GetCheckedColor( ) ); aStyleSettings.SetLightBorderColor( aAppStyle.GetLightBorderColor() ); aStyleSettings.SetLightColor( aAppStyle.GetLightColor() ); aStyleSettings.SetShadowColor( aAppStyle.GetShadowColor() ); aStyleSettings.SetDarkShadowColor( aAppStyle.GetDarkShadowColor() ); } else { Color nBackgroundColor; _rColorValue >>= 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 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 = nBackgroundColor.GetLuminance(); sal_Int32 nWhiteLuminance = COL_WHITE.GetLuminance(); Color aLightShadow( nBackgroundColor ); aLightShadow.IncreaseLuminance( static_cast( ( nWhiteLuminance - nBackgroundLuminance ) * 2 / 3 ) ); aStyleSettings.SetLightBorderColor( aLightShadow ); Color aLight( nBackgroundColor ); aLight.IncreaseLuminance( static_cast( ( nWhiteLuminance - nBackgroundLuminance ) * 1 / 3 ) ); aStyleSettings.SetLightColor( aLight ); Color aShadow( nBackgroundColor ); aShadow.DecreaseLuminance( static_cast( nBackgroundLuminance * 1 / 3 ) ); aStyleSettings.SetShadowColor( aShadow ); Color aDarkShadow( nBackgroundColor ); aDarkShadow.DecreaseLuminance( static_cast( nBackgroundLuminance * 2 / 3 ) ); aStyleSettings.SetDarkShadowColor( aDarkShadow ); } aSettings.SetStyleSettings( aStyleSettings ); _pWindow->SetSettings( aSettings, true ); } Any getButtonLikeFaceColor( const vcl::Window* _pWindow ) { Color nBackgroundColor = _pWindow->GetSettings().GetStyleSettings().GetFaceColor(); return Any( sal_Int32(nBackgroundColor) ); } static void adjustBooleanWindowStyle( const Any& _rValue, vcl::Window* _pWindow, WinBits _nBits, bool _bInverseSemantics ) { WinBits nStyle = _pWindow->GetStyle(); bool bValue( false ); OSL_VERIFY( _rValue >>= bValue ); if ( bValue != _bInverseSemantics ) nStyle |= _nBits; else nStyle &= ~_nBits; _pWindow->SetStyle( nStyle ); } static void setVisualEffect( const Any& _rValue, vcl::Window* _pWindow ) { AllSettings aSettings = _pWindow->GetSettings(); StyleSettings aStyleSettings = aSettings.GetStyleSettings(); sal_Int16 nStyle = LOOK3D; OSL_VERIFY( _rValue >>= nStyle ); switch ( nStyle ) { case FLAT: aStyleSettings.SetOptions( aStyleSettings.GetOptions() | StyleSettingsOptions::Mono ); break; case LOOK3D: default: aStyleSettings.SetOptions( aStyleSettings.GetOptions() & ~StyleSettingsOptions::Mono ); } aSettings.SetStyleSettings( aStyleSettings ); _pWindow->SetSettings( aSettings ); } static Any getVisualEffect( vcl::Window const * _pWindow ) { Any aEffect; StyleSettings aStyleSettings = _pWindow->GetSettings().GetStyleSettings(); if ( aStyleSettings.GetOptions() & StyleSettingsOptions::Mono ) aEffect <<= sal_Int16(FLAT); else aEffect <<= sal_Int16(LOOK3D); return aEffect; } } void VCLXGraphicControl::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) { PushPropertyIds(rIds, BASEPROPERTY_REFERER, 0); VCLXWindow::ImplGetPropertyIds( rIds ); } void VCLXGraphicControl::ImplSetNewImage() { OSL_PRECOND( GetWindow(), "VCLXGraphicControl::ImplSetNewImage: window is required to be not-NULL!" ); VclPtr< Button > pButton = GetAsDynamic< Button >(); pButton->SetModeImage( GetImage() ); } void VCLXGraphicControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) { SolarMutexGuard aGuard; if ( GetWindow() ) { Size aOldSize = GetWindow()->GetSizePixel(); VCLXWindow::setPosSize( X, Y, Width, Height, Flags ); if ( ( aOldSize.Width() != Width ) || ( aOldSize.Height() != Height ) ) ImplSetNewImage(); } } void VCLXGraphicControl::setProperty( const OUString& PropertyName, const css::uno::Any& Value) { SolarMutexGuard aGuard; if ( !GetWindow() ) return; sal_uInt16 nPropType = GetPropertyId( PropertyName ); switch ( nPropType ) { case BASEPROPERTY_GRAPHIC: { Reference< XGraphic > xGraphic; OSL_VERIFY( Value >>= xGraphic ); maImage = Image( xGraphic ); ImplSetNewImage(); } break; case BASEPROPERTY_IMAGEALIGN: { WindowType eType = GetWindow()->GetType(); if ( ( eType == WindowType::PUSHBUTTON ) || ( eType == WindowType::RADIOBUTTON ) || ( eType == WindowType::CHECKBOX ) ) { sal_Int16 nAlignment = sal_Int16(); if ( Value >>= nAlignment ) GetAs< Button >()->SetImageAlign( static_cast< ImageAlign >( nAlignment ) ); } } break; case BASEPROPERTY_IMAGEPOSITION: { WindowType eType = GetWindow()->GetType(); if ( ( eType == WindowType::PUSHBUTTON ) || ( eType == WindowType::RADIOBUTTON ) || ( eType == WindowType::CHECKBOX ) ) { sal_Int16 nImagePosition = 2; OSL_VERIFY( Value >>= nImagePosition ); GetAs