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