compilation fix (not all paths returned a value)
[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 #ifdef __GNUG__
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 <stdlib.h>
34
35
36 //-----------------------------------------------------------------------------
37 // wxHtmlCell
38 //-----------------------------------------------------------------------------
39
40 wxHtmlCell::wxHtmlCell() : wxObject()
41 {
42 m_Next = NULL;
43 m_Parent = NULL;
44 m_Width = m_Height = m_Descent = 0;
45 m_CanLiveOnPagebreak = TRUE;
46 m_Link = NULL;
47 }
48
49 wxHtmlCell::~wxHtmlCell()
50 {
51 delete m_Link;
52 }
53
54
55 void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y,
56 const wxMouseEvent& event)
57 {
58 wxHtmlLinkInfo *lnk = GetLink(x, y);
59 if (lnk != NULL)
60 {
61 wxHtmlLinkInfo lnk2(*lnk);
62 lnk2.SetEvent(&event);
63 lnk2.SetHtmlCell(this);
64
65 // note : this cast is legal because parent is *always* wxHtmlWindow
66 wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2);
67 }
68 }
69
70
71
72 bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const
73 {
74 if ((!m_CanLiveOnPagebreak) &&
75 m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
76 {
77 *pagebreak = m_PosY;
78 return TRUE;
79 }
80
81 return FALSE;
82 }
83
84
85
86 void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
87 {
88 if (m_Link) delete m_Link;
89 m_Link = NULL;
90 if (link.GetHref() != wxEmptyString)
91 m_Link = new wxHtmlLinkInfo(link);
92 }
93
94
95
96 void wxHtmlCell::Layout(int WXUNUSED(w))
97 {
98 SetPos(0, 0);
99 }
100
101
102
103 void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const
104 {
105 if (left)
106 *left = m_PosX;
107 if (right)
108 *right = m_PosX + m_Width;
109 }
110
111
112
113 const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const
114 {
115 return NULL;
116 }
117
118
119 wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y,
120 unsigned flags) const
121 {
122 if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height )
123 {
124 return wxConstCast(this, wxHtmlCell);
125 }
126 else
127 {
128 if ((flags & wxHTML_FIND_NEAREST_AFTER) &&
129 (y < 0 || (y == 0 && x <= 0)))
130 return wxConstCast(this, wxHtmlCell);
131 else if ((flags & wxHTML_FIND_NEAREST_BEFORE) &&
132 (y > m_Height-1 || (y == m_Height-1 && x >= m_Width)))
133 return wxConstCast(this, wxHtmlCell);
134 else
135 return NULL;
136 }
137 }
138
139
140 wxPoint wxHtmlCell::GetAbsPos() const
141 {
142 wxPoint p(m_PosX, m_PosY);
143 for (wxHtmlCell *parent = m_Parent; parent; parent = parent->m_Parent)
144 {
145 p.x += parent->m_PosX;
146 p.y += parent->m_PosY;
147 }
148 return p;
149 }
150
151
152 //-----------------------------------------------------------------------------
153 // wxHtmlWordCell
154 //-----------------------------------------------------------------------------
155
156 wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
157 {
158 m_Word = word;
159 dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
160 SetCanLiveOnPagebreak(FALSE);
161 }
162
163
164
165 void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
166 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
167 wxHtmlRenderingState& state)
168 {
169 if (state.GetSelectionState() != wxHTML_SEL_OUT &&
170 dc.GetBackgroundMode() != wxSOLID)
171 {
172 dc.SetBackgroundMode(wxSOLID);
173 dc.SetTextBackground(
174 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
175 dc.SetTextForeground(
176 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
177 }
178 else if (state.GetSelectionState() == wxHTML_SEL_OUT &&
179 dc.GetBackgroundMode() == wxSOLID)
180 {
181 dc.SetBackgroundMode(wxTRANSPARENT);
182 dc.SetTextForeground(state.GetFgColour());
183 dc.SetTextBackground(state.GetBgColour());
184 }
185
186 dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
187 }
188
189
190
191 //-----------------------------------------------------------------------------
192 // wxHtmlContainerCell
193 //-----------------------------------------------------------------------------
194
195
196 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
197 {
198 m_Cells = m_LastCell = NULL;
199 m_Parent = parent;
200 if (m_Parent) m_Parent->InsertCell(this);
201 m_AlignHor = wxHTML_ALIGN_LEFT;
202 m_AlignVer = wxHTML_ALIGN_BOTTOM;
203 m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
204 m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
205 m_UseBkColour = FALSE;
206 m_UseBorder = FALSE;
207 m_MinHeight = 0;
208 m_MinHeightAlign = wxHTML_ALIGN_TOP;
209 m_LastLayout = -1;
210 }
211
212 wxHtmlContainerCell::~wxHtmlContainerCell()
213 {
214 wxHtmlCell *cell = m_Cells;
215 while ( cell )
216 {
217 wxHtmlCell *cellNext = cell->GetNext();
218 delete cell;
219 cell = cellNext;
220 }
221 }
222
223
224
225 void wxHtmlContainerCell::SetIndent(int i, int what, int units)
226 {
227 int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
228 if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
229 if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
230 if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
231 if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
232 m_LastLayout = -1;
233 }
234
235
236
237 int wxHtmlContainerCell::GetIndent(int ind) const
238 {
239 if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
240 else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
241 else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
242 else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
243 else return -1; /* BUG! Should not be called... */
244 }
245
246
247
248
249 int wxHtmlContainerCell::GetIndentUnits(int ind) const
250 {
251 bool p = FALSE;
252 if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
253 else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
254 else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
255 else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
256 if (p) return wxHTML_UNITS_PERCENT;
257 else return wxHTML_UNITS_PIXELS;
258 }
259
260
261
262 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const
263 {
264 if (!m_CanLiveOnPagebreak)
265 return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages);
266
267 else
268 {
269 wxHtmlCell *c = GetFirstCell();
270 bool rt = FALSE;
271 int pbrk = *pagebreak - m_PosY;
272
273 while (c)
274 {
275 if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages))
276 rt = TRUE;
277 c = c->GetNext();
278 }
279 if (rt)
280 *pagebreak = pbrk + m_PosY;
281 return rt;
282 }
283 }
284
285
286
287 void wxHtmlContainerCell::Layout(int w)
288 {
289 wxHtmlCell::Layout(w);
290
291 if (m_LastLayout == w) return;
292
293 // VS: Any attempt to layout with negative or zero width leads to hell,
294 // but we can't ignore such attempts completely, since it sometimes
295 // happen (e.g. when trying how small a table can be). The best thing we
296 // can do is to set the width of child cells to zero
297 if (w < 1)
298 {
299 m_Width = 0;
300 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
301 cell->Layout(0);
302 // this does two things: it recursively calls this code on all
303 // child contrainers and resets children's position to (0,0)
304 return;
305 }
306
307 wxHtmlCell *cell = m_Cells, *line = m_Cells;
308 long xpos = 0, ypos = m_IndentTop;
309 int xdelta = 0, ybasicpos = 0, ydiff;
310 int s_width, s_indent;
311 int ysizeup = 0, ysizedown = 0;
312 int MaxLineWidth = 0;
313 int xcnt = 0;
314
315
316 /*
317
318 WIDTH ADJUSTING :
319
320 */
321
322 if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
323 {
324 if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
325 else m_Width = m_WidthFloat * w / 100;
326 }
327 else
328 {
329 if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
330 else m_Width = m_WidthFloat;
331 }
332
333 if (m_Cells)
334 {
335 int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
336 int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
337 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
338 cell->Layout(m_Width - (l + r));
339 }
340
341 /*
342
343 LAYOUTING :
344
345 */
346
347 // adjust indentation:
348 s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
349 s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
350
351 // my own layouting:
352 while (cell != NULL)
353 {
354 switch (m_AlignVer)
355 {
356 case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
357 case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
358 case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
359 }
360 ydiff = cell->GetHeight() + ybasicpos;
361
362 if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
363 if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
364
365 cell->SetPos(xpos, ybasicpos + cell->GetDescent());
366 xpos += cell->GetWidth();
367 cell = cell->GetNext();
368 xcnt++;
369
370 // force new line if occured:
371 if ((cell == NULL) || (xpos + cell->GetWidth() > s_width))
372 {
373 if (xpos > MaxLineWidth) MaxLineWidth = xpos;
374 if (ysizeup < 0) ysizeup = 0;
375 if (ysizedown < 0) ysizedown = 0;
376 switch (m_AlignHor) {
377 case wxHTML_ALIGN_LEFT :
378 case wxHTML_ALIGN_JUSTIFY :
379 xdelta = 0;
380 break;
381 case wxHTML_ALIGN_RIGHT :
382 xdelta = 0 + (s_width - xpos);
383 break;
384 case wxHTML_ALIGN_CENTER :
385 xdelta = 0 + (s_width - xpos) / 2;
386 break;
387 }
388 if (xdelta < 0) xdelta = 0;
389 xdelta += s_indent;
390
391 ypos += ysizeup;
392
393 if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
394 while (line != cell)
395 {
396 line->SetPos(line->GetPosX() + xdelta,
397 ypos + line->GetPosY());
398 line = line->GetNext();
399 }
400 else
401 {
402 int counter = 0;
403 int step = (s_width - xpos);
404 if (step < 0) step = 0;
405 xcnt--;
406 if (xcnt > 0) while (line != cell)
407 {
408 line->SetPos(line->GetPosX() + s_indent +
409 (counter++ * step / xcnt),
410 ypos + line->GetPosY());
411 line = line->GetNext();
412 }
413 xcnt++;
414 }
415
416 ypos += ysizedown;
417 xpos = xcnt = 0;
418 ysizeup = ysizedown = 0;
419 line = cell;
420 }
421 }
422
423 // setup height & width, depending on container layout:
424 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
425
426 if (m_Height < m_MinHeight)
427 {
428 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
429 {
430 int diff = m_MinHeight - m_Height;
431 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
432 cell = m_Cells;
433 while (cell)
434 {
435 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
436 cell = cell->GetNext();
437 }
438 }
439 m_Height = m_MinHeight;
440 }
441
442 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
443 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
444
445 m_LastLayout = w;
446 }
447
448 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingState& state,
449 wxHtmlCell *cell) const
450 {
451 wxHtmlSelection *s = state.GetSelection();
452 if (!s) return;
453 if (s->GetFromCell() == cell || s->GetToCell() == cell)
454 {
455 state.SetSelectionState(wxHTML_SEL_CHANGING);
456 }
457 }
458
459 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingState& state,
460 wxHtmlCell *cell) const
461 {
462 wxHtmlSelection *s = state.GetSelection();
463 if (!s) return;
464 if (s->GetToCell() == cell)
465 state.SetSelectionState(wxHTML_SEL_OUT);
466 else if (s->GetFromCell() == cell)
467 state.SetSelectionState(wxHTML_SEL_IN);
468 }
469
470 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
471 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
472
473 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
474 wxHtmlRenderingState& state)
475 {
476 // container visible, draw it:
477 if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1))
478 {
479 if (m_UseBkColour)
480 {
481 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
482
483 int real_y1 = mMax(y + m_PosY, view_y1);
484 int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2);
485
486 dc.SetBrush(myb);
487 dc.SetPen(*wxTRANSPARENT_PEN);
488 dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1);
489 }
490
491 if (m_UseBorder)
492 {
493 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
494 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
495
496 dc.SetPen(mypen1);
497 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1);
498 dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY);
499 dc.SetPen(mypen2);
500 dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
501 dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1);
502 }
503
504 if (m_Cells)
505 {
506 // draw container's contents:
507 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
508 {
509 UpdateRenderingStatePre(state, cell);
510 cell->Draw(dc,
511 x + m_PosX, y + m_PosY, view_y1, view_y2,
512 state);
513 UpdateRenderingStatePost(state, cell);
514 }
515 }
516 }
517 // container invisible, just proceed font+color changing:
518 else
519 {
520 DrawInvisible(dc, x, y, state);
521 }
522 }
523
524
525
526 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
527 wxHtmlRenderingState& state)
528 {
529 if (m_Cells)
530 {
531 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
532 {
533 UpdateRenderingStatePre(state, cell);
534 cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, state);
535 UpdateRenderingStatePost(state, cell);
536 }
537 }
538 }
539
540
541 wxColour wxHtmlContainerCell::GetBackgroundColour()
542 {
543 if (m_UseBkColour)
544 return m_BkColour;
545 else
546 return wxNullColour;
547 }
548
549
550
551 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
552 {
553 wxHtmlCell *cell = FindCellByPos(x, y);
554
555 // VZ: I don't know if we should pass absolute or relative coords to
556 // wxHtmlCell::GetLink()? As the base class version just ignores them
557 // anyhow, it hardly matters right now but should still be clarified
558 return cell ? cell->GetLink(x, y) : NULL;
559 }
560
561
562
563 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
564 {
565 if (!m_Cells) m_Cells = m_LastCell = f;
566 else
567 {
568 m_LastCell->SetNext(f);
569 m_LastCell = f;
570 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
571 }
572 f->SetParent(this);
573 m_LastLayout = -1;
574 }
575
576
577
578 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
579 {
580 if (tag.HasParam(wxT("ALIGN")))
581 {
582 wxString alg = tag.GetParam(wxT("ALIGN"));
583 alg.MakeUpper();
584 if (alg == wxT("CENTER"))
585 SetAlignHor(wxHTML_ALIGN_CENTER);
586 else if (alg == wxT("LEFT"))
587 SetAlignHor(wxHTML_ALIGN_LEFT);
588 else if (alg == wxT("JUSTIFY"))
589 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
590 else if (alg == wxT("RIGHT"))
591 SetAlignHor(wxHTML_ALIGN_RIGHT);
592 m_LastLayout = -1;
593 }
594 }
595
596
597
598 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
599 {
600 if (tag.HasParam(wxT("WIDTH")))
601 {
602 int wdi;
603 wxString wd = tag.GetParam(wxT("WIDTH"));
604
605 if (wd[wd.Length()-1] == wxT('%'))
606 {
607 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
608 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
609 }
610 else
611 {
612 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
613 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
614 }
615 m_LastLayout = -1;
616 }
617 }
618
619
620
621 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
622 {
623 if (m_Cells)
624 {
625 const wxHtmlCell *r = NULL;
626
627 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
628 {
629 r = cell->Find(condition, param);
630 if (r) return r;
631 }
632 }
633 return NULL;
634 }
635
636
637 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
638 unsigned flags) const
639 {
640 if ( flags & wxHTML_FIND_EXACT )
641 {
642 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
643 {
644 int cx = cell->GetPosX(),
645 cy = cell->GetPosY();
646
647 if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
648 (cy <= y) && (cy + cell->GetHeight() > y) )
649 {
650 return cell->FindCellByPos(x - cx, y - cy, flags);
651 }
652 }
653 }
654 else if ( flags & wxHTML_FIND_NEAREST_AFTER )
655 {
656 wxHtmlCell *c;
657 int y2;
658 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
659 {
660 y2 = cell->GetPosY() + cell->GetHeight() - 1;
661 if (y2 < y || (y2 == y && cell->GetPosX()+cell->GetWidth()-1 < x))
662 continue;
663 c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(),
664 flags);
665 if (c) return c;
666 }
667 }
668 else if ( flags & wxHTML_FIND_NEAREST_BEFORE )
669 {
670 wxHtmlCell *c;
671 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
672 {
673 if (cell->GetPosY() > y ||
674 (cell->GetPosY() == y && cell->GetPosX() > x))
675 break;
676 c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(),
677 flags);
678 if (c) return c;
679 }
680 }
681
682 return NULL;
683 }
684
685
686 void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event)
687 {
688 wxHtmlCell *cell = FindCellByPos(x, y);
689 if ( cell )
690 cell->OnMouseClick(parent, x, y, event);
691 }
692
693
694
695 void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const
696 {
697 int cleft = m_PosX + m_Width, cright = m_PosX; // worst case
698 int l, r;
699
700 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
701 {
702 cell->GetHorizontalConstraints(&l, &r);
703 if (l < cleft)
704 cleft = l;
705 if (r > cright)
706 cright = r;
707 }
708
709 cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
710 cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
711
712 if (left)
713 *left = cleft;
714 if (right)
715 *right = cright;
716 }
717
718
719 wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const
720 {
721 if (m_Cells)
722 return m_Cells->GetFirstTerminal();
723 else
724 return NULL;
725 }
726
727 wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
728 {
729 if (m_Cells)
730 {
731 wxHtmlCell *c;
732 for (c = m_Cells; c->GetNext(); c = c->GetNext()) {}
733 return c;
734 }
735 else
736 return NULL;
737 }
738
739
740
741
742 // --------------------------------------------------------------------------
743 // wxHtmlColourCell
744 // --------------------------------------------------------------------------
745
746 void wxHtmlColourCell::Draw(wxDC& dc,
747 int x, int y,
748 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
749 wxHtmlRenderingState& state)
750 {
751 DrawInvisible(dc, x, y, state);
752 }
753
754 void wxHtmlColourCell::DrawInvisible(wxDC& dc,
755 int WXUNUSED(x), int WXUNUSED(y),
756 wxHtmlRenderingState& state)
757 {
758 if (m_Flags & wxHTML_CLR_FOREGROUND)
759 {
760 state.SetFgColour(m_Colour);
761 if (state.GetSelectionState() != wxHTML_SEL_IN)
762 dc.SetTextForeground(m_Colour);
763 }
764 if (m_Flags & wxHTML_CLR_BACKGROUND)
765 {
766 state.SetBgColour(m_Colour);
767 if (state.GetSelectionState() != wxHTML_SEL_IN)
768 dc.SetTextBackground(m_Colour);
769 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
770 }
771 }
772
773
774
775
776 // ---------------------------------------------------------------------------
777 // wxHtmlFontCell
778 // ---------------------------------------------------------------------------
779
780 void wxHtmlFontCell::Draw(wxDC& dc,
781 int WXUNUSED(x), int WXUNUSED(y),
782 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
783 wxHtmlRenderingState& WXUNUSED(state))
784 {
785 dc.SetFont(m_Font);
786 }
787
788 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
789 wxHtmlRenderingState& WXUNUSED(state))
790 {
791 dc.SetFont(m_Font);
792 }
793
794
795
796
797
798
799
800
801 // ---------------------------------------------------------------------------
802 // wxHtmlWidgetCell
803 // ---------------------------------------------------------------------------
804
805 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
806 {
807 int sx, sy;
808 m_Wnd = wnd;
809 m_Wnd->GetSize(&sx, &sy);
810 m_Width = sx, m_Height = sy;
811 m_WidthFloat = w;
812 }
813
814
815 void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
816 int WXUNUSED(x), int WXUNUSED(y),
817 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
818 wxHtmlRenderingState& WXUNUSED(state))
819 {
820 int absx = 0, absy = 0, stx, sty;
821 wxHtmlCell *c = this;
822
823 while (c)
824 {
825 absx += c->GetPosX();
826 absy += c->GetPosY();
827 c = c->GetParent();
828 }
829
830 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
831 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
832 }
833
834
835
836 void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
837 int WXUNUSED(x), int WXUNUSED(y),
838 wxHtmlRenderingState& WXUNUSED(state))
839 {
840 int absx = 0, absy = 0, stx, sty;
841 wxHtmlCell *c = this;
842
843 while (c)
844 {
845 absx += c->GetPosX();
846 absy += c->GetPosY();
847 c = c->GetParent();
848 }
849
850 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
851 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
852 }
853
854
855
856 void wxHtmlWidgetCell::Layout(int w)
857 {
858 if (m_WidthFloat != 0)
859 {
860 m_Width = (w * m_WidthFloat) / 100;
861 m_Wnd->SetSize(m_Width, m_Height);
862 }
863
864 wxHtmlCell::Layout(w);
865 }
866
867 #endif