+//----------------------------------------------------------------------------
+
+
+wxHtmlImageCell::wxHtmlImageCell(wxHtmlWindowInterface *windowIface,
+ wxFSFile *input,
+ int w, bool wpercent, int h, bool hpresent, double scale, int align,
+ const wxString& mapname) : wxHtmlCell()
+{
+ m_windowIface = windowIface;
+ m_scale = scale;
+ m_showFrame = false;
+ m_bitmap = NULL;
+ m_bmpW = w;
+ m_bmpH = h;
+ m_align = align;
+ m_bmpWpercent = wpercent;
+ m_bmpHpresent = hpresent;
+ m_imageMap = NULL;
+ m_mapName = mapname;
+ SetCanLiveOnPagebreak(false);
+#if wxUSE_GIF && wxUSE_TIMER
+ m_gifDecoder = NULL;
+ m_gifTimer = NULL;
+ m_physX = m_physY = wxDefaultCoord;
+ m_nCurrFrame = 0;
+#endif
+
+ if ( m_bmpW && m_bmpH )
+ {
+ if ( input )
+ {
+ wxInputStream *s = input->GetStream();
+
+ if ( s )
+ {
+#if wxUSE_GIF && wxUSE_TIMER
+ bool readImg = true;
+ if ( m_windowIface &&
+ (input->GetLocation().Matches(wxT("*.gif")) ||
+ input->GetLocation().Matches(wxT("*.GIF"))) )
+ {
+ m_gifDecoder = new wxGIFDecoder();
+ if ( m_gifDecoder->LoadGIF(*s) == wxGIF_OK )
+ {
+ wxImage img;
+ if ( m_gifDecoder->ConvertToImage(0, &img) )
+ SetImage(img);
+
+ readImg = false;
+
+ if ( m_gifDecoder->IsAnimation() )
+ {
+ m_gifTimer = new wxGIFTimer(this);
+ long delay = m_gifDecoder->GetDelay(0);
+ if ( delay == 0 )
+ delay = 1;
+ m_gifTimer->Start(delay, true);
+ }
+ else
+ {
+ wxDELETE(m_gifDecoder);
+ }
+ }
+ else
+ {
+ wxDELETE(m_gifDecoder);
+ }
+ }
+
+ if ( readImg )
+#endif // wxUSE_GIF && wxUSE_TIMER
+ {
+ wxImage image(*s, wxBITMAP_TYPE_ANY);
+ if ( image.IsOk() )
+ SetImage(image);
+ }
+ }
+ }
+ else // input==NULL, use "broken image" bitmap
+ {
+ if ( m_bmpW == wxDefaultCoord && m_bmpH == wxDefaultCoord )
+ {
+ m_bmpW = 29;
+ m_bmpH = 31;
+ }
+ else
+ {
+ m_showFrame = true;
+ if ( m_bmpW == wxDefaultCoord ) m_bmpW = 31;
+ if ( m_bmpH == wxDefaultCoord ) m_bmpH = 33;
+ }
+ m_bitmap =
+ new wxBitmap(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE));
+ }
+ }
+ //else: ignore the 0-sized images used sometimes on the Web pages
+
+ }
+
+void wxHtmlImageCell::SetImage(const wxImage& img)
+{
+#if !defined(__WXMSW__) || wxUSE_WXDIB
+ if ( img.IsOk() )
+ {
+ delete m_bitmap;
+
+ int ww, hh;
+ ww = img.GetWidth();
+ hh = img.GetHeight();
+
+ if ( m_bmpW == wxDefaultCoord)
+ m_bmpW = ww;
+ if ( m_bmpH == wxDefaultCoord)
+ m_bmpH = hh;
+
+ // Only scale the bitmap at the rendering stage,
+ // so we don't lose quality twice
+/*
+ if ((m_bmpW != ww) || (m_bmpH != hh))
+ {
+ wxImage img2 = img.Scale(m_bmpW, m_bmpH);
+ m_bitmap = new wxBitmap(img2);
+ }
+ else
+*/
+ m_bitmap = new wxBitmap(img);
+ }
+#endif
+}
+
+void wxHtmlImageCell::SetAlt(const wxString& alt)
+{
+ m_alt = alt;
+}
+
+wxString wxHtmlImageCell::ConvertToText(wxHtmlSelection* WXUNUSED(sel)) const
+{
+ return m_alt;
+}
+
+#if wxUSE_GIF && wxUSE_TIMER
+void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer)
+{
+ wxImage img;
+
+ // advance current frame
+ m_nCurrFrame++;
+ if (m_nCurrFrame == m_gifDecoder->GetFrameCount())
+ m_nCurrFrame = 0;
+
+ if ( m_physX == wxDefaultCoord )
+ {
+ m_physX = m_physY = 0;
+ for (wxHtmlCell *cell = this; cell; cell = cell->GetParent())
+ {
+ m_physX += cell->GetPosX();
+ m_physY += cell->GetPosY();
+ }
+ }
+
+ wxWindow *win = m_windowIface->GetHTMLWindow();
+ wxPoint pos =
+ m_windowIface->HTMLCoordsToWindow(this, wxPoint(m_physX, m_physY));
+ wxRect rect(pos, wxSize(m_Width, m_Height));
+
+ if ( win->GetClientRect().Intersects(rect) &&
+ m_gifDecoder->ConvertToImage(m_nCurrFrame, &img) )
+ {
+#if !defined(__WXMSW__) || wxUSE_WXDIB
+ if ( m_gifDecoder->GetFrameSize(m_nCurrFrame) != wxSize(m_Width, m_Height) ||
+ m_gifDecoder->GetFramePosition(m_nCurrFrame) != wxPoint(0, 0) )
+ {
+ wxBitmap bmp(img);
+ wxMemoryDC dc;
+ dc.SelectObject(*m_bitmap);
+ dc.DrawBitmap(bmp, m_gifDecoder->GetFramePosition(m_nCurrFrame),
+ true /* use mask */);
+ }
+ else
+#endif
+ SetImage(img);
+ win->Refresh(img.HasMask(), &rect);
+ }
+
+ long delay = m_gifDecoder->GetDelay(m_nCurrFrame);
+ if ( delay == 0 )
+ delay = 1;
+ timer->Start(delay, true);
+}