ccrystaleditview.cpp

来自「用bcg库编写的java IDE 源码」· C++ 代码 · 共 2,041 行 · 第 1/5 页

CPP
2,041
字号
              ptCursorPos.x = 0;
              ptCursorPos.y++;

              ASSERT_VALIDTEXTPOS (ptCursorPos);
              SetSelection (ptCursorPos, ptCursorPos);
              SetAnchor (ptCursorPos);
              SetCursorPos (ptCursorPos);
              EnsureVisible (ptCursorPos);
              return;
		  }
	  }

      m_pTextBuffer->BeginUndoGroup ();
	  int x1 =0;
	  int y1 =0;
      if(QueryEditable() && m_pTextBuffer != NULL)
	  {
          CPoint ptCursorPos;
          if(IsSelection ())
		  {
              CPoint ptSelStart, ptSelEnd;
              GetSelection (ptSelStart, ptSelEnd);
        
              ptCursorPos = ptSelStart;
              /*
			   SetAnchor (ptCursorPos);
               SetSelection (ptCursorPos, ptCursorPos);
               SetCursorPos (ptCursorPos);
               EnsureVisible (ptCursorPos);
			  */
        
              // [JRT]:
              m_pTextBuffer->DeleteTextExt(this, ptSelStart.y, ptSelStart.x, 
				         ptSelEnd.y, ptSelEnd.x, CE_ACTION_TYPING);
		  }
          else
          ptCursorPos = GetCursorPos();
          ASSERT_VALIDTEXTPOS (ptCursorPos);
          const static TCHAR pszText[3] = _T ("\r\n");
          
		  m_bDidInsert = TRUE;
          int x, y;
          m_pTextBuffer->InsertTextExt(this,ptCursorPos.y, ptCursorPos.x, pszText,
			                                y, x, CE_ACTION_TYPING);  //  [JRT]


		  //save start point before indentation operation
	      m_rcInsert.left   = ptCursorPos.x;
	      m_rcInsert.top    = ptCursorPos.y;
	      //m_rcInsert.right  = x;
	      //m_rcInsert.bottom = y;


          ptCursorPos.x = x;
          ptCursorPos.y = y;
          ASSERT_VALIDTEXTPOS(ptCursorPos);
          SetSelection(ptCursorPos,ptCursorPos);
          SetAnchor(ptCursorPos);
          SetCursorPos(ptCursorPos);
          EnsureVisible(ptCursorPos);
        }
      m_pTextBuffer->FlushUndoGroup(this);

	  //get actual insert end after indentation analysis
      CPoint ptCursor = GetCursorPos();
	  m_rcInsert.right = ptCursor.x;
	  m_rcInsert.bottom = ptCursor.y;

      return;
    }

  if(nChar > 31)
  {
      if(QueryEditable () && m_pTextBuffer != NULL)
	  {
          m_pTextBuffer->BeginUndoGroup (nChar != _T (' '));

          CPoint ptSelStart, ptSelEnd;
          GetSelection (ptSelStart, ptSelEnd);
          CPoint ptCursorPos;
          if(ptSelStart != ptSelEnd)
		  {
              ptCursorPos = ptSelStart;
              if(IsSelection ())
			  {
                  CPoint ptSelStart, ptSelEnd;
                  GetSelection (ptSelStart, ptSelEnd);
            
                  /*
				  SetAnchor (ptCursorPos);
                  SetSelection (ptCursorPos, ptCursorPos);
                  SetCursorPos (ptCursorPos);
                  EnsureVisible (ptCursorPos);
				  */
            
                  // [JRT]:
                  m_pTextBuffer->DeleteTextExt(this, ptSelStart.y, ptSelStart.x,
					  ptSelEnd.y, ptSelEnd.x, CE_ACTION_TYPING);
			  }
		  }
          else
          {
              ptCursorPos = GetCursorPos ();
              if(m_bOvrMode && ptCursorPos.x < GetLineLength (ptCursorPos.y))
                m_pTextBuffer->DeleteTextExt(this, ptCursorPos.y, ptCursorPos.x, 
				    ptCursorPos.y, ptCursorPos.x + 1, CE_ACTION_TYPING);// [JRT]
		  }

          ASSERT_VALIDTEXTPOS(ptCursorPos);

          TCHAR pszText[2];
          pszText[0] = (TCHAR) nChar;
          pszText[1] = 0;

		  m_bDidInsert = TRUE;
          int x, y;
          m_pTextBuffer->InsertTextExt(this,ptCursorPos.y,ptCursorPos.x,pszText, 
			                            y, x, CE_ACTION_TYPING);// [JRT]


	      m_rcInsert.left   = ptCursorPos.x;
	      m_rcInsert.top    = ptCursorPos.y;
	      //m_rcInsert.right  = x;
	      //m_rcInsert.bottom = y;


          ptCursorPos.x = x;
          ptCursorPos.y = y;
          ASSERT_VALIDTEXTPOS(ptCursorPos);
          SetSelection(ptCursorPos, ptCursorPos);
          SetAnchor(ptCursorPos);
          SetCursorPos(ptCursorPos);
          EnsureVisible(ptCursorPos);

		  //this function does all calls OnEditOperation , which does additional
		  //editing work
          m_pTextBuffer->FlushUndoGroup(this);

	      //get actual insert end after indentation analysis
          CPoint ptCursor = GetCursorPos();
	      m_rcInsert.right = ptCursor.x;
	      m_rcInsert.bottom = ptCursor.y;
        }
    }
}


//
//  [JRT]: Added Support For "Disable Backspace At Start Of Line"
//
void CCrystalEditView::OnEditDeleteBack ()
{
	//BEGIN SW
	// if we are in incremental search mode ignore backspace
  CCrystalTextView::OnEditDeleteBack();
  if(m_bIncrementalSearchForward || m_bIncrementalSearchBackward )
		return;
	//END SW

  if(IsSelection())
  {
     OnEditDelete();
     return;
  }

  if(!QueryEditable() || m_pTextBuffer == NULL)
    return;

  CPoint ptCursorPos = GetCursorPos ();
  CPoint ptCurrentCursorPos = ptCursorPos;
  bool bDeleted = false;

  if(!(ptCursorPos.x))         // If At Start Of Line
  {
      if(!m_bDisableBSAtSOL)   // If DBSASOL Is Disabled
      {
          if(ptCursorPos.y > 0)    // If Previous Lines Available
          {
             ptCursorPos.y--;  // Decrement To Previous Line

			 // Set Cursor To End Of Previous Line
             ptCursorPos.x = GetLineLength (ptCursorPos.y);

             bDeleted = true;  // Set Deleted Flag
		  }
	  }
  }
  else                          // If Caret Not At SOL
  {
     ptCursorPos.x--;          // Decrement Position
     bDeleted = true;          // Set Deleted Flag
  }
   /*
   if(ptCursorPos.x == 0)
   {
     if (ptCursorPos.y == 0)
     return;
     ptCursorPos.y --;
     ptCursorPos.x = GetLineLength(ptCursorPos.y);
   }
   else
   ptCursorPos.x --;
   */
  ASSERT_VALIDTEXTPOS (ptCursorPos);
  SetAnchor (ptCursorPos);
  SetSelection (ptCursorPos, ptCursorPos);
  SetCursorPos (ptCursorPos);
  EnsureVisible (ptCursorPos);

  if(bDeleted)
    m_pTextBuffer->DeleteTextExt(this,ptCursorPos.y,ptCursorPos.x,
		ptCurrentCursorPos.y, ptCurrentCursorPos.x, CE_ACTION_BACKSPACE);// [JRT]
  return;
}

void CCrystalEditView::OnEditTab()
{
  if (!QueryEditable () || m_pTextBuffer == NULL)
    return;

  BOOL bTabify = FALSE;
  CPoint ptSelStart, ptSelEnd;
  if (IsSelection ())
    {
      GetSelection (ptSelStart, ptSelEnd);
      bTabify = ptSelStart.y != ptSelEnd.y;
    }

  CPoint ptCursorPos = GetCursorPos ();
  ASSERT_VALIDTEXTPOS (ptCursorPos);

  static TCHAR pszText[32];
  if (m_bInsertTabs)
    {
      *pszText = _T ('\t');
      pszText[1] = _T ('\0');
    }
  else
    {
      int nTabSize = GetTabSize ();
      int nChars = nTabSize - ptCursorPos.x % nTabSize;
      memset(pszText, _T(' '), nChars);
      pszText[nChars] = _T ('\0');
    }

  if (bTabify)
    {
      m_pTextBuffer->BeginUndoGroup ();

      int nStartLine = ptSelStart.y;
      int nEndLine = ptSelEnd.y;
      ptSelStart.x = 0;
      if (ptSelEnd.x > 0)
        {
          if (ptSelEnd.y == GetLineCount () - 1)
            {
              ptSelEnd.x = GetLineLength (ptSelEnd.y);
            }
          else
            {
              ptSelEnd.x = 0;
              ptSelEnd.y++;
            }
        }
      else
        nEndLine--;
      SetSelection (ptSelStart, ptSelEnd);
      SetCursorPos (ptSelEnd);
      EnsureVisible (ptSelEnd);

      //  Shift selection to right
      m_bHorzScrollBarLocked = TRUE;
      for(int L = nStartLine; L <= nEndLine; L++)
	  {
         int x, y;
         m_pTextBuffer->InsertTextExt(this, L, 0, pszText, y, x, CE_ACTION_INDENT);  //  [JRT]
	  }
      m_bHorzScrollBarLocked = FALSE;
      RecalcHorzScrollBar ();

      m_pTextBuffer->FlushUndoGroup(this);
      return;
  }

  if(m_bOvrMode)
  {
      CPoint ptCursorPos = GetCursorPos ();
      ASSERT_VALIDTEXTPOS (ptCursorPos);

      int nLineLength = GetLineLength (ptCursorPos.y);
      LPCTSTR pszLineChars = GetLineChars (ptCursorPos.y);
      if(ptCursorPos.x < nLineLength)
	  {
          int nTabSize = GetTabSize ();
          int nChars = nTabSize - CalculateActualOffset (ptCursorPos.y, ptCursorPos.x) % nTabSize;
          ASSERT (nChars > 0 && nChars <= nTabSize);

          while(nChars > 0)
		  {
              if(ptCursorPos.x == nLineLength)
                break;
              if(pszLineChars[ptCursorPos.x] == _T ('\t'))
			  {
                  ptCursorPos.x++;
                  break;
			  }
              ptCursorPos.x++;
              nChars--;
		  }
          ASSERT (ptCursorPos.x <= nLineLength);
          ASSERT_VALIDTEXTPOS (ptCursorPos);

          SetSelection (ptCursorPos, ptCursorPos);
          SetAnchor (ptCursorPos);
          SetCursorPos (ptCursorPos);
          EnsureVisible (ptCursorPos);
          return;
	  }
  }

  m_pTextBuffer->BeginUndoGroup();

  if(IsSelection())
  {
      CPoint ptSelStart, ptSelEnd;
      GetSelection (ptSelStart, ptSelEnd);

      /*
	  SetAnchor (ptCursorPos);
      SetSelection (ptCursorPos, ptCursorPos);
      SetCursorPos (ptCursorPos);
      EnsureVisible (ptCursorPos);
	  */

      // [JRT]:
      m_pTextBuffer->DeleteTextExt(this, ptSelStart.y, ptSelStart.x, 
		  ptSelEnd.y, ptSelEnd.x, CE_ACTION_TYPING);
  }

  int x, y;
  m_pTextBuffer->InsertTextExt(this, ptCursorPos.y, ptCursorPos.x, 
	             pszText, y, x, CE_ACTION_TYPING);  //  [JRT]

  ptCursorPos.x = x;
  ptCursorPos.y = y;
  ASSERT_VALIDTEXTPOS (ptCursorPos);
  SetSelection (ptCursorPos, ptCursorPos);
  SetAnchor (ptCursorPos);
  SetCursorPos (ptCursorPos);
  EnsureVisible (ptCursorPos);

  m_pTextBuffer->FlushUndoGroup (this);
}

void CCrystalEditView::OnEditUntab()
{
  if (!QueryEditable () || m_pTextBuffer == NULL)
    return;

  BOOL bTabify = FALSE;
  CPoint ptSelStart, ptSelEnd;
  if(IsSelection())
  {
    GetSelection (ptSelStart, ptSelEnd);
    bTabify = ptSelStart.y != ptSelEnd.y;
  }

  if(bTabify)
  {
      m_pTextBuffer->BeginUndoGroup ();

      CPoint ptSelStart, ptSelEnd;
      GetSelection (ptSelStart, ptSelEnd);
      int nStartLine = ptSelStart.y;
      int nEndLine = ptSelEnd.y;
      ptSelStart.x = 0;
      if (ptSelEnd.x > 0)
        {
          if (ptSelEnd.y == GetLineCount () - 1)
            {
              ptSelEnd.x = GetLineLength (ptSelEnd.y);
            }
          else
            {
              ptSelEnd.x = 0;
              ptSelEnd.y++;
            }
        }
      else
        nEndLine--;
      SetSelection (ptSelStart, ptSelEnd);
      SetCursorPos (ptSelEnd);
      EnsureVisible (ptSelEnd);

      //  Shift selection to left
      m_bHorzScrollBarLocked = TRUE;
      for (int L = nStartLine; L <= nEndLine; L++)
        {
          int nLength = GetLineLength (L);
          if (nLength > 0)
            {
              LPCTSTR pszChars = GetLineChars (L);
              int nPos = 0, nOffset = 0;
              while (nPos < nLength)
                {
                  if (pszChars[nPos] == _T (' '))
                    {
                      nPos++;
                      if (++nOffset >= GetTabSize ())

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?