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