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 55 : ImportInfo::ImportInfo( ImportState eSt, SvParser* pPrsrs, const ESelection& rSel )
40 55 : : aSelection( rSel )
41 : {
42 : pParser = pPrsrs,
43 55 : eState = eSt;
44 :
45 55 : nToken = 0;
46 55 : nTokenValue = 0;
47 55 : pAttrs = NULL;
48 55 : }
49 :
50 55 : ImportInfo::~ImportInfo()
51 : {
52 55 : }
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() == 0;
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() != 0;
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_SHPINST: // fdo#76776 process contents of shpinst
201 0 : break;
202 : case RTF_SP: // fdo#76776 but skip SP groups
203 : {
204 0 : SkipGroup();
205 : }
206 0 : break;
207 : case RTF_PGDSCTBL: // #i29453# ignore \*\pgdsctbl destination
208 : case RTF_LISTTEXT:
209 : {
210 0 : SkipGroup();
211 : }
212 0 : break;
213 : default:
214 : {
215 0 : SvxRTFParser::NextToken( nToken );
216 0 : if ( nToken == RTF_STYLESHEET )
217 0 : CreateStyleSheets();
218 : }
219 0 : break;
220 : }
221 0 : if (mpEditEngine->IsImportHandlerSet())
222 : {
223 0 : ImportInfo aImportInfo(RTFIMP_NEXTTOKEN, this, mpEditEngine->CreateESelection(aCurSel));
224 0 : aImportInfo.nToken = nToken;
225 0 : aImportInfo.nTokenValue = short(nTokenValue);
226 0 : mpEditEngine->CallImportHandler(aImportInfo);
227 : }
228 0 : }
229 :
230 0 : void EditRTFParser::UnknownAttrToken( int nToken, SfxItemSet* )
231 : {
232 : // for Tokens which are not evaluated in ReadAttr
233 : // Actually, only for Calc (RTFTokenHdl), so that RTF_INTBL
234 0 : if (mpEditEngine->IsImportHandlerSet())
235 : {
236 0 : ImportInfo aImportInfo(RTFIMP_UNKNOWNATTR, this, mpEditEngine->CreateESelection(aCurSel));
237 0 : aImportInfo.nToken = nToken;
238 0 : aImportInfo.nTokenValue = short(nTokenValue);
239 0 : mpEditEngine->CallImportHandler(aImportInfo);
240 : }
241 0 : }
242 :
243 0 : void EditRTFParser::InsertText()
244 : {
245 0 : OUString aText( aToken );
246 0 : if (mpEditEngine->IsImportHandlerSet())
247 : {
248 0 : ImportInfo aImportInfo(RTFIMP_INSERTTEXT, this, mpEditEngine->CreateESelection(aCurSel));
249 0 : aImportInfo.aText = aText;
250 0 : mpEditEngine->CallImportHandler(aImportInfo);
251 : }
252 0 : aCurSel = mpEditEngine->InsertText(aCurSel, aText);
253 0 : nLastAction = ACTION_INSERTTEXT;
254 0 : }
255 :
256 0 : void EditRTFParser::InsertPara()
257 : {
258 0 : if (mpEditEngine->IsImportHandlerSet())
259 : {
260 0 : ImportInfo aImportInfo(RTFIMP_INSERTPARA, this, mpEditEngine->CreateESelection(aCurSel));
261 0 : mpEditEngine->CallImportHandler(aImportInfo);
262 : }
263 0 : aCurSel = mpEditEngine->InsertParaBreak(aCurSel);
264 0 : nLastAction = ACTION_INSERTPARABRK;
265 0 : }
266 :
267 0 : void EditRTFParser::MovePos( bool const bForward )
268 : {
269 0 : if( bForward )
270 0 : aCurSel = mpEditEngine->CursorRight(
271 0 : aCurSel.Max(), i18n::CharacterIteratorMode::SKIPCHARACTER);
272 : else
273 0 : aCurSel = mpEditEngine->CursorLeft(
274 0 : aCurSel.Max(), i18n::CharacterIteratorMode::SKIPCHARACTER);
275 0 : }
276 :
277 0 : void EditRTFParser::SetEndPrevPara( SvxNodeIdx*& rpNodePos,
278 : sal_Int32& rCntPos )
279 : {
280 : // The Intention is to: determine the current insert position of the
281 : // previous paragraph and set the end from this.
282 : // This "\pard" always apply on the right paragraph.
283 :
284 0 : ContentNode* pN = aCurSel.Max().GetNode();
285 0 : sal_Int32 nCurPara = mpEditEngine->GetEditDoc().GetPos( pN );
286 : DBG_ASSERT( nCurPara != 0, "Paragraph equal to 0: SetEnfPrevPara" );
287 0 : if ( nCurPara )
288 0 : nCurPara--;
289 0 : ContentNode* pPrevNode = mpEditEngine->GetEditDoc().GetObject( nCurPara );
290 : assert(pPrevNode && "pPrevNode = 0!");
291 0 : rpNodePos = new EditNodeIdx(mpEditEngine, pPrevNode);
292 0 : rCntPos = pPrevNode->Len();
293 0 : }
294 :
295 0 : bool EditRTFParser::IsEndPara( SvxNodeIdx* pNd, sal_Int32 nCnt ) const
296 : {
297 0 : return nCnt == ( static_cast<EditNodeIdx*>(pNd)->GetNode()->Len());
298 : }
299 :
300 0 : void EditRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet )
301 : {
302 0 : ContentNode* pSttNode = const_cast<EditNodeIdx&>(static_cast<const EditNodeIdx&>(rSet.GetSttNode())).GetNode();
303 0 : ContentNode* pEndNode = const_cast<EditNodeIdx&>(static_cast<const EditNodeIdx&>(rSet.GetEndNode())).GetNode();
304 :
305 0 : EditPaM aStartPaM( pSttNode, rSet.GetSttCnt() );
306 0 : EditPaM aEndPaM( pEndNode, rSet.GetEndCnt() );
307 :
308 : // If possible adjust the Escapemant-Item:
309 : const SfxPoolItem* pItem;
310 :
311 : // #i66167# adapt font heights to destination MapUnit if necessary
312 0 : const MapUnit eDestUnit = (MapUnit)(mpEditEngine->GetEditDoc().GetItemPool().GetMetric(0));
313 0 : const MapUnit eSrcUnit = aRTFMapMode.GetMapUnit();
314 0 : if (eDestUnit != eSrcUnit)
315 : {
316 0 : sal_uInt16 aFntHeightIems[3] = { EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT_CJK, EE_CHAR_FONTHEIGHT_CTL };
317 0 : for (size_t i = 0; i < SAL_N_ELEMENTS(aFntHeightIems); ++i)
318 : {
319 0 : if (SfxItemState::SET == rSet.GetAttrSet().GetItemState( aFntHeightIems[i], false, &pItem ))
320 : {
321 0 : sal_uInt32 nHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
322 : long nNewHeight;
323 0 : nNewHeight = OutputDevice::LogicToLogic( (long)nHeight, eSrcUnit, eDestUnit );
324 :
325 0 : SvxFontHeightItem aFntHeightItem( nNewHeight, 100, aFntHeightIems[i] );
326 : aFntHeightItem.SetProp(
327 0 : static_cast<const SvxFontHeightItem*>(pItem)->GetProp(),
328 0 : static_cast<const SvxFontHeightItem*>(pItem)->GetPropUnit());
329 0 : rSet.GetAttrSet().Put( aFntHeightItem );
330 : }
331 : }
332 : }
333 :
334 0 : if( SfxItemState::SET == rSet.GetAttrSet().GetItemState( EE_CHAR_ESCAPEMENT, false, &pItem ))
335 : {
336 : // die richtige
337 0 : long nEsc = static_cast<const SvxEscapementItem*>(pItem)->GetEsc();
338 :
339 0 : if( ( DFLT_ESC_AUTO_SUPER != nEsc ) && ( DFLT_ESC_AUTO_SUB != nEsc ) )
340 : {
341 0 : nEsc *= 10; //HalPoints => Twips was embezzled in RTFITEM.CXX!
342 0 : SvxFont aFont;
343 0 : mpEditEngine->SeekCursor(aStartPaM.GetNode(), aStartPaM.GetIndex()+1, aFont);
344 0 : nEsc = nEsc * 100 / aFont.GetSize().Height();
345 :
346 0 : SvxEscapementItem aEscItem( (short) nEsc, static_cast<const SvxEscapementItem*>(pItem)->GetProp(), EE_CHAR_ESCAPEMENT );
347 0 : rSet.GetAttrSet().Put( aEscItem );
348 : }
349 : }
350 :
351 0 : if (mpEditEngine->IsImportHandlerSet())
352 : {
353 0 : EditSelection aSel( aStartPaM, aEndPaM );
354 0 : ImportInfo aImportInfo(RTFIMP_SETATTR, this, mpEditEngine->CreateESelection(aSel));
355 0 : aImportInfo.pAttrs = &rSet;
356 0 : mpEditEngine->CallImportHandler(aImportInfo);
357 : }
358 :
359 0 : ContentNode* pSN = aStartPaM.GetNode();
360 0 : ContentNode* pEN = aEndPaM.GetNode();
361 0 : sal_Int32 nStartNode = mpEditEngine->GetEditDoc().GetPos( pSN );
362 0 : sal_Int32 nEndNode = mpEditEngine->GetEditDoc().GetPos( pEN );
363 0 : sal_Int16 nOutlLevel = 0xff;
364 :
365 0 : if (rSet.StyleNo() && mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
366 : {
367 0 : SvxRTFStyleTbl::iterator it = GetStyleTbl().find( rSet.StyleNo() );
368 : DBG_ASSERT( it != GetStyleTbl().end(), "Template not defined in RTF!" );
369 0 : if ( it != GetStyleTbl().end() )
370 : {
371 0 : SvxRTFStyleType* pS = it->second;
372 : mpEditEngine->SetStyleSheet(
373 : EditSelection(aStartPaM, aEndPaM),
374 0 : static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find(pS->sName, SFX_STYLE_FAMILY_ALL)));
375 0 : nOutlLevel = pS->nOutlineNo;
376 : }
377 : }
378 :
379 : // When an Attribute goes from 0 to the current paragraph length,
380 : // it should be a paragraph attribute!
381 :
382 : // Note: Selection can reach over several paragraphs.
383 : // All Complete paragraphs are paragraph attributes ...
384 0 : for ( sal_Int32 z = nStartNode+1; z < nEndNode; z++ )
385 : {
386 : DBG_ASSERT(mpEditEngine->GetEditDoc().GetObject(z), "Node does not exist yet(RTF)");
387 0 : mpEditEngine->SetParaAttribsOnly(z, rSet.GetAttrSet());
388 : }
389 :
390 0 : if ( aStartPaM.GetNode() != aEndPaM.GetNode() )
391 : {
392 : // The rest dof the StartNodes...
393 0 : if ( aStartPaM.GetIndex() == 0 )
394 0 : mpEditEngine->SetParaAttribsOnly(nStartNode, rSet.GetAttrSet());
395 : else
396 : mpEditEngine->SetAttribs(
397 0 : EditSelection(aStartPaM, EditPaM(aStartPaM.GetNode(), aStartPaM.GetNode()->Len())), rSet.GetAttrSet());
398 :
399 : // the beginning of the EndNodes....
400 0 : if ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() )
401 0 : mpEditEngine->SetParaAttribsOnly(nEndNode, rSet.GetAttrSet());
402 : else
403 : mpEditEngine->SetAttribs(
404 0 : EditSelection(EditPaM(aEndPaM.GetNode(), 0), aEndPaM), rSet.GetAttrSet());
405 : }
406 : else
407 : {
408 0 : if ( ( aStartPaM.GetIndex() == 0 ) && ( aEndPaM.GetIndex() == aEndPaM.GetNode()->Len() ) )
409 : {
410 : // When settings char attribs as para attribs, we must merge with existing attribs, not overwrite the ItemSet!
411 0 : SfxItemSet aAttrs = mpEditEngine->GetBaseParaAttribs(nStartNode);
412 0 : aAttrs.Put( rSet.GetAttrSet() );
413 0 : mpEditEngine->SetParaAttribsOnly(nStartNode, aAttrs);
414 : }
415 : else
416 : {
417 : mpEditEngine->SetAttribs(
418 0 : EditSelection(aStartPaM, aEndPaM), rSet.GetAttrSet());
419 : }
420 : }
421 :
422 : // OutlLevel...
423 0 : if ( nOutlLevel != 0xff )
424 : {
425 0 : for ( sal_Int32 n = nStartNode; n <= nEndNode; n++ )
426 : {
427 0 : ContentNode* pNode = mpEditEngine->GetEditDoc().GetObject( n );
428 0 : pNode->GetContentAttribs().GetItems().Put( SfxInt16Item( EE_PARA_OUTLLEVEL, nOutlLevel ) );
429 : }
430 : }
431 0 : }
432 :
433 0 : SvxRTFStyleType* EditRTFParser::FindStyleSheet( const OUString& rName )
434 : {
435 0 : SvxRTFStyleTbl& rTable = GetStyleTbl();
436 0 : for ( SvxRTFStyleTbl::iterator it = rTable.begin(); it != rTable.end(); ++it )
437 : {
438 0 : SvxRTFStyleType* pS = it->second;
439 0 : if ( pS->sName == rName )
440 0 : return pS;
441 : }
442 0 : return NULL;
443 : }
444 :
445 0 : SfxStyleSheet* EditRTFParser::CreateStyleSheet( SvxRTFStyleType* pRTFStyle )
446 : {
447 : // Check if a template exists, then it will not be changed!
448 0 : SfxStyleSheet* pStyle = static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find( pRTFStyle->sName, SFX_STYLE_FAMILY_ALL ));
449 0 : if ( pStyle )
450 0 : return pStyle;
451 :
452 0 : OUString aName( pRTFStyle->sName );
453 0 : OUString aParent;
454 0 : if ( pRTFStyle->nBasedOn )
455 : {
456 0 : SvxRTFStyleTbl::iterator it = GetStyleTbl().find( pRTFStyle->nBasedOn );
457 0 : if ( it != GetStyleTbl().end())
458 : {
459 0 : SvxRTFStyleType* pS = it->second;
460 0 : if ( pS && ( pS !=pRTFStyle ) )
461 0 : aParent = pS->sName;
462 : }
463 : }
464 :
465 0 : pStyle = static_cast<SfxStyleSheet*>( &mpEditEngine->GetStyleSheetPool()->Make( aName, SFX_STYLE_FAMILY_PARA ) );
466 :
467 : // 1) convert and take over Items ...
468 0 : ConvertAndPutItems( pStyle->GetItemSet(), pRTFStyle->aAttrSet );
469 :
470 : // 2) As long as Parent is not in the pool, also create this ...
471 0 : if ( !aParent.isEmpty() && ( aParent != aName ) )
472 : {
473 0 : SfxStyleSheet* pS = static_cast<SfxStyleSheet*>(mpEditEngine->GetStyleSheetPool()->Find( aParent, SFX_STYLE_FAMILY_ALL ));
474 0 : if ( !pS )
475 : {
476 : // If not found anywhere, create from RTF ...
477 0 : SvxRTFStyleType* _pRTFStyle = FindStyleSheet( aParent );
478 0 : if ( _pRTFStyle )
479 0 : pS = CreateStyleSheet( _pRTFStyle );
480 : }
481 : // 2b) Link Itemset with Parent ...
482 0 : if ( pS )
483 0 : pStyle->GetItemSet().SetParent( &pS->GetItemSet() );
484 : }
485 0 : return pStyle;
486 : }
487 :
488 0 : void EditRTFParser::CreateStyleSheets()
489 : {
490 : // the SvxRTFParser haa now created the template...
491 0 : if (mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet())
492 : {
493 0 : for (SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); it != GetStyleTbl().end(); ++it)
494 : {
495 0 : SvxRTFStyleType* pRTFStyle = it->second;
496 0 : CreateStyleSheet( pRTFStyle );
497 : }
498 : }
499 0 : }
500 :
501 0 : void EditRTFParser::CalcValue()
502 : {
503 0 : const MapUnit eDestUnit = static_cast< MapUnit >( aEditMapMode.GetMapUnit() );
504 0 : const MapUnit eSrcUnit = aRTFMapMode.GetMapUnit();
505 0 : if (eDestUnit != eSrcUnit)
506 0 : nTokenValue = OutputDevice::LogicToLogic( (long)nTokenValue, eSrcUnit, eDestUnit );
507 0 : }
508 :
509 0 : void EditRTFParser::ReadField()
510 : {
511 : // From SwRTFParser::ReadField()
512 0 : int _nOpenBrakets = 1; // the first was already detected earlier
513 0 : bool bFldInst = false;
514 0 : bool bFldRslt = false;
515 0 : OUString aFldInst;
516 0 : OUString aFldRslt;
517 :
518 0 : while( _nOpenBrakets && IsParserWorking() )
519 : {
520 0 : switch( GetNextToken() )
521 : {
522 : case '}':
523 : {
524 0 : _nOpenBrakets--;
525 0 : if ( _nOpenBrakets == 1 )
526 : {
527 0 : bFldInst = false;
528 0 : bFldRslt = false;
529 : }
530 : }
531 0 : break;
532 :
533 0 : case '{': _nOpenBrakets++;
534 0 : break;
535 :
536 0 : case RTF_FIELD: SkipGroup();
537 0 : break;
538 :
539 0 : case RTF_FLDINST: bFldInst = true;
540 0 : break;
541 :
542 0 : case RTF_FLDRSLT: bFldRslt = true;
543 0 : break;
544 :
545 : case RTF_TEXTTOKEN:
546 : {
547 0 : if ( bFldInst )
548 0 : aFldInst += aToken;
549 0 : else if ( bFldRslt )
550 0 : aFldRslt += aToken;
551 : }
552 0 : break;
553 : }
554 : }
555 0 : if ( !aFldInst.isEmpty() )
556 : {
557 0 : OUString aHyperLinkMarker( "HYPERLINK " );
558 0 : if ( aFldInst.startsWithIgnoreAsciiCase( aHyperLinkMarker ) )
559 : {
560 0 : aFldInst = aFldInst.copy( aHyperLinkMarker.getLength() );
561 0 : aFldInst = comphelper::string::strip(aFldInst, ' ');
562 : // strip start and end quotes
563 0 : aFldInst = aFldInst.copy( 1, aFldInst.getLength()-2 );
564 :
565 0 : if ( aFldRslt.isEmpty() )
566 0 : aFldRslt = aFldInst;
567 :
568 0 : SvxFieldItem aField( SvxURLField( aFldInst, aFldRslt, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
569 0 : aCurSel = mpEditEngine->InsertField(aCurSel, aField);
570 0 : mpEditEngine->UpdateFieldsOnly();
571 0 : nLastAction = ACTION_INSERTTEXT;
572 0 : }
573 : }
574 :
575 0 : SkipToken( -1 ); // the closing brace is evaluated "above"
576 0 : }
577 :
578 0 : void EditRTFParser::SkipGroup()
579 : {
580 0 : int _nOpenBrakets = 1; // the first was already detected earlier
581 :
582 0 : while( _nOpenBrakets && IsParserWorking() )
583 : {
584 0 : switch( GetNextToken() )
585 : {
586 : case '}':
587 : {
588 0 : _nOpenBrakets--;
589 : }
590 0 : break;
591 :
592 : case '{':
593 : {
594 0 : _nOpenBrakets++;
595 : }
596 0 : break;
597 : }
598 : }
599 :
600 0 : SkipToken( -1 ); // the closing brace is evaluated "above"
601 0 : }
602 :
603 0 : EditNodeIdx::EditNodeIdx(EditEngine* pEE, ContentNode* pNd) :
604 0 : mpEditEngine(pEE), mpNode(pNd) {}
605 :
606 0 : sal_Int32 EditNodeIdx::GetIdx() const
607 : {
608 0 : return mpEditEngine->GetEditDoc().GetPos(mpNode);
609 : }
610 :
611 0 : SvxNodeIdx* EditNodeIdx::Clone() const
612 : {
613 0 : return new EditNodeIdx(mpEditEngine, mpNode);
614 : }
615 :
616 0 : EditPosition::EditPosition(EditEngine* pEE, EditSelection* pSel) :
617 0 : mpEditEngine(pEE), mpCurSel(pSel) {}
618 :
619 0 : SvxPosition* EditPosition::Clone() const
620 : {
621 0 : return new EditPosition(mpEditEngine, mpCurSel);
622 : }
623 :
624 0 : SvxNodeIdx* EditPosition::MakeNodeIdx() const
625 : {
626 0 : return new EditNodeIdx(mpEditEngine, mpCurSel->Max().GetNode());
627 : }
628 :
629 0 : sal_Int32 EditPosition::GetNodeIdx() const
630 : {
631 0 : ContentNode* pN = mpCurSel->Max().GetNode();
632 0 : return mpEditEngine->GetEditDoc().GetPos(pN);
633 : }
634 :
635 0 : sal_Int32 EditPosition::GetCntIdx() const
636 : {
637 0 : return mpCurSel->Max().GetIndex();
638 : }
639 :
640 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|