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