LibreOffice Module forms (master) 1
parametrizedattributedispatcher.cxx
Go to the documentation of this file.
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
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>
26
27#include <sfx2/sfxuno.hxx>
28#include <com/sun/star/uno/Sequence.hxx>
29#include <com/sun/star/beans/PropertyValue.hpp>
30
31
32namespace frm
33{
34
35
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::frame;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::util;
40 using namespace ::com::sun::star::beans;
41
43 :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
44 {
45 }
46
47
49 {
50 acquire();
51 dispose();
52 }
53
54
55 namespace
56 {
57 SfxSlotId lcl_normalizeLatinScriptSlotId( SfxSlotId _nSlotId )
58 {
59 switch ( _nSlotId )
60 {
61 case SID_ATTR_CHAR_LATIN_FONT: return SID_ATTR_CHAR_FONT;
62 case SID_ATTR_CHAR_LATIN_LANGUAGE: return SID_ATTR_CHAR_LANGUAGE;
63 case SID_ATTR_CHAR_LATIN_POSTURE: return SID_ATTR_CHAR_POSTURE;
64 case SID_ATTR_CHAR_LATIN_WEIGHT: return SID_ATTR_CHAR_WEIGHT;
65 case SID_ATTR_CHAR_LATIN_FONTHEIGHT:return SID_ATTR_CHAR_FONTHEIGHT;
66 }
67 return _nSlotId;
68 }
69 }
70
71
72 void OParametrizedAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
73 {
74 OSL_ENSURE( getEditView(), "OParametrizedAttributeDispatcher::notifyState: already disposed!" );
75 if ( !getEditView() )
76 return;
77
78 SfxItemSet aEmptySet(getEditView()->GetEmptyItemSet());
79 Sequence< PropertyValue > aUnoStateDescription;
80 if ( _rState.getItem() )
81 {
82 aEmptySet.Put( *_rState.getItem() );
83 SfxSlotId nSlotId = aEmptySet.GetPool()->GetSlotId( _rState.getItem()->Which() );
84 TransformItems( nSlotId, aEmptySet, aUnoStateDescription );
85 _rEvent.State <<= aUnoStateDescription;
86 }
87 else
89 }
90
91
92 const SfxPoolItem* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
93 {
94 // get the real slot id. This may differ from our attribute id: for instance, both
95 // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id
96 SfxSlotId nSlotId = lcl_normalizeLatinScriptSlotId( static_cast<SfxSlotId>(m_nAttributeId) );
97
98 SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
99 TransformParameters( nSlotId, _rArguments, aParameterSet );
100
101 const SfxPoolItem* pArgument = nullptr;
102 if ( aParameterSet.Count() )
103 {
104 OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
105 WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhich( nSlotId );
106 pArgument = aParameterSet.GetItem( nAttributeWhich );
107 OSL_ENSURE( pArgument, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
108 }
109
110 return pArgument;
111 }
112
113
114 void SAL_CALL OParametrizedAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments )
115 {
116 ::osl::MutexGuard aGuard( m_aMutex );
117 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
119 {
120 const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( _rArguments );
122 }
123 }
124
125
126} // namespace frm
127
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
sal_uInt16 Count() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 Which() const
mutable::osl::Mutex m_aMutex
virtual void executeAttribute(AttributeId _nAttributeId, const SfxPoolItem *_pArgument)=0
virtual void fillFeatureEventFromAttributeState(css::frame::FeatureStateEvent &_rEvent, const AttributeState &_rState) const
IMultiAttributeDispatcher * m_pMasterDispatcher
virtual void SAL_CALL dispatch(const css::util::URL &URL, const css::uno::Sequence< css::beans::PropertyValue > &Arguments) override
OParametrizedAttributeDispatcher(EditView &_rView, AttributeId _nAttributeId, const css::util::URL &_rURL, IMultiAttributeDispatcher *_pMasterDispatcher)
virtual const SfxPoolItem * convertDispatchArgsToItem(const css::uno::Sequence< css::beans::PropertyValue > &_rArguments)
convert the arguments as got in a XDispatch::dispatch call into an SfxPoolItem, which can be used wit...
virtual void fillFeatureEventFromAttributeState(css::frame::FeatureStateEvent &_rEvent, const AttributeState &_rState) const override
const css::util::URL & getFeatureURL() const
void dispose()
clean up resources associated with this instance
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
sal_uInt16 WhichId
the "which id" of an item in an SfxItemSet
sal_uInt16 SfxSlotId
a SFX slot id
sal_Int32 AttributeId
the id of an attribute
SFX2_DLLPUBLIC void TransformParameters(sal_uInt16 nSlotId, const css::uno::Sequence< css::beans::PropertyValue > &seqArgs, SfxAllItemSet &aSet, const SfxSlot *pSlot=nullptr)
SFX2_DLLPUBLIC void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &aSet, css::uno::Sequence< css::beans::PropertyValue > &seqArgs, const SfxSlot *pSlot=nullptr)
const SfxPoolItem * getItem() const