+ CaptureMouse();
+ }
+ }
+#endif // wxUSE_CLIPBOARD
+}
+
+void wxHtmlWindow::OnMouseUp(wxMouseEvent& event)
+{
+#if wxUSE_CLIPBOARD
+ if ( m_makingSelection )
+ {
+ ReleaseMouse();
+ m_makingSelection = false;
+
+ // did the user move the mouse far enough from starting point?
+ if ( m_selection )
+ {
+ CopySelection(Primary);
+
+ // we don't want mouse up event that ended selecting to be
+ // handled as mouse click and e.g. follow hyperlink:
+ return;
+ }
+ }
+#endif // wxUSE_CLIPBOARD
+
+ SetFocus();
+ if ( m_Cell )
+ {
+ wxPoint pos = CalcUnscrolledPosition(event.GetPosition());
+ wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y);
+
+ // check is needed because FindCellByPos returns terminal cell and
+ // containers may have empty borders -- in this case NULL will be
+ // returned
+ if ( cell )
+ OnCellClicked(cell, pos.x, pos.y, event);
+ }
+}
+
+
+
+void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
+{
+ if (m_tmpMouseMoved && (m_Cell != NULL))
+ {
+ int xc, yc, x, y;
+ wxGetMousePosition(&xc, &yc);
+ ScreenToClient(&xc, &yc);
+ CalcUnscrolledPosition(xc, yc, &x, &y);
+
+ wxHtmlCell *cell = m_Cell->FindCellByPos(x, y);
+
+ // handle selection update:
+ if ( m_makingSelection )
+ {
+ bool goingDown = m_tmpSelFromPos.y < y ||
+ m_tmpSelFromPos.y == y && m_tmpSelFromPos.x < x;
+
+ if ( !m_tmpSelFromCell )
+ {
+ if (goingDown)
+ {
+ m_tmpSelFromCell = m_Cell->FindCellByPos(
+ m_tmpSelFromPos.x,m_tmpSelFromPos.y,
+ wxHTML_FIND_NEAREST_AFTER);
+ if (!m_tmpSelFromCell)
+ m_tmpSelFromCell = m_Cell->GetFirstTerminal();
+ }
+ else
+ {
+ m_tmpSelFromCell = m_Cell->FindCellByPos(
+ m_tmpSelFromPos.x,m_tmpSelFromPos.y,
+ wxHTML_FIND_NEAREST_BEFORE);
+ if (!m_tmpSelFromCell)
+ m_tmpSelFromCell = m_Cell->GetLastTerminal();
+ }
+ }
+
+ wxHtmlCell *selcell = cell;
+ if (!selcell)
+ {
+ if (goingDown)
+ {
+ selcell = m_Cell->FindCellByPos(x, y,
+ wxHTML_FIND_NEAREST_AFTER);
+ if (!selcell)
+ selcell = m_Cell->GetLastTerminal();
+ }
+ else
+ {
+ selcell = m_Cell->FindCellByPos(x, y,
+ wxHTML_FIND_NEAREST_BEFORE);
+ if (!selcell)
+ selcell = m_Cell->GetFirstTerminal();
+ }
+ }
+
+ // NB: it may *rarely* happen that the code above didn't find one
+ // of the cells, e.g. if wxHtmlWindow doesn't contain any
+ // visible cells.
+ if ( selcell && m_tmpSelFromCell )
+ {
+ if ( !m_selection )
+ {
+ // start selecting only if mouse movement was big enough
+ // (otherwise it was meant as mouse click, not selection):
+ const int PRECISION = 2;
+ wxPoint diff = m_tmpSelFromPos - wxPoint(x,y);
+ if (abs(diff.x) > PRECISION || abs(diff.y) > PRECISION)
+ {
+ m_selection = new wxHtmlSelection();
+ }
+ }
+ if ( m_selection )
+ {
+ if ( m_tmpSelFromCell->IsBefore(selcell) )
+ {
+ m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell,
+ wxPoint(x,y), selcell); }
+ else
+ {
+ m_selection->Set(wxPoint(x,y), selcell,
+ m_tmpSelFromPos, m_tmpSelFromCell);
+ }
+ m_selection->ClearPrivPos();
+ Refresh();
+ }
+ }
+ }
+
+ // handle cursor and status bar text changes:
+ if ( cell != m_tmpLastCell )
+ {
+ wxHtmlLinkInfo *lnk = cell ? cell->GetLink(x, y) : NULL;
+ wxCursor cur;
+ if (cell)
+ cur = cell->GetCursor();
+ else
+ cur = *wxSTANDARD_CURSOR;
+ SetCursor(cur);
+
+ if (lnk != m_tmpLastLink)
+ {
+ if (lnk == NULL)
+ {
+ if (m_RelatedStatusBar != -1)
+ m_RelatedFrame->SetStatusText(wxEmptyString,
+ m_RelatedStatusBar);
+ }
+ else
+ {
+ if (m_RelatedStatusBar != -1)
+ m_RelatedFrame->SetStatusText(lnk->GetHref(),
+ m_RelatedStatusBar);
+ }
+ m_tmpLastLink = lnk;
+ }
+
+ m_tmpLastCell = cell;
+ }
+ else // mouse moved but stayed in the same cell
+ {
+ if ( cell )
+ OnCellMouseHover(cell, x, y);
+ }
+
+ m_tmpMouseMoved = FALSE;