]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtexthtml.h
aui docking works well on systems with solid window dragging turned off
[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 : wxRichTextFileHandler(name, ext, type), m_indent(0), m_font(false), m_list(false), m_is_ul(false)
31 { }
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 protected:
68
69 // Implementation
70
71 #if wxUSE_STREAMS
72 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
73 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
74
75 /// Output character formatting
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 );
78
79 /// Output paragraph formatting
80 virtual void OutputParagraphFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream/*, bool start*/);
81
82 /// Writes an image to its base64 equivalent, or to the memory filesystem, or to a file
83 void WriteImage(wxRichTextImage* image, wxOutputStream& stream);
84
85 /// Builds required indentation
86 void Indent(const wxTextAttrEx& thisStyle, wxTextOutputStream& str);
87
88 /// Left indent
89 void LIndent(const wxTextAttrEx& thisStyle, wxTextOutputStream& str);
90
91 /// Converts from pt to size property compatible height
92 long PtToSize(long size);
93
94 /// Typical base64 encoder
95 wxChar* b64enc(unsigned char* input, size_t in_len);
96
97 /// Gets the mime type of the given wxBITMAP_TYPE
98 const wxChar* GetMimeType(int imageType);
99
100 /// Gets the html equivalent of the specified value
101 wxString GetAlignment(const wxTextAttrEx& thisStyle);
102
103 /// Generates   array for indentations
104 wxString SymbolicIndent(long indent);
105
106 /// Finds the html equivalent of the specified bullet
107 void TypeOfList(const wxTextAttrEx& thisStyle, wxString& tag);
108
109 /// Closes existings or Opens new tables for navigation to an item's horizontal position.
110 void NavigateToListPosition(const wxTextAttrEx& thisStyle, wxTextOutputStream& str);
111 #endif
112
113 // Data members
114
115 /// Indentation values of the table tags
116 wxArrayInt m_indents;
117
118 /// Horizontal position of the current table
119 long m_indent;
120
121 /// Is there any opened font tag
122 bool m_font;
123
124 /// Is there any opened ul/ol tag
125 bool m_list;
126
127 /// type of list, ul or ol?
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;
135
136 /// A counter for generating filenames
137 static int sm_fileCounter;
138 };
139
140 #endif
141 // _WX_RICHTEXTXML_H_