xref: /aoo4110/main/oox/inc/oox/xls/scenariobuffer.hxx (revision b1cdbd2c)
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 #ifndef OOX_XLS_SCENARIOBUFFER_HXX
25 #define OOX_XLS_SCENARIOBUFFER_HXX
26 
27 #include <com/sun/star/table/CellAddress.hpp>
28 #include "oox/helper/refmap.hxx"
29 #include "oox/helper/refvector.hxx"
30 #include "oox/xls/workbookhelper.hxx"
31 
32 namespace oox {
33 namespace xls {
34 
35 // ============================================================================
36 
37 struct ScenarioCellModel
38 {
39     ::com::sun::star::table::CellAddress maPos;
40     ::rtl::OUString     maValue;
41     sal_Int32           mnNumFmtId;
42     bool                mbDeleted;
43 
44     explicit            ScenarioCellModel();
45 };
46 
47 // ----------------------------------------------------------------------------
48 
49 struct ScenarioModel
50 {
51     ::rtl::OUString     maName;             /// Name of the scenario.
52     ::rtl::OUString     maComment;          /// Comment.
53     ::rtl::OUString     maUser;             /// Name of user created the scenario.
54     bool                mbLocked;           /// True = input cell values locked.
55     bool                mbHidden;           /// True = scenario is hidden.
56 
57     explicit            ScenarioModel();
58 };
59 
60 // ----------------------------------------------------------------------------
61 
62 class Scenario : public WorkbookHelper
63 {
64 public:
65     explicit            Scenario( const WorkbookHelper& rHelper, sal_Int16 nSheet );
66 
67     /** Imports a scenario definition from a scenario element. */
68     void                importScenario( const AttributeList& rAttribs );
69     /** Imports a new cell for this scenario from a inputCells element. */
70     void                importInputCells( const AttributeList& rAttribs );
71 
72     /** Imports a scenario definition from a SCENARIO record. */
73     void                importScenario( SequenceInputStream& rStrm );
74     /** Imports a new cell for this scenario from a INPUTCELLS record. */
75     void                importInputCells( SequenceInputStream& rStrm );
76 
77     /** Imports a scenario definition from a SCENARIO record. */
78     void                importScenario( BiffInputStream& rStrm );
79 
80     /** Creates the scenario in the Calc document. */
81     void                finalizeImport();
82 
83 private:
84     typedef ::std::vector< ScenarioCellModel > ScenarioCellVector;
85 
86     ScenarioCellVector  maCells;            /// Scenario cells.
87     ScenarioModel       maModel;            /// Scenario model data.
88     sal_Int16           mnSheet;            /// Index of the sheet this scenario is based on.
89 };
90 
91 // ============================================================================
92 
93 struct SheetScenariosModel
94 {
95     sal_Int32           mnCurrent;          /// Selected scenario.
96     sal_Int32           mnShown;            /// Visible scenario.
97 
98     explicit            SheetScenariosModel();
99 };
100 
101 // ----------------------------------------------------------------------------
102 
103 class SheetScenarios : public WorkbookHelper
104 {
105 public:
106     explicit            SheetScenarios( const WorkbookHelper& rHelper, sal_Int16 nSheet );
107 
108     /** Imports sheet scenario settings from a scenarios element. */
109     void                importScenarios( const AttributeList& rAttribs );
110     /** Imports sheet scenario settings from a SCENARIOS record. */
111     void                importScenarios( SequenceInputStream& rStrm );
112     /** Imports sheet scenario settings from a SCENARIOS record. */
113     void                importScenarios( BiffInputStream& rStrm );
114 
115     /** Creates and returns a new scenario in this collection. */
116     Scenario&           createScenario();
117 
118     /** Creates all scenarios in the Calc sheet. */
119     void                finalizeImport();
120 
121 private:
122     typedef RefVector< Scenario > ScenarioVector;
123     ScenarioVector      maScenarios;
124     SheetScenariosModel maModel;
125     sal_Int16           mnSheet;
126 };
127 
128 // ============================================================================
129 
130 class ScenarioBuffer : public WorkbookHelper
131 {
132 public:
133     explicit            ScenarioBuffer( const WorkbookHelper& rHelper );
134 
135     /** Creates and returns a scenario collection for the passed sheet. */
136     SheetScenarios&     createSheetScenarios( sal_Int16 nSheet );
137 
138     /** Creates all scenarios in the Calc dcument. */
139     void                finalizeImport();
140 
141 private:
142     typedef RefMap< sal_Int16, SheetScenarios, ::std::greater< sal_Int16 > > SheetScenariosMap;
143     SheetScenariosMap   maSheetScenarios;
144 };
145 
146 // ============================================================================
147 
148 } // namespace xls
149 } // namespace oox
150 
151 #endif
152