]> git.saurik.com Git - wxWidgets.git/blame - src/html/mod_image.cpp
Removed default parameter setting for wxHtmlHelpControler::AddBook causing
[wxWidgets.git] / src / html / mod_image.cpp
CommitLineData
5526e819
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: mod_image.cpp
3// Purpose: wxHtml module for displaying images
4// Author: Vaclav Slavik
5// Copyright: (c) 1999 Vaclav Slavik
6// Licence: wxWindows Licence
7/////////////////////////////////////////////////////////////////////////////
8
9#include "wx/defs.h"
10#if wxUSE_HTML
11
12#include <wx/html/forcelink.h>
13#include <wx/html/mod_templ.h>
14
15#include <wx/wxhtml.h>
16#include <wx/image.h>
17
18FORCE_LINK_ME(mod_image)
19
20
21//--------------------------------------------------------------------------------
22// wxHtmlImageCell
23// Image/bitmap
24//--------------------------------------------------------------------------------
25
26class wxHtmlImageCell : public wxHtmlCell
27{
28 public:
29 wxBitmap *m_Image;
30
31 wxHtmlImageCell(wxFSFile *input, int w = -1, int h = -1, int align = HTML_ALIGN_BOTTOM);
32 ~wxHtmlImageCell() {if (m_Image) delete m_Image;}
33 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
34};
35
36
37
38//--------------------------------------------------------------------------------
39// wxHtmlImageCell
40//--------------------------------------------------------------------------------
41
42wxHtmlImageCell::wxHtmlImageCell(wxFSFile *input, int w, int h, int align) : wxHtmlCell()
43{
44 wxImage *img;
45 int ww, hh;
46 wxString m = input -> GetMimeType();
47 wxInputStream *s = input -> GetStream();
48
49#if wxVERSION_NUMBER < 2100
50/* NOTE : use this *old* code only if you have old 2.0.1 wxWindows distribution
51 and don't want to upgrade it with stuffs from add-on/wxwin201 */
52 if (wxMimeTypesManager::IsOfType(m, "image/png")) img = new wxImage(*s, wxBITMAP_TYPE_PNG);
53 else if (wxMimeTypesManager::IsOfType(m, "image/jpeg")) img = new wxImage(*s, wxBITMAP_TYPE_JPEG);
54 else if (wxMimeTypesManager::IsOfType(m, "image/bmp")) img = new wxImage(*s, wxBITMAP_TYPE_BMP);
55 else if (wxMimeTypesManager::IsOfType(m, "image/gif")) img = new wxImage(*s, wxBITMAP_TYPE_GIF);
56 else if (wxMimeTypesManager::IsOfType(m, "image/tiff")) img = new wxImage(*s, wxBITMAP_TYPE_TIF);
57 else if (wxMimeTypesManager::IsOfType(m, "image/xpm")) img = new wxImage(*s, wxBITMAP_TYPE_XPM);
58 else if (wxMimeTypesManager::IsOfType(m, "image/xbm")) img = new wxImage(*s, wxBITMAP_TYPE_XBM);
59 else img = NULL;
60#else
61 img = new wxImage(*s, m);
62#endif
63
64 m_Image = NULL;
65 if (img && (img -> Ok())) {
66 ww = img -> GetWidth();
67 hh = img -> GetHeight();
68 if (w != -1) m_Width = w; else m_Width = ww;
69 if (h != -1) m_Height = h; else m_Height = hh;
70 if ((m_Width != ww) || (m_Height != hh)) {
71 wxImage img2 = img -> Scale(m_Width, m_Height);
72 m_Image = new wxBitmap(img2.ConvertToBitmap());
73 }
74 else
75 m_Image = new wxBitmap(img -> ConvertToBitmap());
76 delete img;
77 }
78 switch (align) {
79 case HTML_ALIGN_TOP :
80 m_Descent = m_Height; break;
81 case HTML_ALIGN_CENTER :
82 m_Descent = m_Height / 2; break;
83 case HTML_ALIGN_BOTTOM : default :
84 m_Descent = 0; break;
85 }
86}
87
88
89
90void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
91{
92 if (m_Image)
93 dc.DrawBitmap(*m_Image, x + m_PosX, y + m_PosY, TRUE);
94 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
95}
96
97
98
99
100
101//--------------------------------------------------------------------------------
102// tag handler
103//--------------------------------------------------------------------------------
104
105TAG_HANDLER_BEGIN(IMG, "IMG")
106
107 TAG_HANDLER_PROC(tag)
108 {
109 if (tag.HasParam("SRC")) {
110 int w = -1, h = -1;
111 int al;
112 wxFSFile *str;
113 wxString tmp = tag.GetParam("SRC");
114
115 str = m_WParser -> GetFS() -> OpenFile(tmp);
116 if (tag.HasParam("WIDTH")) tag.ScanParam("WIDTH", "%i", &w);
117 if (tag.HasParam("HEIGHT")) tag.ScanParam("HEIGHT", "%i", &h);
118 al = HTML_ALIGN_BOTTOM;
119 if (tag.HasParam("ALIGN")) {
120 wxString alstr = tag.GetParam("ALIGN");
121 alstr.MakeUpper(); // for the case alignment was in ".."
122 if (alstr == "TEXTTOP") al = HTML_ALIGN_TOP;
123 else if ((alstr == "CENTER") || (alstr == "ABSCENTER")) al = HTML_ALIGN_CENTER;
124 }
125 if (str) {
126 wxHtmlCell *cel = new wxHtmlImageCell(str, w, h, al);
127 cel -> SetLink(m_WParser -> GetLink());
128 m_WParser -> GetContainer() -> InsertCell(cel);
129 delete str;
130 }
131 }
132
133 return FALSE;
134 }
135
136TAG_HANDLER_END(IMAGE)
137
138
139
140TAGS_MODULE_BEGIN(Image)
141
142 TAGS_MODULE_ADD(IMG)
143
144TAGS_MODULE_END(Image)
145
146
147#endif