1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef CHART_ITEMCONVERTER_HXX
29 #define CHART_ITEMCONVERTER_HXX
31 #include <unotools/eventlisteneradapter.hxx>
32 #include <svl/itempool.hxx>
33 #include <svl/itemset.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
42 /** This class serves for conversion between properties of an XPropertySet and
43 SfxItems in SfxItemSets.
45 With this helper classes, you can feed dialogs with XPropertySets and let
46 those modify by the dialogs.
48 You must implement GetWhichPairs() such that an SfxItemSet created with
49 CreateEmptyItemSet() is able to hold all items that may be mapped.
51 You also have to implement GetItemProperty(), in order to return the
52 property name for a given which-id together with the corresponding member-id
53 that has to be used for conversion in QueryValue/PutValue.
55 FillSpecialItem and ApplySpecialItem may be used for special handling of
56 individual item, e.g. if you need member-ids in QueryValue/PutValue
58 A typical use could be the following:
60 ::comphelper::ChartTypeItemConverter aItemConverter( xPropertySet, GetItemPool() );
61 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
62 aItemConverter.FillItemSet( aItemSet );
63 bool bChanged = false;
65 MyDialog aDlg( aItemSet );
66 if( aDlg.Execute() == RET_OK )
68 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
70 bChanged = aItemConverter.ApplyItemSet( *pOutItemSet );
75 [ apply model changes to view ]
79 public ::utl::OEventListenerAdapter
82 /** Construct an item converter that uses the given property set for
83 reading/writing converted items
86 const ::com::sun::star::uno::Reference
<
87 ::com::sun::star::beans::XPropertySet
> & rPropertySet
,
88 SfxItemPool
& rItemPool
);
89 virtual ~ItemConverter();
91 // typedefs -------------------------------
93 typedef sal_uInt16 tWhichIdType
;
94 typedef ::rtl::OUString tPropertyNameType
;
95 typedef sal_uInt8 tMemberIdType
;
97 typedef ::std::pair
< tPropertyNameType
, tMemberIdType
> tPropertyNameWithMemberId
;
99 // ----------------------------------------
101 /** applies all properties that can be mapped to items into the given item
104 Call this method before opening a dialog.
107 the SfxItemSet is filled with all items that are a result of a
108 conversion from a property of the internal XPropertySet.
110 virtual void FillItemSet( SfxItemSet
& rOutItemSet
) const;
112 /** applies all properties that are results of a conversion from all items
113 in rItemSet to the internal XPropertySet.
115 Call this method after a dialog was closed with OK
117 @return true, if any properties have been changed, false otherwise.
119 virtual bool ApplyItemSet( const SfxItemSet
& rItemSet
);
121 /** creates an empty item set using the given pool or a common pool if empty
122 (see GetItemPool) and allowing all items given in the ranges returned by
125 SfxItemSet
CreateEmptyItemSet() const;
127 /** Invalidates all items in rDestSet, that are set (state SFX_ITEM_SET) in
128 both item sets (rDestSet and rSourceSet) and have differing content.
130 static void InvalidateUnequalItems( SfxItemSet
&rDestSet
, const SfxItemSet
&rSourceSet
);
135 /** implement this method to provide an array of which-ranges of the form:
137 const sal_uInt16 aMyPairs[] =
146 virtual const sal_uInt16
* GetWhichPairs() const = 0;
148 /** implement this method to return a Property object for a given which id.
151 If true is returned, this contains the property name and the
152 corresponding Member-Id.
154 @return true, if the item can be mapped to a property.
156 virtual bool GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const = 0;
158 /** for items that can not be mapped directly to a property.
160 This method is called from FillItemSet(), if GetItemProperty() returns
163 The default implementation does nothing except showing an assertion
165 virtual void FillSpecialItem( sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
166 throw( ::com::sun::star::uno::Exception
);
168 /** for items that can not be mapped directly to a property.
170 This method is called from ApplyItemSet(), if GetItemProperty() returns
173 The default implementation returns just false and shows an assertion
175 @return true if the item changed a property, false otherwise.
177 virtual bool ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
178 throw( ::com::sun::star::uno::Exception
);
183 SfxItemPool
& GetItemPool() const;
185 /** Returns the XPropertySet that was given in the CTOR and is used to apply
186 items in ApplyItemSet().
188 ::com::sun::star::uno::Reference
<
189 ::com::sun::star::beans::XPropertySet
> GetPropertySet() const;
191 // ____ ::utl::OEventListenerAdapter ____
192 virtual void _disposing( const ::com::sun::star::lang::EventObject
& rSource
);
195 /** sets a new property set, that you get with GetPropertySet(). It should
196 not be necessary to use this method. It is introduced to allow changing
197 the regression type of a regression curve which changes the object
200 void resetPropertySet( const ::com::sun::star::uno::Reference
<
201 ::com::sun::star::beans::XPropertySet
> & xPropSet
);
204 ::com::sun::star::uno::Reference
<
205 ::com::sun::star::beans::XPropertySet
> m_xPropertySet
;
206 ::com::sun::star::uno::Reference
<
207 ::com::sun::star::beans::XPropertySetInfo
> m_xPropertySetInfo
;
209 SfxItemPool
& m_rItemPool
;
213 } // namespace comphelper
215 // CHART_ITEMCONVERTER_HXX
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */