1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "PreviewRenderer.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "DrawDocShell.hxx"
34*cdf0e10cSrcweir #include "drawdoc.hxx"
35*cdf0e10cSrcweir #include "drawview.hxx"
36*cdf0e10cSrcweir #include "sdpage.hxx"
37*cdf0e10cSrcweir #include "ViewShell.hxx"
38*cdf0e10cSrcweir #include <vcl/virdev.hxx>
39*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
40*cdf0e10cSrcweir #include <svx/svdoutl.hxx>
41*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
42*cdf0e10cSrcweir #include <editeng/editstat.hxx>
43*cdf0e10cSrcweir #include <tools/link.hxx>
44*cdf0e10cSrcweir #include <vcl/svapp.hxx>
45*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
46*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
47*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir using namespace ::com::sun::star;
50*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace sd {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir const int PreviewRenderer::snSubstitutionTextSize = 11;
56*cdf0e10cSrcweir const int PreviewRenderer::snFrameWidth = 1;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir namespace {
59*cdf0e10cSrcweir     /** This incarnation of the ViewObjectContactRedirector filters away all
60*cdf0e10cSrcweir         PageObj objects, unconditionally.
61*cdf0e10cSrcweir     */
62*cdf0e10cSrcweir     class ViewRedirector : public ::sdr::contact::ViewObjectContactRedirector
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir     public:
65*cdf0e10cSrcweir         ViewRedirector (void);
66*cdf0e10cSrcweir         virtual ~ViewRedirector (void);
67*cdf0e10cSrcweir         virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
68*cdf0e10cSrcweir             const sdr::contact::ViewObjectContact& rOriginal,
69*cdf0e10cSrcweir                 const sdr::contact::DisplayInfo& rDisplayInfo);
70*cdf0e10cSrcweir     };
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //===== PreviewRenderer =======================================================
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir PreviewRenderer::PreviewRenderer (
79*cdf0e10cSrcweir     OutputDevice* pTemplate,
80*cdf0e10cSrcweir     const bool bHasFrame)
81*cdf0e10cSrcweir     : mpPreviewDevice (new VirtualDevice()),
82*cdf0e10cSrcweir       mpView(NULL),
83*cdf0e10cSrcweir       mpDocShellOfView(NULL),
84*cdf0e10cSrcweir       mnWidthOfView(0),
85*cdf0e10cSrcweir       maFrameColor (svtools::ColorConfig().GetColorValue(svtools::DOCBOUNDARIES).nColor),
86*cdf0e10cSrcweir       mbHasFrame(bHasFrame)
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     if (pTemplate != NULL)
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         mpPreviewDevice->SetDigitLanguage (pTemplate->GetDigitLanguage());
91*cdf0e10cSrcweir         mpPreviewDevice->SetBackground(pTemplate->GetBackground());
92*cdf0e10cSrcweir     }
93*cdf0e10cSrcweir     else
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         mpPreviewDevice->SetBackground(Wallpaper(
96*cdf0e10cSrcweir             Application::GetSettings().GetStyleSettings().GetWindowColor()));
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir PreviewRenderer::~PreviewRenderer (void)
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     if (mpDocShellOfView != NULL)
106*cdf0e10cSrcweir         EndListening (*mpDocShellOfView);
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir Image PreviewRenderer::RenderPage (
113*cdf0e10cSrcweir     const SdPage* pPage,
114*cdf0e10cSrcweir     const sal_Int32 nWidth,
115*cdf0e10cSrcweir     const String& rSubstitutionText,
116*cdf0e10cSrcweir     const bool bObeyHighContrastMode,
117*cdf0e10cSrcweir     const bool bDisplayPresentationObjects)
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     if (pPage != NULL)
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         const Size aPageModelSize (pPage->GetSize());
122*cdf0e10cSrcweir         const double nAspectRatio (
123*cdf0e10cSrcweir             double(aPageModelSize.Width()) / double(aPageModelSize.Height()));
124*cdf0e10cSrcweir         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
125*cdf0e10cSrcweir         const sal_Int32 nHeight (sal::static_int_cast<sal_Int32>(
126*cdf0e10cSrcweir             (nWidth - 2*nFrameWidth) / nAspectRatio + 2*nFrameWidth + 0.5));
127*cdf0e10cSrcweir         return RenderPage (
128*cdf0e10cSrcweir             pPage,
129*cdf0e10cSrcweir             Size(nWidth,nHeight),
130*cdf0e10cSrcweir             rSubstitutionText,
131*cdf0e10cSrcweir             bObeyHighContrastMode,
132*cdf0e10cSrcweir             bDisplayPresentationObjects);
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir     else
135*cdf0e10cSrcweir         return Image();
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir Image PreviewRenderer::RenderPage (
142*cdf0e10cSrcweir     const SdPage* pPage,
143*cdf0e10cSrcweir     Size aPixelSize,
144*cdf0e10cSrcweir     const String& rSubstitutionText,
145*cdf0e10cSrcweir     const bool bObeyHighContrastMode,
146*cdf0e10cSrcweir     const bool bDisplayPresentationObjects)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     Image aPreview;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     if (pPage != NULL)
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir         try
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             if (Initialize(pPage, aPixelSize, bObeyHighContrastMode))
155*cdf0e10cSrcweir             {
156*cdf0e10cSrcweir                 PaintPage(pPage, bDisplayPresentationObjects);
157*cdf0e10cSrcweir                 PaintSubstitutionText(rSubstitutionText);
158*cdf0e10cSrcweir                 PaintFrame();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir                 Size aSize (mpPreviewDevice->GetOutputSizePixel());
161*cdf0e10cSrcweir                 aPreview = mpPreviewDevice->GetBitmap (
162*cdf0e10cSrcweir                     mpPreviewDevice->PixelToLogic(Point(0,0)),
163*cdf0e10cSrcweir                     mpPreviewDevice->PixelToLogic(aSize));
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir                 Cleanup();
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir         catch (const com::sun::star::uno::Exception&)
169*cdf0e10cSrcweir         {
170*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
171*cdf0e10cSrcweir         }
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     return aPreview;
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir Image PreviewRenderer::RenderSubstitution (
181*cdf0e10cSrcweir     const Size& rPreviewPixelSize,
182*cdf0e10cSrcweir     const String& rSubstitutionText)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     Image aPreview;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     try
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         // Set size.
189*cdf0e10cSrcweir         mpPreviewDevice->SetOutputSizePixel(rPreviewPixelSize);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir         // Adjust contrast mode.
192*cdf0e10cSrcweir         const bool bUseContrast (
193*cdf0e10cSrcweir             Application::GetSettings().GetStyleSettings().GetHighContrastMode());
194*cdf0e10cSrcweir         mpPreviewDevice->SetDrawMode (bUseContrast
195*cdf0e10cSrcweir             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
196*cdf0e10cSrcweir             : ViewShell::OUTPUT_DRAWMODE_COLOR);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir         // Set a map mode that makes a typical substitution text completely
199*cdf0e10cSrcweir         // visible.
200*cdf0e10cSrcweir         MapMode aMapMode (mpPreviewDevice->GetMapMode());
201*cdf0e10cSrcweir         aMapMode.SetMapUnit(MAP_100TH_MM);
202*cdf0e10cSrcweir         const double nFinalScale (25.0 * rPreviewPixelSize.Width() / 28000.0);
203*cdf0e10cSrcweir         aMapMode.SetScaleX(nFinalScale);
204*cdf0e10cSrcweir         aMapMode.SetScaleY(nFinalScale);
205*cdf0e10cSrcweir         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
206*cdf0e10cSrcweir         aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(
207*cdf0e10cSrcweir             Point(nFrameWidth,nFrameWidth),aMapMode));
208*cdf0e10cSrcweir         mpPreviewDevice->SetMapMode (aMapMode);
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         // Clear the background.
211*cdf0e10cSrcweir         const Rectangle aPaintRectangle (
212*cdf0e10cSrcweir             Point(0,0),
213*cdf0e10cSrcweir             mpPreviewDevice->GetOutputSizePixel());
214*cdf0e10cSrcweir         mpPreviewDevice->EnableMapMode(sal_False);
215*cdf0e10cSrcweir         mpPreviewDevice->SetLineColor();
216*cdf0e10cSrcweir         svtools::ColorConfig aColorConfig;
217*cdf0e10cSrcweir         mpPreviewDevice->SetFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
218*cdf0e10cSrcweir         mpPreviewDevice->DrawRect (aPaintRectangle);
219*cdf0e10cSrcweir         mpPreviewDevice->EnableMapMode(sal_True);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir         // Paint substitution text and a frame around it.
222*cdf0e10cSrcweir         PaintSubstitutionText (rSubstitutionText);
223*cdf0e10cSrcweir         PaintFrame();
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         const Size aSize (mpPreviewDevice->GetOutputSizePixel());
226*cdf0e10cSrcweir         aPreview = mpPreviewDevice->GetBitmap (
227*cdf0e10cSrcweir             mpPreviewDevice->PixelToLogic(Point(0,0)),
228*cdf0e10cSrcweir             mpPreviewDevice->PixelToLogic(aSize));
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir     catch (const com::sun::star::uno::Exception&)
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     return aPreview;
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir bool PreviewRenderer::Initialize (
242*cdf0e10cSrcweir     const SdPage* pPage,
243*cdf0e10cSrcweir     const Size& rPixelSize,
244*cdf0e10cSrcweir     const bool bObeyHighContrastMode)
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir     bool bSuccess = false;
247*cdf0e10cSrcweir     do
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         if (pPage == NULL)
250*cdf0e10cSrcweir             break;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir         SdrModel* pModel = pPage->GetModel();
253*cdf0e10cSrcweir         if (pModel == NULL)
254*cdf0e10cSrcweir             break;
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         SetupOutputSize(*pPage, rPixelSize);
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         SdDrawDocument* pDocument
259*cdf0e10cSrcweir             = static_cast<SdDrawDocument*>(pPage->GetModel());
260*cdf0e10cSrcweir         DrawDocShell* pDocShell = pDocument->GetDocSh();
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir         // Create view
263*cdf0e10cSrcweir         ProvideView (pDocShell);
264*cdf0e10cSrcweir         if (mpView.get() == NULL)
265*cdf0e10cSrcweir             break;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         // Adjust contrast mode.
268*cdf0e10cSrcweir         bool bUseContrast (bObeyHighContrastMode
269*cdf0e10cSrcweir             && Application::GetSettings().GetStyleSettings().GetHighContrastMode());
270*cdf0e10cSrcweir         mpPreviewDevice->SetDrawMode (bUseContrast
271*cdf0e10cSrcweir             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
272*cdf0e10cSrcweir             : ViewShell::OUTPUT_DRAWMODE_COLOR);
273*cdf0e10cSrcweir         mpPreviewDevice->SetSettings(Application::GetSettings());
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         // Tell the view to show the given page.
276*cdf0e10cSrcweir         SdPage* pNonConstPage = const_cast<SdPage*>(pPage);
277*cdf0e10cSrcweir         if (pPage->IsMasterPage())
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			mpView->ShowSdrPage(mpView->GetModel()->GetMasterPage(pPage->GetPageNum()));
280*cdf0e10cSrcweir 		}
281*cdf0e10cSrcweir         else
282*cdf0e10cSrcweir 		{
283*cdf0e10cSrcweir             mpView->ShowSdrPage(pNonConstPage);
284*cdf0e10cSrcweir 		}
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         // Make sure that a page view exists.
287*cdf0e10cSrcweir         SdrPageView* pPageView = mpView->GetSdrPageView();
288*cdf0e10cSrcweir         if (pPageView == NULL)
289*cdf0e10cSrcweir             break;
290*cdf0e10cSrcweir         // Set background color of page view and outliner.
291*cdf0e10cSrcweir         svtools::ColorConfig aColorConfig;
292*cdf0e10cSrcweir         const Color aPageBackgroundColor(pPage->GetPageBackgroundColor(pPageView));
293*cdf0e10cSrcweir         pPageView->SetApplicationBackgroundColor(aPageBackgroundColor);
294*cdf0e10cSrcweir         SdrOutliner& rOutliner (pDocument->GetDrawOutliner(NULL));
295*cdf0e10cSrcweir         rOutliner.SetBackgroundColor(aPageBackgroundColor);
296*cdf0e10cSrcweir         rOutliner.SetDefaultLanguage(pDocument->GetLanguage(EE_CHAR_LANGUAGE));
297*cdf0e10cSrcweir         mpView->SetApplicationBackgroundColor(
298*cdf0e10cSrcweir             Color(aColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor));
299*cdf0e10cSrcweir         mpPreviewDevice->SetBackground(Wallpaper(aPageBackgroundColor));
300*cdf0e10cSrcweir         mpPreviewDevice->Erase();
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir         bSuccess = true;
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir     while (false);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     return bSuccess;
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir void PreviewRenderer::Cleanup (void)
313*cdf0e10cSrcweir {
314*cdf0e10cSrcweir     mpView->HideSdrPage();
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir void PreviewRenderer::PaintPage (
321*cdf0e10cSrcweir     const SdPage* pPage,
322*cdf0e10cSrcweir     const bool bDisplayPresentationObjects)
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir     // Paint the page.
325*cdf0e10cSrcweir     Rectangle aPaintRectangle (Point(0,0), pPage->GetSize());
326*cdf0e10cSrcweir     Region aRegion (aPaintRectangle);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     // Turn off online spelling and redlining.
329*cdf0e10cSrcweir     SdrOutliner* pOutliner = NULL;
330*cdf0e10cSrcweir     sal_uLong nSavedControlWord (0);
331*cdf0e10cSrcweir     if (mpDocShellOfView!=NULL && mpDocShellOfView->GetDoc()!=NULL)
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         pOutliner = &mpDocShellOfView->GetDoc()->GetDrawOutliner();
334*cdf0e10cSrcweir         nSavedControlWord = pOutliner->GetControlWord();
335*cdf0e10cSrcweir         pOutliner->SetControlWord((nSavedControlWord & ~EE_CNTRL_ONLINESPELLING));
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     // Use a special redirector to prevent PresObj shapes from being painted.
339*cdf0e10cSrcweir     boost::scoped_ptr<ViewRedirector> pRedirector;
340*cdf0e10cSrcweir     if ( ! bDisplayPresentationObjects)
341*cdf0e10cSrcweir         pRedirector.reset(new ViewRedirector());
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     try
344*cdf0e10cSrcweir     {
345*cdf0e10cSrcweir         mpView->CompleteRedraw(mpPreviewDevice.get(), aRegion, pRedirector.get());
346*cdf0e10cSrcweir     }
347*cdf0e10cSrcweir     catch (const ::com::sun::star::uno::Exception&)
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     // Restore the previous online spelling and redlining states.
353*cdf0e10cSrcweir     if (pOutliner != NULL)
354*cdf0e10cSrcweir         pOutliner->SetControlWord(nSavedControlWord);
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir void PreviewRenderer::PaintSubstitutionText (const String& rSubstitutionText)
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     if (rSubstitutionText.Len() > 0)
363*cdf0e10cSrcweir     {
364*cdf0e10cSrcweir         // Set the font size.
365*cdf0e10cSrcweir         const Font& rOriginalFont (mpPreviewDevice->GetFont());
366*cdf0e10cSrcweir         Font aFont (mpPreviewDevice->GetSettings().GetStyleSettings().GetAppFont());
367*cdf0e10cSrcweir         sal_Int32 nHeight (mpPreviewDevice->PixelToLogic(Size(0,snSubstitutionTextSize)).Height());
368*cdf0e10cSrcweir         aFont.SetHeight(nHeight);
369*cdf0e10cSrcweir         mpPreviewDevice->SetFont (aFont);
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir         // Paint the substitution text.
372*cdf0e10cSrcweir         Rectangle aTextBox (
373*cdf0e10cSrcweir             Point(0,0),
374*cdf0e10cSrcweir             mpPreviewDevice->PixelToLogic(
375*cdf0e10cSrcweir                 mpPreviewDevice->GetOutputSizePixel()));
376*cdf0e10cSrcweir         sal_uInt16 nTextStyle =
377*cdf0e10cSrcweir             TEXT_DRAW_CENTER
378*cdf0e10cSrcweir             | TEXT_DRAW_VCENTER
379*cdf0e10cSrcweir             | TEXT_DRAW_MULTILINE
380*cdf0e10cSrcweir             | TEXT_DRAW_WORDBREAK;
381*cdf0e10cSrcweir         mpPreviewDevice->DrawText (aTextBox, rSubstitutionText, nTextStyle);
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir         // Restore the font.
384*cdf0e10cSrcweir         mpPreviewDevice->SetFont (rOriginalFont);
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir void PreviewRenderer::PaintFrame (void)
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir     if (mbHasFrame)
394*cdf0e10cSrcweir     {
395*cdf0e10cSrcweir         // Paint a frame arround the preview.
396*cdf0e10cSrcweir         Rectangle aPaintRectangle (
397*cdf0e10cSrcweir             Point(0,0),
398*cdf0e10cSrcweir             mpPreviewDevice->GetOutputSizePixel());
399*cdf0e10cSrcweir         mpPreviewDevice->EnableMapMode(sal_False);
400*cdf0e10cSrcweir         mpPreviewDevice->SetLineColor(maFrameColor);
401*cdf0e10cSrcweir         mpPreviewDevice->SetFillColor();
402*cdf0e10cSrcweir         mpPreviewDevice->DrawRect(aPaintRectangle);
403*cdf0e10cSrcweir         mpPreviewDevice->EnableMapMode(sal_True);
404*cdf0e10cSrcweir      }
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir void PreviewRenderer::SetupOutputSize (
411*cdf0e10cSrcweir     const SdPage& rPage,
412*cdf0e10cSrcweir     const Size& rFramePixelSize)
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir     // First set the map mode to some arbitrary scale that is numerically
415*cdf0e10cSrcweir     // stable.
416*cdf0e10cSrcweir     MapMode aMapMode (mpPreviewDevice->GetMapMode());
417*cdf0e10cSrcweir 	aMapMode.SetMapUnit(MAP_PIXEL);
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir     // Adapt it to the desired width.
420*cdf0e10cSrcweir     const Size aPageModelSize (rPage.GetSize());
421*cdf0e10cSrcweir     if (aPageModelSize.Width()>0 || aPageModelSize.Height()>0)
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
424*cdf0e10cSrcweir         aMapMode.SetScaleX(
425*cdf0e10cSrcweir             Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width()));
426*cdf0e10cSrcweir         aMapMode.SetScaleY(
427*cdf0e10cSrcweir             Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height()));
428*cdf0e10cSrcweir         aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode));
429*cdf0e10cSrcweir     }
430*cdf0e10cSrcweir     else
431*cdf0e10cSrcweir     {
432*cdf0e10cSrcweir         // We should never get here.
433*cdf0e10cSrcweir         OSL_ASSERT(false);
434*cdf0e10cSrcweir         aMapMode.SetScaleX(1.0);
435*cdf0e10cSrcweir         aMapMode.SetScaleY(1.0);
436*cdf0e10cSrcweir     }
437*cdf0e10cSrcweir     mpPreviewDevice->SetMapMode (aMapMode);
438*cdf0e10cSrcweir     mpPreviewDevice->SetOutputSizePixel(rFramePixelSize);
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir void PreviewRenderer::ProvideView (DrawDocShell* pDocShell)
445*cdf0e10cSrcweir {
446*cdf0e10cSrcweir     if (pDocShell != mpDocShellOfView)
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         // Destroy the view that is connected to the current doc shell.
449*cdf0e10cSrcweir         mpView.reset (NULL);
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir         // Switch our attention, i.e. listening for DYING events, to
452*cdf0e10cSrcweir         // the new doc shell.
453*cdf0e10cSrcweir         if (mpDocShellOfView != NULL)
454*cdf0e10cSrcweir             EndListening (*mpDocShellOfView);
455*cdf0e10cSrcweir         mpDocShellOfView = pDocShell;
456*cdf0e10cSrcweir         if (mpDocShellOfView != NULL)
457*cdf0e10cSrcweir             StartListening (*mpDocShellOfView);
458*cdf0e10cSrcweir     }
459*cdf0e10cSrcweir     if (mpView.get() == NULL)
460*cdf0e10cSrcweir     {
461*cdf0e10cSrcweir         mpView.reset (new DrawView (pDocShell, mpPreviewDevice.get(), NULL));
462*cdf0e10cSrcweir     }
463*cdf0e10cSrcweir 	mpView->SetPreviewRenderer(true);
464*cdf0e10cSrcweir #if 1
465*cdf0e10cSrcweir     mpView->SetPageVisible(false);
466*cdf0e10cSrcweir 	mpView->SetPageBorderVisible(true);
467*cdf0e10cSrcweir 	mpView->SetBordVisible(false);
468*cdf0e10cSrcweir #else
469*cdf0e10cSrcweir     // This works in the slide sorter but prevents the master page
470*cdf0e10cSrcweir     // background being painted in the list of current master pages in the
471*cdf0e10cSrcweir     // task manager.
472*cdf0e10cSrcweir     mpView->SetPagePaintingAllowed(false);
473*cdf0e10cSrcweir #endif
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir Image PreviewRenderer::ScaleBitmap (
480*cdf0e10cSrcweir     const BitmapEx& rBitmapEx,
481*cdf0e10cSrcweir     int nWidth)
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir     Image aPreview;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     do
486*cdf0e10cSrcweir     {
487*cdf0e10cSrcweir         // Adjust contrast mode.
488*cdf0e10cSrcweir         bool bUseContrast = Application::GetSettings().GetStyleSettings().
489*cdf0e10cSrcweir             GetHighContrastMode();
490*cdf0e10cSrcweir         mpPreviewDevice->SetDrawMode (bUseContrast
491*cdf0e10cSrcweir             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
492*cdf0e10cSrcweir             : ViewShell::OUTPUT_DRAWMODE_COLOR);
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir         // Set output size.
495*cdf0e10cSrcweir         Size aSize (rBitmapEx.GetSizePixel());
496*cdf0e10cSrcweir         if (aSize.Width() <= 0)
497*cdf0e10cSrcweir             break;
498*cdf0e10cSrcweir         Size aFrameSize (
499*cdf0e10cSrcweir             nWidth,
500*cdf0e10cSrcweir             (long)((nWidth*1.0 * aSize.Height()) / aSize.Width() + 0.5));
501*cdf0e10cSrcweir         Size aPreviewSize (aFrameSize.Width()-2,aFrameSize.Height()-2);
502*cdf0e10cSrcweir         MapMode aMapMode (mpPreviewDevice->GetMapMode());
503*cdf0e10cSrcweir         aMapMode.SetMapUnit(MAP_PIXEL);
504*cdf0e10cSrcweir         aMapMode.SetOrigin (Point());
505*cdf0e10cSrcweir         aMapMode.SetScaleX (1.0);
506*cdf0e10cSrcweir         aMapMode.SetScaleY (1.0);
507*cdf0e10cSrcweir         mpPreviewDevice->SetMapMode (aMapMode);
508*cdf0e10cSrcweir         mpPreviewDevice->SetOutputSize (aFrameSize);
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir         // Paint a frame arround the preview.
511*cdf0e10cSrcweir         mpPreviewDevice->SetLineColor (maFrameColor);
512*cdf0e10cSrcweir         mpPreviewDevice->SetFillColor ();
513*cdf0e10cSrcweir         mpPreviewDevice->DrawRect (Rectangle(Point(0,0), aFrameSize));
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir         // Paint the bitmap scaled to the desired width.
516*cdf0e10cSrcweir         BitmapEx aScaledBitmap (rBitmapEx.GetBitmap());
517*cdf0e10cSrcweir         aScaledBitmap.Scale (aPreviewSize, BMP_SCALE_INTERPOLATE);
518*cdf0e10cSrcweir         mpPreviewDevice->DrawBitmap (
519*cdf0e10cSrcweir             Point(1,1),
520*cdf0e10cSrcweir             aPreviewSize,
521*cdf0e10cSrcweir             aScaledBitmap.GetBitmap());
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir         // Get the resulting bitmap.
524*cdf0e10cSrcweir         aPreview = mpPreviewDevice->GetBitmap (Point(0,0), aFrameSize);
525*cdf0e10cSrcweir     }
526*cdf0e10cSrcweir     while (false);
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir     return aPreview;
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir void PreviewRenderer::Notify(SfxBroadcaster&, const SfxHint& rHint)
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir 	if (rHint.IsA(TYPE(SfxSimpleHint))
537*cdf0e10cSrcweir         && mpDocShellOfView != NULL)
538*cdf0e10cSrcweir     {
539*cdf0e10cSrcweir         const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
540*cdf0e10cSrcweir         if (pSimpleHint != NULL
541*cdf0e10cSrcweir             && pSimpleHint->GetId() == SFX_HINT_DYING)
542*cdf0e10cSrcweir 		{
543*cdf0e10cSrcweir             // The doc shell is dying.  Our view uses its item pool and
544*cdf0e10cSrcweir             // has to be destroyed as well.  The next call to
545*cdf0e10cSrcweir             // ProvideView will create a new one (for another
546*cdf0e10cSrcweir             // doc shell, of course.)
547*cdf0e10cSrcweir             mpView.reset (NULL);
548*cdf0e10cSrcweir             mpDocShellOfView = NULL;
549*cdf0e10cSrcweir         }
550*cdf0e10cSrcweir     }
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir //===== ViewRedirector ========================================================
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir namespace {
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir ViewRedirector::ViewRedirector (void)
561*cdf0e10cSrcweir {
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir ViewRedirector::~ViewRedirector (void)
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ViewRedirector::createRedirectedPrimitive2DSequence(
575*cdf0e10cSrcweir 	const sdr::contact::ViewObjectContact& rOriginal,
576*cdf0e10cSrcweir 	const sdr::contact::DisplayInfo& rDisplayInfo)
577*cdf0e10cSrcweir {
578*cdf0e10cSrcweir 	SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 	if (pObject==NULL || pObject->GetPage() == NULL)
581*cdf0e10cSrcweir 	{
582*cdf0e10cSrcweir 		// not a SdrObject visualisation (maybe e.g. page) or no page
583*cdf0e10cSrcweir 		return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
584*cdf0e10cSrcweir             rOriginal,
585*cdf0e10cSrcweir             rDisplayInfo);
586*cdf0e10cSrcweir     }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir     const bool bDoCreateGeometry (pObject->GetPage()->checkVisibility( rOriginal, rDisplayInfo, true));
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir     if ( ! bDoCreateGeometry
591*cdf0e10cSrcweir         && (pObject->GetObjInventor() != SdrInventor || pObject->GetObjIdentifier() != OBJ_PAGE))
592*cdf0e10cSrcweir     {
593*cdf0e10cSrcweir         return drawinglayer::primitive2d::Primitive2DSequence();
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir     if (pObject->IsEmptyPresObj())
597*cdf0e10cSrcweir         return drawinglayer::primitive2d::Primitive2DSequence();
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
600*cdf0e10cSrcweir         rOriginal,
601*cdf0e10cSrcweir         rDisplayInfo);
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir } // end of anonymous namespace
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir } // end of namespace ::sd
608