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