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