]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlfilter.cpp
1bdccd5b17cc061ef6f6f62fa48a5eecd794221c
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
& 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("<", "<", TRUE
);
66 doc
.Replace(">", ">", TRUE
);
67 doc2
= "<HTML><BODY><PRE>\n" + doc
+ "\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");
132 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
) const
134 wxInputStream
*s
= file
.GetStream();
138 if (s
== NULL
) return wxEmptyString
;
139 src
= (char*) malloc(s
-> GetSize() + 1);
140 src
[s
-> GetSize()] = 0;
141 s
-> Read(src
, s
-> GetSize());
153 class wxHtmlFilterModule
: public wxModule
155 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
158 virtual bool OnInit()
160 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
161 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
164 virtual void OnExit() {}
167 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)