bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / borderconn.cxx
blob6dc3b8e7ffeedb28c1a0c54f4d064c7e46a95f5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "borderconn.hxx"
21 #include <svx/frmsel.hxx>
22 #include "editeng/lineitem.hxx"
23 #include <editeng/boxitem.hxx>
24 #include <svx/algitem.hxx>
25 #include <editeng/shaditem.hxx>
27 namespace svx {
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 ============================================================================ */
38 // 1st: item wrappers ---------------------------------------------------------
40 class LineItemWrapper : public sfx::SingleItemWrapper< SvxLineItem, const editeng::SvxBorderLine* >
42 public:
43 inline explicit LineItemWrapper( sal_uInt16 nSlot ) : SingleItemWrapperType( nSlot ) {}
45 virtual ~LineItemWrapper() {}
47 virtual const editeng::SvxBorderLine* GetItemValue( const SvxLineItem& rItem ) const SAL_OVERRIDE
48 { return rItem.GetLine(); }
49 virtual void SetItemValue( SvxLineItem& rItem, const editeng::SvxBorderLine* pLine ) const SAL_OVERRIDE
50 { rItem.SetLine( pLine ); }
53 // 2nd: control wrappers ------------------------------------------------------
55 class FrameSelectorWrapper : public sfx::SingleControlWrapper< FrameSelector, const editeng::SvxBorderLine* >
57 public:
58 inline explicit FrameSelectorWrapper( FrameSelector& rFrameSel, FrameBorderType eBorder ) :
59 SingleControlWrapperType( rFrameSel ), meBorder( eBorder ) {}
61 virtual bool IsControlDontKnow() const SAL_OVERRIDE;
62 virtual void SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
64 virtual const editeng::SvxBorderLine* GetControlValue() const SAL_OVERRIDE;
65 virtual void SetControlValue( const editeng::SvxBorderLine* pLine ) SAL_OVERRIDE;
67 private:
68 FrameBorderType meBorder; /// The line this wrapper works with.
71 bool FrameSelectorWrapper::IsControlDontKnow() const
73 return GetControl().GetFrameBorderState( meBorder ) == FRAMESTATE_DONTCARE;
76 void FrameSelectorWrapper::SetControlDontKnow( bool bSet )
78 if( bSet )
79 GetControl().SetBorderDontCare( meBorder );
82 const editeng::SvxBorderLine* FrameSelectorWrapper::GetControlValue() const
84 return GetControl().GetFrameBorderStyle( meBorder );
87 void FrameSelectorWrapper::SetControlValue( const editeng::SvxBorderLine* pLine )
89 GetControl().ShowBorder( meBorder, pLine );
92 // 3rd: connection ------------------------------------------------------------
94 typedef sfx::ItemControlConnection< LineItemWrapper, FrameSelectorWrapper > FrameLineConnection;
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 ============================================================================ */
105 // 1st: item wrappers ---------------------------------------------------------
107 typedef sfx::IdentItemWrapper< SvxMarginItem > MarginItemWrapper;
109 // 2nd: control wrappers ------------------------------------------------------
111 class MarginControlsWrapper : public sfx::MultiControlWrapper< SvxMarginItem >
113 public:
114 explicit MarginControlsWrapper(
115 MetricField& rMfLeft, MetricField& rMfRight,
116 MetricField& rMfTop, MetricField& rMfBottom );
118 virtual SvxMarginItem GetControlValue() const SAL_OVERRIDE;
119 virtual void SetControlValue( SvxMarginItem aItem ) SAL_OVERRIDE;
121 private:
122 sfx::Int16MetricFieldWrapper maLeftWrp;
123 sfx::Int16MetricFieldWrapper maRightWrp;
124 sfx::Int16MetricFieldWrapper maTopWrp;
125 sfx::Int16MetricFieldWrapper maBottomWrp;
128 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 maBottomWrp( rMfBottom, FUNIT_TWIP )
135 RegisterControlWrapper( maLeftWrp );
136 RegisterControlWrapper( maRightWrp );
137 RegisterControlWrapper( maTopWrp );
138 RegisterControlWrapper( maBottomWrp );
141 SvxMarginItem MarginControlsWrapper::GetControlValue() const
143 SvxMarginItem aItem( GetDefaultValue() );
144 if( !maLeftWrp.IsControlDontKnow() )
145 aItem.SetLeftMargin( maLeftWrp.GetControlValue() );
146 if( !maRightWrp.IsControlDontKnow() )
147 aItem.SetRightMargin( maRightWrp.GetControlValue() );
148 if( !maTopWrp.IsControlDontKnow() )
149 aItem.SetTopMargin( maTopWrp.GetControlValue() );
150 if( !maBottomWrp.IsControlDontKnow() )
151 aItem.SetBottomMargin( maBottomWrp.GetControlValue() );
152 return aItem;
155 void MarginControlsWrapper::SetControlValue( SvxMarginItem aItem )
157 maLeftWrp.SetControlValue( aItem.GetLeftMargin() );
158 maRightWrp.SetControlValue( aItem.GetRightMargin() );
159 maTopWrp.SetControlValue( aItem.GetTopMargin() );
160 maBottomWrp.SetControlValue( aItem.GetBottomMargin() );
163 // 3rd: connection ------------------------------------------------------------
165 class MarginConnection : public sfx::ItemControlConnection< MarginItemWrapper, MarginControlsWrapper >
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 );
174 MarginConnection::MarginConnection( const SfxItemSet& rItemSet,
175 MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom,
176 sfx::ItemConnFlags nFlags ) :
177 ItemControlConnectionType( SID_ATTR_ALIGN_MARGIN, new MarginControlsWrapper( rMfLeft, rMfRight, rMfTop, rMfBottom ), nFlags )
179 mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
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 ============================================================================ */
190 // 1st: item wrappers ---------------------------------------------------------
192 typedef sfx::IdentItemWrapper< SvxShadowItem > ShadowItemWrapper;
194 // 2nd: control wrappers ------------------------------------------------------
196 typedef sfx::ValueSetWrapper< SvxShadowLocation > ShadowPosWrapper;
197 static const ShadowPosWrapper::MapEntryType s_pShadowPosMap[] =
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 { WRAPPER_VALUESET_ITEM_NOTFOUND, SVX_SHADOW_NONE }
207 class ShadowControlsWrapper : public sfx::MultiControlWrapper< SvxShadowItem >
209 public:
210 explicit ShadowControlsWrapper( ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor );
212 virtual SvxShadowItem GetControlValue() const SAL_OVERRIDE;
213 virtual void SetControlValue( SvxShadowItem aItem ) SAL_OVERRIDE;
215 private:
216 ShadowPosWrapper maPosWrp;
217 sfx::UShortMetricFieldWrapper maSizeWrp;
218 sfx::ColorListBoxWrapper maColorWrp;
221 ShadowControlsWrapper::ShadowControlsWrapper(
222 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor ) :
223 maPosWrp( rVsPos, s_pShadowPosMap ),
224 maSizeWrp( rMfSize, FUNIT_TWIP ),
225 maColorWrp( rLbColor )
227 RegisterControlWrapper( maPosWrp );
228 RegisterControlWrapper( maSizeWrp );
229 RegisterControlWrapper( maColorWrp );
232 SvxShadowItem ShadowControlsWrapper::GetControlValue() const
234 SvxShadowItem aItem( GetDefaultValue() );
235 if( !maPosWrp.IsControlDontKnow() )
236 aItem.SetLocation( maPosWrp.GetControlValue() );
237 if( !maSizeWrp.IsControlDontKnow() )
238 aItem.SetWidth( maSizeWrp.GetControlValue() );
239 if( !maColorWrp.IsControlDontKnow() )
240 aItem.SetColor( maColorWrp.GetControlValue() );
241 return aItem;
244 void ShadowControlsWrapper::SetControlValue( SvxShadowItem aItem )
246 maPosWrp.SetControlValue( aItem.GetLocation() );
247 maSizeWrp.SetControlValue( aItem.GetWidth() );
248 maColorWrp.SetControlValue( aItem.GetColor() );
251 // 3rd: connection ------------------------------------------------------------
253 class ShadowConnection : public sfx::ItemControlConnection< ShadowItemWrapper, ShadowControlsWrapper >
255 public:
256 explicit ShadowConnection( const SfxItemSet& rItemSet,
257 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
258 sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
261 ShadowConnection::ShadowConnection( const SfxItemSet& rItemSet,
262 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor, sfx::ItemConnFlags nFlags ) :
263 ItemControlConnectionType( SID_ATTR_BORDER_SHADOW, new ShadowControlsWrapper( rVsPos, rMfSize, rLbColor ), nFlags )
265 mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
271 sfx::ItemConnectionBase* CreateFrameLineConnection( sal_uInt16 nSlot,
272 FrameSelector& rFrameSel, FrameBorderType eBorder, sfx::ItemConnFlags nFlags )
274 return new FrameLineConnection( nSlot, new FrameSelectorWrapper( rFrameSel, eBorder ), nFlags );
277 sfx::ItemConnectionBase* CreateMarginConnection( const SfxItemSet& rItemSet,
278 MetricField& rMfLeft, MetricField& rMfRight,
279 MetricField& rMfTop, MetricField& rMfBottom,
280 sfx::ItemConnFlags nFlags )
282 return new MarginConnection( rItemSet, rMfLeft, rMfRight, rMfTop, rMfBottom, nFlags );
285 sfx::ItemConnectionBase* CreateShadowConnection( const SfxItemSet& rItemSet,
286 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
287 sfx::ItemConnFlags nFlags )
289 return new ShadowConnection( rItemSet, rVsPos, rMfSize, rLbColor, nFlags );
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */