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