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