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