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