]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtexthtml.h
Fixed [ 1720130 ] A minor 'bug' or 'annoyance' with header file.
[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 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_RICHTEXTHTML_H_
13 #define _WX_RICHTEXTHTML_H_
14
15 /*!
16 * Includes
17 */
18
19 #include "wx/richtext/richtextbuffer.h"
20
21 /*!
22 * wxRichTextHTMLHandler
23 */
24
25 class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler: public wxRichTextFileHandler
26 {
27 DECLARE_CLASS(wxRichTextHTMLHandler)
28 public:
29 wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML);
30
31 /// Can we save using this handler?
32 virtual bool CanSave() const { return true; }
33
34 /// Can we load using this handler?
35 virtual bool CanLoad() const { return false; }
36
37 /// Can we handle this filename (if using files)? By default, checks the extension.
38 virtual bool CanHandle(const wxString& filename) const;
39
40 // Accessors and operations unique to this handler
41
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; }
45
46 /// Clear the image locations generated by the last operation
47 void ClearTemporaryImageLocations() { m_imageLocations.Clear(); }
48
49 /// Delete the in-memory or temporary files generated by the last operation
50 bool DeleteTemporaryImages();
51
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);
56
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; }
59
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; }
64
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; }
70
71 protected:
72
73 // Implementation
74
75 #if wxUSE_STREAMS
76 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
77 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
78
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 );
82
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);
86
87 /// Output font tag
88 void OutputFont(const wxTextAttr& style, wxTextOutputStream& stream);
89
90 /// Closes lists to level (-1 means close all)
91 void CloseLists(int level, wxTextOutputStream& str);
92
93 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
94 void WriteImage(wxRichTextImage* image, wxOutputStream& stream);
95
96 /// Converts from pt to size property compatible height
97 long PtToSize(long size);
98
99 /// Typical base64 encoder
100 wxChar* b64enc(unsigned char* input, size_t in_len);
101
102 /// Gets the mime type of the given wxBITMAP_TYPE
103 const wxChar* GetMimeType(int imageType);
104
105 /// Gets the html equivalent of the specified value
106 wxString GetAlignment(const wxTextAttr& thisStyle);
107
108 /// Generates   array for indentations
109 wxString SymbolicIndent(long indent);
110
111 /// Finds the html equivalent of the specified bullet
112 int TypeOfList(const wxTextAttr& thisStyle, wxString& tag);
113 #endif
114
115 // Data members
116
117 wxRichTextBuffer* m_buffer;
118
119 /// Indentation values of the table tags
120 wxArrayInt m_indents;
121
122 /// Stack of list types: 0 = ol, 1 = ul
123 wxArrayInt m_listTypes;
124
125 /// Is there any opened font tag?
126 bool m_font;
127
128 /// Are we in a table?
129 bool m_inTable;
130
131 /// A list of the image files or in-memory images created by the last operation.
132 wxArrayString m_imageLocations;
133
134 /// A location for the temporary files
135 wxString m_tempDir;
136
137 /// A mapping from point size to HTML font size
138 wxArrayInt m_fontSizeMapping;
139
140 /// A counter for generating filenames
141 static int sm_fileCounter;
142 };
143
144 #endif
145 // _WX_RICHTEXTXML_H_