+#if wxUSE_CLIPBOARD
+ if ( event.LeftDown() && IsSelectionEnabled() )
+ {
+ const long TRIPLECLICK_LEN = 200; // 0.2 sec after doubleclick
+ if ( wxGetLocalTimeMillis() - m_lastDoubleClick <= TRIPLECLICK_LEN )
+ {
+ SelectLine(CalcUnscrolledPosition(event.GetPosition()));
+
+ (void) CopySelection();
+ }
+ else
+ {
+ m_makingSelection = true;
+
+ if ( m_selection )
+ {
+ wxDELETE(m_selection);
+ Refresh();
+ }
+ m_tmpSelFromPos = CalcUnscrolledPosition(event.GetPosition());
+ m_tmpSelFromCell = NULL;
+
+ 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 ( 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::OnInternalIdle()
+{
+ wxWindow::OnInternalIdle();
+
+ if (m_tmpMouseMoved && (m_Cell != NULL))
+ {
+#ifdef DEBUG_HTML_SELECTION
+ Refresh();
+#endif
+ 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 )
+ {
+ if ( !m_tmpSelFromCell )
+ m_tmpSelFromCell = m_Cell->FindCellByPos(
+ m_tmpSelFromPos.x,m_tmpSelFromPos.y);
+
+ // NB: a trick - we adjust selFromPos to be upper left or bottom
+ // right corner of the first cell of the selection depending
+ // on whether the mouse is moving to the right or to the left.
+ // This gives us more "natural" behaviour when selecting
+ // a line (specifically, first cell of the next line is not
+ // included if you drag selection from left to right over
+ // entire line):
+ wxPoint dirFromPos;
+ if ( !m_tmpSelFromCell )
+ {
+ dirFromPos = m_tmpSelFromPos;
+ }
+ else
+ {
+ dirFromPos = m_tmpSelFromCell->GetAbsPos();
+ if ( x < m_tmpSelFromPos.x )
+ {
+ dirFromPos.x += m_tmpSelFromCell->GetWidth();
+ dirFromPos.y += m_tmpSelFromCell->GetHeight();
+ }
+ }
+ bool goingDown = dirFromPos.y < y ||
+ (dirFromPos.y == y && dirFromPos.x < x);
+
+ // determine selection span:
+ if ( /*still*/ !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_BEFORE);
+ if (!selcell)
+ selcell = m_Cell->GetLastTerminal();
+ }
+ else
+ {
+ selcell = m_Cell->FindCellByPos(x, y,
+ wxHTML_FIND_NEAREST_AFTER);
+ if (!selcell)
+ selcell = m_Cell->GetFirstTerminal();
+ }
+ }