forked from amazingfate/loongoffice
The main reason for the "home-grown" UpCast introduced with
904b3d1fceee5827076758ed2a81f80cb73493ca "Up-cast conversion constructor for
css::uno::Reference" in 2013 was probably that we could not yet rely on C++11
std::is_base_of back then. A (welcome) side effect was that the derived class
could be incomplete.
However, specializations of UpCast relying on whether or not T2 is incomplete
are obviously an ODR violation if the type is incomplete in some TUs and
complete (and derived from T1) in others. And even if UpCast had internal
linkage, it would still be brittle that its behavior depends on the completeness
of T2 at the point of the template's instantiation, and not necessarily at the
point of use.
That means we should better base that ctor on std::is_base_of (which we can do
now since 39a1edd6fec902ef378acce8af42c4d7fba280d0 "Make css::uno::Reference
upcast ctor LIBO_INTERNAL_ONLY"), which causes a compilation error at least on
Clang and GCC if the completeness requirements are not met. This change fixes
all the cases where types need to be complete now, plus any resulting
loplugin:referencecasting warnings ("the source reference is already a subtype
of the destination reference").
Change-Id: Ieb9e3552e90adbf2c5a5af933dcb872e20661a2f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92950
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
149 lines
6.1 KiB
C++
149 lines
6.1 KiB
C++
/* -*- 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 <svtools/bindablecontrolhelper.hxx>
|
|
#include <com/sun/star/form/binding/XBindableValue.hpp>
|
|
#include <com/sun/star/form/binding/XValueBinding.hpp>
|
|
#include <com/sun/star/form/binding/XListEntrySink.hpp>
|
|
#include <com/sun/star/form/binding/XListEntrySource.hpp>
|
|
#include <com/sun/star/frame/XModel.hpp>
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
#include <com/sun/star/table/CellRangeAddress.hpp>
|
|
#include <com/sun/star/sheet/XCellRangeReferrer.hpp>
|
|
#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
#include <com/sun/star/table/CellAddress.hpp>
|
|
#include <com/sun/star/beans/NamedValue.hpp>
|
|
|
|
|
|
namespace svt
|
|
{
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
static bool lcl_isNamedRange( const OUString& sAddress, const uno::Reference< frame::XModel >& xModel, css::table::CellRangeAddress& aAddress )
|
|
{
|
|
bool bRes = false;
|
|
uno::Reference< sheet::XCellRangeReferrer > xReferrer;
|
|
try
|
|
{
|
|
uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW );
|
|
uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW );
|
|
xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY );
|
|
}
|
|
catch( uno::Exception& /*e*/ )
|
|
{
|
|
// do nothing
|
|
}
|
|
if ( xReferrer.is() )
|
|
{
|
|
uno::Reference< sheet::XCellRangeAddressable > xRangeAddressable( xReferrer->getReferredCells(), uno::UNO_QUERY );
|
|
if ( xRangeAddressable.is() )
|
|
{
|
|
aAddress = xRangeAddressable->getRangeAddress();
|
|
bRes = true;
|
|
}
|
|
}
|
|
return bRes;
|
|
}
|
|
|
|
|
|
void
|
|
BindableControlHelper::ApplyListSourceAndBindableData( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::uno::XInterface >& rObj, const OUString& rsCtrlSource, const OUString& rsRowSource, sal_uInt16 nRefTab )
|
|
{
|
|
// XBindable etc.
|
|
uno::Reference< lang::XMultiServiceFactory > xFac;
|
|
if ( xModel.is() )
|
|
xFac.set( xModel, uno::UNO_QUERY );
|
|
uno::Reference< form::binding::XBindableValue > xBindable( rObj, uno::UNO_QUERY );
|
|
if ( xFac.is() && rsCtrlSource.getLength() && xBindable.is() )
|
|
{
|
|
|
|
// OOo address structures
|
|
// RefCell - convert from XL
|
|
// pretend we converted the imported string address into the
|
|
// appropriate address structure
|
|
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion"), uno::UNO_QUERY );
|
|
css::table::CellAddress aAddress;
|
|
if ( xConvertor.is() )
|
|
{
|
|
// we need this service to properly convert XL notation also
|
|
// Should be easy to extend
|
|
xConvertor->setPropertyValue( "ReferenceSheet", uno::makeAny( nRefTab ) );
|
|
xConvertor->setPropertyValue( "XLA1Representation", uno::makeAny( rsCtrlSource ) );
|
|
xConvertor->getPropertyValue( "Address" ) >>= aAddress;
|
|
}
|
|
|
|
beans::NamedValue aArg1;
|
|
aArg1.Name = "BoundCell";
|
|
aArg1.Value <<= aAddress;
|
|
|
|
uno::Sequence< uno::Any > aArgs(1);
|
|
aArgs[ 0 ] <<= aArg1;
|
|
|
|
uno::Reference< form::binding::XValueBinding > xBinding( xFac->createInstanceWithArguments( "com.sun.star.table.CellValueBinding", aArgs ), uno::UNO_QUERY );
|
|
xBindable->setValueBinding( xBinding );
|
|
}
|
|
else if ( xBindable.is() ) // reset it
|
|
xBindable->setValueBinding( uno::Reference< form::binding::XValueBinding >() );
|
|
uno::Reference< form::binding::XListEntrySink > xListEntrySink( rObj, uno::UNO_QUERY );
|
|
if ( xFac.is() && rsRowSource.getLength() && xListEntrySink.is() )
|
|
{
|
|
|
|
// OOo address structures
|
|
// RefCell - convert from XL
|
|
// pretend we converted the imported string address into the
|
|
// appropriate address structure
|
|
uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion"), uno::UNO_QUERY );
|
|
css::table::CellRangeAddress aAddress;
|
|
if ( xConvertor.is() )
|
|
{
|
|
if ( !lcl_isNamedRange( rsRowSource, xModel, aAddress ) )
|
|
{
|
|
// we need this service to properly convert XL notation also
|
|
// Should be easy to extend
|
|
xConvertor->setPropertyValue( "ReferenceSheet", uno::makeAny( nRefTab ) );
|
|
xConvertor->setPropertyValue( "XLA1Representation", uno::makeAny( rsRowSource ) );
|
|
xConvertor->getPropertyValue( "Address" ) >>= aAddress;
|
|
}
|
|
}
|
|
|
|
beans::NamedValue aArg1;
|
|
aArg1.Name = "CellRange";
|
|
aArg1.Value <<= aAddress;
|
|
|
|
uno::Sequence< uno::Any > aArgs(1);
|
|
aArgs[ 0 ] <<= aArg1;
|
|
|
|
uno::Reference< form::binding::XListEntrySource > xSource( xFac->createInstanceWithArguments( "com.sun.star.table.CellRangeListSource", aArgs ), uno::UNO_QUERY );
|
|
xListEntrySink->setListEntrySource( xSource );
|
|
}
|
|
else if ( xListEntrySink.is() ) // reset
|
|
xListEntrySink->setListEntrySource( uno::Reference< form::binding::XListEntrySource >() );
|
|
|
|
}
|
|
|
|
|
|
} // namespace svt
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|