]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlfilt.cpp
bb55c450cc02be3886d86817fd51d224b9e5a78a
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlFilter - input filter for translating into HTML format
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation
15 #include "wx/wxprec.h"
27 #include "wx/html/htmlfilt.h"
28 #include "wx/html/htmlwin.h"
33 There is code for several default filters:
37 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter
, wxObject
)
39 //--------------------------------------------------------------------------------
40 // wxHtmlFilterPlainText
41 // filter for text/plain or uknown
42 //--------------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText
, wxHtmlFilter
)
46 bool wxHtmlFilterPlainText::CanRead(const wxFSFile
& WXUNUSED(file
)) const
53 wxString
wxHtmlFilterPlainText::ReadFile(const wxFSFile
& file
) const
55 wxInputStream
*s
= file
.GetStream();
59 if (s
== NULL
) return wxEmptyString
;
60 src
= new char[s
-> GetSize()+1];
61 src
[s
-> GetSize()] = 0;
62 s
-> Read(src
, s
-> GetSize());
66 doc
.Replace("<", "<", TRUE
);
67 doc
.Replace(">", ">", TRUE
);
68 doc2
= "<HTML><BODY><PRE>\n" + doc
+ "\n</PRE></BODY></HTML>";
76 //--------------------------------------------------------------------------------
79 //--------------------------------------------------------------------------------
81 class wxHtmlFilterImage
: public wxHtmlFilter
83 DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage
)
86 virtual bool CanRead(const wxFSFile
& file
) const;
87 virtual wxString
ReadFile(const wxFSFile
& file
) const;
90 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage
, wxHtmlFilter
)
94 bool wxHtmlFilterImage::CanRead(const wxFSFile
& file
) const
96 return (file
.GetMimeType().Left(6) == "image/");
101 wxString
wxHtmlFilterImage::ReadFile(const wxFSFile
& file
) const
103 return ("<HTML><BODY><IMG SRC=\"" + file
.GetLocation() + "\"></BODY></HTML>");
109 //--------------------------------------------------------------------------------
110 // wxHtmlFilterPlainText
111 // filter for text/plain or uknown
112 //--------------------------------------------------------------------------------
114 class wxHtmlFilterHTML
: public wxHtmlFilter
116 DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML
)
119 virtual bool CanRead(const wxFSFile
& file
) const;
120 virtual wxString
ReadFile(const wxFSFile
& file
) const;
124 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML
, wxHtmlFilter
)
126 bool wxHtmlFilterHTML::CanRead(const wxFSFile
& file
) const
128 // return (file.GetMimeType() == "text/html");
129 // This is true in most case but some page can return:
130 // "text/html; char-encoding=...."
131 // So we use Find instead
132 return (file
.GetMimeType().Find(wxT("text/html")) == 0);
137 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
) const
139 wxInputStream
*s
= file
.GetStream();
143 if (s
== NULL
) return wxEmptyString
;
144 src
= new char[s
-> GetSize() + 1];
145 src
[s
-> GetSize()] = 0;
146 s
-> Read(src
, s
-> GetSize());
158 class wxHtmlFilterModule
: public wxModule
160 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
163 virtual bool OnInit()
165 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
166 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
169 virtual void OnExit() {}
172 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)