Update ooo320-m1
[ooovba.git] / sw / source / core / doc / notxtfrm.cxx
blob878429017200809df3314f3ee733edfdd5e5e02f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: notxtfrm.cxx,v $
10 * $Revision: 1.43.54.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <tools/urlobj.hxx>
37 #include <vcl/print.hxx>
38 #include <vcl/virdev.hxx>
39 #include <vcl/svapp.hxx>
40 #include <svtools/imapobj.hxx>
41 #include <svtools/imap.hxx>
42 #include <svtools/urihelper.hxx>
43 #include <svtools/soerr.hxx>
44 #include <sfx2/progress.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <sfx2/printer.hxx>
47 #include <svx/udlnitem.hxx>
48 #include <svx/colritem.hxx>
49 #include <svx/xoutbmp.hxx>
50 #include <vcl/window.hxx>
51 #include <fmturl.hxx>
52 #include <fmtsrnd.hxx>
53 #include <frmfmt.hxx>
54 #include <swrect.hxx>
55 #include <fesh.hxx>
56 #include <doc.hxx>
57 #include <flyfrm.hxx>
58 #include <frmtool.hxx>
59 #include <viewopt.hxx>
60 #include <viewimp.hxx>
61 #include <pam.hxx>
62 #include <hints.hxx>
63 #include <rootfrm.hxx>
64 #include <dflyobj.hxx>
65 #include <pagefrm.hxx>
66 #include <notxtfrm.hxx>
67 #include <grfatr.hxx>
68 #include <charatr.hxx>
69 #include <fmtornt.hxx>
70 #include <ndnotxt.hxx>
71 #include <ndgrf.hxx>
72 #include <ndole.hxx>
73 #include <swregion.hxx>
74 #include <poolfmt.hxx>
75 #include <mdiexp.hxx>
76 #include <swwait.hxx>
77 #ifndef _COMCORE_HRC
78 #include <comcore.hrc>
79 #endif
80 #include <accessibilityoptions.hxx>
81 #include <com/sun/star/embed/EmbedMisc.hpp>
82 #include <com/sun/star/embed/EmbedStates.hpp>
84 #include <svtools/embedhlp.hxx>
85 #include <svtools/chartprettypainter.hxx>
86 // --> OD 2009-03-05 #i99665#
87 #include <dview.hxx>
88 // <--
90 using namespace com::sun::star;
92 #define DEFTEXTSIZE 12
94 extern void ClrContourCache( const SdrObject *pObj ); // TxtFly.Cxx
97 inline BOOL GetRealURL( const SwGrfNode& rNd, String& rTxt )
99 BOOL bRet = rNd.GetFileFilterNms( &rTxt, 0 );
100 if( bRet )
101 rTxt = URIHelper::removePassword( rTxt, INetURLObject::WAS_ENCODED,
102 INetURLObject::DECODE_UNAMBIGUOUS);
103 return bRet;
106 void lcl_PaintReplacement( const SwRect &rRect, const String &rText,
107 const ViewShell &rSh, const SwNoTxtFrm *pFrm,
108 BOOL bDefect )
110 static Font *pFont = 0;
111 if ( !pFont )
113 pFont = new Font();
114 pFont->SetWeight( WEIGHT_BOLD );
115 pFont->SetStyleName( aEmptyStr );
116 pFont->SetName( String::CreateFromAscii(
117 RTL_CONSTASCII_STRINGPARAM( "Arial Unicode" )));
118 pFont->SetFamily( FAMILY_SWISS );
119 pFont->SetTransparent( TRUE );
122 Color aCol( COL_RED );
123 FontUnderline eUnderline = UNDERLINE_NONE;
124 const SwFmtURL &rURL = pFrm->FindFlyFrm()->GetFmt()->GetURL();
125 if( rURL.GetURL().Len() || rURL.GetMap() )
127 BOOL bVisited = FALSE;
128 if ( rURL.GetMap() )
130 ImageMap *pMap = (ImageMap*)rURL.GetMap();
131 for( USHORT i = 0; i < pMap->GetIMapObjectCount(); i++ )
133 IMapObject *pObj = pMap->GetIMapObject( i );
134 if( rSh.GetDoc()->IsVisitedURL( pObj->GetURL() ) )
136 bVisited = TRUE;
137 break;
141 else if ( rURL.GetURL().Len() )
142 bVisited = rSh.GetDoc()->IsVisitedURL( rURL.GetURL() );
144 SwFmt *pFmt = rSh.GetDoc()->GetFmtFromPool( static_cast<sal_uInt16>
145 (bVisited ? RES_POOLCHR_INET_VISIT : RES_POOLCHR_INET_NORMAL ) );
146 aCol = pFmt->GetColor().GetValue();
147 eUnderline = pFmt->GetUnderline().GetLineStyle();
150 pFont->SetUnderline( eUnderline );
151 pFont->SetColor( aCol );
153 const BitmapEx& rBmp = ViewShell::GetReplacementBitmap( bDefect != FALSE );
154 Graphic::DrawEx( rSh.GetOut(), rText, *pFont, rBmp, rRect.Pos(), rRect.SSize() );
157 /*************************************************************************
159 |* SwGrfFrm::SwGrfFrm(ViewShell * const,SwGrfNode *)
161 |* Beschreibung
162 |* Ersterstellung JP 05.03.91
163 |* Letzte Aenderung MA 03. Mar. 93
165 *************************************************************************/
168 SwNoTxtFrm::SwNoTxtFrm(SwNoTxtNode * const pNode)
169 : SwCntntFrm(pNode)
171 InitCtor();
174 // Initialisierung: z.Zt. Eintragen des Frames im Cache
177 void SwNoTxtFrm::InitCtor()
179 nType = FRMC_NOTXT;
180 // Das Gewicht der Grafik ist 0, wenn sie noch nicht
181 // gelesen ist, < 0, wenn ein Lesefehler auftrat und
182 // Ersatzdarstellung angewendet werden musste und >0,
183 // wenn sie zur Verfuegung steht.
184 nWeight = 0;
187 /*************************************************************************
189 |* SwNoTxtNode::MakeFrm()
191 |* Beschreibung
192 |* Ersterstellung JP 05.03.91
193 |* Letzte Aenderung MA 03. Mar. 93
195 *************************************************************************/
198 SwCntntFrm *SwNoTxtNode::MakeFrm()
200 return new SwNoTxtFrm(this);
203 /*************************************************************************
205 |* SwNoTxtFrm::~SwNoTxtFrm()
207 |* Beschreibung
208 |* Ersterstellung JP 05.03.91
209 |* Letzte Aenderung MA 30. Apr. 96
211 *************************************************************************/
213 SwNoTxtFrm::~SwNoTxtFrm()
215 StopAnimation();
218 /*************************************************************************
220 |* void SwNoTxtFrm::Modify( SwHint * pOld, SwHint * pNew )
222 |* Beschreibung
223 |* Ersterstellung JP 05.03.91
224 |* Letzte Aenderung JP 05.03.91
226 *************************************************************************/
228 void SetOutDev( ViewShell *pSh, OutputDevice *pOut )
230 pSh->pOut = pOut;
236 void lcl_ClearArea( const SwFrm &rFrm,
237 OutputDevice &rOut, const SwRect& rPtArea,
238 const SwRect &rGrfArea )
240 SwRegionRects aRegion( rPtArea, 4, 4 );
241 aRegion -= rGrfArea;
243 if ( aRegion.Count() )
245 const SvxBrushItem *pItem; const Color *pCol; SwRect aOrigRect;
246 if ( rFrm.GetBackgroundBrush( pItem, pCol, aOrigRect, FALSE ) )
247 for( USHORT i = 0; i < aRegion.Count(); ++i )
248 ::DrawGraphic( pItem, &rOut, aOrigRect, aRegion[i] );
249 else
251 // OD 2004-04-23 #116347#
252 rOut.Push( PUSH_FILLCOLOR|PUSH_LINECOLOR );
253 rOut.SetFillColor( rFrm.GetShell()->Imp()->GetRetoucheColor());
254 rOut.SetLineColor();
255 for( USHORT i = 0; i < aRegion.Count(); ++i )
256 rOut.DrawRect( aRegion[i].SVRect() );
257 rOut.Pop();
262 /*************************************************************************
264 |* void SwNoTxtFrm::Paint()
266 |* Beschreibung
267 |* Ersterstellung JP 05.03.91
268 |* Letzte Aenderung MA 10. Jan. 97
270 *************************************************************************/
272 void SwNoTxtFrm::Paint( const SwRect &rRect ) const
274 if ( Frm().IsEmpty() )
275 return;
277 const ViewShell* pSh = GetShell();
278 if( !pSh->GetViewOptions()->IsGraphic() )
280 StopAnimation();
281 // OD 10.01.2003 #i6467# - no paint of placeholder for page preview
282 if ( pSh->GetWin() && !pSh->IsPreView() )
284 const SwNoTxtNode* pNd = GetNode()->GetNoTxtNode();
285 String aTxt( pNd->GetTitle() );
286 if ( !aTxt.Len() && pNd->IsGrfNode() )
287 GetRealURL( *(SwGrfNode*)pNd, aTxt );
288 if( !aTxt.Len() )
289 aTxt = FindFlyFrm()->GetFmt()->GetName();
290 lcl_PaintReplacement( Frm(), aTxt, *pSh, this, FALSE );
292 return;
295 if( pSh->GetAccessibilityOptions()->IsStopAnimatedGraphics() ||
296 // --> FME 2004-06-21 #i9684# Stop animation during printing/pdf export
297 !pSh->GetWin() )
298 // <--
299 StopAnimation();
301 if ( pSh->Imp()->IsPaintInScroll() && pSh->GetWin() && rRect != Frm() &&
302 HasAnimation() )
304 pSh->GetWin()->Invalidate( Frm().SVRect() );
305 return;
309 SfxProgress::EnterLock(); //Keine Progress-Reschedules im Paint (SwapIn)
311 OutputDevice *pOut = pSh->GetOut();
312 pOut->Push();
313 BOOL bClip = TRUE;
314 PolyPolygon aPoly;
316 SwNoTxtNode& rNoTNd = *(SwNoTxtNode*)GetNode();
317 SwGrfNode* pGrfNd = rNoTNd.GetGrfNode();
318 if( pGrfNd )
319 pGrfNd->SetFrameInPaint( TRUE );
321 // OD 16.04.2003 #i13147# - add 2nd parameter with value <sal_True> to
322 // method call <FindFlyFrm().GetContour(..)> to indicate that it is called
323 // for paint in order to avoid load of the intrinsic graphic.
324 if ( ( !pOut->GetConnectMetaFile() ||
325 !pSh->GetWin() ) &&
326 FindFlyFrm()->GetContour( aPoly, sal_True )
329 pOut->SetClipRegion( aPoly );
330 bClip = FALSE;
333 SwRect aOrigPaint( rRect );
334 if ( HasAnimation() && pSh->GetWin() )
336 aOrigPaint = Frm(); aOrigPaint += Prt().Pos();
339 SwRect aGrfArea( Frm() );
340 SwRect aPaintArea( aGrfArea );
341 aPaintArea._Intersection( aOrigPaint );
343 SwRect aNormal( Frm().Pos() + Prt().Pos(), Prt().SSize() );
344 aNormal.Justify(); //Normalisiertes Rechteck fuer die Vergleiche
346 if( aPaintArea.IsOver( aNormal ) )
348 // berechne die 4 zu loeschenden Rechtecke
349 if( pSh->GetWin() )
350 ::lcl_ClearArea( *this, *pSh->GetOut(), aPaintArea, aNormal );
352 // in der Schnittmenge vom PaintBereich und der Bitmap liegt
353 // der absolut sichtbare Bereich vom Frame
354 aPaintArea._Intersection( aNormal );
356 if ( bClip )
357 pOut->IntersectClipRegion( aPaintArea.SVRect() );
358 /// OD 25.09.2002 #99739# - delete unused 3rd parameter
359 PaintPicture( pOut, aGrfArea );
361 else
362 // wenn nicht sichtbar, loesche einfach den angegebenen Bereich
363 lcl_ClearArea( *this, *pSh->GetOut(), aPaintArea, SwRect() );
364 if( pGrfNd )
365 pGrfNd->SetFrameInPaint( FALSE );
367 pOut->Pop();
368 SfxProgress::LeaveLock();
371 /*************************************************************************
373 |* void lcl_CalcRect( Point & aPt, Size & aDim,
374 |* USHORT nMirror )
376 |* Beschreibung Errechne die Position und die Groesse der Grafik im
377 |* Frame, entsprechen der aktuellen Grafik-Attribute
379 |* Parameter Point& die Position im Frame ( auch Return-Wert )
380 |* Size& die Groesse der Grafik ( auch Return-Wert )
381 |* MirrorGrf akt. Spiegelungs-Attribut
382 |* Ersterstellung JP 04.03.91
383 |* Letzte Aenderung JP 31.08.94
385 *************************************************************************/
388 void lcl_CalcRect( Point& rPt, Size& rDim, USHORT nMirror )
390 if( nMirror == RES_MIRROR_GRAPH_VERT || nMirror == RES_MIRROR_GRAPH_BOTH )
392 rPt.X() += rDim.Width() -1;
393 rDim.Width() = -rDim.Width();
396 if( nMirror == RES_MIRROR_GRAPH_HOR || nMirror == RES_MIRROR_GRAPH_BOTH )
398 rPt.Y() += rDim.Height() -1;
399 rDim.Height() = -rDim.Height();
403 /*************************************************************************
405 |* void SwNoTxtFrm::GetGrfArea()
407 |* Beschreibung Errechne die Position und die Groesse der Bitmap
408 |* innerhalb des uebergebenem Rechtecks.
410 |* Ersterstellung JP 03.09.91
411 |* Letzte Aenderung MA 11. Oct. 94
413 *************************************************************************/
415 void SwNoTxtFrm::GetGrfArea( SwRect &rRect, SwRect* pOrigRect,
416 BOOL ) const
418 // JP 23.01.2001: currently only used for scaling, cropping and mirroring
419 // the contour of graphics!
420 // all other is handled by the GraphicObject
422 //In rRect wird das sichbare Rechteck der Grafik gesteckt.
423 //In pOrigRect werden Pos+Size der Gesamtgrafik gesteck.
425 const SwAttrSet& rAttrSet = GetNode()->GetSwAttrSet();
426 const SwCropGrf& rCrop = rAttrSet.GetCropGrf();
427 USHORT nMirror = rAttrSet.GetMirrorGrf().GetValue();
429 if( rAttrSet.GetMirrorGrf().IsGrfToggle() )
431 if( !(FindPageFrm()->GetVirtPageNum() % 2) )
433 switch ( nMirror )
435 case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_VERT; break;
436 case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_DONT; break;
437 case RES_MIRROR_GRAPH_HOR: nMirror = RES_MIRROR_GRAPH_BOTH; break;
438 default: nMirror = RES_MIRROR_GRAPH_HOR; break;
443 //Grafik wird vom Node eingelesen falls notwendig. Kann aber schiefgehen.
444 long nLeftCrop, nRightCrop, nTopCrop, nBottomCrop;
445 Size aOrigSz( ((SwNoTxtNode*)GetNode())->GetTwipSize() );
446 if ( !aOrigSz.Width() )
448 aOrigSz.Width() = Prt().Width();
449 nLeftCrop = -rCrop.GetLeft();
450 nRightCrop = -rCrop.GetRight();
452 else
454 nLeftCrop = Max( aOrigSz.Width() -
455 (rCrop.GetRight() + rCrop.GetLeft()), long(1) );
456 const double nScale = double(Prt().Width()) / double(nLeftCrop);
457 nLeftCrop = long(nScale * -rCrop.GetLeft() );
458 nRightCrop = long(nScale * -rCrop.GetRight() );
461 // crop values have to be mirrored too
462 if( nMirror == RES_MIRROR_GRAPH_VERT || nMirror == RES_MIRROR_GRAPH_BOTH )
464 long nTmpCrop = nLeftCrop;
465 nLeftCrop = nRightCrop;
466 nRightCrop= nTmpCrop;
469 if( !aOrigSz.Height() )
471 aOrigSz.Height() = Prt().Height();
472 nTopCrop = -rCrop.GetTop();
473 nBottomCrop= -rCrop.GetBottom();
475 else
477 nTopCrop = Max( aOrigSz.Height() - (rCrop.GetTop() + rCrop.GetBottom()), long(1) );
478 const double nScale = double(Prt().Height()) / double(nTopCrop);
479 nTopCrop = long(nScale * -rCrop.GetTop() );
480 nBottomCrop= long(nScale * -rCrop.GetBottom() );
483 // crop values have to be mirrored too
484 if( nMirror == RES_MIRROR_GRAPH_HOR || nMirror == RES_MIRROR_GRAPH_BOTH )
486 long nTmpCrop = nTopCrop;
487 nTopCrop = nBottomCrop;
488 nBottomCrop= nTmpCrop;
491 Size aVisSz( Prt().SSize() );
492 Size aGrfSz( aVisSz );
493 Point aVisPt( Frm().Pos() + Prt().Pos() );
494 Point aGrfPt( aVisPt );
496 //Erst das 'sichtbare' Rect einstellen.
497 if ( nLeftCrop > 0 )
499 aVisPt.X() += nLeftCrop;
500 aVisSz.Width() -= nLeftCrop;
502 if ( nTopCrop > 0 )
504 aVisPt.Y() += nTopCrop;
505 aVisSz.Height() -= nTopCrop;
507 if ( nRightCrop > 0 )
508 aVisSz.Width() -= nRightCrop;
509 if ( nBottomCrop > 0 )
510 aVisSz.Height() -= nBottomCrop;
512 rRect.Pos ( aVisPt );
513 rRect.SSize( aVisSz );
515 //Ggf. Die Gesamtgrafik berechnen
516 if ( pOrigRect )
518 Size aTmpSz( aGrfSz );
519 aGrfPt.X() += nLeftCrop;
520 aTmpSz.Width() -= nLeftCrop + nRightCrop;
521 aGrfPt.Y() += nTopCrop;
522 aTmpSz.Height()-= nTopCrop + nBottomCrop;
524 if( RES_MIRROR_GRAPH_DONT != nMirror )
525 lcl_CalcRect( aGrfPt, aTmpSz, nMirror );
527 pOrigRect->Pos ( aGrfPt );
528 pOrigRect->SSize( aTmpSz );
532 /*************************************************************************
534 |* Size SwNoTxtFrm::GetSize()
536 |* Beschreibung Gebe die Groesse des umgebenen FLys und
537 |* damit die der Grafik zurueck.
538 |* Ersterstellung JP 04.03.91
539 |* Letzte Aenderung JP 31.08.94
541 *************************************************************************/
544 const Size& SwNoTxtFrm::GetSize() const
546 // gebe die Groesse des Frames zurueck
547 const SwFrm *pFly = FindFlyFrm();
548 if( !pFly )
549 pFly = this;
550 return pFly->Prt().SSize();
553 /*************************************************************************
555 |* SwNoTxtFrm::MakeAll()
557 |* Ersterstellung MA 29. Nov. 96
558 |* Letzte Aenderung MA 29. Nov. 96
560 *************************************************************************/
563 void SwNoTxtFrm::MakeAll()
565 SwCntntNotify aNotify( this );
566 SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
567 const SwBorderAttrs &rAttrs = *aAccess.Get();
569 while ( !bValidPos || !bValidSize || !bValidPrtArea )
571 MakePos();
573 if ( !bValidSize )
574 Frm().Width( GetUpper()->Prt().Width() );
576 MakePrtArea( rAttrs );
578 if ( !bValidSize )
579 { bValidSize = TRUE;
580 Format();
585 /*************************************************************************
587 |* SwNoTxtFrm::Format()
589 |* Beschreibung Errechne die Groesse der Bitmap, wenn noetig
590 |* Ersterstellung JP 11.03.91
591 |* Letzte Aenderung MA 13. Mar. 96
593 *************************************************************************/
596 void SwNoTxtFrm::Format( const SwBorderAttrs * )
598 const Size aNewSize( GetSize() );
600 // hat sich die Hoehe geaendert?
601 SwTwips nChgHght = IsVertical() ?
602 (SwTwips)(aNewSize.Width() - Prt().Width()) :
603 (SwTwips)(aNewSize.Height() - Prt().Height());
604 if( nChgHght > 0)
605 Grow( nChgHght );
606 else if( nChgHght < 0)
607 Shrink( Min(Prt().Height(), -nChgHght) );
610 /*************************************************************************
612 |* SwNoTxtFrm::GetCharRect()
614 |* Beschreibung
615 |* Ersterstellung SS 29-Apr-1991
616 |* Letzte Aenderung MA 10. Oct. 94
618 |*************************************************************************/
621 BOOL SwNoTxtFrm::GetCharRect( SwRect &rRect, const SwPosition& rPos,
622 SwCrsrMoveState *pCMS ) const
624 if ( &rPos.nNode.GetNode() != (SwNode*)GetNode() )
625 return FALSE;
627 Calc();
628 SwRect aFrameRect( Frm() );
629 rRect = aFrameRect;
630 rRect.Pos( Frm().Pos() + Prt().Pos() );
631 rRect.SSize( Prt().SSize() );
633 rRect.Justify();
635 // liegt die Bitmap ueberhaupt im sichtbaren Berich ?
636 if( !aFrameRect.IsOver( rRect ) )
638 // wenn nicht dann steht der Cursor auf dem Frame
639 rRect = aFrameRect;
640 rRect.Width( 1 );
642 else
643 rRect._Intersection( aFrameRect );
645 if ( pCMS )
647 if ( pCMS->bRealHeight )
649 pCMS->aRealHeight.Y() = rRect.Height();
650 pCMS->aRealHeight.X() = 0;
654 return TRUE;
658 BOOL SwNoTxtFrm::GetCrsrOfst(SwPosition* pPos, Point& ,
659 SwCrsrMoveState* ) const
661 SwCntntNode* pCNd = (SwCntntNode*)GetNode();
662 pPos->nNode = *pCNd;
663 pPos->nContent.Assign( pCNd, 0 );
664 return TRUE;
667 #define CLEARCACHE( pNd ) {\
668 (pNd)->GetGrfObj().ReleaseFromCache();\
669 SwFlyFrm* pFly = FindFlyFrm();\
670 if( pFly && pFly->GetFmt()->GetSurround().IsContour() )\
672 ClrContourCache( pFly->GetVirtDrawObj() );\
673 pFly->NotifyBackground( FindPageFrm(), Prt(), PREP_FLY_ATTR_CHG );\
677 void SwNoTxtFrm::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
679 USHORT nWhich = pNew ? pNew->Which() : pOld ? pOld->Which() : 0;
681 // --> OD 2007-03-06 #i73788#
682 // no <SwCntntFrm::Modify(..)> for RES_LINKED_GRAPHIC_STREAM_ARRIVED
683 if ( RES_GRAPHIC_PIECE_ARRIVED != nWhich &&
684 RES_GRAPHIC_ARRIVED != nWhich &&
685 RES_GRF_REREAD_AND_INCACHE != nWhich &&
686 RES_LINKED_GRAPHIC_STREAM_ARRIVED != nWhich )
687 // <--
689 SwCntntFrm::Modify( pOld, pNew );
692 BOOL bComplete = TRUE;
694 switch( nWhich )
696 case RES_OBJECTDYING:
697 break;
699 case RES_GRF_REREAD_AND_INCACHE:
700 if( ND_GRFNODE == GetNode()->GetNodeType() )
702 bComplete = FALSE;
703 SwGrfNode* pNd = (SwGrfNode*) GetNode();
705 ViewShell *pVSh = 0;
706 pNd->GetDoc()->GetEditShell( &pVSh );
707 if( pVSh )
709 GraphicAttr aAttr;
710 if( pNd->GetGrfObj().IsCached( pVSh->GetOut(), Point(),
711 Prt().SSize(), &pNd->GetGraphicAttr( aAttr, this ) ))
713 ViewShell *pSh = pVSh;
714 do {
715 SET_CURR_SHELL( pSh );
716 if( pSh->GetWin() )
718 if( pSh->IsPreView() )
719 ::RepaintPagePreview( pSh, Frm().SVRect() );
720 else
721 pSh->GetWin()->Invalidate( Frm().SVRect() );
723 } while( pVSh != (pSh = (ViewShell*)pSh->GetNext() ));
725 else
726 pNd->SwapIn();
729 break;
731 case RES_UPDATE_ATTR:
732 case RES_FMT_CHG:
733 CLEARCACHE( (SwGrfNode*) GetNode() )
734 break;
736 case RES_ATTRSET_CHG:
738 USHORT n;
739 for( n = RES_GRFATR_BEGIN; n < RES_GRFATR_END; ++n )
740 if( SFX_ITEM_SET == ((SwAttrSetChg*)pOld)->GetChgSet()->
741 GetItemState( n, FALSE ))
743 CLEARCACHE( (SwGrfNode*) GetNode() )
744 break;
746 if( RES_GRFATR_END == n ) // not found
747 return ;
749 break;
751 case RES_GRAPHIC_PIECE_ARRIVED:
752 case RES_GRAPHIC_ARRIVED:
753 // --> OD 2007-03-06 #i73788#
754 // handle RES_LINKED_GRAPHIC_STREAM_ARRIVED as RES_GRAPHIC_ARRIVED
755 case RES_LINKED_GRAPHIC_STREAM_ARRIVED:
756 // <--
757 if ( GetNode()->GetNodeType() == ND_GRFNODE )
759 bComplete = FALSE;
760 SwGrfNode* pNd = (SwGrfNode*) GetNode();
762 CLEARCACHE( pNd )
764 SwRect aRect( Frm() );
766 ViewShell *pVSh = 0;
767 pNd->GetDoc()->GetEditShell( &pVSh );
768 if( !pVSh )
769 break;
771 ViewShell *pSh = pVSh;
772 do {
773 SET_CURR_SHELL( pSh );
774 if( pSh->IsPreView() )
776 if( pSh->GetWin() )
777 ::RepaintPagePreview( pSh, aRect );
779 else if ( pSh->VisArea().IsOver( aRect ) &&
780 OUTDEV_WINDOW == pSh->GetOut()->GetOutDevType() )
782 // OD 27.11.2002 #105519# - invalidate instead of painting
783 pSh->GetWin()->Invalidate( aRect.SVRect() );
786 pSh = (ViewShell *)pSh->GetNext();
787 } while( pSh != pVSh );
789 break;
791 default:
792 if ( !pNew || !isGRFATR(nWhich) )
793 return;
796 if( bComplete )
798 InvalidatePrt();
799 SetCompletePaint();
803 void lcl_correctlyAlignRect( SwRect& rAlignedGrfArea, const SwRect& rInArea, OutputDevice* pOut )
805 if(!pOut)
806 return;
807 Rectangle aPxRect = pOut->LogicToPixel( rInArea.SVRect() );
808 Rectangle aNewPxRect( aPxRect );
809 while( aNewPxRect.Left() < aPxRect.Left() )
811 rAlignedGrfArea.Left( rAlignedGrfArea.Left()+1 );
812 aNewPxRect = pOut->LogicToPixel( rAlignedGrfArea.SVRect() );
814 while( aNewPxRect.Top() < aPxRect.Top() )
816 rAlignedGrfArea.Top( rAlignedGrfArea.Top()+1 );
817 aNewPxRect = pOut->LogicToPixel( rAlignedGrfArea.SVRect() );
819 while( aNewPxRect.Bottom() > aPxRect.Bottom() )
821 rAlignedGrfArea.Bottom( rAlignedGrfArea.Bottom()-1 );
822 aNewPxRect = pOut->LogicToPixel( rAlignedGrfArea.SVRect() );
824 while( aNewPxRect.Right() > aPxRect.Right() )
826 rAlignedGrfArea.Right( rAlignedGrfArea.Right()-1 );
827 aNewPxRect = pOut->LogicToPixel( rAlignedGrfArea.SVRect() );
831 // Ausgabe der Grafik. Hier wird entweder eine QuickDraw-Bmp oder
832 // eine Grafik vorausgesetzt. Ist nichts davon vorhanden, wird
833 // eine Ersatzdarstellung ausgegeben.
834 /// OD 25.09.2002 #99739# - delete unused 3rd parameter.
835 /// OD 25.09.2002 #99739# - use aligned rectangle for drawing graphic.
836 /// OD 25.09.2002 #99739# - pixel-align coordinations for drawing graphic.
837 void SwNoTxtFrm::PaintPicture( OutputDevice* pOut, const SwRect &rGrfArea ) const
839 ViewShell* pShell = GetShell();
841 SwNoTxtNode& rNoTNd = *(SwNoTxtNode*)GetNode();
842 SwGrfNode* pGrfNd = rNoTNd.GetGrfNode();
843 SwOLENode* pOLENd = rNoTNd.GetOLENode();
845 const BOOL bPrn = pOut == rNoTNd.getIDocumentDeviceAccess()->getPrinter( false ) ||
846 pOut->GetConnectMetaFile();
848 const bool bIsChart = pOLENd && ChartPrettyPainter::IsChart( pOLENd->GetOLEObj().GetObject() );
850 /// OD 25.09.2002 #99739# - calculate aligned rectangle from parameter <rGrfArea>.
851 /// Use aligned rectangle <aAlignedGrfArea> instead of <rGrfArea> in
852 /// the following code.
853 SwRect aAlignedGrfArea = rGrfArea;
854 ::SwAlignRect( aAlignedGrfArea, pShell );
856 if( !bIsChart )
858 /// OD 25.09.2002 #99739#
859 /// Because for drawing a graphic left-top-corner and size coordinations are
860 /// used, these coordinations have to be determined on pixel level.
861 ::SwAlignGrfRect( &aAlignedGrfArea, *pOut );
863 else //if( bIsChart )
865 //#i78025# charts own borders are not completely visible
866 //the above pixel correction is not correct - at least not for charts
867 //so a different pixel correction is choosen here
868 //this might be a good idea for all other OLE objects also,
869 //but as I cannot oversee the consequences I fix it only for charts for now
870 lcl_correctlyAlignRect( aAlignedGrfArea, rGrfArea, pOut );
873 if( pGrfNd )
875 BOOL bForceSwap = FALSE, bContinue = TRUE;
876 GraphicObject& rGrfObj = pGrfNd->GetGrfObj();
878 GraphicAttr aGrfAttr;
879 pGrfNd->GetGraphicAttr( aGrfAttr, this );
881 if( !bPrn )
883 // --> OD 2007-01-02 #i73788#
884 if ( pGrfNd->IsLinkedInputStreamReady() )
886 pGrfNd->UpdateLinkWithInputStream();
888 // <--
889 // --> OD 2008-01-30 #i85717#
890 // --> OD 2008-07-21 #i90395# - check, if asynchronous retrieval
891 // if input stream for the graphic is possible
892 // else if( GRAPHIC_DEFAULT == rGrfObj.GetType() &&
893 else if ( ( rGrfObj.GetType() == GRAPHIC_DEFAULT ||
894 rGrfObj.GetType() == GRAPHIC_NONE ) &&
895 pGrfNd->IsLinkedFile() &&
896 pGrfNd->IsAsyncRetrieveInputStreamPossible() )
897 // <--
899 Size aTmpSz;
900 ::sfx2::SvLinkSource* pGrfObj = pGrfNd->GetLink()->GetObj();
901 if( !pGrfObj ||
902 !pGrfObj->IsDataComplete() ||
903 !(aTmpSz = pGrfNd->GetTwipSize()).Width() ||
904 !aTmpSz.Height() || !pGrfNd->GetAutoFmtLvl() )
906 // --> OD 2006-12-22 #i73788#
907 pGrfNd->TriggerAsyncRetrieveInputStream();
908 // <--
910 String aTxt( pGrfNd->GetTitle() );
911 if ( !aTxt.Len() )
912 GetRealURL( *pGrfNd, aTxt );
913 ::lcl_PaintReplacement( aAlignedGrfArea, aTxt, *pShell, this, FALSE );
914 bContinue = FALSE;
916 else if( rGrfObj.IsCached( pOut, aAlignedGrfArea.Pos(),
917 aAlignedGrfArea.SSize(), &aGrfAttr ))
919 rGrfObj.Draw( pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(),
920 &aGrfAttr );
921 bContinue = FALSE;
925 if( bContinue )
927 const BOOL bSwapped = rGrfObj.IsSwappedOut();
928 const BOOL bSwappedIn = 0 != pGrfNd->SwapIn( bPrn );
929 if( bSwappedIn && rGrfObj.GetGraphic().IsSupportedGraphic())
931 const BOOL bAnimate = rGrfObj.IsAnimated() &&
932 !pShell->IsPreView() &&
933 !pShell->GetAccessibilityOptions()->IsStopAnimatedGraphics() &&
934 // --> FME 2004-06-21 #i9684# Stop animation during printing/pdf export
935 pShell->GetWin();
936 // <--
938 if( bAnimate &&
939 FindFlyFrm() != ::GetFlyFromMarked( 0, pShell ))
941 OutputDevice* pVout;
942 if( pOut == pShell->GetOut() && SwRootFrm::FlushVout() )
943 pVout = pOut, pOut = pShell->GetOut();
944 else if( pShell->GetWin() &&
945 OUTDEV_VIRDEV == pOut->GetOutDevType() )
946 pVout = pOut, pOut = pShell->GetWin();
947 else
948 pVout = 0;
950 ASSERT( OUTDEV_VIRDEV != pOut->GetOutDevType() ||
951 pShell->GetViewOptions()->IsPDFExport(),
952 "pOut sollte kein virtuelles Device sein" );
954 rGrfObj.StartAnimation( pOut, aAlignedGrfArea.Pos(),
955 aAlignedGrfArea.SSize(), long(this),
956 0, GRFMGR_DRAW_STANDARD, pVout );
958 else
959 rGrfObj.Draw( pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(),
960 &aGrfAttr );
962 else
964 USHORT nResId = 0;
965 if( bSwappedIn )
967 if( GRAPHIC_NONE == rGrfObj.GetType() )
968 nResId = STR_COMCORE_READERROR;
969 else if ( !rGrfObj.GetGraphic().IsSupportedGraphic() )
970 nResId = STR_COMCORE_CANT_SHOW;
972 ((SwNoTxtFrm*)this)->nWeight = -1;
973 String aText;
974 if ( !nResId &&
975 !(aText = pGrfNd->GetTitle()).Len() &&
976 (!GetRealURL( *pGrfNd, aText ) || !aText.Len()))
978 nResId = STR_COMCORE_READERROR;
980 if ( nResId )
981 aText = SW_RESSTR( nResId );
983 ::lcl_PaintReplacement( aAlignedGrfArea, aText, *pShell, this, TRUE );
986 //Beim Drucken duerfen wir nicht die Grafiken sammeln...
987 if( bSwapped && bPrn )
988 bForceSwap = TRUE;
990 if( bForceSwap )
991 pGrfNd->SwapOut();
993 else if( bIsChart
994 //charts must be painted resolution dependent!! #i82893#, #i75867#
995 && ChartPrettyPainter::ShouldPrettyPaintChartOnThisDevice( pOut )
996 && svt::EmbeddedObjectRef::TryRunningState( pOLENd->GetOLEObj().GetOleRef() )
997 && ChartPrettyPainter::DoPrettyPaintChart( uno::Reference< frame::XModel >(
998 pOLENd->GetOLEObj().GetOleRef()->getComponent(), uno::UNO_QUERY), pOut, aAlignedGrfArea.SVRect() ) )
1000 (void)(0);//all was done in if statement
1002 else if( pOLENd )
1004 // --> OD 2009-03-05 #i99665#
1005 // Adjust AntiAliasing mode at output device for chart OLE
1006 const USHORT nFormerAntialiasingAtOutput( pOut->GetAntialiasing() );
1007 if ( pOLENd->IsChart() &&
1008 pShell->Imp()->GetDrawView()->IsAntiAliasing() )
1010 const USHORT nAntialiasingForChartOLE =
1011 nFormerAntialiasingAtOutput | ANTIALIASING_PIXELSNAPHAIRLINE;
1012 pOut->SetAntialiasing( nAntialiasingForChartOLE );
1014 // <--
1016 Point aPosition(aAlignedGrfArea.Pos());
1017 Size aSize(aAlignedGrfArea.SSize());
1019 // Im BrowseModus gibt es nicht unbedingt einen Drucker und
1020 // damit kein JobSetup, also legen wir eines an ...
1021 const JobSetup* pJobSetup = pOLENd->getIDocumentDeviceAccess()->getJobsetup();
1022 BOOL bDummyJobSetup = 0 == pJobSetup;
1023 if( bDummyJobSetup )
1024 pJobSetup = new JobSetup();
1026 // #i42323#
1027 // The reason for #114233# is gone, so i remove it again
1028 //TODO/LATER: is it a problem that the JopSetup isn't used?
1029 //xRef->DoDraw( pOut, aAlignedGrfArea.Pos(), aAlignedGrfArea.SSize(), *pJobSetup );
1031 // get hi-contrast image, but never for printing
1032 Graphic* pGraphic = NULL;
1033 if (pOut && !bPrn && Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1034 pGraphic = pOLENd->GetHCGraphic();
1036 // when it is not possible to get HC-representation, the original image should be used
1037 if ( !pGraphic )
1038 pGraphic = pOLENd->GetGraphic();
1040 if ( pGraphic && pGraphic->GetType() != GRAPHIC_NONE )
1042 pGraphic->Draw( pOut, aPosition, aSize );
1044 // shade the representation if the object is activated outplace
1045 uno::Reference < embed::XEmbeddedObject > xObj = pOLENd->GetOLEObj().GetOleRef();
1046 if ( xObj.is() && xObj->getCurrentState() == embed::EmbedStates::ACTIVE )
1048 ::svt::EmbeddedObjectRef::DrawShading( Rectangle( aPosition, aSize ), pOut );
1051 else
1052 ::svt::EmbeddedObjectRef::DrawPaintReplacement( Rectangle( aPosition, aSize ), pOLENd->GetOLEObj().GetCurrentPersistName(), pOut );
1054 if( bDummyJobSetup )
1055 delete pJobSetup; // ... und raeumen wieder auf.
1057 sal_Int64 nMiscStatus = pOLENd->GetOLEObj().GetOleRef()->getStatus( pOLENd->GetAspect() );
1058 if ( !bPrn && pShell->ISA( SwCrsrShell ) &&
1059 nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
1061 const SwFlyFrm *pFly = FindFlyFrm();
1062 ASSERT( pFly, "OLE not in FlyFrm" );
1063 ((SwFEShell*)pShell)->ConnectObj( pOLENd->GetOLEObj().GetObject(), pFly->Prt(), pFly->Frm());
1066 // --> OD 2009-03-05 #i99665#
1067 if ( pOLENd->IsChart() &&
1068 pShell->Imp()->GetDrawView()->IsAntiAliasing() )
1070 pOut->SetAntialiasing( nFormerAntialiasingAtOutput );
1072 // <--
1077 BOOL SwNoTxtFrm::IsTransparent() const
1079 const ViewShell* pSh = GetShell();
1080 if ( !pSh || !pSh->GetViewOptions()->IsGraphic() )
1081 return TRUE;
1083 const SwGrfNode *pNd;
1084 if( 0 != (pNd = GetNode()->GetGrfNode()) )
1085 return pNd->IsTransparent();
1087 //#29381# OLE sind immer Transparent.
1088 return TRUE;
1092 void SwNoTxtFrm::StopAnimation( OutputDevice* pOut ) const
1094 //animierte Grafiken anhalten
1095 SwGrfNode* pGrfNd = (SwGrfNode*)GetNode()->GetGrfNode();
1096 if( pGrfNd && pGrfNd->IsAnimated() )
1097 pGrfNd->GetGrfObj().StopAnimation( pOut, long(this) );
1101 BOOL SwNoTxtFrm::HasAnimation() const
1103 const SwGrfNode* pGrfNd = GetNode()->GetGrfNode();
1104 return pGrfNd && pGrfNd->IsAnimated();