1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_forms.hxx" 30 #include "parametrizedattributedispatcher.hxx" 31 #include <editeng/editview.hxx> 32 #include <svl/itemset.hxx> 33 #include <svl/itempool.hxx> 34 35 #ifndef _SVX_SVXIDS_HRC 36 #include <svx/svxids.hrc> 37 #endif 38 #include <sfx2/sfxuno.hxx> 39 #include <com/sun/star/uno/Sequence.hxx> 40 #include <com/sun/star/beans/PropertyValue.hpp> 41 42 //........................................................................ 43 namespace frm 44 { 45 //........................................................................ 46 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::frame; 49 using namespace ::com::sun::star::lang; 50 using namespace ::com::sun::star::util; 51 using namespace ::com::sun::star::beans; 52 53 //==================================================================== 54 //= OParametrizedAttributeDispatcher 55 //==================================================================== 56 //-------------------------------------------------------------------- 57 OParametrizedAttributeDispatcher::OParametrizedAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher ) 58 :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher ) 59 { 60 } 61 62 //-------------------------------------------------------------------- 63 OParametrizedAttributeDispatcher::~OParametrizedAttributeDispatcher() 64 { 65 acquire(); 66 dispose(); 67 } 68 69 //-------------------------------------------------------------------- 70 namespace 71 { 72 static SfxSlotId lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId ) 73 { 74 switch ( _nSlotId ) 75 { 76 case SID_ATTR_CHAR_LATIN_FONT: return SID_ATTR_CHAR_FONT; 77 case SID_ATTR_CHAR_LATIN_LANGUAGE: return SID_ATTR_CHAR_LANGUAGE; 78 case SID_ATTR_CHAR_LATIN_POSTURE: return SID_ATTR_CHAR_POSTURE; 79 case SID_ATTR_CHAR_LATIN_WEIGHT: return SID_ATTR_CHAR_WEIGHT; 80 case SID_ATTR_CHAR_LATIN_FONTHEIGHT:return SID_ATTR_CHAR_FONTHEIGHT; 81 } 82 return _nSlotId; 83 } 84 } 85 86 //-------------------------------------------------------------------- 87 void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const 88 { 89 OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" ); 90 if ( !getEditView() ) 91 return; 92 93 SfxItemSet aEmptySet( const_cast< EditView* >( getEditView() )->GetEmptyItemSet() ); 94 Sequence< PropertyValue > aUnoStateDescription; 95 if ( _rState.getItem() ) 96 { 97 aEmptySet.Put( *_rState.getItem() ); 98 SfxSlotId nSlotId = aEmptySet.GetPool()->GetSlotId( _rState.getItem()->Which() ); 99 TransformItems( nSlotId, aEmptySet, aUnoStateDescription ); 100 _rEvent.State <<= aUnoStateDescription; 101 } 102 else 103 OAttributeDispatcher::fillFeatureEventFromAttributeState( _rEvent, _rState ); 104 } 105 106 //-------------------------------------------------------------------- 107 const SfxPoolItem* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments ) 108 { 109 // get the real slot id. This may differ from our attribute id: for instance, both 110 // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id 111 SfxSlotId nSlotId = lcl_normalizeLatinScriptSlotId( (SfxSlotId)m_nAttributeId ); 112 113 SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() ); 114 TransformParameters( nSlotId, _rArguments, aParameterSet ); 115 116 const SfxPoolItem* pArgument = NULL; 117 if ( aParameterSet.Count() ) 118 { 119 OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" ); 120 WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhich( nSlotId ); 121 pArgument = aParameterSet.GetItem( nAttributeWhich ); 122 OSL_ENSURE( pArgument, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" ); 123 } 124 125 return pArgument; 126 } 127 128 //-------------------------------------------------------------------- 129 void SAL_CALL OParametrizedAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException) 130 { 131 ::osl::MutexGuard aGuard( m_aMutex ); 132 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" ); 133 (void)_rURL; 134 if ( m_pMasterDispatcher ) 135 { 136 const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( _rArguments ); 137 m_pMasterDispatcher->executeAttribute( m_nAttributeId, pConvertedArgument ); 138 } 139 } 140 141 //........................................................................ 142 } // namespace frm 143 //........................................................................ 144