X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e52cac90cda8f499169a247e7f23c985b16a70e6..82ea63e6e046652bc0799badd9d62f91c9918dbe:/src/html/htmlcell.cpp diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index eab1485438..542c1c656e 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -33,23 +33,40 @@ // wxHtmlCell //----------------------------------------------------------------------------- +wxHtmlCell::wxHtmlCell() : wxObject() +{ + m_Next = NULL; + m_Parent = NULL; + m_Width = m_Height = m_Descent = 0; + m_CanLiveOnPagebreak = TRUE; + m_Link = NULL; +} -void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, - bool WXUNUSED(left), - bool WXUNUSED(middle), - bool WXUNUSED(right)) +wxHtmlCell::~wxHtmlCell() { - wxString lnk = GetLink(x, y); - if (lnk != wxEmptyString) - ((wxHtmlWindow*)parent) -> OnLinkClicked(lnk); + if (m_Link) delete m_Link; + if (m_Next) delete m_Next; +} + + +void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, + const wxMouseEvent& event) +{ + wxHtmlLinkInfo *lnk = GetLink(x, y); + if (lnk != NULL) + { + wxHtmlLinkInfo lnk2(*lnk); + lnk2.SetEvent(&event); + lnk2.SetHtmlCell(this); + ((wxHtmlWindow*)parent) -> OnLinkClicked(lnk2); // note : this overcasting is legal because parent is *always* wxHtmlWindow + } } bool wxHtmlCell::AdjustPagebreak(int *pagebreak) { - if ((!m_CanLiveOnPagebreak) && m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) { *pagebreak = m_PosY; @@ -65,6 +82,13 @@ bool wxHtmlCell::AdjustPagebreak(int *pagebreak) +void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) +{ + if (m_Link) delete m_Link; + m_Link = new wxHtmlLinkInfo(link); +} + + //----------------------------------------------------------------------------- // wxHtmlWordCell @@ -73,20 +97,26 @@ bool wxHtmlCell::AdjustPagebreak(int *pagebreak) wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() { m_Word = word; - - m_Word.Replace(wxT(" "), wxT(" "), TRUE); - m_Word.Replace(wxT("©"), wxT("(c)"), TRUE); - m_Word.Replace(wxT("""), wxT("\""), TRUE); - m_Word.Replace(wxT("<"), wxT("<"), TRUE); - m_Word.Replace(wxT(">"), wxT(">"), TRUE); - m_Word.Replace(wxT("&"), wxT("&"), TRUE); - - m_Word.Replace(wxT("  "), wxT(" "), TRUE); - m_Word.Replace(wxT("© "), wxT("(c)"), TRUE); - m_Word.Replace(wxT("" "), wxT("\""), TRUE); - m_Word.Replace(wxT("< "), wxT("<"), TRUE); - m_Word.Replace(wxT("> "), wxT(">"), TRUE); - m_Word.Replace(wxT("& "), wxT("&"), TRUE); + + if (m_Word.Find(wxT('&')) != -1) + { + static wxChar* substitutions[][3] = + { + { wxT(" "), wxT("  "), wxT(" ") }, + { wxT("©"), wxT("© "), wxT("(c)") }, + { wxT("""), wxT("" "), wxT("\"") }, + { wxT("<"), wxT("< "), wxT("<") }, + { wxT(">"), wxT("> "), wxT(">") }, + { wxT("&"), wxT("& "), wxT("&") /*this one should be last one*/ }, + { NULL, NULL, NULL } + }; + + for (int i = 0; substitutions[i][0] != NULL; i++) + { + m_Word.Replace(substitutions[i][0], substitutions[i][2], TRUE); + m_Word.Replace(substitutions[i][1], substitutions[i][2], TRUE); + } + } dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); SetCanLiveOnPagebreak(FALSE); @@ -338,7 +368,7 @@ void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y) -wxString wxHtmlContainerCell::GetLink(int x, int y) const +wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const { wxHtmlCell *c = m_Cells; int cx, cy, cw, ch; @@ -350,7 +380,7 @@ wxString wxHtmlContainerCell::GetLink(int x, int y) const return c -> GetLink(x - cx, y - cy); c = c -> GetNext(); } - return wxEmptyString; + return NULL; } @@ -370,33 +400,33 @@ void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) { - if (tag.HasParam("ALIGN")) { - wxString alg = tag.GetParam("ALIGN"); + if (tag.HasParam(wxT("ALIGN"))) { + wxString alg = tag.GetParam(wxT("ALIGN")); alg.MakeUpper(); - if (alg == "CENTER") + if (alg == wxT("CENTER")) SetAlignHor(wxHTML_ALIGN_CENTER); - else if (alg == "LEFT") + else if (alg == wxT("LEFT")) SetAlignHor(wxHTML_ALIGN_LEFT); - else if (alg == "RIGHT") + else if (alg == wxT("RIGHT")) SetAlignHor(wxHTML_ALIGN_RIGHT); } } -void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag) +void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) { - if (tag.HasParam("WIDTH")) { + if (tag.HasParam(wxT("WIDTH"))) { int wdi; - wxString wd = tag.GetParam("WIDTH"); + wxString wd = tag.GetParam(wxT("WIDTH")); - if (wd[wd.Length()-1] == '%') { + if (wd[wd.Length()-1] == wxT('%')) { wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); } else { wxSscanf(wd.c_str(), wxT("%i"), &wdi); - SetWidthFloat(wdi, wxHTML_UNITS_PIXELS); + SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); } } } @@ -417,7 +447,7 @@ const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) co -void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right) +void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) { if (m_Cells) { wxHtmlCell *c = m_Cells; @@ -426,7 +456,7 @@ void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, bool left (c -> GetPosY() <= y) && (c -> GetPosX() + c -> GetWidth() > x) && (c -> GetPosY() + c -> GetHeight() > y)) { - c -> OnMouseClick(parent, x - c -> GetPosX(), y - c -> GetPosY(), left, middle, right); + c -> OnMouseClick(parent, x - c -> GetPosX(), y - c -> GetPosY(), event); break; } c = c -> GetNext(); @@ -473,13 +503,13 @@ void wxHtmlColourCell::DrawInvisible(wxDC& dc, int x, int y) void wxHtmlFontCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) { - dc.SetFont(*m_Font); + dc.SetFont(m_Font); wxHtmlCell::Draw(dc, x, y, view_y1, view_y2); } void wxHtmlFontCell::DrawInvisible(wxDC& dc, int x, int y) { - dc.SetFont(*m_Font); + dc.SetFont(m_Font); wxHtmlCell::DrawInvisible(dc, x, y); }