From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- toolkit/source/awt/animatedimagespeer.cxx | 521 ++ toolkit/source/awt/asynccallback.cxx | 121 + toolkit/source/awt/non-interactable-containers.xml | 32 + toolkit/source/awt/scrollabledialog.cxx | 173 + toolkit/source/awt/stylesettings.cxx | 949 +++ toolkit/source/awt/stylesettings.hxx | 172 + toolkit/source/awt/vclxaccessiblecomponent.cxx | 824 ++ toolkit/source/awt/vclxbitmap.cxx | 65 + toolkit/source/awt/vclxcontainer.cxx | 293 + toolkit/source/awt/vclxdevice.cxx | 298 + toolkit/source/awt/vclxfont.cxx | 194 + toolkit/source/awt/vclxgraphics.cxx | 492 ++ toolkit/source/awt/vclxmenu.cxx | 855 ++ toolkit/source/awt/vclxpointer.cxx | 73 + toolkit/source/awt/vclxprinter.cxx | 383 + toolkit/source/awt/vclxregion.cxx | 147 + toolkit/source/awt/vclxspinbutton.cxx | 331 + toolkit/source/awt/vclxsystemdependentwindow.cxx | 114 + toolkit/source/awt/vclxtabpagecontainer.cxx | 230 + toolkit/source/awt/vclxtoolkit.cxx | 2639 +++++++ toolkit/source/awt/vclxtopwindow.cxx | 251 + toolkit/source/awt/vclxwindow.cxx | 2525 ++++++ toolkit/source/awt/vclxwindow1.cxx | 95 + toolkit/source/awt/vclxwindows.cxx | 8135 ++++++++++++++++++++ toolkit/source/awt/vclxwindows_internal.hxx | 33 + .../source/controls/accessiblecontrolcontext.cxx | 350 + toolkit/source/controls/animatedimages.cxx | 498 ++ .../source/controls/controlmodelcontainerbase.cxx | 1825 +++++ .../controlmodelcontainerbase_internal.hxx | 30 + toolkit/source/controls/dialogcontrol.cxx | 1235 +++ toolkit/source/controls/eventcontainer.cxx | 181 + toolkit/source/controls/filectrl.cxx | 244 + toolkit/source/controls/formattedcontrol.cxx | 490 ++ toolkit/source/controls/geometrycontrolmodel.cxx | 612 ++ .../controls/grid/defaultgridcolumnmodel.cxx | 393 + .../source/controls/grid/defaultgriddatamodel.cxx | 510 ++ toolkit/source/controls/grid/gridcolumn.cxx | 310 + toolkit/source/controls/grid/gridcolumn.hxx | 127 + toolkit/source/controls/grid/gridcontrol.cxx | 461 ++ toolkit/source/controls/grid/gridcontrol.hxx | 142 + .../source/controls/grid/grideventforwarder.cxx | 128 + .../source/controls/grid/grideventforwarder.hxx | 77 + .../source/controls/grid/sortablegriddatamodel.cxx | 929 +++ toolkit/source/controls/roadmapcontrol.cxx | 513 ++ toolkit/source/controls/roadmapentry.cxx | 106 + toolkit/source/controls/spinningprogress.cxx | 132 + toolkit/source/controls/stdtabcontroller.cxx | 415 + toolkit/source/controls/stdtabcontrollermodel.cxx | 440 ++ toolkit/source/controls/tabpagecontainer.cxx | 353 + toolkit/source/controls/tabpagemodel.cxx | 306 + toolkit/source/controls/tkscrollbar.cxx | 324 + toolkit/source/controls/tkspinbutton.cxx | 426 + toolkit/source/controls/tree/treecontrol.cxx | 515 ++ toolkit/source/controls/tree/treecontrol.hxx | 64 + toolkit/source/controls/tree/treecontrolpeer.cxx | 1581 ++++ toolkit/source/controls/tree/treedatamodel.cxx | 529 ++ toolkit/source/controls/unocontrol.cxx | 1562 ++++ toolkit/source/controls/unocontrolbase.cxx | 253 + toolkit/source/controls/unocontrolcontainer.cxx | 823 ++ .../source/controls/unocontrolcontainermodel.cxx | 93 + toolkit/source/controls/unocontrolmodel.cxx | 1396 ++++ toolkit/source/controls/unocontrols.cxx | 4861 ++++++++++++ toolkit/source/helper/accessibilityclient.cxx | 220 + toolkit/source/helper/btndlg.cxx | 305 + toolkit/source/helper/formpdfexport.cxx | 648 ++ toolkit/source/helper/imagealign.cxx | 128 + toolkit/source/helper/listenermultiplexer.cxx | 261 + toolkit/source/helper/property.cxx | 379 + toolkit/source/helper/servicenames.cxx | 25 + toolkit/source/helper/tkresmgr.cxx | 56 + toolkit/source/helper/unopropertyarrayhelper.cxx | 148 + toolkit/source/helper/unowrapper.cxx | 298 + toolkit/source/helper/vclunohelper.cxx | 591 ++ 73 files changed, 46238 insertions(+) create mode 100644 toolkit/source/awt/animatedimagespeer.cxx create mode 100644 toolkit/source/awt/asynccallback.cxx create mode 100644 toolkit/source/awt/non-interactable-containers.xml create mode 100644 toolkit/source/awt/scrollabledialog.cxx create mode 100644 toolkit/source/awt/stylesettings.cxx create mode 100644 toolkit/source/awt/stylesettings.hxx create mode 100644 toolkit/source/awt/vclxaccessiblecomponent.cxx create mode 100644 toolkit/source/awt/vclxbitmap.cxx create mode 100644 toolkit/source/awt/vclxcontainer.cxx create mode 100644 toolkit/source/awt/vclxdevice.cxx create mode 100644 toolkit/source/awt/vclxfont.cxx create mode 100644 toolkit/source/awt/vclxgraphics.cxx create mode 100644 toolkit/source/awt/vclxmenu.cxx create mode 100644 toolkit/source/awt/vclxpointer.cxx create mode 100644 toolkit/source/awt/vclxprinter.cxx create mode 100644 toolkit/source/awt/vclxregion.cxx create mode 100644 toolkit/source/awt/vclxspinbutton.cxx create mode 100644 toolkit/source/awt/vclxsystemdependentwindow.cxx create mode 100644 toolkit/source/awt/vclxtabpagecontainer.cxx create mode 100644 toolkit/source/awt/vclxtoolkit.cxx create mode 100644 toolkit/source/awt/vclxtopwindow.cxx create mode 100644 toolkit/source/awt/vclxwindow.cxx create mode 100644 toolkit/source/awt/vclxwindow1.cxx create mode 100644 toolkit/source/awt/vclxwindows.cxx create mode 100644 toolkit/source/awt/vclxwindows_internal.hxx create mode 100644 toolkit/source/controls/accessiblecontrolcontext.cxx create mode 100644 toolkit/source/controls/animatedimages.cxx create mode 100644 toolkit/source/controls/controlmodelcontainerbase.cxx create mode 100644 toolkit/source/controls/controlmodelcontainerbase_internal.hxx create mode 100644 toolkit/source/controls/dialogcontrol.cxx create mode 100644 toolkit/source/controls/eventcontainer.cxx create mode 100644 toolkit/source/controls/filectrl.cxx create mode 100644 toolkit/source/controls/formattedcontrol.cxx create mode 100644 toolkit/source/controls/geometrycontrolmodel.cxx create mode 100644 toolkit/source/controls/grid/defaultgridcolumnmodel.cxx create mode 100644 toolkit/source/controls/grid/defaultgriddatamodel.cxx create mode 100644 toolkit/source/controls/grid/gridcolumn.cxx create mode 100644 toolkit/source/controls/grid/gridcolumn.hxx create mode 100644 toolkit/source/controls/grid/gridcontrol.cxx create mode 100644 toolkit/source/controls/grid/gridcontrol.hxx create mode 100644 toolkit/source/controls/grid/grideventforwarder.cxx create mode 100644 toolkit/source/controls/grid/grideventforwarder.hxx create mode 100644 toolkit/source/controls/grid/sortablegriddatamodel.cxx create mode 100644 toolkit/source/controls/roadmapcontrol.cxx create mode 100644 toolkit/source/controls/roadmapentry.cxx create mode 100644 toolkit/source/controls/spinningprogress.cxx create mode 100644 toolkit/source/controls/stdtabcontroller.cxx create mode 100644 toolkit/source/controls/stdtabcontrollermodel.cxx create mode 100644 toolkit/source/controls/tabpagecontainer.cxx create mode 100644 toolkit/source/controls/tabpagemodel.cxx create mode 100644 toolkit/source/controls/tkscrollbar.cxx create mode 100644 toolkit/source/controls/tkspinbutton.cxx create mode 100644 toolkit/source/controls/tree/treecontrol.cxx create mode 100644 toolkit/source/controls/tree/treecontrol.hxx create mode 100644 toolkit/source/controls/tree/treecontrolpeer.cxx create mode 100644 toolkit/source/controls/tree/treedatamodel.cxx create mode 100644 toolkit/source/controls/unocontrol.cxx create mode 100644 toolkit/source/controls/unocontrolbase.cxx create mode 100644 toolkit/source/controls/unocontrolcontainer.cxx create mode 100644 toolkit/source/controls/unocontrolcontainermodel.cxx create mode 100644 toolkit/source/controls/unocontrolmodel.cxx create mode 100644 toolkit/source/controls/unocontrols.cxx create mode 100644 toolkit/source/helper/accessibilityclient.cxx create mode 100644 toolkit/source/helper/btndlg.cxx create mode 100644 toolkit/source/helper/formpdfexport.cxx create mode 100644 toolkit/source/helper/imagealign.cxx create mode 100644 toolkit/source/helper/listenermultiplexer.cxx create mode 100644 toolkit/source/helper/property.cxx create mode 100644 toolkit/source/helper/servicenames.cxx create mode 100644 toolkit/source/helper/tkresmgr.cxx create mode 100644 toolkit/source/helper/unopropertyarrayhelper.cxx create mode 100644 toolkit/source/helper/unowrapper.cxx create mode 100644 toolkit/source/helper/vclunohelper.cxx (limited to 'toolkit/source') diff --git a/toolkit/source/awt/animatedimagespeer.cxx b/toolkit/source/awt/animatedimagespeer.cxx new file mode 100644 index 000000000..087ddb4d3 --- /dev/null +++ b/toolkit/source/awt/animatedimagespeer.cxx @@ -0,0 +1,521 @@ +/* -*- 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 + +namespace toolkit +{ + + + using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::container::ContainerEvent; + using ::com::sun::star::awt::XAnimatedImages; + using ::com::sun::star::awt::Size; + using ::com::sun::star::graphic::XGraphicProvider; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::graphic::XGraphic; + + namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; + + + //= AnimatedImagesPeer_Data + + namespace { + + struct CachedImage + { + OUString sImageURL; + mutable Reference< XGraphic > xGraphic; + + CachedImage() + :sImageURL() + ,xGraphic() + { + } + + explicit CachedImage( OUString const& i_imageURL ) + :sImageURL( i_imageURL ) + ,xGraphic() + { + } + }; + + } + + struct AnimatedImagesPeer_Data + { + AnimatedImagesPeer& rAntiImpl; + ::std::vector< ::std::vector< CachedImage > > aCachedImageSets; + + explicit AnimatedImagesPeer_Data( AnimatedImagesPeer& i_antiImpl ) + :rAntiImpl( i_antiImpl ) + ,aCachedImageSets() + { + } + }; + + + //= helper + + namespace + { + + OUString lcl_getHighContrastURL( OUString const& i_imageURL ) + { + INetURLObject aURL( i_imageURL ); + if ( aURL.GetProtocol() != INetProtocol::PrivSoffice ) + { + OSL_VERIFY( aURL.insertName( "sifr", false, 0 ) ); + return aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + } + // the private: scheme is not considered to be hierarchical by INetURLObject, so manually insert the + // segment + const sal_Int32 separatorPos = i_imageURL.indexOf( '/' ); + ENSURE_OR_RETURN( separatorPos != -1, "lcl_getHighContrastURL: unsupported URL scheme - cannot automatically determine HC version!", i_imageURL ); + + OUStringBuffer composer; + composer.append( std::u16string_view(i_imageURL).substr(0, separatorPos) ); + composer.append( "/sifr" ); + composer.append( std::u16string_view(i_imageURL).substr(separatorPos) ); + return composer.makeStringAndClear(); + } + + + bool lcl_ensureImage_throw( Reference< XGraphicProvider > const& i_graphicProvider, const bool i_isHighContrast, const CachedImage& i_cachedImage ) + { + if ( !i_cachedImage.xGraphic.is() ) + { + ::comphelper::NamedValueCollection aMediaProperties; + if ( i_isHighContrast ) + { + // try (to find) the high-contrast version of the graphic first + aMediaProperties.put( "URL", lcl_getHighContrastURL( i_cachedImage.sImageURL ) ); + i_cachedImage.xGraphic = i_graphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ); + } + if ( !i_cachedImage.xGraphic.is() ) + { + aMediaProperties.put( "URL", i_cachedImage.sImageURL ); + i_cachedImage.xGraphic = i_graphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ); + } + } + return i_cachedImage.xGraphic.is(); + } + + + Size lcl_getGraphicSizePixel( Reference< XGraphic > const& i_graphic ) + { + Size aSizePixel; + try + { + if ( i_graphic.is() ) + { + const Reference< XPropertySet > xGraphicProps( i_graphic, UNO_QUERY_THROW ); + OSL_VERIFY( xGraphicProps->getPropertyValue("SizePixel") >>= aSizePixel ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + return aSizePixel; + } + + + void lcl_init( Sequence< OUString > const& i_imageURLs, ::std::vector< CachedImage >& o_images ) + { + o_images.resize(0); + size_t count = size_t( i_imageURLs.getLength() ); + o_images.reserve( count ); + for ( const auto& rImageURL : i_imageURLs ) + { + o_images.emplace_back( rImageURL ); + } + } + + + void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data ) + { + VclPtr pThrobber = i_data.rAntiImpl.GetAsDynamic(); + if ( !pThrobber ) + return; + + try + { + // collect the image sizes of the different image sets + const Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); + const Reference< XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create(xContext) ); + + const bool isHighContrast = pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode(); + + sal_Int32 nPreferredSet = -1; + const size_t nImageSetCount = i_data.aCachedImageSets.size(); + if ( nImageSetCount < 2 ) + { + nPreferredSet = sal_Int32( nImageSetCount ) - 1; + } + else + { + ::std::vector< Size > aImageSizes( nImageSetCount ); + for ( size_t nImageSet = 0; nImageSet < nImageSetCount; ++nImageSet ) + { + ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nImageSet ] ); + if ( ( rImageSet.empty() ) + || ( !lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rImageSet[0] ) ) + ) + { + aImageSizes[ nImageSet ] = Size( SAL_MAX_INT32, SAL_MAX_INT32 ); + } + else + { + aImageSizes[ nImageSet ] = lcl_getGraphicSizePixel( rImageSet[0].xGraphic ); + } + } + + // find the set with the smallest difference between window size and image size + const ::Size aWindowSizePixel = pThrobber->GetSizePixel(); + long nMinimalDistance = ::std::numeric_limits< long >::max(); + for ( ::std::vector< Size >::const_iterator check = aImageSizes.begin(); + check != aImageSizes.end(); + ++check + ) + { + if ( ( check->Width > aWindowSizePixel.Width() ) + || ( check->Height > aWindowSizePixel.Height() ) + ) + // do not use an image set which doesn't fit into the window + continue; + + const sal_Int64 distance = + ( aWindowSizePixel.Width() - check->Width ) * ( aWindowSizePixel.Width() - check->Width ) + + ( aWindowSizePixel.Height() - check->Height ) * ( aWindowSizePixel.Height() - check->Height ); + if ( distance < nMinimalDistance ) + { + nMinimalDistance = distance; + nPreferredSet = check - aImageSizes.begin(); + } + } + } + + // found a set? + std::vector< Image > aImages; + if ( ( nPreferredSet >= 0 ) && ( o3tl::make_unsigned( nPreferredSet ) < nImageSetCount ) ) + { + // => set the images + ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nPreferredSet ] ); + aImages.resize( rImageSet.size() ); + sal_Int32 imageIndex = 0; + for ( const auto& rCachedImage : rImageSet ) + { + lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rCachedImage ); + aImages[ imageIndex++ ] = Image(rCachedImage.xGraphic); + } + } + pThrobber->setImageList( aImages ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + + + void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data, const Reference< XAnimatedImages >& i_images ) + { + try + { + const sal_Int32 nImageSetCount = i_images->getImageSetCount(); + i_data.aCachedImageSets.resize(0); + for ( sal_Int32 set = 0; set < nImageSetCount; ++set ) + { + const Sequence< OUString > aImageURLs( i_images->getImageSet( set ) ); + ::std::vector< CachedImage > aImages; + lcl_init( aImageURLs, aImages ); + i_data.aCachedImageSets.push_back( aImages ); + } + + lcl_updateImageList_nothrow( i_data ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + } + + + //= AnimatedImagesPeer + + + AnimatedImagesPeer::AnimatedImagesPeer() + :AnimatedImagesPeer_Base() + ,m_xData( new AnimatedImagesPeer_Data( *this ) ) + { + } + + + AnimatedImagesPeer::~AnimatedImagesPeer() + { + } + + + void SAL_CALL AnimatedImagesPeer::startAnimation() + { + SolarMutexGuard aGuard; + VclPtr pThrobber = GetAsDynamic(); + if (pThrobber) + pThrobber->start(); + } + + void SAL_CALL AnimatedImagesPeer::stopAnimation() + { + SolarMutexGuard aGuard; + VclPtr pThrobber = GetAsDynamic(); + if (pThrobber) + pThrobber->stop(); + } + + sal_Bool SAL_CALL AnimatedImagesPeer::isAnimationRunning() + { + SolarMutexGuard aGuard; + VclPtr pThrobber = GetAsDynamic(); + if (pThrobber) + return pThrobber->isRunning(); + return false; + } + + void SAL_CALL AnimatedImagesPeer::setProperty( const OUString& i_propertyName, const Any& i_value ) + { + SolarMutexGuard aGuard; + + VclPtr pThrobber = GetAsDynamic(); + if ( pThrobber ) + { + VCLXWindow::setProperty( i_propertyName, i_value ); + return; + } + + const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_STEP_TIME: + { + sal_Int32 nStepTime( 0 ); + if ( i_value >>= nStepTime ) + pThrobber->setStepTime( nStepTime ); + break; + } + case BASEPROPERTY_AUTO_REPEAT: + { + bool bRepeat( true ); + if ( i_value >>= bRepeat ) + pThrobber->setRepeat( bRepeat ); + break; + } + + case BASEPROPERTY_IMAGE_SCALE_MODE: + { + sal_Int16 nScaleMode( ImageScaleMode::ANISOTROPIC ); + VclPtr pImageControl = GetAsDynamic< ImageControl >(); + if ( pImageControl && ( i_value >>= nScaleMode ) ) + pImageControl->SetScaleMode( nScaleMode ); + } + break; + + default: + AnimatedImagesPeer_Base::setProperty( i_propertyName, i_value ); + break; + } + } + + + Any SAL_CALL AnimatedImagesPeer::getProperty( const OUString& i_propertyName ) + { + SolarMutexGuard aGuard; + + Any aReturn; + + VclPtr pThrobber = GetAsDynamic(); + if ( !pThrobber ) + return VCLXWindow::getProperty( i_propertyName ); + + const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_STEP_TIME: + aReturn <<= pThrobber->getStepTime(); + break; + + case BASEPROPERTY_AUTO_REPEAT: + aReturn <<= pThrobber->getRepeat(); + break; + + case BASEPROPERTY_IMAGE_SCALE_MODE: + { + VclPtr pImageControl = GetAsDynamic(); + aReturn <<= ( pImageControl ? pImageControl->GetScaleMode() : ImageScaleMode::ANISOTROPIC ); + } + break; + + default: + aReturn = AnimatedImagesPeer_Base::getProperty( i_propertyName ); + break; + } + + return aReturn; + } + + + void AnimatedImagesPeer::ProcessWindowEvent( const VclWindowEvent& i_windowEvent ) + { + if ( i_windowEvent.GetId() == VclEventId::WindowResize ) + { + lcl_updateImageList_nothrow( *m_xData ); + } + + AnimatedImagesPeer_Base::ProcessWindowEvent( i_windowEvent ); + } + + + void AnimatedImagesPeer::impl_updateImages_nolck( const Reference< XInterface >& i_animatedImages ) + { + SolarMutexGuard aGuard; + + lcl_updateImageList_nothrow( *m_xData, Reference< XAnimatedImages >( i_animatedImages, UNO_QUERY_THROW ) ); + } + + + void SAL_CALL AnimatedImagesPeer::elementInserted( const ContainerEvent& i_event ) + { + SolarMutexGuard aGuard; + Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW ); + + sal_Int32 nPosition(0); + OSL_VERIFY( i_event.Accessor >>= nPosition ); + size_t position = size_t( nPosition ); + if ( position > m_xData->aCachedImageSets.size() ) + { + OSL_ENSURE( false, "AnimatedImagesPeer::elementInserted: illegal accessor/index!" ); + lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + } + + Sequence< OUString > aImageURLs; + OSL_VERIFY( i_event.Element >>= aImageURLs ); + ::std::vector< CachedImage > aImages; + lcl_init( aImageURLs, aImages ); + m_xData->aCachedImageSets.insert( m_xData->aCachedImageSets.begin() + position, aImages ); + lcl_updateImageList_nothrow( *m_xData ); + } + + + void SAL_CALL AnimatedImagesPeer::elementRemoved( const ContainerEvent& i_event ) + { + SolarMutexGuard aGuard; + Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW ); + + sal_Int32 nPosition(0); + OSL_VERIFY( i_event.Accessor >>= nPosition ); + size_t position = size_t( nPosition ); + if ( position >= m_xData->aCachedImageSets.size() ) + { + OSL_ENSURE( false, "AnimatedImagesPeer::elementRemoved: illegal accessor/index!" ); + lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + } + + m_xData->aCachedImageSets.erase( m_xData->aCachedImageSets.begin() + position ); + lcl_updateImageList_nothrow( *m_xData ); + } + + + void SAL_CALL AnimatedImagesPeer::elementReplaced( const ContainerEvent& i_event ) + { + SolarMutexGuard aGuard; + Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW ); + + sal_Int32 nPosition(0); + OSL_VERIFY( i_event.Accessor >>= nPosition ); + size_t position = size_t( nPosition ); + if ( position >= m_xData->aCachedImageSets.size() ) + { + OSL_ENSURE( false, "AnimatedImagesPeer::elementReplaced: illegal accessor/index!" ); + lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + } + + Sequence< OUString > aImageURLs; + OSL_VERIFY( i_event.Element >>= aImageURLs ); + ::std::vector< CachedImage > aImages; + lcl_init( aImageURLs, aImages ); + m_xData->aCachedImageSets[ position ] = aImages; + lcl_updateImageList_nothrow( *m_xData ); + } + + + void SAL_CALL AnimatedImagesPeer::disposing( const EventObject& i_event ) + { + VCLXWindow::disposing( i_event ); + } + + + void SAL_CALL AnimatedImagesPeer::modified( const EventObject& i_event ) + { + impl_updateImages_nolck( i_event.Source ); + } + + + void SAL_CALL AnimatedImagesPeer::dispose( ) + { + AnimatedImagesPeer_Base::dispose(); + SolarMutexGuard aGuard; + m_xData->aCachedImageSets.resize(0); + } + + +} // namespace toolkit + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/asynccallback.cxx b/toolkit/source/awt/asynccallback.cxx new file mode 100644 index 000000000..d017b3e25 --- /dev/null +++ b/toolkit/source/awt/asynccallback.cxx @@ -0,0 +1,121 @@ +/* -*- 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 + +/// anonymous implementation namespace +namespace { + +class AsyncCallback: + public ::cppu::WeakImplHelper< + css::lang::XServiceInfo, + css::awt::XRequestCallback> +{ +public: + AsyncCallback() {} + AsyncCallback(const AsyncCallback&) = delete; + AsyncCallback& operator=(const AsyncCallback&) = delete; + + // css::lang::XServiceInfo: + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // css::awt::XRequestCallback: + virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) override; + +private: + + struct CallbackData + { + CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) : + xCallback( rCallback ), aData( rAny ) {} + + css::uno::Reference< css::awt::XCallback > xCallback; + css::uno::Any aData; + }; + + DECL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, void ); + + virtual ~AsyncCallback() override {} +}; + +// com.sun.star.uno.XServiceInfo: +OUString SAL_CALL AsyncCallback::getImplementationName() +{ + return "com.sun.star.awt.comp.AsyncCallback"; +} + +sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName) +{ + return cppu::supportsService(this, serviceName); +} + +css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() +{ + return css::uno::Sequence< OUString >{ "com.sun.star.awt.AsyncCallback" }; +} + +// css::awt::XRequestCallback: +void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) +{ + if ( Application::IsInMain() ) + { + // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe + CallbackData* pCallbackData = new CallbackData( xCallback, aData ); + Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData ); + } +} + +// private asynchronous link to call reference to the callback object +IMPL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, p, void ) +{ + CallbackData* pCallbackData = static_cast(p); + try + { + // Asynchronous execution + // Check pointer and reference before! + if ( pCallbackData && pCallbackData->xCallback.is() ) + pCallbackData->xCallback->notify( pCallbackData->aData ); + } + catch ( css::uno::Exception& ) + { + } + + delete pCallbackData; +} + +} // closing anonymous implementation namespace + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +com_sun_star_awt_comp_AsyncCallback_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new AsyncCallback()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/non-interactable-containers.xml b/toolkit/source/awt/non-interactable-containers.xml new file mode 100644 index 000000000..00f3f2a93 --- /dev/null +++ b/toolkit/source/awt/non-interactable-containers.xml @@ -0,0 +1,32 @@ + + + + + + + + + + +
+
+
diff --git a/toolkit/source/awt/scrollabledialog.cxx b/toolkit/source/awt/scrollabledialog.cxx new file mode 100644 index 000000000..ff9abf48b --- /dev/null +++ b/toolkit/source/awt/scrollabledialog.cxx @@ -0,0 +1,173 @@ +/* -*- 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 + +namespace toolkit +{ + +// Using WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a +// problem in the toolkit class where there are some clashing IDs +// ( css::awt::VclWindowPeerAttribute::VSCROLL has the same value +// as css::awt::WindowAttribute::NODECORATION and they are used +// in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for +// child classes ( whole thing is a mess if you ask me ) +ScrollableDialog::ScrollableDialog( vcl::Window* pParent, WinBits nStyle, Dialog::InitFlag eFlag ) + : Dialog( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ), eFlag ), + maHScrollBar( VclPtr::Create(this, WB_HSCROLL | WB_DRAG) ), + maVScrollBar( VclPtr::Create(this, WB_VSCROLL | WB_DRAG) ), + mbHasHoriBar( false ), + mbHasVertBar( false ), + maScrollVis( None ) +{ + Link aLink( LINK( this, ScrollableDialog, ScrollBarHdl ) ); + maVScrollBar->SetScrollHdl( aLink ); + maHScrollBar->SetScrollHdl( aLink ); + + ScrollBarVisibility aVis = None; + + if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) ) + { + if ( nStyle & WB_AUTOHSCROLL ) + aVis = Hori; + if ( nStyle & WB_AUTOVSCROLL ) + { + if ( aVis == Hori ) + aVis = Both; + else + aVis = Vert; + } + } + setScrollVisibility( aVis ); + mnScrWidth = Dialog::GetSettings().GetStyleSettings().GetScrollBarSize(); +} + +void ScrollableDialog::setScrollVisibility( ScrollBarVisibility rVisState ) +{ + maScrollVis = rVisState; + if ( maScrollVis == Hori || maScrollVis == Both ) + { + mbHasHoriBar = true; + maHScrollBar->Show(); + } + if ( maScrollVis == Vert || maScrollVis == Both ) + { + mbHasVertBar = true; + maVScrollBar->Show(); + } + if ( mbHasHoriBar || mbHasVertBar ) + SetStyle( Dialog::GetStyle() | WB_CLIPCHILDREN ); +} + +ScrollableDialog::~ScrollableDialog() +{ + disposeOnce(); +} + +void ScrollableDialog::dispose() +{ + maHScrollBar.disposeAndClear(); + maVScrollBar.disposeAndClear(); + Dialog::dispose(); +} + +void ScrollableDialog::lcl_Scroll( long nX, long nY ) +{ + long nXScroll = mnScrollPos.X() - nX; + long nYScroll = mnScrollPos.Y() - nY; + mnScrollPos = Point( nX, nY ); + + tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() ); + Scroll(nXScroll, nYScroll, aScrollableArea ); + // Manually scroll all children ( except the scrollbars ) + for ( int index = 0; index < GetChildCount(); ++index ) + { + vcl::Window* pChild = GetChild( index ); + if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() ) + { + Point aPos = pChild->GetPosPixel(); + aPos += Point( nXScroll, nYScroll ); + pChild->SetPosPixel( aPos ); + } + } +} + +IMPL_LINK( ScrollableDialog, ScrollBarHdl, ScrollBar*, pSB, void ) +{ + sal_uInt16 nPos = static_cast(pSB->GetThumbPos()); + if( pSB == maVScrollBar.get() ) + lcl_Scroll(mnScrollPos.X(), nPos ); + else if( pSB == maHScrollBar.get() ) + lcl_Scroll(nPos, mnScrollPos.Y() ); +} + +void ScrollableDialog::SetScrollTop( long nTop ) +{ + Point aOld = mnScrollPos; + lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop ); + maHScrollBar->SetThumbPos( 0 ); + // new pos is 0,0 + mnScrollPos = aOld; +} +void ScrollableDialog::SetScrollLeft( long nLeft ) +{ + Point aOld = mnScrollPos; + lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() ); + maVScrollBar->SetThumbPos( 0 ); + // new pos is 0,0 + mnScrollPos = aOld; +} + +void ScrollableDialog::SetScrollWidth( long nWidth ) +{ + maScrollArea.setWidth( nWidth ); + ResetScrollBars(); +} + +void ScrollableDialog::SetScrollHeight( long nHeight ) +{ + maScrollArea.setHeight( nHeight ); + ResetScrollBars(); +} + +void ScrollableDialog::Resize() +{ + ResetScrollBars(); +} + +void ScrollableDialog::ResetScrollBars() +{ + Size aOutSz = GetOutputSizePixel(); + + Point aVPos( aOutSz.Width() - mnScrWidth, 0 ); + Point aHPos( 0, aOutSz.Height() - mnScrWidth ); + + maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth, GetSizePixel().Height() - mnScrWidth ) ); + maHScrollBar->SetPosSizePixel( aHPos, Size( GetSizePixel().Width() - mnScrWidth, mnScrWidth ) ); + + maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth ); + maHScrollBar->SetVisibleSize( GetSizePixel().Width() ); + + maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth ); + maVScrollBar->SetVisibleSize( GetSizePixel().Height() ); +} + +} // toolkit +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/stylesettings.cxx b/toolkit/source/awt/stylesettings.cxx new file mode 100644 index 000000000..65218b33a --- /dev/null +++ b/toolkit/source/awt/stylesettings.cxx @@ -0,0 +1,949 @@ +/* -*- 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 "stylesettings.hxx" +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + +namespace toolkit +{ + + + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::awt::FontDescriptor; + using ::com::sun::star::awt::XStyleChangeListener; + + + //= WindowStyleSettings_Data + + struct WindowStyleSettings_Data + { + VCLXWindow* pOwningWindow; + ::comphelper::OInterfaceContainerHelper2 aStyleChangeListeners; + + WindowStyleSettings_Data( ::osl::Mutex& i_rListenerMutex, VCLXWindow& i_rOwningWindow ) + : pOwningWindow( &i_rOwningWindow ) + ,aStyleChangeListeners( i_rListenerMutex ) + { + } + + DECL_LINK( OnWindowEvent, VclWindowEvent&, void ); + }; + + + IMPL_LINK( WindowStyleSettings_Data, OnWindowEvent, VclWindowEvent&, rEvent, void ) + { + if ( rEvent.GetId() != VclEventId::WindowDataChanged ) + return; + const DataChangedEvent* pDataChangedEvent = static_cast< const DataChangedEvent* >( rEvent.GetData() ); + if ( !pDataChangedEvent || ( pDataChangedEvent->GetType() != DataChangedEventType::SETTINGS ) ) + return; + if ( !( pDataChangedEvent->GetFlags() & AllSettingsFlags::STYLE ) ) + return; + + EventObject aEvent( *pOwningWindow ); + aStyleChangeListeners.notifyEach( &XStyleChangeListener::styleSettingsChanged, aEvent ); + } + + + //= StyleMethodGuard + + namespace { + + class StyleMethodGuard + { + public: + explicit StyleMethodGuard( WindowStyleSettings_Data const & i_rData ) + { + if ( i_rData.pOwningWindow == nullptr ) + throw DisposedException(); + } + + private: + SolarMutexGuard m_aGuard; + }; + + } + + //= WindowStyleSettings + + + WindowStyleSettings::WindowStyleSettings(::osl::Mutex& i_rListenerMutex, VCLXWindow& i_rOwningWindow ) + :m_pData( new WindowStyleSettings_Data(i_rListenerMutex, i_rOwningWindow ) ) + { + VclPtr pWindow = i_rOwningWindow.GetWindow(); + if ( !pWindow ) + throw RuntimeException(); + pWindow->AddEventListener( LINK( m_pData.get(), WindowStyleSettings_Data, OnWindowEvent ) ); + } + + + WindowStyleSettings::~WindowStyleSettings() + { + } + + + void WindowStyleSettings::dispose() + { + StyleMethodGuard aGuard( *m_pData ); + + VclPtr pWindow = m_pData->pOwningWindow->GetWindow(); + OSL_ENSURE( pWindow, "WindowStyleSettings::dispose: window has been reset before we could revoke the listener!" ); + if ( pWindow ) + pWindow->RemoveEventListener( LINK( m_pData.get(), WindowStyleSettings_Data, OnWindowEvent ) ); + + EventObject aEvent( *this ); + m_pData->aStyleChangeListeners.disposeAndClear( aEvent ); + + m_pData->pOwningWindow = nullptr; + } + + + namespace + { + sal_Int32 lcl_getStyleColor( WindowStyleSettings_Data const & i_rData, Color const & (StyleSettings::*i_pGetter)() const ) + { + const VclPtr& pWindow = i_rData.pOwningWindow->GetWindow(); + const AllSettings aAllSettings = pWindow->GetSettings(); + const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); + return sal_Int32((aStyleSettings.*i_pGetter)()); + } + + void lcl_setStyleColor( WindowStyleSettings_Data const & i_rData, void (StyleSettings::*i_pSetter)( Color const & ), sal_Int32 i_nColor ) + { + VclPtr pWindow = i_rData.pOwningWindow->GetWindow(); + AllSettings aAllSettings = pWindow->GetSettings(); + StyleSettings aStyleSettings = aAllSettings.GetStyleSettings(); + (aStyleSettings.*i_pSetter)( Color(i_nColor) ); + aAllSettings.SetStyleSettings( aStyleSettings ); + pWindow->SetSettings( aAllSettings ); + } + + FontDescriptor lcl_getStyleFont( WindowStyleSettings_Data const & i_rData, vcl::Font const & (StyleSettings::*i_pGetter)() const ) + { + const VclPtr& pWindow = i_rData.pOwningWindow->GetWindow(); + const AllSettings aAllSettings = pWindow->GetSettings(); + const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); + return VCLUnoHelper::CreateFontDescriptor( (aStyleSettings.*i_pGetter)() ); + } + + void lcl_setStyleFont( WindowStyleSettings_Data const & i_rData, void (StyleSettings::*i_pSetter)( vcl::Font const &), + vcl::Font const & (StyleSettings::*i_pGetter)() const, const FontDescriptor& i_rFont ) + { + VclPtr pWindow = i_rData.pOwningWindow->GetWindow(); + AllSettings aAllSettings = pWindow->GetSettings(); + StyleSettings aStyleSettings = aAllSettings.GetStyleSettings(); + const vcl::Font aNewFont = VCLUnoHelper::CreateFont( i_rFont, (aStyleSettings.*i_pGetter)() ); + (aStyleSettings.*i_pSetter)( aNewFont ); + aAllSettings.SetStyleSettings( aStyleSettings ); + pWindow->SetSettings( aAllSettings ); + } + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getActiveBorderColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetActiveBorderColor ); + } + + + void SAL_CALL WindowStyleSettings::setActiveBorderColor( ::sal_Int32 _activebordercolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetActiveBorderColor, _activebordercolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getActiveColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetActiveColor ); + } + + + void SAL_CALL WindowStyleSettings::setActiveColor( ::sal_Int32 _activecolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetActiveColor, _activecolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getActiveTabColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetActiveTabColor ); + } + + + void SAL_CALL WindowStyleSettings::setActiveTabColor( ::sal_Int32 _activetabcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetActiveTabColor, _activetabcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getActiveTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetActiveTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setActiveTextColor( ::sal_Int32 _activetextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetActiveTextColor, _activetextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getButtonRolloverTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetButtonRolloverTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setButtonRolloverTextColor( ::sal_Int32 _buttonrollovertextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetButtonRolloverTextColor, _buttonrollovertextcolor ); + // Also need to set ActionButtonRolloverTextColor as this setting can't be + // set through the UNO interface otherwise. + // Previously this setting was used to set colors for both scenarios, + // but action button setting was added to differentiate the buttons from + // "normal" buttons in some themes. + lcl_setStyleColor( *m_pData, &StyleSettings::SetActionButtonRolloverTextColor, _buttonrollovertextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getButtonTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetButtonTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setButtonTextColor( ::sal_Int32 _buttontextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetButtonTextColor, _buttontextcolor ); + // Also need to set ActionButtonTextColor and DefaultActionButtonTextColor + // as this two settings can't be set through the UNO interface otherwise. + // Previously this setting was used to set colors for all three scenarios, + // but action button setting was added to differentiate the buttons from + // "normal" buttons in some themes. + lcl_setStyleColor( *m_pData, &StyleSettings::SetActionButtonTextColor, _buttontextcolor ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDefaultActionButtonTextColor, _buttontextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getCheckedColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetCheckedColor ); + } + + + void SAL_CALL WindowStyleSettings::setCheckedColor( ::sal_Int32 _checkedcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetCheckedColor, _checkedcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDarkShadowColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDarkShadowColor ); + } + + + void SAL_CALL WindowStyleSettings::setDarkShadowColor( ::sal_Int32 _darkshadowcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDarkShadowColor, _darkshadowcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDeactiveBorderColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDeactiveBorderColor ); + } + + + void SAL_CALL WindowStyleSettings::setDeactiveBorderColor( ::sal_Int32 _deactivebordercolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDeactiveBorderColor, _deactivebordercolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDeactiveColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDeactiveColor ); + } + + + void SAL_CALL WindowStyleSettings::setDeactiveColor( ::sal_Int32 _deactivecolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDeactiveColor, _deactivecolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDeactiveTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDeactiveTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setDeactiveTextColor( ::sal_Int32 _deactivetextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDeactiveTextColor, _deactivetextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDialogColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDialogColor ); + } + + + void SAL_CALL WindowStyleSettings::setDialogColor( ::sal_Int32 _dialogcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDialogColor, _dialogcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDialogTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDialogTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setDialogTextColor( ::sal_Int32 _dialogtextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDialogTextColor, _dialogtextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getDisableColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetDisableColor ); + } + + + void SAL_CALL WindowStyleSettings::setDisableColor( ::sal_Int32 _disablecolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetDisableColor, _disablecolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getFaceColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetFaceColor ); + } + + + void SAL_CALL WindowStyleSettings::setFaceColor( ::sal_Int32 _facecolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetFaceColor, _facecolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getFaceGradientColor() + { + StyleMethodGuard aGuard( *m_pData ); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); + const AllSettings aAllSettings = pWindow->GetSettings(); + const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); + return sal_Int32(aStyleSettings.GetFaceGradientColor()); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getFieldColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetFieldColor ); + } + + + void SAL_CALL WindowStyleSettings::setFieldColor( ::sal_Int32 _fieldcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetFieldColor, _fieldcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getFieldRolloverTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetFieldRolloverTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setFieldRolloverTextColor( ::sal_Int32 _fieldrollovertextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetFieldRolloverTextColor, _fieldrollovertextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getFieldTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetFieldTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setFieldTextColor( ::sal_Int32 _fieldtextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetFieldTextColor, _fieldtextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getGroupTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetGroupTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setGroupTextColor( ::sal_Int32 _grouptextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetGroupTextColor, _grouptextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getHelpColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetHelpColor ); + } + + + void SAL_CALL WindowStyleSettings::setHelpColor( ::sal_Int32 _helpcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetHelpColor, _helpcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getHelpTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetHelpTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setHelpTextColor( ::sal_Int32 _helptextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetHelpTextColor, _helptextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getHighlightColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetHighlightColor ); + } + + + void SAL_CALL WindowStyleSettings::setHighlightColor( ::sal_Int32 _highlightcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetHighlightColor, _highlightcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getHighlightTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetHighlightTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setHighlightTextColor( ::sal_Int32 _highlighttextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetHighlightTextColor, _highlighttextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getInactiveTabColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetInactiveTabColor ); + } + + + void SAL_CALL WindowStyleSettings::setInactiveTabColor( ::sal_Int32 _inactivetabcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetInactiveTabColor, _inactivetabcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getLabelTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetLabelTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setLabelTextColor( ::sal_Int32 _labeltextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetLabelTextColor, _labeltextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getLightColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetLightColor ); + } + + + void SAL_CALL WindowStyleSettings::setLightColor( ::sal_Int32 _lightcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetLightColor, _lightcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuBarColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuBarColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuBarColor( ::sal_Int32 _menubarcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuBarColor, _menubarcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuBarTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuBarTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuBarTextColor( ::sal_Int32 _menubartextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuBarTextColor, _menubartextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuBorderColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuBorderColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuBorderColor( ::sal_Int32 _menubordercolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuBorderColor, _menubordercolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuColor( ::sal_Int32 _menucolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuColor, _menucolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuHighlightColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuHighlightColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuHighlightColor( ::sal_Int32 _menuhighlightcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuHighlightColor, _menuhighlightcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuHighlightTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuHighlightTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuHighlightTextColor( ::sal_Int32 _menuhighlighttextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuHighlightTextColor, _menuhighlighttextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMenuTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMenuTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setMenuTextColor( ::sal_Int32 _menutextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMenuTextColor, _menutextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getMonoColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetMonoColor ); + } + + + void SAL_CALL WindowStyleSettings::setMonoColor( ::sal_Int32 _monocolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetMonoColor, _monocolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getRadioCheckTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetRadioCheckTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setRadioCheckTextColor( ::sal_Int32 _radiochecktextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetRadioCheckTextColor, _radiochecktextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getSeparatorColor() + { + StyleMethodGuard aGuard( *m_pData ); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); + const AllSettings aAllSettings = pWindow->GetSettings(); + const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); + return sal_Int32(aStyleSettings.GetSeparatorColor()); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getShadowColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetShadowColor ); + } + + + void SAL_CALL WindowStyleSettings::setShadowColor( ::sal_Int32 _shadowcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetShadowColor, _shadowcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getWindowColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetWindowColor ); + } + + + void SAL_CALL WindowStyleSettings::setWindowColor( ::sal_Int32 _windowcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetWindowColor, _windowcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getWindowTextColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetWindowTextColor ); + } + + + void SAL_CALL WindowStyleSettings::setWindowTextColor( ::sal_Int32 _windowtextcolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetWindowTextColor, _windowtextcolor ); + } + + + ::sal_Int32 SAL_CALL WindowStyleSettings::getWorkspaceColor() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleColor( *m_pData, &StyleSettings::GetWorkspaceColor ); + } + + + void SAL_CALL WindowStyleSettings::setWorkspaceColor( ::sal_Int32 _workspacecolor ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleColor( *m_pData, &StyleSettings::SetWorkspaceColor, _workspacecolor ); + } + + + sal_Bool SAL_CALL WindowStyleSettings::getHighContrastMode() + { + StyleMethodGuard aGuard( *m_pData ); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); + const AllSettings aAllSettings = pWindow->GetSettings(); + const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); + return aStyleSettings.GetHighContrastMode(); + } + + + void SAL_CALL WindowStyleSettings::setHighContrastMode( sal_Bool _highcontrastmode ) + { + StyleMethodGuard aGuard( *m_pData ); + VclPtr pWindow = m_pData->pOwningWindow->GetWindow(); + AllSettings aAllSettings = pWindow->GetSettings(); + StyleSettings aStyleSettings = aAllSettings.GetStyleSettings(); + aStyleSettings.SetHighContrastMode( _highcontrastmode ); + aAllSettings.SetStyleSettings( aStyleSettings ); + pWindow->SetSettings( aAllSettings ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getApplicationFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetAppFont ); + } + + + void SAL_CALL WindowStyleSettings::setApplicationFont( const FontDescriptor& _applicationfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetAppFont, &StyleSettings::GetAppFont, _applicationfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getHelpFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetHelpFont ); + } + + + void SAL_CALL WindowStyleSettings::setHelpFont( const FontDescriptor& _helpfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetHelpFont, &StyleSettings::GetHelpFont, _helpfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getTitleFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetTitleFont ); + } + + + void SAL_CALL WindowStyleSettings::setTitleFont( const FontDescriptor& _titlefont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetTitleFont, &StyleSettings::GetTitleFont, _titlefont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getFloatTitleFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetFloatTitleFont ); + } + + + void SAL_CALL WindowStyleSettings::setFloatTitleFont( const FontDescriptor& _floattitlefont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetFloatTitleFont, &StyleSettings::GetFloatTitleFont, _floattitlefont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getMenuFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetMenuFont ); + } + + + void SAL_CALL WindowStyleSettings::setMenuFont( const FontDescriptor& _menufont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetMenuFont, &StyleSettings::GetMenuFont, _menufont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getToolFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetToolFont ); + } + + + void SAL_CALL WindowStyleSettings::setToolFont( const FontDescriptor& _toolfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetToolFont, &StyleSettings::GetToolFont, _toolfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getGroupFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetGroupFont ); + } + + + void SAL_CALL WindowStyleSettings::setGroupFont( const FontDescriptor& _groupfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetGroupFont, &StyleSettings::GetGroupFont, _groupfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getLabelFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetLabelFont ); + } + + + void SAL_CALL WindowStyleSettings::setLabelFont( const FontDescriptor& _labelfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetLabelFont, &StyleSettings::GetLabelFont, _labelfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getRadioCheckFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetRadioCheckFont ); + } + + + void SAL_CALL WindowStyleSettings::setRadioCheckFont( const FontDescriptor& _radiocheckfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetRadioCheckFont, &StyleSettings::GetRadioCheckFont, _radiocheckfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getPushButtonFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetPushButtonFont ); + } + + + void SAL_CALL WindowStyleSettings::setPushButtonFont( const FontDescriptor& _pushbuttonfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetPushButtonFont, &StyleSettings::GetPushButtonFont, _pushbuttonfont ); + } + + + FontDescriptor SAL_CALL WindowStyleSettings::getFieldFont() + { + StyleMethodGuard aGuard( *m_pData ); + return lcl_getStyleFont( *m_pData, &StyleSettings::GetFieldFont ); + } + + + void SAL_CALL WindowStyleSettings::setFieldFont( const FontDescriptor& _fieldfont ) + { + StyleMethodGuard aGuard( *m_pData ); + lcl_setStyleFont( *m_pData, &StyleSettings::SetFieldFont, &StyleSettings::GetFieldFont, _fieldfont ); + } + + + void SAL_CALL WindowStyleSettings::addStyleChangeListener( const Reference< XStyleChangeListener >& i_rListener ) + { + StyleMethodGuard aGuard( *m_pData ); + if ( i_rListener.is() ) + m_pData->aStyleChangeListeners.addInterface( i_rListener ); + } + + + void SAL_CALL WindowStyleSettings::removeStyleChangeListener( const Reference< XStyleChangeListener >& i_rListener ) + { + StyleMethodGuard aGuard( *m_pData ); + if ( i_rListener.is() ) + m_pData->aStyleChangeListeners.removeInterface( i_rListener ); + } + + +} // namespace toolkit + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/stylesettings.hxx b/toolkit/source/awt/stylesettings.hxx new file mode 100644 index 000000000..0bc28cd1d --- /dev/null +++ b/toolkit/source/awt/stylesettings.hxx @@ -0,0 +1,172 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_TOOLKIT_SOURCE_AWT_STYLESETTINGS_HXX +#define INCLUDED_TOOLKIT_SOURCE_AWT_STYLESETTINGS_HXX + +#include + +#include + +#include + +namespace osl +{ + class Mutex; +} + +class VCLXWindow; + + +namespace toolkit +{ + + + //= WindowStyleSettings + + struct WindowStyleSettings_Data; + typedef ::cppu::WeakImplHelper < css::awt::XStyleSettings + > WindowStyleSettings_Base; + class WindowStyleSettings : public WindowStyleSettings_Base + { + public: + WindowStyleSettings( ::osl::Mutex& i_rListenerMutex, VCLXWindow& i_rOwningWindow ); + virtual ~WindowStyleSettings() override; + + void dispose(); + + // XStyleSettings + virtual ::sal_Int32 SAL_CALL getActiveBorderColor() override; + virtual void SAL_CALL setActiveBorderColor( ::sal_Int32 _activebordercolor ) override; + virtual ::sal_Int32 SAL_CALL getActiveColor() override; + virtual void SAL_CALL setActiveColor( ::sal_Int32 _activecolor ) override; + virtual ::sal_Int32 SAL_CALL getActiveTabColor() override; + virtual void SAL_CALL setActiveTabColor( ::sal_Int32 _activetabcolor ) override; + virtual ::sal_Int32 SAL_CALL getActiveTextColor() override; + virtual void SAL_CALL setActiveTextColor( ::sal_Int32 _activetextcolor ) override; + virtual ::sal_Int32 SAL_CALL getButtonRolloverTextColor() override; + virtual void SAL_CALL setButtonRolloverTextColor( ::sal_Int32 _buttonrollovertextcolor ) override; + virtual ::sal_Int32 SAL_CALL getButtonTextColor() override; + virtual void SAL_CALL setButtonTextColor( ::sal_Int32 _buttontextcolor ) override; + virtual ::sal_Int32 SAL_CALL getCheckedColor() override; + virtual void SAL_CALL setCheckedColor( ::sal_Int32 _checkedcolor ) override; + virtual ::sal_Int32 SAL_CALL getDarkShadowColor() override; + virtual void SAL_CALL setDarkShadowColor( ::sal_Int32 _darkshadowcolor ) override; + virtual ::sal_Int32 SAL_CALL getDeactiveBorderColor() override; + virtual void SAL_CALL setDeactiveBorderColor( ::sal_Int32 _deactivebordercolor ) override; + virtual ::sal_Int32 SAL_CALL getDeactiveColor() override; + virtual void SAL_CALL setDeactiveColor( ::sal_Int32 _deactivecolor ) override; + virtual ::sal_Int32 SAL_CALL getDeactiveTextColor() override; + virtual void SAL_CALL setDeactiveTextColor( ::sal_Int32 _deactivetextcolor ) override; + virtual ::sal_Int32 SAL_CALL getDialogColor() override; + virtual void SAL_CALL setDialogColor( ::sal_Int32 _dialogcolor ) override; + virtual ::sal_Int32 SAL_CALL getDialogTextColor() override; + virtual void SAL_CALL setDialogTextColor( ::sal_Int32 _dialogtextcolor ) override; + virtual ::sal_Int32 SAL_CALL getDisableColor() override; + virtual void SAL_CALL setDisableColor( ::sal_Int32 _disablecolor ) override; + virtual ::sal_Int32 SAL_CALL getFaceColor() override; + virtual void SAL_CALL setFaceColor( ::sal_Int32 _facecolor ) override; + virtual ::sal_Int32 SAL_CALL getFaceGradientColor() override; + virtual ::sal_Int32 SAL_CALL getFieldColor() override; + virtual void SAL_CALL setFieldColor( ::sal_Int32 _fieldcolor ) override; + virtual ::sal_Int32 SAL_CALL getFieldRolloverTextColor() override; + virtual void SAL_CALL setFieldRolloverTextColor( ::sal_Int32 _fieldrollovertextcolor ) override; + virtual ::sal_Int32 SAL_CALL getFieldTextColor() override; + virtual void SAL_CALL setFieldTextColor( ::sal_Int32 _fieldtextcolor ) override; + virtual ::sal_Int32 SAL_CALL getGroupTextColor() override; + virtual void SAL_CALL setGroupTextColor( ::sal_Int32 _grouptextcolor ) override; + virtual ::sal_Int32 SAL_CALL getHelpColor() override; + virtual void SAL_CALL setHelpColor( ::sal_Int32 _helpcolor ) override; + virtual ::sal_Int32 SAL_CALL getHelpTextColor() override; + virtual void SAL_CALL setHelpTextColor( ::sal_Int32 _helptextcolor ) override; + virtual ::sal_Int32 SAL_CALL getHighlightColor() override; + virtual void SAL_CALL setHighlightColor( ::sal_Int32 _highlightcolor ) override; + virtual ::sal_Int32 SAL_CALL getHighlightTextColor() override; + virtual void SAL_CALL setHighlightTextColor( ::sal_Int32 _highlighttextcolor ) override; + virtual ::sal_Int32 SAL_CALL getInactiveTabColor() override; + virtual void SAL_CALL setInactiveTabColor( ::sal_Int32 _inactivetabcolor ) override; + virtual ::sal_Int32 SAL_CALL getLabelTextColor() override; + virtual void SAL_CALL setLabelTextColor( ::sal_Int32 _labeltextcolor ) override; + virtual ::sal_Int32 SAL_CALL getLightColor() override; + virtual void SAL_CALL setLightColor( ::sal_Int32 _lightcolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuBarColor() override; + virtual void SAL_CALL setMenuBarColor( ::sal_Int32 _menubarcolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuBarTextColor() override; + virtual void SAL_CALL setMenuBarTextColor( ::sal_Int32 _menubartextcolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuBorderColor() override; + virtual void SAL_CALL setMenuBorderColor( ::sal_Int32 _menubordercolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuColor() override; + virtual void SAL_CALL setMenuColor( ::sal_Int32 _menucolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuHighlightColor() override; + virtual void SAL_CALL setMenuHighlightColor( ::sal_Int32 _menuhighlightcolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuHighlightTextColor() override; + virtual void SAL_CALL setMenuHighlightTextColor( ::sal_Int32 _menuhighlighttextcolor ) override; + virtual ::sal_Int32 SAL_CALL getMenuTextColor() override; + virtual void SAL_CALL setMenuTextColor( ::sal_Int32 _menutextcolor ) override; + virtual ::sal_Int32 SAL_CALL getMonoColor() override; + virtual void SAL_CALL setMonoColor( ::sal_Int32 _monocolor ) override; + virtual ::sal_Int32 SAL_CALL getRadioCheckTextColor() override; + virtual void SAL_CALL setRadioCheckTextColor( ::sal_Int32 _radiochecktextcolor ) override; + virtual ::sal_Int32 SAL_CALL getSeparatorColor() override; + virtual ::sal_Int32 SAL_CALL getShadowColor() override; + virtual void SAL_CALL setShadowColor( ::sal_Int32 _shadowcolor ) override; + virtual ::sal_Int32 SAL_CALL getWindowColor() override; + virtual void SAL_CALL setWindowColor( ::sal_Int32 _windowcolor ) override; + virtual ::sal_Int32 SAL_CALL getWindowTextColor() override; + virtual void SAL_CALL setWindowTextColor( ::sal_Int32 _windowtextcolor ) override; + virtual ::sal_Int32 SAL_CALL getWorkspaceColor() override; + virtual void SAL_CALL setWorkspaceColor( ::sal_Int32 _workspacecolor ) override; + virtual sal_Bool SAL_CALL getHighContrastMode() override; + virtual void SAL_CALL setHighContrastMode( sal_Bool _highcontrastmode ) override; + virtual css::awt::FontDescriptor SAL_CALL getApplicationFont() override; + virtual void SAL_CALL setApplicationFont( const css::awt::FontDescriptor& _applicationfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getHelpFont() override; + virtual void SAL_CALL setHelpFont( const css::awt::FontDescriptor& _helpfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getTitleFont() override; + virtual void SAL_CALL setTitleFont( const css::awt::FontDescriptor& _titlefont ) override; + virtual css::awt::FontDescriptor SAL_CALL getFloatTitleFont() override; + virtual void SAL_CALL setFloatTitleFont( const css::awt::FontDescriptor& _floattitlefont ) override; + virtual css::awt::FontDescriptor SAL_CALL getMenuFont() override; + virtual void SAL_CALL setMenuFont( const css::awt::FontDescriptor& _menufont ) override; + virtual css::awt::FontDescriptor SAL_CALL getToolFont() override; + virtual void SAL_CALL setToolFont( const css::awt::FontDescriptor& _toolfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getGroupFont() override; + virtual void SAL_CALL setGroupFont( const css::awt::FontDescriptor& _groupfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getLabelFont() override; + virtual void SAL_CALL setLabelFont( const css::awt::FontDescriptor& _labelfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getRadioCheckFont() override; + virtual void SAL_CALL setRadioCheckFont( const css::awt::FontDescriptor& _radiocheckfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getPushButtonFont() override; + virtual void SAL_CALL setPushButtonFont( const css::awt::FontDescriptor& _pushbuttonfont ) override; + virtual css::awt::FontDescriptor SAL_CALL getFieldFont() override; + virtual void SAL_CALL setFieldFont( const css::awt::FontDescriptor& _fieldfont ) override; + virtual void SAL_CALL addStyleChangeListener( const css::uno::Reference< css::awt::XStyleChangeListener >& Listener ) override; + virtual void SAL_CALL removeStyleChangeListener( const css::uno::Reference< css::awt::XStyleChangeListener >& Listener ) override; + + private: + std::unique_ptr< WindowStyleSettings_Data > m_pData; + }; + + +} // namespace toolkit + + +#endif // INCLUDED_TOOLKIT_SOURCE_AWT_STYLESETTINGS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxaccessiblecomponent.cxx b/toolkit/source/awt/vclxaccessiblecomponent.cxx new file mode 100644 index 000000000..b046e9280 --- /dev/null +++ b/toolkit/source/awt/vclxaccessiblecomponent.cxx @@ -0,0 +1,824 @@ +/* -*- 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 + +using namespace ::com::sun::star; +using namespace ::comphelper; + +VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXWindow ) +{ + m_xVCLXWindow = pVCLXWindow; + + DBG_ASSERT( pVCLXWindow->GetWindow(), "VCLXAccessibleComponent - no window!" ); + m_xEventSource = pVCLXWindow->GetWindow(); + if ( m_xEventSource ) + { + m_xEventSource->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + m_xEventSource->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + } + + // announce the XAccessible of our creator to the base class + lateInit( pVCLXWindow ); +} + +VCLXWindow* VCLXAccessibleComponent::GetVCLXWindow() const +{ + return m_xVCLXWindow.get(); +} + +void VCLXAccessibleComponent::DisconnectEvents() +{ + if ( m_xEventSource ) + { + m_xEventSource->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + m_xEventSource->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + m_xEventSource.clear(); + } +} + +VCLXAccessibleComponent::~VCLXAccessibleComponent() +{ + ensureDisposed(); + DisconnectEvents(); +} + +IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE ) +IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE ) + +OUString VCLXAccessibleComponent::getImplementationName() +{ + return "com.sun.star.comp.toolkit.AccessibleWindow"; +} + +sal_Bool VCLXAccessibleComponent::supportsService( const OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence< OUString > VCLXAccessibleComponent::getSupportedServiceNames() +{ + uno::Sequence< OUString > aNames { "com.sun.star.awt.AccessibleWindow" }; + return aNames; +} + +IMPL_LINK( VCLXAccessibleComponent, WindowEventListener, VclWindowEvent&, rEvent, void ) +{ + /* Ignore VclEventId::WindowEndPopupMode, because the UNO accessibility wrapper + * might have been destroyed by the previous VCLEventListener (if no AT tool + * is running), e.g. sub-toolbars in impress. + */ + if ( m_xVCLXWindow.is() /* #122218# */ && (rEvent.GetId() != VclEventId::WindowEndPopupMode) ) + { + DBG_ASSERT( rEvent.GetWindow(), "Window???" ); + if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent.GetId() == VclEventId::ObjectDying ) ) + { + ProcessWindowEvent( rEvent ); + } + } +} + +IMPL_LINK( VCLXAccessibleComponent, WindowChildEventListener, VclWindowEvent&, rEvent, void ) +{ + if ( m_xVCLXWindow.is() /* #i68079# */ ) + { + DBG_ASSERT( rEvent.GetWindow(), "Window???" ); + if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() ) + { + // #103087# to prevent an early release of the component + uno::Reference< accessibility::XAccessibleContext > xHoldAlive = this; + + ProcessWindowChildEvent( rEvent ); + } + } +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent ) +{ + // checks if the data in the window event is our direct child + // and returns its accessible + + // MT: Change this later, normally a show/hide event shouldn't have the vcl::Window* in pData. + vcl::Window* pChildWindow = static_cast(rVclWindowEvent.GetData()); + if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() ) + return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VclEventId::WindowShow ); + else + return uno::Reference< accessibility::XAccessible > (); +} + +void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent ) +{ + uno::Any aOldValue, aNewValue; + uno::Reference< accessibility::XAccessible > xAcc; + + switch ( rVclWindowEvent.GetId() ) + { + case VclEventId::WindowShow: // send create on show for direct accessible children + { + xAcc = GetChildAccessible( rVclWindowEvent ); + if( xAcc.is() ) + { + aNewValue <<= xAcc; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + case VclEventId::WindowHide: // send destroy on hide for direct accessible children + { + xAcc = GetChildAccessible( rVclWindowEvent ); + if( xAcc.is() ) + { + aOldValue <<= xAcc; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + default: break; + } +} + +void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + uno::Any aOldValue, aNewValue; + + vcl::Window* pAccWindow = rVclWindowEvent.GetWindow(); + assert(pAccWindow && "VCLXAccessibleComponent::ProcessWindowEvent - Window?"); + + switch ( rVclWindowEvent.GetId() ) + { + case VclEventId::ObjectDying: + { + DisconnectEvents(); + m_xVCLXWindow.clear(); + } + break; + case VclEventId::WindowChildDestroyed: + { + vcl::Window* pWindow = static_cast(rVclWindowEvent.GetData()); + DBG_ASSERT( pWindow, "VclEventId::WindowChildDestroyed - Window=?" ); + if ( pWindow->GetAccessible( false ).is() ) + { + aOldValue <<= pWindow->GetAccessible( false ); + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + case VclEventId::WindowActivate: + { + sal_Int16 aAccessibleRole = getAccessibleRole(); + // avoid notification if a child frame is already active + // only one frame may be active at a given time + if ( !pAccWindow->HasActiveChildFrame() && + ( aAccessibleRole == accessibility::AccessibleRole::FRAME || + aAccessibleRole == accessibility::AccessibleRole::ALERT || + aAccessibleRole == accessibility::AccessibleRole::DIALOG ) ) // #i18891# + { + aNewValue <<= accessibility::AccessibleStateType::ACTIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VclEventId::WindowDeactivate: + { + sal_Int16 aAccessibleRole = getAccessibleRole(); + if ( aAccessibleRole == accessibility::AccessibleRole::FRAME || + aAccessibleRole == accessibility::AccessibleRole::ALERT || + aAccessibleRole == accessibility::AccessibleRole::DIALOG ) // #i18891# + { + aOldValue <<= accessibility::AccessibleStateType::ACTIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VclEventId::WindowGetFocus: + case VclEventId::ControlGetFocus: + { + if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::ControlGetFocus) || + (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::WindowGetFocus) ) + { + // if multiple listeners were registered it is possible that the + // focus was changed during event processing (eg SfxTopWindow ) + // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself + if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) || + (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) ) + { + aNewValue <<= accessibility::AccessibleStateType::FOCUSED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + } + break; + case VclEventId::WindowLoseFocus: + case VclEventId::ControlLoseFocus: + { + if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::ControlLoseFocus) || + (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::WindowLoseFocus) ) + { + aOldValue <<= accessibility::AccessibleStateType::FOCUSED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VclEventId::WindowFrameTitleChanged: + { + OUString aOldName( *static_cast(rVclWindowEvent.GetData()) ); + OUString aNewName( getAccessibleName() ); + aOldValue <<= aOldName; + aNewValue <<= aNewName; + NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue ); + } + break; + case VclEventId::WindowEnabled: + { + aNewValue <<= accessibility::AccessibleStateType::ENABLED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + aNewValue <<= accessibility::AccessibleStateType::SENSITIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VclEventId::WindowDisabled: + { + aOldValue <<= accessibility::AccessibleStateType::SENSITIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aOldValue <<= accessibility::AccessibleStateType::ENABLED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VclEventId::WindowMove: + case VclEventId::WindowResize: + { + NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue ); + } + break; + case VclEventId::WindowMenubarAdded: + { + MenuBar* pMenuBar = static_cast(rVclWindowEvent.GetData()); + if ( pMenuBar ) + { + uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() ); + if ( xChild.is() ) + { + aNewValue <<= xChild; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + } + break; + case VclEventId::WindowMenubarRemoved: + { + MenuBar* pMenuBar = static_cast(rVclWindowEvent.GetData()); + if ( pMenuBar ) + { + uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() ); + if ( xChild.is() ) + { + aOldValue <<= xChild; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + } + break; + case VclEventId::WindowMinimize: + { + aNewValue <<= accessibility::AccessibleStateType::ICONIFIED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VclEventId::WindowNormalize: + { + aOldValue <<= accessibility::AccessibleStateType::ICONIFIED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + default: + { + } + break; + } +} + +void VCLXAccessibleComponent::disposing() +{ + DisconnectEvents(); + + OAccessibleExtendedComponentHelper::disposing(); + + m_xVCLXWindow.clear(); +} + +VclPtr VCLXAccessibleComponent::GetWindow() const +{ + return GetVCLXWindow() ? GetVCLXWindow()->GetWindow() + : VclPtr(); +} + +void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet ) +{ + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + vcl::Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy(); + if ( pLabeledBy && pLabeledBy != pWindow ) + { + uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabeledBy->GetAccessible() }; + rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) ); + } + + vcl::Window* pLabelFor = pWindow->GetAccessibleRelationLabelFor(); + if ( pLabelFor && pLabelFor != pWindow ) + { + uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabelFor->GetAccessible() }; + rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) ); + } + + vcl::Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf(); + if ( pMemberOf && pMemberOf != pWindow ) + { + uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pMemberOf->GetAccessible() }; + rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) ); + } + } +} + +void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) +{ + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsVisible() ) + { + rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE ); + rStateSet.AddState( accessibility::AccessibleStateType::SHOWING ); + } + else + { + rStateSet.AddState( accessibility::AccessibleStateType::INVALID ); + } + + if ( pWindow->IsEnabled() ) + { + rStateSet.AddState( accessibility::AccessibleStateType::ENABLED ); + rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE ); + } + + if ( pWindow->HasChildPathFocus() && + ( getAccessibleRole() == accessibility::AccessibleRole::FRAME || + getAccessibleRole() == accessibility::AccessibleRole::ALERT || + getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891# + rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE ); + + if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) ) + rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED ); + + if ( pWindow->IsWait() ) + rStateSet.AddState( accessibility::AccessibleStateType::BUSY ); + + if ( pWindow->GetStyle() & WB_SIZEABLE ) + rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE ); + // 6. frame doesn't have MOVABLE state + // 10. for password text, where is the sensitive state? + if( ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||getAccessibleRole() == accessibility::AccessibleRole::DIALOG )&& pWindow->GetStyle() & WB_MOVEABLE ) + rStateSet.AddState( accessibility::AccessibleStateType::MOVEABLE ); + if( pWindow->IsDialog() ) + { + Dialog *pDlg = static_cast< Dialog* >( pWindow.get() ); + if( pDlg->IsInExecute() ) + rStateSet.AddState( accessibility::AccessibleStateType::MODAL ); + } + //If a combobox or list's edit child isn't read-only,EDITABLE state + //should be set. + if( pWindow && pWindow->GetType() == WindowType::COMBOBOX ) + { + if( !( pWindow->GetStyle() & WB_READONLY) || + !static_cast(pWindow.get())->IsReadOnly() ) + rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE ); + } + + VclPtr pChild = pWindow->GetWindow( GetWindowType::FirstChild ); + + while( pWindow && pChild ) + { + VclPtr pWinTemp = pChild->GetWindow( GetWindowType::FirstChild ); + if( pWinTemp && pWinTemp->GetType() == WindowType::EDIT ) + { + if( !( pWinTemp->GetStyle() & WB_READONLY) || + !static_cast(pWinTemp.get())->IsReadOnly() ) + rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE ); + break; + } + if( pChild->GetType() == WindowType::EDIT ) + { + if( !( pChild->GetStyle() & WB_READONLY) || + !static_cast(pChild.get())->IsReadOnly()) + rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE ); + break; + } + pChild = pChild->GetWindow( GetWindowType::Next ); + } + } + else + { + rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC ); + } + +/* + +MUST BE SET FROM DERIVED CLASSES: + +CHECKED +COLLAPSED +EXPANDED +EXPANDABLE +EDITABLE +FOCUSABLE +HORIZONTAL +VERTICAL +ICONIFIED +MULTILINE +MULTI_SELECTABLE +PRESSED +SELECTABLE +SELECTED +SINGLE_LINE +TRANSIENT + + */ +} + + +// accessibility::XAccessibleContext +sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount() +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nChildren = 0; + if ( GetWindow() ) + nChildren = GetWindow()->GetAccessibleChildWindowCount(); + + return nChildren; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i ) +{ + OExternalLockGuard aGuard( this ); + + if ( i >= getAccessibleChildCount() ) + throw lang::IndexOutOfBoundsException(); + + uno::Reference< accessibility::XAccessible > xAcc; + if ( GetWindow() ) + { + vcl::Window* pChild = GetWindow()->GetAccessibleChildWindow( static_cast(i) ); + if ( pChild ) + xAcc = pChild->GetAccessible(); + } + + return xAcc; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const +{ + uno::Reference< accessibility::XAccessible > xAcc; + if ( GetWindow() ) + { + vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow(); + if ( pParent ) + xAcc = pParent->GetAccessible(); + } + return xAcc; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent( ) +{ + OExternalLockGuard aGuard( this ); + + // we do _not_ have a foreign-controlled parent -> default to our VCL parent + uno::Reference< accessibility::XAccessible > xAcc = getVclParent(); + + return xAcc; +} + +sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent( ) +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nIndex = -1; + + if ( GetWindow() ) + { + vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow(); + if ( pParent ) + { + // Iterate over all the parent's children and search for this object. + // this should be compatible with the code in SVX + uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() ); + if ( xParentAcc.is() ) + { + uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() ); + if ( xParentContext.is() ) + { + sal_Int32 nChildCount = xParentContext->getAccessibleChildCount(); + for ( sal_Int32 i=0; i xChild( xParentContext->getAccessibleChild(i) ); + if ( xChild.is() ) + { + uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext(); + if ( xChildContext == static_cast(this) ) + { + nIndex = i; + break; + } + } + } + } + } + } + } + return nIndex; +} + +sal_Int16 VCLXAccessibleComponent::getAccessibleRole( ) +{ + OExternalLockGuard aGuard( this ); + + sal_Int16 nRole = 0; + + if ( GetWindow() ) + nRole = GetWindow()->GetAccessibleRole(); + + return nRole; +} + +OUString VCLXAccessibleComponent::getAccessibleDescription( ) +{ + OExternalLockGuard aGuard( this ); + + OUString aDescription; + + if ( GetWindow() ) + aDescription = GetWindow()->GetAccessibleDescription(); + + return aDescription; +} + +OUString VCLXAccessibleComponent::getAccessibleName( ) +{ + OExternalLockGuard aGuard( this ); + + OUString aName; + if ( GetWindow() ) + { + aName = GetWindow()->GetAccessibleName(); +#if OSL_DEBUG_LEVEL > 0 + aName += " (Type = " + OUString::number(static_cast(GetWindow()->GetType())) + ")"; +#endif + } + return aName; +} + +OUString VCLXAccessibleComponent::getAccessibleId( ) +{ + OExternalLockGuard aGuard( this ); + + OUString aId; + if ( GetWindow() ) + { + const OUString &aWindowId = GetWindow()->get_id(); + aId = aWindowId; + } + return aId; +} + +uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet( ) +{ + OExternalLockGuard aGuard( this ); + + utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; + uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper; + FillAccessibleRelationSet( *pRelationSetHelper ); + return xSet; +} + +uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet( ) +{ + OExternalLockGuard aGuard( this ); + + utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; + uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper; + FillAccessibleStateSet( *pStateSetHelper ); + return xSet; +} + +lang::Locale VCLXAccessibleComponent::getLocale() +{ + OExternalLockGuard aGuard( this ); + + return Application::GetSettings().GetLanguageTag().getLocale(); +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint ) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< accessibility::XAccessible > xChild; + for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i ) + { + uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i ); + if ( xAcc.is() ) + { + uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY ); + if ( xComp.is() ) + { + tools::Rectangle aRect = VCLRectangle( xComp->getBounds() ); + Point aPos = VCLPoint( rPoint ); + if ( aRect.IsInside( aPos ) ) + { + xChild = xAcc; + break; + } + } + } + } + + return xChild; +} + +// accessibility::XAccessibleComponent +awt::Rectangle VCLXAccessibleComponent::implGetBounds() +{ + awt::Rectangle aBounds ( 0, 0, 0, 0 ); + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + tools::Rectangle aRect = pWindow->GetWindowExtentsRelative( nullptr ); + aBounds = AWTRectangle( aRect ); + vcl::Window* pParent = pWindow->GetAccessibleParentWindow(); + if ( pParent ) + { + tools::Rectangle aParentRect = pParent->GetWindowExtentsRelative( nullptr ); + awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() ); + aBounds.X -= aParentScreenLoc.X; + aBounds.Y -= aParentScreenLoc.Y; + } + } + + return aBounds; +} + +awt::Point VCLXAccessibleComponent::getLocationOnScreen( ) +{ + OExternalLockGuard aGuard( this ); + + awt::Point aPos; + if ( GetWindow() ) + { + tools::Rectangle aRect = GetWindow()->GetWindowExtentsRelative( nullptr ); + aPos.X = aRect.Left(); + aPos.Y = aRect.Top(); + } + + return aPos; +} + +void VCLXAccessibleComponent::grabFocus( ) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet(); + if ( m_xVCLXWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) ) + m_xVCLXWindow->setFocus(); +} + +sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground( ) +{ + OExternalLockGuard aGuard( this ); + + Color nColor; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsControlForeground() ) + nColor = pWindow->GetControlForeground(); + else + { + vcl::Font aFont; + if ( pWindow->IsControlFont() ) + aFont = pWindow->GetControlFont(); + else + aFont = pWindow->GetFont(); + nColor = aFont.GetColor(); + // COL_AUTO is not very meaningful for AT + if ( nColor == COL_AUTO) + nColor = pWindow->GetTextColor(); + } + } + + return sal_Int32(nColor); +} + +sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground( ) +{ + OExternalLockGuard aGuard( this ); + + Color nColor; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsControlBackground() ) + nColor = pWindow->GetControlBackground(); + else + nColor = pWindow->GetBackground().GetColor(); + } + + return sal_Int32(nColor); +} + +// XAccessibleExtendedComponent + +uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( ) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< awt::XFont > xFont; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY ); + if ( xDev.is() ) + { + vcl::Font aFont; + if ( pWindow->IsControlFont() ) + aFont = pWindow->GetControlFont(); + else + aFont = pWindow->GetFont(); + VCLXFont* pVCLXFont = new VCLXFont; + pVCLXFont->Init( *xDev, aFont ); + xFont = pVCLXFont; + } + } + + return xFont; +} + +OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText( ) +{ + OExternalLockGuard aGuard( this ); + + OUString sRet; + if ( GetWindow() ) + sRet = GetWindow()->GetText(); + + return sRet; +} + +OUString SAL_CALL VCLXAccessibleComponent::getToolTipText( ) +{ + OExternalLockGuard aGuard( this ); + + OUString sRet; + if ( GetWindow() ) + sRet = GetWindow()->GetQuickHelpText(); + + return sRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxbitmap.cxx b/toolkit/source/awt/vclxbitmap.cxx new file mode 100644 index 000000000..4b08ebd40 --- /dev/null +++ b/toolkit/source/awt/vclxbitmap.cxx @@ -0,0 +1,65 @@ +/* -*- 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 + + + + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXBitmap ); + +// css::awt::XBitmap +css::awt::Size VCLXBitmap::getSize() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::awt::Size aSize( maBitmap.GetSizePixel().Width(), maBitmap.GetSizePixel().Height() ); + return aSize; +} + +css::uno::Sequence< sal_Int8 > VCLXBitmap::getDIB() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + SvMemoryStream aMem; + WriteDIB(maBitmap.GetBitmap(), aMem, false, true); + return css::uno::Sequence( static_cast(aMem.GetData()), aMem.Tell() ); +} + +css::uno::Sequence< sal_Int8 > VCLXBitmap::getMaskDIB() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return vcl::bitmap::GetMaskDIB(maBitmap); +} + +sal_Int64 SAL_CALL VCLXBitmap::estimateUsage() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return maBitmap.GetSizeBytes(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxcontainer.cxx b/toolkit/source/awt/vclxcontainer.cxx new file mode 100644 index 000000000..541a99134 --- /dev/null +++ b/toolkit/source/awt/vclxcontainer.cxx @@ -0,0 +1,293 @@ +/* -*- 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 + + + + +void VCLXContainer::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) +{ + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXContainer::VCLXContainer() +{ +} + +VCLXContainer::~VCLXContainer() +{ +} + +// css::uno::XInterface +css::uno::Any VCLXContainer::queryInterface( const css::uno::Type & rType ) +{ + css::uno::Any aRet = ::cppu::queryInterface( rType, + static_cast< css::awt::XVclContainer* >(this), + static_cast< css::awt::XVclContainerPeer* >(this) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +IMPL_IMPLEMENTATION_ID( VCLXContainer ) + +// css::lang::XTypeProvider +css::uno::Sequence< css::uno::Type > VCLXContainer::getTypes() +{ + static const ::cppu::OTypeCollection aTypeList( + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + VCLXWindow::getTypes() + ); + return aTypeList.getTypes(); +} + + +// css::awt::XVclContainer +void VCLXContainer::addVclContainerListener( const css::uno::Reference< css::awt::XVclContainerListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + GetContainerListeners().addInterface( rxListener ); +} + +void VCLXContainer::removeVclContainerListener( const css::uno::Reference< css::awt::XVclContainerListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + GetContainerListeners().removeInterface( rxListener ); +} + +css::uno::Sequence< css::uno::Reference< css::awt::XWindow > > VCLXContainer::getWindows( ) +{ + SolarMutexGuard aGuard; + + // Request container interface from all children + css::uno::Sequence< css::uno::Reference< css::awt::XWindow > > aSeq; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + sal_uInt16 nChildren = pWindow->GetChildCount(); + if ( nChildren ) + { + aSeq = css::uno::Sequence< css::uno::Reference< css::awt::XWindow > >( nChildren ); + css::uno::Reference< css::awt::XWindow > * pChildRefs = aSeq.getArray(); + for ( sal_uInt16 n = 0; n < nChildren; n++ ) + { + vcl::Window* pChild = pWindow->GetChild( n ); + css::uno::Reference< css::awt::XWindowPeer > xWP = pChild->GetComponentInterface(); + css::uno::Reference< css::awt::XWindow > xW( xWP, css::uno::UNO_QUERY ); + pChildRefs[n] = xW; + } + } + } + return aSeq; +} + + +// css::awt::XVclContainerPeer +void VCLXContainer::enableDialogControl( sal_Bool bEnable ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( bEnable ) + nStyle |= WB_DIALOGCONTROL; + else + nStyle &= (~WB_DIALOGCONTROL); + pWindow->SetStyle( nStyle ); + } +} + +void VCLXContainer::setTabOrder( const css::uno::Sequence< css::uno::Reference< css::awt::XWindow > >& Components, const css::uno::Sequence< css::uno::Any >& Tabs, sal_Bool bGroupControl ) +{ + SolarMutexGuard aGuard; + + sal_uInt32 nCount = Components.getLength(); + DBG_ASSERT( nCount == static_cast(Tabs.getLength()), "setTabOrder: TabCount != ComponentCount" ); + const css::uno::Reference< css::awt::XWindow > * pComps = Components.getConstArray(); + const css::uno::Any* pTabs = Tabs.getConstArray(); + + vcl::Window* pPrevWin = nullptr; + for ( sal_uInt32 n = 0; n < nCount; n++ ) + { + // css::style::TabStop + VclPtr pWin = VCLUnoHelper::GetWindow( pComps[n] ); + // May be NULL if a css::uno::Sequence is originated from TabController and is missing a peer! + if ( pWin ) + { + // Order windows before manipulating their style, because elements such as the + // RadioButton considers the PREV-window in StateChanged. + if ( pPrevWin ) + pWin->SetZOrder( pPrevWin, ZOrderFlags::Behind ); + + WinBits nStyle = pWin->GetStyle(); + nStyle &= ~(WB_TABSTOP|WB_NOTABSTOP|WB_GROUP); + if ( pTabs[n].getValueType().getTypeClass() == css::uno::TypeClass_BOOLEAN ) + { + bool bTab = false; + pTabs[n] >>= bTab; + nStyle |= ( bTab ? WB_TABSTOP : WB_NOTABSTOP ); + } + pWin->SetStyle( nStyle ); + + if ( bGroupControl ) + { + if ( n == 0 ) + pWin->SetDialogControlStart( true ); + else + pWin->SetDialogControlStart( false ); + } + + pPrevWin = pWin; + } + } +} + +void VCLXContainer::setGroup( const css::uno::Sequence< css::uno::Reference< css::awt::XWindow > >& Components ) +{ + SolarMutexGuard aGuard; + + sal_uInt32 nCount = Components.getLength(); + const css::uno::Reference< css::awt::XWindow > * pComps = Components.getConstArray(); + + vcl::Window* pPrevWin = nullptr; + vcl::Window* pPrevRadio = nullptr; + for ( sal_uInt32 n = 0; n < nCount; n++ ) + { + VclPtr pWin = VCLUnoHelper::GetWindow( pComps[n] ); + if ( pWin ) + { + vcl::Window* pSortBehind = pPrevWin; + // #57096# Sort all radios consecutively + bool bNewPrevWin = true; + if ( pWin->GetType() == WindowType::RADIOBUTTON ) + { + if ( pPrevRadio ) + { + // This RadioButton was sorted before PrevWin + bNewPrevWin = ( pPrevWin == pPrevRadio ); + pSortBehind = pPrevRadio; + } + pPrevRadio = pWin; + } + + // Z-Order + if ( pSortBehind ) + pWin->SetZOrder( pSortBehind, ZOrderFlags::Behind ); + + WinBits nStyle = pWin->GetStyle(); + if ( n == 0 ) + nStyle |= WB_GROUP; + else + nStyle &= (~WB_GROUP); + pWin->SetStyle( nStyle ); + + // Add WB_GROUP after the last group + if ( n == ( nCount - 1 ) ) + { + vcl::Window* pBehindLast = pWin->GetWindow( GetWindowType::Next ); + if ( pBehindLast ) + { + WinBits nLastStyle = pBehindLast->GetStyle(); + nLastStyle |= WB_GROUP; + pBehindLast->SetStyle( nLastStyle ); + } + } + + if ( bNewPrevWin ) + pPrevWin = pWin; + } + } +} + +void SAL_CALL VCLXContainer::setProperty( + const OUString& PropertyName, + const css::uno::Any& Value ) +{ + SolarMutexGuard aGuard; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_SCROLLHEIGHT: + case BASEPROPERTY_SCROLLWIDTH: + case BASEPROPERTY_SCROLLTOP: + case BASEPROPERTY_SCROLLLEFT: + { + sal_Int32 nVal =0; + Value >>= nVal; + Size aSize( nVal, nVal ); + VclPtr pWindow = GetWindow(); + MapMode aMode( MapUnit::MapAppFont ); + toolkit::ScrollableDialog* pScrollable = dynamic_cast< toolkit::ScrollableDialog* >( pWindow.get() ); + if ( pWindow && pScrollable ) + { + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); + if ( !pDev ) + pDev = pWindow->GetParent(); + // shouldn't happen but it appears pDev can be NULL + // #FIXME ( find out how/why ) + if ( !pDev ) + break; + + aSize = pDev->LogicToPixel( aSize, aMode ); + switch ( nPropType ) + { + case BASEPROPERTY_SCROLLHEIGHT: + pScrollable->SetScrollHeight( aSize.Height() ); + break; + case BASEPROPERTY_SCROLLWIDTH: + pScrollable->SetScrollWidth( aSize.Width() ); + break; + case BASEPROPERTY_SCROLLTOP: + pScrollable->SetScrollTop( aSize.Height() ); + break; + case BASEPROPERTY_SCROLLLEFT: + pScrollable->SetScrollLeft( aSize.Width() ); + break; + default: + break; + } + break; + } + break; + } + + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxdevice.cxx b/toolkit/source/awt/vclxdevice.cxx new file mode 100644 index 000000000..84e54e630 --- /dev/null +++ b/toolkit/source/awt/vclxdevice.cxx @@ -0,0 +1,298 @@ +/* -*- 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 + + +VCLXDevice::VCLXDevice() +{ +} + +VCLXDevice::~VCLXDevice() +{ + //TODO: why was this empty, and everything done in ~VCLXVirtualDevice? + SolarMutexGuard g; + mpOutputDevice.reset(); +} + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXDevice ); + +// css::awt::XDevice, +css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( ) +{ + SolarMutexGuard aGuard; + + css::uno::Reference< css::awt::XGraphics > xRef; + + if ( mpOutputDevice ) + xRef = mpOutputDevice->CreateUnoGraphics(); + + return xRef; +} + +css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight ) +{ + SolarMutexGuard aGuard; + + css::uno::Reference< css::awt::XDevice > xRef; + if ( GetOutputDevice() ) + { + VCLXVirtualDevice* pVDev = new VCLXVirtualDevice; + VclPtrInstance pVclVDev( *GetOutputDevice() ); + pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) ); + pVDev->SetVirtualDevice( pVclVDev ); + xRef = pVDev; + } + return xRef; +} + +css::awt::DeviceInfo VCLXDevice::getInfo() +{ + SolarMutexGuard aGuard; + + css::awt::DeviceInfo aInfo; + + if( mpOutputDevice ) + { + Size aDevSz; + OutDevType eDevType = mpOutputDevice->GetOutDevType(); + if ( eDevType == OUTDEV_WINDOW ) + { + aDevSz = static_cast(mpOutputDevice.get())->GetSizePixel(); + static_cast(mpOutputDevice.get())->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset ); + } + else if ( eDevType == OUTDEV_PRINTER ) + { + aDevSz = static_cast(mpOutputDevice.get())->GetPaperSizePixel(); + Size aOutSz = mpOutputDevice->GetOutputSizePixel(); + Point aOffset = static_cast(mpOutputDevice.get())->GetPageOffset(); + aInfo.LeftInset = aOffset.X(); + aInfo.TopInset = aOffset.Y(); + aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X(); + aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y(); + } + else // VirtualDevice + { + aDevSz = mpOutputDevice->GetOutputSizePixel(); + aInfo.LeftInset = 0; + aInfo.TopInset = 0; + aInfo.RightInset = 0; + aInfo.BottomInset = 0; + } + + aInfo.Width = aDevSz.Width(); + aInfo.Height = aDevSz.Height(); + + Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MapUnit::MapCM ) ); + aInfo.PixelPerMeterX = aTmpSz.Width()/10; + aInfo.PixelPerMeterY = aTmpSz.Height()/10; + + aInfo.BitsPerPixel = mpOutputDevice->GetBitCount(); + + aInfo.Capabilities = 0; + if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER ) + aInfo.Capabilities = css::awt::DeviceCapability::RASTEROPERATIONS|css::awt::DeviceCapability::GETBITS; + } + + return aInfo; +} + +css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( ) +{ + SolarMutexGuard aGuard; + + css::uno::Sequence< css::awt::FontDescriptor> aFonts; + if( mpOutputDevice ) + { + int nFonts = mpOutputDevice->GetDevFontCount(); + if ( nFonts ) + { + aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts ); + css::awt::FontDescriptor* pFonts = aFonts.getArray(); + for ( int n = 0; n < nFonts; n++ ) + pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) ); + } + } + return aFonts; +} + +css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor ) +{ + SolarMutexGuard aGuard; + + css::uno::Reference< css::awt::XFont > xRef; + if( mpOutputDevice ) + { + VCLXFont* pMetric = new VCLXFont; + pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) ); + xRef = pMetric; + } + return xRef; +} + +css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight ) +{ + SolarMutexGuard aGuard; + + css::uno::Reference< css::awt::XBitmap > xBmp; + if( mpOutputDevice ) + { + BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) ); + + VCLXBitmap* pBmp = new VCLXBitmap; + pBmp->SetBitmap( aBmp ); + xBmp = pBmp; + } + return xBmp; +} + +css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap ) +{ + SolarMutexGuard aGuard; + + BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap ); + VCLXBitmap* pBmp = new VCLXBitmap; + pBmp->SetBitmap( aBmp ); + css::uno::Reference< css::awt::XDisplayBitmap > xDBmp = pBmp; + return xDBmp; +} + +VCLXVirtualDevice::~VCLXVirtualDevice() +{ + SolarMutexGuard aGuard; + + mpOutputDevice.disposeAndClear(); +} + +// Interface implementation of css::awt::XUnitConversion + +css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit ) +{ + SolarMutexGuard aGuard; + if (TargetUnit == css::util::MeasureUnit::PERCENT ) + { + // percentage not allowed here + throw css::lang::IllegalArgumentException(); + } + + css::awt::Point aAWTPoint(0,0); + // X,Y + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); + ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint); + ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode ); + aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint); + } + + return aAWTPoint; +} + + +css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit ) +{ + SolarMutexGuard aGuard; + if (SourceUnit == css::util::MeasureUnit::PERCENT || + SourceUnit == css::util::MeasureUnit::PIXEL ) + { + // pixel or percentage not allowed here + throw css::lang::IllegalArgumentException(); + } + + css::awt::Point aAWTPoint(0,0); + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); + ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint); + ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode ); + aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint); + } + + return aAWTPoint; +} + +css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit ) +{ + SolarMutexGuard aGuard; + if (TargetUnit == css::util::MeasureUnit::PERCENT) + { + // percentage not allowed here + throw css::lang::IllegalArgumentException(); + } + + css::awt::Size aAWTSize(0,0); + // Width, Height + + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); + ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize); + ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode ); + aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz); + } + + return aAWTSize; +} + +css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit ) +{ + SolarMutexGuard aGuard; + if (SourceUnit == css::util::MeasureUnit::PERCENT || + SourceUnit == css::util::MeasureUnit::PIXEL) + { + // pixel or percentage not allowed here + throw css::lang::IllegalArgumentException(); + } + + css::awt::Size aAWTSize(0,0); + // Width, Height + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); + ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize); + ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode ); + aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz); + } + + return aAWTSize; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxfont.cxx b/toolkit/source/awt/vclxfont.cxx new file mode 100644 index 000000000..2f1134eab --- /dev/null +++ b/toolkit/source/awt/vclxfont.cxx @@ -0,0 +1,194 @@ +/* -*- 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 + + + +VCLXFont::VCLXFont() +{ + mpFontMetric = nullptr; +} + +VCLXFont::~VCLXFont() +{ +} + +void VCLXFont::Init( css::awt::XDevice& rxDev, const vcl::Font& rFont ) +{ + mxDevice = &rxDev; + + mpFontMetric.reset(); + + maFont = rFont; +} + +bool VCLXFont::ImplAssertValidFontMetric() +{ + if ( !mpFontMetric && mxDevice.is() ) + { + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + vcl::Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + mpFontMetric.reset( new FontMetric( pOutDev->GetFontMetric() ) ); + pOutDev->SetFont( aOldFont ); + } + } + return mpFontMetric != nullptr; +} + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXFont ); + +css::awt::FontDescriptor VCLXFont::getFontDescriptor( ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return VCLUnoHelper::CreateFontDescriptor( maFont ); + +} + +css::awt::SimpleFontMetric VCLXFont::getFontMetric( ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::awt::SimpleFontMetric aFM; + if ( ImplAssertValidFontMetric() ) + aFM = VCLUnoHelper::CreateFontMetric( *mpFontMetric ); + return aFM; +} + +sal_Int16 VCLXFont::getCharWidth( sal_Unicode c ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int16 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + vcl::Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + + nRet = sal::static_int_cast< sal_Int16 >( + pOutDev->GetTextWidth( OUString(c) )); + + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +css::uno::Sequence< sal_Int16 > VCLXFont::getCharWidths( sal_Unicode nFirst, sal_Unicode nLast ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::uno::Sequence aSeq; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + vcl::Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + + sal_Int16 nCount = nLast-nFirst + 1; + aSeq = css::uno::Sequence( nCount ); + for ( sal_uInt16 n = 0; n < nCount; n++ ) + { + aSeq.getArray()[n] = sal::static_int_cast< sal_Int16 >( + pOutDev->GetTextWidth( + OUString(static_cast< sal_Unicode >(nFirst+n)) )); + } + + pOutDev->SetFont( aOldFont ); + } + return aSeq; +} + +sal_Int32 VCLXFont::getStringWidth( const OUString& str ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + vcl::Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + nRet = pOutDev->GetTextWidth( str ); + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +sal_Int32 VCLXFont::getStringWidthArray( const OUString& str, css::uno::Sequence< sal_Int32 >& rDXArray ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + vcl::Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + std::unique_ptr pDXA(new long[str.getLength()]); + nRet = pOutDev->GetTextArray( str, pDXA.get() ); + rDXArray = css::uno::Sequence( str.getLength() ); + for(int i = 0; i < str.getLength(); i++) + { + rDXArray[i] = pDXA[i]; + } + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +void VCLXFont::getKernPairs( css::uno::Sequence< sal_Unicode >& /*rnChars1*/, css::uno::Sequence< sal_Unicode >& /*rnChars2*/, css::uno::Sequence< sal_Int16 >& /*rnKerns*/ ) +{ + // NOTE: this empty method is just used for keeping the related UNO-API stable +} + +// css::awt::XFont2 +sal_Bool VCLXFont::hasGlyphs( const OUString& aText ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + SolarMutexGuard aSolarGuard; + + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + if ( pOutDev->HasGlyphs( maFont, aText ) == -1 ) + { + return true; + } + } + + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxgraphics.cxx b/toolkit/source/awt/vclxgraphics.cxx new file mode 100644 index 000000000..9fcb527a0 --- /dev/null +++ b/toolkit/source/awt/vclxgraphics.cxx @@ -0,0 +1,492 @@ +/* -*- 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 + +using namespace com::sun::star; + + + +// lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXGraphics ); + +VCLXGraphics::VCLXGraphics() + : mpOutputDevice(nullptr) + , meRasterOp(RasterOp::OverPaint) +{ +} + +VCLXGraphics::~VCLXGraphics() +{ + std::vector< VCLXGraphics* > *pLst = mpOutputDevice ? mpOutputDevice->GetUnoGraphicsList() : nullptr; + if ( pLst ) + { + auto it = std::find(pLst->begin(), pLst->end(), this); + if (it != pLst->end()) + pLst->erase( it ); + } + + mpClipRegion.reset(); + + SolarMutexGuard g; + mpOutputDevice.reset(); +} + +void VCLXGraphics::SetOutputDevice( OutputDevice* pOutDev ) +{ + mpOutputDevice = pOutDev; + mxDevice = nullptr; + initAttrs(); +} + +void VCLXGraphics::Init( OutputDevice* pOutDev ) +{ + DBG_ASSERT( !mpOutputDevice, "VCLXGraphics::Init already has pOutDev !" ); + mpOutputDevice = pOutDev; + + initAttrs(); + mpClipRegion = nullptr; + + // Register at OutputDevice + std::vector< VCLXGraphics* > *pLst = mpOutputDevice->GetUnoGraphicsList(); + if ( !pLst ) + pLst = mpOutputDevice->CreateUnoGraphicsList(); + pLst->push_back( this ); +} + +void VCLXGraphics::initAttrs() +{ + if ( !mpOutputDevice ) + return; + + maFont = mpOutputDevice->GetFont(); + maTextColor = mpOutputDevice->GetTextColor(); /* COL_BLACK */ + maTextFillColor = mpOutputDevice->GetTextFillColor(); /* COL_TRANSPARENT */ + maLineColor = mpOutputDevice->GetLineColor(); /* COL_BLACK */ + maFillColor = mpOutputDevice->GetFillColor(); /* COL_WHITE */ + meRasterOp = mpOutputDevice->GetRasterOp(); /* RasterOp::OverPaint */ +} + +void VCLXGraphics::InitOutputDevice( InitOutDevFlags nFlags ) +{ + if(mpOutputDevice) + { + SolarMutexGuard aVclGuard; + + if ( nFlags & InitOutDevFlags::FONT ) + { + mpOutputDevice->SetFont( maFont ); + mpOutputDevice->SetTextColor( maTextColor ); + mpOutputDevice->SetTextFillColor( maTextFillColor ); + } + + if ( nFlags & InitOutDevFlags::COLORS ) + { + mpOutputDevice->SetLineColor( maLineColor ); + mpOutputDevice->SetFillColor( maFillColor ); + } + + mpOutputDevice->SetRasterOp( meRasterOp ); + + if( mpClipRegion ) + mpOutputDevice->SetClipRegion( *mpClipRegion ); + else + mpOutputDevice->SetClipRegion(); + } +} + +uno::Reference< awt::XDevice > VCLXGraphics::getDevice() +{ + SolarMutexGuard aGuard; + + if( !mxDevice.is() && mpOutputDevice ) + { + VCLXDevice* pDev = new VCLXDevice; + pDev->SetOutputDevice( mpOutputDevice ); + mxDevice = pDev; + } + return mxDevice; +} + +awt::SimpleFontMetric VCLXGraphics::getFontMetric() +{ + SolarMutexGuard aGuard; + + awt::SimpleFontMetric aM; + if( mpOutputDevice ) + { + mpOutputDevice->SetFont( maFont ); + aM = VCLUnoHelper::CreateFontMetric( mpOutputDevice->GetFontMetric() ); + } + return aM; +} + +void VCLXGraphics::setFont( const uno::Reference< awt::XFont >& rxFont ) +{ + SolarMutexGuard aGuard; + + maFont = VCLUnoHelper::CreateFont( rxFont ); +} + +void VCLXGraphics::selectFont( const awt::FontDescriptor& rDescription ) +{ + SolarMutexGuard aGuard; + + maFont = VCLUnoHelper::CreateFont( rDescription, vcl::Font() ); +} + +void VCLXGraphics::setTextColor( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + maTextColor = Color( nColor ); +} + +void VCLXGraphics::setTextFillColor( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + maTextFillColor = Color( nColor ); +} + +void VCLXGraphics::setLineColor( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + maLineColor = Color( nColor ); +} + +void VCLXGraphics::setFillColor( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + maFillColor = Color( nColor ); +} + +void VCLXGraphics::setRasterOp( awt::RasterOperation eROP ) +{ + SolarMutexGuard aGuard; + + meRasterOp = static_cast(eROP); +} + +void VCLXGraphics::setClipRegion( const uno::Reference< awt::XRegion >& rxRegion ) +{ + SolarMutexGuard aGuard; + + if ( rxRegion.is() ) + mpClipRegion.reset( new vcl::Region( VCLUnoHelper::GetRegion( rxRegion ) ) ); + else + mpClipRegion.reset(); +} + +void VCLXGraphics::intersectClipRegion( const uno::Reference< awt::XRegion >& rxRegion ) +{ + SolarMutexGuard aGuard; + + if ( rxRegion.is() ) + { + vcl::Region aRegion( VCLUnoHelper::GetRegion( rxRegion ) ); + if ( !mpClipRegion ) + mpClipRegion.reset( new vcl::Region( aRegion ) ); + else + mpClipRegion->Intersect( aRegion ); + } +} + +void VCLXGraphics::push( ) +{ + SolarMutexGuard aGuard; + + + if( mpOutputDevice ) + mpOutputDevice->Push(); +} + +void VCLXGraphics::pop( ) +{ + SolarMutexGuard aGuard; + + + if( mpOutputDevice ) + mpOutputDevice->Pop(); +} + +void VCLXGraphics::clear( + const awt::Rectangle& aRect ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + const ::tools::Rectangle aVCLRect = VCLUnoHelper::ConvertToVCLRect( aRect ); + mpOutputDevice->Erase( aVCLRect ); + } +} + +void VCLXGraphics::copy( const uno::Reference< awt::XDevice >& rxSource, sal_Int32 nSourceX, sal_Int32 nSourceY, sal_Int32 nSourceWidth, sal_Int32 nSourceHeight, sal_Int32 nDestX, sal_Int32 nDestY, sal_Int32 nDestWidth, sal_Int32 nDestHeight ) +{ + SolarMutexGuard aGuard; + + if ( mpOutputDevice ) + { + VCLXDevice* pFromDev = comphelper::getUnoTunnelImplementation( rxSource ); + DBG_ASSERT( pFromDev, "VCLXGraphics::copy - invalid device" ); + if ( pFromDev ) + { + InitOutputDevice( InitOutDevFlags::NONE ); + mpOutputDevice->DrawOutDev( Point( nDestX, nDestY ), Size( nDestWidth, nDestHeight ), + Point( nSourceX, nSourceY ), Size( nSourceWidth, nSourceHeight ), *pFromDev->GetOutputDevice() ); + } + } +} + +void VCLXGraphics::draw( const uno::Reference< awt::XDisplayBitmap >& rxBitmapHandle, sal_Int32 nSourceX, sal_Int32 nSourceY, sal_Int32 nSourceWidth, sal_Int32 nSourceHeight, sal_Int32 nDestX, sal_Int32 nDestY, sal_Int32 nDestWidth, sal_Int32 nDestHeight ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::NONE); + uno::Reference< awt::XBitmap > xBitmap( rxBitmapHandle, uno::UNO_QUERY ); + BitmapEx aBmpEx = VCLUnoHelper::GetBitmap( xBitmap ); + + Point aPos(nDestX - nSourceX, nDestY - nSourceY); + Size aSz = aBmpEx.GetSizePixel(); + + if(nDestWidth != nSourceWidth) + { + float zoomX = static_cast(nDestWidth) / static_cast(nSourceWidth); + aSz.setWidth( static_cast(static_cast(aSz.Width()) * zoomX) ); + } + + if(nDestHeight != nSourceHeight) + { + float zoomY = static_cast(nDestHeight) / static_cast(nSourceHeight); + aSz.setHeight( static_cast(static_cast(aSz.Height()) * zoomY) ); + } + + if(nSourceX || nSourceY || aSz.Width() != nSourceWidth || aSz.Height() != nSourceHeight) + mpOutputDevice->IntersectClipRegion(vcl::Region(tools::Rectangle(nDestX, nDestY, nDestX + nDestWidth - 1, nDestY + nDestHeight - 1))); + + mpOutputDevice->DrawBitmapEx( aPos, aSz, aBmpEx ); + } +} + +void VCLXGraphics::drawPixel( sal_Int32 x, sal_Int32 y ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawPixel( Point( x, y ) ); + } +} + +void VCLXGraphics::drawLine( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawLine( Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawRect( tools::Rectangle( Point( x, y ), Size( width, height ) ) ); + } +} + +void VCLXGraphics::drawRoundedRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 nHorzRound, sal_Int32 nVertRound ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawRect( tools::Rectangle( Point( x, y ), Size( width, height ) ), nHorzRound, nVertRound ); + } +} + +void VCLXGraphics::drawPolyLine( const uno::Sequence< sal_Int32 >& DataX, const uno::Sequence< sal_Int32 >& DataY ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawPolyLine( VCLUnoHelper::CreatePolygon( DataX, DataY ) ); + } +} + +void VCLXGraphics::drawPolygon( const uno::Sequence< sal_Int32 >& DataX, const uno::Sequence< sal_Int32 >& DataY ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawPolygon( VCLUnoHelper::CreatePolygon( DataX, DataY ) ); + } +} + +void VCLXGraphics::drawPolyPolygon( const uno::Sequence< uno::Sequence< sal_Int32 > >& DataX, const uno::Sequence< uno::Sequence< sal_Int32 > >& DataY ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + sal_uInt16 nPolys = static_cast(DataX.getLength()); + tools::PolyPolygon aPolyPoly( nPolys ); + for ( sal_uInt16 n = 0; n < nPolys; n++ ) + aPolyPoly[n] = VCLUnoHelper::CreatePolygon( DataX.getConstArray()[n], DataY.getConstArray()[n] ); + + mpOutputDevice->DrawPolyPolygon( aPolyPoly ); + } +} + +void VCLXGraphics::drawEllipse( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawEllipse( tools::Rectangle( Point( x, y ), Size( width, height ) ) ); + } +} + +void VCLXGraphics::drawArc( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawArc( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawPie( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawPie( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawChord( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawChord( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawGradient( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, const awt::Gradient& rGradient ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + Gradient aGradient(static_cast(rGradient.Style), Color(rGradient.StartColor), Color(rGradient.EndColor)); + aGradient.SetAngle(rGradient.Angle); + aGradient.SetBorder(rGradient.Border); + aGradient.SetOfsX(rGradient.XOffset); + aGradient.SetOfsY(rGradient.YOffset); + aGradient.SetStartIntensity(rGradient.StartIntensity); + aGradient.SetEndIntensity(rGradient.EndIntensity); + aGradient.SetSteps(rGradient.StepCount); + mpOutputDevice->DrawGradient( tools::Rectangle( Point( x, y ), Size( width, height ) ), aGradient ); + } +} + +void VCLXGraphics::drawText( sal_Int32 x, sal_Int32 y, const OUString& rText ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS |InitOutDevFlags::FONT); + mpOutputDevice->DrawText( Point( x, y ), rText ); + } +} + +void VCLXGraphics::drawTextArray( sal_Int32 x, sal_Int32 y, const OUString& rText, const uno::Sequence< sal_Int32 >& rLongs ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice ) + { + InitOutputDevice( InitOutDevFlags::COLORS|InitOutDevFlags::FONT ); + std::unique_ptr pDXA(new long[rText.getLength()]); + for(int i = 0; i < rText.getLength(); i++) + { + pDXA[i] = rLongs[i]; + } + mpOutputDevice->DrawTextArray( Point( x, y ), rText, pDXA.get() ); + } +} + + +void VCLXGraphics::drawImage( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int16 nStyle, const uno::Reference< graphic::XGraphic >& xGraphic ) +{ + SolarMutexGuard aGuard; + + if( mpOutputDevice && xGraphic.is() ) + { + Image aImage( xGraphic ); + if ( !!aImage ) + { + InitOutputDevice( InitOutDevFlags::COLORS ); + mpOutputDevice->DrawImage( Point( x, y ), Size( width, height ), aImage, static_cast(nStyle) ); + } + } +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxmenu.cxx b/toolkit/source/awt/vclxmenu.cxx new file mode 100644 index 000000000..0ba38df42 --- /dev/null +++ b/toolkit/source/awt/vclxmenu.cxx @@ -0,0 +1,855 @@ +/* -*- 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 + +VCLXMenu::VCLXMenu() + : maMenuListeners( *this ) + , mnDefaultItem(0) +{ + mpMenu = nullptr; +} + +VCLXMenu::VCLXMenu( Menu* pMenu ) + : maMenuListeners( *this ) + , mnDefaultItem(0) +{ + mpMenu = pMenu; +} + +VCLXMenu::~VCLXMenu() +{ + maPopupMenuRefs.clear(); + if ( mpMenu ) + { + mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); + mpMenu.disposeAndClear(); + } +} + +bool VCLXMenu::IsPopupMenu() const +{ + return (mpMenu && ! mpMenu->IsMenuBar()); +} + +void VCLXMenu::ImplCreateMenu( bool bPopup ) +{ + DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" ); + + if ( bPopup ) + mpMenu = VclPtr::Create(); + else + mpMenu = VclPtr::Create(); + + mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); +} + +void VCLXMenu::ImplAddListener() +{ + assert(mpMenu); + mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); +} + +IMPL_LINK( VCLXMenu, MenuEventListener, VclMenuEvent&, rMenuEvent, void ) +{ + DBG_ASSERT( rMenuEvent.GetMenu() && mpMenu, "Menu???" ); + + if ( rMenuEvent.GetMenu() == mpMenu ) // Also called for the root menu + { + switch ( rMenuEvent.GetId() ) + { + case VclEventId::MenuSelect: + { + if ( maMenuListeners.getLength() ) + { + css::awt::MenuEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.itemSelected( aEvent ); + } + } + break; + case VclEventId::ObjectDying: + { + mpMenu = nullptr; + } + break; + case VclEventId::MenuHighlight: + { + if ( maMenuListeners.getLength() ) + { + css::awt::MenuEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.itemHighlighted( aEvent ); + } + } + break; + case VclEventId::MenuActivate: + { + if ( maMenuListeners.getLength() ) + { + css::awt::MenuEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.itemActivated( aEvent ); + } + } + break; + case VclEventId::MenuDeactivate: + { + if ( maMenuListeners.getLength() ) + { + css::awt::MenuEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.itemDeactivated( aEvent ); + } + } + break; + + // ignore accessibility events + case VclEventId::MenuEnable: + case VclEventId::MenuInsertItem: + case VclEventId::MenuRemoveItem: + case VclEventId::MenuSubmenuActivate: + case VclEventId::MenuSubmenuDeactivate: + case VclEventId::MenuSubmenuChanged: + case VclEventId::MenuDehighlight: + case VclEventId::MenuDisable: + case VclEventId::MenuItemTextChanged: + case VclEventId::MenuItemChecked: + case VclEventId::MenuItemUnchecked: + case VclEventId::MenuShow: + case VclEventId::MenuHide: + break; + + default: OSL_FAIL( "MenuEventListener - Unknown event!" ); + } + } +} + + +OUString SAL_CALL VCLXMenu::getImplementationName( ) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + OUString implName( "stardiv.Toolkit." ); + if ( bIsPopupMenu ) + implName += "VCLXPopupMenu"; + else + implName += "VCLXMenuBar"; + + return implName; +} + +css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( ) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + if ( bIsPopupMenu ) + return css::uno::Sequence{ + "com.sun.star.awt.PopupMenu", + "stardiv.vcl.PopupMenu"}; + else + return css::uno::Sequence{ + "com.sun.star.awt.MenuBar", + "stardiv.vcl.MenuBar"}; +} + +sal_Bool SAL_CALL VCLXMenu::supportsService(const OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +css::uno::Any VCLXMenu::queryInterface( + const css::uno::Type & rType ) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + css::uno::Any aRet; + + if ( bIsPopupMenu ) + aRet = ::cppu::queryInterface( rType, + static_cast< css::awt::XMenu* >(static_cast(this)), + static_cast< css::awt::XPopupMenu* >(this), + static_cast< css::lang::XTypeProvider* >(this), + static_cast< css::lang::XServiceInfo* >(this), + static_cast< css::lang::XUnoTunnel* >(this) ); + else + aRet = ::cppu::queryInterface( rType, + static_cast< css::awt::XMenu* >(static_cast(this)), + static_cast< css::awt::XMenuBar* >(this), + static_cast< css::lang::XTypeProvider* >(this), + static_cast< css::lang::XServiceInfo* >(this), + static_cast< css::lang::XUnoTunnel* >(this) ); + + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + + +UNO3_GETIMPLEMENTATION_IMPL( VCLXMenu ); + +css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes() +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + if ( bIsPopupMenu ) + { + static cppu::OTypeCollection collectionPopupMenu( + cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get()); + return collectionPopupMenu.getTypes(); + } + else + { + static cppu::OTypeCollection collectionMenuBar( + cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get()); + return collectionMenuBar.getTypes(); + } +} + + +css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId() +{ + return css::uno::Sequence(); +} + +void VCLXMenu::addMenuListener( + const css::uno::Reference< css::awt::XMenuListener >& rxListener ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maMenuListeners.addInterface( rxListener ); +} + +void VCLXMenu::removeMenuListener( + const css::uno::Reference< css::awt::XMenuListener >& rxListener ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maMenuListeners.removeInterface( rxListener ); +} + +void VCLXMenu::insertItem( + sal_Int16 nItemId, + const OUString& aText, + sal_Int16 nItemStyle, + sal_Int16 nPos ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->InsertItem(nItemId, aText, static_cast(nItemStyle), OString(), nPos); +} + +void VCLXMenu::removeItem( + sal_Int16 nPos, + sal_Int16 nCount ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if (!mpMenu) + return; + + sal_Int32 nItemCount = static_cast(mpMenu->GetItemCount()); + if ((nCount > 0) && (nPos >= 0) && (nPos < nItemCount)) + { + sal_Int16 nP = sal::static_int_cast< sal_Int16 >( + std::min( static_cast(nPos+nCount), static_cast(nItemCount) )); + while( nP-nPos > 0 ) + mpMenu->RemoveItem( --nP ); + } +} + +sal_Int16 VCLXMenu::getItemCount( ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemCount() : 0; +} + +sal_Int16 VCLXMenu::getItemId( + sal_Int16 nPos ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemId( nPos ) : 0; +} + +sal_Int16 VCLXMenu::getItemPos( + sal_Int16 nId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemPos( nId ) : 0; +} + +void VCLXMenu::enableItem( + sal_Int16 nItemId, + sal_Bool bEnable ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->EnableItem( nItemId, bEnable ); +} + +sal_Bool VCLXMenu::isItemEnabled( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu && mpMenu->IsItemEnabled( nItemId ); +} + +void VCLXMenu::setItemText( + sal_Int16 nItemId, + const OUString& aText ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetItemText( nItemId, aText ); +} + +OUString VCLXMenu::getItemText( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OUString aItemText; + if ( mpMenu ) + aItemText = mpMenu->GetItemText( nItemId ); + return aItemText; +} + +void VCLXMenu::setPopupMenu( + sal_Int16 nItemId, + const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + VCLXMenu* pVCLMenu = comphelper::getUnoTunnelImplementation( rxPopupMenu ); + DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" ); + + if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() ) + { + maPopupMenuRefs.push_back( rxPopupMenu ); + + mpMenu->SetPopupMenu( nItemId, static_cast( pVCLMenu->GetMenu() ) ); + } +} + +css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::uno::Reference< css::awt::XPopupMenu > aRef; + Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : nullptr; + if ( pMenu ) + { + for ( size_t n = maPopupMenuRefs.size(); n; ) + { + css::uno::Reference< css::awt::XPopupMenu >& rRef = maPopupMenuRefs[ --n ]; + Menu* pM = static_cast(rRef.get())->GetMenu(); + if ( pM == pMenu ) + { + aRef = rRef; + break; + } + } + // it seems the popup menu is not insert into maPopupMenuRefs + // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu + if( !aRef.is() ) + { + aRef = new VCLXPopupMenu( static_cast(pMenu) ); + } + } + return aRef; +} + +// css::awt::XPopupMenu +void VCLXMenu::insertSeparator( + sal_Int16 nPos ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->InsertSeparator(OString(), nPos); +} + +void VCLXMenu::setDefaultItem( + sal_Int16 nItemId ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + mnDefaultItem = nItemId; +} + +sal_Int16 VCLXMenu::getDefaultItem( ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mnDefaultItem; +} + +void VCLXMenu::checkItem( + sal_Int16 nItemId, + sal_Bool bCheck ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->CheckItem( nItemId, bCheck ); +} + +sal_Bool VCLXMenu::isItemChecked( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu && mpMenu->IsItemChecked( nItemId ); +} + +sal_Int16 VCLXMenu::execute( + const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer, + const css::awt::Rectangle& rPos, + sal_Int16 nFlags ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int16 nRet = 0; + if ( mpMenu && IsPopupMenu() ) + { + nRet = static_cast(mpMenu.get())->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ), + VCLRectangle( rPos ), + static_cast(nFlags) | PopupMenuFlags::NoMouseUpClose ); + } + return nRet; +} + + +void SAL_CALL VCLXMenu::setCommand( + sal_Int16 nItemId, + const OUString& aCommand ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetItemCommand( nItemId, aCommand ); +} + +OUString SAL_CALL VCLXMenu::getCommand( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OUString aItemCommand; + if ( mpMenu ) + aItemCommand = mpMenu->GetItemCommand( nItemId ); + return aItemCommand; +} + +void SAL_CALL VCLXMenu::setHelpCommand( + sal_Int16 nItemId, + const OUString& aHelp ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetHelpCommand( nItemId, aHelp ); +} + +OUString SAL_CALL VCLXMenu::getHelpCommand( + sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OUString aHelpCommand; + if ( mpMenu ) + aHelpCommand = mpMenu->GetHelpCommand( nItemId ); + return aHelpCommand; +} + + +namespace +{ + Image lcl_XGraphic2VCLImage( + const css::uno::Reference< css::graphic::XGraphic >& xGraphic, + bool bResize ) + { + Image aImage; + if ( !xGraphic.is() ) + return aImage; + + aImage = Image( xGraphic ); + const ::Size aCurSize = aImage.GetSizePixel(); + const sal_Int32 nCurWidth = aCurSize.Width(); + const sal_Int32 nCurHeight = aCurSize.Height(); + const sal_Int32 nIdeal( 16 ); + + if ( nCurWidth > 0 && nCurHeight > 0 ) + { + if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) ) + { + sal_Int32 nIdealWidth = std::min(nCurWidth, nIdeal); + sal_Int32 nIdealHeight = std::min(nCurHeight, nIdeal); + + ::Size aNewSize( nIdealWidth, nIdealHeight ); + + bool bModified( false ); + BitmapEx aBitmapEx = aImage.GetBitmapEx(); + bModified = aBitmapEx.Scale( aNewSize, BmpScaleFlag::BestQuality ); + + if ( bModified ) + aImage = Image( aBitmapEx ); + } + } + return aImage; + } + + /** Copied from svtools/inc/acceleratorexecute.hxx */ + css::awt::KeyEvent lcl_VCLKey2AWTKey( + const vcl::KeyCode& aVCLKey) + { + css::awt::KeyEvent aAWTKey; + aAWTKey.Modifiers = 0; + aAWTKey.KeyCode = static_cast(aVCLKey.GetCode()); + + if (aVCLKey.IsShift()) + aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT; + if (aVCLKey.IsMod1()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1; + if (aVCLKey.IsMod2()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2; + if (aVCLKey.IsMod3()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3; + + return aAWTKey; + } + + vcl::KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey) + { + bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ); + bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ); + bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ); + bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ); + sal_uInt16 nKey = static_cast(aAWTKey.KeyCode); + + return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3); + } + +} + + +sal_Bool SAL_CALL VCLXMenu::isPopupMenu( ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return IsPopupMenu(); +} + +void SAL_CALL VCLXMenu::clear( ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + mpMenu->Clear(); +} + + +css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType( + ::sal_Int16 nItemPos ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::awt::MenuItemType aMenuItemType = + css::awt::MenuItemType_DONTKNOW; + if ( mpMenu ) + { + aMenuItemType = static_cast(mpMenu->GetItemType( nItemPos )); + } + + return aMenuItemType; +} + +void SAL_CALL VCLXMenu::hideDisabledEntries( + sal_Bool bHide ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + { + if ( bHide ) + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries ); + else + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::HideDisabledEntries ); + } +} + + +sal_Bool SAL_CALL VCLXMenu::isInExecute( ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + return PopupMenu::IsInExecute(); + else + return false; +} + + +void SAL_CALL VCLXMenu::endExecute() +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + static_cast( mpMenu.get() )->EndExecute(); +} + + +void SAL_CALL VCLXMenu::enableAutoMnemonics( + sal_Bool bEnable ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + { + if ( !bEnable ) + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics ); + else + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics ); + } +} + + +void SAL_CALL VCLXMenu::setAcceleratorKeyEvent( + ::sal_Int16 nItemId, + const css::awt::KeyEvent& aKeyEvent ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + vcl::KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent ); + mpMenu->SetAccelKey( nItemId, aVCLKeyCode ); + } +} + + +css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent( + ::sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::awt::KeyEvent aKeyEvent; + if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + vcl::KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId ); + aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode ); + } + + return aKeyEvent; +} + + +void SAL_CALL VCLXMenu::setHelpText( + ::sal_Int16 nItemId, + const OUString& sHelpText ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + mpMenu->SetHelpText( nItemId, sHelpText ); + } +} + + +OUString SAL_CALL VCLXMenu::getHelpText( + ::sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OUString sHelpText; + if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + sHelpText = mpMenu->GetHelpText( nItemId ); + } + + return sHelpText; +} + + +void SAL_CALL VCLXMenu::setTipHelpText( + ::sal_Int16 nItemId, + const OUString& sTipHelpText ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + mpMenu->SetTipHelpText( nItemId, sTipHelpText ); + } +} + + +OUString SAL_CALL VCLXMenu::getTipHelpText( + ::sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OUString sTipHelpText; + if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + sTipHelpText = mpMenu->GetTipHelpText( nItemId ); + } + return sTipHelpText; +} + + +void SAL_CALL VCLXMenu::setItemImage( + ::sal_Int16 nItemId, + const css::uno::Reference< css::graphic::XGraphic >& xGraphic, + sal_Bool bScale ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale ); + mpMenu->SetItemImage( nItemId, aImage ); + } +} + + +css::uno::Reference< css::graphic::XGraphic > SAL_CALL +VCLXMenu::getItemImage( + ::sal_Int16 nItemId ) +{ + SolarMutexGuard aSolarGuard; + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::uno::Reference< css::graphic::XGraphic > rxGraphic; + + if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) + { + Image aImage = mpMenu->GetItemImage( nItemId ); + if ( !!aImage ) + rxGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic(); + } + return rxGraphic; +} + +VCLXMenuBar::VCLXMenuBar() +{ + ImplCreateMenu( false ); +} + +VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( static_cast(pMenuBar) ) +{ +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +stardiv_Toolkit_VCLXMenuBar_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new VCLXMenuBar()); +} + +VCLXPopupMenu::VCLXPopupMenu() +{ + ImplCreateMenu( true ); +} + +VCLXPopupMenu::VCLXPopupMenu( PopupMenu* pPopMenu ) : VCLXMenu( static_cast(pPopMenu) ) +{ + ImplAddListener(); +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +stardiv_Toolkit_VCLXPopupMenu_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new VCLXPopupMenu()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxpointer.cxx b/toolkit/source/awt/vclxpointer.cxx new file mode 100644 index 000000000..2d382f5c5 --- /dev/null +++ b/toolkit/source/awt/vclxpointer.cxx @@ -0,0 +1,73 @@ +/* -*- 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 + +VCLXPointer::VCLXPointer() : maPointer(PointerStyle::Arrow) +{ +} + +VCLXPointer::~VCLXPointer() +{ +} + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXPointer ); + +void VCLXPointer::setType( sal_Int32 nType ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maPointer = static_cast(nType); +} + +sal_Int32 VCLXPointer::getType() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return static_cast(maPointer); +} + +OUString VCLXPointer::getImplementationName() +{ + return "stardiv.Toolkit.VCLXPointer"; +} + +sal_Bool VCLXPointer::supportsService(OUString const & ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence VCLXPointer::getSupportedServiceNames() +{ + return css::uno::Sequence{ + "com.sun.star.awt.Pointer", "stardiv.vcl.Pointer"}; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +stardiv_Toolkit_VCLXPointer_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new VCLXPointer()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxprinter.cxx b/toolkit/source/awt/vclxprinter.cxx new file mode 100644 index 000000000..51ced99ea --- /dev/null +++ b/toolkit/source/awt/vclxprinter.cxx @@ -0,0 +1,383 @@ +/* -*- 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 + + +#define BINARYSETUPMARKER 0x23864691 + +#define PROPERTY_Orientation 0 +#define PROPERTY_Horizontal 1 + +// ---------------------------------------------------- +// class VCLXPrinterPropertySet +// ---------------------------------------------------- + +IMPLEMENT_FORWARD_XINTERFACE2( VCLXPrinterPropertySet, VCLXPrinterPropertySet_Base, OPropertySetHelper ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXPrinterPropertySet, VCLXPrinterPropertySet_Base, ::cppu::OPropertySetHelper ) + +VCLXPrinterPropertySet::VCLXPrinterPropertySet( const OUString& rPrinterName ) + : OPropertySetHelper( BrdcstHelper ) + , mxPrinter(VclPtrInstance< Printer >(rPrinterName)) +{ + SolarMutexGuard aSolarGuard; + + mnOrientation = 0; + mbHorizontal = false; +} + +VCLXPrinterPropertySet::~VCLXPrinterPropertySet() +{ + SolarMutexGuard aSolarGuard; + mxPrinter.reset(); +} + +css::uno::Reference< css::awt::XDevice > const & VCLXPrinterPropertySet::GetDevice() +{ + if ( !mxPrnDevice.is() ) + { + VCLXDevice* pDev = new VCLXDevice; + pDev->SetOutputDevice( GetPrinter() ); + mxPrnDevice = pDev; + } + return mxPrnDevice; +} + +css::uno::Reference< css::beans::XPropertySetInfo > VCLXPrinterPropertySet::getPropertySetInfo( ) +{ + static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +::cppu::IPropertyArrayHelper& VCLXPrinterPropertySet::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper s_PropertyArrayHelper( + css::uno::Sequence{ + css::beans::Property( "Orientation", PROPERTY_Orientation, cppu::UnoType::get(), 0 ), + css::beans::Property( "Horizontal", PROPERTY_Horizontal, cppu::UnoType::get(), 0 )}, + false); + + return s_PropertyArrayHelper; +} + +sal_Bool VCLXPrinterPropertySet::convertFastPropertyValue( css::uno::Any & rConvertedValue, css::uno::Any & rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + bool bDifferent = false; + switch ( nHandle ) + { + case PROPERTY_Orientation: + { + sal_Int16 n; + if( ( rValue >>= n ) && ( n != mnOrientation ) ) + { + rConvertedValue <<= n; + rOldValue <<= mnOrientation; + bDifferent = true; + } + } + break; + case PROPERTY_Horizontal: + { + bool b; + if( ( rValue >>= b ) && ( b != mbHorizontal ) ) + { + rConvertedValue <<= b; + rOldValue <<= mbHorizontal; + bDifferent = true; + } + } + break; + default: + { + OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } + return bDifferent; +} + +void VCLXPrinterPropertySet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + switch( nHandle ) + { + case PROPERTY_Orientation: + { + rValue >>= mnOrientation; + } + break; + case PROPERTY_Horizontal: + { + rValue >>= mbHorizontal; + } + break; + default: + { + OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } +} + +void VCLXPrinterPropertySet::getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const +{ + ::osl::MutexGuard aGuard( const_cast(this)->Mutex ); + + switch( nHandle ) + { + case PROPERTY_Orientation: + rValue <<= mnOrientation; + break; + case PROPERTY_Horizontal: + rValue <<= mbHorizontal; + break; + default: + { + OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } +} + +// css::awt::XPrinterPropertySet +void VCLXPrinterPropertySet::setHorizontal( sal_Bool bHorizontal ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + css::uno::Any aValue; + aValue <<= bHorizontal; + setFastPropertyValue( PROPERTY_Horizontal, aValue ); +} + +css::uno::Sequence< OUString > VCLXPrinterPropertySet::getFormDescriptions( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + const sal_uInt16 nPaperBinCount = GetPrinter()->GetPaperBinCount(); + css::uno::Sequence< OUString > aDescriptions( nPaperBinCount ); + for ( sal_uInt16 n = 0; n < nPaperBinCount; n++ ) + { + // Format: + OUStringBuffer aDescr( "*;*;" ); + aDescr.append(GetPrinter()->GetPaperBinName( n )); + aDescr.append(';'); + aDescr.append(OUString::number(n)); + aDescr.append(";*;*"); + + aDescriptions.getArray()[n] = aDescr.makeStringAndClear(); + } + return aDescriptions; +} + +void VCLXPrinterPropertySet::selectForm( const OUString& rFormDescription ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + sal_uInt16 nPaperBin = sal::static_int_cast< sal_uInt16 >( + rFormDescription.getToken( 3, ';' ).toInt32()); + GetPrinter()->SetPaperBin( nPaperBin ); +} + +css::uno::Sequence< sal_Int8 > VCLXPrinterPropertySet::getBinarySetup( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + SvMemoryStream aMem; + aMem.WriteUInt32( BINARYSETUPMARKER ); + WriteJobSetup( aMem, GetPrinter()->GetJobSetup() ); + return css::uno::Sequence( static_cast(aMem.GetData()), aMem.Tell() ); +} + +void VCLXPrinterPropertySet::setBinarySetup( const css::uno::Sequence< sal_Int8 >& data ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + SvMemoryStream aMem( const_cast(data.getConstArray()), data.getLength(), StreamMode::READ ); + sal_uInt32 nMarker; + aMem.ReadUInt32( nMarker ); + DBG_ASSERT( nMarker == BINARYSETUPMARKER, "setBinarySetup - invalid!" ); + if ( nMarker == BINARYSETUPMARKER ) + { + JobSetup aSetup; + ReadJobSetup( aMem, aSetup ); + GetPrinter()->SetJobSetup( aSetup ); + } +} + + +// ---------------------------------------------------- +// class VCLXPrinter +// ---------------------------------------------------- +VCLXPrinter::VCLXPrinter( const OUString& rPrinterName ) + : VCLXPrinter_Base( rPrinterName ) +{ +} + +VCLXPrinter::~VCLXPrinter() +{ +} + +sal_Bool VCLXPrinter::start( const OUString& /*rJobName*/, sal_Int16 /*nCopies*/, sal_Bool /*bCollate*/ ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + if (mxPrinter) + { + maInitJobSetup = mxPrinter->GetJobSetup(); + mxListener = std::make_shared(mxPrinter, nullptr); + } + + return true; +} + +void VCLXPrinter::end( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + if (mxListener) + { + Printer::PrintJob(mxListener, maInitJobSetup); + mxListener.reset(); + } +} + +void VCLXPrinter::terminate( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + mxListener.reset(); +} + +css::uno::Reference< css::awt::XDevice > VCLXPrinter::startPage( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + if (mxListener) + { + mxListener->StartPage(); + } + return GetDevice(); +} + +void VCLXPrinter::endPage( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + if (mxListener) + { + mxListener->EndPage(); + } +} + + +// ---------------------------------------------------- +// class VCLXInfoPrinter +// ---------------------------------------------------- + +VCLXInfoPrinter::VCLXInfoPrinter( const OUString& rPrinterName ) + : VCLXInfoPrinter_Base( rPrinterName ) +{ +} + +VCLXInfoPrinter::~VCLXInfoPrinter() +{ +} + +// css::awt::XInfoPrinter +css::uno::Reference< css::awt::XDevice > VCLXInfoPrinter::createDevice( ) +{ + ::osl::MutexGuard aGuard( Mutex ); + + return GetDevice(); +} + +// ---------------------------------------------------- +// class VCLXPrinterServer +// ---------------------------------------------------- + +// css::awt::XPrinterServer2 +css::uno::Sequence< OUString > VCLXPrinterServer::getPrinterNames( ) +{ + const std::vector& rQueues = Printer::GetPrinterQueues(); + sal_uInt32 nPrinters = rQueues.size(); + + css::uno::Sequence< OUString > aNames( nPrinters ); + for ( sal_uInt32 n = 0; n < nPrinters; n++ ) + aNames.getArray()[n] = rQueues[n]; + + return aNames; +} + +OUString VCLXPrinterServer::getDefaultPrinterName() +{ + return Printer::GetDefaultPrinterName(); +} + +css::uno::Reference< css::awt::XPrinter > VCLXPrinterServer::createPrinter( const OUString& rPrinterName ) +{ + css::uno::Reference< css::awt::XPrinter > xP = new VCLXPrinter( rPrinterName ); + return xP; +} + +css::uno::Reference< css::awt::XInfoPrinter > VCLXPrinterServer::createInfoPrinter( const OUString& rPrinterName ) +{ + css::uno::Reference< css::awt::XInfoPrinter > xP = new VCLXInfoPrinter( rPrinterName ); + return xP; +} + +OUString VCLXPrinterServer::getImplementationName() +{ + return "stardiv.Toolkit.VCLXPrinterServer"; +} + +sal_Bool VCLXPrinterServer::supportsService(OUString const & ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence VCLXPrinterServer::getSupportedServiceNames() +{ + return css::uno::Sequence{ + "com.sun.star.awt.PrinterServer", "stardiv.vcl.PrinterServer"}; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +stardiv_Toolkit_VCLXPrinterServer_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new VCLXPrinterServer); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxregion.cxx b/toolkit/source/awt/vclxregion.cxx new file mode 100644 index 000000000..f3356d300 --- /dev/null +++ b/toolkit/source/awt/vclxregion.cxx @@ -0,0 +1,147 @@ +/* -*- 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 + + + +VCLXRegion::VCLXRegion() +{ +} + +VCLXRegion::~VCLXRegion() +{ +} + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL( VCLXRegion ); + +css::awt::Rectangle VCLXRegion::getBounds() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return AWTRectangle( maRegion.GetBoundRect() ); +} + +void VCLXRegion::clear() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.SetEmpty(); +} + +void VCLXRegion::move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Move( nHorzMove, nVertMove ); +} + +void VCLXRegion::unionRectangle( const css::awt::Rectangle& rRect ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Union( VCLRectangle( rRect ) ); +} + +void VCLXRegion::intersectRectangle( const css::awt::Rectangle& rRect ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Intersect( VCLRectangle( rRect ) ); +} + +void VCLXRegion::excludeRectangle( const css::awt::Rectangle& rRect ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Exclude( VCLRectangle( rRect ) ); +} + +void VCLXRegion::xOrRectangle( const css::awt::Rectangle& rRect ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.XOr( VCLRectangle( rRect ) ); +} + +void VCLXRegion::unionRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Union( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::intersectRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Intersect( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::excludeRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Exclude( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::xOrRegion( const css::uno::Reference< css::awt::XRegion >& rxRegion ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.XOr( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +css::uno::Sequence< css::awt::Rectangle > VCLXRegion::getRectangles() +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + RectangleVector aRectangles; + maRegion.GetRegionRectangles(aRectangles); + +// sal_uLong nRects = maRegion.GetRectCount(); + css::uno::Sequence< css::awt::Rectangle > aRects(aRectangles.size()); + sal_uInt32 a(0); + + for(const auto& rRect : aRectangles) + { + aRects.getArray()[a++] = AWTRectangle(rRect); + } + + //Rectangle aRect; + //sal_uInt32 nR = 0; + //RegionHandle h = maRegion.BeginEnumRects(); + //while ( maRegion.GetEnumRects( h, aRect ) ) + // aRects.getArray()[nR++] = AWTRectangle( aRect ); + //maRegion.EndEnumRects( h ); + + return aRects; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxspinbutton.cxx b/toolkit/source/awt/vclxspinbutton.cxx new file mode 100644 index 000000000..197997a12 --- /dev/null +++ b/toolkit/source/awt/vclxspinbutton.cxx @@ -0,0 +1,331 @@ +/* -*- 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 "vclxwindows_internal.hxx" + +namespace toolkit +{ + + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + + + namespace + { + void lcl_modifyStyle( vcl::Window* _pWindow, WinBits _nStyleBits, bool _bShouldBePresent ) + { + WinBits nStyle = _pWindow->GetStyle(); + if ( _bShouldBePresent ) + nStyle |= _nStyleBits; + else + nStyle &= ~_nStyleBits; + _pWindow->SetStyle( nStyle ); + } + } + + VCLXSpinButton::VCLXSpinButton() + :maAdjustmentListeners( *this ) + { + } + + + VCLXSpinButton::~VCLXSpinButton() + { + } + + + IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) + + + IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) + + + void SAL_CALL VCLXSpinButton::dispose( ) + { + { + SolarMutexGuard aGuard; + + EventObject aDisposeEvent; + aDisposeEvent.Source = *this; + maAdjustmentListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); + } + + + void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) + { + if ( listener.is() ) + maAdjustmentListeners.addInterface( listener ); + } + + + void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) + { + if ( listener.is() ) + maAdjustmentListeners.removeInterface( listener ); + } + + namespace + { + typedef void (SpinButton::*SetSpinButtonValue) (long); + typedef long (SpinButton::*GetSpinButtonValue) () const; + + + void lcl_setSpinButtonValue(vcl::Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue ) + { + SolarMutexGuard aGuard; + SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow ); + if ( pSpinButton ) + (pSpinButton->*_pSetter)( _nValue ); + } + + + sal_Int32 lcl_getSpinButtonValue(const vcl::Window* _pWindow, GetSpinButtonValue _pGetter ) + { + SolarMutexGuard aGuard; + + sal_Int32 nValue = 0; + + const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow ); + if ( pSpinButton ) + nValue = (pSpinButton->*_pGetter)( ); + return nValue; + } + } + + + void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) + { + lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n ); + } + + + void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) + { + SolarMutexGuard aGuard; + + setMinimum( minValue ); + setMaximum( maxValue ); + setValue( currentValue ); + } + + + sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) + { + return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue ); + } + + + void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) + { + lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue ); + } + + + void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) + { + lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue ); + } + + + sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) + { + return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin ); + } + + + sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) + { + return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax ); + } + + + void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) + { + lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement ); + } + + + sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) + { + return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep ); + } + + + void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) + { + SolarMutexGuard aGuard; + + lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL ); + } + + + sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) + { + return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) + ? ScrollBarOrientation::HORIZONTAL + : ScrollBarOrientation::VERTICAL; + } + + + void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) + { + SolarMutexClearableGuard aGuard; + Reference< XSpinValue > xKeepAlive( this ); + VclPtr pSpinButton = GetAs(); + if ( !pSpinButton ) + return; + + switch ( _rVclWindowEvent.GetId() ) + { + case VclEventId::SpinbuttonUp: + case VclEventId::SpinbuttonDown: + if ( maAdjustmentListeners.getLength() ) + { + AdjustmentEvent aEvent; + aEvent.Source = *this; + aEvent.Value = pSpinButton->GetValue(); + + aGuard.clear(); + maAdjustmentListeners.adjustmentValueChanged( aEvent ); + } + break; + + default: + xKeepAlive.clear(); + aGuard.clear(); + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + break; + } + } + + + void SAL_CALL VCLXSpinButton::setProperty( const OUString& PropertyName, const Any& Value ) + { + SolarMutexGuard aGuard; + + sal_Int32 nValue = 0; + bool bIsLongValue = ( Value >>= nValue ); + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_BACKGROUNDCOLOR: + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + setButtonLikeFaceColor( GetWindow(), Value); + break; + + case BASEPROPERTY_SPINVALUE: + if ( bIsLongValue ) + setValue( nValue ); + break; + + case BASEPROPERTY_SPINVALUE_MIN: + if ( bIsLongValue ) + setMinimum( nValue ); + break; + + case BASEPROPERTY_SPINVALUE_MAX: + if ( bIsLongValue ) + setMaximum( nValue ); + break; + + case BASEPROPERTY_SPININCREMENT: + if ( bIsLongValue ) + setSpinIncrement( nValue ); + break; + + case BASEPROPERTY_ORIENTATION: + if ( bIsLongValue ) + lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL ); + break; + + default: + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } + + + Any SAL_CALL VCLXSpinButton::getProperty( const OUString& PropertyName ) + { + SolarMutexGuard aGuard; + + Any aReturn; + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_BACKGROUNDCOLOR: + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + aReturn = getButtonLikeFaceColor( GetWindow() ); + break; + + case BASEPROPERTY_SPINVALUE: + aReturn <<= getValue( ); + break; + + case BASEPROPERTY_SPINVALUE_MIN: + aReturn <<= getMinimum( ); + break; + + case BASEPROPERTY_SPINVALUE_MAX: + aReturn <<= getMaximum( ); + break; + + case BASEPROPERTY_SPININCREMENT: + aReturn <<= getSpinIncrement( ); + break; + + case BASEPROPERTY_ORIENTATION: + aReturn <<= static_cast( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) + ? ScrollBarOrientation::HORIZONTAL + : ScrollBarOrientation::VERTICAL + ); + break; + + default: + aReturn = VCLXWindow::getProperty( PropertyName ); + } + } + return aReturn; + } + + +} // namespace toolkit + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxsystemdependentwindow.cxx b/toolkit/source/awt/vclxsystemdependentwindow.cxx new file mode 100644 index 000000000..2c53edf19 --- /dev/null +++ b/toolkit/source/awt/vclxsystemdependentwindow.cxx @@ -0,0 +1,114 @@ +/* -*- 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 + +#if defined UNX && ! defined MACOSX +#include +#endif + +#include +#include +#include +#include + +#ifdef MACOSX +#include +#include +#include +#endif + +#include +#include +#include + + + +VCLXSystemDependentWindow::VCLXSystemDependentWindow() +{ +} + +VCLXSystemDependentWindow::~VCLXSystemDependentWindow() +{ +} + +// css::uno::XInterface +css::uno::Any VCLXSystemDependentWindow::queryInterface( const css::uno::Type & rType ) +{ + css::uno::Any aRet = ::cppu::queryInterface( rType, + static_cast< css::awt::XSystemDependentWindowPeer* >(this) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +IMPL_IMPLEMENTATION_ID( VCLXSystemDependentWindow ) + +// css::lang::XTypeProvider +css::uno::Sequence< css::uno::Type > VCLXSystemDependentWindow::getTypes() +{ + static const ::cppu::OTypeCollection aTypeList( + cppu::UnoType::get(), + cppu::UnoType::get(), + VCLXWindow::getTypes() + ); + return aTypeList.getTypes(); +} + +css::uno::Any VCLXSystemDependentWindow::getWindowHandle( const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) +{ + SolarMutexGuard aGuard; + + // TODO, check the process id + css::uno::Any aRet; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + const SystemEnvData* pSysData = static_cast(pWindow.get())->GetSystemData(); + if( pSysData ) + { +#if defined(_WIN32) + if( SystemType == css::lang::SystemDependent::SYSTEM_WIN32 ) + { + aRet <<= reinterpret_cast(pSysData->hWnd); + } +#elif defined(MACOSX) + if( SystemType == css::lang::SystemDependent::SYSTEM_MAC ) + { + aRet <<= reinterpret_cast(pSysData->mpNSView); + } +#elif defined(ANDROID) + // Nothing + (void) SystemType; +#elif defined(IOS) + // Nothing + (void) SystemType; +#elif defined(UNX) + if( SystemType == css::lang::SystemDependent::SYSTEM_XWINDOW ) + { + css::awt::SystemDependentXWindow aSD; + aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay)); + aSD.WindowHandle = pSysData->aWindow; + aRet <<= aSD; + } +#endif + } + } + return aRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxtabpagecontainer.cxx b/toolkit/source/awt/vclxtabpagecontainer.cxx new file mode 100644 index 000000000..d51fedcff --- /dev/null +++ b/toolkit/source/awt/vclxtabpagecontainer.cxx @@ -0,0 +1,230 @@ +/* -*- 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 + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::view; + + +void VCLXTabPageContainer::GetPropertyIds( std::vector< sal_uInt16 > &rIds ) +{ + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXTabPageContainer::VCLXTabPageContainer() : + m_aTabPageListeners( *this ) +{ +} + +VCLXTabPageContainer::~VCLXTabPageContainer() +{ + SAL_INFO("toolkit", __FUNCTION__); +} + +void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY ) +{ + SolarMutexGuard aGuard; + VclPtr pTabControl = GetAs(); + if ( pTabControl ) + { + TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) ); + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); + if (pTabPage && pDev) + { + ::Point aPos( nX, nY ); + aPos = pDev->PixelToLogic( aPos ); + pTabPage->Draw( pDev, aPos, DrawFlags::NONE ); + } + } + + VCLXWindow::draw( nX, nY ); +} + +void SAL_CALL VCLXTabPageContainer::setProperty(const OUString& PropertyName, const Any& Value ) +{ + SolarMutexGuard aGuard; + VclPtr pTabPage = GetAs(); + if ( pTabPage ) + VCLXWindow::setProperty( PropertyName, Value ); +} + +::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID() +{ + VclPtr pTabCtrl = GetAs(); + return pTabCtrl ? pTabCtrl->GetCurPageId( ) : 0; +} + +void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) +{ + VclPtr pTabCtrl = GetAs(); + if ( pTabCtrl ) + pTabCtrl->SelectTabPage(_activetabpageid); +} + +::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( ) +{ + VclPtr pTabCtrl = GetAs(); + return pTabCtrl ? pTabCtrl->GetPageCount() : 0; +} + +sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) +{ + return (getActiveTabPageID() == tabPageIndex); +} + +Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) +{ + return (tabPageIndex >= 0 && tabPageIndex < static_cast(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : nullptr; +} + +Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) +{ + SolarMutexGuard aGuard; + Reference< css::awt::tab::XTabPage > xTabPage; + for(const auto& rTabPage : m_aTabPages) + { + Reference< awt::XControl > xControl(rTabPage,UNO_QUERY ); + Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); + if ( tabPageID == xP->getTabPageID() ) + { + xTabPage = rTabPage; + break; + } + } + return xTabPage; +} + +void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener ) +{ + m_aTabPageListeners.addInterface( listener ); +} + +void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener ) +{ + m_aTabPageListeners.removeInterface( listener ); +} + +void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ + SolarMutexClearableGuard aGuard; + VclPtr pTabControl = GetAs(); + if ( pTabControl ) + { + switch ( _rVclWindowEvent.GetId() ) + { + case VclEventId::TabpageActivate: + { + sal_uLong page = reinterpret_cast(_rVclWindowEvent.GetData()); + awt::tab::TabPageActivatedEvent aEvent(nullptr,page); + m_aTabPageListeners.tabPageActivated(aEvent); + break; + } + default: + aGuard.clear(); + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + break; + } + } +} +void SAL_CALL VCLXTabPageContainer::disposing( const css::lang::EventObject& /*Source*/ ) +{ +} +void SAL_CALL VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent& Event ) +{ + SolarMutexGuard aGuard; + VclPtr pTabCtrl = GetAs(); + Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); + if ( !pTabCtrl || !xTabPage.is() ) + return; + + Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); + Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); + sal_Int16 nPageID = xP->getTabPageID(); + + if (!xControl->getPeer().is()) + throw RuntimeException("No peer for tabpage container!"); + VclPtr pWindow = VCLUnoHelper::GetWindow(xControl->getPeer()); + TabPage* pPage = static_cast(pWindow.get()); + pTabCtrl->InsertPage(nPageID,pPage->GetText()); + + pPage->Hide(); + pTabCtrl->SetTabPage(nPageID,pPage); + pTabCtrl->SetHelpText(nPageID,xP->getToolTip()); + pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL())); + pTabCtrl->SelectTabPage(nPageID); + pTabCtrl->SetPageEnabled(nPageID,xP->getEnabled()); + m_aTabPages.push_back(xTabPage); + +} +void SAL_CALL VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent& Event ) +{ + SolarMutexGuard aGuard; + VclPtr pTabCtrl = GetAs(); + Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); + if ( pTabCtrl && xTabPage.is() ) + { + Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); + Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); + pTabCtrl->RemovePage(xP->getTabPageID()); + m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage)); + } +} +void SAL_CALL VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent& /*Event*/ ) +{ +} + +void VCLXTabPageContainer::propertiesChange(const::css::uno::Sequence& rEvents) +{ + SolarMutexGuard aGuard; + VclPtr pTabCtrl = GetAs(); + if (!pTabCtrl) + return; + + for (const beans::PropertyChangeEvent& rEvent : rEvents) { + // handle property changes for tab pages + Reference< css::awt::tab::XTabPageModel > xTabPageModel(rEvent.Source, uno::UNO_QUERY); + if (!xTabPageModel.is()) + continue; + + const sal_Int16 nId = xTabPageModel->getTabPageID(); + if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_ENABLED)) { + pTabCtrl->SetPageEnabled(nId, xTabPageModel->getEnabled()); + } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_TITLE)) { + pTabCtrl->SetPageText(nId, xTabPageModel->getTitle()); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx new file mode 100644 index 000000000..b7f6f2f43 --- /dev/null +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -0,0 +1,2639 @@ +/* -*- 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 . + */ + +#ifdef _WIN32 +#include +#include +#endif +#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 + +#ifdef MACOSX +#include +#include +#include +#endif + +#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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if HAVE_FEATURE_OPENGL +#include +#endif +#include +#include +#include +#include +#include + +#include +#include +#include + +#if defined(_WIN32) +#define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_WIN32 +#elif defined(MACOSX) +#define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_MAC +#elif defined(UNX) +#define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_XWINDOW +#endif + +void MessBox::ImplInitButtons() +{ + ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK; + ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel; + ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE; + + if ( mnMessBoxStyle & MessBoxStyle::OkCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultOk + nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::YesNo ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) + nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultNo + nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + nNoFlags |= ButtonDialogFlags::Cancel; + + AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); + AddButton( StandardButtonType::No, RET_NO, nNoFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) + nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo ) + nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); + AddButton( StandardButtonType::No, RET_NO, nNoFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultRetry + nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore ) + { + ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE; + + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry ) + nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore ) + nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags ); + AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); + AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::Ok ) + { + nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); + } +} + +MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits, + const OUString& rTitle, const OUString& rMessage) : + ButtonDialog( WindowType::MESSBOX ), + mbHelpBtn( false ), + mnMessBoxStyle( nMessBoxStyle ), + maMessText( rMessage ) +{ + ImplLOKNotifier(pParent); + ImplInitDialog(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER); + ImplInitButtons(); + + if ( !rTitle.isEmpty() ) + SetText( rTitle ); +} + +MessBox::~MessBox() +{ + disposeOnce(); +} + +void MessBox::dispose() +{ + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); + ButtonDialog::dispose(); +} + +void MessBox::ImplPosControls() +{ + if ( !GetHelpId().isEmpty() ) + { + if ( !mbHelpBtn ) + { + AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 ); + mbHelpBtn = true; + } + } + else + { + if ( mbHelpBtn ) + { + RemoveButton( RET_HELP ); + mbHelpBtn = false; + } + } + + TextRectInfo aTextInfo; + tools::Rectangle aRect( 0, 0, 30000, 30000 ); + tools::Rectangle aFormatRect; + Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y ); + Size aImageSize; + Size aPageSize; + Size aMEditSize; + long nTitleWidth; + long nButtonSize = ImplGetButtonSize(); + long nMaxLineWidth; + long nWidth; + WinBits nWinStyle = WB_LEFT | WB_NOLABEL; + DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left; + + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); + + // Clean up message text with tabs + OUString aMessText(maMessText.replaceAll("\t", " ")); + + //If window too small, we make dialog box be wider + long nMaxWidth = 630 * GetDPIScaleFactor(); + + // MessagBox should be at least as wide as to see the title + // Extra-Width for Close button, because Close button is set after this call + nTitleWidth = CalcTitleWidth(); + + nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2); + + // for an image, get its size, create a suitable control and position it + aImageSize = maImage.GetSizePixel(); + if ( aImageSize.Width() ) + { + aImageSize.AdjustWidth(4 ); + aImageSize.AdjustHeight(4 ); + aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE ); + mpFixedImage = VclPtr::Create( this ); + mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X, + IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ), + aImageSize ); + mpFixedImage->SetImage( maImage ); + mpFixedImage->Show(); + nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE; + } + else + aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X ); + + // Determine maximum line length without wordbreak + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + nMaxLineWidth = aFormatRect.GetWidth(); + nTextStyle |= DrawTextFlags::WordBreak; + + // Determine the width for text formatting + if ( nMaxLineWidth > 450 ) + nWidth = 450; + else if ( nMaxLineWidth > 300 ) + nWidth = nMaxLineWidth+5; + else + nWidth = 300; + + nWidth *= GetDPIScaleFactor(); + + if ( nButtonSize > nWidth ) + nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET); + if ( nWidth > nMaxWidth ) + nWidth = nMaxWidth; + + aRect.SetRight( nWidth ); + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + if ( aTextInfo.GetMaxLineWidth() > nWidth ) + { + nWidth = aTextInfo.GetMaxLineWidth()+8; + aRect.SetRight( nWidth ); + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + } + + // get Style for VCLMultiLineEdit + aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 ); + aMEditSize.setHeight( aFormatRect.GetHeight() ); + aPageSize.setWidth( aImageSize.Width() ); + if ( aMEditSize.Height() < aImageSize.Height() ) + { + nWinStyle |= WB_VCENTER; + aPageSize.setHeight( aImageSize.Height() ); + aMEditSize.setHeight( aImageSize.Height() ); + } + else + { + nWinStyle |= WB_TOP; + aPageSize.setHeight( aMEditSize.Height() ); + } + if ( aImageSize.Width() ) + aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE ); + aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) ); + aPageSize.AdjustWidth(aMEditSize.Width()+1 ); + aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) ); + + if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH ) + aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH ); + if ( aPageSize.Width() < nTitleWidth ) + aPageSize.setWidth( nTitleWidth ); + + mpVCLMultiLineEdit = VclPtr::Create( this, nWinStyle ); + mpVCLMultiLineEdit->SetText( aMessText ); + mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize ); + mpVCLMultiLineEdit->Show(); + mpVCLMultiLineEdit->SetPaintTransparent(true); + mpVCLMultiLineEdit->EnableCursor(false); + SetPageSizePixel( aPageSize ); +} + +void MessBox::StateChanged( StateChangedType nType ) +{ + if ( nType == StateChangedType::InitShow ) + { + ImplPosControls(); + } + ButtonDialog::StateChanged( nType ); +} + +Size MessBox::GetOptimalSize() const +{ + // FIXME: base me on the font size ? + return Size( 250, 100 ); +} + + +namespace { + +extern "C" typedef vcl::Window* (*FN_SvtCreateWindow)( + VCLXWindow** ppNewComp, + const css::awt::WindowDescriptor* pDescriptor, + vcl::Window* pParent, + WinBits nWinBits ); + +class Pause : public Idle +{ +public: + explicit Pause(sal_Int32 nPauseMilliseconds) : + Idle("pause"), + m_nPauseMilliseconds(nPauseMilliseconds) + { + SetPriority(TaskPriority::HIGHEST); + Start(); + } + + virtual void Invoke() override + { + SolarMutexGuard aSolarGuard; + osl::Thread::wait(std::chrono::milliseconds(m_nPauseMilliseconds)); + Stop(); + delete this; + } + + sal_Int32 m_nPauseMilliseconds; +}; + +class VCLXToolkitMutexHelper +{ +protected: + ::osl::Mutex maMutex; +}; + +class VCLXToolkit : public VCLXToolkitMutexHelper, + public cppu::WeakComponentImplHelper< + css::awt::XToolkitExperimental, + css::awt::XToolkitRobot, + css::lang::XServiceInfo > +{ + css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard; + css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxSelection; + + oslModule hSvToolsLib; + FN_SvtCreateWindow fnSvtCreateWindow; + + ::comphelper::OInterfaceContainerHelper2 m_aTopWindowListeners; + ::comphelper::OInterfaceContainerHelper2 m_aKeyHandlers; + ::comphelper::OInterfaceContainerHelper2 m_aFocusListeners; + ::Link m_aEventListenerLink; + ::Link m_aKeyListenerLink; + bool m_bEventListener; + bool m_bKeyListener; + + DECL_LINK(eventListenerHandler, ::VclSimpleEvent&, void); + + DECL_LINK(keyListenerHandler, ::VclWindowEvent&, bool); + + void callTopWindowListeners( + ::VclSimpleEvent const * pEvent, + void (SAL_CALL css::awt::XTopWindowListener::* pFn)( + css::lang::EventObject const &)); + + bool callKeyHandlers(::VclSimpleEvent const * pEvent, bool bPressed); + + void callFocusListeners(::VclSimpleEvent const * pEvent, bool bGained); + +protected: + ::osl::Mutex& GetMutex() { return maMutex; } + + virtual void SAL_CALL disposing() override; + + static vcl::Window* ImplCreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent, + WinBits nWinBits, MessBoxStyle nMessBoxStyle ); + css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor, + MessBoxStyle nForceMessBoxStyle ); + +public: + + VCLXToolkit(); + + // css::awt::XToolkitExperimental + virtual void SAL_CALL processEventsToIdle() override; + + virtual sal_Int64 SAL_CALL getOpenGLBufferSwapCounter() override; + + virtual void SAL_CALL setDeterministicScheduling(sal_Bool bDeterministicMode) override; + + virtual void SAL_CALL pause(sal_Int32 nMilliseconds) override; + + virtual void SAL_CALL startRecording() override; + + virtual void SAL_CALL stopRecording() override; + + css::uno::Sequence< OUString > SAL_CALL getRecordingAndClear() override; + + // css::awt::XToolkit + css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getDesktopWindow( ) override; + css::awt::Rectangle SAL_CALL getWorkArea( ) override; + css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createWindow( const css::awt::WindowDescriptor& Descriptor ) override; + css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > SAL_CALL createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& Descriptors ) override; + css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) override; + css::uno::Reference< css::awt::XRegion > SAL_CALL createRegion( ) override; + + // css::awt::XSystemChildFactory + css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) override; + + // css::awt::XMessageBoxFactory + virtual css::uno::Reference< css::awt::XMessageBox > SAL_CALL createMessageBox( const css::uno::Reference< css::awt::XWindowPeer >& aParent, css::awt::MessageBoxType eType, ::sal_Int32 aButtons, const OUString& aTitle, const OUString& aMessage ) override; + + // css::awt::XDataTransfer + css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) override; + css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) override; + css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) override; + css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL getClipboard( const OUString& clipboardName ) override; + + // css::lang::XServiceInfo + OUString SAL_CALL getImplementationName( ) override; + sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // css::awt::XExtendedToolkit: + + virtual ::sal_Int32 SAL_CALL getTopWindowCount() override; + + virtual css::uno::Reference< css::awt::XTopWindow > + SAL_CALL getTopWindow(::sal_Int32 nIndex) override; + + virtual css::uno::Reference< css::awt::XTopWindow > + SAL_CALL getActiveTopWindow() override; + + virtual void SAL_CALL addTopWindowListener( + css::uno::Reference< + css::awt::XTopWindowListener > const & rListener) override; + + virtual void SAL_CALL removeTopWindowListener( + css::uno::Reference< + css::awt::XTopWindowListener > const & rListener) override; + + virtual void SAL_CALL addKeyHandler( + css::uno::Reference< + css::awt::XKeyHandler > const & rHandler) override; + + virtual void SAL_CALL removeKeyHandler( + css::uno::Reference< + css::awt::XKeyHandler > const & rHandler) override; + + virtual void SAL_CALL addFocusListener( + css::uno::Reference< + css::awt::XFocusListener > const & rListener) override; + + virtual void SAL_CALL removeFocusListener( + css::uno::Reference< + css::awt::XFocusListener > const & rListener) override; + + virtual void SAL_CALL fireFocusGained( + css::uno::Reference< + css::uno::XInterface > const & source) override; + + virtual void SAL_CALL fireFocusLost( + css::uno::Reference< + css::uno::XInterface > const & source) override; + + // css::awt::XReschedule: + virtual void SAL_CALL reschedule() override; + + // css:awt:XToolkitRobot + virtual void SAL_CALL keyPress( const css::awt::KeyEvent & aKeyEvent ) override; + + virtual void SAL_CALL keyRelease( const css::awt::KeyEvent & aKeyEvent ) override; + + virtual void SAL_CALL mousePress( const css::awt::MouseEvent & aMouseEvent ) override; + + virtual void SAL_CALL mouseRelease( const css::awt::MouseEvent & aMouseEvent ) override; + + virtual void SAL_CALL mouseMove( const css::awt::MouseEvent & aMouseEvent ) override; + +}; + +std::pair ImplGetWinBits( sal_uInt32 nComponentAttribs, WindowType nCompType ) +{ + WinBits nWinBits = 0; + MessBoxStyle nStyle = MessBoxStyle::NONE; + + bool bMessBox = false; + if ( ( nCompType == WindowType::INFOBOX ) || + ( nCompType == WindowType::MESSBOX ) || + ( nCompType == WindowType::QUERYBOX ) || + ( nCompType == WindowType::WARNINGBOX ) || + ( nCompType == WindowType::ERRORBOX ) ) + { + bMessBox = true; + } + + bool bDecoratedWindow = false; + if ( bMessBox + || ( nCompType == WindowType::DIALOG ) + || ( nCompType == WindowType::MODELESSDIALOG ) + || ( nCompType == WindowType::MODALDIALOG ) + || ( nCompType == WindowType::DOCKINGWINDOW ) + || ( nCompType == WindowType::TABDIALOG ) + || ( nCompType == WindowType::BUTTONDIALOG ) + || ( nCompType == WindowType::SYSTEMCHILDWINDOW ) + ) + { + bDecoratedWindow = true; + } + + if( nComponentAttribs & css::awt::WindowAttribute::BORDER ) + nWinBits |= WB_BORDER; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOBORDER ) + nWinBits |= WB_NOBORDER; + if( nComponentAttribs & css::awt::WindowAttribute::SIZEABLE ) + nWinBits |= WB_SIZEABLE; + if( nComponentAttribs & css::awt::WindowAttribute::MOVEABLE ) + nWinBits |= WB_MOVEABLE; + if( nComponentAttribs & css::awt::WindowAttribute::CLOSEABLE ) + nWinBits |= WB_CLOSEABLE; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::HSCROLL ) + nWinBits |= WB_HSCROLL; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::VSCROLL ) + nWinBits |= WB_VSCROLL; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::LEFT ) + nWinBits |= WB_LEFT; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CENTER ) + nWinBits |= WB_CENTER; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RIGHT ) + nWinBits |= WB_RIGHT; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SPIN ) + nWinBits |= WB_SPIN; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SORT ) + nWinBits |= WB_SORT; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DROPDOWN ) + nWinBits |= WB_DROPDOWN; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEFBUTTON ) + nWinBits |= WB_DEFBUTTON; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::READONLY ) + nWinBits |= WB_READONLY; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CLIPCHILDREN ) + nWinBits |= WB_CLIPCHILDREN; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::GROUP ) + nWinBits |= WB_GROUP; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712 + nWinBits |= WB_NOLABEL; + + // These bits are not unique + if ( bMessBox ) + { + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK ) + nStyle |= MessBoxStyle::Ok; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK_CANCEL ) + nStyle |= MessBoxStyle::OkCancel; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO ) + nStyle |= MessBoxStyle::YesNo; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO_CANCEL ) + nStyle |= MessBoxStyle::YesNoCancel; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RETRY_CANCEL ) + nStyle |= MessBoxStyle::RetryCancel; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_OK ) + nStyle |= MessBoxStyle::DefaultOk; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_CANCEL ) + nStyle |= MessBoxStyle::DefaultCancel; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_RETRY ) + nStyle |= MessBoxStyle::DefaultRetry; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_YES ) + nStyle |= MessBoxStyle::DefaultYes; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_NO ) + nStyle |= MessBoxStyle::DefaultNo; + } + if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG || nCompType == WindowType::GROUPBOX ) + { + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOHSCROLL ) + nWinBits |= WB_AUTOHSCROLL; + if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOVSCROLL ) + nWinBits |= WB_AUTOVSCROLL; + } + + + if ( bDecoratedWindow ) + { + if( nComponentAttribs & css::awt::WindowAttribute::NODECORATION ) + { + // No decoration removes several window attributes and must + // set WB_NOBORDER! + nWinBits &= ~WB_BORDER; + nWinBits &= ~WB_SIZEABLE; + nWinBits &= ~WB_MOVEABLE; + nWinBits &= ~WB_CLOSEABLE; + nWinBits |= WB_NOBORDER; + } + } + + return { nWinBits, nStyle }; +} + +struct ComponentInfo +{ + OUStringLiteral sName; + WindowType nWinType; +}; + +static ComponentInfo const aComponentInfos [] = +{ + { OUStringLiteral("animatedimages"), WindowType::CONTROL }, + { OUStringLiteral("buttondialog"), WindowType::BUTTONDIALOG }, + { OUStringLiteral("cancelbutton"), WindowType::CANCELBUTTON }, + { OUStringLiteral("checkbox"), WindowType::CHECKBOX }, + { OUStringLiteral("combobox"), WindowType::COMBOBOX }, + { OUStringLiteral("control"), WindowType::CONTROL }, + { OUStringLiteral("currencybox"), WindowType::CURRENCYBOX }, + { OUStringLiteral("currencyfield"), WindowType::CURRENCYFIELD }, + { OUStringLiteral("datebox"), WindowType::DATEBOX }, + { OUStringLiteral("datefield"), WindowType::DATEFIELD }, + { OUStringLiteral("dialog"), WindowType::DIALOG }, + { OUStringLiteral("dockingarea"), WindowType::DOCKINGAREA }, + { OUStringLiteral("dockingwindow"), WindowType::DOCKINGWINDOW }, + { OUStringLiteral("edit"), WindowType::EDIT }, + { OUStringLiteral("errorbox"), WindowType::ERRORBOX }, + { OUStringLiteral("filecontrol"), WindowType::CONTROL }, + { OUStringLiteral("fixedbitmap"), WindowType::FIXEDBITMAP }, + { OUStringLiteral("fixedhyperlink"), WindowType::CONTROL }, + { OUStringLiteral("fixedimage"), WindowType::FIXEDIMAGE }, + { OUStringLiteral("fixedline"), WindowType::FIXEDLINE }, + { OUStringLiteral("fixedtext"), WindowType::FIXEDTEXT }, + { OUStringLiteral("floatingwindow"), WindowType::FLOATINGWINDOW }, + { OUStringLiteral("formattedfield"), WindowType::CONTROL }, + { OUStringLiteral("frame"), WindowType::GROUPBOX }, + { OUStringLiteral("framewindow"), WindowType::TOOLKIT_FRAMEWINDOW }, + { OUStringLiteral("groupbox"), WindowType::GROUPBOX }, + { OUStringLiteral("helpbutton"), WindowType::HELPBUTTON }, + { OUStringLiteral("imagebutton"), WindowType::IMAGEBUTTON }, + { OUStringLiteral("infobox"), WindowType::INFOBOX }, + { OUStringLiteral("listbox"), WindowType::LISTBOX }, + { OUStringLiteral("longcurrencybox"), WindowType::LONGCURRENCYBOX }, + { OUStringLiteral("longcurrencyfield"), WindowType::CONTROL }, + { OUStringLiteral("menubutton"), WindowType::MENUBUTTON }, + { OUStringLiteral("messbox"), WindowType::MESSBOX }, + { OUStringLiteral("metricbox"), WindowType::METRICBOX }, + { OUStringLiteral("metricfield"), WindowType::METRICFIELD }, + { OUStringLiteral("modaldialog"), WindowType::MODALDIALOG }, + { OUStringLiteral("modelessdialog"), WindowType::MODELESSDIALOG }, + { OUStringLiteral("morebutton"), WindowType::MOREBUTTON }, + { OUStringLiteral("multilineedit"), WindowType::MULTILINEEDIT }, + { OUStringLiteral("multilistbox"), WindowType::MULTILISTBOX }, + { OUStringLiteral("numericbox"), WindowType::NUMERICBOX }, + { OUStringLiteral("numericfield"), WindowType::CONTROL }, + { OUStringLiteral("okbutton"), WindowType::OKBUTTON }, + { OUStringLiteral("patternbox"), WindowType::PATTERNBOX }, + { OUStringLiteral("patternfield"), WindowType::PATTERNFIELD }, + { OUStringLiteral("progressbar"), WindowType::CONTROL }, + { OUStringLiteral("pushbutton"), WindowType::PUSHBUTTON }, + { OUStringLiteral("querybox"), WindowType::QUERYBOX }, + { OUStringLiteral("radiobutton"), WindowType::RADIOBUTTON }, + { OUStringLiteral("roadmap"), WindowType::CONTROL }, + { OUStringLiteral("scrollbar"), WindowType::SCROLLBAR }, + { OUStringLiteral("scrollbarbox"), WindowType::SCROLLBARBOX }, + { OUStringLiteral("spinbutton"), WindowType::SPINBUTTON }, + { OUStringLiteral("spinfield"), WindowType::SPINFIELD }, + { OUStringLiteral("splitter"), WindowType::SPLITTER }, + { OUStringLiteral("splitwindow"), WindowType::SPLITWINDOW }, + { OUStringLiteral("statusbar"), WindowType::STATUSBAR }, + { OUStringLiteral("systemchildwindow"), WindowType::TOOLKIT_SYSTEMCHILDWINDOW }, + { OUStringLiteral("tabcontrol"), WindowType::TABCONTROL }, + { OUStringLiteral("tabdialog"), WindowType::TABDIALOG }, + { OUStringLiteral("tabpage"), WindowType::TABPAGE }, + { OUStringLiteral("tabpagecontainer"), WindowType::CONTROL }, + { OUStringLiteral("tabpagemodel"), WindowType::TABPAGE }, + { OUStringLiteral("timebox"), WindowType::TIMEBOX }, + { OUStringLiteral("timefield"), WindowType::TIMEFIELD }, + { OUStringLiteral("toolbox"), WindowType::TOOLBOX }, + { OUStringLiteral("tree"), WindowType::CONTROL }, + { OUStringLiteral("tristatebox"), WindowType::TRISTATEBOX }, + { OUStringLiteral("warningbox"), WindowType::WARNINGBOX }, + { OUStringLiteral("window"), WindowType::WINDOW }, + { OUStringLiteral("workwindow"), WindowType::WORKWINDOW } +}; + +bool ComponentInfoFindCompare( const ComponentInfo & lhs, const OUString & s) +{ + return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(s.pData->buffer, s.pData->length, + lhs.sName.data, lhs.sName.size) > 0; +} + +WindowType ImplGetComponentType( const OUString& rServiceName ) +{ + static bool bSorted = false; + if( !bSorted ) + { + assert( std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), + [](const ComponentInfo & lhs, const ComponentInfo & rhs) { + return + rtl_str_compare_WithLength( + lhs.sName.data, lhs.sName.size, rhs.sName.data, rhs.sName.size) + < 0; + } ) ); + bSorted = true; + } + + OUString sSearch; + if ( !rServiceName.isEmpty() ) + sSearch = rServiceName; + else + sSearch = "window"; + + auto it = std::lower_bound( std::begin(aComponentInfos), std::end(aComponentInfos), sSearch, + ComponentInfoFindCompare ); + if (it != std::end(aComponentInfos) && + rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(sSearch.pData->buffer, sSearch.pData->length, it->sName.data, it->sName.size) == 0) + return it->nWinType; + return WindowType::NONE; +} + +struct MessageBoxTypeInfo +{ + css::awt::MessageBoxType eType; + const char *pName; + sal_Int32 nLen; +}; + +static const MessageBoxTypeInfo aMessageBoxTypeInfo[] = +{ + { css::awt::MessageBoxType_MESSAGEBOX, RTL_CONSTASCII_STRINGPARAM("messbox") }, + { css::awt::MessageBoxType_INFOBOX, RTL_CONSTASCII_STRINGPARAM("infobox") }, + { css::awt::MessageBoxType_WARNINGBOX, RTL_CONSTASCII_STRINGPARAM("warningbox") }, + { css::awt::MessageBoxType_ERRORBOX, RTL_CONSTASCII_STRINGPARAM("errorbox") }, + { css::awt::MessageBoxType_QUERYBOX, RTL_CONSTASCII_STRINGPARAM("querybox") }, + { css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE, nullptr, 0 } +}; + +bool lcl_convertMessageBoxType( + OUString &sType, + css::awt::MessageBoxType eType ) +{ + const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo; + css::awt::MessageBoxType eVal = css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE; + + while ( pMap->pName ) + { + if ( pMap->eType == eType ) + { + eVal = eType; + sType = OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US ); + break; + } + pMap++; + } + + return ( eVal != css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE ); +} + +#ifndef IOS + +static sal_Int32 nVCLToolkitInstanceCount = 0; +static bool bInitedByVCLToolkit = false; + +osl::Mutex & getInitMutex() +{ + static osl::Mutex aMutex; + return aMutex; +} + +osl::Condition & getInitCondition() +{ + static osl::Condition aCondition; + return aCondition; +} + +extern "C" +{ +static void ToolkitWorkerFunction( void* pArgs ) +{ + osl_setThreadName("VCLXToolkit VCL main thread"); + + css::uno::Reference xServiceManager; + try + { + xServiceManager = ::comphelper::getProcessServiceFactory(); + } + catch (const css::uno::DeploymentException&) + { + } + if (!xServiceManager.is()) + { + css::uno::Reference xContext = + ::cppu::defaultBootstrap_InitialComponentContext(); + + xServiceManager.set( xContext->getServiceManager(), css::uno::UNO_QUERY_THROW ); + // set global process service factory used by unotools config helpers + ::comphelper::setProcessServiceFactory( xServiceManager ); + } + + VCLXToolkit * pTk = static_cast(pArgs); + bInitedByVCLToolkit = !IsVCLInit() && InitVCL(); + if( bInitedByVCLToolkit ) + { + UnoWrapper* pUnoWrapper = new UnoWrapper( pTk ); + UnoWrapperBase::SetUnoWrapper( pUnoWrapper ); + } + getInitCondition().set(); + if( bInitedByVCLToolkit ) + { + { + SolarMutexGuard aGuard; + Application::Execute(); + } + try + { + pTk->dispose(); + } + catch( css::uno::Exception & ) + { + } + DeInitVCL(); + } + else + { + // having the thread join itself is pretty stupid. + // but we can't get the osl_Thread to destroy here so just leak it. + } +} +} + +#endif + +// constructor, which might initialize VCL +VCLXToolkit::VCLXToolkit(): + cppu::WeakComponentImplHelper< + css::awt::XToolkitExperimental, + css::awt::XToolkitRobot, + css::lang::XServiceInfo>( GetMutex() ), + m_aTopWindowListeners(rBHelper.rMutex), + m_aKeyHandlers(rBHelper.rMutex), + m_aFocusListeners(rBHelper.rMutex), + m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)), + m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)), + m_bEventListener(false), + m_bKeyListener(false) +{ + hSvToolsLib = nullptr; + fnSvtCreateWindow = nullptr; + +#ifndef IOS + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + nVCLToolkitInstanceCount++; + if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) ) + { + // setup execute thread + CreateMainLoopThread( ToolkitWorkerFunction, this ); + getInitCondition().wait(); + } +#endif +} + +void SAL_CALL VCLXToolkit::disposing() +{ +#ifndef DISABLE_DYNLOADING + if ( hSvToolsLib ) + { + osl_unloadModule( hSvToolsLib ); + hSvToolsLib = nullptr; + fnSvtCreateWindow = nullptr; + } +#endif + +#ifndef IOS + { + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + if( --nVCLToolkitInstanceCount == 0 ) + { + if( bInitedByVCLToolkit ) + { + Application::Quit(); + JoinMainLoopThread(); + bInitedByVCLToolkit = false; + } + } + } +#endif + if (m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } + if (m_bKeyListener) + { + ::Application::RemoveKeyListener(m_aKeyListenerLink); + m_bKeyListener = false; + } + css::lang::EventObject aEvent( + static_cast< ::cppu::OWeakObject * >(this)); + m_aTopWindowListeners.disposeAndClear(aEvent); + m_aKeyHandlers.disposeAndClear(aEvent); + m_aFocusListeners.disposeAndClear(aEvent); +} + + +css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( ) +{ + css::uno::Reference< css::awt::XWindowPeer > xRef; + // 07/00: AppWindow doesn't exist anymore... + return xRef; +} + +css::awt::Rectangle VCLXToolkit::getWorkArea( ) +{ + sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen(); + tools::Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay ); + css::awt::Rectangle aNotherRect; + aNotherRect.X = aWorkRect.getX(); + aNotherRect.Y = aWorkRect.getY(); + aNotherRect.Width = aWorkRect.getWidth(); + aNotherRect.Height = aWorkRect.getHeight(); + return aNotherRect; +} + +css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createWindow( const css::awt::WindowDescriptor& rDescriptor ) +{ + return ImplCreateWindow( rDescriptor, MessBoxStyle::NONE ); +} + +css::uno::Reference< css::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::uno::Reference< css::awt::XDevice > xRef; + VCLXVirtualDevice* pVDev = new VCLXVirtualDevice; + + SolarMutexGuard aSolarGuard; + + VclPtrInstance pV; + pV->SetOutputSizePixel( Size( Width, Height ) ); + pVDev->SetVirtualDevice( pV ); + + xRef = pVDev; + return xRef; +} + +css::uno::Reference< css::awt::XRegion > VCLXToolkit::createRegion( ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + css::uno::Reference< css::awt::XRegion > xRef = new VCLXRegion; + return xRef; +} + +class InfoBox : public MessBox +{ +public: + InfoBox(vcl::Window* pParent, const OUString& rMessage) + : MessBox(pParent, MessBoxStyle::Ok | MessBoxStyle::DefaultOk, 0, OUString(), rMessage) + { + // Default Text is the display title from the application + if (GetText().isEmpty()) + SetText(GetStandardInfoBoxText()); + SetImage(GetStandardInfoBoxImage()); + } +}; + +class ErrorBox : public MessBox +{ +public: + ErrorBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage) + : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage) + { + // Default Text is the display title from the application + if (GetText().isEmpty()) + SetText(GetStandardErrorBoxText()); + SetImage(GetStandardErrorBoxImage()); + } +}; + +class QueryBox : public MessBox +{ +public: + QueryBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage) + : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage) + { + // Default Text is the display title from the application + if (GetText().isEmpty()) + SetText(GetStandardQueryBoxText()); + SetImage(GetStandardQueryBoxImage()); + } +}; + +class WarningBox : public MessBox +{ +public: + WarningBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage) + : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage) + { + // Default Text is the display title from the application + if (GetText().isEmpty()) + SetText(GetStandardWarningBoxText()); + SetImage(GetStandardWarningBoxImage()); + } +}; + + +struct RMItemData +{ + bool b_Enabled; + sal_Int32 n_ID; + OUString Label; +}; + +typedef ::cppu::ImplInheritanceHelper < VCLXGraphicControl + , css::container::XContainerListener + , css::beans::XPropertyChangeListener + , css::awt::XItemEventBroadcaster + > SVTXRoadmap_Base; +class SVTXRoadmap final : public SVTXRoadmap_Base +{ +public: + SVTXRoadmap(); + + void SAL_CALL disposing( const css::lang::EventObject& Source ) override { VCLXWindow::disposing( Source ); } + + // css::awt::XVclWindowPeer + void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override; + + css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override; + + // XContainerListener + void SAL_CALL elementInserted( const css::container::ContainerEvent& rEvent ) override; + void SAL_CALL elementRemoved( const css::container::ContainerEvent& rEvent ) override; + void SAL_CALL elementReplaced( const css::container::ContainerEvent& rEvent ) override; + + // XItemEventBroadcaster + virtual void SAL_CALL addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override; + virtual void SAL_CALL removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override; + + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override; + +private: + + // VCLXGraphicControl overridables + virtual void ImplSetNewImage() override; + + static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds ); + virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); } + + static RMItemData GetRMItemData( const css::container::ContainerEvent& _rEvent ); + + virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override; + + virtual ~SVTXRoadmap() override; + + ItemListenerMultiplexer maItemListeners; +}; + + + + +SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this ) +{ +} + +SVTXRoadmap::~SVTXRoadmap() +{ +} + +void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VclEventId::RoadmapItemSelected: + { + SolarMutexGuard aGuard; + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID(); + css::awt::ItemEvent aEvent; + aEvent.Selected = CurItemID; + aEvent.Highlighted = CurItemID; + aEvent.ItemId = CurItemID; + maItemListeners.itemStateChanged( aEvent ); + } + } + break; + default: + SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +void SVTXRoadmap::propertyChange( const css::beans::PropertyChangeEvent& evt ) +{ + SolarMutexGuard aGuard; + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( !pField ) + return; + + css::uno::Reference< css::uno::XInterface > xRoadmapItem = evt.Source; + sal_Int32 nID = 0; + css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY ); + css::uno::Any aValue = xPropertySet->getPropertyValue("ID"); + aValue >>= nID; + + OUString sPropertyName = evt.PropertyName; + if ( sPropertyName == "Enabled" ) + { + bool bEnable = false; + evt.NewValue >>= bEnable; + pField->EnableRoadmapItem( static_cast(nID) , bEnable ); + } + else if ( sPropertyName == "Label" ) + { + OUString sLabel; + evt.NewValue >>= sLabel; + pField->ChangeRoadmapItemLabel( static_cast(nID) , sLabel ); + } + else if ( sPropertyName == "ID" ) + { + sal_Int32 nNewID = 0; + evt.NewValue >>= nNewID; + evt.OldValue >>= nID; + pField->ChangeRoadmapItemID( static_cast(nID), static_cast(nNewID) ); + } +// else + // TODO handle Interactive appropriately +} + +void SVTXRoadmap::addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) +{ + maItemListeners.addInterface( l ); +} + +void SVTXRoadmap::removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) +{ + maItemListeners.removeInterface( l ); +} + +RMItemData SVTXRoadmap::GetRMItemData( const css::container::ContainerEvent& _rEvent ) +{ + RMItemData aCurRMItemData; + css::uno::Reference< css::uno::XInterface > xRoadmapItem; + _rEvent.Element >>= xRoadmapItem; + css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY ); + if ( xPropertySet.is() ) + { + css::uno::Any aValue = xPropertySet->getPropertyValue("Label"); + aValue >>= aCurRMItemData.Label; + aValue = xPropertySet->getPropertyValue("ID"); + aValue >>= aCurRMItemData.n_ID; + aValue = xPropertySet->getPropertyValue("Enabled"); + aValue >>= aCurRMItemData.b_Enabled; + } + else + { + aCurRMItemData.b_Enabled = false; + aCurRMItemData.n_ID = 0; + } + return aCurRMItemData; +} + +void SVTXRoadmap::elementInserted( const css::container::ContainerEvent& _rEvent ) +{ + SolarMutexGuard aGuard; + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + RMItemData CurItemData = GetRMItemData( _rEvent ); + sal_Int32 InsertIndex = 0; + _rEvent.Accessor >>= InsertIndex; + pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, static_cast(CurItemData.n_ID), CurItemData.b_Enabled ); + } +} + +void SVTXRoadmap::elementRemoved( const css::container::ContainerEvent& _rEvent ) +{ + SolarMutexGuard aGuard; + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + sal_Int32 DelIndex = 0; + _rEvent.Accessor >>= DelIndex; + pField->DeleteRoadmapItem(DelIndex); + } +} + +void SVTXRoadmap::elementReplaced( const css::container::ContainerEvent& _rEvent ) +{ + SolarMutexGuard aGuard; + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + RMItemData CurItemData = GetRMItemData( _rEvent ); + sal_Int32 ReplaceIndex = 0; + _rEvent.Accessor >>= ReplaceIndex; + pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, static_cast(CurItemData.n_ID), CurItemData.b_Enabled ); + } +} + +void SVTXRoadmap::setProperty( const OUString& PropertyName, const css::uno::Any& Value) +{ + SolarMutexGuard aGuard; + + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch (nPropType) + { + case BASEPROPERTY_COMPLETE: + { + bool b = false; + Value >>= b; + pField->SetRoadmapComplete( b); + } + break; + + case BASEPROPERTY_ACTIVATED: + { + bool b = false; + Value >>= b; + pField->SetRoadmapInteractive( b); + } + break; + + case BASEPROPERTY_CURRENTITEMID: + { + sal_Int32 nId = 0; + Value >>= nId; + pField->SelectRoadmapItemByID( static_cast(nId) ); + } + break; + + case BASEPROPERTY_TEXT: + { + OUString aStr; + Value >>= aStr; + pField->SetText( aStr ); + pField->Invalidate(); + } + break; + + default: + SVTXRoadmap_Base::setProperty( PropertyName, Value ); + break; + } + + } + else + SVTXRoadmap_Base::setProperty( PropertyName, Value ); +} + + +css::uno::Any SVTXRoadmap::getProperty( const OUString& PropertyName ) +{ + SolarMutexGuard aGuard; + + css::uno::Any aReturn; + + VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >(); + if ( pField ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch (nPropType) + { + case BASEPROPERTY_COMPLETE: + aReturn <<= pField->IsRoadmapComplete(); + break; + case BASEPROPERTY_ACTIVATED: + aReturn <<= pField->IsRoadmapInteractive(); + break; + case BASEPROPERTY_CURRENTITEMID: + aReturn <<= pField->GetCurrentRoadmapItemID(); + break; + default: + aReturn = SVTXRoadmap_Base::getProperty(PropertyName); + break; + } + } + return aReturn; +} + +void SVTXRoadmap::ImplSetNewImage() +{ + OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" ); + VclPtr< ::vcl::ORoadmap > pButton = GetAs< ::vcl::ORoadmap >(); + pButton->SetRoadmapBitmap( GetImage().GetBitmapEx() ); +} + +void SVTXRoadmap::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_COMPLETE, + BASEPROPERTY_ACTIVATED, + BASEPROPERTY_CURRENTITEMID, + BASEPROPERTY_TEXT, + 0); + VCLXWindow::ImplGetPropertyIds( rIds, true ); + VCLXGraphicControl::ImplGetPropertyIds( rIds ); +} + + + + +vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, + const css::awt::WindowDescriptor& rDescriptor, + vcl::Window* pParent, WinBits nWinBits, MessBoxStyle nMessBoxStyle ) +{ + OUString aServiceName = rDescriptor.WindowServiceName.toAsciiLowerCase(); + + VclPtr pNewWindow; + WindowType nType = ImplGetComponentType( aServiceName ); + bool bFrameControl = false; + if ( aServiceName == "frame" ) + bFrameControl = true; + if ( aServiceName == "tabcontrolnotabs" ) + { + nWinBits |= WB_NOBORDER; + nType = ImplGetComponentType( "tabcontrol" ); + } + if ( !pParent ) + { + // If the component needs a parent, then return NULL, + // some time later css::uno::Exception... + bool bException = true; + if ( ( nType == WindowType::DIALOG ) + || ( nType == WindowType::MODALDIALOG ) + || ( nType == WindowType::MODELESSDIALOG ) + || ( nType == WindowType::MESSBOX ) + || ( nType == WindowType::INFOBOX ) + || ( nType == WindowType::WARNINGBOX ) + || ( nType == WindowType::ERRORBOX ) + || ( nType == WindowType::QUERYBOX ) + ) + bException = false; + else if ( ( nType == WindowType::WINDOW ) || + ( nType == WindowType::WORKWINDOW ) || + ( nType == WindowType::TOOLKIT_FRAMEWINDOW ) ) + { + if ( rDescriptor.Type == css::awt::WindowClass_TOP ) + bException = false; + } + + if ( bException ) + { + *ppNewComp = nullptr; + return nullptr; + } + } + + if ( nType != WindowType::NONE ) + { + SolarMutexGuard aVclGuard; + switch ( nType ) + { + case WindowType::CANCELBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::CHECKBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXCheckBox; + break; + case WindowType::COMBOBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits|WB_AUTOHSCROLL ); + static_cast(pNewWindow.get())->EnableAutoSize( false ); + *ppNewComp = new VCLXComboBox; + break; + case WindowType::CURRENCYBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::CURRENCYFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); + *ppNewComp = new VCLXNumericField; + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); + break; + case WindowType::DATEBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::DATEFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); + *ppNewComp = new VCLXDateField; + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); + break; + case WindowType::DOCKINGAREA: + pNewWindow = VclPtr::Create( pParent ); + break; + case WindowType::MULTILINEEDIT: + case WindowType::EDIT: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXEdit; + break; + case WindowType::ERRORBOX: + pNewWindow = VclPtr::Create( pParent, nMessBoxStyle, nWinBits, OUString() ); + *ppNewComp = new VCLXMessageBox; + break; + case WindowType::FIXEDBITMAP: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::FIXEDIMAGE: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXImageControl; + break; + case WindowType::FIXEDLINE: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::FIXEDTEXT: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXFixedText; + break; + case WindowType::FLOATINGWINDOW: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::GROUPBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + if ( bFrameControl ) + { + GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() ); + *ppNewComp = new VCLXFrame; + // Frame control needs to receive + // Mouse events + pGroupBox->SetMouseTransparent( false ); + } + break; + case WindowType::HELPBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::IMAGEBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::INFOBOX: + pNewWindow = VclPtr::Create( pParent, OUString() ); + *ppNewComp = new VCLXMessageBox; + break; + case WindowType::LISTBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL ); + static_cast(pNewWindow.get())->EnableAutoSize( false ); + *ppNewComp = new VCLXListBox; + break; + case WindowType::LONGCURRENCYBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::MENUBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::MESSBOX: + pNewWindow = VclPtr::Create( pParent, nMessBoxStyle, nWinBits, OUString(), OUString() ); + *ppNewComp = new VCLXMessageBox; + break; + case WindowType::METRICBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::METRICFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXMetricField; + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); + break; + case WindowType::DIALOG: + case WindowType::MODALDIALOG: + case WindowType::MODELESSDIALOG: + { + // Modal/Modeless only via Show/Execute + if ( (pParent == nullptr ) && ( rDescriptor.ParentIndex == -1 ) ) + pNewWindow = VclPtr::Create( nullptr, nWinBits, Dialog::InitFlag::NoParent ); + else + pNewWindow = VclPtr::Create( pParent, nWinBits ); + // #i70217# Don't always create a new component object. It's possible that VCL has called + // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() ) + // which creates a component object. + css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false ); + if ( xWinPeer.is() ) + *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() ); + else + *ppNewComp = new VCLXDialog; + } + break; + case WindowType::MOREBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::MULTILISTBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXListBox; + break; + case WindowType::NUMERICBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::OKBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::PATTERNBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::PATTERNFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXPatternField; + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); + break; + case WindowType::PUSHBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WindowType::QUERYBOX: + pNewWindow = VclPtr::Create( pParent, nMessBoxStyle, nWinBits, OUString() ); + *ppNewComp = new VCLXMessageBox; + break; + case WindowType::RADIOBUTTON: + pNewWindow = VclPtr::Create(pParent, false, nWinBits); + *ppNewComp = new VCLXRadioButton; + + // by default, disable RadioCheck + // Since the VCLXRadioButton really cares for its RadioCheck settings, this is important: + // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState + // This leads to a strange behaviour if the control is newly created: when settings the initial + // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck + // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls + // is not really valid: the controls are grouped after they have been created, but we're still in + // the creation process, so the RadioButton::Check relies on invalid grouping information. + // 07.08.2001 - #87254# - frank.schoenheit@sun.com + static_cast(pNewWindow.get())->EnableRadioCheck( false ); + break; + case WindowType::SCROLLBAR: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXScrollBar; + break; + case WindowType::SCROLLBARBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::SPINBUTTON: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new ::toolkit::VCLXSpinButton; + break; + case WindowType::SPINFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXNumericField; + break; + case WindowType::SPLITTER: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::SPLITWINDOW: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::STATUSBAR: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::TOOLKIT_SYSTEMCHILDWINDOW: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXSystemDependentWindow(); + break; + case WindowType::TABCONTROL: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXMultiPage; + break; + case WindowType::TABDIALOG: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::TABPAGE: + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXTabPage; + } + break; + case WindowType::TIMEBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + break; + case WindowType::TIMEFIELD: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); + *ppNewComp = new VCLXTimeField; + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); + break; + case WindowType::TOOLBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXToolBox; + break; + case WindowType::TRISTATEBOX: + pNewWindow = VclPtr::Create( pParent, nWinBits ); + static_cast(pNewWindow.get())->EnableTriState(true); + break; + case WindowType::WARNINGBOX: + pNewWindow = VclPtr::Create( pParent, nMessBoxStyle, nWinBits, OUString() ); + *ppNewComp = new VCLXMessageBox; + break; + case WindowType::WORKWINDOW: + case WindowType::WINDOW: + case WindowType::TOOLKIT_FRAMEWINDOW: + case WindowType::DOCKINGWINDOW: + if ( rDescriptor.Type == css::awt::WindowClass_TOP ) + { + if (nType == WindowType::DOCKINGWINDOW ) + pNewWindow = VclPtr::Create( pParent, nWinBits ); + else + { + if ((pParent == nullptr) && rDescriptor.Parent.is()) + { + // try to get a system dependent window handle + css::uno::Reference< css::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, css::uno::UNO_QUERY); + + if (xSystemDepParent.is()) + { + sal_Int8 processID[16]; + + rtl_getGlobalProcessId( reinterpret_cast(processID) ); + + // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence + css::uno::Sequence processIdSeq(processID, 16); + + css::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE); + + // use sal_Int64 here to accommodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nWindowHandle = 0; + bool bXEmbed = false; + + bool bUseParentData = true; + if( ! (anyHandle >>= nWindowHandle) ) + { + css::uno::Sequence< css::beans::NamedValue > aProps; + if( anyHandle >>= aProps ) + { + for( const css::beans::NamedValue& rProp : std::as_const(aProps) ) + { + if ( rProp.Name == "WINDOW" ) + rProp.Value >>= nWindowHandle; + else if ( rProp.Name == "XEMBED" ) + rProp.Value >>= bXEmbed; + } + } + else + bUseParentData = false; + } + + if( bUseParentData ) + { + SystemParentData aParentData; + aParentData.nSize = sizeof( aParentData ); + #if defined MACOSX + aParentData.pView = reinterpret_cast(nWindowHandle); + #elif defined ANDROID + // Nothing + #elif defined IOS + // Nothing + #elif defined UNX + aParentData.aWindow = nWindowHandle; + aParentData.bXEmbedSupport = bXEmbed; + #elif defined _WIN32 + aParentData.hWnd = reinterpret_cast(nWindowHandle); + #endif + pNewWindow = VclPtr::Create( &aParentData ); + } + } + } + + if (!pNewWindow) + pNewWindow = VclPtr::Create( pParent, nWinBits ); + } + + *ppNewComp = new VCLXTopWindow(); + } + else if ( rDescriptor.Type == css::awt::WindowClass_CONTAINER ) + { + if (nType == WindowType::DOCKINGWINDOW ) + pNewWindow = VclPtr::Create( pParent, nWinBits ); + else + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXContainer; + } + else + { + if (nType == WindowType::DOCKINGWINDOW ) + pNewWindow = VclPtr::Create( pParent, nWinBits ); + else + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXWindow; + } + break; + case WindowType::CONTROL: + if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( + "tabpagecontainer" ) ) + { + // TabControl has a special case for tabs without border: they are displayed + // in a different way, so we need to ensure that this style is not set, so + // we can guarantee normal tab behavior + pNewWindow = VclPtr::Create( pParent, nWinBits & (~WB_NOBORDER)); + *ppNewComp = new VCLXTabPageContainer; + } + else if ( aServiceName == "animatedimages" ) + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new ::toolkit::AnimatedImagesPeer; + } + else if (aServiceName == "roadmap") + { + pNewWindow = VclPtr<::vcl::ORoadmap>::Create( pParent, WB_TABSTOP ); + *ppNewComp = new SVTXRoadmap; + } + else if (aServiceName == "fixedhyperlink") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXFixedHyperlink; + } + else if (aServiceName == "progressbar") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXProgressBar; + } + else if (aServiceName == "filecontrol") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new VCLXFileControl; + } + else if (aServiceName == "tree") + { + TreeControlPeer* pPeer = new TreeControlPeer; + *ppNewComp = pPeer; + pNewWindow = pPeer->createVclControl( pParent, nWinBits ); + } + else if (aServiceName == "formattedfield") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new SVTXFormattedField; + } + else if (aServiceName == "numericfield") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new SVTXNumericField; + } + else if (aServiceName == "longcurrencyfield") + { + pNewWindow = VclPtr::Create( pParent, nWinBits ); + *ppNewComp = new SVTXCurrencyField; + } + break; + default: + OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" ); + break; + } + } + + // tdf#126717 default that formcontrols show accelerators + if (Control* pControl = dynamic_cast(pNewWindow.get())) + pControl->SetShowAccelerator(true); + return pNewWindow; +} + +#ifndef DISABLE_DYNLOADING + +extern "C" { static void thisModule() {} } + +#else + +extern "C" vcl::Window* SAL_CALL CreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor* pDescriptor, vcl::Window* pParent, WinBits nWinBits ); + +#endif + +css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( + const css::awt::WindowDescriptor& rDescriptor, + MessBoxStyle nForceMessBoxStyle ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + SolarMutexGuard aSolarGuard; + + css::uno::Reference< css::awt::XWindowPeer > xRef; + + VclPtr pParent; + if ( rDescriptor.Parent.is() ) + { + VCLXWindow* pParentComponent = comphelper::getUnoTunnelImplementation( rDescriptor.Parent ); + + // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow. + // DBG_ASSERT( pParentComponent, "ParentComponent not valid" ); + + if ( pParentComponent ) + pParent = pParentComponent->GetWindow(); + } + std::pair aPair = ImplGetWinBits( rDescriptor.WindowAttributes, + ImplGetComponentType( rDescriptor.WindowServiceName ) ); + WinBits nWinBits = aPair.first; + aPair.second |= nForceMessBoxStyle; + + VCLXWindow* pNewComp = nullptr; + + vcl::Window* pNewWindow = nullptr; + // Try to create the window with SvTools + // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way, + // and we need to stay compatible) + // try to load the lib + if ( !fnSvtCreateWindow +#ifndef DISABLE_DYNLOADING + && !hSvToolsLib +#endif + ) + { +#ifndef DISABLE_DYNLOADING + OUString aLibName(SVT_DLL_NAME); + hSvToolsLib = osl_loadModuleRelative( + &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT ); + if ( hSvToolsLib ) + { + OUString aFunctionName( "CreateWindow" ); + fnSvtCreateWindow = reinterpret_cast(osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData )); + } +#else + fnSvtCreateWindow = CreateWindow; +#endif + } + // ask the SvTool creation function + if ( fnSvtCreateWindow ) + pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits ); + + // if SvTools could not provide a window, create it ourself + if ( !pNewWindow ) + pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits, aPair.second ); + + DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" ); + SAL_INFO_IF( !pNewComp, "toolkit", "createWindow: No special Interface!" ); + + if ( pNewWindow ) + { + pNewWindow->SetCreatedWithToolkit( true ); + //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead + + if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::MINSIZE ) + { + pNewWindow->SetSizePixel( Size() ); + } + else if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::FULLSIZE ) + { + if ( pParent ) + pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() ); + } + else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) ) + { + tools::Rectangle aRect = VCLRectangle( rDescriptor.Bounds ); + pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() ); + } + + if ( !pNewComp ) + { + // Default-Interface + xRef = pNewWindow->GetComponentInterface(); + } + else + { + xRef = pNewComp; + pNewWindow->SetComponentInterface( xRef ); + } + DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef, + "VCLXToolkit::createWindow: did #133706# resurge?" ); + + if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW ) + pNewWindow->Show(); + } + + return xRef; +} + +css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& rDescriptors ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nComponents = rDescriptors.getLength(); + css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > aSeq( nComponents ); + for ( sal_uInt32 n = 0; n < nComponents; n++ ) + { + css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n]; + + if ( aDescr.ParentIndex == -1 ) + aDescr.Parent = nullptr; + else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < static_cast(n) ) ) + aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex]; + aSeq.getArray()[n] = createWindow( aDescr ); + } + return aSeq; +} + +// css::awt::XSystemChildFactory +css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType ) +{ + VclPtr pChildWindow; + if ( nSystemType == SYSTEM_DEPENDENT_TYPE ) + { + // use sal_Int64 here to accommodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nWindowHandle = 0; + bool bXEmbed = false; + + bool bUseParentData = true; + if( ! (Parent >>= nWindowHandle) ) + { + css::uno::Sequence< css::beans::NamedValue > aProps; + if( Parent >>= aProps ) + { + for( const css::beans::NamedValue& rProp : std::as_const(aProps) ) + { + if ( rProp.Name == "WINDOW" ) + rProp.Value >>= nWindowHandle; + else if ( rProp.Name == "XEMBED" ) + rProp.Value >>= bXEmbed; + } + } + else + bUseParentData = false; + } + + if( bUseParentData ) + { + SystemParentData aParentData; + aParentData.nSize = sizeof( aParentData ); + #if defined MACOSX + aParentData.pView = reinterpret_cast(nWindowHandle); + #elif defined ANDROID + // Nothing + #elif defined IOS + // Nothing + #elif defined UNX + aParentData.aWindow = nWindowHandle; + aParentData.bXEmbedSupport = bXEmbed; + #elif defined _WIN32 + aParentData.hWnd = reinterpret_cast(nWindowHandle); + #endif + SolarMutexGuard aGuard; + try + { + pChildWindow.reset( VclPtr::Create( &aParentData ) ); + } + catch ( const css::uno::RuntimeException & ) + { + // system child window could not be created + DBG_UNHANDLED_EXCEPTION("toolkit"); + pChildWindow.clear(); + } + } + } + else if (nSystemType == css::lang::SystemDependent::SYSTEM_JAVA) + { + SolarMutexGuard aGuard; + pChildWindow.reset(VclPtr::Create(nullptr, Parent)); + } + + css::uno::Reference< css::awt::XWindowPeer > xPeer; + if ( pChildWindow ) + { + VCLXTopWindow* pPeer = new VCLXTopWindow; + SolarMutexGuard aGuard; + pPeer->SetWindow( pChildWindow ); + xPeer = pPeer; + } + + return xPeer; +} + +// css::awt::XMessageBoxFactory +css::uno::Reference< css::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox( + const css::uno::Reference< css::awt::XWindowPeer >& aParent, + css::awt::MessageBoxType eType, + ::sal_Int32 aButtons, + const OUString& aTitle, + const OUString& aMessage ) +{ + css::awt::WindowDescriptor aDescriptor; + + sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE; + + // Map button definitions to window attributes + if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL; + + // Map default button definitions to window attributes + if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY; + + // No more bits for VclWindowPeerAttribute possible. Mapping must be + // done explicitly using VCL methods + MessBoxStyle nAddWinBits = MessBoxStyle::NONE; + if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY ) + nAddWinBits |= MessBoxStyle::AbortRetryIgnore; + if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE ) + nAddWinBits |= MessBoxStyle::DefaultIgnore; + + OUString aType; + lcl_convertMessageBoxType( aType, eType ); + + aDescriptor.Type = css::awt::WindowClass_MODALTOP; + aDescriptor.WindowServiceName = aType; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = aParent; + aDescriptor.WindowAttributes = nWindowAttributes; + css::uno::Reference< css::awt::XMessageBox > xMsgBox( + ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY ); + css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY ); + if ( xMsgBox.is() && xWindow.is() ) + { + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if ( pWindow ) + { + SolarMutexGuard aGuard; + xMsgBox->setCaptionText( aTitle ); + xMsgBox->setMessageText( aMessage ); + } + } + + return xMsgBox; +} + +css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) +{ + SolarMutexGuard g; + + VclPtr pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDragGestureRecognizer(); + + return css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer >(); +} + +css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) +{ + SolarMutexGuard g; + + VclPtr pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDragSource(); + + return css::uno::Reference< css::datatransfer::dnd::XDragSource >(); +} + +css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) +{ + SolarMutexGuard g; + + VclPtr pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDropTarget(); + + return css::uno::Reference< css::datatransfer::dnd::XDropTarget >(); +} + +css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName ) +{ + if( clipboardName.isEmpty() ) + { + if( !mxClipboard.is() ) + { + // remember clipboard here + mxClipboard = css::datatransfer::clipboard::SystemClipboard::create( + comphelper::getProcessComponentContext()); + } + + return mxClipboard; + } + + else if( clipboardName == "Selection" ) + { + return mxSelection; + } + + return css::uno::Reference< css::datatransfer::clipboard::XClipboard >(); +} + +// XServiceInfo +OUString VCLXToolkit::getImplementationName() +{ + return "stardiv.Toolkit.VCLXToolkit"; +} + +sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +css::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames() +{ + return css::uno::Sequence{ + "com.sun.star.awt.Toolkit", "stardiv.vcl.VclToolkit"}; +} + +// css::awt::XExtendedToolkit: + +// virtual +::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount() +{ + return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount()); + // XXX numeric overflow +} + +// virtual +css::uno::Reference< css::awt::XTopWindow > SAL_CALL +VCLXToolkit::getTopWindow(::sal_Int32 nIndex) +{ + vcl::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex)); + // XXX numeric overflow + return css::uno::Reference< css::awt::XTopWindow >( + p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()), + css::uno::UNO_QUERY); +} + +// virtual +css::uno::Reference< css::awt::XTopWindow > SAL_CALL +VCLXToolkit::getActiveTopWindow() +{ + vcl::Window * p = ::Application::GetActiveTopWindow(); + return css::uno::Reference< css::awt::XTopWindow >( + p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()), + css::uno::UNO_QUERY); +} + +// virtual +void SAL_CALL VCLXToolkit::addTopWindowListener( + css::uno::Reference< css::awt::XTopWindowListener > const & rListener) +{ + OSL_ENSURE(rListener.is(), "Null rListener"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rListener->disposing( + css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aTopWindowListeners.addInterface(rListener) == 1 + && !m_bEventListener) + { + m_bEventListener = true; + ::Application::AddEventListener(m_aEventListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeTopWindowListener( + css::uno::Reference< css::awt::XTopWindowListener > const & rListener) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aTopWindowListeners.removeInterface(rListener) == 0 + && m_aFocusListeners.getLength() == 0 && m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::addKeyHandler( + css::uno::Reference< css::awt::XKeyHandler > const & rHandler) +{ + OSL_ENSURE(rHandler.is(), "Null rHandler"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rHandler->disposing( + css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener) + { + m_bKeyListener = true; + ::Application::AddKeyListener(m_aKeyListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeKeyHandler( + css::uno::Reference< css::awt::XKeyHandler > const & rHandler) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener) + { + ::Application::RemoveKeyListener(m_aKeyListenerLink); + m_bKeyListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::addFocusListener( + css::uno::Reference< css::awt::XFocusListener > const & rListener) +{ + OSL_ENSURE(rListener.is(), "Null rListener"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rListener->disposing( + css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aFocusListeners.addInterface(rListener) == 1 + && !m_bEventListener) + { + m_bEventListener = true; + ::Application::AddEventListener(m_aEventListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeFocusListener( + css::uno::Reference< css::awt::XFocusListener > const & rListener) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aFocusListeners.removeInterface(rListener) == 0 + && m_aTopWindowListeners.getLength() == 0 && m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::fireFocusGained( + css::uno::Reference< + css::uno::XInterface > const &) +{ +} + +// virtual +void SAL_CALL VCLXToolkit::fireFocusLost( + css::uno::Reference< + css::uno::XInterface > const &) +{ +} + + +IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent&, rEvent, void) +{ + switch (rEvent.GetId()) + { + case VclEventId::WindowShow: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowOpened); + break; + case VclEventId::WindowHide: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowClosed); + break; + case VclEventId::WindowActivate: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowActivated); + break; + case VclEventId::WindowDeactivate: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowDeactivated); + break; + case VclEventId::WindowClose: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowClosing); + break; + case VclEventId::WindowGetFocus: + callFocusListeners(&rEvent, true); + break; + case VclEventId::WindowLoseFocus: + callFocusListeners(&rEvent, false); + break; + case VclEventId::WindowMinimize: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowMinimized); + break; + case VclEventId::WindowNormalize: + callTopWindowListeners( + &rEvent, &css::awt::XTopWindowListener::windowNormalized); + break; + default: break; + } +} + +IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclWindowEvent&, rEvent, bool) +{ + switch (rEvent.GetId()) + { + case VclEventId::WindowKeyInput: + return callKeyHandlers(&rEvent, true); + case VclEventId::WindowKeyUp: + return callKeyHandlers(&rEvent, false); + default: break; + } + return false; +} + +void VCLXToolkit::callTopWindowListeners( + ::VclSimpleEvent const * pEvent, + void (SAL_CALL css::awt::XTopWindowListener::* pFn)( + css::lang::EventObject const &)) +{ + vcl::Window * pWindow + = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + if (pWindow->IsTopWindow()) + { + std::vector< css::uno::Reference< css::uno::XInterface > > + aListeners(m_aTopWindowListeners.getElements()); + if (!aListeners.empty()) + { + css::lang::EventObject aAwtEvent( + static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer())); + for (const css::uno::Reference & i : aListeners) + { + css::uno::Reference< css::awt::XTopWindowListener > + xListener(i, css::uno::UNO_QUERY); + try + { + (xListener.get()->*pFn)(aAwtEvent); + } + catch (const css::uno::RuntimeException &) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + } + } +} + +bool VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent, + bool bPressed) +{ + std::vector< css::uno::Reference< css::uno::XInterface > > + aHandlers(m_aKeyHandlers.getElements()); + + if (!aHandlers.empty()) + { + vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + + // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event + ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >( + static_cast< ::VclWindowEvent const * >(pEvent)->GetData()); + css::awt::KeyEvent aAwtEvent( + static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()), + (pKeyEvent->GetKeyCode().IsShift() + ? css::awt::KeyModifier::SHIFT : 0) + | (pKeyEvent->GetKeyCode().IsMod1() + ? css::awt::KeyModifier::MOD1 : 0) + | (pKeyEvent->GetKeyCode().IsMod2() + ? css::awt::KeyModifier::MOD2 : 0) + | (pKeyEvent->GetKeyCode().IsMod3() + ? css::awt::KeyModifier::MOD3 : 0), + pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(), + sal::static_int_cast< sal_Int16 >( + pKeyEvent->GetKeyCode().GetFunction())); + for (const css::uno::Reference & i : aHandlers) + { + css::uno::Reference< css::awt::XKeyHandler > xHandler( + i, css::uno::UNO_QUERY); + try + { + if (bPressed ? xHandler->keyPressed(aAwtEvent) + : xHandler->keyReleased(aAwtEvent)) + return true; + } + catch (const css::uno::RuntimeException &) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + } + return false; +} + +void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent, + bool bGained) +{ + vcl::Window * pWindow + = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + if (pWindow->IsTopWindow()) + { + std::vector< css::uno::Reference< css::uno::XInterface > > + aListeners(m_aFocusListeners.getElements()); + if (!aListeners.empty()) + { + // Ignore the interior of compound controls when determining the + // window that gets the focus next (see implementation in + // vclxwindow.cxx for mapping between VCL and UNO AWT event): + css::uno::Reference< css::uno::XInterface > xNext; + vcl::Window * pFocus = ::Application::GetFocusWindow(); + for (vcl::Window * p = pFocus; p != nullptr; p = p->GetParent()) + if (!p->IsCompoundControl()) + { + pFocus = p; + break; + } + if (pFocus != nullptr) + xNext = pFocus->GetComponentInterface(); + css::awt::FocusEvent aAwtEvent( + static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()), + static_cast(pWindow->GetGetFocusFlags()), + xNext, false); + for (const css::uno::Reference & i : aListeners) + { + css::uno::Reference< css::awt::XFocusListener > xListener( + i, css::uno::UNO_QUERY); + try + { + bGained ? xListener->focusGained(aAwtEvent) + : xListener->focusLost(aAwtEvent); + } + catch (const css::uno::RuntimeException &) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + } + } +} + +// css::awt::XReschedule: + +void SAL_CALL VCLXToolkit::reschedule() +{ + SolarMutexGuard aSolarGuard; + Application::Reschedule(true); +} + +// css::awt::XToolkitExperimental + +void SAL_CALL VCLXToolkit::processEventsToIdle() +{ + SolarMutexGuard aSolarGuard; + comphelper::ProfileZone aZone("processEvents"); + Scheduler::ProcessEventsToIdle(); +} + +sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter() +{ +#if HAVE_FEATURE_OPENGL + return OpenGLWrapper::getBufferSwapCounter(); +#else + return 0; +#endif +} + +void SAL_CALL VCLXToolkit::setDeterministicScheduling(sal_Bool bDeterministicMode) +{ + SolarMutexGuard aSolarGuard; + Scheduler::SetDeterministicMode(bDeterministicMode); +} + +void SAL_CALL VCLXToolkit::pause(sal_Int32 nMilliseconds) +{ + new Pause(nMilliseconds); +} + +void SAL_CALL VCLXToolkit::startRecording() +{ + ::comphelper::ProfileRecording::startRecording(true); +} + +void SAL_CALL VCLXToolkit::stopRecording() +{ + ::comphelper::ProfileRecording::startRecording( false ); +} + +css::uno::Sequence< OUString > VCLXToolkit::getRecordingAndClear() +{ + return ::comphelper::ProfileRecording::getRecordingAndClear(); +} + +// css:awt:XToolkitRobot + +void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent ) +{ + css::uno::Reference xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW ); + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent ); + ::Application::PostKeyEvent( VclEventId::WindowKeyInput, pWindow, &aVCLKeyEvent ); +} + +void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent ) +{ + css::uno::Reference xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW ); + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent ); + ::Application::PostKeyEvent( VclEventId::WindowKeyUp, pWindow, &aVCLKeyEvent ); +} + + +void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent ) +{ + css::uno::Reference xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW ); + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, pWindow, &aVCLMouseEvent ); +} + +void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent ) +{ + css::uno::Reference xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW ); + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, pWindow, &aVCLMouseEvent ); +} + +void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent ) +{ + css::uno::Reference xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW ); + VclPtr pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VclEventId::WindowMouseMove, pWindow, &aVCLMouseEvent ); +} + + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +stardiv_Toolkit_VCLXToolkit_get_implementation( + css::uno::XComponentContext *, + css::uno::Sequence const &) +{ + return cppu::acquire(new VCLXToolkit()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxtopwindow.cxx b/toolkit/source/awt/vclxtopwindow.cxx new file mode 100644 index 000000000..e9fcd2450 --- /dev/null +++ b/toolkit/source/awt/vclxtopwindow.cxx @@ -0,0 +1,251 @@ +/* -*- 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 + +#if defined ( MACOSX ) +#include +#include +#include +#endif + +#include +#include + +#include +#include + +#include +#include +#include +#include + +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Type; +using ::com::sun::star::uno::Any; +using ::com::sun::star::lang::IndexOutOfBoundsException; + + +css::uno::Any VCLXTopWindow::getWindowHandle( const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) +{ + SolarMutexGuard aGuard; + + // TODO, check the process id + css::uno::Any aRet; + vcl::Window* pWindow = VCLXContainer::GetWindow().get(); + if ( pWindow ) + { + const SystemEnvData* pSysData = static_cast(pWindow)->GetSystemData(); + if( pSysData ) + { +#if defined (_WIN32) + if( SystemType == css::lang::SystemDependent::SYSTEM_WIN32 ) + { + aRet <<= reinterpret_cast(pSysData->hWnd); + } +#elif defined(MACOSX) + if( SystemType == css::lang::SystemDependent::SYSTEM_MAC ) + { + aRet <<= reinterpret_cast(pSysData->mpNSView); + } +#elif defined(ANDROID) + // Nothing + (void) SystemType; +#elif defined(IOS) + // Nothing + (void) SystemType; +#elif defined(UNX) + if( SystemType == css::lang::SystemDependent::SYSTEM_XWINDOW ) + { + css::awt::SystemDependentXWindow aSD; + aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay)); + aSD.WindowHandle = pSysData->aWindow; + aRet <<= aSD; + } +#endif + } + } + return aRet; +} + +void VCLXTopWindow::addTopWindowListener( const css::uno::Reference< css::awt::XTopWindowListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + GetTopWindowListeners().addInterface( rxListener ); +} + +void VCLXTopWindow::removeTopWindowListener( const css::uno::Reference< css::awt::XTopWindowListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + GetTopWindowListeners().removeInterface( rxListener ); +} + +void VCLXTopWindow::toFront( ) +{ + SolarMutexGuard aGuard; + + vcl::Window* pWindow = VCLXContainer::GetWindow().get(); + if ( pWindow ) + static_cast(pWindow)->ToTop( ToTopFlags::RestoreWhenMin ); +} + +void VCLXTopWindow::toBack( ) +{ +} + +void VCLXTopWindow::setMenuBar( const css::uno::Reference< css::awt::XMenuBar >& rxMenu ) +{ + SolarMutexGuard aGuard; + + vcl::Window* pWindow = VCLXContainer::GetWindow().get(); + if ( pWindow ) + { + SystemWindow* pSystemWindow = static_cast( pWindow ); + pSystemWindow->SetMenuBar( nullptr ); + if ( rxMenu.is() ) + { + VCLXMenu* pMenu = comphelper::getUnoTunnelImplementation( rxMenu ); + if ( pMenu && !pMenu->IsPopupMenu() ) + pSystemWindow->SetMenuBar( static_cast( pMenu->GetMenu() )); + } + } +} + + +sal_Bool SAL_CALL VCLXTopWindow::getIsMaximized() +{ + SolarMutexGuard aGuard; + + const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return false; + + return pWindow->IsMaximized(); +} + + +void SAL_CALL VCLXTopWindow::setIsMaximized( sal_Bool _ismaximized ) +{ + SolarMutexGuard aGuard; + + WorkWindow* pWindow = dynamic_cast< WorkWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return; + + pWindow->Maximize( _ismaximized ); +} + + +sal_Bool SAL_CALL VCLXTopWindow::getIsMinimized() +{ + SolarMutexGuard aGuard; + + const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return false; + + return pWindow->IsMinimized(); +} + + +void SAL_CALL VCLXTopWindow::setIsMinimized( sal_Bool _isMinimized ) +{ + SolarMutexGuard aGuard; + + WorkWindow* pWindow = dynamic_cast< WorkWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return; + + _isMinimized ? pWindow->Minimize() : pWindow->Restore(); +} + + +::sal_Int32 SAL_CALL VCLXTopWindow::getDisplay() +{ + SolarMutexGuard aGuard; + + const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return 0; + + return pWindow->GetScreenNumber(); +} + + +void SAL_CALL VCLXTopWindow::setDisplay( ::sal_Int32 _display ) +{ + SolarMutexGuard aGuard; + + if ( ( _display < 0 ) || ( _display >= static_cast(Application::GetScreenCount()) ) ) + throw IndexOutOfBoundsException(); + + SystemWindow* pWindow = dynamic_cast< SystemWindow* >( VCLXContainer::GetWindow().get() ); + if ( !pWindow ) + return; + + pWindow->SetScreenNumber( _display ); +} + + + + +void VCLXTopWindow::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) +{ + VCLXContainer::ImplGetPropertyIds( rIds ); +} + +VCLXTopWindow::VCLXTopWindow() +{ +} + +VCLXTopWindow::~VCLXTopWindow() +{ +} + +// css::uno::XInterface +css::uno::Any VCLXTopWindow::queryInterface( const css::uno::Type & rType ) +{ + css::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) ); + + if (!aRet.hasValue()) + aRet = VCLXTopWindow_XBase::queryInterface( rType ); + if ( !aRet.hasValue() ) + aRet = VCLXContainer::queryInterface( rType ); + + return aRet; +} + +css::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() +{ + return css::uno::Sequence(); +} + +css::uno::Sequence< css::uno::Type > VCLXTopWindow::getTypes() +{ + return ::comphelper::concatSequences( VCLXTopWindow_XBase::getTypes(), VCLXContainer::getTypes() ); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx new file mode 100644 index 000000000..dbeeb20f0 --- /dev/null +++ b/toolkit/source/awt/vclxwindow.cxx @@ -0,0 +1,2525 @@ +/* -*- 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 "stylesettings.hxx" +#include + +#include +#include + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::lang::EventObject; +using ::com::sun::star::awt::XWindowListener2; +using ::com::sun::star::awt::XDockableWindowListener; +using ::com::sun::star::awt::XDevice; +using ::com::sun::star::awt::XStyleSettings; +using ::com::sun::star::lang::DisposedException; +using ::com::sun::star::style::VerticalAlignment; +using ::com::sun::star::style::VerticalAlignment_TOP; +using ::com::sun::star::style::VerticalAlignment_MIDDLE; +using ::com::sun::star::style::VerticalAlignment_BOTTOM; + +namespace WritingMode2 = ::com::sun::star::text::WritingMode2; + + +//= VCLXWindowImpl + +class VCLXWindowImpl +{ +private: + typedef ::std::vector< VCLXWindow::Callback > CallbackArray; + +private: + VCLXWindow& mrAntiImpl; + ::toolkit::AccessibilityClient maAccFactory; + bool mbDisposed; + bool mbDrawingOntoParent; // no bit mask, is passed around by reference + bool mbEnableVisible; + bool mbDirectVisible; + + ::osl::Mutex maListenerContainerMutex; + ::comphelper::OInterfaceContainerHelper2 maWindow2Listeners; + ::comphelper::OInterfaceContainerHelper2 maDockableWindowListeners; + EventListenerMultiplexer maEventListeners; + FocusListenerMultiplexer maFocusListeners; + WindowListenerMultiplexer maWindowListeners; + KeyListenerMultiplexer maKeyListeners; + MouseListenerMultiplexer maMouseListeners; + MouseMotionListenerMultiplexer maMouseMotionListeners; + PaintListenerMultiplexer maPaintListeners; + VclContainerListenerMultiplexer maContainerListeners; + TopWindowListenerMultiplexer maTopWindowListeners; + + CallbackArray maCallbackEvents; + ImplSVEvent * mnCallbackEventId; + +public: + bool mbDisposing : 1; + bool mbDesignMode : 1; + bool mbSynthesizingVCLEvent : 1; + bool mbWithDefaultProps : 1; + + sal_uLong mnListenerLockLevel; + sal_Int16 mnWritingMode; + sal_Int16 mnContextWritingMode; + + std::unique_ptr + mpPropHelper; + + css::uno::Reference< css::accessibility::XAccessibleContext > + mxAccessibleContext; + css::uno::Reference< css::awt::XGraphics > + mxViewGraphics; + css::uno::Reference< css::awt::XStyleSettings > + mxWindowStyleSettings; + +public: + bool& getDrawingOntoParent_ref() { return mbDrawingOntoParent; } + +public: + /** ctor + @param _pAntiImpl + the VCLXWindow instance which the object belongs to. Must + live longer then the object just being constructed. + */ + VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps ); + + VCLXWindowImpl( const VCLXWindowImpl& ) = delete; + const VCLXWindowImpl& operator=(const VCLXWindowImpl&) = delete; + + /** synchronously mbEnableVisible + */ + void setEnableVisible( bool bEnableVisible ) { mbEnableVisible = bEnableVisible; } + bool isEnableVisible() const { return mbEnableVisible; } + /** synchronously mbDirectVisible; + */ + void setDirectVisible( bool bDirectVisible ) { mbDirectVisible = bDirectVisible; } + bool isDirectVisible() const { return mbDirectVisible; } + + /** impl-version of VCLXWindow::ImplExecuteAsyncWithoutSolarLock + */ + void callBackAsync( const VCLXWindow::Callback& i_callback ); + + /** notifies the object that its VCLXWindow is being disposed + */ + void disposing(); + + ::toolkit::AccessibilityClient& getAccessibleFactory() + { + return maAccFactory; + } + + Reference< XStyleSettings > getStyleSettings(); + + /** returns the container of registered XWindowListener2 listeners + */ + ::comphelper::OInterfaceContainerHelper2& getWindow2Listeners() { return maWindow2Listeners; } + ::comphelper::OInterfaceContainerHelper2& getDockableWindowListeners(){ return maDockableWindowListeners; } + EventListenerMultiplexer& getEventListeners() { return maEventListeners; } + FocusListenerMultiplexer& getFocusListeners() { return maFocusListeners; } + WindowListenerMultiplexer& getWindowListeners() { return maWindowListeners; } + KeyListenerMultiplexer& getKeyListeners() { return maKeyListeners; } + MouseListenerMultiplexer& getMouseListeners() { return maMouseListeners; } + MouseMotionListenerMultiplexer& getMouseMotionListeners() { return maMouseMotionListeners; } + PaintListenerMultiplexer& getPaintListeners() { return maPaintListeners; } + VclContainerListenerMultiplexer& getContainerListeners() { return maContainerListeners; } + TopWindowListenerMultiplexer& getTopWindowListeners() { return maTopWindowListeners; } + +private: + DECL_LINK( OnProcessCallbacks, void*, void ); +}; + + +VCLXWindowImpl::VCLXWindowImpl( VCLXWindow& _rAntiImpl, bool _bWithDefaultProps ) + :mrAntiImpl( _rAntiImpl ) + ,mbDisposed( false ) + ,mbDrawingOntoParent( false ) + ,mbEnableVisible(true) + ,mbDirectVisible(true) + ,maListenerContainerMutex( ) + ,maWindow2Listeners( maListenerContainerMutex ) + ,maDockableWindowListeners( maListenerContainerMutex ) + ,maEventListeners( _rAntiImpl ) + ,maFocusListeners( _rAntiImpl ) + ,maWindowListeners( _rAntiImpl ) + ,maKeyListeners( _rAntiImpl ) + ,maMouseListeners( _rAntiImpl ) + ,maMouseMotionListeners( _rAntiImpl ) + ,maPaintListeners( _rAntiImpl ) + ,maContainerListeners( _rAntiImpl ) + ,maTopWindowListeners( _rAntiImpl ) + ,mnCallbackEventId( nullptr ) + ,mbDisposing( false ) + ,mbDesignMode( false ) + ,mbSynthesizingVCLEvent( false ) + ,mbWithDefaultProps( _bWithDefaultProps ) + ,mnListenerLockLevel( 0 ) + ,mnWritingMode( WritingMode2::CONTEXT ) + ,mnContextWritingMode( WritingMode2::CONTEXT ) +{ +} + +void VCLXWindowImpl::disposing() +{ + SolarMutexGuard aGuard; + if ( mnCallbackEventId ) + Application::RemoveUserEvent( mnCallbackEventId ); + mnCallbackEventId = nullptr; + + mbDisposed= true; + + css::lang::EventObject aEvent; + aEvent.Source = mrAntiImpl; + + maDockableWindowListeners.disposeAndClear( aEvent ); + maEventListeners.disposeAndClear( aEvent ); + maFocusListeners.disposeAndClear( aEvent ); + maWindowListeners.disposeAndClear( aEvent ); + maKeyListeners.disposeAndClear( aEvent ); + maMouseListeners.disposeAndClear( aEvent ); + maMouseMotionListeners.disposeAndClear( aEvent ); + maPaintListeners.disposeAndClear( aEvent ); + maContainerListeners.disposeAndClear( aEvent ); + maTopWindowListeners.disposeAndClear( aEvent ); + + ::toolkit::WindowStyleSettings* pStyleSettings = static_cast< ::toolkit::WindowStyleSettings* >( mxWindowStyleSettings.get() ); + if ( pStyleSettings != nullptr ) + pStyleSettings->dispose(); + mxWindowStyleSettings.clear(); +} + + +void VCLXWindowImpl::callBackAsync( const VCLXWindow::Callback& i_callback ) +{ + DBG_TESTSOLARMUTEX(); + maCallbackEvents.push_back( i_callback ); + if ( !mnCallbackEventId ) + { + // ensure our VCLXWindow is not destroyed while the event is underway + mrAntiImpl.acquire(); + mnCallbackEventId = Application::PostUserEvent( LINK( this, VCLXWindowImpl, OnProcessCallbacks ) ); + } +} + + +IMPL_LINK_NOARG(VCLXWindowImpl, OnProcessCallbacks, void*, void) +{ + const Reference< uno::XInterface > xKeepAlive( mrAntiImpl ); + + SAL_INFO("toolkit.controls", "OnProcessCallbacks grabbing solarmutex"); + + // work on a copy of the callback array + CallbackArray aCallbacksCopy; + { + SolarMutexGuard aGuard; + aCallbacksCopy.swap(maCallbackEvents); + + // we acquired our VCLXWindow once before posting the event, release this one ref now + mrAntiImpl.release(); + + if ( !mnCallbackEventId ) + // we were disposed while waiting for the mutex to lock + return; + + mnCallbackEventId = nullptr; + } + + { + SAL_INFO("toolkit.controls", "OnProcessCallbacks relinquished solarmutex"); + SolarMutexReleaser aReleaseSolar; + for (const auto& rCallback : aCallbacksCopy) + { + rCallback(); + } + } +} + +Reference< XStyleSettings > VCLXWindowImpl::getStyleSettings() +{ + SolarMutexGuard aGuard; + if ( mbDisposed ) + throw DisposedException( OUString(), mrAntiImpl ); + if ( !mxWindowStyleSettings.is() ) + mxWindowStyleSettings = new ::toolkit::WindowStyleSettings( maListenerContainerMutex, mrAntiImpl ); + return mxWindowStyleSettings; +} + + +// Uses an out-parameter instead of return value, due to the object reference + +static void ImplInitWindowEvent( css::awt::WindowEvent& rEvent, vcl::Window const * pWindow ) +{ + Point aPos = pWindow->GetPosPixel(); + Size aSz = pWindow->GetSizePixel(); + + rEvent.X = aPos.X(); + rEvent.Y = aPos.Y(); + + rEvent.Width = aSz.Width(); + rEvent.Height = aSz.Height(); + + pWindow->GetBorder( rEvent.LeftInset, rEvent.TopInset, rEvent.RightInset, rEvent.BottomInset ); +} + +VCLXWindow::VCLXWindow( bool _bWithDefaultProps ) +{ + mpImpl.reset( new VCLXWindowImpl( *this, _bWithDefaultProps ) ); +} + +VCLXWindow::~VCLXWindow() +{ + mpImpl.reset(); + + if ( GetWindow() ) + { + GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); + GetWindow()->SetWindowPeer( nullptr, nullptr ); + GetWindow()->SetAccessible( nullptr ); + } +} + + +void VCLXWindow::ImplExecuteAsyncWithoutSolarLock( const Callback& i_callback ) +{ + mpImpl->callBackAsync( i_callback ); +} + + +::toolkit::IAccessibleFactory& VCLXWindow::getAccessibleFactory() +{ + return mpImpl->getAccessibleFactory().getFactory(); +} + +void VCLXWindow::SetWindow( const VclPtr &pWindow ) +{ + if ( GetWindow() ) + { + GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); +// GetWindow()->DbgAssertNoEventListeners(); + } + + SetOutputDevice( pWindow ); + + if ( GetWindow() ) + { + GetWindow()->AddEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); + bool bDirectVisible = pWindow && pWindow->IsVisible(); + mpImpl->setDirectVisible( bDirectVisible ); + } +} + +void VCLXWindow::suspendVclEventListening( ) +{ + ++mpImpl->mnListenerLockLevel; +} + +void VCLXWindow::resumeVclEventListening( ) +{ + DBG_ASSERT( mpImpl->mnListenerLockLevel, "VCLXWindow::resumeVclEventListening: not suspended!" ); + --mpImpl->mnListenerLockLevel; +} + +void VCLXWindow::notifyWindowRemoved( vcl::Window const & _rWindow ) +{ + if ( mpImpl->getContainerListeners().getLength() ) + { + awt::VclContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Child = static_cast< XWindow* >( _rWindow.GetWindowPeer() ); + mpImpl->getContainerListeners().windowRemoved( aEvent ); + } +} + +IMPL_LINK( VCLXWindow, WindowEventListener, VclWindowEvent&, rEvent, void ) +{ + if ( mpImpl->mnListenerLockLevel ) + return; + + DBG_ASSERT( rEvent.GetWindow() && GetWindow(), "Window???" ); + ProcessWindowEvent( rEvent ); +} + +namespace +{ + struct CallWindow2Listener + { + CallWindow2Listener( ::comphelper::OInterfaceContainerHelper2& i_rWindow2Listeners, const bool i_bEnabled, const EventObject& i_rEvent ) + :m_rWindow2Listeners( i_rWindow2Listeners ) + ,m_bEnabled( i_bEnabled ) + ,m_aEvent( i_rEvent ) + { + } + + void operator()() + { + m_rWindow2Listeners.notifyEach( m_bEnabled ? &XWindowListener2::windowEnabled : &XWindowListener2::windowDisabled, m_aEvent ); + } + + ::comphelper::OInterfaceContainerHelper2& m_rWindow2Listeners; + const bool m_bEnabled; + const EventObject m_aEvent; + }; +} + +void VCLXWindow::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + css::uno::Reference< css::uno::XInterface > xThis( static_cast(this) ); + + switch ( rVclWindowEvent.GetId() ) + { + case VclEventId::WindowEnabled: + case VclEventId::WindowDisabled: + { + Callback aCallback = CallWindow2Listener( + mpImpl->getWindow2Listeners(), + ( VclEventId::WindowEnabled == rVclWindowEvent.GetId() ), + EventObject( *this ) + ); + ImplExecuteAsyncWithoutSolarLock( aCallback ); + } + break; + + case VclEventId::WindowPaint: + { + if ( mpImpl->getPaintListeners().getLength() ) + { + css::awt::PaintEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.UpdateRect = AWTRectangle( *static_cast(rVclWindowEvent.GetData()) ); + aEvent.Count = 0; + mpImpl->getPaintListeners().windowPaint( aEvent ); + } + } + break; + case VclEventId::WindowMove: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + css::awt::WindowEvent aEvent; + aEvent.Source = static_cast(this); + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowMoved( aEvent ); + } + } + break; + case VclEventId::WindowResize: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + css::awt::WindowEvent aEvent; + aEvent.Source = static_cast(this); + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowResized( aEvent ); + } + } + break; + case VclEventId::WindowShow: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + css::awt::WindowEvent aEvent; + aEvent.Source = static_cast(this); + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowShown( aEvent ); + } + + // For TopWindows this means opened... + if ( mpImpl->getTopWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getTopWindowListeners().windowOpened( aEvent ); + } + } + break; + case VclEventId::WindowHide: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + css::awt::WindowEvent aEvent; + aEvent.Source = static_cast(this); + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowHidden( aEvent ); + } + + // For TopWindows this means closed... + if ( mpImpl->getTopWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getTopWindowListeners().windowClosed( aEvent ); + } + } + break; + case VclEventId::WindowActivate: + case VclEventId::WindowDeactivate: + { + if (!mpImpl->getTopWindowListeners().getLength()) + return; + + // Suppress events which are unlikely to be interesting to our listeners. + vcl::Window* pWin = static_cast(rVclWindowEvent.GetData()); + bool bSuppress = false; + + while (pWin) + { + // Either the event came from the same window, from its + // child, or from a child of its border window (e.g. + // menubar or notebookbar). + if (pWin->GetWindow(GetWindowType::Client) == GetWindow()) + return; + + if (pWin->IsMenuFloatingWindow()) + bSuppress = true; + + if (pWin->GetType() == WindowType::FLOATINGWINDOW && + static_cast(pWin)->IsInPopupMode()) + bSuppress = true; + + // Otherwise, don't suppress if the event came from a different frame. + if (!bSuppress && pWin->GetWindow(GetWindowType::Frame) == pWin) + break; + + pWin = pWin->GetWindow(GetWindowType::RealParent); + } + + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + if (rVclWindowEvent.GetId() == VclEventId::WindowActivate) + mpImpl->getTopWindowListeners().windowActivated( aEvent ); + else + mpImpl->getTopWindowListeners().windowDeactivated( aEvent ); + } + break; + case VclEventId::WindowClose: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::closed, aEvent ); + } + if ( mpImpl->getTopWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getTopWindowListeners().windowClosing( aEvent ); + } + } + break; + case VclEventId::ControlGetFocus: + case VclEventId::WindowGetFocus: + { + if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VclEventId::ControlGetFocus + ) + || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VclEventId::WindowGetFocus + ) + ) + { + if ( mpImpl->getFocusListeners().getLength() ) + { + css::awt::FocusEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.FocusFlags = static_cast(rVclWindowEvent.GetWindow()->GetGetFocusFlags()); + aEvent.Temporary = false; + mpImpl->getFocusListeners().focusGained( aEvent ); + } + } + } + break; + case VclEventId::ControlLoseFocus: + case VclEventId::WindowLoseFocus: + { + if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VclEventId::ControlLoseFocus + ) + || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VclEventId::WindowLoseFocus + ) + ) + { + if ( mpImpl->getFocusListeners().getLength() ) + { + css::awt::FocusEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.FocusFlags = static_cast(rVclWindowEvent.GetWindow()->GetGetFocusFlags()); + aEvent.Temporary = false; + + vcl::Window* pNext = Application::GetFocusWindow(); + if ( pNext ) + { + // Don't care about internals if this control is compound + vcl::Window* pNextC = pNext; + while ( pNextC && !pNextC->IsCompoundControl() ) + pNextC = pNextC->GetParent(); + if ( pNextC ) + pNext = pNextC; + + pNext->GetComponentInterface(); + aEvent.NextFocus = static_cast(pNext->GetWindowPeer()); + } + mpImpl->getFocusListeners().focusLost( aEvent ); + } + } + } + break; + case VclEventId::WindowMinimize: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getTopWindowListeners().windowMinimized( aEvent ); + } + } + break; + case VclEventId::WindowNormalize: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getTopWindowListeners().windowNormalized( aEvent ); + } + } + break; + case VclEventId::WindowKeyInput: + { + if ( mpImpl->getKeyListeners().getLength() ) + { + css::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( + *static_cast(rVclWindowEvent.GetData()), *this + ) ); + mpImpl->getKeyListeners().keyPressed( aEvent ); + } + } + break; + case VclEventId::WindowKeyUp: + { + if ( mpImpl->getKeyListeners().getLength() ) + { + css::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( + *static_cast(rVclWindowEvent.GetData()), *this + ) ); + mpImpl->getKeyListeners().keyReleased( aEvent ); + } + } + break; + case VclEventId::WindowCommand: + { + CommandEvent* pCmdEvt = static_cast(rVclWindowEvent.GetData()); + if ( mpImpl->getMouseListeners().getLength() && ( pCmdEvt->GetCommand() == CommandEventId::ContextMenu ) ) + { + // CommandEventId::ContextMenu: send as mousePressed with PopupTrigger = true ... + Point aWhere = static_cast< CommandEvent* >( rVclWindowEvent.GetData() )->GetMousePosPixel(); + if ( !pCmdEvt->IsMouseEvent() ) + { // for keyboard events, we set the coordinates to -1,-1. This is a slight HACK, but the current API + // handles a context menu command as special case of a mouse event, which is simply wrong. + // Without extending the API, we would not have another chance to notify listeners of a + // keyboard-triggered context menu request + aWhere = Point( -1, -1 ); + } + + MouseEvent aMEvt( aWhere, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT, 0 ); + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( aMEvt, *this ) ); + aEvent.PopupTrigger = true; + + Callback aCallback = [ this, aEvent ]() + { this->mpImpl->getMouseListeners().mousePressed( aEvent ); }; + + ImplExecuteAsyncWithoutSolarLock( aCallback ); + } + } + break; + case VclEventId::WindowMouseMove: + { + MouseEvent* pMouseEvt = static_cast(rVclWindowEvent.GetData()); + if ( mpImpl->getMouseListeners().getLength() && ( pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow() ) ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); + bool const isEnter(pMouseEvt->IsEnterWindow()); + Callback aCallback = [ this, isEnter, aEvent ]() + { MouseListenerMultiplexer& rMouseListeners = this->mpImpl->getMouseListeners(); + isEnter + ? rMouseListeners.mouseEntered(aEvent) + : rMouseListeners.mouseExited(aEvent); }; + + ImplExecuteAsyncWithoutSolarLock( aCallback ); + } + + if ( mpImpl->getMouseMotionListeners().getLength() && !pMouseEvt->IsEnterWindow() && !pMouseEvt->IsLeaveWindow() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); + aEvent.ClickCount = 0; + if ( pMouseEvt->GetMode() & MouseEventModifiers::SIMPLEMOVE ) + mpImpl->getMouseMotionListeners().mouseMoved( aEvent ); + else + mpImpl->getMouseMotionListeners().mouseDragged( aEvent ); + } + } + break; + case VclEventId::WindowMouseButtonDown: + { + if ( mpImpl->getMouseListeners().getLength() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast(rVclWindowEvent.GetData()), *this ) ); + Callback aCallback = [ this, aEvent ]() + { this->mpImpl->getMouseListeners().mousePressed( aEvent ); }; + ImplExecuteAsyncWithoutSolarLock( aCallback ); + } + } + break; + case VclEventId::WindowMouseButtonUp: + { + if ( mpImpl->getMouseListeners().getLength() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast(rVclWindowEvent.GetData()), *this ) ); + + Callback aCallback = [ this, aEvent ]() + { this->mpImpl->getMouseListeners().mouseReleased( aEvent ); }; + ImplExecuteAsyncWithoutSolarLock( aCallback ); + } + } + break; + case VclEventId::WindowStartDocking: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + DockingData *pData = static_cast(rVclWindowEvent.GetData()); + + if( pData ) + { + css::awt::DockingEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); + aEvent.MousePos.X = pData->maMousePos.X(); + aEvent.MousePos.Y = pData->maMousePos.Y(); + aEvent.bLiveMode = false; + aEvent.bInteractive = true; + + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::startDocking, aEvent ); + } + } + } + break; + case VclEventId::WindowDocking: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + DockingData *pData = static_cast(rVclWindowEvent.GetData()); + + if( pData ) + { + css::awt::DockingEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); + aEvent.MousePos.X = pData->maMousePos.X(); + aEvent.MousePos.Y = pData->maMousePos.Y(); + aEvent.bLiveMode = false; + aEvent.bInteractive = true; + + Reference< XDockableWindowListener > xFirstListener; + ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() ); + while ( aIter.hasMoreElements() && !xFirstListener.is() ) + { + xFirstListener.set( aIter.next(), UNO_QUERY ); + } + + css::awt::DockingData aDockingData = + xFirstListener->docking( aEvent ); + pData->maTrackRect = VCLRectangle( aDockingData.TrackingRectangle ); + pData->mbFloating = aDockingData.bFloating; + } + } + } + break; + case VclEventId::WindowEndDocking: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + EndDockingData *pData = static_cast(rVclWindowEvent.GetData()); + + if( pData ) + { + css::awt::EndDockingEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.WindowRectangle = AWTRectangle( pData->maWindowRect ); + aEvent.bFloating = pData->mbFloating; + aEvent.bCancelled = pData->mbCancelled; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endDocking, aEvent ); + } + } + } + break; + case VclEventId::WindowPrepareToggleFloating: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + sal_Bool *p_bFloating = static_cast(rVclWindowEvent.GetData()); + + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + + Reference< XDockableWindowListener > xFirstListener; + ::comphelper::OInterfaceIteratorHelper2 aIter( mpImpl->getDockableWindowListeners() ); + while ( aIter.hasMoreElements() && !xFirstListener.is() ) + { + xFirstListener.set( aIter.next(), UNO_QUERY ); + } + + *p_bFloating = xFirstListener->prepareToggleFloatingMode( aEvent ); + } + } + break; + case VclEventId::WindowToggleFloating: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + css::lang::EventObject aEvent; + aEvent.Source = static_cast(this); + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::toggleFloatingMode, aEvent ); + } + } + break; + case VclEventId::WindowEndPopupMode: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + EndPopupModeData *pData = static_cast(rVclWindowEvent.GetData()); + + if( pData ) + { + css::awt::EndPopupModeEvent aEvent; + aEvent.Source = static_cast(this); + aEvent.FloatingPosition.X = pData->maFloatingPos.X(); + aEvent.FloatingPosition.Y = pData->maFloatingPos.Y(); + aEvent.bTearoff = pData->mbTearoff; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endPopupMode, aEvent ); + } + } + } + break; + default: break; + } +} + +uno::Reference< accessibility::XAccessibleContext > VCLXWindow::CreateAccessibleContext() +{ + SolarMutexGuard aGuard; + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXWindow::SetSynthesizingVCLEvent( bool _b ) +{ + mpImpl->mbSynthesizingVCLEvent = _b; +} + +bool VCLXWindow::IsSynthesizingVCLEvent() const +{ + return mpImpl->mbSynthesizingVCLEvent; +} + +Size VCLXWindow::ImplCalcWindowSize( const Size& rOutSz ) const +{ + Size aSz = rOutSz; + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + sal_Int32 nLeft, nTop, nRight, nBottom; + pWindow->GetBorder( nLeft, nTop, nRight, nBottom ); + aSz.AdjustWidth(nLeft+nRight ); + aSz.AdjustHeight(nTop+nBottom ); + } + return aSz; +} + + +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION2_IMPL(VCLXWindow, VCLXDevice); + + +// css::lang::Component +void VCLXWindow::dispose( ) +{ + SolarMutexGuard aGuard; + + mpImpl->mxViewGraphics = nullptr; + + if ( !mpImpl->mbDisposing ) + { + mpImpl->mbDisposing = true; + + mpImpl->disposing(); + + if ( GetWindow() ) + { + VclPtr pOutDev = GetOutputDevice(); + SetWindow( nullptr ); // so that handlers are logged off, if necessary (virtual) + SetOutputDevice( nullptr ); + pOutDev.disposeAndClear(); + } + + // #i14103# dispose the accessible context after the window has been destroyed, + // otherwise the old value in the child event fired in VCLXAccessibleComponent::ProcessWindowEvent() + // for VclEventId::WindowChildDestroyed contains a reference to an already disposed accessible object + try + { + css::uno::Reference< css::lang::XComponent > xComponent( mpImpl->mxAccessibleContext, css::uno::UNO_QUERY ); + if ( xComponent.is() ) + xComponent->dispose(); + } + catch ( const css::uno::Exception& ) + { + OSL_FAIL( "VCLXWindow::dispose: could not dispose the accessible context!" ); + } + mpImpl->mxAccessibleContext.clear(); + + mpImpl->mbDisposing = false; + } +} + +void VCLXWindow::addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + mpImpl->getEventListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + mpImpl->getEventListeners().removeInterface( rxListener ); +} + + +// css::awt::XWindow +void VCLXWindow::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) +{ + SolarMutexGuard aGuard; + comphelper::ProfileZone aZone("setPosSize"); + + if ( GetWindow() ) + { + if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) ) + vcl::Window::GetDockingManager()->SetPosSizePixel( GetWindow() , X, Y, Width, Height, static_cast(Flags) ); + else + GetWindow()->setPosSizePixel( X, Y, Width, Height, static_cast(Flags) ); + } +} + +css::awt::Rectangle VCLXWindow::getPosSize( ) +{ + SolarMutexGuard aGuard; + + css::awt::Rectangle aBounds; + if ( GetWindow() ) + { + if( vcl::Window::GetDockingManager()->IsDockable( GetWindow() ) ) + aBounds = AWTRectangle( vcl::Window::GetDockingManager()->GetPosSizePixel( GetWindow() ) ); + else + aBounds = AWTRectangle( tools::Rectangle( GetWindow()->GetPosPixel(), GetWindow()->GetSizePixel() ) ); + } + + return aBounds; +} + +void VCLXWindow::setVisible( sal_Bool bVisible ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + mpImpl->setDirectVisible( bVisible ); + pWindow->Show( bVisible && mpImpl->isEnableVisible() ); + } +} + +void VCLXWindow::setEnable( sal_Bool bEnable ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + pWindow->Enable( bEnable, false ); // #95824# without children! + pWindow->EnableInput( bEnable ); + } +} + +void VCLXWindow::setFocus( ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + GetWindow()->GrabFocus(); +} + +void VCLXWindow::addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + mpImpl->getWindowListeners().addInterface( rxListener ); + + Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); + if ( xListener2.is() ) + mpImpl->getWindow2Listeners().addInterface( xListener2 ); + + // #100119# Get all resize events, even if height or width 0, or invisible + if ( GetWindow() ) + GetWindow()->EnableAllResize(); +} + +void VCLXWindow::removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rxListener ) +{ + SolarMutexGuard aGuard; + + Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); + if ( xListener2.is() ) + mpImpl->getWindow2Listeners().removeInterface( xListener2 ); + + mpImpl->getWindowListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getFocusListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getFocusListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getKeyListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getKeyListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getMouseListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getMouseListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getMouseMotionListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getMouseMotionListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getPaintListeners().addInterface( rxListener ); +} + +void VCLXWindow::removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& rxListener ) +{ + SolarMutexGuard aGuard; + mpImpl->getPaintListeners().removeInterface( rxListener ); +} + +// css::awt::XWindowPeer +css::uno::Reference< css::awt::XToolkit > VCLXWindow::getToolkit( ) +{ + // no guard. nothing to guard here. + // 82463 - 12/21/00 - fs + return Application::GetVCLToolkit(); +} + +void VCLXWindow::setPointer( const css::uno::Reference< css::awt::XPointer >& rxPointer ) +{ + SolarMutexGuard aGuard; + + VCLXPointer* pPointer = comphelper::getUnoTunnelImplementation( rxPointer ); + if ( pPointer && GetWindow() ) + GetWindow()->SetPointer( pPointer->GetPointer() ); +} + +void VCLXWindow::setBackground( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + { + Color aColor(nColor); + GetWindow()->SetBackground( aColor ); + GetWindow()->SetControlBackground( aColor ); + + WindowType eWinType = GetWindow()->GetType(); + if ( ( eWinType == WindowType::WINDOW ) || + ( eWinType == WindowType::WORKWINDOW ) || + ( eWinType == WindowType::FLOATINGWINDOW ) ) + { + GetWindow()->Invalidate(); + } + } +} + +void VCLXWindow::invalidate( sal_Int16 nInvalidateFlags ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + GetWindow()->Invalidate( static_cast(nInvalidateFlags) ); +} + +void VCLXWindow::invalidateRect( const css::awt::Rectangle& rRect, sal_Int16 nInvalidateFlags ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + GetWindow()->Invalidate( VCLRectangle(rRect), static_cast(nInvalidateFlags) ); +} + + +// css::awt::XVclWindowPeer +sal_Bool VCLXWindow::isChild( const css::uno::Reference< css::awt::XWindowPeer >& rxPeer ) +{ + SolarMutexGuard aGuard; + + bool bIsChild = false; + VclPtr pWindow = GetWindow(); + if ( pWindow ) + { + VclPtr pPeerWindow = VCLUnoHelper::GetWindow( rxPeer ); + bIsChild = pPeerWindow && pWindow->IsChild( pPeerWindow ); + } + + return bIsChild; +} + +void VCLXWindow::setDesignMode( sal_Bool bOn ) +{ + SolarMutexGuard aGuard; + + mpImpl->mbDesignMode = bOn; +} + +sal_Bool VCLXWindow::isDesignMode( ) +{ + SolarMutexGuard aGuard; + return mpImpl->mbDesignMode; +} + +void VCLXWindow::enableClipSiblings( sal_Bool bClip ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + GetWindow()->EnableClipSiblings( bClip ); +} + +void VCLXWindow::setForeground( sal_Int32 nColor ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + { + GetWindow()->SetControlForeground( Color(nColor) ); + } +} + +void VCLXWindow::setControlFont( const css::awt::FontDescriptor& rFont ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + GetWindow()->SetControlFont( VCLUnoHelper::CreateFont( rFont, GetWindow()->GetControlFont() ) ); +} + +void VCLXWindow::getStyles( sal_Int16 nType, css::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + { + const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings(); + + switch ( nType ) + { + case css::awt::Style::FRAME: + { + Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); + ForegroundColor = sal_Int32(rStyleSettings.GetWindowTextColor()); + BackgroundColor = sal_Int32(rStyleSettings.GetWindowColor()); + } + break; + case css::awt::Style::DIALOG: + { + Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); + ForegroundColor = sal_Int32(rStyleSettings.GetDialogTextColor()); + BackgroundColor = sal_Int32(rStyleSettings.GetDialogColor()); + } + break; + default: OSL_FAIL( "VCLWindow::getStyles() - unknown Type" ); + } + + } +} + +namespace toolkit +{ + static void setColorSettings( vcl::Window* _pWindow, const css::uno::Any& _rValue, + void (StyleSettings::*pSetter)( const Color& ), const Color& (StyleSettings::*pGetter)( ) const ) + { + sal_Int32 nColor = 0; + if ( !( _rValue >>= nColor ) ) + nColor = sal_Int32((Application::GetSettings().GetStyleSettings().*pGetter)()); + + AllSettings aSettings = _pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + + (aStyleSettings.*pSetter)( Color( nColor ) ); + + aSettings.SetStyleSettings( aStyleSettings ); + _pWindow->SetSettings( aSettings, true ); + } +} + +// Terminated by BASEPROPERTY_NOTFOUND (or 0) +void VCLXWindow::PushPropertyIds( std::vector< sal_uInt16 > &rIds, + int nFirstId, ...) +{ + va_list pVarArgs; + va_start( pVarArgs, nFirstId ); + + for ( int nId = nFirstId; nId != BASEPROPERTY_NOTFOUND; + nId = va_arg( pVarArgs, int ) ) + rIds.push_back( static_cast(nId) ); + + va_end( pVarArgs ); +} + +void VCLXWindow::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds, bool bWithDefaults ) +{ + // These are common across ~all VCLXWindow derived classes + if( bWithDefaults ) + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_TEXT, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_ENABLEVISIBLE, // for visibility + BASEPROPERTY_TABSTOP, + 0); + + // lovely hack from: + // void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId ) + if( std::find(rIds.begin(), rIds.end(), BASEPROPERTY_FONTDESCRIPTOR) != rIds.end() ) + { + // some properties are not included in the FontDescriptor, but every time + // when we have a FontDescriptor we want to have these properties too. + // => Easier to register the here, instead everywhere where I register the FontDescriptor... + + rIds.push_back( BASEPROPERTY_TEXTCOLOR ); + rIds.push_back( BASEPROPERTY_TEXTLINECOLOR ); + rIds.push_back( BASEPROPERTY_FONTRELIEF ); + rIds.push_back( BASEPROPERTY_FONTEMPHASISMARK ); + } +} + +void VCLXWindow::GetPropertyIds( std::vector< sal_uInt16 >& _out_rIds ) +{ + return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps ); +} + +::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetContainerListeners() +{ + return mpImpl->getContainerListeners(); +} + +::comphelper::OInterfaceContainerHelper2& VCLXWindow::GetTopWindowListeners() +{ + return mpImpl->getTopWindowListeners(); +} + +namespace +{ + void lcl_updateWritingMode( vcl::Window& _rWindow, const sal_Int16 _nWritingMode, const sal_Int16 _nContextWritingMode ) + { + bool bEnableRTL = false; + switch ( _nWritingMode ) + { + case WritingMode2::LR_TB: bEnableRTL = false; break; + case WritingMode2::RL_TB: bEnableRTL = true; break; + case WritingMode2::CONTEXT: + { + // consult our ContextWritingMode. If it has an explicit RTL/LTR value, then use + // it. If it doesn't (but is CONTEXT itself), then just ask the parent window of our + // own window for its RTL mode + switch ( _nContextWritingMode ) + { + case WritingMode2::LR_TB: bEnableRTL = false; break; + case WritingMode2::RL_TB: bEnableRTL = true; break; + case WritingMode2::CONTEXT: + { + const vcl::Window* pParent = _rWindow.GetParent(); + OSL_ENSURE( pParent, "lcl_updateWritingMode: cannot determine context's writing mode!" ); + if ( pParent ) + bEnableRTL = pParent->IsRTLEnabled(); + } + break; + } + } + break; + default: + OSL_FAIL( "lcl_updateWritingMode: unsupported WritingMode!" ); + } // switch ( nWritingMode ) + + _rWindow.EnableRTL( bEnableRTL ); + } +} + +void VCLXWindow::setProperty( const OUString& PropertyName, const css::uno::Any& Value ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( !pWindow ) + return; + + bool bVoid = Value.getValueType().getTypeClass() == css::uno::TypeClass_VOID; + + WindowType eWinType = pWindow->GetType(); + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_REFERENCE_DEVICE: + { + Control* pControl = dynamic_cast< Control* >( pWindow.get() ); + OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); + if ( !pControl ) + break; + Reference< XDevice > xDevice( Value, UNO_QUERY ); + OutputDevice* pDevice = VCLUnoHelper::GetOutputDevice( xDevice ); + pControl->SetReferenceDevice( pDevice ); + } + break; + + case BASEPROPERTY_CONTEXT_WRITING_MODE: + { + OSL_VERIFY( Value >>= mpImpl->mnContextWritingMode ); + if ( mpImpl->mnWritingMode == WritingMode2::CONTEXT ) + lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); + } + break; + + case BASEPROPERTY_WRITING_MODE: + { + bool bProperType = ( Value >>= mpImpl->mnWritingMode ); + OSL_ENSURE( bProperType, "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" ); + if ( bProperType ) + lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); + } + break; + + case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR: + { + sal_uInt16 nWheelBehavior( css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY ); + OSL_VERIFY( Value >>= nWheelBehavior ); + + AllSettings aSettings = pWindow->GetSettings(); + MouseSettings aMouseSettings = aSettings.GetMouseSettings(); + + MouseWheelBehaviour nVclBehavior( MouseWheelBehaviour::FocusOnly ); + switch ( nWheelBehavior ) + { + case css::awt::MouseWheelBehavior::SCROLL_DISABLED: nVclBehavior = MouseWheelBehaviour::Disable; break; + case css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclBehavior = MouseWheelBehaviour::FocusOnly; break; + case css::awt::MouseWheelBehavior::SCROLL_ALWAYS: nVclBehavior = MouseWheelBehaviour::ALWAYS; break; + default: + OSL_FAIL( "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" ); + } + + aMouseSettings.SetWheelBehavior( nVclBehavior ); + aSettings.SetMouseSettings( aMouseSettings ); + pWindow->SetSettings( aSettings, true ); + } + break; + + case BASEPROPERTY_NATIVE_WIDGET_LOOK: + { + bool bEnable( true ); + OSL_VERIFY( Value >>= bEnable ); + pWindow->EnableNativeWidget( bEnable ); + } + break; + + case BASEPROPERTY_PLUGINPARENT: + { + // set parent handle + SetSystemParent_Impl( Value ); + } + break; + + case BASEPROPERTY_ENABLED: + { + bool b = bool(); + if ( Value >>= b ) + setEnable( b ); + } + break; + case BASEPROPERTY_ENABLEVISIBLE: + { + bool b = false; + if ( Value >>= b ) + { + if( b != mpImpl->isEnableVisible() ) + { + mpImpl->setEnableVisible( b ); + pWindow->Show( b && mpImpl->isDirectVisible() ); + } + } + } + break; + case BASEPROPERTY_TEXT: + case BASEPROPERTY_LABEL: + case BASEPROPERTY_TITLE: + { + OUString aText; + if ( Value >>= aText ) + { + switch (eWinType) + { + case WindowType::OKBUTTON: + case WindowType::CANCELBUTTON: + case WindowType::HELPBUTTON: + // Standard Button: overwrite only if not empty. + if (!aText.isEmpty()) + pWindow->SetText( aText ); + break; + + default: + pWindow->SetText( aText ); + break; + } + } + } + break; + case BASEPROPERTY_ACCESSIBLENAME: + { + OUString aText; + if ( Value >>= aText ) + pWindow->SetAccessibleName( aText ); + } + break; + case BASEPROPERTY_HELPURL: + { + OUString aURL; + if ( Value >>= aURL ) + { + INetURLObject aHelpURL( aURL ); + if ( aHelpURL.GetProtocol() == INetProtocol::Hid ) + pWindow->SetHelpId( OUStringToOString( aHelpURL.GetURLPath(), RTL_TEXTENCODING_UTF8 ) ); + else + pWindow->SetHelpId( OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ) ); + } + } + break; + case BASEPROPERTY_HELPTEXT: + { + OUString aHelpText; + if ( Value >>= aHelpText ) + { + pWindow->SetQuickHelpText( aHelpText ); + } + } + break; + case BASEPROPERTY_FONTDESCRIPTOR: + { + if ( bVoid ) + pWindow->SetControlFont( vcl::Font() ); + else + { + css::awt::FontDescriptor aFont; + if ( Value >>= aFont ) + pWindow->SetControlFont( VCLUnoHelper::CreateFont( aFont, pWindow->GetControlFont() ) ); + } + } + break; + case BASEPROPERTY_FONTRELIEF: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + { + vcl::Font aFont = pWindow->GetControlFont(); + aFont.SetRelief( static_cast(n) ); + pWindow->SetControlFont( aFont ); + } + } + break; + case BASEPROPERTY_FONTEMPHASISMARK: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + { + vcl::Font aFont = pWindow->GetControlFont(); + aFont.SetEmphasisMark( static_cast(n) ); + pWindow->SetControlFont( aFont ); + } + } + break; + case BASEPROPERTY_BACKGROUNDCOLOR: + if ( bVoid ) + { + switch ( eWinType ) + { + // set dialog color for default + case WindowType::DIALOG: + case WindowType::MESSBOX: + case WindowType::INFOBOX: + case WindowType::WARNINGBOX: + case WindowType::ERRORBOX: + case WindowType::QUERYBOX: + case WindowType::TABPAGE: + { + Color aColor = pWindow->GetSettings().GetStyleSettings().GetDialogColor(); + pWindow->SetBackground( aColor ); + pWindow->SetControlBackground( aColor ); + break; + } + + case WindowType::FIXEDTEXT: + case WindowType::CHECKBOX: + case WindowType::RADIOBUTTON: + case WindowType::GROUPBOX: + case WindowType::FIXEDLINE: + { + // support transparency only for special controls + pWindow->SetBackground(); + pWindow->SetControlBackground(); + pWindow->SetPaintTransparent( true ); + break; + } + + default: + { + // default code which enables transparency for + // compound controls. It's not real transparency + // as most of these controls repaint their client + // area completely new. + if ( pWindow->IsCompoundControl() ) + pWindow->SetBackground(); + pWindow->SetControlBackground(); + break; + } + } + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetControlBackground( aColor ); + pWindow->SetBackground( aColor ); + switch ( eWinType ) + { + // reset paint transparent mode + case WindowType::FIXEDTEXT: + case WindowType::CHECKBOX: + case WindowType::RADIOBUTTON: + case WindowType::GROUPBOX: + case WindowType::FIXEDLINE: + pWindow->SetPaintTransparent( false ); + break; + default: + break; + } + pWindow->Invalidate(); // Invalidate if control does not respond to it + } + } + break; + case BASEPROPERTY_TEXTCOLOR: + if ( bVoid ) + { + pWindow->SetControlForeground(); + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetTextColor( aColor ); + pWindow->SetControlForeground( aColor ); + } + } + break; + case BASEPROPERTY_TEXTLINECOLOR: + if ( bVoid ) + { + pWindow->SetTextLineColor(); + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetTextLineColor( aColor ); + } + } + break; + case BASEPROPERTY_FILLCOLOR: + if ( bVoid ) + pWindow->SetFillColor(); + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetFillColor( aColor ); + } + } + break; + case BASEPROPERTY_LINECOLOR: + if ( bVoid ) + pWindow->SetLineColor(); + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetLineColor( aColor ); + } + } + break; + case BASEPROPERTY_BORDER: + { + WinBits nStyle = pWindow->GetStyle(); + sal_uInt16 nTmp = 0; + Value >>= nTmp; + // clear any dodgy bits passed in, can come from dodgy extensions + nTmp &= o3tl::typed_flags::mask; + WindowBorderStyle nBorder = static_cast(nTmp); + if ( !bool(nBorder) ) + { + pWindow->SetStyle( nStyle & ~WB_BORDER ); + } + else + { + pWindow->SetStyle( nStyle | WB_BORDER ); + pWindow->SetBorderStyle( nBorder ); + } + } + break; + case BASEPROPERTY_TABSTOP: + { + WinBits nStyle = pWindow->GetStyle() & ~WB_TABSTOP; + if ( !bVoid ) + { + bool bTab = false; + Value >>= bTab; + if ( bTab ) + nStyle |= WB_TABSTOP; + else + nStyle |= WB_NOTABSTOP; + } + pWindow->SetStyle( nStyle ); + } + break; + case BASEPROPERTY_VERTICALALIGN: + { + VerticalAlignment eAlign = css::style::VerticalAlignment::VerticalAlignment_MAKE_FIXED_SIZE; + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_TOP|WB_VCENTER|WB_BOTTOM); + if ( !bVoid ) + Value >>= eAlign; + switch ( eAlign ) + { + case VerticalAlignment_TOP: + nStyle |= WB_TOP; + break; + case VerticalAlignment_MIDDLE: + nStyle |= WB_VCENTER; + break; + case VerticalAlignment_BOTTOM: + nStyle |= WB_BOTTOM; + break; + default: ; // for warning free code, MAKE_FIXED_SIZE + } + pWindow->SetStyle( nStyle ); + } + break; + case BASEPROPERTY_ALIGN: + { + sal_Int16 nAlign = PROPERTY_ALIGN_LEFT; + switch ( eWinType ) + { + case WindowType::COMBOBOX: + case WindowType::PUSHBUTTON: + case WindowType::OKBUTTON: + case WindowType::CANCELBUTTON: + case WindowType::HELPBUTTON: + nAlign = PROPERTY_ALIGN_CENTER; + [[fallthrough]]; + case WindowType::FIXEDTEXT: + case WindowType::EDIT: + case WindowType::MULTILINEEDIT: + case WindowType::CHECKBOX: + case WindowType::RADIOBUTTON: + case WindowType::LISTBOX: + { + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT); + if ( !bVoid ) + Value >>= nAlign; + if ( nAlign == PROPERTY_ALIGN_LEFT ) + nStyle |= WB_LEFT; + else if ( nAlign == PROPERTY_ALIGN_CENTER ) + nStyle |= WB_CENTER; + else + nStyle |= WB_RIGHT; + pWindow->SetStyle( nStyle ); + } + break; + default: break; + } + } + break; + case BASEPROPERTY_MULTILINE: + { + if ( ( eWinType == WindowType::FIXEDTEXT ) + || ( eWinType == WindowType::CHECKBOX ) + || ( eWinType == WindowType::RADIOBUTTON ) + || ( eWinType == WindowType::PUSHBUTTON ) + || ( eWinType == WindowType::OKBUTTON ) + || ( eWinType == WindowType::CANCELBUTTON ) + || ( eWinType == WindowType::HELPBUTTON ) + ) + { + WinBits nStyle = pWindow->GetStyle(); + bool bMulti = false; + Value >>= bMulti; + if ( bMulti ) + nStyle |= WB_WORDBREAK; + else + nStyle &= ~WB_WORDBREAK; + pWindow->SetStyle( nStyle ); + } + } + break; + case BASEPROPERTY_ORIENTATION: + { + if ( eWinType == WindowType::FIXEDLINE) + { + sal_Int32 nOrientation = 0; + if ( Value >>= nOrientation ) + { + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_HORZ|WB_VERT); + if ( nOrientation == 0 ) + nStyle |= WB_HORZ; + else + nStyle |= WB_VERT; + + pWindow->SetStyle( nStyle ); + } + } + } + break; + case BASEPROPERTY_AUTOMNEMONICS: + { + bool bAutoMnemonics = false; + Value >>= bAutoMnemonics; + AllSettings aSettings = pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + if ( aStyleSettings.GetAutoMnemonic() != bAutoMnemonics ) + { + aStyleSettings.SetAutoMnemonic( bAutoMnemonics ); + aSettings.SetStyleSettings( aStyleSettings ); + pWindow->SetSettings( aSettings ); + } + } + break; + case BASEPROPERTY_MOUSETRANSPARENT: + { + bool bMouseTransparent = false; + Value >>= bMouseTransparent; + pWindow->SetMouseTransparent( bMouseTransparent ); + } + break; + case BASEPROPERTY_PAINTTRANSPARENT: + { + bool bPaintTransparent = false; + Value >>= bPaintTransparent; + pWindow->SetPaintTransparent( bPaintTransparent ); +// pWindow->SetBackground(); + } + break; + + case BASEPROPERTY_REPEAT: + { + bool bRepeat( false ); + Value >>= bRepeat; + + WinBits nStyle = pWindow->GetStyle(); + if ( bRepeat ) + nStyle |= WB_REPEAT; + else + nStyle &= ~WB_REPEAT; + pWindow->SetStyle( nStyle ); + } + break; + + case BASEPROPERTY_REPEAT_DELAY: + { + sal_Int32 nRepeatDelay = 0; + if ( Value >>= nRepeatDelay ) + { + AllSettings aSettings = pWindow->GetSettings(); + MouseSettings aMouseSettings = aSettings.GetMouseSettings(); + + aMouseSettings.SetButtonRepeat( nRepeatDelay ); + aSettings.SetMouseSettings( aMouseSettings ); + + pWindow->SetSettings( aSettings, true ); + } + } + break; + + case BASEPROPERTY_SYMBOL_COLOR: + ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetButtonTextColor, &StyleSettings::GetButtonTextColor ); + break; + + case BASEPROPERTY_BORDERCOLOR: + ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetMonoColor, &StyleSettings::GetMonoColor); + break; + } +} + +css::uno::Any VCLXWindow::getProperty( const OUString& PropertyName ) +{ + SolarMutexGuard aGuard; + + css::uno::Any aProp; + if ( GetWindow() ) + { + WindowType eWinType = GetWindow()->GetType(); + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_REFERENCE_DEVICE: + { + VclPtr pControl = GetAsDynamic(); + OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); + if ( !pControl ) + break; + + VCLXDevice* pDevice = new VCLXDevice; + pDevice->SetOutputDevice( pControl->GetReferenceDevice() ); + aProp <<= Reference< XDevice >( pDevice ); + } + break; + + case BASEPROPERTY_CONTEXT_WRITING_MODE: + aProp <<= mpImpl->mnContextWritingMode; + break; + + case BASEPROPERTY_WRITING_MODE: + aProp <<= mpImpl->mnWritingMode; + break; + + case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR: + { + MouseWheelBehaviour nVclBehavior = GetWindow()->GetSettings().GetMouseSettings().GetWheelBehavior(); + sal_uInt16 nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; + switch ( nVclBehavior ) + { + case MouseWheelBehaviour::Disable: nBehavior = css::awt::MouseWheelBehavior::SCROLL_DISABLED; break; + case MouseWheelBehaviour::FocusOnly: nBehavior = css::awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break; + case MouseWheelBehaviour::ALWAYS: nBehavior = css::awt::MouseWheelBehavior::SCROLL_ALWAYS; break; + default: + OSL_FAIL( "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" ); + } + aProp <<= nBehavior; + } + break; + + case BASEPROPERTY_NATIVE_WIDGET_LOOK: + aProp <<= GetWindow()->IsNativeWidgetEnabled(); + break; + + case BASEPROPERTY_ENABLED: + aProp <<= GetWindow()->IsEnabled(); + break; + + case BASEPROPERTY_ENABLEVISIBLE: + aProp <<= mpImpl->isEnableVisible(); + break; + + case BASEPROPERTY_HIGHCONTRASTMODE: + aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetHighContrastMode(); + break; + + case BASEPROPERTY_TEXT: + case BASEPROPERTY_LABEL: + case BASEPROPERTY_TITLE: + { + OUString aText = GetWindow()->GetText(); + aProp <<= aText; + } + break; + case BASEPROPERTY_ACCESSIBLENAME: + { + OUString aText = GetWindow()->GetAccessibleName(); + aProp <<= aText; + } + break; + case BASEPROPERTY_HELPTEXT: + { + OUString aText = GetWindow()->GetQuickHelpText(); + aProp <<= aText; + } + break; + case BASEPROPERTY_HELPURL: + { + OUString aHelpId( OStringToOUString( GetWindow()->GetHelpId(), RTL_TEXTENCODING_UTF8 ) ); + aProp <<= aHelpId; + } + break; + case BASEPROPERTY_FONTDESCRIPTOR: + { + vcl::Font aFont = GetWindow()->GetControlFont(); + css::awt::FontDescriptor aFD = VCLUnoHelper::CreateFontDescriptor( aFont ); + aProp <<= aFD; + } + break; + case BASEPROPERTY_BACKGROUNDCOLOR: + aProp <<= GetWindow()->GetControlBackground(); + break; + case BASEPROPERTY_DISPLAYBACKGROUNDCOLOR: + aProp <<= GetWindow()->GetBackgroundColor(); + break; + case BASEPROPERTY_FONTRELIEF: + aProp <<= static_cast(GetWindow()->GetControlFont().GetRelief()); + break; + case BASEPROPERTY_FONTEMPHASISMARK: + aProp <<= static_cast(GetWindow()->GetControlFont().GetEmphasisMark()); + break; + case BASEPROPERTY_TEXTCOLOR: + aProp <<= GetWindow()->GetControlForeground(); + break; + case BASEPROPERTY_TEXTLINECOLOR: + aProp <<= GetWindow()->GetTextLineColor(); + break; + case BASEPROPERTY_FILLCOLOR: + aProp <<= GetWindow()->GetFillColor(); + break; + case BASEPROPERTY_LINECOLOR: + aProp <<= GetWindow()->GetLineColor(); + break; + case BASEPROPERTY_BORDER: + { + WindowBorderStyle nBorder = WindowBorderStyle::NONE; + if ( GetWindow()->GetStyle() & WB_BORDER ) + nBorder = GetWindow()->GetBorderStyle(); + aProp <<= static_cast(nBorder); + } + break; + case BASEPROPERTY_TABSTOP: + aProp <<= ( GetWindow()->GetStyle() & WB_TABSTOP ) != 0; + break; + case BASEPROPERTY_VERTICALALIGN: + { + WinBits nStyle = GetWindow()->GetStyle(); + if ( nStyle & WB_TOP ) + aProp <<= VerticalAlignment_TOP; + else if ( nStyle & WB_VCENTER ) + aProp <<= VerticalAlignment_MIDDLE; + else if ( nStyle & WB_BOTTOM ) + aProp <<= VerticalAlignment_BOTTOM; + } + break; + case BASEPROPERTY_ALIGN: + { + switch ( eWinType ) + { + case WindowType::FIXEDTEXT: + case WindowType::EDIT: + case WindowType::MULTILINEEDIT: + case WindowType::CHECKBOX: + case WindowType::RADIOBUTTON: + case WindowType::LISTBOX: + case WindowType::COMBOBOX: + case WindowType::PUSHBUTTON: + case WindowType::OKBUTTON: + case WindowType::CANCELBUTTON: + case WindowType::HELPBUTTON: + { + WinBits nStyle = GetWindow()->GetStyle(); + if ( nStyle & WB_LEFT ) + aProp <<= sal_Int16(PROPERTY_ALIGN_LEFT); + else if ( nStyle & WB_CENTER ) + aProp <<= sal_Int16(PROPERTY_ALIGN_CENTER); + else if ( nStyle & WB_RIGHT ) + aProp <<= sal_Int16(PROPERTY_ALIGN_RIGHT); + } + break; + default: break; + } + } + break; + case BASEPROPERTY_MULTILINE: + { + if ( ( eWinType == WindowType::FIXEDTEXT ) + || ( eWinType == WindowType::CHECKBOX ) + || ( eWinType == WindowType::RADIOBUTTON ) + || ( eWinType == WindowType::PUSHBUTTON ) + || ( eWinType == WindowType::OKBUTTON ) + || ( eWinType == WindowType::CANCELBUTTON ) + || ( eWinType == WindowType::HELPBUTTON ) + ) + aProp <<= ( GetWindow()->GetStyle() & WB_WORDBREAK ) != 0; + } + break; + case BASEPROPERTY_AUTOMNEMONICS: + { + bool bAutoMnemonics = GetWindow()->GetSettings().GetStyleSettings().GetAutoMnemonic(); + aProp <<= bAutoMnemonics; + } + break; + case BASEPROPERTY_MOUSETRANSPARENT: + { + bool bMouseTransparent = GetWindow()->IsMouseTransparent(); + aProp <<= bMouseTransparent; + } + break; + case BASEPROPERTY_PAINTTRANSPARENT: + { + bool bPaintTransparent = GetWindow()->IsPaintTransparent(); + aProp <<= bPaintTransparent; + } + break; + + case BASEPROPERTY_REPEAT: + aProp <<= ( 0 != ( GetWindow()->GetStyle() & WB_REPEAT ) ); + break; + + case BASEPROPERTY_REPEAT_DELAY: + { + sal_Int32 nButtonRepeat = GetWindow()->GetSettings().GetMouseSettings().GetButtonRepeat(); + aProp <<= nButtonRepeat; + } + break; + + case BASEPROPERTY_SYMBOL_COLOR: + aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetButtonTextColor(); + break; + + case BASEPROPERTY_BORDERCOLOR: + aProp <<= GetWindow()->GetSettings().GetStyleSettings().GetMonoColor(); + break; + } + } + return aProp; +} + + +// css::awt::XLayoutConstrains +css::awt::Size VCLXWindow::getMinimumSize( ) +{ + SolarMutexGuard aGuard; + + // Use this method only for those components which can be created through + // css::awt::Toolkit , but do not have an interface + + Size aSz; + if ( GetWindow() ) + { + WindowType nWinType = GetWindow()->GetType(); + switch ( nWinType ) + { + case WindowType::CONTROL: + aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*12 ); + aSz.setHeight( GetWindow()->GetTextHeight()+2*6 ); + break; + + case WindowType::PATTERNBOX: + case WindowType::NUMERICBOX: + case WindowType::METRICBOX: + case WindowType::CURRENCYBOX: + case WindowType::DATEBOX: + case WindowType::TIMEBOX: + case WindowType::LONGCURRENCYBOX: + aSz.setWidth( GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*2 ); + aSz.setHeight( GetWindow()->GetTextHeight()+2*2 ); + break; + case WindowType::SCROLLBARBOX: + return VCLXScrollBar::implGetMinimumSize( GetWindow() ); + default: + aSz = GetWindow()->get_preferred_size(); + } + } + + return css::awt::Size( aSz.Width(), aSz.Height() ); +} + +css::awt::Size VCLXWindow::getPreferredSize( ) +{ + return getMinimumSize(); +} + +css::awt::Size VCLXWindow::calcAdjustedSize( const css::awt::Size& rNewSize ) +{ + SolarMutexGuard aGuard; + + css::awt::Size aNewSize( rNewSize ); + css::awt::Size aMinSize = getMinimumSize(); + + if ( aNewSize.Width < aMinSize.Width ) + aNewSize.Width = aMinSize.Width; + if ( aNewSize.Height < aMinSize.Height ) + aNewSize.Height = aMinSize.Height; + + return aNewSize; +} + + +// css::awt::XView +sal_Bool VCLXWindow::setGraphics( const css::uno::Reference< css::awt::XGraphics >& rxDevice ) +{ + SolarMutexGuard aGuard; + + if ( VCLUnoHelper::GetOutputDevice( rxDevice ) ) + mpImpl->mxViewGraphics = rxDevice; + else + mpImpl->mxViewGraphics = nullptr; + + return mpImpl->mxViewGraphics.is(); +} + +css::uno::Reference< css::awt::XGraphics > VCLXWindow::getGraphics( ) +{ + SolarMutexGuard aGuard; + + return mpImpl->mxViewGraphics; +} + +css::awt::Size VCLXWindow::getSize( ) +{ + SolarMutexGuard aGuard; + + Size aSz; + if ( GetWindow() ) + aSz = GetWindow()->GetSizePixel(); + return css::awt::Size( aSz.Width(), aSz.Height() ); +} + +void VCLXWindow::draw( sal_Int32 nX, sal_Int32 nY ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( !pWindow ) + return; + + if ( isDesignMode() || mpImpl->isEnableVisible() ) + { + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics ); + if (!pDev) + pDev = pWindow->GetParent(); + TabPage* pTabPage = dynamic_cast< TabPage* >( pWindow.get() ); + if ( pTabPage ) + { + Point aPos( nX, nY ); + aPos = pDev->PixelToLogic( aPos ); + pTabPage->Draw( pDev, aPos, DrawFlags::NONE ); + return; + } + + Point aPos( nX, nY ); + + if ( pWindow->GetParent() && !pWindow->IsSystemWindow() && ( pWindow->GetParent() == pDev ) ) + { + // #i40647# don't draw here if this is a recursive call + // sometimes this is called recursively, because the Update call on the parent + // (strangely) triggers another paint. Prevent a stack overflow here + // Yes, this is only fixing symptoms for the moment... + // #i40647# / 2005-01-18 / frank.schoenheit@sun.com + if ( !mpImpl->getDrawingOntoParent_ref() ) + { + ::comphelper::FlagGuard aDrawingflagGuard( mpImpl->getDrawingOntoParent_ref() ); + + bool bWasVisible = pWindow->IsVisible(); + Point aOldPos( pWindow->GetPosPixel() ); + + if ( bWasVisible && aOldPos == aPos ) + { + pWindow->PaintImmediately(); + return; + } + + pWindow->SetPosPixel( aPos ); + + // Update parent first to avoid painting the parent upon the update + // of this window, as it may otherwise cause the parent + // to hide this window again + if( pWindow->GetParent() ) + pWindow->GetParent()->PaintImmediately(); + + pWindow->Show(); + pWindow->PaintImmediately(); + pWindow->SetParentUpdateMode( false ); + pWindow->Hide(); + pWindow->SetParentUpdateMode( true ); + + pWindow->SetPosPixel( aOldPos ); + if ( bWasVisible ) + pWindow->Show(); + } + } + else if ( pDev ) + { + Point aP = pDev->PixelToLogic( aPos ); + + vcl::PDFExtOutDevData* pPDFExport = dynamic_cast(pDev->GetExtOutDevData()); + bool bDrawSimple = ( pDev->GetOutDevType() == OUTDEV_PRINTER ) + || ( pDev->GetOutDevViewType() == OutDevViewType::PrintPreview ) + || ( pPDFExport != nullptr ); + if ( bDrawSimple ) + { + pWindow->Draw( pDev, aP, DrawFlags::NoControls ); + } + else + { + bool bOldNW =pWindow->IsNativeWidgetEnabled(); + if( bOldNW ) + pWindow->EnableNativeWidget(false); + pWindow->PaintToDevice( pDev, aP ); + if( bOldNW ) + pWindow->EnableNativeWidget(); + } + } + } +} + +void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ ) +{ + SolarMutexGuard aGuard; + + if ( GetWindow() ) + { + // Fraction::Fraction takes a double, but we have a float only. + // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to + // 1.200000000047something. To prevent this, we convert explicitly to double, and round it. + double nZoom( fZoomX ); + Fraction aZoom(::rtl::math::round(nZoom, 4)); + aZoom.ReduceInaccurate(10); // to avoid runovers and BigInt mapping + GetWindow()->SetZoom(aZoom); + } +} + +// css::lang::XEventListener +void SAL_CALL VCLXWindow::disposing( const css::lang::EventObject& _rSource ) +{ + SolarMutexGuard aGuard; + + // check if it comes from our AccessibleContext + uno::Reference< uno::XInterface > aAC( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); + uno::Reference< uno::XInterface > xSource( _rSource.Source, uno::UNO_QUERY ); + + if ( aAC.get() == xSource.get() ) + { // yep, it does + mpImpl->mxAccessibleContext.clear(); + } +} + +// css::accessibility::XAccessible +css::uno::Reference< css::accessibility::XAccessibleContext > VCLXWindow::getAccessibleContext( ) +{ + SolarMutexGuard aGuard; + + // already disposed + if( ! mpImpl ) + return uno::Reference< accessibility::XAccessibleContext >(); + + if ( !mpImpl->mxAccessibleContext.is() && GetWindow() ) + { + mpImpl->mxAccessibleContext = CreateAccessibleContext(); + + // add as event listener to this component + // in case somebody disposes it, we do not want to have a (though weak) reference to a dead + // object + uno::Reference< lang::XComponent > xComp( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); + if ( xComp.is() ) + xComp->addEventListener( this ); + } + + return mpImpl->mxAccessibleContext; +} + +// css::awt::XDockable +void SAL_CALL VCLXWindow::addDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) +{ + SolarMutexGuard aGuard; + + if ( xListener.is() ) + mpImpl->getDockableWindowListeners().addInterface( xListener ); + +} + +void SAL_CALL VCLXWindow::removeDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) +{ + SolarMutexGuard aGuard; + + mpImpl->getDockableWindowListeners().removeInterface( xListener ); +} + +void SAL_CALL VCLXWindow::enableDocking( sal_Bool bEnable ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if ( pWindow ) + pWindow->EnableDocking( bEnable ); +} + +sal_Bool SAL_CALL VCLXWindow::isFloating( ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if( pWindow ) + return vcl::Window::GetDockingManager()->IsFloating( pWindow ); + else + return false; +} + +void SAL_CALL VCLXWindow::setFloatingMode( sal_Bool bFloating ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if( pWindow ) + vcl::Window::GetDockingManager()->SetFloatingMode( pWindow, bFloating ); +} + +sal_Bool SAL_CALL VCLXWindow::isLocked( ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if( pWindow ) + return vcl::Window::GetDockingManager()->IsLocked( pWindow ); + else + return false; +} + +void SAL_CALL VCLXWindow::lock( ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) ) + vcl::Window::GetDockingManager()->Lock( pWindow ); +} + +void SAL_CALL VCLXWindow::unlock( ) +{ + SolarMutexGuard aGuard; + + VclPtr pWindow = GetWindow(); + if( pWindow && !vcl::Window::GetDockingManager()->IsFloating( pWindow ) ) + vcl::Window::GetDockingManager()->Unlock( pWindow ); +} + +void SAL_CALL VCLXWindow::startPopupMode( const css::awt::Rectangle& ) +{ + // TODO: remove interface in the next incompatible build +} + +sal_Bool SAL_CALL VCLXWindow::isInPopupMode( ) +{ + // TODO: remove interface in the next incompatible build + return false; +} + + +// css::awt::XWindow2 + +void SAL_CALL VCLXWindow::setOutputSize( const css::awt::Size& aSize ) +{ + SolarMutexGuard aGuard; + if( VclPtr pWindow = GetWindow() ) + pWindow->SetOutputSizePixel( VCLSize( aSize ) ); +} + +css::awt::Size SAL_CALL VCLXWindow::getOutputSize( ) +{ + SolarMutexGuard aGuard; + if( VclPtr pWindow = GetWindow() ) + return AWTSize( pWindow->GetOutputSizePixel() ); + else + return css::awt::Size(); +} + +sal_Bool SAL_CALL VCLXWindow::isVisible( ) +{ + SolarMutexGuard aGuard; + if( GetWindow() ) + return GetWindow()->IsVisible(); + else + return false; +} + +sal_Bool SAL_CALL VCLXWindow::isActive( ) +{ + SolarMutexGuard aGuard; + if( GetWindow() ) + return GetWindow()->IsActive(); + else + return false; + +} + +sal_Bool SAL_CALL VCLXWindow::isEnabled( ) +{ + SolarMutexGuard aGuard; + if( GetWindow() ) + return GetWindow()->IsEnabled(); + else + return false; +} + +sal_Bool SAL_CALL VCLXWindow::hasFocus( ) +{ + SolarMutexGuard aGuard; + if( GetWindow() ) + return GetWindow()->HasFocus(); + else + return false; +} + +// css::beans::XPropertySetInfo + +UnoPropertyArrayHelper * +VCLXWindow::GetPropHelper() +{ + SolarMutexGuard aGuard; + if ( mpImpl->mpPropHelper == nullptr ) + { + std::vector< sal_uInt16 > aIDs; + GetPropertyIds( aIDs ); + mpImpl->mpPropHelper.reset( new UnoPropertyArrayHelper( aIDs ) ); + } + return mpImpl->mpPropHelper.get(); +} + +css::uno::Sequence< css::beans::Property > SAL_CALL +VCLXWindow::getProperties() +{ + return GetPropHelper()->getProperties(); +} +css::beans::Property SAL_CALL +VCLXWindow::getPropertyByName( const OUString& rName ) +{ + return GetPropHelper()->getPropertyByName( rName ); +} + +sal_Bool SAL_CALL +VCLXWindow::hasPropertyByName( const OUString& rName ) +{ + return GetPropHelper()->hasPropertyByName( rName ); +} + +Reference< XStyleSettings > SAL_CALL VCLXWindow::getStyleSettings() +{ + return mpImpl->getStyleSettings(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxwindow1.cxx b/toolkit/source/awt/vclxwindow1.cxx new file mode 100644 index 000000000..8b0cbe132 --- /dev/null +++ b/toolkit/source/awt/vclxwindow1.cxx @@ -0,0 +1,95 @@ +/* -*- 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 + +#ifdef _WIN32 +#include +#include +#elif defined ( MACOSX ) +#include +#include +#include +#endif +#include + +/// helper method to set a window handle into a SystemParentData struct +void VCLXWindow::SetSystemParent_Impl( const css::uno::Any& rHandle ) +{ + // does only work for WorkWindows + VclPtr pWindow = GetWindow(); + if ( pWindow->GetType() != WindowType::WORKWINDOW ) + { + css::uno::RuntimeException aException; + aException.Message = "not a work window"; + throw aException; + } + + // use sal_Int64 here to accommodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nHandle = 0; + bool bXEmbed = false; + bool bThrow = false; + if( ! (rHandle >>= nHandle) ) + { + css::uno::Sequence< css::beans::NamedValue > aProps; + if( rHandle >>= aProps ) + { + for( const css::beans::NamedValue& rProp : std::as_const(aProps) ) + { + if ( rProp.Name == "WINDOW" ) + rProp.Value >>= nHandle; + else if ( rProp.Name == "XEMBED" ) + rProp.Value >>= bXEmbed; + } + } + else + bThrow = true; + } + if( bThrow ) + { + css::uno::RuntimeException aException; + aException.Message = "incorrect window handle type"; + throw aException; + } + // create system parent data + SystemParentData aSysParentData; + aSysParentData.nSize = sizeof ( SystemParentData ); +#if defined(_WIN32) + aSysParentData.hWnd = reinterpret_cast(nHandle); +#elif defined( MACOSX ) + aSysParentData.pView = reinterpret_cast(nHandle); +#elif defined( ANDROID ) + // Nothing +#elif defined( IOS ) + // Nothing +#elif defined( UNX ) + aSysParentData.aWindow = static_cast(nHandle); + aSysParentData.bXEmbedSupport = bXEmbed; +#endif + + // set system parent + static_cast(pWindow.get())->SetPluginParent( &aSysParentData ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx new file mode 100644 index 000000000..b97988934 --- /dev/null +++ b/toolkit/source/awt/vclxwindows.cxx @@ -0,0 +1,8135 @@ +/* -*- 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 + +#include +#include +#include +#include "vclxwindows_internal.hxx" + +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::makeAny; +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 + { + sal_Int32 nBackgroundColor = 0; + _rColorValue >>= nBackgroundColor; + aStyleSettings.SetFaceColor( Color(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 ); + + sal_Int32 nBackgroundLuminance = Color( 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 makeAny( 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 ) +{ + 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