LCOV - code coverage report
Current view: top level - include/sfx2 - controlwrapper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 80 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 166 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 INCLUDED_SFX2_CONTROLWRAPPER_HXX
      21             : #define INCLUDED_SFX2_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           0 :     inline explicit     PosValueMapper( PosT nNFPos, const MapEntryType* pMap = 0 ) :
      85           0 :                             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           0 :     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 TRISTATE_INDET. */
     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             :                         ControlWrapperBase( const ControlWrapperBase& ) SAL_DELETED_FUNCTION;
     166             :     ControlWrapperBase& operator=( const ControlWrapperBase& ) SAL_DELETED_FUNCTION;
     167             : };
     168             : 
     169             : 
     170             : // Single control wrappers
     171             : 
     172             : 
     173             : /** Base class template for control wrappers containing one single control.
     174             : 
     175             :     Classes created from this template store the reference to a single control
     176             :     object. It is not required that the control is derived from VCL's Window
     177             :     class. Derived classes have to implement the abstract functions
     178             :     ShowControl(), EnableControl(), IsControlDontKnow(), SetControlDontKnow(),
     179             :     GetControlValue(), and SetControlValue().
     180             : 
     181             :     As already stated, it is not required for ControlT to be a VCL Window.
     182             :     Anyway, ControlT must support the following functions:
     183             :     - void ControlT::Enable( bool )
     184             :     - void ControlT::Show( bool )
     185             :  */
     186             : template< typename ControlT, typename ValueT >
     187           0 : class SingleControlWrapper : public ControlWrapperBase
     188             : {
     189             : public:
     190             :     typedef ControlT                                 ControlType;
     191             :     typedef ValueT                                   ControlValueType;
     192             :     typedef SingleControlWrapper< ControlT, ValueT > SingleControlWrapperType;
     193             : 
     194           0 :     inline explicit     SingleControlWrapper( ControlT& rControl ) : mrControl( rControl ) {}
     195             : 
     196             :     /** Returns a reference to the control this connection works on. */
     197           0 :     inline const ControlT& GetControl() const { return mrControl; }
     198             :     /** Returns a reference to the control this connection works on. */
     199           0 :     inline ControlT&    GetControl() { return mrControl; }
     200             : 
     201             :     /** Enables, disables, shows, or hides the control.
     202             :         @descr  Does nothing, if the corresponding parameter is TRISTATE_INDET. */
     203             :     virtual void        ModifyControl( TriState eEnable, TriState eShow ) SAL_OVERRIDE;
     204             : 
     205             :     /** Derived classes return the value the control contains. */
     206             :     virtual ValueT      GetControlValue() const = 0;
     207             :     /** Derived classes set the contents of the control to the passed value. */
     208             :     virtual void        SetControlValue( ValueT aValue ) = 0;
     209             : 
     210             : private:
     211             :     ControlT&           mrControl;  /// The control of this wrapper.
     212             : };
     213             : 
     214             : 
     215             : 
     216             : /** A dummy wrapper for a VCL Window that does nothing special.
     217             : 
     218             :     This wrapper is used to implement the DummyItemConnection. It does not
     219             :     connect an item to a control, but handles the special flags to disable or
     220             :     hide a control, if an item is unknown.
     221             :  */
     222           0 : class SFX2_DLLPUBLIC DummyWindowWrapper:
     223             :     public SingleControlWrapper< vcl::Window, void* >
     224             : {
     225             : public:
     226             :     explicit            DummyWindowWrapper( vcl::Window& rWindow );
     227             : 
     228             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     229             :     virtual void        SetControlDontKnow( bool ) SAL_OVERRIDE;
     230             : 
     231             :     virtual void*       GetControlValue() const SAL_OVERRIDE;
     232             :     virtual void        SetControlValue( void* ) SAL_OVERRIDE;
     233             : };
     234             : 
     235             : 
     236             : 
     237             : /** A wrapper for the VCL CheckBox. */
     238           0 : class SFX2_DLLPUBLIC CheckBoxWrapper:
     239             :     public SingleControlWrapper< CheckBox, bool >
     240             : {
     241             : public:
     242             :     explicit            CheckBoxWrapper( CheckBox& rCheckBox );
     243             : 
     244             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     245             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     246             : 
     247             :     virtual bool        GetControlValue() const SAL_OVERRIDE;
     248             :     virtual void        SetControlValue( bool bValue ) SAL_OVERRIDE;
     249             : };
     250             : 
     251             : 
     252             : 
     253             : /** A wrapper for the SVTOOLS ColorListBox. */
     254             : class SFX2_DLLPUBLIC ColorListBoxWrapper:
     255             :     public SingleControlWrapper< ColorListBox, Color >
     256             : {
     257             :     /*  Note: cannot use 'const Color&' as template argument, because the
     258             :         SVTOOLS ColorListBox returns the color by value and not by reference,
     259             :         therefore GetControlValue() must return a temporary object too. */
     260             : public:
     261             :     explicit ColorListBoxWrapper(ColorListBox & rListBox);
     262             : 
     263             :     virtual ~ColorListBoxWrapper();
     264             : 
     265             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     266             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     267             : 
     268             :     virtual Color       GetControlValue() const SAL_OVERRIDE;
     269             :     virtual void        SetControlValue( Color aColor ) SAL_OVERRIDE;
     270             : };
     271             : 
     272             : 
     273             : 
     274             : /** A wrapper for the VCL NumericField. */
     275             : template< typename ValueT >
     276             : class NumericFieldWrapper : public SingleControlWrapper< NumericField, ValueT >
     277             : {
     278             : public:
     279             :     inline explicit     NumericFieldWrapper( NumericField& rField ) :
     280             :                             SingleControlWrapper< NumericField, ValueT >( rField ) {}
     281             : 
     282             :     virtual bool        IsControlDontKnow() const;
     283             :     virtual void        SetControlDontKnow( bool bSet );
     284             : 
     285             :     virtual ValueT      GetControlValue() const;
     286             :     virtual void        SetControlValue( ValueT nValue );
     287             : };
     288             : 
     289             : 
     290             : 
     291             : typedef NumericFieldWrapper< sal_uInt16 > UInt16NumericFieldWrapper;
     292             : typedef NumericFieldWrapper< sal_uInt32 > UInt32NumericFieldWrapper;
     293             : 
     294             : typedef NumericFieldWrapper< sal_uInt16 > UShortNumericFieldWrapper;
     295             : typedef NumericFieldWrapper< sal_uIntPtr >  ULongNumericFieldWrapper;
     296             : 
     297             : 
     298             : 
     299             : /** A wrapper for the VCL MetricField.
     300             : 
     301             :     Adds support for field units during accessing the control value. The
     302             :     wrapper respects the field unit set at the control itself and converts it
     303             :     from/to the field unit passed to the constructor.
     304             :  */
     305             : template< typename ValueT >
     306           0 : class MetricFieldWrapper : public SingleControlWrapper< MetricField, ValueT >
     307             : {
     308             : public:
     309           0 :     inline explicit     MetricFieldWrapper( MetricField& rField, FieldUnit eUnit = FUNIT_NONE ) :
     310           0 :                             SingleControlWrapper< MetricField, ValueT >( rField ), meUnit( eUnit ) {}
     311             : 
     312             :     virtual bool        IsControlDontKnow() const;
     313             :     virtual void        SetControlDontKnow( bool bSet );
     314             : 
     315             :     virtual ValueT      GetControlValue() const;
     316             :     virtual void        SetControlValue( ValueT nValue );
     317             : 
     318             : private:
     319             :     FieldUnit           meUnit;
     320             : };
     321             : 
     322             : 
     323             : 
     324             : typedef MetricFieldWrapper< sal_Int16 >  Int16MetricFieldWrapper;
     325             : typedef MetricFieldWrapper< sal_uInt16 > UInt16MetricFieldWrapper;
     326             : typedef MetricFieldWrapper< sal_uInt32 > UInt32MetricFieldWrapper;
     327             : 
     328             : typedef MetricFieldWrapper< sal_uInt16 > UShortMetricFieldWrapper;
     329             : typedef MetricFieldWrapper< sal_uIntPtr >  ULongMetricFieldWrapper;
     330             : 
     331             : 
     332             : 
     333             : #define WRAPPER_LISTBOX_ENTRY_NOTFOUND  0xFFFF  /* XXX was value of LISTBOX_ENTRY_NOTFOUND */
     334             : 
     335             : /** A wrapper for the VCL ListBox.
     336             : 
     337             :     If a position<->value map is passed to the constructor, it MUST be
     338             :     terminated with an entry containing WRAPPER_LISTBOX_ENTRY_NOTFOUND as list
     339             :     position. See documentation of the PosValueMapper template for details.
     340             :  */
     341             : template< typename ValueT >
     342           0 : class ListBoxWrapper :
     343             :         public SingleControlWrapper< ListBox, ValueT >,
     344             :         public PosValueMapper< ListBoxPosType, ValueT >
     345             : {
     346             :     typedef PosValueMapper< ListBoxPosType, ValueT > MapperType;
     347             : 
     348             : public:
     349             :     typedef typename MapperType::MapEntryType MapEntryType;
     350             : 
     351             :     /** @param pMap  Optional list position <-> value map.
     352             :         See PosValueMapper documentation for details. */
     353           0 :     inline explicit     ListBoxWrapper( ListBox& rListBox, const MapEntryType* pMap = 0 ) :
     354           0 :                             SingleControlWrapper< ListBox, ValueT >( rListBox ), MapperType( WRAPPER_LISTBOX_ENTRY_NOTFOUND, pMap ) {}
     355             : 
     356           0 :     virtual bool        IsControlDontKnow() const
     357           0 :                             { return this->GetControl().GetSelectEntryCount() == 0; }
     358           0 :     virtual void        SetControlDontKnow( bool bSet )
     359           0 :                             { if( bSet ) this->GetControl().SetNoSelection(); }
     360             : 
     361             :     virtual ValueT      GetControlValue() const;
     362             :     virtual void        SetControlValue( ValueT nValue );
     363             : };
     364             : 
     365             : 
     366             : 
     367             : typedef ListBoxWrapper< sal_uInt16 > UInt16ListBoxWrapper;
     368             : typedef ListBoxWrapper< sal_uInt32 > UInt32ListBoxWrapper;
     369             : 
     370             : typedef ListBoxWrapper< sal_uInt16 > UShortListBoxWrapper;
     371             : typedef ListBoxWrapper< sal_uIntPtr >  ULongListBoxWrapper;
     372             : 
     373             : 
     374             : 
     375             : #define WRAPPER_VALUESET_ITEM_NOTFOUND  0xFFFF  /* XXX was value of VALUESET_ITEM_NOTFOUND */
     376             : 
     377             : /** A wrapper for the SVTOOLS ValueSet.
     378             : 
     379             :     If a position<->value map is passed to the constructor, it MUST be
     380             :     terminated with an entry containing WRAPPER_VALUESET_ITEM_NOTFOUND as list
     381             :     position. See documentation of the PosValueMapper template for details.
     382             :  */
     383             : template< typename ValueT >
     384           0 : class ValueSetWrapper :
     385             :         public SingleControlWrapper< ValueSet, ValueT >,
     386             :         public PosValueMapper< ValueSetPosType, ValueT >
     387             : {
     388             :     typedef PosValueMapper< ValueSetPosType, ValueT > MapperType;
     389             : 
     390             : public:
     391             :     typedef typename MapperType::MapEntryType MapEntryType;
     392             : 
     393             :     /** @param pMap  Optional position <-> value map.
     394             :         See PosValueMapper documentation for details. */
     395           0 :     inline explicit     ValueSetWrapper( ValueSet& rValueSet, const MapEntryType* pMap = 0 ) :
     396           0 :                             SingleControlWrapper< ValueSet, ValueT >( rValueSet ), MapperType( WRAPPER_VALUESET_ITEM_NOTFOUND, pMap ) {}
     397             : 
     398           0 :     virtual bool        IsControlDontKnow() const
     399           0 :                             { return this->GetControl().IsNoSelection(); }
     400           0 :     virtual void        SetControlDontKnow( bool bSet )
     401           0 :                             { if( bSet ) this->GetControl().SetNoSelection(); }
     402             : 
     403             :     virtual ValueT      GetControlValue() const;
     404             :     virtual void        SetControlValue( ValueT nValue );
     405             : };
     406             : 
     407             : 
     408             : 
     409             : typedef ValueSetWrapper< sal_uInt16 > UInt16ValueSetWrapper;
     410             : typedef ValueSetWrapper< sal_uInt32 > UInt32ValueSetWrapper;
     411             : 
     412             : typedef ValueSetWrapper< sal_uInt16 > UShortValueSetWrapper;
     413             : typedef ValueSetWrapper< sal_uIntPtr >  ULongValueSetWrapper;
     414             : 
     415             : 
     416             : // Multi control wrappers
     417             : 
     418             : 
     419             : struct MultiControlWrapperHelper_Impl;
     420             : 
     421             : /** A container of control wrappers.
     422             : 
     423             :     Derived classes should define control wrapper members and register them in
     424             :     their constructor, using the function RegisterControlWrapper().
     425             : 
     426             :     This wrapper implements the abstract functions of the ControlWrapperBase
     427             :     base class by calling the functions of all registered wrappers.
     428             :  */
     429             : class SFX2_DLLPUBLIC MultiControlWrapperHelper : public ControlWrapperBase
     430             : {
     431             : public:
     432             :     explicit            MultiControlWrapperHelper();
     433             :     virtual             ~MultiControlWrapperHelper();
     434             : 
     435             :     /** Registers a control wrapper (should be a member of a derived class). */
     436             :     void                RegisterControlWrapper( ControlWrapperBase& rWrapper );
     437             : 
     438             :     /** Enables, disables, shows, or hides the registered controls. */
     439             :     virtual void        ModifyControl( TriState eEnable, TriState eShow ) SAL_OVERRIDE;
     440             : 
     441             :     /** Returns true if all registered controls are in "don't know" state. */
     442             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     443             :     /** Sets all registered controls to "don't know" state. */
     444             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     445             : 
     446             : private:
     447             :     std::unique_ptr< MultiControlWrapperHelper_Impl > mxImpl;
     448             : };
     449             : 
     450             : 
     451             : 
     452             : /** A multi control wrapper with extended interface.
     453             : 
     454             :     This template class extends the MultiControlWrapperHelper class by the
     455             :     functions GetControlValue() and SetControlValue(), known from the
     456             :     SingleControlWrapper template. This makes it possible to use this template
     457             :     in item connections expecting a single control wrapper. The type ValueT
     458             :     should be able to contain the values of all controls handled in this
     459             :     wrapper. In most cases, the easiest way to achieve this is to use the
     460             :     related item type directly, using the IdentItemWrapper template
     461             :     (itemwrapper.hxx).
     462             :  */
     463             : template< typename ValueT >
     464           0 : class MultiControlWrapper : public MultiControlWrapperHelper
     465             : {
     466             : public:
     467             :     typedef MultiControlWrapperHelper       ControlType;
     468             :     typedef ValueT                          ControlValueType;
     469             :     typedef MultiControlWrapper< ValueT >   MultiControlWrapperType;
     470             : 
     471           0 :     MultiControlWrapper() : maDefValue( 0 ){}
     472             : 
     473             :     /** Returns the default value that can be used in GetControlValue(). */
     474           0 :     inline const ValueT& GetDefaultValue() const { return maDefValue; }
     475             :     /** Sets a default value that can be used in GetControlValue(). */
     476           0 :     inline void         SetDefaultValue( const ValueT& rDefValue ) { maDefValue = rDefValue; }
     477             : 
     478             :     /** Derived classes return the value the control contains. */
     479             :     virtual ValueT      GetControlValue() const = 0;
     480             :     /** Derived classes set the contents of the control to the passed value. */
     481             :     virtual void        SetControlValue( ValueT aValue ) = 0;
     482             : 
     483             : private:
     484             :     ValueT              maDefValue;
     485             : };
     486             : 
     487             : 
     488             : 
     489             : 
     490             : 
     491             : //               ***  Implementation of template functions  ***
     492             : 
     493             : 
     494             : 
     495             : // Helpers
     496             : 
     497             : 
     498             : template< typename PosT, typename ValueT >
     499           0 : ValueT PosValueMapper< PosT, ValueT >::GetValueFromPos( PosT nPos ) const
     500             : {
     501             :     ValueT nValue;
     502           0 :     if( mpMap )
     503             :     {
     504           0 :         const MapEntryType* pEntry = mpMap;
     505           0 :         while( (pEntry->mnPos != nPos) && (pEntry->mnPos != mnNFPos) )
     506           0 :             ++pEntry;
     507           0 :         nValue = pEntry->mnValue;
     508             :     }
     509             :     else /* if( nPos != mnNFPos ) */
     510             :     {
     511             :         DBG_ASSERT( nPos != mnNFPos, "sfx2::PosValueMapper< PosT, ValueT >::GetValueFromPos(), previously uninitialized value found!" );
     512           0 :         nValue = static_cast< ValueT >( nPos );
     513             :     }
     514             : 
     515           0 :     return nValue;
     516             : }
     517             : 
     518             : template< typename PosT, typename ValueT >
     519           0 : PosT PosValueMapper< PosT, ValueT >::GetPosFromValue( ValueT nValue ) const
     520             : {
     521           0 :     PosT nPos = mnNFPos;
     522           0 :     if( mpMap )
     523             :     {
     524           0 :         const MapEntryType* pEntry = mpMap;
     525           0 :         while( (pEntry->mnValue != nValue) && (pEntry->mnPos != mnNFPos) )
     526           0 :             ++pEntry;
     527           0 :         nPos = pEntry->mnPos;
     528             :     }
     529           0 :     else if( nValue >= 0 )
     530           0 :         nPos = static_cast< PosT >( nValue );
     531           0 :     return nPos;
     532             : }
     533             : 
     534             : 
     535             : // Single control wrappers
     536             : 
     537             : 
     538             : template< typename ControlT, typename ValueT >
     539           0 : inline void SingleControlWrapper< ControlT, ValueT >::ModifyControl( TriState eEnable, TriState eShow )
     540             : {
     541           0 :     if( eEnable != TRISTATE_INDET )
     542           0 :         mrControl.Enable( eEnable == TRISTATE_TRUE );
     543           0 :     if( eShow != TRISTATE_INDET )
     544           0 :         mrControl.Show( eShow == TRISTATE_TRUE );
     545           0 : }
     546             : 
     547             : 
     548             : 
     549             : template< typename ValueT >
     550             : bool NumericFieldWrapper< ValueT >::IsControlDontKnow() const
     551             : {
     552             :     return this->GetControl().GetText().Len() == 0;
     553             : }
     554             : 
     555             : template< typename ValueT >
     556             : void NumericFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
     557             : {
     558             :     if( bSet )
     559             :         this->GetControl().SetText( OUString() );
     560             : }
     561             : 
     562             : template< typename ValueT >
     563             : ValueT NumericFieldWrapper< ValueT >::GetControlValue() const
     564             : {
     565             :     return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue() ) );
     566             : }
     567             : 
     568             : template< typename ValueT >
     569             : void NumericFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
     570             : {
     571             :     this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ) );
     572             : }
     573             : 
     574             : 
     575             : 
     576             : template< typename ValueT >
     577           0 : bool MetricFieldWrapper< ValueT >::IsControlDontKnow() const
     578             : {
     579           0 :     return this->GetControl().GetText().isEmpty();
     580             : }
     581             : 
     582             : template< typename ValueT >
     583           0 : void MetricFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
     584             : {
     585           0 :     if( bSet )
     586           0 :         this->GetControl().SetText( OUString() );
     587           0 : }
     588             : 
     589             : template< typename ValueT >
     590           0 : ValueT MetricFieldWrapper< ValueT >::GetControlValue() const
     591             : {
     592           0 :     return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue( meUnit ) ) );
     593             : }
     594             : 
     595             : template< typename ValueT >
     596           0 : void MetricFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
     597             : {
     598           0 :     this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ), meUnit );
     599           0 : }
     600             : 
     601             : 
     602             : 
     603             : template< typename ValueT >
     604           0 : ValueT ListBoxWrapper< ValueT >::GetControlValue() const
     605             : {
     606           0 :     return this->GetValueFromPos( this->GetControl().GetSelectEntryPos() );
     607             : }
     608             : 
     609             : template< typename ValueT >
     610           0 : void ListBoxWrapper< ValueT >::SetControlValue( ValueT nValue )
     611             : {
     612           0 :     sal_uInt16 nPos = this->GetPosFromValue( nValue );
     613           0 :     if( nPos != this->GetNotFoundPos() )
     614           0 :         this->GetControl().SelectEntryPos( nPos );
     615           0 : }
     616             : 
     617             : 
     618             : 
     619             : template< typename ValueT >
     620           0 : ValueT ValueSetWrapper< ValueT >::GetControlValue() const
     621             : {
     622           0 :     return this->GetValueFromPos( this->GetControl().GetSelectItemId() );
     623             : }
     624             : 
     625             : template< typename ValueT >
     626           0 : void ValueSetWrapper< ValueT >::SetControlValue( ValueT nValue )
     627             : {
     628           0 :     sal_uInt16 nPos = this->GetPosFromValue( nValue );
     629           0 :     if( nPos != this->GetNotFoundPos() )
     630           0 :         this->GetControl().SelectItem( nPos );
     631           0 : }
     632             : 
     633             : 
     634             : 
     635             : 
     636             : } // namespace sfx
     637             : 
     638             : #endif
     639             : 
     640             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11