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