update emoji autocorrect entries from po-files
[LibreOffice.git] / include / editeng / svxrtf.hxx
blob42098f663220b86cc3ac488700cea062f57f74bd
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 #ifndef INCLUDED_EDITENG_SVXRTF_HXX
21 #define INCLUDED_EDITENG_SVXRTF_HXX
23 #include <svl/itemset.hxx>
24 #include <svtools/parrtf.hxx>
25 #include <rtl/ustring.hxx>
27 #include <editeng/editengdllapi.h>
29 #include <deque>
30 #include <utility>
31 #include <vector>
32 #include <boost/ptr_container/ptr_map.hpp>
33 #include <boost/ptr_container/ptr_vector.hpp>
35 namespace vcl { class Font; }
36 class Color;
37 class Graphic;
38 class DateTime;
39 struct SvxRTFStyleType;
40 class SvxRTFItemStackType;
41 class SvxRTFItemStackList : public boost::ptr_vector<SvxRTFItemStackType> {};
43 namespace com { namespace sun { namespace star {
44 namespace document {
45 class XDocumentProperties;
47 namespace util {
48 struct DateTime;
50 } } }
53 // Mapper-Classes for the various requirements on Document positions
54 // Swg - NodePosition is a SwIndex, which is used internally
55 // EditEngine - ULONG to list of paragraphs
58 class SvxNodeIdx
60 public:
61 virtual ~SvxNodeIdx() {}
62 virtual sal_Int32 GetIdx() const = 0;
63 virtual SvxNodeIdx* Clone() const = 0; // Cloning itself
66 class SvxPosition
68 public:
69 virtual ~SvxPosition() {}
71 virtual sal_Int32 GetNodeIdx() const = 0;
72 virtual sal_Int32 GetCntIdx() const = 0;
74 virtual SvxPosition* Clone() const = 0; // Cloning itself
75 virtual SvxNodeIdx* MakeNodeIdx() const = 0; // Cloning NodeIndex
79 typedef Color* ColorPtr;
80 typedef std::deque< ColorPtr > SvxRTFColorTbl;
81 typedef boost::ptr_map<short, vcl::Font> SvxRTFFontTbl;
82 typedef boost::ptr_map<sal_uInt16, SvxRTFStyleType> SvxRTFStyleTbl;
84 // SvxRTFItemStack can't be "std::stack< SvxRTFItemStackType* >" type, because
85 // the methods are using operator[] in sw/source/filter/rtf/rtftbl.cxx file
86 typedef std::deque< SvxRTFItemStackType* > SvxRTFItemStack;
88 // own helper classes for the RTF Parser
89 struct SvxRTFStyleType
91 SfxItemSet aAttrSet; // the attributes of Style (+ derivate!)
92 OUString sName;
93 sal_uInt16 nBasedOn, nNext;
94 bool bBasedOnIsSet;
95 sal_uInt8 nOutlineNo;
96 bool bIsCharFmt;
98 SvxRTFStyleType( SfxItemPool& rPool, const sal_uInt16* pWhichRange );
102 // Here are the IDs for all character attributes, which can be detected by
103 // SvxParser and can be set in a SfxItemSet. The IDs are set correctly through
104 // the SlotIds from POOL.
105 struct RTFPlainAttrMapIds
107 sal_uInt16 nCaseMap,
108 nBgColor,
109 nColor,
110 nContour,
111 nCrossedOut,
112 nEscapement,
113 nFont,
114 nFontHeight,
115 nKering,
116 nLanguage,
117 nPosture,
118 nShadowed,
119 nUnderline,
120 nOverline,
121 nWeight,
122 nWordlineMode,
123 nAutoKerning,
124 nCJKFont,
125 nCJKFontHeight,
126 nCJKLanguage,
127 nCJKPosture,
128 nCJKWeight,
129 nCTLFont,
130 nCTLFontHeight,
131 nCTLLanguage,
132 nCTLPosture,
133 nCTLWeight,
134 nEmphasis,
135 nTwoLines,
136 nCharScaleX,
137 nHorzVert,
138 nRuby,
139 nRelief,
140 nHidden
142 RTFPlainAttrMapIds( const SfxItemPool& rPool );
145 // Here are the IDs for all paragraph attributes, which can be detected by
146 // SvxParser and can be set in a SfxItemSet. The IDs are set correctly through
147 // the SlotIds from POOL.
148 struct RTFPardAttrMapIds
150 sal_uInt16 nLinespacing,
151 nAdjust,
152 nTabStop,
153 nHyphenzone,
154 nLRSpace,
155 nULSpace,
156 nBrush,
157 nBox,
158 nShadow,
159 nOutlineLvl,
160 nSplit,
161 nKeep,
162 nFontAlign,
163 nScriptSpace,
164 nHangPunct,
165 nForbRule,
166 nDirection
168 RTFPardAttrMapIds( const SfxItemPool& rPool );
176 class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser
178 SvStream &rStrm;
179 SvxRTFColorTbl aColorTbl;
180 SvxRTFFontTbl aFontTbl;
181 SvxRTFStyleTbl aStyleTbl;
182 SvxRTFItemStack aAttrStack;
183 SvxRTFItemStackList aAttrSetList;
185 RTFPlainAttrMapIds aPlainMap;
186 RTFPardAttrMapIds aPardMap;
187 std::vector<sal_uInt16> aWhichMap;
188 OUString sBaseURL;
190 SvxPosition* pInsPos;
191 SfxItemPool* pAttrPool;
192 Color* pDfltColor;
193 vcl::Font* pDfltFont;
194 ::com::sun::star::uno::Reference<
195 ::com::sun::star::document::XDocumentProperties> m_xDocProps;
196 SfxItemSet *pRTFDefaults;
198 long nVersionNo;
199 int nDfltFont;
201 bool bNewDoc : 1; // sal_False - Reading in an existing
202 bool bNewGroup : 1; // sal_True - there was an opening parenthesis
203 bool bIsSetDfltTab : 1; // sal_True - DefTab was loaded
204 bool bChkStyleAttr : 1; // sal_True - StyleSheets are evaluated
205 bool bCalcValue : 1; // sal_True - Twip values adapt to App
206 bool bPardTokenRead : 1; // sal_True - Token \pard was detected
207 bool bReadDocInfo : 1; // sal_True - DocInfo to read
208 bool bIsLeftToRightDef : 1; // sal_True - in LeftToRight char run def.
209 // sal_False - in RightToLeft char run def.
210 bool bIsInReadStyleTab : 1; // sal_True - in ReadStyleTable
212 void ClearColorTbl();
213 void ClearFontTbl();
214 void ClearStyleTbl();
215 void ClearAttrStack();
217 SvxRTFItemStackType* _GetAttrSet(bool bCopyAttr = false); // Create new ItemStackType:s
218 void _ClearStyleAttr( SvxRTFItemStackType& rStkType );
220 // Sets all the attributes that are different from the current
221 void SetAttrSet( SfxItemSet& rAttrSet, SvxPosition& rSttPos );
222 void SetAttrSet( SvxRTFItemStackType &rSet );
223 void SetDefault( int nToken, int nValue );
225 // Execute pard / plain
226 void RTFPardPlain( bool bPard, SfxItemSet** ppSet );
228 void BuildWhichTable();
230 enum RTF_CharTypeDef
232 NOTDEF_CHARTYPE,
233 LOW_CHARTYPE,
234 HIGH_CHARTYPE,
235 DOUBLEBYTE_CHARTYPE
238 // set latin/asian/complex character attributes
239 void SetScriptAttr(
240 RTF_CharTypeDef eType, SfxItemSet& rSet, SfxPoolItem& rItem );
242 protected:
243 virtual void InsertPara() = 0;
245 static OUString& DelCharAtEnd( OUString& rStr, const sal_Unicode cDel );
247 // is called for each token that is recognized in CallParser
248 virtual void NextToken( int nToken ) SAL_OVERRIDE;
250 virtual void ReadBitmapData() SAL_OVERRIDE;
251 virtual void ReadOLEData() SAL_OVERRIDE;
253 void ReadStyleTable();
254 void ReadColorTable();
255 void ReadFontTable();
256 void ReadAttr( int nToken, SfxItemSet* pSet );
257 void ReadTabAttr( int nToken, SfxItemSet& rSet );
259 // Read Document-Info
260 ::com::sun::star::util::DateTime GetDateTimeStamp( );
261 OUString& GetTextToEndGroup( OUString& rStr );
262 void ReadInfo( const sal_Char* pChkForVerNo = 0 );
264 inline SfxItemSet& GetAttrSet();
265 // no text yet inserted? (SttPos from the top stack entry!)
266 bool IsAttrSttPos();
267 void AttrGroupEnd(); // edit the current, delete from stack
268 void SetAllAttrOfStk(); // end all Attr. and set it into doc
271 virtual void InsertText() = 0;
272 virtual void MovePos( bool bForward = true ) = 0;
273 virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos,
274 sal_Int32& rCntPos )=0;
275 virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
276 // for Tokens, which are not evaluated in ReadAttr
277 virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
279 // if no-one would like to have any twips
280 virtual void CalcValue();
282 SvxRTFParser( SfxItemPool& rAttrPool,
283 SvStream& rIn,
284 ::com::sun::star::uno::Reference<
285 ::com::sun::star::document::XDocumentProperties> i_xDocProps,
286 bool bReadNewDoc = true );
287 virtual ~SvxRTFParser();
289 bool IsNewDoc() const { return bNewDoc; }
290 void SetNewDoc( bool bFlag ) { bNewDoc = bFlag; }
291 bool IsNewGroup() const { return bNewGroup; }
292 void SetNewGroup( bool bFlag ) { bNewGroup = bFlag; }
293 bool IsChkStyleAttr() const { return bChkStyleAttr; }
294 void SetChkStyleAttr( bool bFlag ) { bChkStyleAttr = bFlag; }
295 bool IsCalcValue() const { return bCalcValue; }
296 void SetCalcValue( bool bFlag ) { bCalcValue = bFlag; }
297 bool IsPardTokenRead() const { return bPardTokenRead; }
298 void SetPardTokenRead( bool bFlag ) { bPardTokenRead = bFlag; }
299 bool IsReadDocInfo() const { return bReadDocInfo; }
300 void SetReadDocInfo( bool bFlag ) { bReadDocInfo = bFlag; }
302 // Query/Set the current insert position
303 SvxPosition& GetInsPos() const { return *pInsPos; }
304 void SetInsPos( const SvxPosition& rNew );
306 long GetVersionNo() const { return nVersionNo; }
308 SvxRTFStyleTbl& GetStyleTbl() { return aStyleTbl; }
309 SvxRTFItemStack& GetAttrStack() { return aAttrStack; }
310 SvxRTFColorTbl& GetColorTbl() { return aColorTbl; }
311 SvxRTFFontTbl& GetFontTbl() { return aFontTbl; }
313 const OUString& GetBaseURL() const { return sBaseURL; }
315 public:
317 virtual SvParserState CallParser() SAL_OVERRIDE;
319 inline const Color& GetColor( size_t nId ) const;
320 const vcl::Font& GetFont( sal_uInt16 nId ); // Changes the default Font
322 virtual bool IsEndPara( SvxNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
324 // to set a different attribute pool. May only be done prior to CallParser!
325 // The maps are not generated anew!
326 void SetAttrPool( SfxItemPool* pNewPool ) { pAttrPool = pNewPool; }
327 // to set different WhichIds for a different pool.
328 RTFPardAttrMapIds& GetPardMap() { return aPardMap; }
329 RTFPlainAttrMapIds& GetPlainMap() { return aPlainMap; }
330 // to be able to assign them from the outside as for example table cells
331 void ReadBorderAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
332 void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
334 // for asynchronous read from the SvStream
335 virtual void Continue( int nToken ) SAL_OVERRIDE;
337 // get RTF default ItemSets. Must be used by pard/plain tokens or in
338 // reset of Style-Items
339 const SfxItemSet& GetRTFDefaults();
342 // The stack for the attributes:
343 // this class may only be used by SvxRTFParser!
344 class EDITENG_DLLPUBLIC SvxRTFItemStackType
346 friend class SvxRTFParser;
348 SfxItemSet aAttrSet;
349 SvxNodeIdx *pSttNd, *pEndNd;
350 sal_Int32 nSttCnt, nEndCnt;
351 SvxRTFItemStackList* pChildList;
352 sal_uInt16 nStyleNo;
354 SvxRTFItemStackType( SfxItemPool&, const sal_uInt16* pWhichRange,
355 const SvxPosition& );
357 void Add( SvxRTFItemStackType* );
358 void Compress( const SvxRTFParser& );
360 public:
361 SvxRTFItemStackType( const SvxRTFItemStackType&, const SvxPosition&,
362 bool bCopyAttr = false );
363 ~SvxRTFItemStackType();
364 //cmc, I'm very suspicios about SetStartPos, it doesn't change
365 //its children's starting position, and the implementation looks
366 //bad, consider this deprecated.
367 void SetStartPos( const SvxPosition& rPos );
369 void MoveFullNode(const SvxNodeIdx &rOldNode,
370 const SvxNodeIdx &rNewNode);
372 sal_Int32 GetSttNodeIdx() const { return pSttNd->GetIdx(); }
373 sal_Int32 GetEndNodeIdx() const { return pEndNd->GetIdx(); }
375 const SvxNodeIdx& GetSttNode() const { return *pSttNd; }
376 const SvxNodeIdx& GetEndNode() const { return *pEndNd; }
378 sal_Int32 GetSttCnt() const { return nSttCnt; }
379 sal_Int32 GetEndCnt() const { return nEndCnt; }
381 SfxItemSet& GetAttrSet() { return aAttrSet; }
382 const SfxItemSet& GetAttrSet() const { return aAttrSet; }
384 sal_uInt16 StyleNo() const { return nStyleNo; }
386 void SetRTFDefaults( const SfxItemSet& rDefaults );
390 // ----------- Inline Implementations --------------
392 inline const Color& SvxRTFParser::GetColor( size_t nId ) const
394 ColorPtr pColor = (ColorPtr)pDfltColor;
395 if( nId < aColorTbl.size() )
396 pColor = aColorTbl[ nId ];
397 return *pColor;
400 inline SfxItemSet& SvxRTFParser::GetAttrSet()
402 SvxRTFItemStackType* pTmp;
403 if( bNewGroup || 0 == ( pTmp = aAttrStack.empty() ? 0 : aAttrStack.back()) )
404 pTmp = _GetAttrSet();
405 return pTmp->aAttrSet;
409 #endif
410 // INCLUDED_EDITENG_SVXRTF_HXX
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */