]>
git.saurik.com Git - wxWidgets.git/blob - src/html/mod_image.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml module for displaying images
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation
13 #include <wx/wxprec.h>
26 #include <wx/html/forcelink.h>
27 #include <wx/html/mod_templ.h>
29 #include <wx/wxhtml.h>
32 FORCE_LINK_ME(mod_image
)
35 //--------------------------------------------------------------------------------
38 //--------------------------------------------------------------------------------
40 class wxHtmlImageCell
: public wxHtmlCell
45 wxHtmlImageCell(wxFSFile
*input
, int w
= -1, int h
= -1, int align
= HTML_ALIGN_BOTTOM
);
46 ~wxHtmlImageCell() {if (m_Image
) delete m_Image
;}
47 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
52 //--------------------------------------------------------------------------------
54 //--------------------------------------------------------------------------------
56 wxHtmlImageCell::wxHtmlImageCell(wxFSFile
*input
, int w
, int h
, int align
) : wxHtmlCell()
60 wxString m
= input
-> GetMimeType();
61 wxInputStream
*s
= input
-> GetStream();
63 #if wxVERSION_NUMBER < 2100
64 /* NOTE : use this *old* code only if you have old 2.0.1 wxWindows distribution
65 and don't want to upgrade it with stuffs from add-on/wxwin201 */
66 if (wxMimeTypesManager::IsOfType(m
, "image/png")) img
= new wxImage(*s
, wxBITMAP_TYPE_PNG
);
67 else if (wxMimeTypesManager::IsOfType(m
, "image/jpeg")) img
= new wxImage(*s
, wxBITMAP_TYPE_JPEG
);
68 else if (wxMimeTypesManager::IsOfType(m
, "image/bmp")) img
= new wxImage(*s
, wxBITMAP_TYPE_BMP
);
69 else if (wxMimeTypesManager::IsOfType(m
, "image/gif")) img
= new wxImage(*s
, wxBITMAP_TYPE_GIF
);
70 else if (wxMimeTypesManager::IsOfType(m
, "image/tiff")) img
= new wxImage(*s
, wxBITMAP_TYPE_TIF
);
71 else if (wxMimeTypesManager::IsOfType(m
, "image/xpm")) img
= new wxImage(*s
, wxBITMAP_TYPE_XPM
);
72 else if (wxMimeTypesManager::IsOfType(m
, "image/xbm")) img
= new wxImage(*s
, wxBITMAP_TYPE_XBM
);
75 img
= new wxImage(*s
, m
);
79 if (img
&& (img
-> Ok())) {
80 ww
= img
-> GetWidth();
81 hh
= img
-> GetHeight();
82 if (w
!= -1) m_Width
= w
; else m_Width
= ww
;
83 if (h
!= -1) m_Height
= h
; else m_Height
= hh
;
84 if ((m_Width
!= ww
) || (m_Height
!= hh
)) {
85 wxImage img2
= img
-> Scale(m_Width
, m_Height
);
86 m_Image
= new wxBitmap(img2
.ConvertToBitmap());
89 m_Image
= new wxBitmap(img
-> ConvertToBitmap());
94 m_Descent
= m_Height
; break;
95 case HTML_ALIGN_CENTER
:
96 m_Descent
= m_Height
/ 2; break;
97 case HTML_ALIGN_BOTTOM
: default :
104 void wxHtmlImageCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
107 dc
.DrawBitmap(*m_Image
, x
+ m_PosX
, y
+ m_PosY
, TRUE
);
108 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
115 //--------------------------------------------------------------------------------
117 //--------------------------------------------------------------------------------
119 TAG_HANDLER_BEGIN(IMG
, "IMG")
121 TAG_HANDLER_PROC(tag
)
123 if (tag
.HasParam("SRC")) {
127 wxString tmp
= tag
.GetParam("SRC");
129 str
= m_WParser
-> GetFS() -> OpenFile(tmp
);
130 if (tag
.HasParam("WIDTH")) tag
.ScanParam("WIDTH", "%i", &w
);
131 if (tag
.HasParam("HEIGHT")) tag
.ScanParam("HEIGHT", "%i", &h
);
132 al
= HTML_ALIGN_BOTTOM
;
133 if (tag
.HasParam("ALIGN")) {
134 wxString alstr
= tag
.GetParam("ALIGN");
135 alstr
.MakeUpper(); // for the case alignment was in ".."
136 if (alstr
== "TEXTTOP") al
= HTML_ALIGN_TOP
;
137 else if ((alstr
== "CENTER") || (alstr
== "ABSCENTER")) al
= HTML_ALIGN_CENTER
;
140 wxHtmlCell
*cel
= new wxHtmlImageCell(str
, w
, h
, al
);
141 cel
-> SetLink(m_WParser
-> GetLink());
142 m_WParser
-> GetContainer() -> InsertCell(cel
);
150 TAG_HANDLER_END(IMAGE
)
154 TAGS_MODULE_BEGIN(Image
)
158 TAGS_MODULE_END(Image
)