xref: /aoo41x/main/sd/source/ui/inc/PreviewRenderer.hxx (revision c45d927a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_PREVIEW_RENDERER_HXX
25 #define SD_PREVIEW_RENDERER_HXX
26 
27 #include "drawview.hxx"
28 #include <vcl/image.hxx>
29 #include <vcl/virdev.hxx>
30 #include <svl/listener.hxx>
31 #include <memory>
32 
33 
34 class OutputDevice;
35 class SdPage;
36 class VirtualDevice;
37 
38 namespace sd {
39 
40 class DrawDocShell;
41 class DrawView;
42 
43 
44 class PreviewRenderer
45     : public SfxListener
46 {
47 public:
48     /** Create a new preview renderer that takes some of its inital values
49         from the given output device.
50         @param pTemplate
51             May be NULL.
52         @param bPaintFrame
53             When <TRUE/> (the default) then a frame is painted around the
54             preview.  This makes the actual preview smaller.
55     */
56     PreviewRenderer (
57         OutputDevice* pTemplate = NULL,
58         const bool bPaintFrame = true);
59 
60     ~PreviewRenderer (void);
61 
62     /** Render a page with the given pixel size.
63         Use this version when only the width of the preview is known to the
64         caller.  The height is then calculated according to the aspect
65         ration of the given page.
66         @param pPage
67             The page to render.
68         @param nWidth
69             The width of the preview in device coordinates.
70         @param sSubstitutionText
71             When the actual preview can not be created for some reason, then
72             this text is painted in an empty rectangle of the requested size
73             instead.
74         @param bObeyHighContrastMode
75             When <FALSE/> then the high contrast mode of the application is
76             ignored and the preview is rendered in normal mode.  When
77             <TRUE/> and high contrast mode is active then the preview is
78             rendered in high contrast mode.
79         @param bDisplayPresentationObjects
80             When <FALSE/> then the PresObj place holders are not displayed
81             in the returned preview.
82     */
83     Image RenderPage (
84         const SdPage* pPage,
85         const sal_Int32 nWidth,
86         const String& sSubstitutionText,
87         const bool bObeyHighContrastMode = true,
88         const bool bDisplayPresentationObjects = true);
89 
90     /** Render a page with the given pixel size.
91         @param pPage
92             The page to render.
93         @param aPreviewPixelSize
94             The size in device coordinates of the preview.
95         @param sSubstitutionText
96             When the actual preview can not be created for some reason, then
97             this text is painted in an empty rectangle of the requested size
98             instead.
99         @param bObeyHighContrastMode
100             When <FALSE/> then the high contrast mode of the application is
101             ignored and the preview is rendered in normal mode.  When
102             <TRUE/> and high contrast mode is active then the preview is
103             rendered in high contrast mode.
104         @param bDisplayPresentationObjects
105             When <FALSE/> then the PresObj place holders are not displayed
106             in the returned preview.
107     */
108     Image RenderPage (
109         const SdPage* pPage,
110         const Size aPreviewPixelSize,
111         const String& sSubstitutionText,
112         const bool bObeyHighContrastMode = true,
113         const bool bDisplayPresentationObjects = true);
114 
115     /** Render an image that contains the given substitution text instead of a
116         slide preview.
117         @param aPreviewPixelSize
118             The size in device coordinates of the image.
119     */
120     Image RenderSubstitution (
121         const Size& rPreviewPixelSize,
122         const String& sSubstitutionText);
123 
124     /** Scale the given bitmap by keeping its aspect ratio to the desired
125         width.  Add a frame to it afterwards.
126     */
127     Image ScaleBitmap (
128         const BitmapEx& rBitmap,
129         int nWidth);
130 
131 protected:
132 	virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
133 
134 private:
135     ::std::auto_ptr<VirtualDevice> mpPreviewDevice;
136     ::std::auto_ptr<DrawView> mpView;
137     DrawDocShell* mpDocShellOfView;
138     int mnWidthOfView;
139     const Color maFrameColor;
140     const bool mbHasFrame;
141     static const int snSubstitutionTextSize;
142     // Width of the frame that is painted arround the preview.
143     static const int snFrameWidth;
144 
145     bool Initialize (
146         const SdPage* pPage,
147         const Size& rPixelSize,
148         const bool bObeyHighContrastMode);
149     void Cleanup (void);
150     void PaintPage (
151         const SdPage* pPage,
152         const bool bDisplayPresentationObjects);
153     void PaintSubstitutionText (const String& rSubstitutionText);
154     void PaintFrame (void);
155 
156     /** Set up the map mode so that the given page is renderer into a bitmap
157         with the specified width.
158         @param rPage
159             The page for which the preview is created.
160         @param rPixelSize
161             The size of the resulting preview bitmap.  Note that this size
162             includes the frame.  The actual preview is smaller accordingly.
163      */
164     void SetupOutputSize (const SdPage& rPage, const Size& rPixelSize);
165 
166     /** When mpView is empty then create a new view and initialize it.
167         Otherwise just initialize it.
168     */
169     void ProvideView (DrawDocShell* pDocShell);
170 };
171 
172 } // end of namespace ::sd
173 
174 #endif
175