]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlfilter.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlFilter - input filter for translating into HTML format
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "htmlfilter.h"
14 #include "wx/wxprec.h"
25 #include "wx/html/htmlfilter.h"
26 #include "wx/html/htmlwin.h"
31 There is code for several default filters:
35 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter
, wxObject
)
37 //--------------------------------------------------------------------------------
38 // wxHtmlFilterPlainText
39 // filter for text/plain or uknown
40 //--------------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText
, wxHtmlFilter
)
44 bool wxHtmlFilterPlainText::CanRead(const wxFSFile
& WXUNUSED(file
)) const
51 wxString
wxHtmlFilterPlainText::ReadFile(const wxFSFile
& file
) const
53 wxInputStream
*s
= file
.GetStream();
57 if (s
== NULL
) return wxEmptyString
;
58 src
= new char[s
-> GetSize()+1];
59 src
[s
-> GetSize()] = 0;
60 s
-> Read(src
, s
-> GetSize());
64 doc
.Replace(_T("<"), _T("<"), TRUE
);
65 doc
.Replace(_T(">"), _T(">"), TRUE
);
66 doc2
= _T("<HTML><BODY><PRE>\n") + doc
+ _T("\n</PRE></BODY></HTML>");
74 //--------------------------------------------------------------------------------
77 //--------------------------------------------------------------------------------
79 class wxHtmlFilterImage
: public wxHtmlFilter
81 DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage
)
84 virtual bool CanRead(const wxFSFile
& file
) const;
85 virtual wxString
ReadFile(const wxFSFile
& file
) const;
88 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage
, wxHtmlFilter
)
92 bool wxHtmlFilterImage::CanRead(const wxFSFile
& file
) const
94 return (file
.GetMimeType().Left(6) == "image/");
99 wxString
wxHtmlFilterImage::ReadFile(const wxFSFile
& file
) const
101 return ("<HTML><BODY><IMG SRC=\"" + file
.GetLocation() + "\"></BODY></HTML>");
107 //--------------------------------------------------------------------------------
108 // wxHtmlFilterPlainText
109 // filter for text/plain or uknown
110 //--------------------------------------------------------------------------------
112 class wxHtmlFilterHTML
: public wxHtmlFilter
114 DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML
)
117 virtual bool CanRead(const wxFSFile
& file
) const;
118 virtual wxString
ReadFile(const wxFSFile
& file
) const;
122 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML
, wxHtmlFilter
)
124 bool wxHtmlFilterHTML::CanRead(const wxFSFile
& file
) const
126 // return (file.GetMimeType() == "text/html");
127 // This is true in most case but some page can return:
128 // "text/html; char-encoding=...."
129 // So we use Find instead
130 return (file
.GetMimeType().Find(_T("text/html")) == 0);
135 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
) const
137 wxInputStream
*s
= file
.GetStream();
141 if (s
== NULL
) return wxEmptyString
;
142 src
= new char[s
-> GetSize() + 1];
143 src
[s
-> GetSize()] = 0;
144 s
-> Read(src
, s
-> GetSize());
156 class wxHtmlFilterModule
: public wxModule
158 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
161 virtual bool OnInit()
163 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
164 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
167 virtual void OnExit() {}
170 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)