]>
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 | ||
25082126 | 10 | #include "wx/wxprec.h" |
3364ab79 | 11 | |
5526e819 | 12 | #include "wx/defs.h" |
f6bcfd97 | 13 | #if wxUSE_HTML && wxUSE_STREAMS |
5526e819 | 14 | |
2b5f62a0 | 15 | #ifdef __BORLANDC__ |
3364ab79 RS |
16 | #pragma hdrstop |
17 | #endif | |
18 | ||
19 | #ifndef WXPRECOMP | |
04dbb646 | 20 | #include "wx/dc.h" |
ea5c1679 VS |
21 | #include "wx/scrolwin.h" |
22 | #include "wx/timer.h" | |
2d963ba2 | 23 | #include "wx/dcmemory.h" |
3364ab79 RS |
24 | #endif |
25 | ||
69941f05 VS |
26 | #include "wx/html/forcelnk.h" |
27 | #include "wx/html/m_templ.h" | |
04db5c3f | 28 | #include "wx/html/htmlwin.h" |
5526e819 | 29 | |
25082126 | 30 | #include "wx/image.h" |
ea5c1679 | 31 | #include "wx/gifdecod.h" |
25082126 | 32 | #include "wx/dynarray.h" |
311d5aa3 | 33 | #include "wx/log.h" |
214bdb93 | 34 | #include "wx/artprov.h" |
b713f891 | 35 | #include "wx/math.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 | ||
72 | DECLARE_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 VZ |
249 | |
250 | DECLARE_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 VS |
288 | public: |
289 | wxHtmlImageCell(wxWindow *window, | |
d1da8872 | 290 | wxFSFile *input, int w = wxDefaultCoord, int h = wxDefaultCoord, |
5a7fa9ed | 291 | double scale = 1.0, int align = wxHTML_ALIGN_BOTTOM, |
ea5c1679 VS |
292 | const wxString& mapname = wxEmptyString); |
293 | ~wxHtmlImageCell(); | |
36c4ff4d | 294 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
285f58ab | 295 | wxHtmlRenderingInfo& info); |
ea5c1679 VS |
296 | virtual wxHtmlLinkInfo *GetLink(int x = 0, int y = 0) const; |
297 | ||
298 | void SetImage(const wxImage& img); | |
299 | #if wxUSE_GIF && wxUSE_TIMER | |
300 | void AdvanceAnimation(wxTimer *timer); | |
301 | virtual void Layout(int w); | |
302 | #endif | |
303 | ||
304 | private: | |
305 | wxBitmap *m_bitmap; | |
306 | int m_bmpW, m_bmpH; | |
6cc4e6b8 | 307 | bool m_showFrame:1; |
ea5c1679 VS |
308 | wxScrolledWindow *m_window; |
309 | #if wxUSE_GIF && wxUSE_TIMER | |
310 | wxGIFDecoder *m_gifDecoder; | |
311 | wxTimer *m_gifTimer; | |
312 | int m_physX, m_physY; | |
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 | |
5a7fa9ed VZ |
344 | wxHtmlImageCell::wxHtmlImageCell(wxWindow *window, wxFSFile *input, |
345 | int w, int h, double scale, int align, | |
ea5c1679 | 346 | const wxString& mapname) : wxHtmlCell() |
5526e819 | 347 | { |
a4e2b276 | 348 | m_window = window ? wxStaticCast(window, wxScrolledWindow) : NULL; |
ea5c1679 | 349 | m_scale = scale; |
d1da8872 | 350 | m_showFrame = false; |
ea5c1679 VS |
351 | m_bitmap = NULL; |
352 | m_bmpW = w; | |
353 | m_bmpH = h; | |
354 | m_imageMap = NULL; | |
355 | m_mapName = mapname; | |
d1da8872 | 356 | SetCanLiveOnPagebreak(false); |
ea5c1679 VS |
357 | #if wxUSE_GIF && wxUSE_TIMER |
358 | m_gifDecoder = NULL; | |
359 | m_gifTimer = NULL; | |
d1da8872 | 360 | m_physX = m_physY = wxDefaultCoord; |
ea5c1679 | 361 | #endif |
04dbb646 | 362 | |
08a15c0d | 363 | if ( m_bmpW && m_bmpH ) |
4f9297b0 | 364 | { |
08a15c0d | 365 | if ( input ) |
ea5c1679 | 366 | { |
08a15c0d | 367 | wxInputStream *s = input->GetStream(); |
6cc4e6b8 | 368 | |
08a15c0d | 369 | if ( s ) |
ea5c1679 | 370 | { |
08a15c0d | 371 | #if wxUSE_GIF && wxUSE_TIMER |
a8f84bcd | 372 | bool readImg = true; |
08a15c0d VZ |
373 | if ( (input->GetLocation().Matches(wxT("*.gif")) || |
374 | input->GetLocation().Matches(wxT("*.GIF"))) && m_window ) | |
6cc4e6b8 | 375 | { |
d1da8872 | 376 | m_gifDecoder = new wxGIFDecoder(s, true); |
08a15c0d VZ |
377 | if ( m_gifDecoder->ReadGIF() == wxGIF_OK ) |
378 | { | |
379 | wxImage img; | |
380 | if ( m_gifDecoder->ConvertToImage(&img) ) | |
381 | SetImage(img); | |
37a1f3f6 | 382 | |
d1da8872 | 383 | readImg = false; |
37a1f3f6 | 384 | |
08a15c0d VZ |
385 | if ( m_gifDecoder->IsAnimation() ) |
386 | { | |
387 | m_gifTimer = new wxGIFTimer(this); | |
d1da8872 | 388 | m_gifTimer->Start(m_gifDecoder->GetDelay(), true); |
08a15c0d VZ |
389 | } |
390 | else | |
391 | { | |
392 | wxDELETE(m_gifDecoder); | |
393 | } | |
6cc4e6b8 VS |
394 | } |
395 | else | |
396 | { | |
397 | wxDELETE(m_gifDecoder); | |
398 | } | |
ea5c1679 | 399 | } |
6cc4e6b8 | 400 | |
08a15c0d | 401 | if ( readImg ) |
5a7fa9ed | 402 | #endif // wxUSE_GIF && wxUSE_TIMER |
08a15c0d VZ |
403 | { |
404 | wxImage image(*s, wxBITMAP_TYPE_ANY); | |
405 | if ( image.Ok() ) | |
406 | SetImage(image); | |
407 | } | |
ea5c1679 VS |
408 | } |
409 | } | |
08a15c0d | 410 | else // input==NULL, use "broken image" bitmap |
04dbb646 | 411 | { |
d1da8872 | 412 | if ( m_bmpW == wxDefaultCoord && m_bmpH == wxDefaultCoord ) |
08a15c0d VZ |
413 | { |
414 | m_bmpW = 29; | |
415 | m_bmpH = 31; | |
416 | } | |
417 | else | |
418 | { | |
d1da8872 WS |
419 | m_showFrame = true; |
420 | if ( m_bmpW == wxDefaultCoord ) m_bmpW = 31; | |
421 | if ( m_bmpH == wxDefaultCoord ) m_bmpH = 33; | |
08a15c0d | 422 | } |
d1da8872 | 423 | m_bitmap = |
214bdb93 | 424 | new wxBitmap(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE)); |
04dbb646 | 425 | } |
5526e819 | 426 | } |
08a15c0d | 427 | //else: ignore the 0-sized images used sometimes on the Web pages |
ea5c1679 VS |
428 | |
429 | m_Width = (int)(scale * (double)m_bmpW); | |
430 | m_Height = (int)(scale * (double)m_bmpH); | |
431 | ||
04dbb646 | 432 | switch (align) |
4f9297b0 | 433 | { |
efba2b89 | 434 | case wxHTML_ALIGN_TOP : |
01325161 VS |
435 | m_Descent = m_Height; |
436 | break; | |
efba2b89 | 437 | case wxHTML_ALIGN_CENTER : |
01325161 VS |
438 | m_Descent = m_Height / 2; |
439 | break; | |
440 | case wxHTML_ALIGN_BOTTOM : | |
441 | default : | |
442 | m_Descent = 0; | |
443 | break; | |
5526e819 | 444 | } |
ea5c1679 | 445 | } |
25082126 | 446 | |
ea5c1679 VS |
447 | void wxHtmlImageCell::SetImage(const wxImage& img) |
448 | { | |
449 | if ( img.Ok() ) | |
450 | { | |
451 | delete m_bitmap; | |
452 | ||
453 | int ww, hh; | |
454 | ww = img.GetWidth(); | |
455 | hh = img.GetHeight(); | |
456 | ||
d1da8872 | 457 | if ( m_bmpW == wxDefaultCoord ) |
ea5c1679 | 458 | m_bmpW = ww; |
d1da8872 | 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 | } | |
5526e819 VS |
474 | } |
475 | ||
ea5c1679 VS |
476 | #if wxUSE_GIF && wxUSE_TIMER |
477 | void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer) | |
478 | { | |
479 | wxImage img; | |
480 | ||
d1da8872 | 481 | m_gifDecoder->GoNextFrame(true); |
ea5c1679 | 482 | |
d1da8872 | 483 | if ( m_physX == wxDefaultCoord ) |
ea5c1679 VS |
484 | { |
485 | m_physX = m_physY = 0; | |
486 | for (wxHtmlCell *cell = this; cell; cell = cell->GetParent()) | |
487 | { | |
488 | m_physX += cell->GetPosX(); | |
489 | m_physY += cell->GetPosY(); | |
490 | } | |
491 | } | |
492 | ||
493 | int x, y; | |
494 | m_window->CalcScrolledPosition(m_physX, m_physY, &x, &y); | |
495 | wxRect rect(x, y, m_Width, m_Height); | |
496 | ||
5a7fa9ed | 497 | if ( m_window->GetClientRect().Intersects(rect) && |
ea5c1679 VS |
498 | m_gifDecoder->ConvertToImage(&img) ) |
499 | { | |
2d963ba2 VS |
500 | if ( (int)m_gifDecoder->GetWidth() != m_Width || |
501 | (int)m_gifDecoder->GetHeight() != m_Height || | |
502 | m_gifDecoder->GetLeft() != 0 || m_gifDecoder->GetTop() != 0 ) | |
503 | { | |
504 | wxBitmap bmp(img); | |
505 | wxMemoryDC dc; | |
506 | dc.SelectObject(*m_bitmap); | |
80bd0860 | 507 | dc.DrawBitmap(bmp, m_gifDecoder->GetLeft(), m_gifDecoder->GetTop(), |
d1da8872 | 508 | true /* use mask */); |
2d963ba2 VS |
509 | } |
510 | else | |
511 | SetImage(img); | |
ea5c1679 VS |
512 | m_window->Refresh(img.HasMask(), &rect); |
513 | } | |
514 | ||
d1da8872 | 515 | timer->Start(m_gifDecoder->GetDelay(), true); |
ea5c1679 VS |
516 | } |
517 | ||
518 | void wxHtmlImageCell::Layout(int w) | |
519 | { | |
520 | wxHtmlCell::Layout(w); | |
d1da8872 | 521 | m_physX = m_physY = wxDefaultCoord; |
ea5c1679 VS |
522 | } |
523 | ||
524 | #endif | |
525 | ||
526 | wxHtmlImageCell::~wxHtmlImageCell() | |
527 | { | |
528 | delete m_bitmap; | |
529 | #if wxUSE_GIF && wxUSE_TIMER | |
530 | delete m_gifTimer; | |
531 | delete m_gifDecoder; | |
532 | #endif | |
533 | } | |
5526e819 VS |
534 | |
535 | ||
36c4ff4d | 536 | void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, |
2a2e4f4a | 537 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), |
285f58ab | 538 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 539 | { |
6cc4e6b8 VS |
540 | if ( m_showFrame ) |
541 | { | |
542 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
543 | dc.SetPen(*wxBLACK_PEN); | |
544 | dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height); | |
545 | x++, y++; | |
546 | } | |
547 | if ( m_bitmap ) | |
b5c01940 | 548 | { |
7ba62202 JS |
549 | // We add in the scaling from the desired bitmap width |
550 | // and height, so we only do the scaling once. | |
551 | double imageScaleX = 1.0; | |
552 | double imageScaleY = 1.0; | |
553 | if (m_bmpW != m_bitmap->GetWidth()) | |
554 | imageScaleX = (double) m_bmpW / (double) m_bitmap->GetWidth(); | |
555 | if (m_bmpH != m_bitmap->GetHeight()) | |
556 | imageScaleY = (double) m_bmpH / (double) m_bitmap->GetHeight(); | |
d1da8872 | 557 | |
b5c01940 VS |
558 | double us_x, us_y; |
559 | dc.GetUserScale(&us_x, &us_y); | |
7ba62202 | 560 | dc.SetUserScale(us_x * m_scale * imageScaleX, us_y * m_scale * imageScaleY); |
04dbb646 | 561 | |
7ba62202 | 562 | dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / (m_scale*imageScaleX)), |
d1da8872 | 563 | (int) ((y + m_PosY) / (m_scale*imageScaleY)), true); |
b5c01940 VS |
564 | dc.SetUserScale(us_x, us_y); |
565 | } | |
5526e819 VS |
566 | } |
567 | ||
846914d1 | 568 | wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const |
25082126 | 569 | { |
b713f891 | 570 | if (m_mapName.empty()) |
01325161 | 571 | return wxHtmlCell::GetLink( x, y ); |
ea5c1679 | 572 | if (!m_imageMap) |
4f9297b0 | 573 | { |
edbd0635 | 574 | wxHtmlContainerCell *p, *op; |
01325161 | 575 | op = p = GetParent(); |
04dbb646 VZ |
576 | while (p) |
577 | { | |
01325161 VS |
578 | op = p; |
579 | p = p->GetParent(); | |
580 | } | |
581 | p = op; | |
5a7fa9ed | 582 | wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP, |
ea5c1679 | 583 | (const void*)(&m_mapName)); |
04dbb646 VZ |
584 | if (!cell) |
585 | { | |
ea5c1679 | 586 | ((wxString&)m_mapName).Clear(); |
01325161 VS |
587 | return wxHtmlCell::GetLink( x, y ); |
588 | } | |
4f9297b0 | 589 | { // dirty hack, ask Joel why he fills m_ImageMap in this place |
01325161 | 590 | // THE problem is that we're in const method and we can't modify m_ImageMap |
ea5c1679 | 591 | wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap); |
01325161 | 592 | *cx = (wxHtmlImageMapCell*)cell; |
25082126 | 593 | } |
01325161 | 594 | } |
ea5c1679 | 595 | return m_imageMap->GetLink(x, y); |
25082126 | 596 | } |
5526e819 VS |
597 | |
598 | ||
599 | ||
600 | //-------------------------------------------------------------------------------- | |
601 | // tag handler | |
602 | //-------------------------------------------------------------------------------- | |
603 | ||
01325161 | 604 | TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA") |
fc7a2a60 | 605 | TAG_HANDLER_CONSTR(IMG) { } |
5526e819 VS |
606 | |
607 | TAG_HANDLER_PROC(tag) | |
608 | { | |
04dbb646 VZ |
609 | if (tag.GetName() == wxT("IMG")) |
610 | { | |
611 | if (tag.HasParam(wxT("SRC"))) | |
612 | { | |
d1da8872 | 613 | int w = wxDefaultCoord, h = wxDefaultCoord; |
01325161 VS |
614 | int al; |
615 | wxFSFile *str; | |
0413cec5 | 616 | wxString tmp = tag.GetParam(wxT("SRC")); |
01325161 | 617 | wxString mn = wxEmptyString; |
5a7fa9ed | 618 | |
6cc4e6b8 | 619 | str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp); |
5a7fa9ed | 620 | |
04dbb646 | 621 | if (tag.HasParam(wxT("WIDTH"))) |
8bd72d90 | 622 | tag.GetParamAsInt(wxT("WIDTH"), &w); |
04dbb646 | 623 | if (tag.HasParam(wxT("HEIGHT"))) |
8bd72d90 | 624 | tag.GetParamAsInt(wxT("HEIGHT"), &h); |
01325161 | 625 | al = wxHTML_ALIGN_BOTTOM; |
04dbb646 VZ |
626 | if (tag.HasParam(wxT("ALIGN"))) |
627 | { | |
0413cec5 | 628 | wxString alstr = tag.GetParam(wxT("ALIGN")); |
01325161 | 629 | alstr.MakeUpper(); // for the case alignment was in ".." |
04dbb646 | 630 | if (alstr == wxT("TEXTTOP")) |
8bd72d90 | 631 | al = wxHTML_ALIGN_TOP; |
04dbb646 | 632 | else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER"))) |
8bd72d90 | 633 | al = wxHTML_ALIGN_CENTER; |
01325161 | 634 | } |
04dbb646 VZ |
635 | if (tag.HasParam(wxT("USEMAP"))) |
636 | { | |
0413cec5 | 637 | mn = tag.GetParam( wxT("USEMAP") ); |
04dbb646 VZ |
638 | if (mn.GetChar(0) == wxT('#')) |
639 | { | |
01325161 VS |
640 | mn = mn.Mid( 1 ); |
641 | } | |
642 | } | |
6cc4e6b8 VS |
643 | wxHtmlImageCell *cel = new wxHtmlImageCell( |
644 | m_WParser->GetWindow(), | |
5a7fa9ed VZ |
645 | str, w, h, |
646 | m_WParser->GetPixelScale(), | |
6cc4e6b8 | 647 | al, mn); |
3c115835 | 648 | m_WParser->ApplyStateToCell(cel); |
6cc4e6b8 VS |
649 | cel->SetId(tag.GetParam(wxT("id"))); // may be empty |
650 | m_WParser->GetContainer()->InsertCell(cel); | |
04dbb646 | 651 | if (str) |
01325161 | 652 | delete str; |
01325161 VS |
653 | } |
654 | } | |
04dbb646 VZ |
655 | if (tag.GetName() == wxT("MAP")) |
656 | { | |
01325161 VS |
657 | m_WParser->CloseContainer(); |
658 | m_WParser->OpenContainer(); | |
04dbb646 VZ |
659 | if (tag.HasParam(wxT("NAME"))) |
660 | { | |
0413cec5 | 661 | wxString tmp = tag.GetParam(wxT("NAME")); |
01325161 VS |
662 | wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp ); |
663 | m_WParser->GetContainer()->InsertCell( cel ); | |
664 | } | |
665 | ParseInner( tag ); | |
666 | m_WParser->CloseContainer(); | |
667 | m_WParser->OpenContainer(); | |
668 | } | |
04dbb646 VZ |
669 | if (tag.GetName() == wxT("AREA")) |
670 | { | |
671 | if (tag.HasParam(wxT("SHAPE"))) | |
672 | { | |
0413cec5 | 673 | wxString tmp = tag.GetParam(wxT("SHAPE")); |
edbd0635 | 674 | wxString coords = wxEmptyString; |
01325161 VS |
675 | tmp.MakeUpper(); |
676 | wxHtmlImageMapAreaCell *cel = NULL; | |
04dbb646 VZ |
677 | if (tag.HasParam(wxT("COORDS"))) |
678 | { | |
0413cec5 | 679 | coords = tag.GetParam(wxT("COORDS")); |
01325161 | 680 | } |
04dbb646 VZ |
681 | if (tmp == wxT("POLY")) |
682 | { | |
4f9297b0 | 683 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() ); |
04dbb646 VZ |
684 | } |
685 | else if (tmp == wxT("CIRCLE")) | |
686 | { | |
4f9297b0 | 687 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords, m_WParser->GetPixelScale() ); |
04dbb646 VZ |
688 | } |
689 | else if (tmp == wxT("RECT")) | |
690 | { | |
4f9297b0 | 691 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() ); |
01325161 | 692 | } |
04dbb646 VZ |
693 | if (cel != NULL && tag.HasParam(wxT("HREF"))) |
694 | { | |
17a1ebd1 VZ |
695 | wxString target; |
696 | if (tag.HasParam(wxT("TARGET"))) | |
697 | target = tag.GetParam(wxT("TARGET")); | |
698 | cel->SetLink(wxHtmlLinkInfo(tag.GetParam(wxT("HREF")), target)); | |
01325161 | 699 | } |
17a1ebd1 VZ |
700 | if (cel != NULL) |
701 | m_WParser->GetContainer()->InsertCell( cel ); | |
01325161 VS |
702 | } |
703 | } | |
5526e819 | 704 | |
d1da8872 | 705 | return false; |
5526e819 VS |
706 | } |
707 | ||
01325161 | 708 | TAG_HANDLER_END(IMG) |
5526e819 VS |
709 | |
710 | ||
711 | ||
712 | TAGS_MODULE_BEGIN(Image) | |
713 | ||
714 | TAGS_MODULE_ADD(IMG) | |
715 | ||
716 | TAGS_MODULE_END(Image) | |
717 | ||
718 | ||
3364ab79 | 719 | #endif |