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