xref: /aoo41x/main/sd/source/ui/inc/PreviewRenderer.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_PREVIEW_RENDERER_HXX
29 #define SD_PREVIEW_RENDERER_HXX
30 
31 #include "drawview.hxx"
32 #include <vcl/image.hxx>
33 #include <vcl/virdev.hxx>
34 #include <svl/listener.hxx>
35 #include <memory>
36 
37 
38 class OutputDevice;
39 class SdPage;
40 class VirtualDevice;
41 
42 namespace sd {
43 
44 class DrawDocShell;
45 class DrawView;
46 
47 
48 class PreviewRenderer
49     : public SfxListener
50 {
51 public:
52     /** Create a new preview renderer that takes some of its inital values
53         from the given output device.
54         @param pTemplate
55             May be NULL.
56         @param bPaintFrame
57             When <TRUE/> (the default) then a frame is painted around the
58             preview.  This makes the actual preview smaller.
59     */
60     PreviewRenderer (
61         OutputDevice* pTemplate = NULL,
62         const bool bPaintFrame = true);
63 
64     ~PreviewRenderer (void);
65 
66     /** Render a page with the given pixel size.
67         Use this version when only the width of the preview is known to the
68         caller.  The height is then calculated according to the aspect
69         ration of the given page.
70         @param pPage
71             The page to render.
72         @param nWidth
73             The width of the preview in device coordinates.
74         @param sSubstitutionText
75             When the actual preview can not be created for some reason, then
76             this text is painted in an empty rectangle of the requested size
77             instead.
78         @param bObeyHighContrastMode
79             When <FALSE/> then the high contrast mode of the application is
80             ignored and the preview is rendered in normal mode.  When
81             <TRUE/> and high contrast mode is active then the preview is
82             rendered in high contrast mode.
83         @param bDisplayPresentationObjects
84             When <FALSE/> then the PresObj place holders are not displayed
85             in the returned preview.
86     */
87     Image RenderPage (
88         const SdPage* pPage,
89         const sal_Int32 nWidth,
90         const String& sSubstitutionText,
91         const bool bObeyHighContrastMode = true,
92         const bool bDisplayPresentationObjects = true);
93 
94     /** Render a page with the given pixel size.
95         @param pPage
96             The page to render.
97         @param aPreviewPixelSize
98             The size in device coordinates of the preview.
99         @param sSubstitutionText
100             When the actual preview can not be created for some reason, then
101             this text is painted in an empty rectangle of the requested size
102             instead.
103         @param bObeyHighContrastMode
104             When <FALSE/> then the high contrast mode of the application is
105             ignored and the preview is rendered in normal mode.  When
106             <TRUE/> and high contrast mode is active then the preview is
107             rendered in high contrast mode.
108         @param bDisplayPresentationObjects
109             When <FALSE/> then the PresObj place holders are not displayed
110             in the returned preview.
111     */
112     Image RenderPage (
113         const SdPage* pPage,
114         const Size aPreviewPixelSize,
115         const String& sSubstitutionText,
116         const bool bObeyHighContrastMode = true,
117         const bool bDisplayPresentationObjects = true);
118 
119     /** Render an image that contains the given substitution text instead of a
120         slide preview.
121         @param aPreviewPixelSize
122             The size in device coordinates of the image.
123     */
124     Image RenderSubstitution (
125         const Size& rPreviewPixelSize,
126         const String& sSubstitutionText);
127 
128     /** Scale the given bitmap by keeping its aspect ratio to the desired
129         width.  Add a frame to it afterwards.
130     */
131     Image ScaleBitmap (
132         const BitmapEx& rBitmap,
133         int nWidth);
134 
135 protected:
136 	virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
137 
138 private:
139     ::std::auto_ptr<VirtualDevice> mpPreviewDevice;
140     ::std::auto_ptr<DrawView> mpView;
141     DrawDocShell* mpDocShellOfView;
142     int mnWidthOfView;
143     const Color maFrameColor;
144     const bool mbHasFrame;
145     static const int snSubstitutionTextSize;
146     // Width of the frame that is painted arround the preview.
147     static const int snFrameWidth;
148 
149     bool Initialize (
150         const SdPage* pPage,
151         const Size& rPixelSize,
152         const bool bObeyHighContrastMode);
153     void Cleanup (void);
154     void PaintPage (
155         const SdPage* pPage,
156         const bool bDisplayPresentationObjects);
157     void PaintSubstitutionText (const String& rSubstitutionText);
158     void PaintFrame (void);
159 
160     /** Set up the map mode so that the given page is renderer into a bitmap
161         with the specified width.
162         @param rPage
163             The page for which the preview is created.
164         @param rPixelSize
165             The size of the resulting preview bitmap.  Note that this size
166             includes the frame.  The actual preview is smaller accordingly.
167      */
168     void SetupOutputSize (const SdPage& rPage, const Size& rPixelSize);
169 
170     /** When mpView is empty then create a new view and initialize it.
171         Otherwise just initialize it.
172     */
173     void ProvideView (DrawDocShell* pDocShell);
174 };
175 
176 } // end of namespace ::sd
177 
178 #endif
179