00001 /*! \file wx/canvas/xmlpars.h 00002 \brief a2dIOHandlerCVGIn and a2dIOHandlerCVGOut - XML I/O classes for the CVG format. 00003 00004 The main way of serialisation is done with XML and the format is called CVG ( canvas vector graphics ). 00005 00006 \author Probably Klaas Holwerda 00007 00008 Copyright: 2001-2004 (C) Probably Klaas Holwerda 00009 00010 Licence: wxWidgets licence 00011 00012 RCS-ID: $Id: xmlpars.h,v 1.16 2009/05/15 16:34:28 titato Exp $ 00013 */ 00014 00015 #ifndef _WX_CANVASXMLIO_H_ 00016 #define _WX_CANVASXMLIO_H_ 00017 00018 #include "a2dprivate.h" 00019 00020 #if wxART2D_USE_XMLPARSE 00021 00022 #include <wx/defs.h> 00023 #include <wx/string.h> 00024 #include <wx/txtstrm.h> 00025 00026 #if wxCHECK_VERSION(2, 5, 3) 00027 #include <wx/sstream.h> 00028 #endif 00029 00030 #include <expat.h> 00031 00032 #include "wx/docview/docviewref.h" 00033 00034 #include "wx/xmlparse/genxmlpars.h" 00035 #include "wx/xmlparse/xmlencode.h" 00036 #include "wx/canvas/candefs.h" 00037 00038 #if wxART2D_USE_CVGIO 00039 00040 00041 //! Input handler for the CVG format. 00042 /*! 00043 The CVG format is the native file format of wxArt2d. 00044 It's a XML format and each a2dCanvasObject is able to load its data from CVG. 00045 There's no specification of the CVG, please have a look into the DoLoad methods 00046 of the a2dCanvasObject derived classes to see details. 00047 00048 In general the following is done. 00049 - each a2dObject has a2dObject::Save() and a2dObject::Load() as a start for serialisation. 00050 - a2dObject::DoLoad and a2dObject::DoSave() methods are virtual and should be implemented 00051 to save also the data of the derived classes. 00052 - Saving is a two pass process, in order to first write all XML attributes of an object and next 00053 its NON attribute data and nested objects. 00054 - one always needs to call derivedFrom::DoLoad in the implementation of a Doload() 00055 - one always needs to call derivedFrom::DoSave in the implementation of a DoSave() 00056 - multiple referenced objects are written only by refid attribute. When loading the file, 00057 those references are resolved. 00058 00059 \ingroup fileio cvgfileio 00060 */ 00061 class A2DCANVASDLLEXP a2dIOHandlerCVGIn : public a2dIOHandlerXmlSerIn 00062 { 00063 public: 00064 //! Constructor. 00065 a2dIOHandlerCVGIn(); 00066 00067 //! Destructor. 00068 ~a2dIOHandlerCVGIn(); 00069 00070 //! test header of the file to see if its CVG format 00071 virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL ); 00072 00073 //! load a layer definition from a CVG file. 00074 bool LoadLayers( a2dDocumentInputStream& stream, a2dLayers* layers ); 00075 00076 //! reading a CVG document and add the contents as children to a given a2dCanvasObject parent. 00077 /*! 00078 This can be used to include a CVG document in an existing document. 00079 Also clipboard action might use this. 00080 */ 00081 bool Load( a2dDocumentStringInputStream& stream, a2dCanvasDocument* doc, a2dCanvasObject* parent ); 00082 00083 protected: 00084 00085 //! the document to store/load the data found into 00086 a2dCanvasDocument* m_doc; 00087 00088 }; 00089 00090 //! output handler for the CVG format. 00091 /*! 00092 The CVG format is the native file format of wxArt2d. 00093 It's a XML format and each a2dCanvasObject is able to save its data as CVG. 00094 There's no specification of the CVG, please have a look into the DoSave methods 00095 of the a2dCanvasObject derived classes to see details. 00096 00097 \ingroup fileio cvgfileio 00098 */ 00099 class A2DCANVASDLLEXP a2dIOHandlerCVGOut : public a2dIOHandlerXmlSerOut 00100 { 00101 public: 00102 //! Constructor. 00103 a2dIOHandlerCVGOut(); 00104 00105 //! Destructor. 00106 ~a2dIOHandlerCVGOut(); 00107 00108 //! this handler can also save as CVG 00109 bool CanSave( const wxObject* obj = NULL ) { return true; } 00110 00111 //! saves as CVG starting at object start 00112 bool SaveStartAt( a2dDocumentOutputStream& stream, const a2dCanvasDocument* doc, a2dCanvasObject* start ); 00113 00114 //! save a layer definition to a CVG file. 00115 bool SaveLayers( a2dDocumentOutputStream& stream, a2dLayers* layers ); 00116 00117 void WriteCvgStartDocument( a2dDocumentOutputStream& stream ); 00118 00119 void WriteCvgEndDocument(); 00120 00121 void WriteObject( a2dCanvasObject* start ); 00122 00123 protected: 00124 00125 //! the document to store/load the data found into 00126 a2dCanvasDocument* m_doc; 00127 }; 00128 00129 #endif //wxART2D_USE_CVGIO 00130 00131 #endif // wxART2D_USE_XMLPARSE 00132 00133 #endif /* _WX_CANVASXMLIO_H_ */ 00134