]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_image.cpp
suppress harmless warning about possibly uninitialized variable in OpenLogFile()...
[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
b4f4d3dd 18#ifndef WX_PRECOMP
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
c0c133e1 71 wxDECLARE_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 248
c0c133e1 249 wxDECLARE_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;
72045d57 312 size_t m_nCurrFrame;
ea5c1679
VS
313#endif
314 double m_scale;
315 wxHtmlImageMapCell *m_imageMap;
316 wxString m_mapName;
22f3361e 317
c0c133e1 318 wxDECLARE_NO_COPY_CLASS(wxHtmlImageCell);
5526e819
VS
319};
320
ea5c1679
VS
321#if wxUSE_GIF && wxUSE_TIMER
322class wxGIFTimer : public wxTimer
323{
324 public:
325 wxGIFTimer(wxHtmlImageCell *cell) : m_cell(cell) {}
326 virtual void Notify()
327 {
328 m_cell->AdvanceAnimation(this);
329 }
5526e819 330
ea5c1679
VS
331 private:
332 wxHtmlImageCell *m_cell;
22f3361e 333
c0c133e1 334 wxDECLARE_NO_COPY_CLASS(wxGIFTimer);
ea5c1679
VS
335};
336#endif
5526e819 337
25082126 338
214bdb93 339//----------------------------------------------------------------------------
5526e819 340// wxHtmlImageCell
214bdb93 341//----------------------------------------------------------------------------
5526e819 342
6cc4e6b8 343
bc55e31b
VS
344wxHtmlImageCell::wxHtmlImageCell(wxHtmlWindowInterface *windowIface,
345 wxFSFile *input,
5a7fa9ed 346 int w, int h, double scale, int align,
ea5c1679 347 const wxString& mapname) : wxHtmlCell()
5526e819 348{
bc55e31b 349 m_windowIface = windowIface;
ea5c1679 350 m_scale = scale;
d1da8872 351 m_showFrame = false;
ea5c1679
VS
352 m_bitmap = NULL;
353 m_bmpW = w;
354 m_bmpH = h;
355 m_imageMap = NULL;
356 m_mapName = mapname;
d1da8872 357 SetCanLiveOnPagebreak(false);
ea5c1679
VS
358#if wxUSE_GIF && wxUSE_TIMER
359 m_gifDecoder = NULL;
360 m_gifTimer = NULL;
d1da8872 361 m_physX = m_physY = wxDefaultCoord;
72045d57 362 m_nCurrFrame = 0;
ea5c1679 363#endif
04dbb646 364
08a15c0d 365 if ( m_bmpW && m_bmpH )
4f9297b0 366 {
08a15c0d 367 if ( input )
ea5c1679 368 {
08a15c0d 369 wxInputStream *s = input->GetStream();
6cc4e6b8 370
08a15c0d 371 if ( s )
ea5c1679 372 {
08a15c0d 373#if wxUSE_GIF && wxUSE_TIMER
a8f84bcd 374 bool readImg = true;
bc55e31b
VS
375 if ( m_windowIface &&
376 (input->GetLocation().Matches(wxT("*.gif")) ||
377 input->GetLocation().Matches(wxT("*.GIF"))) )
6cc4e6b8 378 {
72045d57
VZ
379 m_gifDecoder = new wxGIFDecoder();
380 if ( m_gifDecoder->LoadGIF(*s) == wxGIF_OK )
08a15c0d
VZ
381 {
382 wxImage img;
72045d57 383 if ( m_gifDecoder->ConvertToImage(0, &img) )
08a15c0d 384 SetImage(img);
37a1f3f6 385
d1da8872 386 readImg = false;
37a1f3f6 387
08a15c0d
VZ
388 if ( m_gifDecoder->IsAnimation() )
389 {
390 m_gifTimer = new wxGIFTimer(this);
f89940e6
VS
391 long delay = m_gifDecoder->GetDelay(0);
392 if ( delay == 0 )
393 delay = 1;
394 m_gifTimer->Start(delay, true);
08a15c0d
VZ
395 }
396 else
397 {
398 wxDELETE(m_gifDecoder);
399 }
6cc4e6b8
VS
400 }
401 else
402 {
403 wxDELETE(m_gifDecoder);
404 }
ea5c1679 405 }
6cc4e6b8 406
08a15c0d 407 if ( readImg )
5a7fa9ed 408#endif // wxUSE_GIF && wxUSE_TIMER
08a15c0d
VZ
409 {
410 wxImage image(*s, wxBITMAP_TYPE_ANY);
411 if ( image.Ok() )
412 SetImage(image);
413 }
ea5c1679
VS
414 }
415 }
08a15c0d 416 else // input==NULL, use "broken image" bitmap
04dbb646 417 {
d1da8872 418 if ( m_bmpW == wxDefaultCoord && m_bmpH == wxDefaultCoord )
08a15c0d
VZ
419 {
420 m_bmpW = 29;
421 m_bmpH = 31;
422 }
423 else
424 {
d1da8872
WS
425 m_showFrame = true;
426 if ( m_bmpW == wxDefaultCoord ) m_bmpW = 31;
427 if ( m_bmpH == wxDefaultCoord ) m_bmpH = 33;
08a15c0d 428 }
d1da8872 429 m_bitmap =
214bdb93 430 new wxBitmap(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE));
04dbb646 431 }
5526e819 432 }
08a15c0d 433 //else: ignore the 0-sized images used sometimes on the Web pages
ea5c1679
VS
434
435 m_Width = (int)(scale * (double)m_bmpW);
436 m_Height = (int)(scale * (double)m_bmpH);
437
04dbb646 438 switch (align)
4f9297b0 439 {
efba2b89 440 case wxHTML_ALIGN_TOP :
01325161
VS
441 m_Descent = m_Height;
442 break;
efba2b89 443 case wxHTML_ALIGN_CENTER :
01325161
VS
444 m_Descent = m_Height / 2;
445 break;
446 case wxHTML_ALIGN_BOTTOM :
447 default :
448 m_Descent = 0;
449 break;
5526e819 450 }
ea5c1679 451 }
25082126 452
ea5c1679
VS
453void wxHtmlImageCell::SetImage(const wxImage& img)
454{
64c288fa 455#if !defined(__WXMSW__) || wxUSE_WXDIB
ea5c1679
VS
456 if ( img.Ok() )
457 {
458 delete m_bitmap;
459
460 int ww, hh;
461 ww = img.GetWidth();
462 hh = img.GetHeight();
463
d1da8872 464 if ( m_bmpW == wxDefaultCoord )
ea5c1679 465 m_bmpW = ww;
d1da8872 466 if ( m_bmpH == wxDefaultCoord )
ea5c1679
VS
467 m_bmpH = hh;
468
7ba62202
JS
469 // Only scale the bitmap at the rendering stage,
470 // so we don't lose quality twice
471/*
ea5c1679
VS
472 if ((m_bmpW != ww) || (m_bmpH != hh))
473 {
474 wxImage img2 = img.Scale(m_bmpW, m_bmpH);
475 m_bitmap = new wxBitmap(img2);
476 }
477 else
7ba62202 478*/
ea5c1679
VS
479 m_bitmap = new wxBitmap(img);
480 }
64c288fa 481#endif
5526e819
VS
482}
483
ea5c1679
VS
484#if wxUSE_GIF && wxUSE_TIMER
485void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer)
486{
487 wxImage img;
488
72045d57
VZ
489 // advance current frame
490 m_nCurrFrame++;
491 if (m_nCurrFrame == m_gifDecoder->GetFrameCount())
492 m_nCurrFrame = 0;
ea5c1679 493
d1da8872 494 if ( m_physX == wxDefaultCoord )
ea5c1679
VS
495 {
496 m_physX = m_physY = 0;
497 for (wxHtmlCell *cell = this; cell; cell = cell->GetParent())
498 {
499 m_physX += cell->GetPosX();
500 m_physY += cell->GetPosY();
501 }
502 }
503
bc55e31b
VS
504 wxWindow *win = m_windowIface->GetHTMLWindow();
505 wxPoint pos =
506 m_windowIface->HTMLCoordsToWindow(this, wxPoint(m_physX, m_physY));
507 wxRect rect(pos, wxSize(m_Width, m_Height));
ea5c1679 508
bc55e31b 509 if ( win->GetClientRect().Intersects(rect) &&
72045d57 510 m_gifDecoder->ConvertToImage(m_nCurrFrame, &img) )
ea5c1679 511 {
64c288fa 512#if !defined(__WXMSW__) || wxUSE_WXDIB
72045d57
VZ
513 if ( m_gifDecoder->GetFrameSize(m_nCurrFrame) != wxSize(m_Width, m_Height) ||
514 m_gifDecoder->GetFramePosition(m_nCurrFrame) != wxPoint(0, 0) )
2d963ba2
VS
515 {
516 wxBitmap bmp(img);
517 wxMemoryDC dc;
518 dc.SelectObject(*m_bitmap);
72045d57 519 dc.DrawBitmap(bmp, m_gifDecoder->GetFramePosition(m_nCurrFrame),
d1da8872 520 true /* use mask */);
2d963ba2
VS
521 }
522 else
bc55e31b 523#endif
2d963ba2 524 SetImage(img);
bc55e31b 525 win->Refresh(img.HasMask(), &rect);
ea5c1679
VS
526 }
527
f89940e6
VS
528 long delay = m_gifDecoder->GetDelay(m_nCurrFrame);
529 if ( delay == 0 )
530 delay = 1;
531 timer->Start(delay, true);
ea5c1679
VS
532}
533
534void wxHtmlImageCell::Layout(int w)
535{
536 wxHtmlCell::Layout(w);
d1da8872 537 m_physX = m_physY = wxDefaultCoord;
ea5c1679
VS
538}
539
540#endif
541
542wxHtmlImageCell::~wxHtmlImageCell()
543{
544 delete m_bitmap;
545#if wxUSE_GIF && wxUSE_TIMER
546 delete m_gifTimer;
547 delete m_gifDecoder;
548#endif
549}
5526e819
VS
550
551
36c4ff4d 552void wxHtmlImageCell::Draw(wxDC& dc, int x, int y,
2a2e4f4a 553 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 554 wxHtmlRenderingInfo& WXUNUSED(info))
5526e819 555{
6cc4e6b8
VS
556 if ( m_showFrame )
557 {
558 dc.SetBrush(*wxTRANSPARENT_BRUSH);
559 dc.SetPen(*wxBLACK_PEN);
560 dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height);
561 x++, y++;
562 }
563 if ( m_bitmap )
b5c01940 564 {
7ba62202
JS
565 // We add in the scaling from the desired bitmap width
566 // and height, so we only do the scaling once.
567 double imageScaleX = 1.0;
568 double imageScaleY = 1.0;
569 if (m_bmpW != m_bitmap->GetWidth())
570 imageScaleX = (double) m_bmpW / (double) m_bitmap->GetWidth();
571 if (m_bmpH != m_bitmap->GetHeight())
572 imageScaleY = (double) m_bmpH / (double) m_bitmap->GetHeight();
d1da8872 573
b5c01940
VS
574 double us_x, us_y;
575 dc.GetUserScale(&us_x, &us_y);
7ba62202 576 dc.SetUserScale(us_x * m_scale * imageScaleX, us_y * m_scale * imageScaleY);
04dbb646 577
7ba62202 578 dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / (m_scale*imageScaleX)),
d1da8872 579 (int) ((y + m_PosY) / (m_scale*imageScaleY)), true);
b5c01940
VS
580 dc.SetUserScale(us_x, us_y);
581 }
5526e819
VS
582}
583
846914d1 584wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const
25082126 585{
b713f891 586 if (m_mapName.empty())
01325161 587 return wxHtmlCell::GetLink( x, y );
ea5c1679 588 if (!m_imageMap)
4f9297b0 589 {
edbd0635 590 wxHtmlContainerCell *p, *op;
01325161 591 op = p = GetParent();
04dbb646
VZ
592 while (p)
593 {
01325161
VS
594 op = p;
595 p = p->GetParent();
596 }
597 p = op;
5a7fa9ed 598 wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP,
ea5c1679 599 (const void*)(&m_mapName));
04dbb646
VZ
600 if (!cell)
601 {
ea5c1679 602 ((wxString&)m_mapName).Clear();
01325161
VS
603 return wxHtmlCell::GetLink( x, y );
604 }
4f9297b0 605 { // dirty hack, ask Joel why he fills m_ImageMap in this place
01325161 606 // THE problem is that we're in const method and we can't modify m_ImageMap
ea5c1679 607 wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap);
01325161 608 *cx = (wxHtmlImageMapCell*)cell;
25082126 609 }
01325161 610 }
ea5c1679 611 return m_imageMap->GetLink(x, y);
25082126 612}
5526e819
VS
613
614
615
616//--------------------------------------------------------------------------------
617// tag handler
618//--------------------------------------------------------------------------------
619
01325161 620TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
fc7a2a60 621 TAG_HANDLER_CONSTR(IMG) { }
5526e819
VS
622
623 TAG_HANDLER_PROC(tag)
624 {
04dbb646
VZ
625 if (tag.GetName() == wxT("IMG"))
626 {
627 if (tag.HasParam(wxT("SRC")))
628 {
d1da8872 629 int w = wxDefaultCoord, h = wxDefaultCoord;
01325161
VS
630 int al;
631 wxFSFile *str;
0413cec5 632 wxString tmp = tag.GetParam(wxT("SRC"));
01325161 633 wxString mn = wxEmptyString;
5a7fa9ed 634
6cc4e6b8 635 str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp);
5a7fa9ed 636
04dbb646 637 if (tag.HasParam(wxT("WIDTH")))
8bd72d90 638 tag.GetParamAsInt(wxT("WIDTH"), &w);
04dbb646 639 if (tag.HasParam(wxT("HEIGHT")))
8bd72d90 640 tag.GetParamAsInt(wxT("HEIGHT"), &h);
01325161 641 al = wxHTML_ALIGN_BOTTOM;
04dbb646
VZ
642 if (tag.HasParam(wxT("ALIGN")))
643 {
0413cec5 644 wxString alstr = tag.GetParam(wxT("ALIGN"));
01325161 645 alstr.MakeUpper(); // for the case alignment was in ".."
04dbb646 646 if (alstr == wxT("TEXTTOP"))
8bd72d90 647 al = wxHTML_ALIGN_TOP;
04dbb646 648 else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
8bd72d90 649 al = wxHTML_ALIGN_CENTER;
01325161 650 }
04dbb646
VZ
651 if (tag.HasParam(wxT("USEMAP")))
652 {
0413cec5 653 mn = tag.GetParam( wxT("USEMAP") );
04dbb646
VZ
654 if (mn.GetChar(0) == wxT('#'))
655 {
01325161
VS
656 mn = mn.Mid( 1 );
657 }
658 }
6cc4e6b8 659 wxHtmlImageCell *cel = new wxHtmlImageCell(
bc55e31b 660 m_WParser->GetWindowInterface(),
5a7fa9ed
VZ
661 str, w, h,
662 m_WParser->GetPixelScale(),
6cc4e6b8 663 al, mn);
3c115835 664 m_WParser->ApplyStateToCell(cel);
6cc4e6b8
VS
665 cel->SetId(tag.GetParam(wxT("id"))); // may be empty
666 m_WParser->GetContainer()->InsertCell(cel);
04dbb646 667 if (str)
01325161 668 delete str;
01325161
VS
669 }
670 }
04dbb646
VZ
671 if (tag.GetName() == wxT("MAP"))
672 {
01325161
VS
673 m_WParser->CloseContainer();
674 m_WParser->OpenContainer();
04dbb646
VZ
675 if (tag.HasParam(wxT("NAME")))
676 {
0413cec5 677 wxString tmp = tag.GetParam(wxT("NAME"));
01325161
VS
678 wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
679 m_WParser->GetContainer()->InsertCell( cel );
680 }
681 ParseInner( tag );
682 m_WParser->CloseContainer();
683 m_WParser->OpenContainer();
684 }
04dbb646
VZ
685 if (tag.GetName() == wxT("AREA"))
686 {
687 if (tag.HasParam(wxT("SHAPE")))
688 {
0413cec5 689 wxString tmp = tag.GetParam(wxT("SHAPE"));
edbd0635 690 wxString coords = wxEmptyString;
01325161
VS
691 tmp.MakeUpper();
692 wxHtmlImageMapAreaCell *cel = NULL;
04dbb646
VZ
693 if (tag.HasParam(wxT("COORDS")))
694 {
0413cec5 695 coords = tag.GetParam(wxT("COORDS"));
01325161 696 }
04dbb646
VZ
697 if (tmp == wxT("POLY"))
698 {
4f9297b0 699 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() );
04dbb646
VZ
700 }
701 else if (tmp == wxT("CIRCLE"))
702 {
4f9297b0 703 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords, m_WParser->GetPixelScale() );
04dbb646
VZ
704 }
705 else if (tmp == wxT("RECT"))
706 {
4f9297b0 707 cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() );
01325161 708 }
04dbb646
VZ
709 if (cel != NULL && tag.HasParam(wxT("HREF")))
710 {
17a1ebd1
VZ
711 wxString target;
712 if (tag.HasParam(wxT("TARGET")))
713 target = tag.GetParam(wxT("TARGET"));
714 cel->SetLink(wxHtmlLinkInfo(tag.GetParam(wxT("HREF")), target));
01325161 715 }
17a1ebd1
VZ
716 if (cel != NULL)
717 m_WParser->GetContainer()->InsertCell( cel );
01325161
VS
718 }
719 }
5526e819 720
d1da8872 721 return false;
5526e819
VS
722 }
723
01325161 724TAG_HANDLER_END(IMG)
5526e819
VS
725
726
727
728TAGS_MODULE_BEGIN(Image)
729
730 TAGS_MODULE_ADD(IMG)
731
732TAGS_MODULE_END(Image)
733
734
3364ab79 735#endif