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
)
30 : wxRichTextFileHandler(name
, ext
, type
), m_indent(0), m_font(false), m_list(false), m_is_ul(false)
33 /// Can we save using this handler?
34 virtual bool CanSave() const { return true; }
36 /// Can we load using this handler?
37 virtual bool CanLoad() const { return false; }
39 /// Can we handle this filename (if using files)? By default, checks the extension.
40 virtual bool CanHandle(const wxString
& filename
) const;
42 // Accessors and operations unique to this handler
44 /// Set and get the list of image locations generated by the last operation
45 void SetTemporaryImageLocations(const wxArrayString
& locations
) { m_imageLocations
= locations
; }
46 const wxArrayString
& GetTemporaryImageLocations() const { return m_imageLocations
; }
48 /// Clear the image locations generated by the last operation
49 void ClearTemporaryImageLocations() { m_imageLocations
.Clear(); }
51 /// Delete the in-memory or temporary files generated by the last operation
52 bool DeleteTemporaryImages();
54 /// Delete the in-memory or temporary files generated by the last operation. This is a static
55 /// function that can be used to delete the saved locations from an earlier operation,
56 /// for example after the user has viewed the HTML file.
57 static bool DeleteTemporaryImages(int flags
, const wxArrayString
& imageLocations
);
59 /// Reset the file counter, in case, for example, the same names are required each time
60 static void SetFileCounter(int counter
) { sm_fileCounter
= counter
; }
62 /// Set and get the directory for storing temporary files. If empty, the system
63 /// temporary directory will be used.
64 void SetTempDir(const wxString
& tempDir
) { m_tempDir
= tempDir
; }
65 const wxString
& GetTempDir() const { return m_tempDir
; }
72 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
73 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
75 /// Output character formatting
76 virtual void BeginCharacterFormatting(const wxTextAttrEx
& currentStyle
, const wxTextAttrEx
& thisStyle
, const wxTextAttrEx
& paraStyle
, wxOutputStream
& stream
);
77 virtual void EndCharacterFormatting(const wxTextAttrEx
& WXUNUSED(currentStyle
), const wxTextAttrEx
& thisStyle
, const wxTextAttrEx
& paraStyle
, wxOutputStream
& stream
);
79 /// Output paragraph formatting
80 virtual void OutputParagraphFormatting(const wxTextAttrEx
& WXUNUSED(currentStyle
), const wxTextAttrEx
& thisStyle
, wxOutputStream
& stream
/*, bool start*/);
82 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
83 void WriteImage(wxRichTextImage
* image
, wxOutputStream
& stream
);
85 /// Builds required indentation
86 void Indent(const wxTextAttrEx
& thisStyle
, wxTextOutputStream
& str
);
89 void LIndent(const wxTextAttrEx
& thisStyle
, wxTextOutputStream
& str
);
91 /// Converts from pt to size property compatible height
92 long PtToSize(long size
);
94 /// Typical base64 encoder
95 wxChar
* b64enc(unsigned char* input
, size_t in_len
);
97 /// Gets the mime type of the given wxBITMAP_TYPE
98 const wxChar
* GetMimeType(int imageType
);
100 /// Gets the html equivalent of the specified value
101 wxString
GetAlignment(const wxTextAttrEx
& thisStyle
);
103 /// Generates array for indentations
104 wxString
SymbolicIndent(long indent
);
106 /// Finds the html equivalent of the specified bullet
107 void TypeOfList(const wxTextAttrEx
& thisStyle
, wxString
& tag
);
109 /// Closes existings or Opens new tables for navigation to an item's horizontal position.
110 void NavigateToListPosition(const wxTextAttrEx
& thisStyle
, wxTextOutputStream
& str
);
115 /// Indentation values of the table tags
116 wxArrayInt m_indents
;
118 /// Horizontal position of the current table
121 /// Is there any opened font tag
124 /// Is there any opened ul/ol tag
127 /// type of list, ul or ol?
130 /// A list of the image files or in-memory images created by the last operation.
131 wxArrayString m_imageLocations
;
133 /// A location for the temporary files
136 /// A counter for generating filenames
137 static int sm_fileCounter
;
141 // _WX_RICHTEXTXML_H_