]>
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
14 #include <wx/wxprec.h>
27 #include <wx/html/htmlfilter.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
& file
)
53 wxString
wxHtmlFilterPlainText::ReadFile(const wxFSFile
& file
)
55 wxInputStream
*s
= file
.GetStream();
59 if (s
== NULL
) return wxEmptyString
;
60 src
= (char*) malloc(s
-> StreamSize());
61 src
[s
-> StreamSize()] = 0;
62 s
-> Read(src
, s
-> StreamSize());
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
);
87 virtual wxString
ReadFile(const wxFSFile
& file
);
90 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage
, wxHtmlFilter
)
94 bool wxHtmlFilterImage::CanRead(const wxFSFile
& file
)
96 return (file
.GetMimeType().Left(6) == "image/");
101 wxString
wxHtmlFilterImage::ReadFile(const wxFSFile
& file
)
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
);
120 virtual wxString
ReadFile(const wxFSFile
& file
);
124 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML
, wxHtmlFilter
)
126 bool wxHtmlFilterHTML::CanRead(const wxFSFile
& file
)
128 return (file
.GetMimeType() == "text/html");
133 wxString
wxHtmlFilterHTML::ReadFile(const wxFSFile
& file
)
135 wxInputStream
*s
= file
.GetStream();
139 if (s
== NULL
) return wxEmptyString
;
140 src
= (char*) malloc(s
-> StreamSize() + 1);
141 src
[s
-> StreamSize()] = 0;
142 s
-> Read(src
, s
-> StreamSize());
154 class wxHtmlFilterModule
: public wxModule
156 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule
)
159 virtual bool OnInit()
161 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML
);
162 wxHtmlWindow::AddFilter(new wxHtmlFilterImage
);
165 virtual void OnExit() {}
168 IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule
, wxModule
)