Files
Caolán McNamara 92f5913aef cid#1556442 COPY_INSTEAD_OF_MOVE
and

cid#1607753 COPY_INSTEAD_OF_MOVE
cid#1554790 COPY_INSTEAD_OF_MOVE
cid#1556463 COPY_INSTEAD_OF_MOVE
cid#1554838 COPY_INSTEAD_OF_MOVE
cid#1556231 COPY_INSTEAD_OF_MOVE
cid#1556878 COPY_INSTEAD_OF_MOVE
cid#1554913 COPY_INSTEAD_OF_MOVE
cid#1558064 COPY_INSTEAD_OF_MOVE
cid#1557043 COPY_INSTEAD_OF_MOVE
cid#1556985 COPY_INSTEAD_OF_MOVE
cid#1556766 COPY_INSTEAD_OF_MOVE
cid#1557351 COPY_INSTEAD_OF_MOVE
cid#1554863 COPY_INSTEAD_OF_MOVE
cid#1556764 COPY_INSTEAD_OF_MOVE
cid#1556279 COPY_INSTEAD_OF_MOVE
cid#1555970 COPY_INSTEAD_OF_MOVE
cid#1556942 COPY_INSTEAD_OF_MOVE
cid#1557964 COPY_INSTEAD_OF_MOVE
cid#1555166 COPY_INSTEAD_OF_MOVE
cid#1556496 COPY_INSTEAD_OF_MOVE
cid#1557175 COPY_INSTEAD_OF_MOVE
cid#1558054 COPY_INSTEAD_OF_MOVE
cid#1557392 COPY_INSTEAD_OF_MOVE
cid#1557850 COPY_INSTEAD_OF_MOVE
cid#1555118 COPY_INSTEAD_OF_MOVE
cid#1557131 COPY_INSTEAD_OF_MOVE
cid#1556614 COPY_INSTEAD_OF_MOVE
cid#1609650 COPY_INSTEAD_OF_MOVE
cid#1555114 COPY_INSTEAD_OF_MOVE
cid#1555241 COPY_INSTEAD_OF_MOVE
cid#1555442 COPY_INSTEAD_OF_MOVE
cid#1556473 COPY_INSTEAD_OF_MOVE
cid#1557654 COPY_INSTEAD_OF_MOVE
cid#1554689 COPY_INSTEAD_OF_MOVE
cid#1556316 COPY_INSTEAD_OF_MOVE
cid#1557929 COPY_INSTEAD_OF_MOVE
cid#1554807 COPY_INSTEAD_OF_MOVE
cid#1554858 COPY_INSTEAD_OF_MOVE
cid#1555103 COPY_INSTEAD_OF_MOVE
cid#1555517 COPY_INSTEAD_OF_MOVE
cid#1556424 COPY_INSTEAD_OF_MOVE
cid#1557252 COPY_INSTEAD_OF_MOVE
cid#1557566 COPY_INSTEAD_OF_MOVE
cid#1608020 COPY_INSTEAD_OF_MOVE
cid#1557742 COPY_INSTEAD_OF_MOVE
cid#1555884 COPY_INSTEAD_OF_MOVE
cid#1554809 COPY_INSTEAD_OF_MOVE
cid#1555336 COPY_INSTEAD_OF_MOVE
cid#1555173 COPY_INSTEAD_OF_MOVE
cid#1556067 COPY_INSTEAD_OF_MOVE
cid#1557040 COPY_INSTEAD_OF_MOVE
cid#1556235 COPY_INSTEAD_OF_MOVE
cid#1557366 COPY_INSTEAD_OF_MOVE
cid#1555910 COPY_INSTEAD_OF_MOVE
cid#1556716 COPY_INSTEAD_OF_MOVE
cid#1558022 COPY_INSTEAD_OF_MOVE
cid#1555769 COPY_INSTEAD_OF_MOVE
cid#1555940 COPY_INSTEAD_OF_MOVE
cid#1557077 COPY_INSTEAD_OF_MOVE
cid#1555270 COPY_INSTEAD_OF_MOVE
cid#1555660 COPY_INSTEAD_OF_MOVE
cid#1556302 COPY_INSTEAD_OF_MOVE
cid#1555678 COPY_INSTEAD_OF_MOVE
cid#1556538 COPY_INSTEAD_OF_MOVE
cid#1557689 COPY_INSTEAD_OF_MOVE
cid#1555009 COPY_INSTEAD_OF_MOVE
cid#1555433 COPY_INSTEAD_OF_MOVE
cid#1555671 COPY_INSTEAD_OF_MOVE
cid#1555255 COPY_INSTEAD_OF_MOVE
cid#1557681 COPY_INSTEAD_OF_MOVE
cid#1557512 COPY_INSTEAD_OF_MOVE
cid#1554958 COPY_INSTEAD_OF_MOVE
cid#1555758 COPY_INSTEAD_OF_MOVE
cid#1555597 COPY_INSTEAD_OF_MOVE
cid#1558040 COPY_INSTEAD_OF_MOVE
cid#1556476 COPY_INSTEAD_OF_MOVE
cid#1557646 COPY_INSTEAD_OF_MOVE
cid#1557950 COPY_INSTEAD_OF_MOVE
cid#1557019 COPY_INSTEAD_OF_MOVE
cid#1557885 COPY_INSTEAD_OF_MOVE
cid#1556402 COPY_INSTEAD_OF_MOVE
cid#1557906 COPY_INSTEAD_OF_MOVE
cid#1556619 COPY_INSTEAD_OF_MOVE
cid#1554683 COPY_INSTEAD_OF_MOVE
cid#1556549 COPY_INSTEAD_OF_MOVE
cid#1554747 COPY_INSTEAD_OF_MOVE
cid#1554929 COPY_INSTEAD_OF_MOVE
cid#1555362 COPY_INSTEAD_OF_MOVE
cid#1557053 COPY_INSTEAD_OF_MOVE
cid#1557891 COPY_INSTEAD_OF_MOVE
cid#1555043 COPY_INSTEAD_OF_MOVE
cid#1555107 COPY_INSTEAD_OF_MOVE
cid#1557203 COPY_INSTEAD_OF_MOVE
cid#1556728 COPY_INSTEAD_OF_MOVE
cid#1557773 COPY_INSTEAD_OF_MOVE
cid#1556845 COPY_INSTEAD_OF_MOVE

Change-Id: I001fb67e597b096e992fd8a0cd6f3ec577767c33
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176098
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
2024-11-06 13:58:54 +01:00

326 lines
11 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 "entrylisthelper.hxx"
#include <FormComponent.hxx>
#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <comphelper/sequence.hxx>
#include <comphelper/property.hxx>
#include <com/sun/star/form/binding/XListEntryTypedSource.hpp>
#include <algorithm>
namespace frm
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::form::binding;
OEntryListHelper::OEntryListHelper( OControlModel& _rControlModel )
:m_rControlModel( _rControlModel )
,m_aRefreshListeners( _rControlModel.getInstanceMutex() )
{
}
OEntryListHelper::OEntryListHelper( const OEntryListHelper& _rSource, OControlModel& _rControlModel )
:m_rControlModel( _rControlModel )
,m_xListSource ( _rSource.m_xListSource )
,m_aStringItems( _rSource.m_aStringItems )
,m_aRefreshListeners( _rControlModel.getInstanceMutex() )
{
}
OEntryListHelper::~OEntryListHelper( )
{
}
void SAL_CALL OEntryListHelper::setListEntrySource( const Reference< XListEntrySource >& _rxSource )
{
ControlModelLock aLock( m_rControlModel );
// disconnect from the current external list source
disconnectExternalListSource();
// and connect to the new one
if ( _rxSource.is() )
connectExternalListSource( _rxSource, aLock );
}
Reference< XListEntrySource > SAL_CALL OEntryListHelper::getListEntrySource( )
{
return m_xListSource;
}
void SAL_CALL OEntryListHelper::entryChanged( const ListEntryEvent& _rEvent )
{
ControlModelLock aLock( m_rControlModel );
OSL_ENSURE( _rEvent.Source == m_xListSource,
"OEntryListHelper::entryChanged: where did this come from?" );
OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ),
"OEntryListHelper::entryChanged: invalid index!" );
OSL_ENSURE( _rEvent.Entries.getLength() == 1,
"OEntryListHelper::entryChanged: invalid string list!" );
if ( ( _rEvent.Position >= 0 )
&& ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() )
&& _rEvent.Entries.hasElements()
)
{
m_aStringItems[ _rEvent.Position ] = _rEvent.Entries[ 0 ];
if (m_aTypedItems.hasElements())
m_aTypedItems = Sequence<Any>(); // doesn't match anymore
stringItemListChanged( aLock );
}
}
void SAL_CALL OEntryListHelper::entryRangeInserted( const ListEntryEvent& _rEvent )
{
ControlModelLock aLock( m_rControlModel );
OSL_ENSURE( _rEvent.Source == m_xListSource,
"OEntryListHelper::entryRangeInserted: where did this come from?" );
OSL_ENSURE( ( _rEvent.Position > 0 ) && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ) && _rEvent.Entries.hasElements(),
"OEntryListHelper::entryRangeRemoved: invalid count and/or position!" );
if ( ( _rEvent.Position > 0 )
&& ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() )
&& _rEvent.Entries.hasElements()
)
{
m_aStringItems.insert(m_aStringItems.begin() + _rEvent.Position, _rEvent.Entries.begin(), _rEvent.Entries.end());
if (m_aTypedItems.hasElements())
m_aTypedItems = Sequence<Any>(); // doesn't match anymore
stringItemListChanged( aLock );
}
}
void SAL_CALL OEntryListHelper::entryRangeRemoved( const ListEntryEvent& _rEvent )
{
ControlModelLock aLock( m_rControlModel );
OSL_ENSURE( _rEvent.Source == m_xListSource,
"OEntryListHelper::entryRangeRemoved: where did this come from?" );
OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Count > 0 ) && ( _rEvent.Position + _rEvent.Count <= static_cast<sal_Int32>(m_aStringItems.size()) ),
"OEntryListHelper::entryRangeRemoved: invalid count and/or position!" );
if ( !(( _rEvent.Position > 0 )
&& ( _rEvent.Count > 0 )
&& ( _rEvent.Position + _rEvent.Count <= static_cast<sal_Int32>(m_aStringItems.size()) ))
)
return;
m_aStringItems.erase(m_aStringItems.begin() + _rEvent.Position,
m_aStringItems.begin() + _rEvent.Position + _rEvent.Count );
if (_rEvent.Position + _rEvent.Count <= m_aTypedItems.getLength())
{
Sequence<Any> aTmp( m_aTypedItems.getLength() - _rEvent.Count );
auto aTmpRange = asNonConstRange(aTmp);
sal_Int32 nStop = _rEvent.Position;
sal_Int32 i = 0;
for ( ; i < nStop; ++i)
{
aTmpRange[i] = m_aTypedItems[i];
}
nStop = aTmp.getLength();
for (sal_Int32 j = _rEvent.Position + _rEvent.Count; i < nStop; ++i, ++j)
{
aTmpRange[i] = m_aTypedItems[j];
}
m_aTypedItems = std::move(aTmp);
}
else if (m_aTypedItems.hasElements())
{
m_aTypedItems = Sequence<Any>(); // doesn't match anymore
}
stringItemListChanged( aLock );
}
void SAL_CALL OEntryListHelper::allEntriesChanged( const EventObject& _rEvent )
{
ControlModelLock aLock( m_rControlModel );
OSL_ENSURE( _rEvent.Source == m_xListSource,
"OEntryListHelper::allEntriesChanged: where did this come from?" );
if ( _rEvent.Source == m_xListSource )
{
impl_lock_refreshList( aLock );
}
}
// XRefreshable
void SAL_CALL OEntryListHelper::addRefreshListener(const Reference<XRefreshListener>& _rxListener)
{
if ( _rxListener.is() )
m_aRefreshListeners.addInterface( _rxListener );
}
void SAL_CALL OEntryListHelper::removeRefreshListener(const Reference<XRefreshListener>& _rxListener)
{
if ( _rxListener.is() )
m_aRefreshListeners.removeInterface( _rxListener );
}
void SAL_CALL OEntryListHelper::refresh()
{
{
ControlModelLock aLock( m_rControlModel );
impl_lock_refreshList( aLock );
}
EventObject aEvt( static_cast< XRefreshable* >( this ) );
m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt );
}
void OEntryListHelper::impl_lock_refreshList( ControlModelLock& _rInstanceLock )
{
if ( hasExternalListSource() )
obtainListSourceEntries( _rInstanceLock );
else
refreshInternalEntryList();
}
bool OEntryListHelper::handleDisposing( const EventObject& _rEvent )
{
if ( m_xListSource .is() && ( _rEvent.Source == m_xListSource ) )
{
disconnectExternalListSource( );
return true;
}
return false;
}
void OEntryListHelper::disposing( )
{
EventObject aEvt( static_cast< XRefreshable* >( this ) );
m_aRefreshListeners.disposeAndClear(aEvt);
if ( hasExternalListSource( ) )
disconnectExternalListSource( );
}
void OEntryListHelper::disconnectExternalListSource( )
{
if ( m_xListSource.is() )
m_xListSource->removeListEntryListener( this );
m_xListSource.clear();
}
void OEntryListHelper::connectExternalListSource( const Reference< XListEntrySource >& _rxSource, ControlModelLock& _rInstanceLock )
{
OSL_ENSURE( !hasExternalListSource(), "OEntryListHelper::connectExternalListSource: only to be called if no external source is active!" );
OSL_ENSURE( _rxSource.is(), "OEntryListHelper::connectExternalListSource: invalid list source!" );
// remember it
m_xListSource = _rxSource;
// initially fill our item list
if ( m_xListSource.is() )
{
// be notified when the list changes ...
m_xListSource->addListEntryListener( this );
obtainListSourceEntries( _rInstanceLock );
}
}
void OEntryListHelper::obtainListSourceEntries( ControlModelLock& _rInstanceLock )
{
Reference< XListEntryTypedSource > xTyped;
xTyped.set( m_xListSource, UNO_QUERY);
if (xTyped.is())
{
comphelper::sequenceToContainer( m_aStringItems, xTyped->getAllListEntriesTyped( m_aTypedItems));
}
else
{
comphelper::sequenceToContainer( m_aStringItems, m_xListSource->getAllListEntries());
if (m_aTypedItems.hasElements())
m_aTypedItems = Sequence<Any>();
}
stringItemListChanged( _rInstanceLock );
}
bool OEntryListHelper::convertNewListSourceProperty( Any& _rConvertedValue,
Any& _rOldValue, const Any& _rValue )
{
if ( hasExternalListSource() )
throw IllegalArgumentException( );
// TODO: error message
return ::comphelper::tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, comphelper::containerToSequence(m_aStringItems) );
}
void OEntryListHelper::setNewStringItemList( const css::uno::Any& _rValue, ControlModelLock& _rInstanceLock )
{
OSL_PRECOND( !hasExternalListSource(), "OEntryListHelper::setNewStringItemList: this should never have survived convertNewListSourceProperty!" );
css::uno::Sequence<OUString> aTmp;
OSL_VERIFY( _rValue >>= aTmp );
comphelper::sequenceToContainer(m_aStringItems, aTmp);
if (m_aTypedItems.hasElements())
m_aTypedItems = Sequence<Any>(); // doesn't match anymore
stringItemListChanged( _rInstanceLock );
}
void OEntryListHelper::setNewTypedItemList( const css::uno::Any& _rValue, ControlModelLock& _rInstanceLock )
{
OSL_PRECOND( !hasExternalListSource(), "OEntryListHelper::setNewTypedItemList: this should never have survived convertNewListSourceProperty!" );
if (!(_rValue >>= m_aTypedItems ))
{
OSL_VERIFY(false);
if (m_aTypedItems.hasElements())
m_aTypedItems = Sequence<Any>(); // doesn't match anymore
}
// Sets both properties, assuming that TypedItemList belongs to StringItemList.
stringItemListChanged( _rInstanceLock );
}
} // namespace frm
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */