merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / docprev.cxx
blob40be6e1caea1400fa770df6f92f89e2099afad09
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docprev.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/drawing/XDrawPage.hpp>
34 #include <com/sun/star/animations/XAnimationNode.hpp>
35 #include "slideshow.hxx"
36 #include <sfx2/objsh.hxx>
37 #include <vcl/gdimtf.hxx>
38 #include <vcl/virdev.hxx>
39 #include <com/sun/star/presentation/FadeEffect.hpp>
40 #include <fadedef.h>
41 #include <vcl/ctrl.hxx>
42 #include <svx/svdoutl.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <svx/svdorect.hxx>
46 #include "docprev.hxx"
47 #include "drawdoc.hxx"
48 #include "DrawDocShell.hxx"
49 #include "ViewShell.hxx"
50 #include "ViewShellBase.hxx"
51 #include "showview.hxx"
52 #include "drawview.hxx"
53 #include "sdpage.hxx"
54 #include "sfx2/viewfrm.hxx"
55 #include <vcl/svapp.hxx>
57 #include <memory>
59 using ::com::sun::star::drawing::XDrawPage;
60 using ::com::sun::star::animations::XAnimationNode;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
64 const int SdDocPreviewWin::FRAME = 4;
66 void SdDocPreviewWin::SetObjectShell( SfxObjectShell* pObj, sal_uInt16 nShowPage )
68 mpObj = pObj;
69 mnShowPage = nShowPage;
70 if (mxSlideShow.is())
72 mxSlideShow->end();
73 mxSlideShow.clear();
75 updateViewSettings();
78 SdDocPreviewWin::SdDocPreviewWin( Window* pParent, const ResId& rResId )
79 : Control(pParent, rResId), pMetaFile( 0 ), bInEffect(FALSE), mpObj(NULL), mnShowPage(0)
81 SetBorderStyle( WINDOW_BORDER_MONO );
82 svtools::ColorConfig aColorConfig;
83 Wallpaper aEmpty;
84 SetBackground( aEmpty );
87 SdDocPreviewWin::SdDocPreviewWin( Window* pParent )
88 : Control(pParent, 0 ), pMetaFile( 0 ), bInEffect(FALSE), mpObj(NULL), mnShowPage(0)
90 SetBorderStyle( WINDOW_BORDER_MONO );
91 svtools::ColorConfig aColorConfig;
92 Wallpaper aEmpty;
93 SetBackground( aEmpty );
94 Resize();
95 Show();
98 SdDocPreviewWin::~SdDocPreviewWin()
100 delete pMetaFile;
103 void SdDocPreviewWin::Resize()
105 Invalidate();
106 if( mxSlideShow.is() )
107 mxSlideShow->resize( GetSizePixel() );
110 void SdDocPreviewWin::SetGDIFile( GDIMetaFile* pFile )
112 delete pMetaFile;
113 pMetaFile = pFile;
114 Invalidate();
117 void SdDocPreviewWin::CalcSizeAndPos( GDIMetaFile* pFile, Size& rSize, Point& rPoint )
119 Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 );
120 long nWidth = rSize.Width() - 2*FRAME;
121 long nHeight = rSize.Height() - 2*FRAME;
122 if( nWidth < 0 ) nWidth = 0;
123 if( nHeight < 0 ) nHeight = 0;
125 double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
126 double dRatioPreV=((double) nWidth ) / nHeight;
128 if (dRatio>dRatioPreV)
130 rSize=Size(nWidth, (USHORT)(nWidth/dRatio));
131 rPoint=Point( 0, (USHORT)((nHeight-rSize.Height())/2));
133 else
135 rSize=Size((USHORT)(nHeight*dRatio), nHeight);
136 rPoint=Point((USHORT)((nWidth-rSize.Width())/2),0);
140 void SdDocPreviewWin::ImpPaint( GDIMetaFile* pFile, OutputDevice* pVDev )
142 Point aPoint;
143 Size aSize = pVDev->GetOutputSize();
144 Point bPoint(aSize.Width()-2*FRAME, aSize.Height()-2*FRAME );
145 CalcSizeAndPos( pFile, aSize, aPoint );
146 bPoint -= aPoint;
147 aPoint += Point( FRAME, FRAME );
149 svtools::ColorConfig aColorConfig;
151 pVDev->SetLineColor();
152 pVDev->SetFillColor( Color( aColorConfig.GetColorValue( svtools::APPBACKGROUND ).nColor ) );
153 pVDev->DrawRect(Rectangle( Point(0,0 ), pVDev->GetOutputSize()));
154 if( pFile )
156 pVDev->SetFillColor( maDocumentColor );
157 pVDev->DrawRect(Rectangle(aPoint, aSize));
158 pFile->WindStart();
159 pFile->Play( pVDev, aPoint, aSize );
163 void SdDocPreviewWin::Paint( const Rectangle& rRect )
165 if( (!mxSlideShow.is()) || (!mxSlideShow->isRunning() ) )
167 SvtAccessibilityOptions aAccOptions;
168 bool bUseContrast = aAccOptions.GetIsForPagePreviews() && Application::GetSettings().GetStyleSettings().GetHighContrastMode();
169 SetDrawMode( bUseContrast
170 ? ::sd::ViewShell::OUTPUT_DRAWMODE_CONTRAST
171 : ::sd::ViewShell::OUTPUT_DRAWMODE_COLOR );
173 ImpPaint( pMetaFile, (VirtualDevice*)this );
175 else
177 mxSlideShow->paint( rRect );
181 void SdDocPreviewWin::startPreview()
183 ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell * >( mpObj );
184 if( mpObj )
186 SdDrawDocument* pDoc = pDocShell->GetDoc();
188 if( pDoc )
190 SdPage* pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD );
192 if( pPage && (pPage->getTransitionType() != 0) )
194 if( !mxSlideShow.is() )
195 mxSlideShow = sd::SlideShow::Create( pDoc );
197 Reference< XDrawPage > xDrawPage( pPage->getUnoPage(), UNO_QUERY );
198 Reference< XAnimationNode > xAnimationNode;
200 mxSlideShow->startPreview( xDrawPage, xAnimationNode, this );
206 long SdDocPreviewWin::Notify( NotifyEvent& rNEvt )
208 if ( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
210 const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
211 if ( pMEvt->IsLeft() )
213 if( rNEvt.GetWindow() == this )
215 if(aClickHdl.IsSet())
216 aClickHdl.Call(this);
221 return Control::Notify( rNEvt );
225 void SdDocPreviewWin::updateViewSettings()
227 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell,mpObj);
228 SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
230 SvtAccessibilityOptions aAccOptions;
231 bool bUseWhiteColor = !aAccOptions.GetIsForPagePreviews() && GetSettings().GetStyleSettings().GetHighContrastMode();
232 if( bUseWhiteColor )
234 maDocumentColor = Color( COL_WHITE );
236 else
238 svtools::ColorConfig aColorConfig;
239 maDocumentColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
242 GDIMetaFile* pMtf = NULL;
244 if(pDoc)
246 SdPage * pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD );
247 if( pPage )
249 SdrOutliner& rOutl = pDoc->GetDrawOutliner();
250 Color aOldBackgroundColor = rOutl.GetBackgroundColor();
251 rOutl.SetBackgroundColor( maDocumentColor );
253 pMtf = new GDIMetaFile;
255 VirtualDevice aVDev;
257 const Fraction aFrac( pDoc->GetScaleFraction() );
258 const MapMode aMap( pDoc->GetScaleUnit(), Point(), aFrac, aFrac );
260 aVDev.SetMapMode( aMap );
262 // #109058# Disable output, as we only want to record a metafile
263 aVDev.EnableOutput( FALSE );
265 pMtf->Record( &aVDev );
267 ::sd::DrawView* pView = new ::sd::DrawView(pDocShell, this, NULL);
270 const Size aSize( pPage->GetSize() );
272 pView->SetBordVisible( FALSE );
273 pView->SetPageVisible( FALSE );
274 pView->ShowSdrPage( pPage );
276 const Point aNewOrg( pPage->GetLftBorder(), pPage->GetUppBorder() );
277 const Size aNewSize( aSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder(),
278 aSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder() );
279 const Rectangle aClipRect( aNewOrg, aNewSize );
280 MapMode aVMap( aMap );
282 aVDev.Push();
283 aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
284 aVDev.SetRelativeMapMode( aVMap );
285 aVDev.IntersectClipRegion( aClipRect );
287 // Use new StandardCheckVisisbilityRedirector
288 StandardCheckVisisbilityRedirector aRedirector;
289 const Rectangle aRedrawRectangle = Rectangle( Point(), aNewSize );
290 Region aRedrawRegion(aRedrawRectangle);
291 pView->SdrPaintView::CompleteRedraw(&aVDev,aRedrawRegion,&aRedirector);
293 aVDev.Pop();
295 pMtf->Stop();
296 pMtf->WindStart();
297 pMtf->SetPrefMapMode( aMap );
298 pMtf->SetPrefSize( aNewSize );
300 rOutl.SetBackgroundColor( aOldBackgroundColor );
302 delete pView;
306 delete pMetaFile;
307 pMetaFile = pMtf;
309 Invalidate();
312 void SdDocPreviewWin::Notify(SfxBroadcaster&, const SfxHint& rHint)
314 if( rHint.ISA( SfxSimpleHint ) && ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_COLORS_CHANGED )
316 updateViewSettings();
319 void SdDocPreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
321 Control::DataChanged( rDCEvt );
323 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
325 updateViewSettings();