]>
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)); | |
36c4ff4d | 352 | } |
5a1597e9 | 353 | else |
36c4ff4d VS |
354 | { |
355 | dc.SetBackgroundMode(wxTRANSPARENT); | |
f30e67db VS |
356 | dc.SetTextForeground(fg); |
357 | dc.SetTextBackground(bg); | |
36c4ff4d | 358 | } |
5a1597e9 | 359 | } |
36c4ff4d | 360 | |
5a1597e9 VS |
361 | |
362 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
363 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 364 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
365 | { |
366 | #if 0 // useful for debugging | |
367 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
368 | #endif | |
369 | ||
f30e67db | 370 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
371 | { |
372 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
373 | wxHtmlSelection *s = info.GetSelection(); |
374 | wxString txt; | |
375 | int w, h; | |
376 | int ofs = 0; | |
86ff9b45 VZ |
377 | |
378 | wxPoint priv = (this == s->GetFromCell()) ? | |
f30e67db | 379 | s->GetFromPrivPos() : s->GetToPrivPos(); |
1338c59a VS |
380 | |
381 | // NB: this is quite a hack: in order to compute selection boundaries | |
382 | // (in word's characters) we must know current font, which is only | |
383 | // possible inside rendering code. Therefore we update the | |
384 | // information here and store it in wxHtmlSelection so that | |
385 | // ConvertToText can use it later: | |
386 | if ( priv == wxDefaultPosition ) | |
387 | { | |
388 | SetSelectionPrivPos(dc, s); | |
86ff9b45 | 389 | priv = (this == s->GetFromCell()) ? |
1338c59a VS |
390 | s->GetFromPrivPos() : s->GetToPrivPos(); |
391 | } | |
86ff9b45 | 392 | |
f30e67db VS |
393 | int part1 = priv.x; |
394 | int part2 = priv.y; | |
395 | ||
396 | if ( part1 > 0 ) | |
5a1597e9 | 397 | { |
f30e67db VS |
398 | txt = m_Word.Mid(0, part1); |
399 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
400 | dc.GetTextExtent(txt, &w, &h); | |
401 | ofs += w; | |
5a1597e9 | 402 | } |
86ff9b45 | 403 | |
f30e67db | 404 | SwitchSelState(dc, info, true); |
86ff9b45 | 405 | |
f30e67db VS |
406 | txt = m_Word.Mid(part1, part2-part1); |
407 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
408 | ||
70bae016 | 409 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 410 | { |
f30e67db VS |
411 | dc.GetTextExtent(txt, &w, &h); |
412 | ofs += w; | |
413 | SwitchSelState(dc, info, false); | |
414 | txt = m_Word.Mid(part2); | |
415 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 VS |
416 | } |
417 | } | |
418 | else | |
419 | { | |
420 | // Not changing selection state, draw the word in single mode: | |
421 | ||
f30e67db | 422 | if ( info.GetState().GetSelectionState() != wxHTML_SEL_OUT && |
5a1597e9 VS |
423 | dc.GetBackgroundMode() != wxSOLID ) |
424 | { | |
f30e67db | 425 | SwitchSelState(dc, info, true); |
5a1597e9 | 426 | } |
f30e67db | 427 | else if ( info.GetState().GetSelectionState() == wxHTML_SEL_OUT && |
5a1597e9 VS |
428 | dc.GetBackgroundMode() == wxSOLID ) |
429 | { | |
f30e67db | 430 | SwitchSelState(dc, info, false); |
5a1597e9 VS |
431 | } |
432 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
433 | } | |
5526e819 | 434 | } |
86ff9b45 | 435 | |
e3774124 | 436 | |
f30e67db | 437 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 438 | { |
f30e67db VS |
439 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
440 | { | |
86ff9b45 VZ |
441 | wxPoint priv = this == s->GetFromCell() ? s->GetFromPrivPos() |
442 | : s->GetToPrivPos(); | |
443 | ||
444 | // VZ: we may be called before we had a chance to re-render ourselves | |
445 | // and in this case GetFrom/ToPrivPos() is not set yet -- assume | |
446 | // that this only happens in case of a double/triple click (which | |
447 | // seems to be the case now) and so it makes sense to select the | |
448 | // entire contents of the cell in this case | |
449 | // | |
450 | // TODO: but this really needs to be fixed in some better way later... | |
451 | if ( priv != wxDefaultPosition ) | |
452 | { | |
453 | int part1 = priv.x; | |
454 | int part2 = priv.y; | |
455 | return m_Word.Mid(part1, part2-part1); | |
456 | } | |
457 | //else: return the whole word below | |
f30e67db | 458 | } |
86ff9b45 VZ |
459 | |
460 | return m_Word; | |
e3774124 | 461 | } |
5526e819 | 462 | |
77bae5e2 VS |
463 | wxCursor wxHtmlWordCell::GetCursor() const |
464 | { | |
465 | if ( !GetLink() ) | |
466 | { | |
467 | if ( !gs_cursorText ) | |
468 | gs_cursorText = new wxCursor(wxCURSOR_IBEAM); | |
469 | return *gs_cursorText; | |
470 | } | |
471 | else | |
472 | return wxHtmlCell::GetCursor(); | |
473 | } | |
474 | ||
5526e819 | 475 | |
5526e819 VS |
476 | //----------------------------------------------------------------------------- |
477 | // wxHtmlContainerCell | |
478 | //----------------------------------------------------------------------------- | |
479 | ||
480 | ||
481 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
482 | { | |
483 | m_Cells = m_LastCell = NULL; | |
484 | m_Parent = parent; | |
4f9297b0 | 485 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
486 | m_AlignHor = wxHTML_ALIGN_LEFT; |
487 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 488 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 489 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
5526e819 VS |
490 | m_UseBkColour = FALSE; |
491 | m_UseBorder = FALSE; | |
5c1bfc5d | 492 | m_MinHeight = 0; |
efba2b89 | 493 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 494 | m_LastLayout = -1; |
5526e819 VS |
495 | } |
496 | ||
04dbb646 | 497 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 498 | { |
491c9920 VZ |
499 | wxHtmlCell *cell = m_Cells; |
500 | while ( cell ) | |
bf7d7ee7 | 501 | { |
491c9920 VZ |
502 | wxHtmlCell *cellNext = cell->GetNext(); |
503 | delete cell; | |
504 | cell = cellNext; | |
bf7d7ee7 | 505 | } |
721ab905 VS |
506 | } |
507 | ||
5526e819 VS |
508 | |
509 | ||
510 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
511 | { | |
efba2b89 VS |
512 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
513 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
514 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
515 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
516 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 517 | m_LastLayout = -1; |
5526e819 VS |
518 | } |
519 | ||
520 | ||
521 | ||
522 | int wxHtmlContainerCell::GetIndent(int ind) const | |
523 | { | |
efba2b89 VS |
524 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
525 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
526 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
527 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
528 | else return -1; /* BUG! Should not be called... */ |
529 | } | |
530 | ||
531 | ||
532 | ||
533 | ||
534 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
535 | { | |
536 | bool p = FALSE; | |
efba2b89 VS |
537 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
538 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
539 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
540 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
541 | if (p) return wxHTML_UNITS_PERCENT; | |
542 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
543 | } |
544 | ||
545 | ||
546 | ||
f2034f1b | 547 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const |
db98870d | 548 | { |
04dbb646 | 549 | if (!m_CanLiveOnPagebreak) |
f2034f1b | 550 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages); |
e52d6dbc | 551 | |
04dbb646 | 552 | else |
4f9297b0 | 553 | { |
e3774124 | 554 | wxHtmlCell *c = GetFirstChild(); |
db98870d | 555 | bool rt = FALSE; |
e52d6dbc | 556 | int pbrk = *pagebreak - m_PosY; |
db98870d | 557 | |
04dbb646 | 558 | while (c) |
0cb9cfb2 | 559 | { |
f2034f1b | 560 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages)) |
bf7d7ee7 | 561 | rt = TRUE; |
4f9297b0 | 562 | c = c->GetNext(); |
db98870d | 563 | } |
d699f48b | 564 | if (rt) |
bf7d7ee7 | 565 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
566 | return rt; |
567 | } | |
568 | } | |
569 | ||
570 | ||
571 | ||
5526e819 VS |
572 | void wxHtmlContainerCell::Layout(int w) |
573 | { | |
026d1fac VS |
574 | wxHtmlCell::Layout(w); |
575 | ||
576 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 577 | |
026d1fac VS |
578 | // VS: Any attempt to layout with negative or zero width leads to hell, |
579 | // but we can't ignore such attempts completely, since it sometimes | |
580 | // happen (e.g. when trying how small a table can be). The best thing we | |
581 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 582 | if (w < 1) |
4f9297b0 | 583 | { |
026d1fac VS |
584 | m_Width = 0; |
585 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
586 | cell->Layout(0); | |
2b5f62a0 VZ |
587 | // this does two things: it recursively calls this code on all |
588 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 589 | return; |
04dbb646 | 590 | } |
5660c520 | 591 | |
5526e819 VS |
592 | wxHtmlCell *cell = m_Cells, *line = m_Cells; |
593 | long xpos = 0, ypos = m_IndentTop; | |
594 | int xdelta = 0, ybasicpos = 0, ydiff; | |
595 | int s_width, s_indent; | |
596 | int ysizeup = 0, ysizedown = 0; | |
5c1bfc5d VS |
597 | int MaxLineWidth = 0; |
598 | int xcnt = 0; | |
599 | ||
5526e819 VS |
600 | |
601 | /* | |
7e941458 | 602 | |
5526e819 | 603 | WIDTH ADJUSTING : |
7e941458 | 604 | |
5526e819 VS |
605 | */ |
606 | ||
04dbb646 | 607 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 608 | { |
5526e819 VS |
609 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
610 | else m_Width = m_WidthFloat * w / 100; | |
611 | } | |
04dbb646 | 612 | else |
4f9297b0 | 613 | { |
5526e819 VS |
614 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
615 | else m_Width = m_WidthFloat; | |
616 | } | |
617 | ||
04dbb646 | 618 | if (m_Cells) |
4f9297b0 | 619 | { |
5526e819 VS |
620 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
621 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
622 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
623 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
624 | } |
625 | ||
626 | /* | |
627 | ||
628 | LAYOUTING : | |
7e941458 | 629 | |
5526e819 VS |
630 | */ |
631 | ||
632 | // adjust indentation: | |
633 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
634 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
635 | ||
5526e819 | 636 | // my own layouting: |
04dbb646 | 637 | while (cell != NULL) |
4f9297b0 | 638 | { |
04dbb646 | 639 | switch (m_AlignVer) |
0cb9cfb2 | 640 | { |
efba2b89 | 641 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
642 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
643 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 644 | } |
4f9297b0 | 645 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 646 | |
4f9297b0 VS |
647 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
648 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 649 | |
4f9297b0 VS |
650 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
651 | xpos += cell->GetWidth(); | |
652 | cell = cell->GetNext(); | |
5c1bfc5d | 653 | xcnt++; |
5526e819 VS |
654 | |
655 | // force new line if occured: | |
04dbb646 | 656 | if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) |
0cb9cfb2 | 657 | { |
5c1bfc5d | 658 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
659 | if (ysizeup < 0) ysizeup = 0; |
660 | if (ysizedown < 0) ysizedown = 0; | |
661 | switch (m_AlignHor) { | |
04dbb646 VZ |
662 | case wxHTML_ALIGN_LEFT : |
663 | case wxHTML_ALIGN_JUSTIFY : | |
664 | xdelta = 0; | |
5c1bfc5d | 665 | break; |
04dbb646 VZ |
666 | case wxHTML_ALIGN_RIGHT : |
667 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 668 | break; |
04dbb646 VZ |
669 | case wxHTML_ALIGN_CENTER : |
670 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 671 | break; |
5526e819 VS |
672 | } |
673 | if (xdelta < 0) xdelta = 0; | |
674 | xdelta += s_indent; | |
675 | ||
676 | ypos += ysizeup; | |
04dbb646 | 677 | |
5c1bfc5d | 678 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
04dbb646 | 679 | while (line != cell) |
0cb9cfb2 | 680 | { |
04dbb646 | 681 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
682 | ypos + line->GetPosY()); |
683 | line = line->GetNext(); | |
5c1bfc5d VS |
684 | } |
685 | else | |
04dbb646 | 686 | { |
5c1bfc5d VS |
687 | int counter = 0; |
688 | int step = (s_width - xpos); | |
689 | if (step < 0) step = 0; | |
c1e5e881 | 690 | xcnt--; |
04dbb646 | 691 | if (xcnt > 0) while (line != cell) |
0cb9cfb2 | 692 | { |
4f9297b0 | 693 | line->SetPos(line->GetPosX() + s_indent + |
5c1bfc5d | 694 | (counter++ * step / xcnt), |
4f9297b0 VS |
695 | ypos + line->GetPosY()); |
696 | line = line->GetNext(); | |
5c1bfc5d | 697 | } |
c1e5e881 | 698 | xcnt++; |
5526e819 VS |
699 | } |
700 | ||
701 | ypos += ysizedown; | |
5c1bfc5d | 702 | xpos = xcnt = 0; |
5526e819 VS |
703 | ysizeup = ysizedown = 0; |
704 | line = cell; | |
705 | } | |
706 | } | |
707 | ||
708 | // setup height & width, depending on container layout: | |
709 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
710 | ||
04dbb646 | 711 | if (m_Height < m_MinHeight) |
4f9297b0 | 712 | { |
04dbb646 | 713 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 714 | { |
5526e819 | 715 | int diff = m_MinHeight - m_Height; |
efba2b89 | 716 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 717 | cell = m_Cells; |
04dbb646 | 718 | while (cell) |
0cb9cfb2 | 719 | { |
4f9297b0 VS |
720 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
721 | cell = cell->GetNext(); | |
5526e819 VS |
722 | } |
723 | } | |
724 | m_Height = m_MinHeight; | |
725 | } | |
726 | ||
5c1bfc5d VS |
727 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
728 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 729 | |
5660c520 | 730 | m_LastLayout = w; |
5526e819 VS |
731 | } |
732 | ||
f30e67db | 733 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
734 | wxHtmlCell *cell) const |
735 | { | |
f30e67db | 736 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 737 | if (!s) return; |
cd275246 | 738 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 739 | { |
f30e67db | 740 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
741 | } |
742 | } | |
743 | ||
f30e67db | 744 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
745 | wxHtmlCell *cell) const |
746 | { | |
f30e67db | 747 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 748 | if (!s) return; |
adf2eb2d | 749 | if (s->GetToCell() == cell) |
f30e67db | 750 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 751 | else if (s->GetFromCell() == cell) |
f30e67db | 752 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 753 | } |
5526e819 VS |
754 | |
755 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
756 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
757 | ||
36c4ff4d | 758 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 759 | wxHtmlRenderingInfo& info) |
5526e819 | 760 | { |
94bc8b14 VS |
761 | // container visible, draw it: |
762 | if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) | |
4f9297b0 | 763 | { |
04dbb646 | 764 | if (m_UseBkColour) |
0cb9cfb2 | 765 | { |
5526e819 VS |
766 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
767 | ||
768 | int real_y1 = mMax(y + m_PosY, view_y1); | |
769 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
770 | ||
771 | dc.SetBrush(myb); | |
772 | dc.SetPen(*wxTRANSPARENT_PEN); | |
773 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
774 | } | |
775 | ||
04dbb646 | 776 | if (m_UseBorder) |
0cb9cfb2 | 777 | { |
5526e819 VS |
778 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
779 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
780 | ||
781 | dc.SetPen(mypen1); | |
782 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
5f265f87 | 783 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY); |
5526e819 VS |
784 | dc.SetPen(mypen2); |
785 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
5f265f87 | 786 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1); |
5526e819 VS |
787 | } |
788 | ||
d699f48b | 789 | if (m_Cells) |
bf7d7ee7 | 790 | { |
36c4ff4d | 791 | // draw container's contents: |
bf7d7ee7 | 792 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
36c4ff4d | 793 | { |
f30e67db | 794 | UpdateRenderingStatePre(info, cell); |
36c4ff4d VS |
795 | cell->Draw(dc, |
796 | x + m_PosX, y + m_PosY, view_y1, view_y2, | |
f30e67db VS |
797 | info); |
798 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 799 | } |
bf7d7ee7 | 800 | } |
5526e819 VS |
801 | } |
802 | // container invisible, just proceed font+color changing: | |
04dbb646 | 803 | else |
4f9297b0 | 804 | { |
f30e67db | 805 | DrawInvisible(dc, x, y, info); |
5526e819 | 806 | } |
5526e819 VS |
807 | } |
808 | ||
809 | ||
810 | ||
36c4ff4d | 811 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 812 | wxHtmlRenderingInfo& info) |
5526e819 | 813 | { |
d699f48b | 814 | if (m_Cells) |
bf7d7ee7 VS |
815 | { |
816 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 817 | { |
f30e67db VS |
818 | UpdateRenderingStatePre(info, cell); |
819 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
820 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 821 | } |
bf7d7ee7 | 822 | } |
5526e819 VS |
823 | } |
824 | ||
825 | ||
2b5f62a0 VZ |
826 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
827 | { | |
828 | if (m_UseBkColour) | |
829 | return m_BkColour; | |
830 | else | |
831 | return wxNullColour; | |
832 | } | |
833 | ||
834 | ||
5526e819 | 835 | |
846914d1 | 836 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 837 | { |
f6010d8f | 838 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 839 | |
f6010d8f VZ |
840 | // VZ: I don't know if we should pass absolute or relative coords to |
841 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
842 | // anyhow, it hardly matters right now but should still be clarified | |
843 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
844 | } |
845 | ||
846 | ||
847 | ||
848 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
849 | { | |
850 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 851 | else |
4f9297b0 VS |
852 | { |
853 | m_LastCell->SetNext(f); | |
5526e819 | 854 | m_LastCell = f; |
4f9297b0 | 855 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 856 | } |
4f9297b0 | 857 | f->SetParent(this); |
5660c520 | 858 | m_LastLayout = -1; |
5526e819 VS |
859 | } |
860 | ||
861 | ||
862 | ||
863 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
864 | { | |
04dbb646 | 865 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 866 | { |
0413cec5 | 867 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 868 | alg.MakeUpper(); |
0413cec5 | 869 | if (alg == wxT("CENTER")) |
efba2b89 | 870 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 871 | else if (alg == wxT("LEFT")) |
efba2b89 | 872 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
873 | else if (alg == wxT("JUSTIFY")) |
874 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 875 | else if (alg == wxT("RIGHT")) |
efba2b89 | 876 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 877 | m_LastLayout = -1; |
5526e819 VS |
878 | } |
879 | } | |
880 | ||
881 | ||
882 | ||
edbd0635 | 883 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 884 | { |
04dbb646 | 885 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 886 | { |
5526e819 | 887 | int wdi; |
0413cec5 | 888 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 889 | |
04dbb646 | 890 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 891 | { |
66a77a74 | 892 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 893 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 894 | } |
04dbb646 | 895 | else |
0cb9cfb2 | 896 | { |
66a77a74 | 897 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 898 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 899 | } |
5660c520 | 900 | m_LastLayout = -1; |
5526e819 VS |
901 | } |
902 | } | |
903 | ||
904 | ||
905 | ||
906 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
907 | { | |
04dbb646 | 908 | if (m_Cells) |
d699f48b | 909 | { |
bf7d7ee7 | 910 | const wxHtmlCell *r = NULL; |
5526e819 | 911 | |
bf7d7ee7 VS |
912 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
913 | { | |
914 | r = cell->Find(condition, param); | |
915 | if (r) return r; | |
916 | } | |
917 | } | |
918 | return NULL; | |
5526e819 VS |
919 | } |
920 | ||
921 | ||
36c4ff4d VS |
922 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
923 | unsigned flags) const | |
5526e819 | 924 | { |
6d41981d | 925 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 926 | { |
adf2eb2d VS |
927 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
928 | { | |
929 | int cx = cell->GetPosX(), | |
930 | cy = cell->GetPosY(); | |
931 | ||
932 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
933 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
934 | { | |
935 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
936 | } | |
937 | } | |
adf2eb2d | 938 | } |
6d41981d | 939 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
940 | { |
941 | wxHtmlCell *c; | |
942 | int y2; | |
943 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) | |
0cb9cfb2 | 944 | { |
adf2eb2d VS |
945 | y2 = cell->GetPosY() + cell->GetHeight() - 1; |
946 | if (y2 < y || (y2 == y && cell->GetPosX()+cell->GetWidth()-1 < x)) | |
947 | continue; | |
948 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(), | |
949 | flags); | |
950 | if (c) return c; | |
5526e819 VS |
951 | } |
952 | } | |
6d41981d | 953 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 954 | { |
e24529d7 | 955 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
956 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
957 | { | |
86ff9b45 | 958 | if (cell->GetPosY() > y || |
adf2eb2d VS |
959 | (cell->GetPosY() == y && cell->GetPosX() > x)) |
960 | break; | |
e24529d7 VS |
961 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(), |
962 | flags); | |
963 | if (c2) | |
964 | c = c2; | |
adf2eb2d | 965 | } |
e24529d7 | 966 | if (c) return c; |
adf2eb2d | 967 | } |
6d41981d VZ |
968 | |
969 | return NULL; | |
f6010d8f VZ |
970 | } |
971 | ||
972 | ||
973 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) | |
974 | { | |
975 | wxHtmlCell *cell = FindCellByPos(x, y); | |
976 | if ( cell ) | |
977 | cell->OnMouseClick(parent, x, y, event); | |
5526e819 VS |
978 | } |
979 | ||
980 | ||
981 | ||
79d6c018 VS |
982 | void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const |
983 | { | |
984 | int cleft = m_PosX + m_Width, cright = m_PosX; // worst case | |
985 | int l, r; | |
0cb9cfb2 | 986 | |
79d6c018 VS |
987 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
988 | { | |
989 | cell->GetHorizontalConstraints(&l, &r); | |
990 | if (l < cleft) | |
991 | cleft = l; | |
992 | if (r > cright) | |
993 | cright = r; | |
0cb9cfb2 | 994 | } |
79d6c018 | 995 | |
026d1fac VS |
996 | cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
997 | cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
998 | ||
79d6c018 VS |
999 | if (left) |
1000 | *left = cleft; | |
1001 | if (right) | |
1002 | *right = cright; | |
1003 | } | |
1004 | ||
86ff9b45 | 1005 | |
adf2eb2d VS |
1006 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const |
1007 | { | |
e3774124 VS |
1008 | if ( m_Cells ) |
1009 | { | |
1010 | wxHtmlCell *c2; | |
1011 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
1012 | { | |
1013 | c2 = c->GetFirstTerminal(); | |
1014 | if ( c2 ) | |
1015 | return c2; | |
1016 | } | |
1017 | } | |
1018 | return NULL; | |
adf2eb2d VS |
1019 | } |
1020 | ||
1021 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
1022 | { | |
e3774124 | 1023 | if ( m_Cells ) |
adf2eb2d | 1024 | { |
e3774124 | 1025 | // most common case first: |
4ce19ed7 | 1026 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
1027 | if ( c ) |
1028 | return c; | |
4ce19ed7 VZ |
1029 | |
1030 | wxHtmlCell *c2 = NULL; | |
1031 | for (c = m_Cells; c; c = c->GetNext()) | |
e3774124 VS |
1032 | c2 = c->GetLastTerminal(); |
1033 | return c2; | |
adf2eb2d VS |
1034 | } |
1035 | else | |
1036 | return NULL; | |
1037 | } | |
79d6c018 VS |
1038 | |
1039 | ||
5526e819 VS |
1040 | |
1041 | ||
36c4ff4d | 1042 | // -------------------------------------------------------------------------- |
5526e819 | 1043 | // wxHtmlColourCell |
36c4ff4d | 1044 | // -------------------------------------------------------------------------- |
5526e819 | 1045 | |
36c4ff4d VS |
1046 | void wxHtmlColourCell::Draw(wxDC& dc, |
1047 | int x, int y, | |
1048 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1049 | wxHtmlRenderingInfo& info) |
5526e819 | 1050 | { |
f30e67db | 1051 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1052 | } |
1053 | ||
36c4ff4d VS |
1054 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1055 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1056 | wxHtmlRenderingInfo& info) |
5526e819 | 1057 | { |
f30e67db | 1058 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1059 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1060 | { |
1061 | state.SetFgColour(m_Colour); | |
1062 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1063 | dc.SetTextForeground(m_Colour); |
1064 | else | |
1065 | dc.SetTextForeground( | |
1066 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1067 | } |
04dbb646 | 1068 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1069 | { |
36c4ff4d VS |
1070 | state.SetBgColour(m_Colour); |
1071 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
1072 | dc.SetTextBackground(m_Colour); | |
bfc248a3 VS |
1073 | else |
1074 | dc.SetTextBackground( | |
1075 | info.GetStyle().GetSelectedTextBgColour(m_Colour)); | |
5526e819 | 1076 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
5526e819 | 1077 | } |
5526e819 VS |
1078 | } |
1079 | ||
1080 | ||
1081 | ||
1082 | ||
36c4ff4d | 1083 | // --------------------------------------------------------------------------- |
5526e819 | 1084 | // wxHtmlFontCell |
36c4ff4d | 1085 | // --------------------------------------------------------------------------- |
5526e819 | 1086 | |
36c4ff4d VS |
1087 | void wxHtmlFontCell::Draw(wxDC& dc, |
1088 | int WXUNUSED(x), int WXUNUSED(y), | |
1089 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1090 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1091 | { |
921d0fb1 | 1092 | dc.SetFont(m_Font); |
5526e819 VS |
1093 | } |
1094 | ||
36c4ff4d | 1095 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1096 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1097 | { |
921d0fb1 | 1098 | dc.SetFont(m_Font); |
5526e819 VS |
1099 | } |
1100 | ||
1101 | ||
1102 | ||
1103 | ||
1104 | ||
1105 | ||
1106 | ||
1107 | ||
36c4ff4d | 1108 | // --------------------------------------------------------------------------- |
5526e819 | 1109 | // wxHtmlWidgetCell |
36c4ff4d | 1110 | // --------------------------------------------------------------------------- |
5526e819 VS |
1111 | |
1112 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) | |
1113 | { | |
1114 | int sx, sy; | |
1115 | m_Wnd = wnd; | |
4f9297b0 | 1116 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1117 | m_Width = sx, m_Height = sy; |
1118 | m_WidthFloat = w; | |
1119 | } | |
1120 | ||
1121 | ||
36c4ff4d VS |
1122 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1123 | int WXUNUSED(x), int WXUNUSED(y), | |
1124 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1125 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1126 | { |
1127 | int absx = 0, absy = 0, stx, sty; | |
1128 | wxHtmlCell *c = this; | |
1129 | ||
04dbb646 | 1130 | while (c) |
4f9297b0 VS |
1131 | { |
1132 | absx += c->GetPosX(); | |
1133 | absy += c->GetPosY(); | |
1134 | c = c->GetParent(); | |
5526e819 VS |
1135 | } |
1136 | ||
e421922f | 1137 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1138 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1139 | } |
1140 | ||
1141 | ||
1142 | ||
36c4ff4d VS |
1143 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1144 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1145 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1146 | { |
1147 | int absx = 0, absy = 0, stx, sty; | |
1148 | wxHtmlCell *c = this; | |
1149 | ||
04dbb646 | 1150 | while (c) |
4f9297b0 VS |
1151 | { |
1152 | absx += c->GetPosX(); | |
1153 | absy += c->GetPosY(); | |
1154 | c = c->GetParent(); | |
5526e819 | 1155 | } |
7e941458 | 1156 | |
e421922f | 1157 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1158 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1159 | } |
1160 | ||
1161 | ||
1162 | ||
1163 | void wxHtmlWidgetCell::Layout(int w) | |
1164 | { | |
04dbb646 | 1165 | if (m_WidthFloat != 0) |
4f9297b0 | 1166 | { |
5526e819 | 1167 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1168 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1169 | } |
1170 | ||
1171 | wxHtmlCell::Layout(w); | |
1172 | } | |
1173 | ||
e3774124 VS |
1174 | |
1175 | ||
1176 | // ---------------------------------------------------------------------------- | |
1177 | // wxHtmlTerminalCellsInterator | |
1178 | // ---------------------------------------------------------------------------- | |
1179 | ||
1180 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1181 | { | |
1182 | if ( !m_pos ) | |
1183 | return NULL; | |
1184 | ||
1185 | do | |
1186 | { | |
1187 | if ( m_pos == m_to ) | |
1188 | { | |
1189 | m_pos = NULL; | |
1190 | return NULL; | |
1191 | } | |
1192 | ||
1193 | if ( m_pos->GetNext() ) | |
1194 | m_pos = m_pos->GetNext(); | |
1195 | else | |
1196 | { | |
1197 | // we must go up the hierarchy until we reach container where this | |
1198 | // is not the last child, and then go down to first terminal cell: | |
1199 | while ( m_pos->GetNext() == NULL ) | |
1200 | { | |
1201 | m_pos = m_pos->GetParent(); | |
1202 | if ( !m_pos ) | |
1203 | return NULL; | |
1204 | } | |
1205 | m_pos = m_pos->GetNext(); | |
1206 | } | |
1207 | while ( m_pos->GetFirstChild() != NULL ) | |
1208 | m_pos = m_pos->GetFirstChild(); | |
1209 | } while ( !m_pos->IsTerminalCell() ); | |
86ff9b45 | 1210 | |
e3774124 VS |
1211 | return m_pos; |
1212 | } | |
1213 | ||
77bae5e2 VS |
1214 | |
1215 | ||
1216 | ||
1217 | ||
1218 | ||
1219 | ||
1220 | //----------------------------------------------------------------------------- | |
1221 | // Cleanup | |
1222 | //----------------------------------------------------------------------------- | |
1223 | ||
1224 | class wxHtmlCellModule: public wxModule | |
1225 | { | |
1226 | DECLARE_DYNAMIC_CLASS(wxHtmlCellModule) | |
1227 | public: | |
1228 | wxHtmlCellModule() : wxModule() {} | |
1229 | bool OnInit() { return true; } | |
1230 | void OnExit() | |
1231 | { | |
1232 | wxDELETE(gs_cursorLink); | |
1233 | wxDELETE(gs_cursorText); | |
1234 | } | |
1235 | }; | |
1236 | ||
1237 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule, wxModule) | |
1238 | ||
5526e819 | 1239 | #endif |