1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DomainMapper_Impl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef INCLUDED_DMAPPER_DOMAINMAPPER_IMPL_HXX
31 #define INCLUDED_DMAPPER_DOMAINMAPPER_IMPL_HXX
33 #include <com/sun/star/text/XTextDocument.hpp>
34 #include <com/sun/star/text/XTextCursor.hpp>
35 #include <com/sun/star/text/XTextAppend.hpp>
36 #include <com/sun/star/text/XTextAppendAndConvert.hpp>
37 #include <com/sun/star/style/TabStop.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
42 #ifndef INCLUDED_RESOURCESIDS
43 #include <doctok/resourceids.hxx>
44 #include <ooxml/resourceids.hxx>
46 #include <dmapper/DomainMapper.hxx>
47 #include <DomainMapperTableManager.hxx>
48 #include <PropertyMap.hxx>
49 #include <FontTable.hxx>
50 #include <ListTable.hxx>
51 #include <LFOTable.hxx>
52 #include <StyleSheetTable.hxx>
53 #include <ThemeTable.hxx>
54 #include <GraphicImport.hxx>
55 #include <OLEHandler.hxx>
60 namespace com
{ namespace sun
{ namespace star
{
65 class XMultiServiceFactory
;
72 namespace beans
{ class XPropertySet
;}
75 namespace writerfilter
{
78 using namespace com::sun::star
;
80 //#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
81 //sal_Int32 lcl_convertToMM100(sal_Int32 _t);
106 /*-- 14.06.2006 07:42:52---------------------------------------------------
107 property stack element
108 -----------------------------------------------------------------------*/
124 /*-----------------29.01.2007 11:47-----------------
126 * --------------------------------------------------*/
129 bool m_bFieldCommandCompleted
;
130 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> m_xStartRange
;
132 ::rtl::OUString m_sCommand
;
134 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextField
> m_xTextField
;
135 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xTOC
;//TOX
136 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xTC
;//TOX entry
137 ::rtl::OUString m_sHyperlinkURL
;
140 FieldContext(::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> xStart
);
143 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> GetStartRange() const { return m_xStartRange
; }
145 void AppendCommand(const ::rtl::OUString
& rPart
);
146 const ::rtl::OUString
& GetCommand() const {return m_sCommand
; }
148 void SetCommandCompleted() { m_bFieldCommandCompleted
= true; }
149 bool IsCommandCompleted() const { return m_bFieldCommandCompleted
; }
151 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextField
> GetTextField() const { return m_xTextField
;}
152 void SetTextField(::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextField
> xTextField
) { m_xTextField
= xTextField
;}
154 void SetTOC( ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xTOC
) { m_xTOC
= xTOC
; }
155 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> GetTOC() { return m_xTOC
; }
157 void SetTC( ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xTC
) { m_xTC
= xTC
; }
158 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> GetTC( ) { return m_xTC
; }
160 void SetHyperlinkURL( const ::rtl::OUString
& rURL
) { m_sHyperlinkURL
= rURL
; }
161 const ::rtl::OUString
& GetHyperlinkURL() { return m_sHyperlinkURL
; }
165 struct TextAppendContext
167 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextAppend
> xTextAppend
;
168 ParagraphPropertiesPtr pLastParagraphProperties
;
170 TextAppendContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextAppend
>& xAppend
) :
171 xTextAppend( xAppend
){}
174 typedef boost::shared_ptr
<FieldContext
> FieldContextPtr
;
176 typedef std::stack
<ContextType
> ContextStack
;
177 typedef std::stack
<PropertyMapPtr
> PropertyStack
;
178 typedef std::stack
< TextAppendContext
> TextAppendStack
;
179 typedef std::stack
<FieldContextPtr
> FieldStack
;
181 /*-- 18.07.2006 08:49:08---------------------------------------------------
183 -----------------------------------------------------------------------*/
186 sal_Int32 aFIBData
[ NS_rtf::LN_LCBSTTBFUSSR
- NS_rtf::LN_WIDENT
+ 1];
192 memset(&aFIBData
, 0x00, sizeof(aFIBData
));
195 sal_Int32
GetLNCHS() const {return nLNCHS
;}
196 void SetLNCHS(sal_Int32 nValue
) {nLNCHS
= nValue
;}
197 sal_Int32
GetData( Id nName
);
198 void SetData( Id nName
, sal_Int32 nValue
);
201 /*-- 17.07.2006 09:14:13---------------------------------------------------
202 extended tab stop struct
203 -----------------------------------------------------------------------*/
204 struct DeletableTabStop
: public ::com::sun::star::style::TabStop
209 DeletableTabStop( const ::com::sun::star::style::TabStop
& rTabStop
) :
213 /*-- 12.06.2007 07:15:31---------------------------------------------------
214 /// helper to remember bookmark start position
215 -----------------------------------------------------------------------*/
216 struct BookmarkInsertPosition
218 bool m_bIsStartOfText
;
219 ::rtl::OUString m_sBookmarkName
;
220 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> m_xTextRange
;
221 BookmarkInsertPosition(bool bIsStartOfText
, const ::rtl::OUString
& rName
, ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> xTextRange
):
222 m_bIsStartOfText( bIsStartOfText
),
223 m_sBookmarkName( rName
),
224 m_xTextRange( xTextRange
)
228 /*-- 03.03.2008 11:01:38---------------------------------------------------
230 -----------------------------------------------------------------------*/
231 struct LineNumberSettings
236 sal_Int32 bRestartAtEachPage
;
237 sal_Int32 nStartValue
;
238 LineNumberSettings() :
242 ,bRestartAtEachPage(true)
247 /*-- 09.06.2006 10:15:20---------------------------------------------------
249 -----------------------------------------------------------------------*/
251 class DomainMapper_Impl
254 typedef TableManager
< ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
>, PropertyMapPtr
> TableManager_t
;
255 typedef TableDataHandler
< ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
>, TablePropertyMapPtr
> TableDataHandler_t
;
256 typedef std::map
< ::rtl::OUString
, BookmarkInsertPosition
> BookmarkMap_t
;
259 SourceDocumentType m_eDocumentType
;
260 DomainMapper
& m_rDMapper
;
261 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextDocument
> m_xTextDocument
;
262 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xDocumentSettings
;
263 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xTextFactory
;
264 ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xComponentContext
;
265 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> m_xPageStyles
;
266 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> m_xBodyText
;
268 TextAppendStack m_aTextAppendStack
;
270 FieldStack m_aFieldStack
;
272 bool m_bSetUserFieldContent
;
273 bool m_bIsFirstSection
;
274 bool m_bIsColumnBreakDeferred
;
275 bool m_bIsPageBreakDeferred
;
277 LineNumberSettings m_aLineNumberSettings
;
279 BookmarkMap_t m_aBookmarkMap
;
281 _PageMar m_aPageMargins
;
284 DomainMapperTableManager m_TableManager
;
286 //each context needs a stack of currently used attributes
288 PropertyStack m_aPropertyStacks
[NUMBER_OF_CONTEXTS
];
289 ContextStack m_aContextStack
;
290 FontTablePtr m_pFontTable
;
291 ListTablePtr m_pListTable
;
292 LFOTablePtr m_pLFOTable
;
293 StyleSheetTablePtr m_pStyleSheetTable
;
294 ThemeTablePtr m_pThemeTable
;
295 GraphicImportPtr m_pGraphicImport
;
297 PropertyMapPtr m_pTopContext
;
299 ::std::vector
<DeletableTabStop
> m_aCurrentTabStops
;
300 sal_uInt32 m_nCurrentTabStopIndex
;
301 ::rtl::OUString m_sCurrentParaStyleId
;
302 bool m_bInStyleSheetImport
; //in import of fonts, styles, lists or lfos
303 bool m_bInAnyTableImport
; //in import of fonts, styles, lists or lfos
305 bool m_bLineNumberingSet
;
306 bool m_bIsInFootnoteProperties
;
307 bool m_bIsCustomFtnMark
;
309 //registered frame properties
310 ::com::sun::star::uno::Sequence
< beans::PropertyValue
> m_aFrameProperties
;
311 ::com::sun::star::uno::Reference
< text::XTextRange
> m_xFrameStartRange
;
312 ::com::sun::star::uno::Reference
< text::XTextRange
> m_xFrameEndRange
;
315 ::rtl::OUString m_CurrentRedlineAuthor
;
316 ::rtl::OUString m_CurrentRedlineDate
;
317 ::rtl::OUString m_CurrentRedlineId
;
318 sal_Int32 n_CurrentRedlineToken
;
321 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> m_xTemporaryShape
;
324 uno::Reference
< beans::XPropertySet
> m_xAnnotationField
;
326 void GetCurrentLocale(::com::sun::star::lang::Locale
& rLocale
);
327 void SetNumberFormat( const ::rtl::OUString
& rCommand
,
328 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropertySet
);
329 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>
330 FindOrCreateFieldMaster( const sal_Char
* pFieldMasterService
,
331 const ::rtl::OUString
& rFieldMasterName
)
332 throw(::com::sun::star::uno::Exception
);
333 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> GetDocumentSettings();
337 DomainMapper
& rDMapper
,
338 uno::Reference
< uno::XComponentContext
> xContext
,
339 uno::Reference
< lang::XComponent
> xModel
,
340 SourceDocumentType eDocumentType
);
342 virtual ~DomainMapper_Impl();
344 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> GetPageStyles();
345 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> GetBodyText();
346 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> GetTextFactory() const
348 return m_xTextFactory
;
350 ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> GetComponentContext() const
352 return m_xComponentContext
;
354 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextDocument
> GetTextDocument() const
356 return m_xTextDocument
;
358 void SetDocumentSettingsProperty( const ::rtl::OUString
& rPropName
, const uno::Any
& rValue
);
360 void deferBreak( BreakType deferredBreakType
);
361 bool isBreakDeferred( BreakType deferredBreakType
);
362 void clearDeferredBreaks();
363 void finishParagraph( PropertyMapPtr pPropertyMap
);
364 void appendTextPortion( const ::rtl::OUString
& rString
, PropertyMapPtr pPropertyMap
);
365 void appendTextContent( const ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextContent
>,
366 const uno::Sequence
< beans::PropertyValue
> );
367 void appendOLE( const ::rtl::OUString
& rStreamName
, OLEHandlerPtr pOleHandler
);
368 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> appendTextSectionAfter(
369 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
>& xBefore
);
371 // void appendTextSection();
373 FIB
& GetFIB() {return m_aFIB
;}
374 // push the new properties onto the stack and make it the 'current' property map
375 void PushProperties(ContextType eId
);
376 void PushStyleProperties(PropertyMapPtr pStyleProperties
);
377 void PushListProperties(PropertyMapPtr pListProperties
);
378 void PopProperties(ContextType eId
);
380 ContextType
GetTopContextType() const { return m_aContextStack
.top(); }
381 PropertyMapPtr
GetTopContext()
383 return m_pTopContext
;
385 PropertyMapPtr
GetTopContextOfType(ContextType eId
);
387 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextAppend
> GetTopTextAppend();
389 FontTablePtr
GetFontTable()
392 m_pFontTable
.reset(new FontTable());
395 StyleSheetTablePtr
GetStyleSheetTable()
397 if(!m_pStyleSheetTable
)
398 m_pStyleSheetTable
.reset(new StyleSheetTable( m_rDMapper
, m_xTextDocument
));
399 return m_pStyleSheetTable
;
401 ListTablePtr
GetListTable();
402 LFOTablePtr
GetLFOTable()
405 m_pLFOTable
.reset( new LFOTable
);
408 ThemeTablePtr
GetThemeTable()
411 m_pThemeTable
.reset( new ThemeTable
);
412 return m_pThemeTable
;
415 GraphicImportPtr
GetGraphicImport( GraphicImportType eGraphicImportType
);
416 void ResetGraphicImport();
417 // this method deletes the current m_pGraphicImport after import
418 void ImportGraphic(writerfilter::Reference
< Properties
>::Pointer_t
, GraphicImportType eGraphicImportType
);
420 void InitTabStopFromStyle( const ::com::sun::star::uno::Sequence
< ::com::sun::star::style::TabStop
>& rInitTabStops
);
421 void ModifyCurrentTabStop( Id nId
, sal_Int32 nValue
);
422 void IncorporateTabStop( const DeletableTabStop
&aTabStop
);
423 ::com::sun::star::uno::Sequence
< ::com::sun::star::style::TabStop
> GetCurrentTabStopAndClear();
424 void NextTabStop() {++m_nCurrentTabStopIndex
;}
426 void SetCurrentParaStyleId(::rtl::OUString sStringValue
) {m_sCurrentParaStyleId
= sStringValue
;}
427 ::rtl::OUString
GetCurrentParaStyleId() const {return m_sCurrentParaStyleId
;}
429 ::com::sun::star::uno::Any
GetPropertyFromStyleSheet(PropertyIds eId
);
430 void SetStyleSheetImport( bool bSet
) { m_bInStyleSheetImport
= bSet
;}
431 bool IsStyleSheetImport()const { return m_bInStyleSheetImport
;}
432 void SetAnyTableImport( bool bSet
) { m_bInAnyTableImport
= bSet
;}
433 bool IsAnyTableImport()const { return m_bInAnyTableImport
;}
435 void PushShapeContext();
436 void PopShapeContext();
437 bool IsInShapeContext() const { return m_xTemporaryShape
.is(); }
438 void CopyTemporaryShapeText( ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> xShape
);
440 void PushPageHeader(SectionPropertyMap::PageType eType
);
441 void PushPageFooter(SectionPropertyMap::PageType eType
);
443 void PopPageHeaderFooter();
445 void PushFootOrEndnote( bool bIsFootnote
);
446 void PopFootOrEndnote();
448 void PushAnnotation();
449 void PopAnnotation();
451 //field context starts with a 0x13
452 void PushFieldContext();
453 //the current field context waits for the completion of the command
454 bool IsOpenFieldCommand() const;
455 bool IsOpenField() const;
456 //collect the pieces of the command
457 void AppendFieldCommand(::rtl::OUString
& rPartOfCommand
);
458 //the field command has to be closed (0x14 appeared)
459 void CloseFieldCommand();
460 //the _current_ fields require a string type result while TOCs accept richt results
461 bool IsFieldResultAsString();
462 //apply the result text to the related field
463 void SetFieldResult( ::rtl::OUString
& rResult
);
464 //the end of field is reached (0x15 appeared) - the command might still be open
465 void PopFieldContext();
467 void AddBookmark( const ::rtl::OUString
& rBookmarkName
, const ::rtl::OUString
& rId
);
469 DomainMapperTableManager
& getTableManager() { return m_TableManager
; }
471 void SetLineNumbering( sal_Int32 nLnnMod
, sal_Int32 nLnc
, sal_Int32 ndxaLnn
);
472 bool IsLineNumberingSet() const {return m_bLineNumberingSet
;}
474 DeletableTabStop m_aCurrentTabStop
;
476 bool IsOOXMLImport() const { return m_eDocumentType
== DOCUMENT_OOXML
; }
478 void InitPageMargins() { m_aPageMargins
= _PageMar(); }
479 void SetPageMarginTwip( PageMarElement eElement
, sal_Int32 nValue
);
480 const _PageMar
& GetPageMargins() const {return m_aPageMargins
;}
482 const LineNumberSettings
& GetLineNumberSettings() const { return m_aLineNumberSettings
;}
483 void SetLineNumberSettings(const LineNumberSettings
& rSet
) { m_aLineNumberSettings
= rSet
;}
485 void SetInFootnoteProperties(bool bSet
) { m_bIsInFootnoteProperties
= bSet
;}
486 bool IsInFootnoteProperties() const { return m_bIsInFootnoteProperties
;}
488 void SetCustomFtnMark(bool bSet
) { m_bIsCustomFtnMark
= bSet
; }
489 bool IsCustomFtnMark() const { return m_bIsCustomFtnMark
; }
491 void RegisterFrameConversion(
492 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> xFrameStartRange
,
493 ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> xFrameEndRange
,
494 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aFrameProperties
496 bool ExecuteFrameConversion();
498 ::rtl::OUString
GetCurrentRedlineAuthor() const { return m_CurrentRedlineAuthor
; }
499 void SetCurrentRedlineAuthor( const ::rtl::OUString
& rSet
) { m_CurrentRedlineAuthor
= rSet
; }
501 ::rtl::OUString
GetCurrentRedlineDate() const { return m_CurrentRedlineDate
; }
502 void SetCurrentRedlineDate( const ::rtl::OUString
& rSet
) { m_CurrentRedlineDate
= rSet
; }
504 ::rtl::OUString
GetCurrentRedlineId() const { return m_CurrentRedlineId
; }
505 void SetCurrentRedlineId( const ::rtl::OUString
& rSet
) { m_CurrentRedlineId
= rSet
; }
507 sal_Int32
GetCurrentRedlineToken() const { return n_CurrentRedlineToken
; }
508 void SetCurrentRedlineToken(sal_Int32 nSet
) { n_CurrentRedlineToken
= nSet
; }
510 void ResetRedlineProperties();
513 } //namespace dmapper
514 } //namespace writerfilter