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 :
21 : #include "hintids.hxx"
22 : #include <comphelper/string.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/wrkwin.hxx>
25 : #include <svx/svxids.hrc>
26 : #include <sfx2/sfx.hrc>
27 : #include <i18npool/languagetag.hxx>
28 : #include <svl/stritem.hxx>
29 : #include <svl/urihelper.hxx>
30 : #include <editeng/fhgtitem.hxx>
31 : #include <editeng/lrspitem.hxx>
32 : #include <editeng/adjitem.hxx>
33 : #include <editeng/brshitem.hxx>
34 : #include <editeng/colritem.hxx>
35 : #include <editeng/boxitem.hxx>
36 : #include <editeng/ulspitem.hxx>
37 : #include <editeng/langitem.hxx>
38 : #include <editeng/scripttypeitem.hxx>
39 : #include <sfx2/docfile.hxx>
40 : #include <svtools/imap.hxx>
41 : #include <svtools/htmltokn.h>
42 : #include <svtools/htmlkywd.hxx>
43 : #include <unotools/eventcfg.hxx>
44 :
45 : #include <fmtornt.hxx>
46 : #include <fmturl.hxx>
47 : #include <fmtsrnd.hxx>
48 : #include <fmtinfmt.hxx>
49 : #include <fmtcntnt.hxx>
50 : #include <fmtanchr.hxx>
51 : #include <fmtfsize.hxx>
52 : #include "frmatr.hxx"
53 : #include "charatr.hxx"
54 : #include <frmfmt.hxx>
55 : #include <charfmt.hxx>
56 : #include <docary.hxx>
57 : #include <docsh.hxx>
58 : #include <pam.hxx>
59 : #include <doc.hxx>
60 : #include <ndtxt.hxx>
61 : #include <shellio.hxx>
62 : #include <poolfmt.hxx>
63 : #include <IMark.hxx>
64 : #include <ndgrf.hxx>
65 : #include <htmlnum.hxx>
66 : #include <swcss1.hxx>
67 : #include <swhtml.hxx>
68 : #include <numrule.hxx>
69 : #include <boost/shared_ptr.hpp>
70 :
71 : using namespace ::com::sun::star;
72 :
73 :
74 : HTMLOptionEnum aHTMLImgHAlignTable[] =
75 : {
76 : { OOO_STRING_SVTOOLS_HTML_AL_left, text::HoriOrientation::LEFT },
77 : { OOO_STRING_SVTOOLS_HTML_AL_right, text::HoriOrientation::RIGHT },
78 : { 0, 0 }
79 : };
80 :
81 :
82 : HTMLOptionEnum aHTMLImgVAlignTable[] =
83 : {
84 : { OOO_STRING_SVTOOLS_HTML_VA_top, text::VertOrientation::LINE_TOP },
85 : { OOO_STRING_SVTOOLS_HTML_VA_texttop, text::VertOrientation::CHAR_TOP },
86 : { OOO_STRING_SVTOOLS_HTML_VA_middle, text::VertOrientation::CENTER },
87 : { OOO_STRING_SVTOOLS_HTML_AL_center, text::VertOrientation::CENTER },
88 : { OOO_STRING_SVTOOLS_HTML_VA_absmiddle, text::VertOrientation::LINE_CENTER },
89 : { OOO_STRING_SVTOOLS_HTML_VA_bottom, text::VertOrientation::TOP },
90 : { OOO_STRING_SVTOOLS_HTML_VA_baseline, text::VertOrientation::TOP },
91 : { OOO_STRING_SVTOOLS_HTML_VA_absbottom, text::VertOrientation::LINE_BOTTOM },
92 : { 0, 0 }
93 : };
94 :
95 0 : ImageMap *SwHTMLParser::FindImageMap( const String& rName ) const
96 : {
97 0 : ImageMap *pMap = 0;
98 :
99 : OSL_ENSURE( rName.GetChar(0) != '#', "FindImageName: Name beginnt mit #!" );
100 :
101 0 : if( pImageMaps )
102 : {
103 0 : for( sal_uInt16 i=0; i<pImageMaps->size(); i++ )
104 : {
105 0 : ImageMap *pIMap = &(*pImageMaps)[i];
106 0 : if( rName.EqualsIgnoreCaseAscii( pIMap->GetName() ) )
107 : {
108 0 : pMap = pIMap;
109 0 : break;
110 : }
111 : }
112 : }
113 0 : return pMap;
114 : }
115 :
116 0 : void SwHTMLParser::ConnectImageMaps()
117 : {
118 0 : SwNodes& rNds = pDoc->GetNodes();
119 : // auf den Start-Node der 1. Section
120 0 : sal_uLong nIdx = rNds.GetEndOfAutotext().StartOfSectionIndex() + 1;
121 0 : sal_uLong nEndIdx = rNds.GetEndOfAutotext().GetIndex();
122 :
123 : SwGrfNode* pGrfNd;
124 0 : while( nMissingImgMaps > 0 && nIdx < nEndIdx )
125 : {
126 0 : SwNode *pNd = rNds[nIdx + 1];
127 0 : if( 0 != (pGrfNd = pNd->GetGrfNode()) )
128 : {
129 0 : SwFrmFmt *pFmt = pGrfNd->GetFlyFmt();
130 0 : SwFmtURL aURL( pFmt->GetURL() );
131 0 : const ImageMap *pIMap = aURL.GetMap();
132 0 : if( pIMap && pIMap->GetIMapObjectCount()==0 )
133 : {
134 : // Die (leere) Image-Map des Nodes wird entweder
135 : // durch die jetzt gefundene Image-Map ersetzt
136 : // oder geloescht.
137 : ImageMap *pNewIMap =
138 0 : FindImageMap( pIMap->GetName() );
139 0 : aURL.SetMap( pNewIMap );
140 0 : pFmt->SetFmtAttr( aURL );
141 0 : if( !pGrfNd->IsScaleImageMap() )
142 : {
143 : // die Grafikgroesse ist mitlerweile da oder dir
144 : // Grafik muss nicht skaliert werden
145 0 : pGrfNd->ScaleImageMap();
146 : }
147 0 : nMissingImgMaps--; // eine Map weniger suchen
148 0 : }
149 : }
150 0 : nIdx = rNds[nIdx]->EndOfSectionIndex() + 1;
151 : }
152 0 : }
153 :
154 :
155 : /* */
156 :
157 0 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
158 : sal_Int16 eHoriOri,
159 : const SfxItemSet &rCSS1ItemSet,
160 : const SvxCSS1PropertyInfo &rCSS1PropInfo,
161 : SfxItemSet& rFrmItemSet )
162 : {
163 0 : const SfxItemSet *pCntnrItemSet = 0;
164 0 : sal_uInt16 i = aContexts.size();
165 0 : while( !pCntnrItemSet && i > nContextStMin )
166 0 : pCntnrItemSet = aContexts[--i]->GetFrmItemSet();
167 :
168 0 : if( pCntnrItemSet )
169 : {
170 : // Wenn wir und in einem Container befinden wird die Verankerung
171 : // des Containers uebernommen.
172 0 : rFrmItemSet.Put( *pCntnrItemSet );
173 : }
174 0 : else if( pCSS1Parser->MayBePositioned( rCSS1PropInfo, sal_True ) )
175 : {
176 : // Wenn die Ausrichtung anhand der CSS1-Optionen gesetzt werden kann
177 : // werden die benutzt.
178 0 : SetAnchorAndAdjustment( rCSS1ItemSet, rCSS1PropInfo, rFrmItemSet );
179 : }
180 : else
181 : {
182 : // Sonst wird die Ausrichtung entsprechend der normalen HTML-Optionen
183 : // gesetzt.
184 0 : SetAnchorAndAdjustment( eVertOri, eHoriOri, rFrmItemSet );
185 : }
186 0 : }
187 :
188 0 : void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
189 : sal_Int16 eHoriOri,
190 : SfxItemSet& rFrmSet,
191 : sal_Bool bDontAppend )
192 : {
193 0 : sal_Bool bMoveBackward = sal_False;
194 0 : SwFmtAnchor aAnchor( FLY_AS_CHAR );
195 0 : sal_Int16 eVertRel = text::RelOrientation::FRAME;
196 :
197 0 : if( text::HoriOrientation::NONE != eHoriOri )
198 : {
199 : // den Absatz-Einzug bestimmen
200 0 : sal_uInt16 nLeftSpace = 0, nRightSpace = 0;
201 0 : short nIndent = 0;
202 0 : GetMarginsFromContextWithNumBul( nLeftSpace, nRightSpace, nIndent );
203 :
204 : // Horizonale Ausrichtung und Umlauf bestimmen.
205 : sal_Int16 eHoriRel;
206 : SwSurround eSurround;
207 0 : switch( eHoriOri )
208 : {
209 : case text::HoriOrientation::LEFT:
210 0 : eHoriRel = nLeftSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
211 0 : eSurround = SURROUND_RIGHT;
212 0 : break;
213 : case text::HoriOrientation::RIGHT:
214 0 : eHoriRel = nRightSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
215 0 : eSurround = SURROUND_LEFT;
216 0 : break;
217 : case text::HoriOrientation::CENTER: // fuer Tabellen
218 0 : eHoriRel = text::RelOrientation::FRAME;
219 0 : eSurround = SURROUND_NONE;
220 0 : break;
221 : default:
222 0 : eHoriRel = text::RelOrientation::FRAME;
223 0 : eSurround = SURROUND_PARALLEL;
224 0 : break;
225 : }
226 :
227 : // Einen neuen Absatz aufmachen, wenn der aktuelle
228 : // absatzgebundene Rahmen ohne Umlauf enthaelt.
229 0 : if( !bDontAppend && HasCurrentParaFlys( sal_True ) )
230 : {
231 : // Wenn der Absatz nur Grafiken enthaelt, braucht er
232 : // auch keinen unteren Absatz-Abstand. Da hier auch bei
233 : // Verwendung von Styles kein Abstand enstehen soll, wird
234 : // hier auch geweohnlich attributiert !!!
235 0 : sal_uInt16 nUpper=0, nLower=0;
236 0 : GetULSpaceFromContext( nUpper, nLower );
237 0 : InsertAttr( SvxULSpaceItem( nUpper, 0, RES_UL_SPACE ), sal_False, sal_True );
238 :
239 0 : AppendTxtNode( AM_NOSPACE );
240 :
241 0 : if( nUpper )
242 : {
243 0 : NewAttr( &aAttrTab.pULSpace, SvxULSpaceItem( 0, nLower, RES_UL_SPACE ) );
244 0 : aParaAttrs.push_back( aAttrTab.pULSpace );
245 0 : EndAttr( aAttrTab.pULSpace, 0, sal_False );
246 : }
247 : }
248 :
249 : // Vertikale Ausrichtung und Verankerung bestimmen.
250 0 : xub_StrLen nCntnt = pPam->GetPoint()->nContent.GetIndex();
251 0 : if( nCntnt )
252 : {
253 0 : aAnchor.SetType( FLY_AT_CHAR );
254 0 : bMoveBackward = sal_True;
255 0 : eVertOri = text::VertOrientation::CHAR_BOTTOM;
256 0 : eVertRel = text::RelOrientation::CHAR;
257 : }
258 : else
259 : {
260 0 : aAnchor.SetType( FLY_AT_PARA );
261 0 : eVertOri = text::VertOrientation::TOP;
262 0 : eVertRel = text::RelOrientation::PRINT_AREA;
263 : }
264 :
265 0 : rFrmSet.Put( SwFmtHoriOrient( 0, eHoriOri, eHoriRel) );
266 :
267 0 : rFrmSet.Put( SwFmtSurround( eSurround ) );
268 : }
269 0 : rFrmSet.Put( SwFmtVertOrient( 0, eVertOri, eVertRel) );
270 :
271 0 : if( bMoveBackward )
272 0 : pPam->Move( fnMoveBackward );
273 :
274 0 : aAnchor.SetAnchor( pPam->GetPoint() );
275 :
276 0 : if( bMoveBackward )
277 0 : pPam->Move( fnMoveForward );
278 :
279 0 : rFrmSet.Put( aAnchor );
280 0 : }
281 :
282 0 : void SwHTMLParser::RegisterFlyFrm( SwFrmFmt *pFlyFmt )
283 : {
284 : // automatisch verankerte Rahmen muessen noch um eine Position
285 : // nach vorne verschoben werden.
286 0 : if( RES_DRAWFRMFMT != pFlyFmt->Which() &&
287 0 : (FLY_AT_PARA == pFlyFmt->GetAnchor().GetAnchorId()) &&
288 0 : SURROUND_THROUGHT == pFlyFmt->GetSurround().GetSurround() )
289 : {
290 0 : aMoveFlyFrms.push_back( pFlyFmt );
291 0 : aMoveFlyCnts.push_back( pPam->GetPoint()->nContent.GetIndex() );
292 : }
293 0 : }
294 :
295 : /* */
296 :
297 0 : void SwHTMLParser::GetDefaultScriptType( ScriptType& rType,
298 : String& rTypeStr ) const
299 : {
300 0 : SwDocShell *pDocSh = pDoc->GetDocShell();
301 0 : SvKeyValueIterator* pHeaderAttrs = pDocSh ? pDocSh->GetHeaderAttributes()
302 0 : : 0;
303 0 : rType = GetScriptType( pHeaderAttrs );
304 0 : rTypeStr = GetScriptTypeString( pHeaderAttrs );
305 0 : }
306 :
307 : /* */
308 :
309 0 : void SwHTMLParser::InsertImage()
310 : {
311 : // und jetzt auswerten
312 0 : String sGrfNm, sAltNm, aId, aClass, aStyle, aMap, sHTMLGrfName;
313 0 : sal_Int16 eVertOri = text::VertOrientation::TOP;
314 0 : sal_Int16 eHoriOri = text::HoriOrientation::NONE;
315 0 : long nWidth=0, nHeight=0;
316 0 : long nVSpace=0, nHSpace=0;
317 :
318 0 : sal_uInt16 nBorder = (aAttrTab.pINetFmt ? 1 : 0);
319 0 : sal_Bool bIsMap = sal_False;
320 0 : sal_Bool bPrcWidth = sal_False;
321 0 : sal_Bool bPrcHeight = sal_False;
322 0 : SvxMacroItem aMacroItem(RES_FRMMACRO);
323 :
324 : ScriptType eDfltScriptType;
325 0 : String sDfltScriptType;
326 0 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
327 :
328 0 : const HTMLOptions& rHTMLOptions = GetOptions();
329 0 : for (size_t i = rHTMLOptions.size(); i; )
330 : {
331 0 : sal_uInt16 nEvent = 0;
332 0 : ScriptType eScriptType2 = eDfltScriptType;
333 0 : const HTMLOption& rOption = rHTMLOptions[--i];
334 0 : switch( rOption.GetToken() )
335 : {
336 : case HTML_O_ID:
337 0 : aId = rOption.GetString();
338 0 : break;
339 : case HTML_O_STYLE:
340 0 : aStyle = rOption.GetString();
341 0 : break;
342 : case HTML_O_CLASS:
343 0 : aClass = rOption.GetString();
344 0 : break;
345 : case HTML_O_SRC:
346 0 : sGrfNm = rOption.GetString();
347 0 : if( !InternalImgToPrivateURL(sGrfNm) )
348 0 : sGrfNm = INetURLObject::GetAbsURL( sBaseURL, sGrfNm );
349 0 : break;
350 : case HTML_O_ALIGN:
351 : eVertOri =
352 : rOption.GetEnum( aHTMLImgVAlignTable,
353 0 : text::VertOrientation::TOP );
354 : eHoriOri =
355 : rOption.GetEnum( aHTMLImgHAlignTable,
356 0 : text::HoriOrientation::NONE );
357 0 : break;
358 : case HTML_O_WIDTH:
359 : // erstmal nur als Pixelwerte merken!
360 0 : nWidth = rOption.GetNumber();
361 0 : bPrcWidth = (rOption.GetString().Search('%') != STRING_NOTFOUND);
362 0 : if( bPrcWidth && nWidth>100 )
363 0 : nWidth = 100;
364 0 : break;
365 : case HTML_O_HEIGHT:
366 : // erstmal nur als Pixelwerte merken!
367 0 : nHeight = rOption.GetNumber();
368 0 : bPrcHeight = (rOption.GetString().Search('%') != STRING_NOTFOUND);
369 0 : if( bPrcHeight && nHeight>100 )
370 0 : nHeight = 100;
371 0 : break;
372 : case HTML_O_VSPACE:
373 0 : nVSpace = rOption.GetNumber();
374 0 : break;
375 : case HTML_O_HSPACE:
376 0 : nHSpace = rOption.GetNumber();
377 0 : break;
378 : case HTML_O_ALT:
379 0 : sAltNm = rOption.GetString();
380 0 : break;
381 : case HTML_O_BORDER:
382 0 : nBorder = (sal_uInt16)rOption.GetNumber();
383 0 : break;
384 : case HTML_O_ISMAP:
385 0 : bIsMap = sal_True;
386 0 : break;
387 : case HTML_O_USEMAP:
388 0 : aMap = rOption.GetString();
389 0 : break;
390 : case HTML_O_NAME:
391 0 : sHTMLGrfName = rOption.GetString();
392 0 : break;
393 :
394 : case HTML_O_SDONLOAD:
395 0 : eScriptType2 = STARBASIC;
396 : case HTML_O_ONLOAD:
397 0 : nEvent = SVX_EVENT_IMAGE_LOAD;
398 0 : goto IMAGE_SETEVENT;
399 :
400 : case HTML_O_SDONABORT:
401 0 : eScriptType2 = STARBASIC;
402 : case HTML_O_ONABORT:
403 0 : nEvent = SVX_EVENT_IMAGE_ABORT;
404 0 : goto IMAGE_SETEVENT;
405 :
406 : case HTML_O_SDONERROR:
407 0 : eScriptType2 = STARBASIC;
408 : case HTML_O_ONERROR:
409 0 : nEvent = SVX_EVENT_IMAGE_ERROR;
410 0 : goto IMAGE_SETEVENT;
411 : IMAGE_SETEVENT:
412 : {
413 0 : String sTmp( rOption.GetString() );
414 0 : if( sTmp.Len() )
415 : {
416 0 : sTmp = convertLineEnd(sTmp, GetSystemLineEnd());
417 0 : String sScriptType;
418 0 : if( EXTENDED_STYPE == eScriptType2 )
419 0 : sScriptType = sDfltScriptType;
420 : aMacroItem.SetMacro( nEvent,
421 0 : SvxMacro( sTmp, sScriptType, eScriptType2 ));
422 0 : }
423 : }
424 0 : break;
425 : }
426 : }
427 :
428 0 : if( !sGrfNm.Len() )
429 : return;
430 :
431 : // Wenn wir in einer Numerierung stehen und der Absatz noch leer und
432 : // nicht numeriert ist, handelt es sich vielleicht um die Grafik
433 : // einer Bullet-Liste
434 0 : if( !pPam->GetPoint()->nContent.GetIndex() &&
435 0 : GetNumInfo().GetDepth() > 0 && GetNumInfo().GetDepth() <= MAXLEVEL &&
436 0 : aBulletGrfs[GetNumInfo().GetDepth()-1].Len() &&
437 0 : aBulletGrfs[GetNumInfo().GetDepth()-1]==sGrfNm )
438 : {
439 0 : SwTxtNode* pTxtNode = pPam->GetNode()->GetTxtNode();
440 :
441 0 : if( pTxtNode && ! pTxtNode->IsCountedInList())
442 : {
443 : OSL_ENSURE( pTxtNode->GetActualListLevel() == GetNumInfo().GetLevel(),
444 : "Numerierungs-Ebene stimmt nicht" );
445 :
446 0 : pTxtNode->SetCountedInList( true );
447 :
448 : // Rule invalisieren ist noetig, weil zwischem dem einlesen
449 : // des LI und der Grafik ein EndAction gerufen worden sein kann.
450 0 : if( GetNumInfo().GetNumRule() )
451 0 : GetNumInfo().GetNumRule()->SetInvalidRule( sal_True );
452 :
453 : // Die Vorlage novh mal setzen. Ist noetig, damit der
454 : // Erstzeilen-Einzug stimmt.
455 0 : SetTxtCollAttrs();
456 :
457 : return;
458 : }
459 : }
460 :
461 0 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
462 0 : SvxCSS1PropertyInfo aPropInfo;
463 0 : if( HasStyleOptions( aStyle, aId, aClass ) )
464 0 : ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo );
465 :
466 0 : SfxItemSet aFrmSet( pDoc->GetAttrPool(),
467 0 : RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
468 0 : if( !IsNewDoc() )
469 0 : Reader::ResetFrmFmtAttrs( aFrmSet );
470 :
471 : // Umrandung setzen
472 0 : long nHBorderWidth = 0, nVBorderWidth = 0;
473 0 : if( nBorder )
474 : {
475 0 : nHBorderWidth = (long)nBorder;
476 0 : nVBorderWidth = (long)nBorder;
477 0 : SvxCSS1Parser::PixelToTwip( nVBorderWidth, nHBorderWidth );
478 :
479 0 : ::editeng::SvxBorderLine aHBorderLine( NULL, nHBorderWidth );
480 0 : ::editeng::SvxBorderLine aVBorderLine( NULL, nVBorderWidth );
481 :
482 0 : if( aAttrTab.pINetFmt )
483 : {
484 : const String& rURL =
485 0 : ((const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem()).GetValue();
486 :
487 0 : pCSS1Parser->SetATagStyles();
488 0 : sal_uInt16 nPoolId = static_cast< sal_uInt16 >(pDoc->IsVisitedURL( rURL )
489 : ? RES_POOLCHR_INET_VISIT
490 0 : : RES_POOLCHR_INET_NORMAL);
491 0 : const SwCharFmt *pCharFmt = pCSS1Parser->GetCharFmtFromPool( nPoolId );
492 0 : aHBorderLine.SetColor( pCharFmt->GetColor().GetValue() );
493 0 : aVBorderLine.SetColor( aHBorderLine.GetColor() );
494 : }
495 : else
496 : {
497 : const SvxColorItem& rColorItem = aAttrTab.pFontColor ?
498 0 : (const SvxColorItem &)aAttrTab.pFontColor->GetItem() :
499 0 : (const SvxColorItem &)pDoc->GetDefault(RES_CHRATR_COLOR);
500 0 : aHBorderLine.SetColor( rColorItem.GetValue() );
501 0 : aVBorderLine.SetColor( aHBorderLine.GetColor() );
502 : }
503 :
504 :
505 0 : SvxBoxItem aBoxItem( RES_BOX );
506 0 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_TOP );
507 0 : aBoxItem.SetLine( &aHBorderLine, BOX_LINE_BOTTOM );
508 0 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_LEFT );
509 0 : aBoxItem.SetLine( &aVBorderLine, BOX_LINE_RIGHT );
510 0 : aFrmSet.Put( aBoxItem );
511 : }
512 :
513 : // Ausrichtung setzen
514 0 : SetAnchorAndAdjustment( eVertOri, eHoriOri, aItemSet, aPropInfo, aFrmSet );
515 :
516 : // Abstaende setzen
517 0 : SetSpace( Size( nHSpace, nVSpace), aItemSet, aPropInfo, aFrmSet );
518 :
519 : // Sonstige CSS1-Attribute Setzen
520 0 : SetFrmFmtAttrs( aItemSet, aPropInfo, HTML_FF_BOX, aFrmSet );
521 :
522 0 : Size aTwipSz( bPrcWidth ? 0 : nWidth, bPrcHeight ? 0 : nHeight );
523 0 : if( (aTwipSz.Width() || aTwipSz.Height()) && Application::GetDefaultDevice() )
524 : {
525 : aTwipSz = Application::GetDefaultDevice()
526 0 : ->PixelToLogic( aTwipSz, MapMode( MAP_TWIP ) );
527 : }
528 :
529 : // CSS1-Groesse auf "normale" Groesse umrechnen
530 0 : switch( aPropInfo.eWidthType )
531 : {
532 : case SVX_CSS1_LTYPE_TWIP:
533 0 : aTwipSz.Width() = aPropInfo.nWidth;
534 0 : nWidth = 1; // != 0
535 0 : bPrcWidth = sal_False;
536 0 : break;
537 : case SVX_CSS1_LTYPE_PERCENTAGE:
538 0 : aTwipSz.Width() = 0;
539 0 : nWidth = aPropInfo.nWidth;
540 0 : bPrcWidth = sal_True;
541 0 : break;
542 : default:
543 : ;
544 : }
545 0 : switch( aPropInfo.eHeightType )
546 : {
547 : case SVX_CSS1_LTYPE_TWIP:
548 0 : aTwipSz.Height() = aPropInfo.nHeight;
549 0 : nHeight = 1; // != 0
550 0 : bPrcHeight = sal_False;
551 0 : break;
552 : case SVX_CSS1_LTYPE_PERCENTAGE:
553 0 : aTwipSz.Height() = 0;
554 0 : nHeight = aPropInfo.nHeight;
555 0 : bPrcHeight = sal_True;
556 0 : break;
557 : default:
558 : ;
559 : }
560 :
561 0 : Size aGrfSz( 0, 0 );
562 0 : sal_Bool bSetTwipSize = sal_True; // Twip-Size am Node setzen?
563 0 : sal_Bool bChangeFrmSize = sal_False; // Frame-Format nachtraeglich anpassen?
564 0 : sal_Bool bRequestGrfNow = sal_False;
565 0 : sal_Bool bSetScaleImageMap = sal_False;
566 0 : sal_uInt8 nPrcWidth = 0, nPrcHeight = 0;
567 :
568 0 : if( !nWidth || !nHeight )
569 : {
570 : // Es fehlt die Breite oder die Hoehe
571 : // Wenn die Grfik in einer Tabelle steht, wird sie gleich
572 : // angefordert, damit sie eventuell schon da ist, bevor die
573 : // Tabelle layoutet wird.
574 0 : if( pTable!=0 && !nWidth )
575 : {
576 0 : bRequestGrfNow = sal_True;
577 0 : IncGrfsThatResizeTable();
578 : }
579 :
580 : // Die Groesse des Rahmens wird nachtraeglich gesetzt
581 0 : bChangeFrmSize = sal_True;
582 0 : aGrfSz = aTwipSz;
583 0 : if( !nWidth && !nHeight )
584 : {
585 0 : aTwipSz.Width() = HTML_DFLT_IMG_WIDTH;
586 0 : aTwipSz.Height() = HTML_DFLT_IMG_HEIGHT;
587 : }
588 0 : else if( nWidth )
589 : {
590 : // eine %-Angabe
591 0 : if( bPrcWidth )
592 : {
593 0 : nPrcWidth = (sal_uInt8)nWidth;
594 0 : nPrcHeight = 255;
595 : }
596 : else
597 : {
598 0 : aTwipSz.Height() = HTML_DFLT_IMG_HEIGHT;
599 : }
600 : }
601 0 : else if( nHeight )
602 : {
603 0 : if( bPrcHeight )
604 : {
605 0 : nPrcHeight = (sal_uInt8)nHeight;
606 0 : nPrcWidth = 255;
607 : }
608 : else
609 : {
610 0 : aTwipSz.Width() = HTML_DFLT_IMG_WIDTH;
611 : }
612 : }
613 : }
614 : else
615 : {
616 : // Breite und Hoehe wurden angegeben und brauchen nicht gesetzt
617 : // zu werden
618 0 : bSetTwipSize = sal_False;
619 :
620 0 : if( bPrcWidth )
621 0 : nPrcWidth = (sal_uInt8)nWidth;
622 :
623 0 : if( bPrcHeight )
624 0 : nPrcHeight = (sal_uInt8)nHeight;
625 : }
626 :
627 : // Image-Map setzen
628 0 : aMap = comphelper::string::stripEnd(aMap, ' ');
629 0 : if( aMap.Len() )
630 : {
631 : // Da wir nur lokale Image-Maps kennen nehmen wireinfach alles
632 : // hinter dem # als Namen
633 0 : xub_StrLen nPos = aMap.Search( '#' );
634 0 : String aName;
635 0 : if ( STRING_NOTFOUND==nPos )
636 0 : aName = aMap ;
637 : else
638 0 : aName = aMap.Copy(nPos+1);
639 :
640 0 : ImageMap *pImgMap = FindImageMap( aName );
641 0 : if( pImgMap )
642 : {
643 0 : SwFmtURL aURL; aURL.SetMap( pImgMap );//wird kopieiert
644 :
645 0 : bSetScaleImageMap = !nPrcWidth || !nPrcHeight;
646 0 : aFrmSet.Put( aURL );
647 : }
648 : else
649 : {
650 0 : ImageMap aEmptyImgMap( aName );
651 0 : SwFmtURL aURL; aURL.SetMap( &aEmptyImgMap );//wird kopieiert
652 0 : aFrmSet.Put( aURL );
653 0 : nMissingImgMaps++; // es fehlen noch Image-Maps
654 :
655 : // die Grafik muss beim SetTwipSize skaliert werden, wenn
656 : // wir keine Groesse am Node gesetzt haben oder die Groesse
657 : // nicht der Grafikgroesse entsprach.
658 0 : bSetScaleImageMap = sal_True;
659 0 : }
660 : }
661 :
662 : // min. Werte einhalten !!
663 0 : if( nPrcWidth )
664 : {
665 : OSL_ENSURE( !aTwipSz.Width(),
666 : "Wieso ist da trotz %-Angabe eine Breite gesetzt?" );
667 0 : aTwipSz.Width() = aGrfSz.Width() ? aGrfSz.Width()
668 0 : : HTML_DFLT_IMG_WIDTH;
669 : }
670 : else
671 : {
672 0 : aTwipSz.Width() += 2*nVBorderWidth;
673 0 : if( aTwipSz.Width() < MINFLY )
674 0 : aTwipSz.Width() = MINFLY;
675 : }
676 0 : if( nPrcHeight )
677 : {
678 : OSL_ENSURE( !aTwipSz.Height(),
679 : "Wieso ist da trotz %-Angabe eine Hoehe gesetzt?" );
680 0 : aTwipSz.Height() = aGrfSz.Height() ? aGrfSz.Height()
681 0 : : HTML_DFLT_IMG_HEIGHT;
682 : }
683 : else
684 : {
685 0 : aTwipSz.Height() += 2*nHBorderWidth;
686 0 : if( aTwipSz.Height() < MINFLY )
687 0 : aTwipSz.Height() = MINFLY;
688 : }
689 :
690 0 : SwFmtFrmSize aFrmSize( ATT_FIX_SIZE, aTwipSz.Width(), aTwipSz.Height() );
691 0 : aFrmSize.SetWidthPercent( nPrcWidth );
692 0 : aFrmSize.SetHeightPercent( nPrcHeight );
693 0 : aFrmSet.Put( aFrmSize );
694 :
695 0 : Graphic aEmptyGrf;
696 0 : aEmptyGrf.SetDefaultType();
697 : SwFrmFmt *pFlyFmt = pDoc->Insert( *pPam, sGrfNm, aEmptyStr, &aEmptyGrf,
698 0 : &aFrmSet, NULL, NULL );
699 0 : SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFlyFmt->GetCntnt().GetCntntIdx()
700 0 : ->GetIndex()+1 ]->GetGrfNode();
701 :
702 0 : if( sHTMLGrfName.Len() )
703 : {
704 0 : pFlyFmt->SetName( sHTMLGrfName );
705 :
706 : // ggfs. eine Grafik anspringen
707 0 : if( JUMPTO_GRAPHIC == eJumpTo && sHTMLGrfName == sJmpMark )
708 : {
709 0 : bChkJumpMark = sal_True;
710 0 : eJumpTo = JUMPTO_NONE;
711 : }
712 : }
713 :
714 0 : if( sAltNm.Len() )
715 0 : pGrfNd->SetTitle( sAltNm );
716 :
717 0 : if( bSetTwipSize )
718 0 : pGrfNd->SetTwipSize( aGrfSz );
719 :
720 0 : pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize );
721 :
722 0 : if( bSetScaleImageMap )
723 0 : pGrfNd->SetScaleImageMap( sal_True );
724 :
725 0 : if( aAttrTab.pINetFmt )
726 : {
727 : const SwFmtINetFmt &rINetFmt =
728 0 : (const SwFmtINetFmt&)aAttrTab.pINetFmt->GetItem();
729 :
730 0 : SwFmtURL aURL( pFlyFmt->GetURL() );
731 :
732 0 : aURL.SetURL( rINetFmt.GetValue(), bIsMap );
733 0 : aURL.SetTargetFrameName( rINetFmt.GetTargetFrame() );
734 0 : aURL.SetName( rINetFmt.GetName() );
735 0 : pFlyFmt->SetFmtAttr( aURL );
736 :
737 : {
738 : const SvxMacro *pMacro;
739 : static sal_uInt16 aEvents[] = {
740 : SFX_EVENT_MOUSEOVER_OBJECT,
741 : SFX_EVENT_MOUSECLICK_OBJECT,
742 : SFX_EVENT_MOUSEOUT_OBJECT,
743 : 0 };
744 :
745 0 : for( sal_uInt16 n = 0; aEvents[ n ]; ++n )
746 0 : if( 0 != ( pMacro = rINetFmt.GetMacro( aEvents[ n ] ) ))
747 0 : aMacroItem.SetMacro( aEvents[ n ], *pMacro );
748 : }
749 :
750 0 : if ((FLY_AS_CHAR == pFlyFmt->GetAnchor().GetAnchorId()) &&
751 0 : aAttrTab.pINetFmt->GetSttPara() ==
752 0 : pPam->GetPoint()->nNode &&
753 0 : aAttrTab.pINetFmt->GetSttCnt() ==
754 0 : pPam->GetPoint()->nContent.GetIndex() - 1 )
755 : {
756 : // das Attribut wurde unmitellbar vor einer zeichengeb.
757 : // Grafik eingefuegt, also verschieben wir es
758 0 : aAttrTab.pINetFmt->SetStart( *pPam->GetPoint() );
759 :
760 : // Wenn das Attribut auch ein Sprungziel ist, fuegen
761 : // wir noch eine Bookmark vor der Grafik ein, weil das
762 : // SwFmtURL kein Sprungziel ist.
763 0 : if( rINetFmt.GetName().Len() )
764 : {
765 0 : pPam->Move( fnMoveBackward );
766 0 : InsertBookmark( rINetFmt.GetName() );
767 0 : pPam->Move( fnMoveForward );
768 : }
769 0 : }
770 :
771 : }
772 :
773 0 : if( !aMacroItem.GetMacroTable().empty() )
774 0 : pFlyFmt->SetFmtAttr( aMacroItem );
775 :
776 : // Wenn die Grafik gleich angeforder wird, muss dies geschehen,
777 : // nachdem das Format vollstaendig aufgebaut ist, weil es evtl.
778 : // gleich (synchron) angepasst wird (war bug #40983#)
779 0 : if( bRequestGrfNow )
780 : {
781 0 : pGrfNd->SwapIn();
782 : }
783 :
784 : // Ggf. Frames anlegen und Auto-gebundenen Rahmen registrieren
785 0 : RegisterFlyFrm( pFlyFmt );
786 :
787 0 : if( aId.Len() )
788 0 : InsertBookmark( aId );
789 : }
790 :
791 : /* */
792 :
793 0 : void SwHTMLParser::InsertBodyOptions()
794 : {
795 : pDoc->SetTxtFmtColl( *pPam,
796 0 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_TEXT ) );
797 :
798 0 : String aBackGround, aId, aStyle, aLang, aDir;
799 0 : Color aBGColor, aTextColor, aLinkColor, aVLinkColor;
800 0 : sal_Bool bBGColor=sal_False, bTextColor=sal_False;
801 0 : sal_Bool bLinkColor=sal_False, bVLinkColor=sal_False;
802 :
803 : ScriptType eDfltScriptType;
804 0 : String sDfltScriptType;
805 0 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
806 :
807 0 : const HTMLOptions& rHTMLOptions = GetOptions();
808 0 : for (size_t i = rHTMLOptions.size(); i; )
809 : {
810 0 : const HTMLOption& rOption = rHTMLOptions[--i];
811 0 : ScriptType eScriptType2 = eDfltScriptType;
812 0 : rtl::OUString aEvent;
813 0 : sal_Bool bSetEvent = sal_False;
814 :
815 0 : switch( rOption.GetToken() )
816 : {
817 : case HTML_O_ID:
818 0 : aId = rOption.GetString();
819 0 : break;
820 : case HTML_O_BACKGROUND:
821 0 : aBackGround = rOption.GetString();
822 0 : break;
823 : case HTML_O_BGCOLOR:
824 0 : rOption.GetColor( aBGColor );
825 0 : bBGColor = sal_True;
826 0 : break;
827 : case HTML_O_TEXT:
828 0 : rOption.GetColor( aTextColor );
829 0 : bTextColor = sal_True;
830 0 : break;
831 : case HTML_O_LINK:
832 0 : rOption.GetColor( aLinkColor );
833 0 : bLinkColor = sal_True;
834 0 : break;
835 : case HTML_O_VLINK:
836 0 : rOption.GetColor( aVLinkColor );
837 0 : bVLinkColor = sal_True;
838 0 : break;
839 :
840 : case HTML_O_SDONLOAD:
841 0 : eScriptType2 = STARBASIC;
842 : case HTML_O_ONLOAD:
843 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC );
844 0 : bSetEvent = sal_True;
845 0 : break;
846 :
847 : case HTML_O_SDONUNLOAD:
848 0 : eScriptType2 = STARBASIC;
849 : case HTML_O_ONUNLOAD:
850 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC );
851 0 : bSetEvent = sal_True;
852 0 : break;
853 :
854 : case HTML_O_SDONFOCUS:
855 0 : eScriptType2 = STARBASIC;
856 : case HTML_O_ONFOCUS:
857 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC );
858 0 : bSetEvent = sal_True;
859 0 : break;
860 :
861 : case HTML_O_SDONBLUR:
862 0 : eScriptType2 = STARBASIC;
863 : case HTML_O_ONBLUR:
864 0 : aEvent = GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC );
865 0 : bSetEvent = sal_True;
866 0 : break;
867 :
868 : case HTML_O_ONERROR:
869 0 : break;
870 :
871 : case HTML_O_STYLE:
872 0 : aStyle = rOption.GetString();
873 0 : bTextColor = sal_True;
874 0 : break;
875 : case HTML_O_LANG:
876 0 : aLang = rOption.GetString();
877 0 : break;
878 : case HTML_O_DIR:
879 0 : aDir = rOption.GetString();
880 0 : break;
881 : }
882 :
883 0 : if( bSetEvent )
884 : {
885 0 : const String& rEvent = rOption.GetString();
886 0 : if( rEvent.Len() )
887 : InsertBasicDocEvent( aEvent, rEvent, eScriptType2,
888 0 : sDfltScriptType );
889 : }
890 0 : }
891 :
892 0 : if( bTextColor && !pCSS1Parser->IsBodyTextSet() )
893 : {
894 : // Die Textfarbe wird an der Standard-Vorlage gesetzt
895 0 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
896 0 : ->SetFmtAttr( SvxColorItem(aTextColor, RES_CHRATR_COLOR) );
897 0 : pCSS1Parser->SetBodyTextSet();
898 : }
899 :
900 :
901 : // Die Item fuer die Seitenvorlage vorbereiten (Hintergrund, Umrandung)
902 : // Beim BrushItem muessen schon gesetzte werte erhalten bleiben!
903 0 : SvxBrushItem aBrushItem( pCSS1Parser->GetPageDescBackground() );
904 0 : sal_Bool bSetBrush = sal_False;
905 :
906 0 : if( bBGColor && !pCSS1Parser->IsBodyBGColorSet() )
907 : {
908 : // Hintergrundfarbe aus "BGCOLOR"
909 0 : String aLink;
910 0 : if( aBrushItem.GetGraphicLink() )
911 0 : aLink = *aBrushItem.GetGraphicLink();
912 0 : SvxGraphicPosition ePos = aBrushItem.GetGraphicPos();
913 :
914 0 : aBrushItem.SetColor( aBGColor );
915 :
916 0 : if( aLink.Len() )
917 : {
918 0 : aBrushItem.SetGraphicLink( aLink );
919 0 : aBrushItem.SetGraphicPos( ePos );
920 : }
921 0 : bSetBrush = sal_True;
922 0 : pCSS1Parser->SetBodyBGColorSet();
923 : }
924 :
925 0 : if( aBackGround.Len() && !pCSS1Parser->IsBodyBackgroundSet() )
926 : {
927 : // Hintergrundgrafik aus "BACKGROUND"
928 0 : aBrushItem.SetGraphicLink( INetURLObject::GetAbsURL( sBaseURL, aBackGround ) );
929 0 : aBrushItem.SetGraphicPos( GPOS_TILED );
930 0 : bSetBrush = sal_True;
931 0 : pCSS1Parser->SetBodyBackgroundSet();
932 : }
933 :
934 0 : if( aStyle.Len() || aDir.Len() )
935 : {
936 0 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
937 0 : SvxCSS1PropertyInfo aPropInfo;
938 0 : String aDummy;
939 0 : ParseStyleOptions( aStyle, aDummy, aDummy, aItemSet, aPropInfo, 0, &aDir );
940 :
941 : // Ein par Attribute muessen an der Seitenvorlage gesetzt werden,
942 : // und zwar die, die nicht vererbit werden
943 : pCSS1Parser->SetPageDescAttrs( bSetBrush ? &aBrushItem : 0,
944 0 : &aItemSet );
945 :
946 : const SfxPoolItem *pItem;
947 : static sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONTSIZE,
948 : RES_CHRATR_CJK_FONTSIZE,
949 : RES_CHRATR_CTL_FONTSIZE };
950 0 : for( sal_uInt16 i=0; i<3; i++ )
951 : {
952 0 : if( SFX_ITEM_SET == aItemSet.GetItemState( aWhichIds[i], sal_False,
953 0 : &pItem ) &&
954 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() != 100)
955 : {
956 : sal_uInt32 nHeight =
957 0 : ( aFontHeights[2] *
958 0 : static_cast <const SvxFontHeightItem * >(pItem)->GetProp() ) / 100;
959 0 : SvxFontHeightItem aNewItem( nHeight, 100, aWhichIds[i] );
960 0 : aItemSet.Put( aNewItem );
961 : }
962 : }
963 :
964 : // alle noch uebrigen Optionen koennen an der Standard-Vorlage
965 : // gesetzt werden und gelten dann automatisch als defaults
966 0 : pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_STANDARD )
967 0 : ->SetFmtAttr( aItemSet );
968 : }
969 0 : else if( bSetBrush )
970 : {
971 0 : pCSS1Parser->SetPageDescAttrs( &aBrushItem );
972 : }
973 :
974 0 : if( bLinkColor && !pCSS1Parser->IsBodyLinkSet() )
975 : {
976 : SwCharFmt *pCharFmt =
977 0 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_NORMAL);
978 0 : pCharFmt->SetFmtAttr( SvxColorItem(aLinkColor, RES_CHRATR_COLOR) );
979 0 : pCSS1Parser->SetBodyLinkSet();
980 : }
981 0 : if( bVLinkColor && !pCSS1Parser->IsBodyVLinkSet() )
982 : {
983 : SwCharFmt *pCharFmt =
984 0 : pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_INET_VISIT);
985 0 : pCharFmt->SetFmtAttr( SvxColorItem(aVLinkColor, RES_CHRATR_COLOR) );
986 0 : pCSS1Parser->SetBodyVLinkSet();
987 : }
988 0 : if( aLang.Len() )
989 : {
990 0 : LanguageType eLang = LanguageTag( aLang ).getLanguageType();
991 0 : if( LANGUAGE_DONTKNOW != eLang )
992 : {
993 0 : sal_uInt16 nWhich = 0;
994 0 : switch( SvtLanguageOptions::GetScriptTypeOfLanguage( eLang ) )
995 : {
996 : case SCRIPTTYPE_LATIN:
997 0 : nWhich = RES_CHRATR_LANGUAGE;
998 0 : break;
999 : case SCRIPTTYPE_ASIAN:
1000 0 : nWhich = RES_CHRATR_CJK_LANGUAGE;
1001 0 : break;
1002 : case SCRIPTTYPE_COMPLEX:
1003 0 : nWhich = RES_CHRATR_CTL_LANGUAGE;
1004 0 : break;
1005 : }
1006 0 : if( nWhich )
1007 : {
1008 0 : SvxLanguageItem aLanguage( eLang, nWhich );
1009 0 : aLanguage.SetWhich( nWhich );
1010 0 : pDoc->SetDefault( aLanguage );
1011 : }
1012 : }
1013 : }
1014 :
1015 0 : if( aId.Len() )
1016 0 : InsertBookmark( aId );
1017 0 : }
1018 :
1019 : /* */
1020 :
1021 0 : void SwHTMLParser::NewAnchor()
1022 : {
1023 : // den voherigen Link beenden, falls es einen gab
1024 0 : _HTMLAttrContext *pOldCntxt = PopContext( HTML_ANCHOR_ON );
1025 0 : if( pOldCntxt )
1026 : {
1027 : // und ggf. die Attribute beenden
1028 0 : EndContext( pOldCntxt );
1029 0 : delete pOldCntxt;
1030 : }
1031 :
1032 0 : SvxMacroTableDtor aMacroTbl;
1033 0 : String sHRef, aName, sTarget;
1034 0 : String aId, aStyle, aClass, aLang, aDir;
1035 0 : sal_Bool bHasHRef = sal_False, bFixed = sal_False;
1036 :
1037 : ScriptType eDfltScriptType;
1038 0 : String sDfltScriptType;
1039 0 : GetDefaultScriptType( eDfltScriptType, sDfltScriptType );
1040 :
1041 0 : const HTMLOptions& rHTMLOptions = GetOptions();
1042 0 : for (size_t i = rHTMLOptions.size(); i; )
1043 : {
1044 0 : sal_uInt16 nEvent = 0;
1045 0 : ScriptType eScriptType2 = eDfltScriptType;
1046 0 : const HTMLOption& rOption = rHTMLOptions[--i];
1047 0 : switch( rOption.GetToken() )
1048 : {
1049 : case HTML_O_NAME:
1050 0 : aName = rOption.GetString();
1051 0 : break;
1052 :
1053 : case HTML_O_HREF:
1054 0 : sHRef = rOption.GetString();
1055 0 : bHasHRef = sal_True;
1056 0 : break;
1057 : case HTML_O_TARGET:
1058 0 : sTarget = rOption.GetString();
1059 0 : break;
1060 :
1061 : case HTML_O_STYLE:
1062 0 : aStyle = rOption.GetString();
1063 0 : break;
1064 : case HTML_O_ID:
1065 0 : aId = rOption.GetString();
1066 0 : break;
1067 : case HTML_O_CLASS:
1068 0 : aClass = rOption.GetString();
1069 0 : break;
1070 : case HTML_O_SDFIXED:
1071 0 : bFixed = sal_True;
1072 0 : break;
1073 : case HTML_O_LANG:
1074 0 : aLang = rOption.GetString();
1075 0 : break;
1076 : case HTML_O_DIR:
1077 0 : aDir = rOption.GetString();
1078 0 : break;
1079 :
1080 : case HTML_O_SDONCLICK:
1081 0 : eScriptType2 = STARBASIC;
1082 : case HTML_O_ONCLICK:
1083 0 : nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
1084 0 : goto ANCHOR_SETEVENT;
1085 :
1086 : case HTML_O_SDONMOUSEOVER:
1087 0 : eScriptType2 = STARBASIC;
1088 : case HTML_O_ONMOUSEOVER:
1089 0 : nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
1090 0 : goto ANCHOR_SETEVENT;
1091 :
1092 : case HTML_O_SDONMOUSEOUT:
1093 0 : eScriptType2 = STARBASIC;
1094 : case HTML_O_ONMOUSEOUT:
1095 0 : nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
1096 0 : goto ANCHOR_SETEVENT;
1097 : ANCHOR_SETEVENT:
1098 : {
1099 0 : String sTmp( rOption.GetString() );
1100 0 : if( sTmp.Len() )
1101 : {
1102 0 : sTmp = convertLineEnd(sTmp, GetSystemLineEnd());
1103 0 : String sScriptType;
1104 0 : if( EXTENDED_STYPE == eScriptType2 )
1105 0 : sScriptType = sDfltScriptType;
1106 0 : aMacroTbl.Insert( nEvent, SvxMacro( sTmp, sScriptType, eScriptType2 ));
1107 0 : }
1108 : }
1109 0 : break;
1110 :
1111 : }
1112 : }
1113 :
1114 : // Sprungziele, die unseren ipmliziten Zielen entsprechen, schmeissen
1115 : // wir hier ganz rigoros raus.
1116 0 : if( aName.Len() )
1117 : {
1118 : String sDecoded( INetURLObject::decode( aName, INET_HEX_ESCAPE,
1119 : INetURLObject::DECODE_UNAMBIGUOUS,
1120 0 : RTL_TEXTENCODING_UTF8 ));
1121 0 : xub_StrLen nPos = sDecoded.SearchBackward( cMarkSeperator );
1122 0 : if( STRING_NOTFOUND != nPos )
1123 : {
1124 0 : String sCmp(comphelper::string::remove(sDecoded.Copy(nPos+1), ' '));
1125 0 : if( sCmp.Len() )
1126 : {
1127 0 : sCmp.ToLowerAscii();
1128 0 : if( sCmp.EqualsAscii( pMarkToRegion ) ||
1129 0 : sCmp.EqualsAscii( pMarkToFrame ) ||
1130 0 : sCmp.EqualsAscii( pMarkToGraphic ) ||
1131 0 : sCmp.EqualsAscii( pMarkToOLE ) ||
1132 0 : sCmp.EqualsAscii( pMarkToTable ) ||
1133 0 : sCmp.EqualsAscii( pMarkToOutline ) ||
1134 0 : sCmp.EqualsAscii( pMarkToText ) )
1135 : {
1136 0 : aName.Erase();
1137 : }
1138 0 : }
1139 0 : }
1140 : }
1141 :
1142 : // einen neuen Kontext anlegen
1143 0 : _HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_ANCHOR_ON );
1144 :
1145 0 : sal_Bool bEnAnchor = sal_False, bFtnAnchor = sal_False, bFtnEnSymbol = sal_False;
1146 0 : String aFtnName;
1147 0 : String aStrippedClass( aClass );
1148 0 : SwCSS1Parser::GetScriptFromClass( aStrippedClass, sal_False );
1149 0 : if( aStrippedClass.Len() >=9 && bHasHRef && sHRef.Len() > 1 &&
1150 0 : ('s' == aStrippedClass.GetChar(0) || 'S' == aStrippedClass.GetChar(0)) &&
1151 0 : ('d' == aStrippedClass.GetChar(1) || 'D' == aStrippedClass.GetChar(1)) )
1152 : {
1153 0 : if( aStrippedClass.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_sdendnote_anc ) )
1154 0 : bEnAnchor = sal_True;
1155 0 : else if( aStrippedClass.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_sdfootnote_anc ) )
1156 0 : bFtnAnchor = sal_True;
1157 0 : else if( aStrippedClass.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_sdendnote_sym ) ||
1158 0 : aStrippedClass.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_sdfootnote_sym ) )
1159 0 : bFtnEnSymbol = sal_True;
1160 0 : if( bEnAnchor || bFtnAnchor || bFtnEnSymbol )
1161 : {
1162 0 : aFtnName = sHRef.Copy( 1 );
1163 0 : aClass = aStrippedClass = aName = aEmptyStr;
1164 0 : bHasHRef = sal_False;
1165 : }
1166 : }
1167 :
1168 : // Styles parsen
1169 0 : if( HasStyleOptions( aStyle, aId, aStrippedClass, &aLang, &aDir ) )
1170 : {
1171 0 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
1172 0 : SvxCSS1PropertyInfo aPropInfo;
1173 :
1174 0 : if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
1175 : {
1176 0 : DoPositioning( aItemSet, aPropInfo, pCntxt );
1177 0 : InsertAttrs( aItemSet, aPropInfo, pCntxt, sal_True );
1178 0 : }
1179 : }
1180 :
1181 0 : if( bHasHRef )
1182 : {
1183 0 : if( sHRef.Len() )
1184 : {
1185 0 : sHRef = URIHelper::SmartRel2Abs( INetURLObject(sBaseURL), sHRef, Link(), false );
1186 : }
1187 : else
1188 : {
1189 : // Bei leerer URL das Directory nehmen
1190 0 : INetURLObject aURLObj( aPathToFile );
1191 0 : sHRef = aURLObj.GetPartBeforeLastName();
1192 : }
1193 :
1194 0 : pCSS1Parser->SetATagStyles();
1195 0 : SwFmtINetFmt aINetFmt( sHRef, sTarget );
1196 0 : aINetFmt.SetName( aName );
1197 :
1198 0 : if( !aMacroTbl.empty() )
1199 0 : aINetFmt.SetMacroTbl( &aMacroTbl );
1200 :
1201 : // das Default-Attribut setzen
1202 0 : InsertAttr( &aAttrTab.pINetFmt, aINetFmt, pCntxt );
1203 : }
1204 0 : else if( aName.Len() )
1205 : {
1206 0 : InsertBookmark( aName );
1207 : }
1208 :
1209 0 : if( bEnAnchor || bFtnAnchor )
1210 : {
1211 0 : InsertFootEndNote( aFtnName, bEnAnchor, bFixed );
1212 0 : bInFootEndNoteAnchor = bCallNextToken = sal_True;
1213 : }
1214 0 : else if( bFtnEnSymbol )
1215 : {
1216 0 : bInFootEndNoteSymbol = bCallNextToken = sal_True;
1217 : }
1218 :
1219 : // den Kontext merken
1220 0 : PushContext( pCntxt );
1221 0 : }
1222 :
1223 0 : void SwHTMLParser::EndAnchor()
1224 : {
1225 0 : if( bInFootEndNoteAnchor )
1226 : {
1227 0 : FinishFootEndNote();
1228 0 : bInFootEndNoteAnchor = sal_False;
1229 : }
1230 0 : else if( bInFootEndNoteSymbol )
1231 : {
1232 0 : bInFootEndNoteSymbol = sal_False;
1233 : }
1234 :
1235 0 : EndTag( HTML_ANCHOR_OFF );
1236 0 : }
1237 :
1238 : /* */
1239 :
1240 0 : void SwHTMLParser::InsertBookmark( const String& rName )
1241 : {
1242 0 : _HTMLAttr* pTmp = new _HTMLAttr( *pPam->GetPoint(),
1243 0 : SfxStringItem( RES_FLTR_BOOKMARK, rName ));
1244 0 : aSetAttrTab.push_back( pTmp );
1245 0 : }
1246 :
1247 0 : sal_Bool SwHTMLParser::HasCurrentParaBookmarks( sal_Bool bIgnoreStack ) const
1248 : {
1249 0 : sal_Bool bHasMarks = sal_False;
1250 0 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1251 :
1252 : // first step: are there still bookmark in the attribute-stack?
1253 : // bookmarks are added to the end of the stack - thus we only have
1254 : // to check the last bookmark
1255 0 : if( !bIgnoreStack )
1256 : {
1257 : _HTMLAttr* pAttr;
1258 0 : for( sal_uInt16 i = aSetAttrTab.size(); i; )
1259 : {
1260 0 : pAttr = aSetAttrTab[ --i ];
1261 0 : if( RES_FLTR_BOOKMARK == pAttr->pItem->Which() )
1262 : {
1263 0 : if( pAttr->GetSttParaIdx() == nNodeIdx )
1264 0 : bHasMarks = sal_True;
1265 0 : break;
1266 : }
1267 : }
1268 : }
1269 :
1270 0 : if( !bHasMarks )
1271 : {
1272 : // second step: when we didnt find a bookmark, check if there is one
1273 : // set already
1274 0 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1275 0 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
1276 0 : ppMark != pMarkAccess->getMarksEnd();
1277 : ++ppMark)
1278 : {
1279 0 : const ::sw::mark::IMark* pBookmark = ppMark->get();
1280 0 : sal_uLong nBookNdIdx = pBookmark->GetMarkPos().nNode.GetIndex();
1281 0 : if( nBookNdIdx==nNodeIdx )
1282 : {
1283 0 : bHasMarks = sal_True;
1284 0 : break;
1285 : }
1286 0 : else if( nBookNdIdx > nNodeIdx )
1287 0 : break;
1288 : }
1289 : }
1290 :
1291 0 : return bHasMarks;
1292 : }
1293 :
1294 : /* */
1295 :
1296 0 : void SwHTMLParser::StripTrailingPara()
1297 : {
1298 0 : sal_Bool bSetSmallFont = sal_False;
1299 :
1300 0 : SwCntntNode* pCNd = pPam->GetCntntNode();
1301 0 : if( !pPam->GetPoint()->nContent.GetIndex() )
1302 : {
1303 0 : if( pCNd && pCNd->StartOfSectionIndex()+2 <
1304 0 : pCNd->EndOfSectionIndex() )
1305 : {
1306 0 : sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
1307 :
1308 0 : const SwFrmFmts& rFrmFmtTbl = *pDoc->GetSpzFrmFmts();
1309 :
1310 0 : for( sal_uInt16 i=0; i<rFrmFmtTbl.size(); i++ )
1311 : {
1312 0 : SwFrmFmt const*const pFmt = rFrmFmtTbl[i];
1313 0 : SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
1314 0 : SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
1315 0 : if (pAPos &&
1316 0 : ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
1317 0 : (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
1318 0 : pAPos->nNode == nNodeIdx )
1319 :
1320 0 : return; // den Knoten duerfen wir nicht loeschen
1321 : }
1322 :
1323 0 : SetAttr( sal_False ); // die noch offenen Attribute muessen
1324 : // beendet werden, bevor der Node
1325 : // geloescht wird, weil sonst der
1326 : // End-Index in die Botanik zeigt
1327 :
1328 0 : if( pCNd->Len() && pCNd->IsTxtNode() )
1329 : {
1330 : // es wurden Felder in den Node eingefuegt, die muessen
1331 : // wir jetzt verschieben
1332 0 : SwTxtNode *pPrvNd = pDoc->GetNodes()[nNodeIdx-1]->GetTxtNode();
1333 0 : if( pPrvNd )
1334 : {
1335 0 : SwIndex aSrc( pCNd, 0 );
1336 0 : pCNd->GetTxtNode()->CutText( pPrvNd, aSrc, pCNd->Len() );
1337 : }
1338 : }
1339 :
1340 : // jetz muessen wir noch eventuell vorhandene Bookmarks
1341 : // verschieben
1342 0 : IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
1343 0 : for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
1344 0 : ppMark != pMarkAccess->getMarksEnd();
1345 : ++ppMark)
1346 : {
1347 0 : ::sw::mark::IMark* pMark = ppMark->get();
1348 0 : sal_uLong nBookNdIdx = pMark->GetMarkPos().nNode.GetIndex();
1349 0 : if(nBookNdIdx==nNodeIdx)
1350 : {
1351 0 : SwNodeIndex nNewNdIdx(pPam->GetPoint()->nNode);
1352 0 : SwCntntNode* pNd = pDoc->GetNodes().GoPrevious(&nNewNdIdx);
1353 0 : if(!pNd)
1354 : {
1355 : OSL_ENSURE(!this, "Hoppla, wo ist mein Vorgaenger-Node");
1356 : return;
1357 : }
1358 : // #i81002# - refactoring
1359 : // Do not directly manipulate member of <SwBookmark>
1360 : {
1361 0 : SwPosition aNewPos(*pNd);
1362 0 : aNewPos.nContent.Assign(pNd, pNd->Len());
1363 0 : const SwPaM aPaM(aNewPos);
1364 0 : pMarkAccess->repositionMark(ppMark->get(), aPaM);
1365 0 : }
1366 : }
1367 0 : else if( nBookNdIdx > nNodeIdx )
1368 0 : break;
1369 : }
1370 :
1371 0 : pPam->GetPoint()->nContent.Assign( 0, 0 );
1372 0 : pPam->SetMark();
1373 0 : pPam->DeleteMark();
1374 0 : pDoc->GetNodes().Delete( pPam->GetPoint()->nNode );
1375 0 : pPam->Move( fnMoveBackward, fnGoNode );
1376 : }
1377 0 : else if( pCNd && pCNd->IsTxtNode() && pTable )
1378 : {
1379 : // In leeren Zellen stellen wir einen kleinen Font ein, damit die
1380 : // Zelle nicht hoeher wird als die Grafik bzw. so niedrig wie
1381 : // moeglich bleibt.
1382 0 : bSetSmallFont = sal_True;
1383 : }
1384 : }
1385 0 : else if( pCNd && pCNd->IsTxtNode() && pTable &&
1386 0 : pCNd->StartOfSectionIndex()+2 ==
1387 0 : pCNd->EndOfSectionIndex() )
1388 : {
1389 : // Wenn die Zelle nur zeichengebundene Grafiken/Rahmen enthaelt
1390 : // stellen wir ebenfalls einen kleinen Font ein.
1391 0 : bSetSmallFont = sal_True;
1392 0 : SwTxtNode* pTxtNd = pCNd->GetTxtNode();
1393 :
1394 0 : xub_StrLen nPos = pPam->GetPoint()->nContent.GetIndex();
1395 0 : while( bSetSmallFont && nPos>0 )
1396 : {
1397 0 : --nPos;
1398 : bSetSmallFont =
1399 0 : (CH_TXTATR_BREAKWORD == pTxtNd->GetTxt().GetChar( nPos )) &&
1400 0 : (0 != pTxtNd->GetTxtAttrForCharAt( nPos, RES_TXTATR_FLYCNT ));
1401 : }
1402 : }
1403 :
1404 0 : if( bSetSmallFont )
1405 : {
1406 : //Added default to CJK and CTL
1407 0 : SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
1408 0 : pCNd->SetAttr( aFontHeight );
1409 0 : SvxFontHeightItem aFontHeightCJK( 40, 100, RES_CHRATR_CJK_FONTSIZE );
1410 0 : pCNd->SetAttr( aFontHeightCJK );
1411 0 : SvxFontHeightItem aFontHeightCTL( 40, 100, RES_CHRATR_CTL_FONTSIZE );
1412 0 : pCNd->SetAttr( aFontHeightCTL );
1413 : }
1414 : }
1415 :
1416 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|