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_sw.hxx" 26 27 28 #include <hintids.hxx> 29 #include <tools/poly.hxx> 30 #include <svl/stritem.hxx> 31 #include <svx/contdlg.hxx> 32 #include <vcl/svapp.hxx> 33 #include <docary.hxx> 34 #include <doc.hxx> 35 #include <fmtcol.hxx> 36 #include <ndnotxt.hxx> 37 #include <ndgrf.hxx> 38 #include <ndole.hxx> 39 #include <ndindex.hxx> 40 #include <hints.hxx> // fuer SwFmtChg 41 #include <istyleaccess.hxx> 42 #include <SwStyleNameMapper.hxx> 43 44 // --> OD 2009-07-13 #i73249# 45 #include <frmfmt.hxx> 46 // <-- 47 48 SwNoTxtNode::SwNoTxtNode( const SwNodeIndex & rWhere, 49 const sal_uInt8 nNdType, 50 SwGrfFmtColl *pGrfColl, 51 SwAttrSet* pAutoAttr ) : 52 SwCntntNode( rWhere, nNdType, pGrfColl ), 53 pContour( 0 ), 54 bAutomaticContour( sal_False ), 55 bContourMapModeValid( sal_True ), 56 bPixelContour( sal_False ) 57 { 58 // soll eine Harte-Attributierung gesetzt werden? 59 if( pAutoAttr ) 60 SetAttr( *pAutoAttr ); 61 } 62 63 64 SwNoTxtNode::~SwNoTxtNode() 65 { 66 delete pContour; 67 } 68 69 70 // erzeugt fuer alle Ableitungen einen AttrSet mit Bereichen 71 // fuer Frame- und Grafik-Attributen 72 void SwNoTxtNode::NewAttrSet( SwAttrPool& rPool ) 73 { 74 ASSERT( !mpAttrSet.get(), "AttrSet ist doch gesetzt" ); 75 SwAttrSet aNewAttrSet( rPool, aNoTxtNodeSetRange ); 76 77 // put names of parent style and conditional style: 78 const SwFmtColl* pFmtColl = GetFmtColl(); 79 String sVal; 80 SwStyleNameMapper::FillProgName( pFmtColl->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True ); 81 SfxStringItem aFmtColl( RES_FRMATR_STYLE_NAME, sVal ); 82 aNewAttrSet.Put( aFmtColl ); 83 84 aNewAttrSet.SetParent( &GetFmtColl()->GetAttrSet() ); 85 mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, IStyleAccess::AUTO_STYLE_NOTXT ); 86 } 87 88 // Dummies fuer das Laden/Speichern von persistenten Daten 89 // bei Grafiken und OLE-Objekten 90 91 92 sal_Bool SwNoTxtNode::RestorePersistentData() 93 { 94 return sal_True; 95 } 96 97 98 sal_Bool SwNoTxtNode::SavePersistentData() 99 { 100 return sal_True; 101 } 102 103 104 void SwNoTxtNode::SetContour( const PolyPolygon *pPoly, sal_Bool bAutomatic ) 105 { 106 delete pContour; 107 if ( pPoly ) 108 pContour = new PolyPolygon( *pPoly ); 109 else 110 pContour = 0; 111 bAutomaticContour = bAutomatic; 112 bContourMapModeValid = sal_True; 113 bPixelContour = sal_False; 114 } 115 116 117 void SwNoTxtNode::CreateContour() 118 { 119 ASSERT( !pContour, "Contour available." ); 120 pContour = new PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic())); 121 bAutomaticContour = sal_True; 122 bContourMapModeValid = sal_True; 123 bPixelContour = sal_False; 124 } 125 126 const PolyPolygon *SwNoTxtNode::HasContour() const 127 { 128 if( !bContourMapModeValid ) 129 { 130 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() ); 131 sal_Bool bPixelGrf = aGrfMap.GetMapUnit() == MAP_PIXEL; 132 const MapMode aContourMap( bPixelGrf ? MAP_PIXEL : MAP_100TH_MM ); 133 if( bPixelGrf ? !bPixelContour : aGrfMap != aContourMap ) 134 { 135 // --> OD #i102238# 136 double nGrfDPIx = 0.0; 137 double nGrfDPIy = 0.0; 138 { 139 if ( !bPixelGrf && bPixelContour ) 140 { 141 const Size aGrfPixelSize( GetGraphic().GetSizePixel() ); 142 const Size aGrfPrefMapModeSize( GetGraphic().GetPrefSize() ); 143 if ( aGrfMap.GetMapUnit() == MAP_INCH ) 144 { 145 nGrfDPIx = aGrfPixelSize.Width() / ( (double)aGrfMap.GetScaleX() * aGrfPrefMapModeSize.Width() ); 146 nGrfDPIy = aGrfPixelSize.Height() / ( (double)aGrfMap.GetScaleY() * aGrfPrefMapModeSize.Height() ); 147 } 148 else 149 { 150 const Size aGrf1000thInchSize = 151 OutputDevice::LogicToLogic( aGrfPrefMapModeSize, 152 aGrfMap, MAP_1000TH_INCH ); 153 nGrfDPIx = 1000.0 * aGrfPixelSize.Width() / aGrf1000thInchSize.Width(); 154 nGrfDPIy = 1000.0 * aGrfPixelSize.Height() / aGrf1000thInchSize.Height(); 155 } 156 } 157 } 158 // <-- 159 ASSERT( !bPixelGrf || aGrfMap == aContourMap, 160 "scale factor for pixel unsupported" ); 161 OutputDevice* pOutDev = 162 (bPixelGrf || bPixelContour) ? Application::GetDefaultDevice() 163 : 0; 164 sal_uInt16 nPolyCount = pContour->Count(); 165 for( sal_uInt16 j=0; j<nPolyCount; j++ ) 166 { 167 Polygon& rPoly = (*pContour)[j]; 168 169 sal_uInt16 nCount = rPoly.GetSize(); 170 for( sal_uInt16 i=0 ; i<nCount; i++ ) 171 { 172 if( bPixelGrf ) 173 rPoly[i] = pOutDev->LogicToPixel( rPoly[i], 174 aContourMap ); 175 else if( bPixelContour ) 176 { 177 rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap ); 178 // --> OD #i102238# 179 if ( nGrfDPIx != 0 && nGrfDPIy != 0 ) 180 { 181 rPoly[i] = Point( rPoly[i].X() * pOutDev->ImplGetDPIX() / nGrfDPIx, 182 rPoly[i].Y() * pOutDev->ImplGetDPIY() / nGrfDPIy ); 183 } 184 // <-- 185 } 186 else 187 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], 188 aContourMap, 189 aGrfMap ); 190 } 191 } 192 } 193 ((SwNoTxtNode *)this)->bContourMapModeValid = sal_True; 194 ((SwNoTxtNode *)this)->bPixelContour = sal_False; 195 } 196 197 return pContour; 198 } 199 200 void SwNoTxtNode::GetContour( PolyPolygon &rPoly ) const 201 { 202 ASSERT( pContour, "Contour not available." ); 203 rPoly = *HasContour(); 204 } 205 206 void SwNoTxtNode::SetContourAPI( const PolyPolygon *pPoly ) 207 { 208 delete pContour; 209 if ( pPoly ) 210 pContour = new PolyPolygon( *pPoly ); 211 else 212 pContour = 0; 213 bContourMapModeValid = sal_False; 214 } 215 216 sal_Bool SwNoTxtNode::GetContourAPI( PolyPolygon &rContour ) const 217 { 218 if( !pContour ) 219 return sal_False; 220 221 rContour = *pContour; 222 if( bContourMapModeValid ) 223 { 224 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() ); 225 const MapMode aContourMap( MAP_100TH_MM ); 226 ASSERT( aGrfMap.GetMapUnit() != MAP_PIXEL || 227 aGrfMap == MapMode( MAP_PIXEL ), 228 "scale factor for pixel unsupported" ); 229 if( aGrfMap.GetMapUnit() != MAP_PIXEL && 230 aGrfMap != aContourMap ) 231 { 232 sal_uInt16 nPolyCount = rContour.Count(); 233 for( sal_uInt16 j=0; j<nPolyCount; j++ ) 234 { 235 // --> OD #i102238# - use the right <PolyPolygon> instance 236 Polygon& rPoly = rContour[j]; 237 // <-- 238 239 sal_uInt16 nCount = rPoly.GetSize(); 240 for( sal_uInt16 i=0 ; i<nCount; i++ ) 241 { 242 rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap, 243 aContourMap ); 244 } 245 } 246 } 247 } 248 249 return sal_True; 250 } 251 252 sal_Bool SwNoTxtNode::IsPixelContour() const 253 { 254 sal_Bool bRet; 255 if( bContourMapModeValid ) 256 { 257 const MapMode aGrfMap( GetGraphic().GetPrefMapMode() ); 258 bRet = aGrfMap.GetMapUnit() == MAP_PIXEL; 259 } 260 else 261 { 262 bRet = bPixelContour; 263 } 264 265 return bRet; 266 } 267 268 269 Graphic SwNoTxtNode::GetGraphic() const 270 { 271 Graphic aRet; 272 if ( GetGrfNode() ) 273 { 274 ((SwGrfNode*)this)->SwapIn( sal_True ); 275 aRet = ((SwGrfNode*)this)->GetGrf(); 276 } 277 else 278 { 279 ASSERT( GetOLENode(), "new type of Node?" ); 280 aRet = *((SwOLENode*)this)->SwOLENode::GetGraphic(); 281 } 282 return aRet; 283 } 284 285 // --> OD 2009-07-14 #i73249# 286 void SwNoTxtNode::SetTitle( const String& rTitle, bool bBroadcast ) 287 { 288 // Title attribute of <SdrObject> replaces own AlternateText attribute 289 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt()); 290 ASSERT( pFlyFmt, 291 "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" ); 292 if ( !pFlyFmt ) 293 { 294 return; 295 } 296 297 pFlyFmt->SetObjTitle( rTitle, bBroadcast ); 298 } 299 300 const String SwNoTxtNode::GetTitle() const 301 { 302 const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt()); 303 ASSERT( pFlyFmt, 304 "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" ); 305 if ( !pFlyFmt ) 306 { 307 return aEmptyStr; 308 } 309 310 return pFlyFmt->GetObjTitle(); 311 } 312 313 void SwNoTxtNode::SetDescription( const String& rDescription, bool bBroadcast ) 314 { 315 SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt()); 316 ASSERT( pFlyFmt, 317 "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" ); 318 if ( !pFlyFmt ) 319 { 320 return; 321 } 322 323 pFlyFmt->SetObjDescription( rDescription, bBroadcast ); 324 } 325 326 const String SwNoTxtNode::GetDescription() const 327 { 328 const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt()); 329 ASSERT( pFlyFmt, 330 "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" ); 331 if ( !pFlyFmt ) 332 { 333 return aEmptyStr; 334 } 335 336 return pFlyFmt->GetObjDescription(); 337 } 338 // <-- 339