LCOV - code coverage report
Current view: top level - libreoffice/sfx2/inc/sfx2 - controlwrapper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 13 0.0 %
Date: 2012-12-27 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10