1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "parametrizedattributedispatcher.hxx"
21 #include <editeng/editids.hrc>
22 #include <editeng/editview.hxx>
23 #include <svl/itemset.hxx>
24 #include <svl/itempool.hxx>
25 #include <osl/diagnose.h>
27 #include <sfx2/sfxuno.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/beans/PropertyValue.hpp>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::frame
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::beans
;
42 OParametrizedAttributeDispatcher::OParametrizedAttributeDispatcher( EditView
& _rView
, AttributeId _nAttributeId
, const URL
& _rURL
, IMultiAttributeDispatcher
* _pMasterDispatcher
)
43 :OAttributeDispatcher( _rView
, _nAttributeId
, _rURL
, _pMasterDispatcher
)
48 OParametrizedAttributeDispatcher::~OParametrizedAttributeDispatcher()
57 SfxSlotId
lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId
)
61 case SID_ATTR_CHAR_LATIN_FONT
: return SID_ATTR_CHAR_FONT
;
62 case SID_ATTR_CHAR_LATIN_LANGUAGE
: return SID_ATTR_CHAR_LANGUAGE
;
63 case SID_ATTR_CHAR_LATIN_POSTURE
: return SID_ATTR_CHAR_POSTURE
;
64 case SID_ATTR_CHAR_LATIN_WEIGHT
: return SID_ATTR_CHAR_WEIGHT
;
65 case SID_ATTR_CHAR_LATIN_FONTHEIGHT
:return SID_ATTR_CHAR_FONTHEIGHT
;
72 void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent
& _rEvent
, const AttributeState
& _rState
) const
74 OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" );
78 SfxItemSet
aEmptySet(getEditView()->GetEmptyItemSet());
79 Sequence
< PropertyValue
> aUnoStateDescription
;
80 if ( _rState
.getItem() )
82 aEmptySet
.Put( *_rState
.getItem() );
83 SfxSlotId nSlotId
= aEmptySet
.GetPool()->GetSlotId( _rState
.getItem()->Which() );
84 TransformItems( nSlotId
, aEmptySet
, aUnoStateDescription
);
85 _rEvent
.State
<<= aUnoStateDescription
;
88 OAttributeDispatcher::fillFeatureEventFromAttributeState( _rEvent
, _rState
);
92 const SfxPoolItem
* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence
< PropertyValue
>& _rArguments
)
94 // get the real slot id. This may differ from our attribute id: for instance, both
95 // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id
96 SfxSlotId nSlotId
= lcl_normalizeLatinScriptSlotId( static_cast<SfxSlotId
>(m_nAttributeId
) );
98 SfxAllItemSet
aParameterSet( getEditView()->GetEmptyItemSet() );
99 TransformParameters( nSlotId
, _rArguments
, aParameterSet
);
101 const SfxPoolItem
* pArgument
= nullptr;
102 if ( aParameterSet
.Count() )
104 OSL_ENSURE( aParameterSet
.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
105 WhichId nAttributeWhich
= aParameterSet
.GetPool()->GetWhich( nSlotId
);
106 pArgument
= aParameterSet
.GetItem( nAttributeWhich
);
107 OSL_ENSURE( pArgument
, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
114 void SAL_CALL
OParametrizedAttributeDispatcher::dispatch( const URL
& _rURL
, const Sequence
< PropertyValue
>& _rArguments
)
116 ::osl::MutexGuard
aGuard( m_aMutex
);
117 OSL_ENSURE( _rURL
.Complete
== getFeatureURL().Complete
, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
118 if ( m_pMasterDispatcher
)
120 const SfxPoolItem
* pConvertedArgument
= convertDispatchArgsToItem( _rArguments
);
121 m_pMasterDispatcher
->executeAttribute( m_nAttributeId
, pConvertedArgument
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */