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