]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmlcell.cpp | |
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 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
1aedb1dd | 11 | #pragma implementation "htmlcell.h" |
5526e819 VS |
12 | #endif |
13 | ||
4dcaf11a | 14 | #include "wx/wxprec.h" |
5526e819 | 15 | |
314260fb | 16 | #include "wx/defs.h" |
f6bcfd97 BP |
17 | |
18 | #if wxUSE_HTML && wxUSE_STREAMS | |
5526e819 | 19 | |
2b5f62a0 | 20 | #ifdef __BORLANDC__ |
5526e819 VS |
21 | #pragma hdrstop |
22 | #endif | |
23 | ||
24 | #ifndef WXPRECOMP | |
04dbb646 VZ |
25 | #include "wx/brush.h" |
26 | #include "wx/colour.h" | |
27 | #include "wx/dc.h" | |
5526e819 VS |
28 | #endif |
29 | ||
4dcaf11a RR |
30 | #include "wx/html/htmlcell.h" |
31 | #include "wx/html/htmlwin.h" | |
36c4ff4d | 32 | #include "wx/settings.h" |
77bae5e2 | 33 | #include "wx/module.h" |
ace0fab4 | 34 | #include "wx/dynarray.h" |
77bae5e2 | 35 | |
5526e819 VS |
36 | #include <stdlib.h> |
37 | ||
77bae5e2 VS |
38 | //----------------------------------------------------------------------------- |
39 | // Global variables | |
40 | //----------------------------------------------------------------------------- | |
41 | ||
42 | static wxCursor *gs_cursorLink = NULL; | |
43 | static wxCursor *gs_cursorText = NULL; | |
44 | ||
45 | ||
e3774124 VS |
46 | //----------------------------------------------------------------------------- |
47 | // Helper classes | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
1338c59a VS |
50 | void wxHtmlSelection::Set(const wxPoint& fromPos, const wxHtmlCell *fromCell, |
51 | const wxPoint& toPos, const wxHtmlCell *toCell) | |
e3774124 VS |
52 | { |
53 | m_fromCell = fromCell; | |
54 | m_toCell = toCell; | |
55 | m_fromPos = fromPos; | |
56 | m_toPos = toPos; | |
57 | } | |
58 | ||
1338c59a | 59 | void wxHtmlSelection::Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell) |
e3774124 VS |
60 | { |
61 | wxPoint p1 = fromCell ? fromCell->GetAbsPos() : wxDefaultPosition; | |
62 | wxPoint p2 = toCell ? toCell->GetAbsPos() : wxDefaultPosition; | |
63 | if ( toCell ) | |
64 | { | |
afcc5de1 VS |
65 | p2.x += toCell->GetWidth(); |
66 | p2.y += toCell->GetHeight(); | |
e3774124 VS |
67 | } |
68 | Set(p1, fromCell, p2, toCell); | |
69 | } | |
5526e819 | 70 | |
fc7a2a60 VZ |
71 | wxColour |
72 | wxDefaultHtmlRenderingStyle:: | |
73 | GetSelectedTextColour(const wxColour& WXUNUSED(clr)) | |
f30e67db VS |
74 | { |
75 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
76 | } | |
77 | ||
fc7a2a60 VZ |
78 | wxColour |
79 | wxDefaultHtmlRenderingStyle:: | |
80 | GetSelectedTextBgColour(const wxColour& WXUNUSED(clr)) | |
f30e67db VS |
81 | { |
82 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); | |
83 | } | |
84 | ||
85 | ||
5526e819 VS |
86 | //----------------------------------------------------------------------------- |
87 | // wxHtmlCell | |
88 | //----------------------------------------------------------------------------- | |
89 | ||
4f44ea36 MB |
90 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell, wxObject) |
91 | ||
04dbb646 | 92 | wxHtmlCell::wxHtmlCell() : wxObject() |
846914d1 | 93 | { |
04dbb646 VZ |
94 | m_Next = NULL; |
95 | m_Parent = NULL; | |
96 | m_Width = m_Height = m_Descent = 0; | |
49f6740f | 97 | m_CanLiveOnPagebreak = true; |
846914d1 VS |
98 | m_Link = NULL; |
99 | } | |
100 | ||
04dbb646 | 101 | wxHtmlCell::~wxHtmlCell() |
846914d1 | 102 | { |
0cb9cfb2 | 103 | delete m_Link; |
846914d1 VS |
104 | } |
105 | ||
5526e819 | 106 | |
04dbb646 | 107 | void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, |
0b2dadd3 | 108 | const wxMouseEvent& event) |
5526e819 | 109 | { |
846914d1 VS |
110 | wxHtmlLinkInfo *lnk = GetLink(x, y); |
111 | if (lnk != NULL) | |
0b2dadd3 VS |
112 | { |
113 | wxHtmlLinkInfo lnk2(*lnk); | |
114 | lnk2.SetEvent(&event); | |
9bc8fded | 115 | lnk2.SetHtmlCell(this); |
0cb9cfb2 VZ |
116 | |
117 | // note : this cast is legal because parent is *always* wxHtmlWindow | |
118 | wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2); | |
0b2dadd3 | 119 | } |
5526e819 VS |
120 | } |
121 | ||
122 | ||
77bae5e2 VS |
123 | wxCursor wxHtmlCell::GetCursor() const |
124 | { | |
125 | if ( GetLink() ) | |
126 | { | |
127 | if ( !gs_cursorLink ) | |
128 | gs_cursorLink = new wxCursor(wxCURSOR_HAND); | |
129 | return *gs_cursorLink; | |
130 | } | |
131 | else | |
132 | return *wxSTANDARD_CURSOR; | |
133 | } | |
134 | ||
5526e819 | 135 | |
f2034f1b | 136 | bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const |
db98870d | 137 | { |
04dbb646 VZ |
138 | if ((!m_CanLiveOnPagebreak) && |
139 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) | |
0cb9cfb2 | 140 | { |
db98870d | 141 | *pagebreak = m_PosY; |
49f6740f | 142 | return true; |
db98870d | 143 | } |
0cb9cfb2 | 144 | |
49f6740f | 145 | return false; |
db98870d VS |
146 | } |
147 | ||
148 | ||
149 | ||
04dbb646 | 150 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 VS |
151 | { |
152 | if (m_Link) delete m_Link; | |
af1ed0c1 VS |
153 | m_Link = NULL; |
154 | if (link.GetHref() != wxEmptyString) | |
155 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
156 | } |
157 | ||
158 | ||
d699f48b | 159 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 160 | { |
04dbb646 | 161 | SetPos(0, 0); |
721ab905 VS |
162 | } |
163 | ||
164 | ||
79d6c018 | 165 | |
d699f48b | 166 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 167 | { |
bf7d7ee7 | 168 | return NULL; |
721ab905 VS |
169 | } |
170 | ||
171 | ||
36c4ff4d VS |
172 | wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y, |
173 | unsigned flags) const | |
f6010d8f | 174 | { |
adf2eb2d | 175 | if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height ) |
36c4ff4d | 176 | { |
f6010d8f | 177 | return wxConstCast(this, wxHtmlCell); |
36c4ff4d | 178 | } |
adf2eb2d VS |
179 | else |
180 | { | |
181 | if ((flags & wxHTML_FIND_NEAREST_AFTER) && | |
03693319 | 182 | (y < 0 || (y < 0+m_Height && x < 0+m_Width))) |
adf2eb2d VS |
183 | return wxConstCast(this, wxHtmlCell); |
184 | else if ((flags & wxHTML_FIND_NEAREST_BEFORE) && | |
03693319 | 185 | (y >= 0+m_Height || (y >= 0 && x >= 0))) |
adf2eb2d VS |
186 | return wxConstCast(this, wxHtmlCell); |
187 | else | |
188 | return NULL; | |
189 | } | |
190 | } | |
191 | ||
192 | ||
193 | wxPoint wxHtmlCell::GetAbsPos() const | |
194 | { | |
195 | wxPoint p(m_PosX, m_PosY); | |
196 | for (wxHtmlCell *parent = m_Parent; parent; parent = parent->m_Parent) | |
197 | { | |
198 | p.x += parent->m_PosX; | |
199 | p.y += parent->m_PosY; | |
200 | } | |
201 | return p; | |
f6010d8f | 202 | } |
86ff9b45 | 203 | |
e3774124 VS |
204 | unsigned wxHtmlCell::GetDepth() const |
205 | { | |
206 | unsigned d = 0; | |
207 | for (wxHtmlCell *p = m_Parent; p; p = p->m_Parent) | |
208 | d++; | |
209 | return d; | |
210 | } | |
86ff9b45 | 211 | |
e3774124 VS |
212 | bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const |
213 | { | |
214 | const wxHtmlCell *c1 = this; | |
215 | const wxHtmlCell *c2 = cell; | |
216 | unsigned d1 = GetDepth(); | |
217 | unsigned d2 = cell->GetDepth(); | |
218 | ||
219 | if ( d1 > d2 ) | |
220 | for (; d1 != d2; d1-- ) | |
221 | c1 = c1->m_Parent; | |
222 | else if ( d1 < d2 ) | |
223 | for (; d1 != d2; d2-- ) | |
224 | c2 = c2->m_Parent; | |
225 | ||
226 | if ( cell == this ) | |
227 | return true; | |
228 | ||
229 | while ( c1 && c2 ) | |
230 | { | |
231 | if ( c1->m_Parent == c2->m_Parent ) | |
232 | { | |
233 | while ( c1 ) | |
234 | { | |
235 | if ( c1 == c2 ) | |
236 | return true; | |
237 | c1 = c1->GetNext(); | |
86ff9b45 | 238 | } |
e3774124 VS |
239 | return false; |
240 | } | |
241 | else | |
242 | { | |
243 | c1 = c1->m_Parent; | |
244 | c2 = c2->m_Parent; | |
245 | } | |
246 | } | |
247 | ||
248 | wxFAIL_MSG(_T("Cells are in different trees")); | |
249 | return false; | |
250 | } | |
f6010d8f | 251 | |
721ab905 | 252 | |
5526e819 VS |
253 | //----------------------------------------------------------------------------- |
254 | // wxHtmlWordCell | |
255 | //----------------------------------------------------------------------------- | |
256 | ||
4f44ea36 MB |
257 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell) |
258 | ||
5526e819 VS |
259 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() |
260 | { | |
261 | m_Word = word; | |
5526e819 | 262 | dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); |
49f6740f | 263 | SetCanLiveOnPagebreak(false); |
b6d93b26 | 264 | m_allowLinebreak = true; |
5526e819 VS |
265 | } |
266 | ||
b6d93b26 VS |
267 | void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell) |
268 | { | |
269 | if ( cell && m_Parent == cell->m_Parent && | |
270 | !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) ) | |
271 | { | |
272 | m_allowLinebreak = false; | |
273 | } | |
274 | } | |
5526e819 | 275 | |
5a1597e9 VS |
276 | // Splits m_Word into up to three parts according to selection, returns |
277 | // substring before, in and after selection and the points (in relative coords) | |
278 | // where s2 and s3 start: | |
1338c59a | 279 | void wxHtmlWordCell::Split(wxDC& dc, |
5a1597e9 | 280 | const wxPoint& selFrom, const wxPoint& selTo, |
f30e67db | 281 | unsigned& pos1, unsigned& pos2) const |
5a1597e9 VS |
282 | { |
283 | wxPoint pt1 = (selFrom == wxDefaultPosition) ? | |
284 | wxDefaultPosition : selFrom - GetAbsPos(); | |
285 | wxPoint pt2 = (selTo == wxDefaultPosition) ? | |
49f6740f | 286 | wxPoint(m_Width, wxDefaultPosition.y) : selTo - GetAbsPos(); |
5a1597e9 VS |
287 | |
288 | wxCoord charW, charH; | |
289 | unsigned len = m_Word.length(); | |
290 | unsigned i = 0; | |
291 | pos1 = 0; | |
5a1597e9 | 292 | |
03693319 VS |
293 | // adjust for cases when the start/end position is completely |
294 | // outside the cell: | |
295 | if ( pt1.y < 0 ) | |
296 | pt1.x = 0; | |
297 | if ( pt2.y >= m_Height ) | |
298 | pt2.x = m_Width; | |
299 | ||
5a1597e9 VS |
300 | // before selection: |
301 | while ( pt1.x > 0 && i < len ) | |
302 | { | |
303 | dc.GetTextExtent(m_Word[i], &charW, &charH); | |
304 | pt1.x -= charW; | |
305 | if ( pt1.x >= 0 ) | |
306 | { | |
307 | pos1 += charW; | |
308 | i++; | |
309 | } | |
310 | } | |
5526e819 | 311 | |
5a1597e9 VS |
312 | // in selection: |
313 | unsigned j = i; | |
314 | pos2 = pos1; | |
f30e67db | 315 | pt2.x -= pos2; |
5a1597e9 VS |
316 | while ( pt2.x > 0 && j < len ) |
317 | { | |
318 | dc.GetTextExtent(m_Word[j], &charW, &charH); | |
319 | pt2.x -= charW; | |
320 | if ( pt2.x >= 0 ) | |
321 | { | |
322 | pos2 += charW; | |
323 | j++; | |
324 | } | |
325 | } | |
f30e67db VS |
326 | |
327 | pos1 = i; | |
328 | pos2 = j; | |
329 | } | |
330 | ||
331 | void wxHtmlWordCell::SetSelectionPrivPos(wxDC& dc, wxHtmlSelection *s) const | |
332 | { | |
333 | unsigned p1, p2; | |
86ff9b45 VZ |
334 | |
335 | Split(dc, | |
f30e67db VS |
336 | this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition, |
337 | this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition, | |
338 | p1, p2); | |
339 | ||
340 | wxPoint p(0, m_Word.length()); | |
86ff9b45 | 341 | |
f30e67db VS |
342 | if ( this == s->GetFromCell() ) |
343 | p.x = p1; // selection starts here | |
344 | if ( this == s->GetToCell() ) | |
345 | p.y = p2; // selection ends here | |
86ff9b45 | 346 | |
f30e67db VS |
347 | if ( this == s->GetFromCell() ) |
348 | s->SetFromPrivPos(p); | |
349 | if ( this == s->GetToCell() ) | |
350 | s->SetToPrivPos(p); | |
5a1597e9 VS |
351 | } |
352 | ||
353 | ||
f30e67db | 354 | static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info, |
5a1597e9 | 355 | bool toSelection) |
5526e819 | 356 | { |
f30e67db VS |
357 | wxColour fg = info.GetState().GetFgColour(); |
358 | wxColour bg = info.GetState().GetBgColour(); | |
86ff9b45 | 359 | |
5a1597e9 | 360 | if ( toSelection ) |
36c4ff4d VS |
361 | { |
362 | dc.SetBackgroundMode(wxSOLID); | |
f30e67db VS |
363 | dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg)); |
364 | dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg)); | |
b87dd6f5 VS |
365 | dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg), |
366 | wxSOLID)); | |
36c4ff4d | 367 | } |
5a1597e9 | 368 | else |
36c4ff4d VS |
369 | { |
370 | dc.SetBackgroundMode(wxTRANSPARENT); | |
f30e67db VS |
371 | dc.SetTextForeground(fg); |
372 | dc.SetTextBackground(bg); | |
b87dd6f5 | 373 | dc.SetBackground(wxBrush(bg, wxSOLID)); |
36c4ff4d | 374 | } |
5a1597e9 | 375 | } |
36c4ff4d | 376 | |
5a1597e9 VS |
377 | |
378 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
379 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 380 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
381 | { |
382 | #if 0 // useful for debugging | |
ace0fab4 | 383 | dc.SetPen(*wxBLACK_PEN); |
4dd9ae57 | 384 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height); |
5a1597e9 VS |
385 | #endif |
386 | ||
b87dd6f5 VS |
387 | bool drawSelectionAfterCell = false; |
388 | ||
f30e67db | 389 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
390 | { |
391 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
392 | wxHtmlSelection *s = info.GetSelection(); |
393 | wxString txt; | |
394 | int w, h; | |
395 | int ofs = 0; | |
86ff9b45 VZ |
396 | |
397 | wxPoint priv = (this == s->GetFromCell()) ? | |
f30e67db | 398 | s->GetFromPrivPos() : s->GetToPrivPos(); |
1338c59a VS |
399 | |
400 | // NB: this is quite a hack: in order to compute selection boundaries | |
401 | // (in word's characters) we must know current font, which is only | |
402 | // possible inside rendering code. Therefore we update the | |
403 | // information here and store it in wxHtmlSelection so that | |
404 | // ConvertToText can use it later: | |
405 | if ( priv == wxDefaultPosition ) | |
406 | { | |
407 | SetSelectionPrivPos(dc, s); | |
86ff9b45 | 408 | priv = (this == s->GetFromCell()) ? |
1338c59a VS |
409 | s->GetFromPrivPos() : s->GetToPrivPos(); |
410 | } | |
86ff9b45 | 411 | |
f30e67db VS |
412 | int part1 = priv.x; |
413 | int part2 = priv.y; | |
414 | ||
415 | if ( part1 > 0 ) | |
5a1597e9 | 416 | { |
f30e67db VS |
417 | txt = m_Word.Mid(0, part1); |
418 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
419 | dc.GetTextExtent(txt, &w, &h); | |
420 | ofs += w; | |
5a1597e9 | 421 | } |
86ff9b45 | 422 | |
f30e67db | 423 | SwitchSelState(dc, info, true); |
86ff9b45 | 424 | |
f30e67db VS |
425 | txt = m_Word.Mid(part1, part2-part1); |
426 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
427 | ||
70bae016 | 428 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 429 | { |
f30e67db VS |
430 | dc.GetTextExtent(txt, &w, &h); |
431 | ofs += w; | |
432 | SwitchSelState(dc, info, false); | |
433 | txt = m_Word.Mid(part2); | |
434 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 | 435 | } |
b87dd6f5 VS |
436 | else |
437 | drawSelectionAfterCell = true; | |
5a1597e9 VS |
438 | } |
439 | else | |
440 | { | |
b87dd6f5 | 441 | wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); |
5a1597e9 | 442 | // Not changing selection state, draw the word in single mode: |
b87dd6f5 | 443 | if ( selstate != wxHTML_SEL_OUT && |
5a1597e9 VS |
444 | dc.GetBackgroundMode() != wxSOLID ) |
445 | { | |
f30e67db | 446 | SwitchSelState(dc, info, true); |
5a1597e9 | 447 | } |
b87dd6f5 | 448 | else if ( selstate == wxHTML_SEL_OUT && |
5a1597e9 VS |
449 | dc.GetBackgroundMode() == wxSOLID ) |
450 | { | |
f30e67db | 451 | SwitchSelState(dc, info, false); |
5a1597e9 VS |
452 | } |
453 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
b87dd6f5 VS |
454 | drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); |
455 | } | |
456 | ||
457 | // NB: If the text is justified then there is usually some free space | |
458 | // between adjacent cells and drawing the selection only onto cells | |
459 | // would result in ugly unselected spaces. The code below detects | |
460 | // this special case and renders the selection *outside* the sell, | |
461 | // too. | |
462 | if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY && | |
463 | drawSelectionAfterCell ) | |
464 | { | |
465 | wxHtmlCell *nextCell = m_Next; | |
466 | while ( nextCell && nextCell->IsFormattingCell() ) | |
467 | nextCell = nextCell->GetNext(); | |
468 | if ( nextCell ) | |
469 | { | |
470 | int nextX = nextCell->GetPosX(); | |
471 | if ( m_PosX + m_Width < nextX ) | |
472 | { | |
473 | dc.SetBrush(dc.GetBackground()); | |
474 | dc.SetPen(*wxTRANSPARENT_PEN); | |
475 | dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY, | |
476 | nextX - m_PosX - m_Width, m_Height); | |
477 | } | |
478 | } | |
5a1597e9 | 479 | } |
5526e819 | 480 | } |
86ff9b45 | 481 | |
e3774124 | 482 | |
f30e67db | 483 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 484 | { |
f30e67db VS |
485 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
486 | { | |
86ff9b45 VZ |
487 | wxPoint priv = this == s->GetFromCell() ? s->GetFromPrivPos() |
488 | : s->GetToPrivPos(); | |
489 | ||
490 | // VZ: we may be called before we had a chance to re-render ourselves | |
491 | // and in this case GetFrom/ToPrivPos() is not set yet -- assume | |
492 | // that this only happens in case of a double/triple click (which | |
493 | // seems to be the case now) and so it makes sense to select the | |
494 | // entire contents of the cell in this case | |
495 | // | |
496 | // TODO: but this really needs to be fixed in some better way later... | |
497 | if ( priv != wxDefaultPosition ) | |
498 | { | |
499 | int part1 = priv.x; | |
500 | int part2 = priv.y; | |
501 | return m_Word.Mid(part1, part2-part1); | |
502 | } | |
503 | //else: return the whole word below | |
f30e67db | 504 | } |
86ff9b45 VZ |
505 | |
506 | return m_Word; | |
e3774124 | 507 | } |
5526e819 | 508 | |
77bae5e2 VS |
509 | wxCursor wxHtmlWordCell::GetCursor() const |
510 | { | |
511 | if ( !GetLink() ) | |
512 | { | |
513 | if ( !gs_cursorText ) | |
514 | gs_cursorText = new wxCursor(wxCURSOR_IBEAM); | |
515 | return *gs_cursorText; | |
516 | } | |
517 | else | |
518 | return wxHtmlCell::GetCursor(); | |
519 | } | |
520 | ||
5526e819 | 521 | |
5526e819 VS |
522 | //----------------------------------------------------------------------------- |
523 | // wxHtmlContainerCell | |
524 | //----------------------------------------------------------------------------- | |
525 | ||
4f44ea36 | 526 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell) |
5526e819 VS |
527 | |
528 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
529 | { | |
530 | m_Cells = m_LastCell = NULL; | |
531 | m_Parent = parent; | |
ca16b7a9 | 532 | m_MaxTotalWidth = 0; |
4f9297b0 | 533 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
534 | m_AlignHor = wxHTML_ALIGN_LEFT; |
535 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 536 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 537 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
49f6740f WS |
538 | m_UseBkColour = false; |
539 | m_UseBorder = false; | |
5c1bfc5d | 540 | m_MinHeight = 0; |
efba2b89 | 541 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 542 | m_LastLayout = -1; |
5526e819 VS |
543 | } |
544 | ||
04dbb646 | 545 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 546 | { |
491c9920 VZ |
547 | wxHtmlCell *cell = m_Cells; |
548 | while ( cell ) | |
bf7d7ee7 | 549 | { |
491c9920 VZ |
550 | wxHtmlCell *cellNext = cell->GetNext(); |
551 | delete cell; | |
552 | cell = cellNext; | |
bf7d7ee7 | 553 | } |
721ab905 VS |
554 | } |
555 | ||
5526e819 VS |
556 | |
557 | ||
558 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
559 | { | |
efba2b89 VS |
560 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
561 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
562 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
563 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
564 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 565 | m_LastLayout = -1; |
5526e819 VS |
566 | } |
567 | ||
568 | ||
569 | ||
570 | int wxHtmlContainerCell::GetIndent(int ind) const | |
571 | { | |
efba2b89 VS |
572 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
573 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
574 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
575 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
576 | else return -1; /* BUG! Should not be called... */ |
577 | } | |
578 | ||
579 | ||
580 | ||
581 | ||
582 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
583 | { | |
49f6740f | 584 | bool p = false; |
efba2b89 VS |
585 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
586 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
587 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
588 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
589 | if (p) return wxHTML_UNITS_PERCENT; | |
590 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
591 | } |
592 | ||
593 | ||
594 | ||
f2034f1b | 595 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const |
db98870d | 596 | { |
04dbb646 | 597 | if (!m_CanLiveOnPagebreak) |
f2034f1b | 598 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages); |
e52d6dbc | 599 | |
04dbb646 | 600 | else |
4f9297b0 | 601 | { |
e3774124 | 602 | wxHtmlCell *c = GetFirstChild(); |
49f6740f | 603 | bool rt = false; |
e52d6dbc | 604 | int pbrk = *pagebreak - m_PosY; |
db98870d | 605 | |
04dbb646 | 606 | while (c) |
0cb9cfb2 | 607 | { |
f2034f1b | 608 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages)) |
49f6740f | 609 | rt = true; |
4f9297b0 | 610 | c = c->GetNext(); |
db98870d | 611 | } |
d699f48b | 612 | if (rt) |
bf7d7ee7 | 613 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
614 | return rt; |
615 | } | |
616 | } | |
617 | ||
618 | ||
619 | ||
5526e819 VS |
620 | void wxHtmlContainerCell::Layout(int w) |
621 | { | |
026d1fac VS |
622 | wxHtmlCell::Layout(w); |
623 | ||
624 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 625 | |
026d1fac VS |
626 | // VS: Any attempt to layout with negative or zero width leads to hell, |
627 | // but we can't ignore such attempts completely, since it sometimes | |
628 | // happen (e.g. when trying how small a table can be). The best thing we | |
629 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 630 | if (w < 1) |
4f9297b0 | 631 | { |
026d1fac VS |
632 | m_Width = 0; |
633 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
634 | cell->Layout(0); | |
2b5f62a0 VZ |
635 | // this does two things: it recursively calls this code on all |
636 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 637 | return; |
04dbb646 | 638 | } |
5660c520 | 639 | |
a1ae1090 VZ |
640 | wxHtmlCell *cell = m_Cells, |
641 | *line = m_Cells; | |
b6d93b26 | 642 | wxHtmlCell *nextCell; |
5526e819 VS |
643 | long xpos = 0, ypos = m_IndentTop; |
644 | int xdelta = 0, ybasicpos = 0, ydiff; | |
b6d93b26 | 645 | int s_width, nextWordWidth, s_indent; |
5526e819 | 646 | int ysizeup = 0, ysizedown = 0; |
5c1bfc5d | 647 | int MaxLineWidth = 0; |
ca16b7a9 VS |
648 | int curLineWidth = 0; |
649 | m_MaxTotalWidth = 0; | |
5c1bfc5d | 650 | |
5526e819 VS |
651 | |
652 | /* | |
7e941458 | 653 | |
5526e819 | 654 | WIDTH ADJUSTING : |
7e941458 | 655 | |
5526e819 VS |
656 | */ |
657 | ||
04dbb646 | 658 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 659 | { |
5526e819 VS |
660 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
661 | else m_Width = m_WidthFloat * w / 100; | |
662 | } | |
04dbb646 | 663 | else |
4f9297b0 | 664 | { |
5526e819 VS |
665 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
666 | else m_Width = m_WidthFloat; | |
667 | } | |
668 | ||
04dbb646 | 669 | if (m_Cells) |
4f9297b0 | 670 | { |
5526e819 VS |
671 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
672 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
673 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
674 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
675 | } |
676 | ||
677 | /* | |
678 | ||
679 | LAYOUTING : | |
7e941458 | 680 | |
5526e819 VS |
681 | */ |
682 | ||
683 | // adjust indentation: | |
684 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
685 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
686 | ||
5526e819 | 687 | // my own layouting: |
04dbb646 | 688 | while (cell != NULL) |
4f9297b0 | 689 | { |
04dbb646 | 690 | switch (m_AlignVer) |
0cb9cfb2 | 691 | { |
efba2b89 | 692 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
693 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
694 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 695 | } |
4f9297b0 | 696 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 697 | |
4f9297b0 VS |
698 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
699 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 700 | |
b6d93b26 | 701 | // layout nonbreakable run of cells: |
4f9297b0 VS |
702 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
703 | xpos += cell->GetWidth(); | |
ca16b7a9 VS |
704 | if (!cell->IsTerminalCell()) |
705 | { | |
706 | // Container cell indicates new line | |
707 | if (curLineWidth > m_MaxTotalWidth) | |
708 | m_MaxTotalWidth = curLineWidth; | |
709 | ||
710 | if (wxMax(cell->GetWidth(), cell->GetMaxTotalWidth()) > m_MaxTotalWidth) | |
711 | m_MaxTotalWidth = cell->GetMaxTotalWidth(); | |
712 | curLineWidth = 0; | |
713 | } | |
714 | else | |
715 | // Normal cell, add maximum cell width to line width | |
716 | curLineWidth += cell->GetMaxTotalWidth(); | |
717 | ||
4f9297b0 | 718 | cell = cell->GetNext(); |
b6d93b26 VS |
719 | |
720 | // compute length of the next word that would be added: | |
721 | nextWordWidth = 0; | |
722 | if (cell) | |
723 | { | |
724 | nextCell = cell; | |
725 | do | |
726 | { | |
727 | nextWordWidth += nextCell->GetWidth(); | |
728 | nextCell = nextCell->GetNext(); | |
729 | } while (nextCell && !nextCell->IsLinebreakAllowed()); | |
730 | } | |
731 | ||
5526e819 | 732 | // force new line if occured: |
b6d93b26 VS |
733 | if ((cell == NULL) || |
734 | (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed())) | |
0cb9cfb2 | 735 | { |
5c1bfc5d | 736 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
737 | if (ysizeup < 0) ysizeup = 0; |
738 | if (ysizedown < 0) ysizedown = 0; | |
739 | switch (m_AlignHor) { | |
04dbb646 VZ |
740 | case wxHTML_ALIGN_LEFT : |
741 | case wxHTML_ALIGN_JUSTIFY : | |
742 | xdelta = 0; | |
5c1bfc5d | 743 | break; |
04dbb646 VZ |
744 | case wxHTML_ALIGN_RIGHT : |
745 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 746 | break; |
04dbb646 VZ |
747 | case wxHTML_ALIGN_CENTER : |
748 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 749 | break; |
5526e819 VS |
750 | } |
751 | if (xdelta < 0) xdelta = 0; | |
752 | xdelta += s_indent; | |
753 | ||
754 | ypos += ysizeup; | |
04dbb646 | 755 | |
5c1bfc5d | 756 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
a1ae1090 | 757 | { |
04dbb646 | 758 | while (line != cell) |
0cb9cfb2 | 759 | { |
04dbb646 | 760 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
761 | ypos + line->GetPosY()); |
762 | line = line->GetNext(); | |
5c1bfc5d | 763 | } |
a1ae1090 VZ |
764 | } |
765 | else // align == justify | |
04dbb646 | 766 | { |
a1ae1090 VZ |
767 | // we have to distribute the extra horz space between the cells |
768 | // on this line | |
769 | ||
770 | // an added complication is that some cells have fixed size and | |
771 | // shouldn't get any increment (it so happens that these cells | |
772 | // also don't allow line break on them which provides with an | |
4dd9ae57 VZ |
773 | // easy way to test for this) -- and neither should the cells |
774 | // adjacent to them as this could result in a visible space | |
775 | // between two cells separated by, e.g. font change, cell which | |
776 | // is wrong | |
a1ae1090 | 777 | |
2d1d813e | 778 | int step = s_width - xpos; |
a1ae1090 | 779 | if ( step > 0 ) |
0cb9cfb2 | 780 | { |
a1ae1090 VZ |
781 | // first count the cells which will get extra space |
782 | int total = 0; | |
4dd9ae57 VZ |
783 | |
784 | const wxHtmlCell *c, | |
785 | *prev = NULL, | |
786 | *next = NULL; | |
787 | for ( c = line; c != cell; prev = c, c = next ) | |
a1ae1090 | 788 | { |
4dd9ae57 VZ |
789 | next = c->GetNext(); |
790 | if ( c->IsLinebreakAllowed() && | |
791 | (next == cell || next->IsLinebreakAllowed()) && | |
792 | (!prev || prev->IsLinebreakAllowed()) ) | |
793 | { | |
a1ae1090 | 794 | total++; |
4dd9ae57 | 795 | } |
a1ae1090 VZ |
796 | } |
797 | ||
798 | // and now extra space to those cells which merit it | |
799 | if ( total ) | |
800 | { | |
4dd9ae57 VZ |
801 | prev = |
802 | next = NULL; | |
22c956d8 | 803 | for ( int n = 0; line != cell; prev = line, line = line->GetNext() ) |
a1ae1090 VZ |
804 | { |
805 | line->SetPos(line->GetPosX() + s_indent + | |
806 | ((n * step) / total), | |
807 | line->GetPosY() + ypos); | |
808 | ||
4dd9ae57 VZ |
809 | next = line->GetNext(); |
810 | if ( line->IsLinebreakAllowed() && | |
811 | (next == cell || | |
812 | next->IsLinebreakAllowed()) && | |
813 | (!prev || prev->IsLinebreakAllowed()) ) | |
a1ae1090 VZ |
814 | { |
815 | // offset the next cell relative to this one | |
816 | // thus increasing our size | |
817 | n++; | |
818 | } | |
819 | } | |
820 | } | |
2d1d813e VS |
821 | else |
822 | { | |
823 | // this will cause the code to enter "else branch" below: | |
824 | step = 0; | |
825 | } | |
a1ae1090 | 826 | } |
2d1d813e VS |
827 | // else branch: |
828 | if ( step <= 0 ) // no extra space to distribute | |
a1ae1090 VZ |
829 | { |
830 | // just set the indent properly | |
831 | while (line != cell) | |
832 | { | |
833 | line->SetPos(line->GetPosX() + s_indent, | |
834 | line->GetPosY() + ypos); | |
835 | line = line->GetNext(); | |
836 | } | |
5c1bfc5d | 837 | } |
5526e819 VS |
838 | } |
839 | ||
840 | ypos += ysizedown; | |
49f6740f | 841 | xpos = 0; |
5526e819 VS |
842 | ysizeup = ysizedown = 0; |
843 | line = cell; | |
844 | } | |
845 | } | |
846 | ||
847 | // setup height & width, depending on container layout: | |
848 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
849 | ||
04dbb646 | 850 | if (m_Height < m_MinHeight) |
4f9297b0 | 851 | { |
04dbb646 | 852 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 853 | { |
5526e819 | 854 | int diff = m_MinHeight - m_Height; |
efba2b89 | 855 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 856 | cell = m_Cells; |
04dbb646 | 857 | while (cell) |
0cb9cfb2 | 858 | { |
4f9297b0 VS |
859 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
860 | cell = cell->GetNext(); | |
5526e819 VS |
861 | } |
862 | } | |
863 | m_Height = m_MinHeight; | |
864 | } | |
865 | ||
ca16b7a9 VS |
866 | if (curLineWidth > m_MaxTotalWidth) |
867 | m_MaxTotalWidth = curLineWidth; | |
868 | ||
869 | m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
5c1bfc5d VS |
870 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
871 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 872 | |
5660c520 | 873 | m_LastLayout = w; |
5526e819 VS |
874 | } |
875 | ||
f30e67db | 876 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
877 | wxHtmlCell *cell) const |
878 | { | |
f30e67db | 879 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 880 | if (!s) return; |
cd275246 | 881 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 882 | { |
f30e67db | 883 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
884 | } |
885 | } | |
886 | ||
f30e67db | 887 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
888 | wxHtmlCell *cell) const |
889 | { | |
f30e67db | 890 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 891 | if (!s) return; |
adf2eb2d | 892 | if (s->GetToCell() == cell) |
f30e67db | 893 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 894 | else if (s->GetFromCell() == cell) |
f30e67db | 895 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 896 | } |
5526e819 VS |
897 | |
898 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
899 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
900 | ||
36c4ff4d | 901 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 902 | wxHtmlRenderingInfo& info) |
5526e819 | 903 | { |
ace0fab4 VS |
904 | #if 0 // useful for debugging |
905 | dc.SetPen(*wxRED_PEN); | |
906 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
907 | #endif | |
94bc8b14 VS |
908 | // container visible, draw it: |
909 | if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) | |
4f9297b0 | 910 | { |
04dbb646 | 911 | if (m_UseBkColour) |
0cb9cfb2 | 912 | { |
5526e819 VS |
913 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
914 | ||
915 | int real_y1 = mMax(y + m_PosY, view_y1); | |
916 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
917 | ||
918 | dc.SetBrush(myb); | |
919 | dc.SetPen(*wxTRANSPARENT_PEN); | |
920 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
921 | } | |
922 | ||
04dbb646 | 923 | if (m_UseBorder) |
0cb9cfb2 | 924 | { |
5526e819 VS |
925 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
926 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
927 | ||
928 | dc.SetPen(mypen1); | |
929 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
5f265f87 | 930 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY); |
5526e819 VS |
931 | dc.SetPen(mypen2); |
932 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
5f265f87 | 933 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1); |
5526e819 VS |
934 | } |
935 | ||
d699f48b | 936 | if (m_Cells) |
bf7d7ee7 | 937 | { |
36c4ff4d | 938 | // draw container's contents: |
bf7d7ee7 | 939 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
36c4ff4d | 940 | { |
f30e67db | 941 | UpdateRenderingStatePre(info, cell); |
36c4ff4d VS |
942 | cell->Draw(dc, |
943 | x + m_PosX, y + m_PosY, view_y1, view_y2, | |
f30e67db VS |
944 | info); |
945 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 946 | } |
bf7d7ee7 | 947 | } |
5526e819 VS |
948 | } |
949 | // container invisible, just proceed font+color changing: | |
04dbb646 | 950 | else |
4f9297b0 | 951 | { |
f30e67db | 952 | DrawInvisible(dc, x, y, info); |
5526e819 | 953 | } |
5526e819 VS |
954 | } |
955 | ||
956 | ||
957 | ||
36c4ff4d | 958 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 959 | wxHtmlRenderingInfo& info) |
5526e819 | 960 | { |
d699f48b | 961 | if (m_Cells) |
bf7d7ee7 VS |
962 | { |
963 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 964 | { |
f30e67db VS |
965 | UpdateRenderingStatePre(info, cell); |
966 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
967 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 968 | } |
bf7d7ee7 | 969 | } |
5526e819 VS |
970 | } |
971 | ||
972 | ||
2b5f62a0 VZ |
973 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
974 | { | |
975 | if (m_UseBkColour) | |
976 | return m_BkColour; | |
977 | else | |
978 | return wxNullColour; | |
979 | } | |
980 | ||
981 | ||
5526e819 | 982 | |
846914d1 | 983 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 984 | { |
f6010d8f | 985 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 986 | |
f6010d8f VZ |
987 | // VZ: I don't know if we should pass absolute or relative coords to |
988 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
989 | // anyhow, it hardly matters right now but should still be clarified | |
990 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
991 | } |
992 | ||
993 | ||
994 | ||
995 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
996 | { | |
997 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 998 | else |
4f9297b0 VS |
999 | { |
1000 | m_LastCell->SetNext(f); | |
5526e819 | 1001 | m_LastCell = f; |
4f9297b0 | 1002 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 1003 | } |
4f9297b0 | 1004 | f->SetParent(this); |
5660c520 | 1005 | m_LastLayout = -1; |
5526e819 VS |
1006 | } |
1007 | ||
1008 | ||
1009 | ||
1010 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
1011 | { | |
04dbb646 | 1012 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 1013 | { |
0413cec5 | 1014 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 1015 | alg.MakeUpper(); |
0413cec5 | 1016 | if (alg == wxT("CENTER")) |
efba2b89 | 1017 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 1018 | else if (alg == wxT("LEFT")) |
efba2b89 | 1019 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
1020 | else if (alg == wxT("JUSTIFY")) |
1021 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 1022 | else if (alg == wxT("RIGHT")) |
efba2b89 | 1023 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 1024 | m_LastLayout = -1; |
5526e819 VS |
1025 | } |
1026 | } | |
1027 | ||
1028 | ||
1029 | ||
edbd0635 | 1030 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 1031 | { |
04dbb646 | 1032 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 1033 | { |
5526e819 | 1034 | int wdi; |
0413cec5 | 1035 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 1036 | |
04dbb646 | 1037 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 1038 | { |
66a77a74 | 1039 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 1040 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 1041 | } |
04dbb646 | 1042 | else |
0cb9cfb2 | 1043 | { |
66a77a74 | 1044 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 1045 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 1046 | } |
5660c520 | 1047 | m_LastLayout = -1; |
5526e819 VS |
1048 | } |
1049 | } | |
1050 | ||
1051 | ||
1052 | ||
1053 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
1054 | { | |
04dbb646 | 1055 | if (m_Cells) |
d699f48b | 1056 | { |
bf7d7ee7 VS |
1057 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
1058 | { | |
999836aa | 1059 | const wxHtmlCell *r = cell->Find(condition, param); |
bf7d7ee7 VS |
1060 | if (r) return r; |
1061 | } | |
1062 | } | |
1063 | return NULL; | |
5526e819 VS |
1064 | } |
1065 | ||
1066 | ||
36c4ff4d VS |
1067 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
1068 | unsigned flags) const | |
5526e819 | 1069 | { |
6d41981d | 1070 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 1071 | { |
adf2eb2d VS |
1072 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1073 | { | |
1074 | int cx = cell->GetPosX(), | |
1075 | cy = cell->GetPosY(); | |
1076 | ||
1077 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
1078 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
1079 | { | |
1080 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
1081 | } | |
1082 | } | |
adf2eb2d | 1083 | } |
6d41981d | 1084 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
1085 | { |
1086 | wxHtmlCell *c; | |
adf2eb2d | 1087 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
0cb9cfb2 | 1088 | { |
03693319 VS |
1089 | if ( cell->IsFormattingCell() ) |
1090 | continue; | |
1091 | int cellY = cell->GetPosY(); | |
1092 | if (!( y < cellY || (y < cellY + cell->GetHeight() && | |
1093 | x < cell->GetPosX() + cell->GetWidth()) )) | |
adf2eb2d | 1094 | continue; |
03693319 VS |
1095 | |
1096 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); | |
adf2eb2d | 1097 | if (c) return c; |
5526e819 VS |
1098 | } |
1099 | } | |
6d41981d | 1100 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 1101 | { |
e24529d7 | 1102 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
1103 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1104 | { | |
03693319 VS |
1105 | if ( cell->IsFormattingCell() ) |
1106 | continue; | |
1107 | int cellY = cell->GetPosY(); | |
1108 | if (!( cellY + cell->GetHeight() <= y || | |
1109 | (y >= cellY && x >= cell->GetPosX()) )) | |
adf2eb2d | 1110 | break; |
03693319 | 1111 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
e24529d7 VS |
1112 | if (c2) |
1113 | c = c2; | |
adf2eb2d | 1114 | } |
e24529d7 | 1115 | if (c) return c; |
adf2eb2d | 1116 | } |
6d41981d VZ |
1117 | |
1118 | return NULL; | |
f6010d8f VZ |
1119 | } |
1120 | ||
1121 | ||
1122 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) | |
1123 | { | |
1124 | wxHtmlCell *cell = FindCellByPos(x, y); | |
1125 | if ( cell ) | |
1126 | cell->OnMouseClick(parent, x, y, event); | |
5526e819 VS |
1127 | } |
1128 | ||
1129 | ||
1130 | ||
adf2eb2d VS |
1131 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1132 | { | |
e3774124 VS |
1133 | if ( m_Cells ) |
1134 | { | |
1135 | wxHtmlCell *c2; | |
1136 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1137 | { | |
1138 | c2 = c->GetFirstTerminal(); | |
1139 | if ( c2 ) | |
1140 | return c2; | |
1141 | } | |
1142 | } | |
1143 | return NULL; | |
adf2eb2d VS |
1144 | } |
1145 | ||
1146 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1147 | { | |
e3774124 | 1148 | if ( m_Cells ) |
adf2eb2d | 1149 | { |
e3774124 | 1150 | // most common case first: |
4ce19ed7 | 1151 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1152 | if ( c ) |
1153 | return c; | |
4ce19ed7 | 1154 | |
ace0fab4 | 1155 | wxHtmlCell *ctmp; |
4ce19ed7 VZ |
1156 | wxHtmlCell *c2 = NULL; |
1157 | for (c = m_Cells; c; c = c->GetNext()) | |
ace0fab4 VS |
1158 | { |
1159 | ctmp = c->GetLastTerminal(); | |
1160 | if ( ctmp ) | |
1161 | c2 = ctmp; | |
1162 | } | |
e3774124 | 1163 | return c2; |
adf2eb2d VS |
1164 | } |
1165 | else | |
1166 | return NULL; | |
1167 | } | |
79d6c018 VS |
1168 | |
1169 | ||
ace0fab4 VS |
1170 | static bool IsEmptyContainer(wxHtmlContainerCell *cell) |
1171 | { | |
1172 | for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() ) | |
1173 | { | |
1174 | if ( !c->IsTerminalCell() || !c->IsFormattingCell() ) | |
1175 | return false; | |
1176 | } | |
1177 | return true; | |
1178 | } | |
1179 | ||
1180 | void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom) | |
1181 | { | |
1182 | if ( top ) | |
1183 | SetIndent(0, wxHTML_INDENT_TOP); | |
1184 | if ( bottom ) | |
1185 | SetIndent(0, wxHTML_INDENT_BOTTOM); | |
1186 | ||
1187 | if ( m_Cells ) | |
1188 | { | |
1189 | wxHtmlCell *c; | |
1190 | wxHtmlContainerCell *cont; | |
1191 | if ( top ) | |
1192 | { | |
1193 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1194 | { | |
1195 | if ( c->IsTerminalCell() ) | |
1196 | { | |
1197 | if ( !c->IsFormattingCell() ) | |
1198 | break; | |
1199 | } | |
1200 | else | |
1201 | { | |
1202 | cont = (wxHtmlContainerCell*)c; | |
1203 | if ( IsEmptyContainer(cont) ) | |
1204 | { | |
1205 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); | |
1206 | } | |
1207 | else | |
1208 | { | |
1209 | cont->RemoveExtraSpacing(true, false); | |
1210 | break; | |
1211 | } | |
1212 | } | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | if ( bottom ) | |
1217 | { | |
1218 | wxArrayPtrVoid arr; | |
1219 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1220 | arr.Add((void*)c); | |
1221 | ||
1222 | for ( int i = arr.GetCount() - 1; i >= 0; i--) | |
1223 | { | |
1224 | c = (wxHtmlCell*)arr[i]; | |
1225 | if ( c->IsTerminalCell() ) | |
1226 | { | |
1227 | if ( !c->IsFormattingCell() ) | |
1228 | break; | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | cont = (wxHtmlContainerCell*)c; | |
1233 | if ( IsEmptyContainer(cont) ) | |
1234 | { | |
1235 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); } | |
1236 | else | |
1237 | { | |
1238 | cont->RemoveExtraSpacing(false, true); | |
1239 | break; | |
1240 | } | |
1241 | } | |
1242 | } | |
1243 | } | |
1244 | } | |
1245 | } | |
1246 | ||
1247 | ||
5526e819 VS |
1248 | |
1249 | ||
36c4ff4d | 1250 | // -------------------------------------------------------------------------- |
5526e819 | 1251 | // wxHtmlColourCell |
36c4ff4d | 1252 | // -------------------------------------------------------------------------- |
5526e819 | 1253 | |
4f44ea36 MB |
1254 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell) |
1255 | ||
36c4ff4d VS |
1256 | void wxHtmlColourCell::Draw(wxDC& dc, |
1257 | int x, int y, | |
1258 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1259 | wxHtmlRenderingInfo& info) |
5526e819 | 1260 | { |
f30e67db | 1261 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1262 | } |
1263 | ||
36c4ff4d VS |
1264 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1265 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1266 | wxHtmlRenderingInfo& info) |
5526e819 | 1267 | { |
f30e67db | 1268 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1269 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1270 | { |
1271 | state.SetFgColour(m_Colour); | |
1272 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1273 | dc.SetTextForeground(m_Colour); |
1274 | else | |
1275 | dc.SetTextForeground( | |
1276 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1277 | } |
04dbb646 | 1278 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1279 | { |
36c4ff4d VS |
1280 | state.SetBgColour(m_Colour); |
1281 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
b87dd6f5 | 1282 | { |
36c4ff4d | 1283 | dc.SetTextBackground(m_Colour); |
b87dd6f5 VS |
1284 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
1285 | } | |
bfc248a3 | 1286 | else |
b87dd6f5 VS |
1287 | { |
1288 | wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); | |
1289 | dc.SetTextBackground(c); | |
1290 | dc.SetBackground(wxBrush(c, wxSOLID)); | |
1291 | } | |
5526e819 | 1292 | } |
5526e819 VS |
1293 | } |
1294 | ||
1295 | ||
1296 | ||
1297 | ||
36c4ff4d | 1298 | // --------------------------------------------------------------------------- |
5526e819 | 1299 | // wxHtmlFontCell |
36c4ff4d | 1300 | // --------------------------------------------------------------------------- |
5526e819 | 1301 | |
4f44ea36 MB |
1302 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1303 | ||
36c4ff4d VS |
1304 | void wxHtmlFontCell::Draw(wxDC& dc, |
1305 | int WXUNUSED(x), int WXUNUSED(y), | |
1306 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1307 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1308 | { |
921d0fb1 | 1309 | dc.SetFont(m_Font); |
5526e819 VS |
1310 | } |
1311 | ||
36c4ff4d | 1312 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1313 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1314 | { |
921d0fb1 | 1315 | dc.SetFont(m_Font); |
5526e819 VS |
1316 | } |
1317 | ||
1318 | ||
1319 | ||
1320 | ||
1321 | ||
1322 | ||
1323 | ||
1324 | ||
36c4ff4d | 1325 | // --------------------------------------------------------------------------- |
5526e819 | 1326 | // wxHtmlWidgetCell |
36c4ff4d | 1327 | // --------------------------------------------------------------------------- |
5526e819 | 1328 | |
4f44ea36 MB |
1329 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1330 | ||
5526e819 VS |
1331 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1332 | { | |
1333 | int sx, sy; | |
1334 | m_Wnd = wnd; | |
4f9297b0 | 1335 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1336 | m_Width = sx, m_Height = sy; |
1337 | m_WidthFloat = w; | |
1338 | } | |
1339 | ||
1340 | ||
36c4ff4d VS |
1341 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1342 | int WXUNUSED(x), int WXUNUSED(y), | |
1343 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1344 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1345 | { |
1346 | int absx = 0, absy = 0, stx, sty; | |
1347 | wxHtmlCell *c = this; | |
1348 | ||
04dbb646 | 1349 | while (c) |
4f9297b0 VS |
1350 | { |
1351 | absx += c->GetPosX(); | |
1352 | absy += c->GetPosY(); | |
1353 | c = c->GetParent(); | |
5526e819 VS |
1354 | } |
1355 | ||
e421922f | 1356 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1357 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1358 | } |
1359 | ||
1360 | ||
1361 | ||
36c4ff4d VS |
1362 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1363 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1364 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1365 | { |
1366 | int absx = 0, absy = 0, stx, sty; | |
1367 | wxHtmlCell *c = this; | |
1368 | ||
04dbb646 | 1369 | while (c) |
4f9297b0 VS |
1370 | { |
1371 | absx += c->GetPosX(); | |
1372 | absy += c->GetPosY(); | |
1373 | c = c->GetParent(); | |
5526e819 | 1374 | } |
7e941458 | 1375 | |
e421922f | 1376 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1377 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1378 | } |
1379 | ||
1380 | ||
1381 | ||
1382 | void wxHtmlWidgetCell::Layout(int w) | |
1383 | { | |
04dbb646 | 1384 | if (m_WidthFloat != 0) |
4f9297b0 | 1385 | { |
5526e819 | 1386 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1387 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1388 | } |
1389 | ||
1390 | wxHtmlCell::Layout(w); | |
1391 | } | |
1392 | ||
e3774124 VS |
1393 | |
1394 | ||
1395 | // ---------------------------------------------------------------------------- | |
1396 | // wxHtmlTerminalCellsInterator | |
1397 | // ---------------------------------------------------------------------------- | |
1398 | ||
1399 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1400 | { | |
1401 | if ( !m_pos ) | |
1402 | return NULL; | |
1403 | ||
1404 | do | |
1405 | { | |
1406 | if ( m_pos == m_to ) | |
1407 | { | |
1408 | m_pos = NULL; | |
1409 | return NULL; | |
1410 | } | |
1411 | ||
1412 | if ( m_pos->GetNext() ) | |
1413 | m_pos = m_pos->GetNext(); | |
1414 | else | |
1415 | { | |
1416 | // we must go up the hierarchy until we reach container where this | |
1417 | // is not the last child, and then go down to first terminal cell: | |
1418 | while ( m_pos->GetNext() == NULL ) | |
1419 | { | |
1420 | m_pos = m_pos->GetParent(); | |
1421 | if ( !m_pos ) | |
1422 | return NULL; | |
1423 | } | |
1424 | m_pos = m_pos->GetNext(); | |
1425 | } | |
1426 | while ( m_pos->GetFirstChild() != NULL ) | |
1427 | m_pos = m_pos->GetFirstChild(); | |
1428 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1429 | |
e3774124 VS |
1430 | return m_pos; |
1431 | } | |
1432 | ||
77bae5e2 VS |
1433 | |
1434 | ||
1435 | ||
1436 | ||
1437 | ||
1438 | ||
1439 | //----------------------------------------------------------------------------- | |
1440 | // Cleanup | |
1441 | //----------------------------------------------------------------------------- | |
1442 | ||
1443 | class wxHtmlCellModule: public wxModule | |
1444 | { | |
1445 | DECLARE_DYNAMIC_CLASS(wxHtmlCellModule) | |
1446 | public: | |
1447 | wxHtmlCellModule() : wxModule() {} | |
1448 | bool OnInit() { return true; } | |
1449 | void OnExit() | |
1450 | { | |
1451 | wxDELETE(gs_cursorLink); | |
1452 | wxDELETE(gs_cursorText); | |
1453 | } | |
1454 | }; | |
1455 | ||
1456 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule, wxModule) | |
1457 | ||
5526e819 | 1458 | #endif |