]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmlcell.cpp
fixed iso8859-15 handling (backmerged from 2.2)
[wxWidgets.git] / src / html / htmlcell.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlcell.cpp
3 // Purpose: wxHtmlCell - basic element of HTML output
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include "wx/wxprec.h"
15
16 #include "wx/defs.h"
17
18 #if wxUSE_HTML && wxUSE_STREAMS
19
20 #ifdef __BORDLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WXPRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 #include "wx/html/htmlcell.h"
29 #include "wx/html/htmlwin.h"
30 #include <stdlib.h>
31
32
33 //-----------------------------------------------------------------------------
34 // wxHtmlCell
35 //-----------------------------------------------------------------------------
36
37 wxHtmlCell::wxHtmlCell() : wxObject()
38 {
39 m_Next = NULL;
40 m_Parent = NULL;
41 m_Width = m_Height = m_Descent = 0;
42 m_CanLiveOnPagebreak = TRUE;
43 m_Link = NULL;
44 }
45
46 wxHtmlCell::~wxHtmlCell()
47 {
48 if (m_Link) delete m_Link;
49 if (m_Next) delete m_Next;
50 }
51
52
53 void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y,
54 const wxMouseEvent& event)
55 {
56 wxHtmlLinkInfo *lnk = GetLink(x, y);
57 if (lnk != NULL)
58 {
59 wxHtmlLinkInfo lnk2(*lnk);
60 lnk2.SetEvent(&event);
61 lnk2.SetHtmlCell(this);
62 ((wxHtmlWindow*)parent)->OnLinkClicked(lnk2);
63 // note : this overcasting is legal because parent is *always* wxHtmlWindow
64 }
65 }
66
67
68
69 bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const
70 {
71 if ((!m_CanLiveOnPagebreak) &&
72 m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
73 {
74 *pagebreak = m_PosY;
75 if (m_Next != NULL) m_Next->AdjustPagebreak(pagebreak);
76 return TRUE;
77 }
78
79 else
80 {
81 if (m_Next != NULL) return m_Next->AdjustPagebreak(pagebreak);
82 else return FALSE;
83 }
84 }
85
86
87
88 void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
89 {
90 if (m_Link) delete m_Link;
91 m_Link = NULL;
92 if (link.GetHref() != wxEmptyString)
93 m_Link = new wxHtmlLinkInfo(link);
94 }
95
96
97
98 void wxHtmlCell::Layout(int w)
99 {
100 SetPos(0, 0);
101 if (m_Next) m_Next->Layout(w);
102 }
103
104
105 void wxHtmlCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
106 {
107 if (m_Next) m_Next->Draw(dc, x, y, view_y1, view_y2);
108 }
109
110
111
112 void wxHtmlCell::DrawInvisible(wxDC& dc, int x, int y)
113 {
114 if (m_Next) m_Next->DrawInvisible(dc, x, y);
115 }
116
117
118
119 const wxHtmlCell* wxHtmlCell::Find(int condition, const void* param) const
120 {
121 if (m_Next) return m_Next->Find(condition, param);
122 else return NULL;
123 }
124
125
126
127 //-----------------------------------------------------------------------------
128 // wxHtmlWordCell
129 //-----------------------------------------------------------------------------
130
131 wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
132 {
133 m_Word = word;
134
135 if (m_Word.Find(wxT('&')) != -1)
136 {
137 #define ESCSEQ(escape, subst) \
138 { _T("&") _T(escape) _T(";"), _T("&") _T(escape) _T(" "), _T("&") _T(escape), _T(subst) }
139 static wxChar* substitutions[][4] =
140 {
141 ESCSEQ("quot", "\""),
142 ESCSEQ("#34", "\""),
143 ESCSEQ("lt", "<"),
144 ESCSEQ("#60", "<"),
145 ESCSEQ("gt", ">"),
146 ESCSEQ("#62", ">"),
147
148 ESCSEQ("#94", "^"), /* ^ */
149
150 ESCSEQ("nbsp", " "),
151 ESCSEQ("#32", " "),
152 ESCSEQ("iexcl", "!"),
153 ESCSEQ("#33", "!"),
154 ESCSEQ("cent", "¢"/* ¢ */),
155 ESCSEQ("#162", "¢"/* ¢ */),
156
157 ESCSEQ("trade", "(TM)"),
158 ESCSEQ("#153", "(TM)"),
159
160 ESCSEQ("yen", "¥"),
161 ESCSEQ("#165", "¥"),
162 ESCSEQ("brkbar", "¦"),
163 ESCSEQ("#166", "¦"),
164 ESCSEQ("sect", "§"),
165 ESCSEQ("#167", "§"),
166 ESCSEQ("uml", "¨"),
167 ESCSEQ("#168", "¨"),
168
169 ESCSEQ("copy", "©"), /* © */
170 ESCSEQ("#169", "©"),
171 ESCSEQ("ordf", "ª"),
172 ESCSEQ("#170", "ª"),
173 ESCSEQ("laquo", "«"), /* « */
174 ESCSEQ("#171", "«"),
175 ESCSEQ("not", "¬"),
176 ESCSEQ("#172", "¬"),
177
178 ESCSEQ("reg", "®"), /* ® */
179 ESCSEQ("#174", "®"),
180
181 ESCSEQ("deg", "°"), /* ° */
182 ESCSEQ("#176", "°"),
183 ESCSEQ("plusm", "±"), /* ± */
184 ESCSEQ("#177", "±"),
185
186 ESCSEQ("acute", "´"),
187 ESCSEQ("#180", "´"),
188 ESCSEQ("macron", "¯"),
189 ESCSEQ("#175", "¯"),
190 ESCSEQ("micro", "µ"), /* µ */
191 ESCSEQ("#181", "µ"),
192 ESCSEQ("para", "¶"), /* ¶ */
193 ESCSEQ("#182", "¶"),
194
195 ESCSEQ("ordm", "º"), /* º */
196 ESCSEQ("#186", "º"),
197 ESCSEQ("raquo", "»"), /* » */
198 ESCSEQ("#187", "»"),
199
200 ESCSEQ("iquest", "¿"), /* ¿ */
201 ESCSEQ("#191", "¿"),
202 ESCSEQ("Agrave", "\300"/* À */),
203 ESCSEQ("#193", "\300"/* À */),
204
205 ESCSEQ("Acirc", "\302"/* Â */),
206 ESCSEQ("Atilde", "\303"/* Ã */),
207 ESCSEQ("Auml", "\304"/* Ä */),
208 ESCSEQ("Aring", " "),
209 ESCSEQ("AElig", " "),
210 ESCSEQ("Ccedil", "\347"/* ç */),
211 ESCSEQ("Egrave", "\310"/* È */),
212 ESCSEQ("Eacute", "\311"/* É */),
213 ESCSEQ("Ecirc", "\312"/* Ê */),
214 ESCSEQ("Euml", "\313"/* Ë */),
215 ESCSEQ("Igrave", "\314"/* Ì */),
216
217 ESCSEQ("Icirc", "\316"/* Î */),
218 ESCSEQ("Iuml", "\317"/* Ï */),
219
220 ESCSEQ("Ntilde", "\321"/* Ñ */),
221 ESCSEQ("Ograve", "\322"/* Ò */),
222
223 ESCSEQ("Ocirc", "\324"/* Ô */),
224 ESCSEQ("Otilde", "\325"/* Õ */),
225 ESCSEQ("Ouml", "\326"/* Ö */),
226
227 ESCSEQ("Oslash", " "),
228 ESCSEQ("Ugrave", "\331"/* Ù */),
229
230 ESCSEQ("Ucirc", " "),
231 ESCSEQ("Uuml", "\334"/* Ü */),
232
233 ESCSEQ("szlig", "\247"/* § */),
234 ESCSEQ("agrave;","à"),
235 ESCSEQ("aacute", "\341"/* á */),
236 ESCSEQ("acirc", "\342"/* â */),
237 ESCSEQ("atilde", "\343"/* ã */),
238 ESCSEQ("auml", "\344"/* ä */),
239 ESCSEQ("aring", "a"),
240 ESCSEQ("aelig", "ae"),
241 ESCSEQ("ccedil", "\347"/* ç */),
242 ESCSEQ("egrave", "\350"/* è */),
243 ESCSEQ("eacute", "\351"/* é */),
244 ESCSEQ("ecirc", "\352"/* ê */),
245 ESCSEQ("euml", "\353"/* ë */),
246 ESCSEQ("igrave", "\354"/* ì */),
247 ESCSEQ("iacute", "\355"/* í */),
248 ESCSEQ("icirc", " "),
249 ESCSEQ("iuml", "\357"/* ï */),
250 ESCSEQ("eth", " "),
251 ESCSEQ("ntilde", "\361"/* ñ */),
252 ESCSEQ("ograve", "\362"/* ò */),
253 ESCSEQ("oacute", "\363"/* ó */),
254 ESCSEQ("ocirc", "\364"/* ô */),
255 ESCSEQ("otilde", "\365"/* õ */),
256 ESCSEQ("ouml", "\366"/* ö */),
257 ESCSEQ("divide", " "),
258 ESCSEQ("oslash", " "),
259 ESCSEQ("ugrave", "\371"/* ù */),
260 ESCSEQ("uacute", "\372"/* ú */),
261 ESCSEQ("ucirc", "\373"/* û */),
262 ESCSEQ("uuml", "\374"/* ü */),
263
264 ESCSEQ("yuml", ""),
265
266 /* this one should ALWAYS stay the last one!!! */
267 ESCSEQ("amp", "&"),
268 ESCSEQ("#38", "&"),
269
270 { NULL, NULL, NULL }
271 };
272
273 for (int i = 0; substitutions[i][0] != NULL; i++)
274 {
275 m_Word.Replace(substitutions[i][0], substitutions[i][3], TRUE);
276 m_Word.Replace(substitutions[i][1], substitutions[i][3], TRUE);
277 m_Word.Replace(substitutions[i][2], substitutions[i][3], TRUE);
278 }
279 }
280
281 dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
282 SetCanLiveOnPagebreak(FALSE);
283 }
284
285
286
287 void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
288 {
289 dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
290 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
291 }
292
293
294
295 //-----------------------------------------------------------------------------
296 // wxHtmlContainerCell
297 //-----------------------------------------------------------------------------
298
299
300 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
301 {
302 m_Cells = m_LastCell = NULL;
303 m_Parent = parent;
304 if (m_Parent) m_Parent->InsertCell(this);
305 m_AlignHor = wxHTML_ALIGN_LEFT;
306 m_AlignVer = wxHTML_ALIGN_BOTTOM;
307 m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
308 m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
309 m_UseBkColour = FALSE;
310 m_UseBorder = FALSE;
311 m_MinHeight = 0;
312 m_MinHeightAlign = wxHTML_ALIGN_TOP;
313 m_LastLayout = -1;
314 }
315
316 wxHtmlContainerCell::~wxHtmlContainerCell()
317 {
318 if (m_Cells) delete m_Cells;
319 }
320
321
322
323 void wxHtmlContainerCell::SetIndent(int i, int what, int units)
324 {
325 int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
326 if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
327 if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
328 if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
329 if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
330 m_LastLayout = -1;
331 }
332
333
334
335 int wxHtmlContainerCell::GetIndent(int ind) const
336 {
337 if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
338 else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
339 else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
340 else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
341 else return -1; /* BUG! Should not be called... */
342 }
343
344
345
346
347 int wxHtmlContainerCell::GetIndentUnits(int ind) const
348 {
349 bool p = FALSE;
350 if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
351 else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
352 else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
353 else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
354 if (p) return wxHTML_UNITS_PERCENT;
355 else return wxHTML_UNITS_PIXELS;
356 }
357
358
359
360 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak) const
361 {
362 if (!m_CanLiveOnPagebreak)
363 return wxHtmlCell::AdjustPagebreak(pagebreak);
364
365 else
366 {
367 wxHtmlCell *c = GetFirstCell();
368 bool rt = FALSE;
369 int pbrk = *pagebreak - m_PosY;
370
371 while (c)
372 {
373 if (c->AdjustPagebreak(&pbrk)) rt = TRUE;
374 c = c->GetNext();
375 }
376 if (rt) *pagebreak = pbrk + m_PosY;
377 return rt;
378 }
379 }
380
381
382
383 void wxHtmlContainerCell::Layout(int w)
384 {
385 if (m_LastLayout == w)
386 {
387 wxHtmlCell::Layout(w);
388 return;
389 }
390
391 wxHtmlCell *cell = m_Cells, *line = m_Cells;
392 long xpos = 0, ypos = m_IndentTop;
393 int xdelta = 0, ybasicpos = 0, ydiff;
394 int s_width, s_indent;
395 int ysizeup = 0, ysizedown = 0;
396 int MaxLineWidth = 0;
397 int xcnt = 0;
398
399
400 /*
401
402 WIDTH ADJUSTING :
403
404 */
405
406 if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
407 {
408 if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
409 else m_Width = m_WidthFloat * w / 100;
410 }
411 else
412 {
413 if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
414 else m_Width = m_WidthFloat;
415 }
416
417 if (m_Cells)
418 {
419 int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
420 int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
421 m_Cells->Layout(m_Width - (l + r));
422 }
423
424 /*
425
426 LAYOUTING :
427
428 */
429
430 // adjust indentation:
431 s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
432 s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
433
434 // my own layouting:
435 while (cell != NULL)
436 {
437 switch (m_AlignVer)
438 {
439 case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
440 case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
441 case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
442 }
443 ydiff = cell->GetHeight() + ybasicpos;
444
445 if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
446 if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
447
448 cell->SetPos(xpos, ybasicpos + cell->GetDescent());
449 xpos += cell->GetWidth();
450 cell = cell->GetNext();
451 xcnt++;
452
453 // force new line if occured:
454 if ((cell == NULL) || (xpos + cell->GetWidth() > s_width))
455 {
456 if (xpos > MaxLineWidth) MaxLineWidth = xpos;
457 if (ysizeup < 0) ysizeup = 0;
458 if (ysizedown < 0) ysizedown = 0;
459 switch (m_AlignHor) {
460 case wxHTML_ALIGN_LEFT :
461 case wxHTML_ALIGN_JUSTIFY :
462 xdelta = 0;
463 break;
464 case wxHTML_ALIGN_RIGHT :
465 xdelta = 0 + (s_width - xpos);
466 break;
467 case wxHTML_ALIGN_CENTER :
468 xdelta = 0 + (s_width - xpos) / 2;
469 break;
470 }
471 if (xdelta < 0) xdelta = 0;
472 xdelta += s_indent;
473
474 ypos += ysizeup;
475
476 if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
477 while (line != cell)
478 {
479 line->SetPos(line->GetPosX() + xdelta,
480 ypos + line->GetPosY());
481 line = line->GetNext();
482 }
483 else
484 {
485 int counter = 0;
486 int step = (s_width - xpos);
487 if (step < 0) step = 0;
488 xcnt--;
489 if (xcnt > 0) while (line != cell)
490 {
491 line->SetPos(line->GetPosX() + s_indent +
492 (counter++ * step / xcnt),
493 ypos + line->GetPosY());
494 line = line->GetNext();
495 }
496 xcnt++;
497 }
498
499 ypos += ysizedown;
500 xpos = xcnt = 0;
501 ysizeup = ysizedown = 0;
502 line = cell;
503 }
504 }
505
506 // setup height & width, depending on container layout:
507 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
508
509 if (m_Height < m_MinHeight)
510 {
511 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
512 {
513 int diff = m_MinHeight - m_Height;
514 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
515 cell = m_Cells;
516 while (cell)
517 {
518 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
519 cell = cell->GetNext();
520 }
521 }
522 m_Height = m_MinHeight;
523 }
524
525 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
526 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
527
528 m_LastLayout = w;
529
530 wxHtmlCell::Layout(w);
531 }
532
533
534 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
535 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
536
537 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
538 {
539 // container visible, draw it:
540 if ((y + m_PosY < view_y2) && (y + m_PosY + m_Height > view_y1))
541 {
542
543 if (m_UseBkColour)
544 {
545 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
546
547 int real_y1 = mMax(y + m_PosY, view_y1);
548 int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2);
549
550 dc.SetBrush(myb);
551 dc.SetPen(*wxTRANSPARENT_PEN);
552 dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1);
553 }
554
555 if (m_UseBorder)
556 {
557 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
558 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
559
560 dc.SetPen(mypen1);
561 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1);
562 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY);
563 dc.SetPen(mypen2);
564 dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
565 dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
566 }
567
568 if (m_Cells) m_Cells->Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2);
569 }
570 // container invisible, just proceed font+color changing:
571 else
572 {
573 if (m_Cells) m_Cells->DrawInvisible(dc, x + m_PosX, y + m_PosY);
574 }
575
576 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
577 }
578
579
580
581 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y)
582 {
583 if (m_Cells) m_Cells->DrawInvisible(dc, x + m_PosX, y + m_PosY);
584 wxHtmlCell::DrawInvisible(dc, x, y);
585 }
586
587
588
589 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
590 {
591 wxHtmlCell *c = m_Cells;
592 int cx, cy, cw, ch;
593
594 while (c)
595 {
596 cx = c->GetPosX(), cy = c->GetPosY();
597 cw = c->GetWidth(), ch = c->GetHeight();
598 if ((x >= cx) && (x < cx + cw) && (y >= cy) && (y < cy + ch))
599 return c->GetLink(x - cx, y - cy);
600 c = c->GetNext();
601 }
602 return NULL;
603 }
604
605
606
607 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
608 {
609 if (!m_Cells) m_Cells = m_LastCell = f;
610 else
611 {
612 m_LastCell->SetNext(f);
613 m_LastCell = f;
614 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
615 }
616 f->SetParent(this);
617 m_LastLayout = -1;
618 }
619
620
621
622 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
623 {
624 if (tag.HasParam(wxT("ALIGN")))
625 {
626 wxString alg = tag.GetParam(wxT("ALIGN"));
627 alg.MakeUpper();
628 if (alg == wxT("CENTER"))
629 SetAlignHor(wxHTML_ALIGN_CENTER);
630 else if (alg == wxT("LEFT"))
631 SetAlignHor(wxHTML_ALIGN_LEFT);
632 else if (alg == wxT("JUSTIFY"))
633 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
634 else if (alg == wxT("RIGHT"))
635 SetAlignHor(wxHTML_ALIGN_RIGHT);
636 m_LastLayout = -1;
637 }
638 }
639
640
641
642 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
643 {
644 if (tag.HasParam(wxT("WIDTH")))
645 {
646 int wdi;
647 wxString wd = tag.GetParam(wxT("WIDTH"));
648
649 if (wd[wd.Length()-1] == wxT('%'))
650 {
651 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
652 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
653 }
654 else
655 {
656 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
657 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
658 }
659 m_LastLayout = -1;
660 }
661 }
662
663
664
665 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
666 {
667 const wxHtmlCell *r = NULL;
668
669 if (m_Cells)
670 {
671 r = m_Cells->Find(condition, param);
672 if (r) return r;
673 }
674
675 return wxHtmlCell::Find(condition, param);
676 }
677
678
679
680 void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event)
681 {
682 if (m_Cells)
683 {
684 wxHtmlCell *c = m_Cells;
685 while (c)
686 {
687 if ( (c->GetPosX() <= x) &&
688 (c->GetPosY() <= y) &&
689 (c->GetPosX() + c->GetWidth() > x) &&
690 (c->GetPosY() + c->GetHeight() > y))
691 {
692 c->OnMouseClick(parent, x - c->GetPosX(), y - c->GetPosY(), event);
693 break;
694 }
695 c = c->GetNext();
696 }
697 }
698 }
699
700
701
702
703
704 //--------------------------------------------------------------------------------
705 // wxHtmlColourCell
706 //--------------------------------------------------------------------------------
707
708 void wxHtmlColourCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
709 {
710 if (m_Flags & wxHTML_CLR_FOREGROUND)
711 dc.SetTextForeground(m_Colour);
712 if (m_Flags & wxHTML_CLR_BACKGROUND)
713 {
714 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
715 dc.SetTextBackground(m_Colour);
716 }
717 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
718 }
719
720 void wxHtmlColourCell::DrawInvisible(wxDC& dc, int x, int y)
721 {
722 if (m_Flags & wxHTML_CLR_FOREGROUND)
723 dc.SetTextForeground(m_Colour);
724 if (m_Flags & wxHTML_CLR_BACKGROUND)
725 {
726 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
727 dc.SetTextBackground(m_Colour);
728 }
729 wxHtmlCell::DrawInvisible(dc, x, y);
730 }
731
732
733
734
735 //--------------------------------------------------------------------------------
736 // wxHtmlFontCell
737 //--------------------------------------------------------------------------------
738
739 void wxHtmlFontCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
740 {
741 dc.SetFont(m_Font);
742 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
743 }
744
745 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int x, int y)
746 {
747 dc.SetFont(m_Font);
748 wxHtmlCell::DrawInvisible(dc, x, y);
749 }
750
751
752
753
754
755
756
757
758 //--------------------------------------------------------------------------------
759 // wxHtmlWidgetCell
760 //--------------------------------------------------------------------------------
761
762 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
763 {
764 int sx, sy;
765 m_Wnd = wnd;
766 m_Wnd->GetSize(&sx, &sy);
767 m_Width = sx, m_Height = sy;
768 m_WidthFloat = w;
769 }
770
771
772 void wxHtmlWidgetCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
773 {
774 int absx = 0, absy = 0, stx, sty;
775 wxHtmlCell *c = this;
776
777 while (c)
778 {
779 absx += c->GetPosX();
780 absy += c->GetPosY();
781 c = c->GetParent();
782 }
783
784 ((wxScrolledWindow*)(m_Wnd->GetParent()))->ViewStart(&stx, &sty);
785 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
786
787 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
788 }
789
790
791
792 void wxHtmlWidgetCell::DrawInvisible(wxDC& dc, int x, int y)
793 {
794 int absx = 0, absy = 0, stx, sty;
795 wxHtmlCell *c = this;
796
797 while (c)
798 {
799 absx += c->GetPosX();
800 absy += c->GetPosY();
801 c = c->GetParent();
802 }
803
804 ((wxScrolledWindow*)(m_Wnd->GetParent()))->ViewStart(&stx, &sty);
805 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
806
807 wxHtmlCell::DrawInvisible(dc, x, y);
808 }
809
810
811
812 void wxHtmlWidgetCell::Layout(int w)
813 {
814 if (m_WidthFloat != 0)
815 {
816 m_Width = (w * m_WidthFloat) / 100;
817 m_Wnd->SetSize(m_Width, m_Height);
818 }
819
820 wxHtmlCell::Layout(w);
821 }
822
823 #endif