xref: /trunk/main/vcl/inc/vcl/gfxlink.hxx (revision 72583341)
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 _SV_GFXLINK_HXX
25 #define _SV_GFXLINK_HXX
26 
27 #include <vcl/dllapi.h>
28 #include <vcl/sv.h>
29 #include <vcl/mapmod.hxx>
30 #include <tools/stream.hxx>
31 
32 // -------------
33 // - ImpBuffer -
34 // -------------
35 
36 struct ImpBuffer
37 {
38 	sal_uLong		mnRefCount;
39 	sal_uInt8*		mpBuffer;
40 
ImpBufferImpBuffer41 				ImpBuffer( sal_uLong nSize )
42 				{
43 					mnRefCount = 1UL;
44 					mpBuffer = nSize ? new sal_uInt8[ nSize ] : NULL;
45 				}
46 
ImpBufferImpBuffer47 				ImpBuffer( sal_uInt8* pBuf ) { mnRefCount = 1UL; mpBuffer = pBuf; }
48 
~ImpBufferImpBuffer49 				~ImpBuffer() { delete[] mpBuffer; }
50 };
51 
52 // -----------
53 // - ImpSwap -
54 // -----------
55 
56 struct ImpSwap
57 {
58 	rtl::OUString	maURL;
59 	sal_uLong			mnDataSize;
60 	sal_uLong			mnRefCount;
61 
62 					ImpSwap( sal_uInt8* pData, sal_uLong nDataSize );
63 					~ImpSwap();
64 
65 	sal_uInt8*			GetData() const;
66 
IsSwappedImpSwap67 	sal_Bool			IsSwapped() const { return maURL.getLength() > 0; }
68 
69 	void			WriteTo( SvStream& rOStm ) const;
70 };
71 
72 // --------------
73 // - ImpGfxLink -
74 // --------------
75 
76 struct ImpGfxLink
77 {
78     MapMode         maPrefMapMode;
79     Size            maPrefSize;
80     bool			mbPrefMapModeValid;
81     bool			mbPrefSizeValid;
82 
ImpGfxLinkImpGfxLink83     ImpGfxLink() :
84         maPrefMapMode(),
85         maPrefSize(),
86         mbPrefMapModeValid( false ),
87         mbPrefSizeValid( false )
88     {}
89 };
90 
91 //#endif // __PRIVATE
92 
93 // ---------------
94 // - GfxLinkType -
95 // ---------------
96 
97 enum GfxLinkType
98 {
99 	GFX_LINK_TYPE_NONE			= 0,
100 	GFX_LINK_TYPE_EPS_BUFFER	= 1,
101 	GFX_LINK_TYPE_NATIVE_GIF	= 2,	// Don't forget to update the following defines
102 	GFX_LINK_TYPE_NATIVE_JPG	= 3,	// Don't forget to update the following defines
103 	GFX_LINK_TYPE_NATIVE_PNG	= 4,	// Don't forget to update the following defines
104 	GFX_LINK_TYPE_NATIVE_TIF	= 5,	// Don't forget to update the following defines
105 	GFX_LINK_TYPE_NATIVE_WMF	= 6,	// Don't forget to update the following defines
106 	GFX_LINK_TYPE_NATIVE_MET	= 7,	// Don't forget to update the following defines
107 	GFX_LINK_TYPE_NATIVE_PCT	= 8,	// Don't forget to update the following defines
108 	GFX_LINK_TYPE_NATIVE_SVG	= 9,	// Don't forget to update the following defines
109 
110     // #15508# added BMP type support
111     GFX_LINK_TYPE_NATIVE_BMP    = 10,   // Don't forget to update the following defines
112 
113 	GFX_LINK_TYPE_USER			= 0xffff
114 };
115 
116 #define GFX_LINK_FIRST_NATIVE_ID	GFX_LINK_TYPE_NATIVE_GIF
117 #define GFX_LINK_LAST_NATIVE_ID		GFX_LINK_TYPE_NATIVE_BMP
118 
119 // -----------
120 // - GfxLink -
121 // -----------
122 
123 struct ImpBuffer;
124 struct ImpSwap;
125 struct ImpGfxLink;
126 class Graphic;
127 
128 class VCL_DLLPUBLIC GfxLink
129 {
130 private:
131 
132 	GfxLinkType			meType;
133 	ImpBuffer*			mpBuf;
134 	ImpSwap*			mpSwap;
135 	sal_uInt32			mnBufSize;
136 	sal_uInt32			mnUserId;
137     ImpGfxLink*         mpImpData;
138 	sal_uLong				mnExtra2;
139 
140 	SAL_DLLPRIVATE void	ImplCopy( const GfxLink& rGfxLink );
141 
142 public:
143 						GfxLink();
144 						GfxLink( const GfxLink& );
145 						GfxLink( const String& rPath, GfxLinkType nType );
146 						GfxLink( sal_uInt8* pBuf, sal_uInt32 nBufSize, GfxLinkType nType, sal_Bool bOwns );
147 						~GfxLink();
148 
149 	GfxLink&			operator=( const GfxLink& );
150 	sal_Bool			IsEqual( const GfxLink& ) const;
151 
152 	GfxLinkType			GetType() const;
153 
SetUserId(sal_uInt32 nUserId)154 	void				SetUserId( sal_uInt32 nUserId ) { mnUserId = nUserId; }
GetUserId() const155 	sal_uInt32			GetUserId() const { return mnUserId; }
156 
157 	sal_uInt32			GetDataSize() const;
158 	void				SetData( sal_uInt8* pBuf, sal_uInt32 nSize, GfxLinkType nType, sal_Bool bOwns );
159 	const sal_uInt8*			GetData() const;
160 
161 	const Size&			GetPrefSize() const;
162 	void				SetPrefSize( const Size& rPrefSize );
163 	bool 				IsPrefSizeValid();
164 
165 	const MapMode&		GetPrefMapMode() const;
166 	void				SetPrefMapMode( const MapMode& rPrefMapMode );
167 	bool 				IsPrefMapModeValid();
168 
169 	sal_Bool				IsNative() const;
IsUser() const170 	sal_Bool				IsUser() const { return( GFX_LINK_TYPE_USER == meType ); }
171 
172 	sal_Bool				LoadNative( Graphic& rGraphic );
173 
174 	sal_Bool				ExportNative( SvStream& rOStream ) const;
175 
176 	void				SwapOut();
177 	void				SwapIn();
IsSwappedOut() const178 	sal_Bool				IsSwappedOut() const { return( mpSwap != NULL ); }
179 
180 public:
181 
182 	friend VCL_DLLPUBLIC SvStream&	operator<<( SvStream& rOStream, const GfxLink& rGfxLink );
183 	friend VCL_DLLPUBLIC SvStream&	operator>>( SvStream& rIStream, GfxLink& rGfxLink );
184 };
185 
186 #endif
187