]>
git.saurik.com Git - wxWidgets.git/blob - src/html/mod_image.cpp
908e4b62413d1b45cdc8dd661941e3eb5d1021ac
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml module for displaying images
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
12 #include <wx/html/forcelink.h>
13 #include <wx/html/mod_templ.h>
15 #include <wx/wxhtml.h>
18 FORCE_LINK_ME(mod_image
)
21 //--------------------------------------------------------------------------------
24 //--------------------------------------------------------------------------------
26 class wxHtmlImageCell
: public wxHtmlCell
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
);
38 //--------------------------------------------------------------------------------
40 //--------------------------------------------------------------------------------
42 wxHtmlImageCell::wxHtmlImageCell(wxFSFile
*input
, int w
, int h
, int align
) : wxHtmlCell()
46 wxString m
= input
-> GetMimeType();
47 wxInputStream
*s
= input
-> GetStream();
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
);
61 img
= new wxImage(*s
, m
);
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());
75 m_Image
= new wxBitmap(img
-> ConvertToBitmap());
80 m_Descent
= m_Height
; break;
81 case HTML_ALIGN_CENTER
:
82 m_Descent
= m_Height
/ 2; break;
83 case HTML_ALIGN_BOTTOM
: default :
90 void wxHtmlImageCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
93 dc
.DrawBitmap(*m_Image
, x
+ m_PosX
, y
+ m_PosY
, TRUE
);
94 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
101 //--------------------------------------------------------------------------------
103 //--------------------------------------------------------------------------------
105 TAG_HANDLER_BEGIN(IMG
, "IMG")
107 TAG_HANDLER_PROC(tag
)
109 if (tag
.HasParam("SRC")) {
113 wxString tmp
= tag
.GetParam("SRC");
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
;
126 wxHtmlCell
*cel
= new wxHtmlImageCell(str
, w
, h
, al
);
127 cel
-> SetLink(m_WParser
-> GetLink());
128 m_WParser
-> GetContainer() -> InsertCell(cel
);
136 TAG_HANDLER_END(IMAGE
)
140 TAGS_MODULE_BEGIN(Image
)
144 TAGS_MODULE_END(Image
)