merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / borderconn.cxx
blob82f51bf2b866fdbe2ae802bd5739d934ed798321
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: borderconn.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 #include "borderconn.hxx"
39 #include <svx/frmsel.hxx>
40 #include "bolnitem.hxx"
41 #include <svx/boxitem.hxx>
42 #include <svx/algitem.hxx>
43 #include <svx/shaditem.hxx>
45 namespace svx {
47 /* ============================================================================
48 SvxLineItem connection
49 ----------------------
50 Connects an SvxLineItem (that contains the style of one line of a cell border)
51 with one frame border from a svx::FrameSelector control. If this connection is
52 used, no additional code is needed in the Reset() and FillItemSet() functions
53 of the tab page.
54 ============================================================================ */
56 // 1st: item wrappers ---------------------------------------------------------
58 class LineItemWrapper : public sfx::SingleItemWrapper< SvxLineItem, const SvxBorderLine* >
60 public:
61 inline explicit LineItemWrapper( USHORT nSlot ) : SingleItemWrapperType( nSlot ) {}
63 virtual const SvxBorderLine* GetItemValue( const SvxLineItem& rItem ) const
64 { return rItem.GetLine(); }
65 virtual void SetItemValue( SvxLineItem& rItem, const SvxBorderLine* pLine ) const
66 { rItem.SetLine( pLine ); }
69 // 2nd: control wrappers ------------------------------------------------------
71 class FrameSelectorWrapper : public sfx::SingleControlWrapper< FrameSelector, const SvxBorderLine* >
73 public:
74 inline explicit FrameSelectorWrapper( FrameSelector& rFrameSel, FrameBorderType eBorder ) :
75 SingleControlWrapperType( rFrameSel ), meBorder( eBorder ) {}
77 virtual bool IsControlDontKnow() const;
78 virtual void SetControlDontKnow( bool bSet );
80 virtual const SvxBorderLine* GetControlValue() const;
81 virtual void SetControlValue( const SvxBorderLine* pLine );
83 private:
84 FrameBorderType meBorder; /// The line this wrapper works with.
87 bool FrameSelectorWrapper::IsControlDontKnow() const
89 return GetControl().GetFrameBorderState( meBorder ) == FRAMESTATE_DONTCARE;
92 void FrameSelectorWrapper::SetControlDontKnow( bool bSet )
94 if( bSet )
95 GetControl().SetBorderDontCare( meBorder );
98 const SvxBorderLine* FrameSelectorWrapper::GetControlValue() const
100 return GetControl().GetFrameBorderStyle( meBorder );
103 void FrameSelectorWrapper::SetControlValue( const SvxBorderLine* pLine )
105 GetControl().ShowBorder( meBorder, pLine );
108 // 3rd: connection ------------------------------------------------------------
110 typedef sfx::ItemControlConnection< LineItemWrapper, FrameSelectorWrapper > FrameLineConnection;
112 /* ============================================================================
113 SvxMarginItem connection
114 ------------------------
115 Connects an SvxMarginItem (that contains the inner margin of all cell borders)
116 with the numerical edit controls of the SvxBorderTabPage. If this connection is
117 used, no additional code is needed in the Reset() and FillItemSet() functions
118 of the tab page.
119 ============================================================================ */
121 // 1st: item wrappers ---------------------------------------------------------
123 typedef sfx::IdentItemWrapper< SvxMarginItem > MarginItemWrapper;
125 // 2nd: control wrappers ------------------------------------------------------
127 class MarginControlsWrapper : public sfx::MultiControlWrapper< SvxMarginItem >
129 public:
130 explicit MarginControlsWrapper(
131 MetricField& rMfLeft, MetricField& rMfRight,
132 MetricField& rMfTop, MetricField& rMfBottom );
134 virtual SvxMarginItem GetControlValue() const;
135 virtual void SetControlValue( SvxMarginItem aItem );
137 private:
138 sfx::Int16MetricFieldWrapper maLeftWrp;
139 sfx::Int16MetricFieldWrapper maRightWrp;
140 sfx::Int16MetricFieldWrapper maTopWrp;
141 sfx::Int16MetricFieldWrapper maBottomWrp;
144 MarginControlsWrapper::MarginControlsWrapper(
145 MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom ) :
146 maLeftWrp( rMfLeft, FUNIT_TWIP ),
147 maRightWrp( rMfRight, FUNIT_TWIP ),
148 maTopWrp( rMfTop, FUNIT_TWIP ),
149 maBottomWrp( rMfBottom, FUNIT_TWIP )
151 RegisterControlWrapper( maLeftWrp );
152 RegisterControlWrapper( maRightWrp );
153 RegisterControlWrapper( maTopWrp );
154 RegisterControlWrapper( maBottomWrp );
157 SvxMarginItem MarginControlsWrapper::GetControlValue() const
159 SvxMarginItem aItem( GetDefaultValue() );
160 if( !maLeftWrp.IsControlDontKnow() )
161 aItem.SetLeftMargin( maLeftWrp.GetControlValue() );
162 if( !maRightWrp.IsControlDontKnow() )
163 aItem.SetRightMargin( maRightWrp.GetControlValue() );
164 if( !maTopWrp.IsControlDontKnow() )
165 aItem.SetTopMargin( maTopWrp.GetControlValue() );
166 if( !maBottomWrp.IsControlDontKnow() )
167 aItem.SetBottomMargin( maBottomWrp.GetControlValue() );
168 return aItem;
171 void MarginControlsWrapper::SetControlValue( SvxMarginItem aItem )
173 maLeftWrp.SetControlValue( aItem.GetLeftMargin() );
174 maRightWrp.SetControlValue( aItem.GetRightMargin() );
175 maTopWrp.SetControlValue( aItem.GetTopMargin() );
176 maBottomWrp.SetControlValue( aItem.GetBottomMargin() );
179 // 3rd: connection ------------------------------------------------------------
181 class MarginConnection : public sfx::ItemControlConnection< MarginItemWrapper, MarginControlsWrapper >
183 public:
184 explicit MarginConnection( const SfxItemSet& rItemSet,
185 MetricField& rMfLeft, MetricField& rMfRight,
186 MetricField& rMfTop, MetricField& rMfBottom,
187 sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
190 MarginConnection::MarginConnection( const SfxItemSet& rItemSet,
191 MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom,
192 sfx::ItemConnFlags nFlags ) :
193 ItemControlConnectionType( SID_ATTR_ALIGN_MARGIN, new MarginControlsWrapper( rMfLeft, rMfRight, rMfTop, rMfBottom ), nFlags )
195 mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
198 /* ============================================================================
199 SvxShadowItem connection
200 ------------------------
201 Connects an SvxShadowItem (that contains shadow position, size, and color) with
202 the controls of the SvxBorderTabPage. If this connection is used, no additional
203 code is needed in the Reset() and FillItemSet() functions of the tab page.
204 ============================================================================ */
206 // 1st: item wrappers ---------------------------------------------------------
208 typedef sfx::IdentItemWrapper< SvxShadowItem > ShadowItemWrapper;
210 // 2nd: control wrappers ------------------------------------------------------
212 typedef sfx::ValueSetWrapper< SvxShadowLocation > ShadowPosWrapper;
213 static const ShadowPosWrapper::MapEntryType s_pShadowPosMap[] =
215 { 1, SVX_SHADOW_NONE },
216 { 2, SVX_SHADOW_BOTTOMRIGHT },
217 { 3, SVX_SHADOW_TOPRIGHT },
218 { 4, SVX_SHADOW_BOTTOMLEFT },
219 { 5, SVX_SHADOW_TOPLEFT },
220 { VALUESET_ITEM_NOTFOUND, SVX_SHADOW_NONE }
223 class ShadowControlsWrapper : public sfx::MultiControlWrapper< SvxShadowItem >
225 public:
226 explicit ShadowControlsWrapper( ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor );
228 virtual SvxShadowItem GetControlValue() const;
229 virtual void SetControlValue( SvxShadowItem aItem );
231 private:
232 ShadowPosWrapper maPosWrp;
233 sfx::UShortMetricFieldWrapper maSizeWrp;
234 sfx::ColorListBoxWrapper maColorWrp;
237 ShadowControlsWrapper::ShadowControlsWrapper(
238 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor ) :
239 maPosWrp( rVsPos, s_pShadowPosMap ),
240 maSizeWrp( rMfSize, FUNIT_TWIP ),
241 maColorWrp( rLbColor )
243 RegisterControlWrapper( maPosWrp );
244 RegisterControlWrapper( maSizeWrp );
245 RegisterControlWrapper( maColorWrp );
248 SvxShadowItem ShadowControlsWrapper::GetControlValue() const
250 SvxShadowItem aItem( GetDefaultValue() );
251 if( !maPosWrp.IsControlDontKnow() )
252 aItem.SetLocation( maPosWrp.GetControlValue() );
253 if( !maSizeWrp.IsControlDontKnow() )
254 aItem.SetWidth( maSizeWrp.GetControlValue() );
255 if( !maColorWrp.IsControlDontKnow() )
256 aItem.SetColor( maColorWrp.GetControlValue() );
257 return aItem;
260 void ShadowControlsWrapper::SetControlValue( SvxShadowItem aItem )
262 maPosWrp.SetControlValue( aItem.GetLocation() );
263 maSizeWrp.SetControlValue( aItem.GetWidth() );
264 maColorWrp.SetControlValue( aItem.GetColor() );
267 // 3rd: connection ------------------------------------------------------------
269 class ShadowConnection : public sfx::ItemControlConnection< ShadowItemWrapper, ShadowControlsWrapper >
271 public:
272 explicit ShadowConnection( const SfxItemSet& rItemSet,
273 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
274 sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
277 ShadowConnection::ShadowConnection( const SfxItemSet& rItemSet,
278 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor, sfx::ItemConnFlags nFlags ) :
279 ItemControlConnectionType( SID_ATTR_BORDER_SHADOW, new ShadowControlsWrapper( rVsPos, rMfSize, rLbColor ), nFlags )
281 mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
284 // ============================================================================
285 // ============================================================================
287 sfx::ItemConnectionBase* CreateFrameLineConnection( USHORT nSlot,
288 FrameSelector& rFrameSel, FrameBorderType eBorder, sfx::ItemConnFlags nFlags )
290 return new FrameLineConnection( nSlot, new FrameSelectorWrapper( rFrameSel, eBorder ), nFlags );
293 sfx::ItemConnectionBase* CreateFrameBoxConnection( USHORT /*nBoxSlot*/, USHORT /*nBoxInfoSlot*/,
294 FrameSelector& /*rFrameSel*/, FrameBorderType /*eBorder*/, sfx::ItemConnFlags /*nFlags*/ )
296 DBG_ERRORFILE( "svx::CreateFrameBoxConnection - not implemented" );
297 return 0;
300 sfx::ItemConnectionBase* CreateMarginConnection( const SfxItemSet& rItemSet,
301 MetricField& rMfLeft, MetricField& rMfRight,
302 MetricField& rMfTop, MetricField& rMfBottom,
303 sfx::ItemConnFlags nFlags )
305 return new MarginConnection( rItemSet, rMfLeft, rMfRight, rMfTop, rMfBottom, nFlags );
308 sfx::ItemConnectionBase* CreateShadowConnection( const SfxItemSet& rItemSet,
309 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
310 sfx::ItemConnFlags nFlags )
312 return new ShadowConnection( rItemSet, rVsPos, rMfSize, rLbColor, nFlags );
315 // ============================================================================
317 } // namespace svx