LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - customshapeproperties.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 71 86 82.6 %
Date: 2014-04-11 Functions: 15 16 93.8 %
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 <svx/sdr/properties/customshapeproperties.hxx>
      21             : #include <svl/itemset.hxx>
      22             : #include <svl/style.hxx>
      23             : #include <svx/svdoashp.hxx>
      24             : #include <editeng/eeitem.hxx>
      25             : #include <svx/sdtagitm.hxx>
      26             : #include <svl/whiter.hxx>
      27             : #include <svl/smplhint.hxx>
      28             : 
      29             : 
      30             : 
      31             : namespace sdr
      32             : {
      33             :     namespace properties
      34             :     {
      35      107177 :         void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
      36             :         {
      37      107177 :             SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
      38      107177 :             const bool bOld(rObj.bTextFrame);
      39             : 
      40             :             // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
      41             :             // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
      42      107177 :             rObj.bTextFrame = static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
      43             : 
      44             :             // check if it did change
      45      107177 :             if(rObj.bTextFrame != bOld)
      46             :             {
      47             :                 // on change also invalidate render geometry
      48        2067 :                 bInvalidateRenderGeometry = true;
      49             : 
      50             :                 // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
      51             :                 // will not change again. Thus it will be only one level and terminate safely
      52        2067 :                 rObj.AdaptTextMinSize();
      53             :             }
      54             : 
      55      107177 :             if(bInvalidateRenderGeometry)
      56             :             {
      57             :                 // if asked for or bResizeShapeToFitText changed, make sure that
      58             :                 // the render geometry is reconstructed using changed parameters
      59      103261 :                 rObj.InvalidateRenderGeometry();
      60             :             }
      61      107177 :         }
      62             : 
      63        2215 :         SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
      64             :         {
      65             :             return *(new SfxItemSet(rPool,
      66             : 
      67             :                 // ranges from SdrAttrObj
      68             :                 SDRATTR_START, SDRATTR_SHADOW_LAST,
      69             :                 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
      70             :                 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
      71             : 
      72             :                 // Graphic Attributes
      73             :                 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
      74             : 
      75             :                 // 3d Properties
      76             :                 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
      77             : 
      78             :                 // CustomShape properties
      79             :                 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
      80             : 
      81             :                 // range from SdrTextObj
      82             :                 EE_ITEMS_START, EE_ITEMS_END,
      83             : 
      84             :                 // end
      85        2215 :                 0, 0));
      86             :         }
      87             : 
      88       78656 :         bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
      89             :         {
      90       78656 :             sal_Bool bAllowItemChange = sal_True;
      91       78656 :             if ( !pNewItem )
      92             :             {
      93       14214 :                 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
      94         276 :                     bAllowItemChange = sal_False;
      95             :             }
      96       78656 :             if ( bAllowItemChange )
      97       78380 :                 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
      98       78656 :             return bAllowItemChange;
      99             :         }
     100             : 
     101          69 :         void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
     102             :         {
     103          69 :             if ( !nWhich )
     104             :             {
     105          69 :                 SfxWhichIter aIter( *mpItemSet );
     106          69 :                 sal_uInt16 nWhich2 = aIter.FirstWhich();
     107       14352 :                 while( nWhich2 )
     108             :                 {
     109       14214 :                     TextProperties::ClearObjectItemDirect( nWhich2 );
     110       14214 :                     nWhich2 = aIter.NextWhich();
     111             :                 }
     112         138 :                 SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
     113         138 :                 ItemSetChanged(aSet);
     114             :             }
     115             :             else
     116           0 :                 TextProperties::ClearObjectItem( nWhich );
     117          69 :         }
     118             : 
     119           0 :         void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
     120             :         {
     121           0 :             if ( !nWhich )
     122             :             {
     123           0 :                 SfxWhichIter aIter( *mpItemSet );
     124           0 :                 sal_uInt16 nWhich2 = aIter.FirstWhich();
     125           0 :                 while( nWhich2 )
     126             :                 {
     127           0 :                     TextProperties::ClearObjectItemDirect( nWhich2 );
     128           0 :                     nWhich2 = aIter.NextWhich();
     129           0 :                 }
     130             :             }
     131             :             else
     132           0 :                 TextProperties::ClearObjectItemDirect( nWhich );
     133           0 :         }
     134             : 
     135       19999 :         void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
     136             :         {
     137             :             // call parent
     138       19999 :             TextProperties::ItemSetChanged(rSet);
     139             : 
     140             :             // update bTextFrame and RenderGeometry
     141       19999 :             UpdateTextFrameStatus(true);
     142       19999 :         }
     143             : 
     144       58725 :         void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
     145             :         {
     146       58725 :             switch(nWhich)
     147             :             {
     148             :                 case SDRATTR_TEXT_AUTOGROWHEIGHT:
     149             :                 {
     150             :                     // #115391#  update bTextFrame and RenderGeometry using AdaptTextMinSize()
     151        3808 :                     UpdateTextFrameStatus(false);
     152        3808 :                     break;
     153             :                 }
     154             :                 default:
     155             :                 {
     156       54917 :                     break;
     157             :                 }
     158             :             }
     159             : 
     160             :             // call parent
     161       58725 :             TextProperties::PostItemChange(nWhich);
     162       58725 :         }
     163             : 
     164       78380 :         void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
     165             :         {
     166             :             // call parent
     167       78380 :             TextProperties::ItemChange( nWhich, pNewItem );
     168             : 
     169             :             // update bTextFrame and RenderGeometry
     170       78380 :             UpdateTextFrameStatus(true);
     171       78380 :         }
     172             : 
     173        2667 :         void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     174             :         {
     175             :             // call parent
     176        2667 :             TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
     177             : 
     178             :             // update bTextFrame and RenderGeometry
     179        2667 :             UpdateTextFrameStatus(true);
     180        2667 :         }
     181             : 
     182        2215 :         void CustomShapeProperties::ForceDefaultAttributes()
     183             :         {
     184             :             // update bTextFrame and RenderGeometry
     185        2215 :             UpdateTextFrameStatus(true);
     186             : 
     187             :             // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
     188             :             // This means: Do *not* call parent here is by purpose...
     189        2215 :         }
     190             : 
     191        2215 :         CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
     192        2215 :         :   TextProperties(rObj)
     193             :         {
     194        2215 :         }
     195             : 
     196          20 :         CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
     197          20 :         :   TextProperties(rProps, rObj)
     198             :         {
     199          20 :         }
     200             : 
     201        4454 :         CustomShapeProperties::~CustomShapeProperties()
     202             :         {
     203        4454 :         }
     204             : 
     205          20 :         BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
     206             :         {
     207          20 :             return *(new CustomShapeProperties(*this, rObj));
     208             :         }
     209             : 
     210         108 :         void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     211             :         {
     212         108 :             TextProperties::Notify( rBC, rHint );
     213             : 
     214         108 :             sal_Bool bRemoveRenderGeometry = sal_False;
     215         108 :             const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
     216         108 :             const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
     217             : 
     218         108 :             if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
     219             :             {
     220           0 :                 switch( pStyleHint->GetHint() )
     221             :                 {
     222             :                     case SFX_STYLESHEET_MODIFIED :
     223             :                     case SFX_STYLESHEET_CHANGED  :
     224           0 :                         bRemoveRenderGeometry = sal_True;
     225           0 :                     break;
     226             :                 };
     227             :             }
     228         108 :             else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
     229             :             {
     230           0 :                 bRemoveRenderGeometry = sal_True;
     231             :             }
     232             : 
     233             :                 // update bTextFrame and RenderGeometry
     234         108 :             UpdateTextFrameStatus(bRemoveRenderGeometry);
     235         108 :         }
     236             :     } // end of namespace properties
     237             : } // end of namespace sdr
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10