LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - customshapeproperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 87 82.8 %
Date: 2014-11-03 Functions: 17 18 94.4 %
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 <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      307730 :         void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
      36             :         {
      37      307730 :             SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
      38      307730 :             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      307730 :             rObj.bTextFrame = static_cast< const SdrOnOffItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
      43             : 
      44             :             // check if it did change
      45      307730 :             if(rObj.bTextFrame != bOld)
      46             :             {
      47             :                 // on change also invalidate render geometry
      48        5762 :                 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        5762 :                 rObj.AdaptTextMinSize();
      53             :             }
      54             : 
      55      307730 :             if(bInvalidateRenderGeometry)
      56             :             {
      57             :                 // if asked for or bResizeShapeToFitText changed, make sure that
      58             :                 // the render geometry is reconstructed using changed parameters
      59      296396 :                 rObj.InvalidateRenderGeometry();
      60             :             }
      61      307730 :         }
      62             : 
      63        5972 :         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        5972 :                 0, 0));
      86             :         }
      87             : 
      88      222128 :         bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
      89             :         {
      90      222128 :             bool bAllowItemChange = true;
      91      222128 :             if ( !pNewItem )
      92             :             {
      93       33948 :                 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
      94         656 :                     bAllowItemChange = false;
      95             :             }
      96      222128 :             if ( bAllowItemChange )
      97      221472 :                 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
      98      222128 :             return bAllowItemChange;
      99             :         }
     100             : 
     101         164 :         void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
     102             :         {
     103         164 :             if ( !nWhich )
     104             :             {
     105         164 :                 SfxWhichIter aIter( *mpItemSet );
     106         164 :                 sal_uInt16 nWhich2 = aIter.FirstWhich();
     107       34276 :                 while( nWhich2 )
     108             :                 {
     109       33948 :                     TextProperties::ClearObjectItemDirect( nWhich2 );
     110       33948 :                     nWhich2 = aIter.NextWhich();
     111             :                 }
     112         328 :                 SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
     113         328 :                 ItemSetChanged(aSet);
     114             :             }
     115             :             else
     116           0 :                 TextProperties::ClearObjectItem( nWhich );
     117         164 :         }
     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       62020 :         void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
     136             :         {
     137             :             // call parent
     138       62020 :             TextProperties::ItemSetChanged(rSet);
     139             : 
     140             :             // update bTextFrame and RenderGeometry
     141       62020 :             UpdateTextFrameStatus(true);
     142       62020 :         }
     143             : 
     144      172228 :         void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
     145             :         {
     146      172228 :             switch(nWhich)
     147             :             {
     148             :                 case SDRATTR_TEXT_AUTOGROWHEIGHT:
     149             :                 {
     150             :                     // #115391#  update bTextFrame and RenderGeometry using AdaptTextMinSize()
     151       11118 :                     UpdateTextFrameStatus(false);
     152       11118 :                     break;
     153             :                 }
     154             :                 default:
     155             :                 {
     156      161110 :                     break;
     157             :                 }
     158             :             }
     159             : 
     160             :             // call parent
     161      172228 :             TextProperties::PostItemChange(nWhich);
     162      172228 :         }
     163             : 
     164      221472 :         void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
     165             :         {
     166             :             // call parent
     167      221472 :             TextProperties::ItemChange( nWhich, pNewItem );
     168             : 
     169             :             // update bTextFrame and RenderGeometry
     170      221472 :             UpdateTextFrameStatus(true);
     171      221472 :         }
     172             : 
     173        6932 :         void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     174             :         {
     175             :             // call parent
     176        6932 :             TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
     177             : 
     178             :             // update bTextFrame and RenderGeometry
     179        6932 :             UpdateTextFrameStatus(true);
     180        6932 :         }
     181             : 
     182        5972 :         void CustomShapeProperties::ForceDefaultAttributes()
     183             :         {
     184             :             // update bTextFrame and RenderGeometry
     185        5972 :             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        5972 :         }
     190             : 
     191        5972 :         CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
     192        5972 :         :   TextProperties(rObj)
     193             :         {
     194        5972 :         }
     195             : 
     196         346 :         CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
     197         346 :         :   TextProperties(rProps, rObj)
     198             :         {
     199         346 :         }
     200             : 
     201       12636 :         CustomShapeProperties::~CustomShapeProperties()
     202             :         {
     203       12636 :         }
     204             : 
     205         346 :         BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
     206             :         {
     207         346 :             return *(new CustomShapeProperties(*this, rObj));
     208             :         }
     209             : 
     210         216 :         void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     211             :         {
     212         216 :             TextProperties::Notify( rBC, rHint );
     213             : 
     214         216 :             bool bRemoveRenderGeometry = false;
     215         216 :             const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
     216         216 :             const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     217             : 
     218         216 :             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 = true;
     225           0 :                     break;
     226             :                 };
     227             :             }
     228         216 :             else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
     229             :             {
     230           0 :                 bRemoveRenderGeometry = true;
     231             :             }
     232             : 
     233             :                 // update bTextFrame and RenderGeometry
     234         216 :             UpdateTextFrameStatus(bRemoveRenderGeometry);
     235         216 :         }
     236             :     } // end of namespace properties
     237         651 : } // end of namespace sdr
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10