예제 #1
0
void ME_MouseMove(ME_TextEditor *editor, int x, int y)
{
  ME_Cursor tmp_cursor;

  if (editor->nSelectionType == stDocument)
      return;
  x += editor->horz_si.nPos;
  y += editor->vert_si.nPos;

  tmp_cursor = editor->pCursors[0];
  /* FIXME: do something with the return value of ME_FindPixelPos */
  ME_FindPixelPos(editor, x, y, &tmp_cursor, &editor->bCaretAtEnd);

  ME_InvalidateSelection(editor);
  editor->pCursors[0] = tmp_cursor;
  ME_ExtendAnchorSelection(editor);

  if (editor->nSelectionType != stPosition &&
      memcmp(&editor->pCursors[1], &editor->pCursors[3], sizeof(ME_Cursor)))
  {
      /* The scroll the cursor towards the other end, since it was the one
       * extended by ME_ExtendAnchorSelection */
      ME_EnsureVisible(editor, &editor->pCursors[1]);
  } else {
      ME_EnsureVisible(editor, &editor->pCursors[0]);
  }

  ME_InvalidateSelection(editor);
  HideCaret(editor->hWnd);
  ME_ShowCaret(editor);
  ME_SendSelChange(editor);
}
예제 #2
0
void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
{
    /* FIXME: Shift tab should move to the previous cell. */
    ME_Cursor fromCursor, toCursor;
    ME_InvalidateSelection(editor);
    {
        int from, to;
        from = ME_GetCursorOfs(editor, 0);
        to = ME_GetCursorOfs(editor, 1);
        if (from <= to)
        {
            fromCursor = editor->pCursors[0];
            toCursor = editor->pCursors[1];
        } else {
            fromCursor = editor->pCursors[1];
            toCursor = editor->pCursors[0];
        }
    }
    if (!editor->bEmulateVersion10) /* v4.1 */
    {
        if (!ME_IsInTable(toCursor.pRun))
        {
            editor->pCursors[0] = toCursor;
            editor->pCursors[1] = toCursor;
        } else {
            ME_SelectOrInsertNextCell(editor, toCursor.pRun);
        }
    } else { /* v1.0 - 3.0 */
        if (!ME_IsInTable(fromCursor.pRun)) {
            editor->pCursors[0] = fromCursor;
            editor->pCursors[1] = fromCursor;
            /* FIXME: For some reason the caret is shown at the start of the
             *        previous paragraph in v1.0 to v3.0, and bCaretAtEnd only works
             *        within the paragraph for wrapped lines. */
            if (ME_FindItemBack(fromCursor.pRun, diRun))
                editor->bCaretAtEnd = TRUE;
        } else if ((bSelectedRow || !ME_IsInTable(toCursor.pRun))) {
            ME_SelectOrInsertNextCell(editor, fromCursor.pRun);
        } else {
            if (ME_IsSelection(editor) && !toCursor.nOffset)
            {
                ME_DisplayItem *run;
                run = ME_FindItemBack(toCursor.pRun, diRunOrParagraphOrEnd);
                if (run->type == diRun && run->member.run.nFlags & MERF_TAB)
                    ME_SelectOrInsertNextCell(editor, run);
                else
                    ME_SelectOrInsertNextCell(editor, toCursor.pRun);
            } else {
                ME_SelectOrInsertNextCell(editor, toCursor.pRun);
            }
        }
    }
    ME_InvalidateSelection(editor);
    ME_Repaint(editor);
    HideCaret(editor->hWnd);
    ME_ShowCaret(editor);
    ME_SendSelChange(editor);
}
예제 #3
0
BOOL
ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
{
  int nCursor = 0;
  ME_Cursor *p = &editor->pCursors[nCursor];
  ME_Cursor tmp_curs = *p;
  BOOL success = FALSE;

  ME_CheckCharOffsets(editor);
  switch(nVKey) {
    case VK_LEFT:
      editor->bCaretAtEnd = 0;
      if (ctrl)
        success = ME_MoveCursorWords(editor, &tmp_curs, -1);
      else
        success = ME_MoveCursorChars(editor, &tmp_curs, -1);
      break;
    case VK_RIGHT:
      editor->bCaretAtEnd = 0;
      if (ctrl)
        success = ME_MoveCursorWords(editor, &tmp_curs, +1);
      else
        success = ME_MoveCursorChars(editor, &tmp_curs, +1);
      break;
    case VK_UP:
      ME_MoveCursorLines(editor, &tmp_curs, -1);
      break;
    case VK_DOWN:
      ME_MoveCursorLines(editor, &tmp_curs, +1);
      break;
    case VK_PRIOR:
      ME_ArrowPageUp(editor, &tmp_curs);
      break;
    case VK_NEXT:
      ME_ArrowPageDown(editor, &tmp_curs);
      break;
    case VK_HOME: {
      if (ctrl)
        ME_ArrowCtrlHome(editor, &tmp_curs);
      else
        ME_ArrowHome(editor, &tmp_curs);
      editor->bCaretAtEnd = 0;
      break;
    }
    case VK_END:
      if (ctrl)
        ME_ArrowCtrlEnd(editor, &tmp_curs);
      else
        ME_ArrowEnd(editor, &tmp_curs);
      break;
  }

  if (!extend)
    editor->pCursors[1] = tmp_curs;
  *p = tmp_curs;

  ME_InvalidateSelection(editor);
  ME_Repaint(editor);
  HideCaret(editor->hWnd);
  ME_EnsureVisible(editor, &tmp_curs);
  ME_ShowCaret(editor);
  ME_SendSelChange(editor);
  return success;
}
예제 #4
0
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
{
  ME_Cursor tmp_cursor;
  int is_selection = 0;
  BOOL is_shift;

  editor->nUDArrowX = -1;

  x += editor->horz_si.nPos;
  y += editor->vert_si.nPos;

  tmp_cursor = editor->pCursors[0];
  is_selection = ME_IsSelection(editor);
  is_shift = GetKeyState(VK_SHIFT) < 0;

  ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd);

  if (x >= editor->rcFormat.left || is_shift)
  {
    if (clickNum > 1)
    {
      editor->pCursors[1] = editor->pCursors[0];
      if (is_shift) {
          if (x >= editor->rcFormat.left)
              ME_SelectByType(editor, stWord);
          else
              ME_SelectByType(editor, stParagraph);
      } else if (clickNum % 2 == 0) {
          ME_SelectByType(editor, stWord);
      } else {
          ME_SelectByType(editor, stParagraph);
      }
    }
    else if (!is_shift)
    {
      editor->nSelectionType = stPosition;
      editor->pCursors[1] = editor->pCursors[0];
    }
    else if (!is_selection)
    {
      editor->nSelectionType = stPosition;
      editor->pCursors[1] = tmp_cursor;
    }
    else if (editor->nSelectionType != stPosition)
    {
      ME_ExtendAnchorSelection(editor);
    }
  }
  else
  {
    if (clickNum < 2) {
        ME_SelectByType(editor, stLine);
    } else if (clickNum % 2 == 0 || is_shift) {
        ME_SelectByType(editor, stParagraph);
    } else {
        ME_SelectByType(editor, stDocument);
    }
  }
  ME_InvalidateSelection(editor);
  HideCaret(editor->hWnd);
  ME_ShowCaret(editor);
  ME_ClearTempStyle(editor);
  ME_SendSelChange(editor);
}