tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / forms / source / richtext / parametrizedattributedispatcher.cxx
bloba86441cd87dd94e70d809592c85cb6276ff50312
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
32 namespace frm
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::frame;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::beans;
41 OParametrizedAttributeDispatcher::OParametrizedAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
42 :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
47 OParametrizedAttributeDispatcher::~OParametrizedAttributeDispatcher()
49 acquire();
50 dispose();
54 namespace
56 SfxSlotId lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId )
58 switch ( _nSlotId )
60 case SID_ATTR_CHAR_LATIN_FONT: return SID_ATTR_CHAR_FONT;
61 case SID_ATTR_CHAR_LATIN_LANGUAGE: return SID_ATTR_CHAR_LANGUAGE;
62 case SID_ATTR_CHAR_LATIN_POSTURE: return SID_ATTR_CHAR_POSTURE;
63 case SID_ATTR_CHAR_LATIN_WEIGHT: return SID_ATTR_CHAR_WEIGHT;
64 case SID_ATTR_CHAR_LATIN_FONTHEIGHT:return SID_ATTR_CHAR_FONTHEIGHT;
66 return _nSlotId;
71 void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
73 OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" );
74 if ( !getEditView() )
75 return;
77 SfxItemSet aEmptySet(getEditView()->GetEmptyItemSet());
78 Sequence< PropertyValue > aUnoStateDescription;
79 if ( _rState.getItem() )
81 aEmptySet.Put( *_rState.getItem() );
82 SfxSlotId nSlotId = aEmptySet.GetPool()->GetSlotId( _rState.getItem()->Which() );
83 TransformItems( nSlotId, aEmptySet, aUnoStateDescription );
84 _rEvent.State <<= aUnoStateDescription;
86 else
87 OAttributeDispatcher::fillFeatureEventFromAttributeState( _rEvent, _rState );
91 SfxPoolItemHolder OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
93 // get the real slot id. This may differ from our attribute id: for instance, both
94 // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id
95 SfxSlotId nSlotId = lcl_normalizeLatinScriptSlotId( static_cast<SfxSlotId>(m_nAttributeId) );
97 SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
98 TransformParameters( nSlotId, _rArguments, aParameterSet );
100 if ( aParameterSet.Count() )
102 OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
103 WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhichIDFromSlotID( nSlotId );
104 SfxPoolItemHolder aArgument(*aParameterSet.GetPool(), aParameterSet.GetItem(nAttributeWhich));
105 OSL_ENSURE( aArgument.getItem(), "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
106 return aArgument;
109 return SfxPoolItemHolder();
113 void SAL_CALL OParametrizedAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments )
115 ::osl::MutexGuard aGuard( m_aMutex );
116 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
117 if ( m_pMasterDispatcher )
119 const SfxPoolItemHolder aConvertedArgument(convertDispatchArgsToItem(_rArguments));
120 m_pMasterDispatcher->executeAttribute(m_nAttributeId, aConvertedArgument.getItem());
125 } // namespace frm
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */