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