]> git.saurik.com Git - wxWidgets.git/blame - src/html/htmlfilt.cpp
removed show_progress argument in some private functions -- was never used
[wxWidgets.git] / src / html / htmlfilt.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
69941f05 2// Name: htmlfilt.cpp
5526e819
VS
3// Purpose: wxHtmlFilter - input filter for translating into HTML format
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
69941f05 12#pragma implementation
5526e819
VS
13#endif
14
4dcaf11a 15#include "wx/wxprec.h"
5526e819 16
314260fb 17#include "wx/defs.h"
5526e819
VS
18#if wxUSE_HTML
19
20#ifdef __BORDLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WXPRECOMP
4dcaf11a 25#include "wx/wx.h"
5526e819
VS
26#endif
27
69941f05 28#include "wx/html/htmlfilt.h"
4dcaf11a 29#include "wx/html/htmlwin.h"
5526e819
VS
30
31
32/*
33
34There is code for several default filters:
35
36*/
37
38IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter, wxObject)
39
40//--------------------------------------------------------------------------------
41// wxHtmlFilterPlainText
42// filter for text/plain or uknown
43//--------------------------------------------------------------------------------
44
45IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText, wxHtmlFilter)
46
a4c97004 47bool wxHtmlFilterPlainText::CanRead(const wxFSFile& WXUNUSED(file)) const
5526e819
VS
48{
49 return TRUE;
50}
51
52
53
420ec58a 54wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file) const
5526e819
VS
55{
56 wxInputStream *s = file.GetStream();
57 char *src;
58 wxString doc, doc2;
59
60 if (s == NULL) return wxEmptyString;
259d1674
VZ
61 src = new char[s -> GetSize()+1];
62 src[s -> GetSize()] = 0;
63 s -> Read(src, s -> GetSize());
5526e819 64 doc = src;
8dd71e2b 65 delete [] src;
5526e819 66
66a77a74
OK
67 doc.Replace(wxT("<"), wxT("&lt;"), TRUE);
68 doc.Replace(wxT(">"), wxT("&gt;"), TRUE);
5526e819
VS
69 doc2 = "<HTML><BODY><PRE>\n" + doc + "\n</PRE></BODY></HTML>";
70 return doc2;
71}
72
73
74
75
76
77//--------------------------------------------------------------------------------
78// wxHtmlFilterImage
79// filter for image/*
80//--------------------------------------------------------------------------------
81
82class wxHtmlFilterImage : public wxHtmlFilter
83{
84 DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage)
85
86 public:
420ec58a
VS
87 virtual bool CanRead(const wxFSFile& file) const;
88 virtual wxString ReadFile(const wxFSFile& file) const;
5526e819
VS
89};
90
91IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage, wxHtmlFilter)
92
93
94
420ec58a 95bool wxHtmlFilterImage::CanRead(const wxFSFile& file) const
5526e819 96{
0413cec5 97 return (file.GetMimeType().Left(6) == wxT("image/"));
5526e819
VS
98}
99
100
101
420ec58a 102wxString wxHtmlFilterImage::ReadFile(const wxFSFile& file) const
5526e819
VS
103{
104 return ("<HTML><BODY><IMG SRC=\"" + file.GetLocation() + "\"></BODY></HTML>");
105}
106
107
108
109
110//--------------------------------------------------------------------------------
111// wxHtmlFilterPlainText
112// filter for text/plain or uknown
113//--------------------------------------------------------------------------------
114
115class wxHtmlFilterHTML : public wxHtmlFilter
116{
117 DECLARE_DYNAMIC_CLASS(wxHtmlFilterHTML)
118
119 public:
420ec58a
VS
120 virtual bool CanRead(const wxFSFile& file) const;
121 virtual wxString ReadFile(const wxFSFile& file) const;
5526e819
VS
122};
123
124
125IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML, wxHtmlFilter)
126
420ec58a 127bool wxHtmlFilterHTML::CanRead(const wxFSFile& file) const
5526e819 128{
f61815af
GL
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
981e62aa 133 return (file.GetMimeType().Find(_("text/html")) == 0);
5526e819
VS
134}
135
136
137
420ec58a 138wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file) const
5526e819
VS
139{
140 wxInputStream *s = file.GetStream();
141 char *src;
142 wxString doc;
143
144 if (s == NULL) return wxEmptyString;
2776d7c3 145 src = new char[s -> GetSize() + 1];
259d1674
VZ
146 src[s -> GetSize()] = 0;
147 s -> Read(src, s -> GetSize());
5526e819 148 doc = src;
2776d7c3 149 delete[] src;
5526e819 150
981e62aa
VS
151 // add meta tag if we obtained this through http:
152 if (file.GetMimeType().Find(_T("; charset=")) == 0)
153 {
154 wxString s(_T("<meta http-equiv=\"Content-Type\" content=\""));
155 s << file.GetMimeType() << _T("\">");
156 return s;
157 }
158
159 else return doc;
5526e819
VS
160}
161
162
163
164
165///// Module:
166
167class wxHtmlFilterModule : public wxModule
168{
169 DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule)
170
171 public:
172 virtual bool OnInit()
173 {
174 wxHtmlWindow::AddFilter(new wxHtmlFilterHTML);
175 wxHtmlWindow::AddFilter(new wxHtmlFilterImage);
176 return TRUE;
177 }
178 virtual void OnExit() {}
179};
180
181IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule, wxModule)
182
8dd71e2b 183#endif