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