Update ooo320-m1
[ooovba.git] / writerfilter / source / dmapper / DomainMapper_Impl.hxx
blob8dbfa4e6373cce9b21d81a37d0ff4e1143318650
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 $
10 * $Revision: 1.27 $
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/text/XTextFrame.hpp>
38 #include <com/sun/star/style/TabStop.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <vector>
41 #include <stack>
43 #ifndef INCLUDED_RESOURCESIDS
44 #include <doctok/resourceids.hxx>
45 #include <ooxml/resourceids.hxx>
46 #endif
47 #include <dmapper/DomainMapper.hxx>
48 #include <DomainMapperTableManager.hxx>
49 #include <PropertyMap.hxx>
50 #include <FontTable.hxx>
51 #include <NumberingManager.hxx>
52 #include <StyleSheetTable.hxx>
53 #include <ThemeTable.hxx>
54 #include <SettingsTable.hxx>
55 #include <GraphicImport.hxx>
56 #include <OLEHandler.hxx>
57 #include <map>
59 #include <string.h>
61 namespace com{ namespace sun{ namespace star{
62 namespace awt{
63 struct Size;
65 namespace lang{
66 class XMultiServiceFactory;
67 struct Locale;
69 namespace text
71 class XTextField;
73 namespace beans{ class XPropertySet;}
74 }}}
76 namespace writerfilter {
77 namespace dmapper {
79 using namespace com::sun::star;
81 //#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
82 //sal_Int32 lcl_convertToMM100(sal_Int32 _t);
84 struct _PageMar
86 sal_Int32 top;
87 sal_Int32 right;
88 sal_Int32 bottom;
89 sal_Int32 left;
90 sal_Int32 header;
91 sal_Int32 footer;
92 sal_Int32 gutter;
93 public:
94 _PageMar();
96 enum PageMarElement
98 PAGE_MAR_TOP,
99 PAGE_MAR_RIGHT,
100 PAGE_MAR_BOTTOM,
101 PAGE_MAR_LEFT,
102 PAGE_MAR_HEADER,
103 PAGE_MAR_FOOTER,
104 PAGE_MAR_GUTTER
107 /*-- 14.06.2006 07:42:52---------------------------------------------------
108 property stack element
109 -----------------------------------------------------------------------*/
110 enum ContextType
112 CONTEXT_SECTION,
113 CONTEXT_PARAGRAPH,
114 CONTEXT_CHARACTER,
115 CONTEXT_STYLESHEET,
116 CONTEXT_LIST,
117 NUMBER_OF_CONTEXTS
120 enum BreakType
122 PAGE_BREAK,
123 COLUMN_BREAK
125 /*-----------------29.01.2007 11:47-----------------
126 field stack element
127 * --------------------------------------------------*/
128 class FieldContext
130 bool m_bFieldCommandCompleted;
131 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > m_xStartRange;
133 ::rtl::OUString m_sCommand;
135 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > m_xTextField;
136 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTOC;//TOX
137 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTC;//TOX entry
138 ::rtl::OUString m_sHyperlinkURL;
140 public:
141 FieldContext(::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xStart);
142 ~FieldContext();
144 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > GetStartRange() const { return m_xStartRange; }
146 void AppendCommand(const ::rtl::OUString& rPart);
147 const ::rtl::OUString& GetCommand() const {return m_sCommand; }
149 void SetCommandCompleted() { m_bFieldCommandCompleted = true; }
150 bool IsCommandCompleted() const { return m_bFieldCommandCompleted; }
152 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > GetTextField() const { return m_xTextField;}
153 void SetTextField(::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > xTextField) { m_xTextField = xTextField;}
155 void SetTOC( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xTOC ) { m_xTOC = xTOC; }
156 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GetTOC() { return m_xTOC; }
158 void SetTC( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xTC ) { m_xTC = xTC; }
159 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GetTC( ) { return m_xTC; }
161 void SetHyperlinkURL( const ::rtl::OUString& rURL ) { m_sHyperlinkURL = rURL; }
162 const ::rtl::OUString& GetHyperlinkURL() { return m_sHyperlinkURL; }
166 struct TextAppendContext
168 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextAppend > xTextAppend;
169 ParagraphPropertiesPtr pLastParagraphProperties;
171 TextAppendContext( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextAppend >& xAppend ) :
172 xTextAppend( xAppend ){}
175 typedef boost::shared_ptr<FieldContext> FieldContextPtr;
177 typedef std::stack<ContextType> ContextStack;
178 typedef std::stack<PropertyMapPtr> PropertyStack;
179 typedef std::stack< TextAppendContext > TextAppendStack;
180 typedef std::stack<FieldContextPtr> FieldStack;
181 typedef std::stack< com::sun::star::uno::Reference< com::sun::star::text::XTextContent > > TextContentStack;
183 /*-- 18.07.2006 08:49:08---------------------------------------------------
185 -----------------------------------------------------------------------*/
186 class FIB
188 sal_Int32 aFIBData[ NS_rtf::LN_LCBSTTBFUSSR - NS_rtf::LN_WIDENT + 1];
189 sal_Int32 nLNCHS;
190 public:
191 FIB() :
192 nLNCHS( 0 )
194 memset(&aFIBData, 0x00, sizeof(aFIBData));
197 sal_Int32 GetLNCHS() const {return nLNCHS;}
198 void SetLNCHS(sal_Int32 nValue) {nLNCHS = nValue;}
199 sal_Int32 GetData( Id nName );
200 void SetData( Id nName, sal_Int32 nValue );
203 /*-- 17.07.2006 09:14:13---------------------------------------------------
204 extended tab stop struct
205 -----------------------------------------------------------------------*/
206 struct DeletableTabStop : public ::com::sun::star::style::TabStop
208 bool bDeleted;
209 DeletableTabStop() :
210 bDeleted( false ){}
211 DeletableTabStop( const ::com::sun::star::style::TabStop& rTabStop ) :
212 TabStop( rTabStop ),
213 bDeleted( false ){}
215 /*-- 12.06.2007 07:15:31---------------------------------------------------
216 /// helper to remember bookmark start position
217 -----------------------------------------------------------------------*/
218 struct BookmarkInsertPosition
220 bool m_bIsStartOfText;
221 ::rtl::OUString m_sBookmarkName;
222 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > m_xTextRange;
223 BookmarkInsertPosition(bool bIsStartOfText, const ::rtl::OUString& rName, ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xTextRange):
224 m_bIsStartOfText( bIsStartOfText ),
225 m_sBookmarkName( rName ),
226 m_xTextRange( xTextRange )
230 struct RedlineParams
232 ::rtl::OUString m_sAuthor;
233 ::rtl::OUString m_sDate;
234 sal_Int32 m_nId;
235 sal_Int32 m_nToken;
237 typedef boost::shared_ptr< RedlineParams > RedlineParamsPtr;
239 /*-- 03.03.2008 11:01:38---------------------------------------------------
241 -----------------------------------------------------------------------*/
242 struct LineNumberSettings
244 bool bIsOn;
245 sal_Int32 nDistance;
246 sal_Int32 nInterval;
247 sal_Int32 bRestartAtEachPage;
248 sal_Int32 nStartValue;
249 LineNumberSettings() :
250 bIsOn(false)
251 ,nDistance(0)
252 ,nInterval(0)
253 ,bRestartAtEachPage(true)
254 ,nStartValue(1)
258 /*-- 09.06.2006 10:15:20---------------------------------------------------
260 -----------------------------------------------------------------------*/
261 class DomainMapper;
262 class DomainMapper_Impl
264 public:
265 typedef TableManager< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >, PropertyMapPtr > TableManager_t;
266 typedef TableDataHandler< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >, TablePropertyMapPtr > TableDataHandler_t;
267 typedef std::map < ::rtl::OUString, BookmarkInsertPosition > BookmarkMap_t;
269 private:
270 SourceDocumentType m_eDocumentType;
271 DomainMapper& m_rDMapper;
272 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextDocument > m_xTextDocument;
273 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDocumentSettings;
274 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > m_xTextFactory;
275 ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xComponentContext;
276 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xPageStyles;
277 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > m_xBodyText;
279 TextAppendStack m_aTextAppendStack;
281 TextContentStack
282 m_aAnchoredStack;
284 FieldStack m_aFieldStack;
285 bool m_bFieldMode;
286 bool m_bSetUserFieldContent;
287 bool m_bIsFirstSection;
288 bool m_bIsColumnBreakDeferred;
289 bool m_bIsPageBreakDeferred;
290 bool m_bIsInShape;
291 bool m_bShapeContextAdded;
293 LineNumberSettings m_aLineNumberSettings;
295 BookmarkMap_t m_aBookmarkMap;
297 _PageMar m_aPageMargins;
300 // TableManagers are stacked: one for each stream to avoid any confusion
301 std::stack< boost::shared_ptr< DomainMapperTableManager > > m_aTableManagers;
303 //each context needs a stack of currently used attributes
304 FIB m_aFIB;
305 PropertyStack m_aPropertyStacks[NUMBER_OF_CONTEXTS];
306 ContextStack m_aContextStack;
307 FontTablePtr m_pFontTable;
308 ListsManager::Pointer m_pListTable;
309 StyleSheetTablePtr m_pStyleSheetTable;
310 ThemeTablePtr m_pThemeTable;
311 GraphicImportPtr m_pGraphicImport;
312 SettingsTablePtr m_pSettingsTable;
314 PropertyMapPtr m_pTopContext;
315 PropertyMapPtr m_pLastSectionContext;
317 ::std::vector<DeletableTabStop> m_aCurrentTabStops;
318 sal_uInt32 m_nCurrentTabStopIndex;
319 ::rtl::OUString m_sCurrentParaStyleId;
320 bool m_bInStyleSheetImport; //in import of fonts, styles, lists or lfos
321 bool m_bInAnyTableImport; //in import of fonts, styles, lists or lfos
323 bool m_bLineNumberingSet;
324 bool m_bIsInFootnoteProperties;
325 bool m_bIsCustomFtnMark;
327 //registered frame properties
328 ::com::sun::star::uno::Sequence< beans::PropertyValue > m_aFrameProperties;
329 ::com::sun::star::uno::Reference< text::XTextRange > m_xFrameStartRange;
330 ::com::sun::star::uno::Reference< text::XTextRange > m_xFrameEndRange;
332 // Redline stack
333 std::vector< RedlineParamsPtr > m_aRedlines;
334 RedlineParamsPtr m_pParaRedline;
335 bool m_bIsParaChange;
337 bool m_bParaChanged;
338 bool m_bIsLastParaInSection;
340 //annotation import
341 uno::Reference< beans::XPropertySet > m_xAnnotationField;
343 void GetCurrentLocale(::com::sun::star::lang::Locale& rLocale);
344 void SetNumberFormat( const ::rtl::OUString& rCommand,
345 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xPropertySet );
346 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
347 FindOrCreateFieldMaster( const sal_Char* pFieldMasterService,
348 const ::rtl::OUString& rFieldMasterName )
349 throw(::com::sun::star::uno::Exception);
350 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GetDocumentSettings();
352 public:
353 DomainMapper_Impl(
354 DomainMapper& rDMapper,
355 uno::Reference < uno::XComponentContext > xContext,
356 uno::Reference< lang::XComponent > xModel,
357 SourceDocumentType eDocumentType );
358 DomainMapper_Impl();
359 virtual ~DomainMapper_Impl();
361 SectionPropertyMap* GetLastSectionContext( )
363 return dynamic_cast< SectionPropertyMap* >( m_pLastSectionContext.get( ) );
366 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > GetPageStyles();
367 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > GetBodyText();
368 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > GetTextFactory() const
370 return m_xTextFactory;
372 ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > GetComponentContext() const
374 return m_xComponentContext;
376 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextDocument > GetTextDocument() const
378 return m_xTextDocument;
380 void SetDocumentSettingsProperty( const ::rtl::OUString& rPropName, const uno::Any& rValue );
382 void CreateRedline( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xRange, RedlineParamsPtr& pRedline );
384 void CheckParaRedline( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xRange );
386 void CheckRedline( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xRange );
388 void StartParaChange( );
389 void EndParaChange( );
391 void RemoveLastParagraph( );
392 void SetIsLastParagraphInSection( bool bIsLast );
394 void deferBreak( BreakType deferredBreakType );
395 bool isBreakDeferred( BreakType deferredBreakType );
396 void clearDeferredBreaks();
397 void finishParagraph( PropertyMapPtr pPropertyMap );
398 void appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap );
399 void appendTextContent( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent >,
400 const uno::Sequence< beans::PropertyValue > );
401 void appendOLE( const ::rtl::OUString& rStreamName, OLEHandlerPtr pOleHandler );
402 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > appendTextSectionAfter(
403 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >& xBefore );
405 // void appendTextSection();
407 FIB& GetFIB() {return m_aFIB;}
408 // push the new properties onto the stack and make it the 'current' property map
409 void PushProperties(ContextType eId);
410 void PushStyleProperties(PropertyMapPtr pStyleProperties);
411 void PushListProperties(PropertyMapPtr pListProperties);
412 void PopProperties(ContextType eId);
414 ContextType GetTopContextType() const { return m_aContextStack.top(); }
415 PropertyMapPtr GetTopContext()
417 return m_pTopContext;
419 PropertyMapPtr GetTopContextOfType(ContextType eId);
421 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextAppend > GetTopTextAppend();
423 FontTablePtr GetFontTable()
425 if(!m_pFontTable)
426 m_pFontTable.reset(new FontTable());
427 return m_pFontTable;
429 StyleSheetTablePtr GetStyleSheetTable()
431 if(!m_pStyleSheetTable)
432 m_pStyleSheetTable.reset(new StyleSheetTable( m_rDMapper, m_xTextDocument ));
433 return m_pStyleSheetTable;
435 ListsManager::Pointer GetListTable();
436 ThemeTablePtr GetThemeTable()
438 if(!m_pThemeTable)
439 m_pThemeTable.reset( new ThemeTable );
440 return m_pThemeTable;
443 SettingsTablePtr GetSettingsTable( )
445 if ( !m_pSettingsTable )
446 m_pSettingsTable.reset( new SettingsTable );
447 return m_pSettingsTable;
450 GraphicImportPtr GetGraphicImport( GraphicImportType eGraphicImportType );
451 void ResetGraphicImport();
452 // this method deletes the current m_pGraphicImport after import
453 void ImportGraphic(writerfilter::Reference< Properties>::Pointer_t, GraphicImportType eGraphicImportType );
455 void InitTabStopFromStyle( const ::com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop >& rInitTabStops );
456 void ModifyCurrentTabStop( Id nId, sal_Int32 nValue);
457 void IncorporateTabStop( const DeletableTabStop &aTabStop );
458 ::com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop > GetCurrentTabStopAndClear();
459 void NextTabStop() {++m_nCurrentTabStopIndex;}
461 void SetCurrentParaStyleId(::rtl::OUString sStringValue) {m_sCurrentParaStyleId = sStringValue;}
462 ::rtl::OUString GetCurrentParaStyleId() const {return m_sCurrentParaStyleId;}
464 ::com::sun::star::uno::Any GetPropertyFromStyleSheet(PropertyIds eId);
465 void SetStyleSheetImport( bool bSet ) { m_bInStyleSheetImport = bSet;}
466 bool IsStyleSheetImport()const { return m_bInStyleSheetImport;}
467 void SetAnyTableImport( bool bSet ) { m_bInAnyTableImport = bSet;}
468 bool IsAnyTableImport()const { return m_bInAnyTableImport;}
470 void PushShapeContext( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
471 void PopShapeContext();
473 void PushPageHeader(SectionPropertyMap::PageType eType);
474 void PushPageFooter(SectionPropertyMap::PageType eType);
476 void PopPageHeaderFooter();
478 void PushFootOrEndnote( bool bIsFootnote );
479 void PopFootOrEndnote();
481 void PushAnnotation();
482 void PopAnnotation();
484 //field context starts with a 0x13
485 void PushFieldContext();
486 //the current field context waits for the completion of the command
487 bool IsOpenFieldCommand() const;
488 bool IsOpenField() const;
489 //collect the pieces of the command
490 void AppendFieldCommand(::rtl::OUString& rPartOfCommand);
491 //the field command has to be closed (0x14 appeared)
492 void CloseFieldCommand();
493 //the _current_ fields require a string type result while TOCs accept richt results
494 bool IsFieldResultAsString();
495 //apply the result text to the related field
496 void SetFieldResult( ::rtl::OUString& rResult );
497 //the end of field is reached (0x15 appeared) - the command might still be open
498 void PopFieldContext();
500 void AddBookmark( const ::rtl::OUString& rBookmarkName, const ::rtl::OUString& rId );
502 DomainMapperTableManager& getTableManager()
504 boost::shared_ptr< DomainMapperTableManager > pMngr = m_aTableManagers.top();
505 return *pMngr.get( );
508 void appendTableManager( )
510 boost::shared_ptr< DomainMapperTableManager > pMngr(
511 new DomainMapperTableManager( m_eDocumentType == DOCUMENT_OOXML ) );
512 m_aTableManagers.push( pMngr );
515 void popTableManager( )
517 if ( m_aTableManagers.size( ) > 0 )
518 m_aTableManagers.pop( );
521 void SetLineNumbering( sal_Int32 nLnnMod, sal_Int32 nLnc, sal_Int32 ndxaLnn );
522 bool IsLineNumberingSet() const {return m_bLineNumberingSet;}
524 DeletableTabStop m_aCurrentTabStop;
526 bool IsOOXMLImport() const { return m_eDocumentType == DOCUMENT_OOXML; }
528 void InitPageMargins() { m_aPageMargins = _PageMar(); }
529 void SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue );
530 const _PageMar& GetPageMargins() const {return m_aPageMargins;}
532 const LineNumberSettings& GetLineNumberSettings() const { return m_aLineNumberSettings;}
533 void SetLineNumberSettings(const LineNumberSettings& rSet) { m_aLineNumberSettings = rSet;}
535 void SetInFootnoteProperties(bool bSet) { m_bIsInFootnoteProperties = bSet;}
536 bool IsInFootnoteProperties() const { return m_bIsInFootnoteProperties;}
538 void SetCustomFtnMark(bool bSet) { m_bIsCustomFtnMark = bSet; }
539 bool IsCustomFtnMark() const { return m_bIsCustomFtnMark; }
541 void RegisterFrameConversion(
542 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xFrameStartRange,
543 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > xFrameEndRange,
544 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aFrameProperties
546 bool ExecuteFrameConversion();
548 void AddNewRedline( );
550 RedlineParamsPtr GetTopRedline( );
552 sal_Int32 GetCurrentRedlineToken( );
553 void SetCurrentRedlineAuthor( rtl::OUString sAuthor );
554 void SetCurrentRedlineDate( rtl::OUString sDate );
555 void SetCurrentRedlineId( sal_Int32 nId );
556 void SetCurrentRedlineToken( sal_Int32 nToken );
557 void RemoveCurrentRedline( );
558 void ResetParaRedline( );
561 } //namespace dmapper
562 } //namespace writerfilter
563 #endif