LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - docprev.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 145 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10