diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h index 1dfc31b5cd..472fffbc81 100644 --- a/include/wx/html/htmlwin.h +++ b/include/wx/html/htmlwin.h @@ -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); diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 0585f12a1a..f3c8bbf632 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -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)