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