示例#1
0
mpz_class evaluatePolynomial(unsigned int x, const std::vector<mpz_class>& coefficients, const mpz_class& p)
{
    mpz_class result(0);
    mpz_class expX(1);
    for (size_t i = 0; i < coefficients.size(); ++i)
    {
        result = (result + (coefficients[i] * expX) % p) % p;
        expX = (expX * x) % p;
    }
    return result;
}
/*!
 * This method is called at the commencement of a visual drag. If the offsets
 * to the caret are too big, this method will adjust them and shift the image
 * of the dragged text to a comfortable distance fromthe caret.
 * Returns true if the offsets are shifted.
 * UT_sint32 x pos of the caret
 * UT_sint32 y pos of  the caret 
 */
bool FV_VisualDragText::reposOffsets(UT_sint32 x, UT_sint32 y)
{
  UT_sint32 dx = 0;
  UT_sint32 dy = 0;
  bool bAdjustX = false;
  bool bAdjustY = false;
  UT_sint32 iext = getGraphics()->tlu(3);
  dx = x - m_recCurFrame.left - m_recOrigLeft.width;
  dy = y - m_recCurFrame.top;
  UT_DEBUGMSG((" repos dx = %d \n",dx));
  UT_DEBUGMSG((" repos dy = %d \n",dy));
  UT_Rect expX(0,m_recCurFrame.top,0,m_recCurFrame.height);
  UT_Rect expY(m_recCurFrame.left,0,m_recCurFrame.width,0);
  if(abs(dx) > getGraphics()->tlu(40))
  {
    bAdjustX = true;
    dx -= getGraphics()->tlu(20);
    m_iInitialOffX -= dx;
    expX.set(0,m_recCurFrame.top,0,m_recCurFrame.height);
    m_recCurFrame.left += dx;
    m_recOrigLeft.left += dx;
    m_recOrigRight.left += dx;
  }
  if(dy > getGraphics()->tlu(40))
  {
    bAdjustY = true;
    dy -= getGraphics()->tlu(20);
    m_iInitialOffY -= dy;
    expY.set(m_recCurFrame.left,0,m_recCurFrame.width,0);
    m_recCurFrame.top += dy;
    m_recOrigLeft.top += dy;
    m_recOrigRight.top += dy;
  }

  if(bAdjustX && dx < 0)
  {
    expX.left = m_recCurFrame.left+m_recCurFrame.width -iext;
    expX.width = -dx + 2*iext;
    if(dy > 0)
    {
        expX.top -=  iext;
	expX.height += dy + 2*iext;
    }
    else
    {
	expX.top -=  iext;
	expX.height += (-dy + 2*iext);
    }
  }
  else if(bAdjustX)
  {
      expX.left = m_recCurFrame.left - dx - iext;
      expX.width = dx + 2*iext;
      if(dy > 0)
      {
	  expX.top -=  iext;
	  expX.height += dy + 2*iext;
      }
      else
      {
	  expX.top -= iext;
	  expX.height += (-dy + 2*iext);
      }
  }
  expY.left -= iext;
  expY.width += 2*iext;
  if(bAdjustY && dy < 0)
  {
        expY.top = m_recCurFrame.top + m_recCurFrame.height -iext;
	expY.height = -dy + 2*iext;
  }
  else if(bAdjustY)
  {
        expY.top = m_recCurFrame.top - dy - iext;
	expY.height = dy + 2*iext;
  }

  if(bAdjustX && expX.width > 0)
  {
      getGraphics()->setClipRect(&expX);
      m_pView->updateScreen(false);
  }
  if(bAdjustY && (expY.height > 0))
  {
      getGraphics()->setClipRect(&expY);
      m_pView->updateScreen(false);
  }
  if(bAdjustX || bAdjustY)
  {
      getGraphics()->setClipRect(NULL);
      drawImage();
      if(m_recOrigLeft.width > 0)
      {
	  getGraphics()->setClipRect(&m_recOrigLeft);
	  m_pView->updateScreen(false);
      }
      if(m_recOrigRight.width > 0)
      {
	  getGraphics()->setClipRect(&m_recOrigRight);
	  m_pView->updateScreen(false);
      }
      return true;
  }
  return false;
}
void FV_VisualDragText::_mouseDrag(UT_sint32 x, UT_sint32 y)
{
 	  //
	  // Don't try to drag the entire document.
	  //
  if(!m_bDoingCopy && (m_pView->isSelectAll() && !m_pView->isHdrFtrEdit())&&(m_iVisualDragMode != FV_VisualDrag_DRAGGING))
	 {
	     setMode(FV_VisualDrag_NOT_ACTIVE);
	     return;
	 }

        if(m_iVisualDragMode == FV_VisualDrag_NOT_ACTIVE)
        {
	  m_iInitialOffX = x;
	  m_iInitialOffY = y;
	  m_iVisualDragMode = FV_VisualDrag_WAIT_FOR_MOUSE_DRAG;
	  UT_DEBUGMSG(("Initial call for drag -1\n"));
	  return;
	}
	if((m_iInitialOffX == 0) && (m_iInitialOffY == 0))
	{
	  m_iInitialOffX = x;
	  m_iInitialOffY = y;
	  m_iVisualDragMode = FV_VisualDrag_WAIT_FOR_MOUSE_DRAG;
	  UT_DEBUGMSG(("Initial call for drag -2 \n"));
	}
	if(m_iVisualDragMode == FV_VisualDrag_WAIT_FOR_MOUSE_DRAG)
	{
          double diff = sqrt((static_cast<double>(x) - static_cast<double>(m_iInitialOffX))*(static_cast<double>(x) - static_cast<double>(m_iInitialOffX)) +
                              (static_cast<double>(y) - static_cast<double>(m_iInitialOffY))*(static_cast<double>(y) - static_cast<double>(m_iInitialOffY)));
          if(diff < static_cast<double>(getGraphics()->tlu(MIN_DRAG_PIXELS)))
          {
	    UT_DEBUGMSG(("Not yet dragged enough.%f \n", diff));
            //
            // Have to drag 4 pixels before initiating the drag
            //
            return;
          }
	  else
	  {
	    m_iVisualDragMode = FV_VisualDrag_START_DRAGGING;
	    XAP_Frame * pFrame = static_cast<XAP_Frame*>(m_pView->getParentData());
	    if (pFrame)
	      pFrame->dragText();
	  }
        }
	if((m_iVisualDragMode != FV_VisualDrag_DRAGGING) && (m_iVisualDragMode != FV_VisualDrag_WAIT_FOR_MOUSE_DRAG) && !m_bDoingCopy)
	{
//
// Haven't started the drag yet so create our image and cut the text.
//
		m_pView->getDocument()->beginUserAtomicGlob();
		mouseCut(m_iInitialOffX,m_iInitialOffY);
		m_bTextCut = true;

	}
	clearCursor();
	if(m_iVisualDragMode == FV_VisualDrag_START_DRAGGING)
	{
	  reposOffsets(x,y);
	}
	m_iVisualDragMode = FV_VisualDrag_DRAGGING;
	xxx_UT_DEBUGMSG(("x = %d y = %d width \n",x,y));
	bool bScrollDown = false;
	bool bScrollUp = false;
	bool bScrollLeft = false;
	bool bScrollRight = false;
	m_xLastMouse = x;
	m_yLastMouse = y;
	if(y<=0)
	{
		bScrollUp = true;
	}
	else if( y >= m_pView->getWindowHeight())
	{
		bScrollDown = true;
	}
	if(x <= 0)
	{
		bScrollLeft = true;
	}
	else if(x >= m_pView->getWindowWidth())
	{
		bScrollRight = true;
	}
	if(bScrollDown || bScrollUp || bScrollLeft || bScrollRight)
	{
		if(m_pAutoScrollTimer != NULL)
		{
			return;
		}
		m_pAutoScrollTimer = UT_Timer::static_constructor(_autoScroll, this);
		m_pAutoScrollTimer->set(AUTO_SCROLL_MSECS);
		m_pAutoScrollTimer->start();
		return;
	}
	UT_sint32 dx = 0;
	UT_sint32 dy = 0;
	UT_Rect expX(0,m_recCurFrame.top,0,m_recCurFrame.height);
	UT_Rect expY(m_recCurFrame.left,0,m_recCurFrame.width,0);
	UT_sint32 iext = getGraphics()->tlu(3);
	dx = x - m_iLastX;
	dy = y - m_iLastY;
	m_recCurFrame.left += dx;
	m_recCurFrame.top += dy;
	m_recOrigLeft.left += dx;
	m_recOrigLeft.top += dy;
	m_recOrigRight.left += dx;
	m_recOrigRight.top += dy;
	if(dx < 0)
	{
		expX.left = m_recCurFrame.left+m_recCurFrame.width -iext;
		expX.width = -dx + 2*iext;
		if(dy > 0)
		{
			expX.top -=  iext;
			expX.height += dy + 2*iext;
		}
		else
		{
			expX.top -=  iext;
			expX.height += (-dy + 2*iext);
		}
	}
	else
	{
		expX.left = m_recCurFrame.left - dx - iext;
		expX.width = dx + 2*iext;
		if(dy > 0)
		{
			expX.top -=  iext;
			expX.height += dy + 2*iext;
		}
		else
		{
			expX.top -= iext;
			expX.height += (-dy + 2*iext);
		}
	}
	expY.left -= iext;
	expY.width += 2*iext;
	if(dy < 0)
	{
		expY.top = m_recCurFrame.top + m_recCurFrame.height -iext;
		expY.height = -dy + 2*iext;
	}
	else
	{
		expY.top = m_recCurFrame.top - dy - iext;
		expY.height = dy + 2*iext;
	}

	if(!m_bNotDraggingImage && (expX.width > 0))
	{
		getGraphics()->setClipRect(&expX);
		if(m_bSelectedRow)

		{
		      m_pView->setSelectionMode(FV_SelectionMode_NONE);
		}
		m_pView->updateScreen(false);
		if(m_bSelectedRow)
		{
		      m_pView->setSelectionMode(FV_SelectionMode_TableRow);
		}

	}
	if(!m_bNotDraggingImage && (expY.height > 0))
	{
	  xxx_UT_DEBUGMSG(("expY left %d top %d width %d height %d \n",expY.left,expY.top,expY.width,expY.height));
		getGraphics()->setClipRect(&expY);
		if(m_bSelectedRow)
		{
		      m_pView->setSelectionMode(FV_SelectionMode_NONE);
		}
		m_pView->updateScreen(false);
		if(m_bSelectedRow)
		{
		      m_pView->setSelectionMode(FV_SelectionMode_TableRow);
		}

	}
	if(!m_bNotDraggingImage && (expX.height > 0))
	{
	  xxx_UT_DEBUGMSG(("expY left %d top %d width %d height %d \n",expX.left,expX.top,expX.width,expX.height));
		getGraphics()->setClipRect(&expX);
		if(m_bSelectedRow)
		{
		      m_pView->setSelectionMode(FV_SelectionMode_NONE);
		}
		m_pView->updateScreen(false);
		if(m_bSelectedRow)
		{
		      m_pView->setSelectionMode(FV_SelectionMode_TableRow);
		}

	}
	if(!m_bNotDraggingImage)
	{
	        getGraphics()->setClipRect(NULL);
		drawImage();
		if(m_recOrigLeft.width > 0)
		{
		     getGraphics()->setClipRect(&m_recOrigLeft);
		     m_pView->updateScreen(false);
		}
		if(m_recOrigRight.width > 0)
		{
		     getGraphics()->setClipRect(&m_recOrigRight);
		     m_pView->updateScreen(false);
		}
	}
	m_iLastX = x;
	m_iLastY = y;
	getGraphics()->setClipRect(NULL);
	PT_DocPosition posAtXY = getPosFromXY(x,y);
	m_pView->_setPoint(posAtXY);
	xxx_UT_DEBUGMSG(("Point at visual drag set to %d \n",m_pView->getPoint()));
//	m_pView->_fixInsertionPointCoords();
	drawCursor(posAtXY);
}