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_sc.hxx"
26 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 #include "XMLColumnRowGroupExport.hxx"
31 #include "xmlexprt.hxx"
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmlnmspe.hxx>
35 
36 #include <algorithm>
37 
38 using namespace xmloff::token;
39 
ScMyColumnRowGroup()40 ScMyColumnRowGroup::ScMyColumnRowGroup()
41 {
42 }
43 
operator <(const ScMyColumnRowGroup & rGroup) const44 sal_Bool ScMyColumnRowGroup::operator<(const ScMyColumnRowGroup& rGroup) const
45 {
46 	if (rGroup.nField > nField)
47 		return sal_True;
48 	else
49 		if (rGroup.nField == nField && rGroup.nLevel > nLevel)
50 			return sal_True;
51 		else
52 			return sal_False;
53 }
54 
ScMyOpenCloseColumnRowGroup(ScXMLExport & rTempExport,sal_uInt32 nToken)55 ScMyOpenCloseColumnRowGroup::ScMyOpenCloseColumnRowGroup(ScXMLExport& rTempExport, sal_uInt32 nToken)
56 	: rExport(rTempExport),
57 	rName(rExport.GetNamespaceMap().GetQNameByKey(XML_NAMESPACE_TABLE, GetXMLToken(XMLTokenEnum(nToken)))),
58 	aTableStart(),
59 	aTableEnd()
60 {
61 }
62 
~ScMyOpenCloseColumnRowGroup()63 ScMyOpenCloseColumnRowGroup::~ScMyOpenCloseColumnRowGroup()
64 {
65 }
66 
NewTable()67 void ScMyOpenCloseColumnRowGroup::NewTable()
68 {
69 	aTableStart.clear();
70 	aTableEnd.clear();
71 }
72 
AddGroup(const ScMyColumnRowGroup & aGroup,const sal_Int32 nEndField)73 void ScMyOpenCloseColumnRowGroup::AddGroup(const ScMyColumnRowGroup& aGroup, const sal_Int32 nEndField)
74 {
75 	aTableStart.push_back(aGroup);
76 	aTableEnd.push_back(nEndField);
77 }
78 
IsGroupStart(const sal_Int32 nField)79 sal_Bool ScMyOpenCloseColumnRowGroup::IsGroupStart(const sal_Int32 nField)
80 {
81 	sal_Bool bGroupStart(sal_False);
82 	if (!aTableStart.empty())
83 	{
84 		ScMyColumnRowGroupVec::iterator aItr(aTableStart.begin());
85 		sal_Int32 nItrField = aItr->nField;
86 		if ( nItrField < nField )
87 		{
88 			//	#103327# when used to find repeated rows at the beginning of a group,
89 			//	aTableStart may contain entries before nField. They must be skipped here
90 			//	(they will be used for OpenGroups later in the right order).
91 
92 			ScMyColumnRowGroupVec::iterator aEnd(aTableStart.end());
93 			while ( aItr != aEnd && nItrField < nField )
94 			{
95 				++aItr;
96 				if ( aItr != aEnd )
97 					nItrField = aItr->nField;
98 			}
99 		}
100 
101 		if (nItrField == nField)
102 			bGroupStart = sal_True;
103 	}
104 	return bGroupStart;
105 }
106 
OpenGroup(const ScMyColumnRowGroup & rGroup)107 void ScMyOpenCloseColumnRowGroup::OpenGroup(const ScMyColumnRowGroup& rGroup)
108 {
109 	if (!rGroup.bDisplay)
110 		rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
111 	rExport.StartElement( rName, sal_True);
112 }
113 
OpenGroups(const sal_Int32 nField)114 void ScMyOpenCloseColumnRowGroup::OpenGroups(const sal_Int32 nField)
115 {
116 	ScMyColumnRowGroupVec::iterator aItr(aTableStart.begin());
117 	ScMyColumnRowGroupVec::iterator aEndItr(aTableStart.end());
118 	sal_Bool bReady(sal_False);
119 	while(!bReady && aItr != aEndItr)
120 	{
121 		if (aItr->nField == nField)
122 		{
123 			OpenGroup(*aItr);
124 			aItr = aTableStart.erase(aItr);
125 		}
126 		else
127 			bReady = sal_True;
128 	}
129 }
130 
IsGroupEnd(const sal_Int32 nField)131 sal_Bool ScMyOpenCloseColumnRowGroup::IsGroupEnd(const sal_Int32 nField)
132 {
133 	sal_Bool bGroupEnd(sal_False);
134 	if (!aTableEnd.empty())
135 	{
136 		if (*(aTableEnd.begin()) == nField)
137 			bGroupEnd = sal_True;
138 	}
139 	return bGroupEnd;
140 }
141 
CloseGroup()142 void ScMyOpenCloseColumnRowGroup::CloseGroup()
143 {
144 	rExport.EndElement( rName, sal_True );
145 }
146 
CloseGroups(const sal_Int32 nField)147 void ScMyOpenCloseColumnRowGroup::CloseGroups(const sal_Int32 nField)
148 {
149 	ScMyFieldGroupVec::iterator aItr(aTableEnd.begin());
150 	ScMyFieldGroupVec::iterator aEndItr(aTableEnd.end());
151 	sal_Bool bReady(sal_False);
152 	while(!bReady && aItr != aEndItr)
153 	{
154 		if (*aItr == nField)
155 		{
156 			CloseGroup();
157 			aItr = aTableEnd.erase(aItr);
158 		}
159 		else
160 			bReady = sal_True;
161 	}
162 }
163 
GetLast()164 sal_Int32 ScMyOpenCloseColumnRowGroup::GetLast()
165 {
166 	sal_Int32 maximum(-1);
167     ScMyFieldGroupVec::iterator i(aTableEnd.begin());
168     ScMyFieldGroupVec::iterator endi(aTableEnd.end());
169 	while (i != endi)
170     {
171 		if (*i > maximum)
172 			maximum = *i;
173         ++i;
174     }
175 	return maximum;
176 }
177 
Sort()178 void ScMyOpenCloseColumnRowGroup::Sort()
179 {
180 	aTableStart.sort();
181 	aTableEnd.sort();
182 }
183 
184