LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/docnode - ndnotxt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 134 35.1 %
Date: 2012-12-27 Functions: 9 18 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : #include <tools/poly.hxx>
      22             : #include <svl/stritem.hxx>
      23             : #include <svx/contdlg.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <docary.hxx>
      26             : #include <doc.hxx>
      27             : #include <fmtcol.hxx>
      28             : #include <ndnotxt.hxx>
      29             : #include <ndgrf.hxx>
      30             : #include <ndole.hxx>
      31             : #include <ndindex.hxx>
      32             : #include <hints.hxx>
      33             : #include <istyleaccess.hxx>
      34             : #include <SwStyleNameMapper.hxx>
      35             : 
      36             : #include <frmfmt.hxx> // #i73249#
      37             : 
      38         186 : SwNoTxtNode::SwNoTxtNode( const SwNodeIndex & rWhere,
      39             :                   const sal_uInt8 nNdType,
      40             :                   SwGrfFmtColl *pGrfColl,
      41             :                   SwAttrSet* pAutoAttr ) :
      42             :     SwCntntNode( rWhere, nNdType, pGrfColl ),
      43             :     pContour( 0 ),
      44             :     bAutomaticContour( sal_False ),
      45             :     bContourMapModeValid( sal_True ),
      46         186 :     bPixelContour( sal_False )
      47             : {
      48             :     // Should this set a hard attribute?
      49         186 :     if( pAutoAttr )
      50           1 :         SetAttr( *pAutoAttr );
      51         186 : }
      52             : 
      53         184 : SwNoTxtNode::~SwNoTxtNode()
      54             : {
      55          92 :     delete pContour;
      56          92 : }
      57             : 
      58             : /// Creates an AttrSet for all derivations with ranges for frame-
      59             : /// and graphics-attributes.
      60          40 : void SwNoTxtNode::NewAttrSet( SwAttrPool& rPool )
      61             : {
      62             :     OSL_ENSURE( !mpAttrSet.get(), "AttrSet is already set" );
      63          40 :     SwAttrSet aNewAttrSet( rPool, aNoTxtNodeSetRange );
      64             : 
      65             :     // put names of parent style and conditional style:
      66          40 :     const SwFmtColl* pFmtColl = GetFmtColl();
      67          40 :     String sVal;
      68          40 :     SwStyleNameMapper::FillProgName( pFmtColl->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
      69          40 :     SfxStringItem aFmtColl( RES_FRMATR_STYLE_NAME, sVal );
      70          40 :     aNewAttrSet.Put( aFmtColl );
      71             : 
      72          40 :     aNewAttrSet.SetParent( &GetFmtColl()->GetAttrSet() );
      73          40 :     mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, IStyleAccess::AUTO_STYLE_NOTXT );
      74          40 : }
      75             : 
      76             : /// Dummies for loading/saving of persistent data
      77             : /// when working with graphics and OLE objects
      78           0 : sal_Bool SwNoTxtNode::RestorePersistentData()
      79             : {
      80           0 :     return sal_True;
      81             : }
      82             : 
      83           0 : sal_Bool SwNoTxtNode::SavePersistentData()
      84             : {
      85           0 :     return sal_True;
      86             : }
      87             : 
      88           8 : void SwNoTxtNode::SetContour( const PolyPolygon *pPoly, sal_Bool bAutomatic )
      89             : {
      90           8 :     delete pContour;
      91           8 :     if ( pPoly )
      92           0 :         pContour = new PolyPolygon( *pPoly );
      93             :     else
      94           8 :         pContour = 0;
      95           8 :     bAutomaticContour = bAutomatic;
      96           8 :     bContourMapModeValid = sal_True;
      97           8 :     bPixelContour = sal_False;
      98           8 : }
      99             : 
     100           0 : void SwNoTxtNode::CreateContour()
     101             : {
     102             :     OSL_ENSURE( !pContour, "Contour available." );
     103           0 :     pContour = new PolyPolygon(SvxContourDlg::CreateAutoContour(GetGraphic()));
     104           0 :     bAutomaticContour = sal_True;
     105           0 :     bContourMapModeValid = sal_True;
     106           0 :     bPixelContour = sal_False;
     107           0 : }
     108             : 
     109           1 : const PolyPolygon *SwNoTxtNode::HasContour() const
     110             : {
     111           1 :     if( !bContourMapModeValid )
     112             :     {
     113           0 :         const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
     114           0 :         bool bPixelGrf = aGrfMap.GetMapUnit() == MAP_PIXEL;
     115           0 :         const MapMode aContourMap( bPixelGrf ? MAP_PIXEL : MAP_100TH_MM );
     116           0 :         if( bPixelGrf ? !bPixelContour : aGrfMap != aContourMap )
     117             :         {
     118             :             // #i102238#
     119           0 :             double nGrfDPIx = 0.0;
     120           0 :             double nGrfDPIy = 0.0;
     121             :             {
     122           0 :                 if ( !bPixelGrf && bPixelContour )
     123             :                 {
     124           0 :                     const Size aGrfPixelSize( GetGraphic().GetSizePixel() );
     125           0 :                     const Size aGrfPrefMapModeSize( GetGraphic().GetPrefSize() );
     126           0 :                     if ( aGrfMap.GetMapUnit() == MAP_INCH )
     127             :                     {
     128           0 :                         nGrfDPIx = aGrfPixelSize.Width() / ( (double)aGrfMap.GetScaleX() * aGrfPrefMapModeSize.Width() );
     129           0 :                         nGrfDPIy = aGrfPixelSize.Height() / ( (double)aGrfMap.GetScaleY() * aGrfPrefMapModeSize.Height() );
     130             :                     }
     131             :                     else
     132             :                     {
     133             :                         const Size aGrf1000thInchSize =
     134             :                             OutputDevice::LogicToLogic( aGrfPrefMapModeSize,
     135           0 :                                                         aGrfMap, MAP_1000TH_INCH );
     136           0 :                         nGrfDPIx = 1000.0 * aGrfPixelSize.Width() / aGrf1000thInchSize.Width();
     137           0 :                         nGrfDPIy = 1000.0 * aGrfPixelSize.Height() / aGrf1000thInchSize.Height();
     138             :                     }
     139             :                 }
     140             :             }
     141             :             OSL_ENSURE( !bPixelGrf || aGrfMap == aContourMap,
     142             :                         "scale factor for pixel unsupported" );
     143             :             OutputDevice* pOutDev =
     144             :                 (bPixelGrf || bPixelContour) ? Application::GetDefaultDevice()
     145           0 :                                              : 0;
     146           0 :             sal_uInt16 nPolyCount = pContour->Count();
     147           0 :             for( sal_uInt16 j=0; j<nPolyCount; j++ )
     148             :             {
     149           0 :                 Polygon& rPoly = (*pContour)[j];
     150             : 
     151           0 :                 sal_uInt16 nCount = rPoly.GetSize();
     152           0 :                 for( sal_uInt16 i=0 ; i<nCount; i++ )
     153             :                 {
     154           0 :                     if( bPixelGrf )
     155           0 :                         rPoly[i] = pOutDev->LogicToPixel( rPoly[i],
     156           0 :                                                           aContourMap );
     157           0 :                     else if( bPixelContour )
     158             :                     {
     159           0 :                         rPoly[i] = pOutDev->PixelToLogic( rPoly[i], aGrfMap );
     160             :                         // #i102238#
     161           0 :                         if ( nGrfDPIx != 0 && nGrfDPIy != 0 )
     162             :                         {
     163           0 :                             rPoly[i] = Point( rPoly[i].X() * pOutDev->ImplGetDPIX() / nGrfDPIx,
     164           0 :                                               rPoly[i].Y() * pOutDev->ImplGetDPIY() / nGrfDPIy );
     165             :                         }
     166             :                     }
     167             :                     else
     168           0 :                         rPoly[i] = OutputDevice::LogicToLogic( rPoly[i],
     169             :                                                                  aContourMap,
     170           0 :                                                                  aGrfMap );
     171             :                 }
     172             :             }
     173             :         }
     174           0 :         ((SwNoTxtNode *)this)->bContourMapModeValid = sal_True;
     175           0 :         ((SwNoTxtNode *)this)->bPixelContour = sal_False;
     176             :     }
     177             : 
     178           1 :     return pContour;
     179             : }
     180             : 
     181           0 : void SwNoTxtNode::GetContour( PolyPolygon &rPoly ) const
     182             : {
     183             :     OSL_ENSURE( pContour, "Contour not available." );
     184           0 :     rPoly = *HasContour();
     185           0 : }
     186             : 
     187           0 : void SwNoTxtNode::SetContourAPI( const PolyPolygon *pPoly )
     188             : {
     189           0 :     delete pContour;
     190           0 :     if ( pPoly )
     191           0 :         pContour = new PolyPolygon( *pPoly );
     192             :     else
     193           0 :         pContour = 0;
     194           0 :     bContourMapModeValid = sal_False;
     195           0 : }
     196             : 
     197           0 : sal_Bool SwNoTxtNode::GetContourAPI( PolyPolygon &rContour ) const
     198             : {
     199           0 :     if( !pContour )
     200           0 :         return sal_False;
     201             : 
     202           0 :     rContour = *pContour;
     203           0 :     if( bContourMapModeValid )
     204             :     {
     205           0 :         const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
     206           0 :         const MapMode aContourMap( MAP_100TH_MM );
     207             :         OSL_ENSURE( aGrfMap.GetMapUnit() != MAP_PIXEL ||
     208             :                 aGrfMap == MapMode( MAP_PIXEL ),
     209             :                     "scale factor for pixel unsupported" );
     210           0 :         if( aGrfMap.GetMapUnit() != MAP_PIXEL &&
     211           0 :             aGrfMap != aContourMap )
     212             :         {
     213           0 :             sal_uInt16 nPolyCount = rContour.Count();
     214           0 :             for( sal_uInt16 j=0; j<nPolyCount; j++ )
     215             :             {
     216             :                 // --> OD #i102238# - use the right <PolyPolygon> instance
     217           0 :                 Polygon& rPoly = rContour[j];
     218             :                 // <--
     219             : 
     220           0 :                 sal_uInt16 nCount = rPoly.GetSize();
     221           0 :                 for( sal_uInt16 i=0 ; i<nCount; i++ )
     222             :                 {
     223           0 :                     rPoly[i] = OutputDevice::LogicToLogic( rPoly[i], aGrfMap,
     224           0 :                                                            aContourMap );
     225             :                 }
     226             :             }
     227           0 :         }
     228             :     }
     229             : 
     230           0 :     return sal_True;
     231             : }
     232             : 
     233           0 : sal_Bool SwNoTxtNode::IsPixelContour() const
     234             : {
     235             :     sal_Bool bRet;
     236           0 :     if( bContourMapModeValid )
     237             :     {
     238           0 :         const MapMode aGrfMap( GetGraphic().GetPrefMapMode() );
     239           0 :         bRet = aGrfMap.GetMapUnit() == MAP_PIXEL;
     240             :     }
     241             :     else
     242             :     {
     243           0 :         bRet = bPixelContour;
     244             :     }
     245             : 
     246           0 :     return bRet;
     247             : }
     248             : 
     249           0 : Graphic SwNoTxtNode::GetGraphic() const
     250             : {
     251           0 :     Graphic aRet;
     252           0 :     if ( GetGrfNode() )
     253             :     {
     254           0 :         ((SwGrfNode*)this)->SwapIn( sal_True );
     255           0 :         aRet = ((SwGrfNode*)this)->GetGrf();
     256             :     }
     257             :     else
     258             :     {
     259             :         OSL_ENSURE( GetOLENode(), "new type of Node?" );
     260           0 :         aRet = *((SwOLENode*)this)->SwOLENode::GetGraphic();
     261             :     }
     262           0 :     return aRet;
     263             : }
     264             : 
     265             : // #i73249#
     266           1 : void SwNoTxtNode::SetTitle( const String& rTitle, bool bBroadcast )
     267             : {
     268             :     // Title attribute of <SdrObject> replaces own AlternateText attribute
     269           1 :     SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
     270             :     OSL_ENSURE( pFlyFmt,
     271             :             "<SwNoTxtNode::SetTitle(..)> - missing <SwFlyFrmFmt> instance" );
     272           1 :     if ( !pFlyFmt )
     273             :     {
     274           1 :         return;
     275             :     }
     276             : 
     277           1 :     pFlyFmt->SetObjTitle( rTitle, bBroadcast );
     278             : }
     279             : 
     280           1 : const String SwNoTxtNode::GetTitle() const
     281             : {
     282           1 :     const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
     283             :     OSL_ENSURE( pFlyFmt,
     284             :             "<SwNoTxtNode::GetTitle(..)> - missing <SwFlyFrmFmt> instance" );
     285           1 :     if ( !pFlyFmt )
     286             :     {
     287           0 :         return aEmptyStr;
     288             :     }
     289             : 
     290           1 :     return pFlyFmt->GetObjTitle();
     291             : }
     292             : 
     293           1 : void SwNoTxtNode::SetDescription( const String& rDescription, bool bBroadcast )
     294             : {
     295           1 :     SwFlyFrmFmt* pFlyFmt = dynamic_cast<SwFlyFrmFmt*>(GetFlyFmt());
     296             :     OSL_ENSURE( pFlyFmt,
     297             :             "<SwNoTxtNode::SetDescription(..)> - missing <SwFlyFrmFmt> instance" );
     298           1 :     if ( !pFlyFmt )
     299             :     {
     300           1 :         return;
     301             :     }
     302             : 
     303           1 :     pFlyFmt->SetObjDescription( rDescription, bBroadcast );
     304             : }
     305             : 
     306           1 : const String SwNoTxtNode::GetDescription() const
     307             : {
     308           1 :     const SwFlyFrmFmt* pFlyFmt = dynamic_cast<const SwFlyFrmFmt*>(GetFlyFmt());
     309             :     OSL_ENSURE( pFlyFmt,
     310             :             "<SwNoTxtNode::GetDescription(..)> - missing <SwFlyFrmFmt> instance" );
     311           1 :     if ( !pFlyFmt )
     312             :     {
     313           0 :         return aEmptyStr;
     314             :     }
     315             : 
     316           1 :     return pFlyFmt->GetObjDescription();
     317             : }
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10