sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / filter.hxx
blob3ff171b4f199253c10aa18199df06068803c28f5
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: filter.hxx,v $
10 * $Revision: 1.4 $
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 _FILTER_HXX
32 #define _FILTER_HXX
34 #ifndef _FLTCALL_HXX
35 #include <bf_svtools/fltcall.hxx>
36 #endif
38 #ifndef INCLUDED_SVTDLLAPI_H
39 #include "bf_svtools/svtdllapi.h"
40 #endif
42 #ifndef _STREAM_HXX //autogen
43 #include <tools/stream.hxx>
44 #endif
45 #ifndef _SV_GRAPH_HXX //autogen
46 #include <vcl/graph.hxx>
47 #endif
48 #ifndef _GEN_HXX //autogen
49 #include <tools/gen.hxx>
50 #endif
51 #ifndef _URLOBJ_HXX
52 #include <tools/urlobj.hxx>
53 #endif
55 #ifndef _SV_FIELD_HXX
56 #include <vcl/field.hxx>
57 #endif
59 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_
60 #include <com/sun/star/uno/Sequence.h>
61 #endif
62 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
63 #include <com/sun/star/beans/PropertyValue.hpp>
64 #endif
66 class Window;
67 struct ConvertData;
69 namespace binfilter
72 // -----------------------
73 // - GraphicFilter-Types -
74 // -----------------------
76 struct ImplDirEntryHelper
78 static BOOL Exists( const INetURLObject& rObj );
79 static void Kill( const String& rStr );
84 #define OPT_FILTERSECTION "Graphic"
86 #define GRFILTER_OK 0
87 #define GRFILTER_OPENERROR 1
88 #define GRFILTER_IOERROR 2
89 #define GRFILTER_FORMATERROR 3
90 #define GRFILTER_VERSIONERROR 4
91 #define GRFILTER_FILTERERROR 5
92 #define GRFILTER_ABORT 6
93 #define GRFILTER_TOOBIG 7
95 #define GRFILTER_FORMAT_NOTFOUND ((USHORT)0xFFFF)
96 #define GRFILTER_FORMAT_DONTKNOW ((USHORT)0xFFFF)
98 #define GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG 00000001
99 #define GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG 00000002
100 #define GRFILTER_I_FLAGS_FOR_PREVIEW 00000004
101 #define GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD 00000010
103 #define IMP_BMP "SVBMP"
104 #define IMP_SVMETAFILE "SVMETAFILE"
105 #define IMP_WMF "SVWMF"
106 #define IMP_EMF "SVEMF"
107 #define IMP_SVSGF "SVSGF"
108 #define IMP_SVSGV "SVSGV"
109 #define IMP_GIF "SVIGIF"
110 #define IMP_PNG "SVIPNG"
111 #define IMP_JPEG "SVIJPEG"
112 #define IMP_XBM "SVIXBM"
113 #define IMP_XPM "SVIXPM"
114 #define EXP_BMP "SVBMP"
115 #define EXP_SVMETAFILE "SVMETAFILE"
116 #define EXP_WMF "SVWMF"
117 #define EXP_EMF "SVEMF"
118 #define EXP_JPEG "SVEJPEG"
119 #define EXP_SVG "SVESVG"
120 #define EXP_PNG "SVEPNG"
122 #define BMP_SHORTNAME "BMP"
123 #define GIF_SHORTNAME "GIF"
124 #define JPG_SHORTNAME "JPG"
125 #define MET_SHORTNAME "MET"
126 #define PCT_SHORTNAME "PCT"
127 #define PNG_SHORTNAME "PNG"
128 #define SVM_SHORTNAME "SVM"
129 #define TIF_SHORTNAME "TIF"
130 #define WMF_SHORTNAME "WMF"
131 #define EMF_SHORTNAME "EMF"
133 // ------------------------------------
134 // - Info-Klasse fuer alle von uns
135 // unterstuetzten Grafik-Fileformate
136 // ------------------------------------
138 #define GFF_NOT ( (USHORT)0x0000 )
139 #define GFF_BMP ( (USHORT)0x0001 )
140 #define GFF_GIF ( (USHORT)0x0002 )
141 #define GFF_JPG ( (USHORT)0x0003 )
142 #define GFF_PCD ( (USHORT)0x0004 )
143 #define GFF_PCX ( (USHORT)0x0005 )
144 #define GFF_PNG ( (USHORT)0x0006 )
145 #define GFF_TIF ( (USHORT)0x0007 )
146 #define GFF_XBM ( (USHORT)0x0008 )
147 #define GFF_XPM ( (USHORT)0x0009 )
148 #define GFF_PBM ( (USHORT)0x000a )
149 #define GFF_PGM ( (USHORT)0x000b )
150 #define GFF_PPM ( (USHORT)0x000c )
151 #define GFF_RAS ( (USHORT)0x000d )
152 #define GFF_TGA ( (USHORT)0x000e )
153 #define GFF_PSD ( (USHORT)0x000f )
154 #define GFF_EPS ( (USHORT)0x0010 )
155 #define GFF_DXF ( (USHORT)0x00f1 )
156 #define GFF_MET ( (USHORT)0x00f2 )
157 #define GFF_PCT ( (USHORT)0x00f3 )
158 #define GFF_SGF ( (USHORT)0x00f4 )
159 #define GFF_SVM ( (USHORT)0x00f5 )
160 #define GFF_WMF ( (USHORT)0x00f6 )
161 #define GFF_SGV ( (USHORT)0x00f7 )
162 #define GFF_EMF ( (USHORT)0x00f8 )
163 #define GFF_XXX ( (USHORT)0xffff )
165 // ---------------
166 // - RequestInfo -
167 // ---------------
169 struct RequestInfo
171 BYTE* pBuffer;
172 ULONG nRealBufferSize;
175 // ---------------------
176 // - GraphicDescriptor -
177 // ---------------------
179 class GraphicDescriptor
181 SvStream* pFileStm;
182 Link aReqLink;
183 String aPathExt;
184 Size aPixSize;
185 Size aLogSize;
186 SvStream* pMemStm;
187 SvStream* pBaseStm;
188 ULONG nStmPos;
189 USHORT nBitsPerPixel;
190 USHORT nPlanes;
191 USHORT nFormat;
192 BOOL bCompressed;
193 BOOL bDataReady;
194 BOOL bLinked;
195 BOOL bLinkChanged;
196 BOOL bWideSearch;
197 BOOL bBaseStm;
198 long nExtra1;
199 long nExtra2;
201 void ImpConstruct();
203 //#if 0 // _SOLAR__PRIVATE
205 BOOL ImpDetectBMP( SvStream& rStm, BOOL bExtendedInfo );
206 BOOL ImpDetectGIF( SvStream& rStm, BOOL bExtendedInfo );
207 BOOL ImpDetectJPG( SvStream& rStm, BOOL bExtendedInfo );
208 BOOL ImpDetectPCD( SvStream& rStm, BOOL bExtendedInfo );
209 BOOL ImpDetectPCX( SvStream& rStm, BOOL bExtendedInfo );
210 BOOL ImpDetectPNG( SvStream& rStm, BOOL bExtendedInfo );
211 BOOL ImpDetectTIF( SvStream& rStm, BOOL bExtendedInfo );
212 BOOL ImpDetectXBM( SvStream& rStm, BOOL bExtendedInfo );
213 BOOL ImpDetectXPM( SvStream& rStm, BOOL bExtendedInfo );
214 BOOL ImpDetectPBM( SvStream& rStm, BOOL bExtendedInfo );
215 BOOL ImpDetectPGM( SvStream& rStm, BOOL bExtendedInfo );
216 BOOL ImpDetectPPM( SvStream& rStm, BOOL bExtendedInfo );
217 BOOL ImpDetectRAS( SvStream& rStm, BOOL bExtendedInfo );
218 BOOL ImpDetectTGA( SvStream& rStm, BOOL bExtendedInfo );
219 BOOL ImpDetectPSD( SvStream& rStm, BOOL bExtendedInfo );
220 BOOL ImpDetectEPS( SvStream& rStm, BOOL bExtendedInfo );
221 BOOL ImpDetectDXF( SvStream& rStm, BOOL bExtendedInfo );
222 BOOL ImpDetectMET( SvStream& rStm, BOOL bExtendedInfo );
223 BOOL ImpDetectPCT( SvStream& rStm, BOOL bExtendedInfo );
224 BOOL ImpDetectSGF( SvStream& rStm, BOOL bExtendedInfo );
225 BOOL ImpDetectSVM( SvStream& rStm, BOOL bExtendedInfo );
226 BOOL ImpDetectWMF( SvStream& rStm, BOOL bExtendedInfo );
227 BOOL ImpDetectSGV( SvStream& rStm, BOOL bExtendedInfo );
228 BOOL ImpDetectEMF( SvStream& rStm, BOOL bExtendedInfo );
230 //#endif
232 GraphicDescriptor( const GraphicDescriptor& );
233 GraphicDescriptor& operator=( const GraphicDescriptor& );
235 protected:
237 SvStream& GetSearchStream() const;
238 const String& GetPathExtension() const;
240 public:
241 // Ctor, um einen Stream zu setzen. Es muss ::Detect() gerufen werden,
242 // um das File zu identifizieren;
243 // da einige Formate ( Mtf's ) keinen eindeutigen Header besitzen,
244 // ist es sinnvoll den Filenamen (inkl. Ext. ) mitanzugeben,
245 // da so das Format ueber die Extension ermittelt werden kann
246 GraphicDescriptor( SvStream& rInStream, const String* pPath = NULL );
248 // Dtor
249 virtual ~GraphicDescriptor();
251 // Startet die Detektion;
252 // bei bExtendedInfo == TRUE werden soweit wie moeglich
253 // Daten aus dem jeweiligen FileHeader ermittelt
254 // ( Groesse, Farbtiefe usw. )
255 virtual BOOL Detect( BOOL bExtendedInfo = FALSE );
257 // liefert das Fileformat nach erfolgreicher Detektion zurueck;
258 // wenn kein Format erkannt wurde, ist das Formart GFF_NOT
259 USHORT GetFileFormat() const { return nFormat; }
261 // liefert die Pixel-Bildgroesse oder 0-Size zurueck
262 const Size& GetSizePixel() const { return (Size&) aPixSize; }
264 // liefert die logische Bildgroesse in 1/100mm oder 0-Size zurueck
265 const Size& GetSize_100TH_MM() const { return (Size&) aLogSize; }
267 // liefert die Bits/Pixel oder 0 zurueck
268 USHORT GetBitsPerPixel() const { return nBitsPerPixel; }
270 // liefert die Anzahl der Planes oder 0 zurueck
271 USHORT GetPlanes() const { return nPlanes; }
273 // zeigt an, ob das Bild evtl. komprimiert (wie auch immer) ist
274 BOOL IsCompressed() const { return bCompressed; }
276 // gibt den LinkHdl zum Setzen der Bytes zurueck
277 const Link& GetRequestHdl() const { return aReqLink; }
279 // gibt die Filternummer des Filters zurueck,
280 // der im GraphicFilter zum Lesen dieses Formats
281 // benoetigt wird
282 static String GetImportFormatShortName( sal_uInt16 nFormat );
285 // -----------------
286 // - GraphicFilter -
287 // -----------------
289 struct FilterErrorEx
291 ULONG nFilterError;
292 ULONG nStreamError;
293 long nDummy1;
294 long nDummy2;
295 long nDummy3;
296 long nDummy4;
298 FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
301 // -----------------------------------------------------------------------------
303 class FilterConfigCache;
304 class GraphicFilter
306 friend class SvFilterOptionsDialog;
308 private:
310 void ImplInit();
311 ULONG ImplSetError( ULONG nError, const SvStream* pStm = NULL );
312 sal_uInt16 ImpTestOrFindFormat( const String& rPath, SvStream& rStream, sal_uInt16& rFormat );
314 DECL_LINK( FilterCallback, ConvertData* pData );
316 protected:
318 String aFilterPath;
319 FilterConfigCache* pConfig;
320 FilterErrorEx* pErrorEx;
321 sal_Bool bAbort;
322 sal_Bool bUseConfig;
323 sal_Bool bDummy1;
324 sal_Bool bDummy2;
325 sal_Bool bDummy3;
326 sal_Bool bDummy4;
327 long nDummy1;
328 long nDummy2;
329 void* pDummy1;
330 void* pDummy2;
332 public:
334 GraphicFilter( sal_Bool bUseConfig = sal_True );
335 ~GraphicFilter();
337 void SetFilterPath( const String& rFilterPath ) { aFilterPath = rFilterPath; };
339 USHORT GetImportFormatCount();
340 USHORT GetImportFormatNumber( const String& rFormatName );
341 USHORT GetImportFormatNumberForMediaType( const String& rMediaType );
342 USHORT GetImportFormatNumberForShortName( const String& rShortName );
343 sal_uInt16 GetImportFormatNumberForTypeName( const String& rType );
344 String GetImportFormatName( USHORT nFormat );
345 String GetImportFormatTypeName( USHORT nFormat );
346 String GetImportFormatMediaType( USHORT nFormat );
347 String GetImportFormatShortName( USHORT nFormat );
348 String GetImportWildcard( USHORT nFormat, sal_Int32 nEntry = 0 );
349 BOOL IsImportPixelFormat( USHORT nFormat );
351 USHORT GetExportFormatCount();
352 USHORT GetExportFormatNumber( const String& rFormatName );
353 USHORT GetExportFormatNumberForMediaType( const String& rShortName );
354 USHORT GetExportFormatNumberForShortName( const String& rShortName );
355 sal_uInt16 GetExportFormatNumberForTypeName( const String& rType );
356 String GetExportFormatName( USHORT nFormat );
357 String GetExportFormatTypeName( USHORT nFormat );
358 String GetExportFormatMediaType( USHORT nFormat );
359 String GetExportFormatShortName( USHORT nFormat );
360 String GetExportWildcard( USHORT nFormat, sal_Int32 nEntry = 0 );
361 USHORT ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath,
362 USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
363 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL );
364 USHORT ExportGraphic( const Graphic& rGraphic, const String& rPath,
365 SvStream& rOStm, USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
366 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL );
368 USHORT CanImportGraphic( const INetURLObject& rPath,
369 USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
370 USHORT * pDeterminedFormat = NULL);
372 USHORT ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
373 USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
374 USHORT * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 );
376 USHORT CanImportGraphic( const String& rPath, SvStream& rStream,
377 USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
378 USHORT * pDeterminedFormat = NULL);
380 USHORT ImportGraphic( Graphic& rGraphic, const String& rPath,
381 SvStream& rStream,
382 USHORT nFormat = GRFILTER_FORMAT_DONTKNOW,
383 USHORT * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 );
385 USHORT ImportGraphic( Graphic& rGraphic, const String& rPath,
386 SvStream& rStream,
387 USHORT nFormat,
388 USHORT * pDeterminedFormat, sal_uInt32 nImportFlags,
389 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData );
391 void Abort() { bAbort = TRUE; }
393 void ResetLastError();
395 static GraphicFilter* GetGraphicFilter();
398 // ------------------------------------
399 // - Windows Metafile Lesen/Schreiben -
400 // ------------------------------------
402 BOOL ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pConfigItem );
403 BOOL WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF );
407 #endif //_FILTER_HXX