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