]>
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 | ||
21 | /*! | |
22 | * wxRichTextHTMLHandler | |
23 | */ | |
24 | ||
3b2cb431 | 25 | class WXDLLIMPEXP_RICHTEXT wxRichTextHTMLHandler: public wxRichTextFileHandler |
b71e9aa4 JS |
26 | { |
27 | DECLARE_CLASS(wxRichTextHTMLHandler) | |
28 | public: | |
50f65288 | 29 | wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML); |
b71e9aa4 | 30 | |
b71e9aa4 JS |
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 | ||
d2d0adc7 JS |
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 | ||
50f65288 WS |
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 | ||
b71e9aa4 | 71 | protected: |
2dec6761 | 72 | |
d2d0adc7 JS |
73 | // Implementation |
74 | ||
6f02a879 VZ |
75 | #if wxUSE_STREAMS |
76 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
77 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
2dec6761 JS |
78 | |
79 | /// Output character formatting | |
50f65288 WS |
80 | void BeginCharacterFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, const wxTextAttrEx& paraStyle, wxTextOutputStream& stream ); |
81 | void EndCharacterFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, const wxTextAttrEx& paraStyle, wxTextOutputStream& stream ); | |
1b88201f WS |
82 | |
83 | /// Output paragraph formatting | |
50f65288 WS |
84 | void BeginParagraphFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxTextOutputStream& stream); |
85 | void EndParagraphFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxTextOutputStream& stream); | |
1b88201f | 86 | |
50f65288 WS |
87 | /// Output font tag |
88 | void OutputFont(const wxTextAttrEx& style, wxTextOutputStream& stream); | |
1b88201f | 89 | |
50f65288 WS |
90 | /// Closes lists to level (-1 means close all) |
91 | void CloseLists(int level, wxTextOutputStream& str); | |
1b88201f | 92 | |
50f65288 WS |
93 | /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file |
94 | void WriteImage(wxRichTextImage* image, wxOutputStream& stream); | |
1b88201f WS |
95 | |
96 | /// Converts from pt to size property compatible height | |
d2d0adc7 | 97 | long PtToSize(long size); |
1b88201f WS |
98 | |
99 | /// Typical base64 encoder | |
d2d0adc7 | 100 | wxChar* b64enc(unsigned char* input, size_t in_len); |
1b88201f WS |
101 | |
102 | /// Gets the mime type of the given wxBITMAP_TYPE | |
21e354f1 | 103 | const wxChar* GetMimeType(int imageType); |
1b88201f WS |
104 | |
105 | /// Gets the html equivalent of the specified value | |
d2d0adc7 | 106 | wxString GetAlignment(const wxTextAttrEx& thisStyle); |
1b88201f WS |
107 | |
108 | /// Generates array for indentations | |
109 | wxString SymbolicIndent(long indent); | |
110 | ||
111 | /// Finds the html equivalent of the specified bullet | |
50f65288 | 112 | int TypeOfList(const wxTextAttrEx& thisStyle, wxString& tag); |
d2d0adc7 JS |
113 | #endif |
114 | ||
115 | // Data members | |
1b88201f | 116 | |
50f65288 WS |
117 | wxRichTextBuffer* m_buffer; |
118 | ||
1b88201f | 119 | /// Indentation values of the table tags |
d2d0adc7 | 120 | wxArrayInt m_indents; |
1b88201f | 121 | |
50f65288 WS |
122 | /// Stack of list types: 0 = ol, 1 = ul |
123 | wxArrayInt m_listTypes; | |
1b88201f | 124 | |
50f65288 | 125 | /// Is there any opened font tag? |
d2d0adc7 | 126 | bool m_font; |
1b88201f | 127 | |
50f65288 WS |
128 | /// Are we in a table? |
129 | bool m_inTable; | |
d2d0adc7 JS |
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; | |
2dec6761 | 136 | |
50f65288 WS |
137 | /// A mapping from point size to HTML font size |
138 | wxArrayInt m_fontSizeMapping; | |
139 | ||
d2d0adc7 JS |
140 | /// A counter for generating filenames |
141 | static int sm_fileCounter; | |
b71e9aa4 JS |
142 | }; |
143 | ||
144 | #endif | |
145 | // _WX_RICHTEXTXML_H_ |