]>
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: | |
29 | wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML) | |
d2d0adc7 | 30 | : wxRichTextFileHandler(name, ext, type), m_indent(0), m_font(false), m_list(false), m_is_ul(false) |
b71e9aa4 JS |
31 | { } |
32 | ||
b71e9aa4 JS |
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 | ||
d2d0adc7 JS |
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 | ||
b71e9aa4 | 67 | protected: |
2dec6761 | 68 | |
d2d0adc7 JS |
69 | // Implementation |
70 | ||
6f02a879 VZ |
71 | #if wxUSE_STREAMS |
72 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
73 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
2dec6761 JS |
74 | |
75 | /// Output character formatting | |
27507b61 JS |
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 ); | |
1b88201f WS |
78 | |
79 | /// Output paragraph formatting | |
2dec6761 | 80 | virtual void OutputParagraphFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream/*, bool start*/); |
1b88201f | 81 | |
d2d0adc7 JS |
82 | /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file |
83 | void WriteImage(wxRichTextImage* image, wxOutputStream& stream); | |
1b88201f WS |
84 | |
85 | /// Builds required indentation | |
d2d0adc7 | 86 | void Indent(const wxTextAttrEx& thisStyle, wxTextOutputStream& str); |
1b88201f WS |
87 | |
88 | /// Left indent | |
d2d0adc7 | 89 | void LIndent(const wxTextAttrEx& thisStyle, wxTextOutputStream& str); |
1b88201f WS |
90 | |
91 | /// Converts from pt to size property compatible height | |
d2d0adc7 | 92 | long PtToSize(long size); |
1b88201f WS |
93 | |
94 | /// Typical base64 encoder | |
d2d0adc7 | 95 | wxChar* b64enc(unsigned char* input, size_t in_len); |
1b88201f WS |
96 | |
97 | /// Gets the mime type of the given wxBITMAP_TYPE | |
21e354f1 | 98 | const wxChar* GetMimeType(int imageType); |
1b88201f WS |
99 | |
100 | /// Gets the html equivalent of the specified value | |
d2d0adc7 | 101 | wxString GetAlignment(const wxTextAttrEx& thisStyle); |
1b88201f WS |
102 | |
103 | /// Generates array for indentations | |
104 | wxString SymbolicIndent(long indent); | |
105 | ||
106 | /// Finds the html equivalent of the specified bullet | |
d2d0adc7 | 107 | void TypeOfList(const wxTextAttrEx& thisStyle, wxString& tag); |
1b88201f WS |
108 | |
109 | /// Closes existings or Opens new tables for navigation to an item's horizontal position. | |
d2d0adc7 JS |
110 | void NavigateToListPosition(const wxTextAttrEx& thisStyle, wxTextOutputStream& str); |
111 | #endif | |
112 | ||
113 | // Data members | |
1b88201f WS |
114 | |
115 | /// Indentation values of the table tags | |
d2d0adc7 | 116 | wxArrayInt m_indents; |
1b88201f WS |
117 | |
118 | /// Horizontal position of the current table | |
d2d0adc7 | 119 | long m_indent; |
1b88201f WS |
120 | |
121 | /// Is there any opened font tag | |
d2d0adc7 | 122 | bool m_font; |
1b88201f WS |
123 | |
124 | /// Is there any opened ul/ol tag | |
d2d0adc7 | 125 | bool m_list; |
1b88201f WS |
126 | |
127 | /// type of list, ul or ol? | |
d2d0adc7 JS |
128 | bool m_is_ul; |
129 | ||
130 | /// A list of the image files or in-memory images created by the last operation. | |
131 | wxArrayString m_imageLocations; | |
132 | ||
133 | /// A location for the temporary files | |
134 | wxString m_tempDir; | |
2dec6761 | 135 | |
d2d0adc7 JS |
136 | /// A counter for generating filenames |
137 | static int sm_fileCounter; | |
b71e9aa4 JS |
138 | }; |
139 | ||
140 | #endif | |
141 | // _WX_RICHTEXTXML_H_ |