1353d8f4dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3353d8f4dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4353d8f4dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5353d8f4dSAndrew Rist * distributed with this work for additional information
6353d8f4dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7353d8f4dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8353d8f4dSAndrew Rist * "License"); you may not use this file except in compliance
9353d8f4dSAndrew Rist * with the License. You may obtain a copy of the License at
10353d8f4dSAndrew Rist *
11353d8f4dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12353d8f4dSAndrew Rist *
13353d8f4dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14353d8f4dSAndrew Rist * software distributed under the License is distributed on an
15353d8f4dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16353d8f4dSAndrew Rist * KIND, either express or implied. See the License for the
17353d8f4dSAndrew Rist * specific language governing permissions and limitations
18353d8f4dSAndrew Rist * under the License.
19353d8f4dSAndrew Rist *
20353d8f4dSAndrew Rist *************************************************************/
21353d8f4dSAndrew Rist
22353d8f4dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef SFX_CONTROLWRAPPER_HXX
25cdf0e10cSrcweir #define SFX_CONTROLWRAPPER_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include "sal/config.h"
29cdf0e10cSrcweir #include "sfx2/dllapi.h"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <memory>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #ifndef _SV_BUTTON_HXX
34cdf0e10cSrcweir #include <vcl/button.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <vcl/edit.hxx>
37cdf0e10cSrcweir #include <vcl/field.hxx>
38cdf0e10cSrcweir #include <vcl/lstbox.hxx>
39cdf0e10cSrcweir #include <svtools/valueset.hxx>
40cdf0e10cSrcweir #include <svtools/ctrlbox.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir // ============================================================================
43cdf0e10cSrcweir
44cdf0e10cSrcweir namespace sfx {
45cdf0e10cSrcweir
46cdf0e10cSrcweir // ============================================================================
47cdf0e10cSrcweir
48cdf0e10cSrcweir /** List position type of VCL ListBox. */
49cdf0e10cSrcweir typedef sal_uInt16 ListBoxPosType;
50cdf0e10cSrcweir /** List position type of SVTOOLS ValueSet. */
51cdf0e10cSrcweir typedef sal_uInt16 ValueSetPosType;
52cdf0e10cSrcweir
53cdf0e10cSrcweir // ============================================================================
54cdf0e10cSrcweir // Helpers
55cdf0e10cSrcweir // ============================================================================
56cdf0e10cSrcweir
57cdf0e10cSrcweir /** A helper class for mapping list positions from/to represented values.
58cdf0e10cSrcweir
59cdf0e10cSrcweir Deriving from this helper class adds the two functions GetValueFromPos()
60cdf0e10cSrcweir and GetPosFromValue(). The constructor receives an array of MapEntryType
61cdf0e10cSrcweir structures that represents the table of positions and values. It is
62cdf0e10cSrcweir possible to pass a null pointer, this results in a direct mapping between
63cdf0e10cSrcweir list positions and values. If the map exists, it MUST be terminated with an
64cdf0e10cSrcweir entry containing the special "not found" list position passed to the
65cdf0e10cSrcweir constructor. The value contained in this last entry is used as default
66cdf0e10cSrcweir value in case of an error.
67cdf0e10cSrcweir */
68cdf0e10cSrcweir template< typename PosT, typename ValueT >
69cdf0e10cSrcweir class PosValueMapper
70cdf0e10cSrcweir {
71cdf0e10cSrcweir public:
72cdf0e10cSrcweir typedef PosT PosType;
73cdf0e10cSrcweir typedef ValueT ValueType;
74cdf0e10cSrcweir typedef PosValueMapper< PosT, ValueT > MapperType;
75cdf0e10cSrcweir
76cdf0e10cSrcweir /** A helper struct that contains a list position - value pair. */
77cdf0e10cSrcweir struct MapEntryType
78cdf0e10cSrcweir {
79cdf0e10cSrcweir PosT mnPos; /// Position in the list.
80cdf0e10cSrcweir ValueT mnValue; /// Corresponding value.
81cdf0e10cSrcweir };
82cdf0e10cSrcweir
83cdf0e10cSrcweir /** Constructs the map helper with the passed map.
84cdf0e10cSrcweir @param nNFPos This list position is used to represent the
85cdf0e10cSrcweir "not found" or "not existing" state.
86cdf0e10cSrcweir @param pMap The map of list positions/values. If 0, a direct mapping
87cdf0e10cSrcweir is used (simply casting between list position and values). If the map
88cdf0e10cSrcweir exists, it *MUST* be terminated by an entry containing the special
89cdf0e10cSrcweir "not found" list position. */
PosValueMapper(PosT nNFPos,const MapEntryType * pMap=0)90cdf0e10cSrcweir inline explicit PosValueMapper( PosT nNFPos, const MapEntryType* pMap = 0 ) :
91cdf0e10cSrcweir mpMap( pMap ), mnNFPos( nNFPos ) {}
92cdf0e10cSrcweir
93cdf0e10cSrcweir /** Returns the value at the specified list position.
94cdf0e10cSrcweir @return The found value, or the value of the last map entry on error. */
95cdf0e10cSrcweir ValueT GetValueFromPos( PosT nPos ) const;
96cdf0e10cSrcweir /** Returns the list position of the specified value.
97cdf0e10cSrcweir @return The position, or the special "not found" position on error. */
98cdf0e10cSrcweir PosT GetPosFromValue( ValueT nValue ) const;
99cdf0e10cSrcweir
100cdf0e10cSrcweir /** Returns the special "not found" list position. */
GetNotFoundPos() const101cdf0e10cSrcweir inline PosT GetNotFoundPos() const { return mnNFPos; }
102cdf0e10cSrcweir
103cdf0e10cSrcweir private:
104cdf0e10cSrcweir const MapEntryType* mpMap; /// The list position/value map.
105cdf0e10cSrcweir PosT mnNFPos; /// Special "not found" list position.
106cdf0e10cSrcweir };
107cdf0e10cSrcweir
108cdf0e10cSrcweir // ============================================================================
109cdf0e10cSrcweir // Base control wrapper classes
110cdf0e10cSrcweir // ============================================================================
111cdf0e10cSrcweir
112cdf0e10cSrcweir /** Base class for all control wrappers.
113cdf0e10cSrcweir
114cdf0e10cSrcweir Control wrappers are used to have an equal interface for various functions
115cdf0e10cSrcweir used in connections for different types of controls.
116cdf0e10cSrcweir
117cdf0e10cSrcweir The current tree of base classes/templates and standard control wrappers:
118cdf0e10cSrcweir
119cdf0e10cSrcweir ControlWrapperBase
120cdf0e10cSrcweir |
121cdf0e10cSrcweir +- SingleControlWrapper< ControlT, ValueT >
122cdf0e10cSrcweir | |
123cdf0e10cSrcweir | +- DummyWindowWrapper [1]
124cdf0e10cSrcweir | +- CheckBoxWrapper [1]
125cdf0e10cSrcweir | +- EditWrapper [1]
126cdf0e10cSrcweir | +- ColorListBoxWrapper [1]
127cdf0e10cSrcweir | |
128cdf0e10cSrcweir | +- NumericFieldWrapper< ValueT > [1]
129cdf0e10cSrcweir | | |
130cdf0e10cSrcweir | | +- [ValueType]NumericFieldWrapper [1] [2]
131cdf0e10cSrcweir | |
132cdf0e10cSrcweir | +- MetricFieldWrapper< ValueT > [1]
133cdf0e10cSrcweir | | |
134cdf0e10cSrcweir | | +- [ValueType]MetricFieldWrapper [1] [2]
135cdf0e10cSrcweir | |
136cdf0e10cSrcweir | +- ListBoxWrapper< ValueT > [1]
137cdf0e10cSrcweir | | |
138cdf0e10cSrcweir | | +- [ValueType]ListBoxWrapper [1] [2]
139cdf0e10cSrcweir | |
140cdf0e10cSrcweir | +- ValueSetWrapper< ValueT > [1]
141cdf0e10cSrcweir | |
142cdf0e10cSrcweir | +- [ValueType]ValueSetWrapper [1] [2]
143cdf0e10cSrcweir |
144cdf0e10cSrcweir +- MultiControlWrapperHelper
145cdf0e10cSrcweir |
146cdf0e10cSrcweir +- MultiControlWrapper< ValueT >
147cdf0e10cSrcweir
148cdf0e10cSrcweir Notes:
149cdf0e10cSrcweir [1] Standard wrappers ready to use.
150cdf0e10cSrcweir [2] [ValueType] is one of Int16, UInt16, Int32, UInt32, UShort, ULong.
151cdf0e10cSrcweir
152cdf0e10cSrcweir See documentation of class ItemConnectionBase (itemconnect.hxx) for more
153cdf0e10cSrcweir details.
154cdf0e10cSrcweir */
155cdf0e10cSrcweir class SFX2_DLLPUBLIC ControlWrapperBase
156cdf0e10cSrcweir {
157cdf0e10cSrcweir public:
ControlWrapperBase()158cdf0e10cSrcweir inline explicit ControlWrapperBase() {}
159cdf0e10cSrcweir virtual ~ControlWrapperBase();
160cdf0e10cSrcweir
161cdf0e10cSrcweir /** Derived classes enable, disable, show, or hide control(s).
162cdf0e10cSrcweir @descr Will do nothing, if the corresponding parameter is STATE_DONTKNOW. */
163cdf0e10cSrcweir virtual void ModifyControl( TriState eEnable, TriState eShow ) = 0;
164cdf0e10cSrcweir
165cdf0e10cSrcweir /** Derived classes return true if the control is in "don't know" state. */
166cdf0e10cSrcweir virtual bool IsControlDontKnow() const = 0;
167cdf0e10cSrcweir /** Derived classes set the control to "don't know" state. */
168cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet ) = 0;
169cdf0e10cSrcweir
170cdf0e10cSrcweir private:
171cdf0e10cSrcweir /* Disable copy c'tor and assignment. */
172cdf0e10cSrcweir ControlWrapperBase( const ControlWrapperBase& );
173cdf0e10cSrcweir ControlWrapperBase& operator=( const ControlWrapperBase& );
174cdf0e10cSrcweir };
175cdf0e10cSrcweir
176cdf0e10cSrcweir // ============================================================================
177cdf0e10cSrcweir // Single control wrappers
178cdf0e10cSrcweir // ============================================================================
179cdf0e10cSrcweir
180cdf0e10cSrcweir /** Base class template for control wrappers containing one single control.
181cdf0e10cSrcweir
182cdf0e10cSrcweir Classes created from this template store the reference to a single control
183cdf0e10cSrcweir object. It is not required that the control is derived from VCL's Window
184cdf0e10cSrcweir class. Derived classes have to implement the abstract functions
185cdf0e10cSrcweir ShowControl(), EnableControl(), IsControlDontKnow(), SetControlDontKnow(),
186cdf0e10cSrcweir GetControlValue(), and SetControlValue().
187cdf0e10cSrcweir
188cdf0e10cSrcweir As already stated, it is not required for ControlT to be a VCL Window.
189cdf0e10cSrcweir Anyway, ControlT must support the following functions:
190cdf0e10cSrcweir - void ControlT::Enable( bool )
191cdf0e10cSrcweir - void ControlT::Show( bool )
192cdf0e10cSrcweir */
193cdf0e10cSrcweir template< typename ControlT, typename ValueT >
194cdf0e10cSrcweir class SingleControlWrapper : public ControlWrapperBase
195cdf0e10cSrcweir {
196cdf0e10cSrcweir public:
197cdf0e10cSrcweir typedef ControlT ControlType;
198cdf0e10cSrcweir typedef ValueT ControlValueType;
199cdf0e10cSrcweir typedef SingleControlWrapper< ControlT, ValueT > SingleControlWrapperType;
200cdf0e10cSrcweir
SingleControlWrapper(ControlT & rControl)201cdf0e10cSrcweir inline explicit SingleControlWrapper( ControlT& rControl ) : mrControl( rControl ) {}
202cdf0e10cSrcweir
203cdf0e10cSrcweir /** Returns a reference to the control this connection works on. */
GetControl() const204cdf0e10cSrcweir inline const ControlT& GetControl() const { return mrControl; }
205cdf0e10cSrcweir /** Returns a reference to the control this connection works on. */
GetControl()206cdf0e10cSrcweir inline ControlT& GetControl() { return mrControl; }
207cdf0e10cSrcweir
208cdf0e10cSrcweir /** Enables, disables, shows, or hides the control.
209cdf0e10cSrcweir @descr Does nothing, if the corresponding parameter is STATE_DONTKNOW. */
210cdf0e10cSrcweir virtual void ModifyControl( TriState eEnable, TriState eShow );
211cdf0e10cSrcweir
212cdf0e10cSrcweir /** Derived classes return the value the control contains. */
213cdf0e10cSrcweir virtual ValueT GetControlValue() const = 0;
214cdf0e10cSrcweir /** Derived classes set the contents of the control to the passed value. */
215cdf0e10cSrcweir virtual void SetControlValue( ValueT aValue ) = 0;
216cdf0e10cSrcweir
217cdf0e10cSrcweir private:
218cdf0e10cSrcweir ControlT& mrControl; /// The control of this wrapper.
219cdf0e10cSrcweir };
220cdf0e10cSrcweir
221cdf0e10cSrcweir // ============================================================================
222cdf0e10cSrcweir
223cdf0e10cSrcweir /** A dummy wrapper for a VCL Window that does nothing special.
224cdf0e10cSrcweir
225cdf0e10cSrcweir This wrapper is used to implement the DummyItemConnection. It does not
226cdf0e10cSrcweir connect an item to a control, but handles the special flags to disable or
227cdf0e10cSrcweir hide a control, if an item is unknown.
228cdf0e10cSrcweir */
229cdf0e10cSrcweir class SFX2_DLLPUBLIC DummyWindowWrapper:
230cdf0e10cSrcweir public SingleControlWrapper< Window, void* >
231cdf0e10cSrcweir {
232cdf0e10cSrcweir public:
233cdf0e10cSrcweir explicit DummyWindowWrapper( Window& rWindow );
234cdf0e10cSrcweir
235cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
236cdf0e10cSrcweir virtual void SetControlDontKnow( bool );
237cdf0e10cSrcweir
238cdf0e10cSrcweir virtual void* GetControlValue() const;
239cdf0e10cSrcweir virtual void SetControlValue( void* );
240cdf0e10cSrcweir };
241cdf0e10cSrcweir
242cdf0e10cSrcweir // ----------------------------------------------------------------------------
243cdf0e10cSrcweir
244cdf0e10cSrcweir /** A wrapper for the VCL CheckBox. */
245cdf0e10cSrcweir class SFX2_DLLPUBLIC CheckBoxWrapper:
246cdf0e10cSrcweir public SingleControlWrapper< CheckBox, sal_Bool >
247cdf0e10cSrcweir {
248cdf0e10cSrcweir public:
249cdf0e10cSrcweir explicit CheckBoxWrapper( CheckBox& rCheckBox );
250cdf0e10cSrcweir
251cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
252cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
253cdf0e10cSrcweir
254cdf0e10cSrcweir virtual sal_Bool GetControlValue() const;
255cdf0e10cSrcweir virtual void SetControlValue( sal_Bool bValue );
256cdf0e10cSrcweir };
257cdf0e10cSrcweir
258cdf0e10cSrcweir // ----------------------------------------------------------------------------
259cdf0e10cSrcweir
260cdf0e10cSrcweir /** A wrapper for the VCL Edit. */
261cdf0e10cSrcweir class EditWrapper : public SingleControlWrapper< Edit, String >
262cdf0e10cSrcweir {
263cdf0e10cSrcweir /* Note: cannot use 'const String&' as template argument, because VCL's
264cdf0e10cSrcweir Edit control returns the string by value and not by reference,
265cdf0e10cSrcweir therefore GetControlValue() must return a temporary object too. */
266cdf0e10cSrcweir public:
267cdf0e10cSrcweir explicit EditWrapper( Edit& rEdit );
268cdf0e10cSrcweir
269cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
270cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
271cdf0e10cSrcweir
272cdf0e10cSrcweir virtual String GetControlValue() const;
273cdf0e10cSrcweir virtual void SetControlValue( String aValue );
274cdf0e10cSrcweir };
275cdf0e10cSrcweir
276cdf0e10cSrcweir // ----------------------------------------------------------------------------
277cdf0e10cSrcweir
278cdf0e10cSrcweir /** A wrapper for the SVTOOLS ColorListBox. */
279cdf0e10cSrcweir class SFX2_DLLPUBLIC ColorListBoxWrapper:
280cdf0e10cSrcweir public SingleControlWrapper< ColorListBox, Color >
281cdf0e10cSrcweir {
282cdf0e10cSrcweir /* Note: cannot use 'const Color&' as template argument, because the
283cdf0e10cSrcweir SVTOOLS ColorListBox returns the color by value and not by reference,
284cdf0e10cSrcweir therefore GetControlValue() must return a temporary object too. */
285cdf0e10cSrcweir public:
286cdf0e10cSrcweir explicit ColorListBoxWrapper(ColorListBox & rListBox);
287cdf0e10cSrcweir
288cdf0e10cSrcweir virtual ~ColorListBoxWrapper();
289cdf0e10cSrcweir
290cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
291cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
292cdf0e10cSrcweir
293cdf0e10cSrcweir virtual Color GetControlValue() const;
294cdf0e10cSrcweir virtual void SetControlValue( Color aColor );
295cdf0e10cSrcweir };
296cdf0e10cSrcweir
297cdf0e10cSrcweir // ============================================================================
298cdf0e10cSrcweir
299cdf0e10cSrcweir /** A wrapper for the VCL NumericField. */
300cdf0e10cSrcweir template< typename ValueT >
301cdf0e10cSrcweir class NumericFieldWrapper : public SingleControlWrapper< NumericField, ValueT >
302cdf0e10cSrcweir {
303cdf0e10cSrcweir public:
NumericFieldWrapper(NumericField & rField)304cdf0e10cSrcweir inline explicit NumericFieldWrapper( NumericField& rField ) :
305cdf0e10cSrcweir SingleControlWrapper< NumericField, ValueT >( rField ) {}
306cdf0e10cSrcweir
307cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
308cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
309cdf0e10cSrcweir
310cdf0e10cSrcweir virtual ValueT GetControlValue() const;
311cdf0e10cSrcweir virtual void SetControlValue( ValueT nValue );
312cdf0e10cSrcweir };
313cdf0e10cSrcweir
314cdf0e10cSrcweir // ----------------------------------------------------------------------------
315cdf0e10cSrcweir
316cdf0e10cSrcweir typedef NumericFieldWrapper< sal_Int16 > Int16NumericFieldWrapper;
317cdf0e10cSrcweir typedef NumericFieldWrapper< sal_uInt16 > UInt16NumericFieldWrapper;
318cdf0e10cSrcweir typedef NumericFieldWrapper< sal_Int32 > Int32NumericFieldWrapper;
319cdf0e10cSrcweir typedef NumericFieldWrapper< sal_uInt32 > UInt32NumericFieldWrapper;
320cdf0e10cSrcweir
321cdf0e10cSrcweir typedef NumericFieldWrapper< sal_uInt16 > UShortNumericFieldWrapper;
322cdf0e10cSrcweir typedef NumericFieldWrapper< sal_uIntPtr > ULongNumericFieldWrapper;
323cdf0e10cSrcweir
324cdf0e10cSrcweir // ============================================================================
325cdf0e10cSrcweir
326cdf0e10cSrcweir /** A wrapper for the VCL MetricField.
327cdf0e10cSrcweir
328cdf0e10cSrcweir Adds support for field units during accessing the control value. The
329cdf0e10cSrcweir wrapper respects the field unit set at the control itself and converts it
330cdf0e10cSrcweir from/to the field unit passed to the constructor.
331cdf0e10cSrcweir */
332cdf0e10cSrcweir template< typename ValueT >
333cdf0e10cSrcweir class MetricFieldWrapper : public SingleControlWrapper< MetricField, ValueT >
334cdf0e10cSrcweir {
335cdf0e10cSrcweir public:
MetricFieldWrapper(MetricField & rField,FieldUnit eUnit=FUNIT_NONE)336cdf0e10cSrcweir inline explicit MetricFieldWrapper( MetricField& rField, FieldUnit eUnit = FUNIT_NONE ) :
337cdf0e10cSrcweir SingleControlWrapper< MetricField, ValueT >( rField ), meUnit( eUnit ) {}
338cdf0e10cSrcweir
339cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
340cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
341cdf0e10cSrcweir
342cdf0e10cSrcweir virtual ValueT GetControlValue() const;
343cdf0e10cSrcweir virtual void SetControlValue( ValueT nValue );
344cdf0e10cSrcweir
345cdf0e10cSrcweir private:
346cdf0e10cSrcweir FieldUnit meUnit;
347cdf0e10cSrcweir };
348cdf0e10cSrcweir
349cdf0e10cSrcweir // ----------------------------------------------------------------------------
350cdf0e10cSrcweir
351cdf0e10cSrcweir typedef MetricFieldWrapper< sal_Int16 > Int16MetricFieldWrapper;
352cdf0e10cSrcweir typedef MetricFieldWrapper< sal_uInt16 > UInt16MetricFieldWrapper;
353cdf0e10cSrcweir typedef MetricFieldWrapper< sal_Int32 > Int32MetricFieldWrapper;
354cdf0e10cSrcweir typedef MetricFieldWrapper< sal_uInt32 > UInt32MetricFieldWrapper;
355cdf0e10cSrcweir
356cdf0e10cSrcweir typedef MetricFieldWrapper< sal_uInt16 > UShortMetricFieldWrapper;
357cdf0e10cSrcweir typedef MetricFieldWrapper< sal_uIntPtr > ULongMetricFieldWrapper;
358cdf0e10cSrcweir
359cdf0e10cSrcweir // ============================================================================
360cdf0e10cSrcweir
361cdf0e10cSrcweir /** A wrapper for the VCL ListBox.
362cdf0e10cSrcweir
363cdf0e10cSrcweir If a position<->value map is passed to the constructor, it MUST be
364cdf0e10cSrcweir terminated with an entry containing LISTBOX_ENTRY_NOTFOUND as list
365cdf0e10cSrcweir position. See documentation of the PosValueMapper template for details.
366cdf0e10cSrcweir */
367cdf0e10cSrcweir template< typename ValueT >
368cdf0e10cSrcweir class ListBoxWrapper :
369cdf0e10cSrcweir public SingleControlWrapper< ListBox, ValueT >,
370cdf0e10cSrcweir public PosValueMapper< ListBoxPosType, ValueT >
371cdf0e10cSrcweir {
372cdf0e10cSrcweir typedef PosValueMapper< ListBoxPosType, ValueT > MapperType;
373cdf0e10cSrcweir
374cdf0e10cSrcweir public:
375cdf0e10cSrcweir typedef typename MapperType::MapEntryType MapEntryType;
376cdf0e10cSrcweir
377cdf0e10cSrcweir /** @param pMap Optional list position <-> value map.
378cdf0e10cSrcweir See PosValueMapper documentation for details. */
ListBoxWrapper(ListBox & rListBox,const MapEntryType * pMap=0)379cdf0e10cSrcweir inline explicit ListBoxWrapper( ListBox& rListBox, const MapEntryType* pMap = 0 ) :
380cdf0e10cSrcweir SingleControlWrapper< ListBox, ValueT >( rListBox ), MapperType( LISTBOX_ENTRY_NOTFOUND, pMap ) {}
381cdf0e10cSrcweir
IsControlDontKnow() const382cdf0e10cSrcweir virtual bool IsControlDontKnow() const
383cdf0e10cSrcweir { return this->GetControl().GetSelectEntryCount() == 0; }
SetControlDontKnow(bool bSet)384cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet )
385cdf0e10cSrcweir { if( bSet ) this->GetControl().SetNoSelection(); }
386cdf0e10cSrcweir
387cdf0e10cSrcweir virtual ValueT GetControlValue() const;
388cdf0e10cSrcweir virtual void SetControlValue( ValueT nValue );
389cdf0e10cSrcweir };
390cdf0e10cSrcweir
391cdf0e10cSrcweir // ----------------------------------------------------------------------------
392cdf0e10cSrcweir
393cdf0e10cSrcweir typedef ListBoxWrapper< sal_Int16 > Int16ListBoxWrapper;
394cdf0e10cSrcweir typedef ListBoxWrapper< sal_uInt16 > UInt16ListBoxWrapper;
395cdf0e10cSrcweir typedef ListBoxWrapper< sal_Int32 > Int32ListBoxWrapper;
396cdf0e10cSrcweir typedef ListBoxWrapper< sal_uInt32 > UInt32ListBoxWrapper;
397cdf0e10cSrcweir
398cdf0e10cSrcweir typedef ListBoxWrapper< sal_uInt16 > UShortListBoxWrapper;
399cdf0e10cSrcweir typedef ListBoxWrapper< sal_uIntPtr > ULongListBoxWrapper;
400cdf0e10cSrcweir
401cdf0e10cSrcweir // ============================================================================
402cdf0e10cSrcweir
403cdf0e10cSrcweir /** A wrapper for the SVTOOLS ValueSet.
404cdf0e10cSrcweir
405cdf0e10cSrcweir If a position<->value map is passed to the constructor, it MUST be
406cdf0e10cSrcweir terminated with an entry containing VALUESET_ITEM_NOTFOUND as list
407cdf0e10cSrcweir position. See documentation of the PosValueMapper template for details.
408cdf0e10cSrcweir */
409cdf0e10cSrcweir template< typename ValueT >
410cdf0e10cSrcweir class ValueSetWrapper :
411cdf0e10cSrcweir public SingleControlWrapper< ValueSet, ValueT >,
412cdf0e10cSrcweir public PosValueMapper< ValueSetPosType, ValueT >
413cdf0e10cSrcweir {
414cdf0e10cSrcweir typedef PosValueMapper< ValueSetPosType, ValueT > MapperType;
415cdf0e10cSrcweir
416cdf0e10cSrcweir public:
417cdf0e10cSrcweir typedef typename MapperType::MapEntryType MapEntryType;
418cdf0e10cSrcweir
419cdf0e10cSrcweir /** @param pMap Optional position <-> value map.
420cdf0e10cSrcweir See PosValueMapper documentation for details. */
ValueSetWrapper(ValueSet & rValueSet,const MapEntryType * pMap=0)421cdf0e10cSrcweir inline explicit ValueSetWrapper( ValueSet& rValueSet, const MapEntryType* pMap = 0 ) :
422cdf0e10cSrcweir SingleControlWrapper< ValueSet, ValueT >( rValueSet ), MapperType( VALUESET_ITEM_NOTFOUND, pMap ) {}
423cdf0e10cSrcweir
IsControlDontKnow() const424cdf0e10cSrcweir virtual bool IsControlDontKnow() const
425cdf0e10cSrcweir { return this->GetControl().IsNoSelection(); }
SetControlDontKnow(bool bSet)426cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet )
427cdf0e10cSrcweir { if( bSet ) this->GetControl().SetNoSelection(); }
428cdf0e10cSrcweir
429cdf0e10cSrcweir virtual ValueT GetControlValue() const;
430cdf0e10cSrcweir virtual void SetControlValue( ValueT nValue );
431cdf0e10cSrcweir };
432cdf0e10cSrcweir
433cdf0e10cSrcweir // ----------------------------------------------------------------------------
434cdf0e10cSrcweir
435cdf0e10cSrcweir typedef ValueSetWrapper< sal_Int16 > Int16ValueSetWrapper;
436cdf0e10cSrcweir typedef ValueSetWrapper< sal_uInt16 > UInt16ValueSetWrapper;
437cdf0e10cSrcweir typedef ValueSetWrapper< sal_Int32 > Int32ValueSetWrapper;
438cdf0e10cSrcweir typedef ValueSetWrapper< sal_uInt32 > UInt32ValueSetWrapper;
439cdf0e10cSrcweir
440cdf0e10cSrcweir typedef ValueSetWrapper< sal_uInt16 > UShortValueSetWrapper;
441cdf0e10cSrcweir typedef ValueSetWrapper< sal_uIntPtr > ULongValueSetWrapper;
442cdf0e10cSrcweir
443cdf0e10cSrcweir // ============================================================================
444cdf0e10cSrcweir // Multi control wrappers
445cdf0e10cSrcweir // ============================================================================
446cdf0e10cSrcweir
447cdf0e10cSrcweir struct MultiControlWrapperHelper_Impl;
448cdf0e10cSrcweir
449cdf0e10cSrcweir /** A container of control wrappers.
450cdf0e10cSrcweir
451cdf0e10cSrcweir Derived classes should define control wrapper members and register them in
452cdf0e10cSrcweir their constructor, using the function RegisterControlWrapper().
453cdf0e10cSrcweir
454cdf0e10cSrcweir This wrapper implements the abstract functions of the ControlWrapperBase
455cdf0e10cSrcweir base class by calling the functions of all registered wrappers.
456cdf0e10cSrcweir */
457cdf0e10cSrcweir class SFX2_DLLPUBLIC MultiControlWrapperHelper : public ControlWrapperBase
458cdf0e10cSrcweir {
459cdf0e10cSrcweir public:
460cdf0e10cSrcweir explicit MultiControlWrapperHelper();
461cdf0e10cSrcweir virtual ~MultiControlWrapperHelper();
462cdf0e10cSrcweir
463cdf0e10cSrcweir /** Registers a control wrapper (should be a member of a derived class). */
464cdf0e10cSrcweir void RegisterControlWrapper( ControlWrapperBase& rWrapper );
465cdf0e10cSrcweir
466cdf0e10cSrcweir /** Enables, disables, shows, or hides the registered controls. */
467cdf0e10cSrcweir virtual void ModifyControl( TriState eEnable, TriState eShow );
468cdf0e10cSrcweir
469cdf0e10cSrcweir /** Returns true if all registered controls are in "don't know" state. */
470cdf0e10cSrcweir virtual bool IsControlDontKnow() const;
471cdf0e10cSrcweir /** Sets all registered controls to "don't know" state. */
472cdf0e10cSrcweir virtual void SetControlDontKnow( bool bSet );
473cdf0e10cSrcweir
474cdf0e10cSrcweir private:
475cdf0e10cSrcweir std::auto_ptr< MultiControlWrapperHelper_Impl > mxImpl;
476cdf0e10cSrcweir };
477cdf0e10cSrcweir
478cdf0e10cSrcweir // ----------------------------------------------------------------------------
479cdf0e10cSrcweir
480cdf0e10cSrcweir /** A multi control wrapper with extended interface.
481cdf0e10cSrcweir
482cdf0e10cSrcweir This template class extends the MultiControlWrapperHelper class by the
483cdf0e10cSrcweir functions GetControlValue() and SetControlValue(), known from the
484cdf0e10cSrcweir SingleControlWrapper template. This makes it possible to use this template
485cdf0e10cSrcweir in item connections expecting a single control wrapper. The type ValueT
486cdf0e10cSrcweir should be able to contain the values of all controls handled in this
487cdf0e10cSrcweir wrapper. In most cases, the easiest way to achieve this is to use the
488cdf0e10cSrcweir related item type directly, using the IdentItemWrapper template
489cdf0e10cSrcweir (itemwrapper.hxx).
490cdf0e10cSrcweir */
491cdf0e10cSrcweir template< typename ValueT >
492cdf0e10cSrcweir class MultiControlWrapper : public MultiControlWrapperHelper
493cdf0e10cSrcweir {
494cdf0e10cSrcweir public:
495cdf0e10cSrcweir typedef MultiControlWrapperHelper ControlType;
496cdf0e10cSrcweir typedef ValueT ControlValueType;
497cdf0e10cSrcweir typedef MultiControlWrapper< ValueT > MultiControlWrapperType;
498cdf0e10cSrcweir
MultiControlWrapper()499cdf0e10cSrcweir MultiControlWrapper() : maDefValue( 0 ){}
500cdf0e10cSrcweir
501cdf0e10cSrcweir /** Returns the default value that can be used in GetControlValue(). */
GetDefaultValue() const502cdf0e10cSrcweir inline const ValueT& GetDefaultValue() const { return maDefValue; }
503cdf0e10cSrcweir /** Sets a default value that can be used in GetControlValue(). */
SetDefaultValue(const ValueT & rDefValue)504cdf0e10cSrcweir inline void SetDefaultValue( const ValueT& rDefValue ) { maDefValue = rDefValue; }
505cdf0e10cSrcweir
506cdf0e10cSrcweir /** Derived classes return the value the control contains. */
507cdf0e10cSrcweir virtual ValueT GetControlValue() const = 0;
508cdf0e10cSrcweir /** Derived classes set the contents of the control to the passed value. */
509cdf0e10cSrcweir virtual void SetControlValue( ValueT aValue ) = 0;
510cdf0e10cSrcweir
511cdf0e10cSrcweir private:
512cdf0e10cSrcweir ValueT maDefValue;
513cdf0e10cSrcweir };
514cdf0e10cSrcweir
515cdf0e10cSrcweir // ============================================================================
516cdf0e10cSrcweir
517cdf0e10cSrcweir
518cdf0e10cSrcweir // ============================================================================
519cdf0e10cSrcweir // *** Implementation of template functions ***
520cdf0e10cSrcweir // ============================================================================
521cdf0e10cSrcweir
522cdf0e10cSrcweir // ============================================================================
523cdf0e10cSrcweir // Helpers
524cdf0e10cSrcweir // ============================================================================
525cdf0e10cSrcweir
526cdf0e10cSrcweir template< typename PosT, typename ValueT >
GetValueFromPos(PosT nPos) const527cdf0e10cSrcweir ValueT PosValueMapper< PosT, ValueT >::GetValueFromPos( PosT nPos ) const
528cdf0e10cSrcweir {
529cdf0e10cSrcweir ValueT nValue;
530cdf0e10cSrcweir if( mpMap )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir const MapEntryType* pEntry = mpMap;
533cdf0e10cSrcweir while( (pEntry->mnPos != nPos) && (pEntry->mnPos != mnNFPos) )
534cdf0e10cSrcweir ++pEntry;
535cdf0e10cSrcweir nValue = pEntry->mnValue;
536cdf0e10cSrcweir }
537cdf0e10cSrcweir else /* if( nPos != mnNFPos ) */
538cdf0e10cSrcweir {
539cdf0e10cSrcweir DBG_ASSERT( nPos != mnNFPos, "sfx2::PosValueMapper< PosT, ValueT >::GetValueFromPos(), previously uninitialized value found!" );
540cdf0e10cSrcweir nValue = static_cast< ValueT >( nPos );
541cdf0e10cSrcweir }
542cdf0e10cSrcweir
543cdf0e10cSrcweir return nValue;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
546cdf0e10cSrcweir template< typename PosT, typename ValueT >
GetPosFromValue(ValueT nValue) const547cdf0e10cSrcweir PosT PosValueMapper< PosT, ValueT >::GetPosFromValue( ValueT nValue ) const
548cdf0e10cSrcweir {
549cdf0e10cSrcweir PosT nPos = mnNFPos;
550cdf0e10cSrcweir if( mpMap )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir const MapEntryType* pEntry = mpMap;
553cdf0e10cSrcweir while( (pEntry->mnValue != nValue) && (pEntry->mnPos != mnNFPos) )
554cdf0e10cSrcweir ++pEntry;
555cdf0e10cSrcweir nPos = pEntry->mnPos;
556cdf0e10cSrcweir }
557cdf0e10cSrcweir else if( nValue >= 0 )
558cdf0e10cSrcweir nPos = static_cast< PosT >( nValue );
559cdf0e10cSrcweir return nPos;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir
562cdf0e10cSrcweir // ============================================================================
563cdf0e10cSrcweir // Single control wrappers
564cdf0e10cSrcweir // ============================================================================
565cdf0e10cSrcweir
566cdf0e10cSrcweir template< typename ControlT, typename ValueT >
ModifyControl(TriState eEnable,TriState eShow)567cdf0e10cSrcweir inline void SingleControlWrapper< ControlT, ValueT >::ModifyControl( TriState eEnable, TriState eShow )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir if( eEnable != STATE_DONTKNOW )
570cdf0e10cSrcweir mrControl.Enable( eEnable == STATE_CHECK );
571cdf0e10cSrcweir if( eShow != STATE_DONTKNOW )
572cdf0e10cSrcweir mrControl.Show( eShow == STATE_CHECK );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir
575cdf0e10cSrcweir // ============================================================================
576cdf0e10cSrcweir
577cdf0e10cSrcweir template< typename ValueT >
IsControlDontKnow() const578cdf0e10cSrcweir bool NumericFieldWrapper< ValueT >::IsControlDontKnow() const
579cdf0e10cSrcweir {
580cdf0e10cSrcweir return this->GetControl().GetText().Len() == 0;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir
583cdf0e10cSrcweir template< typename ValueT >
SetControlDontKnow(bool bSet)584cdf0e10cSrcweir void NumericFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir if( bSet )
587cdf0e10cSrcweir this->GetControl().SetText( String() );
588cdf0e10cSrcweir }
589cdf0e10cSrcweir
590cdf0e10cSrcweir template< typename ValueT >
GetControlValue() const591cdf0e10cSrcweir ValueT NumericFieldWrapper< ValueT >::GetControlValue() const
592cdf0e10cSrcweir {
593cdf0e10cSrcweir return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue() ) );
594cdf0e10cSrcweir }
595cdf0e10cSrcweir
596cdf0e10cSrcweir template< typename ValueT >
SetControlValue(ValueT nValue)597cdf0e10cSrcweir void NumericFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ) );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir // ============================================================================
603cdf0e10cSrcweir
604cdf0e10cSrcweir template< typename ValueT >
IsControlDontKnow() const605cdf0e10cSrcweir bool MetricFieldWrapper< ValueT >::IsControlDontKnow() const
606cdf0e10cSrcweir {
607cdf0e10cSrcweir return this->GetControl().GetText().Len() == 0;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir
610cdf0e10cSrcweir template< typename ValueT >
SetControlDontKnow(bool bSet)611cdf0e10cSrcweir void MetricFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
612cdf0e10cSrcweir {
613cdf0e10cSrcweir if( bSet )
614cdf0e10cSrcweir this->GetControl().SetText( String() );
615cdf0e10cSrcweir }
616cdf0e10cSrcweir
617cdf0e10cSrcweir template< typename ValueT >
GetControlValue() const618cdf0e10cSrcweir ValueT MetricFieldWrapper< ValueT >::GetControlValue() const
619cdf0e10cSrcweir {
620cdf0e10cSrcweir return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue( meUnit ) ) );
621cdf0e10cSrcweir }
622cdf0e10cSrcweir
623cdf0e10cSrcweir template< typename ValueT >
SetControlValue(ValueT nValue)624cdf0e10cSrcweir void MetricFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ), meUnit );
627cdf0e10cSrcweir }
628cdf0e10cSrcweir
629cdf0e10cSrcweir // ============================================================================
630cdf0e10cSrcweir
631cdf0e10cSrcweir template< typename ValueT >
GetControlValue() const632cdf0e10cSrcweir ValueT ListBoxWrapper< ValueT >::GetControlValue() const
633cdf0e10cSrcweir {
634*7ee1d29cSAriel Constenla-Haile return this->GetValueFromPos( this->GetControl().GetSelectEntryPos() );
635cdf0e10cSrcweir }
636cdf0e10cSrcweir
637cdf0e10cSrcweir template< typename ValueT >
SetControlValue(ValueT nValue)638cdf0e10cSrcweir void ListBoxWrapper< ValueT >::SetControlValue( ValueT nValue )
639cdf0e10cSrcweir {
640*7ee1d29cSAriel Constenla-Haile sal_uInt16 nPos = this->GetPosFromValue( nValue );
641cdf0e10cSrcweir if( nPos != this->GetNotFoundPos() )
642cdf0e10cSrcweir this->GetControl().SelectEntryPos( nPos );
643cdf0e10cSrcweir }
644cdf0e10cSrcweir
645cdf0e10cSrcweir // ----------------------------------------------------------------------------
646cdf0e10cSrcweir
647cdf0e10cSrcweir template< typename ValueT >
GetControlValue() const648cdf0e10cSrcweir ValueT ValueSetWrapper< ValueT >::GetControlValue() const
649cdf0e10cSrcweir {
650*7ee1d29cSAriel Constenla-Haile return this->GetValueFromPos( this->GetControl().GetSelectItemId() );
651cdf0e10cSrcweir }
652cdf0e10cSrcweir
653cdf0e10cSrcweir template< typename ValueT >
SetControlValue(ValueT nValue)654cdf0e10cSrcweir void ValueSetWrapper< ValueT >::SetControlValue( ValueT nValue )
655cdf0e10cSrcweir {
656*7ee1d29cSAriel Constenla-Haile sal_uInt16 nPos = this->GetPosFromValue( nValue );
657cdf0e10cSrcweir if( nPos != this->GetNotFoundPos() )
658cdf0e10cSrcweir this->GetControl().SelectItem( nPos );
659cdf0e10cSrcweir }
660cdf0e10cSrcweir
661cdf0e10cSrcweir // ============================================================================
662cdf0e10cSrcweir
663cdf0e10cSrcweir
664cdf0e10cSrcweir } // namespace sfx
665cdf0e10cSrcweir
666cdf0e10cSrcweir #endif
667cdf0e10cSrcweir
668