]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtexthtml.h
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / include / wx / richtext / richtexthtml.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtexthtml.h
3 // Purpose: HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_RICHTEXTHTML_H_
12 #define _WX_RICHTEXTHTML_H_
13
14 /*!
15 * Includes
16 */
17
18 #include "wx/richtext/richtextbuffer.h"
19
20 // Use CSS styles where applicable, otherwise use non-CSS workarounds
21 #define wxRICHTEXT_HANDLER_USE_CSS 0x1000
22
23 /*!
24 * wxRichTextHTMLHandler
25 */
26
27 class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler: public wxRichTextFileHandler
28 {
29 DECLARE_DYNAMIC_CLASS(wxRichTextHTMLHandler)
30 public:
31 wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML);
32
33 /// Can we save using this handler?
34 virtual bool CanSave() const { return true; }
35
36 /// Can we load using this handler?
37 virtual bool CanLoad() const { return false; }
38
39 /// Can we handle this filename (if using files)? By default, checks the extension.
40 virtual bool CanHandle(const wxString& filename) const;
41
42 // Accessors and operations unique to this handler
43
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; }
47
48 /// Clear the image locations generated by the last operation
49 void ClearTemporaryImageLocations() { m_imageLocations.Clear(); }
50
51 /// Delete the in-memory or temporary files generated by the last operation
52 bool DeleteTemporaryImages();
53
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);
58
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; }
61
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; }
66
67 /// Set and get mapping from point size to HTML font size. There should be 7 elements,
68 /// one for each HTML font size, each element specifying the maximum point size for that
69 /// HTML font size. E.g. 8, 10, 13, 17, 22, 29, 100
70 void SetFontSizeMapping(const wxArrayInt& fontSizeMapping) { m_fontSizeMapping = fontSizeMapping; }
71 wxArrayInt GetFontSizeMapping() const { return m_fontSizeMapping; }
72
73 protected:
74
75 // Implementation
76
77 #if wxUSE_STREAMS
78 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
79 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
80
81 /// Output character formatting
82 void BeginCharacterFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, const wxRichTextAttr& paraStyle, wxTextOutputStream& stream );
83 void EndCharacterFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, const wxRichTextAttr& paraStyle, wxTextOutputStream& stream );
84
85 /// Output paragraph formatting
86 void BeginParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream);
87 void EndParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream);
88
89 /// Output font tag
90 void OutputFont(const wxRichTextAttr& style, wxTextOutputStream& stream);
91
92 /// Closes lists to level (-1 means close all)
93 void CloseLists(int level, wxTextOutputStream& str);
94
95 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
96 void WriteImage(wxRichTextImage* image, wxOutputStream& stream);
97
98 /// Converts from pt to size property compatible height
99 long PtToSize(long size);
100
101 /// Typical base64 encoder
102 wxChar* b64enc(unsigned char* input, size_t in_len);
103
104 /// Gets the mime type of the given wxBITMAP_TYPE
105 const wxChar* GetMimeType(int imageType);
106
107 /// Gets the html equivalent of the specified value
108 wxString GetAlignment(const wxRichTextAttr& thisStyle);
109
110 /// Generates   array for indentations
111 wxString SymbolicIndent(long indent);
112
113 /// Finds the html equivalent of the specified bullet
114 int TypeOfList(const wxRichTextAttr& thisStyle, wxString& tag);
115 #endif
116
117 // Data members
118
119 wxRichTextBuffer* m_buffer;
120
121 /// Indentation values of the table tags
122 wxArrayInt m_indents;
123
124 /// Stack of list types: 0 = ol, 1 = ul
125 wxArrayInt m_listTypes;
126
127 /// Is there any opened font tag?
128 bool m_font;
129
130 /// Are we in a table?
131 bool m_inTable;
132
133 /// A list of the image files or in-memory images created by the last operation.
134 wxArrayString m_imageLocations;
135
136 /// A location for the temporary files
137 wxString m_tempDir;
138
139 /// A mapping from point size to HTML font size
140 wxArrayInt m_fontSizeMapping;
141
142 /// A counter for generating filenames
143 static int sm_fileCounter;
144 };
145
146 #endif
147 // _WX_RICHTEXTXML_H_