Update ooo320-m1
[ooovba.git] / canvas / source / vcl / canvashelper.hxx
blob444892eba95cc851a2d04827d63ea8cfe7cb521e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: canvashelper.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _VCLCANVAS_CANVASHELPER_HXX_
32 #define _VCLCANVAS_CANVASHELPER_HXX_
34 #include <com/sun/star/rendering/XCanvas.hpp>
35 #include <com/sun/star/rendering/XIntegerBitmap.hpp>
37 #include <vcl/outdev.hxx>
39 #include <canvas/vclwrapper.hxx>
41 #include "cachedbitmap.hxx"
42 #include "outdevprovider.hxx"
44 #include <boost/utility.hpp>
47 namespace vclcanvas
49 class SpriteCanvas;
51 /** Helper class for basic canvas functionality. Also offers
52 optional backbuffer painting, when providing it with a second
53 OutputDevice to render into.
55 class CanvasHelper : private ::boost::noncopyable
57 public:
58 /** Create canvas helper
60 CanvasHelper();
62 /// Release all references
63 void disposing();
65 /** Initialize canvas helper
67 This method late-initializes the canvas helper, providing
68 it with the necessary device and output objects. Note that
69 the CanvasHelper does <em>not</em> take ownership of the
70 passed rDevice reference, nor does it perform any
71 reference counting. Thus, to prevent the reference counted
72 SpriteCanvas object from deletion, the user of this class
73 is responsible for holding ref-counted references itself!
75 @param rDevice
76 Reference device this canvas is associated with
78 @param rOutDev
79 Set primary output device for this canvas. That's where
80 all content is output to.
82 @param bProtect
83 When true, all output operations preserve outdev
84 state. When false, outdev state might change at any time.
86 @param bHaveAlpha
87 When true, hasAlpha() will always return true, otherwise, false.
89 void init( ::com::sun::star::rendering::XGraphicDevice& rDevice,
90 const OutDevProviderSharedPtr& rOutDev,
91 bool bProtect,
92 bool bHaveAlpha );
94 /** Set primary output device
96 This changes the primary output device, where rendering is
97 sent to.
99 void setOutDev( const OutDevProviderSharedPtr& rOutDev,
100 bool bProtect);
102 /** Set secondary output device
104 Used for sprites, to generate mask bitmap.
106 void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev );
109 // CanvasHelper functionality
110 // ==========================
112 // XCanvas (only providing, not implementing the
113 // interface. Also note subtle method parameter differences)
114 void clear();
115 void drawPoint( const ::com::sun::star::rendering::XCanvas* rCanvas,
116 const ::com::sun::star::geometry::RealPoint2D& aPoint,
117 const ::com::sun::star::rendering::ViewState& viewState,
118 const ::com::sun::star::rendering::RenderState& renderState );
119 void drawLine( const ::com::sun::star::rendering::XCanvas* rCanvas,
120 const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
121 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
122 const ::com::sun::star::rendering::ViewState& viewState,
123 const ::com::sun::star::rendering::RenderState& renderState );
124 void drawBezier( const ::com::sun::star::rendering::XCanvas* rCanvas,
125 const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
126 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
127 const ::com::sun::star::rendering::ViewState& viewState,
128 const ::com::sun::star::rendering::RenderState& renderState );
129 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
130 drawPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
131 const ::com::sun::star::uno::Reference<
132 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
133 const ::com::sun::star::rendering::ViewState& viewState,
134 const ::com::sun::star::rendering::RenderState& renderState );
135 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
136 strokePolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
137 const ::com::sun::star::uno::Reference<
138 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
139 const ::com::sun::star::rendering::ViewState& viewState,
140 const ::com::sun::star::rendering::RenderState& renderState,
141 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
142 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
143 strokeTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
144 const ::com::sun::star::uno::Reference<
145 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
146 const ::com::sun::star::rendering::ViewState& viewState,
147 const ::com::sun::star::rendering::RenderState& renderState,
148 const ::com::sun::star::uno::Sequence<
149 ::com::sun::star::rendering::Texture >& textures,
150 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
151 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
152 strokeTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
153 const ::com::sun::star::uno::Reference<
154 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
155 const ::com::sun::star::rendering::ViewState& viewState,
156 const ::com::sun::star::rendering::RenderState& renderState,
157 const ::com::sun::star::uno::Sequence<
158 ::com::sun::star::rendering::Texture >& textures,
159 const ::com::sun::star::uno::Reference<
160 ::com::sun::star::geometry::XMapping2D >& xMapping,
161 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
162 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >
163 queryStrokeShapes( const ::com::sun::star::rendering::XCanvas* rCanvas,
164 const ::com::sun::star::uno::Reference<
165 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
166 const ::com::sun::star::rendering::ViewState& viewState,
167 const ::com::sun::star::rendering::RenderState& renderState,
168 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
169 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
170 fillPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
171 const ::com::sun::star::uno::Reference<
172 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
173 const ::com::sun::star::rendering::ViewState& viewState,
174 const ::com::sun::star::rendering::RenderState& renderState );
175 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
176 fillTexturedPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
177 const ::com::sun::star::uno::Reference<
178 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
179 const ::com::sun::star::rendering::ViewState& viewState,
180 const ::com::sun::star::rendering::RenderState& renderState,
181 const ::com::sun::star::uno::Sequence<
182 ::com::sun::star::rendering::Texture >& textures );
183 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
184 fillTextureMappedPolyPolygon( const ::com::sun::star::rendering::XCanvas* rCanvas,
185 const ::com::sun::star::uno::Reference<
186 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
187 const ::com::sun::star::rendering::ViewState& viewState,
188 const ::com::sun::star::rendering::RenderState& renderState,
189 const ::com::sun::star::uno::Sequence<
190 ::com::sun::star::rendering::Texture >& textures,
191 const ::com::sun::star::uno::Reference<
192 ::com::sun::star::geometry::XMapping2D >& xMapping );
194 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >
195 createFont( const ::com::sun::star::rendering::XCanvas* rCanvas,
196 const ::com::sun::star::rendering::FontRequest& fontRequest,
197 const ::com::sun::star::uno::Sequence<
198 ::com::sun::star::beans::PropertyValue >& extraFontProperties,
199 const ::com::sun::star::geometry::Matrix2D& fontMatrix );
201 ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo >
202 queryAvailableFonts( const ::com::sun::star::rendering::XCanvas* rCanvas,
203 const ::com::sun::star::rendering::FontInfo& aFilter,
204 const ::com::sun::star::uno::Sequence<
205 ::com::sun::star::beans::PropertyValue >& aFontProperties );
207 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
208 drawText( const ::com::sun::star::rendering::XCanvas* rCanvas,
209 const ::com::sun::star::rendering::StringContext& text,
210 const ::com::sun::star::uno::Reference<
211 ::com::sun::star::rendering::XCanvasFont >& xFont,
212 const ::com::sun::star::rendering::ViewState& viewState,
213 const ::com::sun::star::rendering::RenderState& renderState,
214 sal_Int8 textDirection );
216 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
217 drawTextLayout( const ::com::sun::star::rendering::XCanvas* rCanvas,
218 const ::com::sun::star::uno::Reference<
219 ::com::sun::star::rendering::XTextLayout >& layoutetText,
220 const ::com::sun::star::rendering::ViewState& viewState,
221 const ::com::sun::star::rendering::RenderState& renderState );
223 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
224 drawBitmap( const ::com::sun::star::rendering::XCanvas* rCanvas,
225 const ::com::sun::star::uno::Reference<
226 ::com::sun::star::rendering::XBitmap >& xBitmap,
227 const ::com::sun::star::rendering::ViewState& viewState,
228 const ::com::sun::star::rendering::RenderState& renderState );
229 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
230 drawBitmapModulated( const ::com::sun::star::rendering::XCanvas* rCanvas,
231 const ::com::sun::star::uno::Reference<
232 ::com::sun::star::rendering::XBitmap >& xBitmap,
233 const ::com::sun::star::rendering::ViewState& viewState,
234 const ::com::sun::star::rendering::RenderState& renderState );
235 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice >
236 getDevice();
238 // BitmapCanvasHelper functionality
239 // ================================
241 void copyRect( const ::com::sun::star::rendering::XCanvas* rCanvas,
242 const ::com::sun::star::uno::Reference<
243 ::com::sun::star::rendering::XBitmapCanvas >& sourceCanvas,
244 const ::com::sun::star::geometry::RealRectangle2D& sourceRect,
245 const ::com::sun::star::rendering::ViewState& sourceViewState,
246 const ::com::sun::star::rendering::RenderState& sourceRenderState,
247 const ::com::sun::star::geometry::RealRectangle2D& destRect,
248 const ::com::sun::star::rendering::ViewState& destViewState,
249 const ::com::sun::star::rendering::RenderState& destRenderState );
251 ::com::sun::star::geometry::IntegerSize2D getSize();
253 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas > queryBitmapCanvas();
255 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >
256 getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
257 sal_Bool beFast );
259 ::com::sun::star::uno::Sequence< sal_Int8 >
260 getData( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
261 const ::com::sun::star::geometry::IntegerRectangle2D& rect );
263 void setData( const ::com::sun::star::uno::Sequence< sal_Int8 >& data,
264 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
265 const ::com::sun::star::geometry::IntegerRectangle2D& rect );
267 void setPixel( const ::com::sun::star::uno::Sequence< sal_Int8 >& color,
268 const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
269 const ::com::sun::star::geometry::IntegerPoint2D& pos );
271 ::com::sun::star::uno::Sequence< sal_Int8 >
272 getPixel( ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
273 const ::com::sun::star::geometry::IntegerPoint2D& pos );
275 ::com::sun::star::rendering::IntegerBitmapLayout getMemoryLayout();
277 /// Repaint a cached bitmap
278 bool repaint( const GraphicObjectSharedPtr& rGrf,
279 const ::com::sun::star::rendering::ViewState& viewState,
280 const ::com::sun::star::rendering::RenderState& renderState,
281 const ::Point& rPt,
282 const ::Size& rSz,
283 const GraphicAttr& rAttr ) const;
285 /** Flush drawing queue.
287 This only works for Window canvases, and ensures that all
288 pending render operations are flushed to the
289 driver/hardware.
291 void flush() const;
293 enum ColorType
295 LINE_COLOR, FILL_COLOR, TEXT_COLOR, IGNORE_COLOR
298 // returns transparency of color
299 int setupOutDevState( const ::com::sun::star::rendering::ViewState& viewState,
300 const ::com::sun::star::rendering::RenderState& renderState,
301 ColorType eColorType ) const;
303 /** Called from XCanvas base classes, to notify that content
304 is _about_ to change
306 void modifying() {}
308 bool hasAlpha() const { return mbHaveAlpha; }
310 protected:
311 /** Phyical output device
313 Deliberately not a refcounted reference, because of
314 potential circular references for spritecanvas.
316 ::com::sun::star::rendering::XGraphicDevice* mpDevice;
318 /// Rendering to this outdev preserves its state
319 OutDevProviderSharedPtr mpProtectedOutDev;
321 /// Rendering to this outdev does not preserve its state
322 OutDevProviderSharedPtr mpOutDev;
324 /// Rendering to this outdev does not preserve its state
325 OutDevProviderSharedPtr mp2ndOutDev;
327 /// When true, content is able to represent alpha
328 bool mbHaveAlpha;
330 private:
331 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive >
332 implDrawBitmap( const ::com::sun::star::rendering::XCanvas* rCanvas,
333 const ::com::sun::star::uno::Reference<
334 ::com::sun::star::rendering::XBitmap >& xBitmap,
335 const ::com::sun::star::rendering::ViewState& viewState,
336 const ::com::sun::star::rendering::RenderState& renderState,
337 bool bModulateColors );
339 bool setupTextOutput( ::Point& o_rOutPos,
340 const ::com::sun::star::rendering::ViewState& viewState,
341 const ::com::sun::star::rendering::RenderState& renderState,
342 const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >& xFont ) const;
347 #endif /* _VCLCANVAS_CANVASHELPER_HXX_ */