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