]>
Commit | Line | Data |
---|---|---|
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 |
36 | void 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 | 45 | void 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 |
57 | wxColour |
58 | wxDefaultHtmlRenderingStyle:: | |
59 | GetSelectedTextColour(const wxColour& WXUNUSED(clr)) | |
f30e67db VS |
60 | { |
61 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
62 | } | |
63 | ||
fc7a2a60 VZ |
64 | wxColour |
65 | wxDefaultHtmlRenderingStyle:: | |
66 | GetSelectedTextBgColour(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 |
76 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell, wxObject) |
77 | ||
04dbb646 | 78 | wxHtmlCell::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 | 89 | wxHtmlCell::~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 | |
96 | void 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 | ||
112 | struct wxHtmlCellOnMouseClickCompatHelper; | |
113 | ||
114 | static wxHtmlCellOnMouseClickCompatHelper *gs_helperOnMouseClick = NULL; | |
115 | ||
116 | // helper for routing calls to new ProcessMouseClick() method to deprecated | |
117 | // OnMouseClick() method | |
118 | struct 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 | ||
148 | bool 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 | ||
164 | void 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 |
192 | wxCursor wxHtmlCell::GetCursor() const |
193 | { | |
88a1b648 VS |
194 | return wxNullCursor; |
195 | } | |
196 | #endif // WXWIN_COMPATIBILITY_2_6 | |
197 | ||
198 | wxCursor 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 |
222 | bool 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 | 237 | void 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 | 246 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 247 | { |
04dbb646 | 248 | SetPos(0, 0); |
721ab905 VS |
249 | } |
250 | ||
251 | ||
79d6c018 | 252 | |
d699f48b | 253 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 254 | { |
bf7d7ee7 | 255 | return NULL; |
721ab905 VS |
256 | } |
257 | ||
258 | ||
36c4ff4d VS |
259 | wxHtmlCell *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 | 280 | wxPoint 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 |
292 | wxHtmlCell *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 |
300 | unsigned 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 |
308 | bool 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 |
353 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell) |
354 | ||
fbfb8bcc | 355 | wxHtmlWordCell::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 |
363 | void 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 | 375 | void 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 | 440 | void 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 | 463 | static 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 | |
487 | void 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 | 592 | wxString 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 | 618 | wxCursor 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 | 635 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell) |
5526e819 VS |
636 | |
637 | wxHtmlContainerCell::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 | 654 | wxHtmlContainerCell::~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 | ||
667 | void 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 | ||
679 | int 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 | ||
691 | int 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 |
703 | bool 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 |
725 | void 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 VZ |
886 | // first count the cells which will get extra space |
887 | int total = 0; | |
4dd9ae57 | 888 | |
1c0ee565 VS |
889 | const wxHtmlCell *c; |
890 | if ( line != cell ) | |
a1ae1090 | 891 | { |
1c0ee565 | 892 | for ( c = line->GetNext(); 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 | { | |
1c0ee565 VS |
904 | // first cell on line is not moved: |
905 | line->SetPos(line->GetPosX() + s_indent, | |
906 | line->GetPosY() + ypos); | |
d1da8872 | 907 | |
1c0ee565 VS |
908 | line = line->GetNext(); |
909 | for ( int n = 0; line != cell; line = line->GetNext() ) | |
a1ae1090 | 910 | { |
1c0ee565 | 911 | if ( line->IsLinebreakAllowed() ) |
a1ae1090 VZ |
912 | { |
913 | // offset the next cell relative to this one | |
914 | // thus increasing our size | |
915 | n++; | |
916 | } | |
d1da8872 | 917 | |
1c0ee565 VS |
918 | line->SetPos(line->GetPosX() + s_indent + |
919 | ((n * step) / total), | |
920 | line->GetPosY() + ypos); | |
a1ae1090 VZ |
921 | } |
922 | } | |
2d1d813e VS |
923 | else |
924 | { | |
925 | // this will cause the code to enter "else branch" below: | |
926 | step = 0; | |
927 | } | |
a1ae1090 | 928 | } |
2d1d813e VS |
929 | // else branch: |
930 | if ( step <= 0 ) // no extra space to distribute | |
a1ae1090 VZ |
931 | { |
932 | // just set the indent properly | |
933 | while (line != cell) | |
934 | { | |
935 | line->SetPos(line->GetPosX() + s_indent, | |
936 | line->GetPosY() + ypos); | |
937 | line = line->GetNext(); | |
938 | } | |
5c1bfc5d | 939 | } |
5526e819 VS |
940 | } |
941 | ||
942 | ypos += ysizedown; | |
49f6740f | 943 | xpos = 0; |
5526e819 VS |
944 | ysizeup = ysizedown = 0; |
945 | line = cell; | |
946 | } | |
947 | } | |
948 | ||
949 | // setup height & width, depending on container layout: | |
950 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
951 | ||
04dbb646 | 952 | if (m_Height < m_MinHeight) |
4f9297b0 | 953 | { |
04dbb646 | 954 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 955 | { |
5526e819 | 956 | int diff = m_MinHeight - m_Height; |
efba2b89 | 957 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 958 | cell = m_Cells; |
04dbb646 | 959 | while (cell) |
0cb9cfb2 | 960 | { |
4f9297b0 VS |
961 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
962 | cell = cell->GetNext(); | |
5526e819 VS |
963 | } |
964 | } | |
965 | m_Height = m_MinHeight; | |
966 | } | |
967 | ||
ca16b7a9 VS |
968 | if (curLineWidth > m_MaxTotalWidth) |
969 | m_MaxTotalWidth = curLineWidth; | |
d1da8872 | 970 | |
ca16b7a9 | 971 | m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
5c1bfc5d VS |
972 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
973 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 974 | |
5660c520 | 975 | m_LastLayout = w; |
5526e819 VS |
976 | } |
977 | ||
f30e67db | 978 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
979 | wxHtmlCell *cell) const |
980 | { | |
f30e67db | 981 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 982 | if (!s) return; |
cd275246 | 983 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 984 | { |
f30e67db | 985 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
986 | } |
987 | } | |
988 | ||
f30e67db | 989 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
990 | wxHtmlCell *cell) const |
991 | { | |
f30e67db | 992 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 993 | if (!s) return; |
adf2eb2d | 994 | if (s->GetToCell() == cell) |
f30e67db | 995 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 996 | else if (s->GetFromCell() == cell) |
f30e67db | 997 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 998 | } |
5526e819 VS |
999 | |
1000 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
1001 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
1002 | ||
36c4ff4d | 1003 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 1004 | wxHtmlRenderingInfo& info) |
5526e819 | 1005 | { |
ace0fab4 VS |
1006 | #if 0 // useful for debugging |
1007 | dc.SetPen(*wxRED_PEN); | |
1008 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
1009 | #endif | |
95af070a | 1010 | |
848c4eb2 VS |
1011 | int xlocal = x + m_PosX; |
1012 | int ylocal = y + m_PosY; | |
1013 | ||
1014 | if (m_UseBkColour) | |
4f9297b0 | 1015 | { |
848c4eb2 | 1016 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
5526e819 | 1017 | |
848c4eb2 VS |
1018 | int real_y1 = mMax(ylocal, view_y1); |
1019 | int real_y2 = mMin(ylocal + m_Height - 1, view_y2); | |
5526e819 | 1020 | |
848c4eb2 VS |
1021 | dc.SetBrush(myb); |
1022 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1023 | dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1); | |
1024 | } | |
5526e819 | 1025 | |
848c4eb2 VS |
1026 | if (m_UseBorder) |
1027 | { | |
1028 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); | |
1029 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
1030 | ||
1031 | dc.SetPen(mypen1); | |
1032 | dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1); | |
1033 | dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal); | |
1034 | dc.SetPen(mypen2); | |
1035 | dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1); | |
1036 | dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1); | |
1037 | } | |
5526e819 | 1038 | |
848c4eb2 VS |
1039 | if (m_Cells) |
1040 | { | |
1041 | // draw container's contents: | |
1042 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
bf7d7ee7 | 1043 | { |
95af070a | 1044 | |
848c4eb2 VS |
1045 | // optimize drawing: don't render off-screen content: |
1046 | if ((ylocal + cell->GetPosY() <= view_y2) && | |
1047 | (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1)) | |
36c4ff4d | 1048 | { |
848c4eb2 | 1049 | // the cell is visible, draw it: |
f30e67db | 1050 | UpdateRenderingStatePre(info, cell); |
36c4ff4d | 1051 | cell->Draw(dc, |
848c4eb2 | 1052 | xlocal, ylocal, view_y1, view_y2, |
f30e67db VS |
1053 | info); |
1054 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1055 | } |
848c4eb2 VS |
1056 | else |
1057 | { | |
1058 | // the cell is off-screen, proceed with font+color+etc. | |
1059 | // changes only: | |
1060 | cell->DrawInvisible(dc, xlocal, ylocal, info); | |
1061 | } | |
bf7d7ee7 | 1062 | } |
5526e819 | 1063 | } |
5526e819 VS |
1064 | } |
1065 | ||
1066 | ||
1067 | ||
36c4ff4d | 1068 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 1069 | wxHtmlRenderingInfo& info) |
5526e819 | 1070 | { |
d699f48b | 1071 | if (m_Cells) |
bf7d7ee7 VS |
1072 | { |
1073 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 1074 | { |
f30e67db VS |
1075 | UpdateRenderingStatePre(info, cell); |
1076 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
1077 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1078 | } |
bf7d7ee7 | 1079 | } |
5526e819 VS |
1080 | } |
1081 | ||
1082 | ||
2b5f62a0 VZ |
1083 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
1084 | { | |
1085 | if (m_UseBkColour) | |
1086 | return m_BkColour; | |
1087 | else | |
1088 | return wxNullColour; | |
1089 | } | |
1090 | ||
1091 | ||
5526e819 | 1092 | |
846914d1 | 1093 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 1094 | { |
f6010d8f | 1095 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 1096 | |
f6010d8f VZ |
1097 | // VZ: I don't know if we should pass absolute or relative coords to |
1098 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
1099 | // anyhow, it hardly matters right now but should still be clarified | |
1100 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
1101 | } |
1102 | ||
1103 | ||
1104 | ||
1105 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
1106 | { | |
1107 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 1108 | else |
4f9297b0 VS |
1109 | { |
1110 | m_LastCell->SetNext(f); | |
5526e819 | 1111 | m_LastCell = f; |
4f9297b0 | 1112 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 1113 | } |
4f9297b0 | 1114 | f->SetParent(this); |
5660c520 | 1115 | m_LastLayout = -1; |
5526e819 VS |
1116 | } |
1117 | ||
1118 | ||
1119 | ||
1120 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
1121 | { | |
04dbb646 | 1122 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 1123 | { |
0413cec5 | 1124 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 1125 | alg.MakeUpper(); |
0413cec5 | 1126 | if (alg == wxT("CENTER")) |
efba2b89 | 1127 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 1128 | else if (alg == wxT("LEFT")) |
efba2b89 | 1129 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
1130 | else if (alg == wxT("JUSTIFY")) |
1131 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 1132 | else if (alg == wxT("RIGHT")) |
efba2b89 | 1133 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 1134 | m_LastLayout = -1; |
5526e819 VS |
1135 | } |
1136 | } | |
1137 | ||
1138 | ||
1139 | ||
edbd0635 | 1140 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 1141 | { |
04dbb646 | 1142 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 1143 | { |
5526e819 | 1144 | int wdi; |
0413cec5 | 1145 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 1146 | |
93763ad5 | 1147 | if (wd[wd.length()-1] == wxT('%')) |
0cb9cfb2 | 1148 | { |
66a77a74 | 1149 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 1150 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 1151 | } |
04dbb646 | 1152 | else |
0cb9cfb2 | 1153 | { |
66a77a74 | 1154 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 1155 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 1156 | } |
5660c520 | 1157 | m_LastLayout = -1; |
5526e819 VS |
1158 | } |
1159 | } | |
1160 | ||
1161 | ||
1162 | ||
1163 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
1164 | { | |
04dbb646 | 1165 | if (m_Cells) |
d699f48b | 1166 | { |
bf7d7ee7 VS |
1167 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
1168 | { | |
999836aa | 1169 | const wxHtmlCell *r = cell->Find(condition, param); |
bf7d7ee7 VS |
1170 | if (r) return r; |
1171 | } | |
1172 | } | |
1173 | return NULL; | |
5526e819 VS |
1174 | } |
1175 | ||
1176 | ||
36c4ff4d VS |
1177 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
1178 | unsigned flags) const | |
5526e819 | 1179 | { |
6d41981d | 1180 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 1181 | { |
adf2eb2d VS |
1182 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1183 | { | |
1184 | int cx = cell->GetPosX(), | |
1185 | cy = cell->GetPosY(); | |
1186 | ||
1187 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
1188 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
1189 | { | |
1190 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
1191 | } | |
1192 | } | |
adf2eb2d | 1193 | } |
6d41981d | 1194 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
1195 | { |
1196 | wxHtmlCell *c; | |
adf2eb2d | 1197 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
0cb9cfb2 | 1198 | { |
03693319 VS |
1199 | if ( cell->IsFormattingCell() ) |
1200 | continue; | |
1201 | int cellY = cell->GetPosY(); | |
d1da8872 | 1202 | if (!( y < cellY || (y < cellY + cell->GetHeight() && |
03693319 | 1203 | x < cell->GetPosX() + cell->GetWidth()) )) |
adf2eb2d | 1204 | continue; |
d1da8872 | 1205 | |
03693319 | 1206 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
adf2eb2d | 1207 | if (c) return c; |
5526e819 VS |
1208 | } |
1209 | } | |
6d41981d | 1210 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 1211 | { |
e24529d7 | 1212 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
1213 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1214 | { | |
03693319 VS |
1215 | if ( cell->IsFormattingCell() ) |
1216 | continue; | |
1217 | int cellY = cell->GetPosY(); | |
1218 | if (!( cellY + cell->GetHeight() <= y || | |
1219 | (y >= cellY && x >= cell->GetPosX()) )) | |
adf2eb2d | 1220 | break; |
03693319 | 1221 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
e24529d7 VS |
1222 | if (c2) |
1223 | c = c2; | |
adf2eb2d | 1224 | } |
e24529d7 | 1225 | if (c) return c; |
adf2eb2d | 1226 | } |
6d41981d VZ |
1227 | |
1228 | return NULL; | |
f6010d8f VZ |
1229 | } |
1230 | ||
1231 | ||
bc55e31b VS |
1232 | bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window, |
1233 | const wxPoint& pos, | |
1234 | const wxMouseEvent& event) | |
f6010d8f | 1235 | { |
bc55e31b VS |
1236 | #if WXWIN_COMPATIBILITY_2_6 |
1237 | wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event); | |
1238 | return compat.CallOnMouseClick(this); | |
5526e819 VS |
1239 | } |
1240 | ||
bc55e31b VS |
1241 | void wxHtmlContainerCell::OnMouseClick(wxWindow*, |
1242 | int, int, const wxMouseEvent& event) | |
1243 | { | |
1244 | wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") ); | |
1245 | wxHtmlWindowInterface *window = gs_helperOnMouseClick->window; | |
1246 | const wxPoint& pos = gs_helperOnMouseClick->pos; | |
1247 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1248 | ||
1249 | bool retval = false; | |
1250 | wxHtmlCell *cell = FindCellByPos(pos.x, pos.y); | |
1251 | if ( cell ) | |
1252 | retval = cell->ProcessMouseClick(window, pos, event); | |
1253 | ||
1254 | #if WXWIN_COMPATIBILITY_2_6 | |
1255 | gs_helperOnMouseClick->retval = retval; | |
1256 | #else | |
1257 | return retval; | |
1258 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1259 | } | |
5526e819 VS |
1260 | |
1261 | ||
adf2eb2d VS |
1262 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1263 | { | |
e3774124 VS |
1264 | if ( m_Cells ) |
1265 | { | |
1266 | wxHtmlCell *c2; | |
1267 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1268 | { | |
1269 | c2 = c->GetFirstTerminal(); | |
1270 | if ( c2 ) | |
1271 | return c2; | |
1272 | } | |
1273 | } | |
1274 | return NULL; | |
adf2eb2d VS |
1275 | } |
1276 | ||
1277 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1278 | { | |
e3774124 | 1279 | if ( m_Cells ) |
adf2eb2d | 1280 | { |
e3774124 | 1281 | // most common case first: |
4ce19ed7 | 1282 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1283 | if ( c ) |
1284 | return c; | |
4ce19ed7 | 1285 | |
ace0fab4 | 1286 | wxHtmlCell *ctmp; |
4ce19ed7 VZ |
1287 | wxHtmlCell *c2 = NULL; |
1288 | for (c = m_Cells; c; c = c->GetNext()) | |
ace0fab4 VS |
1289 | { |
1290 | ctmp = c->GetLastTerminal(); | |
1291 | if ( ctmp ) | |
1292 | c2 = ctmp; | |
1293 | } | |
e3774124 | 1294 | return c2; |
adf2eb2d VS |
1295 | } |
1296 | else | |
1297 | return NULL; | |
1298 | } | |
79d6c018 VS |
1299 | |
1300 | ||
ace0fab4 VS |
1301 | static bool IsEmptyContainer(wxHtmlContainerCell *cell) |
1302 | { | |
1303 | for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() ) | |
1304 | { | |
1305 | if ( !c->IsTerminalCell() || !c->IsFormattingCell() ) | |
1306 | return false; | |
1307 | } | |
1308 | return true; | |
1309 | } | |
1310 | ||
1311 | void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom) | |
d1da8872 | 1312 | { |
ace0fab4 VS |
1313 | if ( top ) |
1314 | SetIndent(0, wxHTML_INDENT_TOP); | |
1315 | if ( bottom ) | |
1316 | SetIndent(0, wxHTML_INDENT_BOTTOM); | |
1317 | ||
1318 | if ( m_Cells ) | |
1319 | { | |
1320 | wxHtmlCell *c; | |
1321 | wxHtmlContainerCell *cont; | |
1322 | if ( top ) | |
1323 | { | |
1324 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1325 | { | |
1326 | if ( c->IsTerminalCell() ) | |
1327 | { | |
1328 | if ( !c->IsFormattingCell() ) | |
1329 | break; | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | cont = (wxHtmlContainerCell*)c; | |
1334 | if ( IsEmptyContainer(cont) ) | |
1335 | { | |
1336 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); | |
1337 | } | |
1338 | else | |
1339 | { | |
1340 | cont->RemoveExtraSpacing(true, false); | |
1341 | break; | |
1342 | } | |
1343 | } | |
1344 | } | |
1345 | } | |
d1da8872 | 1346 | |
ace0fab4 VS |
1347 | if ( bottom ) |
1348 | { | |
1349 | wxArrayPtrVoid arr; | |
1350 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1351 | arr.Add((void*)c); | |
d1da8872 | 1352 | |
ace0fab4 VS |
1353 | for ( int i = arr.GetCount() - 1; i >= 0; i--) |
1354 | { | |
1355 | c = (wxHtmlCell*)arr[i]; | |
1356 | if ( c->IsTerminalCell() ) | |
1357 | { | |
1358 | if ( !c->IsFormattingCell() ) | |
1359 | break; | |
1360 | } | |
1361 | else | |
1362 | { | |
1363 | cont = (wxHtmlContainerCell*)c; | |
1364 | if ( IsEmptyContainer(cont) ) | |
1365 | { | |
3e905c52 RD |
1366 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); |
1367 | } | |
ace0fab4 VS |
1368 | else |
1369 | { | |
1370 | cont->RemoveExtraSpacing(false, true); | |
1371 | break; | |
1372 | } | |
1373 | } | |
1374 | } | |
1375 | } | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | ||
5526e819 VS |
1380 | |
1381 | ||
36c4ff4d | 1382 | // -------------------------------------------------------------------------- |
5526e819 | 1383 | // wxHtmlColourCell |
36c4ff4d | 1384 | // -------------------------------------------------------------------------- |
5526e819 | 1385 | |
4f44ea36 MB |
1386 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell) |
1387 | ||
36c4ff4d VS |
1388 | void wxHtmlColourCell::Draw(wxDC& dc, |
1389 | int x, int y, | |
1390 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1391 | wxHtmlRenderingInfo& info) |
5526e819 | 1392 | { |
f30e67db | 1393 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1394 | } |
1395 | ||
36c4ff4d VS |
1396 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1397 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1398 | wxHtmlRenderingInfo& info) |
5526e819 | 1399 | { |
f30e67db | 1400 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1401 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1402 | { |
1403 | state.SetFgColour(m_Colour); | |
1404 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1405 | dc.SetTextForeground(m_Colour); |
1406 | else | |
1407 | dc.SetTextForeground( | |
1408 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1409 | } |
04dbb646 | 1410 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1411 | { |
36c4ff4d VS |
1412 | state.SetBgColour(m_Colour); |
1413 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
b87dd6f5 | 1414 | { |
36c4ff4d | 1415 | dc.SetTextBackground(m_Colour); |
b87dd6f5 VS |
1416 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
1417 | } | |
bfc248a3 | 1418 | else |
b87dd6f5 VS |
1419 | { |
1420 | wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); | |
1421 | dc.SetTextBackground(c); | |
1422 | dc.SetBackground(wxBrush(c, wxSOLID)); | |
1423 | } | |
5526e819 | 1424 | } |
5526e819 VS |
1425 | } |
1426 | ||
1427 | ||
1428 | ||
1429 | ||
36c4ff4d | 1430 | // --------------------------------------------------------------------------- |
5526e819 | 1431 | // wxHtmlFontCell |
36c4ff4d | 1432 | // --------------------------------------------------------------------------- |
5526e819 | 1433 | |
4f44ea36 MB |
1434 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1435 | ||
36c4ff4d VS |
1436 | void wxHtmlFontCell::Draw(wxDC& dc, |
1437 | int WXUNUSED(x), int WXUNUSED(y), | |
1438 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1439 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1440 | { |
921d0fb1 | 1441 | dc.SetFont(m_Font); |
5526e819 VS |
1442 | } |
1443 | ||
36c4ff4d | 1444 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1445 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1446 | { |
921d0fb1 | 1447 | dc.SetFont(m_Font); |
5526e819 VS |
1448 | } |
1449 | ||
1450 | ||
1451 | ||
1452 | ||
1453 | ||
1454 | ||
1455 | ||
1456 | ||
36c4ff4d | 1457 | // --------------------------------------------------------------------------- |
5526e819 | 1458 | // wxHtmlWidgetCell |
36c4ff4d | 1459 | // --------------------------------------------------------------------------- |
5526e819 | 1460 | |
4f44ea36 MB |
1461 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1462 | ||
5526e819 VS |
1463 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1464 | { | |
1465 | int sx, sy; | |
1466 | m_Wnd = wnd; | |
4f9297b0 | 1467 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1468 | m_Width = sx, m_Height = sy; |
1469 | m_WidthFloat = w; | |
1470 | } | |
1471 | ||
1472 | ||
36c4ff4d VS |
1473 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1474 | int WXUNUSED(x), int WXUNUSED(y), | |
1475 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1476 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1477 | { |
1478 | int absx = 0, absy = 0, stx, sty; | |
1479 | wxHtmlCell *c = this; | |
1480 | ||
04dbb646 | 1481 | while (c) |
4f9297b0 VS |
1482 | { |
1483 | absx += c->GetPosX(); | |
1484 | absy += c->GetPosY(); | |
1485 | c = c->GetParent(); | |
5526e819 VS |
1486 | } |
1487 | ||
e421922f | 1488 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1489 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1490 | } |
1491 | ||
1492 | ||
1493 | ||
36c4ff4d VS |
1494 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1495 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1496 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1497 | { |
1498 | int absx = 0, absy = 0, stx, sty; | |
1499 | wxHtmlCell *c = this; | |
1500 | ||
04dbb646 | 1501 | while (c) |
4f9297b0 VS |
1502 | { |
1503 | absx += c->GetPosX(); | |
1504 | absy += c->GetPosY(); | |
1505 | c = c->GetParent(); | |
5526e819 | 1506 | } |
7e941458 | 1507 | |
e421922f | 1508 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1509 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1510 | } |
1511 | ||
1512 | ||
1513 | ||
1514 | void wxHtmlWidgetCell::Layout(int w) | |
1515 | { | |
04dbb646 | 1516 | if (m_WidthFloat != 0) |
4f9297b0 | 1517 | { |
5526e819 | 1518 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1519 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1520 | } |
1521 | ||
1522 | wxHtmlCell::Layout(w); | |
1523 | } | |
1524 | ||
e3774124 VS |
1525 | |
1526 | ||
1527 | // ---------------------------------------------------------------------------- | |
1528 | // wxHtmlTerminalCellsInterator | |
1529 | // ---------------------------------------------------------------------------- | |
1530 | ||
1531 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1532 | { | |
1533 | if ( !m_pos ) | |
1534 | return NULL; | |
1535 | ||
1536 | do | |
1537 | { | |
1538 | if ( m_pos == m_to ) | |
1539 | { | |
1540 | m_pos = NULL; | |
1541 | return NULL; | |
1542 | } | |
1543 | ||
1544 | if ( m_pos->GetNext() ) | |
1545 | m_pos = m_pos->GetNext(); | |
1546 | else | |
1547 | { | |
1548 | // we must go up the hierarchy until we reach container where this | |
1549 | // is not the last child, and then go down to first terminal cell: | |
1550 | while ( m_pos->GetNext() == NULL ) | |
1551 | { | |
1552 | m_pos = m_pos->GetParent(); | |
1553 | if ( !m_pos ) | |
1554 | return NULL; | |
1555 | } | |
1556 | m_pos = m_pos->GetNext(); | |
1557 | } | |
1558 | while ( m_pos->GetFirstChild() != NULL ) | |
1559 | m_pos = m_pos->GetFirstChild(); | |
1560 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1561 | |
e3774124 VS |
1562 | return m_pos; |
1563 | } | |
1564 | ||
5526e819 | 1565 | #endif |