00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #ifndef INC_CXFILE
00101 #define INC_CXFILE
00102
00103
00104
00105
00106 #include "taglists.h"
00107
00108 #if defined(EXCLUDE_FROM_XARLIB)
00109 #include "xarlib.h"
00110 #endif
00111
00112 class CCLexFile;
00113 class Progress;
00114 class StringBase;
00115 class BaseCamelotFilter;
00116 class CCPanose;
00117 class BitmapSource;
00118
00119 class CXaraFileRecord;
00120 class CXaraFileRecordHandler;
00121 class CamelotRecordHandler;
00122 class StandardDefaultRecordHandler;
00123 class StripSubTreeRecordHandler;
00124 class CXaraFileMapTagToHandler;
00125
00126
00127 #define SIZEOF_XAR_UTF16 2 // UTF16 characters are only 2 byte
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 class CXaraFile : public CCObject
00150 {
00151
00152 CC_DECLARE_DYNAMIC(CXaraFile);
00153
00154 public:
00155 CXaraFile();
00156 virtual ~CXaraFile() { }
00157
00158 virtual BOOL OpenToWrite(CCLexFile* pCCFile);
00159 virtual BOOL OpenToRead(CCLexFile* pCCFile);
00160 virtual BOOL Close();
00161
00162
00163
00164 BOOL SetCompression(BOOL NewState);
00165
00166
00167 virtual BOOL StartCompression();
00168 virtual BOOL StopCompression();
00169 virtual BOOL IsCompressionOn();
00170
00171
00172
00173 virtual CCLexFile* GetCCFile(void) const;
00174
00175
00176 UINT32 GetCurrentRecordSize();
00177
00178 virtual INT32 StartRecord(UINT32 Tag,INT32 Size);
00179 virtual BOOL EndRecord(void);
00180 virtual INT32 StartStreamedRecord(UINT32 Tag,INT32 Size);
00181 virtual BOOL EndStreamedRecord(UINT32 *RecordSize);
00182
00183
00184 UINT32 GetRecordTag();
00185 INT32 GetRecordNum();
00186
00187
00188 virtual BOOL Write(BYTE b);
00189
00190 BOOL Write(UINT32 n);
00191 BOOL Write(INT32 n);
00192 BOOL Write(const DocCoord& Coord);
00193 BOOL Write(BYTE* pBuf,UINT32 Size);
00194 BOOL Write(FLOAT f);
00195 BOOL Write(double d);
00196
00197 BOOL WriteWCHAR(WCHAR w);
00198
00199 BOOL WriteCCPanose(const CCPanose& Panose);
00200
00201 #if !defined(EXCLUDE_FROM_XARLIB)
00202 BOOL WriteBitmapSource(const BitmapSource& Source, UINT32 Height, BaseCamelotFilter* pThisFilter);
00203 #endif
00204
00205 BOOL Write(TCHAR* pStr);
00206 BOOL WriteASCII(TCHAR* pStr);
00207 BOOL WriteUnicode(TCHAR* pStr);
00208
00209
00210
00211 virtual UINT32 Write(CXaraFileRecord* pRecord);
00212
00213
00214
00215 virtual UINT32 WriteDefinitionRecord(CXaraFileRecord* pRecord);
00216
00217
00218 BOOL Read(UINT32* pUINT32);
00219 BOOL Read(BYTE* pBuf,UINT32 Size);
00220 BOOL Read(BYTE* pBYTE);
00221 BOOL Read(FLOAT* pf);
00222 BOOL Read(double* pd);
00223
00224 BOOL ReadWCHAR(WCHAR *pw);
00225
00226 BOOL ReadCCPanose(CCPanose *pPanose);
00227
00228 BOOL Read(TCHAR* pStr,UINT32 MaxChars);
00229 BOOL ReadUnicode(TCHAR* pStr,UINT32 MaxChars);
00230
00231 BOOL ReadNextRecord();
00232 BOOL ReadNextRecordHeader();
00233
00234 virtual UINT32 GetNumBytesWritten() { return NumBytesWritten; }
00235 virtual UINT32 GetNumBytesRead() { return NumBytesRead; }
00236 virtual UINT32 GetTotalNumBytesToRead() { return TotalNumBytesToRead; }
00237 virtual void SetTotalNumBytesToRead(UINT32 n) { TotalNumBytesToRead = n; }
00238
00239 virtual FilePos GetFilePos();
00240
00241 #if !defined(EXCLUDE_FROM_XARLIB)
00242 virtual BOOL SetUpHandlers(BaseCamelotFilter* pThisFilter);
00243 #else
00244 virtual BOOL SetUpHandlers(void);
00245 void SetExternalRecordHandler(void* pMagic, RecordHandler* pfnRecordHandler);
00246
00247 void SetEndOfFile() { EndOfFile = TRUE; }
00248 BOOL IsEndOfFile() { return(EndOfFile); }
00249 #endif
00250
00251 virtual void SetDefaultRecordHandler(CXaraFileRecordHandler* pHandler);
00252 virtual CXaraFileRecordHandler* GetDefaultRecordHandler();
00253
00254 virtual void SetStripSubTreeRecordHandler(StripSubTreeRecordHandler* pHandler);
00255 virtual StripSubTreeRecordHandler* GetStripSubTreeRecordHandler();
00256
00257
00258 void StripNextSubTree();
00259
00260
00261 void GotError(UINT32 errorID);
00262 void GotError( UINT32 errorID , const TCHAR* errorString);
00263
00264
00265 BOOL RegisterRecordHandlers(List* pListOfHandlers);
00266
00267
00268 UINT32 GetLastReadTag() { return ReadTag; }
00269
00270 #if !defined(EXCLUDE_FROM_XARLIB)
00271 void SetFilter(BaseCamelotFilter* pThisFilter) { pFilter = pThisFilter; }
00272 BaseCamelotFilter* GetFilter() { return pFilter; }
00273 #else
00274
00275 void AddAtomicTag(AtomicTagListItem* pItem);
00276 void AddEssentialTag(EssentialTagListItem* pItem);
00277
00278 BOOL IsTagInAtomicList(UINT32 Tag);
00279 BOOL IsTagInEssentialList(UINT32 Tag);
00280
00281 BOOL WriteRemainingAtomicTagDefinitions();
00282 #endif
00283
00284 protected:
00285
00286 virtual CXaraFileRecordHandler* FindHandler(UINT32 Tag);
00287 virtual CXaraFileRecordHandler* SearchForHandler(UINT32 Tag);
00288 virtual CXaraFileRecordHandler* LookUpHandler(UINT32 Tag);
00289
00290 virtual void SetUpHandlerMap();
00291 virtual void ResetHandlers();
00292
00293 protected:
00294
00295
00296 UINT32 WriteRecordHeader(UINT32 Tag, INT32 Size);
00297
00298 virtual BOOL FixStreamedRecordHeader(UINT32 *RecordSize);
00299
00300 virtual void IncNumBytesWritten(UINT32 n){ NumBytesWritten += n; }
00301 virtual void IncNumBytesRead(UINT32 n) { NumBytesRead += n; }
00302
00303 protected:
00304 CXaraFileRecord* pRecord;
00305 BOOL WriteToRecord;
00306
00307
00308
00309 protected:
00310 CCLexFile* pCCFile;
00311 INT32 RecordNumber;
00312 UINT32 NumBytesWritten;
00313 UINT32 NumBytesRead;
00314 UINT32 TotalNumBytesToRead;
00315 UINT32 ProgressID;
00316
00317
00318 UINT32 ReadTag;
00319 UINT32 ReadSize;
00320
00321
00322 List* pRecordHandlerList;
00323
00324
00325 CXaraFileRecordHandler* pDefaultRecordHandler;
00326 CamelotRecordHandler* pStandardDefaultRecordHandler;
00327
00328
00329 StripSubTreeRecordHandler* pStripSubTreeRecordHandler;
00330 StripSubTreeRecordHandler* pStandardStripSubTreeRecordHandler;
00331
00332
00333 FilePos StartOfStreamedRecord;
00334 BOOL WritingStreamedRecord;
00335 BOOL CompOffDueToStreamedRecord;
00336
00337
00338 BaseCamelotFilter* pFilter;
00339 CXaraFileMapTagToHandler* pMap;
00340
00341 #if defined(EXCLUDE_FROM_XARLIB)
00342
00343 AtomicTagList* pAtomicTagList;
00344 EssentialTagList* pEssentialTagList;
00345
00346 BOOL EndOfFile;
00347 #endif
00348 };
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 class NULLXaraFile : public CXaraFile
00364 {
00365
00366 CC_DECLARE_DYNAMIC(NULLXaraFile);
00367
00368 public:
00369 NULLXaraFile() { }
00370
00371 virtual BOOL OpenToWrite(CCLexFile* pThisCCFile);
00372 virtual BOOL Close();
00373 virtual BOOL Write(BYTE b);
00374
00375 virtual FilePos GetFilePos();
00376
00377 virtual BOOL IsCompressionOn();
00378 virtual BOOL StartCompression();
00379 virtual BOOL StopCompression();
00380
00381
00382
00383 virtual CCLexFile* GetCCFile() const;
00384
00385 protected:
00386 virtual BOOL FixStreamedRecordHeader(UINT32 *RecordSize);
00387 };
00388
00389
00390
00391 class StandardDefaultRecordHandler : public CamelotRecordHandler
00392 {
00393
00394 CC_DECLARE_DYNAMIC(StandardDefaultRecordHandler);
00395
00396 public:
00397 StandardDefaultRecordHandler()
00398 {
00399 #if defined(EXCLUDE_FROM_XARLIB)
00400 m_pfnRecordHandler = NULL;
00401 m_pMagic = NULL;
00402 #endif
00403 };
00404
00405
00406 virtual UINT32* GetTagList() { static UINT32 TagList[]={CXFRH_TAG_LIST_END}; return (UINT32*)TagList; }
00407 virtual BOOL HandleRecord(CXaraFileRecord* pCXaraFileRecord);
00408
00409 virtual void IncProgressBarCount(UINT32 n) {};
00410 virtual BOOL IsStreamed(UINT32 Tag) { return FALSE; }
00411
00412 #if defined(EXCLUDE_FROM_XARLIB)
00413 void SetExternalHandler(void* pMagic, RecordHandler pfnRecordHandler)
00414 {
00415 m_pfnRecordHandler = pfnRecordHandler;
00416 m_pMagic = pMagic;
00417 }
00418
00419 protected:
00420 RecordHandler* m_pfnRecordHandler;
00421 void* m_pMagic;
00422 #endif
00423 };
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 class GeneralRecordHandler : public CamelotRecordHandler
00437 {
00438
00439 CC_DECLARE_DYNAMIC(GeneralRecordHandler);
00440
00441 public:
00442 virtual UINT32* GetTagList();
00443 virtual BOOL HandleRecord(CXaraFileRecord* pCXaraFileRecord);
00444 virtual void IncProgressBarCount(UINT32 n) {};
00445
00446 #ifdef XAR_TREE_DIALOG
00447 virtual void GetRecordDescriptionText(CXaraFileRecord* pCXaraFileRecord,StringBase* Str);
00448 #endif
00449
00450 private:
00451 BOOL HandleFileHeader(CXaraFileRecord* pCXaraFileRecord);
00452 BOOL HandleAtomicTagsRecord(CXaraFileRecord* pCXaraFileRecord);
00453 BOOL HandleEssentialTagsRecord(CXaraFileRecord* pCXaraFileRecord);
00454 #if !defined(EXCLUDE_FROM_XARLIB)
00455 BOOL HandleTagDescriptionRecord(CXaraFileRecord* pCXaraFileRecord);
00456 BOOL HandleTagNudgeSizeRecord(CXaraFileRecord* pCXaraFileRecord);
00457 #endif
00458 };
00459
00460 #endif // INC_CXFILE