xref: /AOO41X/main/cui/source/tabpages/borderconn.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "borderconn.hxx"
32*cdf0e10cSrcweir #include <svx/frmsel.hxx>
33*cdf0e10cSrcweir #include "editeng/bolnitem.hxx"
34*cdf0e10cSrcweir #include <editeng/boxitem.hxx>
35*cdf0e10cSrcweir #include <svx/algitem.hxx>
36*cdf0e10cSrcweir #include <editeng/shaditem.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace svx {
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /* ============================================================================
41*cdf0e10cSrcweir SvxLineItem connection
42*cdf0e10cSrcweir ----------------------
43*cdf0e10cSrcweir Connects an SvxLineItem (that contains the style of one line of a cell border)
44*cdf0e10cSrcweir with one frame border from a svx::FrameSelector control. If this connection is
45*cdf0e10cSrcweir used, no additional code is needed in the Reset() and FillItemSet() functions
46*cdf0e10cSrcweir of the tab page.
47*cdf0e10cSrcweir ============================================================================ */
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // 1st: item wrappers ---------------------------------------------------------
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir class LineItemWrapper : public sfx::SingleItemWrapper< SvxLineItem, const SvxBorderLine* >
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir public:
54*cdf0e10cSrcweir     inline explicit     LineItemWrapper( sal_uInt16 nSlot ) : SingleItemWrapperType( nSlot ) {}
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir     virtual const SvxBorderLine* GetItemValue( const SvxLineItem& rItem ) const
57*cdf0e10cSrcweir                             { return rItem.GetLine(); }
58*cdf0e10cSrcweir     virtual void        SetItemValue( SvxLineItem& rItem, const SvxBorderLine* pLine ) const
59*cdf0e10cSrcweir                             { rItem.SetLine( pLine ); }
60*cdf0e10cSrcweir };
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir // 2nd: control wrappers ------------------------------------------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir class FrameSelectorWrapper : public sfx::SingleControlWrapper< FrameSelector, const SvxBorderLine* >
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir public:
67*cdf0e10cSrcweir     inline explicit     FrameSelectorWrapper( FrameSelector& rFrameSel, FrameBorderType eBorder ) :
68*cdf0e10cSrcweir                             SingleControlWrapperType( rFrameSel ), meBorder( eBorder ) {}
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     virtual bool        IsControlDontKnow() const;
71*cdf0e10cSrcweir     virtual void        SetControlDontKnow( bool bSet );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     virtual const SvxBorderLine* GetControlValue() const;
74*cdf0e10cSrcweir     virtual void        SetControlValue( const SvxBorderLine* pLine );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir private:
77*cdf0e10cSrcweir     FrameBorderType       meBorder;         /// The line this wrapper works with.
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir bool FrameSelectorWrapper::IsControlDontKnow() const
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     return GetControl().GetFrameBorderState( meBorder ) == FRAMESTATE_DONTCARE;
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void FrameSelectorWrapper::SetControlDontKnow( bool bSet )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     if( bSet )
88*cdf0e10cSrcweir         GetControl().SetBorderDontCare( meBorder );
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir const SvxBorderLine* FrameSelectorWrapper::GetControlValue() const
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     return GetControl().GetFrameBorderStyle( meBorder );
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir void FrameSelectorWrapper::SetControlValue( const SvxBorderLine* pLine )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     GetControl().ShowBorder( meBorder, pLine );
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // 3rd: connection ------------------------------------------------------------
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir typedef sfx::ItemControlConnection< LineItemWrapper, FrameSelectorWrapper > FrameLineConnection;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir /* ============================================================================
106*cdf0e10cSrcweir SvxMarginItem connection
107*cdf0e10cSrcweir ------------------------
108*cdf0e10cSrcweir Connects an SvxMarginItem (that contains the inner margin of all cell borders)
109*cdf0e10cSrcweir with the numerical edit controls of the SvxBorderTabPage. If this connection is
110*cdf0e10cSrcweir used, no additional code is needed in the Reset() and FillItemSet() functions
111*cdf0e10cSrcweir of the tab page.
112*cdf0e10cSrcweir ============================================================================ */
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir // 1st: item wrappers ---------------------------------------------------------
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir typedef sfx::IdentItemWrapper< SvxMarginItem > MarginItemWrapper;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // 2nd: control wrappers ------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir class MarginControlsWrapper : public sfx::MultiControlWrapper< SvxMarginItem >
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir public:
123*cdf0e10cSrcweir     explicit            MarginControlsWrapper(
124*cdf0e10cSrcweir                             MetricField& rMfLeft, MetricField& rMfRight,
125*cdf0e10cSrcweir                             MetricField& rMfTop, MetricField& rMfBottom );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     virtual SvxMarginItem GetControlValue() const;
128*cdf0e10cSrcweir     virtual void        SetControlValue( SvxMarginItem aItem );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir private:
131*cdf0e10cSrcweir     sfx::Int16MetricFieldWrapper maLeftWrp;
132*cdf0e10cSrcweir     sfx::Int16MetricFieldWrapper maRightWrp;
133*cdf0e10cSrcweir     sfx::Int16MetricFieldWrapper maTopWrp;
134*cdf0e10cSrcweir     sfx::Int16MetricFieldWrapper maBottomWrp;
135*cdf0e10cSrcweir };
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir MarginControlsWrapper::MarginControlsWrapper(
138*cdf0e10cSrcweir         MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom ) :
139*cdf0e10cSrcweir     maLeftWrp( rMfLeft, FUNIT_TWIP ),
140*cdf0e10cSrcweir     maRightWrp( rMfRight, FUNIT_TWIP ),
141*cdf0e10cSrcweir     maTopWrp( rMfTop, FUNIT_TWIP ),
142*cdf0e10cSrcweir     maBottomWrp( rMfBottom, FUNIT_TWIP )
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     RegisterControlWrapper( maLeftWrp );
145*cdf0e10cSrcweir     RegisterControlWrapper( maRightWrp );
146*cdf0e10cSrcweir     RegisterControlWrapper( maTopWrp );
147*cdf0e10cSrcweir     RegisterControlWrapper( maBottomWrp );
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir SvxMarginItem MarginControlsWrapper::GetControlValue() const
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     SvxMarginItem aItem( GetDefaultValue() );
153*cdf0e10cSrcweir     if( !maLeftWrp.IsControlDontKnow() )
154*cdf0e10cSrcweir         aItem.SetLeftMargin( maLeftWrp.GetControlValue() );
155*cdf0e10cSrcweir     if( !maRightWrp.IsControlDontKnow() )
156*cdf0e10cSrcweir         aItem.SetRightMargin( maRightWrp.GetControlValue() );
157*cdf0e10cSrcweir     if( !maTopWrp.IsControlDontKnow() )
158*cdf0e10cSrcweir         aItem.SetTopMargin( maTopWrp.GetControlValue() );
159*cdf0e10cSrcweir     if( !maBottomWrp.IsControlDontKnow() )
160*cdf0e10cSrcweir         aItem.SetBottomMargin( maBottomWrp.GetControlValue() );
161*cdf0e10cSrcweir     return aItem;
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir void MarginControlsWrapper::SetControlValue( SvxMarginItem aItem )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     maLeftWrp.SetControlValue( aItem.GetLeftMargin() );
167*cdf0e10cSrcweir     maRightWrp.SetControlValue( aItem.GetRightMargin() );
168*cdf0e10cSrcweir     maTopWrp.SetControlValue( aItem.GetTopMargin() );
169*cdf0e10cSrcweir     maBottomWrp.SetControlValue( aItem.GetBottomMargin() );
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir // 3rd: connection ------------------------------------------------------------
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir class MarginConnection : public sfx::ItemControlConnection< MarginItemWrapper, MarginControlsWrapper >
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir public:
177*cdf0e10cSrcweir     explicit            MarginConnection( const SfxItemSet& rItemSet,
178*cdf0e10cSrcweir                             MetricField& rMfLeft, MetricField& rMfRight,
179*cdf0e10cSrcweir                             MetricField& rMfTop, MetricField& rMfBottom,
180*cdf0e10cSrcweir                             sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
181*cdf0e10cSrcweir };
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir MarginConnection::MarginConnection( const SfxItemSet& rItemSet,
184*cdf0e10cSrcweir         MetricField& rMfLeft, MetricField& rMfRight, MetricField& rMfTop, MetricField& rMfBottom,
185*cdf0e10cSrcweir         sfx::ItemConnFlags nFlags ) :
186*cdf0e10cSrcweir     ItemControlConnectionType( SID_ATTR_ALIGN_MARGIN, new MarginControlsWrapper( rMfLeft, rMfRight, rMfTop, rMfBottom ), nFlags )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir /* ============================================================================
192*cdf0e10cSrcweir SvxShadowItem connection
193*cdf0e10cSrcweir ------------------------
194*cdf0e10cSrcweir Connects an SvxShadowItem (that contains shadow position, size, and color) with
195*cdf0e10cSrcweir the controls of the SvxBorderTabPage. If this connection is used, no additional
196*cdf0e10cSrcweir code is needed in the Reset() and FillItemSet() functions of the tab page.
197*cdf0e10cSrcweir ============================================================================ */
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // 1st: item wrappers ---------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir typedef sfx::IdentItemWrapper< SvxShadowItem > ShadowItemWrapper;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir // 2nd: control wrappers ------------------------------------------------------
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir typedef sfx::ValueSetWrapper< SvxShadowLocation > ShadowPosWrapper;
206*cdf0e10cSrcweir static const ShadowPosWrapper::MapEntryType s_pShadowPosMap[] =
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     { 1,                        SVX_SHADOW_NONE         },
209*cdf0e10cSrcweir     { 2,                        SVX_SHADOW_BOTTOMRIGHT  },
210*cdf0e10cSrcweir     { 3,                        SVX_SHADOW_TOPRIGHT     },
211*cdf0e10cSrcweir     { 4,                        SVX_SHADOW_BOTTOMLEFT   },
212*cdf0e10cSrcweir     { 5,                        SVX_SHADOW_TOPLEFT      },
213*cdf0e10cSrcweir     { VALUESET_ITEM_NOTFOUND,   SVX_SHADOW_NONE         }
214*cdf0e10cSrcweir };
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir class ShadowControlsWrapper : public sfx::MultiControlWrapper< SvxShadowItem >
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir public:
219*cdf0e10cSrcweir     explicit            ShadowControlsWrapper( ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     virtual SvxShadowItem GetControlValue() const;
222*cdf0e10cSrcweir     virtual void        SetControlValue( SvxShadowItem aItem );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir private:
225*cdf0e10cSrcweir     ShadowPosWrapper                maPosWrp;
226*cdf0e10cSrcweir     sfx::UShortMetricFieldWrapper   maSizeWrp;
227*cdf0e10cSrcweir     sfx::ColorListBoxWrapper        maColorWrp;
228*cdf0e10cSrcweir };
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir ShadowControlsWrapper::ShadowControlsWrapper(
231*cdf0e10cSrcweir         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor ) :
232*cdf0e10cSrcweir     maPosWrp( rVsPos, s_pShadowPosMap ),
233*cdf0e10cSrcweir     maSizeWrp( rMfSize, FUNIT_TWIP ),
234*cdf0e10cSrcweir     maColorWrp( rLbColor )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     RegisterControlWrapper( maPosWrp );
237*cdf0e10cSrcweir     RegisterControlWrapper( maSizeWrp );
238*cdf0e10cSrcweir     RegisterControlWrapper( maColorWrp );
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir SvxShadowItem ShadowControlsWrapper::GetControlValue() const
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     SvxShadowItem aItem( GetDefaultValue() );
244*cdf0e10cSrcweir     if( !maPosWrp.IsControlDontKnow() )
245*cdf0e10cSrcweir         aItem.SetLocation( maPosWrp.GetControlValue() );
246*cdf0e10cSrcweir     if( !maSizeWrp.IsControlDontKnow() )
247*cdf0e10cSrcweir         aItem.SetWidth( maSizeWrp.GetControlValue() );
248*cdf0e10cSrcweir     if( !maColorWrp.IsControlDontKnow() )
249*cdf0e10cSrcweir         aItem.SetColor( maColorWrp.GetControlValue() );
250*cdf0e10cSrcweir     return aItem;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void ShadowControlsWrapper::SetControlValue( SvxShadowItem aItem )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     maPosWrp.SetControlValue( aItem.GetLocation() );
256*cdf0e10cSrcweir     maSizeWrp.SetControlValue( aItem.GetWidth() );
257*cdf0e10cSrcweir     maColorWrp.SetControlValue( aItem.GetColor() );
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir // 3rd: connection ------------------------------------------------------------
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir class ShadowConnection : public sfx::ItemControlConnection< ShadowItemWrapper, ShadowControlsWrapper >
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir public:
265*cdf0e10cSrcweir     explicit            ShadowConnection( const SfxItemSet& rItemSet,
266*cdf0e10cSrcweir                                 ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
267*cdf0e10cSrcweir                                 sfx::ItemConnFlags nFlags = sfx::ITEMCONN_DEFAULT );
268*cdf0e10cSrcweir };
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir ShadowConnection::ShadowConnection( const SfxItemSet& rItemSet,
271*cdf0e10cSrcweir         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor, sfx::ItemConnFlags nFlags ) :
272*cdf0e10cSrcweir     ItemControlConnectionType( SID_ATTR_BORDER_SHADOW, new ShadowControlsWrapper( rVsPos, rMfSize, rLbColor ), nFlags )
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir     mxCtrlWrp->SetDefaultValue( maItemWrp.GetDefaultItem( rItemSet ) );
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // ============================================================================
278*cdf0e10cSrcweir // ============================================================================
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir sfx::ItemConnectionBase* CreateFrameLineConnection( sal_uInt16 nSlot,
281*cdf0e10cSrcweir         FrameSelector& rFrameSel, FrameBorderType eBorder, sfx::ItemConnFlags nFlags )
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir     return new FrameLineConnection( nSlot, new FrameSelectorWrapper( rFrameSel, eBorder ), nFlags );
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir sfx::ItemConnectionBase* CreateMarginConnection( const SfxItemSet& rItemSet,
287*cdf0e10cSrcweir         MetricField& rMfLeft, MetricField& rMfRight,
288*cdf0e10cSrcweir         MetricField& rMfTop, MetricField& rMfBottom,
289*cdf0e10cSrcweir         sfx::ItemConnFlags nFlags )
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     return new MarginConnection( rItemSet, rMfLeft, rMfRight, rMfTop, rMfBottom, nFlags );
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir sfx::ItemConnectionBase* CreateShadowConnection( const SfxItemSet& rItemSet,
295*cdf0e10cSrcweir         ValueSet& rVsPos, MetricField& rMfSize, ColorListBox& rLbColor,
296*cdf0e10cSrcweir         sfx::ItemConnFlags nFlags )
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir     return new ShadowConnection( rItemSet, rVsPos, rMfSize, rLbColor, nFlags );
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir // ============================================================================
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir } // namespace svx
304*cdf0e10cSrcweir 
305