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