]>
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 | { |
04ee05f9 | 499 | dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); |
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 | { |
04ee05f9 | 507 | dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
f30e67db VS |
508 | dc.SetTextForeground(fg); |
509 | dc.SetTextBackground(bg); | |
04ee05f9 | 510 | dc.SetBackground(wxBrush(bg, wxBRUSHSTYLE_SOLID)); |
36c4ff4d | 511 | } |
5a1597e9 | 512 | } |
36c4ff4d | 513 | |
5a1597e9 VS |
514 | |
515 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
2a2e4f4a | 516 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), |
f30e67db | 517 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
518 | { |
519 | #if 0 // useful for debugging | |
ace0fab4 | 520 | dc.SetPen(*wxBLACK_PEN); |
4dd9ae57 | 521 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height); |
5a1597e9 VS |
522 | #endif |
523 | ||
b87dd6f5 | 524 | bool drawSelectionAfterCell = false; |
d1da8872 | 525 | |
f30e67db | 526 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
527 | { |
528 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
529 | wxHtmlSelection *s = info.GetSelection(); |
530 | wxString txt; | |
531 | int w, h; | |
532 | int ofs = 0; | |
86ff9b45 | 533 | |
1338c59a VS |
534 | // NB: this is quite a hack: in order to compute selection boundaries |
535 | // (in word's characters) we must know current font, which is only | |
536 | // possible inside rendering code. Therefore we update the | |
537 | // information here and store it in wxHtmlSelection so that | |
538 | // ConvertToText can use it later: | |
2f0bebe6 | 539 | if ( !s->AreFromToCharacterPosSet () ) |
1338c59a VS |
540 | { |
541 | SetSelectionPrivPos(dc, s); | |
1338c59a | 542 | } |
86ff9b45 | 543 | |
2f0bebe6 VZ |
544 | int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
545 | int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
f30e67db VS |
546 | |
547 | if ( part1 > 0 ) | |
5a1597e9 | 548 | { |
f30e67db VS |
549 | txt = m_Word.Mid(0, part1); |
550 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
551 | dc.GetTextExtent(txt, &w, &h); | |
552 | ofs += w; | |
5a1597e9 | 553 | } |
86ff9b45 | 554 | |
f30e67db | 555 | SwitchSelState(dc, info, true); |
86ff9b45 | 556 | |
f30e67db VS |
557 | txt = m_Word.Mid(part1, part2-part1); |
558 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
559 | ||
70bae016 | 560 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 561 | { |
f30e67db VS |
562 | dc.GetTextExtent(txt, &w, &h); |
563 | ofs += w; | |
564 | SwitchSelState(dc, info, false); | |
565 | txt = m_Word.Mid(part2); | |
566 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 | 567 | } |
b87dd6f5 VS |
568 | else |
569 | drawSelectionAfterCell = true; | |
5a1597e9 VS |
570 | } |
571 | else | |
572 | { | |
b87dd6f5 | 573 | wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); |
5a1597e9 | 574 | // Not changing selection state, draw the word in single mode: |
b87dd6f5 | 575 | if ( selstate != wxHTML_SEL_OUT && |
04ee05f9 | 576 | dc.GetBackgroundMode() != wxBRUSHSTYLE_SOLID ) |
5a1597e9 | 577 | { |
f30e67db | 578 | SwitchSelState(dc, info, true); |
5a1597e9 | 579 | } |
b87dd6f5 | 580 | else if ( selstate == wxHTML_SEL_OUT && |
04ee05f9 | 581 | dc.GetBackgroundMode() == wxBRUSHSTYLE_SOLID ) |
5a1597e9 | 582 | { |
f30e67db | 583 | SwitchSelState(dc, info, false); |
5a1597e9 VS |
584 | } |
585 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
b87dd6f5 VS |
586 | drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); |
587 | } | |
588 | ||
589 | // NB: If the text is justified then there is usually some free space | |
590 | // between adjacent cells and drawing the selection only onto cells | |
591 | // would result in ugly unselected spaces. The code below detects | |
592 | // this special case and renders the selection *outside* the sell, | |
593 | // too. | |
594 | if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY && | |
595 | drawSelectionAfterCell ) | |
596 | { | |
597 | wxHtmlCell *nextCell = m_Next; | |
598 | while ( nextCell && nextCell->IsFormattingCell() ) | |
599 | nextCell = nextCell->GetNext(); | |
600 | if ( nextCell ) | |
601 | { | |
602 | int nextX = nextCell->GetPosX(); | |
603 | if ( m_PosX + m_Width < nextX ) | |
604 | { | |
605 | dc.SetBrush(dc.GetBackground()); | |
606 | dc.SetPen(*wxTRANSPARENT_PEN); | |
607 | dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY, | |
608 | nextX - m_PosX - m_Width, m_Height); | |
609 | } | |
610 | } | |
5a1597e9 | 611 | } |
5526e819 | 612 | } |
86ff9b45 | 613 | |
6a603a10 VS |
614 | wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const |
615 | { | |
616 | if ( !GetLink() ) | |
617 | { | |
618 | return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text); | |
619 | } | |
620 | else | |
621 | { | |
622 | return wxHtmlCell::GetMouseCursor(window); | |
623 | } | |
624 | } | |
e3774124 | 625 | |
f30e67db | 626 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 627 | { |
f30e67db VS |
628 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
629 | { | |
86ff9b45 VZ |
630 | // VZ: we may be called before we had a chance to re-render ourselves |
631 | // and in this case GetFrom/ToPrivPos() is not set yet -- assume | |
632 | // that this only happens in case of a double/triple click (which | |
633 | // seems to be the case now) and so it makes sense to select the | |
634 | // entire contents of the cell in this case | |
635 | // | |
636 | // TODO: but this really needs to be fixed in some better way later... | |
2f0bebe6 | 637 | if ( s->AreFromToCharacterPosSet() ) |
86ff9b45 | 638 | { |
2f0bebe6 VZ |
639 | const int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0; |
640 | const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length(); | |
6a603a10 VS |
641 | if ( part1 == part2 ) |
642 | return wxEmptyString; | |
643 | return GetPartAsText(part1, part2); | |
86ff9b45 VZ |
644 | } |
645 | //else: return the whole word below | |
f30e67db | 646 | } |
86ff9b45 | 647 | |
6a603a10 | 648 | return GetAllAsText(); |
e3774124 | 649 | } |
5526e819 | 650 | |
6a603a10 | 651 | wxString wxHtmlWordWithTabsCell::GetAllAsText() const |
77bae5e2 | 652 | { |
6a603a10 VS |
653 | return m_wordOrig; |
654 | } | |
655 | ||
656 | wxString wxHtmlWordWithTabsCell::GetPartAsText(int begin, int end) const | |
657 | { | |
658 | // NB: The 'begin' and 'end' positions are in the _displayed_ text | |
659 | // (stored in m_Word) and not in the text with tabs that should | |
660 | // be copied to clipboard (m_wordOrig). | |
661 | // | |
662 | // NB: Because selection is performed on displayed text, it's possible | |
663 | // to select e.g. "half of TAB character" -- IOW, 'begin' and 'end' | |
664 | // may be in the middle of TAB character expansion into ' 's. In this | |
665 | // case, we copy the TAB character to clipboard once. | |
666 | ||
667 | wxASSERT( begin < end ); | |
668 | ||
669 | const unsigned SPACES_PER_TAB = 8; | |
670 | ||
671 | wxString sel; | |
672 | ||
673 | int pos = 0; | |
674 | wxString::const_iterator i = m_wordOrig.begin(); | |
675 | ||
676 | // find the beginning of text to copy: | |
677 | for ( ; pos < begin; ++i ) | |
77bae5e2 | 678 | { |
6a603a10 VS |
679 | if ( *i == '\t' ) |
680 | { | |
681 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
682 | if ( pos >= begin ) | |
683 | { | |
684 | sel += '\t'; | |
685 | } | |
686 | } | |
687 | else | |
688 | { | |
689 | ++pos; | |
690 | } | |
77bae5e2 | 691 | } |
6a603a10 VS |
692 | |
693 | // copy the content until we reach 'end': | |
694 | for ( ; pos < end; ++i ) | |
88a1b648 | 695 | { |
6a603a10 VS |
696 | const wxChar c = *i; |
697 | sel += c; | |
698 | ||
699 | if ( c == '\t' ) | |
700 | pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; | |
701 | else | |
702 | ++pos; | |
88a1b648 | 703 | } |
6a603a10 VS |
704 | |
705 | return sel; | |
77bae5e2 VS |
706 | } |
707 | ||
5526e819 | 708 | |
6a603a10 | 709 | |
5526e819 VS |
710 | //----------------------------------------------------------------------------- |
711 | // wxHtmlContainerCell | |
712 | //----------------------------------------------------------------------------- | |
713 | ||
4f44ea36 | 714 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell) |
5526e819 VS |
715 | |
716 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
717 | { | |
718 | m_Cells = m_LastCell = NULL; | |
719 | m_Parent = parent; | |
ca16b7a9 | 720 | m_MaxTotalWidth = 0; |
4f9297b0 | 721 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
722 | m_AlignHor = wxHTML_ALIGN_LEFT; |
723 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 724 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 725 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
49f6740f | 726 | m_UseBkColour = false; |
3aaaf1aa | 727 | m_Border = 0; |
5c1bfc5d | 728 | m_MinHeight = 0; |
efba2b89 | 729 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 730 | m_LastLayout = -1; |
5526e819 VS |
731 | } |
732 | ||
04dbb646 | 733 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 734 | { |
491c9920 VZ |
735 | wxHtmlCell *cell = m_Cells; |
736 | while ( cell ) | |
bf7d7ee7 | 737 | { |
491c9920 VZ |
738 | wxHtmlCell *cellNext = cell->GetNext(); |
739 | delete cell; | |
740 | cell = cellNext; | |
bf7d7ee7 | 741 | } |
721ab905 VS |
742 | } |
743 | ||
5526e819 VS |
744 | |
745 | ||
746 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
747 | { | |
efba2b89 VS |
748 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
749 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
750 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
751 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
752 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 753 | m_LastLayout = -1; |
5526e819 VS |
754 | } |
755 | ||
756 | ||
757 | ||
758 | int wxHtmlContainerCell::GetIndent(int ind) const | |
759 | { | |
efba2b89 VS |
760 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
761 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
762 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
763 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
764 | else return -1; /* BUG! Should not be called... */ |
765 | } | |
766 | ||
767 | ||
768 | ||
769 | ||
770 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
771 | { | |
49f6740f | 772 | bool p = false; |
efba2b89 VS |
773 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
774 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
775 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
776 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
777 | if (p) return wxHTML_UNITS_PERCENT; | |
778 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
779 | } |
780 | ||
781 | ||
846f4568 VZ |
782 | bool |
783 | wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, | |
784 | const wxArrayInt& known_pagebreaks, | |
785 | int pageHeight) const | |
db98870d | 786 | { |
04dbb646 | 787 | if (!m_CanLiveOnPagebreak) |
846f4568 | 788 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, pageHeight); |
e52d6dbc | 789 | |
fd0bab43 VZ |
790 | wxHtmlCell *c = GetFirstChild(); |
791 | bool rt = false; | |
792 | int pbrk = *pagebreak - m_PosY; | |
db98870d | 793 | |
fd0bab43 VZ |
794 | while (c) |
795 | { | |
846f4568 | 796 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, pageHeight)) |
fd0bab43 VZ |
797 | rt = true; |
798 | c = c->GetNext(); | |
db98870d | 799 | } |
fd0bab43 VZ |
800 | if (rt) |
801 | *pagebreak = pbrk + m_PosY; | |
802 | return rt; | |
db98870d VS |
803 | } |
804 | ||
805 | ||
5526e819 VS |
806 | void wxHtmlContainerCell::Layout(int w) |
807 | { | |
026d1fac VS |
808 | wxHtmlCell::Layout(w); |
809 | ||
5540b06b VS |
810 | if (m_LastLayout == w) |
811 | return; | |
812 | m_LastLayout = w; | |
0cb9cfb2 | 813 | |
026d1fac VS |
814 | // VS: Any attempt to layout with negative or zero width leads to hell, |
815 | // but we can't ignore such attempts completely, since it sometimes | |
816 | // happen (e.g. when trying how small a table can be). The best thing we | |
817 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 818 | if (w < 1) |
4f9297b0 | 819 | { |
026d1fac VS |
820 | m_Width = 0; |
821 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
822 | cell->Layout(0); | |
2b5f62a0 VZ |
823 | // this does two things: it recursively calls this code on all |
824 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 825 | return; |
04dbb646 | 826 | } |
5660c520 | 827 | |
b6d93b26 | 828 | wxHtmlCell *nextCell; |
5526e819 VS |
829 | long xpos = 0, ypos = m_IndentTop; |
830 | int xdelta = 0, ybasicpos = 0, ydiff; | |
b6d93b26 | 831 | int s_width, nextWordWidth, s_indent; |
5526e819 | 832 | int ysizeup = 0, ysizedown = 0; |
5c1bfc5d | 833 | int MaxLineWidth = 0; |
ca16b7a9 VS |
834 | int curLineWidth = 0; |
835 | m_MaxTotalWidth = 0; | |
5c1bfc5d | 836 | |
5526e819 VS |
837 | |
838 | /* | |
7e941458 | 839 | |
5526e819 | 840 | WIDTH ADJUSTING : |
7e941458 | 841 | |
5526e819 VS |
842 | */ |
843 | ||
04dbb646 | 844 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 845 | { |
5526e819 VS |
846 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
847 | else m_Width = m_WidthFloat * w / 100; | |
848 | } | |
04dbb646 | 849 | else |
4f9297b0 | 850 | { |
5526e819 VS |
851 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
852 | else m_Width = m_WidthFloat; | |
853 | } | |
854 | ||
04dbb646 | 855 | if (m_Cells) |
4f9297b0 | 856 | { |
5526e819 VS |
857 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
858 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
859 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
860 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
861 | } |
862 | ||
863 | /* | |
864 | ||
d13b34d3 | 865 | LAYOUT : |
7e941458 | 866 | |
5526e819 VS |
867 | */ |
868 | ||
869 | // adjust indentation: | |
870 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
871 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
872 | ||
d13b34d3 | 873 | // my own layout: |
17a1ebd1 VZ |
874 | wxHtmlCell *cell = m_Cells, |
875 | *line = m_Cells; | |
04dbb646 | 876 | while (cell != NULL) |
4f9297b0 | 877 | { |
04dbb646 | 878 | switch (m_AlignVer) |
0cb9cfb2 | 879 | { |
efba2b89 | 880 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
881 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
882 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 883 | } |
4f9297b0 | 884 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 885 | |
4f9297b0 VS |
886 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
887 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 888 | |
b6d93b26 | 889 | // layout nonbreakable run of cells: |
4f9297b0 VS |
890 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
891 | xpos += cell->GetWidth(); | |
ca16b7a9 VS |
892 | if (!cell->IsTerminalCell()) |
893 | { | |
894 | // Container cell indicates new line | |
895 | if (curLineWidth > m_MaxTotalWidth) | |
896 | m_MaxTotalWidth = curLineWidth; | |
897 | ||
898 | if (wxMax(cell->GetWidth(), cell->GetMaxTotalWidth()) > m_MaxTotalWidth) | |
899 | m_MaxTotalWidth = cell->GetMaxTotalWidth(); | |
900 | curLineWidth = 0; | |
901 | } | |
902 | else | |
903 | // Normal cell, add maximum cell width to line width | |
904 | curLineWidth += cell->GetMaxTotalWidth(); | |
905 | ||
4f9297b0 | 906 | cell = cell->GetNext(); |
d1da8872 | 907 | |
b6d93b26 VS |
908 | // compute length of the next word that would be added: |
909 | nextWordWidth = 0; | |
910 | if (cell) | |
911 | { | |
912 | nextCell = cell; | |
913 | do | |
914 | { | |
915 | nextWordWidth += nextCell->GetWidth(); | |
916 | nextCell = nextCell->GetNext(); | |
917 | } while (nextCell && !nextCell->IsLinebreakAllowed()); | |
918 | } | |
d1da8872 | 919 | |
3103e8a9 | 920 | // force new line if occurred: |
d1da8872 | 921 | if ((cell == NULL) || |
b6d93b26 | 922 | (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed())) |
0cb9cfb2 | 923 | { |
5c1bfc5d | 924 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
925 | if (ysizeup < 0) ysizeup = 0; |
926 | if (ysizedown < 0) ysizedown = 0; | |
927 | switch (m_AlignHor) { | |
04dbb646 VZ |
928 | case wxHTML_ALIGN_LEFT : |
929 | case wxHTML_ALIGN_JUSTIFY : | |
930 | xdelta = 0; | |
5c1bfc5d | 931 | break; |
04dbb646 VZ |
932 | case wxHTML_ALIGN_RIGHT : |
933 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 934 | break; |
04dbb646 VZ |
935 | case wxHTML_ALIGN_CENTER : |
936 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 937 | break; |
5526e819 VS |
938 | } |
939 | if (xdelta < 0) xdelta = 0; | |
940 | xdelta += s_indent; | |
941 | ||
942 | ypos += ysizeup; | |
04dbb646 | 943 | |
5c1bfc5d | 944 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
a1ae1090 | 945 | { |
04dbb646 | 946 | while (line != cell) |
0cb9cfb2 | 947 | { |
04dbb646 | 948 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
949 | ypos + line->GetPosY()); |
950 | line = line->GetNext(); | |
5c1bfc5d | 951 | } |
a1ae1090 VZ |
952 | } |
953 | else // align == justify | |
04dbb646 | 954 | { |
a1ae1090 VZ |
955 | // we have to distribute the extra horz space between the cells |
956 | // on this line | |
957 | ||
958 | // an added complication is that some cells have fixed size and | |
959 | // shouldn't get any increment (it so happens that these cells | |
960 | // also don't allow line break on them which provides with an | |
4dd9ae57 VZ |
961 | // easy way to test for this) -- and neither should the cells |
962 | // adjacent to them as this could result in a visible space | |
963 | // between two cells separated by, e.g. font change, cell which | |
964 | // is wrong | |
a1ae1090 | 965 | |
2d1d813e | 966 | int step = s_width - xpos; |
a1ae1090 | 967 | if ( step > 0 ) |
0cb9cfb2 | 968 | { |
a1ae1090 | 969 | // first count the cells which will get extra space |
9076e56d | 970 | int total = -1; |
4dd9ae57 | 971 | |
1c0ee565 VS |
972 | const wxHtmlCell *c; |
973 | if ( line != cell ) | |
a1ae1090 | 974 | { |
9076e56d | 975 | for ( c = line; c != cell; c = c->GetNext() ) |
4dd9ae57 | 976 | { |
1c0ee565 VS |
977 | if ( c->IsLinebreakAllowed() ) |
978 | { | |
979 | total++; | |
980 | } | |
4dd9ae57 | 981 | } |
a1ae1090 VZ |
982 | } |
983 | ||
984 | // and now extra space to those cells which merit it | |
985 | if ( total ) | |
986 | { | |
9076e56d VZ |
987 | // first visible cell on line is not moved: |
988 | while (line !=cell && !line->IsLinebreakAllowed()) | |
989 | { | |
990 | line->SetPos(line->GetPosX() + s_indent, | |
991 | line->GetPosY() + ypos); | |
992 | line = line->GetNext(); | |
993 | } | |
994 | ||
995 | if (line != cell) | |
996 | { | |
997 | line->SetPos(line->GetPosX() + s_indent, | |
998 | line->GetPosY() + ypos); | |
999 | ||
1000 | line = line->GetNext(); | |
1001 | } | |
d1da8872 | 1002 | |
1c0ee565 | 1003 | for ( int n = 0; line != cell; line = line->GetNext() ) |
a1ae1090 | 1004 | { |
1c0ee565 | 1005 | if ( line->IsLinebreakAllowed() ) |
a1ae1090 VZ |
1006 | { |
1007 | // offset the next cell relative to this one | |
1008 | // thus increasing our size | |
1009 | n++; | |
1010 | } | |
d1da8872 | 1011 | |
1c0ee565 VS |
1012 | line->SetPos(line->GetPosX() + s_indent + |
1013 | ((n * step) / total), | |
1014 | line->GetPosY() + ypos); | |
a1ae1090 VZ |
1015 | } |
1016 | } | |
2d1d813e VS |
1017 | else |
1018 | { | |
1019 | // this will cause the code to enter "else branch" below: | |
1020 | step = 0; | |
1021 | } | |
a1ae1090 | 1022 | } |
2d1d813e VS |
1023 | // else branch: |
1024 | if ( step <= 0 ) // no extra space to distribute | |
a1ae1090 VZ |
1025 | { |
1026 | // just set the indent properly | |
1027 | while (line != cell) | |
1028 | { | |
1029 | line->SetPos(line->GetPosX() + s_indent, | |
1030 | line->GetPosY() + ypos); | |
1031 | line = line->GetNext(); | |
1032 | } | |
5c1bfc5d | 1033 | } |
5526e819 VS |
1034 | } |
1035 | ||
1036 | ypos += ysizedown; | |
49f6740f | 1037 | xpos = 0; |
5526e819 VS |
1038 | ysizeup = ysizedown = 0; |
1039 | line = cell; | |
1040 | } | |
1041 | } | |
1042 | ||
1043 | // setup height & width, depending on container layout: | |
1044 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
1045 | ||
04dbb646 | 1046 | if (m_Height < m_MinHeight) |
4f9297b0 | 1047 | { |
04dbb646 | 1048 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 1049 | { |
5526e819 | 1050 | int diff = m_MinHeight - m_Height; |
efba2b89 | 1051 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 1052 | cell = m_Cells; |
04dbb646 | 1053 | while (cell) |
0cb9cfb2 | 1054 | { |
4f9297b0 VS |
1055 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
1056 | cell = cell->GetNext(); | |
5526e819 VS |
1057 | } |
1058 | } | |
1059 | m_Height = m_MinHeight; | |
1060 | } | |
1061 | ||
ca16b7a9 VS |
1062 | if (curLineWidth > m_MaxTotalWidth) |
1063 | m_MaxTotalWidth = curLineWidth; | |
d1da8872 | 1064 | |
ca16b7a9 | 1065 | m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
5c1bfc5d VS |
1066 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
1067 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 VS |
1068 | } |
1069 | ||
f30e67db | 1070 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
1071 | wxHtmlCell *cell) const |
1072 | { | |
f30e67db | 1073 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 1074 | if (!s) return; |
cd275246 | 1075 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 1076 | { |
f30e67db | 1077 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
1078 | } |
1079 | } | |
1080 | ||
f30e67db | 1081 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
1082 | wxHtmlCell *cell) const |
1083 | { | |
f30e67db | 1084 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 1085 | if (!s) return; |
adf2eb2d | 1086 | if (s->GetToCell() == cell) |
f30e67db | 1087 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 1088 | else if (s->GetFromCell() == cell) |
f30e67db | 1089 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 1090 | } |
5526e819 VS |
1091 | |
1092 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
1093 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
1094 | ||
36c4ff4d | 1095 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 1096 | wxHtmlRenderingInfo& info) |
5526e819 | 1097 | { |
ace0fab4 VS |
1098 | #if 0 // useful for debugging |
1099 | dc.SetPen(*wxRED_PEN); | |
1100 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
1101 | #endif | |
95af070a | 1102 | |
848c4eb2 VS |
1103 | int xlocal = x + m_PosX; |
1104 | int ylocal = y + m_PosY; | |
1105 | ||
1106 | if (m_UseBkColour) | |
4f9297b0 | 1107 | { |
04ee05f9 | 1108 | wxBrush myb = wxBrush(m_BkColour, wxBRUSHSTYLE_SOLID); |
5526e819 | 1109 | |
848c4eb2 VS |
1110 | int real_y1 = mMax(ylocal, view_y1); |
1111 | int real_y2 = mMin(ylocal + m_Height - 1, view_y2); | |
5526e819 | 1112 | |
848c4eb2 VS |
1113 | dc.SetBrush(myb); |
1114 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1115 | dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1); | |
1116 | } | |
5526e819 | 1117 | |
3aaaf1aa | 1118 | if (m_Border == 1) |
848c4eb2 | 1119 | { |
03647350 | 1120 | // draw thin border using lines |
04ee05f9 PC |
1121 | wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID); |
1122 | wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID); | |
848c4eb2 VS |
1123 | |
1124 | dc.SetPen(mypen1); | |
1125 | dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1); | |
1126 | dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal); | |
1127 | dc.SetPen(mypen2); | |
1128 | dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1); | |
1129 | dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1); | |
1130 | } | |
3aaaf1aa | 1131 | else if (m_Border> 0) |
03647350 | 1132 | { |
3aaaf1aa VZ |
1133 | wxBrush mybrush1(m_BorderColour1, wxBRUSHSTYLE_SOLID); |
1134 | wxBrush mybrush2(m_BorderColour2, wxBRUSHSTYLE_SOLID); | |
03647350 | 1135 | |
3aaaf1aa VZ |
1136 | // draw upper left corner |
1137 | // 0---------------5 | |
1138 | // | / | |
1139 | // | 3-----------4 | |
1140 | // | | | |
1141 | // | 2 | |
1142 | // |/ | |
03647350 | 1143 | // 1 |
3aaaf1aa VZ |
1144 | |
1145 | wxPoint poly[6]; | |
1146 | poly[0].x =m_PosX; poly[0].y = m_PosY ; | |
1147 | poly[1].x =m_PosX; poly[1].y = m_PosY + m_Height; | |
1148 | poly[2].x =m_PosX + m_Border; poly[2].y = poly[1].y - m_Border; | |
1149 | poly[3].x =poly[2].x ; poly[3].y = m_PosY + m_Border; | |
1150 | poly[4].x =m_PosX + m_Width - m_Border; poly[4].y = poly[3].y; | |
1151 | poly[5].x =m_PosX + m_Width; poly[5].y = m_PosY; | |
1152 | ||
1153 | dc.SetBrush(mybrush1); | |
1154 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1155 | dc.DrawPolygon(6, poly, x, y); | |
03647350 | 1156 | |
3aaaf1aa VZ |
1157 | // draw lower right corner reusing point 1,2,4 and 5 |
1158 | // 5 | |
1159 | // /| | |
1160 | // 4 | | |
1161 | // | | | |
1162 | // 2-----------3 | | |
1163 | // / | | |
1164 | // 1---------------0 | |
1165 | dc.SetBrush(mybrush2); | |
1166 | poly[0].x = poly[5].x; poly[0].y = poly[1].y; | |
1167 | poly[3].x = poly[4].x; poly[3].y = poly[2].y; | |
1168 | dc.DrawPolygon(6, poly, x, y); | |
1169 | ||
03647350 | 1170 | // smooth color transition like firefox |
3aaaf1aa VZ |
1171 | wxColour borderMediumColour( |
1172 | (m_BorderColour1.Red() + m_BorderColour2.Red()) /2 , | |
1173 | (m_BorderColour1.Green() + m_BorderColour2.Green()) /2 , | |
03647350 | 1174 | (m_BorderColour1.Blue() + m_BorderColour2.Blue()) /2 |
3aaaf1aa VZ |
1175 | ); |
1176 | wxPen mypen3(borderMediumColour, 1, wxPENSTYLE_SOLID); | |
1177 | dc.SetPen(mypen3); | |
1178 | dc.DrawLines(2, &poly[1], x, y - 1); // between 1 and 2 | |
1179 | dc.DrawLines(2, &poly[4], x, y - 1); // between 4 and 5 | |
1180 | } | |
848c4eb2 VS |
1181 | if (m_Cells) |
1182 | { | |
1183 | // draw container's contents: | |
1184 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
bf7d7ee7 | 1185 | { |
95af070a | 1186 | |
848c4eb2 VS |
1187 | // optimize drawing: don't render off-screen content: |
1188 | if ((ylocal + cell->GetPosY() <= view_y2) && | |
1189 | (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1)) | |
36c4ff4d | 1190 | { |
848c4eb2 | 1191 | // the cell is visible, draw it: |
f30e67db | 1192 | UpdateRenderingStatePre(info, cell); |
36c4ff4d | 1193 | cell->Draw(dc, |
848c4eb2 | 1194 | xlocal, ylocal, view_y1, view_y2, |
f30e67db VS |
1195 | info); |
1196 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1197 | } |
848c4eb2 VS |
1198 | else |
1199 | { | |
1200 | // the cell is off-screen, proceed with font+color+etc. | |
1201 | // changes only: | |
1202 | cell->DrawInvisible(dc, xlocal, ylocal, info); | |
1203 | } | |
bf7d7ee7 | 1204 | } |
5526e819 | 1205 | } |
5526e819 VS |
1206 | } |
1207 | ||
1208 | ||
1209 | ||
36c4ff4d | 1210 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 1211 | wxHtmlRenderingInfo& info) |
5526e819 | 1212 | { |
d699f48b | 1213 | if (m_Cells) |
bf7d7ee7 VS |
1214 | { |
1215 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 1216 | { |
f30e67db VS |
1217 | UpdateRenderingStatePre(info, cell); |
1218 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
1219 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 1220 | } |
bf7d7ee7 | 1221 | } |
5526e819 VS |
1222 | } |
1223 | ||
1224 | ||
2b5f62a0 VZ |
1225 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
1226 | { | |
1227 | if (m_UseBkColour) | |
1228 | return m_BkColour; | |
1229 | else | |
1230 | return wxNullColour; | |
1231 | } | |
1232 | ||
1233 | ||
5526e819 | 1234 | |
846914d1 | 1235 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 1236 | { |
f6010d8f | 1237 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 1238 | |
f6010d8f VZ |
1239 | // VZ: I don't know if we should pass absolute or relative coords to |
1240 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
1241 | // anyhow, it hardly matters right now but should still be clarified | |
1242 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
1243 | } |
1244 | ||
1245 | ||
1246 | ||
1247 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
1248 | { | |
1249 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 1250 | else |
4f9297b0 VS |
1251 | { |
1252 | m_LastCell->SetNext(f); | |
5526e819 | 1253 | m_LastCell = f; |
4f9297b0 | 1254 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 1255 | } |
4f9297b0 | 1256 | f->SetParent(this); |
5660c520 | 1257 | m_LastLayout = -1; |
5526e819 VS |
1258 | } |
1259 | ||
1260 | ||
1261 | ||
1262 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
1263 | { | |
04dbb646 | 1264 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 1265 | { |
0413cec5 | 1266 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 1267 | alg.MakeUpper(); |
0413cec5 | 1268 | if (alg == wxT("CENTER")) |
efba2b89 | 1269 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 1270 | else if (alg == wxT("LEFT")) |
efba2b89 | 1271 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
1272 | else if (alg == wxT("JUSTIFY")) |
1273 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 1274 | else if (alg == wxT("RIGHT")) |
efba2b89 | 1275 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 1276 | m_LastLayout = -1; |
5526e819 VS |
1277 | } |
1278 | } | |
1279 | ||
1280 | ||
1281 | ||
edbd0635 | 1282 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 1283 | { |
04dbb646 | 1284 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 1285 | { |
5526e819 | 1286 | int wdi; |
0413cec5 | 1287 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 1288 | |
93763ad5 | 1289 | if (wd[wd.length()-1] == wxT('%')) |
0cb9cfb2 | 1290 | { |
66a77a74 | 1291 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 1292 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 1293 | } |
04dbb646 | 1294 | else |
0cb9cfb2 | 1295 | { |
66a77a74 | 1296 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
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 VS |
1554 | state.SetBgColour(m_Colour); |
1555 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
b87dd6f5 | 1556 | { |
36c4ff4d | 1557 | dc.SetTextBackground(m_Colour); |
04ee05f9 | 1558 | dc.SetBackground(wxBrush(m_Colour, wxBRUSHSTYLE_SOLID)); |
b87dd6f5 | 1559 | } |
bfc248a3 | 1560 | else |
b87dd6f5 VS |
1561 | { |
1562 | wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); | |
1563 | dc.SetTextBackground(c); | |
04ee05f9 | 1564 | dc.SetBackground(wxBrush(c, wxBRUSHSTYLE_SOLID)); |
b87dd6f5 | 1565 | } |
5526e819 | 1566 | } |
5526e819 VS |
1567 | } |
1568 | ||
1569 | ||
1570 | ||
1571 | ||
36c4ff4d | 1572 | // --------------------------------------------------------------------------- |
5526e819 | 1573 | // wxHtmlFontCell |
36c4ff4d | 1574 | // --------------------------------------------------------------------------- |
5526e819 | 1575 | |
4f44ea36 MB |
1576 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1577 | ||
36c4ff4d VS |
1578 | void wxHtmlFontCell::Draw(wxDC& dc, |
1579 | int WXUNUSED(x), int WXUNUSED(y), | |
1580 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1581 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1582 | { |
921d0fb1 | 1583 | dc.SetFont(m_Font); |
5526e819 VS |
1584 | } |
1585 | ||
36c4ff4d | 1586 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1587 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1588 | { |
921d0fb1 | 1589 | dc.SetFont(m_Font); |
5526e819 VS |
1590 | } |
1591 | ||
1592 | ||
1593 | ||
1594 | ||
1595 | ||
1596 | ||
1597 | ||
1598 | ||
36c4ff4d | 1599 | // --------------------------------------------------------------------------- |
5526e819 | 1600 | // wxHtmlWidgetCell |
36c4ff4d | 1601 | // --------------------------------------------------------------------------- |
5526e819 | 1602 | |
4f44ea36 MB |
1603 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1604 | ||
5526e819 VS |
1605 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1606 | { | |
1607 | int sx, sy; | |
1608 | m_Wnd = wnd; | |
4f9297b0 | 1609 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1610 | m_Width = sx, m_Height = sy; |
1611 | m_WidthFloat = w; | |
1612 | } | |
1613 | ||
1614 | ||
36c4ff4d VS |
1615 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1616 | int WXUNUSED(x), int WXUNUSED(y), | |
1617 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1618 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1619 | { |
1620 | int absx = 0, absy = 0, stx, sty; | |
1621 | wxHtmlCell *c = this; | |
1622 | ||
04dbb646 | 1623 | while (c) |
4f9297b0 VS |
1624 | { |
1625 | absx += c->GetPosX(); | |
1626 | absy += c->GetPosY(); | |
1627 | c = c->GetParent(); | |
5526e819 VS |
1628 | } |
1629 | ||
c4184573 VS |
1630 | wxScrolledWindow *scrolwin = |
1631 | wxDynamicCast(m_Wnd->GetParent(), wxScrolledWindow); | |
1632 | wxCHECK_RET( scrolwin, | |
9a83f860 | 1633 | wxT("widget cells can only be placed in wxHtmlWindow") ); |
c4184573 VS |
1634 | |
1635 | scrolwin->GetViewStart(&stx, &sty); | |
1636 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, | |
1637 | absy - wxHTML_SCROLL_STEP * sty, | |
1638 | m_Width, m_Height); | |
5526e819 VS |
1639 | } |
1640 | ||
1641 | ||
1642 | ||
36c4ff4d VS |
1643 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1644 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1645 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1646 | { |
1647 | int absx = 0, absy = 0, stx, sty; | |
1648 | wxHtmlCell *c = this; | |
1649 | ||
04dbb646 | 1650 | while (c) |
4f9297b0 VS |
1651 | { |
1652 | absx += c->GetPosX(); | |
1653 | absy += c->GetPosY(); | |
1654 | c = c->GetParent(); | |
5526e819 | 1655 | } |
7e941458 | 1656 | |
e421922f | 1657 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1658 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1659 | } |
1660 | ||
1661 | ||
1662 | ||
1663 | void wxHtmlWidgetCell::Layout(int w) | |
1664 | { | |
04dbb646 | 1665 | if (m_WidthFloat != 0) |
4f9297b0 | 1666 | { |
5526e819 | 1667 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1668 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1669 | } |
1670 | ||
1671 | wxHtmlCell::Layout(w); | |
1672 | } | |
1673 | ||
e3774124 VS |
1674 | |
1675 | ||
1676 | // ---------------------------------------------------------------------------- | |
1677 | // wxHtmlTerminalCellsInterator | |
1678 | // ---------------------------------------------------------------------------- | |
1679 | ||
1680 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1681 | { | |
1682 | if ( !m_pos ) | |
1683 | return NULL; | |
1684 | ||
1685 | do | |
1686 | { | |
1687 | if ( m_pos == m_to ) | |
1688 | { | |
1689 | m_pos = NULL; | |
1690 | return NULL; | |
1691 | } | |
1692 | ||
1693 | if ( m_pos->GetNext() ) | |
1694 | m_pos = m_pos->GetNext(); | |
1695 | else | |
1696 | { | |
1697 | // we must go up the hierarchy until we reach container where this | |
1698 | // is not the last child, and then go down to first terminal cell: | |
1699 | while ( m_pos->GetNext() == NULL ) | |
1700 | { | |
1701 | m_pos = m_pos->GetParent(); | |
1702 | if ( !m_pos ) | |
1703 | return NULL; | |
1704 | } | |
1705 | m_pos = m_pos->GetNext(); | |
1706 | } | |
1707 | while ( m_pos->GetFirstChild() != NULL ) | |
1708 | m_pos = m_pos->GetFirstChild(); | |
1709 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1710 | |
e3774124 VS |
1711 | return m_pos; |
1712 | } | |
1713 | ||
5526e819 | 1714 | #endif |