2005-12-18 07:31:07 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-17 10:44:52 -04:00
|
|
|
// Name: wx/richtext/richtexthtml.h
|
2005-12-18 07:31:07 -05:00
|
|
|
// Purpose: HTML I/O for wxRichTextCtrl
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2005-09-30
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_RICHTEXTHTML_H_
|
|
|
|
#define _WX_RICHTEXTHTML_H_
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Includes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wx/richtext/richtextbuffer.h"
|
|
|
|
|
2009-09-23 07:05:52 -04:00
|
|
|
// Use CSS styles where applicable, otherwise use non-CSS workarounds
|
|
|
|
#define wxRICHTEXT_HANDLER_USE_CSS 0x1000
|
|
|
|
|
2005-12-18 07:31:07 -05:00
|
|
|
/*!
|
|
|
|
* wxRichTextHTMLHandler
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler: public wxRichTextFileHandler
|
2005-12-18 07:31:07 -05:00
|
|
|
{
|
2011-06-07 12:48:36 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxRichTextHTMLHandler)
|
2005-12-18 07:31:07 -05:00
|
|
|
public:
|
2006-07-25 02:50:19 -04:00
|
|
|
wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML);
|
2005-12-18 07:31:07 -05:00
|
|
|
|
|
|
|
/// Can we save using this handler?
|
|
|
|
virtual bool CanSave() const { return true; }
|
|
|
|
|
|
|
|
/// Can we load using this handler?
|
|
|
|
virtual bool CanLoad() const { return false; }
|
|
|
|
|
|
|
|
/// Can we handle this filename (if using files)? By default, checks the extension.
|
|
|
|
virtual bool CanHandle(const wxString& filename) const;
|
|
|
|
|
2006-10-26 02:32:47 -04:00
|
|
|
// Accessors and operations unique to this handler
|
|
|
|
|
|
|
|
/// Set and get the list of image locations generated by the last operation
|
|
|
|
void SetTemporaryImageLocations(const wxArrayString& locations) { m_imageLocations = locations; }
|
|
|
|
const wxArrayString& GetTemporaryImageLocations() const { return m_imageLocations; }
|
|
|
|
|
|
|
|
/// Clear the image locations generated by the last operation
|
|
|
|
void ClearTemporaryImageLocations() { m_imageLocations.Clear(); }
|
|
|
|
|
|
|
|
/// Delete the in-memory or temporary files generated by the last operation
|
|
|
|
bool DeleteTemporaryImages();
|
|
|
|
|
|
|
|
/// Delete the in-memory or temporary files generated by the last operation. This is a static
|
|
|
|
/// function that can be used to delete the saved locations from an earlier operation,
|
|
|
|
/// for example after the user has viewed the HTML file.
|
|
|
|
static bool DeleteTemporaryImages(int flags, const wxArrayString& imageLocations);
|
|
|
|
|
|
|
|
/// Reset the file counter, in case, for example, the same names are required each time
|
|
|
|
static void SetFileCounter(int counter) { sm_fileCounter = counter; }
|
|
|
|
|
|
|
|
/// Set and get the directory for storing temporary files. If empty, the system
|
|
|
|
/// temporary directory will be used.
|
|
|
|
void SetTempDir(const wxString& tempDir) { m_tempDir = tempDir; }
|
|
|
|
const wxString& GetTempDir() const { return m_tempDir; }
|
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Set and get mapping from point size to HTML font size. There should be 7 elements,
|
|
|
|
/// one for each HTML font size, each element specifying the maximum point size for that
|
|
|
|
/// HTML font size. E.g. 8, 10, 13, 17, 22, 29, 100
|
|
|
|
void SetFontSizeMapping(const wxArrayInt& fontSizeMapping) { m_fontSizeMapping = fontSizeMapping; }
|
|
|
|
wxArrayInt GetFontSizeMapping() const { return m_fontSizeMapping; }
|
|
|
|
|
2005-12-18 07:31:07 -05:00
|
|
|
protected:
|
2006-03-07 09:48:17 -05:00
|
|
|
|
2006-10-26 02:32:47 -04:00
|
|
|
// Implementation
|
|
|
|
|
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);
|
2006-03-07 09:48:17 -05:00
|
|
|
|
|
|
|
/// Output character formatting
|
2010-10-04 04:37:31 -04:00
|
|
|
void BeginCharacterFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, const wxRichTextAttr& paraStyle, wxTextOutputStream& stream );
|
|
|
|
void EndCharacterFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, const wxRichTextAttr& paraStyle, wxTextOutputStream& stream );
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Output paragraph formatting
|
2010-10-04 04:37:31 -04:00
|
|
|
void BeginParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream);
|
|
|
|
void EndParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Output font tag
|
2010-10-04 04:37:31 -04:00
|
|
|
void OutputFont(const wxRichTextAttr& style, wxTextOutputStream& stream);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Closes lists to level (-1 means close all)
|
|
|
|
void CloseLists(int level, wxTextOutputStream& str);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
|
|
|
|
void WriteImage(wxRichTextImage* image, wxOutputStream& stream);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Converts from pt to size property compatible height
|
2006-10-26 02:32:47 -04:00
|
|
|
long PtToSize(long size);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Typical base64 encoder
|
2006-10-26 02:32:47 -04:00
|
|
|
wxChar* b64enc(unsigned char* input, size_t in_len);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Gets the mime type of the given wxBITMAP_TYPE
|
2006-03-07 15:40:31 -05:00
|
|
|
const wxChar* GetMimeType(int imageType);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Gets the html equivalent of the specified value
|
2010-10-04 04:37:31 -04:00
|
|
|
wxString GetAlignment(const wxRichTextAttr& thisStyle);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
|
|
|
/// Generates array for indentations
|
|
|
|
wxString SymbolicIndent(long indent);
|
|
|
|
|
|
|
|
/// Finds the html equivalent of the specified bullet
|
2010-10-04 04:37:31 -04:00
|
|
|
int TypeOfList(const wxRichTextAttr& thisStyle, wxString& tag);
|
2006-10-26 02:32:47 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Data members
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
wxRichTextBuffer* m_buffer;
|
|
|
|
|
2006-10-17 10:44:52 -04:00
|
|
|
/// Indentation values of the table tags
|
2006-10-26 02:32:47 -04:00
|
|
|
wxArrayInt m_indents;
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Stack of list types: 0 = ol, 1 = ul
|
|
|
|
wxArrayInt m_listTypes;
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Is there any opened font tag?
|
2006-10-26 02:32:47 -04:00
|
|
|
bool m_font;
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// Are we in a table?
|
|
|
|
bool m_inTable;
|
2006-10-26 02:32:47 -04:00
|
|
|
|
|
|
|
/// A list of the image files or in-memory images created by the last operation.
|
|
|
|
wxArrayString m_imageLocations;
|
|
|
|
|
|
|
|
/// A location for the temporary files
|
|
|
|
wxString m_tempDir;
|
2006-03-07 09:48:17 -05:00
|
|
|
|
2006-07-25 02:50:19 -04:00
|
|
|
/// A mapping from point size to HTML font size
|
|
|
|
wxArrayInt m_fontSizeMapping;
|
|
|
|
|
2006-10-26 02:32:47 -04:00
|
|
|
/// A counter for generating filenames
|
|
|
|
static int sm_fileCounter;
|
2005-12-18 07:31:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_RICHTEXTXML_H_
|