xref: /aoo42x/main/oox/source/xls/scenariocontext.cxx (revision cdf0e10c)
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 #include "oox/xls/scenariocontext.hxx"
29 
30 #include "oox/xls/scenariobuffer.hxx"
31 
32 namespace oox {
33 namespace xls {
34 
35 // ============================================================================
36 
37 using ::oox::core::ContextHandlerRef;
38 
39 // ============================================================================
40 
41 ScenarioContext::ScenarioContext( WorksheetContextBase& rParent, SheetScenarios& rSheetScenarios ) :
42     WorksheetContextBase( rParent ),
43     mrScenario( rSheetScenarios.createScenario() )
44 {
45 }
46 
47 ContextHandlerRef ScenarioContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
48 {
49     switch( getCurrentElement() )
50     {
51         case XLS_TOKEN( scenario ):
52             if( nElement == XLS_TOKEN( inputCells ) ) mrScenario.importInputCells( rAttribs );
53         break;
54     }
55     return 0;
56 }
57 
58 void ScenarioContext::onStartElement( const AttributeList& rAttribs )
59 {
60     if( isRootElement() )
61         mrScenario.importScenario( rAttribs );
62 }
63 
64 ContextHandlerRef ScenarioContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
65 {
66     switch( getCurrentElement() )
67     {
68         case BIFF12_ID_SCENARIO:
69             if( nRecId == BIFF12_ID_INPUTCELLS ) mrScenario.importInputCells( rStrm );
70         break;
71     }
72     return 0;
73 }
74 
75 void ScenarioContext::onStartRecord( SequenceInputStream& rStrm )
76 {
77     if( isRootElement() )
78         mrScenario.importScenario( rStrm );
79 }
80 
81 // ============================================================================
82 
83 ScenariosContext::ScenariosContext( WorksheetFragmentBase& rFragment ) :
84     WorksheetContextBase( rFragment ),
85     mrSheetScenarios( getScenarios().createSheetScenarios( getSheetIndex() ) )
86 {
87 }
88 
89 ContextHandlerRef ScenariosContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
90 {
91     switch( getCurrentElement() )
92     {
93         case XLS_TOKEN( scenarios ):
94             if( nElement == XLS_TOKEN( scenario ) ) return new ScenarioContext( *this, mrSheetScenarios );
95         break;
96     }
97     return 0;
98 }
99 
100 void ScenariosContext::onStartElement( const AttributeList& rAttribs )
101 {
102     if( isRootElement() )
103         mrSheetScenarios.importScenarios( rAttribs );
104 }
105 
106 ContextHandlerRef ScenariosContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& )
107 {
108     switch( getCurrentElement() )
109     {
110         case BIFF12_ID_SCENARIOS:
111             if( nRecId == BIFF12_ID_SCENARIO ) return new ScenarioContext( *this, mrSheetScenarios );
112         break;
113     }
114     return 0;
115 }
116 
117 void ScenariosContext::onStartRecord( SequenceInputStream& rStrm )
118 {
119     if( isRootElement() )
120         mrSheetScenarios.importScenarios( rStrm );
121 }
122 
123 // ============================================================================
124 
125 } // namespace xls
126 } // namespace oox
127