Use correct object
[LibreOffice.git] / include / xmloff / txtimp.hxx
blobc04e577c6573db9feb6c870fea597b86f2ec6464
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 .
19 #ifndef INCLUDED_XMLOFF_TXTIMP_HXX
20 #define INCLUDED_XMLOFF_TXTIMP_HXX
22 #include <sal/config.h>
23 #include <xmloff/dllapi.h>
24 #include <sal/types.h>
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/uno/Sequence.hxx>
29 #include <map>
30 #include <memory>
32 #include <salhelper/simplereferenceobject.hxx>
34 class XMLTextListsHelper;
35 class SvXMLImportContext;
36 class SvXMLTokenMap;
37 class SvXMLImportPropertyMapper;
38 class SvXMLImport;
39 class SvXMLStylesContext;
40 class SvxXMLListStyleContext;
41 class XMLPropStyleContext;
42 class SvI18NMap;
43 template<class A> class XMLPropertyBackpatcher;
44 class XMLEventsImportContext;
46 namespace xmloff {
47 struct ParsedRDFaAttributes;
50 namespace com::sun::star {
51 namespace text {
52 class XText;
53 class XTextCursor;
54 class XTextRange;
55 class XTextContent;
56 class XFormField;
58 namespace frame { class XModel; }
59 namespace container { class XNameContainer; class XIndexReplace; }
60 namespace beans { class XPropertySet; }
61 namespace xml::sax { class XAttributeList; }
62 namespace xml::sax { class XFastAttributeList; }
63 namespace util { struct DateTime; }
66 namespace rtl { template <class reference_type> class Reference; }
68 enum XMLTextType
70 Body,
71 Cell,
72 Shape,
73 TextBox,
74 HeaderFooter,
75 Section,
76 Footnote,
77 ChangedRegion
80 /// variable type (for XMLSetVarFieldImportContext)
81 enum VarType
83 VarTypeSimple,
84 VarTypeUserField,
85 VarTypeSequence
86 // see following NOTE!
89 // NOTE: these values must be distinct from any in "enum VarType" because they
90 // are used as keys to SvI18NMap::Add()
91 #define XML_TEXT_RENAME_TYPE_FRAME 10
92 #define XML_TEXT_RENAME_TYPE_TABLE 20
94 class XMLOFF_DLLPUBLIC XMLTextImportHelper : public salhelper::SimpleReferenceObject
96 private:
97 XMLTextImportHelper(const XMLTextImportHelper&) = delete;
98 XMLTextImportHelper& operator=(const XMLTextImportHelper&) = delete;
100 struct Impl;
101 std::unique_ptr<Impl> m_xImpl;
102 /// ugly, but implementation of this is in XMLPropertyBackpatcher.cxx
103 struct BackpatcherImpl;
104 std::shared_ptr<BackpatcherImpl> m_xBackpatcherImpl;
105 static std::shared_ptr<BackpatcherImpl> MakeBackpatcherImpl();
107 protected:
108 virtual SvXMLImportContext *CreateTableChildContext(
109 SvXMLImport& rImport,
110 sal_Int32 nElement,
111 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
113 // access, lazy initialization and destruction of backpatchers
114 // Code is implemented in XMLPropertyBackpatcher.cxx
115 inline XMLPropertyBackpatcher<sal_Int16>& GetFootnoteBP();
116 inline XMLPropertyBackpatcher<sal_Int16>& GetSequenceIdBP();
117 inline XMLPropertyBackpatcher< OUString> & GetSequenceNameBP();
119 public:
121 XMLTextImportHelper(
122 css::uno::Reference< css::frame::XModel > const& rModel,
123 SvXMLImport& rImport,
124 bool const bInsertMode = false, bool const bStylesOnlyMode = false,
125 bool const bProgress = false, bool const bBlockMode = false,
126 bool const bOrganizerMode = false);
128 virtual ~XMLTextImportHelper() override;
130 void dispose();
132 void SetCursor(
133 const css::uno::Reference< css::text::XTextCursor >& rCursor );
134 void ResetCursor();
136 void SetAutoStyles( SvXMLStylesContext *pStyles );
138 SvXMLImportContext *CreateTextChildContext(
139 SvXMLImport& rImport,
140 sal_Int32 nElement,
141 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
142 XMLTextType eType = XMLTextType::Shape );
144 css::uno::Reference< css::text::XText > & GetText();
145 css::uno::Reference< css::text::XTextCursor > & GetCursor();
146 css::uno::Reference< css::text::XTextRange > & GetCursorAsRange();
148 bool IsInsertMode() const;
149 bool IsStylesOnlyMode() const;
150 bool IsBlockMode() const;
151 bool IsOrganizerMode() const;
152 bool IsProgress() const;
154 OUString ConvertStarFonts( const OUString& rChars,
155 const OUString& rStyleName,
156 sal_uInt8& rFlags,
157 bool bPara,
158 SvXMLImport& rImport ) const;
159 // insert a string without special whitespace processing enabled
160 void InsertString( const OUString& rChars );
161 // insert a string with special whitespace processing enabled
162 void InsertString( std::u16string_view rChars,
163 bool& rIgnoreLeadingSpace );
164 // Delete current paragraph
165 void DeleteParagraph();
167 void InsertControlCharacter( sal_Int16 nControl );
168 void InsertTextContent( css::uno::Reference< css::text::XTextContent > const & xContent);
170 // Add parameter <bOutlineLevelAttrFound> (#i73509#)
171 // Add parameter <bSetListAttrs> in order to suppress the handling of the list attributes (#i80724#)
172 OUString SetStyleAndAttrs(
173 SvXMLImport & rImport,
174 const css::uno::Reference< css::text::XTextCursor >& rCursor,
175 const OUString& rStyleName,
176 bool bPara,
177 bool bOutlineLevelAttrFound = false,
178 sal_Int8 nOutlineLevel = -1,
179 bool bSetListAttrs = true,
180 bool bOutlineContentVisible = true);
182 /** Find a suitable name for the given outline level.
183 * If rStyleName is empty, change it to a previously used or default style
184 * name for that level. Otherwise, leave rStyleName unmodified.
186 // Adjust 2nd parameter (#i69629#)
187 void FindOutlineStyleName( OUString& rStyleName,
188 sal_Int8 nOutlineLevel );
190 // Change method name to reflect change of data structure (#i69629#)
191 void AddOutlineStyleCandidate( const sal_Int8 nOutlineLevel,
192 const OUString& rStyleName );
194 void SetOutlineStyles( bool bSetEmpty );
196 void SetHyperlink(
197 SvXMLImport const & rImport,
198 const css::uno::Reference< css::text::XTextCursor >& rCursor,
199 const OUString& rHRef,
200 const OUString& rName,
201 const OUString& rTargetFrameName,
202 const OUString& rStyleName,
203 const OUString& rVisitedStyleName,
204 XMLEventsImportContext* pEvents);
205 void SetRuby(
206 SvXMLImport const & rImport,
207 const css::uno::Reference< css::text::XTextCursor >& rCursor,
208 const OUString& rStyleName,
209 const OUString& rTextStyleName,
210 const OUString& rText );
212 /// return key appropriate for use with NumberFormat property
213 /// return -1 if style is not found
214 /// (may return whether data style uses the system language)
215 sal_Int32 GetDataStyleKey( const OUString& sStyleName,
216 bool* pIsSystemLanguage = nullptr );
218 const SvxXMLListStyleContext *FindAutoListStyle(
219 const OUString& rName ) const;
220 XMLPropStyleContext *FindAutoFrameStyle(
221 const OUString& rName ) const;
222 XMLPropStyleContext* FindSectionStyle(
223 const OUString& rName ) const;
224 XMLPropStyleContext* FindPageMaster(
225 const OUString& rName ) const;
226 XMLPropStyleContext* FindAutoCharStyle(const OUString& rName) const;
228 XMLPropStyleContext* FindDrawingPage(OUString const& rName) const;
230 const css::uno::Reference< css::container::XNameContainer> & GetParaStyles() const;
232 const css::uno::Reference< css::container::XNameContainer> & GetTextStyles() const;
234 const css::uno::Reference< css::container::XNameContainer> &
235 GetNumberingStyles() const;
237 const css::uno::Reference< css::container::XNameContainer> & GetFrameStyles() const;
239 const css::uno::Reference< css::container::XNameContainer> & GetPageStyles() const;
241 const css::uno::Reference< css::container::XNameContainer> & GetCellStyles() const;
243 const css::uno::Reference< css::container::XIndexReplace > &
244 GetChapterNumbering() const;
246 bool HasFrameByName( const OUString& rName ) const;
248 bool IsDuplicateFrame(const OUString& sName, sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight) const;
249 void StoreLastImportedFrameName(const OUString& rName);
250 void ClearLastImportedTextFrameName();
252 void ConnectFrameChains( const OUString& rFrmName,
253 const OUString& rNextFrmName,
254 const css::uno::Reference< css::beans::XPropertySet >& rFrmPropSet );
256 rtl::Reference< SvXMLImportPropertyMapper > const&
257 GetParaImportPropertySetMapper() const;
258 rtl::Reference< SvXMLImportPropertyMapper > const&
259 GetTextImportPropertySetMapper() const;
260 rtl::Reference< SvXMLImportPropertyMapper > const&
261 GetSectionImportPropertySetMapper() const;
262 rtl::Reference< SvXMLImportPropertyMapper > const&
263 GetRubyImportPropertySetMapper() const;
265 static SvXMLImportPropertyMapper *CreateShapeExtPropMapper(SvXMLImport&);
266 static SvXMLImportPropertyMapper *CreateParaExtPropMapper(SvXMLImport&);
267 static SvXMLImportPropertyMapper* CreateParaDefaultExtPropMapper(SvXMLImport&);
268 static SvXMLImportPropertyMapper* CreateTableDefaultExtPropMapper(SvXMLImport&);
269 static SvXMLImportPropertyMapper* CreateTableRowDefaultExtPropMapper(SvXMLImport&);
270 static SvXMLImportPropertyMapper* CreateTableCellExtPropMapper(SvXMLImport&);
271 static SvXMLImportPropertyMapper* CreateDrawingPageExtPropMapper(SvXMLImport&);
273 SvI18NMap& GetRenameMap();
275 /// save the start of a range reference
276 void InsertBookmarkStartRange(
277 const OUString & sName,
278 const css::uno::Reference< css::text::XTextRange> & rRange,
279 OUString const& i_rXmlId,
280 std::shared_ptr< ::xmloff::ParsedRDFaAttributes > &
281 i_rpRDFaAttributes);
283 /// process the start of a range reference
284 bool FindAndRemoveBookmarkStartRange(
285 const OUString & sName,
286 css::uno::Reference< css::text::XTextRange> & o_rRange,
287 OUString & o_rXmlId,
288 std::shared_ptr< ::xmloff::ParsedRDFaAttributes > & o_rpRDFaAttributes);
290 void pushFieldCtx( const OUString& name, const OUString& type );
291 css::uno::Reference<css::text::XFormField> popFieldCtx();
292 void addFieldParam( const OUString& name, const OUString& value );
293 void setCurrentFieldParamsTo(css::uno::Reference< css::text::XFormField> const &xFormField);
294 ::std::pair<OUString, OUString> getCurrentFieldType() const;
295 css::uno::Reference<css::text::XTextRange> getCurrentFieldStart() const;
296 bool hasCurrentFieldSeparator() const;
297 bool hasCurrentFieldCtx() const;
300 /// insert new footnote ID.
301 /// Also fixup open references from the backpatch list to this ID.
302 // Code is implemented in XMLPropertyBackpatcher.cxx
303 void InsertFootnoteID(const OUString& sXMLId, sal_Int16 nAPIId);
305 /// set the proper footnote reference ID,
306 /// or put into backpatch list if ID is unknown
307 // Code is implemented in XMLPropertyBackpatcher.cxx
308 void ProcessFootnoteReference(
309 const OUString& sXMLId,
310 const css::uno::Reference< css::beans::XPropertySet> & xPropSet);
312 /// insert new sequence ID
313 /// Also fixup open references from backpatch list to this ID.
314 // Code is implemented in XMLPropertyBackpatcher.cxx
315 void InsertSequenceID(const OUString& sXMLId,
316 const OUString& sName,
317 sal_Int16 nAPIId);
319 /// set sequence ID or insert into backpatch list
320 // Code is implemented in XMLPropertyBackpatcher.cxx
321 void ProcessSequenceReference(
322 const OUString& sXMLId,
323 const css::uno::Reference< css::beans::XPropertySet> & xPropSet);
325 bool IsInFrame() const;
326 virtual bool IsInHeaderFooter() const;
328 virtual css::uno::Reference< css::beans::XPropertySet>
329 createAndInsertOLEObject( SvXMLImport& rImport,
330 const OUString& rHRef,
331 const OUString &rStyleName,
332 const OUString &rTblName,
333 sal_Int32 nWidth, sal_Int32 nHeight );
335 virtual css::uno::Reference< css::beans::XPropertySet>
336 createAndInsertOOoLink( SvXMLImport& rImport,
337 const OUString& rHRef,
338 const OUString &rStyleName,
339 const OUString &rTblName,
340 sal_Int32 nWidth, sal_Int32 nHeight );
342 virtual css::uno::Reference< css::beans::XPropertySet>
343 createAndInsertApplet(
344 const OUString &rName,
345 const OUString &rCode,
346 bool bMayScript,
347 const OUString& rHRef,
348 sal_Int32 nWidth, sal_Int32 nHeight );
350 virtual css::uno::Reference< css::beans::XPropertySet>
351 createAndInsertPlugin(
352 const OUString &rMimeType,
353 const OUString& rHRef,
354 sal_Int32 nWidth, sal_Int32 nHeight );
356 virtual css::uno::Reference< css::beans::XPropertySet>
357 createAndInsertFloatingFrame(
358 const OUString &rName,
359 const OUString &rHRef,
360 const OUString &rStyleName,
361 sal_Int32 nWidth, sal_Int32 nHeight );
363 virtual void endAppletOrPlugin(
364 const css::uno::Reference< css::beans::XPropertySet> &rPropSet,
365 ::std::map < const OUString, OUString > &rParamMap );
367 // applet helper methods
368 // implemented in sw/filter/xml/txtparai.hxx
370 // redlining helper methods
371 // (to be implemented in sw/filter/xml/txtparai.hxx)
373 virtual void RedlineAdd(
374 /// redline type (insert, del,... )
375 const OUString& rType,
376 /// use to identify this redline
377 const OUString& rId,
378 /// name of the author
379 const OUString& rAuthor,
380 /// redline comment
381 const OUString& rComment,
382 /// date+time
383 const css::util::DateTime& rDateTime,
384 /// move id, to find other parts (moveFrom/MoveTo)
385 const OUString& rMoveId,
386 /// merge last paras
387 bool bMergeLastParagraph);
389 virtual css::uno::Reference< css::text::XTextCursor> RedlineCreateText(
390 /// needed to get the document
391 css::uno::Reference< css::text::XTextCursor > & rOldCursor,
392 /// ID used to RedlineAdd() call
393 const OUString& rId);
395 virtual void RedlineSetCursor(
396 /// ID used to RedlineAdd() call
397 const OUString& rId,
398 /// start or end Cursor
399 bool bStart,
400 /// range is not within <text:p>
401 bool bIsOutsideOfParagraph);
403 virtual void RedlineAdjustStartNodeCursor();
404 virtual void SetShowChanges( bool bShowChanges );
405 virtual void SetRecordChanges( bool bRecordChanges );
406 virtual void SetChangesProtectionKey(
407 const css::uno::Sequence<sal_Int8> & rProtectionKey );
409 /// get the last open redline ID
410 OUString const & GetOpenRedlineId() const;
411 /// modify the last open redline ID
412 void SetOpenRedlineId( OUString const & rId);
413 /// reset the last open redline ID
414 void ResetOpenRedlineId();
416 /** redlining : Setter to remember the fact we are inside/outside
417 * a <text:deletion> element (deleted redline section) */
418 void SetInsideDeleteContext(bool const bNew);
419 /** redlining : Getter to know if we are inside
420 * a <text:deletion> element (deleted redline section) */
421 bool IsInsideDeleteContext() const;
423 SvXMLImport & GetXMLImport();
425 XMLTextListsHelper & GetTextListHelper();
427 // forwards to TextListHelper; these are used in many places
428 /// push a list context on the list context stack
429 void PushListContext();
430 /// pop the list context stack
431 void PopListContext();
433 void SetCellParaStyleDefault(OUString const& rNewValue);
434 OUString const& GetCellParaStyleDefault() const;
436 void AddCrossRefHeadingMapping(OUString const& rFrom, OUString const& rTo);
437 void MapCrossRefHeadingFieldsHorribly();
439 void setBookmarkAttributes(OUString const& bookmark, bool hidden, OUString const& condition);
440 bool getBookmarkHidden(OUString const& bookmark) const;
441 const OUString& getBookmarkCondition(OUString const& bookmark) const;
445 #endif
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */