]>
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 | ||
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 |
37 | void 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 | 46 | void 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 |
58 | wxColour |
59 | wxDefaultHtmlRenderingStyle:: | |
60 | GetSelectedTextColour(const wxColour& WXUNUSED(clr)) | |
f30e67db VS |
61 | { |
62 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
63 | } | |
64 | ||
fc7a2a60 VZ |
65 | wxColour |
66 | wxDefaultHtmlRenderingStyle:: | |
67 | GetSelectedTextBgColour(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 |
77 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell, wxObject) |
78 | ||
04dbb646 | 79 | wxHtmlCell::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 | 90 | wxHtmlCell::~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 | |
97 | void 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 | ||
113 | struct wxHtmlCellOnMouseClickCompatHelper; | |
114 | ||
115 | static wxHtmlCellOnMouseClickCompatHelper *gs_helperOnMouseClick = NULL; | |
116 | ||
117 | // helper for routing calls to new ProcessMouseClick() method to deprecated | |
118 | // OnMouseClick() method | |
119 | struct 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 | ||
149 | bool wxHtmlCell::ProcessMouseClick(wxHtmlWindowInterface *window, | |
150 | const wxPoint& pos, | |
151 | const wxMouseEvent& event) | |
152 | { | |
9a83f860 | 153 | wxCHECK_MSG( window, false, wxT("window interface must be provided") ); |
bc55e31b VS |
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 | ||
165 | void wxHtmlCell::OnMouseClick(wxWindow *, int, int, const wxMouseEvent& event) | |
166 | { | |
9a83f860 | 167 | wxCHECK_RET( gs_helperOnMouseClick, wxT("unexpected call to OnMouseClick") ); |
bc55e31b VS |
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 |
193 | wxCursor wxHtmlCell::GetCursor() const |
194 | { | |
88a1b648 VS |
195 | return wxNullCursor; |
196 | } | |
197 | #endif // WXWIN_COMPATIBILITY_2_6 | |
198 | ||
199 | wxCursor 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 | |
4c51a665 | 204 | // overridden GetCursor() continues to work. The trick is that the base |
88a1b648 | 205 | // wxHtmlCell::GetCursor() method simply returns wxNullCursor, so we |
4c51a665 | 206 | // know that GetCursor() was overridden iff it returns valid cursor. |
88a1b648 | 207 | wxCursor cur = GetCursor(); |
a1b806b9 | 208 | if (cur.IsOk()) |
88a1b648 VS |
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 |
223 | bool 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 | 238 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 | 239 | { |
5276b0a5 | 240 | wxDELETE(m_Link); |
af1ed0c1 VS |
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 | ||
9a83f860 | 344 | wxFAIL_MSG(wxT("Cells are in different trees")); |
e3774124 VS |
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; | |
091e74e7 RR |
358 | wxCoord w, h, d; |
359 | dc.GetTextExtent(m_Word, &w, &h, &d); | |
360 | m_Width = w; | |
361 | m_Height = h; | |
362 | m_Descent = d; | |
49f6740f | 363 | SetCanLiveOnPagebreak(false); |
b6d93b26 | 364 | m_allowLinebreak = true; |
5526e819 VS |
365 | } |
366 | ||
b6d93b26 VS |
367 | void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell) |
368 | { | |
369 | if ( cell && m_Parent == cell->m_Parent && | |
370 | !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) ) | |
371 | { | |
372 | m_allowLinebreak = false; | |
373 | } | |
374 | } | |
5526e819 | 375 | |
5a1597e9 VS |
376 | // Splits m_Word into up to three parts according to selection, returns |
377 | // substring before, in and after selection and the points (in relative coords) | |
378 | // where s2 and s3 start: | |
fbfb8bcc | 379 | void wxHtmlWordCell::Split(const wxDC& dc, |
5a1597e9 | 380 | const wxPoint& selFrom, const wxPoint& selTo, |
f30e67db | 381 | unsigned& pos1, unsigned& pos2) const |
5a1597e9 VS |
382 | { |
383 | wxPoint pt1 = (selFrom == wxDefaultPosition) ? | |
384 | wxDefaultPosition : selFrom - GetAbsPos(); | |
385 | wxPoint pt2 = (selTo == wxDefaultPosition) ? | |
422d0ff0 | 386 | wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos(); |
5a1597e9 | 387 | |
117f4046 VS |
388 | // if the selection is entirely within this cell, make sure pt1 < pt2 in |
389 | // order to make the rest of this function simpler: | |
390 | if ( selFrom != wxDefaultPosition && selTo != wxDefaultPosition && | |
391 | selFrom.x > selTo.x ) | |
392 | { | |
393 | wxPoint tmp = pt1; | |
394 | pt1 = pt2; | |
395 | pt2 = tmp; | |
396 | } | |
397 | ||
5a1597e9 VS |
398 | unsigned len = m_Word.length(); |
399 | unsigned i = 0; | |
400 | pos1 = 0; | |
5a1597e9 | 401 | |
03693319 VS |
402 | // adjust for cases when the start/end position is completely |
403 | // outside the cell: | |
404 | if ( pt1.y < 0 ) | |
405 | pt1.x = 0; | |
406 | if ( pt2.y >= m_Height ) | |
407 | pt2.x = m_Width; | |
95af070a VZ |
408 | |
409 | // before selection: | |
8eb3a3a9 | 410 | // (include character under caret only if in first half of width) |
95af070a | 411 | #ifdef __WXMAC__ |
89e94a4b SC |
412 | // implementation using PartialExtents to support fractional widths |
413 | wxArrayInt widths ; | |
414 | dc.GetPartialTextExtents(m_Word,widths) ; | |
89e94a4b SC |
415 | while( i < len && pt1.x >= widths[i] ) |
416 | i++ ; | |
8eb3a3a9 VS |
417 | if ( i < len ) |
418 | { | |
419 | int charW = (i > 0) ? widths[i] - widths[i-1] : widths[i]; | |
420 | if ( widths[i] - pt1.x < charW/2 ) | |
421 | i++; | |
422 | } | |
423 | #else // !__WXMAC__ | |
95af070a | 424 | wxCoord charW, charH; |
5a1597e9 VS |
425 | while ( pt1.x > 0 && i < len ) |
426 | { | |
427 | dc.GetTextExtent(m_Word[i], &charW, &charH); | |
428 | pt1.x -= charW; | |
8eb3a3a9 | 429 | if ( pt1.x >= -charW/2 ) |
5a1597e9 VS |
430 | { |
431 | pos1 += charW; | |
432 | i++; | |
433 | } | |
434 | } | |
95af070a | 435 | #endif // __WXMAC__/!__WXMAC__ |
5526e819 | 436 | |
5a1597e9 | 437 | // in selection: |
8eb3a3a9 | 438 | // (include character under caret only if in first half of width) |
5a1597e9 | 439 | unsigned j = i; |
95af070a | 440 | #ifdef __WXMAC__ |
89e94a4b SC |
441 | while( j < len && pt2.x >= widths[j] ) |
442 | j++ ; | |
8eb3a3a9 VS |
443 | if ( j < len ) |
444 | { | |
445 | int charW = (j > 0) ? widths[j] - widths[j-1] : widths[j]; | |
446 | if ( widths[j] - pt2.x < charW/2 ) | |
447 | j++; | |
448 | } | |
449 | #else // !__WXMAC__ | |
5a1597e9 | 450 | pos2 = pos1; |
f30e67db | 451 | pt2.x -= pos2; |
5a1597e9 VS |
452 | while ( pt2.x > 0 && j < len ) |
453 | { | |
454 | dc.GetTextExtent(m_Word[j], &charW, &charH); | |
455 | pt2.x -= charW; | |
8eb3a3a9 | 456 | if ( pt2.x >= -charW/2 ) |
5a1597e9 VS |
457 | { |
458 | pos2 += charW; | |
459 | j++; | |
460 | } | |
461 | } | |
95af070a | 462 | #endif // __WXMAC__/!__WXMAC__ |
f30e67db VS |
463 | |
464 | pos1 = i; | |
465 | pos2 = j; | |
6a603a10 VS |
466 | |
467 | wxASSERT( pos2 >= pos1 ); | |
f30e67db VS |
468 | } |
469 | ||
fbfb8bcc | 470 | void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const |
f30e67db VS |
471 | { |
472 | unsigned p1, p2; | |
86ff9b45 VZ |
473 | |
474 | Split(dc, | |
f30e67db VS |
475 | this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition, |
476 | this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition, | |
477 | p1, p2); | |
478 | ||
f30e67db | 479 | if ( this == s->GetFromCell() ) |
2f0bebe6 | 480 | s->SetFromCharacterPos (p1); // selection starts here |
f30e67db | 481 | if ( this == s->GetToCell() ) |
2f0bebe6 | 482 | s->SetToCharacterPos (p2); // selection ends here |
5a1597e9 VS |
483 | } |
484 | ||
485 | ||
f30e67db | 486 | static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info, |
5a1597e9 | 487 | bool toSelection) |
5526e819 | 488 | { |
f30e67db VS |
489 | wxColour fg = info.GetState().GetFgColour(); |
490 | wxColour bg = info.GetState().GetBgColour(); | |
86ff9b45 | 491 | |
5a1597e9 | 492 | if ( toSelection ) |
36c4ff4d | 493 | { |
04ee05f9 | 494 | dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); |
f30e67db VS |
495 | dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg)); |
496 | dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg)); | |
b87dd6f5 | 497 | dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg), |
04ee05f9 | 498 | wxBRUSHSTYLE_SOLID)); |
36c4ff4d | 499 | } |
5a1597e9 | 500 | else |
36c4ff4d | 501 | { |
04ee05f9 | 502 | dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
f30e67db VS |
503 | dc.SetTextForeground(fg); |
504 | dc.SetTextBackground(bg); | |
04ee05f9 | 505 | dc.SetBackground(wxBrush(bg, wxBRUSHSTYLE_SOLID)); |
36c4ff4d | 506 | } |
5a1597e9 | 507 | } |
36c4ff4d | 508 | |
5a1597e9 VS |
509 | |
510 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
2a2e4f4a | 511 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), |
f30e67db | 512 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
513 | { |
514 | #if 0 // useful for debugging | |
ace0fab4 | 515 | dc.SetPen(*wxBLACK_PEN); |
4dd9ae57 | 516 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height); |
5a1597e9 VS |
517 | #endif |
518 | ||
b87dd6f5 | 519 | bool drawSelectionAfterCell = false; |
d1da8872 | 520 | |
f30e67db | 521 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
522 | { |
523 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
524 | wxHtmlSelection *s = info.GetSelection(); |
525 | wxString txt; | |
526 | int w, h; | |
527 | int ofs = 0; | |
86ff9b45 | 528 | |
1338c59a VS |
529 | // NB: this is quite a hack: in order to compute selection boundaries |
530 | // (in word's characters) we must know current font, which is only | |
531 | // possible inside rendering code. Therefore we update the | |
532 | // information here and store it in wxHtmlSelection so that | |
533 | // ConvertToText can use it later: | |
2f0bebe6 | 534 | if ( !s->AreFromToCharacterPosSet () ) |
1338c59a VS |
535 | { |
536 | SetSelectionPrivPos(dc, s); | |
1338c59a | 537 | } |
86ff9b45 | 538 | |
2f0bebe6 VZ |
539 | int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
540 | int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
f30e67db VS |
541 | |
542 | if ( part1 > 0 ) | |
5a1597e9 | 543 | { |
f30e67db VS |
544 | txt = m_Word.Mid(0, part1); |
545 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
546 | dc.GetTextExtent(txt, &w, &h); | |
547 | ofs += w; | |
5a1597e9 | 548 | } |
86ff9b45 | 549 | |
f30e67db | 550 | SwitchSelState(dc, info, true); |
86ff9b45 | 551 | |
f30e67db VS |
552 | txt = m_Word.Mid(part1, part2-part1); |
553 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
554 | ||
70bae016 | 555 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 556 | { |
f30e67db VS |
557 | dc.GetTextExtent(txt, &w, &h); |
558 | ofs += w; | |
559 | SwitchSelState(dc, info, false); | |
560 | txt = m_Word.Mid(part2); | |
561 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 | 562 | } |
b87dd6f5 VS |
563 | else |
564 | drawSelectionAfterCell = true; | |
5a1597e9 VS |
565 | } |
566 | else | |
567 | { | |
b87dd6f5 | 568 | wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); |
5a1597e9 | 569 | // Not changing selection state, draw the word in single mode: |
b87dd6f5 | 570 | if ( selstate != wxHTML_SEL_OUT && |
04ee05f9 | 571 | dc.GetBackgroundMode() != wxBRUSHSTYLE_SOLID ) |
5a1597e9 | 572 | { |
f30e67db | 573 | SwitchSelState(dc, info, true); |
5a1597e9 | 574 | } |
b87dd6f5 | 575 | else if ( selstate == wxHTML_SEL_OUT && |
04ee05f9 | 576 | dc.GetBackgroundMode() == wxBRUSHSTYLE_SOLID ) |
5a1597e9 | 577 | { |
f30e67db | 578 | SwitchSelState(dc, info, false); |
5a1597e9 VS |
579 | } |
580 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
b87dd6f5 VS |
581 | drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); |
582 | } | |
583 | ||
584 | // NB: If the text is justified then there is usually some free space | |
585 | // between adjacent cells and drawing the selection only onto cells | |
586 | // would result in ugly unselected spaces. The code below detects | |
587 | // this special case and renders the selection *outside* the sell, | |
588 | // too. | |
589 | if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY && | |
590 | drawSelectionAfterCell ) | |
591 | { | |
592 | wxHtmlCell *nextCell = m_Next; | |
593 | while ( nextCell && nextCell->IsFormattingCell() ) | |
594 | nextCell = nextCell->GetNext(); | |
595 | if ( nextCell ) | |
596 | { | |
597 | int nextX = nextCell->GetPosX(); | |
598 | if ( m_PosX + m_Width < nextX ) | |
599 | { | |
600 | dc.SetBrush(dc.GetBackground()); | |
601 | dc.SetPen(*wxTRANSPARENT_PEN); | |
602 | dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY, | |
603 | nextX - m_PosX - m_Width, m_Height); | |
604 | } | |
605 | } | |
5a1597e9 | 606 | } |
5526e819 | 607 | } |
86ff9b45 | 608 | |
6a603a10 VS |
609 | wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const |
610 | { | |
611 | if ( !GetLink() ) | |
612 | { | |
613 | return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text); | |
614 | } | |
615 | else | |
616 | { | |
617 | return wxHtmlCell::GetMouseCursor(window); | |
618 | } | |
619 | } | |
e3774124 | 620 | |
f30e67db | 621 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 622 | { |
f30e67db VS |
623 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
624 | { | |
86ff9b45 VZ |
625 | // VZ: we may be called before we had a chance to re-render ourselves |
626 | // and in this case GetFrom/ToPrivPos() is not set yet -- assume | |
627 | // that this only happens in case of a double/triple click (which | |
628 | // seems to be the case now) and so it makes sense to select the | |
629 | // entire contents of the cell in this case | |
630 | // | |
631 | // TODO: but this really needs to be fixed in some better way later... | |
2f0bebe6 | 632 | if ( s->AreFromToCharacterPosSet() ) |
86ff9b45 | 633 | { |
2f0bebe6 VZ |
634 | const int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
635 | const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
6a603a10 VS |
636 | if ( part1 == part2 ) |
637 | return wxEmptyString; | |
638 | return GetPartAsText(part1, part2); | |
86ff9b45 VZ |
639 | } |
640 | //else: return the whole word below | |
f30e67db | 641 | } |
86ff9b45 | 642 | |
6a603a10 | 643 | return GetAllAsText(); |
e3774124 | 644 | } |
5526e819 | 645 | |
6a603a10 | 646 | wxString wxHtmlWordWithTabsCell::GetAllAsText() const |
77bae5e2 | 647 | { |
6a603a10 VS |
648 | return m_wordOrig; |
649 | } | |
650 | ||
651 | wxString wxHtmlWordWithTabsCell::GetPartAsText(int begin, int end) const | |
652 | { | |
653 | // NB: The 'begin' and 'end' positions are in the _displayed_ text | |
654 | // (stored in m_Word) and not in the text with tabs that should | |
655 | // be copied to clipboard (m_wordOrig). | |
656 | // | |
657 | // NB: Because selection is performed on displayed text, it's possible | |
658 | // to select e.g. "half of TAB character" -- IOW, 'begin' and 'end' | |
659 | // may be in the middle of TAB character expansion into ' 's. In this | |
660 | // case, we copy the TAB character to clipboard once. | |
661 | ||
662 | wxASSERT( begin < end ); | |
663 | ||
664 | const unsigned SPACES_PER_TAB = 8; | |
665 | ||
666 | wxString sel; | |
667 | ||
668 | int pos = 0; | |
669 | wxString::const_iterator i = m_wordOrig.begin(); | |
670 | ||
671 | // find the beginning of text to copy: | |
672 | for ( ; pos < begin; ++i ) | |
77bae5e2 | 673 | { |
6a603a10 VS |
674 | if ( *i == '\t' ) |
675 | { | |
676 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
677 | if ( pos >= begin ) | |
678 | { | |
679 | sel += '\t'; | |
680 | } | |
681 | } | |
682 | else | |
683 | { | |
684 | ++pos; | |
685 | } | |
77bae5e2 | 686 | } |
6a603a10 VS |
687 | |
688 | // copy the content until we reach 'end': | |
689 | for ( ; pos < end; ++i ) | |
88a1b648 | 690 | { |
6a603a10 VS |
691 | const wxChar c = *i; |
692 | sel += c; | |
693 | ||
694 | if ( c == '\t' ) | |
695 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
696 | else | |
697 | ++pos; | |
88a1b648 | 698 | } |
6a603a10 VS |
699 | |
700 | return sel; | |
77bae5e2 VS |
701 | } |
702 | ||
5526e819 | 703 | |
6a603a10 | 704 | |
5526e819 VS |
705 | //----------------------------------------------------------------------------- |
706 | // wxHtmlContainerCell | |
707 | //----------------------------------------------------------------------------- | |
708 | ||
4f44ea36 | 709 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell) |
5526e819 VS |
710 | |
711 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
712 | { | |
713 | m_Cells = m_LastCell = NULL; | |
714 | m_Parent = parent; | |
ca16b7a9 | 715 | m_MaxTotalWidth = 0; |
4f9297b0 | 716 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
717 | m_AlignHor = wxHTML_ALIGN_LEFT; |
718 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 719 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 720 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
49f6740f | 721 | m_UseBkColour = false; |
3aaaf1aa | 722 | m_Border = 0; |
5c1bfc5d | 723 | m_MinHeight = 0; |
efba2b89 | 724 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 725 | m_LastLayout = -1; |
5526e819 VS |
726 | } |
727 | ||
04dbb646 | 728 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 729 | { |
491c9920 VZ |
730 | wxHtmlCell *cell = m_Cells; |
731 | while ( cell ) | |
bf7d7ee7 | 732 | { |
491c9920 VZ |
733 | wxHtmlCell *cellNext = cell->GetNext(); |
734 | delete cell; | |
735 | cell = cellNext; | |
bf7d7ee7 | 736 | } |
721ab905 VS |
737 | } |
738 | ||
5526e819 VS |
739 | |
740 | ||
741 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
742 | { | |
efba2b89 VS |
743 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
744 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
745 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
746 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
747 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 748 | m_LastLayout = -1; |
5526e819 VS |
749 | } |
750 | ||
751 | ||
752 | ||
753 | int wxHtmlContainerCell::GetIndent(int ind) const | |
754 | { | |
efba2b89 VS |
755 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
756 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
757 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
758 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
759 | else return -1; /* BUG! Should not be called... */ |
760 | } | |
761 | ||
762 | ||
763 | ||
764 | ||
765 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
766 | { | |
49f6740f | 767 | bool p = false; |
efba2b89 VS |
768 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
769 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
770 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
771 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
772 | if (p) return wxHTML_UNITS_PERCENT; | |
773 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
774 | } |
775 | ||
776 | ||
fd0bab43 VZ |
777 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, |
778 | wxArrayInt& known_pagebreaks) const | |
db98870d | 779 | { |
04dbb646 | 780 | if (!m_CanLiveOnPagebreak) |
fd0bab43 | 781 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks); |
e52d6dbc | 782 | |
fd0bab43 VZ |
783 | wxHtmlCell *c = GetFirstChild(); |
784 | bool rt = false; | |
785 | int pbrk = *pagebreak - m_PosY; | |
db98870d | 786 | |
fd0bab43 VZ |
787 | while (c) |
788 | { | |
789 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks)) | |
790 | rt = true; | |
791 | c = c->GetNext(); | |
db98870d | 792 | } |
fd0bab43 VZ |
793 | if (rt) |
794 | *pagebreak = pbrk + m_PosY; | |
795 | return rt; | |
db98870d VS |
796 | } |
797 | ||
798 | ||
5526e819 VS |
799 | void wxHtmlContainerCell::Layout(int w) |
800 | { | |
026d1fac VS |
801 | wxHtmlCell::Layout(w); |
802 | ||
5540b06b VS |
803 | if (m_LastLayout == w) |
804 | return; | |
805 | m_LastLayout = w; | |
0cb9cfb2 | 806 | |
026d1fac VS |
807 | // VS: Any attempt to layout with negative or zero width leads to hell, |
808 | // but we can't ignore such attempts completely, since it sometimes | |
809 | // happen (e.g. when trying how small a table can be). The best thing we | |
810 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 811 | if (w < 1) |
4f9297b0 | 812 | { |
026d1fac VS |
813 | m_Width = 0; |
814 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
815 | cell->Layout(0); | |
2b5f62a0 VZ |
816 | // this does two things: it recursively calls this code on all |
817 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 818 | return; |
04dbb646 | 819 | } |
5660c520 | 820 | |
b6d93b26 | 821 | wxHtmlCell *nextCell; |
5526e819 VS |
822 | long xpos = 0, ypos = m_IndentTop; |
823 | int xdelta = 0, ybasicpos = 0, ydiff; | |
b6d93b26 | 824 | int s_width, nextWordWidth, s_indent; |
5526e819 | 825 | int ysizeup = 0, ysizedown = 0; |
5c1bfc5d | 826 | int MaxLineWidth = 0; |
ca16b7a9 VS |
827 | int curLineWidth = 0; |
828 | m_MaxTotalWidth = 0; | |
5c1bfc5d | 829 | |
5526e819 VS |
830 | |
831 | /* | |
7e941458 | 832 | |
5526e819 | 833 | WIDTH ADJUSTING : |
7e941458 | 834 | |
5526e819 VS |
835 | */ |
836 | ||
04dbb646 | 837 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 838 | { |
5526e819 VS |
839 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
840 | else m_Width = m_WidthFloat * w / 100; | |
841 | } | |
04dbb646 | 842 | else |
4f9297b0 | 843 | { |
5526e819 VS |
844 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
845 | else m_Width = m_WidthFloat; | |
846 | } | |
847 | ||
04dbb646 | 848 | if (m_Cells) |
4f9297b0 | 849 | { |
5526e819 VS |
850 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
851 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
852 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
853 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
854 | } |
855 | ||
856 | /* | |
857 | ||
d13b34d3 | 858 | LAYOUT : |
7e941458 | 859 | |
5526e819 VS |
860 | */ |
861 | ||
862 | // adjust indentation: | |
863 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
864 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
865 | ||
d13b34d3 | 866 | // my own layout: |
17a1ebd1 VZ |
867 | wxHtmlCell *cell = m_Cells, |
868 | *line = m_Cells; | |
04dbb646 | 869 | while (cell != NULL) |
4f9297b0 | 870 | { |
04dbb646 | 871 | switch (m_AlignVer) |
0cb9cfb2 | 872 | { |
efba2b89 | 873 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
874 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
875 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 876 | } |
4f9297b0 | 877 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 878 | |
4f9297b0 VS |
879 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
880 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 881 | |
b6d93b26 | 882 | // layout nonbreakable run of cells: |
4f9297b0 VS |
883 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
884 | xpos += cell->GetWidth(); | |
ca16b7a9 VS |
885 | if (!cell->IsTerminalCell()) |
886 | { | |
887 | // Container cell indicates new line | |
888 | if (curLineWidth > m_MaxTotalWidth) | |
889 | m_MaxTotalWidth = curLineWidth; | |
890 | ||
891 | if (wxMax(cell->GetWidth(), cell->GetMaxTotalWidth()) > m_MaxTotalWidth) | |
892 | m_MaxTotalWidth = cell->GetMaxTotalWidth(); | |
893 | curLineWidth = 0; | |
894 | } | |
895 | else | |
896 | // Normal cell, add maximum cell width to line width | |
897 | curLineWidth += cell->GetMaxTotalWidth(); | |
898 | ||
4f9297b0 | 899 | cell = cell->GetNext(); |
d1da8872 | 900 | |
b6d93b26 VS |
901 | // compute length of the next word that would be added: |
902 | nextWordWidth = 0; | |
903 | if (cell) | |
904 | { | |
905 | nextCell = cell; | |
906 | do | |
907 | { | |
908 | nextWordWidth += nextCell->GetWidth(); | |
909 | nextCell = nextCell->GetNext(); | |
910 | } while (nextCell && !nextCell->IsLinebreakAllowed()); | |
911 | } | |
d1da8872 | 912 | |
3103e8a9 | 913 | // force new line if occurred: |
d1da8872 | 914 | if ((cell == NULL) || |
b6d93b26 | 915 | (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed())) |
0cb9cfb2 | 916 | { |
5c1bfc5d | 917 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
918 | if (ysizeup < 0) ysizeup = 0; |
919 | if (ysizedown < 0) ysizedown = 0; | |
920 | switch (m_AlignHor) { | |
04dbb646 VZ |
921 | case wxHTML_ALIGN_LEFT : |
922 | case wxHTML_ALIGN_JUSTIFY : | |
923 | xdelta = 0; | |
5c1bfc5d | 924 | break; |
04dbb646 VZ |
925 | case wxHTML_ALIGN_RIGHT : |
926 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 927 | break; |
04dbb646 VZ |
928 | case wxHTML_ALIGN_CENTER : |
929 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 930 | break; |
5526e819 VS |
931 | } |
932 | if (xdelta < 0) xdelta = 0; | |
933 | xdelta += s_indent; | |
934 | ||
935 | ypos += ysizeup; | |
04dbb646 | 936 | |
5c1bfc5d | 937 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
a1ae1090 | 938 | { |
04dbb646 | 939 | while (line != cell) |
0cb9cfb2 | 940 | { |
04dbb646 | 941 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
942 | ypos + line->GetPosY()); |
943 | line = line->GetNext(); | |
5c1bfc5d | 944 | } |
a1ae1090 VZ |
945 | } |
946 | else // align == justify | |
04dbb646 | 947 | { |
a1ae1090 VZ |
948 | // we have to distribute the extra horz space between the cells |
949 | // on this line | |
950 | ||
951 | // an added complication is that some cells have fixed size and | |
952 | // shouldn't get any increment (it so happens that these cells | |
953 | // also don't allow line break on them which provides with an | |
4dd9ae57 VZ |
954 | // easy way to test for this) -- and neither should the cells |
955 | // adjacent to them as this could result in a visible space | |
956 | // between two cells separated by, e.g. font change, cell which | |
957 | // is wrong | |
a1ae1090 | 958 | |
2d1d813e | 959 | int step = s_width - xpos; |
a1ae1090 | 960 | if ( step > 0 ) |
0cb9cfb2 | 961 | { |
a1ae1090 | 962 | // first count the cells which will get extra space |
9076e56d | 963 | int total = -1; |
4dd9ae57 | 964 | |
1c0ee565 VS |
965 | const wxHtmlCell *c; |
966 | if ( line != cell ) | |
a1ae1090 | 967 | { |
9076e56d | 968 | for ( c = line; c != cell; c = c->GetNext() ) |
4dd9ae57 | 969 | { |
1c0ee565 VS |
970 | if ( c->IsLinebreakAllowed() ) |
971 | { | |
972 | total++; | |
973 | } | |
4dd9ae57 | 974 | } |
a1ae1090 VZ |
975 | } |
976 | ||
977 | // and now extra space to those cells which merit it | |
978 | if ( total ) | |
979 | { | |
9076e56d VZ |
980 | // first visible cell on line is not moved: |
981 | while (line !=cell && !line->IsLinebreakAllowed()) | |
982 | { | |
983 | line->SetPos(line->GetPosX() + s_indent, | |
984 | line->GetPosY() + ypos); | |
985 | line = line->GetNext(); | |
986 | } | |
987 | ||
988 | if (line != cell) | |
989 | { | |
990 | line->SetPos(line->GetPosX() + s_indent, | |
991 | line->GetPosY() + ypos); | |
992 | ||
993 | line = line->GetNext(); | |
994 | } | |
d1da8872 | 995 | |
1c0ee565 | 996 | for ( int n = 0; line != cell; line = line->GetNext() ) |
a1ae1090 | 997 | { |
1c0ee565 | 998 | if ( line->IsLinebreakAllowed() ) |
a1ae1090 VZ |
999 | { |
1000 | // offset the next cell relative to this one | |
1001 | // thus increasing our size | |
1002 | n++; | |
1003 | } | |
d1da8872 | 1004 | |
1c0ee565 VS |
1005 | line->SetPos(line->GetPosX() + s_indent + |
1006 | ((n * step) / total), | |
1007 | line->GetPosY() + ypos); | |
a1ae1090 VZ |
1008 | } |
1009 | } | |
2d1d813e VS |
1010 | else |
1011 | { | |
1012 | // this will cause the code to enter "else branch" below: | |
1013 | step = 0; | |
1014 | } | |
a1ae1090 | 1015 | } |
2d1d813e VS |
1016 | // else branch: |
1017 | if ( step <= 0 ) // no extra space to distribute | |
a1ae1090 VZ |
1018 | { |
1019 | // just set the indent properly | |
1020 | while (line != cell) | |
1021 | { | |
1022 | line->SetPos(line->GetPosX() + s_indent, | |
1023 | line->GetPosY() + ypos); | |
1024 | line = line->GetNext(); | |
1025 | } | |
5c1bfc5d | 1026 | } |
5526e819 VS |
1027 | } |
1028 | ||
1029 | ypos += ysizedown; | |
49f6740f | 1030 | xpos = 0; |
5526e819 VS |
1031 | ysizeup = ysizedown = 0; |
1032 | line = cell; | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | // setup height & width, depending on container layout: | |
1037 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
1038 | ||
04dbb646 | 1039 | if (m_Height < m_MinHeight) |
4f9297b0 | 1040 | { |
04dbb646 | 1041 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 1042 | { |
5526e819 | 1043 | int diff = m_MinHeight - m_Height; |
efba2b89 | 1044 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 1045 | cell = m_Cells; |
04dbb646 | 1046 | while (cell) |
0cb9cfb2 | 1047 | { |
4f9297b0 VS |
1048 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
1049 | cell = cell->GetNext(); | |
5526e819 VS |
1050 | } |
1051 | } | |
1052 | m_Height = m_MinHeight; | |
1053 | } | |
1054 | ||
ca16b7a9 VS |
1055 | if (curLineWidth > m_MaxTotalWidth) |
1056 | m_MaxTotalWidth = curLineWidth; | |
d1da8872 | 1057 | |
ca16b7a9 | 1058 | m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
5c1bfc5d VS |
1059 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
1060 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 VS |
1061 | } |
1062 | ||
f30e67db | 1063 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
1064 | wxHtmlCell *cell) const |
1065 | { | |
f30e67db | 1066 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 1067 | if (!s) return; |
cd275246 | 1068 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 1069 | { |
f30e67db | 1070 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
1071 | } |
1072 | } | |
1073 | ||
f30e67db | 1074 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
1075 | wxHtmlCell *cell) const |
1076 | { | |
f30e67db | 1077 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 1078 | if (!s) return; |
adf2eb2d | 1079 | if (s->GetToCell() == cell) |
f30e67db | 1080 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 1081 | else if (s->GetFromCell() == cell) |
f30e67db | 1082 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 1083 | } |
5526e819 VS |
1084 | |
1085 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
1086 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
1087 | ||
36c4ff4d | 1088 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 1089 | wxHtmlRenderingInfo& info) |
5526e819 | 1090 | { |
ace0fab4 VS |
1091 | #if 0 // useful for debugging |
1092 | dc.SetPen(*wxRED_PEN); | |
1093 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
1094 | #endif | |
95af070a | 1095 | |
848c4eb2 VS |
1096 | int xlocal = x + m_PosX; |
1097 | int ylocal = y + m_PosY; | |
1098 | ||
1099 | if (m_UseBkColour) | |
4f9297b0 | 1100 | { |
04ee05f9 | 1101 | wxBrush myb = wxBrush(m_BkColour, wxBRUSHSTYLE_SOLID); |
5526e819 | 1102 | |
848c4eb2 VS |
1103 | int real_y1 = mMax(ylocal, view_y1); |
1104 | int real_y2 = mMin(ylocal + m_Height - 1, view_y2); | |
5526e819 | 1105 | |
848c4eb2 VS |
1106 | dc.SetBrush(myb); |
1107 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1108 | dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1); | |
1109 | } | |
5526e819 | 1110 | |
3aaaf1aa | 1111 | if (m_Border == 1) |
848c4eb2 | 1112 | { |
03647350 | 1113 | // draw thin border using lines |
04ee05f9 PC |
1114 | wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID); |
1115 | wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID); | |
848c4eb2 VS |
1116 | |
1117 | dc.SetPen(mypen1); | |
1118 | dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1); | |
1119 | dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal); | |
1120 | dc.SetPen(mypen2); | |
1121 | dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1); | |
1122 | dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1); | |
1123 | } | |
3aaaf1aa | 1124 | else if (m_Border> 0) |
03647350 | 1125 | { |
3aaaf1aa VZ |
1126 | wxBrush mybrush1(m_BorderColour1, wxBRUSHSTYLE_SOLID); |
1127 | wxBrush mybrush2(m_BorderColour2, wxBRUSHSTYLE_SOLID); | |
03647350 | 1128 | |
3aaaf1aa VZ |
1129 | // draw upper left corner |
1130 | // 0---------------5 | |
1131 | // | / | |
1132 | // | 3-----------4 | |
1133 | // | | | |
1134 | // | 2 | |
1135 | // |/ | |
03647350 | 1136 | // 1 |
3aaaf1aa VZ |
1137 | |
1138 | wxPoint poly[6]; | |
1139 | poly[0].x =m_PosX; poly[0].y = m_PosY ; | |
1140 | poly[1].x =m_PosX; poly[1].y = m_PosY + m_Height; | |
1141 | poly[2].x =m_PosX + m_Border; poly[2].y = poly[1].y - m_Border; | |
1142 | poly[3].x =poly[2].x ; poly[3].y = m_PosY + m_Border; | |
1143 | poly[4].x =m_PosX + m_Width - m_Border; poly[4].y = poly[3].y; | |
1144 | poly[5].x =m_PosX + m_Width; poly[5].y = m_PosY; | |
1145 | ||
1146 | dc.SetBrush(mybrush1); | |
1147 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1148 | dc.DrawPolygon(6, poly, x, y); | |
03647350 | 1149 | |
3aaaf1aa VZ |
1150 | // draw lower right corner reusing point 1,2,4 and 5 |
1151 | // 5 | |
1152 | // /| | |
1153 | // 4 | | |
1154 | // | | | |
1155 | // 2-----------3 | | |
1156 | // / | | |
1157 | // 1---------------0 | |
1158 | dc.SetBrush(mybrush2); | |
1159 | poly[0].x = poly[5].x; poly[0].y = poly[1].y; | |
1160 | poly[3].x = poly[4].x; poly[3].y = poly[2].y; | |
1161 | dc.DrawPolygon(6, poly, x, y); | |
1162 | ||
03647350 | 1163 | // smooth color transition like firefox |
3aaaf1aa VZ |
1164 | wxColour borderMediumColour( |
1165 | (m_BorderColour1.Red() + m_BorderColour2.Red()) /2 , | |
1166 | (m_BorderColour1.Green() + m_BorderColour2.Green()) /2 , | |
03647350 | 1167 | (m_BorderColour1.Blue() + m_BorderColour2.Blue()) /2 |
3aaaf1aa VZ |
1168 | ); |
1169 | wxPen mypen3(borderMediumColour, 1, wxPENSTYLE_SOLID); | |
1170 | dc.SetPen(mypen3); | |
1171 | dc.DrawLines(2, &poly[1], x, y - 1); // between 1 and 2 | |
1172 | dc.DrawLines(2, &poly[4], x, y - 1); // between 4 and 5 | |
1173 | } | |
848c4eb2 VS |
1174 | if (m_Cells) |
1175 | { | |
1176 | // draw container's contents: | |
1177 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
bf7d7ee7 | 1178 | { |
95af070a | 1179 | |
848c4eb2 VS |
1180 | // optimize drawing: don't render off-screen content: |
1181 | if ((ylocal + cell->GetPosY() <= view_y2) && | |
1182 | (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1)) | |
36c4ff4d | 1183 | { |
848c4eb2 | 1184 | // the cell is visible, draw it: |
f30e67db | 1185 | UpdateRenderingStatePre(info, cell); |
36c4ff4d | 1186 | cell->Draw(dc, |
848c4eb2 | 1187 | xlocal, ylocal, view_y1, view_y2, |
f30e67db VS |
1188 | info); |
1189 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1190 | } |
848c4eb2 VS |
1191 | else |
1192 | { | |
1193 | // the cell is off-screen, proceed with font+color+etc. | |
1194 | // changes only: | |
1195 | cell->DrawInvisible(dc, xlocal, ylocal, info); | |
1196 | } | |
bf7d7ee7 | 1197 | } |
5526e819 | 1198 | } |
5526e819 VS |
1199 | } |
1200 | ||
1201 | ||
1202 | ||
36c4ff4d | 1203 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 1204 | wxHtmlRenderingInfo& info) |
5526e819 | 1205 | { |
d699f48b | 1206 | if (m_Cells) |
bf7d7ee7 VS |
1207 | { |
1208 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 1209 | { |
f30e67db VS |
1210 | UpdateRenderingStatePre(info, cell); |
1211 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
1212 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1213 | } |
bf7d7ee7 | 1214 | } |
5526e819 VS |
1215 | } |
1216 | ||
1217 | ||
2b5f62a0 VZ |
1218 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
1219 | { | |
1220 | if (m_UseBkColour) | |
1221 | return m_BkColour; | |
1222 | else | |
1223 | return wxNullColour; | |
1224 | } | |
1225 | ||
1226 | ||
5526e819 | 1227 | |
846914d1 | 1228 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 1229 | { |
f6010d8f | 1230 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 1231 | |
f6010d8f VZ |
1232 | // VZ: I don't know if we should pass absolute or relative coords to |
1233 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
1234 | // anyhow, it hardly matters right now but should still be clarified | |
1235 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
1236 | } |
1237 | ||
1238 | ||
1239 | ||
1240 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
1241 | { | |
1242 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 1243 | else |
4f9297b0 VS |
1244 | { |
1245 | m_LastCell->SetNext(f); | |
5526e819 | 1246 | m_LastCell = f; |
4f9297b0 | 1247 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 1248 | } |
4f9297b0 | 1249 | f->SetParent(this); |
5660c520 | 1250 | m_LastLayout = -1; |
5526e819 VS |
1251 | } |
1252 | ||
1253 | ||
1254 | ||
1255 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
1256 | { | |
04dbb646 | 1257 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 1258 | { |
0413cec5 | 1259 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 1260 | alg.MakeUpper(); |
0413cec5 | 1261 | if (alg == wxT("CENTER")) |
efba2b89 | 1262 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 1263 | else if (alg == wxT("LEFT")) |
efba2b89 | 1264 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
1265 | else if (alg == wxT("JUSTIFY")) |
1266 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 1267 | else if (alg == wxT("RIGHT")) |
efba2b89 | 1268 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 1269 | m_LastLayout = -1; |
5526e819 VS |
1270 | } |
1271 | } | |
1272 | ||
1273 | ||
1274 | ||
edbd0635 | 1275 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 1276 | { |
04dbb646 | 1277 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 1278 | { |
5526e819 | 1279 | int wdi; |
0413cec5 | 1280 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 1281 | |
93763ad5 | 1282 | if (wd[wd.length()-1] == wxT('%')) |
0cb9cfb2 | 1283 | { |
66a77a74 | 1284 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 1285 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 1286 | } |
04dbb646 | 1287 | else |
0cb9cfb2 | 1288 | { |
66a77a74 | 1289 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 1290 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 1291 | } |
5660c520 | 1292 | m_LastLayout = -1; |
5526e819 VS |
1293 | } |
1294 | } | |
1295 | ||
1296 | ||
1297 | ||
1298 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
1299 | { | |
04dbb646 | 1300 | if (m_Cells) |
d699f48b | 1301 | { |
bf7d7ee7 VS |
1302 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
1303 | { | |
999836aa | 1304 | const wxHtmlCell *r = cell->Find(condition, param); |
bf7d7ee7 VS |
1305 | if (r) return r; |
1306 | } | |
1307 | } | |
1308 | return NULL; | |
5526e819 VS |
1309 | } |
1310 | ||
1311 | ||
36c4ff4d VS |
1312 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
1313 | unsigned flags) const | |
5526e819 | 1314 | { |
6d41981d | 1315 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 1316 | { |
adf2eb2d VS |
1317 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1318 | { | |
1319 | int cx = cell->GetPosX(), | |
1320 | cy = cell->GetPosY(); | |
1321 | ||
1322 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
1323 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
1324 | { | |
1325 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
1326 | } | |
1327 | } | |
adf2eb2d | 1328 | } |
6d41981d | 1329 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
1330 | { |
1331 | wxHtmlCell *c; | |
adf2eb2d | 1332 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
0cb9cfb2 | 1333 | { |
03693319 VS |
1334 | if ( cell->IsFormattingCell() ) |
1335 | continue; | |
1336 | int cellY = cell->GetPosY(); | |
d1da8872 | 1337 | if (!( y < cellY || (y < cellY + cell->GetHeight() && |
03693319 | 1338 | x < cell->GetPosX() + cell->GetWidth()) )) |
adf2eb2d | 1339 | continue; |
d1da8872 | 1340 | |
03693319 | 1341 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
adf2eb2d | 1342 | if (c) return c; |
5526e819 VS |
1343 | } |
1344 | } | |
6d41981d | 1345 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 1346 | { |
e24529d7 | 1347 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
1348 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1349 | { | |
03693319 VS |
1350 | if ( cell->IsFormattingCell() ) |
1351 | continue; | |
1352 | int cellY = cell->GetPosY(); | |
1353 | if (!( cellY + cell->GetHeight() <= y || | |
1354 | (y >= cellY && x >= cell->GetPosX()) )) | |
adf2eb2d | 1355 | break; |
03693319 | 1356 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
e24529d7 VS |
1357 | if (c2) |
1358 | c = c2; | |
adf2eb2d | 1359 | } |
e24529d7 | 1360 | if (c) return c; |
adf2eb2d | 1361 | } |
6d41981d VZ |
1362 | |
1363 | return NULL; | |
f6010d8f VZ |
1364 | } |
1365 | ||
1366 | ||
bc55e31b VS |
1367 | bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window, |
1368 | const wxPoint& pos, | |
1369 | const wxMouseEvent& event) | |
f6010d8f | 1370 | { |
bc55e31b VS |
1371 | #if WXWIN_COMPATIBILITY_2_6 |
1372 | wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event); | |
1373 | return compat.CallOnMouseClick(this); | |
5526e819 VS |
1374 | } |
1375 | ||
bc55e31b VS |
1376 | void wxHtmlContainerCell::OnMouseClick(wxWindow*, |
1377 | int, int, const wxMouseEvent& event) | |
1378 | { | |
9a83f860 | 1379 | wxCHECK_RET( gs_helperOnMouseClick, wxT("unexpected call to OnMouseClick") ); |
bc55e31b VS |
1380 | wxHtmlWindowInterface *window = gs_helperOnMouseClick->window; |
1381 | const wxPoint& pos = gs_helperOnMouseClick->pos; | |
1382 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1383 | ||
1384 | bool retval = false; | |
1385 | wxHtmlCell *cell = FindCellByPos(pos.x, pos.y); | |
1386 | if ( cell ) | |
1387 | retval = cell->ProcessMouseClick(window, pos, event); | |
1388 | ||
1389 | #if WXWIN_COMPATIBILITY_2_6 | |
1390 | gs_helperOnMouseClick->retval = retval; | |
1391 | #else | |
1392 | return retval; | |
1393 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1394 | } | |
5526e819 VS |
1395 | |
1396 | ||
adf2eb2d VS |
1397 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1398 | { | |
e3774124 VS |
1399 | if ( m_Cells ) |
1400 | { | |
1401 | wxHtmlCell *c2; | |
1402 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1403 | { | |
1404 | c2 = c->GetFirstTerminal(); | |
1405 | if ( c2 ) | |
1406 | return c2; | |
1407 | } | |
1408 | } | |
1409 | return NULL; | |
adf2eb2d VS |
1410 | } |
1411 | ||
1412 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1413 | { | |
e3774124 | 1414 | if ( m_Cells ) |
adf2eb2d | 1415 | { |
e3774124 | 1416 | // most common case first: |
4ce19ed7 | 1417 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1418 | if ( c ) |
1419 | return c; | |
4ce19ed7 | 1420 | |
ace0fab4 | 1421 | wxHtmlCell *ctmp; |
4ce19ed7 VZ |
1422 | wxHtmlCell *c2 = NULL; |
1423 | for (c = m_Cells; c; c = c->GetNext()) | |
ace0fab4 VS |
1424 | { |
1425 | ctmp = c->GetLastTerminal(); | |
1426 | if ( ctmp ) | |
1427 | c2 = ctmp; | |
1428 | } | |
e3774124 | 1429 | return c2; |
adf2eb2d VS |
1430 | } |
1431 | else | |
1432 | return NULL; | |
1433 | } | |
79d6c018 VS |
1434 | |
1435 | ||
ace0fab4 VS |
1436 | static bool IsEmptyContainer(wxHtmlContainerCell *cell) |
1437 | { | |
1438 | for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() ) | |
1439 | { | |
1440 | if ( !c->IsTerminalCell() || !c->IsFormattingCell() ) | |
1441 | return false; | |
1442 | } | |
1443 | return true; | |
1444 | } | |
1445 | ||
1446 | void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom) | |
d1da8872 | 1447 | { |
ace0fab4 VS |
1448 | if ( top ) |
1449 | SetIndent(0, wxHTML_INDENT_TOP); | |
1450 | if ( bottom ) | |
1451 | SetIndent(0, wxHTML_INDENT_BOTTOM); | |
1452 | ||
1453 | if ( m_Cells ) | |
1454 | { | |
1455 | wxHtmlCell *c; | |
1456 | wxHtmlContainerCell *cont; | |
1457 | if ( top ) | |
1458 | { | |
1459 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1460 | { | |
1461 | if ( c->IsTerminalCell() ) | |
1462 | { | |
1463 | if ( !c->IsFormattingCell() ) | |
1464 | break; | |
1465 | } | |
1466 | else | |
1467 | { | |
1468 | cont = (wxHtmlContainerCell*)c; | |
1469 | if ( IsEmptyContainer(cont) ) | |
1470 | { | |
1471 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); | |
1472 | } | |
1473 | else | |
1474 | { | |
1475 | cont->RemoveExtraSpacing(true, false); | |
1476 | break; | |
1477 | } | |
1478 | } | |
1479 | } | |
1480 | } | |
d1da8872 | 1481 | |
ace0fab4 VS |
1482 | if ( bottom ) |
1483 | { | |
1484 | wxArrayPtrVoid arr; | |
1485 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1486 | arr.Add((void*)c); | |
d1da8872 | 1487 | |
ace0fab4 VS |
1488 | for ( int i = arr.GetCount() - 1; i >= 0; i--) |
1489 | { | |
1490 | c = (wxHtmlCell*)arr[i]; | |
1491 | if ( c->IsTerminalCell() ) | |
1492 | { | |
1493 | if ( !c->IsFormattingCell() ) | |
1494 | break; | |
1495 | } | |
1496 | else | |
1497 | { | |
1498 | cont = (wxHtmlContainerCell*)c; | |
1499 | if ( IsEmptyContainer(cont) ) | |
1500 | { | |
3e905c52 RD |
1501 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); |
1502 | } | |
ace0fab4 VS |
1503 | else |
1504 | { | |
1505 | cont->RemoveExtraSpacing(false, true); | |
1506 | break; | |
1507 | } | |
1508 | } | |
1509 | } | |
1510 | } | |
1511 | } | |
1512 | } | |
1513 | ||
1514 | ||
5526e819 VS |
1515 | |
1516 | ||
36c4ff4d | 1517 | // -------------------------------------------------------------------------- |
5526e819 | 1518 | // wxHtmlColourCell |
36c4ff4d | 1519 | // -------------------------------------------------------------------------- |
5526e819 | 1520 | |
4f44ea36 MB |
1521 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell) |
1522 | ||
36c4ff4d VS |
1523 | void wxHtmlColourCell::Draw(wxDC& dc, |
1524 | int x, int y, | |
1525 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1526 | wxHtmlRenderingInfo& info) |
5526e819 | 1527 | { |
f30e67db | 1528 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1529 | } |
1530 | ||
36c4ff4d VS |
1531 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1532 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1533 | wxHtmlRenderingInfo& info) |
5526e819 | 1534 | { |
f30e67db | 1535 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1536 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1537 | { |
1538 | state.SetFgColour(m_Colour); | |
1539 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1540 | dc.SetTextForeground(m_Colour); |
1541 | else | |
1542 | dc.SetTextForeground( | |
1543 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1544 | } |
04dbb646 | 1545 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1546 | { |
36c4ff4d VS |
1547 | state.SetBgColour(m_Colour); |
1548 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
b87dd6f5 | 1549 | { |
36c4ff4d | 1550 | dc.SetTextBackground(m_Colour); |
04ee05f9 | 1551 | dc.SetBackground(wxBrush(m_Colour, wxBRUSHSTYLE_SOLID)); |
b87dd6f5 | 1552 | } |
bfc248a3 | 1553 | else |
b87dd6f5 VS |
1554 | { |
1555 | wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); | |
1556 | dc.SetTextBackground(c); | |
04ee05f9 | 1557 | dc.SetBackground(wxBrush(c, wxBRUSHSTYLE_SOLID)); |
b87dd6f5 | 1558 | } |
5526e819 | 1559 | } |
5526e819 VS |
1560 | } |
1561 | ||
1562 | ||
1563 | ||
1564 | ||
36c4ff4d | 1565 | // --------------------------------------------------------------------------- |
5526e819 | 1566 | // wxHtmlFontCell |
36c4ff4d | 1567 | // --------------------------------------------------------------------------- |
5526e819 | 1568 | |
4f44ea36 MB |
1569 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1570 | ||
36c4ff4d VS |
1571 | void wxHtmlFontCell::Draw(wxDC& dc, |
1572 | int WXUNUSED(x), int WXUNUSED(y), | |
1573 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1574 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1575 | { |
921d0fb1 | 1576 | dc.SetFont(m_Font); |
5526e819 VS |
1577 | } |
1578 | ||
36c4ff4d | 1579 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1580 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1581 | { |
921d0fb1 | 1582 | dc.SetFont(m_Font); |
5526e819 VS |
1583 | } |
1584 | ||
1585 | ||
1586 | ||
1587 | ||
1588 | ||
1589 | ||
1590 | ||
1591 | ||
36c4ff4d | 1592 | // --------------------------------------------------------------------------- |
5526e819 | 1593 | // wxHtmlWidgetCell |
36c4ff4d | 1594 | // --------------------------------------------------------------------------- |
5526e819 | 1595 | |
4f44ea36 MB |
1596 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1597 | ||
5526e819 VS |
1598 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1599 | { | |
1600 | int sx, sy; | |
1601 | m_Wnd = wnd; | |
4f9297b0 | 1602 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1603 | m_Width = sx, m_Height = sy; |
1604 | m_WidthFloat = w; | |
1605 | } | |
1606 | ||
1607 | ||
36c4ff4d VS |
1608 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1609 | int WXUNUSED(x), int WXUNUSED(y), | |
1610 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1611 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1612 | { |
1613 | int absx = 0, absy = 0, stx, sty; | |
1614 | wxHtmlCell *c = this; | |
1615 | ||
04dbb646 | 1616 | while (c) |
4f9297b0 VS |
1617 | { |
1618 | absx += c->GetPosX(); | |
1619 | absy += c->GetPosY(); | |
1620 | c = c->GetParent(); | |
5526e819 VS |
1621 | } |
1622 | ||
c4184573 VS |
1623 | wxScrolledWindow *scrolwin = |
1624 | wxDynamicCast(m_Wnd->GetParent(), wxScrolledWindow); | |
1625 | wxCHECK_RET( scrolwin, | |
9a83f860 | 1626 | wxT("widget cells can only be placed in wxHtmlWindow") ); |
c4184573 VS |
1627 | |
1628 | scrolwin->GetViewStart(&stx, &sty); | |
1629 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, | |
1630 | absy - wxHTML_SCROLL_STEP * sty, | |
1631 | m_Width, m_Height); | |
5526e819 VS |
1632 | } |
1633 | ||
1634 | ||
1635 | ||
36c4ff4d VS |
1636 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1637 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1638 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1639 | { |
1640 | int absx = 0, absy = 0, stx, sty; | |
1641 | wxHtmlCell *c = this; | |
1642 | ||
04dbb646 | 1643 | while (c) |
4f9297b0 VS |
1644 | { |
1645 | absx += c->GetPosX(); | |
1646 | absy += c->GetPosY(); | |
1647 | c = c->GetParent(); | |
5526e819 | 1648 | } |
7e941458 | 1649 | |
e421922f | 1650 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1651 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1652 | } |
1653 | ||
1654 | ||
1655 | ||
1656 | void wxHtmlWidgetCell::Layout(int w) | |
1657 | { | |
04dbb646 | 1658 | if (m_WidthFloat != 0) |
4f9297b0 | 1659 | { |
5526e819 | 1660 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1661 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1662 | } |
1663 | ||
1664 | wxHtmlCell::Layout(w); | |
1665 | } | |
1666 | ||
e3774124 VS |
1667 | |
1668 | ||
1669 | // ---------------------------------------------------------------------------- | |
1670 | // wxHtmlTerminalCellsInterator | |
1671 | // ---------------------------------------------------------------------------- | |
1672 | ||
1673 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1674 | { | |
1675 | if ( !m_pos ) | |
1676 | return NULL; | |
1677 | ||
1678 | do | |
1679 | { | |
1680 | if ( m_pos == m_to ) | |
1681 | { | |
1682 | m_pos = NULL; | |
1683 | return NULL; | |
1684 | } | |
1685 | ||
1686 | if ( m_pos->GetNext() ) | |
1687 | m_pos = m_pos->GetNext(); | |
1688 | else | |
1689 | { | |
1690 | // we must go up the hierarchy until we reach container where this | |
1691 | // is not the last child, and then go down to first terminal cell: | |
1692 | while ( m_pos->GetNext() == NULL ) | |
1693 | { | |
1694 | m_pos = m_pos->GetParent(); | |
1695 | if ( !m_pos ) | |
1696 | return NULL; | |
1697 | } | |
1698 | m_pos = m_pos->GetNext(); | |
1699 | } | |
1700 | while ( m_pos->GetFirstChild() != NULL ) | |
1701 | m_pos = m_pos->GetFirstChild(); | |
1702 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1703 | |
e3774124 VS |
1704 | return m_pos; |
1705 | } | |
1706 | ||
5526e819 | 1707 | #endif |