1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtexthtml.h
3 // Purpose: HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTHTML_H_
13 #define _WX_RICHTEXTHTML_H_
19 #include "wx/richtext/richtextbuffer.h"
21 // Use CSS styles where applicable, otherwise use non-CSS workarounds
22 #define wxRICHTEXT_HANDLER_USE_CSS 0x1000
25 * wxRichTextHTMLHandler
28 class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler
: public wxRichTextFileHandler
30 DECLARE_CLASS(wxRichTextHTMLHandler
)
32 wxRichTextHTMLHandler(const wxString
& name
= wxT("HTML"), const wxString
& ext
= wxT("html"), int type
= wxRICHTEXT_TYPE_HTML
);
34 /// Can we save using this handler?
35 virtual bool CanSave() const { return true; }
37 /// Can we load using this handler?
38 virtual bool CanLoad() const { return false; }
40 /// Can we handle this filename (if using files)? By default, checks the extension.
41 virtual bool CanHandle(const wxString
& filename
) const;
43 // Accessors and operations unique to this handler
45 /// Set and get the list of image locations generated by the last operation
46 void SetTemporaryImageLocations(const wxArrayString
& locations
) { m_imageLocations
= locations
; }
47 const wxArrayString
& GetTemporaryImageLocations() const { return m_imageLocations
; }
49 /// Clear the image locations generated by the last operation
50 void ClearTemporaryImageLocations() { m_imageLocations
.Clear(); }
52 /// Delete the in-memory or temporary files generated by the last operation
53 bool DeleteTemporaryImages();
55 /// Delete the in-memory or temporary files generated by the last operation. This is a static
56 /// function that can be used to delete the saved locations from an earlier operation,
57 /// for example after the user has viewed the HTML file.
58 static bool DeleteTemporaryImages(int flags
, const wxArrayString
& imageLocations
);
60 /// Reset the file counter, in case, for example, the same names are required each time
61 static void SetFileCounter(int counter
) { sm_fileCounter
= counter
; }
63 /// Set and get the directory for storing temporary files. If empty, the system
64 /// temporary directory will be used.
65 void SetTempDir(const wxString
& tempDir
) { m_tempDir
= tempDir
; }
66 const wxString
& GetTempDir() const { return m_tempDir
; }
68 /// Set and get mapping from point size to HTML font size. There should be 7 elements,
69 /// one for each HTML font size, each element specifying the maximum point size for that
70 /// HTML font size. E.g. 8, 10, 13, 17, 22, 29, 100
71 void SetFontSizeMapping(const wxArrayInt
& fontSizeMapping
) { m_fontSizeMapping
= fontSizeMapping
; }
72 wxArrayInt
GetFontSizeMapping() const { return m_fontSizeMapping
; }
79 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
80 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
82 /// Output character formatting
83 void BeginCharacterFormatting(const wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& thisStyle
, const wxRichTextAttr
& paraStyle
, wxTextOutputStream
& stream
);
84 void EndCharacterFormatting(const wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& thisStyle
, const wxRichTextAttr
& paraStyle
, wxTextOutputStream
& stream
);
86 /// Output paragraph formatting
87 void BeginParagraphFormatting(const wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& thisStyle
, wxTextOutputStream
& stream
);
88 void EndParagraphFormatting(const wxRichTextAttr
& currentStyle
, const wxRichTextAttr
& thisStyle
, wxTextOutputStream
& stream
);
91 void OutputFont(const wxRichTextAttr
& style
, wxTextOutputStream
& stream
);
93 /// Closes lists to level (-1 means close all)
94 void CloseLists(int level
, wxTextOutputStream
& str
);
96 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
97 void WriteImage(wxRichTextImage
* image
, wxOutputStream
& stream
);
99 /// Converts from pt to size property compatible height
100 long PtToSize(long size
);
102 /// Typical base64 encoder
103 wxChar
* b64enc(unsigned char* input
, size_t in_len
);
105 /// Gets the mime type of the given wxBITMAP_TYPE
106 const wxChar
* GetMimeType(int imageType
);
108 /// Gets the html equivalent of the specified value
109 wxString
GetAlignment(const wxRichTextAttr
& thisStyle
);
111 /// Generates array for indentations
112 wxString
SymbolicIndent(long indent
);
114 /// Finds the html equivalent of the specified bullet
115 int TypeOfList(const wxRichTextAttr
& thisStyle
, wxString
& tag
);
120 wxRichTextBuffer
* m_buffer
;
122 /// Indentation values of the table tags
123 wxArrayInt m_indents
;
125 /// Stack of list types: 0 = ol, 1 = ul
126 wxArrayInt m_listTypes
;
128 /// Is there any opened font tag?
131 /// Are we in a table?
134 /// A list of the image files or in-memory images created by the last operation.
135 wxArrayString m_imageLocations
;
137 /// A location for the temporary files
140 /// A mapping from point size to HTML font size
141 wxArrayInt m_fontSizeMapping
;
143 /// A counter for generating filenames
144 static int sm_fileCounter
;
148 // _WX_RICHTEXTXML_H_