1*353d8f4dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*353d8f4dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*353d8f4dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*353d8f4dSAndrew Rist * distributed with this work for additional information
6*353d8f4dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*353d8f4dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*353d8f4dSAndrew Rist * "License"); you may not use this file except in compliance
9*353d8f4dSAndrew Rist * with the License. You may obtain a copy of the License at
10*353d8f4dSAndrew Rist *
11*353d8f4dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*353d8f4dSAndrew Rist *
13*353d8f4dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*353d8f4dSAndrew Rist * software distributed under the License is distributed on an
15*353d8f4dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*353d8f4dSAndrew Rist * KIND, either express or implied. See the License for the
17*353d8f4dSAndrew Rist * specific language governing permissions and limitations
18*353d8f4dSAndrew Rist * under the License.
19*353d8f4dSAndrew Rist *
20*353d8f4dSAndrew Rist *************************************************************/
21*353d8f4dSAndrew Rist
22*353d8f4dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef SFX_ITEMCONNECT_HXX
25cdf0e10cSrcweir #define SFX_ITEMCONNECT_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "sal/config.h"
28cdf0e10cSrcweir #include "sfx2/dllapi.h"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <memory>
31cdf0e10cSrcweir #include <sfx2/itemwrapper.hxx>
32cdf0e10cSrcweir #include <sfx2/controlwrapper.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir // ============================================================================
35cdf0e10cSrcweir
36cdf0e10cSrcweir namespace sfx {
37cdf0e10cSrcweir
38cdf0e10cSrcweir // ============================================================================
39cdf0e10cSrcweir
40cdf0e10cSrcweir typedef int ItemConnFlags;
41cdf0e10cSrcweir
42cdf0e10cSrcweir /** No special state for the connection. */
43cdf0e10cSrcweir const ItemConnFlags ITEMCONN_NONE = 0x0000;
44cdf0e10cSrcweir
45cdf0e10cSrcweir /** Connection is inactive - virtual functions will not be called. */
46cdf0e10cSrcweir const ItemConnFlags ITEMCONN_INACTIVE = 0x0001;
47cdf0e10cSrcweir /** Clone item in FillItemSet() from old item set. */
48cdf0e10cSrcweir //const ItemConnFlags ITEMCONN_CLONE_ITEM = 0x0002;
49cdf0e10cSrcweir
50cdf0e10cSrcweir /** Enable control(s), if the item is known. */
51cdf0e10cSrcweir const ItemConnFlags ITEMCONN_ENABLE_KNOWN = 0x0010;
52cdf0e10cSrcweir /** Disable control(s), if the item is unknown. */
53cdf0e10cSrcweir const ItemConnFlags ITEMCONN_DISABLE_UNKNOWN = 0x0020;
54cdf0e10cSrcweir /** Show control(s), if the item is known. */
55cdf0e10cSrcweir const ItemConnFlags ITEMCONN_SHOW_KNOWN = 0x0040;
56cdf0e10cSrcweir /** Hide control(s), if the item is unknown. */
57cdf0e10cSrcweir const ItemConnFlags ITEMCONN_HIDE_UNKNOWN = 0x0080;
58cdf0e10cSrcweir
59cdf0e10cSrcweir /** Default value for constructors. */
60cdf0e10cSrcweir const ItemConnFlags ITEMCONN_DEFAULT = ITEMCONN_NONE;
61cdf0e10cSrcweir
62cdf0e10cSrcweir // ============================================================================
63cdf0e10cSrcweir // Base connection classes
64cdf0e10cSrcweir // ============================================================================
65cdf0e10cSrcweir
66cdf0e10cSrcweir /** A helper for SfxTabPages to connect controls to items.
67cdf0e10cSrcweir
68cdf0e10cSrcweir This is the base class of all control connection classes. Their purpose is
69cdf0e10cSrcweir to connect one or more controls from an SfxTabPage with an item from an
70cdf0e10cSrcweir item set. The goal is to omit any additional code in the virtual functions
71cdf0e10cSrcweir Reset() and FillItemSet() in classes derived from SfxTabPage.
72cdf0e10cSrcweir
73cdf0e10cSrcweir Examples of connections:
74cdf0e10cSrcweir - A check box with an SfxBoolItem,
75cdf0e10cSrcweir - A metric (spin) field with an SfxInt32Item.
76cdf0e10cSrcweir - A group of radio buttons with an SfxEnumItem.
77cdf0e10cSrcweir
78cdf0e10cSrcweir Each SfxTabPage will contain a list of connection objects (derived from
79cdf0e10cSrcweir this class). The connection objects remember the item and control(s) they
80cdf0e10cSrcweir have to work on. The SfxTabPage will call the DoApplyFlags(), DoReset(),
81cdf0e10cSrcweir and DoFillItemSet() functions of all connection objects it knows. The code
82cdf0e10cSrcweir to initialize control(s) from the item value and fill the item from
83cdf0e10cSrcweir control(s) has to be written only once for each control type.
84cdf0e10cSrcweir
85cdf0e10cSrcweir Additional flags passed in the constructor allow to control the behaviour
86cdf0e10cSrcweir of the control(s) if the item is supported/unsupported in the currently
87cdf0e10cSrcweir used item set. For example, it is possible to specify that a control will
88cdf0e10cSrcweir be disabled or hidden if the item is not supported. This is done before
89cdf0e10cSrcweir each call of Reset().
90cdf0e10cSrcweir
91cdf0e10cSrcweir The special flag ITEMCONN_CLONE_ITEM controls how to create new items in
92cdf0e10cSrcweir the DoFillItemSet() function. The standard (and faster) method is to create
93cdf0e10cSrcweir a temporary item on the stack and put it into the item set. But this does
94cdf0e10cSrcweir not work if the item set expects a special item type derived from a common
95cdf0e10cSrcweir item class, i.e. a Boolean item derived from SfxBoolItem providing special
96cdf0e10cSrcweir item representation text. As this code does not know the item type, the
97cdf0e10cSrcweir item cannot be created on the stack. For this case the flag specifies to
98cdf0e10cSrcweir use the virtual Clone() method of the pool default item. This will create
99cdf0e10cSrcweir an item of the correct type but can still be used in conjunction with i.e.
100cdf0e10cSrcweir the standard BoolItemWrapper.
101cdf0e10cSrcweir
102cdf0e10cSrcweir How to use the item connection feature:
103cdf0e10cSrcweir
104cdf0e10cSrcweir A) Single item <-> single control connection
105cdf0e10cSrcweir
106cdf0e10cSrcweir Example: An SfxBoolItem and a check box.
107cdf0e10cSrcweir
108cdf0e10cSrcweir A1) Create a new item wrapper class derived from the SingleItemWrapper
109cdf0e10cSrcweir template, or use the template directly, or use one of the
110cdf0e10cSrcweir predefined item wrappers. See documentation of the
111cdf0e10cSrcweir SingleItemWrapper template for details (itemwrapper.hxx).
112cdf0e10cSrcweir A2) Create a new control wrapper class derived from the
113cdf0e10cSrcweir SingleControlWrapper template and implement the abstract functions,
114cdf0e10cSrcweir or use one of the predefined control wrappers. See documentation of
115cdf0e10cSrcweir the SingleControlWrapper template for details (controlwrapper.hxx).
116cdf0e10cSrcweir A3) Create a new connection class derived from one of the following
117cdf0e10cSrcweir base classes, and implement the abstract functions, or use the
118cdf0e10cSrcweir ItemControlConnection template directly, or use one of the
119cdf0e10cSrcweir predefined connections.
120cdf0e10cSrcweir A4) Create connection objects in the constructor of the tab page, and
121cdf0e10cSrcweir insert them into the tab page with SfxTabPage::AddItemConnection().
122cdf0e10cSrcweir A5) Remove old code from the tab page's Reset() and FillItemSet()
123cdf0e10cSrcweir functions, if necessary.
124cdf0e10cSrcweir
125cdf0e10cSrcweir B) Single item <-> multiple controls connections
126cdf0e10cSrcweir
127cdf0e10cSrcweir B1) See step A1. If the item contains multiple values (and not a
128cdf0e10cSrcweir structure that contains all the values for the different controls),
129cdf0e10cSrcweir the best way is to use the IdentItemWrapper template, that works
130cdf0e10cSrcweir with the item itself. This way it is possible to provide a 'data
131cdf0e10cSrcweir type' that contains the values for all controls.
132cdf0e10cSrcweir B2) Create a new control wrapper class derived from the
133cdf0e10cSrcweir MultiControlWrapper template. Add single control wrapper members
134cdf0e10cSrcweir for all controls to this class and register them in the
135cdf0e10cSrcweir constructor, using the RegisterControlWrapper() function. Implement
136cdf0e10cSrcweir the abstract functions GetControlValue() and SetControlValue().
137cdf0e10cSrcweir These functions should call the respective functions of the own
138cdf0e10cSrcweir single control wrappers and either fill a new data object (the item
139cdf0e10cSrcweir itself in most cases, see step B1) with all the values from the
140cdf0e10cSrcweir controls, or fill all the controls from the data object.
141cdf0e10cSrcweir B3) Create a new connection class derived from ItemControlConnection,
142cdf0e10cSrcweir or use the ItemControlConnection template directly. The multiple
143cdf0e10cSrcweir control wrapper from step B2 acts like a single control, therefore
144cdf0e10cSrcweir it is possible to use the ItemControlConnection.
145cdf0e10cSrcweir B4) See steps A4 and A5.
146cdf0e10cSrcweir
147cdf0e10cSrcweir C) Multiple items <-> single control connections
148cdf0e10cSrcweir
149cdf0e10cSrcweir todo
150cdf0e10cSrcweir
151cdf0e10cSrcweir D) Multiple items <-> multiple controls connections
152cdf0e10cSrcweir
153cdf0e10cSrcweir todo
154cdf0e10cSrcweir
155cdf0e10cSrcweir The current tree of base classes/templates and standard connections:
156cdf0e10cSrcweir
157cdf0e10cSrcweir ItemConnectionBase
158cdf0e10cSrcweir |
159cdf0e10cSrcweir +- DummyItemConnection [1]
160cdf0e10cSrcweir |
161cdf0e10cSrcweir +- ItemControlConnection< ItemWrpT, ControlWrpT >
162cdf0e10cSrcweir | |
163cdf0e10cSrcweir | +- CheckBoxConnection [1]
164cdf0e10cSrcweir | +- EditConnection [1]
165cdf0e10cSrcweir | |
166cdf0e10cSrcweir | +- NumericConnection< ItemWrpT > [1]
167cdf0e10cSrcweir | | |
168cdf0e10cSrcweir | | +- [ValueType]NumericConnection [1] [2]
169cdf0e10cSrcweir | |
170cdf0e10cSrcweir | +- MetricConnection< ItemWrpT > [1]
171cdf0e10cSrcweir | | |
172cdf0e10cSrcweir | | +- [ValueType]MetricConnection [1] [2]
173cdf0e10cSrcweir | |
174cdf0e10cSrcweir | +- ListBoxConnection< ItemWrpT > [1]
175cdf0e10cSrcweir | | |
176cdf0e10cSrcweir | | +- [ValueType]ListBoxConnection [1] [2]
177cdf0e10cSrcweir | |
178cdf0e10cSrcweir | +- ValueSetConnection< ItemWrpT > [1]
179cdf0e10cSrcweir | |
180cdf0e10cSrcweir | +- [ValueType]ValueSetConnection [1] [2]
181cdf0e10cSrcweir |
182cdf0e10cSrcweir +- ItemConnectionArray [1]
183cdf0e10cSrcweir
184cdf0e10cSrcweir Notes:
185cdf0e10cSrcweir [1] Standard connections ready to use.
186cdf0e10cSrcweir [2] [ValueType] is one of Int16, UInt16, Int32, UInt32.
187cdf0e10cSrcweir */
188cdf0e10cSrcweir class SFX2_DLLPUBLIC ItemConnectionBase
189cdf0e10cSrcweir {
190cdf0e10cSrcweir public:
191cdf0e10cSrcweir virtual ~ItemConnectionBase();
192cdf0e10cSrcweir
193cdf0e10cSrcweir /** Returns the flags passed in the constructor. */
GetFlags() const194cdf0e10cSrcweir inline ItemConnFlags GetFlags() const { return mnFlags; }
195cdf0e10cSrcweir
196cdf0e10cSrcweir /** Activates or deactivates this connection.
197cdf0e10cSrcweir @descr Deactivated connections do not execute the virtual functions
198cdf0e10cSrcweir ApplyFlags(), Reset(), and FillItemSet(). */
199cdf0e10cSrcweir void Activate( bool bActive = true );
200cdf0e10cSrcweir /** Returns true if this connection is active. */
201cdf0e10cSrcweir bool IsActive() const;
202cdf0e10cSrcweir
203cdf0e10cSrcweir /** Calls the virtual ApplyFlags() function, if connection is active. */
204cdf0e10cSrcweir void DoApplyFlags( const SfxItemSet& rItemSet );
205cdf0e10cSrcweir /** Calls the virtual Reset() function, if connection is active. */
206cdf0e10cSrcweir void DoReset( const SfxItemSet& rItemSet );
207cdf0e10cSrcweir /** Calls the virtual FillItemSet() function, if connection is active. */
208cdf0e10cSrcweir bool DoFillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
209cdf0e10cSrcweir
210cdf0e10cSrcweir protected:
211cdf0e10cSrcweir explicit ItemConnectionBase( ItemConnFlags nFlags = ITEMCONN_DEFAULT );
212cdf0e10cSrcweir
213cdf0e10cSrcweir /** Derived classes implement actions according to current flags here. */
214cdf0e10cSrcweir virtual void ApplyFlags( const SfxItemSet& rItemSet ) = 0;
215cdf0e10cSrcweir /** Derived classes implement initializing controls from item sets here. */
216cdf0e10cSrcweir virtual void Reset( const SfxItemSet& rItemSet ) = 0;
217cdf0e10cSrcweir /** Derived classes implement filling item sets from controls here. */
218cdf0e10cSrcweir virtual bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet ) = 0;
219cdf0e10cSrcweir
220cdf0e10cSrcweir /** Returns whether to enable a control, according to current flags. */
221cdf0e10cSrcweir TriState GetEnableState( bool bKnown ) const;
222cdf0e10cSrcweir /** Returns whether to show a control, according to current flags. */
223cdf0e10cSrcweir TriState GetShowState( bool bKnown ) const;
224cdf0e10cSrcweir
225cdf0e10cSrcweir private:
226cdf0e10cSrcweir /* Disable copy c'tor and assignment. */
227cdf0e10cSrcweir ItemConnectionBase( const ItemConnectionBase& );
228cdf0e10cSrcweir ItemConnectionBase& operator=( const ItemConnectionBase& );
229cdf0e10cSrcweir
230cdf0e10cSrcweir ItemConnFlags mnFlags; /// Flags for additional options.
231cdf0e10cSrcweir };
232cdf0e10cSrcweir
233cdf0e10cSrcweir // ----------------------------------------------------------------------------
234cdf0e10cSrcweir
235cdf0e10cSrcweir /** Base class template for single item <-> single control connection objects.
236cdf0e10cSrcweir
237cdf0e10cSrcweir This template uses functions provided by the SingleItemWrapper and the
238cdf0e10cSrcweir SingleControlWrapper template classes. The virtual functions ApplyFlags(),
239cdf0e10cSrcweir Reset(), and FillItemSet() are implemented here in a generic way using the
240cdf0e10cSrcweir virtual functions of the wrapper classes. Derived classes only have to
241cdf0e10cSrcweir create or otherwise provide appropriate wrappers.
242cdf0e10cSrcweir */
243cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
244cdf0e10cSrcweir class ItemControlConnection : public ItemConnectionBase
245cdf0e10cSrcweir {
246cdf0e10cSrcweir public:
247cdf0e10cSrcweir typedef ItemWrpT ItemWrapperType;
248cdf0e10cSrcweir typedef ControlWrpT ControlWrapperType;
249cdf0e10cSrcweir typedef ItemControlConnection< ItemWrpT, ControlWrpT > ItemControlConnectionType;
250cdf0e10cSrcweir typedef typename ItemWrpT::ItemType ItemType;
251cdf0e10cSrcweir typedef typename ItemWrpT::ItemValueType ItemValueType;
252cdf0e10cSrcweir typedef typename ControlWrpT::ControlType ControlType;
253cdf0e10cSrcweir typedef typename ControlWrpT::ControlValueType ControlValueType;
254cdf0e10cSrcweir
255cdf0e10cSrcweir typedef std::auto_ptr< ItemWrpT > ItemWrapperRef;
256cdf0e10cSrcweir typedef std::auto_ptr< ControlWrpT > ControlWrapperRef;
257cdf0e10cSrcweir
258cdf0e10cSrcweir /** Receives pointer to a newly created control wrapper.
259cdf0e10cSrcweir @descr Takes ownership of the control wrapper. */
260cdf0e10cSrcweir explicit ItemControlConnection( sal_uInt16 nSlot, ControlWrpT* pNewCtrlWrp,
261cdf0e10cSrcweir ItemConnFlags nFlags = ITEMCONN_DEFAULT );
262cdf0e10cSrcweir
263cdf0e10cSrcweir /** Convenience constructor. Receives reference to a control directly.
264cdf0e10cSrcweir @descr May only be used, if ControlWrpT::ControlWrpT( ControlType& )
265cdf0e10cSrcweir constructor exists. */
266cdf0e10cSrcweir explicit ItemControlConnection( sal_uInt16 nSlot, ControlType& rControl,
267cdf0e10cSrcweir ItemConnFlags nFlags = ITEMCONN_DEFAULT );
268cdf0e10cSrcweir
269cdf0e10cSrcweir virtual ~ItemControlConnection();
270cdf0e10cSrcweir
271cdf0e10cSrcweir protected:
272cdf0e10cSrcweir /** Actions according to current flags for the control. */
273cdf0e10cSrcweir virtual void ApplyFlags( const SfxItemSet& rItemSet );
274cdf0e10cSrcweir /** Resets the control according to the item contents. */
275cdf0e10cSrcweir virtual void Reset( const SfxItemSet& rItemSet );
276cdf0e10cSrcweir /** Fills the item set according to the control's state. */
277cdf0e10cSrcweir virtual bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
278cdf0e10cSrcweir
279cdf0e10cSrcweir ItemWrapperType maItemWrp;
280cdf0e10cSrcweir ControlWrapperRef mxCtrlWrp;
281cdf0e10cSrcweir };
282cdf0e10cSrcweir
283cdf0e10cSrcweir // ============================================================================
284cdf0e10cSrcweir // Standard connections
285cdf0e10cSrcweir // ============================================================================
286cdf0e10cSrcweir
287cdf0e10cSrcweir /** This is a helper class to enable/disable/show/hide a control only.
288cdf0e10cSrcweir
289cdf0e10cSrcweir This class does nothing special in the Reset() and FillItemSet() functions.
290cdf0e10cSrcweir It can be used to control the visibility of i.e. fixed lines or fixed texts
291cdf0e10cSrcweir related to the availability of an item by passing the appropriate flags to
292cdf0e10cSrcweir the constructor of this connection.
293cdf0e10cSrcweir */
294cdf0e10cSrcweir class SFX2_DLLPUBLIC DummyItemConnection:
295cdf0e10cSrcweir public ItemConnectionBase, public DummyWindowWrapper
296cdf0e10cSrcweir {
297cdf0e10cSrcweir public:
298cdf0e10cSrcweir explicit DummyItemConnection( sal_uInt16 nSlot, Window& rWindow,
299cdf0e10cSrcweir ItemConnFlags nFlags = ITEMCONN_DEFAULT );
300cdf0e10cSrcweir
301cdf0e10cSrcweir protected:
302cdf0e10cSrcweir virtual void ApplyFlags( const SfxItemSet& rItemSet );
303cdf0e10cSrcweir virtual void Reset( const SfxItemSet& rItemSet );
304cdf0e10cSrcweir virtual bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
305cdf0e10cSrcweir
306cdf0e10cSrcweir private:
307cdf0e10cSrcweir sal_uInt16 mnSlot;
308cdf0e10cSrcweir };
309cdf0e10cSrcweir
310cdf0e10cSrcweir // ----------------------------------------------------------------------------
311cdf0e10cSrcweir
312cdf0e10cSrcweir /** Connection between an SfxBoolItem and a VCL CheckBox. */
313cdf0e10cSrcweir typedef ItemControlConnection< BoolItemWrapper, CheckBoxWrapper > CheckBoxConnection;
314cdf0e10cSrcweir
315cdf0e10cSrcweir /** Connection between an SfxStringItem and a VCL Edit. */
316cdf0e10cSrcweir typedef ItemControlConnection< StringItemWrapper, EditWrapper > EditConnection;
317cdf0e10cSrcweir
318cdf0e10cSrcweir // ============================================================================
319cdf0e10cSrcweir
320cdf0e10cSrcweir /** Connection between an item and the VCL NumericField. */
321cdf0e10cSrcweir template< typename ItemWrpT >
322cdf0e10cSrcweir class NumericConnection : public ItemControlConnection< ItemWrpT,
323cdf0e10cSrcweir NumericFieldWrapper< typename ItemWrpT::ItemValueType > >
324cdf0e10cSrcweir {
325cdf0e10cSrcweir typedef ItemControlConnection< ItemWrpT,
326cdf0e10cSrcweir NumericFieldWrapper< typename ItemWrpT::ItemValueType > >
327cdf0e10cSrcweir ItemControlConnectionType;
328cdf0e10cSrcweir
329cdf0e10cSrcweir public:
330cdf0e10cSrcweir typedef typename ItemControlConnectionType::ControlWrapperType NumericFieldWrapperType;
331cdf0e10cSrcweir
332cdf0e10cSrcweir explicit NumericConnection( sal_uInt16 nSlot, NumericField& rField,
333cdf0e10cSrcweir ItemConnFlags nFlags = ITEMCONN_DEFAULT );
334cdf0e10cSrcweir };
335cdf0e10cSrcweir
336cdf0e10cSrcweir // ----------------------------------------------------------------------------
337cdf0e10cSrcweir
338cdf0e10cSrcweir typedef NumericConnection< Int16ItemWrapper > Int16NumericConnection;
339cdf0e10cSrcweir typedef NumericConnection< UInt16ItemWrapper > UInt16NumericConnection;
340cdf0e10cSrcweir typedef NumericConnection< Int32ItemWrapper > Int32NumericConnection;
341cdf0e10cSrcweir typedef NumericConnection< UInt32ItemWrapper > UInt32NumericConnection;
342cdf0e10cSrcweir
343cdf0e10cSrcweir // ============================================================================
344cdf0e10cSrcweir
345cdf0e10cSrcweir /** Connection between an item and the VCL MetricField.
346cdf0e10cSrcweir
347cdf0e10cSrcweir Adds support of different field units during control value <-> item value
348cdf0e10cSrcweir conversion. The field unit passed to the constructor applies for the item
349cdf0e10cSrcweir values, while the field unit used in the control has to be set at the
350cdf0e10cSrcweir control itself.
351cdf0e10cSrcweir */
352cdf0e10cSrcweir template< typename ItemWrpT >
353cdf0e10cSrcweir class MetricConnection : public ItemControlConnection< ItemWrpT,
354cdf0e10cSrcweir MetricFieldWrapper< typename ItemWrpT::ItemValueType > >
355cdf0e10cSrcweir {
356cdf0e10cSrcweir typedef ItemControlConnection< ItemWrpT,
357cdf0e10cSrcweir MetricFieldWrapper< typename ItemWrpT::ItemValueType > >
358cdf0e10cSrcweir ItemControlConnectionType;
359cdf0e10cSrcweir
360cdf0e10cSrcweir public:
361cdf0e10cSrcweir typedef typename ItemControlConnectionType::ControlWrapperType MetricFieldWrapperType;
362cdf0e10cSrcweir
363cdf0e10cSrcweir explicit MetricConnection( sal_uInt16 nSlot, MetricField& rField,
364cdf0e10cSrcweir FieldUnit eItemUnit = FUNIT_NONE, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
365cdf0e10cSrcweir };
366cdf0e10cSrcweir
367cdf0e10cSrcweir // ----------------------------------------------------------------------------
368cdf0e10cSrcweir
369cdf0e10cSrcweir typedef MetricConnection< Int16ItemWrapper > Int16MetricConnection;
370cdf0e10cSrcweir typedef MetricConnection< UInt16ItemWrapper > UInt16MetricConnection;
371cdf0e10cSrcweir typedef MetricConnection< Int32ItemWrapper > Int32MetricConnection;
372cdf0e10cSrcweir typedef MetricConnection< UInt32ItemWrapper > UInt32MetricConnection;
373cdf0e10cSrcweir
374cdf0e10cSrcweir // ============================================================================
375cdf0e10cSrcweir
376cdf0e10cSrcweir /** Connection between an item and a VCL ListBox.
377cdf0e10cSrcweir
378cdf0e10cSrcweir Optionally a map can be passed that maps list box positions to item values.
379cdf0e10cSrcweir This map MUST be terminated with an entry containing LISTBOX_ENTRY_NOTFOUND
380cdf0e10cSrcweir as list box position. The item value contained in this last entry is used
381cdf0e10cSrcweir as default item value in case of an error.
382cdf0e10cSrcweir */
383cdf0e10cSrcweir template< typename ItemWrpT >
384cdf0e10cSrcweir class ListBoxConnection : public ItemControlConnection< ItemWrpT,
385cdf0e10cSrcweir ListBoxWrapper< typename ItemWrpT::ItemValueType > >
386cdf0e10cSrcweir {
387cdf0e10cSrcweir typedef ItemControlConnection< ItemWrpT,
388cdf0e10cSrcweir ListBoxWrapper< typename ItemWrpT::ItemValueType > >
389cdf0e10cSrcweir ItemControlConnectionType;
390cdf0e10cSrcweir
391cdf0e10cSrcweir public:
392cdf0e10cSrcweir typedef typename ItemControlConnectionType::ControlWrapperType ListBoxWrapperType;
393cdf0e10cSrcweir typedef typename ListBoxWrapperType::MapEntryType MapEntryType;
394cdf0e10cSrcweir
395cdf0e10cSrcweir explicit ListBoxConnection( sal_uInt16 nSlot, ListBox& rListBox,
396cdf0e10cSrcweir const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
397cdf0e10cSrcweir };
398cdf0e10cSrcweir
399cdf0e10cSrcweir // ----------------------------------------------------------------------------
400cdf0e10cSrcweir
401cdf0e10cSrcweir typedef ListBoxConnection< Int16ItemWrapper > Int16ListBoxConnection;
402cdf0e10cSrcweir typedef ListBoxConnection< UInt16ItemWrapper > UInt16ListBoxConnection;
403cdf0e10cSrcweir typedef ListBoxConnection< Int32ItemWrapper > Int32ListBoxConnection;
404cdf0e10cSrcweir typedef ListBoxConnection< UInt32ItemWrapper > UInt32ListBoxConnection;
405cdf0e10cSrcweir
406cdf0e10cSrcweir // ============================================================================
407cdf0e10cSrcweir
408cdf0e10cSrcweir /** Connection between an item and an SVTOOLS ValueSet.
409cdf0e10cSrcweir
410cdf0e10cSrcweir Optionally a map can be passed that maps value set identifiers to item
411cdf0e10cSrcweir values. This map MUST be terminated with an entry containing
412cdf0e10cSrcweir VALUESET_ITEM_NOTFOUND as value set identifier. The item value contained in
413cdf0e10cSrcweir this last entry is used as default item value in case of an error.
414cdf0e10cSrcweir */
415cdf0e10cSrcweir template< typename ItemWrpT >
416cdf0e10cSrcweir class ValueSetConnection : public ItemControlConnection< ItemWrpT,
417cdf0e10cSrcweir ValueSetWrapper< typename ItemWrpT::ItemValueType > >
418cdf0e10cSrcweir {
419cdf0e10cSrcweir typedef ItemControlConnection< ItemWrpT,
420cdf0e10cSrcweir ValueSetWrapper< typename ItemWrpT::ItemValueType > >
421cdf0e10cSrcweir ItemControlConnectionType;
422cdf0e10cSrcweir
423cdf0e10cSrcweir public:
424cdf0e10cSrcweir typedef typename ItemControlConnectionType::ControlWrapperType ValueSetWrapperType;
425cdf0e10cSrcweir typedef typename ValueSetWrapperType::MapEntryType MapEntryType;
426cdf0e10cSrcweir
427cdf0e10cSrcweir explicit ValueSetConnection( sal_uInt16 nSlot, ValueSet& rValueSet,
428cdf0e10cSrcweir const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
429cdf0e10cSrcweir };
430cdf0e10cSrcweir
431cdf0e10cSrcweir // ----------------------------------------------------------------------------
432cdf0e10cSrcweir
433cdf0e10cSrcweir typedef ValueSetConnection< Int16ItemWrapper > Int16ValueSetConnection;
434cdf0e10cSrcweir typedef ValueSetConnection< UInt16ItemWrapper > UInt16ValueSetConnection;
435cdf0e10cSrcweir typedef ValueSetConnection< Int32ItemWrapper > Int32ValueSetConnection;
436cdf0e10cSrcweir typedef ValueSetConnection< UInt32ItemWrapper > UInt32ValueSetConnection;
437cdf0e10cSrcweir
438cdf0e10cSrcweir // ============================================================================
439cdf0e10cSrcweir // Array of connections
440cdf0e10cSrcweir // ============================================================================
441cdf0e10cSrcweir
442cdf0e10cSrcweir class ItemConnectionArrayImpl;
443cdf0e10cSrcweir
444cdf0e10cSrcweir /** A container of connection objects.
445cdf0e10cSrcweir
446cdf0e10cSrcweir This is a connection with the only purpose to contain other connection
447cdf0e10cSrcweir objects. This way it is possible to create a tree structure of connections
448cdf0e10cSrcweir for a convenient connection management. This class is used by the class
449cdf0e10cSrcweir SfxTabPage to store all connections.
450cdf0e10cSrcweir */
451cdf0e10cSrcweir class ItemConnectionArray : public ItemConnectionBase
452cdf0e10cSrcweir {
453cdf0e10cSrcweir public:
454cdf0e10cSrcweir explicit ItemConnectionArray();
455cdf0e10cSrcweir virtual ~ItemConnectionArray();
456cdf0e10cSrcweir
457cdf0e10cSrcweir /** Adds a new connection to the list.
458cdf0e10cSrcweir @descr Takes ownership of the connection! */
459cdf0e10cSrcweir void AddConnection( ItemConnectionBase* pConnection );
460cdf0e10cSrcweir
461cdf0e10cSrcweir protected:
462cdf0e10cSrcweir virtual void ApplyFlags( const SfxItemSet& rItemSet );
463cdf0e10cSrcweir virtual void Reset( const SfxItemSet& rItemSet );
464cdf0e10cSrcweir virtual bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
465cdf0e10cSrcweir
466cdf0e10cSrcweir private:
467cdf0e10cSrcweir std::auto_ptr< ItemConnectionArrayImpl > mxImpl;
468cdf0e10cSrcweir };
469cdf0e10cSrcweir
470cdf0e10cSrcweir // ============================================================================
471cdf0e10cSrcweir
472cdf0e10cSrcweir // ============================================================================
473cdf0e10cSrcweir // *** Implementation of template functions ***
474cdf0e10cSrcweir // ============================================================================
475cdf0e10cSrcweir
476cdf0e10cSrcweir // ============================================================================
477cdf0e10cSrcweir // Base connection classes
478cdf0e10cSrcweir // ============================================================================
479cdf0e10cSrcweir
480cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
ItemControlConnection(sal_uInt16 nSlot,ControlWrpT * pNewCtrlWrp,ItemConnFlags nFlags)481cdf0e10cSrcweir ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
482cdf0e10cSrcweir sal_uInt16 nSlot, ControlWrpT* pNewCtrlWrp, ItemConnFlags nFlags ) :
483cdf0e10cSrcweir ItemConnectionBase( nFlags ),
484cdf0e10cSrcweir maItemWrp( nSlot ),
485cdf0e10cSrcweir mxCtrlWrp( pNewCtrlWrp )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
489cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
ItemControlConnection(sal_uInt16 nSlot,ControlType & rControl,ItemConnFlags nFlags)490cdf0e10cSrcweir ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
491cdf0e10cSrcweir sal_uInt16 nSlot, ControlType& rControl, ItemConnFlags nFlags ) :
492cdf0e10cSrcweir ItemConnectionBase( nFlags ),
493cdf0e10cSrcweir maItemWrp( nSlot ),
494cdf0e10cSrcweir mxCtrlWrp( new ControlWrpT( rControl ) )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
~ItemControlConnection()499cdf0e10cSrcweir ItemControlConnection< ItemWrpT, ControlWrpT >::~ItemControlConnection()
500cdf0e10cSrcweir {
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
ApplyFlags(const SfxItemSet & rItemSet)504cdf0e10cSrcweir void ItemControlConnection< ItemWrpT, ControlWrpT >::ApplyFlags( const SfxItemSet& rItemSet )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir bool bKnown = ItemWrapperHelper::IsKnownItem( rItemSet, maItemWrp.GetSlotId() );
507cdf0e10cSrcweir mxCtrlWrp->ModifyControl( GetEnableState( bKnown ), GetShowState( bKnown ) );
508cdf0e10cSrcweir }
509cdf0e10cSrcweir
510cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
Reset(const SfxItemSet & rItemSet)511cdf0e10cSrcweir void ItemControlConnection< ItemWrpT, ControlWrpT >::Reset( const SfxItemSet& rItemSet )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir const ItemType* pItem = maItemWrp.GetUniqueItem( rItemSet );
514cdf0e10cSrcweir mxCtrlWrp->SetControlDontKnow( pItem == 0 );
515cdf0e10cSrcweir if( pItem )
516cdf0e10cSrcweir mxCtrlWrp->SetControlValue( maItemWrp.GetItemValue( *pItem ) );
517cdf0e10cSrcweir }
518cdf0e10cSrcweir
519cdf0e10cSrcweir template< typename ItemWrpT, typename ControlWrpT >
FillItemSet(SfxItemSet & rDestSet,const SfxItemSet & rOldSet)520cdf0e10cSrcweir bool ItemControlConnection< ItemWrpT, ControlWrpT >::FillItemSet(
521cdf0e10cSrcweir SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir const ItemType* pOldItem = maItemWrp.GetUniqueItem( rOldSet );
524cdf0e10cSrcweir bool bChanged = false;
525cdf0e10cSrcweir if( !mxCtrlWrp->IsControlDontKnow() )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir // first store the control value in a local variable
528cdf0e10cSrcweir ControlValueType aCtrlValue( mxCtrlWrp->GetControlValue() );
529cdf0e10cSrcweir // convert to item value type -> possible to convert i.e. from 'T' to 'const T&'
530cdf0e10cSrcweir ItemValueType aNewValue( aCtrlValue );
531cdf0e10cSrcweir // do not rely on existence of ItemValueType::operator!=
532cdf0e10cSrcweir if( !pOldItem || !(maItemWrp.GetItemValue( *pOldItem ) == aNewValue) )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir sal_uInt16 nWhich = ItemWrapperHelper::GetWhichId( rDestSet, maItemWrp.GetSlotId() );
535cdf0e10cSrcweir std::auto_ptr< ItemType > xItem(
536cdf0e10cSrcweir static_cast< ItemType* >( maItemWrp.GetDefaultItem( rDestSet ).Clone() ) );
537cdf0e10cSrcweir xItem->SetWhich( nWhich );
538cdf0e10cSrcweir maItemWrp.SetItemValue( *xItem, aNewValue );
539cdf0e10cSrcweir rDestSet.Put( *xItem );
540cdf0e10cSrcweir bChanged = true;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir if( !bChanged )
544cdf0e10cSrcweir ItemWrapperHelper::RemoveDefaultItem( rDestSet, rOldSet, maItemWrp.GetSlotId() );
545cdf0e10cSrcweir return bChanged;
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir // ============================================================================
549cdf0e10cSrcweir // Standard connections
550cdf0e10cSrcweir // ============================================================================
551cdf0e10cSrcweir
552cdf0e10cSrcweir template< typename ItemWrpT >
NumericConnection(sal_uInt16 nSlot,NumericField & rField,ItemConnFlags nFlags)553cdf0e10cSrcweir NumericConnection< ItemWrpT >::NumericConnection(
554cdf0e10cSrcweir sal_uInt16 nSlot, NumericField& rField, ItemConnFlags nFlags ) :
555cdf0e10cSrcweir ItemControlConnectionType( nSlot, rField, nFlags )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir }
558cdf0e10cSrcweir
559cdf0e10cSrcweir // ============================================================================
560cdf0e10cSrcweir
561cdf0e10cSrcweir template< typename ItemWrpT >
MetricConnection(sal_uInt16 nSlot,MetricField & rField,FieldUnit eItemUnit,ItemConnFlags nFlags)562cdf0e10cSrcweir MetricConnection< ItemWrpT >::MetricConnection(
563cdf0e10cSrcweir sal_uInt16 nSlot, MetricField& rField, FieldUnit eItemUnit, ItemConnFlags nFlags ) :
564cdf0e10cSrcweir ItemControlConnectionType( nSlot, new MetricFieldWrapperType( rField, eItemUnit ), nFlags )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir }
567cdf0e10cSrcweir
568cdf0e10cSrcweir // ============================================================================
569cdf0e10cSrcweir
570cdf0e10cSrcweir template< typename ItemWrpT >
ListBoxConnection(sal_uInt16 nSlot,ListBox & rListBox,const MapEntryType * pMap,ItemConnFlags nFlags)571cdf0e10cSrcweir ListBoxConnection< ItemWrpT >::ListBoxConnection(
572cdf0e10cSrcweir sal_uInt16 nSlot, ListBox& rListBox, const MapEntryType* pMap, ItemConnFlags nFlags ) :
573cdf0e10cSrcweir ItemControlConnectionType( nSlot, new ListBoxWrapperType( rListBox, pMap ), nFlags )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir }
576cdf0e10cSrcweir
577cdf0e10cSrcweir // ============================================================================
578cdf0e10cSrcweir
579cdf0e10cSrcweir template< typename ItemWrpT >
ValueSetConnection(sal_uInt16 nSlot,ValueSet & rValueSet,const MapEntryType * pMap,ItemConnFlags nFlags)580cdf0e10cSrcweir ValueSetConnection< ItemWrpT >::ValueSetConnection(
581cdf0e10cSrcweir sal_uInt16 nSlot, ValueSet& rValueSet, const MapEntryType* pMap, ItemConnFlags nFlags ) :
582cdf0e10cSrcweir ItemControlConnectionType( nSlot, new ValueSetWrapperType( rValueSet, pMap ), nFlags )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir }
585cdf0e10cSrcweir
586cdf0e10cSrcweir // ============================================================================
587cdf0e10cSrcweir
588cdf0e10cSrcweir } // namespace sfx
589cdf0e10cSrcweir
590cdf0e10cSrcweir #endif
591cdf0e10cSrcweir
592