1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sd.hxx" 26cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp> 27cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp> 28cdf0e10cSrcweir #include "slideshow.hxx" 29cdf0e10cSrcweir #include <sfx2/objsh.hxx> 30cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 31cdf0e10cSrcweir #include <vcl/virdev.hxx> 32cdf0e10cSrcweir #include <com/sun/star/presentation/FadeEffect.hpp> 33cdf0e10cSrcweir #include <fadedef.h> 34cdf0e10cSrcweir #include <vcl/ctrl.hxx> 35cdf0e10cSrcweir #include <svx/svdoutl.hxx> 36cdf0e10cSrcweir #include <svx/svdpagv.hxx> 37cdf0e10cSrcweir #include <svx/svdorect.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include "docprev.hxx" 40cdf0e10cSrcweir #include "drawdoc.hxx" 41cdf0e10cSrcweir #include "DrawDocShell.hxx" 42cdf0e10cSrcweir #include "ViewShell.hxx" 43cdf0e10cSrcweir #include "ViewShellBase.hxx" 44cdf0e10cSrcweir #include "drawview.hxx" 45cdf0e10cSrcweir #include "sdpage.hxx" 46cdf0e10cSrcweir #include "sfx2/viewfrm.hxx" 47cdf0e10cSrcweir #include <vcl/svapp.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <memory> 50cdf0e10cSrcweir 51cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPage; 52cdf0e10cSrcweir using ::com::sun::star::animations::XAnimationNode; 53cdf0e10cSrcweir using namespace ::com::sun::star; 54cdf0e10cSrcweir using namespace ::com::sun::star::uno; 55cdf0e10cSrcweir 56cdf0e10cSrcweir const int SdDocPreviewWin::FRAME = 4; 57cdf0e10cSrcweir 58cdf0e10cSrcweir void SdDocPreviewWin::SetObjectShell( SfxObjectShell* pObj, sal_uInt16 nShowPage ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir mpObj = pObj; 61cdf0e10cSrcweir mnShowPage = nShowPage; 62cdf0e10cSrcweir if (mxSlideShow.is()) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir mxSlideShow->end(); 65cdf0e10cSrcweir mxSlideShow.clear(); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir updateViewSettings(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir SdDocPreviewWin::SdDocPreviewWin( Window* pParent, const ResId& rResId ) 71cdf0e10cSrcweir : Control(pParent, rResId), pMetaFile( 0 ), bInEffect(sal_False), mpObj(NULL), mnShowPage(0) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir SetBorderStyle( WINDOW_BORDER_MONO ); 74cdf0e10cSrcweir svtools::ColorConfig aColorConfig; 75cdf0e10cSrcweir Wallpaper aEmpty; 76cdf0e10cSrcweir SetBackground( aEmpty ); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir SdDocPreviewWin::~SdDocPreviewWin() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir delete pMetaFile; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir void SdDocPreviewWin::Resize() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir Invalidate(); 87cdf0e10cSrcweir if( mxSlideShow.is() ) 88cdf0e10cSrcweir mxSlideShow->resize( GetSizePixel() ); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir void SdDocPreviewWin::CalcSizeAndPos( GDIMetaFile* pFile, Size& rSize, Point& rPoint ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 ); 94cdf0e10cSrcweir long nWidth = rSize.Width() - 2*FRAME; 95cdf0e10cSrcweir long nHeight = rSize.Height() - 2*FRAME; 96cdf0e10cSrcweir if( nWidth < 0 ) nWidth = 0; 97cdf0e10cSrcweir if( nHeight < 0 ) nHeight = 0; 98cdf0e10cSrcweir 99cdf0e10cSrcweir double dRatio=((double)aTmpSize.Width())/aTmpSize.Height(); 100cdf0e10cSrcweir double dRatioPreV=((double) nWidth ) / nHeight; 101cdf0e10cSrcweir 102cdf0e10cSrcweir if (dRatio>dRatioPreV) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir rSize=Size(nWidth, (sal_uInt16)(nWidth/dRatio)); 105cdf0e10cSrcweir rPoint=Point( 0, (sal_uInt16)((nHeight-rSize.Height())/2)); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir else 108cdf0e10cSrcweir { 109cdf0e10cSrcweir rSize=Size((sal_uInt16)(nHeight*dRatio), nHeight); 110cdf0e10cSrcweir rPoint=Point((sal_uInt16)((nWidth-rSize.Width())/2),0); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir void SdDocPreviewWin::ImpPaint( GDIMetaFile* pFile, OutputDevice* pVDev ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir Point aPoint; 117cdf0e10cSrcweir Size aSize = pVDev->GetOutputSize(); 118cdf0e10cSrcweir Point bPoint(aSize.Width()-2*FRAME, aSize.Height()-2*FRAME ); 119cdf0e10cSrcweir CalcSizeAndPos( pFile, aSize, aPoint ); 120cdf0e10cSrcweir bPoint -= aPoint; 121cdf0e10cSrcweir aPoint += Point( FRAME, FRAME ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir svtools::ColorConfig aColorConfig; 124cdf0e10cSrcweir 125cdf0e10cSrcweir pVDev->SetLineColor(); 126cdf0e10cSrcweir pVDev->SetFillColor( Color( aColorConfig.GetColorValue( svtools::APPBACKGROUND ).nColor ) ); 127cdf0e10cSrcweir pVDev->DrawRect(Rectangle( Point(0,0 ), pVDev->GetOutputSize())); 128cdf0e10cSrcweir if( pFile ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir pVDev->SetFillColor( maDocumentColor ); 131cdf0e10cSrcweir pVDev->DrawRect(Rectangle(aPoint, aSize)); 132cdf0e10cSrcweir pFile->WindStart(); 133cdf0e10cSrcweir pFile->Play( pVDev, aPoint, aSize ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir void SdDocPreviewWin::Paint( const Rectangle& rRect ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if( (!mxSlideShow.is()) || (!mxSlideShow->isRunning() ) ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir SvtAccessibilityOptions aAccOptions; 142cdf0e10cSrcweir bool bUseContrast = aAccOptions.GetIsForPagePreviews() && Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 143cdf0e10cSrcweir SetDrawMode( bUseContrast 144cdf0e10cSrcweir ? ::sd::ViewShell::OUTPUT_DRAWMODE_CONTRAST 145cdf0e10cSrcweir : ::sd::ViewShell::OUTPUT_DRAWMODE_COLOR ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir ImpPaint( pMetaFile, (VirtualDevice*)this ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir else 150cdf0e10cSrcweir { 151cdf0e10cSrcweir mxSlideShow->paint( rRect ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir void SdDocPreviewWin::startPreview() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell * >( mpObj ); 158cdf0e10cSrcweir if( mpObj ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir SdDrawDocument* pDoc = pDocShell->GetDoc(); 161cdf0e10cSrcweir 162cdf0e10cSrcweir if( pDoc ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir SdPage* pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir if( pPage && (pPage->getTransitionType() != 0) ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if( !mxSlideShow.is() ) 169cdf0e10cSrcweir mxSlideShow = sd::SlideShow::Create( pDoc ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir Reference< XDrawPage > xDrawPage( pPage->getUnoPage(), UNO_QUERY ); 172cdf0e10cSrcweir Reference< XAnimationNode > xAnimationNode; 173cdf0e10cSrcweir 174cdf0e10cSrcweir mxSlideShow->startPreview( xDrawPage, xAnimationNode, this ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir long SdDocPreviewWin::Notify( NotifyEvent& rNEvt ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir const MouseEvent* pMEvt = rNEvt.GetMouseEvent(); 185cdf0e10cSrcweir if ( pMEvt->IsLeft() ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if( rNEvt.GetWindow() == this ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if(aClickHdl.IsSet()) 190cdf0e10cSrcweir aClickHdl.Call(this); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir return Control::Notify( rNEvt ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir 199cdf0e10cSrcweir void SdDocPreviewWin::updateViewSettings() 200cdf0e10cSrcweir { 201cdf0e10cSrcweir ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell,mpObj); 202cdf0e10cSrcweir SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL; 203cdf0e10cSrcweir 204cdf0e10cSrcweir SvtAccessibilityOptions aAccOptions; 205cdf0e10cSrcweir bool bUseWhiteColor = !aAccOptions.GetIsForPagePreviews() && GetSettings().GetStyleSettings().GetHighContrastMode(); 206cdf0e10cSrcweir if( bUseWhiteColor ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir maDocumentColor = Color( COL_WHITE ); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir else 211cdf0e10cSrcweir { 212cdf0e10cSrcweir svtools::ColorConfig aColorConfig; 213cdf0e10cSrcweir maDocumentColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor ); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir GDIMetaFile* pMtf = NULL; 217cdf0e10cSrcweir 218cdf0e10cSrcweir if(pDoc) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir SdPage * pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD ); 221cdf0e10cSrcweir if( pPage ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir SdrOutliner& rOutl = pDoc->GetDrawOutliner(); 224cdf0e10cSrcweir Color aOldBackgroundColor = rOutl.GetBackgroundColor(); 225cdf0e10cSrcweir rOutl.SetBackgroundColor( maDocumentColor ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir pMtf = new GDIMetaFile; 228cdf0e10cSrcweir 229cdf0e10cSrcweir VirtualDevice aVDev; 230cdf0e10cSrcweir 231cdf0e10cSrcweir const Fraction aFrac( pDoc->GetScaleFraction() ); 232cdf0e10cSrcweir const MapMode aMap( pDoc->GetScaleUnit(), Point(), aFrac, aFrac ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir aVDev.SetMapMode( aMap ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir // #109058# Disable output, as we only want to record a metafile 237cdf0e10cSrcweir aVDev.EnableOutput( sal_False ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir pMtf->Record( &aVDev ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir ::sd::DrawView* pView = new ::sd::DrawView(pDocShell, this, NULL); 242cdf0e10cSrcweir 243cdf0e10cSrcweir 244cdf0e10cSrcweir const Size aSize( pPage->GetSize() ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir pView->SetBordVisible( sal_False ); 247cdf0e10cSrcweir pView->SetPageVisible( sal_False ); 248cdf0e10cSrcweir pView->ShowSdrPage( pPage ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir const Point aNewOrg( pPage->GetLftBorder(), pPage->GetUppBorder() ); 251cdf0e10cSrcweir const Size aNewSize( aSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder(), 252cdf0e10cSrcweir aSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder() ); 253cdf0e10cSrcweir const Rectangle aClipRect( aNewOrg, aNewSize ); 254cdf0e10cSrcweir MapMode aVMap( aMap ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir aVDev.Push(); 257cdf0e10cSrcweir aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) ); 258cdf0e10cSrcweir aVDev.SetRelativeMapMode( aVMap ); 259cdf0e10cSrcweir aVDev.IntersectClipRegion( aClipRect ); 260cdf0e10cSrcweir 261cdf0e10cSrcweir // Use new StandardCheckVisisbilityRedirector 262cdf0e10cSrcweir StandardCheckVisisbilityRedirector aRedirector; 263cdf0e10cSrcweir const Rectangle aRedrawRectangle = Rectangle( Point(), aNewSize ); 264cdf0e10cSrcweir Region aRedrawRegion(aRedrawRectangle); 265cdf0e10cSrcweir pView->SdrPaintView::CompleteRedraw(&aVDev,aRedrawRegion,&aRedirector); 266cdf0e10cSrcweir 267cdf0e10cSrcweir aVDev.Pop(); 268cdf0e10cSrcweir 269cdf0e10cSrcweir pMtf->Stop(); 270cdf0e10cSrcweir pMtf->WindStart(); 271cdf0e10cSrcweir pMtf->SetPrefMapMode( aMap ); 272cdf0e10cSrcweir pMtf->SetPrefSize( aNewSize ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir rOutl.SetBackgroundColor( aOldBackgroundColor ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir delete pView; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir delete pMetaFile; 281cdf0e10cSrcweir pMetaFile = pMtf; 282cdf0e10cSrcweir 283cdf0e10cSrcweir Invalidate(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir void SdDocPreviewWin::Notify(SfxBroadcaster&, const SfxHint& rHint) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir if( rHint.ISA( SfxSimpleHint ) && ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_COLORS_CHANGED ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir updateViewSettings(); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir } 293cdf0e10cSrcweir void SdDocPreviewWin::DataChanged( const DataChangedEvent& rDCEvt ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir Control::DataChanged( rDCEvt ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir updateViewSettings(); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302