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_slideshow.hxx" 26 27 #include <canvas/debug.hxx> 28 #include <tools/diagnose_ex.h> 29 30 #include <comphelper/anytostring.hxx> 31 #include <cppuhelper/exc_hlp.hxx> 32 33 #include "shapesubset.hxx" 34 35 36 using namespace ::com::sun::star; 37 38 namespace slideshow 39 { 40 namespace internal 41 { ShapeSubset(const AttributableShapeSharedPtr & rOriginalShape,const DocTreeNode & rTreeNode,const SubsettableShapeManagerSharedPtr & rShapeManager)42 ShapeSubset::ShapeSubset( const AttributableShapeSharedPtr& rOriginalShape, 43 const DocTreeNode& rTreeNode, 44 const SubsettableShapeManagerSharedPtr& rShapeManager ) : 45 mpOriginalShape( rOriginalShape ), 46 mpSubsetShape(), 47 maTreeNode( rTreeNode ), 48 mpShapeManager( rShapeManager ) 49 { 50 ENSURE_OR_THROW( mpShapeManager, 51 "ShapeSubset::ShapeSubset(): Invalid shape manager" ); 52 } 53 ShapeSubset(const ShapeSubsetSharedPtr & rOriginalSubset,const DocTreeNode & rTreeNode)54 ShapeSubset::ShapeSubset( const ShapeSubsetSharedPtr& rOriginalSubset, 55 const DocTreeNode& rTreeNode ) : 56 mpOriginalShape( rOriginalSubset->mpSubsetShape ? 57 rOriginalSubset->mpSubsetShape : 58 rOriginalSubset->mpOriginalShape ), 59 mpSubsetShape(), 60 maTreeNode( rTreeNode ), 61 mpShapeManager( rOriginalSubset->mpShapeManager ) 62 { 63 ENSURE_OR_THROW( mpShapeManager, 64 "ShapeSubset::ShapeSubset(): Invalid shape manager" ); 65 ENSURE_OR_THROW( rOriginalSubset->maTreeNode.isEmpty() || 66 (rTreeNode.getStartIndex() >= rOriginalSubset->maTreeNode.getStartIndex() && 67 rTreeNode.getEndIndex() <= rOriginalSubset->maTreeNode.getEndIndex()), 68 "ShapeSubset::ShapeSubset(): Subset is bigger than parent" ); 69 } 70 ShapeSubset(const AttributableShapeSharedPtr & rOriginalShape,const SubsettableShapeManagerSharedPtr & rShapeManager)71 ShapeSubset::ShapeSubset( const AttributableShapeSharedPtr& rOriginalShape, 72 const SubsettableShapeManagerSharedPtr& rShapeManager ) : 73 mpOriginalShape( rOriginalShape ), 74 mpSubsetShape(), 75 maTreeNode(), 76 mpShapeManager( rShapeManager ) 77 { 78 ENSURE_OR_THROW( mpShapeManager, 79 "ShapeSubset::ShapeSubset(): Invalid shape manager" ); 80 } 81 ~ShapeSubset()82 ShapeSubset::~ShapeSubset() 83 { 84 try 85 { 86 // if not done yet: revoke subset from original 87 disableSubsetShape(); 88 } 89 catch (uno::Exception &) 90 { 91 OSL_ENSURE( false, rtl::OUStringToOString( 92 comphelper::anyToString( 93 cppu::getCaughtException() ), 94 RTL_TEXTENCODING_UTF8 ).getStr() ); 95 } 96 } 97 getSubsetShape() const98 AttributableShapeSharedPtr ShapeSubset::getSubsetShape() const 99 { 100 return mpSubsetShape ? mpSubsetShape : mpOriginalShape; 101 } 102 enableSubsetShape()103 bool ShapeSubset::enableSubsetShape() 104 { 105 if( !mpSubsetShape && 106 !maTreeNode.isEmpty() ) 107 { 108 mpSubsetShape = mpShapeManager->getSubsetShape( 109 mpOriginalShape, 110 maTreeNode ); 111 } 112 113 return (mpSubsetShape.get() != NULL); 114 } 115 disableSubsetShape()116 void ShapeSubset::disableSubsetShape() 117 { 118 if( mpSubsetShape ) 119 { 120 mpShapeManager->revokeSubset( mpOriginalShape, 121 mpSubsetShape ); 122 mpSubsetShape.reset(); 123 } 124 } 125 isFullSet() const126 bool ShapeSubset::isFullSet() const 127 { 128 return maTreeNode.isEmpty(); 129 } 130 getSubset() const131 DocTreeNode ShapeSubset::getSubset() const 132 { 133 return maTreeNode; 134 } 135 136 } 137 } 138