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