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