Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* SectionStyle: Stores (and writes) section-based information (e.g.: a column
3 : * break needs a new section) that is needed at the head of an OO document and
4 : * is referenced throughout the entire document
5 : *
6 : * This Source Code Form is subject to the terms of the Mozilla Public
7 : * License, v. 2.0. If a copy of the MPL was not distributed with this
8 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 : *
10 : * For further information visit http://libwpd.sourceforge.net
11 : */
12 :
13 : /* "This product is not manufactured, approved, or supported by
14 : * Corel Corporation or Corel Corporation Limited."
15 : */
16 : #include "FilterInternal.hxx"
17 : #include "PageSpan.hxx"
18 : #include "DocumentElement.hxx"
19 :
20 0 : PageSpan::PageSpan(const WPXPropertyList &xPropList) :
21 : mxPropList(xPropList),
22 : mpHeaderContent(0),
23 : mpFooterContent(0),
24 : mpHeaderLeftContent(0),
25 0 : mpFooterLeftContent(0)
26 : {
27 0 : }
28 :
29 : namespace
30 : {
31 : typedef std::vector<DocumentElement *>::iterator DEVIter;
32 : }
33 :
34 0 : PageSpan::~PageSpan()
35 : {
36 0 : if (mpHeaderContent)
37 : {
38 0 : for (DEVIter iterHeaderContent = mpHeaderContent->begin();
39 0 : iterHeaderContent != mpHeaderContent->end();
40 : ++iterHeaderContent)
41 0 : delete(*iterHeaderContent);
42 0 : delete mpHeaderContent;
43 : }
44 :
45 0 : if (mpHeaderLeftContent)
46 : {
47 0 : for (DEVIter iterHeaderLeftContent = mpHeaderLeftContent->begin();
48 0 : iterHeaderLeftContent != mpHeaderLeftContent->end();
49 : ++iterHeaderLeftContent)
50 0 : delete(*iterHeaderLeftContent);
51 0 : delete mpHeaderLeftContent;
52 : }
53 :
54 0 : if (mpFooterContent)
55 : {
56 0 : for (DEVIter iterFooterContent = mpFooterContent->begin();
57 0 : iterFooterContent != mpFooterContent->end();
58 : ++iterFooterContent)
59 0 : delete(*iterFooterContent);
60 0 : delete mpFooterContent;
61 : }
62 :
63 0 : if (mpFooterLeftContent)
64 : {
65 0 : for (DEVIter iterFooterLeftContent = mpFooterLeftContent->begin();
66 0 : iterFooterLeftContent != mpFooterLeftContent->end();
67 : ++iterFooterLeftContent)
68 0 : delete(*iterFooterLeftContent);
69 0 : delete mpFooterLeftContent;
70 : }
71 0 : }
72 :
73 0 : int PageSpan::getSpan() const
74 : {
75 0 : if (mxPropList["libwpd:num-pages"])
76 0 : return mxPropList["libwpd:num-pages"]->getInt();
77 :
78 0 : return 0; // should never happen
79 : }
80 :
81 0 : void PageSpan::setHeaderContent(std::vector<DocumentElement *> * pHeaderContent)
82 : {
83 0 : if (mpHeaderContent)
84 : {
85 0 : for (DEVIter iterHeaderContent = mpHeaderContent->begin();
86 0 : iterHeaderContent != mpHeaderContent->end();
87 : ++iterHeaderContent)
88 0 : delete(*iterHeaderContent);
89 0 : delete mpHeaderContent;
90 : }
91 :
92 0 : mpHeaderContent = pHeaderContent;
93 0 : }
94 :
95 0 : void PageSpan::setFooterContent(std::vector<DocumentElement *> * pFooterContent)
96 : {
97 0 : if (mpFooterContent)
98 : {
99 0 : for (DEVIter iterFooterContent = mpFooterContent->begin();
100 0 : iterFooterContent != mpFooterContent->end();
101 : ++iterFooterContent)
102 0 : delete(*iterFooterContent);
103 0 : delete mpFooterContent;
104 : }
105 :
106 0 : mpFooterContent = pFooterContent;
107 0 : }
108 :
109 0 : void PageSpan::setHeaderLeftContent(std::vector<DocumentElement *> * pHeaderContent)
110 : {
111 0 : if (mpHeaderLeftContent)
112 : {
113 0 : for (DEVIter iterHeaderLeftContent = mpHeaderLeftContent->begin();
114 0 : iterHeaderLeftContent != mpHeaderLeftContent->end();
115 : ++iterHeaderLeftContent)
116 0 : delete(*iterHeaderLeftContent);
117 0 : delete mpHeaderLeftContent;
118 : }
119 :
120 0 : mpHeaderLeftContent = pHeaderContent;
121 0 : }
122 :
123 0 : void PageSpan::setFooterLeftContent(std::vector<DocumentElement *> * pFooterContent)
124 : {
125 0 : if (mpFooterLeftContent)
126 : {
127 0 : for (DEVIter iterFooterLeftContent = mpFooterLeftContent->begin();
128 0 : iterFooterLeftContent != mpFooterLeftContent->end();
129 : ++iterFooterLeftContent)
130 0 : delete(*iterFooterLeftContent);
131 0 : delete mpFooterLeftContent;
132 : }
133 :
134 0 : mpFooterLeftContent = pFooterContent;
135 0 : }
136 :
137 0 : void PageSpan::writePageLayout(const int iNum, OdfDocumentHandler *pHandler) const
138 : {
139 0 : WPXPropertyList propList;
140 :
141 0 : WPXString sPageLayoutName;
142 0 : sPageLayoutName.sprintf("PM%i", iNum+2);
143 0 : propList.insert("style:name", sPageLayoutName);
144 0 : pHandler->startElement("style:page-layout", propList);
145 :
146 0 : WPXPropertyList tempPropList = mxPropList;
147 0 : if (!tempPropList["style:writing-mode"])
148 0 : tempPropList.insert("style:writing-mode", WPXString("lr-tb"));
149 0 : if (!tempPropList["style:footnote-max-height"])
150 0 : tempPropList.insert("style:footnote-max-height", WPXString("0in"));
151 0 : pHandler->startElement("style:page-layout-properties", tempPropList);
152 :
153 0 : WPXPropertyList footnoteSepPropList;
154 0 : footnoteSepPropList.insert("style:width", WPXString("0.0071in"));
155 0 : footnoteSepPropList.insert("style:distance-before-sep", WPXString("0.0398in"));
156 0 : footnoteSepPropList.insert("style:distance-after-sep", WPXString("0.0398in"));
157 0 : footnoteSepPropList.insert("style:adjustment", WPXString("left"));
158 0 : footnoteSepPropList.insert("style:rel-width", WPXString("25%"));
159 0 : footnoteSepPropList.insert("style:color", WPXString("#000000"));
160 0 : pHandler->startElement("style:footnote-sep", footnoteSepPropList);
161 :
162 0 : pHandler->endElement("style:footnote-sep");
163 0 : pHandler->endElement("style:page-layout-properties");
164 0 : pHandler->endElement("style:page-layout");
165 0 : }
166 :
167 0 : void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum, const bool bLastPageSpan,
168 : OdfDocumentHandler *pHandler) const
169 : {
170 0 : int iSpan = 0;
171 0 : (bLastPageSpan) ? iSpan = 1 : iSpan = getSpan();
172 :
173 0 : for (int i=iStartingNum; i<(iStartingNum+iSpan); ++i)
174 : {
175 0 : TagOpenElement masterPageOpen("style:master-page");
176 0 : WPXString sMasterPageName, sMasterPageDisplayName;
177 0 : sMasterPageName.sprintf("Page_Style_%i", i);
178 0 : sMasterPageDisplayName.sprintf("Page Style %i", i);
179 0 : WPXString sPageLayoutName;
180 0 : WPXPropertyList propList;
181 0 : sPageLayoutName.sprintf("PM%i", iPageLayoutNum+2);
182 0 : propList.insert("style:name", sMasterPageName);
183 0 : propList.insert("style:display-name", sMasterPageDisplayName);
184 0 : propList.insert("style:page-layout-name", sPageLayoutName);
185 0 : if (!bLastPageSpan)
186 : {
187 0 : WPXString sNextMasterPageName;
188 0 : sNextMasterPageName.sprintf("Page_Style_%i", (i+1));
189 0 : propList.insert("style:next-style-name", sNextMasterPageName);
190 : }
191 0 : pHandler->startElement("style:master-page", propList);
192 :
193 0 : if (mpHeaderContent)
194 : {
195 0 : _writeHeaderFooter("style:header", *mpHeaderContent, pHandler);
196 0 : pHandler->endElement("style:header");
197 0 : if (mpHeaderLeftContent)
198 : {
199 0 : _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler);
200 0 : pHandler->endElement("style:header-left");
201 : }
202 : }
203 0 : else if (mpHeaderLeftContent)
204 : {
205 0 : TagOpenElement("style:header").write(pHandler);
206 0 : pHandler->endElement("style:header");
207 0 : _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler);
208 0 : pHandler->endElement("style:header-left");
209 : }
210 :
211 0 : if (mpFooterContent)
212 : {
213 0 : _writeHeaderFooter("style:footer", *mpFooterContent, pHandler);
214 0 : pHandler->endElement("style:footer");
215 0 : if (mpFooterLeftContent)
216 : {
217 0 : _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler);
218 0 : pHandler->endElement("style:footer-left");
219 : }
220 : }
221 0 : else if (mpFooterLeftContent)
222 : {
223 0 : TagOpenElement("style:footer").write(pHandler);
224 0 : pHandler->endElement("style:footer");
225 0 : _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler);
226 0 : pHandler->endElement("style:footer-left");
227 : }
228 :
229 0 : pHandler->endElement("style:master-page");
230 0 : }
231 0 : }
232 :
233 0 : void PageSpan::_writeHeaderFooter(const char *headerFooterTagName,
234 : const std::vector<DocumentElement *> & headerFooterContent,
235 : OdfDocumentHandler *pHandler) const
236 : {
237 0 : TagOpenElement headerFooterOpen(headerFooterTagName);
238 0 : headerFooterOpen.write(pHandler);
239 0 : for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin();
240 0 : iter != headerFooterContent.end();
241 : ++iter)
242 : {
243 0 : (*iter)->write(pHandler);
244 0 : }
245 0 : }
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|