lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / writerfilter / source / ooxml / Handler.cxx
blob290a4b7497580e7b375bc6d9981b4e78000b2d0c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ooxml/resourceids.hxx>
21 #include "Handler.hxx"
23 #include <sal/log.hxx>
25 namespace writerfilter {
26 namespace ooxml
30 class OOXMLFootnoteHandler
32 OOXMLFootnoteHandler::OOXMLFootnoteHandler(OOXMLFastContextHandler * pContext)
33 : mpFastContext(pContext)
37 OOXMLFootnoteHandler::~OOXMLFootnoteHandler()
41 void OOXMLFootnoteHandler::attribute(Id name, Value & val)
43 switch (name)
45 case NS_ooxml::LN_CT_FtnEdnRef_id:
46 mpFastContext->resolveFootnote(sal_Int32(val.getInt()));
47 break;
48 default:
49 break;
53 void OOXMLFootnoteHandler::sprm(Sprm & /*sprm*/)
58 class OOXMLEndnoteHandler
60 OOXMLEndnoteHandler::OOXMLEndnoteHandler(OOXMLFastContextHandler * pContext)
61 : mpFastContext(pContext)
65 OOXMLEndnoteHandler::~OOXMLEndnoteHandler()
69 void OOXMLEndnoteHandler::attribute(Id name, Value & val)
71 switch (name)
73 case NS_ooxml::LN_CT_FtnEdnRef_id:
74 mpFastContext->resolveEndnote(sal_Int32(val.getInt()));
75 break;
76 default:
77 break;
81 void OOXMLEndnoteHandler::sprm(Sprm & /*sprm*/)
86 class OOXMLCommentHandler
88 OOXMLCommentHandler::OOXMLCommentHandler(OOXMLFastContextHandler * pContext)
89 : mpFastContext(pContext)
93 OOXMLCommentHandler::~OOXMLCommentHandler()
97 void OOXMLCommentHandler::attribute(Id name, Value & val)
99 switch (name)
101 case NS_ooxml::LN_CT_Markup_id:
102 mpFastContext->resolveComment(val.getInt());
103 break;
104 default:
109 void OOXMLCommentHandler::sprm(Sprm & /*sprm*/)
114 class OOXMLOLEHandler
116 OOXMLOLEHandler::OOXMLOLEHandler(OOXMLFastContextHandler * pContext)
117 : mpFastContext(pContext)
121 OOXMLOLEHandler::~OOXMLOLEHandler()
125 void OOXMLOLEHandler::attribute(Id name, Value & val)
127 switch (name)
129 case NS_ooxml::LN_CT_OLEObject_r_id:
130 try {
131 mpFastContext->resolveData(val.getString());
133 catch (const ::css::uno::Exception&)
135 // Can't resolve OLE stream
136 SAL_WARN("writerfilter.ooxml", "Failed to open OLE stream!");
138 break;
139 default:
144 void OOXMLOLEHandler::sprm(Sprm & /*sprm*/)
148 OOXMLEmbeddedFontHandler::OOXMLEmbeddedFontHandler(OOXMLFastContextHandler * pContext)
149 : mpFastContext(pContext)
153 OOXMLEmbeddedFontHandler::~OOXMLEmbeddedFontHandler()
157 void OOXMLEmbeddedFontHandler::attribute(Id name, Value & val)
159 switch (name)
161 case NS_ooxml::LN_CT_Rel_id:
162 mpFastContext->resolveData(val.getString());
163 break;
164 default:
165 break;
169 void OOXMLEmbeddedFontHandler::sprm(Sprm & /*sprm*/)
174 class OOXMLFooterHandler
176 OOXMLFooterHandler::OOXMLFooterHandler(OOXMLFastContextHandler * pContext)
177 : mpFastContext(pContext), msStreamId(), mnType(0)
181 void OOXMLFooterHandler::finalize()
183 mpFastContext->resolveFooter(mnType, msStreamId);
186 void OOXMLFooterHandler::attribute(Id name, Value & val)
188 switch (name)
190 case NS_ooxml::LN_CT_HdrFtrRef_id:
191 msStreamId = val.getString();
192 break;
193 case NS_ooxml::LN_CT_HdrFtrRef_type:
194 mnType = val.getInt();
195 break;
196 default:
197 break;
201 void OOXMLFooterHandler::sprm(Sprm & /*sprm*/)
206 class OOXMLHeaderHandler
208 OOXMLHeaderHandler::OOXMLHeaderHandler(OOXMLFastContextHandler * pContext)
209 : mpFastContext(pContext), msStreamId(), mnType(0)
213 void OOXMLHeaderHandler::finalize()
215 mpFastContext->resolveHeader(mnType, msStreamId);
218 void OOXMLHeaderHandler::attribute(Id name, Value & val)
220 switch (name)
222 case NS_ooxml::LN_CT_HdrFtrRef_id:
223 msStreamId = val.getString();
224 break;
225 case NS_ooxml::LN_CT_HdrFtrRef_type:
226 mnType = val.getInt();
227 break;
228 default:
229 break;
233 void OOXMLHeaderHandler::sprm(Sprm & /*sprm*/)
238 class OOXMLBreakHandler
240 OOXMLBreakHandler::OOXMLBreakHandler(Stream &rStream)
241 : mnType(0), mnClear(0),
242 mrStream(rStream)
246 OOXMLBreakHandler::~OOXMLBreakHandler()
248 sal_uInt8 tmpBreak[1];
249 switch (mnType)
251 case NS_ooxml::LN_Value_ST_BrType_column:
252 tmpBreak[0] = 0x0E;
253 break;
254 case NS_ooxml::LN_Value_ST_BrType_page:
255 tmpBreak[0] = 0x0C;
256 break;
257 case NS_ooxml::LN_Value_ST_BrType_textWrapping:
258 default: // when no attribute type is present, the spec assume textWrapping
259 tmpBreak[0] = 0x0A;
260 break;
262 mrStream.text(&tmpBreak[0], 1);
265 void OOXMLBreakHandler::attribute(Id name, Value & val)
267 switch (name)
269 case NS_ooxml::LN_CT_Br_type:
270 mnType = val.getInt();
271 break;
272 case NS_ooxml::LN_CT_Br_clear:
273 mnClear = val.getInt();
274 break;
275 default:
276 break;
280 void OOXMLBreakHandler::sprm(Sprm & /*sprm*/)
285 class OOXMLPictureHandler
287 OOXMLPictureHandler::OOXMLPictureHandler(OOXMLFastContextHandler * pContext)
288 : mpFastContext(pContext)
292 OOXMLPictureHandler::~OOXMLPictureHandler()
296 void OOXMLPictureHandler::attribute(Id name, Value & val)
298 if (name == NS_ooxml::LN_AG_Blob_r_embed)
299 mpFastContext->resolvePicture(val.getString());
300 else
302 writerfilter::Reference<Properties>::Pointer_t pProps
303 (val.getProperties());
304 if (pProps.get() != nullptr)
305 pProps->resolve(*this);
309 void OOXMLPictureHandler::sprm(Sprm & rSprm)
311 writerfilter::Reference<Properties>::Pointer_t pProps
312 (rSprm.getProps());
314 if (pProps.get() != nullptr)
315 pProps->resolve(*this);
319 class OOXMLHyperlinkHandler
322 OOXMLHyperlinkHandler::OOXMLHyperlinkHandler(OOXMLFastContextHandler * pContext)
323 : mpFastContext(pContext)
327 OOXMLHyperlinkHandler::~OOXMLHyperlinkHandler()
331 void OOXMLHyperlinkHandler::writetext()
333 OUString sReturn(" HYPERLINK \"");
335 sReturn += mURL;
336 sReturn += "\"";
337 sReturn += mFieldCode;
339 mpFastContext->text(sReturn);
342 void OOXMLHyperlinkHandler::attribute(Id name, Value & val)
344 switch (name)
346 case NS_ooxml::LN_CT_Hyperlink_tgtFrame:
347 mFieldCode += " \\t \"";
348 mFieldCode += val.getString();
349 mFieldCode += "\"";
350 break;
351 case NS_ooxml::LN_CT_Hyperlink_tooltip:
352 mFieldCode += " \\o \"";
353 mFieldCode += val.getString();
354 mFieldCode += "\"";
355 break;
356 case NS_ooxml::LN_CT_Hyperlink_docLocation:
357 break;
358 case NS_ooxml::LN_CT_Hyperlink_history:
359 break;
360 case NS_ooxml::LN_CT_Hyperlink_anchor:
361 mFieldCode += " \\l \"";
362 mFieldCode += val.getString();
363 mFieldCode += "\"";
364 break;
365 case NS_ooxml::LN_CT_Hyperlink_r_id:
366 mURL = mpFastContext->getTargetForId(val.getString());
367 break;
368 default:
369 break;
373 void OOXMLHyperlinkHandler::sprm(Sprm & /*rSprm*/)
378 class OOXMLHyperlinkURLHandler
381 OOXMLHyperlinkURLHandler::OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pContext)
382 : mpFastContext(pContext)
386 OOXMLHyperlinkURLHandler::~OOXMLHyperlinkURLHandler()
388 mpFastContext->clearProps();
389 mpFastContext->newProperty(NS_ooxml::LN_CT_Hyperlink_URL, OOXMLValue::Pointer_t(new OOXMLStringValue(mURL)));
392 void OOXMLHyperlinkURLHandler::attribute(Id name, Value & val)
394 switch (name)
396 case NS_ooxml::LN_CT_Hyperlink_URL:
397 mURL = mpFastContext->getTargetForId(val.getString());
398 break;
399 default:
400 break;
404 void OOXMLHyperlinkURLHandler::sprm(Sprm & /*rSprm*/)
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */