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

Generated by: LCOV version 1.10