]>
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"
26 #include "wx/html/htmlfilter.h"
27 #include "wx/html/htmlwin.h"
32 There is code for several default filters:
36 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter
, wxObject
)
38 //--------------------------------------------------------------------------------
39 // wxHtmlFilterPlainText
40 // filter for text/plain or uknown
41 //--------------------------------------------------------------------------------
43 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText
, wxHtmlFilter
)
45 bool wxHtmlFilterPlainText::CanRead(const wxFSFile
& WXUNUSED(file
)) const
52 wxString
wxHtmlFilterPlainText::ReadFile(const wxFSFile
& file
) const
54 wxInputStream
*s
= file
.GetStream();
58 if (s
== NULL
) return wxEmptyString
;
59 src
= new char[s
-> GetSize()+1];
60 src
[s
-> GetSize()] = 0;
61 s
-> Read(src
, s
-> GetSize());
65 doc
.Replace(_T("<"), _T("<"), TRUE
);
66 doc
.Replace(_T(">"), _T(">"), TRUE
);
67 doc2
= _T("<HTML><BODY><PRE>\n") + doc
+ _T("\n</PRE></BODY></HTML>");
75 //--------------------------------------------------------------------------------
78 //--------------------------------------------------------------------------------
80 class wxHtmlFilterImage
: public wxHtmlFilter
82 DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage
)
85 virtual bool CanRead(const wxFSFile
& file
) const;
86 virtual wxString
ReadFile(const wxFSFile
& file
) const;
89 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage
, wxHtmlFilter
)
93 bool wxHtmlFilterImage::CanRead(const wxFSFile
& file
) const
95 return (file
.GetMimeType().Left(6) == "image/");
100 wxString
wxHtmlFilterImage::ReadFile(const wxFSFile
& file
) const
102 return ("<HTML><BODY><IMG SRC=\"" + file
.GetLocation() + "\"></BODY></HTML>");
108 //--------------------------------------------------------------------------------
109 // wxHtmlFilterPlainText
110 // filter for text/plain or uknown
111 //--------------------------------------------------------------------------------
113 class wxHtmlFilterHTML
: public wxHtmlFilter
115 DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML
)
118 virtual bool CanRead(const wxFSFile
& file
) const;
119 virtual wxString
ReadFile(const wxFSFile
& file
) const;
123 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML
, wxHtmlFilter
)
125 bool wxHtmlFilterHTML::CanRead(const wxFSFile
& file
) const
127 // return (file.GetMimeType() == "text/html");
128 // This is true in most case but some page can return:
129 // "text/html; char-encoding=...."
130 // So we use Find instead
131 return (file
.GetMimeType().Find(_T("text/html")) == 0);
136 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
) const
138 wxInputStream
*s
= file
.GetStream();
142 if (s
== NULL
) return wxEmptyString
;
143 src
= new char[s
-> GetSize() + 1];
144 src
[s
-> GetSize()] = 0;
145 s
-> Read(src
, s
-> GetSize());
157 class wxHtmlFilterModule
: public wxModule
159 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
162 virtual bool OnInit()
164 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
165 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
168 virtual void OnExit() {}
171 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)