2005-10-19 08:52:47 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-03-19 20:14:35 -04:00
|
|
|
// Name: wx/richtext/richtextxml.h
|
2005-10-19 08:52:47 -04:00
|
|
|
// Purpose: XML and HTML I/O for wxRichTextCtrl
|
|
|
|
// Author: Julian Smart
|
2005-10-19 13:00:58 -04:00
|
|
|
// Modified by:
|
2005-10-19 08:52:47 -04:00
|
|
|
// Created: 2005-09-30
|
2005-10-19 13:00:58 -04:00
|
|
|
// RCS-ID: $Id$
|
2005-10-19 08:52:47 -04:00
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_RICHTEXTXML_H_
|
|
|
|
#define _WX_RICHTEXTXML_H_
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Includes
|
|
|
|
*/
|
|
|
|
|
2005-10-28 10:24:04 -04:00
|
|
|
#include "wx/richtext/richtextbuffer.h"
|
2006-10-26 02:32:47 -04:00
|
|
|
#include "wx/richtext/richtextstyles.h"
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2005-10-31 09:27:53 -05:00
|
|
|
#if wxUSE_RICHTEXT && wxUSE_XML
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextXMLHandler
|
|
|
|
*/
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_XML wxXmlNode;
|
2010-10-06 16:22:03 -04:00
|
|
|
class WXDLLIMPEXP_FWD_XML wxXmlDocument;
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler: public wxRichTextFileHandler
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
2011-06-07 12:48:36 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxRichTextXMLHandler)
|
2005-10-19 08:52:47 -04:00
|
|
|
public:
|
|
|
|
wxRichTextXMLHandler(const wxString& name = wxT("XML"), const wxString& ext = wxT("xml"), int type = wxRICHTEXT_TYPE_XML)
|
|
|
|
: wxRichTextFileHandler(name, ext, type)
|
2010-10-06 16:22:03 -04:00
|
|
|
{ Init(); }
|
|
|
|
|
|
|
|
void Init();
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
#if wxUSE_STREAMS
|
2010-10-06 16:22:03 -04:00
|
|
|
|
|
|
|
#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Recursively export an object
|
2010-10-06 16:22:03 -04:00
|
|
|
bool ExportXML(wxOutputStream& stream, wxRichTextObject& obj, int level);
|
|
|
|
bool ExportStyleDefinition(wxOutputStream& stream, wxRichTextStyleDefinition* def, int level);
|
|
|
|
wxString AddAttributes(const wxRichTextAttr& attr, bool isPara = false);
|
|
|
|
bool WriteProperties(wxOutputStream& stream, const wxRichTextProperties& properties, int level);
|
|
|
|
void OutputString(wxOutputStream& stream, const wxString& str);
|
|
|
|
void OutputStringEnt(wxOutputStream& stream, const wxString& str);
|
|
|
|
void OutputIndentation(wxOutputStream& stream, int indent);
|
|
|
|
static wxString AttributeToXML(const wxString& str);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
|
|
|
|
bool ExportXML(wxXmlNode* parent, wxRichTextObject& obj);
|
|
|
|
bool ExportStyleDefinition(wxXmlNode* parent, wxRichTextStyleDefinition* def);
|
|
|
|
bool AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, bool isPara = false);
|
|
|
|
bool WriteProperties(wxXmlNode* node, const wxRichTextProperties& properties);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// Make a string from the given property. This can be overridden for custom variants.
|
|
|
|
virtual wxString MakeStringFromProperty(const wxVariant& var);
|
|
|
|
|
|
|
|
/// Create a proprty from the string read from the XML file.
|
|
|
|
virtual wxVariant MakePropertyFromString(const wxString& name, const wxString& value, const wxString& type);
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/// Recursively import an object
|
2010-10-06 16:22:03 -04:00
|
|
|
bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node);
|
2006-10-26 02:32:47 -04:00
|
|
|
bool ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node);
|
2010-10-06 16:22:03 -04:00
|
|
|
bool ImportProperties(wxRichTextObject* obj, wxXmlNode* node);
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2010-10-06 16:22:03 -04:00
|
|
|
/// Import style parameters
|
|
|
|
bool ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara = false);
|
2005-10-19 08:52:47 -04:00
|
|
|
#endif
|
|
|
|
|
2010-10-06 16:22:03 -04:00
|
|
|
/// Creates an object given an XML element name
|
|
|
|
virtual wxRichTextObject* CreateObjectForXMLName(wxRichTextObject* parent, const wxString& name) const;
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Can we save using this handler?
|
|
|
|
virtual bool CanSave() const { return true; }
|
|
|
|
|
|
|
|
/// Can we load using this handler?
|
|
|
|
virtual bool CanLoad() const { return true; }
|
|
|
|
|
2010-10-06 16:22:03 -04:00
|
|
|
// Used during saving
|
|
|
|
wxMBConv* GetConvMem() const { return m_convMem; }
|
|
|
|
wxMBConv* GetConvFile() const { return m_convFile; }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
// Implementation
|
|
|
|
|
|
|
|
bool HasParam(wxXmlNode* node, const wxString& param);
|
|
|
|
wxXmlNode *GetParamNode(wxXmlNode* node, const wxString& param);
|
|
|
|
wxString GetNodeContent(wxXmlNode *node);
|
|
|
|
wxString GetParamValue(wxXmlNode *node, const wxString& param);
|
|
|
|
wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false);
|
2011-01-14 06:57:44 -05:00
|
|
|
static wxXmlNode* FindNode(wxXmlNode* node, const wxString& name);
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
protected:
|
2006-02-08 16:47:09 -05:00
|
|
|
#if wxUSE_STREAMS
|
|
|
|
virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
|
|
|
|
virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
|
|
|
|
#endif
|
2010-10-06 16:22:03 -04:00
|
|
|
|
|
|
|
#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
|
|
|
|
// Used during saving
|
|
|
|
wxMBConv* m_convMem;
|
|
|
|
wxMBConv* m_convFile;
|
|
|
|
#endif
|
2005-10-19 08:52:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2005-10-31 09:27:53 -05:00
|
|
|
// wxUSE_RICHTEXT && wxUSE_XML
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_RICHTEXTXML_H_
|