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