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