LCOV - code coverage report
Current view: top level - include/sfx2 - itemconnect.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 48 0.0 %
Date: 2014-04-14 Functions: 0 80 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_ITEMCONNECT_HXX
      21             : #define INCLUDED_SFX2_ITEMCONNECT_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : #include <sfx2/dllapi.h>
      25             : 
      26             : #include <memory>
      27             : 
      28             : #include <boost/scoped_ptr.hpp>
      29             : #include <sfx2/itemwrapper.hxx>
      30             : #include <sfx2/controlwrapper.hxx>
      31             : 
      32             : 
      33             : 
      34             : namespace sfx {
      35             : 
      36             : 
      37             : 
      38             : typedef int ItemConnFlags;
      39             : 
      40             : /** No special state for the connection. */
      41             : const ItemConnFlags ITEMCONN_NONE               = 0x0000;
      42             : 
      43             : /** Connection is inactive - virtual functions will not be called. */
      44             : const ItemConnFlags ITEMCONN_INACTIVE           = 0x0001;
      45             : 
      46             : /** Enable control(s), if the item is known. */
      47             : const ItemConnFlags ITEMCONN_ENABLE_KNOWN       = 0x0010;
      48             : /** Disable control(s), if the item is unknown. */
      49             : const ItemConnFlags ITEMCONN_DISABLE_UNKNOWN    = 0x0020;
      50             : /** Show control(s), if the item is known. */
      51             : const ItemConnFlags ITEMCONN_SHOW_KNOWN         = 0x0040;
      52             : /** Hide control(s), if the item is unknown. */
      53             : const ItemConnFlags ITEMCONN_HIDE_UNKNOWN       = 0x0080;
      54             : 
      55             : /** Default value for constructors. */
      56             : const ItemConnFlags ITEMCONN_DEFAULT            = ITEMCONN_NONE;
      57             : 
      58             : 
      59             : // Base connection classes
      60             : 
      61             : 
      62             : /** A helper for SfxTabPages to connect controls to items.
      63             : 
      64             :     This is the base class of all control connection classes. Their purpose is
      65             :     to connect one or more controls from an SfxTabPage with an item from an
      66             :     item set. The goal is to omit any additional code in the virtual functions
      67             :     Reset() and FillItemSet() in classes derived from SfxTabPage.
      68             : 
      69             :     Examples of connections:
      70             :     - A check box with an SfxBoolItem,
      71             :     - A metric (spin) field with an SfxInt32Item.
      72             :     - A group of radio buttons with an SfxEnumItem.
      73             : 
      74             :     Each SfxTabPage will contain a list of connection objects (derived from
      75             :     this class). The connection objects remember the item and control(s) they
      76             :     have to work on. The SfxTabPage will call the DoApplyFlags(), DoReset(),
      77             :     and DoFillItemSet() functions of all connection objects it knows. The code
      78             :     to initialize control(s) from the item value and fill the item from
      79             :     control(s) has to be written only once for each control type.
      80             : 
      81             :     Additional flags passed in the constructor allow to control the behaviour
      82             :     of the control(s) if the item is supported/unsupported in the currently
      83             :     used item set. For example, it is possible to specify that a control will
      84             :     be disabled or hidden if the item is not supported. This is done before
      85             :     each call of Reset().
      86             : 
      87             :     The special flag ITEMCONN_CLONE_ITEM controls how to create new items in
      88             :     the DoFillItemSet() function. The standard (and faster) method is to create
      89             :     a temporary item on the stack and put it into the item set. But this does
      90             :     not work if the item set expects a special item type derived from a common
      91             :     item class, i.e. a Boolean item derived from SfxBoolItem providing special
      92             :     item representation text. As this code does not know the item type, the
      93             :     item cannot be created on the stack. For this case the flag specifies to
      94             :     use the virtual Clone() method of the pool default item. This will create
      95             :     an item of the correct type but can still be used in conjunction with i.e.
      96             :     the standard BoolItemWrapper.
      97             : 
      98             :     How to use the item connection feature:
      99             : 
     100             :     A)  Single item <-> single control connection
     101             : 
     102             :         Example: An SfxBoolItem and a check box.
     103             : 
     104             :         A1) Create a new item wrapper class derived from the SingleItemWrapper
     105             :             template, or use the template directly, or use one of the
     106             :             predefined item wrappers. See documentation of the
     107             :             SingleItemWrapper template for details (itemwrapper.hxx).
     108             :         A2) Create a new control wrapper class derived from the
     109             :             SingleControlWrapper template and implement the abstract functions,
     110             :             or use one of the predefined control wrappers. See documentation of
     111             :             the SingleControlWrapper template for details (controlwrapper.hxx).
     112             :         A3) Create a new connection class derived from one of the following
     113             :             base classes, and implement the abstract functions, or use the
     114             :             ItemControlConnection template directly, or use one of the
     115             :             predefined connections.
     116             :         A4) Create connection objects in the constructor of the tab page, and
     117             :             insert them into the tab page with SfxTabPage::AddItemConnection().
     118             :         A5) Remove old code from the tab page's Reset() and FillItemSet()
     119             :             functions, if necessary.
     120             : 
     121             :     B)  Single item <-> multiple controls connections
     122             : 
     123             :         B1) See step A1. If the item contains multiple values (and not a
     124             :             structure that contains all the values for the different controls),
     125             :             the best way is to use the IdentItemWrapper template, that works
     126             :             with the item itself. This way it is possible to provide a 'data
     127             :             type' that contains the values for all controls.
     128             :         B2) Create a new control wrapper class derived from the
     129             :             MultiControlWrapper template. Add single control wrapper members
     130             :             for all controls to this class and register them in the
     131             :             constructor, using the RegisterControlWrapper() function. Implement
     132             :             the abstract functions GetControlValue() and SetControlValue().
     133             :             These functions should call the respective functions of the own
     134             :             single control wrappers and either fill a new data object (the item
     135             :             itself in most cases, see step B1) with all the values from the
     136             :             controls, or fill all the controls from the data object.
     137             :         B3) Create a new connection class derived from ItemControlConnection,
     138             :             or use the ItemControlConnection template directly. The multiple
     139             :             control wrapper from step B2 acts like a single control, therefore
     140             :             it is possible to use the ItemControlConnection.
     141             :         B4) See steps A4 and A5.
     142             : 
     143             :     C)  Multiple items <-> single control connections
     144             : 
     145             :         todo
     146             : 
     147             :     D)  Multiple items <-> multiple controls connections
     148             : 
     149             :         todo
     150             : 
     151             :     The current tree of base classes/templates and standard connections:
     152             : 
     153             :     ItemConnectionBase
     154             :      |
     155             :      +- DummyItemConnection   [1]
     156             :      |
     157             :      +- ItemControlConnection< ItemWrpT, ControlWrpT >
     158             :      |   |
     159             :      |   +- CheckBoxConnection   [1]
     160             :      |   |
     161             :      |   +- NumericConnection< ItemWrpT >   [1]
     162             :      |   |   |
     163             :      |   |   +- [ValueType]NumericConnection   [1] [2]
     164             :      |   |
     165             :      |   +- MetricConnection< ItemWrpT >   [1]
     166             :      |   |   |
     167             :      |   |   +- [ValueType]MetricConnection   [1] [2]
     168             :      |   |
     169             :      |   +- ListBoxConnection< ItemWrpT >   [1]
     170             :      |   |   |
     171             :      |   |   +- [ValueType]ListBoxConnection   [1] [2]
     172             :      |   |
     173             :      |   +- ValueSetConnection< ItemWrpT >   [1]
     174             :      |       |
     175             :      |       +- [ValueType]ValueSetConnection   [1] [2]
     176             :      |
     177             :      +- ItemConnectionArray   [1]
     178             : 
     179             :     Notes:
     180             :     [1] Standard connections ready to use.
     181             :     [2] [ValueType] is one of Int16, UInt16, Int32, UInt32.
     182             :  */
     183             : class SFX2_DLLPUBLIC ItemConnectionBase
     184             : {
     185             : public:
     186             :     virtual             ~ItemConnectionBase();
     187             : 
     188             :     /** Returns the flags passed in the constructor. */
     189             :     inline ItemConnFlags GetFlags() const { return mnFlags; }
     190             : 
     191             :     /** Returns true if this connection is active. */
     192             :     bool                IsActive() const;
     193             : 
     194             :     /** Calls the virtual ApplyFlags() function, if connection is active. */
     195             :     void                DoApplyFlags( const SfxItemSet& rItemSet );
     196             :     /** Calls the virtual Reset() function, if connection is active. */
     197             :     void                DoReset( const SfxItemSet& rItemSet );
     198             :     /** Calls the virtual FillItemSet() function, if connection is active. */
     199             :     bool                DoFillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
     200             : 
     201             : protected:
     202             :     explicit            ItemConnectionBase( ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     203             : 
     204             :     /** Derived classes implement actions according to current flags here. */
     205             :     virtual void        ApplyFlags( const SfxItemSet& rItemSet ) = 0;
     206             :     /** Derived classes implement initializing controls from item sets here. */
     207             :     virtual void        Reset( const SfxItemSet& rItemSet ) = 0;
     208             :     /** Derived classes implement filling item sets from controls here. */
     209             :     virtual bool        FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet ) = 0;
     210             : 
     211             :     /** Returns whether to enable a control, according to current flags. */
     212             :     TriState            GetEnableState( bool bKnown ) const;
     213             :     /** Returns whether to show a control, according to current flags. */
     214             :     TriState            GetShowState( bool bKnown ) const;
     215             : 
     216             : private:
     217             :     /* Disable copy c'tor and assignment. */
     218             :                         ItemConnectionBase( const ItemConnectionBase& );
     219             :     ItemConnectionBase& operator=( const ItemConnectionBase& );
     220             : 
     221             :     ItemConnFlags       mnFlags;    /// Flags for additional options.
     222             : };
     223             : 
     224             : 
     225             : 
     226             : /** Base class template for single item <-> single control connection objects.
     227             : 
     228             :     This template uses functions provided by the SingleItemWrapper and the
     229             :     SingleControlWrapper template classes. The virtual functions ApplyFlags(),
     230             :     Reset(), and FillItemSet() are implemented here in a generic way using the
     231             :     virtual functions of the wrapper classes. Derived classes only have to
     232             :     create or otherwise provide appropriate wrappers.
     233             :  */
     234             : template< typename ItemWrpT, typename ControlWrpT >
     235             : class ItemControlConnection : public ItemConnectionBase
     236             : {
     237             : public:
     238             :     typedef ItemWrpT                                        ItemWrapperType;
     239             :     typedef ControlWrpT                                     ControlWrapperType;
     240             :     typedef ItemControlConnection< ItemWrpT, ControlWrpT >  ItemControlConnectionType;
     241             :     typedef typename ItemWrpT::ItemType                     ItemType;
     242             :     typedef typename ItemWrpT::ItemValueType                ItemValueType;
     243             :     typedef typename ControlWrpT::ControlType               ControlType;
     244             :     typedef typename ControlWrpT::ControlValueType          ControlValueType;
     245             : 
     246             :     typedef std::auto_ptr< ItemWrpT >                       ItemWrapperRef;
     247             :     typedef std::auto_ptr< ControlWrpT >                    ControlWrapperRef;
     248             : 
     249             :     /** Receives pointer to a newly created control wrapper.
     250             :         @descr  Takes ownership of the control wrapper. */
     251             :     explicit            ItemControlConnection( sal_uInt16 nSlot, ControlWrpT* pNewCtrlWrp,
     252             :                             ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     253             : 
     254             :     /** Convenience constructor. Receives reference to a control directly.
     255             :         @descr  May only be used, if ControlWrpT::ControlWrpT( ControlType& )
     256             :         constructor exists. */
     257             :     explicit            ItemControlConnection( sal_uInt16 nSlot, ControlType& rControl,
     258             :                             ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     259             : 
     260             :     virtual             ~ItemControlConnection();
     261             : 
     262             : protected:
     263             :     /** Actions according to current flags for the control. */
     264             :     virtual void        ApplyFlags( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     265             :     /** Resets the control according to the item contents. */
     266             :     virtual void        Reset( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     267             :     /** Fills the item set according to the control's state. */
     268             :     virtual bool        FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet ) SAL_OVERRIDE;
     269             : 
     270             :     ItemWrapperType     maItemWrp;
     271             :     ControlWrapperRef   mxCtrlWrp;
     272             : };
     273             : 
     274             : 
     275             : // Standard connections
     276             : 
     277             : 
     278             : /** This is a helper class to enable/disable/show/hide a control only.
     279             : 
     280             :     This class does nothing special in the Reset() and FillItemSet() functions.
     281             :     It can be used to control the visibility of i.e. fixed lines or fixed texts
     282             :     related to the availability of an item by passing the appropriate flags to
     283             :     the constructor of this connection.
     284             :  */
     285           0 : class SFX2_DLLPUBLIC DummyItemConnection:
     286             :     public ItemConnectionBase, public DummyWindowWrapper
     287             : {
     288             : public:
     289             :     explicit            DummyItemConnection( sal_uInt16 nSlot, Window& rWindow,
     290             :                             ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     291             : 
     292             : protected:
     293             :     virtual void        ApplyFlags( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     294             :     virtual void        Reset( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     295             :     virtual bool        FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet ) SAL_OVERRIDE;
     296             : 
     297             : private:
     298             :     sal_uInt16              mnSlot;
     299             : };
     300             : 
     301             : 
     302             : 
     303             : /** Connection between an SfxBoolItem and a VCL CheckBox. */
     304             : typedef ItemControlConnection< BoolItemWrapper, CheckBoxWrapper > CheckBoxConnection;
     305             : 
     306             : 
     307             : 
     308             : /** Connection between an item and the VCL NumericField. */
     309             : template< typename ItemWrpT >
     310             : class NumericConnection : public ItemControlConnection< ItemWrpT,
     311             :         NumericFieldWrapper< typename ItemWrpT::ItemValueType > >
     312             : {
     313             :     typedef ItemControlConnection< ItemWrpT,
     314             :         NumericFieldWrapper< typename ItemWrpT::ItemValueType > >
     315             :     ItemControlConnectionType;
     316             : 
     317             : public:
     318             :     typedef typename ItemControlConnectionType::ControlWrapperType NumericFieldWrapperType;
     319             : 
     320             :     explicit            NumericConnection( sal_uInt16 nSlot, NumericField& rField,
     321             :                             ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     322             : };
     323             : 
     324             : 
     325             : 
     326             : typedef NumericConnection< Int16ItemWrapper  > Int16NumericConnection;
     327             : typedef NumericConnection< UInt16ItemWrapper > UInt16NumericConnection;
     328             : typedef NumericConnection< Int32ItemWrapper  > Int32NumericConnection;
     329             : typedef NumericConnection< UInt32ItemWrapper > UInt32NumericConnection;
     330             : 
     331             : 
     332             : 
     333             : /** Connection between an item and the VCL MetricField.
     334             : 
     335             :     Adds support of different field units during control value <-> item value
     336             :     conversion. The field unit passed to the constructor applies for the item
     337             :     values, while the field unit used in the control has to be set at the
     338             :     control itself.
     339             :  */
     340             : template< typename ItemWrpT >
     341           0 : class MetricConnection : public ItemControlConnection< ItemWrpT,
     342             :         MetricFieldWrapper< typename ItemWrpT::ItemValueType > >
     343             : {
     344             :     typedef ItemControlConnection< ItemWrpT,
     345             :         MetricFieldWrapper< typename ItemWrpT::ItemValueType > >
     346             :     ItemControlConnectionType;
     347             : 
     348             : public:
     349             :     typedef typename ItemControlConnectionType::ControlWrapperType MetricFieldWrapperType;
     350             : 
     351             :     explicit            MetricConnection( sal_uInt16 nSlot, MetricField& rField,
     352             :                             FieldUnit eItemUnit = FUNIT_NONE, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     353             : };
     354             : 
     355             : 
     356             : 
     357             : typedef MetricConnection< Int16ItemWrapper  > Int16MetricConnection;
     358             : typedef MetricConnection< UInt16ItemWrapper > UInt16MetricConnection;
     359             : typedef MetricConnection< Int32ItemWrapper  > Int32MetricConnection;
     360             : typedef MetricConnection< UInt32ItemWrapper > UInt32MetricConnection;
     361             : 
     362             : 
     363             : 
     364             : /** Connection between an item and a VCL ListBox.
     365             : 
     366             :     Optionally a map can be passed that maps list box positions to item values.
     367             :     This map MUST be terminated with an entry containing
     368             :     WRAPPER_LISTBOX_ENTRY_NOTFOUND as list box position. The item value
     369             :     contained in this last entry is used as default item value in case of an
     370             :     error.
     371             :  */
     372             : template< typename ItemWrpT >
     373           0 : class ListBoxConnection : public ItemControlConnection< ItemWrpT,
     374             :         ListBoxWrapper< typename ItemWrpT::ItemValueType > >
     375             : {
     376             :     typedef ItemControlConnection< ItemWrpT,
     377             :         ListBoxWrapper< typename ItemWrpT::ItemValueType > >
     378             :     ItemControlConnectionType;
     379             : 
     380             : public:
     381             :     typedef typename ItemControlConnectionType::ControlWrapperType  ListBoxWrapperType;
     382             :     typedef typename ListBoxWrapperType::MapEntryType               MapEntryType;
     383             : 
     384             :     explicit            ListBoxConnection( sal_uInt16 nSlot, ListBox& rListBox,
     385             :                             const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     386             : };
     387             : 
     388             : 
     389             : 
     390             : typedef ListBoxConnection< Int16ItemWrapper >  Int16ListBoxConnection;
     391             : typedef ListBoxConnection< UInt16ItemWrapper > UInt16ListBoxConnection;
     392             : typedef ListBoxConnection< Int32ItemWrapper >  Int32ListBoxConnection;
     393             : typedef ListBoxConnection< UInt32ItemWrapper > UInt32ListBoxConnection;
     394             : 
     395             : 
     396             : 
     397             : /** Connection between an item and an SVTOOLS ValueSet.
     398             : 
     399             :     Optionally a map can be passed that maps value set identifiers to item
     400             :     values. This map MUST be terminated with an entry containing
     401             :     WRAPPER_VALUESET_ITEM_NOTFOUND as value set identifier. The item value
     402             :     contained in this last entry is used as default item value in case of an
     403             :     error.
     404             :  */
     405             : template< typename ItemWrpT >
     406           0 : class ValueSetConnection : public ItemControlConnection< ItemWrpT,
     407             :         ValueSetWrapper< typename ItemWrpT::ItemValueType > >
     408             : {
     409             :     typedef ItemControlConnection< ItemWrpT,
     410             :         ValueSetWrapper< typename ItemWrpT::ItemValueType > >
     411             :     ItemControlConnectionType;
     412             : 
     413             : public:
     414             :     typedef typename ItemControlConnectionType::ControlWrapperType  ValueSetWrapperType;
     415             :     typedef typename ValueSetWrapperType::MapEntryType              MapEntryType;
     416             : 
     417             :     explicit            ValueSetConnection( sal_uInt16 nSlot, ValueSet& rValueSet,
     418             :                             const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
     419             : };
     420             : 
     421             : 
     422             : 
     423             : typedef ValueSetConnection< Int16ItemWrapper >  Int16ValueSetConnection;
     424             : typedef ValueSetConnection< UInt16ItemWrapper > UInt16ValueSetConnection;
     425             : typedef ValueSetConnection< Int32ItemWrapper >  Int32ValueSetConnection;
     426             : typedef ValueSetConnection< UInt32ItemWrapper > UInt32ValueSetConnection;
     427             : 
     428             : 
     429             : // Array of connections
     430             : 
     431             : 
     432             : class ItemConnectionArrayImpl;
     433             : 
     434             : /** A container of connection objects.
     435             : 
     436             :     This is a connection with the only purpose to contain other connection
     437             :     objects. This way it is possible to create a tree structure of connections
     438             :     for a convenient connection management. This class is used by the class
     439             :     SfxTabPage to store all connections.
     440             :  */
     441             : class ItemConnectionArray : public ItemConnectionBase
     442             : {
     443             : public:
     444             :     explicit            ItemConnectionArray();
     445             :     virtual             ~ItemConnectionArray();
     446             : 
     447             :     /** Adds a new connection to the list.
     448             :         @descr  Takes ownership of the connection! */
     449             :     void                AddConnection( ItemConnectionBase* pConnection );
     450             : 
     451             : protected:
     452             :     virtual void        ApplyFlags( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     453             :     virtual void        Reset( const SfxItemSet& rItemSet ) SAL_OVERRIDE;
     454             :     virtual bool        FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet ) SAL_OVERRIDE;
     455             : 
     456             : private:
     457             :     std::auto_ptr< ItemConnectionArrayImpl > mxImpl;
     458             : };
     459             : 
     460             : 
     461             : 
     462             : 
     463             : //               ***  Implementation of template functions  ***
     464             : 
     465             : 
     466             : 
     467             : // Base connection classes
     468             : 
     469             : 
     470             : template< typename ItemWrpT, typename ControlWrpT >
     471           0 : ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
     472             :         sal_uInt16 nSlot, ControlWrpT* pNewCtrlWrp, ItemConnFlags nFlags ) :
     473             :     ItemConnectionBase( nFlags ),
     474             :     maItemWrp( nSlot ),
     475           0 :     mxCtrlWrp( pNewCtrlWrp )
     476             : {
     477           0 : }
     478             : 
     479             : template< typename ItemWrpT, typename ControlWrpT >
     480           0 : ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
     481             :         sal_uInt16 nSlot, ControlType& rControl, ItemConnFlags nFlags ) :
     482             :     ItemConnectionBase( nFlags ),
     483             :     maItemWrp( nSlot ),
     484           0 :     mxCtrlWrp( new ControlWrpT( rControl ) )
     485             : {
     486           0 : }
     487             : 
     488             : template< typename ItemWrpT, typename ControlWrpT >
     489           0 : ItemControlConnection< ItemWrpT, ControlWrpT >::~ItemControlConnection()
     490             : {
     491           0 : }
     492             : 
     493             : template< typename ItemWrpT, typename ControlWrpT >
     494           0 : void ItemControlConnection< ItemWrpT, ControlWrpT >::ApplyFlags( const SfxItemSet& rItemSet )
     495             : {
     496           0 :     bool bKnown = ItemWrapperHelper::IsKnownItem( rItemSet, maItemWrp.GetSlotId() );
     497           0 :     mxCtrlWrp->ModifyControl( GetEnableState( bKnown ), GetShowState( bKnown ) );
     498           0 : }
     499             : 
     500             : template< typename ItemWrpT, typename ControlWrpT >
     501           0 : void ItemControlConnection< ItemWrpT, ControlWrpT >::Reset( const SfxItemSet& rItemSet )
     502             : {
     503           0 :     const ItemType* pItem = maItemWrp.GetUniqueItem( rItemSet );
     504           0 :     mxCtrlWrp->SetControlDontKnow( pItem == 0 );
     505           0 :     if( pItem )
     506           0 :         mxCtrlWrp->SetControlValue( maItemWrp.GetItemValue( *pItem ) );
     507           0 : }
     508             : 
     509             : template< typename ItemWrpT, typename ControlWrpT >
     510           0 : bool ItemControlConnection< ItemWrpT, ControlWrpT >::FillItemSet(
     511             :         SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
     512             : {
     513           0 :     const ItemType* pOldItem = maItemWrp.GetUniqueItem( rOldSet );
     514           0 :     bool bChanged = false;
     515           0 :     if( !mxCtrlWrp->IsControlDontKnow() )
     516             :     {
     517             :         // first store the control value in a local variable
     518           0 :         ControlValueType aCtrlValue( mxCtrlWrp->GetControlValue() );
     519             :         // convert to item value type -> possible to convert i.e. from 'T' to 'const T&'
     520           0 :         ItemValueType aNewValue( aCtrlValue );
     521             :         // do not rely on existence of ItemValueType::operator!=
     522           0 :         if( !pOldItem || !(maItemWrp.GetItemValue( *pOldItem ) == aNewValue) )
     523             :         {
     524           0 :             sal_uInt16 nWhich = ItemWrapperHelper::GetWhichId( rDestSet, maItemWrp.GetSlotId() );
     525             :             boost::scoped_ptr< ItemType > xItem(
     526           0 :                 static_cast< ItemType* >( maItemWrp.GetDefaultItem( rDestSet ).Clone() ) );
     527           0 :             xItem->SetWhich( nWhich );
     528           0 :             maItemWrp.SetItemValue( *xItem, aNewValue );
     529           0 :             rDestSet.Put( *xItem );
     530           0 :             bChanged = true;
     531           0 :         }
     532             :     }
     533           0 :     if( !bChanged )
     534           0 :         ItemWrapperHelper::RemoveDefaultItem( rDestSet, rOldSet, maItemWrp.GetSlotId() );
     535           0 :     return bChanged;
     536             : }
     537             : 
     538             : 
     539             : // Standard connections
     540             : 
     541             : 
     542             : template< typename ItemWrpT >
     543             : NumericConnection< ItemWrpT >::NumericConnection(
     544             :         sal_uInt16 nSlot, NumericField& rField, ItemConnFlags nFlags ) :
     545             :     ItemControlConnectionType( nSlot, rField, nFlags )
     546             : {
     547             : }
     548             : 
     549             : 
     550             : 
     551             : template< typename ItemWrpT >
     552           0 : MetricConnection< ItemWrpT >::MetricConnection(
     553             :         sal_uInt16 nSlot, MetricField& rField, FieldUnit eItemUnit, ItemConnFlags nFlags ) :
     554           0 :     ItemControlConnectionType( nSlot, new MetricFieldWrapperType( rField, eItemUnit ), nFlags )
     555             : {
     556           0 : }
     557             : 
     558             : 
     559             : 
     560             : template< typename ItemWrpT >
     561           0 : ListBoxConnection< ItemWrpT >::ListBoxConnection(
     562             :         sal_uInt16 nSlot, ListBox& rListBox, const MapEntryType* pMap, ItemConnFlags nFlags ) :
     563           0 :     ItemControlConnectionType( nSlot, new ListBoxWrapperType( rListBox, pMap ), nFlags )
     564             : {
     565           0 : }
     566             : 
     567             : 
     568             : 
     569             : template< typename ItemWrpT >
     570           0 : ValueSetConnection< ItemWrpT >::ValueSetConnection(
     571             :         sal_uInt16 nSlot, ValueSet& rValueSet, const MapEntryType* pMap, ItemConnFlags nFlags ) :
     572           0 :     ItemControlConnectionType( nSlot, new ValueSetWrapperType( rValueSet, pMap ), nFlags )
     573             : {
     574           0 : }
     575             : 
     576             : 
     577             : 
     578             : } // namespace sfx
     579             : 
     580             : #endif
     581             : 
     582             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10