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