LCOV - code coverage report
Current view: top level - include/sfx2 - controlwrapper.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 80 0.0 %
Date: 2014-04-14 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             :     /* 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 TRISTATE_INDET. */
     204             :     virtual void        ModifyControl( TriState eEnable, TriState eShow ) SAL_OVERRIDE;
     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 SAL_OVERRIDE;
     230             :     virtual void        SetControlDontKnow( bool ) SAL_OVERRIDE;
     231             : 
     232             :     virtual void*       GetControlValue() const SAL_OVERRIDE;
     233             :     virtual void        SetControlValue( void* ) SAL_OVERRIDE;
     234             : };
     235             : 
     236             : 
     237             : 
     238             : /** A wrapper for the VCL CheckBox. */
     239           0 : class SFX2_DLLPUBLIC CheckBoxWrapper:
     240             :     public SingleControlWrapper< CheckBox, bool >
     241             : {
     242             : public:
     243             :     explicit            CheckBoxWrapper( CheckBox& rCheckBox );
     244             : 
     245             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     246             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     247             : 
     248             :     virtual bool        GetControlValue() const SAL_OVERRIDE;
     249             :     virtual void        SetControlValue( bool bValue ) SAL_OVERRIDE;
     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 SAL_OVERRIDE;
     267             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     268             : 
     269             :     virtual Color       GetControlValue() const SAL_OVERRIDE;
     270             :     virtual void        SetControlValue( Color aColor ) SAL_OVERRIDE;
     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           0 : class MetricFieldWrapper : public SingleControlWrapper< MetricField, ValueT >
     310             : {
     311             : public:
     312           0 :     inline explicit     MetricFieldWrapper( MetricField& rField, FieldUnit eUnit = FUNIT_NONE ) :
     313           0 :                             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             : #define WRAPPER_LISTBOX_ENTRY_NOTFOUND  0xFFFF  /* XXX was value of LISTBOX_ENTRY_NOTFOUND */
     338             : 
     339             : /** A wrapper for the VCL ListBox.
     340             : 
     341             :     If a position<->value map is passed to the constructor, it MUST be
     342             :     terminated with an entry containing WRAPPER_LISTBOX_ENTRY_NOTFOUND as list
     343             :     position. See documentation of the PosValueMapper template for details.
     344             :  */
     345             : template< typename ValueT >
     346           0 : class ListBoxWrapper :
     347             :         public SingleControlWrapper< ListBox, ValueT >,
     348             :         public PosValueMapper< ListBoxPosType, ValueT >
     349             : {
     350             :     typedef PosValueMapper< ListBoxPosType, ValueT > MapperType;
     351             : 
     352             : public:
     353             :     typedef typename MapperType::MapEntryType MapEntryType;
     354             : 
     355             :     /** @param pMap  Optional list position <-> value map.
     356             :         See PosValueMapper documentation for details. */
     357           0 :     inline explicit     ListBoxWrapper( ListBox& rListBox, const MapEntryType* pMap = 0 ) :
     358           0 :                             SingleControlWrapper< ListBox, ValueT >( rListBox ), MapperType( WRAPPER_LISTBOX_ENTRY_NOTFOUND, pMap ) {}
     359             : 
     360           0 :     virtual bool        IsControlDontKnow() const
     361           0 :                             { return this->GetControl().GetSelectEntryCount() == 0; }
     362           0 :     virtual void        SetControlDontKnow( bool bSet )
     363           0 :                             { if( bSet ) this->GetControl().SetNoSelection(); }
     364             : 
     365             :     virtual ValueT      GetControlValue() const;
     366             :     virtual void        SetControlValue( ValueT nValue );
     367             : };
     368             : 
     369             : 
     370             : 
     371             : typedef ListBoxWrapper< sal_Int16 >  Int16ListBoxWrapper;
     372             : typedef ListBoxWrapper< sal_uInt16 > UInt16ListBoxWrapper;
     373             : typedef ListBoxWrapper< sal_Int32 >  Int32ListBoxWrapper;
     374             : typedef ListBoxWrapper< sal_uInt32 > UInt32ListBoxWrapper;
     375             : 
     376             : typedef ListBoxWrapper< sal_uInt16 > UShortListBoxWrapper;
     377             : typedef ListBoxWrapper< sal_uIntPtr >  ULongListBoxWrapper;
     378             : 
     379             : 
     380             : 
     381             : #define WRAPPER_VALUESET_ITEM_NOTFOUND  0xFFFF  /* XXX was value of VALUESET_ITEM_NOTFOUND */
     382             : 
     383             : /** A wrapper for the SVTOOLS ValueSet.
     384             : 
     385             :     If a position<->value map is passed to the constructor, it MUST be
     386             :     terminated with an entry containing WRAPPER_VALUESET_ITEM_NOTFOUND as list
     387             :     position. See documentation of the PosValueMapper template for details.
     388             :  */
     389             : template< typename ValueT >
     390           0 : class ValueSetWrapper :
     391             :         public SingleControlWrapper< ValueSet, ValueT >,
     392             :         public PosValueMapper< ValueSetPosType, ValueT >
     393             : {
     394             :     typedef PosValueMapper< ValueSetPosType, ValueT > MapperType;
     395             : 
     396             : public:
     397             :     typedef typename MapperType::MapEntryType MapEntryType;
     398             : 
     399             :     /** @param pMap  Optional position <-> value map.
     400             :         See PosValueMapper documentation for details. */
     401           0 :     inline explicit     ValueSetWrapper( ValueSet& rValueSet, const MapEntryType* pMap = 0 ) :
     402           0 :                             SingleControlWrapper< ValueSet, ValueT >( rValueSet ), MapperType( WRAPPER_VALUESET_ITEM_NOTFOUND, pMap ) {}
     403             : 
     404           0 :     virtual bool        IsControlDontKnow() const
     405           0 :                             { return this->GetControl().IsNoSelection(); }
     406           0 :     virtual void        SetControlDontKnow( bool bSet )
     407           0 :                             { if( bSet ) this->GetControl().SetNoSelection(); }
     408             : 
     409             :     virtual ValueT      GetControlValue() const;
     410             :     virtual void        SetControlValue( ValueT nValue );
     411             : };
     412             : 
     413             : 
     414             : 
     415             : typedef ValueSetWrapper< sal_Int16 >  Int16ValueSetWrapper;
     416             : typedef ValueSetWrapper< sal_uInt16 > UInt16ValueSetWrapper;
     417             : typedef ValueSetWrapper< sal_Int32 >  Int32ValueSetWrapper;
     418             : typedef ValueSetWrapper< sal_uInt32 > UInt32ValueSetWrapper;
     419             : 
     420             : typedef ValueSetWrapper< sal_uInt16 > UShortValueSetWrapper;
     421             : typedef ValueSetWrapper< sal_uIntPtr >  ULongValueSetWrapper;
     422             : 
     423             : 
     424             : // Multi control wrappers
     425             : 
     426             : 
     427             : struct MultiControlWrapperHelper_Impl;
     428             : 
     429             : /** A container of control wrappers.
     430             : 
     431             :     Derived classes should define control wrapper members and register them in
     432             :     their constructor, using the function RegisterControlWrapper().
     433             : 
     434             :     This wrapper implements the abstract functions of the ControlWrapperBase
     435             :     base class by calling the functions of all registered wrappers.
     436             :  */
     437             : class SFX2_DLLPUBLIC MultiControlWrapperHelper : public ControlWrapperBase
     438             : {
     439             : public:
     440             :     explicit            MultiControlWrapperHelper();
     441             :     virtual             ~MultiControlWrapperHelper();
     442             : 
     443             :     /** Registers a control wrapper (should be a member of a derived class). */
     444             :     void                RegisterControlWrapper( ControlWrapperBase& rWrapper );
     445             : 
     446             :     /** Enables, disables, shows, or hides the registered controls. */
     447             :     virtual void        ModifyControl( TriState eEnable, TriState eShow ) SAL_OVERRIDE;
     448             : 
     449             :     /** Returns true if all registered controls are in "don't know" state. */
     450             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     451             :     /** Sets all registered controls to "don't know" state. */
     452             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     453             : 
     454             : private:
     455             :     std::auto_ptr< MultiControlWrapperHelper_Impl > mxImpl;
     456             : };
     457             : 
     458             : 
     459             : 
     460             : /** A multi control wrapper with extended interface.
     461             : 
     462             :     This template class extends the MultiControlWrapperHelper class by the
     463             :     functions GetControlValue() and SetControlValue(), known from the
     464             :     SingleControlWrapper template. This makes it possible to use this template
     465             :     in item connections expecting a single control wrapper. The type ValueT
     466             :     should be able to contain the values of all controls handled in this
     467             :     wrapper. In most cases, the easiest way to achieve this is to use the
     468             :     related item type directly, using the IdentItemWrapper template
     469             :     (itemwrapper.hxx).
     470             :  */
     471             : template< typename ValueT >
     472           0 : class MultiControlWrapper : public MultiControlWrapperHelper
     473             : {
     474             : public:
     475             :     typedef MultiControlWrapperHelper       ControlType;
     476             :     typedef ValueT                          ControlValueType;
     477             :     typedef MultiControlWrapper< ValueT >   MultiControlWrapperType;
     478             : 
     479           0 :     MultiControlWrapper() : maDefValue( 0 ){}
     480             : 
     481             :     /** Returns the default value that can be used in GetControlValue(). */
     482           0 :     inline const ValueT& GetDefaultValue() const { return maDefValue; }
     483             :     /** Sets a default value that can be used in GetControlValue(). */
     484           0 :     inline void         SetDefaultValue( const ValueT& rDefValue ) { maDefValue = rDefValue; }
     485             : 
     486             :     /** Derived classes return the value the control contains. */
     487             :     virtual ValueT      GetControlValue() const = 0;
     488             :     /** Derived classes set the contents of the control to the passed value. */
     489             :     virtual void        SetControlValue( ValueT aValue ) = 0;
     490             : 
     491             : private:
     492             :     ValueT              maDefValue;
     493             : };
     494             : 
     495             : 
     496             : 
     497             : 
     498             : 
     499             : //               ***  Implementation of template functions  ***
     500             : 
     501             : 
     502             : 
     503             : // Helpers
     504             : 
     505             : 
     506             : template< typename PosT, typename ValueT >
     507           0 : ValueT PosValueMapper< PosT, ValueT >::GetValueFromPos( PosT nPos ) const
     508             : {
     509             :     ValueT nValue;
     510           0 :     if( mpMap )
     511             :     {
     512           0 :         const MapEntryType* pEntry = mpMap;
     513           0 :         while( (pEntry->mnPos != nPos) && (pEntry->mnPos != mnNFPos) )
     514           0 :             ++pEntry;
     515           0 :         nValue = pEntry->mnValue;
     516             :     }
     517             :     else /* if( nPos != mnNFPos ) */
     518             :     {
     519             :         DBG_ASSERT( nPos != mnNFPos, "sfx2::PosValueMapper< PosT, ValueT >::GetValueFromPos(), previously uninitialized value found!" );
     520           0 :         nValue = static_cast< ValueT >( nPos );
     521             :     }
     522             : 
     523           0 :     return nValue;
     524             : }
     525             : 
     526             : template< typename PosT, typename ValueT >
     527           0 : PosT PosValueMapper< PosT, ValueT >::GetPosFromValue( ValueT nValue ) const
     528             : {
     529           0 :     PosT nPos = mnNFPos;
     530           0 :     if( mpMap )
     531             :     {
     532           0 :         const MapEntryType* pEntry = mpMap;
     533           0 :         while( (pEntry->mnValue != nValue) && (pEntry->mnPos != mnNFPos) )
     534           0 :             ++pEntry;
     535           0 :         nPos = pEntry->mnPos;
     536             :     }
     537           0 :     else if( nValue >= 0 )
     538           0 :         nPos = static_cast< PosT >( nValue );
     539           0 :     return nPos;
     540             : }
     541             : 
     542             : 
     543             : // Single control wrappers
     544             : 
     545             : 
     546             : template< typename ControlT, typename ValueT >
     547           0 : inline void SingleControlWrapper< ControlT, ValueT >::ModifyControl( TriState eEnable, TriState eShow )
     548             : {
     549           0 :     if( eEnable != TRISTATE_INDET )
     550           0 :         mrControl.Enable( eEnable == TRISTATE_TRUE );
     551           0 :     if( eShow != TRISTATE_INDET )
     552           0 :         mrControl.Show( eShow == TRISTATE_TRUE );
     553           0 : }
     554             : 
     555             : 
     556             : 
     557             : template< typename ValueT >
     558             : bool NumericFieldWrapper< ValueT >::IsControlDontKnow() const
     559             : {
     560             :     return this->GetControl().GetText().Len() == 0;
     561             : }
     562             : 
     563             : template< typename ValueT >
     564             : void NumericFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
     565             : {
     566             :     if( bSet )
     567             :         this->GetControl().SetText( OUString() );
     568             : }
     569             : 
     570             : template< typename ValueT >
     571             : ValueT NumericFieldWrapper< ValueT >::GetControlValue() const
     572             : {
     573             :     return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue() ) );
     574             : }
     575             : 
     576             : template< typename ValueT >
     577             : void NumericFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
     578             : {
     579             :     this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ) );
     580             : }
     581             : 
     582             : 
     583             : 
     584             : template< typename ValueT >
     585           0 : bool MetricFieldWrapper< ValueT >::IsControlDontKnow() const
     586             : {
     587           0 :     return this->GetControl().GetText().isEmpty();
     588             : }
     589             : 
     590             : template< typename ValueT >
     591           0 : void MetricFieldWrapper< ValueT >::SetControlDontKnow( bool bSet )
     592             : {
     593           0 :     if( bSet )
     594           0 :         this->GetControl().SetText( OUString() );
     595           0 : }
     596             : 
     597             : template< typename ValueT >
     598           0 : ValueT MetricFieldWrapper< ValueT >::GetControlValue() const
     599             : {
     600           0 :     return static_cast< ValueT >( this->GetControl().Denormalize( this->GetControl().GetValue( meUnit ) ) );
     601             : }
     602             : 
     603             : template< typename ValueT >
     604           0 : void MetricFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
     605             : {
     606           0 :     this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ), meUnit );
     607           0 : }
     608             : 
     609             : 
     610             : 
     611             : template< typename ValueT >
     612           0 : ValueT ListBoxWrapper< ValueT >::GetControlValue() const
     613             : {
     614           0 :     return this->GetValueFromPos( this->GetControl().GetSelectEntryPos() );
     615             : }
     616             : 
     617             : template< typename ValueT >
     618           0 : void ListBoxWrapper< ValueT >::SetControlValue( ValueT nValue )
     619             : {
     620           0 :     sal_uInt16 nPos = this->GetPosFromValue( nValue );
     621           0 :     if( nPos != this->GetNotFoundPos() )
     622           0 :         this->GetControl().SelectEntryPos( nPos );
     623           0 : }
     624             : 
     625             : 
     626             : 
     627             : template< typename ValueT >
     628           0 : ValueT ValueSetWrapper< ValueT >::GetControlValue() const
     629             : {
     630           0 :     return this->GetValueFromPos( this->GetControl().GetSelectItemId() );
     631             : }
     632             : 
     633             : template< typename ValueT >
     634           0 : void ValueSetWrapper< ValueT >::SetControlValue( ValueT nValue )
     635             : {
     636           0 :     sal_uInt16 nPos = this->GetPosFromValue( nValue );
     637           0 :     if( nPos != this->GetNotFoundPos() )
     638           0 :         this->GetControl().SelectItem( nPos );
     639           0 : }
     640             : 
     641             : 
     642             : 
     643             : 
     644             : } // namespace sfx
     645             : 
     646             : #endif
     647             : 
     648             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10