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_sdext.hxx" 26 27 #include "optimizationstats.hxx" 28 #include <com/sun/star/awt/Size.hpp> 29 #include <com/sun/star/drawing/XShapes.hpp> 30 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> 31 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> 32 33 34 using namespace ::rtl; 35 using namespace ::com::sun::star; 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::frame; 38 using namespace ::com::sun::star::drawing; 39 using namespace ::com::sun::star::beans; 40 41 // ----------------------------------------------------------------------------- 42 43 OptimizationStats::OptimizationStats() 44 { 45 } 46 47 // ----------------------------------------------------------------------------- 48 49 void OptimizationStats::SetStatusValue( const PPPOptimizerTokenEnum eStat, const uno::Any& rStatValue ) 50 { 51 maStats[ eStat ] = rStatValue; 52 } 53 54 // ----------------------------------------------------------------------------- 55 56 const uno::Any* OptimizationStats::GetStatusValue( const PPPOptimizerTokenEnum eStat ) const 57 { 58 std::map< PPPOptimizerTokenEnum, uno::Any, Compare >::const_iterator aIter( maStats.find( eStat ) ); 59 return aIter != maStats.end() ? &((*aIter).second) : NULL; 60 } 61 62 // ----------------------------------------------------------------------------- 63 64 com::sun::star::beans::PropertyValues OptimizationStats::GetStatusSequence() 65 { 66 int i = 0; 67 uno::Sequence< PropertyValue > aStatsSequence( maStats.size() ); 68 std::map< PPPOptimizerTokenEnum, uno::Any, Compare >::iterator aIter( maStats.begin() ); 69 while( aIter != maStats.end() ) 70 { 71 aStatsSequence[ i ].Name = TKGet( (*aIter).first ); 72 aStatsSequence[ i++ ].Value <<= (*aIter++).second; 73 } 74 return aStatsSequence; 75 } 76 77 // ----------------------------------------------------------------------------- 78 79 void OptimizationStats::InitializeStatusValues( const uno::Sequence< PropertyValue >& rOptimizationStats ) 80 { 81 for( int i = 0; i < rOptimizationStats.getLength(); i++ ) 82 rOptimizationStats[ i ].Value >>= maStats[ TKGet( rOptimizationStats[ i ].Name ) ]; 83 } 84 85 // ----------------------------------------------------------------------------- 86 87 void OptimizationStats::InitializeStatusValuesFromDocument( Reference< XModel > rxModel ) 88 { 89 try 90 { 91 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW ); 92 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW ); 93 SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) ); 94 } 95 catch ( Exception& ) 96 { 97 } 98 } 99