Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/string.hxx>
30 : : #include <vcl/wrkwin.hxx>
31 : : #include <vcl/dialog.hxx>
32 : : #include <vcl/msgbox.hxx>
33 : : #include <vcl/svapp.hxx>
34 : :
35 : : #include <eertfpar.hxx>
36 : : #include <impedit.hxx>
37 : : #include <svl/intitem.hxx>
38 : : #include <editeng/escpitem.hxx>
39 : : #include <editeng/fhgtitem.hxx>
40 : : #include <editeng/fontitem.hxx>
41 : : #include <editeng/flditem.hxx>
42 : : #include "editeng/editeng.hxx"
43 : :
44 : : #include <svtools/rtftoken.h>
45 : :
46 : : using namespace com::sun::star;
47 : :
48 : : // Set all values to defaultt; is called after loading the bitmap!
49 : 0 : void SvxRTFPictureType::ResetValues()
50 : : { // Set all values RTF-Defaults
51 : 0 : eStyle = RTF_BITMAP;
52 : 0 : nMode = HEX_MODE;
53 : 0 : nType = nGoalWidth = nGoalHeight = 0;
54 : 0 : nWidth = nHeight = nWidthBytes = 0;
55 : 0 : uPicLen = 0;
56 : 0 : nBitsPerPixel = nPlanes = 1;
57 : 0 : nScalX = nScalY = 100; // Scale in percent
58 : 0 : nCropT = nCropB = nCropL = nCropR = 0;
59 : 0 : aPropertyPairs.clear();
60 : 0 : }
61 : :
62 : 165 : ImportInfo::ImportInfo( ImportState eSt, SvParser* pPrsrs, const ESelection& rSel )
63 : 165 : : aSelection( rSel )
64 : : {
65 : : pParser = pPrsrs,
66 : 165 : eState = eSt;
67 : :
68 : 165 : nToken = 0;
69 : 165 : nTokenValue = 0;
70 : 165 : pAttrs = NULL;
71 : 165 : }
72 : :
73 : 165 : ImportInfo::~ImportInfo()
74 : : {
75 : 165 : }
76 : :
77 : 0 : EditRTFParser::EditRTFParser(
78 : : SvStream& rIn, EditSelection aSel, SfxItemPool& rAttrPool, EditEngine* pEditEngine) :
79 : : SvxRTFParser(rAttrPool, rIn, 0),
80 : : mpEditEngine(pEditEngine),
81 [ # # ][ # # ]: 0 : aRTFMapMode(MAP_TWIP)
[ # # ][ # # ]
82 : : {
83 [ # # ]: 0 : aCurSel = aSel;
84 : 0 : eDestCharSet = RTL_TEXTENCODING_DONTKNOW;
85 : 0 : nDefFont = 0;
86 : 0 : nDefTab = 0;
87 : 0 : nLastAction = 0;
88 : 0 : nDefFontHeight = 0;
89 : :
90 [ # # ]: 0 : SetInsPos(EditPosition(mpEditEngine, &aCurSel));
91 : :
92 : : // Convert the twips values ...
93 : 0 : SetCalcValue(true);
94 [ # # ]: 0 : SetChkStyleAttr(mpEditEngine->IsImportRTFStyleSheetsSet());
95 : 0 : SetNewDoc(false); // So that the Pool-Defaults are not overwritten...
96 [ # # ][ # # ]: 0 : aEditMapMode = MapMode(mpEditEngine->GetRefDevice()->GetMapMode().GetMapUnit());
[ # # ][ # # ]
97 : 0 : }
98 : :
99 [ # # ][ # # ]: 0 : EditRTFParser::~EditRTFParser()
100 : : {
101 [ # # ]: 0 : }
102 : :
103 : 0 : SvParserState EditRTFParser::CallParser()
104 : : {
105 : : DBG_ASSERT( !aCurSel.HasRange(), "Selection for CallParser!" );
106 : : // Separate the part that is imported from the rest.
107 : : // This expression should be used for all imports.
108 : : // aStart1PaM: Last position before the imported content
109 : : // aEnd1PaM: First position after the imported content
110 : : // aStart2PaM: First position of the imported content
111 : : // aEnd2PaM: Last position of the imported content
112 [ # # ][ # # ]: 0 : EditPaM aStart1PaM( aCurSel.Min().GetNode(), aCurSel.Min().GetIndex() );
113 [ # # ][ # # ]: 0 : aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
114 [ # # ]: 0 : EditPaM aStart2PaM = aCurSel.Min();
115 : : // Useful or not?
116 [ # # ][ # # ]: 0 : aStart2PaM.GetNode()->GetContentAttribs().GetItems().ClearItem();
117 [ # # ]: 0 : AddRTFDefaultValues( aStart2PaM, aStart2PaM );
118 [ # # ][ # # ]: 0 : EditPaM aEnd1PaM = mpEditEngine->InsertParaBreak(aCurSel.Max());
119 : : // aCurCel now points to the gap
120 : :
121 [ # # ][ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
122 : : {
123 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_START, this, mpEditEngine->CreateESelection(aCurSel));
124 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
125 : : }
126 : :
127 [ # # ]: 0 : SvParserState _eState = SvxRTFParser::CallParser();
128 : :
129 [ # # ][ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
130 : : {
131 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_END, this, mpEditEngine->CreateESelection(aCurSel));
132 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
133 : : }
134 : :
135 [ # # ]: 0 : if ( nLastAction == ACTION_INSERTPARABRK )
136 : : {
137 [ # # ]: 0 : ContentNode* pCurNode = aCurSel.Max().GetNode();
138 [ # # ][ # # ]: 0 : sal_uInt16 nPara = mpEditEngine->GetEditDoc().GetPos(pCurNode);
139 [ # # ][ # # ]: 0 : ContentNode* pPrevNode = mpEditEngine->GetEditDoc().GetObject(nPara-1);
140 : : DBG_ASSERT( pPrevNode, "Invalid RTF-Document?!" );
141 [ # # ]: 0 : EditSelection aSel;
142 [ # # ][ # # ]: 0 : aSel.Min() = EditPaM( pPrevNode, pPrevNode->Len() );
[ # # ]
143 [ # # ][ # # ]: 0 : aSel.Max() = EditPaM( pCurNode, 0 );
144 [ # # ][ # # ]: 0 : aCurSel.Max() = mpEditEngine->DeleteSelection(aSel);
145 : : }
146 [ # # ]: 0 : EditPaM aEnd2PaM( aCurSel.Max() );
147 : : //AddRTFDefaultValues( aStart2PaM, aEnd2PaM );
148 [ # # ][ # # ]: 0 : sal_Bool bOnlyOnePara = ( aEnd2PaM.GetNode() == aStart2PaM.GetNode() );
149 : : // Paste the chunk again ...
150 : : // Problem: Paragraph attributes may not possibly be taken over
151 : : // => Do Character attributes.
152 : :
153 [ # # ][ # # ]: 0 : sal_Bool bSpecialBackward = aStart1PaM.GetNode()->Len() ? sal_False : sal_True;
154 [ # # ][ # # ]: 0 : if ( bOnlyOnePara || aStart1PaM.GetNode()->Len() )
[ # # ][ # # ]
[ # # ]
155 [ # # ][ # # ]: 0 : mpEditEngine->ParaAttribsToCharAttribs( aStart2PaM.GetNode() );
156 : 0 : aCurSel.Min() = mpEditEngine->ConnectParagraphs(
157 [ # # ][ # # ]: 0 : aStart1PaM.GetNode(), aStart2PaM.GetNode(), bSpecialBackward );
[ # # # # ]
158 [ # # ][ # # ]: 0 : bSpecialBackward = aEnd1PaM.GetNode()->Len() ? sal_True : sal_False;
[ # # ]
159 : : // when bOnlyOnePara, then the node is gone on Connect.
160 [ # # ][ # # ]: 0 : if ( !bOnlyOnePara && aEnd1PaM.GetNode()->Len() )
[ # # ][ # # ]
[ # # ]
161 [ # # ][ # # ]: 0 : mpEditEngine->ParaAttribsToCharAttribs( aEnd2PaM.GetNode() );
162 : 0 : aCurSel.Max() = mpEditEngine->ConnectParagraphs(
163 : : ( bOnlyOnePara ? aStart1PaM.GetNode() : aEnd2PaM.GetNode() ),
164 [ # # ][ # # ]: 0 : aEnd1PaM.GetNode(), bSpecialBackward );
[ # # ][ # # ]
[ # # # # ]
165 : :
166 : 0 : return _eState;
167 : : }
168 : :
169 : 0 : void EditRTFParser::AddRTFDefaultValues( const EditPaM& rStart, const EditPaM& rEnd )
170 : : {
171 : : // Problem: DefFont and DefFontHeight
172 : 0 : Size aSz( 12, 0 );
173 [ # # ]: 0 : MapMode aPntMode( MAP_POINT );
174 [ # # ][ # # ]: 0 : MapMode _aEditMapMode(mpEditEngine->GetRefDevice()->GetMapMode().GetMapUnit());
175 [ # # ][ # # ]: 0 : aSz = mpEditEngine->GetRefDevice()->LogicToLogic(aSz, &aPntMode, &_aEditMapMode);
176 [ # # ]: 0 : SvxFontHeightItem aFontHeightItem( aSz.Width(), 100, EE_CHAR_FONTHEIGHT );
177 [ # # ]: 0 : Font aDefFont( GetDefFont() );
178 [ # # ]: 0 : SvxFontItem aFontItem( aDefFont.GetFamily(), aDefFont.GetName(),
179 [ # # ][ # # ]: 0 : aDefFont.GetStyleName(), aDefFont.GetPitch(), aDefFont.GetCharSet(), EE_CHAR_FONTINFO );
[ # # ][ # # ]
[ # # ]
180 : :
181 [ # # ][ # # ]: 0 : sal_uInt16 nStartPara = mpEditEngine->GetEditDoc().GetPos( rStart.GetNode() );
[ # # ]
182 [ # # ][ # # ]: 0 : sal_uInt16 nEndPara = mpEditEngine->GetEditDoc().GetPos( rEnd.GetNode() );
[ # # ]
183 [ # # ]: 0 : for ( sal_uInt16 nPara = nStartPara; nPara <= nEndPara; nPara++ )
184 : : {
185 [ # # ][ # # ]: 0 : ContentNode* pNode = mpEditEngine->GetEditDoc().GetObject( nPara );
186 : : DBG_ASSERT( pNode, "AddRTFDefaultValues - No paragraph?!" );
187 [ # # ][ # # ]: 0 : if ( !pNode->GetContentAttribs().HasItem( EE_CHAR_FONTINFO ) )
188 [ # # ]: 0 : pNode->GetContentAttribs().GetItems().Put( aFontItem );
189 [ # # ][ # # ]: 0 : if ( !pNode->GetContentAttribs().HasItem( EE_CHAR_FONTHEIGHT ) )
190 [ # # ]: 0 : pNode->GetContentAttribs().GetItems().Put( aFontHeightItem );
191 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
192 : 0 : }
193 : :
194 : 0 : void EditRTFParser::NextToken( int nToken )
195 : : {
196 [ # # # # : 0 : switch( nToken )
# # # ]
197 : : {
198 : : case RTF_DEFF:
199 : : {
200 : 0 : nDefFont = sal_uInt16(nTokenValue);
201 : : }
202 : 0 : break;
203 : : case RTF_DEFTAB:
204 : : {
205 : 0 : nDefTab = sal_uInt16(nTokenValue);
206 : : }
207 : 0 : break;
208 : : case RTF_CELL:
209 : : {
210 [ # # ]: 0 : aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
211 : : }
212 : 0 : break;
213 : : case RTF_LINE:
214 : : {
215 [ # # ]: 0 : aCurSel = mpEditEngine->InsertLineBreak(aCurSel);
216 : : }
217 : 0 : break;
218 : : case RTF_FIELD:
219 : : {
220 : 0 : ReadField();
221 : : }
222 : 0 : break;
223 : : case RTF_PGDSCTBL: // #i29453# ignore \*\pgdsctbl destination
224 : : case RTF_LISTTEXT:
225 : : {
226 : 0 : SkipGroup();
227 : : }
228 : 0 : break;
229 : : default:
230 : : {
231 : 0 : SvxRTFParser::NextToken( nToken );
232 [ # # ]: 0 : if ( nToken == RTF_STYLESHEET )
233 : 0 : CreateStyleSheets();
234 : : }
235 : 0 : break;
236 : : }
237 [ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
238 : : {
239 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_NEXTTOKEN, this, mpEditEngine->CreateESelection(aCurSel));
240 : 0 : aImportInfo.nToken = nToken;
241 : 0 : aImportInfo.nTokenValue = short(nTokenValue);
242 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
243 : : }
244 : 0 : }
245 : :
246 : 0 : void EditRTFParser::UnknownAttrToken( int nToken, SfxItemSet* )
247 : : {
248 : : // for Tokens which are not evaluated in ReadAttr
249 : : // Actually, only for Calc (RTFTokenHdl), so that RTF_INTBL
250 [ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
251 : : {
252 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_UNKNOWNATTR, this, mpEditEngine->CreateESelection(aCurSel));
253 : 0 : aImportInfo.nToken = nToken;
254 : 0 : aImportInfo.nTokenValue = short(nTokenValue);
255 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
256 : : }
257 : 0 : }
258 : :
259 : 0 : void EditRTFParser::InsertText()
260 : : {
261 [ # # ]: 0 : String aText( aToken );
262 [ # # ][ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
263 : : {
264 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_INSERTTEXT, this, mpEditEngine->CreateESelection(aCurSel));
265 [ # # ]: 0 : aImportInfo.aText = aText;
266 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
267 : : }
268 [ # # ][ # # ]: 0 : aCurSel = mpEditEngine->InsertText(aCurSel, aText);
269 [ # # ]: 0 : nLastAction = ACTION_INSERTTEXT;
270 : 0 : }
271 : :
272 : 0 : void EditRTFParser::InsertPara()
273 : : {
274 [ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
275 : : {
276 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_INSERTPARA, this, mpEditEngine->CreateESelection(aCurSel));
277 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
278 : : }
279 [ # # ]: 0 : aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
280 : 0 : nLastAction = ACTION_INSERTPARABRK;
281 : 0 : }
282 : :
283 : 0 : void EditRTFParser::MovePos( int bForward )
284 : : {
285 [ # # ]: 0 : if( bForward )
286 : : aCurSel = mpEditEngine->CursorRight(
287 [ # # ]: 0 : aCurSel.Max(), i18n::CharacterIteratorMode::SKIPCHARACTER);
288 : : else
289 : : aCurSel = mpEditEngine->CursorLeft(
290 [ # # ]: 0 : aCurSel.Max(), i18n::CharacterIteratorMode::SKIPCHARACTER);
291 : 0 : }
292 : :
293 : 0 : void EditRTFParser::SetEndPrevPara( SvxNodeIdx*& rpNodePos,
294 : : sal_uInt16& rCntPos )
295 : : {
296 : : // The Intention is to: determine the current insert position of the
297 : : // previous paragraph and set the end from this.
298 : : // This "\pard" always apply on the right paragraph.
299 : :
300 : 0 : ContentNode* pN = aCurSel.Max().GetNode();
301 : 0 : sal_uInt16 nCurPara = mpEditEngine->GetEditDoc().GetPos( pN );
302 : : DBG_ASSERT( nCurPara != 0, "Paragraph equal to 0: SetEnfPrevPara" );
303 [ # # ]: 0 : if ( nCurPara )
304 : 0 : nCurPara--;
305 : 0 : ContentNode* pPrevNode = mpEditEngine->GetEditDoc().GetObject( nCurPara );
306 : : DBG_ASSERT( pPrevNode, "pPrevNode = 0!" );
307 : 0 : rpNodePos = new EditNodeIdx(mpEditEngine, pPrevNode);
308 : 0 : rCntPos = pPrevNode->Len();
309 : 0 : }
310 : :
311 : 0 : int EditRTFParser::IsEndPara( SvxNodeIdx* pNd, sal_uInt16 nCnt ) const
312 : : {
313 : 0 : return ( nCnt == ( ((EditNodeIdx*)pNd)->GetNode()->Len()) );
314 : : }
315 : :
316 : 0 : void EditRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet )
317 : : {
318 : 0 : ContentNode* pSttNode = ((EditNodeIdx&)rSet.GetSttNode()).GetNode();
319 : 0 : ContentNode* pEndNode = ((EditNodeIdx&)rSet.GetEndNode()).GetNode();
320 : :
321 [ # # ]: 0 : EditPaM aStartPaM( pSttNode, rSet.GetSttCnt() );
322 [ # # ]: 0 : EditPaM aEndPaM( pEndNode, rSet.GetEndCnt() );
323 : :
324 : : // If possible adjust the Escapemant-Item:
325 : : const SfxPoolItem* pItem;
326 : :
327 : : // #i66167# adapt font heights to destination MapUnit if necessary
328 [ # # ][ # # ]: 0 : const MapUnit eDestUnit = (MapUnit)(mpEditEngine->GetEditDoc().GetItemPool().GetMetric(0));
329 : 0 : const MapUnit eSrcUnit = aRTFMapMode.GetMapUnit();
330 [ # # ]: 0 : if (eDestUnit != eSrcUnit)
331 : : {
332 : 0 : sal_uInt16 aFntHeightIems[3] = { EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT_CJK, EE_CHAR_FONTHEIGHT_CTL };
333 [ # # ]: 0 : for (size_t i = 0; i < SAL_N_ELEMENTS(aFntHeightIems); ++i)
334 : : {
335 [ # # ][ # # ]: 0 : if (SFX_ITEM_SET == rSet.GetAttrSet().GetItemState( aFntHeightIems[i], sal_False, &pItem ))
336 : : {
337 : 0 : sal_uInt32 nHeight = ((SvxFontHeightItem*)pItem)->GetHeight();
338 : : long nNewHeight;
339 [ # # ][ # # ]: 0 : nNewHeight = mpEditEngine->GetRefDevice()->LogicToLogic( (long)nHeight, eSrcUnit, eDestUnit );
340 : :
341 [ # # ]: 0 : SvxFontHeightItem aFntHeightItem( nNewHeight, ((SvxFontHeightItem*)pItem)->GetProp(), aFntHeightIems[i] );
342 [ # # ][ # # ]: 0 : rSet.GetAttrSet().Put( aFntHeightItem );
343 : : }
344 : : }
345 : : }
346 : :
347 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetAttrSet().GetItemState( EE_CHAR_ESCAPEMENT, sal_False, &pItem ))
348 : : {
349 : : // die richtige
350 : 0 : long nEsc = ((SvxEscapementItem*)pItem)->GetEsc();
351 : :
352 [ # # ][ # # ]: 0 : if( ( DFLT_ESC_AUTO_SUPER != nEsc ) && ( DFLT_ESC_AUTO_SUB != nEsc ) )
353 : : {
354 : 0 : nEsc *= 10; //HalPoints => Twips was embezzled in RTFITEM.CXX!
355 [ # # ]: 0 : SvxFont aFont;
356 [ # # ][ # # ]: 0 : mpEditEngine->SeekCursor(aStartPaM.GetNode(), aStartPaM.GetIndex()+1, aFont);
357 [ # # ]: 0 : nEsc = nEsc * 100 / aFont.GetSize().Height();
358 : :
359 [ # # ]: 0 : SvxEscapementItem aEscItem( (short) nEsc, ((SvxEscapementItem*)pItem)->GetProp(), EE_CHAR_ESCAPEMENT );
360 [ # # ][ # # ]: 0 : rSet.GetAttrSet().Put( aEscItem );
[ # # ]
361 : : }
362 : : }
363 : :
364 [ # # ][ # # ]: 0 : if (mpEditEngine->IsImportHandlerSet())
365 : : {
366 [ # # ]: 0 : EditSelection aSel( aStartPaM, aEndPaM );
367 [ # # ][ # # ]: 0 : ImportInfo aImportInfo(RTFIMP_SETATTR, this, mpEditEngine->CreateESelection(aSel));
368 : 0 : aImportInfo.pAttrs = &rSet;
369 [ # # ][ # # ]: 0 : mpEditEngine->CallImportHandler(aImportInfo);
370 : : }
371 : :
372 [ # # ]: 0 : ContentNode* pSN = aStartPaM.GetNode();
373 [ # # ]: 0 : ContentNode* pEN = aEndPaM.GetNode();
374 [ # # ][ # # ]: 0 : sal_uInt16 nStartNode = mpEditEngine->GetEditDoc().GetPos( pSN );
375 [ # # ][ # # ]: 0 : sal_uInt16 nEndNode = mpEditEngine->GetEditDoc().GetPos( pEN );
376 : 0 : sal_Int16 nOutlLevel = 0xff;
377 : :
378 [ # # ][ # # ]: 0 : if (rSet.StyleNo() && mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
[ # # ][ # # ]
[ # # ][ # # ]
379 : : {
380 [ # # ]: 0 : SvxRTFStyleTbl::iterator it = GetStyleTbl().find( rSet.StyleNo() );
381 : : DBG_ASSERT( it != GetStyleTbl().end(), "Template not defined in RTF!" );
382 [ # # ][ # # ]: 0 : if ( it != GetStyleTbl().end() )
[ # # ]
383 : : {
384 [ # # ]: 0 : SvxRTFStyleType* pS = it->second;
385 : : mpEditEngine->SetStyleSheet(
386 : : EditSelection(aStartPaM, aEndPaM),
387 [ # # ][ # # ]: 0 : (SfxStyleSheet*)mpEditEngine->GetStyleSheetPool()->Find(pS->sName, SFX_STYLE_FAMILY_ALL));
[ # # ][ # # ]
388 : 0 : nOutlLevel = pS->nOutlineNo;
389 : : }
390 : : }
391 : :
392 : : // When an Attribute goes from 0 to the current paragraph length,
393 : : // it should be a paragraph attribute!
394 : :
395 : : // Note: Selection can reach over several paragraphs.
396 : : // All Complete paragraphs are paragraph attributes ...
397 [ # # ]: 0 : for ( sal_uInt16 z = nStartNode+1; z < nEndNode; z++ )
398 : : {
399 : : DBG_ASSERT(mpEditEngine->GetEditDoc().GetObject(z), "Node does not exist yet(RTF)");
400 [ # # ]: 0 : mpEditEngine->SetParaAttribsOnly(z, rSet.GetAttrSet());
401 : : }
402 : :
403 [ # # ][ # # ]: 0 : if ( aStartPaM.GetNode() != aEndPaM.GetNode() )
[ # # ]
404 : : {
405 : : // The rest dof the StartNodes...
406 [ # # ]: 0 : if ( aStartPaM.GetIndex() == 0 )
407 [ # # ]: 0 : mpEditEngine->SetParaAttribsOnly(nStartNode, rSet.GetAttrSet());
408 : : else
409 : : mpEditEngine->SetAttribs(
410 [ # # ][ # # ]: 0 : EditSelection(aStartPaM, EditPaM(aStartPaM.GetNode(), aStartPaM.GetNode()->Len())), rSet.GetAttrSet());
[ # # ][ # # ]
[ # # ][ # # ]
411 : :
412 : : // the beginning of the EndNodes....
413 [ # # ][ # # ]: 0 : if ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() )
[ # # ]
414 [ # # ]: 0 : mpEditEngine->SetParaAttribsOnly(nEndNode, rSet.GetAttrSet());
415 : : else
416 : : mpEditEngine->SetAttribs(
417 [ # # ][ # # ]: 0 : EditSelection(EditPaM(aEndPaM.GetNode(), 0), aEndPaM), rSet.GetAttrSet());
[ # # ][ # # ]
418 : : }
419 : : else
420 : : {
421 [ # # ][ # # ]: 0 : if ( ( aStartPaM.GetIndex() == 0 ) && ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() ) )
[ # # ][ # # ]
[ # # ]
422 : : {
423 : : // When settings char attribs as para attribs, we must merge with existing attribs, not overwrite the ItemSet!
424 [ # # ][ # # ]: 0 : SfxItemSet aAttrs = mpEditEngine->GetBaseParaAttribs(nStartNode);
425 [ # # ]: 0 : aAttrs.Put( rSet.GetAttrSet() );
426 [ # # ][ # # ]: 0 : mpEditEngine->SetParaAttribsOnly(nStartNode, aAttrs);
427 : : }
428 : : else
429 : : {
430 : : mpEditEngine->SetAttribs(
431 [ # # ][ # # ]: 0 : EditSelection(aStartPaM, aEndPaM), rSet.GetAttrSet());
432 : : }
433 : : }
434 : :
435 : : // OutlLevel...
436 [ # # ]: 0 : if ( nOutlLevel != 0xff )
437 : : {
438 [ # # ]: 0 : for ( sal_uInt16 n = nStartNode; n <= nEndNode; n++ )
439 : : {
440 [ # # ][ # # ]: 0 : ContentNode* pNode = mpEditEngine->GetEditDoc().GetObject( n );
441 [ # # ][ # # ]: 0 : pNode->GetContentAttribs().GetItems().Put( SfxInt16Item( EE_PARA_OUTLLEVEL, nOutlLevel ) );
[ # # ]
442 : : }
443 : : }
444 : 0 : }
445 : :
446 : 0 : SvxRTFStyleType* EditRTFParser::FindStyleSheet( const XubString& rName )
447 : : {
448 : 0 : SvxRTFStyleTbl& rTable = GetStyleTbl();
449 [ # # ][ # # ]: 0 : for ( SvxRTFStyleTbl::iterator it = rTable.begin(); it != rTable.end(); ++it )
[ # # ][ # # ]
[ # # ]
450 : : {
451 [ # # ]: 0 : SvxRTFStyleType* pS = it->second;
452 [ # # ][ # # ]: 0 : if ( pS->sName == rName )
453 : 0 : return pS;
454 : : }
455 : 0 : return NULL;
456 : : }
457 : :
458 : 0 : SfxStyleSheet* EditRTFParser::CreateStyleSheet( SvxRTFStyleType* pRTFStyle )
459 : : {
460 : : // Check if a template exists, then it will not be changed!
461 [ # # ][ # # ]: 0 : SfxStyleSheet* pStyle = (SfxStyleSheet*)mpEditEngine->GetStyleSheetPool()->Find( pRTFStyle->sName, SFX_STYLE_FAMILY_ALL );
462 [ # # ]: 0 : if ( pStyle )
463 : 0 : return pStyle;
464 : :
465 [ # # ]: 0 : String aName( pRTFStyle->sName );
466 [ # # ]: 0 : String aParent;
467 [ # # ]: 0 : if ( pRTFStyle->nBasedOn )
468 : : {
469 [ # # ]: 0 : SvxRTFStyleTbl::iterator it = GetStyleTbl().find( pRTFStyle->nBasedOn );
470 [ # # ][ # # ]: 0 : if ( it != GetStyleTbl().end())
[ # # ]
471 : : {
472 [ # # ]: 0 : SvxRTFStyleType* pS = it->second;
473 [ # # ][ # # ]: 0 : if ( pS && ( pS !=pRTFStyle ) )
474 [ # # ]: 0 : aParent = pS->sName;
475 : : }
476 : : }
477 : :
478 [ # # ][ # # ]: 0 : pStyle = (SfxStyleSheet*) &mpEditEngine->GetStyleSheetPool()->Make( aName, SFX_STYLE_FAMILY_PARA );
479 : :
480 : : // 1) convert and take over Items ...
481 [ # # ][ # # ]: 0 : ConvertAndPutItems( pStyle->GetItemSet(), pRTFStyle->aAttrSet );
482 : :
483 : : // 2) As long as Parent is not in the pool, also create this ...
484 [ # # ][ # # ]: 0 : if ( aParent.Len() && ( aParent != aName ) )
[ # # ][ # # ]
485 : : {
486 [ # # ][ # # ]: 0 : SfxStyleSheet* pS = (SfxStyleSheet*)mpEditEngine->GetStyleSheetPool()->Find( aParent, SFX_STYLE_FAMILY_ALL );
487 [ # # ]: 0 : if ( !pS )
488 : : {
489 : : // If not found anywhere, create from RTF ...
490 [ # # ]: 0 : SvxRTFStyleType* _pRTFStyle = FindStyleSheet( aParent );
491 [ # # ]: 0 : if ( _pRTFStyle )
492 [ # # ]: 0 : pS = CreateStyleSheet( _pRTFStyle );
493 : : }
494 : : // 2b) Link Itemset with Parent ...
495 [ # # ]: 0 : if ( pS )
496 [ # # ][ # # ]: 0 : pStyle->GetItemSet().SetParent( &pS->GetItemSet() );
497 : : }
498 [ # # ][ # # ]: 0 : return pStyle;
499 : : }
500 : :
501 : 0 : void EditRTFParser::CreateStyleSheets()
502 : : {
503 : : // the SvxRTFParser haa now created the template...
504 [ # # ][ # # ]: 0 : if (mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
[ # # ]
505 : : {
506 [ # # ][ # # ]: 0 : for (SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); it != GetStyleTbl().end(); ++it)
[ # # ][ # # ]
[ # # ]
507 : : {
508 [ # # ]: 0 : SvxRTFStyleType* pRTFStyle = it->second;
509 [ # # ]: 0 : CreateStyleSheet( pRTFStyle );
510 : : }
511 : : }
512 : 0 : }
513 : :
514 : 0 : void EditRTFParser::CalcValue()
515 : : {
516 : 0 : const MapUnit eDestUnit = static_cast< MapUnit >( aEditMapMode.GetMapUnit() );
517 : 0 : const MapUnit eSrcUnit = aRTFMapMode.GetMapUnit();
518 [ # # ]: 0 : if (eDestUnit != eSrcUnit)
519 : 0 : nTokenValue = OutputDevice::LogicToLogic( (long)nTokenValue, eSrcUnit, eDestUnit );
520 : 0 : }
521 : :
522 : 0 : void EditRTFParser::ReadField()
523 : : {
524 : : // From SwRTFParser::ReadField()
525 : 0 : int _nOpenBrakets = 1; // the first was already detected earlier
526 : 0 : sal_Bool bFldInst = sal_False;
527 : 0 : sal_Bool bFldRslt = sal_False;
528 [ # # ]: 0 : String aFldInst;
529 [ # # ]: 0 : String aFldRslt;
530 : :
531 [ # # ][ # # ]: 0 : while( _nOpenBrakets && IsParserWorking() )
[ # # ]
532 : : {
533 [ # # ][ # # : 0 : switch( GetNextToken() )
# # # #
# ]
534 : : {
535 : : case '}':
536 : : {
537 : 0 : _nOpenBrakets--;
538 [ # # ]: 0 : if ( _nOpenBrakets == 1 )
539 : : {
540 : 0 : bFldInst = sal_False;
541 : 0 : bFldRslt = sal_False;
542 : : }
543 : : }
544 : 0 : break;
545 : :
546 : 0 : case '{': _nOpenBrakets++;
547 : 0 : break;
548 : :
549 [ # # ]: 0 : case RTF_FIELD: SkipGroup();
550 : 0 : break;
551 : :
552 : 0 : case RTF_FLDINST: bFldInst = sal_True;
553 : 0 : break;
554 : :
555 : 0 : case RTF_FLDRSLT: bFldRslt = sal_True;
556 : 0 : break;
557 : :
558 : : case RTF_TEXTTOKEN:
559 : : {
560 [ # # ]: 0 : if ( bFldInst )
561 [ # # ]: 0 : aFldInst += aToken;
562 [ # # ]: 0 : else if ( bFldRslt )
563 [ # # ]: 0 : aFldRslt += aToken;
564 : : }
565 : 0 : break;
566 : : }
567 : : }
568 [ # # ]: 0 : if ( aFldInst.Len() )
569 : : {
570 [ # # ]: 0 : String aHyperLinkMarker( RTL_CONSTASCII_USTRINGPARAM( "HYPERLINK " ) );
571 [ # # ][ # # ]: 0 : if ( aFldInst.CompareIgnoreCaseToAscii( aHyperLinkMarker, aHyperLinkMarker.Len() ) == COMPARE_EQUAL )
572 : : {
573 [ # # ]: 0 : aFldInst.Erase( 0, aHyperLinkMarker.Len() );
574 [ # # ][ # # ]: 0 : aFldInst = comphelper::string::strip(aFldInst, ' ');
[ # # ]
575 [ # # ]: 0 : aFldInst.Erase( 0, 1 ); // "
576 [ # # ]: 0 : aFldInst.Erase( aFldInst.Len()-1, 1 ); // "
577 : :
578 [ # # ]: 0 : if ( !aFldRslt.Len() )
579 [ # # ]: 0 : aFldRslt = aFldInst;
580 : :
581 [ # # ][ # # ]: 0 : SvxFieldItem aField( SvxURLField( aFldInst, aFldRslt, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
[ # # ][ # # ]
[ # # ]
582 [ # # ][ # # ]: 0 : aCurSel = mpEditEngine->InsertField(aCurSel, aField);
583 [ # # ]: 0 : mpEditEngine->UpdateFieldsOnly();
584 [ # # ]: 0 : nLastAction = ACTION_INSERTTEXT;
585 [ # # ]: 0 : }
586 : : }
587 : :
588 [ # # ][ # # ]: 0 : SkipToken( -1 ); // the closing brace is evaluated "above"
[ # # ]
589 : 0 : }
590 : :
591 : 0 : void EditRTFParser::SkipGroup()
592 : : {
593 : 0 : int _nOpenBrakets = 1; // the first was already detected earlier
594 : :
595 [ # # ][ # # ]: 0 : while( _nOpenBrakets && IsParserWorking() )
[ # # ]
596 : : {
597 [ # # # ]: 0 : switch( GetNextToken() )
598 : : {
599 : : case '}':
600 : : {
601 : 0 : _nOpenBrakets--;
602 : : }
603 : 0 : break;
604 : :
605 : : case '{':
606 : : {
607 : 0 : _nOpenBrakets++;
608 : : }
609 : 0 : break;
610 : : }
611 : : }
612 : :
613 : 0 : SkipToken( -1 ); // the closing brace is evaluated "above"
614 : 0 : }
615 : :
616 : 0 : EditNodeIdx::EditNodeIdx(EditEngine* pEE, ContentNode* pNd) :
617 : 0 : mpEditEngine(pEE), mpNode(pNd) {}
618 : :
619 : 0 : sal_uLong EditNodeIdx::GetIdx() const
620 : : {
621 : 0 : return mpEditEngine->GetEditDoc().GetPos(mpNode);
622 : : }
623 : :
624 : 0 : SvxNodeIdx* EditNodeIdx::Clone() const
625 : : {
626 : 0 : return new EditNodeIdx(mpEditEngine, mpNode);
627 : : }
628 : :
629 : 0 : EditPosition::EditPosition(EditEngine* pEE, EditSelection* pSel) :
630 : 0 : mpEditEngine(pEE), mpCurSel(pSel) {}
631 : :
632 : 0 : SvxPosition* EditPosition::Clone() const
633 : : {
634 : 0 : return new EditPosition(mpEditEngine, mpCurSel);
635 : : }
636 : :
637 : 0 : SvxNodeIdx* EditPosition::MakeNodeIdx() const
638 : : {
639 : 0 : return new EditNodeIdx(mpEditEngine, mpCurSel->Max().GetNode());
640 : : }
641 : :
642 : 0 : sal_uLong EditPosition::GetNodeIdx() const
643 : : {
644 : 0 : ContentNode* pN = mpCurSel->Max().GetNode();
645 : 0 : return mpEditEngine->GetEditDoc().GetPos(pN);
646 : : }
647 : :
648 : 0 : sal_uInt16 EditPosition::GetCntIdx() const
649 : : {
650 : 0 : return mpCurSel->Max().GetIndex();
651 : : }
652 : :
653 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|