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