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