]>
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 | |
846f4568 VZ |
223 | bool |
224 | wxHtmlCell::AdjustPagebreak(int *pagebreak, | |
225 | const wxArrayInt& WXUNUSED(known_pagebreaks), | |
226 | int pageHeight) const | |
227 | { | |
228 | // Notice that we always break the cells bigger than the page height here | |
229 | // as otherwise we wouldn't be able to break them at all. | |
230 | if ( m_Height <= pageHeight && | |
231 | (!m_CanLiveOnPagebreak && | |
232 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) ) | |
0cb9cfb2 | 233 | { |
db98870d | 234 | *pagebreak = m_PosY; |
49f6740f | 235 | return true; |
db98870d | 236 | } |
0cb9cfb2 | 237 | |
49f6740f | 238 | return false; |
db98870d VS |
239 | } |
240 | ||
241 | ||
242 | ||
04dbb646 | 243 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 | 244 | { |
5276b0a5 | 245 | wxDELETE(m_Link); |
af1ed0c1 VS |
246 | if (link.GetHref() != wxEmptyString) |
247 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
248 | } |
249 | ||
250 | ||
d699f48b | 251 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 252 | { |
04dbb646 | 253 | SetPos(0, 0); |
721ab905 VS |
254 | } |
255 | ||
256 | ||
79d6c018 | 257 | |
d699f48b | 258 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 259 | { |
bf7d7ee7 | 260 | return NULL; |
721ab905 VS |
261 | } |
262 | ||
263 | ||
36c4ff4d VS |
264 | wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y, |
265 | unsigned flags) const | |
f6010d8f | 266 | { |
adf2eb2d | 267 | if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height ) |
36c4ff4d | 268 | { |
f6010d8f | 269 | return wxConstCast(this, wxHtmlCell); |
36c4ff4d | 270 | } |
adf2eb2d VS |
271 | else |
272 | { | |
273 | if ((flags & wxHTML_FIND_NEAREST_AFTER) && | |
03693319 | 274 | (y < 0 || (y < 0+m_Height && x < 0+m_Width))) |
adf2eb2d VS |
275 | return wxConstCast(this, wxHtmlCell); |
276 | else if ((flags & wxHTML_FIND_NEAREST_BEFORE) && | |
03693319 | 277 | (y >= 0+m_Height || (y >= 0 && x >= 0))) |
adf2eb2d VS |
278 | return wxConstCast(this, wxHtmlCell); |
279 | else | |
280 | return NULL; | |
281 | } | |
282 | } | |
283 | ||
284 | ||
bc55e31b | 285 | wxPoint wxHtmlCell::GetAbsPos(wxHtmlCell *rootCell) const |
adf2eb2d VS |
286 | { |
287 | wxPoint p(m_PosX, m_PosY); | |
bc55e31b VS |
288 | for (wxHtmlCell *parent = m_Parent; parent && parent != rootCell; |
289 | parent = parent->m_Parent) | |
adf2eb2d VS |
290 | { |
291 | p.x += parent->m_PosX; | |
292 | p.y += parent->m_PosY; | |
293 | } | |
294 | return p; | |
f6010d8f | 295 | } |
86ff9b45 | 296 | |
bc55e31b VS |
297 | wxHtmlCell *wxHtmlCell::GetRootCell() const |
298 | { | |
299 | wxHtmlCell *c = wxConstCast(this, wxHtmlCell); | |
300 | while ( c->m_Parent ) | |
301 | c = c->m_Parent; | |
302 | return c; | |
303 | } | |
304 | ||
e3774124 VS |
305 | unsigned wxHtmlCell::GetDepth() const |
306 | { | |
307 | unsigned d = 0; | |
308 | for (wxHtmlCell *p = m_Parent; p; p = p->m_Parent) | |
309 | d++; | |
310 | return d; | |
311 | } | |
86ff9b45 | 312 | |
e3774124 VS |
313 | bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const |
314 | { | |
315 | const wxHtmlCell *c1 = this; | |
316 | const wxHtmlCell *c2 = cell; | |
317 | unsigned d1 = GetDepth(); | |
318 | unsigned d2 = cell->GetDepth(); | |
319 | ||
320 | if ( d1 > d2 ) | |
321 | for (; d1 != d2; d1-- ) | |
322 | c1 = c1->m_Parent; | |
323 | else if ( d1 < d2 ) | |
324 | for (; d1 != d2; d2-- ) | |
325 | c2 = c2->m_Parent; | |
326 | ||
327 | if ( cell == this ) | |
328 | return true; | |
329 | ||
330 | while ( c1 && c2 ) | |
331 | { | |
332 | if ( c1->m_Parent == c2->m_Parent ) | |
333 | { | |
334 | while ( c1 ) | |
335 | { | |
336 | if ( c1 == c2 ) | |
337 | return true; | |
338 | c1 = c1->GetNext(); | |
86ff9b45 | 339 | } |
e3774124 VS |
340 | return false; |
341 | } | |
342 | else | |
343 | { | |
344 | c1 = c1->m_Parent; | |
345 | c2 = c2->m_Parent; | |
346 | } | |
347 | } | |
348 | ||
9a83f860 | 349 | wxFAIL_MSG(wxT("Cells are in different trees")); |
e3774124 VS |
350 | return false; |
351 | } | |
f6010d8f | 352 | |
721ab905 | 353 | |
5526e819 VS |
354 | //----------------------------------------------------------------------------- |
355 | // wxHtmlWordCell | |
356 | //----------------------------------------------------------------------------- | |
357 | ||
4f44ea36 MB |
358 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell) |
359 | ||
fbfb8bcc | 360 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, const wxDC& dc) : wxHtmlCell() |
5526e819 VS |
361 | { |
362 | m_Word = word; | |
091e74e7 RR |
363 | wxCoord w, h, d; |
364 | dc.GetTextExtent(m_Word, &w, &h, &d); | |
365 | m_Width = w; | |
366 | m_Height = h; | |
367 | m_Descent = d; | |
49f6740f | 368 | SetCanLiveOnPagebreak(false); |
b6d93b26 | 369 | m_allowLinebreak = true; |
5526e819 VS |
370 | } |
371 | ||
b6d93b26 VS |
372 | void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell) |
373 | { | |
374 | if ( cell && m_Parent == cell->m_Parent && | |
375 | !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) ) | |
376 | { | |
377 | m_allowLinebreak = false; | |
378 | } | |
379 | } | |
5526e819 | 380 | |
5a1597e9 VS |
381 | // Splits m_Word into up to three parts according to selection, returns |
382 | // substring before, in and after selection and the points (in relative coords) | |
383 | // where s2 and s3 start: | |
fbfb8bcc | 384 | void wxHtmlWordCell::Split(const wxDC& dc, |
5a1597e9 | 385 | const wxPoint& selFrom, const wxPoint& selTo, |
f30e67db | 386 | unsigned& pos1, unsigned& pos2) const |
5a1597e9 VS |
387 | { |
388 | wxPoint pt1 = (selFrom == wxDefaultPosition) ? | |
389 | wxDefaultPosition : selFrom - GetAbsPos(); | |
390 | wxPoint pt2 = (selTo == wxDefaultPosition) ? | |
422d0ff0 | 391 | wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos(); |
5a1597e9 | 392 | |
117f4046 VS |
393 | // if the selection is entirely within this cell, make sure pt1 < pt2 in |
394 | // order to make the rest of this function simpler: | |
395 | if ( selFrom != wxDefaultPosition && selTo != wxDefaultPosition && | |
396 | selFrom.x > selTo.x ) | |
397 | { | |
398 | wxPoint tmp = pt1; | |
399 | pt1 = pt2; | |
400 | pt2 = tmp; | |
401 | } | |
402 | ||
5a1597e9 VS |
403 | unsigned len = m_Word.length(); |
404 | unsigned i = 0; | |
405 | pos1 = 0; | |
5a1597e9 | 406 | |
03693319 VS |
407 | // adjust for cases when the start/end position is completely |
408 | // outside the cell: | |
409 | if ( pt1.y < 0 ) | |
410 | pt1.x = 0; | |
411 | if ( pt2.y >= m_Height ) | |
412 | pt2.x = m_Width; | |
95af070a VZ |
413 | |
414 | // before selection: | |
8eb3a3a9 | 415 | // (include character under caret only if in first half of width) |
95af070a | 416 | #ifdef __WXMAC__ |
89e94a4b SC |
417 | // implementation using PartialExtents to support fractional widths |
418 | wxArrayInt widths ; | |
419 | dc.GetPartialTextExtents(m_Word,widths) ; | |
89e94a4b SC |
420 | while( i < len && pt1.x >= widths[i] ) |
421 | i++ ; | |
8eb3a3a9 VS |
422 | if ( i < len ) |
423 | { | |
424 | int charW = (i > 0) ? widths[i] - widths[i-1] : widths[i]; | |
425 | if ( widths[i] - pt1.x < charW/2 ) | |
426 | i++; | |
427 | } | |
428 | #else // !__WXMAC__ | |
95af070a | 429 | wxCoord charW, charH; |
5a1597e9 VS |
430 | while ( pt1.x > 0 && i < len ) |
431 | { | |
432 | dc.GetTextExtent(m_Word[i], &charW, &charH); | |
433 | pt1.x -= charW; | |
8eb3a3a9 | 434 | if ( pt1.x >= -charW/2 ) |
5a1597e9 VS |
435 | { |
436 | pos1 += charW; | |
437 | i++; | |
438 | } | |
439 | } | |
95af070a | 440 | #endif // __WXMAC__/!__WXMAC__ |
5526e819 | 441 | |
5a1597e9 | 442 | // in selection: |
8eb3a3a9 | 443 | // (include character under caret only if in first half of width) |
5a1597e9 | 444 | unsigned j = i; |
95af070a | 445 | #ifdef __WXMAC__ |
89e94a4b SC |
446 | while( j < len && pt2.x >= widths[j] ) |
447 | j++ ; | |
8eb3a3a9 VS |
448 | if ( j < len ) |
449 | { | |
450 | int charW = (j > 0) ? widths[j] - widths[j-1] : widths[j]; | |
451 | if ( widths[j] - pt2.x < charW/2 ) | |
452 | j++; | |
453 | } | |
454 | #else // !__WXMAC__ | |
5a1597e9 | 455 | pos2 = pos1; |
f30e67db | 456 | pt2.x -= pos2; |
5a1597e9 VS |
457 | while ( pt2.x > 0 && j < len ) |
458 | { | |
459 | dc.GetTextExtent(m_Word[j], &charW, &charH); | |
460 | pt2.x -= charW; | |
8eb3a3a9 | 461 | if ( pt2.x >= -charW/2 ) |
5a1597e9 VS |
462 | { |
463 | pos2 += charW; | |
464 | j++; | |
465 | } | |
466 | } | |
95af070a | 467 | #endif // __WXMAC__/!__WXMAC__ |
f30e67db VS |
468 | |
469 | pos1 = i; | |
470 | pos2 = j; | |
6a603a10 VS |
471 | |
472 | wxASSERT( pos2 >= pos1 ); | |
f30e67db VS |
473 | } |
474 | ||
fbfb8bcc | 475 | void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const |
f30e67db VS |
476 | { |
477 | unsigned p1, p2; | |
86ff9b45 VZ |
478 | |
479 | Split(dc, | |
f30e67db VS |
480 | this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition, |
481 | this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition, | |
482 | p1, p2); | |
483 | ||
f30e67db | 484 | if ( this == s->GetFromCell() ) |
2f0bebe6 | 485 | s->SetFromCharacterPos (p1); // selection starts here |
f30e67db | 486 | if ( this == s->GetToCell() ) |
2f0bebe6 | 487 | s->SetToCharacterPos (p2); // selection ends here |
5a1597e9 VS |
488 | } |
489 | ||
490 | ||
f30e67db | 491 | static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info, |
5a1597e9 | 492 | bool toSelection) |
5526e819 | 493 | { |
f30e67db VS |
494 | wxColour fg = info.GetState().GetFgColour(); |
495 | wxColour bg = info.GetState().GetBgColour(); | |
86ff9b45 | 496 | |
5a1597e9 | 497 | if ( toSelection ) |
36c4ff4d | 498 | { |
3ee9771b | 499 | dc.SetBackgroundMode(wxSOLID); |
f30e67db VS |
500 | dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg)); |
501 | dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg)); | |
b87dd6f5 | 502 | dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg), |
04ee05f9 | 503 | wxBRUSHSTYLE_SOLID)); |
36c4ff4d | 504 | } |
5a1597e9 | 505 | else |
36c4ff4d | 506 | { |
f5413b87 VZ |
507 | const int mode = info.GetState().GetBgMode(); |
508 | dc.SetBackgroundMode(mode); | |
f30e67db VS |
509 | dc.SetTextForeground(fg); |
510 | dc.SetTextBackground(bg); | |
f5413b87 VZ |
511 | if ( mode != wxTRANSPARENT ) |
512 | dc.SetBackground(wxBrush(bg, mode)); | |
36c4ff4d | 513 | } |
5a1597e9 | 514 | } |
36c4ff4d | 515 | |
5a1597e9 VS |
516 | |
517 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
2a2e4f4a | 518 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), |
f30e67db | 519 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
520 | { |
521 | #if 0 // useful for debugging | |
ace0fab4 | 522 | dc.SetPen(*wxBLACK_PEN); |
4dd9ae57 | 523 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height); |
5a1597e9 VS |
524 | #endif |
525 | ||
b87dd6f5 | 526 | bool drawSelectionAfterCell = false; |
d1da8872 | 527 | |
f30e67db | 528 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
529 | { |
530 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
531 | wxHtmlSelection *s = info.GetSelection(); |
532 | wxString txt; | |
533 | int w, h; | |
534 | int ofs = 0; | |
86ff9b45 | 535 | |
1338c59a VS |
536 | // NB: this is quite a hack: in order to compute selection boundaries |
537 | // (in word's characters) we must know current font, which is only | |
538 | // possible inside rendering code. Therefore we update the | |
539 | // information here and store it in wxHtmlSelection so that | |
540 | // ConvertToText can use it later: | |
2f0bebe6 | 541 | if ( !s->AreFromToCharacterPosSet () ) |
1338c59a VS |
542 | { |
543 | SetSelectionPrivPos(dc, s); | |
1338c59a | 544 | } |
86ff9b45 | 545 | |
2f0bebe6 VZ |
546 | int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
547 | int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
f30e67db VS |
548 | |
549 | if ( part1 > 0 ) | |
5a1597e9 | 550 | { |
f30e67db VS |
551 | txt = m_Word.Mid(0, part1); |
552 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
553 | dc.GetTextExtent(txt, &w, &h); | |
554 | ofs += w; | |
5a1597e9 | 555 | } |
86ff9b45 | 556 | |
f30e67db | 557 | SwitchSelState(dc, info, true); |
86ff9b45 | 558 | |
f30e67db VS |
559 | txt = m_Word.Mid(part1, part2-part1); |
560 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
561 | ||
70bae016 | 562 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 563 | { |
f30e67db VS |
564 | dc.GetTextExtent(txt, &w, &h); |
565 | ofs += w; | |
566 | SwitchSelState(dc, info, false); | |
567 | txt = m_Word.Mid(part2); | |
568 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 | 569 | } |
b87dd6f5 VS |
570 | else |
571 | drawSelectionAfterCell = true; | |
5a1597e9 VS |
572 | } |
573 | else | |
574 | { | |
b87dd6f5 | 575 | wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); |
5a1597e9 | 576 | // Not changing selection state, draw the word in single mode: |
f5413b87 | 577 | SwitchSelState(dc, info, selstate != wxHTML_SEL_OUT); |
5a1597e9 | 578 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); |
b87dd6f5 VS |
579 | drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); |
580 | } | |
581 | ||
582 | // NB: If the text is justified then there is usually some free space | |
583 | // between adjacent cells and drawing the selection only onto cells | |
584 | // would result in ugly unselected spaces. The code below detects | |
585 | // this special case and renders the selection *outside* the sell, | |
586 | // too. | |
587 | if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY && | |
588 | drawSelectionAfterCell ) | |
589 | { | |
590 | wxHtmlCell *nextCell = m_Next; | |
591 | while ( nextCell && nextCell->IsFormattingCell() ) | |
592 | nextCell = nextCell->GetNext(); | |
593 | if ( nextCell ) | |
594 | { | |
595 | int nextX = nextCell->GetPosX(); | |
596 | if ( m_PosX + m_Width < nextX ) | |
597 | { | |
598 | dc.SetBrush(dc.GetBackground()); | |
599 | dc.SetPen(*wxTRANSPARENT_PEN); | |
600 | dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY, | |
601 | nextX - m_PosX - m_Width, m_Height); | |
602 | } | |
603 | } | |
5a1597e9 | 604 | } |
5526e819 | 605 | } |
86ff9b45 | 606 | |
6a603a10 VS |
607 | wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const |
608 | { | |
609 | if ( !GetLink() ) | |
610 | { | |
611 | return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text); | |
612 | } | |
613 | else | |
614 | { | |
615 | return wxHtmlCell::GetMouseCursor(window); | |
616 | } | |
617 | } | |
e3774124 | 618 | |
f30e67db | 619 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 620 | { |
f30e67db VS |
621 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
622 | { | |
86ff9b45 VZ |
623 | // VZ: we may be called before we had a chance to re-render ourselves |
624 | // and in this case GetFrom/ToPrivPos() is not set yet -- assume | |
625 | // that this only happens in case of a double/triple click (which | |
626 | // seems to be the case now) and so it makes sense to select the | |
627 | // entire contents of the cell in this case | |
628 | // | |
629 | // TODO: but this really needs to be fixed in some better way later... | |
2f0bebe6 | 630 | if ( s->AreFromToCharacterPosSet() ) |
86ff9b45 | 631 | { |
2f0bebe6 VZ |
632 | const int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
633 | const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
6a603a10 VS |
634 | if ( part1 == part2 ) |
635 | return wxEmptyString; | |
636 | return GetPartAsText(part1, part2); | |
86ff9b45 VZ |
637 | } |
638 | //else: return the whole word below | |
f30e67db | 639 | } |
86ff9b45 | 640 | |
6a603a10 | 641 | return GetAllAsText(); |
e3774124 | 642 | } |
5526e819 | 643 | |
6a603a10 | 644 | wxString wxHtmlWordWithTabsCell::GetAllAsText() const |
77bae5e2 | 645 | { |
6a603a10 VS |
646 | return m_wordOrig; |
647 | } | |
648 | ||
649 | wxString wxHtmlWordWithTabsCell::GetPartAsText(int begin, int end) const | |
650 | { | |
651 | // NB: The 'begin' and 'end' positions are in the _displayed_ text | |
652 | // (stored in m_Word) and not in the text with tabs that should | |
653 | // be copied to clipboard (m_wordOrig). | |
654 | // | |
655 | // NB: Because selection is performed on displayed text, it's possible | |
656 | // to select e.g. "half of TAB character" -- IOW, 'begin' and 'end' | |
657 | // may be in the middle of TAB character expansion into ' 's. In this | |
658 | // case, we copy the TAB character to clipboard once. | |
659 | ||
660 | wxASSERT( begin < end ); | |
661 | ||
662 | const unsigned SPACES_PER_TAB = 8; | |
663 | ||
664 | wxString sel; | |
665 | ||
666 | int pos = 0; | |
667 | wxString::const_iterator i = m_wordOrig.begin(); | |
668 | ||
669 | // find the beginning of text to copy: | |
670 | for ( ; pos < begin; ++i ) | |
77bae5e2 | 671 | { |
6a603a10 VS |
672 | if ( *i == '\t' ) |
673 | { | |
674 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
675 | if ( pos >= begin ) | |
676 | { | |
677 | sel += '\t'; | |
678 | } | |
679 | } | |
680 | else | |
681 | { | |
682 | ++pos; | |
683 | } | |
77bae5e2 | 684 | } |
6a603a10 VS |
685 | |
686 | // copy the content until we reach 'end': | |
687 | for ( ; pos < end; ++i ) | |
88a1b648 | 688 | { |
6a603a10 VS |
689 | const wxChar c = *i; |
690 | sel += c; | |
691 | ||
692 | if ( c == '\t' ) | |
693 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
694 | else | |
695 | ++pos; | |
88a1b648 | 696 | } |
6a603a10 VS |
697 | |
698 | return sel; | |
77bae5e2 VS |
699 | } |
700 | ||
5526e819 | 701 | |
6a603a10 | 702 | |
5526e819 VS |
703 | //----------------------------------------------------------------------------- |
704 | // wxHtmlContainerCell | |
705 | //----------------------------------------------------------------------------- | |
706 | ||
4f44ea36 | 707 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell) |
5526e819 VS |
708 | |
709 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
710 | { | |
711 | m_Cells = m_LastCell = NULL; | |
712 | m_Parent = parent; | |
ca16b7a9 | 713 | m_MaxTotalWidth = 0; |
4f9297b0 | 714 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
715 | m_AlignHor = wxHTML_ALIGN_LEFT; |
716 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 717 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 718 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
88343dda | 719 | m_BkColour = wxNullColour; |
3aaaf1aa | 720 | m_Border = 0; |
5c1bfc5d | 721 | m_MinHeight = 0; |
efba2b89 | 722 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 723 | m_LastLayout = -1; |
5526e819 VS |
724 | } |
725 | ||
04dbb646 | 726 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 727 | { |
491c9920 VZ |
728 | wxHtmlCell *cell = m_Cells; |
729 | while ( cell ) | |
bf7d7ee7 | 730 | { |
491c9920 VZ |
731 | wxHtmlCell *cellNext = cell->GetNext(); |
732 | delete cell; | |
733 | cell = cellNext; | |
bf7d7ee7 | 734 | } |
721ab905 VS |
735 | } |
736 | ||
5526e819 VS |
737 | |
738 | ||
739 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
740 | { | |
efba2b89 VS |
741 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
742 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
743 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
744 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
745 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 746 | m_LastLayout = -1; |
5526e819 VS |
747 | } |
748 | ||
749 | ||
750 | ||
751 | int wxHtmlContainerCell::GetIndent(int ind) const | |
752 | { | |
efba2b89 VS |
753 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
754 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
755 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
756 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
757 | else return -1; /* BUG! Should not be called... */ |
758 | } | |
759 | ||
760 | ||
761 | ||
762 | ||
763 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
764 | { | |
49f6740f | 765 | bool p = false; |
efba2b89 VS |
766 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
767 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
768 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
769 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
770 | if (p) return wxHTML_UNITS_PERCENT; | |
771 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
772 | } |
773 | ||
774 | ||
846f4568 VZ |
775 | bool |
776 | wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, | |
777 | const wxArrayInt& known_pagebreaks, | |
778 | int pageHeight) const | |
db98870d | 779 | { |
04dbb646 | 780 | if (!m_CanLiveOnPagebreak) |
846f4568 | 781 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, pageHeight); |
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 | { | |
846f4568 | 789 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, pageHeight)) |
fd0bab43 VZ |
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 | ||
88343dda | 1099 | if (m_BkColour.IsOk()) |
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 | { | |
88343dda | 1220 | return m_BkColour; |
2b5f62a0 VZ |
1221 | } |
1222 | ||
1223 | ||
5526e819 | 1224 | |
846914d1 | 1225 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 1226 | { |
f6010d8f | 1227 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 1228 | |
f6010d8f VZ |
1229 | // VZ: I don't know if we should pass absolute or relative coords to |
1230 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
1231 | // anyhow, it hardly matters right now but should still be clarified | |
1232 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
1233 | } |
1234 | ||
1235 | ||
1236 | ||
1237 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
1238 | { | |
1239 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 1240 | else |
4f9297b0 VS |
1241 | { |
1242 | m_LastCell->SetNext(f); | |
5526e819 | 1243 | m_LastCell = f; |
4f9297b0 | 1244 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 1245 | } |
4f9297b0 | 1246 | f->SetParent(this); |
5660c520 | 1247 | m_LastLayout = -1; |
5526e819 VS |
1248 | } |
1249 | ||
1250 | ||
1251 | ||
1252 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
1253 | { | |
04dbb646 | 1254 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 1255 | { |
0413cec5 | 1256 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 1257 | alg.MakeUpper(); |
0413cec5 | 1258 | if (alg == wxT("CENTER")) |
efba2b89 | 1259 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 1260 | else if (alg == wxT("LEFT")) |
efba2b89 | 1261 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
1262 | else if (alg == wxT("JUSTIFY")) |
1263 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 1264 | else if (alg == wxT("RIGHT")) |
efba2b89 | 1265 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 1266 | m_LastLayout = -1; |
5526e819 VS |
1267 | } |
1268 | } | |
1269 | ||
1270 | ||
1271 | ||
edbd0635 | 1272 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 1273 | { |
04dbb646 | 1274 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 1275 | { |
5526e819 | 1276 | int wdi; |
0413cec5 | 1277 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 1278 | |
93763ad5 | 1279 | if (wd[wd.length()-1] == wxT('%')) |
0cb9cfb2 | 1280 | { |
66a77a74 | 1281 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 1282 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 1283 | } |
04dbb646 | 1284 | else |
0cb9cfb2 | 1285 | { |
66a77a74 | 1286 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 1287 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 1288 | } |
5660c520 | 1289 | m_LastLayout = -1; |
5526e819 VS |
1290 | } |
1291 | } | |
1292 | ||
1293 | ||
1294 | ||
1295 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
1296 | { | |
04dbb646 | 1297 | if (m_Cells) |
d699f48b | 1298 | { |
bf7d7ee7 VS |
1299 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
1300 | { | |
999836aa | 1301 | const wxHtmlCell *r = cell->Find(condition, param); |
bf7d7ee7 VS |
1302 | if (r) return r; |
1303 | } | |
1304 | } | |
1305 | return NULL; | |
5526e819 VS |
1306 | } |
1307 | ||
1308 | ||
36c4ff4d VS |
1309 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
1310 | unsigned flags) const | |
5526e819 | 1311 | { |
6d41981d | 1312 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 1313 | { |
adf2eb2d VS |
1314 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1315 | { | |
1316 | int cx = cell->GetPosX(), | |
1317 | cy = cell->GetPosY(); | |
1318 | ||
1319 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
1320 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
1321 | { | |
1322 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
1323 | } | |
1324 | } | |
adf2eb2d | 1325 | } |
6d41981d | 1326 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
1327 | { |
1328 | wxHtmlCell *c; | |
adf2eb2d | 1329 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
0cb9cfb2 | 1330 | { |
03693319 VS |
1331 | if ( cell->IsFormattingCell() ) |
1332 | continue; | |
1333 | int cellY = cell->GetPosY(); | |
d1da8872 | 1334 | if (!( y < cellY || (y < cellY + cell->GetHeight() && |
03693319 | 1335 | x < cell->GetPosX() + cell->GetWidth()) )) |
adf2eb2d | 1336 | continue; |
d1da8872 | 1337 | |
03693319 | 1338 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
adf2eb2d | 1339 | if (c) return c; |
5526e819 VS |
1340 | } |
1341 | } | |
6d41981d | 1342 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 1343 | { |
e24529d7 | 1344 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
1345 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1346 | { | |
03693319 VS |
1347 | if ( cell->IsFormattingCell() ) |
1348 | continue; | |
1349 | int cellY = cell->GetPosY(); | |
1350 | if (!( cellY + cell->GetHeight() <= y || | |
1351 | (y >= cellY && x >= cell->GetPosX()) )) | |
adf2eb2d | 1352 | break; |
03693319 | 1353 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
e24529d7 VS |
1354 | if (c2) |
1355 | c = c2; | |
adf2eb2d | 1356 | } |
e24529d7 | 1357 | if (c) return c; |
adf2eb2d | 1358 | } |
6d41981d VZ |
1359 | |
1360 | return NULL; | |
f6010d8f VZ |
1361 | } |
1362 | ||
1363 | ||
bc55e31b VS |
1364 | bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window, |
1365 | const wxPoint& pos, | |
1366 | const wxMouseEvent& event) | |
f6010d8f | 1367 | { |
bc55e31b VS |
1368 | #if WXWIN_COMPATIBILITY_2_6 |
1369 | wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event); | |
1370 | return compat.CallOnMouseClick(this); | |
5526e819 VS |
1371 | } |
1372 | ||
bc55e31b VS |
1373 | void wxHtmlContainerCell::OnMouseClick(wxWindow*, |
1374 | int, int, const wxMouseEvent& event) | |
1375 | { | |
9a83f860 | 1376 | wxCHECK_RET( gs_helperOnMouseClick, wxT("unexpected call to OnMouseClick") ); |
bc55e31b VS |
1377 | wxHtmlWindowInterface *window = gs_helperOnMouseClick->window; |
1378 | const wxPoint& pos = gs_helperOnMouseClick->pos; | |
1379 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1380 | ||
1381 | bool retval = false; | |
1382 | wxHtmlCell *cell = FindCellByPos(pos.x, pos.y); | |
1383 | if ( cell ) | |
1384 | retval = cell->ProcessMouseClick(window, pos, event); | |
1385 | ||
1386 | #if WXWIN_COMPATIBILITY_2_6 | |
1387 | gs_helperOnMouseClick->retval = retval; | |
1388 | #else | |
1389 | return retval; | |
1390 | #endif // WXWIN_COMPATIBILITY_2_6 | |
1391 | } | |
5526e819 VS |
1392 | |
1393 | ||
adf2eb2d VS |
1394 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1395 | { | |
e3774124 VS |
1396 | if ( m_Cells ) |
1397 | { | |
1398 | wxHtmlCell *c2; | |
1399 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1400 | { | |
1401 | c2 = c->GetFirstTerminal(); | |
1402 | if ( c2 ) | |
1403 | return c2; | |
1404 | } | |
1405 | } | |
1406 | return NULL; | |
adf2eb2d VS |
1407 | } |
1408 | ||
1409 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1410 | { | |
e3774124 | 1411 | if ( m_Cells ) |
adf2eb2d | 1412 | { |
e3774124 | 1413 | // most common case first: |
4ce19ed7 | 1414 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1415 | if ( c ) |
1416 | return c; | |
4ce19ed7 | 1417 | |
ace0fab4 | 1418 | wxHtmlCell *ctmp; |
4ce19ed7 VZ |
1419 | wxHtmlCell *c2 = NULL; |
1420 | for (c = m_Cells; c; c = c->GetNext()) | |
ace0fab4 VS |
1421 | { |
1422 | ctmp = c->GetLastTerminal(); | |
1423 | if ( ctmp ) | |
1424 | c2 = ctmp; | |
1425 | } | |
e3774124 | 1426 | return c2; |
adf2eb2d VS |
1427 | } |
1428 | else | |
1429 | return NULL; | |
1430 | } | |
79d6c018 VS |
1431 | |
1432 | ||
ace0fab4 VS |
1433 | static bool IsEmptyContainer(wxHtmlContainerCell *cell) |
1434 | { | |
1435 | for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() ) | |
1436 | { | |
1437 | if ( !c->IsTerminalCell() || !c->IsFormattingCell() ) | |
1438 | return false; | |
1439 | } | |
1440 | return true; | |
1441 | } | |
1442 | ||
1443 | void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom) | |
d1da8872 | 1444 | { |
ace0fab4 VS |
1445 | if ( top ) |
1446 | SetIndent(0, wxHTML_INDENT_TOP); | |
1447 | if ( bottom ) | |
1448 | SetIndent(0, wxHTML_INDENT_BOTTOM); | |
1449 | ||
1450 | if ( m_Cells ) | |
1451 | { | |
1452 | wxHtmlCell *c; | |
1453 | wxHtmlContainerCell *cont; | |
1454 | if ( top ) | |
1455 | { | |
1456 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1457 | { | |
1458 | if ( c->IsTerminalCell() ) | |
1459 | { | |
1460 | if ( !c->IsFormattingCell() ) | |
1461 | break; | |
1462 | } | |
1463 | else | |
1464 | { | |
1465 | cont = (wxHtmlContainerCell*)c; | |
1466 | if ( IsEmptyContainer(cont) ) | |
1467 | { | |
1468 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); | |
1469 | } | |
1470 | else | |
1471 | { | |
1472 | cont->RemoveExtraSpacing(true, false); | |
1473 | break; | |
1474 | } | |
1475 | } | |
1476 | } | |
1477 | } | |
d1da8872 | 1478 | |
ace0fab4 VS |
1479 | if ( bottom ) |
1480 | { | |
1481 | wxArrayPtrVoid arr; | |
1482 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1483 | arr.Add((void*)c); | |
d1da8872 | 1484 | |
ace0fab4 VS |
1485 | for ( int i = arr.GetCount() - 1; i >= 0; i--) |
1486 | { | |
1487 | c = (wxHtmlCell*)arr[i]; | |
1488 | if ( c->IsTerminalCell() ) | |
1489 | { | |
1490 | if ( !c->IsFormattingCell() ) | |
1491 | break; | |
1492 | } | |
1493 | else | |
1494 | { | |
1495 | cont = (wxHtmlContainerCell*)c; | |
1496 | if ( IsEmptyContainer(cont) ) | |
1497 | { | |
3e905c52 RD |
1498 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); |
1499 | } | |
ace0fab4 VS |
1500 | else |
1501 | { | |
1502 | cont->RemoveExtraSpacing(false, true); | |
1503 | break; | |
1504 | } | |
1505 | } | |
1506 | } | |
1507 | } | |
1508 | } | |
1509 | } | |
1510 | ||
1511 | ||
5526e819 VS |
1512 | |
1513 | ||
36c4ff4d | 1514 | // -------------------------------------------------------------------------- |
5526e819 | 1515 | // wxHtmlColourCell |
36c4ff4d | 1516 | // -------------------------------------------------------------------------- |
5526e819 | 1517 | |
4f44ea36 MB |
1518 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell) |
1519 | ||
36c4ff4d VS |
1520 | void wxHtmlColourCell::Draw(wxDC& dc, |
1521 | int x, int y, | |
1522 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1523 | wxHtmlRenderingInfo& info) |
5526e819 | 1524 | { |
f30e67db | 1525 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1526 | } |
1527 | ||
36c4ff4d VS |
1528 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1529 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1530 | wxHtmlRenderingInfo& info) |
5526e819 | 1531 | { |
f30e67db | 1532 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1533 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1534 | { |
1535 | state.SetFgColour(m_Colour); | |
1536 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1537 | dc.SetTextForeground(m_Colour); |
1538 | else | |
1539 | dc.SetTextForeground( | |
1540 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1541 | } |
04dbb646 | 1542 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1543 | { |
36c4ff4d | 1544 | state.SetBgColour(m_Colour); |
f5413b87 VZ |
1545 | state.SetBgMode(wxSOLID); |
1546 | const wxColour c = state.GetSelectionState() == wxHTML_SEL_IN | |
1547 | ? info.GetStyle().GetSelectedTextBgColour(m_Colour) | |
1548 | : m_Colour; | |
1549 | dc.SetTextBackground(c); | |
1550 | dc.SetBackground(c); | |
1551 | dc.SetBackgroundMode(wxSOLID); | |
1552 | } | |
1553 | if (m_Flags & wxHTML_CLR_TRANSPARENT_BACKGROUND) | |
1554 | { | |
1555 | state.SetBgColour(m_Colour); | |
1556 | state.SetBgMode(wxTRANSPARENT); | |
1557 | const wxColour c = state.GetSelectionState() == wxHTML_SEL_IN | |
1558 | ? info.GetStyle().GetSelectedTextBgColour(m_Colour) | |
1559 | : m_Colour; | |
1560 | dc.SetTextBackground(c); | |
1561 | dc.SetBackgroundMode(wxTRANSPARENT); | |
5526e819 | 1562 | } |
5526e819 VS |
1563 | } |
1564 | ||
1565 | ||
1566 | ||
1567 | ||
36c4ff4d | 1568 | // --------------------------------------------------------------------------- |
5526e819 | 1569 | // wxHtmlFontCell |
36c4ff4d | 1570 | // --------------------------------------------------------------------------- |
5526e819 | 1571 | |
4f44ea36 MB |
1572 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1573 | ||
36c4ff4d VS |
1574 | void wxHtmlFontCell::Draw(wxDC& dc, |
1575 | int WXUNUSED(x), int WXUNUSED(y), | |
1576 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1577 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1578 | { |
921d0fb1 | 1579 | dc.SetFont(m_Font); |
5526e819 VS |
1580 | } |
1581 | ||
36c4ff4d | 1582 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1583 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1584 | { |
921d0fb1 | 1585 | dc.SetFont(m_Font); |
5526e819 VS |
1586 | } |
1587 | ||
1588 | ||
1589 | ||
1590 | ||
1591 | ||
1592 | ||
1593 | ||
1594 | ||
36c4ff4d | 1595 | // --------------------------------------------------------------------------- |
5526e819 | 1596 | // wxHtmlWidgetCell |
36c4ff4d | 1597 | // --------------------------------------------------------------------------- |
5526e819 | 1598 | |
4f44ea36 MB |
1599 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1600 | ||
5526e819 VS |
1601 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1602 | { | |
1603 | int sx, sy; | |
1604 | m_Wnd = wnd; | |
4f9297b0 | 1605 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1606 | m_Width = sx, m_Height = sy; |
1607 | m_WidthFloat = w; | |
1608 | } | |
1609 | ||
1610 | ||
36c4ff4d VS |
1611 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1612 | int WXUNUSED(x), int WXUNUSED(y), | |
1613 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1614 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1615 | { |
1616 | int absx = 0, absy = 0, stx, sty; | |
1617 | wxHtmlCell *c = this; | |
1618 | ||
04dbb646 | 1619 | while (c) |
4f9297b0 VS |
1620 | { |
1621 | absx += c->GetPosX(); | |
1622 | absy += c->GetPosY(); | |
1623 | c = c->GetParent(); | |
5526e819 VS |
1624 | } |
1625 | ||
c4184573 VS |
1626 | wxScrolledWindow *scrolwin = |
1627 | wxDynamicCast(m_Wnd->GetParent(), wxScrolledWindow); | |
1628 | wxCHECK_RET( scrolwin, | |
9a83f860 | 1629 | wxT("widget cells can only be placed in wxHtmlWindow") ); |
c4184573 VS |
1630 | |
1631 | scrolwin->GetViewStart(&stx, &sty); | |
1632 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, | |
1633 | absy - wxHTML_SCROLL_STEP * sty, | |
1634 | m_Width, m_Height); | |
5526e819 VS |
1635 | } |
1636 | ||
1637 | ||
1638 | ||
36c4ff4d VS |
1639 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1640 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1641 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1642 | { |
1643 | int absx = 0, absy = 0, stx, sty; | |
1644 | wxHtmlCell *c = this; | |
1645 | ||
04dbb646 | 1646 | while (c) |
4f9297b0 VS |
1647 | { |
1648 | absx += c->GetPosX(); | |
1649 | absy += c->GetPosY(); | |
1650 | c = c->GetParent(); | |
5526e819 | 1651 | } |
7e941458 | 1652 | |
e421922f | 1653 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1654 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1655 | } |
1656 | ||
1657 | ||
1658 | ||
1659 | void wxHtmlWidgetCell::Layout(int w) | |
1660 | { | |
04dbb646 | 1661 | if (m_WidthFloat != 0) |
4f9297b0 | 1662 | { |
5526e819 | 1663 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1664 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1665 | } |
1666 | ||
1667 | wxHtmlCell::Layout(w); | |
1668 | } | |
1669 | ||
e3774124 VS |
1670 | |
1671 | ||
1672 | // ---------------------------------------------------------------------------- | |
1673 | // wxHtmlTerminalCellsInterator | |
1674 | // ---------------------------------------------------------------------------- | |
1675 | ||
1676 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1677 | { | |
1678 | if ( !m_pos ) | |
1679 | return NULL; | |
1680 | ||
1681 | do | |
1682 | { | |
1683 | if ( m_pos == m_to ) | |
1684 | { | |
1685 | m_pos = NULL; | |
1686 | return NULL; | |
1687 | } | |
1688 | ||
1689 | if ( m_pos->GetNext() ) | |
1690 | m_pos = m_pos->GetNext(); | |
1691 | else | |
1692 | { | |
1693 | // we must go up the hierarchy until we reach container where this | |
1694 | // is not the last child, and then go down to first terminal cell: | |
1695 | while ( m_pos->GetNext() == NULL ) | |
1696 | { | |
1697 | m_pos = m_pos->GetParent(); | |
1698 | if ( !m_pos ) | |
1699 | return NULL; | |
1700 | } | |
1701 | m_pos = m_pos->GetNext(); | |
1702 | } | |
1703 | while ( m_pos->GetFirstChild() != NULL ) | |
1704 | m_pos = m_pos->GetFirstChild(); | |
1705 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1706 | |
e3774124 VS |
1707 | return m_pos; |
1708 | } | |
1709 | ||
5526e819 | 1710 | #endif |