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

Generated by: LCOV version 1.11