]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_image.cpp
compilation fix after last change (GTK1 doesn't have g_signal_stop_emission_by_name...
[wxWidgets.git] / src / html / m_image.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/html/m_image.cpp
5526e819
VS
3// Purpose: wxHtml module for displaying images
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
25082126 6// Copyright: (c) 1999 Vaclav Slavik, Joel Lucsy
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
25082126 10#include "wx/wxprec.h"
3364ab79 11
2b5f62a0 12#ifdef __BORLANDC__
93763ad5 13 #pragma hdrstop
3364ab79
RS
14#endif
15
93763ad5
WS
16#if wxUSE_HTML && wxUSE_STREAMS
17
3364ab79 18#ifndef WXPRECOMP
ad9835c9 19 #include "wx/dynarray.h"
04dbb646 20 #include "wx/dc.h"
ea5c1679
VS
21 #include "wx/scrolwin.h"
22 #include "wx/timer.h"
2d963ba2 23 #include "wx/dcmemory.h"
e4db172a 24 #include "wx/log.h"
18680f86 25 #include "wx/math.h"
155ecd4c 26 #include "wx/image.h"
3364ab79
RS
27#endif
28
69941f05
VS
29#include "wx/html/forcelnk.h"
30#include "wx/html/m_templ.h"
04db5c3f 31#include "wx/html/htmlwin.h"
5526e819 32
ea5c1679 33#include "wx/gifdecod.h"
214bdb93 34#include "wx/artprov.h"
25082126 35
25082126 36#include <float.h>
5526e819 37
c88293a4 38FORCE_LINK_ME(m_image)
5526e819
VS
39
40
25082126
VS
41
42
43WX_DECLARE_OBJARRAY(int, CoordArray);
3096bd2f 44#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
17a1ebd1 45WX_DEFINE_OBJARRAY(CoordArray)
25082126
VS
46
47
36c4ff4d 48// ---------------------------------------------------------------------------
25082126 49// wxHtmlImageMapAreaCell
36c4ff4d
VS
50// 0-width, 0-height cell that represents single area in
51// imagemap (it's GetLink is called from wxHtmlImageCell's)
52// ---------------------------------------------------------------------------
25082126
VS
53
54class wxHtmlImageMapAreaCell : public wxHtmlCell
55{
01325161
VS
56 public:
57 enum celltype { CIRCLE, RECT, POLY };
58 protected:
59 CoordArray coords;
60 celltype type;
edbd0635 61 int radius;
01325161 62 public:
edbd0635 63 wxHtmlImageMapAreaCell( celltype t, wxString &coords, double pixel_scale = 1.0);
846914d1 64 virtual wxHtmlLinkInfo *GetLink( int x = 0, int y = 0 ) const;
36c4ff4d
VS
65 void Draw(wxDC& WXUNUSED(dc),
66 int WXUNUSED(x), int WXUNUSED(y),
67 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 68 wxHtmlRenderingInfo& WXUNUSED(info)) {}
fc7a2a60
VZ
69
70
71 DECLARE_NO_COPY_CLASS(wxHtmlImageMapAreaCell)
25082126
VS
72};
73
74
75
76
77
edbd0635 78wxHtmlImageMapAreaCell::wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::celltype t, wxString &incoords, double pixel_scale )
25082126 79{
edbd0635 80 int i;
01325161
VS
81 wxString x = incoords, y;
82
83 type = t;
d1da8872 84 while ((i = x.Find( ',' )) != wxNOT_FOUND)
4f9297b0 85 {
edbd0635 86 coords.Add( (int)(pixel_scale * (double)wxAtoi( x.Left( i ).c_str())) );
01325161
VS
87 x = x.Mid( i + 1 );
88 }
edbd0635 89 coords.Add( (int)(pixel_scale * (double)wxAtoi( x.c_str())) );
25082126
VS
90}
91
846914d1 92wxHtmlLinkInfo *wxHtmlImageMapAreaCell::GetLink( int x, int y ) const
25082126 93{
04dbb646 94 switch (type)
4f9297b0 95 {
01325161
VS
96 case RECT:
97 {
edbd0635 98 int l, t, r, b;
01325161
VS
99
100 l = coords[ 0 ];
101 t = coords[ 1 ];
102 r = coords[ 2 ];
103 b = coords[ 3 ];
04dbb646
VZ
104 if (x >= l && x <= r && y >= t && y <= b)
105 {
01325161
VS
106 return m_Link;
107 }
108 break;
109 }
110 case CIRCLE:
111 {
edbd0635
VS
112 int l, t, r;
113 double d;
01325161
VS
114
115 l = coords[ 0 ];
116 t = coords[ 1 ];
117 r = coords[ 2 ];
118 d = sqrt( (double) (((x - l) * (x - l)) + ((y - t) * (y - t))) );
04dbb646
VZ
119 if (d < (double)r)
120 {
01325161
VS
121 return m_Link;
122 }
123 }
124 break;
125 case POLY:
126 {
04dbb646
VZ
127 if (coords.GetCount() >= 6)
128 {
edbd0635
VS
129 int intersects = 0;
130 int wherex = x;
131 int wherey = y;
132 int totalv = coords.GetCount() / 2;
133 int totalc = totalv * 2;
134 int xval = coords[totalc - 2];
135 int yval = coords[totalc - 1];
136 int end = totalc;
137 int pointer = 1;
01325161 138
04dbb646
VZ
139 if ((yval >= wherey) != (coords[pointer] >= wherey))
140 {
141 if ((xval >= wherex) == (coords[0] >= wherex))
142 {
01325161 143 intersects += (xval >= wherex) ? 1 : 0;
04dbb646
VZ
144 }
145 else
146 {
01325161
VS
147 intersects += ((xval - (yval - wherey) *
148 (coords[0] - xval) /
149 (coords[pointer] - yval)) >= wherex) ? 1 : 0;
150 }
151 }
152
04dbb646
VZ
153 while (pointer < end)
154 {
01325161
VS
155 yval = coords[pointer];
156 pointer += 2;
04dbb646
VZ
157 if (yval >= wherey)
158 {
159 while ((pointer < end) && (coords[pointer] >= wherey))
160 {
01325161
VS
161 pointer += 2;
162 }
04dbb646
VZ
163 if (pointer >= end)
164 {
01325161
VS
165 break;
166 }
167 if ((coords[pointer - 3] >= wherex) ==
168 (coords[pointer - 1] >= wherex)) {
169 intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
04dbb646
VZ
170 }
171 else
172 {
01325161
VS
173 intersects +=
174 ((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
175 (coords[pointer - 1] - coords[pointer - 3]) /
176 (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
177 }
04dbb646
VZ
178 }
179 else
180 {
181 while ((pointer < end) && (coords[pointer] < wherey))
182 {
01325161
VS
183 pointer += 2;
184 }
04dbb646
VZ
185 if (pointer >= end)
186 {
01325161
VS
187 break;
188 }
189 if ((coords[pointer - 3] >= wherex) ==
04dbb646
VZ
190 (coords[pointer - 1] >= wherex))
191 {
01325161 192 intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
04dbb646
VZ
193 }
194 else
195 {
01325161
VS
196 intersects +=
197 ((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
198 (coords[pointer - 1] - coords[pointer - 3]) /
199 (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
200 }
201 }
202 }
04dbb646
VZ
203 if ((intersects & 1) != 0)
204 {
01325161
VS
205 return m_Link;
206 }
207 }
208 }
209 break;
210 }
4f9297b0 211
04dbb646 212 if (m_Next)
4f9297b0 213 {
edbd0635 214 wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
01325161
VS
215 return a->GetLink( x, y );
216 }
846914d1 217 return NULL;
25082126
VS
218}
219
220
221
222
223
224
225
226
227//--------------------------------------------------------------------------------
228// wxHtmlImageMapCell
229// 0-width, 0-height cell that represents map from imagemaps
230// it is always placed before wxHtmlImageMapAreaCells
efba2b89 231// It responds to Find(wxHTML_COND_ISIMAGEMAP)
25082126
VS
232//--------------------------------------------------------------------------------
233
234
235class wxHtmlImageMapCell : public wxHtmlCell
236{
01325161
VS
237 public:
238 wxHtmlImageMapCell( wxString &name );
239 protected:
240 wxString m_Name;
241 public:
846914d1 242 virtual wxHtmlLinkInfo *GetLink( int x = 0, int y = 0 ) const;
01325161 243 virtual const wxHtmlCell *Find( int cond, const void *param ) const;
36c4ff4d
VS
244 void Draw(wxDC& WXUNUSED(dc),
245 int WXUNUSED(x), int WXUNUSED(y),
246 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 247 wxHtmlRenderingInfo& WXUNUSED(info)) {}
fc7a2a60
VZ
248
249 DECLARE_NO_COPY_CLASS(wxHtmlImageMapCell)
25082126
VS
250};
251
252
253wxHtmlImageMapCell::wxHtmlImageMapCell( wxString &name )
254{
01325161 255 m_Name = name ;
25082126
VS
256}
257
846914d1 258wxHtmlLinkInfo *wxHtmlImageMapCell::GetLink( int x, int y ) const
25082126 259{
edbd0635 260 wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
01325161
VS
261 if (a)
262 return a->GetLink( x, y );
263 return wxHtmlCell::GetLink( x, y );
25082126
VS
264}
265
266const wxHtmlCell *wxHtmlImageMapCell::Find( int cond, const void *param ) const
267{
04dbb646 268 if (cond == wxHTML_COND_ISIMAGEMAP)
4f9297b0 269 {
01325161
VS
270 if (m_Name == *((wxString*)(param)))
271 return this;
272 }
273 return wxHtmlCell::Find(cond, param);
25082126
VS
274}
275
276
277
278
279
5526e819
VS
280//--------------------------------------------------------------------------------
281// wxHtmlImageCell
282// Image/bitmap
283//--------------------------------------------------------------------------------
284
285class wxHtmlImageCell : public wxHtmlCell
286{
ea5c1679 287public:
bc55e31b 288 wxHtmlImageCell(wxHtmlWindowInterface *windowIface,
d1da8872 289 wxFSFile *input, int w = wxDefaultCoord, int h = wxDefaultCoord,
5a7fa9ed 290 double scale = 1.0, int align = wxHTML_ALIGN_BOTTOM,
ea5c1679 291 const wxString& mapname = wxEmptyString);
d3c7fc99 292 virtual ~wxHtmlImageCell();
36c4ff4d 293 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
285f58ab 294 wxHtmlRenderingInfo& info);
ea5c1679
VS
295 virtual wxHtmlLinkInfo *GetLink(int x = 0, int y = 0) const;
296
297 void SetImage(const wxImage& img);
298#if wxUSE_GIF && wxUSE_TIMER
299 void AdvanceAnimation(wxTimer *timer);
300 virtual void Layout(int w);
301#endif
302
303private:
304 wxBitmap *m_bitmap;
305 int m_bmpW, m_bmpH;
6cc4e6b8 306 bool m_showFrame:1;
bc55e31b 307 wxHtmlWindowInterface *m_windowIface;
ea5c1679
VS
308#if wxUSE_GIF && wxUSE_TIMER
309 wxGIFDecoder *m_gifDecoder;
310 wxTimer *m_gifTimer;
311 int m_physX, m_physY;
312#endif
313 double m_scale;
314 wxHtmlImageMapCell *m_imageMap;
315 wxString m_mapName;
22f3361e
VZ
316
317 DECLARE_NO_COPY_CLASS(wxHtmlImageCell)
5526e819
VS
318};
319
ea5c1679
VS
320#if wxUSE_GIF && wxUSE_TIMER
321class wxGIFTimer : public wxTimer
322{
323 public:
324 wxGIFTimer(wxHtmlImageCell *cell) : m_cell(cell) {}
325 virtual void Notify()
326 {
327 m_cell->AdvanceAnimation(this);
328 }
5526e819 329
ea5c1679
VS
330 private:
331 wxHtmlImageCell *m_cell;
22f3361e
VZ
332
333 DECLARE_NO_COPY_CLASS(wxGIFTimer)
ea5c1679
VS
334};
335#endif
5526e819 336
25082126 337
214bdb93 338//----------------------------------------------------------------------------
5526e819 339// wxHtmlImageCell
214bdb93 340//----------------------------------------------------------------------------
5526e819 341
6cc4e6b8 342
bc55e31b
VS
343wxHtmlImageCell::wxHtmlImageCell(wxHtmlWindowInterface *windowIface,
344 wxFSFile *input,
5a7fa9ed 345 int w, int h, double scale, int align,
ea5c1679 346 const wxString& mapname) : wxHtmlCell()
5526e819 347{
bc55e31b 348 m_windowIface = windowIface;
ea5c1679 349 m_scale = scale;
d1da8872 350 m_showFrame = false;
ea5c1679
VS
351 m_bitmap = NULL;
352 m_bmpW = w;
353 m_bmpH = h;
354 m_imageMap = NULL;
355 m_mapName = mapname;
d1da8872 356 SetCanLiveOnPagebreak(false);
ea5c1679
VS
357#if wxUSE_GIF && wxUSE_TIMER
358 m_gifDecoder = NULL;
359 m_gifTimer = NULL;
d1da8872 360 m_physX = m_physY = wxDefaultCoord;
ea5c1679 361#endif
04dbb646 362
08a15c0d 363 if ( m_bmpW && m_bmpH )
4f9297b0 364 {
08a15c0d 365 if ( input )
ea5c1679 366 {
08a15c0d 367 wxInputStream *s = input->GetStream();
6cc4e6b8 368
08a15c0d 369 if ( s )
ea5c1679 370 {
08a15c0d 371#if wxUSE_GIF && wxUSE_TIMER
a8f84bcd 372 bool readImg = true;
bc55e31b
VS
373 if ( m_windowIface &&
374 (input->GetLocation().Matches(wxT("*.gif")) ||
375 input->GetLocation().Matches(wxT("*.GIF"))) )
6cc4e6b8 376 {
d1da8872 377 m_gifDecoder = new wxGIFDecoder(s, true);
08a15c0d
VZ
378 if ( m_gifDecoder->ReadGIF() == wxGIF_OK )
379 {
380 wxImage img;
381 if ( m_gifDecoder->ConvertToImage(&img) )
382 SetImage(img);
37a1f3f6 383
d1da8872 384 readImg = false;
37a1f3f6 385
08a15c0d
VZ
386 if ( m_gifDecoder->IsAnimation() )
387 {
388 m_gifTimer = new wxGIFTimer(this);
d1da8872 389 m_gifTimer->Start(m_gifDecoder->GetDelay(), true);
08a15c0d
VZ
390 }
391 else
392 {
393 wxDELETE(m_gifDecoder);
394 }
6cc4e6b8
VS
395 }
396 else
397 {
398 wxDELETE(m_gifDecoder);
399 }
ea5c1679 400 }
6cc4e6b8 401
08a15c0d 402 if ( readImg )
5a7fa9ed 403#endif // wxUSE_GIF && wxUSE_TIMER
08a15c0d
VZ
404 {
405 wxImage image(*s, wxBITMAP_TYPE_ANY);
406 if ( image.Ok() )
407 SetImage(image);
408 }
ea5c1679
VS
409 }
410 }
08a15c0d 411 else // input==NULL, use "broken image" bitmap
04dbb646 412 {
d1da8872 413 if ( m_bmpW == wxDefaultCoord && m_bmpH == wxDefaultCoord )
08a15c0d
VZ
414 {
415 m_bmpW = 29;
416 m_bmpH = 31;
417 }
418 else
419 {
d1da8872
WS
420 m_showFrame = true;
421 if ( m_bmpW == wxDefaultCoord ) m_bmpW = 31;
422 if ( m_bmpH == wxDefaultCoord ) m_bmpH = 33;
08a15c0d 423 }
d1da8872 424 m_bitmap =
214bdb93 425 new wxBitmap(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE));
04dbb646 426 }
5526e819 427 }
08a15c0d 428 //else: ignore the 0-sized images used sometimes on the Web pages
ea5c1679
VS
429
430 m_Width = (int)(scale * (double)m_bmpW);
431 m_Height = (int)(scale * (double)m_bmpH);
432
04dbb646 433 switch (align)
4f9297b0 434 {
efba2b89 435 case wxHTML_ALIGN_TOP :
01325161
VS
436 m_Descent = m_Height;
437 break;
efba2b89 438 case wxHTML_ALIGN_CENTER :
01325161
VS
439 m_Descent = m_Height / 2;
440 break;
441 case wxHTML_ALIGN_BOTTOM :
442 default :
443 m_Descent = 0;
444 break;
5526e819 445 }
ea5c1679 446 }
25082126 447
ea5c1679
VS
448void wxHtmlImageCell::SetImage(const wxImage& img)
449{
64c288fa 450#if !defined(__WXMSW__) || wxUSE_WXDIB
ea5c1679
VS
451 if ( img.Ok() )
452 {
453 delete m_bitmap;
454
455 int ww, hh;
456 ww = img.GetWidth();
457 hh = img.GetHeight();
458
d1da8872 459 if ( m_bmpW == wxDefaultCoord )
ea5c1679 460 m_bmpW = ww;
d1da8872 461 if ( m_bmpH == wxDefaultCoord )
ea5c1679
VS
462 m_bmpH = hh;
463
7ba62202
JS
464 // Only scale the bitmap at the rendering stage,
465 // so we don't lose quality twice
466/*
ea5c1679
VS
467 if ((m_bmpW != ww) || (m_bmpH != hh))
468 {
469 wxImage img2 = img.Scale(m_bmpW, m_bmpH);
470 m_bitmap = new wxBitmap(img2);
471 }
472 else
7ba62202 473*/
ea5c1679
VS
474 m_bitmap = new wxBitmap(img);
475 }
64c288fa 476#endif
5526e819
VS
477}
478
ea5c1679
VS
479#if wxUSE_GIF && wxUSE_TIMER
480void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer)
481{
482 wxImage img;
483
d1da8872 484 m_gifDecoder->GoNextFrame(true);
ea5c1679 485
d1da8872 486 if ( m_physX == wxDefaultCoord )
ea5c1679
VS
487 {
488 m_physX = m_physY = 0;
489 for (wxHtmlCell *cell = this; cell; cell = cell->GetParent())
490 {
491 m_physX += cell->GetPosX();
492 m_physY += cell->GetPosY();
493 }
494 }
495
bc55e31b
VS
496 wxWindow *win = m_windowIface->GetHTMLWindow();
497 wxPoint pos =
498 m_windowIface->HTMLCoordsToWindow(this, wxPoint(m_physX, m_physY));
499 wxRect rect(pos, wxSize(m_Width, m_Height));
ea5c1679 500
bc55e31b 501 if ( win->GetClientRect().Intersects(rect) &&
ea5c1679
VS
502 m_gifDecoder->ConvertToImage(&img) )
503 {
64c288fa 504#if !defined(__WXMSW__) || wxUSE_WXDIB
2d963ba2
VS
505 if ( (int)m_gifDecoder->GetWidth() != m_Width ||
506 (int)m_gifDecoder->GetHeight() != m_Height ||
507 m_gifDecoder->GetLeft() != 0 || m_gifDecoder->GetTop() != 0 )
508 {
509 wxBitmap bmp(img);
510 wxMemoryDC dc;
511 dc.SelectObject(*m_bitmap);
80bd0860 512 dc.DrawBitmap(bmp, m_gifDecoder->GetLeft(), m_gifDecoder->GetTop(),
d1da8872 513 true /* use mask */);
2d963ba2
VS
514 }
515 else
bc55e31b 516#endif
2d963ba2 517 SetImage(img);
bc55e31b 518 win->Refresh(img.HasMask(), &rect);
ea5c1679
VS
519 }
520
d1da8872 521 timer->Start(m_gifDecoder->GetDelay(), true);
ea5c1679
VS
522}
523
524void wxHtmlImageCell::Layout(int w)
525{
526 wxHtmlCell::Layout(w);
d1da8872 527 m_physX = m_physY = wxDefaultCoord;
ea5c1679
VS
528}
529
530#endif
531
532wxHtmlImageCell::~wxHtmlImageCell()
533{
534 delete m_bitmap;
535#if wxUSE_GIF && wxUSE_TIMER
536 delete m_gifTimer;
537 delete m_gifDecoder;
538#endif
539}
5526e819
VS
540
541
36c4ff4d 542void wxHtmlImageCell::Draw(wxDC& dc, int x, int y,
2a2e4f4a 543 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 544 wxHtmlRenderingInfo& WXUNUSED(info))
5526e819 545{
6cc4e6b8
VS
546 if ( m_showFrame )
547 {
548 dc.SetBrush(*wxTRANSPARENT_BRUSH);
549 dc.SetPen(*wxBLACK_PEN);
550 dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height);
551 x++, y++;
552 }
553 if ( m_bitmap )
b5c01940 554 {
7ba62202
JS
555 // We add in the scaling from the desired bitmap width
556 // and height, so we only do the scaling once.
557 double imageScaleX = 1.0;
558 double imageScaleY = 1.0;
559 if (m_bmpW != m_bitmap->GetWidth())
560 imageScaleX = (double) m_bmpW / (double) m_bitmap->GetWidth();
561 if (m_bmpH != m_bitmap->GetHeight())
562 imageScaleY = (double) m_bmpH / (double) m_bitmap->GetHeight();
d1da8872 563
b5c01940
VS
564 double us_x, us_y;
565 dc.GetUserScale(&us_x, &us_y);
7ba62202 566 dc.SetUserScale(us_x * m_scale * imageScaleX, us_y * m_scale * imageScaleY);
04dbb646 567
7ba62202 568 dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / (m_scale*imageScaleX)),
d1da8872 569 (int) ((y + m_PosY) / (m_scale*imageScaleY)), true);
b5c01940
VS
570 dc.SetUserScale(us_x, us_y);
571 }
5526e819
VS
572}
573
846914d1 574wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const
25082126 575{
b713f891 576 if (m_mapName.empty())
01325161 577 return wxHtmlCell::GetLink( x, y );
ea5c1679 578 if (!m_imageMap)
4f9297b0 579 {
edbd0635 580 wxHtmlContainerCell *p, *op;
01325161 581 op = p = GetParent();
04dbb646
VZ
582 while (p)
583 {
01325161
VS
584 op = p;
585 p = p->GetParent();
586 }
587 p = op;
5a7fa9ed 588 wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP,
ea5c1679 589 (const void*)(&m_mapName));
04dbb646
VZ
590 if (!cell)
591 {
ea5c1679 592 ((wxString&)m_mapName).Clear();
01325161
VS
593 return wxHtmlCell::GetLink( x, y );
594 }
4f9297b0 595 { // dirty hack, ask Joel why he fills m_ImageMap in this place
01325161 596 // THE problem is that we're in const method and we can't modify m_ImageMap
ea5c1679 597 wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap);
01325161 598 *cx = (wxHtmlImageMapCell*)cell;
25082126 599 }
01325161 600 }
ea5c1679 601 return m_imageMap->GetLink(x, y);
25082126 602}
5526e819
VS
603
604
605
606//--------------------------------------------------------------------------------
607// tag handler
608//--------------------------------------------------------------------------------
609
01325161 610TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
fc7a2a60 611 TAG_HANDLER_CONSTR(IMG) { }
5526e819
VS
612
613 TAG_HANDLER_PROC(tag)
614 {
04dbb646
VZ
615 if (tag.GetName() == wxT("IMG"))
616 {
617 if (tag.HasParam(wxT("SRC")))
618 {
d1da8872 619 int w = wxDefaultCoord, h = wxDefaultCoord;
01325161
VS
620 int al;
621 wxFSFile *str;
0413cec5 622 wxString tmp = tag.GetParam(wxT("SRC"));
01325161 623 wxString mn = wxEmptyString;
5a7fa9ed 624
6cc4e6b8 625 str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp);
5a7fa9ed 626
04dbb646 627 if (tag.HasParam(wxT("WIDTH")))
8bd72d90 628 tag.GetParamAsInt(wxT("WIDTH"), &w);
04dbb646 629 if (tag.HasParam(wxT("HEIGHT")))
8bd72d90 630 tag.GetParamAsInt(wxT("HEIGHT"), &h);
01325161 631 al = wxHTML_ALIGN_BOTTOM;
04dbb646
VZ
632 if (tag.HasParam(wxT("ALIGN")))
633 {
0413cec5 634 wxString alstr = tag.GetParam(wxT("ALIGN"));
01325161 635 alstr.MakeUpper(); // for the case alignment was in ".."
04dbb646 636 if (alstr == wxT("TEXTTOP"))
8bd72d90 637 al = wxHTML_ALIGN_TOP;
04dbb646 638 else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
8bd72d90 639 al = wxHTML_ALIGN_CENTER;
01325161 640 }
04dbb646
VZ
641 if (tag.HasParam(wxT("USEMAP")))
642 {
0413cec5 643 mn = tag.GetParam( wxT("USEMAP") );
04dbb646
VZ
644 if (mn.GetChar(0) == wxT('#'))
645 {
01325161
VS
646 mn = mn.Mid( 1 );
647 }
648 }
6cc4e6b8 649 wxHtmlImageCell *cel = new wxHtmlImageCell(
bc55e31b 650 m_WParser->GetWindowInterface(),
5a7fa9ed
VZ
651 str, w, h,
652 m_WParser->GetPixelScale(),
6cc4e6b8 653 al, mn);
3c115835 654 m_WParser->ApplyStateToCell(cel);
6cc4e6b8
VS
655 cel->SetId(tag.GetParam(wxT("id"))); // may be empty
656 m_WParser->GetContainer()->InsertCell(cel);
04dbb646 657 if (str)
01325161 658 delete str;
01325161
VS
659 }
660 }
04dbb646
VZ
661 if (tag.GetName() == wxT("MAP"))
662 {
01325161
VS
663 m_WParser->CloseContainer();
664 m_WParser->OpenContainer();
04dbb646
VZ
665 if (tag.HasParam(wxT("NAME")))
666 {
0413cec5 667 wxString tmp = tag.GetParam(wxT("NAME"));
01325161
VS
668 wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
669 m_WParser->GetContainer()->InsertCell( cel );
670 }
671 ParseInner( tag );
672 m_WParser->CloseContainer();
673 m_WParser->OpenContainer();
674 }
04dbb646
VZ
675 if (tag.GetName() == wxT("AREA"))
676 {
677 if (tag.HasParam(wxT("SHAPE")))
678 {
0413cec5 679 wxString tmp = tag.GetParam(wxT("SHAPE"));
edbd0635 680 wxString coords = wxEmptyString;
01325161
VS
681 tmp.MakeUpper();
682 wxHtmlImageMapAreaCell *cel = NULL;
04dbb646
VZ
683 if (tag.HasParam(wxT("COORDS")))
684 {
0413cec5 685 coords = tag.GetParam(wxT("COORDS"));
01325161 686 }
04dbb646
VZ
687 if (tmp == wxT("POLY"))
688 {
4f9297b0 689 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() );
04dbb646
VZ
690 }
691 else if (tmp == wxT("CIRCLE"))
692 {
4f9297b0 693 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords, m_WParser->GetPixelScale() );
04dbb646
VZ
694 }
695 else if (tmp == wxT("RECT"))
696 {
4f9297b0 697 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() );
01325161 698 }
04dbb646
VZ
699 if (cel != NULL && tag.HasParam(wxT("HREF")))
700 {
17a1ebd1
VZ
701 wxString target;
702 if (tag.HasParam(wxT("TARGET")))
703 target = tag.GetParam(wxT("TARGET"));
704 cel->SetLink(wxHtmlLinkInfo(tag.GetParam(wxT("HREF")), target));
01325161 705 }
17a1ebd1
VZ
706 if (cel != NULL)
707 m_WParser->GetContainer()->InsertCell( cel );
01325161
VS
708 }
709 }
5526e819 710
d1da8872 711 return false;
5526e819
VS
712 }
713
01325161 714TAG_HANDLER_END(IMG)
5526e819
VS
715
716
717
718TAGS_MODULE_BEGIN(Image)
719
720 TAGS_MODULE_ADD(IMG)
721
722TAGS_MODULE_END(Image)
723
724
3364ab79 725#endif