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