]>
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" | |
5526e819 VS |
32 | #include <stdlib.h> |
33 | ||
34 | ||
5526e819 VS |
35 | //----------------------------------------------------------------------------- |
36 | // wxHtmlCell | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
04dbb646 | 39 | wxHtmlCell::wxHtmlCell() : wxObject() |
846914d1 | 40 | { |
04dbb646 VZ |
41 | m_Next = NULL; |
42 | m_Parent = NULL; | |
43 | m_Width = m_Height = m_Descent = 0; | |
846914d1 VS |
44 | m_CanLiveOnPagebreak = TRUE; |
45 | m_Link = NULL; | |
46 | } | |
47 | ||
04dbb646 | 48 | wxHtmlCell::~wxHtmlCell() |
846914d1 | 49 | { |
0cb9cfb2 | 50 | delete m_Link; |
846914d1 VS |
51 | } |
52 | ||
5526e819 | 53 | |
04dbb646 | 54 | void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, |
0b2dadd3 | 55 | const wxMouseEvent& event) |
5526e819 | 56 | { |
846914d1 VS |
57 | wxHtmlLinkInfo *lnk = GetLink(x, y); |
58 | if (lnk != NULL) | |
0b2dadd3 VS |
59 | { |
60 | wxHtmlLinkInfo lnk2(*lnk); | |
61 | lnk2.SetEvent(&event); | |
9bc8fded | 62 | lnk2.SetHtmlCell(this); |
0cb9cfb2 VZ |
63 | |
64 | // note : this cast is legal because parent is *always* wxHtmlWindow | |
65 | wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2); | |
0b2dadd3 | 66 | } |
5526e819 VS |
67 | } |
68 | ||
69 | ||
70 | ||
5660c520 | 71 | bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const |
db98870d | 72 | { |
04dbb646 VZ |
73 | if ((!m_CanLiveOnPagebreak) && |
74 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) | |
0cb9cfb2 | 75 | { |
db98870d | 76 | *pagebreak = m_PosY; |
db98870d VS |
77 | return TRUE; |
78 | } | |
0cb9cfb2 VZ |
79 | |
80 | return FALSE; | |
db98870d VS |
81 | } |
82 | ||
83 | ||
84 | ||
04dbb646 | 85 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 VS |
86 | { |
87 | if (m_Link) delete m_Link; | |
af1ed0c1 VS |
88 | m_Link = NULL; |
89 | if (link.GetHref() != wxEmptyString) | |
90 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
91 | } |
92 | ||
93 | ||
db98870d | 94 | |
d699f48b | 95 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 96 | { |
04dbb646 | 97 | SetPos(0, 0); |
721ab905 VS |
98 | } |
99 | ||
100 | ||
79d6c018 VS |
101 | |
102 | void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const | |
103 | { | |
104 | if (left) | |
105 | *left = m_PosX; | |
106 | if (right) | |
026d1fac | 107 | *right = m_PosX + m_Width; |
79d6c018 VS |
108 | } |
109 | ||
110 | ||
111 | ||
d699f48b | 112 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 113 | { |
bf7d7ee7 | 114 | return NULL; |
721ab905 VS |
115 | } |
116 | ||
117 | ||
f6010d8f VZ |
118 | wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y) const |
119 | { | |
120 | if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height ) | |
121 | return wxConstCast(this, wxHtmlCell); | |
122 | ||
123 | return NULL; | |
124 | } | |
125 | ||
721ab905 | 126 | |
5526e819 VS |
127 | //----------------------------------------------------------------------------- |
128 | // wxHtmlWordCell | |
129 | //----------------------------------------------------------------------------- | |
130 | ||
131 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() | |
132 | { | |
133 | m_Word = word; | |
5526e819 | 134 | dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); |
db98870d | 135 | SetCanLiveOnPagebreak(FALSE); |
5526e819 VS |
136 | } |
137 | ||
138 | ||
139 | ||
d699f48b | 140 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 VS |
141 | { |
142 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
5526e819 VS |
143 | } |
144 | ||
145 | ||
146 | ||
5526e819 VS |
147 | //----------------------------------------------------------------------------- |
148 | // wxHtmlContainerCell | |
149 | //----------------------------------------------------------------------------- | |
150 | ||
151 | ||
152 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
153 | { | |
154 | m_Cells = m_LastCell = NULL; | |
155 | m_Parent = parent; | |
4f9297b0 | 156 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
157 | m_AlignHor = wxHTML_ALIGN_LEFT; |
158 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 159 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 160 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
5526e819 VS |
161 | m_UseBkColour = FALSE; |
162 | m_UseBorder = FALSE; | |
5c1bfc5d | 163 | m_MinHeight = 0; |
efba2b89 | 164 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 165 | m_LastLayout = -1; |
5526e819 VS |
166 | } |
167 | ||
04dbb646 | 168 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 169 | { |
491c9920 VZ |
170 | wxHtmlCell *cell = m_Cells; |
171 | while ( cell ) | |
bf7d7ee7 | 172 | { |
491c9920 VZ |
173 | wxHtmlCell *cellNext = cell->GetNext(); |
174 | delete cell; | |
175 | cell = cellNext; | |
bf7d7ee7 | 176 | } |
721ab905 VS |
177 | } |
178 | ||
5526e819 VS |
179 | |
180 | ||
181 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
182 | { | |
efba2b89 VS |
183 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
184 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
185 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
186 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
187 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 188 | m_LastLayout = -1; |
5526e819 VS |
189 | } |
190 | ||
191 | ||
192 | ||
193 | int wxHtmlContainerCell::GetIndent(int ind) const | |
194 | { | |
efba2b89 VS |
195 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
196 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
197 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
198 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
199 | else return -1; /* BUG! Should not be called... */ |
200 | } | |
201 | ||
202 | ||
203 | ||
204 | ||
205 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
206 | { | |
207 | bool p = FALSE; | |
efba2b89 VS |
208 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
209 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
210 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
211 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
212 | if (p) return wxHTML_UNITS_PERCENT; | |
213 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
214 | } |
215 | ||
216 | ||
217 | ||
5660c520 | 218 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak) const |
db98870d | 219 | { |
04dbb646 | 220 | if (!m_CanLiveOnPagebreak) |
db98870d | 221 | return wxHtmlCell::AdjustPagebreak(pagebreak); |
e52d6dbc | 222 | |
04dbb646 | 223 | else |
4f9297b0 | 224 | { |
db98870d VS |
225 | wxHtmlCell *c = GetFirstCell(); |
226 | bool rt = FALSE; | |
e52d6dbc | 227 | int pbrk = *pagebreak - m_PosY; |
db98870d | 228 | |
04dbb646 | 229 | while (c) |
0cb9cfb2 | 230 | { |
d699f48b | 231 | if (c->AdjustPagebreak(&pbrk)) |
bf7d7ee7 | 232 | rt = TRUE; |
4f9297b0 | 233 | c = c->GetNext(); |
db98870d | 234 | } |
d699f48b | 235 | if (rt) |
bf7d7ee7 | 236 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
237 | return rt; |
238 | } | |
239 | } | |
240 | ||
241 | ||
242 | ||
5526e819 VS |
243 | void wxHtmlContainerCell::Layout(int w) |
244 | { | |
026d1fac VS |
245 | wxHtmlCell::Layout(w); |
246 | ||
247 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 248 | |
026d1fac VS |
249 | // VS: Any attempt to layout with negative or zero width leads to hell, |
250 | // but we can't ignore such attempts completely, since it sometimes | |
251 | // happen (e.g. when trying how small a table can be). The best thing we | |
252 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 253 | if (w < 1) |
4f9297b0 | 254 | { |
026d1fac VS |
255 | m_Width = 0; |
256 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
257 | cell->Layout(0); | |
2b5f62a0 VZ |
258 | // this does two things: it recursively calls this code on all |
259 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 260 | return; |
04dbb646 | 261 | } |
5660c520 | 262 | |
5526e819 VS |
263 | wxHtmlCell *cell = m_Cells, *line = m_Cells; |
264 | long xpos = 0, ypos = m_IndentTop; | |
265 | int xdelta = 0, ybasicpos = 0, ydiff; | |
266 | int s_width, s_indent; | |
267 | int ysizeup = 0, ysizedown = 0; | |
5c1bfc5d VS |
268 | int MaxLineWidth = 0; |
269 | int xcnt = 0; | |
270 | ||
5526e819 VS |
271 | |
272 | /* | |
7e941458 | 273 | |
5526e819 | 274 | WIDTH ADJUSTING : |
7e941458 | 275 | |
5526e819 VS |
276 | */ |
277 | ||
04dbb646 | 278 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 279 | { |
5526e819 VS |
280 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
281 | else m_Width = m_WidthFloat * w / 100; | |
282 | } | |
04dbb646 | 283 | else |
4f9297b0 | 284 | { |
5526e819 VS |
285 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
286 | else m_Width = m_WidthFloat; | |
287 | } | |
288 | ||
04dbb646 | 289 | if (m_Cells) |
4f9297b0 | 290 | { |
5526e819 VS |
291 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
292 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
293 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
294 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
295 | } |
296 | ||
297 | /* | |
298 | ||
299 | LAYOUTING : | |
7e941458 | 300 | |
5526e819 VS |
301 | */ |
302 | ||
303 | // adjust indentation: | |
304 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
305 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
306 | ||
5526e819 | 307 | // my own layouting: |
04dbb646 | 308 | while (cell != NULL) |
4f9297b0 | 309 | { |
04dbb646 | 310 | switch (m_AlignVer) |
0cb9cfb2 | 311 | { |
efba2b89 | 312 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
313 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
314 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 315 | } |
4f9297b0 | 316 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 317 | |
4f9297b0 VS |
318 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
319 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 320 | |
4f9297b0 VS |
321 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
322 | xpos += cell->GetWidth(); | |
323 | cell = cell->GetNext(); | |
5c1bfc5d | 324 | xcnt++; |
5526e819 VS |
325 | |
326 | // force new line if occured: | |
04dbb646 | 327 | if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) |
0cb9cfb2 | 328 | { |
5c1bfc5d | 329 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
330 | if (ysizeup < 0) ysizeup = 0; |
331 | if (ysizedown < 0) ysizedown = 0; | |
332 | switch (m_AlignHor) { | |
04dbb646 VZ |
333 | case wxHTML_ALIGN_LEFT : |
334 | case wxHTML_ALIGN_JUSTIFY : | |
335 | xdelta = 0; | |
5c1bfc5d | 336 | break; |
04dbb646 VZ |
337 | case wxHTML_ALIGN_RIGHT : |
338 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 339 | break; |
04dbb646 VZ |
340 | case wxHTML_ALIGN_CENTER : |
341 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 342 | break; |
5526e819 VS |
343 | } |
344 | if (xdelta < 0) xdelta = 0; | |
345 | xdelta += s_indent; | |
346 | ||
347 | ypos += ysizeup; | |
04dbb646 | 348 | |
5c1bfc5d | 349 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
04dbb646 | 350 | while (line != cell) |
0cb9cfb2 | 351 | { |
04dbb646 | 352 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
353 | ypos + line->GetPosY()); |
354 | line = line->GetNext(); | |
5c1bfc5d VS |
355 | } |
356 | else | |
04dbb646 | 357 | { |
5c1bfc5d VS |
358 | int counter = 0; |
359 | int step = (s_width - xpos); | |
360 | if (step < 0) step = 0; | |
c1e5e881 | 361 | xcnt--; |
04dbb646 | 362 | if (xcnt > 0) while (line != cell) |
0cb9cfb2 | 363 | { |
4f9297b0 | 364 | line->SetPos(line->GetPosX() + s_indent + |
5c1bfc5d | 365 | (counter++ * step / xcnt), |
4f9297b0 VS |
366 | ypos + line->GetPosY()); |
367 | line = line->GetNext(); | |
5c1bfc5d | 368 | } |
c1e5e881 | 369 | xcnt++; |
5526e819 VS |
370 | } |
371 | ||
372 | ypos += ysizedown; | |
5c1bfc5d | 373 | xpos = xcnt = 0; |
5526e819 VS |
374 | ysizeup = ysizedown = 0; |
375 | line = cell; | |
376 | } | |
377 | } | |
378 | ||
379 | // setup height & width, depending on container layout: | |
380 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
381 | ||
04dbb646 | 382 | if (m_Height < m_MinHeight) |
4f9297b0 | 383 | { |
04dbb646 | 384 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 385 | { |
5526e819 | 386 | int diff = m_MinHeight - m_Height; |
efba2b89 | 387 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 388 | cell = m_Cells; |
04dbb646 | 389 | while (cell) |
0cb9cfb2 | 390 | { |
4f9297b0 VS |
391 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
392 | cell = cell->GetNext(); | |
5526e819 VS |
393 | } |
394 | } | |
395 | m_Height = m_MinHeight; | |
396 | } | |
397 | ||
5c1bfc5d VS |
398 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
399 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 400 | |
5660c520 | 401 | m_LastLayout = w; |
5526e819 VS |
402 | } |
403 | ||
404 | ||
405 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
406 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
407 | ||
408 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) | |
409 | { | |
94bc8b14 VS |
410 | // container visible, draw it: |
411 | if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) | |
4f9297b0 | 412 | { |
04dbb646 | 413 | if (m_UseBkColour) |
0cb9cfb2 | 414 | { |
5526e819 VS |
415 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
416 | ||
417 | int real_y1 = mMax(y + m_PosY, view_y1); | |
418 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
419 | ||
420 | dc.SetBrush(myb); | |
421 | dc.SetPen(*wxTRANSPARENT_PEN); | |
422 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
423 | } | |
424 | ||
04dbb646 | 425 | if (m_UseBorder) |
0cb9cfb2 | 426 | { |
5526e819 VS |
427 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
428 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
429 | ||
d840aae3 | 430 | int subtractMe = 1; |
76985f52 JS |
431 | // We get a missing pixel if subtract 1. |
432 | #if defined(__WXMSW__) || defined(__WXGTK__) | |
d840aae3 JS |
433 | subtractMe = 0; |
434 | #endif | |
5526e819 VS |
435 | dc.SetPen(mypen1); |
436 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
d840aae3 | 437 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width - subtractMe, y + m_PosY); |
5526e819 VS |
438 | dc.SetPen(mypen2); |
439 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
d840aae3 | 440 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width - subtractMe, y + m_PosY + m_Height - 1); |
5526e819 VS |
441 | } |
442 | ||
d699f48b | 443 | if (m_Cells) |
bf7d7ee7 VS |
444 | { |
445 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
446 | cell->Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2); | |
447 | } | |
5526e819 VS |
448 | } |
449 | // container invisible, just proceed font+color changing: | |
04dbb646 | 450 | else |
4f9297b0 | 451 | { |
d699f48b | 452 | if (m_Cells) |
bf7d7ee7 VS |
453 | { |
454 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
455 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); | |
456 | } | |
5526e819 | 457 | } |
5526e819 VS |
458 | } |
459 | ||
460 | ||
461 | ||
462 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y) | |
463 | { | |
d699f48b | 464 | if (m_Cells) |
bf7d7ee7 VS |
465 | { |
466 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
467 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); | |
468 | } | |
5526e819 VS |
469 | } |
470 | ||
471 | ||
2b5f62a0 VZ |
472 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
473 | { | |
474 | if (m_UseBkColour) | |
475 | return m_BkColour; | |
476 | else | |
477 | return wxNullColour; | |
478 | } | |
479 | ||
480 | ||
5526e819 | 481 | |
846914d1 | 482 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 483 | { |
f6010d8f | 484 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 485 | |
f6010d8f VZ |
486 | // VZ: I don't know if we should pass absolute or relative coords to |
487 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
488 | // anyhow, it hardly matters right now but should still be clarified | |
489 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
490 | } |
491 | ||
492 | ||
493 | ||
494 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
495 | { | |
496 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 497 | else |
4f9297b0 VS |
498 | { |
499 | m_LastCell->SetNext(f); | |
5526e819 | 500 | m_LastCell = f; |
4f9297b0 | 501 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 502 | } |
4f9297b0 | 503 | f->SetParent(this); |
5660c520 | 504 | m_LastLayout = -1; |
5526e819 VS |
505 | } |
506 | ||
507 | ||
508 | ||
509 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
510 | { | |
04dbb646 | 511 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 512 | { |
0413cec5 | 513 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 514 | alg.MakeUpper(); |
0413cec5 | 515 | if (alg == wxT("CENTER")) |
efba2b89 | 516 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 517 | else if (alg == wxT("LEFT")) |
efba2b89 | 518 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
519 | else if (alg == wxT("JUSTIFY")) |
520 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 521 | else if (alg == wxT("RIGHT")) |
efba2b89 | 522 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 523 | m_LastLayout = -1; |
5526e819 VS |
524 | } |
525 | } | |
526 | ||
527 | ||
528 | ||
edbd0635 | 529 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 530 | { |
04dbb646 | 531 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 532 | { |
5526e819 | 533 | int wdi; |
0413cec5 | 534 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 535 | |
04dbb646 | 536 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 537 | { |
66a77a74 | 538 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 539 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 540 | } |
04dbb646 | 541 | else |
0cb9cfb2 | 542 | { |
66a77a74 | 543 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 544 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 545 | } |
5660c520 | 546 | m_LastLayout = -1; |
5526e819 VS |
547 | } |
548 | } | |
549 | ||
550 | ||
551 | ||
552 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
553 | { | |
04dbb646 | 554 | if (m_Cells) |
d699f48b | 555 | { |
bf7d7ee7 | 556 | const wxHtmlCell *r = NULL; |
5526e819 | 557 | |
bf7d7ee7 VS |
558 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
559 | { | |
560 | r = cell->Find(condition, param); | |
561 | if (r) return r; | |
562 | } | |
563 | } | |
564 | return NULL; | |
5526e819 VS |
565 | } |
566 | ||
567 | ||
f6010d8f | 568 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y) const |
5526e819 | 569 | { |
f6010d8f | 570 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
4f9297b0 | 571 | { |
f6010d8f VZ |
572 | int cx = cell->GetPosX(), |
573 | cy = cell->GetPosY(); | |
574 | ||
575 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
576 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
0cb9cfb2 | 577 | { |
f6010d8f | 578 | return cell->FindCellByPos(x - cx, y - cy); |
5526e819 VS |
579 | } |
580 | } | |
f6010d8f VZ |
581 | |
582 | return NULL; | |
583 | } | |
584 | ||
585 | ||
586 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) | |
587 | { | |
588 | wxHtmlCell *cell = FindCellByPos(x, y); | |
589 | if ( cell ) | |
590 | cell->OnMouseClick(parent, x, y, event); | |
5526e819 VS |
591 | } |
592 | ||
593 | ||
594 | ||
79d6c018 VS |
595 | void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const |
596 | { | |
597 | int cleft = m_PosX + m_Width, cright = m_PosX; // worst case | |
598 | int l, r; | |
0cb9cfb2 | 599 | |
79d6c018 VS |
600 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
601 | { | |
602 | cell->GetHorizontalConstraints(&l, &r); | |
603 | if (l < cleft) | |
604 | cleft = l; | |
605 | if (r > cright) | |
606 | cright = r; | |
0cb9cfb2 | 607 | } |
79d6c018 | 608 | |
026d1fac VS |
609 | cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
610 | cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
611 | ||
79d6c018 VS |
612 | if (left) |
613 | *left = cleft; | |
614 | if (right) | |
615 | *right = cright; | |
616 | } | |
617 | ||
618 | ||
619 | ||
5526e819 VS |
620 | |
621 | ||
622 | //-------------------------------------------------------------------------------- | |
623 | // wxHtmlColourCell | |
624 | //-------------------------------------------------------------------------------- | |
625 | ||
d699f48b | 626 | void wxHtmlColourCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 | 627 | { |
efba2b89 | 628 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
5526e819 | 629 | dc.SetTextForeground(m_Colour); |
04dbb646 | 630 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 631 | { |
5526e819 VS |
632 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
633 | dc.SetTextBackground(m_Colour); | |
634 | } | |
5526e819 VS |
635 | } |
636 | ||
d699f48b | 637 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 | 638 | { |
efba2b89 | 639 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
5526e819 | 640 | dc.SetTextForeground(m_Colour); |
04dbb646 | 641 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 642 | { |
5526e819 VS |
643 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
644 | dc.SetTextBackground(m_Colour); | |
645 | } | |
5526e819 VS |
646 | } |
647 | ||
648 | ||
649 | ||
650 | ||
651 | //-------------------------------------------------------------------------------- | |
652 | // wxHtmlFontCell | |
653 | //-------------------------------------------------------------------------------- | |
654 | ||
d699f48b | 655 | void wxHtmlFontCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 | 656 | { |
921d0fb1 | 657 | dc.SetFont(m_Font); |
5526e819 VS |
658 | } |
659 | ||
d699f48b | 660 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 | 661 | { |
921d0fb1 | 662 | dc.SetFont(m_Font); |
5526e819 VS |
663 | } |
664 | ||
665 | ||
666 | ||
667 | ||
668 | ||
669 | ||
670 | ||
671 | ||
672 | //-------------------------------------------------------------------------------- | |
673 | // wxHtmlWidgetCell | |
674 | //-------------------------------------------------------------------------------- | |
675 | ||
676 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) | |
677 | { | |
678 | int sx, sy; | |
679 | m_Wnd = wnd; | |
4f9297b0 | 680 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
681 | m_Width = sx, m_Height = sy; |
682 | m_WidthFloat = w; | |
683 | } | |
684 | ||
685 | ||
d699f48b | 686 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 VS |
687 | { |
688 | int absx = 0, absy = 0, stx, sty; | |
689 | wxHtmlCell *c = this; | |
690 | ||
04dbb646 | 691 | while (c) |
4f9297b0 VS |
692 | { |
693 | absx += c->GetPosX(); | |
694 | absy += c->GetPosY(); | |
695 | c = c->GetParent(); | |
5526e819 VS |
696 | } |
697 | ||
e421922f | 698 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 699 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
700 | } |
701 | ||
702 | ||
703 | ||
d699f48b | 704 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 VS |
705 | { |
706 | int absx = 0, absy = 0, stx, sty; | |
707 | wxHtmlCell *c = this; | |
708 | ||
04dbb646 | 709 | while (c) |
4f9297b0 VS |
710 | { |
711 | absx += c->GetPosX(); | |
712 | absy += c->GetPosY(); | |
713 | c = c->GetParent(); | |
5526e819 | 714 | } |
7e941458 | 715 | |
e421922f | 716 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 717 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
718 | } |
719 | ||
720 | ||
721 | ||
722 | void wxHtmlWidgetCell::Layout(int w) | |
723 | { | |
04dbb646 | 724 | if (m_WidthFloat != 0) |
4f9297b0 | 725 | { |
5526e819 | 726 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 727 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
728 | } |
729 | ||
730 | wxHtmlCell::Layout(w); | |
731 | } | |
732 | ||
733 | #endif |