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