fixed UpdateRenderingState to do what it was meant to
[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 "htmlcell.h"
12 #endif
13
14 #include "wx/wxprec.h"
15
16 #include "wx/defs.h"
17
18 #if wxUSE_HTML && wxUSE_STREAMS
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WXPRECOMP
25 #include "wx/brush.h"
26 #include "wx/colour.h"
27 #include "wx/dc.h"
28 #endif
29
30 #include "wx/html/htmlcell.h"
31 #include "wx/html/htmlwin.h"
32 #include "wx/settings.h"
33 #include <stdlib.h>
34
35
36 //-----------------------------------------------------------------------------
37 // wxHtmlCell
38 //-----------------------------------------------------------------------------
39
40 wxHtmlCell::wxHtmlCell() : wxObject()
41 {
42 m_Next = NULL;
43 m_Parent = NULL;
44 m_Width = m_Height = m_Descent = 0;
45 m_CanLiveOnPagebreak = TRUE;
46 m_Link = NULL;
47 }
48
49 wxHtmlCell::~wxHtmlCell()
50 {
51 delete m_Link;
52 }
53
54
55 void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y,
56 const wxMouseEvent& event)
57 {
58 wxHtmlLinkInfo *lnk = GetLink(x, y);
59 if (lnk != NULL)
60 {
61 wxHtmlLinkInfo lnk2(*lnk);
62 lnk2.SetEvent(&event);
63 lnk2.SetHtmlCell(this);
64
65 // note : this cast is legal because parent is *always* wxHtmlWindow
66 wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2);
67 }
68 }
69
70
71
72 bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const
73 {
74 if ((!m_CanLiveOnPagebreak) &&
75 m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
76 {
77 *pagebreak = m_PosY;
78 return TRUE;
79 }
80
81 return FALSE;
82 }
83
84
85
86 void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
87 {
88 if (m_Link) delete m_Link;
89 m_Link = NULL;
90 if (link.GetHref() != wxEmptyString)
91 m_Link = new wxHtmlLinkInfo(link);
92 }
93
94
95
96 void wxHtmlCell::Layout(int WXUNUSED(w))
97 {
98 SetPos(0, 0);
99 }
100
101
102
103 void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const
104 {
105 if (left)
106 *left = m_PosX;
107 if (right)
108 *right = m_PosX + m_Width;
109 }
110
111
112
113 const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const
114 {
115 return NULL;
116 }
117
118
119 wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y,
120 unsigned flags) const
121 {
122 if ( (flags & wxHTML_FIND_TERMINAL) &&
123 x >= 0 && x < m_Width && y >= 0 && y < m_Height )
124 {
125 return wxConstCast(this, wxHtmlCell);
126 }
127 return NULL;
128 }
129
130
131 //-----------------------------------------------------------------------------
132 // wxHtmlWordCell
133 //-----------------------------------------------------------------------------
134
135 wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
136 {
137 m_Word = word;
138 dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
139 SetCanLiveOnPagebreak(FALSE);
140 }
141
142
143
144 void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
145 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
146 wxHtmlRenderingState& state)
147 {
148 if (state.GetSelectionState() == wxHTML_SEL_IN &&
149 dc.GetBackgroundMode() != wxSOLID)
150 {
151 dc.SetBackgroundMode(wxSOLID);
152 dc.SetTextBackground(
153 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
154 dc.SetTextForeground(
155 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
156 }
157 else if (state.GetSelectionState() == wxHTML_SEL_OUT &&
158 dc.GetBackgroundMode() == wxSOLID)
159 {
160 dc.SetBackgroundMode(wxTRANSPARENT);
161 dc.SetTextForeground(state.GetFgColour());
162 dc.SetTextBackground(state.GetBgColour());
163 }
164
165 dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
166 }
167
168
169
170 //-----------------------------------------------------------------------------
171 // wxHtmlContainerCell
172 //-----------------------------------------------------------------------------
173
174
175 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
176 {
177 m_Cells = m_LastCell = NULL;
178 m_Parent = parent;
179 if (m_Parent) m_Parent->InsertCell(this);
180 m_AlignHor = wxHTML_ALIGN_LEFT;
181 m_AlignVer = wxHTML_ALIGN_BOTTOM;
182 m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
183 m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
184 m_UseBkColour = FALSE;
185 m_UseBorder = FALSE;
186 m_MinHeight = 0;
187 m_MinHeightAlign = wxHTML_ALIGN_TOP;
188 m_LastLayout = -1;
189 }
190
191 wxHtmlContainerCell::~wxHtmlContainerCell()
192 {
193 wxHtmlCell *cell = m_Cells;
194 while ( cell )
195 {
196 wxHtmlCell *cellNext = cell->GetNext();
197 delete cell;
198 cell = cellNext;
199 }
200 }
201
202
203
204 void wxHtmlContainerCell::SetIndent(int i, int what, int units)
205 {
206 int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
207 if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
208 if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
209 if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
210 if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
211 m_LastLayout = -1;
212 }
213
214
215
216 int wxHtmlContainerCell::GetIndent(int ind) const
217 {
218 if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
219 else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
220 else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
221 else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
222 else return -1; /* BUG! Should not be called... */
223 }
224
225
226
227
228 int wxHtmlContainerCell::GetIndentUnits(int ind) const
229 {
230 bool p = FALSE;
231 if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
232 else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
233 else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
234 else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
235 if (p) return wxHTML_UNITS_PERCENT;
236 else return wxHTML_UNITS_PIXELS;
237 }
238
239
240
241 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const
242 {
243 if (!m_CanLiveOnPagebreak)
244 return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages);
245
246 else
247 {
248 wxHtmlCell *c = GetFirstCell();
249 bool rt = FALSE;
250 int pbrk = *pagebreak - m_PosY;
251
252 while (c)
253 {
254 if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages))
255 rt = TRUE;
256 c = c->GetNext();
257 }
258 if (rt)
259 *pagebreak = pbrk + m_PosY;
260 return rt;
261 }
262 }
263
264
265
266 void wxHtmlContainerCell::Layout(int w)
267 {
268 wxHtmlCell::Layout(w);
269
270 if (m_LastLayout == w) return;
271
272 // VS: Any attempt to layout with negative or zero width leads to hell,
273 // but we can't ignore such attempts completely, since it sometimes
274 // happen (e.g. when trying how small a table can be). The best thing we
275 // can do is to set the width of child cells to zero
276 if (w < 1)
277 {
278 m_Width = 0;
279 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
280 cell->Layout(0);
281 // this does two things: it recursively calls this code on all
282 // child contrainers and resets children's position to (0,0)
283 return;
284 }
285
286 wxHtmlCell *cell = m_Cells, *line = m_Cells;
287 long xpos = 0, ypos = m_IndentTop;
288 int xdelta = 0, ybasicpos = 0, ydiff;
289 int s_width, s_indent;
290 int ysizeup = 0, ysizedown = 0;
291 int MaxLineWidth = 0;
292 int xcnt = 0;
293
294
295 /*
296
297 WIDTH ADJUSTING :
298
299 */
300
301 if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
302 {
303 if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
304 else m_Width = m_WidthFloat * w / 100;
305 }
306 else
307 {
308 if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
309 else m_Width = m_WidthFloat;
310 }
311
312 if (m_Cells)
313 {
314 int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
315 int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
316 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
317 cell->Layout(m_Width - (l + r));
318 }
319
320 /*
321
322 LAYOUTING :
323
324 */
325
326 // adjust indentation:
327 s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
328 s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
329
330 // my own layouting:
331 while (cell != NULL)
332 {
333 switch (m_AlignVer)
334 {
335 case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
336 case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
337 case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
338 }
339 ydiff = cell->GetHeight() + ybasicpos;
340
341 if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
342 if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
343
344 cell->SetPos(xpos, ybasicpos + cell->GetDescent());
345 xpos += cell->GetWidth();
346 cell = cell->GetNext();
347 xcnt++;
348
349 // force new line if occured:
350 if ((cell == NULL) || (xpos + cell->GetWidth() > s_width))
351 {
352 if (xpos > MaxLineWidth) MaxLineWidth = xpos;
353 if (ysizeup < 0) ysizeup = 0;
354 if (ysizedown < 0) ysizedown = 0;
355 switch (m_AlignHor) {
356 case wxHTML_ALIGN_LEFT :
357 case wxHTML_ALIGN_JUSTIFY :
358 xdelta = 0;
359 break;
360 case wxHTML_ALIGN_RIGHT :
361 xdelta = 0 + (s_width - xpos);
362 break;
363 case wxHTML_ALIGN_CENTER :
364 xdelta = 0 + (s_width - xpos) / 2;
365 break;
366 }
367 if (xdelta < 0) xdelta = 0;
368 xdelta += s_indent;
369
370 ypos += ysizeup;
371
372 if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
373 while (line != cell)
374 {
375 line->SetPos(line->GetPosX() + xdelta,
376 ypos + line->GetPosY());
377 line = line->GetNext();
378 }
379 else
380 {
381 int counter = 0;
382 int step = (s_width - xpos);
383 if (step < 0) step = 0;
384 xcnt--;
385 if (xcnt > 0) while (line != cell)
386 {
387 line->SetPos(line->GetPosX() + s_indent +
388 (counter++ * step / xcnt),
389 ypos + line->GetPosY());
390 line = line->GetNext();
391 }
392 xcnt++;
393 }
394
395 ypos += ysizedown;
396 xpos = xcnt = 0;
397 ysizeup = ysizedown = 0;
398 line = cell;
399 }
400 }
401
402 // setup height & width, depending on container layout:
403 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
404
405 if (m_Height < m_MinHeight)
406 {
407 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
408 {
409 int diff = m_MinHeight - m_Height;
410 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
411 cell = m_Cells;
412 while (cell)
413 {
414 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
415 cell = cell->GetNext();
416 }
417 }
418 m_Height = m_MinHeight;
419 }
420
421 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
422 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
423
424 m_LastLayout = w;
425 }
426
427 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingState& state,
428 wxHtmlCell *cell) const
429 {
430 wxHtmlSelection *s = state.GetSelection();
431 if (!s) return;
432 if (s->GetFromCell() == cell || s->GetToCell() == cell)
433 {
434 state.SetSelectionState(wxHTML_SEL_CHANGING);
435 }
436 }
437
438 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingState& state,
439 wxHtmlCell *cell) const
440 {
441 wxHtmlSelection *s = state.GetSelection();
442 if (!s) return;
443 if (s->GetFromCell() == cell)
444 state.SetSelectionState(wxHTML_SEL_IN);
445 else if (s->GetToCell() == cell)
446 state.SetSelectionState(wxHTML_SEL_OUT);
447 }
448
449 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
450 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
451
452 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
453 wxHtmlRenderingState& state)
454 {
455 // container visible, draw it:
456 if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1))
457 {
458 if (m_UseBkColour)
459 {
460 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
461
462 int real_y1 = mMax(y + m_PosY, view_y1);
463 int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2);
464
465 dc.SetBrush(myb);
466 dc.SetPen(*wxTRANSPARENT_PEN);
467 dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1);
468 }
469
470 if (m_UseBorder)
471 {
472 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
473 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
474
475 dc.SetPen(mypen1);
476 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1);
477 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY);
478 dc.SetPen(mypen2);
479 dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
480 dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1);
481 }
482
483 if (m_Cells)
484 {
485 // draw container's contents:
486 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
487 {
488 UpdateRenderingStatePre(state, cell);
489 cell->Draw(dc,
490 x + m_PosX, y + m_PosY, view_y1, view_y2,
491 state);
492 UpdateRenderingStatePost(state, cell);
493 }
494 }
495 }
496 // container invisible, just proceed font+color changing:
497 else
498 {
499 DrawInvisible(dc, x, y, state);
500 }
501 }
502
503
504
505 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
506 wxHtmlRenderingState& state)
507 {
508 if (m_Cells)
509 {
510 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
511 {
512 UpdateRenderingStatePre(state, cell);
513 cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, state);
514 UpdateRenderingStatePost(state, cell);
515 }
516 }
517 }
518
519
520 wxColour wxHtmlContainerCell::GetBackgroundColour()
521 {
522 if (m_UseBkColour)
523 return m_BkColour;
524 else
525 return wxNullColour;
526 }
527
528
529
530 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
531 {
532 wxHtmlCell *cell = FindCellByPos(x, y);
533
534 // VZ: I don't know if we should pass absolute or relative coords to
535 // wxHtmlCell::GetLink()? As the base class version just ignores them
536 // anyhow, it hardly matters right now but should still be clarified
537 return cell ? cell->GetLink(x, y) : NULL;
538 }
539
540
541
542 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
543 {
544 if (!m_Cells) m_Cells = m_LastCell = f;
545 else
546 {
547 m_LastCell->SetNext(f);
548 m_LastCell = f;
549 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
550 }
551 f->SetParent(this);
552 m_LastLayout = -1;
553 }
554
555
556
557 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
558 {
559 if (tag.HasParam(wxT("ALIGN")))
560 {
561 wxString alg = tag.GetParam(wxT("ALIGN"));
562 alg.MakeUpper();
563 if (alg == wxT("CENTER"))
564 SetAlignHor(wxHTML_ALIGN_CENTER);
565 else if (alg == wxT("LEFT"))
566 SetAlignHor(wxHTML_ALIGN_LEFT);
567 else if (alg == wxT("JUSTIFY"))
568 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
569 else if (alg == wxT("RIGHT"))
570 SetAlignHor(wxHTML_ALIGN_RIGHT);
571 m_LastLayout = -1;
572 }
573 }
574
575
576
577 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
578 {
579 if (tag.HasParam(wxT("WIDTH")))
580 {
581 int wdi;
582 wxString wd = tag.GetParam(wxT("WIDTH"));
583
584 if (wd[wd.Length()-1] == wxT('%'))
585 {
586 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
587 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
588 }
589 else
590 {
591 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
592 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
593 }
594 m_LastLayout = -1;
595 }
596 }
597
598
599
600 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
601 {
602 if (m_Cells)
603 {
604 const wxHtmlCell *r = NULL;
605
606 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
607 {
608 r = cell->Find(condition, param);
609 if (r) return r;
610 }
611 }
612 return NULL;
613 }
614
615
616 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
617 unsigned flags) const
618 {
619 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
620 {
621 int cx = cell->GetPosX(),
622 cy = cell->GetPosY();
623
624 if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
625 (cy <= y) && (cy + cell->GetHeight() > y) )
626 {
627 wxHtmlCell *c = cell->FindCellByPos(x - cx, y - cy, flags);
628 if (c == NULL && (flags & wxHTML_FIND_NONTERMINAL))
629 return wxConstCast(this, wxHtmlContainerCell);
630 else
631 return c;
632 }
633 }
634
635 return (flags & wxHTML_FIND_NONTERMINAL) ?
636 wxConstCast(this, wxHtmlContainerCell) : NULL;
637 }
638
639
640 void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event)
641 {
642 wxHtmlCell *cell = FindCellByPos(x, y);
643 if ( cell )
644 cell->OnMouseClick(parent, x, y, event);
645 }
646
647
648
649 void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const
650 {
651 int cleft = m_PosX + m_Width, cright = m_PosX; // worst case
652 int l, r;
653
654 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
655 {
656 cell->GetHorizontalConstraints(&l, &r);
657 if (l < cleft)
658 cleft = l;
659 if (r > cright)
660 cright = r;
661 }
662
663 cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
664 cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
665
666 if (left)
667 *left = cleft;
668 if (right)
669 *right = cright;
670 }
671
672
673
674
675
676 // --------------------------------------------------------------------------
677 // wxHtmlColourCell
678 // --------------------------------------------------------------------------
679
680 void wxHtmlColourCell::Draw(wxDC& dc,
681 int x, int y,
682 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
683 wxHtmlRenderingState& state)
684 {
685 DrawInvisible(dc, x, y, state);
686 }
687
688 void wxHtmlColourCell::DrawInvisible(wxDC& dc,
689 int WXUNUSED(x), int WXUNUSED(y),
690 wxHtmlRenderingState& state)
691 {
692 if (m_Flags & wxHTML_CLR_FOREGROUND)
693 {
694 state.SetFgColour(m_Colour);
695 if (state.GetSelectionState() != wxHTML_SEL_IN)
696 dc.SetTextForeground(m_Colour);
697 }
698 if (m_Flags & wxHTML_CLR_BACKGROUND)
699 {
700 state.SetBgColour(m_Colour);
701 if (state.GetSelectionState() != wxHTML_SEL_IN)
702 dc.SetTextBackground(m_Colour);
703 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
704 }
705 }
706
707
708
709
710 // ---------------------------------------------------------------------------
711 // wxHtmlFontCell
712 // ---------------------------------------------------------------------------
713
714 void wxHtmlFontCell::Draw(wxDC& dc,
715 int WXUNUSED(x), int WXUNUSED(y),
716 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
717 wxHtmlRenderingState& WXUNUSED(state))
718 {
719 dc.SetFont(m_Font);
720 }
721
722 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
723 wxHtmlRenderingState& WXUNUSED(state))
724 {
725 dc.SetFont(m_Font);
726 }
727
728
729
730
731
732
733
734
735 // ---------------------------------------------------------------------------
736 // wxHtmlWidgetCell
737 // ---------------------------------------------------------------------------
738
739 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
740 {
741 int sx, sy;
742 m_Wnd = wnd;
743 m_Wnd->GetSize(&sx, &sy);
744 m_Width = sx, m_Height = sy;
745 m_WidthFloat = w;
746 }
747
748
749 void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
750 int WXUNUSED(x), int WXUNUSED(y),
751 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
752 wxHtmlRenderingState& WXUNUSED(state))
753 {
754 int absx = 0, absy = 0, stx, sty;
755 wxHtmlCell *c = this;
756
757 while (c)
758 {
759 absx += c->GetPosX();
760 absy += c->GetPosY();
761 c = c->GetParent();
762 }
763
764 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
765 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
766 }
767
768
769
770 void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
771 int WXUNUSED(x), int WXUNUSED(y),
772 wxHtmlRenderingState& WXUNUSED(state))
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()))->GetViewStart(&stx, &sty);
785 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
786 }
787
788
789
790 void wxHtmlWidgetCell::Layout(int w)
791 {
792 if (m_WidthFloat != 0)
793 {
794 m_Width = (w * m_WidthFloat) / 100;
795 m_Wnd->SetSize(m_Width, m_Height);
796 }
797
798 wxHtmlCell::Layout(w);
799 }
800
801 #endif