xref: /trunk/main/sd/source/ui/inc/PreviewRenderer.hxx (revision cdf0e10c)
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 #ifndef SD_PREVIEW_RENDERER_HXX
29*cdf0e10cSrcweir #define SD_PREVIEW_RENDERER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "drawview.hxx"
32*cdf0e10cSrcweir #include <vcl/image.hxx>
33*cdf0e10cSrcweir #include <vcl/virdev.hxx>
34*cdf0e10cSrcweir #include <svl/listener.hxx>
35*cdf0e10cSrcweir #include <memory>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir class OutputDevice;
39*cdf0e10cSrcweir class SdPage;
40*cdf0e10cSrcweir class VirtualDevice;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace sd {
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir class DrawDocShell;
45*cdf0e10cSrcweir class DrawView;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir class PreviewRenderer
49*cdf0e10cSrcweir     : public SfxListener
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir public:
52*cdf0e10cSrcweir     /** Create a new preview renderer that takes some of its inital values
53*cdf0e10cSrcweir         from the given output device.
54*cdf0e10cSrcweir         @param pTemplate
55*cdf0e10cSrcweir             May be NULL.
56*cdf0e10cSrcweir         @param bPaintFrame
57*cdf0e10cSrcweir             When <TRUE/> (the default) then a frame is painted around the
58*cdf0e10cSrcweir             preview.  This makes the actual preview smaller.
59*cdf0e10cSrcweir     */
60*cdf0e10cSrcweir     PreviewRenderer (
61*cdf0e10cSrcweir         OutputDevice* pTemplate = NULL,
62*cdf0e10cSrcweir         const bool bPaintFrame = true);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     ~PreviewRenderer (void);
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     /** Render a page with the given pixel size.
67*cdf0e10cSrcweir         Use this version when only the width of the preview is known to the
68*cdf0e10cSrcweir         caller.  The height is then calculated according to the aspect
69*cdf0e10cSrcweir         ration of the given page.
70*cdf0e10cSrcweir         @param pPage
71*cdf0e10cSrcweir             The page to render.
72*cdf0e10cSrcweir         @param nWidth
73*cdf0e10cSrcweir             The width of the preview in device coordinates.
74*cdf0e10cSrcweir         @param sSubstitutionText
75*cdf0e10cSrcweir             When the actual preview can not be created for some reason, then
76*cdf0e10cSrcweir             this text is painted in an empty rectangle of the requested size
77*cdf0e10cSrcweir             instead.
78*cdf0e10cSrcweir         @param bObeyHighContrastMode
79*cdf0e10cSrcweir             When <FALSE/> then the high contrast mode of the application is
80*cdf0e10cSrcweir             ignored and the preview is rendered in normal mode.  When
81*cdf0e10cSrcweir             <TRUE/> and high contrast mode is active then the preview is
82*cdf0e10cSrcweir             rendered in high contrast mode.
83*cdf0e10cSrcweir         @param bDisplayPresentationObjects
84*cdf0e10cSrcweir             When <FALSE/> then the PresObj place holders are not displayed
85*cdf0e10cSrcweir             in the returned preview.
86*cdf0e10cSrcweir     */
87*cdf0e10cSrcweir     Image RenderPage (
88*cdf0e10cSrcweir         const SdPage* pPage,
89*cdf0e10cSrcweir         const sal_Int32 nWidth,
90*cdf0e10cSrcweir         const String& sSubstitutionText,
91*cdf0e10cSrcweir         const bool bObeyHighContrastMode = true,
92*cdf0e10cSrcweir         const bool bDisplayPresentationObjects = true);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     /** Render a page with the given pixel size.
95*cdf0e10cSrcweir         @param pPage
96*cdf0e10cSrcweir             The page to render.
97*cdf0e10cSrcweir         @param aPreviewPixelSize
98*cdf0e10cSrcweir             The size in device coordinates of the preview.
99*cdf0e10cSrcweir         @param sSubstitutionText
100*cdf0e10cSrcweir             When the actual preview can not be created for some reason, then
101*cdf0e10cSrcweir             this text is painted in an empty rectangle of the requested size
102*cdf0e10cSrcweir             instead.
103*cdf0e10cSrcweir         @param bObeyHighContrastMode
104*cdf0e10cSrcweir             When <FALSE/> then the high contrast mode of the application is
105*cdf0e10cSrcweir             ignored and the preview is rendered in normal mode.  When
106*cdf0e10cSrcweir             <TRUE/> and high contrast mode is active then the preview is
107*cdf0e10cSrcweir             rendered in high contrast mode.
108*cdf0e10cSrcweir         @param bDisplayPresentationObjects
109*cdf0e10cSrcweir             When <FALSE/> then the PresObj place holders are not displayed
110*cdf0e10cSrcweir             in the returned preview.
111*cdf0e10cSrcweir     */
112*cdf0e10cSrcweir     Image RenderPage (
113*cdf0e10cSrcweir         const SdPage* pPage,
114*cdf0e10cSrcweir         const Size aPreviewPixelSize,
115*cdf0e10cSrcweir         const String& sSubstitutionText,
116*cdf0e10cSrcweir         const bool bObeyHighContrastMode = true,
117*cdf0e10cSrcweir         const bool bDisplayPresentationObjects = true);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     /** Render an image that contains the given substitution text instead of a
120*cdf0e10cSrcweir         slide preview.
121*cdf0e10cSrcweir         @param aPreviewPixelSize
122*cdf0e10cSrcweir             The size in device coordinates of the image.
123*cdf0e10cSrcweir     */
124*cdf0e10cSrcweir     Image RenderSubstitution (
125*cdf0e10cSrcweir         const Size& rPreviewPixelSize,
126*cdf0e10cSrcweir         const String& sSubstitutionText);
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     /** Scale the given bitmap by keeping its aspect ratio to the desired
129*cdf0e10cSrcweir         width.  Add a frame to it afterwards.
130*cdf0e10cSrcweir     */
131*cdf0e10cSrcweir     Image ScaleBitmap (
132*cdf0e10cSrcweir         const BitmapEx& rBitmap,
133*cdf0e10cSrcweir         int nWidth);
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir protected:
136*cdf0e10cSrcweir 	virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir private:
139*cdf0e10cSrcweir     ::std::auto_ptr<VirtualDevice> mpPreviewDevice;
140*cdf0e10cSrcweir     ::std::auto_ptr<DrawView> mpView;
141*cdf0e10cSrcweir     DrawDocShell* mpDocShellOfView;
142*cdf0e10cSrcweir     int mnWidthOfView;
143*cdf0e10cSrcweir     const Color maFrameColor;
144*cdf0e10cSrcweir     const bool mbHasFrame;
145*cdf0e10cSrcweir     static const int snSubstitutionTextSize;
146*cdf0e10cSrcweir     // Width of the frame that is painted arround the preview.
147*cdf0e10cSrcweir     static const int snFrameWidth;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     bool Initialize (
150*cdf0e10cSrcweir         const SdPage* pPage,
151*cdf0e10cSrcweir         const Size& rPixelSize,
152*cdf0e10cSrcweir         const bool bObeyHighContrastMode);
153*cdf0e10cSrcweir     void Cleanup (void);
154*cdf0e10cSrcweir     void PaintPage (
155*cdf0e10cSrcweir         const SdPage* pPage,
156*cdf0e10cSrcweir         const bool bDisplayPresentationObjects);
157*cdf0e10cSrcweir     void PaintSubstitutionText (const String& rSubstitutionText);
158*cdf0e10cSrcweir     void PaintFrame (void);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     /** Set up the map mode so that the given page is renderer into a bitmap
161*cdf0e10cSrcweir         with the specified width.
162*cdf0e10cSrcweir         @param rPage
163*cdf0e10cSrcweir             The page for which the preview is created.
164*cdf0e10cSrcweir         @param rPixelSize
165*cdf0e10cSrcweir             The size of the resulting preview bitmap.  Note that this size
166*cdf0e10cSrcweir             includes the frame.  The actual preview is smaller accordingly.
167*cdf0e10cSrcweir      */
168*cdf0e10cSrcweir     void SetupOutputSize (const SdPage& rPage, const Size& rPixelSize);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     /** When mpView is empty then create a new view and initialize it.
171*cdf0e10cSrcweir         Otherwise just initialize it.
172*cdf0e10cSrcweir     */
173*cdf0e10cSrcweir     void ProvideView (DrawDocShell* pDocShell);
174*cdf0e10cSrcweir };
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir } // end of namespace ::sd
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir #endif
179