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