Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "parametrizedattributedispatcher.hxx"
21 : #include <editeng/editview.hxx>
22 : #include <svl/itemset.hxx>
23 : #include <svl/itempool.hxx>
24 :
25 : #include <svx/svxids.hrc>
26 : #include <sfx2/sfxuno.hxx>
27 : #include <com/sun/star/uno/Sequence.hxx>
28 : #include <com/sun/star/beans/PropertyValue.hpp>
29 :
30 :
31 : namespace frm
32 : {
33 :
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::frame;
37 : using namespace ::com::sun::star::lang;
38 : using namespace ::com::sun::star::util;
39 : using namespace ::com::sun::star::beans;
40 :
41 0 : OParametrizedAttributeDispatcher::OParametrizedAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
42 0 : :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
43 : {
44 0 : }
45 :
46 :
47 0 : OParametrizedAttributeDispatcher::~OParametrizedAttributeDispatcher()
48 : {
49 0 : acquire();
50 0 : dispose();
51 0 : }
52 :
53 :
54 : namespace
55 : {
56 0 : static SfxSlotId lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId )
57 : {
58 0 : switch ( _nSlotId )
59 : {
60 0 : case SID_ATTR_CHAR_LATIN_FONT: return SID_ATTR_CHAR_FONT;
61 0 : case SID_ATTR_CHAR_LATIN_LANGUAGE: return SID_ATTR_CHAR_LANGUAGE;
62 0 : case SID_ATTR_CHAR_LATIN_POSTURE: return SID_ATTR_CHAR_POSTURE;
63 0 : case SID_ATTR_CHAR_LATIN_WEIGHT: return SID_ATTR_CHAR_WEIGHT;
64 0 : case SID_ATTR_CHAR_LATIN_FONTHEIGHT:return SID_ATTR_CHAR_FONTHEIGHT;
65 : }
66 0 : return _nSlotId;
67 : }
68 : }
69 :
70 :
71 0 : void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
72 : {
73 : OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" );
74 0 : if ( !getEditView() )
75 0 : return;
76 :
77 0 : SfxItemSet aEmptySet( const_cast< EditView* >( getEditView() )->GetEmptyItemSet() );
78 0 : Sequence< PropertyValue > aUnoStateDescription;
79 0 : if ( _rState.getItem() )
80 : {
81 0 : aEmptySet.Put( *_rState.getItem() );
82 0 : SfxSlotId nSlotId = aEmptySet.GetPool()->GetSlotId( _rState.getItem()->Which() );
83 0 : TransformItems( nSlotId, aEmptySet, aUnoStateDescription );
84 0 : _rEvent.State <<= aUnoStateDescription;
85 : }
86 : else
87 0 : OAttributeDispatcher::fillFeatureEventFromAttributeState( _rEvent, _rState );
88 : }
89 :
90 :
91 0 : const SfxPoolItem* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
92 : {
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 0 : SfxSlotId nSlotId = lcl_normalizeLatinScriptSlotId( (SfxSlotId)m_nAttributeId );
96 :
97 0 : SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
98 0 : TransformParameters( nSlotId, _rArguments, aParameterSet );
99 :
100 0 : const SfxPoolItem* pArgument = NULL;
101 0 : if ( aParameterSet.Count() )
102 : {
103 : OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
104 0 : WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhich( nSlotId );
105 0 : pArgument = aParameterSet.GetItem( nAttributeWhich );
106 : OSL_ENSURE( pArgument, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
107 : }
108 :
109 0 : return pArgument;
110 : }
111 :
112 :
113 0 : void SAL_CALL OParametrizedAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException, std::exception)
114 : {
115 0 : ::osl::MutexGuard aGuard( m_aMutex );
116 : OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
117 : (void)_rURL;
118 0 : if ( m_pMasterDispatcher )
119 : {
120 0 : const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( _rArguments );
121 0 : m_pMasterDispatcher->executeAttribute( m_nAttributeId, pConvertedArgument );
122 0 : }
123 0 : }
124 :
125 :
126 : } // namespace frm
127 :
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|