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"
22 * wxRichTextHTMLHandler
25 class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler
: public wxRichTextFileHandler
27 DECLARE_CLASS(wxRichTextHTMLHandler
)
29 wxRichTextHTMLHandler(const wxString
& name
= wxT("HTML"), const wxString
& ext
= wxT("html"), int type
= wxRICHTEXT_TYPE_HTML
);
31 /// Can we save using this handler?
32 virtual bool CanSave() const { return true; }
34 /// Can we load using this handler?
35 virtual bool CanLoad() const { return false; }
37 /// Can we handle this filename (if using files)? By default, checks the extension.
38 virtual bool CanHandle(const wxString
& filename
) const;
40 // Accessors and operations unique to this handler
42 /// Set and get the list of image locations generated by the last operation
43 void SetTemporaryImageLocations(const wxArrayString
& locations
) { m_imageLocations
= locations
; }
44 const wxArrayString
& GetTemporaryImageLocations() const { return m_imageLocations
; }
46 /// Clear the image locations generated by the last operation
47 void ClearTemporaryImageLocations() { m_imageLocations
.Clear(); }
49 /// Delete the in-memory or temporary files generated by the last operation
50 bool DeleteTemporaryImages();
52 /// Delete the in-memory or temporary files generated by the last operation. This is a static
53 /// function that can be used to delete the saved locations from an earlier operation,
54 /// for example after the user has viewed the HTML file.
55 static bool DeleteTemporaryImages(int flags
, const wxArrayString
& imageLocations
);
57 /// Reset the file counter, in case, for example, the same names are required each time
58 static void SetFileCounter(int counter
) { sm_fileCounter
= counter
; }
60 /// Set and get the directory for storing temporary files. If empty, the system
61 /// temporary directory will be used.
62 void SetTempDir(const wxString
& tempDir
) { m_tempDir
= tempDir
; }
63 const wxString
& GetTempDir() const { return m_tempDir
; }
65 /// Set and get mapping from point size to HTML font size. There should be 7 elements,
66 /// one for each HTML font size, each element specifying the maximum point size for that
67 /// HTML font size. E.g. 8, 10, 13, 17, 22, 29, 100
68 void SetFontSizeMapping(const wxArrayInt
& fontSizeMapping
) { m_fontSizeMapping
= fontSizeMapping
; }
69 wxArrayInt
GetFontSizeMapping() const { return m_fontSizeMapping
; }
76 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
77 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
79 /// Output character formatting
80 void BeginCharacterFormatting(const wxTextAttr
& currentStyle
, const wxTextAttr
& thisStyle
, const wxTextAttr
& paraStyle
, wxTextOutputStream
& stream
);
81 void EndCharacterFormatting(const wxTextAttr
& currentStyle
, const wxTextAttr
& thisStyle
, const wxTextAttr
& paraStyle
, wxTextOutputStream
& stream
);
83 /// Output paragraph formatting
84 void BeginParagraphFormatting(const wxTextAttr
& currentStyle
, const wxTextAttr
& thisStyle
, wxTextOutputStream
& stream
);
85 void EndParagraphFormatting(const wxTextAttr
& currentStyle
, const wxTextAttr
& thisStyle
, wxTextOutputStream
& stream
);
88 void OutputFont(const wxTextAttr
& style
, wxTextOutputStream
& stream
);
90 /// Closes lists to level (-1 means close all)
91 void CloseLists(int level
, wxTextOutputStream
& str
);
93 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
94 void WriteImage(wxRichTextImage
* image
, wxOutputStream
& stream
);
96 /// Converts from pt to size property compatible height
97 long PtToSize(long size
);
99 /// Typical base64 encoder
100 wxChar
* b64enc(unsigned char* input
, size_t in_len
);
102 /// Gets the mime type of the given wxBITMAP_TYPE
103 const wxChar
* GetMimeType(int imageType
);
105 /// Gets the html equivalent of the specified value
106 wxString
GetAlignment(const wxTextAttr
& thisStyle
);
108 /// Generates array for indentations
109 wxString
SymbolicIndent(long indent
);
111 /// Finds the html equivalent of the specified bullet
112 int TypeOfList(const wxTextAttr
& thisStyle
, wxString
& tag
);
117 wxRichTextBuffer
* m_buffer
;
119 /// Indentation values of the table tags
120 wxArrayInt m_indents
;
122 /// Stack of list types: 0 = ol, 1 = ul
123 wxArrayInt m_listTypes
;
125 /// Is there any opened font tag?
128 /// Are we in a table?
131 /// A list of the image files or in-memory images created by the last operation.
132 wxArrayString m_imageLocations
;
134 /// A location for the temporary files
137 /// A mapping from point size to HTML font size
138 wxArrayInt m_fontSizeMapping
;
140 /// A counter for generating filenames
141 static int sm_fileCounter
;
145 // _WX_RICHTEXTXML_H_