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 :
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 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSdDocPreviewWin(vcl::Window *pParent, VclBuilder::stringmap &rMap)
65 : {
66 0 : WinBits nWinStyle = 0;
67 :
68 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
69 0 : if (!sBorder.isEmpty())
70 0 : nWinStyle |= WB_BORDER;
71 :
72 0 : return new SdDocPreviewWin(pParent, nWinStyle);
73 : }
74 :
75 0 : SdDocPreviewWin::SdDocPreviewWin( vcl::Window* pParent, const WinBits nStyle )
76 0 : : Control(pParent, nStyle), pMetaFile( 0 ), bInEffect(false), mpObj(NULL), mnShowPage(0)
77 : {
78 0 : SetBorderStyle( WindowBorderStyle::MONO );
79 0 : svtools::ColorConfig aColorConfig;
80 0 : Wallpaper aEmpty;
81 0 : SetBackground( aEmpty );
82 0 : }
83 :
84 0 : SdDocPreviewWin::~SdDocPreviewWin()
85 : {
86 0 : delete pMetaFile;
87 0 : }
88 :
89 0 : Size SdDocPreviewWin::GetOptimalSize() const
90 : {
91 0 : return LogicToPixel(Size(122, 96), MAP_APPFONT);
92 : }
93 :
94 0 : void SdDocPreviewWin::Resize()
95 : {
96 0 : Invalidate();
97 0 : if( mxSlideShow.is() )
98 0 : mxSlideShow->resize( GetSizePixel() );
99 0 : }
100 :
101 0 : void SdDocPreviewWin::CalcSizeAndPos( GDIMetaFile* pFile, Size& rSize, Point& rPoint )
102 : {
103 0 : Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 );
104 0 : long nWidth = rSize.Width() - 2*FRAME;
105 0 : long nHeight = rSize.Height() - 2*FRAME;
106 0 : if( nWidth < 0 ) nWidth = 0;
107 0 : if( nHeight < 0 ) nHeight = 0;
108 :
109 0 : double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
110 0 : double dRatioPreV = nHeight ? (((double) nWidth ) / nHeight) : 0.0;
111 :
112 0 : if (dRatio > dRatioPreV)
113 : {
114 0 : rSize=Size(nWidth, (sal_uInt16)(nWidth/dRatio));
115 0 : rPoint=Point( 0, (sal_uInt16)((nHeight-rSize.Height())/2));
116 : }
117 : else
118 : {
119 0 : rSize=Size((sal_uInt16)(nHeight*dRatio), nHeight);
120 0 : rPoint=Point((sal_uInt16)((nWidth-rSize.Width())/2),0);
121 : }
122 0 : }
123 :
124 0 : void SdDocPreviewWin::ImpPaint( GDIMetaFile* pFile, OutputDevice* pVDev )
125 : {
126 0 : Point aPoint;
127 0 : Size aSize = pVDev->GetOutputSize();
128 0 : Point bPoint(aSize.Width()-2*FRAME, aSize.Height()-2*FRAME );
129 0 : CalcSizeAndPos( pFile, aSize, aPoint );
130 0 : bPoint -= aPoint;
131 0 : aPoint += Point( FRAME, FRAME );
132 :
133 0 : svtools::ColorConfig aColorConfig;
134 :
135 0 : pVDev->SetLineColor();
136 0 : pVDev->SetFillColor( Color( aColorConfig.GetColorValue( svtools::APPBACKGROUND ).nColor ) );
137 0 : pVDev->DrawRect(Rectangle( Point(0,0 ), pVDev->GetOutputSize()));
138 0 : if( pFile )
139 : {
140 0 : pVDev->SetFillColor( maDocumentColor );
141 0 : pVDev->DrawRect(Rectangle(aPoint, aSize));
142 0 : pFile->WindStart();
143 0 : pFile->Play( pVDev, aPoint, aSize );
144 0 : }
145 0 : }
146 :
147 0 : void SdDocPreviewWin::Paint( const Rectangle& rRect )
148 : {
149 0 : if( (!mxSlideShow.is()) || (!mxSlideShow->isRunning() ) )
150 : {
151 0 : SvtAccessibilityOptions aAccOptions;
152 0 : bool bUseContrast = aAccOptions.GetIsForPagePreviews() && Application::GetSettings().GetStyleSettings().GetHighContrastMode();
153 : SetDrawMode( bUseContrast
154 : ? ::sd::ViewShell::OUTPUT_DRAWMODE_CONTRAST
155 0 : : ::sd::ViewShell::OUTPUT_DRAWMODE_COLOR );
156 :
157 0 : ImpPaint( pMetaFile, (VirtualDevice*)this );
158 : }
159 : else
160 : {
161 0 : mxSlideShow->paint( rRect );
162 : }
163 0 : }
164 :
165 0 : void SdDocPreviewWin::startPreview()
166 : {
167 0 : ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell * >( mpObj );
168 0 : if( pDocShell )
169 : {
170 0 : SdDrawDocument* pDoc = pDocShell->GetDoc();
171 :
172 0 : if( pDoc )
173 : {
174 0 : SdPage* pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD );
175 :
176 0 : if( pPage && (pPage->getTransitionType() != 0) )
177 : {
178 0 : if( !mxSlideShow.is() )
179 0 : mxSlideShow = sd::SlideShow::Create( pDoc );
180 :
181 0 : Reference< XDrawPage > xDrawPage( pPage->getUnoPage(), UNO_QUERY );
182 0 : Reference< XAnimationNode > xAnimationNode;
183 :
184 0 : mxSlideShow->startPreview( xDrawPage, xAnimationNode, this );
185 : }
186 : }
187 : }
188 0 : }
189 :
190 0 : bool SdDocPreviewWin::Notify( NotifyEvent& rNEvt )
191 : {
192 0 : if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
193 : {
194 0 : const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
195 0 : if ( pMEvt->IsLeft() )
196 : {
197 0 : if( rNEvt.GetWindow() == this )
198 : {
199 0 : if(aClickHdl.IsSet())
200 0 : aClickHdl.Call(this);
201 : }
202 : }
203 : }
204 :
205 0 : return Control::Notify( rNEvt );
206 : }
207 :
208 0 : void SdDocPreviewWin::updateViewSettings()
209 : {
210 0 : ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell,mpObj);
211 0 : SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
212 :
213 0 : SvtAccessibilityOptions aAccOptions;
214 0 : bool bUseWhiteColor = !aAccOptions.GetIsForPagePreviews() && GetSettings().GetStyleSettings().GetHighContrastMode();
215 0 : if( bUseWhiteColor )
216 : {
217 0 : maDocumentColor = Color( COL_WHITE );
218 : }
219 : else
220 : {
221 0 : svtools::ColorConfig aColorConfig;
222 0 : maDocumentColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
223 : }
224 :
225 0 : GDIMetaFile* pMtf = NULL;
226 :
227 0 : if(pDoc)
228 : {
229 0 : SdPage * pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD );
230 0 : if( pPage )
231 : {
232 0 : SdrOutliner& rOutl = pDoc->GetDrawOutliner();
233 0 : Color aOldBackgroundColor = rOutl.GetBackgroundColor();
234 0 : rOutl.SetBackgroundColor( maDocumentColor );
235 :
236 0 : pMtf = new GDIMetaFile;
237 :
238 0 : VirtualDevice aVDev;
239 :
240 0 : const Fraction aFrac( pDoc->GetScaleFraction() );
241 0 : const MapMode aMap( pDoc->GetScaleUnit(), Point(), aFrac, aFrac );
242 :
243 0 : aVDev.SetMapMode( aMap );
244 :
245 : // Disable output, as we only want to record a metafile
246 0 : aVDev.EnableOutput( false );
247 :
248 0 : pMtf->Record( &aVDev );
249 :
250 0 : ::sd::DrawView* pView = new ::sd::DrawView(pDocShell, this, NULL);
251 :
252 0 : const Size aSize( pPage->GetSize() );
253 :
254 0 : pView->SetBordVisible( false );
255 0 : pView->SetPageVisible( false );
256 0 : pView->ShowSdrPage( pPage );
257 :
258 0 : const Point aNewOrg( pPage->GetLftBorder(), pPage->GetUppBorder() );
259 0 : const Size aNewSize( aSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder(),
260 0 : aSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder() );
261 0 : const Rectangle aClipRect( aNewOrg, aNewSize );
262 0 : MapMode aVMap( aMap );
263 :
264 0 : aVDev.Push();
265 0 : aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
266 0 : aVDev.SetRelativeMapMode( aVMap );
267 0 : aVDev.IntersectClipRegion( aClipRect );
268 :
269 : // Use new StandardCheckVisisbilityRedirector
270 0 : StandardCheckVisisbilityRedirector aRedirector;
271 0 : const Rectangle aRedrawRectangle = Rectangle( Point(), aNewSize );
272 0 : vcl::Region aRedrawRegion(aRedrawRectangle);
273 0 : pView->SdrPaintView::CompleteRedraw(&aVDev,aRedrawRegion,&aRedirector);
274 :
275 0 : aVDev.Pop();
276 :
277 0 : pMtf->Stop();
278 0 : pMtf->WindStart();
279 0 : pMtf->SetPrefMapMode( aMap );
280 0 : pMtf->SetPrefSize( aNewSize );
281 :
282 0 : rOutl.SetBackgroundColor( aOldBackgroundColor );
283 :
284 0 : delete pView;
285 : }
286 : }
287 :
288 0 : delete pMetaFile;
289 0 : pMetaFile = pMtf;
290 :
291 0 : Invalidate();
292 0 : }
293 :
294 0 : void SdDocPreviewWin::Notify(SfxBroadcaster&, const SfxHint& rHint)
295 : {
296 0 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
297 0 : if( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_COLORS_CHANGED )
298 : {
299 0 : updateViewSettings();
300 : }
301 0 : }
302 0 : void SdDocPreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
303 : {
304 0 : Control::DataChanged( rDCEvt );
305 :
306 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
307 : {
308 0 : updateViewSettings();
309 : }
310 114 : }
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|