]>
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 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
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; | |
846914d1 VS |
97 | m_CanLiveOnPagebreak = TRUE; |
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; |
db98870d VS |
142 | return TRUE; |
143 | } | |
0cb9cfb2 VZ |
144 | |
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); |
db98870d | 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) ? | |
286 | wxPoint(m_Width, -1) : selTo - GetAbsPos(); | |
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); |
5a1597e9 VS |
384 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); |
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; | |
4f9297b0 | 532 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
533 | m_AlignHor = wxHTML_ALIGN_LEFT; |
534 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 535 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 536 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
5526e819 VS |
537 | m_UseBkColour = FALSE; |
538 | m_UseBorder = FALSE; | |
5c1bfc5d | 539 | m_MinHeight = 0; |
efba2b89 | 540 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 541 | m_LastLayout = -1; |
5526e819 VS |
542 | } |
543 | ||
04dbb646 | 544 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 545 | { |
491c9920 VZ |
546 | wxHtmlCell *cell = m_Cells; |
547 | while ( cell ) | |
bf7d7ee7 | 548 | { |
491c9920 VZ |
549 | wxHtmlCell *cellNext = cell->GetNext(); |
550 | delete cell; | |
551 | cell = cellNext; | |
bf7d7ee7 | 552 | } |
721ab905 VS |
553 | } |
554 | ||
5526e819 VS |
555 | |
556 | ||
557 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
558 | { | |
efba2b89 VS |
559 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
560 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
561 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
562 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
563 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 564 | m_LastLayout = -1; |
5526e819 VS |
565 | } |
566 | ||
567 | ||
568 | ||
569 | int wxHtmlContainerCell::GetIndent(int ind) const | |
570 | { | |
efba2b89 VS |
571 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
572 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
573 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
574 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
575 | else return -1; /* BUG! Should not be called... */ |
576 | } | |
577 | ||
578 | ||
579 | ||
580 | ||
581 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
582 | { | |
583 | bool p = FALSE; | |
efba2b89 VS |
584 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
585 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
586 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
587 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
588 | if (p) return wxHTML_UNITS_PERCENT; | |
589 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
590 | } |
591 | ||
592 | ||
593 | ||
f2034f1b | 594 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const |
db98870d | 595 | { |
04dbb646 | 596 | if (!m_CanLiveOnPagebreak) |
f2034f1b | 597 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages); |
e52d6dbc | 598 | |
04dbb646 | 599 | else |
4f9297b0 | 600 | { |
e3774124 | 601 | wxHtmlCell *c = GetFirstChild(); |
db98870d | 602 | bool rt = FALSE; |
e52d6dbc | 603 | int pbrk = *pagebreak - m_PosY; |
db98870d | 604 | |
04dbb646 | 605 | while (c) |
0cb9cfb2 | 606 | { |
f2034f1b | 607 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages)) |
bf7d7ee7 | 608 | rt = TRUE; |
4f9297b0 | 609 | c = c->GetNext(); |
db98870d | 610 | } |
d699f48b | 611 | if (rt) |
bf7d7ee7 | 612 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
613 | return rt; |
614 | } | |
615 | } | |
616 | ||
617 | ||
618 | ||
5526e819 VS |
619 | void wxHtmlContainerCell::Layout(int w) |
620 | { | |
026d1fac VS |
621 | wxHtmlCell::Layout(w); |
622 | ||
623 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 624 | |
026d1fac VS |
625 | // VS: Any attempt to layout with negative or zero width leads to hell, |
626 | // but we can't ignore such attempts completely, since it sometimes | |
627 | // happen (e.g. when trying how small a table can be). The best thing we | |
628 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 629 | if (w < 1) |
4f9297b0 | 630 | { |
026d1fac VS |
631 | m_Width = 0; |
632 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
633 | cell->Layout(0); | |
2b5f62a0 VZ |
634 | // this does two things: it recursively calls this code on all |
635 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 636 | return; |
04dbb646 | 637 | } |
5660c520 | 638 | |
5526e819 | 639 | wxHtmlCell *cell = m_Cells, *line = m_Cells; |
b6d93b26 | 640 | wxHtmlCell *nextCell; |
5526e819 VS |
641 | long xpos = 0, ypos = m_IndentTop; |
642 | int xdelta = 0, ybasicpos = 0, ydiff; | |
b6d93b26 | 643 | int s_width, nextWordWidth, s_indent; |
5526e819 | 644 | int ysizeup = 0, ysizedown = 0; |
5c1bfc5d VS |
645 | int MaxLineWidth = 0; |
646 | int xcnt = 0; | |
647 | ||
5526e819 VS |
648 | |
649 | /* | |
7e941458 | 650 | |
5526e819 | 651 | WIDTH ADJUSTING : |
7e941458 | 652 | |
5526e819 VS |
653 | */ |
654 | ||
04dbb646 | 655 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 656 | { |
5526e819 VS |
657 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
658 | else m_Width = m_WidthFloat * w / 100; | |
659 | } | |
04dbb646 | 660 | else |
4f9297b0 | 661 | { |
5526e819 VS |
662 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
663 | else m_Width = m_WidthFloat; | |
664 | } | |
665 | ||
04dbb646 | 666 | if (m_Cells) |
4f9297b0 | 667 | { |
5526e819 VS |
668 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
669 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
670 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
671 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
672 | } |
673 | ||
674 | /* | |
675 | ||
676 | LAYOUTING : | |
7e941458 | 677 | |
5526e819 VS |
678 | */ |
679 | ||
680 | // adjust indentation: | |
681 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
682 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
683 | ||
5526e819 | 684 | // my own layouting: |
04dbb646 | 685 | while (cell != NULL) |
4f9297b0 | 686 | { |
04dbb646 | 687 | switch (m_AlignVer) |
0cb9cfb2 | 688 | { |
efba2b89 | 689 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
690 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
691 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 692 | } |
4f9297b0 | 693 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 694 | |
4f9297b0 VS |
695 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
696 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 697 | |
b6d93b26 | 698 | // layout nonbreakable run of cells: |
4f9297b0 VS |
699 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
700 | xpos += cell->GetWidth(); | |
701 | cell = cell->GetNext(); | |
5c1bfc5d | 702 | xcnt++; |
b6d93b26 VS |
703 | |
704 | // compute length of the next word that would be added: | |
705 | nextWordWidth = 0; | |
706 | if (cell) | |
707 | { | |
708 | nextCell = cell; | |
709 | do | |
710 | { | |
711 | nextWordWidth += nextCell->GetWidth(); | |
712 | nextCell = nextCell->GetNext(); | |
713 | } while (nextCell && !nextCell->IsLinebreakAllowed()); | |
714 | } | |
715 | ||
5526e819 | 716 | // force new line if occured: |
b6d93b26 VS |
717 | if ((cell == NULL) || |
718 | (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed())) | |
0cb9cfb2 | 719 | { |
5c1bfc5d | 720 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
721 | if (ysizeup < 0) ysizeup = 0; |
722 | if (ysizedown < 0) ysizedown = 0; | |
723 | switch (m_AlignHor) { | |
04dbb646 VZ |
724 | case wxHTML_ALIGN_LEFT : |
725 | case wxHTML_ALIGN_JUSTIFY : | |
726 | xdelta = 0; | |
5c1bfc5d | 727 | break; |
04dbb646 VZ |
728 | case wxHTML_ALIGN_RIGHT : |
729 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 730 | break; |
04dbb646 VZ |
731 | case wxHTML_ALIGN_CENTER : |
732 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 733 | break; |
5526e819 VS |
734 | } |
735 | if (xdelta < 0) xdelta = 0; | |
736 | xdelta += s_indent; | |
737 | ||
738 | ypos += ysizeup; | |
04dbb646 | 739 | |
5c1bfc5d | 740 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
04dbb646 | 741 | while (line != cell) |
0cb9cfb2 | 742 | { |
04dbb646 | 743 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
744 | ypos + line->GetPosY()); |
745 | line = line->GetNext(); | |
5c1bfc5d VS |
746 | } |
747 | else | |
04dbb646 | 748 | { |
5c1bfc5d VS |
749 | int counter = 0; |
750 | int step = (s_width - xpos); | |
751 | if (step < 0) step = 0; | |
c1e5e881 | 752 | xcnt--; |
04dbb646 | 753 | if (xcnt > 0) while (line != cell) |
0cb9cfb2 | 754 | { |
4f9297b0 | 755 | line->SetPos(line->GetPosX() + s_indent + |
5c1bfc5d | 756 | (counter++ * step / xcnt), |
4f9297b0 VS |
757 | ypos + line->GetPosY()); |
758 | line = line->GetNext(); | |
5c1bfc5d | 759 | } |
5526e819 VS |
760 | } |
761 | ||
762 | ypos += ysizedown; | |
5c1bfc5d | 763 | xpos = xcnt = 0; |
5526e819 VS |
764 | ysizeup = ysizedown = 0; |
765 | line = cell; | |
766 | } | |
767 | } | |
768 | ||
769 | // setup height & width, depending on container layout: | |
770 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
771 | ||
04dbb646 | 772 | if (m_Height < m_MinHeight) |
4f9297b0 | 773 | { |
04dbb646 | 774 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 775 | { |
5526e819 | 776 | int diff = m_MinHeight - m_Height; |
efba2b89 | 777 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 778 | cell = m_Cells; |
04dbb646 | 779 | while (cell) |
0cb9cfb2 | 780 | { |
4f9297b0 VS |
781 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
782 | cell = cell->GetNext(); | |
5526e819 VS |
783 | } |
784 | } | |
785 | m_Height = m_MinHeight; | |
786 | } | |
787 | ||
5c1bfc5d VS |
788 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
789 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 790 | |
5660c520 | 791 | m_LastLayout = w; |
5526e819 VS |
792 | } |
793 | ||
f30e67db | 794 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
795 | wxHtmlCell *cell) const |
796 | { | |
f30e67db | 797 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 798 | if (!s) return; |
cd275246 | 799 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 800 | { |
f30e67db | 801 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
802 | } |
803 | } | |
804 | ||
f30e67db | 805 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
806 | wxHtmlCell *cell) const |
807 | { | |
f30e67db | 808 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 809 | if (!s) return; |
adf2eb2d | 810 | if (s->GetToCell() == cell) |
f30e67db | 811 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 812 | else if (s->GetFromCell() == cell) |
f30e67db | 813 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 814 | } |
5526e819 VS |
815 | |
816 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
817 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
818 | ||
36c4ff4d | 819 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 820 | wxHtmlRenderingInfo& info) |
5526e819 | 821 | { |
ace0fab4 VS |
822 | #if 0 // useful for debugging |
823 | dc.SetPen(*wxRED_PEN); | |
824 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
825 | #endif | |
94bc8b14 VS |
826 | // container visible, draw it: |
827 | if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) | |
4f9297b0 | 828 | { |
04dbb646 | 829 | if (m_UseBkColour) |
0cb9cfb2 | 830 | { |
5526e819 VS |
831 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
832 | ||
833 | int real_y1 = mMax(y + m_PosY, view_y1); | |
834 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
835 | ||
836 | dc.SetBrush(myb); | |
837 | dc.SetPen(*wxTRANSPARENT_PEN); | |
838 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
839 | } | |
840 | ||
04dbb646 | 841 | if (m_UseBorder) |
0cb9cfb2 | 842 | { |
5526e819 VS |
843 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
844 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
845 | ||
846 | dc.SetPen(mypen1); | |
847 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
5f265f87 | 848 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY); |
5526e819 VS |
849 | dc.SetPen(mypen2); |
850 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
5f265f87 | 851 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1); |
5526e819 VS |
852 | } |
853 | ||
d699f48b | 854 | if (m_Cells) |
bf7d7ee7 | 855 | { |
36c4ff4d | 856 | // draw container's contents: |
bf7d7ee7 | 857 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
36c4ff4d | 858 | { |
f30e67db | 859 | UpdateRenderingStatePre(info, cell); |
36c4ff4d VS |
860 | cell->Draw(dc, |
861 | x + m_PosX, y + m_PosY, view_y1, view_y2, | |
f30e67db VS |
862 | info); |
863 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 864 | } |
bf7d7ee7 | 865 | } |
5526e819 VS |
866 | } |
867 | // container invisible, just proceed font+color changing: | |
04dbb646 | 868 | else |
4f9297b0 | 869 | { |
f30e67db | 870 | DrawInvisible(dc, x, y, info); |
5526e819 | 871 | } |
5526e819 VS |
872 | } |
873 | ||
874 | ||
875 | ||
36c4ff4d | 876 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 877 | wxHtmlRenderingInfo& info) |
5526e819 | 878 | { |
d699f48b | 879 | if (m_Cells) |
bf7d7ee7 VS |
880 | { |
881 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 882 | { |
f30e67db VS |
883 | UpdateRenderingStatePre(info, cell); |
884 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
885 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 886 | } |
bf7d7ee7 | 887 | } |
5526e819 VS |
888 | } |
889 | ||
890 | ||
2b5f62a0 VZ |
891 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
892 | { | |
893 | if (m_UseBkColour) | |
894 | return m_BkColour; | |
895 | else | |
896 | return wxNullColour; | |
897 | } | |
898 | ||
899 | ||
5526e819 | 900 | |
846914d1 | 901 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 902 | { |
f6010d8f | 903 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 904 | |
f6010d8f VZ |
905 | // VZ: I don't know if we should pass absolute or relative coords to |
906 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
907 | // anyhow, it hardly matters right now but should still be clarified | |
908 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
909 | } |
910 | ||
911 | ||
912 | ||
913 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
914 | { | |
915 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 916 | else |
4f9297b0 VS |
917 | { |
918 | m_LastCell->SetNext(f); | |
5526e819 | 919 | m_LastCell = f; |
4f9297b0 | 920 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 921 | } |
4f9297b0 | 922 | f->SetParent(this); |
5660c520 | 923 | m_LastLayout = -1; |
5526e819 VS |
924 | } |
925 | ||
926 | ||
927 | ||
928 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
929 | { | |
04dbb646 | 930 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 931 | { |
0413cec5 | 932 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 933 | alg.MakeUpper(); |
0413cec5 | 934 | if (alg == wxT("CENTER")) |
efba2b89 | 935 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 936 | else if (alg == wxT("LEFT")) |
efba2b89 | 937 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
938 | else if (alg == wxT("JUSTIFY")) |
939 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 940 | else if (alg == wxT("RIGHT")) |
efba2b89 | 941 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 942 | m_LastLayout = -1; |
5526e819 VS |
943 | } |
944 | } | |
945 | ||
946 | ||
947 | ||
edbd0635 | 948 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 949 | { |
04dbb646 | 950 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 951 | { |
5526e819 | 952 | int wdi; |
0413cec5 | 953 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 954 | |
04dbb646 | 955 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 956 | { |
66a77a74 | 957 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 958 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 959 | } |
04dbb646 | 960 | else |
0cb9cfb2 | 961 | { |
66a77a74 | 962 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 963 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 964 | } |
5660c520 | 965 | m_LastLayout = -1; |
5526e819 VS |
966 | } |
967 | } | |
968 | ||
969 | ||
970 | ||
971 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
972 | { | |
04dbb646 | 973 | if (m_Cells) |
d699f48b | 974 | { |
bf7d7ee7 VS |
975 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
976 | { | |
999836aa | 977 | const wxHtmlCell *r = cell->Find(condition, param); |
bf7d7ee7 VS |
978 | if (r) return r; |
979 | } | |
980 | } | |
981 | return NULL; | |
5526e819 VS |
982 | } |
983 | ||
984 | ||
36c4ff4d VS |
985 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
986 | unsigned flags) const | |
5526e819 | 987 | { |
6d41981d | 988 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 989 | { |
adf2eb2d VS |
990 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
991 | { | |
992 | int cx = cell->GetPosX(), | |
993 | cy = cell->GetPosY(); | |
994 | ||
995 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
996 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
997 | { | |
998 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
999 | } | |
1000 | } | |
adf2eb2d | 1001 | } |
6d41981d | 1002 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
1003 | { |
1004 | wxHtmlCell *c; | |
adf2eb2d | 1005 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
0cb9cfb2 | 1006 | { |
03693319 VS |
1007 | if ( cell->IsFormattingCell() ) |
1008 | continue; | |
1009 | int cellY = cell->GetPosY(); | |
1010 | if (!( y < cellY || (y < cellY + cell->GetHeight() && | |
1011 | x < cell->GetPosX() + cell->GetWidth()) )) | |
adf2eb2d | 1012 | continue; |
03693319 VS |
1013 | |
1014 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); | |
adf2eb2d | 1015 | if (c) return c; |
5526e819 VS |
1016 | } |
1017 | } | |
6d41981d | 1018 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 1019 | { |
e24529d7 | 1020 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
1021 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
1022 | { | |
03693319 VS |
1023 | if ( cell->IsFormattingCell() ) |
1024 | continue; | |
1025 | int cellY = cell->GetPosY(); | |
1026 | if (!( cellY + cell->GetHeight() <= y || | |
1027 | (y >= cellY && x >= cell->GetPosX()) )) | |
adf2eb2d | 1028 | break; |
03693319 | 1029 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags); |
e24529d7 VS |
1030 | if (c2) |
1031 | c = c2; | |
adf2eb2d | 1032 | } |
e24529d7 | 1033 | if (c) return c; |
adf2eb2d | 1034 | } |
6d41981d VZ |
1035 | |
1036 | return NULL; | |
f6010d8f VZ |
1037 | } |
1038 | ||
1039 | ||
1040 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) | |
1041 | { | |
1042 | wxHtmlCell *cell = FindCellByPos(x, y); | |
1043 | if ( cell ) | |
1044 | cell->OnMouseClick(parent, x, y, event); | |
5526e819 VS |
1045 | } |
1046 | ||
1047 | ||
1048 | ||
adf2eb2d VS |
1049 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1050 | { | |
e3774124 VS |
1051 | if ( m_Cells ) |
1052 | { | |
1053 | wxHtmlCell *c2; | |
1054 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1055 | { | |
1056 | c2 = c->GetFirstTerminal(); | |
1057 | if ( c2 ) | |
1058 | return c2; | |
1059 | } | |
1060 | } | |
1061 | return NULL; | |
adf2eb2d VS |
1062 | } |
1063 | ||
1064 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1065 | { | |
e3774124 | 1066 | if ( m_Cells ) |
adf2eb2d | 1067 | { |
e3774124 | 1068 | // most common case first: |
4ce19ed7 | 1069 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1070 | if ( c ) |
1071 | return c; | |
4ce19ed7 | 1072 | |
ace0fab4 | 1073 | wxHtmlCell *ctmp; |
4ce19ed7 VZ |
1074 | wxHtmlCell *c2 = NULL; |
1075 | for (c = m_Cells; c; c = c->GetNext()) | |
ace0fab4 VS |
1076 | { |
1077 | ctmp = c->GetLastTerminal(); | |
1078 | if ( ctmp ) | |
1079 | c2 = ctmp; | |
1080 | } | |
e3774124 | 1081 | return c2; |
adf2eb2d VS |
1082 | } |
1083 | else | |
1084 | return NULL; | |
1085 | } | |
79d6c018 VS |
1086 | |
1087 | ||
ace0fab4 VS |
1088 | static bool IsEmptyContainer(wxHtmlContainerCell *cell) |
1089 | { | |
1090 | for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() ) | |
1091 | { | |
1092 | if ( !c->IsTerminalCell() || !c->IsFormattingCell() ) | |
1093 | return false; | |
1094 | } | |
1095 | return true; | |
1096 | } | |
1097 | ||
1098 | void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom) | |
1099 | { | |
1100 | if ( top ) | |
1101 | SetIndent(0, wxHTML_INDENT_TOP); | |
1102 | if ( bottom ) | |
1103 | SetIndent(0, wxHTML_INDENT_BOTTOM); | |
1104 | ||
1105 | if ( m_Cells ) | |
1106 | { | |
1107 | wxHtmlCell *c; | |
1108 | wxHtmlContainerCell *cont; | |
1109 | if ( top ) | |
1110 | { | |
1111 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1112 | { | |
1113 | if ( c->IsTerminalCell() ) | |
1114 | { | |
1115 | if ( !c->IsFormattingCell() ) | |
1116 | break; | |
1117 | } | |
1118 | else | |
1119 | { | |
1120 | cont = (wxHtmlContainerCell*)c; | |
1121 | if ( IsEmptyContainer(cont) ) | |
1122 | { | |
1123 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); | |
1124 | } | |
1125 | else | |
1126 | { | |
1127 | cont->RemoveExtraSpacing(true, false); | |
1128 | break; | |
1129 | } | |
1130 | } | |
1131 | } | |
1132 | } | |
1133 | ||
1134 | if ( bottom ) | |
1135 | { | |
1136 | wxArrayPtrVoid arr; | |
1137 | for ( c = m_Cells; c; c = c->GetNext() ) | |
1138 | arr.Add((void*)c); | |
1139 | ||
1140 | for ( int i = arr.GetCount() - 1; i >= 0; i--) | |
1141 | { | |
1142 | c = (wxHtmlCell*)arr[i]; | |
1143 | if ( c->IsTerminalCell() ) | |
1144 | { | |
1145 | if ( !c->IsFormattingCell() ) | |
1146 | break; | |
1147 | } | |
1148 | else | |
1149 | { | |
1150 | cont = (wxHtmlContainerCell*)c; | |
1151 | if ( IsEmptyContainer(cont) ) | |
1152 | { | |
1153 | cont->SetIndent(0, wxHTML_INDENT_VERTICAL); } | |
1154 | else | |
1155 | { | |
1156 | cont->RemoveExtraSpacing(false, true); | |
1157 | break; | |
1158 | } | |
1159 | } | |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | ||
5526e819 VS |
1166 | |
1167 | ||
36c4ff4d | 1168 | // -------------------------------------------------------------------------- |
5526e819 | 1169 | // wxHtmlColourCell |
36c4ff4d | 1170 | // -------------------------------------------------------------------------- |
5526e819 | 1171 | |
4f44ea36 MB |
1172 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell) |
1173 | ||
36c4ff4d VS |
1174 | void wxHtmlColourCell::Draw(wxDC& dc, |
1175 | int x, int y, | |
1176 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1177 | wxHtmlRenderingInfo& info) |
5526e819 | 1178 | { |
f30e67db | 1179 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1180 | } |
1181 | ||
36c4ff4d VS |
1182 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1183 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1184 | wxHtmlRenderingInfo& info) |
5526e819 | 1185 | { |
f30e67db | 1186 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1187 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1188 | { |
1189 | state.SetFgColour(m_Colour); | |
1190 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1191 | dc.SetTextForeground(m_Colour); |
1192 | else | |
1193 | dc.SetTextForeground( | |
1194 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1195 | } |
04dbb646 | 1196 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1197 | { |
36c4ff4d VS |
1198 | state.SetBgColour(m_Colour); |
1199 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
b87dd6f5 | 1200 | { |
36c4ff4d | 1201 | dc.SetTextBackground(m_Colour); |
b87dd6f5 VS |
1202 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
1203 | } | |
bfc248a3 | 1204 | else |
b87dd6f5 VS |
1205 | { |
1206 | wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); | |
1207 | dc.SetTextBackground(c); | |
1208 | dc.SetBackground(wxBrush(c, wxSOLID)); | |
1209 | } | |
5526e819 | 1210 | } |
5526e819 VS |
1211 | } |
1212 | ||
1213 | ||
1214 | ||
1215 | ||
36c4ff4d | 1216 | // --------------------------------------------------------------------------- |
5526e819 | 1217 | // wxHtmlFontCell |
36c4ff4d | 1218 | // --------------------------------------------------------------------------- |
5526e819 | 1219 | |
4f44ea36 MB |
1220 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell) |
1221 | ||
36c4ff4d VS |
1222 | void wxHtmlFontCell::Draw(wxDC& dc, |
1223 | int WXUNUSED(x), int WXUNUSED(y), | |
1224 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1225 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1226 | { |
921d0fb1 | 1227 | dc.SetFont(m_Font); |
5526e819 VS |
1228 | } |
1229 | ||
36c4ff4d | 1230 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1231 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1232 | { |
921d0fb1 | 1233 | dc.SetFont(m_Font); |
5526e819 VS |
1234 | } |
1235 | ||
1236 | ||
1237 | ||
1238 | ||
1239 | ||
1240 | ||
1241 | ||
1242 | ||
36c4ff4d | 1243 | // --------------------------------------------------------------------------- |
5526e819 | 1244 | // wxHtmlWidgetCell |
36c4ff4d | 1245 | // --------------------------------------------------------------------------- |
5526e819 | 1246 | |
4f44ea36 MB |
1247 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell) |
1248 | ||
5526e819 VS |
1249 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) |
1250 | { | |
1251 | int sx, sy; | |
1252 | m_Wnd = wnd; | |
4f9297b0 | 1253 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1254 | m_Width = sx, m_Height = sy; |
1255 | m_WidthFloat = w; | |
1256 | } | |
1257 | ||
1258 | ||
36c4ff4d VS |
1259 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1260 | int WXUNUSED(x), int WXUNUSED(y), | |
1261 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1262 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1263 | { |
1264 | int absx = 0, absy = 0, stx, sty; | |
1265 | wxHtmlCell *c = this; | |
1266 | ||
04dbb646 | 1267 | while (c) |
4f9297b0 VS |
1268 | { |
1269 | absx += c->GetPosX(); | |
1270 | absy += c->GetPosY(); | |
1271 | c = c->GetParent(); | |
5526e819 VS |
1272 | } |
1273 | ||
e421922f | 1274 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1275 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1276 | } |
1277 | ||
1278 | ||
1279 | ||
36c4ff4d VS |
1280 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1281 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1282 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1283 | { |
1284 | int absx = 0, absy = 0, stx, sty; | |
1285 | wxHtmlCell *c = this; | |
1286 | ||
04dbb646 | 1287 | while (c) |
4f9297b0 VS |
1288 | { |
1289 | absx += c->GetPosX(); | |
1290 | absy += c->GetPosY(); | |
1291 | c = c->GetParent(); | |
5526e819 | 1292 | } |
7e941458 | 1293 | |
e421922f | 1294 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1295 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1296 | } |
1297 | ||
1298 | ||
1299 | ||
1300 | void wxHtmlWidgetCell::Layout(int w) | |
1301 | { | |
04dbb646 | 1302 | if (m_WidthFloat != 0) |
4f9297b0 | 1303 | { |
5526e819 | 1304 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1305 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1306 | } |
1307 | ||
1308 | wxHtmlCell::Layout(w); | |
1309 | } | |
1310 | ||
e3774124 VS |
1311 | |
1312 | ||
1313 | // ---------------------------------------------------------------------------- | |
1314 | // wxHtmlTerminalCellsInterator | |
1315 | // ---------------------------------------------------------------------------- | |
1316 | ||
1317 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1318 | { | |
1319 | if ( !m_pos ) | |
1320 | return NULL; | |
1321 | ||
1322 | do | |
1323 | { | |
1324 | if ( m_pos == m_to ) | |
1325 | { | |
1326 | m_pos = NULL; | |
1327 | return NULL; | |
1328 | } | |
1329 | ||
1330 | if ( m_pos->GetNext() ) | |
1331 | m_pos = m_pos->GetNext(); | |
1332 | else | |
1333 | { | |
1334 | // we must go up the hierarchy until we reach container where this | |
1335 | // is not the last child, and then go down to first terminal cell: | |
1336 | while ( m_pos->GetNext() == NULL ) | |
1337 | { | |
1338 | m_pos = m_pos->GetParent(); | |
1339 | if ( !m_pos ) | |
1340 | return NULL; | |
1341 | } | |
1342 | m_pos = m_pos->GetNext(); | |
1343 | } | |
1344 | while ( m_pos->GetFirstChild() != NULL ) | |
1345 | m_pos = m_pos->GetFirstChild(); | |
1346 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1347 | |
e3774124 VS |
1348 | return m_pos; |
1349 | } | |
1350 | ||
77bae5e2 VS |
1351 | |
1352 | ||
1353 | ||
1354 | ||
1355 | ||
1356 | ||
1357 | //----------------------------------------------------------------------------- | |
1358 | // Cleanup | |
1359 | //----------------------------------------------------------------------------- | |
1360 | ||
1361 | class wxHtmlCellModule: public wxModule | |
1362 | { | |
1363 | DECLARE_DYNAMIC_CLASS(wxHtmlCellModule) | |
1364 | public: | |
1365 | wxHtmlCellModule() : wxModule() {} | |
1366 | bool OnInit() { return true; } | |
1367 | void OnExit() | |
1368 | { | |
1369 | wxDELETE(gs_cursorLink); | |
1370 | wxDELETE(gs_cursorText); | |
1371 | } | |
1372 | }; | |
1373 | ||
1374 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule, wxModule) | |
1375 | ||
5526e819 | 1376 | #endif |