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_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 #include "XMLExportSharedData.hxx"
35 #include "XMLExportIterator.hxx"
36 #include <tools/debug.hxx>
37 
38 using namespace com::sun::star;
39 
40 ScMySharedData::ScMySharedData(const sal_Int32 nTempTableCount) :
41 	nLastColumns(nTempTableCount, 0),
42 	nLastRows(nTempTableCount, 0),
43 	pTableShapes(NULL),
44 	pDrawPages(NULL),
45 	pShapesContainer(NULL),
46 	pDetectiveObjContainer(new ScMyDetectiveObjContainer()),
47     pNoteShapes(NULL),
48 	nTableCount(nTempTableCount)
49 {
50 }
51 
52 ScMySharedData::~ScMySharedData()
53 {
54 	if (pShapesContainer)
55 		delete pShapesContainer;
56 	if (pTableShapes)
57 		delete pTableShapes;
58 	if (pDrawPages)
59 		delete pDrawPages;
60 	if (pDetectiveObjContainer)
61 		delete pDetectiveObjContainer;
62     if (pNoteShapes)
63         delete pNoteShapes;
64 }
65 
66 void ScMySharedData::SetLastColumn(const sal_Int32 nTable, const sal_Int32 nCol)
67 {
68 	if(nCol > nLastColumns[nTable]) nLastColumns[nTable] = nCol;
69 }
70 
71 sal_Int32 ScMySharedData::GetLastColumn(const sal_Int32 nTable)
72 {
73 	return nLastColumns[nTable];
74 }
75 
76 void ScMySharedData::SetLastRow(const sal_Int32 nTable, const sal_Int32 nRow)
77 {
78 	if(nRow > nLastRows[nTable]) nLastRows[nTable] = nRow;
79 }
80 
81 sal_Int32 ScMySharedData::GetLastRow(const sal_Int32 nTable)
82 {
83 	return nLastRows[nTable];
84 }
85 
86 void ScMySharedData::AddDrawPage(const ScMyDrawPage& aDrawPage, const sal_Int32 nTable)
87 {
88 	if (!pDrawPages)
89 		pDrawPages = new ScMyDrawPages(nTableCount, ScMyDrawPage());
90 	(*pDrawPages)[nTable] = aDrawPage;
91 }
92 
93 void ScMySharedData::SetDrawPageHasForms(const sal_Int32 nTable, sal_Bool bHasForms)
94 {
95 	DBG_ASSERT(pDrawPages, "DrawPages not collected");
96 	if (pDrawPages)
97 		(*pDrawPages)[nTable].bHasForms = bHasForms;
98 }
99 
100 uno::Reference<drawing::XDrawPage> ScMySharedData::GetDrawPage(const sal_Int32 nTable)
101 {
102 	DBG_ASSERT(pDrawPages, "DrawPages not collected");
103 	if (pDrawPages)
104 		return (*pDrawPages)[nTable].xDrawPage;
105 	else
106 		return uno::Reference<drawing::XDrawPage>();
107 }
108 
109 sal_Bool ScMySharedData::HasForm(const sal_Int32 nTable, uno::Reference<drawing::XDrawPage>& xDrawPage)
110 {
111 	sal_Bool bResult(sal_False);
112 	if (pDrawPages)
113 	{
114 		if ((*pDrawPages)[nTable].bHasForms)
115 		{
116 			bResult = sal_True;
117 			xDrawPage = (*pDrawPages)[nTable].xDrawPage;
118 		}
119 	}
120 	return bResult;
121 }
122 
123 void ScMySharedData::AddNewShape(const ScMyShape& aMyShape)
124 {
125 	if (!pShapesContainer)
126 		pShapesContainer = new ScMyShapesContainer();
127 	pShapesContainer->AddNewShape(aMyShape);
128 }
129 
130 void ScMySharedData::SortShapesContainer()
131 {
132 	if (pShapesContainer)
133 		pShapesContainer->Sort();
134 }
135 
136 sal_Bool ScMySharedData::HasShapes()
137 {
138 	return ((pShapesContainer && pShapesContainer->HasShapes()) ||
139 			(pTableShapes && !pTableShapes->empty()));
140 }
141 
142 void ScMySharedData::AddTableShape(const sal_Int32 nTable, const uno::Reference<drawing::XShape>& xShape)
143 {
144 	if (!pTableShapes)
145 		pTableShapes = new ScMyTableShapes(nTableCount);
146 	(*pTableShapes)[nTable].push_back(xShape);
147 }
148 
149 void ScMySharedData::AddNoteObj(const uno::Reference<drawing::XShape>& xShape, const ScAddress& rPos)
150 {
151     if (!pNoteShapes)
152         pNoteShapes = new ScMyNoteShapesContainer();
153     ScMyNoteShape aNote;
154     aNote.xShape = xShape;
155     aNote.aPos = rPos;
156     pNoteShapes->AddNewNote(aNote);
157 }
158 
159 void ScMySharedData::SortNoteShapes()
160 {
161     if (pNoteShapes)
162         pNoteShapes->Sort();
163 }
164