LCOV - code coverage report
Current view: top level - libreoffice/cui/source/tabpages - borderconn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 82 0.0 %
Date: 2012-12-27 Functions: 0 31 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             : #include "borderconn.hxx"
      21             : #include <svx/frmsel.hxx>
      22             : #include "editeng/bolnitem.hxx"
      23             : #include <editeng/boxitem.hxx>
      24             : #include <svx/algitem.hxx>
      25             : #include <editeng/shaditem.hxx>
      26             : 
      27             : namespace svx {
      28             : 
      29             : /* ============================================================================
      30             : SvxLineItem connection
      31             : ----------------------
      32             : Connects an SvxLineItem (that contains the style of one line of a cell border)
      33             : with one frame border from a svx::FrameSelector control. If this connection is
      34             : used, no additional code is needed in the Reset() and FillItemSet() functions
      35             : of the tab page.
      36             : ============================================================================ */
      37             : 
      38             : // 1st: item wrappers ---------------------------------------------------------
      39             : 
      40             : class LineItemWrapper : public sfx::SingleItemWrapper< SvxLineItem, const editeng::SvxBorderLine* >
      41             : {
      42             : public:
      43           0 :     inline explicit     LineItemWrapper( sal_uInt16 nSlot ) : SingleItemWrapperType( nSlot ) {}
      44             : 
      45           0 :     virtual ~LineItemWrapper() {}
      46             : 
      47           0 :     virtual const editeng::SvxBorderLine* GetItemValue( const SvxLineItem& rItem ) const
      48           0 :                             { return rItem.GetLine(); }
      49           0 :     virtual void        SetItemValue( SvxLineItem& rItem, const editeng::SvxBorderLine* pLine ) const
      50           0 :                             { rItem.SetLine( pLine ); }
      51             : };
      52             : 
      53             : // 2nd: control wrappers ------------------------------------------------------
      54             : 
      55           0 : class FrameSelectorWrapper : public sfx::SingleControlWrapper< FrameSelector, const editeng::SvxBorderLine* >
      56             : {
      57             : public:
      58           0 :     inline explicit     FrameSelectorWrapper( FrameSelector& rFrameSel, FrameBorderType eBorder ) :
      59           0 :                             SingleControlWrapperType( rFrameSel ), meBorder( eBorder ) {}
      60             : 
      61             :     virtual bool        IsControlDontKnow() const;
      62             :     virtual void        SetControlDontKnow( bool bSet );
      63             : 
      64             :     virtual const editeng::SvxBorderLine* GetControlValue() const;
      65             :     virtual void        SetControlValue( const editeng::SvxBorderLine* pLine );
      66             : 
      67             : private:
      68             :     FrameBorderType       meBorder;         /// The line this wrapper works with.
      69             : };
      70             : 
      71           0 : bool FrameSelectorWrapper::IsControlDontKnow() const
      72             : {
      73           0 :     return GetControl().GetFrameBorderState( meBorder ) == FRAMESTATE_DONTCARE;
      74             : }
      75             : 
      76           0 : void FrameSelectorWrapper::SetControlDontKnow( bool bSet )
      77             : {
      78           0 :     if( bSet )
      79           0 :         GetControl().SetBorderDontCare( meBorder );
      80           0 : }
      81             : 
      82           0 : const editeng::SvxBorderLine* FrameSelectorWrapper::GetControlValue() const
      83             : {
      84           0 :     return GetControl().GetFrameBorderStyle( meBorder );
      85             : }
      86             : 
      87           0 : void FrameSelectorWrapper::SetControlValue( const editeng::SvxBorderLine* pLine )
      88             : {
      89           0 :     GetControl().ShowBorder( meBorder, pLine );
      90           0 : }
      91             : 
      92             : // 3rd: connection ------------------------------------------------------------
      93             : 
      94             : typedef sfx::ItemControlConnection< LineItemWrapper, FrameSelectorWrapper > FrameLineConnection;
      95             : 
      96             : /* ============================================================================
      97             : SvxMarginItem connection
      98             : ------------------------
      99             : Connects an SvxMarginItem (that contains the inner margin of all cell borders)
     100             : with the numerical edit controls of the SvxBorderTabPage. If this connection is
     101             : used, no additional code is needed in the Reset() and FillItemSet() functions
     102             : of the tab page.
     103             : ============================================================================ */
     104             : 
     105             : // 1st: item wrappers ---------------------------------------------------------
     106             : 
     107             : typedef sfx::IdentItemWrapper< SvxMarginItem > MarginItemWrapper;
     108             : 
     109             : // 2nd: control wrappers ------------------------------------------------------
     110             : 
     111           0 : class MarginControlsWrapper : public sfx::MultiControlWrapper< SvxMarginItem >
     112             : {
     113             : public:
     114             :     explicit            MarginControlsWrapper(
     115             :                             MetricField& rMfLeft, MetricField& rMfRight,
     116             :                             MetricField& rMfTop, MetricField& rMfBottom );
     117             : 
     118             :     virtual SvxMarginItem GetControlValue() const;
     119             :     virtual void        SetControlValue( SvxMarginItem aItem );
     120             : 
     121             : private:
     122             :     sfx::Int16MetricFieldWrapper maLeftWrp;
     123             :     sfx::Int16MetricFieldWrapper maRightWrp;
     124             :     sfx::Int16MetricFieldWrapper maTopWrp;
     125             :     sfx::Int16MetricFieldWrapper maBottomWrp;
     126             : };
     127             : 
     128           0 : MarginControlsWrapper::MarginControlsWrapper(
     129             :         MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom ) :
     130             :     maLeftWrp( rMfLeft, FUNIT_TWIP ),
     131             :     maRightWrp( rMfRight, FUNIT_TWIP ),
     132             :     maTopWrp( rMfTop, FUNIT_TWIP ),
     133           0 :     maBottomWrp( rMfBottom, FUNIT_TWIP )
     134             : {
     135           0 :     RegisterControlWrapper( maLeftWrp );
     136           0 :     RegisterControlWrapper( maRightWrp );
     137           0 :     RegisterControlWrapper( maTopWrp );
     138           0 :     RegisterControlWrapper( maBottomWrp );
     139           0 : }
     140             : 
     141           0 : SvxMarginItem MarginControlsWrapper::GetControlValue() const
     142             : {
     143           0 :     SvxMarginItem aItem( GetDefaultValue() );
     144           0 :     if( !maLeftWrp.IsControlDontKnow() )
     145           0 :         aItem.SetLeftMargin( maLeftWrp.GetControlValue() );
     146           0 :     if( !maRightWrp.IsControlDontKnow() )
     147           0 :         aItem.SetRightMargin( maRightWrp.GetControlValue() );
     148           0 :     if( !maTopWrp.IsControlDontKnow() )
     149           0 :         aItem.SetTopMargin( maTopWrp.GetControlValue() );
     150           0 :     if( !maBottomWrp.IsControlDontKnow() )
     151           0 :         aItem.SetBottomMargin( maBottomWrp.GetControlValue() );
     152           0 :     return aItem;
     153             : }
     154             : 
     155           0 : void MarginControlsWrapper::SetControlValue( SvxMarginItem aItem )
     156             : {
     157           0 :     maLeftWrp.SetControlValue( aItem.GetLeftMargin() );
     158           0 :     maRightWrp.SetControlValue( aItem.GetRightMargin() );
     159           0 :     maTopWrp.SetControlValue( aItem.GetTopMargin() );
     160           0 :     maBottomWrp.SetControlValue( aItem.GetBottomMargin() );
     161           0 : }
     162             : 
     163             : // 3rd: connection ------------------------------------------------------------
     164             : 
     165           0 : class MarginConnection : public sfx::ItemControlConnection< MarginItemWrapper, MarginControlsWrapper >
     166             : {
     167             : public:
     168             :     explicit            MarginConnection( const SfxItemSet& rItemSet,
     169             :                             MetricField& rMfLeft, MetricField& rMfRight,
     170             :                             MetricField& rMfTop, MetricField& rMfBottom,
     171             :                             sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
     172             : };
     173             : 
     174           0 : MarginConnection::MarginConnection( const SfxItemSet& rItemSet,
     175             :         MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom,
     176             :         sfx::ItemConnFlags nFlags ) :
     177           0 :     ItemControlConnectionType( SID_ATTR_ALIGN_MARGIN, new MarginControlsWrapper( rMfLeft, rMfRight, rMfTop, rMfBottom ), nFlags )
     178             : {
     179           0 :     mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
     180           0 : }
     181             : 
     182             : /* ============================================================================
     183             : SvxShadowItem connection
     184             : ------------------------
     185             : Connects an SvxShadowItem (that contains shadow position, size, and color) with
     186             : the controls of the SvxBorderTabPage. If this connection is used, no additional
     187             : code is needed in the Reset() and FillItemSet() functions of the tab page.
     188             : ============================================================================ */
     189             : 
     190             : // 1st: item wrappers ---------------------------------------------------------
     191             : 
     192             : typedef sfx::IdentItemWrapper< SvxShadowItem > ShadowItemWrapper;
     193             : 
     194             : // 2nd: control wrappers ------------------------------------------------------
     195             : 
     196             : typedef sfx::ValueSetWrapper< SvxShadowLocation > ShadowPosWrapper;
     197             : static const ShadowPosWrapper::MapEntryType s_pShadowPosMap[] =
     198             : {
     199             :     { 1,                        SVX_SHADOW_NONE         },
     200             :     { 2,                        SVX_SHADOW_BOTTOMRIGHT  },
     201             :     { 3,                        SVX_SHADOW_TOPRIGHT     },
     202             :     { 4,                        SVX_SHADOW_BOTTOMLEFT   },
     203             :     { 5,                        SVX_SHADOW_TOPLEFT      },
     204             :     { VALUESET_ITEM_NOTFOUND,   SVX_SHADOW_NONE         }
     205             : };
     206             : 
     207           0 : class ShadowControlsWrapper : public sfx::MultiControlWrapper< SvxShadowItem >
     208             : {
     209             : public:
     210             :     explicit            ShadowControlsWrapper( ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor );
     211             : 
     212             :     virtual SvxShadowItem GetControlValue() const;
     213             :     virtual void        SetControlValue( SvxShadowItem aItem );
     214             : 
     215             : private:
     216             :     ShadowPosWrapper                maPosWrp;
     217             :     sfx::UShortMetricFieldWrapper   maSizeWrp;
     218             :     sfx::ColorListBoxWrapper        maColorWrp;
     219             : };
     220             : 
     221           0 : ShadowControlsWrapper::ShadowControlsWrapper(
     222             :         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor ) :
     223             :     maPosWrp( rVsPos, s_pShadowPosMap ),
     224             :     maSizeWrp( rMfSize, FUNIT_TWIP ),
     225           0 :     maColorWrp( rLbColor )
     226             : {
     227           0 :     RegisterControlWrapper( maPosWrp );
     228           0 :     RegisterControlWrapper( maSizeWrp );
     229           0 :     RegisterControlWrapper( maColorWrp );
     230           0 : }
     231             : 
     232           0 : SvxShadowItem ShadowControlsWrapper::GetControlValue() const
     233             : {
     234           0 :     SvxShadowItem aItem( GetDefaultValue() );
     235           0 :     if( !maPosWrp.IsControlDontKnow() )
     236           0 :         aItem.SetLocation( maPosWrp.GetControlValue() );
     237           0 :     if( !maSizeWrp.IsControlDontKnow() )
     238           0 :         aItem.SetWidth( maSizeWrp.GetControlValue() );
     239           0 :     if( !maColorWrp.IsControlDontKnow() )
     240           0 :         aItem.SetColor( maColorWrp.GetControlValue() );
     241           0 :     return aItem;
     242             : }
     243             : 
     244           0 : void ShadowControlsWrapper::SetControlValue( SvxShadowItem aItem )
     245             : {
     246           0 :     maPosWrp.SetControlValue( aItem.GetLocation() );
     247           0 :     maSizeWrp.SetControlValue( aItem.GetWidth() );
     248           0 :     maColorWrp.SetControlValue( aItem.GetColor() );
     249           0 : }
     250             : 
     251             : // 3rd: connection ------------------------------------------------------------
     252             : 
     253           0 : class ShadowConnection : public sfx::ItemControlConnection< ShadowItemWrapper, ShadowControlsWrapper >
     254             : {
     255             : public:
     256             :     explicit            ShadowConnection( const SfxItemSet& rItemSet,
     257             :                                 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
     258             :                                 sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
     259             : };
     260             : 
     261           0 : ShadowConnection::ShadowConnection( const SfxItemSet& rItemSet,
     262             :         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor, sfx::ItemConnFlags nFlags ) :
     263           0 :     ItemControlConnectionType( SID_ATTR_BORDER_SHADOW, new ShadowControlsWrapper( rVsPos, rMfSize, rLbColor ), nFlags )
     264             : {
     265           0 :     mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
     266           0 : }
     267             : 
     268             : // ============================================================================
     269             : // ============================================================================
     270             : 
     271           0 : sfx::ItemConnectionBase* CreateFrameLineConnection( sal_uInt16 nSlot,
     272             :         FrameSelector& rFrameSel, FrameBorderType eBorder, sfx::ItemConnFlags nFlags )
     273             : {
     274           0 :     return new FrameLineConnection( nSlot, new FrameSelectorWrapper( rFrameSel, eBorder ), nFlags );
     275             : }
     276             : 
     277           0 : sfx::ItemConnectionBase* CreateMarginConnection( const SfxItemSet& rItemSet,
     278             :         MetricField& rMfLeft, MetricField& rMfRight,
     279             :         MetricField& rMfTop, MetricField& rMfBottom,
     280             :         sfx::ItemConnFlags nFlags )
     281             : {
     282           0 :     return new MarginConnection( rItemSet, rMfLeft, rMfRight, rMfTop, rMfBottom, nFlags );
     283             : }
     284             : 
     285           0 : sfx::ItemConnectionBase* CreateShadowConnection( const SfxItemSet& rItemSet,
     286             :         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
     287             :         sfx::ItemConnFlags nFlags )
     288             : {
     289           0 :     return new ShadowConnection( rItemSet, rVsPos, rMfSize, rLbColor, nFlags );
     290             : }
     291             : 
     292             : // ============================================================================
     293             : 
     294             : } // namespace svx
     295             : 
     296             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10