xref: /trunk/main/svtools/inc/svtools/grfmgr.hxx (revision 3e526e08)
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 _GRFMGR_HXX
25 #define _GRFMGR_HXX
26 
27 #include <vcl/graph.hxx>
28 #include <svtools/svtdllapi.h>
29 
30 // -----------
31 // - Defines -
32 // -----------
33 
34 #define GRFMGR_DRAW_NOTCACHED			    0x00000000UL
35 #define GRFMGR_DRAW_CACHED				    0x00000001UL
36 #define GRFMGR_DRAW_BILINEAR			    0x00000002UL
37 #define GRFMGR_DRAW_USE_DRAWMODE_SETTINGS	0x00000004UL
38 #define GRFMGR_DRAW_SUBSTITUTE	            0x00000008UL
39 #define GRFMGR_DRAW_NO_SUBSTITUTE	        0x00000010UL
40 #define GRFMGR_DRAW_STANDARD			    (GRFMGR_DRAW_CACHED|GRFMGR_DRAW_BILINEAR)
41 
42 // --------------------
43 // - AutoSwap Defines -
44 // --------------------
45 
46 #define GRFMGR_AUTOSWAPSTREAM_LINK		((SvStream*)0x00000000UL)
47 #define GRFMGR_AUTOSWAPSTREAM_LOADED	((SvStream*)0xfffffffdUL)
48 #define GRFMGR_AUTOSWAPSTREAM_TEMP		((SvStream*)0xfffffffeUL)
49 #define GRFMGR_AUTOSWAPSTREAM_NONE		((SvStream*)0xffffffffUL)
50 
51 // ----------------------
52 // - Adjustment Defines -
53 // ----------------------
54 
55 #define ADJUSTMENT_NONE					0x00000000UL
56 #define ADJUSTMENT_DRAWMODE				0x00000001UL
57 #define ADJUSTMENT_COLORS				0x00000002UL
58 #define ADJUSTMENT_MIRROR				0x00000004UL
59 #define ADJUSTMENT_ROTATE				0x00000008UL
60 #define ADJUSTMENT_TRANSPARENCY			0x00000010UL
61 #define ADJUSTMENT_ALL					0xFFFFFFFFUL
62 
63 // ---------
64 // - Enums -
65 // ---------
66 
67 enum GraphicDrawMode
68 {
69 	GRAPHICDRAWMODE_STANDARD = 0,
70 	GRAPHICDRAWMODE_GREYS = 1,
71 	GRAPHICDRAWMODE_MONO = 2,
72 	GRAPHICDRAWMODE_WATERMARK = 3
73 };
74 
75 // ------------
76 // - Forwards -
77 // ------------
78 
79 class GraphicManager;
80 class SvStream;
81 class BitmapWriteAccess;
82 class GraphicCache;
83 class VirtualDevice;
84 struct GrfSimpleCacheObj;
85 struct ImplTileInfo;
86 
87 // ---------------
88 // - GraphicAttr -
89 // ---------------
90 
91 class SVT_DLLPUBLIC GraphicAttr
92 {
93 private:
94 
95 	long			mnDummy1;
96 	long			mnDummy2;
97 	double			mfGamma;
98 	sal_uInt32		mnMirrFlags;
99 	long			mnLeftCrop;
100 	long			mnTopCrop;
101 	long			mnRightCrop;
102 	long			mnBottomCrop;
103 	sal_uInt16			mnRotate10;
104 	short			mnContPercent;
105 	short			mnLumPercent;
106 	short			mnRPercent;
107 	short			mnGPercent;
108 	short			mnBPercent;
109 	sal_Bool			mbInvert;
110 	sal_uInt8			mcTransparency;
111 	GraphicDrawMode	meDrawMode;
112 
113 	void*			mpDummy;
114 
115 public:
116 
117 					GraphicAttr();
118 					~GraphicAttr();
119 
120 	sal_Bool			operator==( const GraphicAttr& rAttr ) const;
operator !=(const GraphicAttr & rAttr) const121 	sal_Bool			operator!=( const GraphicAttr& rAttr ) const { return !( *this == rAttr ); }
122 
SetDrawMode(GraphicDrawMode eDrawMode)123 	void			SetDrawMode( GraphicDrawMode eDrawMode ) { meDrawMode = eDrawMode; }
GetDrawMode() const124 	GraphicDrawMode	GetDrawMode() const { return meDrawMode; }
125 
SetMirrorFlags(sal_uLong nMirrFlags)126 	void			SetMirrorFlags( sal_uLong nMirrFlags ) { mnMirrFlags = nMirrFlags; }
GetMirrorFlags() const127 	sal_uLong			GetMirrorFlags() const { return mnMirrFlags; }
128 
SetCrop(long nLeft_100TH_MM,long nTop_100TH_MM,long nRight_100TH_MM,long nBottom_100TH_MM)129 	void			SetCrop( long nLeft_100TH_MM, long nTop_100TH_MM, long nRight_100TH_MM, long nBottom_100TH_MM )
130 					{
131 						mnLeftCrop = nLeft_100TH_MM; mnTopCrop = nTop_100TH_MM;
132 						mnRightCrop = nRight_100TH_MM; mnBottomCrop = nBottom_100TH_MM;
133 					}
GetLeftCrop() const134 	long			GetLeftCrop() const { return mnLeftCrop; }
GetTopCrop() const135 	long			GetTopCrop() const { return mnTopCrop; }
GetRightCrop() const136 	long			GetRightCrop() const { return mnRightCrop; }
GetBottomCrop() const137 	long			GetBottomCrop() const { return mnBottomCrop; }
138 
SetRotation(sal_uInt16 nRotate10)139 	void			SetRotation( sal_uInt16 nRotate10 ) { mnRotate10 = nRotate10; }
GetRotation() const140 	sal_uInt16			GetRotation() const { return mnRotate10; }
141 
SetLuminance(short nLuminancePercent)142 	void			SetLuminance( short nLuminancePercent ) { mnLumPercent = nLuminancePercent; }
GetLuminance() const143 	short			GetLuminance() const { return mnLumPercent; }
144 
SetContrast(short nContrastPercent)145 	void			SetContrast( short nContrastPercent ) { mnContPercent = nContrastPercent; }
GetContrast() const146 	short			GetContrast() const { return mnContPercent; }
147 
SetChannelR(short nChannelRPercent)148 	void			SetChannelR( short nChannelRPercent ) { mnRPercent = nChannelRPercent; }
GetChannelR() const149 	short			GetChannelR() const { return mnRPercent; }
150 
SetChannelG(short nChannelGPercent)151 	void			SetChannelG( short nChannelGPercent ) { mnGPercent = nChannelGPercent; }
GetChannelG() const152 	short			GetChannelG() const { return mnGPercent; }
153 
SetChannelB(short nChannelBPercent)154 	void			SetChannelB( short nChannelBPercent ) { mnBPercent = nChannelBPercent; }
GetChannelB() const155 	short			GetChannelB() const { return mnBPercent; }
156 
SetGamma(double fGamma)157 	void			SetGamma( double fGamma ) { mfGamma = fGamma; }
GetGamma() const158 	double			GetGamma() const { return mfGamma; }
159 
SetInvert(sal_Bool bInvert)160 	void			SetInvert( sal_Bool bInvert ) { mbInvert = bInvert; }
IsInvert() const161 	sal_Bool			IsInvert() const { return mbInvert; }
162 
SetTransparency(sal_uInt8 cTransparency)163 	void			SetTransparency( sal_uInt8 cTransparency ) { mcTransparency = cTransparency; }
GetTransparency() const164 	sal_uInt8			GetTransparency() const { return mcTransparency; }
165 
IsSpecialDrawMode() const166 	sal_Bool			IsSpecialDrawMode() const { return( meDrawMode != GRAPHICDRAWMODE_STANDARD ); }
IsMirrored() const167 	sal_Bool			IsMirrored() const { return( mnMirrFlags != 0UL ); }
IsCropped() const168 	sal_Bool			IsCropped() const
169 					{
170 						return( mnLeftCrop != 0 || mnTopCrop != 0 ||
171 								mnRightCrop != 0 || mnBottomCrop != 0 );
172 					}
IsRotated() const173 	sal_Bool			IsRotated() const { return( ( mnRotate10 % 3600 ) != 0 ); }
IsTransparent() const174 	sal_Bool			IsTransparent() const { return( mcTransparency > 0 ); }
IsAdjusted() const175 	sal_Bool			IsAdjusted() const
176 					{
177 						return( mnLumPercent != 0 || mnContPercent != 0 || mnRPercent != 0 ||
178 								mnGPercent != 0 || mnBPercent != 0 || mfGamma != 1.0 || mbInvert );
179 					}
180 
181     friend SvStream& operator<<( SvStream& rOStm, const GraphicAttr& rAttr );
182     friend SvStream& operator>>( SvStream& rIStm, GraphicAttr& rAttr );
183 };
184 
185 // -----------------
186 // - GraphicObject -
187 // -----------------
188 
189 class SVT_DLLPUBLIC GraphicObject : public SvDataCopyStream
190 {
191 	friend class GraphicManager;
192 
193 private:
194 
195 	static GraphicManager*	mpGlobalMgr;
196 
197 	Graphic					maGraphic;
198 	GraphicAttr				maAttr;
199 	Size					maPrefSize;
200 	MapMode					maPrefMapMode;
201 	sal_uLong					mnSizeBytes;
202 	GraphicType				meType;
203 	GraphicManager*			mpMgr;
204 	String*					mpLink;
205 	Link*					mpSwapStreamHdl;
206 	String*					mpUserData;
207 	Timer*					mpSwapOutTimer;
208 	GrfSimpleCacheObj*		mpSimpleCache;
209     sal_uLong                   mnAnimationLoopCount;
210 
211     // a unique increasing ID to be able to say which data change is older
212     sal_uLong               mnDataChangeTimeStamp;
213 
214 	void*                   mpDummy2;
215 	sal_Bool				mbAutoSwapped	: 1;
216 	sal_Bool				mbTransparent	: 1;
217 	sal_Bool				mbAnimated		: 1;
218 	sal_Bool				mbEPS			: 1;
219 	sal_Bool				mbIsInSwapIn	: 1;
220 	sal_Bool				mbIsInSwapOut	: 1;
221 	sal_Bool				mbAlpha			: 1;
222 	sal_Bool				mbDummyFlag8	: 1;
223 
224 	void					SVT_DLLPRIVATE ImplConstruct();
225 	void					SVT_DLLPRIVATE ImplAssignGraphicData();
226 	void					SVT_DLLPRIVATE ImplSetGraphicManager( const GraphicManager* pMgr,
227                                                    const ByteString* pID = NULL,
228                                                    const GraphicObject* pCopyObj = NULL );
229 	void					SVT_DLLPRIVATE ImplAutoSwapIn();
ImplIsAutoSwapped() const230 	sal_Bool					SVT_DLLPRIVATE ImplIsAutoSwapped() const { return mbAutoSwapped; }
231 	sal_Bool					SVT_DLLPRIVATE ImplGetCropParams( OutputDevice* pOut, Point& rPt, Size& rSz, const GraphicAttr* pAttr,
232 											   PolyPolygon& rClipPolyPoly, sal_Bool& bRectClipRegion ) const;
233 
234 	/** Render a given number of tiles in an optimized way
235 
236 		This method recursively subdivides the tile rendering problem
237 		in smaller parts, i.e. rendering output size x with few tiles
238 		of size y, which in turn are generated from the original
239 		bitmap in a recursive fashion. The subdivision size can be
240 		controlled by the exponent argument, which specifies the
241 		minimal number of smaller tiles used in one recursion
242 		step. The resulting tile size is given as the integer number
243 		of repetitions of the original bitmap along x and y. As the
244 		exponent need not necessarily divide these numbers without
245 		remainder, the repetition counts are effectively converted to
246 		base-exponent numbers, where each place denotes the number of
247 		times the corresponding tile size is rendered.
248 
249         @param rVDev
250         Virtual device to render everything into
251 
252         @param nExponent
253         Number of repetitions per subdivision step, _must_ be greater than 1
254 
255         @param nNumTilesX
256         Number of original tiles to generate in x direction
257 
258         @param nNumTilesY
259         Number of original tiles to generate in y direction
260 
261         @param rTileSizePixel
262         Size in pixel of the original tile bitmap to render it in
263 
264         @param pAttr
265         Graphic attributes to be used for rendering
266 
267         @param nFlags
268         Graphic flags to be used for rendering
269 
270         @param rCurrPos
271         Current output point for this recursion level (should start with (0,0))
272 
273         @return true, if everything was successfully rendered.
274     */
275     bool 					SVT_DLLPRIVATE ImplRenderTempTile( VirtualDevice& rVDev, int nExponent,
276                                                 int nNumTilesX, int nNumTilesY,
277                                                 const Size& rTileSizePixel,
278                                                 const GraphicAttr* pAttr, sal_uLong nFlags );
279 
280     /// internally called by ImplRenderTempTile()
281     bool 					SVT_DLLPRIVATE ImplRenderTileRecursive( VirtualDevice& rVDev, int nExponent, int nMSBFactor,
282                                                      int nNumOrigTilesX, int nNumOrigTilesY,
283                                                      int nRemainderTilesX, int nRemainderTilesY,
284                                                      const Size& rTileSizePixel, const GraphicAttr* pAttr,
285                                                      sal_uLong nFlags, ImplTileInfo& rTileInfo );
286 
287     bool 					SVT_DLLPRIVATE ImplDrawTiled( OutputDevice* pOut, const Rectangle& rArea, const Size& rSizePixel,
288                                            const Size& rOffset, const GraphicAttr* pAttr, sal_uLong nFlags, int nTileCacheSize1D );
289 
290     bool 					SVT_DLLPRIVATE ImplDrawTiled( OutputDevice& rOut, const Point& rPos,
291                                            int nNumTilesX, int nNumTilesY,
292                                            const Size& rTileSize,
293                                            const GraphicAttr* pAttr, sal_uLong nFlags );
294 
295     void 					SVT_DLLPRIVATE ImplTransformBitmap( BitmapEx& 			rBmpEx,
296                                                  const GraphicAttr& rAttr,
297                                                  const Size&		rCropLeftTop,
298                                                  const Size&		rCropRightBottom,
299                                                  const Rectangle&	rCropRect,
300                                                  const Size& 		rDstSize,
301                                                  sal_Bool				bEnlarge ) const;
302 
303 							DECL_LINK( ImplAutoSwapOutHdl, void* );
304 
305     // Handle evtl. needed AfterDataChanges, needs to be called when new
306     // graphic data is swapped in/added to the GraphicManager
307     void ImplAfterDataChange();
308 
309 protected:
310 
311 	virtual void			GraphicManagerDestroyed();
312 	virtual SvStream*		GetSwapStream() const;
313 
314 	// !!! to be removed
315 	virtual	sal_uLong			GetReleaseFromCache() const;
316 
317 	virtual void			Load( SvStream& );
318     virtual void			Save( SvStream& );
319     virtual void			Assign( const SvDataCopyStream& );
320 
321 public:
322 
323 	                        TYPEINFO();
324 
325 							GraphicObject( const GraphicManager* pMgr = NULL );
326 							GraphicObject( const Graphic& rGraphic, const GraphicManager* pMgr = NULL );
327 							GraphicObject( const Graphic& rGraphic, const String& rLink, const GraphicManager* pMgr = NULL );
328 							GraphicObject( const GraphicObject& rCacheObj, const GraphicManager* pMgr = NULL );
329 							GraphicObject( const ByteString& rUniqueID, const GraphicManager* pMgr = NULL );
330 							~GraphicObject();
331 
332 	GraphicObject&			operator=( const GraphicObject& rCacheObj );
333 	sal_Bool					operator==( const GraphicObject& rCacheObj ) const;
operator !=(const GraphicObject & rCacheObj) const334 	sal_Bool					operator!=( const GraphicObject& rCacheObj ) const { return !( *this == rCacheObj ); }
335 
HasSwapStreamHdl() const336 	sal_Bool					HasSwapStreamHdl() const { return( mpSwapStreamHdl != NULL && mpSwapStreamHdl->IsSet() ); }
337 	void					SetSwapStreamHdl();
338 	void					SetSwapStreamHdl( const Link& rHdl, const sal_uLong nSwapOutTimeout = 0UL );
339 	Link					GetSwapStreamHdl() const;
GetSwapOutTimeout() const340 	sal_uLong					GetSwapOutTimeout() const { return( mpSwapOutTimer ? mpSwapOutTimer->GetTimeout() : 0 ); }
341 
342 	void					FireSwapInRequest();
343 	void					FireSwapOutRequest();
344 
345 	void					SetGraphicManager( const GraphicManager& rMgr );
GetGraphicManager() const346 	GraphicManager&			GetGraphicManager() const { return *mpMgr; }
347 
348 	sal_Bool					IsCached( OutputDevice* pOut, const Point& rPt, const Size& rSz,
349 									  const GraphicAttr* pAttr = NULL, sal_uLong nFlags = GRFMGR_DRAW_STANDARD) const;
350 	void					ReleaseFromCache();
351 
352 	const Graphic&			GetGraphic() const;
353 	void					SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj = 0);
354 	void					SetGraphic( const Graphic& rGraphic, const String& rLink );
355 
356     /** Get graphic transformed according to given attributes
357 
358     	This method returns a Graphic transformed, cropped and scaled
359     	to the given parameters, ready to be rendered to printer or
360     	display. The returned graphic has the same visual appearance
361     	as if it had been drawn via GraphicObject::Draw() to a
362     	specific output device.
363 
364         @param rDestSize
365         Desired output size in logical coordinates. The mapmode to
366         interpret these logical coordinates in is given by the second
367         parameter, rDestMap.
368 
369         @param rDestMap
370         Mapmode the output should be interpreted in. This is used to
371         interpret rDestSize, to set the appropriate PrefMapMode on the
372         returned Graphic, and to deal correctly with metafile graphics.
373 
374         @param rAttr
375         Graphic attributes used to transform the graphic. This
376         includes cropping, rotation, mirroring, and various color
377         adjustment parameters.
378 
379         @return the readily transformed Graphic
380      */
381     Graphic 				GetTransformedGraphic( const Size& rDestSize, const MapMode& rDestMap, const GraphicAttr& rAttr ) const;
382 	Graphic					GetTransformedGraphic( const GraphicAttr* pAttr = NULL ) const; // TODO: Change to Impl
383 
384 	void					SetAttr( const GraphicAttr& rAttr );
GetAttr() const385 	const GraphicAttr&		GetAttr() const { return maAttr; }
386 
HasLink() const387 	sal_Bool					HasLink() const { return( mpLink != NULL && mpLink->Len() > 0 ); }
388 	void					SetLink();
389 	void					SetLink( const String& rLink );
390 	String					GetLink() const;
391 
HasUserData() const392 	sal_Bool					HasUserData() const { return( mpUserData != NULL && mpUserData->Len() > 0 ); }
393 	void					SetUserData();
394 	void					SetUserData( const String& rUserData );
395 	String					GetUserData() const;
396 
397 	ByteString				GetUniqueID() const;
398 
GetType() const399 	GraphicType				GetType() const { return meType; }
GetPrefSize() const400 	const Size&				GetPrefSize() const { return maPrefSize; }
GetPrefMapMode() const401 	const MapMode&			GetPrefMapMode() const { return maPrefMapMode; }
GetSizeBytes() const402 	sal_uLong				GetSizeBytes() const { return mnSizeBytes; }
403 	sal_uLong				GetChecksum() const;
IsTransparent() const404 	sal_Bool				IsTransparent() const { return mbTransparent; }
IsAlpha() const405 	sal_Bool				IsAlpha() const { return mbAlpha; }
IsAnimated() const406 	sal_Bool				IsAnimated() const { return mbAnimated; }
IsEPS() const407 	sal_Bool				IsEPS() const { return mbEPS; }
408 
409 	void					ResetAnimationLoopCount();
410 	List*					GetAnimationInfoList() const;
GetAnimationNotifyHdl() const411 	Link					GetAnimationNotifyHdl() const { return maGraphic.GetAnimationNotifyHdl(); }
412 	void					SetAnimationNotifyHdl( const Link& rLink );
413 
414 	sal_Bool					SwapOut();
415 	sal_Bool					SwapOut( SvStream* pOStm );
416 	sal_Bool					SwapIn();
417 	sal_Bool					SwapIn( SvStream* pIStm );
418 
IsInSwapIn() const419 	sal_Bool					IsInSwapIn() const { return mbIsInSwapIn; }
IsInSwapOut() const420 	sal_Bool					IsInSwapOut() const { return mbIsInSwapOut; }
IsInSwap() const421 	sal_Bool					IsInSwap() const { return( mbIsInSwapOut || mbIsInSwapOut ); }
IsSwappedOut() const422 	sal_Bool					IsSwappedOut() const { return( mbAutoSwapped || maGraphic.IsSwapOut() ); }
423 	void					SetSwapState();
424 
425 	sal_Bool					Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
426 								  const GraphicAttr* pAttr = NULL, sal_uLong nFlags = GRFMGR_DRAW_STANDARD );
427 
428     sal_Bool DrawWithPDFHandling( OutputDevice& rOutDev,
429                               const Point& rPt, const Size& rSz,
430                               const GraphicAttr* pGrfAttr = NULL,
431                               const sal_uLong nFlags = GRFMGR_DRAW_STANDARD );
432 
433     /** Draw the graphic repeatedly into the given output rectangle
434 
435     	@param pOut
436         OutputDevice where the rendering should take place
437 
438         @param rArea
439         The output area that is filled with tiled instances of this graphic
440 
441         @param rSize
442         The actual size of a single tile
443 
444         @param rOffset
445         Offset from the left, top position of rArea, where to start
446         the tiling. The upper left corner of the graphic tilings will
447         virtually start at this position. Concretely, only that many
448         tiles are drawn to completely fill the given output area.
449 
450         @param pAttr
451         Optional GraphicAttr
452 
453         @param nFlags
454         Optional rendering flags
455 
456         @param nTileCacheSize1D
457         Optional dimension of the generated cache tiles. The pOut sees
458         a number of tile draws, which have approximately
459         nTileCacheSize1D times nTileCacheSize1D bitmap sizes if the
460         tile bitmap is smaller. Otherwise, the tile is drawn as
461         is. This is useful if e.g. you want only a few, very large
462         bitmap drawings appear on the outdev.
463 
464         @return sal_True, if drawing completed successfully
465      */
466 	sal_Bool					DrawTiled( OutputDevice* pOut, const Rectangle& rArea, const Size& rSize,
467                                        const Size& rOffset, const GraphicAttr* pAttr = NULL,
468                                        sal_uLong nFlags = GRFMGR_DRAW_STANDARD, int nTileCacheSize1D=128 );
469 
470 	sal_Bool					StartAnimation( OutputDevice* pOut, const Point& rPt, const Size& rSz, long nExtraData = 0L,
471 											const GraphicAttr* pAttr = NULL, sal_uLong nFlags = GRFMGR_DRAW_STANDARD,
472 											OutputDevice* pFirstFrameOutDev = NULL );
473 
474 	void					StopAnimation( OutputDevice* pOut = NULL, long nExtraData = 0L );
475 
476     friend SvStream&		operator<<( SvStream& rOStm, const GraphicObject& rGraphicObj );
477     friend SvStream&		operator>>( SvStream& rIStm, GraphicObject& rGraphicObj );
478 
479 	static GraphicObject CreateGraphicObjectFromURL( const ::rtl::OUString &rURL );
480 
481     // create CropScaling information
482     // fWidth, fHeight: object size
483     // f*Crop: crop values relative to original bitmap size
484     basegfx::B2DVector calculateCropScaling(
485         double fWidth,
486         double fHeight,
487         double fLeftCrop,
488         double fTopCrop,
489         double fRightCrop,
490         double fBottomCrop) const;
491 
492     // read access
GetDataChangeTimeStamp() const493     sal_uLong GetDataChangeTimeStamp() const { return mnDataChangeTimeStamp; }
494 
495     // restart SwapOut timer; this is like touching in a cache to reset to the full timeout value
496     void restartSwapOutTimer() const;
497 };
498 
499 // ------------------
500 // - GraphicManager -
501 // ------------------
502 
503 class SVT_DLLPUBLIC GraphicManager
504 {
505 	friend class GraphicObject;
506 	friend class GraphicDisplayCacheEntry;
507 
508 private:
509 
510 	List			maObjList;
511 	GraphicCache*	mpCache;
512 
GraphicManager(const GraphicManager &)513 					GraphicManager( const GraphicManager& ) {}
operator =(const GraphicManager &)514 	GraphicManager&	operator=( const GraphicManager& ) { return *this; }
515 
516 	sal_Bool			SVT_DLLPRIVATE ImplDraw( OutputDevice* pOut, const Point& rPt,
517 							  const Size& rSz, GraphicObject& rObj,
518 							  const GraphicAttr& rAttr,
519                               const sal_uLong nFlags, sal_Bool& rCached );
520 
521 	sal_Bool			SVT_DLLPRIVATE ImplCreateOutput( OutputDevice* pOut, const Point& rPt, const Size& rSz,
522 									  const BitmapEx& rBmpEx, const GraphicAttr& rAttr,
523                                       const sal_uLong nFlags, BitmapEx* pBmpEx = NULL );
524     sal_Bool            SVT_DLLPRIVATE ImplCreateOutput( OutputDevice* pOut,
525                                       const Point& rPt, const Size& rSz,
526                                       const GDIMetaFile& rMtf, const GraphicAttr& rAttr,
527                                       const sal_uLong nFlags, GDIMetaFile& rOutMtf, BitmapEx& rOutBmpEx );
528 
529 	sal_Bool			SVT_DLLPRIVATE ImplCreateScaled( const BitmapEx& rBmpEx,
530 									  long* pMapIX, long* pMapFX, long* pMapIY, long* pMapFY,
531 									  long nStartX, long nEndX, long nStartY, long nEndY,
532                                       BitmapEx& rOutBmpEx );
533 
534 	sal_Bool			SVT_DLLPRIVATE ImplCreateRotatedScaled( const BitmapEx& rBmpEx,
535 											 sal_uInt16 nRot10, const Size& rOutSzPix, const Size& rUntSzPix,
536 											 long* pMapIX, long* pMapFX, long* pMapIY, long* pMapFY,
537 											 long nStartX, long nEndX, long nStartY, long nEndY,
538                                              BitmapEx& rOutBmpEx );
539 
540 	static void		SVT_DLLPRIVATE ImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags );
541 	static void		SVT_DLLPRIVATE ImplAdjust( GDIMetaFile& rMtf, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags );
542 	static void		SVT_DLLPRIVATE ImplAdjust( Animation& rAnimation, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags );
543 
544 	static void		SVT_DLLPRIVATE ImplDraw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
545 							  const GDIMetaFile& rMtf, const GraphicAttr& rAttr );
546 
547 					// Only used by GraphicObject's Ctor's and Dtor's
548 	void			SVT_DLLPRIVATE ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubstitute,
549                                      const ByteString* pID = NULL,
550                                      const GraphicObject* pCopyObj = NULL );
551 	void			SVT_DLLPRIVATE ImplUnregisterObj( const GraphicObject& rObj );
ImplHasObjects() const552 	inline sal_Bool		SVT_DLLPRIVATE ImplHasObjects() const { return( maObjList.Count() > 0UL ); }
553 
554 					// Only used in swap case by GraphicObject
555 	void			SVT_DLLPRIVATE ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj );
556 	sal_Bool			SVT_DLLPRIVATE ImplFillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute );
557 	void			SVT_DLLPRIVATE ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj );
558 
559 	ByteString		SVT_DLLPRIVATE ImplGetUniqueID( const GraphicObject& rObj ) const;
560 
561     // This method allows to check memory footprint for all currently swapped in GraphicObjects on this GraphicManager
562     // which are based on Bitmaps. This is needed on 32Bit systems and only does something on those systems. The problem
563     // to solve is that normally the SwapOut is timer-driven, but even with short timer settings there are situations
564     // where this does not trigger - or in other words: A maximum limitation for GraphicManagers was not in place before.
565     // For 32Bit systems this leads to situations where graphics will be missing. This method will actively swap out
566     // the longest swapped in graphics until a maximum memory boundary (derived from user settings in tools/options/memory)
567     // is no longer exceeded
568     void ImplCheckSizeOfSwappedInGraphics();
569 
570 public:
571 
572 					GraphicManager( sal_uLong nCacheSize = 10000000UL, sal_uLong nMaxObjCacheSize = 2400000UL );
573 					~GraphicManager();
574 
575 	void			SetMaxCacheSize( sal_uLong nNewCacheSize );
576 	sal_uLong			GetMaxCacheSize() const;
577 
578 	void			SetMaxObjCacheSize( sal_uLong nNewMaxObjSize, sal_Bool bDestroyGreaterCached = sal_False );
579 	sal_uLong			GetMaxObjCacheSize() const;
580 
581 	sal_uLong			GetUsedCacheSize() const;
582 	sal_uLong			GetFreeCacheSize() const;
583 
584     void            SetCacheTimeout( sal_uLong nTimeoutSeconds );
585     sal_uLong           GetCacheTimeout() const;
586 
587 	void			ClearCache();
588 
589 	void			ReleaseFromCache( const GraphicObject& rObj );
590 
591 	sal_Bool			IsInCache( OutputDevice* pOut, const Point& rPt, const Size& rSz,
592 							   const GraphicObject& rObj, const GraphicAttr& rAttr ) const;
593 
594 	sal_Bool			DrawObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
595 							 GraphicObject& rObj, const GraphicAttr& rAttr,
596 							 const sal_uLong nFlags, sal_Bool& rCached );
597 };
598 
599 #endif // _GRFMGR_HXX
600