]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlfilt.cpp
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"
28 #include "wx/html/htmlfilt.h"
29 #include "wx/html/htmlwin.h"
34 There is code for several default filters:
38 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter
, wxObject
)
40 //--------------------------------------------------------------------------------
41 // wxHtmlFilterPlainText
42 // filter for text/plain or uknown
43 //--------------------------------------------------------------------------------
45 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText
, wxHtmlFilter
)
47 bool wxHtmlFilterPlainText::CanRead(const wxFSFile
& WXUNUSED(file
)) const
54 wxString
wxHtmlFilterPlainText::ReadFile(const wxFSFile
& file
) const
56 wxInputStream
*s
= file
.GetStream();
60 if (s
== NULL
) return wxEmptyString
;
61 src
= new char[s
-> GetSize()+1];
62 src
[s
-> GetSize()] = 0;
63 s
-> Read(src
, s
-> GetSize());
67 doc
.Replace("<", "<", TRUE
);
68 doc
.Replace(">", ">", TRUE
);
69 doc2
= "<HTML><BODY><PRE>\n" + doc
+ "\n</PRE></BODY></HTML>";
77 //--------------------------------------------------------------------------------
80 //--------------------------------------------------------------------------------
82 class wxHtmlFilterImage
: public wxHtmlFilter
84 DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage
)
87 virtual bool CanRead(const wxFSFile
& file
) const;
88 virtual wxString
ReadFile(const wxFSFile
& file
) const;
91 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage
, wxHtmlFilter
)
95 bool wxHtmlFilterImage::CanRead(const wxFSFile
& file
) const
97 return (file
.GetMimeType().Left(6) == "image/");
102 wxString
wxHtmlFilterImage::ReadFile(const wxFSFile
& file
) const
104 return ("<HTML><BODY><IMG SRC=\"" + file
.GetLocation() + "\"></BODY></HTML>");
110 //--------------------------------------------------------------------------------
111 // wxHtmlFilterPlainText
112 // filter for text/plain or uknown
113 //--------------------------------------------------------------------------------
115 class wxHtmlFilterHTML
: public wxHtmlFilter
117 DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML
)
120 virtual bool CanRead(const wxFSFile
& file
) const;
121 virtual wxString
ReadFile(const wxFSFile
& file
) const;
125 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML
, wxHtmlFilter
)
127 bool wxHtmlFilterHTML::CanRead(const wxFSFile
& file
) const
129 // return (file.GetMimeType() == "text/html");
130 // This is true in most case but some page can return:
131 // "text/html; char-encoding=...."
132 // So we use Find instead
133 return (file
.GetMimeType().Find(wxT("text/html")) == 0);
138 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
) const
140 wxInputStream
*s
= file
.GetStream();
144 if (s
== NULL
) return wxEmptyString
;
145 src
= new char[s
-> GetSize() + 1];
146 src
[s
-> GetSize()] = 0;
147 s
-> Read(src
, s
-> GetSize());
159 class wxHtmlFilterModule
: public wxModule
161 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
164 virtual bool OnInit()
166 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
167 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
170 virtual void OnExit() {}
173 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)