1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "parametrizedattributedispatcher.hxx"
27cdf0e10cSrcweir #include <editeng/editview.hxx>
28cdf0e10cSrcweir #include <svl/itemset.hxx>
29cdf0e10cSrcweir #include <svl/itempool.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
32cdf0e10cSrcweir #include <svx/svxids.hrc>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
35cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //........................................................................
39cdf0e10cSrcweir namespace frm
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
45cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir     using namespace ::com::sun::star::util;
47cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     //====================================================================
50cdf0e10cSrcweir 	//= OParametrizedAttributeDispatcher
51cdf0e10cSrcweir 	//====================================================================
52cdf0e10cSrcweir 	//--------------------------------------------------------------------
OParametrizedAttributeDispatcher(EditView & _rView,AttributeId _nAttributeId,const URL & _rURL,IMultiAttributeDispatcher * _pMasterDispatcher)53cdf0e10cSrcweir     OParametrizedAttributeDispatcher::OParametrizedAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
54cdf0e10cSrcweir         :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//--------------------------------------------------------------------
~OParametrizedAttributeDispatcher()59cdf0e10cSrcweir     OParametrizedAttributeDispatcher::~OParametrizedAttributeDispatcher()
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         acquire();
62cdf0e10cSrcweir         dispose();
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     //--------------------------------------------------------------------
66cdf0e10cSrcweir     namespace
67cdf0e10cSrcweir     {
lcl_normalizeLatinScriptSlotId(SfxSlotId _nSlotId)68cdf0e10cSrcweir         static SfxSlotId lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId )
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             switch ( _nSlotId )
71cdf0e10cSrcweir             {
72cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_FONT:      return SID_ATTR_CHAR_FONT;
73cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_LANGUAGE:  return SID_ATTR_CHAR_LANGUAGE;
74cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_POSTURE:   return SID_ATTR_CHAR_POSTURE;
75cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_WEIGHT:    return SID_ATTR_CHAR_WEIGHT;
76cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_FONTHEIGHT:return SID_ATTR_CHAR_FONTHEIGHT;
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir             return _nSlotId;
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     //--------------------------------------------------------------------
fillFeatureEventFromAttributeState(FeatureStateEvent & _rEvent,const AttributeState & _rState) const83cdf0e10cSrcweir     void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" );
86cdf0e10cSrcweir         if ( !getEditView() )
87cdf0e10cSrcweir             return;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         SfxItemSet aEmptySet( const_cast< EditView* >( getEditView() )->GetEmptyItemSet() );
90cdf0e10cSrcweir         Sequence< PropertyValue > aUnoStateDescription;
91cdf0e10cSrcweir         if ( _rState.getItem() )
92cdf0e10cSrcweir         {
93cdf0e10cSrcweir             aEmptySet.Put( *_rState.getItem() );
94cdf0e10cSrcweir             SfxSlotId nSlotId = aEmptySet.GetPool()->GetSlotId( _rState.getItem()->Which() );
95cdf0e10cSrcweir             TransformItems( nSlotId, aEmptySet, aUnoStateDescription );
96cdf0e10cSrcweir             _rEvent.State <<= aUnoStateDescription;
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         else
99cdf0e10cSrcweir             OAttributeDispatcher::fillFeatureEventFromAttributeState( _rEvent, _rState );
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	//--------------------------------------------------------------------
convertDispatchArgsToItem(const Sequence<PropertyValue> & _rArguments)103cdf0e10cSrcweir     const SfxPoolItem* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         // get the real slot id. This may differ from our attribute id: for instance, both
106cdf0e10cSrcweir         // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id
107cdf0e10cSrcweir         SfxSlotId nSlotId = lcl_normalizeLatinScriptSlotId( (SfxSlotId)m_nAttributeId );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
110cdf0e10cSrcweir         TransformParameters( nSlotId, _rArguments, aParameterSet );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         const SfxPoolItem* pArgument = NULL;
113cdf0e10cSrcweir         if ( aParameterSet.Count() )
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
116cdf0e10cSrcweir             WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhich( nSlotId );
117cdf0e10cSrcweir             pArgument = aParameterSet.GetItem( nAttributeWhich );
118cdf0e10cSrcweir             OSL_ENSURE( pArgument, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         return pArgument;
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	//--------------------------------------------------------------------
dispatch(const URL & _rURL,const Sequence<PropertyValue> & _rArguments)125cdf0e10cSrcweir     void SAL_CALL OParametrizedAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
128cdf0e10cSrcweir         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
129cdf0e10cSrcweir         (void)_rURL;
130cdf0e10cSrcweir         if ( m_pMasterDispatcher )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( _rArguments );
133cdf0e10cSrcweir             m_pMasterDispatcher->executeAttribute( m_nAttributeId, pConvertedArgument );
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //........................................................................
138cdf0e10cSrcweir }   // namespace frm
139cdf0e10cSrcweir //........................................................................
140