X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8eb3a3a923b1dc0dd736643e85ba2711d0ae3c6d..65669e3152f9d6d3bb77c31d4211a356fe089d56:/src/html/htmlcell.cpp?ds=sidebyside diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index e0ca15d66e..01d92107bd 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -464,6 +464,8 @@ void wxHtmlWordCell::Split(const wxDC& dc, pos1 = i; pos2 = j; + + wxASSERT( pos2 >= pos1 ); } void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const @@ -497,18 +499,18 @@ static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info, if ( toSelection ) { - dc.SetBackgroundMode(wxSOLID); + dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg)); dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg)); dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg), - wxSOLID)); + wxBRUSHSTYLE_SOLID)); } else { - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); dc.SetTextForeground(fg); dc.SetTextBackground(bg); - dc.SetBackground(wxBrush(bg, wxSOLID)); + dc.SetBackground(wxBrush(bg, wxBRUSHSTYLE_SOLID)); } } @@ -579,12 +581,12 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); // Not changing selection state, draw the word in single mode: if ( selstate != wxHTML_SEL_OUT && - dc.GetBackgroundMode() != wxSOLID ) + dc.GetBackgroundMode() != wxBRUSHSTYLE_SOLID ) { SwitchSelState(dc, info, true); } else if ( selstate == wxHTML_SEL_OUT && - dc.GetBackgroundMode() == wxSOLID ) + dc.GetBackgroundMode() == wxBRUSHSTYLE_SOLID ) { SwitchSelState(dc, info, false); } @@ -617,6 +619,17 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, } } +wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const +{ + if ( !GetLink() ) + { + return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text); + } + else + { + return wxHtmlCell::GetMouseCursor(window); + } +} wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const { @@ -634,29 +647,77 @@ wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const // TODO: but this really needs to be fixed in some better way later... if ( priv != wxDefaultPosition ) { - int part1 = priv.x; - int part2 = priv.y; - return m_Word.Mid(part1, part2-part1); + const int part1 = priv.x; + const int part2 = priv.y; + if ( part1 == part2 ) + return wxEmptyString; + return GetPartAsText(part1, part2); } //else: return the whole word below } - return m_Word; + return GetAllAsText(); } -wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const +wxString wxHtmlWordWithTabsCell::GetAllAsText() const { - if ( !GetLink() ) + return m_wordOrig; +} + +wxString wxHtmlWordWithTabsCell::GetPartAsText(int begin, int end) const +{ + // NB: The 'begin' and 'end' positions are in the _displayed_ text + // (stored in m_Word) and not in the text with tabs that should + // be copied to clipboard (m_wordOrig). + // + // NB: Because selection is performed on displayed text, it's possible + // to select e.g. "half of TAB character" -- IOW, 'begin' and 'end' + // may be in the middle of TAB character expansion into ' 's. In this + // case, we copy the TAB character to clipboard once. + + wxASSERT( begin < end ); + + const unsigned SPACES_PER_TAB = 8; + + wxString sel; + + int pos = 0; + wxString::const_iterator i = m_wordOrig.begin(); + + // find the beginning of text to copy: + for ( ; pos < begin; ++i ) { - return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text); + if ( *i == '\t' ) + { + pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; + if ( pos >= begin ) + { + sel += '\t'; + } + } + else + { + ++pos; + } } - else + + // copy the content until we reach 'end': + for ( ; pos < end; ++i ) { - return wxHtmlCell::GetMouseCursor(window); + const wxChar c = *i; + sel += c; + + if ( c == '\t' ) + pos += 8 - (m_linepos + pos) % SPACES_PER_TAB; + else + ++pos; } + + return sel; } + //----------------------------------------------------------------------------- // wxHtmlContainerCell //----------------------------------------------------------------------------- @@ -755,7 +816,9 @@ void wxHtmlContainerCell::Layout(int w) { wxHtmlCell::Layout(w); - if (m_LastLayout == w) return; + if (m_LastLayout == w) + return; + m_LastLayout = w; // VS: Any attempt to layout with negative or zero width leads to hell, // but we can't ignore such attempts completely, since it sometimes @@ -1011,8 +1074,6 @@ void wxHtmlContainerCell::Layout(int w) m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; - - m_LastLayout = w; } void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, @@ -1053,7 +1114,7 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, if (m_UseBkColour) { - wxBrush myb = wxBrush(m_BkColour, wxSOLID); + wxBrush myb = wxBrush(m_BkColour, wxBRUSHSTYLE_SOLID); int real_y1 = mMax(ylocal, view_y1); int real_y2 = mMin(ylocal + m_Height - 1, view_y2); @@ -1065,8 +1126,8 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, if (m_UseBorder) { - wxPen mypen1(m_BorderColour1, 1, wxSOLID); - wxPen mypen2(m_BorderColour2, 1, wxSOLID); + wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID); + wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID); dc.SetPen(mypen1); dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1); @@ -1453,13 +1514,13 @@ void wxHtmlColourCell::DrawInvisible(wxDC& dc, if (state.GetSelectionState() != wxHTML_SEL_IN) { dc.SetTextBackground(m_Colour); - dc.SetBackground(wxBrush(m_Colour, wxSOLID)); + dc.SetBackground(wxBrush(m_Colour, wxBRUSHSTYLE_SOLID)); } else { wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour); dc.SetTextBackground(c); - dc.SetBackground(wxBrush(c, wxSOLID)); + dc.SetBackground(wxBrush(c, wxBRUSHSTYLE_SOLID)); } } }