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