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