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