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