Redraw selection in wxHtmlWindow on focus event

This commit is contained in:
Pavel Kalugin 2019-04-09 07:02:02 +03:00 committed by Vadim Zeitlin
parent ef524931cc
commit 3db142e58f
2 changed files with 27 additions and 0 deletions

View File

@ -408,6 +408,7 @@ protected:
void OnMouseMove(wxMouseEvent& event);
void OnMouseDown(wxMouseEvent& event);
void OnMouseUp(wxMouseEvent& event);
void OnFocusEvent(wxFocusEvent& event);
#if wxUSE_CLIPBOARD
void OnKeyUp(wxKeyEvent& event);
void OnDoubleClick(wxMouseEvent& event);

View File

@ -1184,7 +1184,31 @@ void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
}
}
void wxHtmlWindow::OnFocusEvent(wxFocusEvent& event)
{
event.Skip();
// Redraw selection, because its background colour depends on
// whether the window has keyboard focus or not.
if ( !m_selection || m_selection->IsEmpty() )
return;
const wxHtmlCell* fromCell = m_selection->GetFromCell();
const wxHtmlCell* toCell = m_selection->GetToCell();
wxCHECK_RET(fromCell || toCell,
"Unexpected: selection is set but cells are not");
if ( !fromCell )
fromCell = toCell;
if ( !toCell )
toCell = fromCell;
const wxPoint topLeft = fromCell->GetAbsPos();
const wxPoint bottomRight = toCell->GetAbsPos() +
wxSize(toCell->GetWidth(), toCell->GetHeight());
RefreshRect(wxRect(CalcScrolledPosition(topLeft),
CalcScrolledPosition(bottomRight)));
}
void wxHtmlWindow::OnSize(wxSizeEvent& event)
@ -1656,6 +1680,8 @@ wxBEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
EVT_MOTION(wxHtmlWindow::OnMouseMove)
EVT_PAINT(wxHtmlWindow::OnPaint)
EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground)
EVT_SET_FOCUS(wxHtmlWindow::OnFocusEvent)
EVT_KILL_FOCUS(wxHtmlWindow::OnFocusEvent)
#if wxUSE_CLIPBOARD
EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick)
EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter)