]>
Commit | Line | Data |
---|---|---|
b71e9aa4 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1b88201f | 2 | // Name: wx/richtext/richtexthtml.h |
b71e9aa4 JS |
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 | ||
4fdc2c5f JS |
21 | // Use CSS styles where applicable, otherwise use non-CSS workarounds |
22 | #define wxRICHTEXT_HANDLER_USE_CSS 0x1000 | |
23 | ||
b71e9aa4 JS |
24 | /*! |
25 | * wxRichTextHTMLHandler | |
26 | */ | |
27 | ||
3b2cb431 | 28 | class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler: public wxRichTextFileHandler |
b71e9aa4 | 29 | { |
48dd0055 | 30 | DECLARE_DYNAMIC_CLASS(wxRichTextHTMLHandler) |
b71e9aa4 | 31 | public: |
50f65288 | 32 | wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML); |
b71e9aa4 | 33 | |
b71e9aa4 JS |
34 | /// Can we save using this handler? |
35 | virtual bool CanSave() const { return true; } | |
36 | ||
37 | /// Can we load using this handler? | |
38 | virtual bool CanLoad() const { return false; } | |
39 | ||
40 | /// Can we handle this filename (if using files)? By default, checks the extension. | |
41 | virtual bool CanHandle(const wxString& filename) const; | |
42 | ||
d2d0adc7 JS |
43 | // Accessors and operations unique to this handler |
44 | ||
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; } | |
48 | ||
49 | /// Clear the image locations generated by the last operation | |
50 | void ClearTemporaryImageLocations() { m_imageLocations.Clear(); } | |
51 | ||
52 | /// Delete the in-memory or temporary files generated by the last operation | |
53 | bool DeleteTemporaryImages(); | |
54 | ||
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); | |
59 | ||
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; } | |
62 | ||
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; } | |
67 | ||
50f65288 WS |
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; } | |
73 | ||
b71e9aa4 | 74 | protected: |
2dec6761 | 75 | |
d2d0adc7 JS |
76 | // Implementation |
77 | ||
6f02a879 VZ |
78 | #if wxUSE_STREAMS |
79 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
80 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
2dec6761 JS |
81 | |
82 | /// Output character formatting | |
24777478 JS |
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 ); | |
1b88201f WS |
85 | |
86 | /// Output paragraph formatting | |
24777478 JS |
87 | void BeginParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream); |
88 | void EndParagraphFormatting(const wxRichTextAttr& currentStyle, const wxRichTextAttr& thisStyle, wxTextOutputStream& stream); | |
1b88201f | 89 | |
50f65288 | 90 | /// Output font tag |
24777478 | 91 | void OutputFont(const wxRichTextAttr& style, wxTextOutputStream& stream); |
1b88201f | 92 | |
50f65288 WS |
93 | /// Closes lists to level (-1 means close all) |
94 | void CloseLists(int level, wxTextOutputStream& str); | |
1b88201f | 95 | |
50f65288 WS |
96 | /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file |
97 | void WriteImage(wxRichTextImage* image, wxOutputStream& stream); | |
1b88201f WS |
98 | |
99 | /// Converts from pt to size property compatible height | |
d2d0adc7 | 100 | long PtToSize(long size); |
1b88201f WS |
101 | |
102 | /// Typical base64 encoder | |
d2d0adc7 | 103 | wxChar* b64enc(unsigned char* input, size_t in_len); |
1b88201f WS |
104 | |
105 | /// Gets the mime type of the given wxBITMAP_TYPE | |
21e354f1 | 106 | const wxChar* GetMimeType(int imageType); |
1b88201f WS |
107 | |
108 | /// Gets the html equivalent of the specified value | |
24777478 | 109 | wxString GetAlignment(const wxRichTextAttr& thisStyle); |
1b88201f WS |
110 | |
111 | /// Generates array for indentations | |
112 | wxString SymbolicIndent(long indent); | |
113 | ||
114 | /// Finds the html equivalent of the specified bullet | |
24777478 | 115 | int TypeOfList(const wxRichTextAttr& thisStyle, wxString& tag); |
d2d0adc7 JS |
116 | #endif |
117 | ||
118 | // Data members | |
1b88201f | 119 | |
50f65288 WS |
120 | wxRichTextBuffer* m_buffer; |
121 | ||
1b88201f | 122 | /// Indentation values of the table tags |
d2d0adc7 | 123 | wxArrayInt m_indents; |
1b88201f | 124 | |
50f65288 WS |
125 | /// Stack of list types: 0 = ol, 1 = ul |
126 | wxArrayInt m_listTypes; | |
1b88201f | 127 | |
50f65288 | 128 | /// Is there any opened font tag? |
d2d0adc7 | 129 | bool m_font; |
1b88201f | 130 | |
50f65288 WS |
131 | /// Are we in a table? |
132 | bool m_inTable; | |
d2d0adc7 JS |
133 | |
134 | /// A list of the image files or in-memory images created by the last operation. | |
135 | wxArrayString m_imageLocations; | |
136 | ||
137 | /// A location for the temporary files | |
138 | wxString m_tempDir; | |
2dec6761 | 139 | |
50f65288 WS |
140 | /// A mapping from point size to HTML font size |
141 | wxArrayInt m_fontSizeMapping; | |
142 | ||
d2d0adc7 JS |
143 | /// A counter for generating filenames |
144 | static int sm_fileCounter; | |
b71e9aa4 JS |
145 | }; |
146 | ||
147 | #endif | |
148 | // _WX_RICHTEXTXML_H_ |