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