1. added abstract interface to wxHtmlWindow for use by wxHtmlWinParser and implemente...
[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 #include "wx/wxprec.h"
11
12 #include "wx/defs.h"
13
14 #if wxUSE_HTML && wxUSE_STREAMS
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WXPRECOMP
21 #include "wx/brush.h"
22 #include "wx/colour.h"
23 #include "wx/dc.h"
24 #endif
25
26 #include "wx/html/htmlcell.h"
27 #include "wx/html/htmlwin.h"
28 #include "wx/settings.h"
29 #include "wx/module.h"
30 #include "wx/dynarray.h"
31
32 #include <stdlib.h>
33
34 //-----------------------------------------------------------------------------
35 // Global variables
36 //-----------------------------------------------------------------------------
37
38 static wxCursor *gs_cursorLink = NULL;
39 static wxCursor *gs_cursorText = NULL;
40
41
42 //-----------------------------------------------------------------------------
43 // Helper classes
44 //-----------------------------------------------------------------------------
45
46 void wxHtmlSelection::Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
47 const wxPoint& toPos, const wxHtmlCell *toCell)
48 {
49 m_fromCell = fromCell;
50 m_toCell = toCell;
51 m_fromPos = fromPos;
52 m_toPos = toPos;
53 }
54
55 void wxHtmlSelection::Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell)
56 {
57 wxPoint p1 = fromCell ? fromCell->GetAbsPos() : wxDefaultPosition;
58 wxPoint p2 = toCell ? toCell->GetAbsPos() : wxDefaultPosition;
59 if ( toCell )
60 {
61 p2.x += toCell->GetWidth();
62 p2.y += toCell->GetHeight();
63 }
64 Set(p1, fromCell, p2, toCell);
65 }
66
67 wxColour
68 wxDefaultHtmlRenderingStyle::
69 GetSelectedTextColour(const wxColour& WXUNUSED(clr))
70 {
71 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
72 }
73
74 wxColour
75 wxDefaultHtmlRenderingStyle::
76 GetSelectedTextBgColour(const wxColour& WXUNUSED(clr))
77 {
78 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
79 }
80
81
82 //-----------------------------------------------------------------------------
83 // wxHtmlCell
84 //-----------------------------------------------------------------------------
85
86 IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell, wxObject)
87
88 wxHtmlCell::wxHtmlCell() : wxObject()
89 {
90 m_Next = NULL;
91 m_Parent = NULL;
92 m_Width = m_Height = m_Descent = 0;
93 m_ScriptMode = wxHTML_SCRIPT_NORMAL; // <sub> or <sup> mode
94 m_ScriptBaseline = 0; // <sub> or <sup> baseline
95 m_CanLiveOnPagebreak = true;
96 m_Link = NULL;
97 }
98
99 wxHtmlCell::~wxHtmlCell()
100 {
101 delete m_Link;
102 }
103
104 // Update the descent value when whe are in a <sub> or <sup>.
105 // prevbase is the parent base
106 void wxHtmlCell::SetScriptMode(wxHtmlScriptMode mode, long previousBase)
107 {
108 m_ScriptMode = mode;
109
110 if (mode == wxHTML_SCRIPT_SUP)
111 m_ScriptBaseline = previousBase - (m_Height + 1) / 2;
112 else if (mode == wxHTML_SCRIPT_SUB)
113 m_ScriptBaseline = previousBase + (m_Height + 1) / 6;
114 else
115 m_ScriptBaseline = 0;
116
117 m_Descent += m_ScriptBaseline;
118 }
119
120 #if WXWIN_COMPATIBILITY_2_6
121
122 struct wxHtmlCellOnMouseClickCompatHelper;
123
124 static wxHtmlCellOnMouseClickCompatHelper *gs_helperOnMouseClick = NULL;
125
126 // helper for routing calls to new ProcessMouseClick() method to deprecated
127 // OnMouseClick() method
128 struct wxHtmlCellOnMouseClickCompatHelper
129 {
130 wxHtmlCellOnMouseClickCompatHelper(wxHtmlWindowInterface *window_,
131 const wxPoint& pos_,
132 const wxMouseEvent& event_)
133 : window(window_), pos(pos_), event(event_), retval(false)
134 {
135 }
136
137 bool CallOnMouseClick(wxHtmlCell *cell)
138 {
139 wxHtmlCellOnMouseClickCompatHelper *oldHelper = gs_helperOnMouseClick;
140 gs_helperOnMouseClick = this;
141 cell->OnMouseClick
142 (
143 window ? window->GetHTMLWindow() : NULL,
144 pos.x, pos.y,
145 event
146 );
147 gs_helperOnMouseClick = oldHelper;
148 return retval;
149 }
150
151 wxHtmlWindowInterface *window;
152 const wxPoint& pos;
153 const wxMouseEvent& event;
154 bool retval;
155 };
156 #endif // WXWIN_COMPATIBILITY_2_6
157
158 bool wxHtmlCell::ProcessMouseClick(wxHtmlWindowInterface *window,
159 const wxPoint& pos,
160 const wxMouseEvent& event)
161 {
162 wxCHECK_MSG( window, false, _T("window interface must be provided") );
163
164 #if WXWIN_COMPATIBILITY_2_6
165 // NB: this hack puts the body of ProcessMouseClick() into OnMouseClick()
166 // (for which it has to pass the arguments and return value via a
167 // helper variable because these two methods have different
168 // signatures), so that old code overriding OnMouseClick will continue
169 // to work
170 wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event);
171 return compat.CallOnMouseClick(this);
172 }
173
174 void wxHtmlCell::OnMouseClick(wxWindow *, int, int, const wxMouseEvent& event)
175 {
176 wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") );
177 wxHtmlWindowInterface *window = gs_helperOnMouseClick->window;
178 const wxPoint& pos = gs_helperOnMouseClick->pos;
179 #endif // WXWIN_COMPATIBILITY_2_6
180
181 wxHtmlLinkInfo *lnk = GetLink(pos.x, pos.y);
182 bool retval = false;
183
184 if (lnk)
185 {
186 wxHtmlLinkInfo lnk2(*lnk);
187 lnk2.SetEvent(&event);
188 lnk2.SetHtmlCell(this);
189
190 window->OnHTMLLinkClicked(lnk2);
191 retval = true;
192 }
193
194 #if WXWIN_COMPATIBILITY_2_6
195 gs_helperOnMouseClick->retval = retval;
196 #else
197 return retval;
198 #endif // WXWIN_COMPATIBILITY_2_6
199 }
200
201
202 wxCursor wxHtmlCell::GetCursor() const
203 {
204 if ( GetLink() )
205 {
206 if ( !gs_cursorLink )
207 gs_cursorLink = new wxCursor(wxCURSOR_HAND);
208 return *gs_cursorLink;
209 }
210 else
211 return *wxSTANDARD_CURSOR;
212 }
213
214
215 bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const
216 {
217 if ((!m_CanLiveOnPagebreak) &&
218 m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
219 {
220 *pagebreak = m_PosY;
221 return true;
222 }
223
224 return false;
225 }
226
227
228
229 void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
230 {
231 if (m_Link) delete m_Link;
232 m_Link = NULL;
233 if (link.GetHref() != wxEmptyString)
234 m_Link = new wxHtmlLinkInfo(link);
235 }
236
237
238 void wxHtmlCell::Layout(int WXUNUSED(w))
239 {
240 SetPos(0, 0);
241 }
242
243
244
245 const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const
246 {
247 return NULL;
248 }
249
250
251 wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y,
252 unsigned flags) const
253 {
254 if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height )
255 {
256 return wxConstCast(this, wxHtmlCell);
257 }
258 else
259 {
260 if ((flags & wxHTML_FIND_NEAREST_AFTER) &&
261 (y < 0 || (y < 0+m_Height && x < 0+m_Width)))
262 return wxConstCast(this, wxHtmlCell);
263 else if ((flags & wxHTML_FIND_NEAREST_BEFORE) &&
264 (y >= 0+m_Height || (y >= 0 && x >= 0)))
265 return wxConstCast(this, wxHtmlCell);
266 else
267 return NULL;
268 }
269 }
270
271
272 wxPoint wxHtmlCell::GetAbsPos(wxHtmlCell *rootCell) const
273 {
274 wxPoint p(m_PosX, m_PosY);
275 for (wxHtmlCell *parent = m_Parent; parent && parent != rootCell;
276 parent = parent->m_Parent)
277 {
278 p.x += parent->m_PosX;
279 p.y += parent->m_PosY;
280 }
281 return p;
282 }
283
284 wxHtmlCell *wxHtmlCell::GetRootCell() const
285 {
286 wxHtmlCell *c = wxConstCast(this, wxHtmlCell);
287 while ( c->m_Parent )
288 c = c->m_Parent;
289 return c;
290 }
291
292 unsigned wxHtmlCell::GetDepth() const
293 {
294 unsigned d = 0;
295 for (wxHtmlCell *p = m_Parent; p; p = p->m_Parent)
296 d++;
297 return d;
298 }
299
300 bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const
301 {
302 const wxHtmlCell *c1 = this;
303 const wxHtmlCell *c2 = cell;
304 unsigned d1 = GetDepth();
305 unsigned d2 = cell->GetDepth();
306
307 if ( d1 > d2 )
308 for (; d1 != d2; d1-- )
309 c1 = c1->m_Parent;
310 else if ( d1 < d2 )
311 for (; d1 != d2; d2-- )
312 c2 = c2->m_Parent;
313
314 if ( cell == this )
315 return true;
316
317 while ( c1 && c2 )
318 {
319 if ( c1->m_Parent == c2->m_Parent )
320 {
321 while ( c1 )
322 {
323 if ( c1 == c2 )
324 return true;
325 c1 = c1->GetNext();
326 }
327 return false;
328 }
329 else
330 {
331 c1 = c1->m_Parent;
332 c2 = c2->m_Parent;
333 }
334 }
335
336 wxFAIL_MSG(_T("Cells are in different trees"));
337 return false;
338 }
339
340
341 //-----------------------------------------------------------------------------
342 // wxHtmlWordCell
343 //-----------------------------------------------------------------------------
344
345 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell)
346
347 wxHtmlWordCell::wxHtmlWordCell(const wxString& word, const wxDC& dc) : wxHtmlCell()
348 {
349 m_Word = word;
350 dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
351 SetCanLiveOnPagebreak(false);
352 m_allowLinebreak = true;
353 }
354
355 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell)
356 {
357 if ( cell && m_Parent == cell->m_Parent &&
358 !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) )
359 {
360 m_allowLinebreak = false;
361 }
362 }
363
364 // Splits m_Word into up to three parts according to selection, returns
365 // substring before, in and after selection and the points (in relative coords)
366 // where s2 and s3 start:
367 void wxHtmlWordCell::Split(const wxDC& dc,
368 const wxPoint& selFrom, const wxPoint& selTo,
369 unsigned& pos1, unsigned& pos2) const
370 {
371 wxPoint pt1 = (selFrom == wxDefaultPosition) ?
372 wxDefaultPosition : selFrom - GetAbsPos();
373 wxPoint pt2 = (selTo == wxDefaultPosition) ?
374 wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos();
375
376 unsigned len = m_Word.length();
377 unsigned i = 0;
378 pos1 = 0;
379
380 // adjust for cases when the start/end position is completely
381 // outside the cell:
382 if ( pt1.y < 0 )
383 pt1.x = 0;
384 if ( pt2.y >= m_Height )
385 pt2.x = m_Width;
386
387 // before selection:
388 #ifdef __WXMAC__
389 // implementation using PartialExtents to support fractional widths
390 wxArrayInt widths ;
391 dc.GetPartialTextExtents(m_Word,widths) ;
392 while( i < len && pt1.x >= widths[i] )
393 i++ ;
394 #else // __WXMAC__
395 wxCoord charW, charH;
396 while ( pt1.x > 0 && i < len )
397 {
398 dc.GetTextExtent(m_Word[i], &charW, &charH);
399 pt1.x -= charW;
400 if ( pt1.x >= 0 )
401 {
402 pos1 += charW;
403 i++;
404 }
405 }
406 #endif // __WXMAC__/!__WXMAC__
407
408 // in selection:
409 unsigned j = i;
410 #ifdef __WXMAC__
411 while( j < len && pt2.x >= widths[j] )
412 j++ ;
413 #else // __WXMAC__
414 pos2 = pos1;
415 pt2.x -= pos2;
416 while ( pt2.x > 0 && j < len )
417 {
418 dc.GetTextExtent(m_Word[j], &charW, &charH);
419 pt2.x -= charW;
420 if ( pt2.x >= 0 )
421 {
422 pos2 += charW;
423 j++;
424 }
425 }
426 #endif // __WXMAC__/!__WXMAC__
427
428 pos1 = i;
429 pos2 = j;
430 }
431
432 void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const
433 {
434 unsigned p1, p2;
435
436 Split(dc,
437 this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition,
438 this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
439 p1, p2);
440
441 wxPoint p(0, m_Word.length());
442
443 if ( this == s->GetFromCell() )
444 p.x = p1; // selection starts here
445 if ( this == s->GetToCell() )
446 p.y = p2; // selection ends here
447
448 if ( this == s->GetFromCell() )
449 s->SetFromPrivPos(p);
450 if ( this == s->GetToCell() )
451 s->SetToPrivPos(p);
452 }
453
454
455 static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
456 bool toSelection)
457 {
458 wxColour fg = info.GetState().GetFgColour();
459 wxColour bg = info.GetState().GetBgColour();
460
461 if ( toSelection )
462 {
463 dc.SetBackgroundMode(wxSOLID);
464 dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg));
465 dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg));
466 dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg),
467 wxSOLID));
468 }
469 else
470 {
471 dc.SetBackgroundMode(wxTRANSPARENT);
472 dc.SetTextForeground(fg);
473 dc.SetTextBackground(bg);
474 dc.SetBackground(wxBrush(bg, wxSOLID));
475 }
476 }
477
478
479 void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
480 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
481 wxHtmlRenderingInfo& info)
482 {
483 #if 0 // useful for debugging
484 dc.SetPen(*wxBLACK_PEN);
485 dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height);
486 #endif
487
488 bool drawSelectionAfterCell = false;
489
490 if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
491 {
492 // Selection changing, we must draw the word piecewise:
493 wxHtmlSelection *s = info.GetSelection();
494 wxString txt;
495 int w, h;
496 int ofs = 0;
497
498 wxPoint priv = (this == s->GetFromCell()) ?
499 s->GetFromPrivPos() : s->GetToPrivPos();
500
501 // NB: this is quite a hack: in order to compute selection boundaries
502 // (in word's characters) we must know current font, which is only
503 // possible inside rendering code. Therefore we update the
504 // information here and store it in wxHtmlSelection so that
505 // ConvertToText can use it later:
506 if ( priv == wxDefaultPosition )
507 {
508 SetSelectionPrivPos(dc, s);
509 priv = (this == s->GetFromCell()) ?
510 s->GetFromPrivPos() : s->GetToPrivPos();
511 }
512
513 int part1 = priv.x;
514 int part2 = priv.y;
515
516 if ( part1 > 0 )
517 {
518 txt = m_Word.Mid(0, part1);
519 dc.DrawText(txt, x + m_PosX, y + m_PosY);
520 dc.GetTextExtent(txt, &w, &h);
521 ofs += w;
522 }
523
524 SwitchSelState(dc, info, true);
525
526 txt = m_Word.Mid(part1, part2-part1);
527 dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
528
529 if ( (size_t)part2 < m_Word.length() )
530 {
531 dc.GetTextExtent(txt, &w, &h);
532 ofs += w;
533 SwitchSelState(dc, info, false);
534 txt = m_Word.Mid(part2);
535 dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
536 }
537 else
538 drawSelectionAfterCell = true;
539 }
540 else
541 {
542 wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
543 // Not changing selection state, draw the word in single mode:
544 if ( selstate != wxHTML_SEL_OUT &&
545 dc.GetBackgroundMode() != wxSOLID )
546 {
547 SwitchSelState(dc, info, true);
548 }
549 else if ( selstate == wxHTML_SEL_OUT &&
550 dc.GetBackgroundMode() == wxSOLID )
551 {
552 SwitchSelState(dc, info, false);
553 }
554 dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
555 drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
556 }
557
558 // NB: If the text is justified then there is usually some free space
559 // between adjacent cells and drawing the selection only onto cells
560 // would result in ugly unselected spaces. The code below detects
561 // this special case and renders the selection *outside* the sell,
562 // too.
563 if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY &&
564 drawSelectionAfterCell )
565 {
566 wxHtmlCell *nextCell = m_Next;
567 while ( nextCell && nextCell->IsFormattingCell() )
568 nextCell = nextCell->GetNext();
569 if ( nextCell )
570 {
571 int nextX = nextCell->GetPosX();
572 if ( m_PosX + m_Width < nextX )
573 {
574 dc.SetBrush(dc.GetBackground());
575 dc.SetPen(*wxTRANSPARENT_PEN);
576 dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY,
577 nextX - m_PosX - m_Width, m_Height);
578 }
579 }
580 }
581 }
582
583
584 wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
585 {
586 if ( s && (this == s->GetFromCell() || this == s->GetToCell()) )
587 {
588 wxPoint priv = this == s->GetFromCell() ? s->GetFromPrivPos()
589 : s->GetToPrivPos();
590
591 // VZ: we may be called before we had a chance to re-render ourselves
592 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
593 // that this only happens in case of a double/triple click (which
594 // seems to be the case now) and so it makes sense to select the
595 // entire contents of the cell in this case
596 //
597 // TODO: but this really needs to be fixed in some better way later...
598 if ( priv != wxDefaultPosition )
599 {
600 int part1 = priv.x;
601 int part2 = priv.y;
602 return m_Word.Mid(part1, part2-part1);
603 }
604 //else: return the whole word below
605 }
606
607 return m_Word;
608 }
609
610 wxCursor wxHtmlWordCell::GetCursor() const
611 {
612 if ( !GetLink() )
613 {
614 if ( !gs_cursorText )
615 gs_cursorText = new wxCursor(wxCURSOR_IBEAM);
616 return *gs_cursorText;
617 }
618 else
619 return wxHtmlCell::GetCursor();
620 }
621
622
623 //-----------------------------------------------------------------------------
624 // wxHtmlContainerCell
625 //-----------------------------------------------------------------------------
626
627 IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell)
628
629 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
630 {
631 m_Cells = m_LastCell = NULL;
632 m_Parent = parent;
633 m_MaxTotalWidth = 0;
634 if (m_Parent) m_Parent->InsertCell(this);
635 m_AlignHor = wxHTML_ALIGN_LEFT;
636 m_AlignVer = wxHTML_ALIGN_BOTTOM;
637 m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
638 m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
639 m_UseBkColour = false;
640 m_UseBorder = false;
641 m_MinHeight = 0;
642 m_MinHeightAlign = wxHTML_ALIGN_TOP;
643 m_LastLayout = -1;
644 }
645
646 wxHtmlContainerCell::~wxHtmlContainerCell()
647 {
648 wxHtmlCell *cell = m_Cells;
649 while ( cell )
650 {
651 wxHtmlCell *cellNext = cell->GetNext();
652 delete cell;
653 cell = cellNext;
654 }
655 }
656
657
658
659 void wxHtmlContainerCell::SetIndent(int i, int what, int units)
660 {
661 int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
662 if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
663 if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
664 if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
665 if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
666 m_LastLayout = -1;
667 }
668
669
670
671 int wxHtmlContainerCell::GetIndent(int ind) const
672 {
673 if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
674 else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
675 else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
676 else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
677 else return -1; /* BUG! Should not be called... */
678 }
679
680
681
682
683 int wxHtmlContainerCell::GetIndentUnits(int ind) const
684 {
685 bool p = false;
686 if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
687 else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
688 else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
689 else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
690 if (p) return wxHTML_UNITS_PERCENT;
691 else return wxHTML_UNITS_PIXELS;
692 }
693
694
695
696 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const
697 {
698 if (!m_CanLiveOnPagebreak)
699 return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages);
700
701 else
702 {
703 wxHtmlCell *c = GetFirstChild();
704 bool rt = false;
705 int pbrk = *pagebreak - m_PosY;
706
707 while (c)
708 {
709 if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages))
710 rt = true;
711 c = c->GetNext();
712 }
713 if (rt)
714 *pagebreak = pbrk + m_PosY;
715 return rt;
716 }
717 }
718
719
720
721 void wxHtmlContainerCell::Layout(int w)
722 {
723 wxHtmlCell::Layout(w);
724
725 if (m_LastLayout == w) return;
726
727 // VS: Any attempt to layout with negative or zero width leads to hell,
728 // but we can't ignore such attempts completely, since it sometimes
729 // happen (e.g. when trying how small a table can be). The best thing we
730 // can do is to set the width of child cells to zero
731 if (w < 1)
732 {
733 m_Width = 0;
734 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
735 cell->Layout(0);
736 // this does two things: it recursively calls this code on all
737 // child contrainers and resets children's position to (0,0)
738 return;
739 }
740
741 wxHtmlCell *nextCell;
742 long xpos = 0, ypos = m_IndentTop;
743 int xdelta = 0, ybasicpos = 0, ydiff;
744 int s_width, nextWordWidth, s_indent;
745 int ysizeup = 0, ysizedown = 0;
746 int MaxLineWidth = 0;
747 int curLineWidth = 0;
748 m_MaxTotalWidth = 0;
749
750
751 /*
752
753 WIDTH ADJUSTING :
754
755 */
756
757 if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
758 {
759 if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
760 else m_Width = m_WidthFloat * w / 100;
761 }
762 else
763 {
764 if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
765 else m_Width = m_WidthFloat;
766 }
767
768 if (m_Cells)
769 {
770 int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
771 int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
772 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
773 cell->Layout(m_Width - (l + r));
774 }
775
776 /*
777
778 LAYOUTING :
779
780 */
781
782 // adjust indentation:
783 s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
784 s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
785
786 // my own layouting:
787 wxHtmlCell *cell = m_Cells,
788 *line = m_Cells;
789 while (cell != NULL)
790 {
791 switch (m_AlignVer)
792 {
793 case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
794 case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
795 case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
796 }
797 ydiff = cell->GetHeight() + ybasicpos;
798
799 if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
800 if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
801
802 // layout nonbreakable run of cells:
803 cell->SetPos(xpos, ybasicpos + cell->GetDescent());
804 xpos += cell->GetWidth();
805 if (!cell->IsTerminalCell())
806 {
807 // Container cell indicates new line
808 if (curLineWidth > m_MaxTotalWidth)
809 m_MaxTotalWidth = curLineWidth;
810
811 if (wxMax(cell->GetWidth(), cell->GetMaxTotalWidth()) > m_MaxTotalWidth)
812 m_MaxTotalWidth = cell->GetMaxTotalWidth();
813 curLineWidth = 0;
814 }
815 else
816 // Normal cell, add maximum cell width to line width
817 curLineWidth += cell->GetMaxTotalWidth();
818
819 cell = cell->GetNext();
820
821 // compute length of the next word that would be added:
822 nextWordWidth = 0;
823 if (cell)
824 {
825 nextCell = cell;
826 do
827 {
828 nextWordWidth += nextCell->GetWidth();
829 nextCell = nextCell->GetNext();
830 } while (nextCell && !nextCell->IsLinebreakAllowed());
831 }
832
833 // force new line if occurred:
834 if ((cell == NULL) ||
835 (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed()))
836 {
837 if (xpos > MaxLineWidth) MaxLineWidth = xpos;
838 if (ysizeup < 0) ysizeup = 0;
839 if (ysizedown < 0) ysizedown = 0;
840 switch (m_AlignHor) {
841 case wxHTML_ALIGN_LEFT :
842 case wxHTML_ALIGN_JUSTIFY :
843 xdelta = 0;
844 break;
845 case wxHTML_ALIGN_RIGHT :
846 xdelta = 0 + (s_width - xpos);
847 break;
848 case wxHTML_ALIGN_CENTER :
849 xdelta = 0 + (s_width - xpos) / 2;
850 break;
851 }
852 if (xdelta < 0) xdelta = 0;
853 xdelta += s_indent;
854
855 ypos += ysizeup;
856
857 if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
858 {
859 while (line != cell)
860 {
861 line->SetPos(line->GetPosX() + xdelta,
862 ypos + line->GetPosY());
863 line = line->GetNext();
864 }
865 }
866 else // align == justify
867 {
868 // we have to distribute the extra horz space between the cells
869 // on this line
870
871 // an added complication is that some cells have fixed size and
872 // shouldn't get any increment (it so happens that these cells
873 // also don't allow line break on them which provides with an
874 // easy way to test for this) -- and neither should the cells
875 // adjacent to them as this could result in a visible space
876 // between two cells separated by, e.g. font change, cell which
877 // is wrong
878
879 int step = s_width - xpos;
880 if ( step > 0 )
881 {
882 // first count the cells which will get extra space
883 int total = 0;
884
885 const wxHtmlCell *c;
886 if ( line != cell )
887 {
888 for ( c = line->GetNext(); c != cell; c = c->GetNext() )
889 {
890 if ( c->IsLinebreakAllowed() )
891 {
892 total++;
893 }
894 }
895 }
896
897 // and now extra space to those cells which merit it
898 if ( total )
899 {
900 // first cell on line is not moved:
901 line->SetPos(line->GetPosX() + s_indent,
902 line->GetPosY() + ypos);
903
904 line = line->GetNext();
905 for ( int n = 0; line != cell; line = line->GetNext() )
906 {
907 if ( line->IsLinebreakAllowed() )
908 {
909 // offset the next cell relative to this one
910 // thus increasing our size
911 n++;
912 }
913
914 line->SetPos(line->GetPosX() + s_indent +
915 ((n * step) / total),
916 line->GetPosY() + ypos);
917 }
918 }
919 else
920 {
921 // this will cause the code to enter "else branch" below:
922 step = 0;
923 }
924 }
925 // else branch:
926 if ( step <= 0 ) // no extra space to distribute
927 {
928 // just set the indent properly
929 while (line != cell)
930 {
931 line->SetPos(line->GetPosX() + s_indent,
932 line->GetPosY() + ypos);
933 line = line->GetNext();
934 }
935 }
936 }
937
938 ypos += ysizedown;
939 xpos = 0;
940 ysizeup = ysizedown = 0;
941 line = cell;
942 }
943 }
944
945 // setup height & width, depending on container layout:
946 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
947
948 if (m_Height < m_MinHeight)
949 {
950 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
951 {
952 int diff = m_MinHeight - m_Height;
953 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
954 cell = m_Cells;
955 while (cell)
956 {
957 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
958 cell = cell->GetNext();
959 }
960 }
961 m_Height = m_MinHeight;
962 }
963
964 if (curLineWidth > m_MaxTotalWidth)
965 m_MaxTotalWidth = curLineWidth;
966
967 m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
968 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
969 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
970
971 m_LastLayout = w;
972 }
973
974 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
975 wxHtmlCell *cell) const
976 {
977 wxHtmlSelection *s = info.GetSelection();
978 if (!s) return;
979 if (s->GetFromCell() == cell || s->GetToCell() == cell)
980 {
981 info.GetState().SetSelectionState(wxHTML_SEL_CHANGING);
982 }
983 }
984
985 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
986 wxHtmlCell *cell) const
987 {
988 wxHtmlSelection *s = info.GetSelection();
989 if (!s) return;
990 if (s->GetToCell() == cell)
991 info.GetState().SetSelectionState(wxHTML_SEL_OUT);
992 else if (s->GetFromCell() == cell)
993 info.GetState().SetSelectionState(wxHTML_SEL_IN);
994 }
995
996 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
997 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
998
999 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
1000 wxHtmlRenderingInfo& info)
1001 {
1002 #if 0 // useful for debugging
1003 dc.SetPen(*wxRED_PEN);
1004 dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height);
1005 #endif
1006
1007 int xlocal = x + m_PosX;
1008 int ylocal = y + m_PosY;
1009
1010 if (m_UseBkColour)
1011 {
1012 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
1013
1014 int real_y1 = mMax(ylocal, view_y1);
1015 int real_y2 = mMin(ylocal + m_Height - 1, view_y2);
1016
1017 dc.SetBrush(myb);
1018 dc.SetPen(*wxTRANSPARENT_PEN);
1019 dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
1020 }
1021
1022 if (m_UseBorder)
1023 {
1024 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
1025 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
1026
1027 dc.SetPen(mypen1);
1028 dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1);
1029 dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal);
1030 dc.SetPen(mypen2);
1031 dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
1032 dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
1033 }
1034
1035 if (m_Cells)
1036 {
1037 // draw container's contents:
1038 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1039 {
1040
1041 // optimize drawing: don't render off-screen content:
1042 if ((ylocal + cell->GetPosY() <= view_y2) &&
1043 (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1))
1044 {
1045 // the cell is visible, draw it:
1046 UpdateRenderingStatePre(info, cell);
1047 cell->Draw(dc,
1048 xlocal, ylocal, view_y1, view_y2,
1049 info);
1050 UpdateRenderingStatePost(info, cell);
1051 }
1052 else
1053 {
1054 // the cell is off-screen, proceed with font+color+etc.
1055 // changes only:
1056 cell->DrawInvisible(dc, xlocal, ylocal, info);
1057 }
1058 }
1059 }
1060 }
1061
1062
1063
1064 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
1065 wxHtmlRenderingInfo& info)
1066 {
1067 if (m_Cells)
1068 {
1069 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1070 {
1071 UpdateRenderingStatePre(info, cell);
1072 cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info);
1073 UpdateRenderingStatePost(info, cell);
1074 }
1075 }
1076 }
1077
1078
1079 wxColour wxHtmlContainerCell::GetBackgroundColour()
1080 {
1081 if (m_UseBkColour)
1082 return m_BkColour;
1083 else
1084 return wxNullColour;
1085 }
1086
1087
1088
1089 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
1090 {
1091 wxHtmlCell *cell = FindCellByPos(x, y);
1092
1093 // VZ: I don't know if we should pass absolute or relative coords to
1094 // wxHtmlCell::GetLink()? As the base class version just ignores them
1095 // anyhow, it hardly matters right now but should still be clarified
1096 return cell ? cell->GetLink(x, y) : NULL;
1097 }
1098
1099
1100
1101 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
1102 {
1103 if (!m_Cells) m_Cells = m_LastCell = f;
1104 else
1105 {
1106 m_LastCell->SetNext(f);
1107 m_LastCell = f;
1108 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
1109 }
1110 f->SetParent(this);
1111 m_LastLayout = -1;
1112 }
1113
1114
1115
1116 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
1117 {
1118 if (tag.HasParam(wxT("ALIGN")))
1119 {
1120 wxString alg = tag.GetParam(wxT("ALIGN"));
1121 alg.MakeUpper();
1122 if (alg == wxT("CENTER"))
1123 SetAlignHor(wxHTML_ALIGN_CENTER);
1124 else if (alg == wxT("LEFT"))
1125 SetAlignHor(wxHTML_ALIGN_LEFT);
1126 else if (alg == wxT("JUSTIFY"))
1127 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
1128 else if (alg == wxT("RIGHT"))
1129 SetAlignHor(wxHTML_ALIGN_RIGHT);
1130 m_LastLayout = -1;
1131 }
1132 }
1133
1134
1135
1136 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
1137 {
1138 if (tag.HasParam(wxT("WIDTH")))
1139 {
1140 int wdi;
1141 wxString wd = tag.GetParam(wxT("WIDTH"));
1142
1143 if (wd[wd.Length()-1] == wxT('%'))
1144 {
1145 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
1146 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
1147 }
1148 else
1149 {
1150 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
1151 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
1152 }
1153 m_LastLayout = -1;
1154 }
1155 }
1156
1157
1158
1159 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
1160 {
1161 if (m_Cells)
1162 {
1163 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1164 {
1165 const wxHtmlCell *r = cell->Find(condition, param);
1166 if (r) return r;
1167 }
1168 }
1169 return NULL;
1170 }
1171
1172
1173 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
1174 unsigned flags) const
1175 {
1176 if ( flags & wxHTML_FIND_EXACT )
1177 {
1178 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1179 {
1180 int cx = cell->GetPosX(),
1181 cy = cell->GetPosY();
1182
1183 if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
1184 (cy <= y) && (cy + cell->GetHeight() > y) )
1185 {
1186 return cell->FindCellByPos(x - cx, y - cy, flags);
1187 }
1188 }
1189 }
1190 else if ( flags & wxHTML_FIND_NEAREST_AFTER )
1191 {
1192 wxHtmlCell *c;
1193 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1194 {
1195 if ( cell->IsFormattingCell() )
1196 continue;
1197 int cellY = cell->GetPosY();
1198 if (!( y < cellY || (y < cellY + cell->GetHeight() &&
1199 x < cell->GetPosX() + cell->GetWidth()) ))
1200 continue;
1201
1202 c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1203 if (c) return c;
1204 }
1205 }
1206 else if ( flags & wxHTML_FIND_NEAREST_BEFORE )
1207 {
1208 wxHtmlCell *c2, *c = NULL;
1209 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1210 {
1211 if ( cell->IsFormattingCell() )
1212 continue;
1213 int cellY = cell->GetPosY();
1214 if (!( cellY + cell->GetHeight() <= y ||
1215 (y >= cellY && x >= cell->GetPosX()) ))
1216 break;
1217 c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1218 if (c2)
1219 c = c2;
1220 }
1221 if (c) return c;
1222 }
1223
1224 return NULL;
1225 }
1226
1227
1228 bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window,
1229 const wxPoint& pos,
1230 const wxMouseEvent& event)
1231 {
1232 #if WXWIN_COMPATIBILITY_2_6
1233 wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event);
1234 return compat.CallOnMouseClick(this);
1235 }
1236
1237 void wxHtmlContainerCell::OnMouseClick(wxWindow*,
1238 int, int, const wxMouseEvent& event)
1239 {
1240 wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") );
1241 wxHtmlWindowInterface *window = gs_helperOnMouseClick->window;
1242 const wxPoint& pos = gs_helperOnMouseClick->pos;
1243 #endif // WXWIN_COMPATIBILITY_2_6
1244
1245 bool retval = false;
1246 wxHtmlCell *cell = FindCellByPos(pos.x, pos.y);
1247 if ( cell )
1248 retval = cell->ProcessMouseClick(window, pos, event);
1249
1250 #if WXWIN_COMPATIBILITY_2_6
1251 gs_helperOnMouseClick->retval = retval;
1252 #else
1253 return retval;
1254 #endif // WXWIN_COMPATIBILITY_2_6
1255 }
1256
1257
1258 wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const
1259 {
1260 if ( m_Cells )
1261 {
1262 wxHtmlCell *c2;
1263 for (wxHtmlCell *c = m_Cells; c; c = c->GetNext())
1264 {
1265 c2 = c->GetFirstTerminal();
1266 if ( c2 )
1267 return c2;
1268 }
1269 }
1270 return NULL;
1271 }
1272
1273 wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
1274 {
1275 if ( m_Cells )
1276 {
1277 // most common case first:
1278 wxHtmlCell *c = m_LastCell->GetLastTerminal();
1279 if ( c )
1280 return c;
1281
1282 wxHtmlCell *ctmp;
1283 wxHtmlCell *c2 = NULL;
1284 for (c = m_Cells; c; c = c->GetNext())
1285 {
1286 ctmp = c->GetLastTerminal();
1287 if ( ctmp )
1288 c2 = ctmp;
1289 }
1290 return c2;
1291 }
1292 else
1293 return NULL;
1294 }
1295
1296
1297 static bool IsEmptyContainer(wxHtmlContainerCell *cell)
1298 {
1299 for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() )
1300 {
1301 if ( !c->IsTerminalCell() || !c->IsFormattingCell() )
1302 return false;
1303 }
1304 return true;
1305 }
1306
1307 void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom)
1308 {
1309 if ( top )
1310 SetIndent(0, wxHTML_INDENT_TOP);
1311 if ( bottom )
1312 SetIndent(0, wxHTML_INDENT_BOTTOM);
1313
1314 if ( m_Cells )
1315 {
1316 wxHtmlCell *c;
1317 wxHtmlContainerCell *cont;
1318 if ( top )
1319 {
1320 for ( c = m_Cells; c; c = c->GetNext() )
1321 {
1322 if ( c->IsTerminalCell() )
1323 {
1324 if ( !c->IsFormattingCell() )
1325 break;
1326 }
1327 else
1328 {
1329 cont = (wxHtmlContainerCell*)c;
1330 if ( IsEmptyContainer(cont) )
1331 {
1332 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1333 }
1334 else
1335 {
1336 cont->RemoveExtraSpacing(true, false);
1337 break;
1338 }
1339 }
1340 }
1341 }
1342
1343 if ( bottom )
1344 {
1345 wxArrayPtrVoid arr;
1346 for ( c = m_Cells; c; c = c->GetNext() )
1347 arr.Add((void*)c);
1348
1349 for ( int i = arr.GetCount() - 1; i >= 0; i--)
1350 {
1351 c = (wxHtmlCell*)arr[i];
1352 if ( c->IsTerminalCell() )
1353 {
1354 if ( !c->IsFormattingCell() )
1355 break;
1356 }
1357 else
1358 {
1359 cont = (wxHtmlContainerCell*)c;
1360 if ( IsEmptyContainer(cont) )
1361 {
1362 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1363 }
1364 else
1365 {
1366 cont->RemoveExtraSpacing(false, true);
1367 break;
1368 }
1369 }
1370 }
1371 }
1372 }
1373 }
1374
1375
1376
1377
1378 // --------------------------------------------------------------------------
1379 // wxHtmlColourCell
1380 // --------------------------------------------------------------------------
1381
1382 IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell)
1383
1384 void wxHtmlColourCell::Draw(wxDC& dc,
1385 int x, int y,
1386 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1387 wxHtmlRenderingInfo& info)
1388 {
1389 DrawInvisible(dc, x, y, info);
1390 }
1391
1392 void wxHtmlColourCell::DrawInvisible(wxDC& dc,
1393 int WXUNUSED(x), int WXUNUSED(y),
1394 wxHtmlRenderingInfo& info)
1395 {
1396 wxHtmlRenderingState& state = info.GetState();
1397 if (m_Flags & wxHTML_CLR_FOREGROUND)
1398 {
1399 state.SetFgColour(m_Colour);
1400 if (state.GetSelectionState() != wxHTML_SEL_IN)
1401 dc.SetTextForeground(m_Colour);
1402 else
1403 dc.SetTextForeground(
1404 info.GetStyle().GetSelectedTextColour(m_Colour));
1405 }
1406 if (m_Flags & wxHTML_CLR_BACKGROUND)
1407 {
1408 state.SetBgColour(m_Colour);
1409 if (state.GetSelectionState() != wxHTML_SEL_IN)
1410 {
1411 dc.SetTextBackground(m_Colour);
1412 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
1413 }
1414 else
1415 {
1416 wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour);
1417 dc.SetTextBackground(c);
1418 dc.SetBackground(wxBrush(c, wxSOLID));
1419 }
1420 }
1421 }
1422
1423
1424
1425
1426 // ---------------------------------------------------------------------------
1427 // wxHtmlFontCell
1428 // ---------------------------------------------------------------------------
1429
1430 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell)
1431
1432 void wxHtmlFontCell::Draw(wxDC& dc,
1433 int WXUNUSED(x), int WXUNUSED(y),
1434 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1435 wxHtmlRenderingInfo& WXUNUSED(info))
1436 {
1437 dc.SetFont(m_Font);
1438 }
1439
1440 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
1441 wxHtmlRenderingInfo& WXUNUSED(info))
1442 {
1443 dc.SetFont(m_Font);
1444 }
1445
1446
1447
1448
1449
1450
1451
1452
1453 // ---------------------------------------------------------------------------
1454 // wxHtmlWidgetCell
1455 // ---------------------------------------------------------------------------
1456
1457 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell)
1458
1459 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
1460 {
1461 int sx, sy;
1462 m_Wnd = wnd;
1463 m_Wnd->GetSize(&sx, &sy);
1464 m_Width = sx, m_Height = sy;
1465 m_WidthFloat = w;
1466 }
1467
1468
1469 void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
1470 int WXUNUSED(x), int WXUNUSED(y),
1471 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1472 wxHtmlRenderingInfo& WXUNUSED(info))
1473 {
1474 int absx = 0, absy = 0, stx, sty;
1475 wxHtmlCell *c = this;
1476
1477 while (c)
1478 {
1479 absx += c->GetPosX();
1480 absy += c->GetPosY();
1481 c = c->GetParent();
1482 }
1483
1484 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1485 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1486 }
1487
1488
1489
1490 void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
1491 int WXUNUSED(x), int WXUNUSED(y),
1492 wxHtmlRenderingInfo& WXUNUSED(info))
1493 {
1494 int absx = 0, absy = 0, stx, sty;
1495 wxHtmlCell *c = this;
1496
1497 while (c)
1498 {
1499 absx += c->GetPosX();
1500 absy += c->GetPosY();
1501 c = c->GetParent();
1502 }
1503
1504 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1505 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1506 }
1507
1508
1509
1510 void wxHtmlWidgetCell::Layout(int w)
1511 {
1512 if (m_WidthFloat != 0)
1513 {
1514 m_Width = (w * m_WidthFloat) / 100;
1515 m_Wnd->SetSize(m_Width, m_Height);
1516 }
1517
1518 wxHtmlCell::Layout(w);
1519 }
1520
1521
1522
1523 // ----------------------------------------------------------------------------
1524 // wxHtmlTerminalCellsInterator
1525 // ----------------------------------------------------------------------------
1526
1527 const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++()
1528 {
1529 if ( !m_pos )
1530 return NULL;
1531
1532 do
1533 {
1534 if ( m_pos == m_to )
1535 {
1536 m_pos = NULL;
1537 return NULL;
1538 }
1539
1540 if ( m_pos->GetNext() )
1541 m_pos = m_pos->GetNext();
1542 else
1543 {
1544 // we must go up the hierarchy until we reach container where this
1545 // is not the last child, and then go down to first terminal cell:
1546 while ( m_pos->GetNext() == NULL )
1547 {
1548 m_pos = m_pos->GetParent();
1549 if ( !m_pos )
1550 return NULL;
1551 }
1552 m_pos = m_pos->GetNext();
1553 }
1554 while ( m_pos->GetFirstChild() != NULL )
1555 m_pos = m_pos->GetFirstChild();
1556 } while ( !m_pos->IsTerminalCell() );
1557
1558 return m_pos;
1559 }
1560
1561
1562
1563
1564
1565
1566
1567 //-----------------------------------------------------------------------------
1568 // Cleanup
1569 //-----------------------------------------------------------------------------
1570
1571 class wxHtmlCellModule: public wxModule
1572 {
1573 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule)
1574 public:
1575 wxHtmlCellModule() : wxModule() {}
1576 bool OnInit() { return true; }
1577 void OnExit()
1578 {
1579 wxDELETE(gs_cursorLink);
1580 wxDELETE(gs_cursorText);
1581 }
1582 };
1583
1584 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule, wxModule)
1585
1586 #endif