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