]>
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" |
214bdb93 | 38 | #include "wx/artprov.h" |
25082126 VS |
39 | |
40 | #include <math.h> | |
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), | |
73 | wxHtmlRenderingState& WXUNUSED(state)) {} | |
25082126 VS |
74 | }; |
75 | ||
76 | ||
77 | ||
78 | ||
79 | ||
edbd0635 | 80 | wxHtmlImageMapAreaCell::wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::celltype t, wxString &incoords, double pixel_scale ) |
25082126 | 81 | { |
edbd0635 | 82 | int i; |
01325161 VS |
83 | wxString x = incoords, y; |
84 | ||
85 | type = t; | |
04dbb646 | 86 | while ((i = x.Find( ',' )) != -1) |
4f9297b0 | 87 | { |
edbd0635 | 88 | coords.Add( (int)(pixel_scale * (double)wxAtoi( x.Left( i ).c_str())) ); |
01325161 VS |
89 | x = x.Mid( i + 1 ); |
90 | } | |
edbd0635 | 91 | coords.Add( (int)(pixel_scale * (double)wxAtoi( x.c_str())) ); |
25082126 VS |
92 | } |
93 | ||
846914d1 | 94 | wxHtmlLinkInfo *wxHtmlImageMapAreaCell::GetLink( int x, int y ) const |
25082126 | 95 | { |
04dbb646 | 96 | switch (type) |
4f9297b0 | 97 | { |
01325161 VS |
98 | case RECT: |
99 | { | |
edbd0635 | 100 | int l, t, r, b; |
01325161 VS |
101 | |
102 | l = coords[ 0 ]; | |
103 | t = coords[ 1 ]; | |
104 | r = coords[ 2 ]; | |
105 | b = coords[ 3 ]; | |
04dbb646 VZ |
106 | if (x >= l && x <= r && y >= t && y <= b) |
107 | { | |
01325161 VS |
108 | return m_Link; |
109 | } | |
110 | break; | |
111 | } | |
112 | case CIRCLE: | |
113 | { | |
edbd0635 VS |
114 | int l, t, r; |
115 | double d; | |
01325161 VS |
116 | |
117 | l = coords[ 0 ]; | |
118 | t = coords[ 1 ]; | |
119 | r = coords[ 2 ]; | |
120 | d = sqrt( (double) (((x - l) * (x - l)) + ((y - t) * (y - t))) ); | |
04dbb646 VZ |
121 | if (d < (double)r) |
122 | { | |
01325161 VS |
123 | return m_Link; |
124 | } | |
125 | } | |
126 | break; | |
127 | case POLY: | |
128 | { | |
04dbb646 VZ |
129 | if (coords.GetCount() >= 6) |
130 | { | |
edbd0635 VS |
131 | int intersects = 0; |
132 | int wherex = x; | |
133 | int wherey = y; | |
134 | int totalv = coords.GetCount() / 2; | |
135 | int totalc = totalv * 2; | |
136 | int xval = coords[totalc - 2]; | |
137 | int yval = coords[totalc - 1]; | |
138 | int end = totalc; | |
139 | int pointer = 1; | |
01325161 | 140 | |
04dbb646 VZ |
141 | if ((yval >= wherey) != (coords[pointer] >= wherey)) |
142 | { | |
143 | if ((xval >= wherex) == (coords[0] >= wherex)) | |
144 | { | |
01325161 | 145 | intersects += (xval >= wherex) ? 1 : 0; |
04dbb646 VZ |
146 | } |
147 | else | |
148 | { | |
01325161 VS |
149 | intersects += ((xval - (yval - wherey) * |
150 | (coords[0] - xval) / | |
151 | (coords[pointer] - yval)) >= wherex) ? 1 : 0; | |
152 | } | |
153 | } | |
154 | ||
04dbb646 VZ |
155 | while (pointer < end) |
156 | { | |
01325161 VS |
157 | yval = coords[pointer]; |
158 | pointer += 2; | |
04dbb646 VZ |
159 | if (yval >= wherey) |
160 | { | |
161 | while ((pointer < end) && (coords[pointer] >= wherey)) | |
162 | { | |
01325161 VS |
163 | pointer += 2; |
164 | } | |
04dbb646 VZ |
165 | if (pointer >= end) |
166 | { | |
01325161 VS |
167 | break; |
168 | } | |
169 | if ((coords[pointer - 3] >= wherex) == | |
170 | (coords[pointer - 1] >= wherex)) { | |
171 | intersects += (coords[pointer - 3] >= wherex) ? 1 : 0; | |
04dbb646 VZ |
172 | } |
173 | else | |
174 | { | |
01325161 VS |
175 | intersects += |
176 | ((coords[pointer - 3] - (coords[pointer - 2] - wherey) * | |
177 | (coords[pointer - 1] - coords[pointer - 3]) / | |
178 | (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0; | |
179 | } | |
04dbb646 VZ |
180 | } |
181 | else | |
182 | { | |
183 | while ((pointer < end) && (coords[pointer] < wherey)) | |
184 | { | |
01325161 VS |
185 | pointer += 2; |
186 | } | |
04dbb646 VZ |
187 | if (pointer >= end) |
188 | { | |
01325161 VS |
189 | break; |
190 | } | |
191 | if ((coords[pointer - 3] >= wherex) == | |
04dbb646 VZ |
192 | (coords[pointer - 1] >= wherex)) |
193 | { | |
01325161 | 194 | intersects += (coords[pointer - 3] >= wherex) ? 1 : 0; |
04dbb646 VZ |
195 | } |
196 | else | |
197 | { | |
01325161 VS |
198 | intersects += |
199 | ((coords[pointer - 3] - (coords[pointer - 2] - wherey) * | |
200 | (coords[pointer - 1] - coords[pointer - 3]) / | |
201 | (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0; | |
202 | } | |
203 | } | |
204 | } | |
04dbb646 VZ |
205 | if ((intersects & 1) != 0) |
206 | { | |
01325161 VS |
207 | return m_Link; |
208 | } | |
209 | } | |
210 | } | |
211 | break; | |
212 | } | |
4f9297b0 | 213 | |
04dbb646 | 214 | if (m_Next) |
4f9297b0 | 215 | { |
edbd0635 | 216 | wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next; |
01325161 VS |
217 | return a->GetLink( x, y ); |
218 | } | |
846914d1 | 219 | return NULL; |
25082126 VS |
220 | } |
221 | ||
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 | //-------------------------------------------------------------------------------- | |
230 | // wxHtmlImageMapCell | |
231 | // 0-width, 0-height cell that represents map from imagemaps | |
232 | // it is always placed before wxHtmlImageMapAreaCells | |
efba2b89 | 233 | // It responds to Find(wxHTML_COND_ISIMAGEMAP) |
25082126 VS |
234 | //-------------------------------------------------------------------------------- |
235 | ||
236 | ||
237 | class wxHtmlImageMapCell : public wxHtmlCell | |
238 | { | |
01325161 VS |
239 | public: |
240 | wxHtmlImageMapCell( wxString &name ); | |
241 | protected: | |
242 | wxString m_Name; | |
243 | public: | |
846914d1 | 244 | virtual wxHtmlLinkInfo *GetLink( int x = 0, int y = 0 ) const; |
01325161 | 245 | virtual const wxHtmlCell *Find( int cond, const void *param ) const; |
36c4ff4d VS |
246 | void Draw(wxDC& WXUNUSED(dc), |
247 | int WXUNUSED(x), int WXUNUSED(y), | |
248 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
249 | wxHtmlRenderingState& WXUNUSED(state)) {} | |
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 VS |
287 | public: |
288 | wxHtmlImageCell(wxWindow *window, | |
5a7fa9ed VZ |
289 | wxFSFile *input, int w = -1, int h = -1, |
290 | double scale = 1.0, int align = wxHTML_ALIGN_BOTTOM, | |
ea5c1679 VS |
291 | const wxString& mapname = wxEmptyString); |
292 | ~wxHtmlImageCell(); | |
36c4ff4d VS |
293 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
294 | wxHtmlRenderingState& state); | |
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; |
ea5c1679 VS |
307 | wxScrolledWindow *m_window; |
308 | #if wxUSE_GIF && wxUSE_TIMER | |
309 | wxGIFDecoder *m_gifDecoder; | |
310 | wxTimer *m_gifTimer; | |
311 | int m_physX, m_physY; | |
312 | #endif | |
313 | double m_scale; | |
314 | wxHtmlImageMapCell *m_imageMap; | |
315 | wxString m_mapName; | |
22f3361e VZ |
316 | |
317 | DECLARE_NO_COPY_CLASS(wxHtmlImageCell) | |
5526e819 VS |
318 | }; |
319 | ||
ea5c1679 VS |
320 | #if wxUSE_GIF && wxUSE_TIMER |
321 | class wxGIFTimer : public wxTimer | |
322 | { | |
323 | public: | |
324 | wxGIFTimer(wxHtmlImageCell *cell) : m_cell(cell) {} | |
325 | virtual void Notify() | |
326 | { | |
327 | m_cell->AdvanceAnimation(this); | |
328 | } | |
5526e819 | 329 | |
ea5c1679 VS |
330 | private: |
331 | wxHtmlImageCell *m_cell; | |
22f3361e VZ |
332 | |
333 | DECLARE_NO_COPY_CLASS(wxGIFTimer) | |
ea5c1679 VS |
334 | }; |
335 | #endif | |
5526e819 | 336 | |
25082126 | 337 | |
214bdb93 | 338 | //---------------------------------------------------------------------------- |
5526e819 | 339 | // wxHtmlImageCell |
214bdb93 | 340 | //---------------------------------------------------------------------------- |
5526e819 | 341 | |
6cc4e6b8 | 342 | |
5a7fa9ed VZ |
343 | wxHtmlImageCell::wxHtmlImageCell(wxWindow *window, wxFSFile *input, |
344 | int w, int h, double scale, int align, | |
ea5c1679 | 345 | const wxString& mapname) : wxHtmlCell() |
5526e819 | 346 | { |
a4e2b276 | 347 | m_window = window ? wxStaticCast(window, wxScrolledWindow) : NULL; |
ea5c1679 | 348 | m_scale = scale; |
6cc4e6b8 | 349 | m_showFrame = FALSE; |
ea5c1679 VS |
350 | m_bitmap = NULL; |
351 | m_bmpW = w; | |
352 | m_bmpH = h; | |
353 | m_imageMap = NULL; | |
354 | m_mapName = mapname; | |
355 | SetCanLiveOnPagebreak(FALSE); | |
356 | #if wxUSE_GIF && wxUSE_TIMER | |
357 | m_gifDecoder = NULL; | |
358 | m_gifTimer = NULL; | |
359 | m_physX = m_physY = -1; | |
360 | #endif | |
04dbb646 | 361 | |
08a15c0d | 362 | if ( m_bmpW && m_bmpH ) |
4f9297b0 | 363 | { |
08a15c0d | 364 | if ( input ) |
ea5c1679 | 365 | { |
08a15c0d | 366 | wxInputStream *s = input->GetStream(); |
6cc4e6b8 | 367 | |
08a15c0d | 368 | if ( s ) |
ea5c1679 | 369 | { |
08a15c0d VZ |
370 | bool readImg = TRUE; |
371 | ||
372 | #if wxUSE_GIF && wxUSE_TIMER | |
373 | if ( (input->GetLocation().Matches(wxT("*.gif")) || | |
374 | input->GetLocation().Matches(wxT("*.GIF"))) && m_window ) | |
6cc4e6b8 | 375 | { |
08a15c0d VZ |
376 | m_gifDecoder = new wxGIFDecoder(s, TRUE); |
377 | if ( m_gifDecoder->ReadGIF() == wxGIF_OK ) | |
378 | { | |
379 | wxImage img; | |
380 | if ( m_gifDecoder->ConvertToImage(&img) ) | |
381 | SetImage(img); | |
37a1f3f6 | 382 | |
08a15c0d | 383 | readImg = FALSE; |
37a1f3f6 | 384 | |
08a15c0d VZ |
385 | if ( m_gifDecoder->IsAnimation() ) |
386 | { | |
387 | m_gifTimer = new wxGIFTimer(this); | |
388 | m_gifTimer->Start(m_gifDecoder->GetDelay(), TRUE); | |
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 | { |
08a15c0d VZ |
412 | if ( m_bmpW == -1 && m_bmpH == -1 ) |
413 | { | |
414 | m_bmpW = 29; | |
415 | m_bmpH = 31; | |
416 | } | |
417 | else | |
418 | { | |
419 | m_showFrame = TRUE; | |
420 | if ( m_bmpW == -1 ) m_bmpW = 31; | |
421 | if ( m_bmpH == -1 ) m_bmpH = 33; | |
422 | } | |
214bdb93 VS |
423 | m_bitmap = |
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 | ||
457 | if ( m_bmpW == -1 ) | |
458 | m_bmpW = ww; | |
459 | if ( m_bmpH == -1 ) | |
460 | m_bmpH = hh; | |
461 | ||
462 | if ((m_bmpW != ww) || (m_bmpH != hh)) | |
463 | { | |
464 | wxImage img2 = img.Scale(m_bmpW, m_bmpH); | |
465 | m_bitmap = new wxBitmap(img2); | |
466 | } | |
467 | else | |
468 | m_bitmap = new wxBitmap(img); | |
469 | } | |
5526e819 VS |
470 | } |
471 | ||
ea5c1679 VS |
472 | #if wxUSE_GIF && wxUSE_TIMER |
473 | void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer) | |
474 | { | |
475 | wxImage img; | |
476 | ||
477 | m_gifDecoder->GoNextFrame(TRUE); | |
478 | ||
479 | if ( m_physX == -1 ) | |
480 | { | |
481 | m_physX = m_physY = 0; | |
482 | for (wxHtmlCell *cell = this; cell; cell = cell->GetParent()) | |
483 | { | |
484 | m_physX += cell->GetPosX(); | |
485 | m_physY += cell->GetPosY(); | |
486 | } | |
487 | } | |
488 | ||
489 | int x, y; | |
490 | m_window->CalcScrolledPosition(m_physX, m_physY, &x, &y); | |
491 | wxRect rect(x, y, m_Width, m_Height); | |
492 | ||
5a7fa9ed | 493 | if ( m_window->GetClientRect().Intersects(rect) && |
ea5c1679 VS |
494 | m_gifDecoder->ConvertToImage(&img) ) |
495 | { | |
2d963ba2 VS |
496 | if ( (int)m_gifDecoder->GetWidth() != m_Width || |
497 | (int)m_gifDecoder->GetHeight() != m_Height || | |
498 | m_gifDecoder->GetLeft() != 0 || m_gifDecoder->GetTop() != 0 ) | |
499 | { | |
500 | wxBitmap bmp(img); | |
501 | wxMemoryDC dc; | |
502 | dc.SelectObject(*m_bitmap); | |
503 | dc.DrawBitmap(bmp, m_gifDecoder->GetLeft(), m_gifDecoder->GetTop()); | |
504 | } | |
505 | else | |
506 | SetImage(img); | |
ea5c1679 VS |
507 | m_window->Refresh(img.HasMask(), &rect); |
508 | } | |
509 | ||
510 | timer->Start(m_gifDecoder->GetDelay(), TRUE); | |
511 | } | |
512 | ||
513 | void wxHtmlImageCell::Layout(int w) | |
514 | { | |
515 | wxHtmlCell::Layout(w); | |
516 | m_physX = m_physY = -1; | |
517 | } | |
518 | ||
519 | #endif | |
520 | ||
521 | wxHtmlImageCell::~wxHtmlImageCell() | |
522 | { | |
523 | delete m_bitmap; | |
524 | #if wxUSE_GIF && wxUSE_TIMER | |
525 | delete m_gifTimer; | |
526 | delete m_gifDecoder; | |
527 | #endif | |
528 | } | |
5526e819 VS |
529 | |
530 | ||
36c4ff4d VS |
531 | void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, |
532 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
533 | wxHtmlRenderingState& WXUNUSED(state)) | |
5526e819 | 534 | { |
6cc4e6b8 VS |
535 | if ( m_showFrame ) |
536 | { | |
537 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
538 | dc.SetPen(*wxBLACK_PEN); | |
539 | dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height); | |
540 | x++, y++; | |
541 | } | |
542 | if ( m_bitmap ) | |
b5c01940 VS |
543 | { |
544 | double us_x, us_y; | |
545 | dc.GetUserScale(&us_x, &us_y); | |
ea5c1679 | 546 | dc.SetUserScale(us_x * m_scale, us_y * m_scale); |
04dbb646 | 547 | |
ea5c1679 VS |
548 | dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / m_scale), |
549 | (int) ((y + m_PosY) / m_scale), TRUE); | |
b5c01940 VS |
550 | dc.SetUserScale(us_x, us_y); |
551 | } | |
5526e819 VS |
552 | } |
553 | ||
846914d1 | 554 | wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const |
25082126 | 555 | { |
ea5c1679 | 556 | if (m_mapName.IsEmpty()) |
01325161 | 557 | return wxHtmlCell::GetLink( x, y ); |
ea5c1679 | 558 | if (!m_imageMap) |
4f9297b0 | 559 | { |
edbd0635 | 560 | wxHtmlContainerCell *p, *op; |
01325161 | 561 | op = p = GetParent(); |
04dbb646 VZ |
562 | while (p) |
563 | { | |
01325161 VS |
564 | op = p; |
565 | p = p->GetParent(); | |
566 | } | |
567 | p = op; | |
5a7fa9ed | 568 | wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP, |
ea5c1679 | 569 | (const void*)(&m_mapName)); |
04dbb646 VZ |
570 | if (!cell) |
571 | { | |
ea5c1679 | 572 | ((wxString&)m_mapName).Clear(); |
01325161 VS |
573 | return wxHtmlCell::GetLink( x, y ); |
574 | } | |
4f9297b0 | 575 | { // dirty hack, ask Joel why he fills m_ImageMap in this place |
01325161 | 576 | // THE problem is that we're in const method and we can't modify m_ImageMap |
ea5c1679 | 577 | wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap); |
01325161 | 578 | *cx = (wxHtmlImageMapCell*)cell; |
25082126 | 579 | } |
01325161 | 580 | } |
ea5c1679 | 581 | return m_imageMap->GetLink(x, y); |
25082126 | 582 | } |
5526e819 VS |
583 | |
584 | ||
585 | ||
586 | //-------------------------------------------------------------------------------- | |
587 | // tag handler | |
588 | //-------------------------------------------------------------------------------- | |
589 | ||
01325161 | 590 | TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA") |
5526e819 VS |
591 | |
592 | TAG_HANDLER_PROC(tag) | |
593 | { | |
04dbb646 VZ |
594 | if (tag.GetName() == wxT("IMG")) |
595 | { | |
596 | if (tag.HasParam(wxT("SRC"))) | |
597 | { | |
01325161 VS |
598 | int w = -1, h = -1; |
599 | int al; | |
600 | wxFSFile *str; | |
0413cec5 | 601 | wxString tmp = tag.GetParam(wxT("SRC")); |
01325161 | 602 | wxString mn = wxEmptyString; |
5a7fa9ed | 603 | |
6cc4e6b8 | 604 | str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp); |
5a7fa9ed | 605 | |
04dbb646 | 606 | if (tag.HasParam(wxT("WIDTH"))) |
8bd72d90 | 607 | tag.GetParamAsInt(wxT("WIDTH"), &w); |
04dbb646 | 608 | if (tag.HasParam(wxT("HEIGHT"))) |
8bd72d90 | 609 | tag.GetParamAsInt(wxT("HEIGHT"), &h); |
01325161 | 610 | al = wxHTML_ALIGN_BOTTOM; |
04dbb646 VZ |
611 | if (tag.HasParam(wxT("ALIGN"))) |
612 | { | |
0413cec5 | 613 | wxString alstr = tag.GetParam(wxT("ALIGN")); |
01325161 | 614 | alstr.MakeUpper(); // for the case alignment was in ".." |
04dbb646 | 615 | if (alstr == wxT("TEXTTOP")) |
8bd72d90 | 616 | al = wxHTML_ALIGN_TOP; |
04dbb646 | 617 | else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER"))) |
8bd72d90 | 618 | al = wxHTML_ALIGN_CENTER; |
01325161 | 619 | } |
04dbb646 VZ |
620 | if (tag.HasParam(wxT("USEMAP"))) |
621 | { | |
0413cec5 | 622 | mn = tag.GetParam( wxT("USEMAP") ); |
04dbb646 VZ |
623 | if (mn.GetChar(0) == wxT('#')) |
624 | { | |
01325161 VS |
625 | mn = mn.Mid( 1 ); |
626 | } | |
627 | } | |
6cc4e6b8 VS |
628 | wxHtmlImageCell *cel = new wxHtmlImageCell( |
629 | m_WParser->GetWindow(), | |
5a7fa9ed VZ |
630 | str, w, h, |
631 | m_WParser->GetPixelScale(), | |
6cc4e6b8 VS |
632 | al, mn); |
633 | cel->SetLink(m_WParser->GetLink()); | |
634 | cel->SetId(tag.GetParam(wxT("id"))); // may be empty | |
635 | m_WParser->GetContainer()->InsertCell(cel); | |
04dbb646 | 636 | if (str) |
01325161 | 637 | delete str; |
01325161 VS |
638 | } |
639 | } | |
04dbb646 VZ |
640 | if (tag.GetName() == wxT("MAP")) |
641 | { | |
01325161 VS |
642 | m_WParser->CloseContainer(); |
643 | m_WParser->OpenContainer(); | |
04dbb646 VZ |
644 | if (tag.HasParam(wxT("NAME"))) |
645 | { | |
0413cec5 | 646 | wxString tmp = tag.GetParam(wxT("NAME")); |
01325161 VS |
647 | wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp ); |
648 | m_WParser->GetContainer()->InsertCell( cel ); | |
649 | } | |
650 | ParseInner( tag ); | |
651 | m_WParser->CloseContainer(); | |
652 | m_WParser->OpenContainer(); | |
653 | } | |
04dbb646 VZ |
654 | if (tag.GetName() == wxT("AREA")) |
655 | { | |
656 | if (tag.HasParam(wxT("SHAPE"))) | |
657 | { | |
0413cec5 | 658 | wxString tmp = tag.GetParam(wxT("SHAPE")); |
edbd0635 | 659 | wxString coords = wxEmptyString; |
01325161 VS |
660 | tmp.MakeUpper(); |
661 | wxHtmlImageMapAreaCell *cel = NULL; | |
04dbb646 VZ |
662 | if (tag.HasParam(wxT("COORDS"))) |
663 | { | |
0413cec5 | 664 | coords = tag.GetParam(wxT("COORDS")); |
01325161 | 665 | } |
04dbb646 VZ |
666 | if (tmp == wxT("POLY")) |
667 | { | |
4f9297b0 | 668 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() ); |
04dbb646 VZ |
669 | } |
670 | else if (tmp == wxT("CIRCLE")) | |
671 | { | |
4f9297b0 | 672 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords, m_WParser->GetPixelScale() ); |
04dbb646 VZ |
673 | } |
674 | else if (tmp == wxT("RECT")) | |
675 | { | |
4f9297b0 | 676 | cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() ); |
01325161 | 677 | } |
04dbb646 VZ |
678 | if (cel != NULL && tag.HasParam(wxT("HREF"))) |
679 | { | |
0413cec5 | 680 | wxString tmp = tag.GetParam(wxT("HREF")); |
846914d1 | 681 | wxString target = wxEmptyString; |
0413cec5 | 682 | if (tag.HasParam(wxT("TARGET"))) target = tag.GetParam(wxT("TARGET")); |
846914d1 | 683 | cel->SetLink( wxHtmlLinkInfo(tmp, target)); |
01325161 VS |
684 | } |
685 | if (cel != NULL) m_WParser->GetContainer()->InsertCell( cel ); | |
686 | } | |
687 | } | |
5526e819 VS |
688 | |
689 | return FALSE; | |
690 | } | |
691 | ||
01325161 | 692 | TAG_HANDLER_END(IMG) |
5526e819 VS |
693 | |
694 | ||
695 | ||
696 | TAGS_MODULE_BEGIN(Image) | |
697 | ||
698 | TAGS_MODULE_ADD(IMG) | |
699 | ||
700 | TAGS_MODULE_END(Image) | |
701 | ||
702 | ||
3364ab79 | 703 | #endif |