void ME_LButtonDown(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; int is_selection = 0; editor->nUDArrowX = -1; y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; is_selection = ME_IsSelection(editor); ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd); if (GetKeyState(VK_SHIFT)>=0) { editor->pCursors[1] = editor->pCursors[0]; } else { if (!is_selection) { editor->pCursors[1] = tmp_cursor; is_selection = 1; } } ME_InvalidateSelection(editor); HideCaret(editor->hWnd); ME_MoveCaret(editor); ShowCaret(editor->hWnd); ME_ClearTempStyle(editor); ME_SendSelChange(editor); }
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); }
void ME_MouseMove(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; /* FIXME: do something with the return value of ME_FindPixelPos */ if (!editor->linesel) ME_FindPixelPos(editor, x, y, &tmp_cursor, &editor->bCaretAtEnd); else ME_FindPixelPos(editor, (y > editor->sely) * editor->rcFormat.right, y, &tmp_cursor, &editor->bCaretAtEnd); if (!memcmp(&tmp_cursor, editor->pCursors, sizeof(tmp_cursor))) return; ME_InvalidateSelection(editor); if (!editor->linesel) editor->pCursors[0] = tmp_cursor; else if (!memcmp(&tmp_cursor, editor->pCursors+2, sizeof(tmp_cursor)) || !memcmp(&tmp_cursor, editor->pCursors+3, sizeof(tmp_cursor))) { editor->pCursors[0] = editor->pCursors[2]; editor->pCursors[1] = editor->pCursors[3]; } else if (y < editor->sely) { editor->pCursors[0] = tmp_cursor; editor->pCursors[1] = editor->pCursors[2]; } else { editor->pCursors[0] = tmp_cursor; editor->pCursors[1] = editor->pCursors[3]; } HideCaret(editor->hWnd); ME_MoveCaret(editor); ME_InvalidateSelection(editor); ShowCaret(editor->hWnd); ME_SendSelChange(editor); }
int ME_CharFromPos(ME_TextEditor *editor, int x, int y) { ME_Cursor cursor; RECT rc; GetClientRect(editor->hWnd, &rc); if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) return -1; y += ME_GetYScrollPos(editor); ME_FindPixelPos(editor, x, y, &cursor, NULL); return (ME_GetParagraph(cursor.pRun)->member.para.nCharOfs + cursor.pRun->member.run.nCharOfs + cursor.nOffset); }
/* Sets the cursor to the position closest to the pixel position * * x & y are pixel positions in client coordinates. * * isExact will be set to TRUE if the run is directly under the pixel * position, FALSE if it not, unless isExact is set to NULL. * * return FALSE if outside client area and the cursor is not set, * otherwise TRUE is returned. */ BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y, ME_Cursor *cursor, BOOL *isExact) { RECT rc; BOOL bResult; ITextHost_TxGetClientRect(editor->texthost, &rc); if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) { if (isExact) *isExact = FALSE; return FALSE; } x += editor->horz_si.nPos; y += editor->vert_si.nPos; bResult = ME_FindPixelPos(editor, x, y, cursor, NULL); if (isExact) *isExact = bResult; return TRUE; }
/* Returns the character offset closest to the pixel position * * x & y are pixel positions in client coordinates. * * isExact will be set to TRUE if the run is directly under the pixel * position, FALSE if it not, unless isExact is set to NULL. */ int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact) { ME_Cursor cursor; RECT rc; BOOL bResult; GetClientRect(editor->hWnd, &rc); if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) { if (isExact) *isExact = FALSE; return -1; } x += editor->horz_si.nPos; y += editor->vert_si.nPos; bResult = ME_FindPixelPos(editor, x, y, &cursor, NULL); if (isExact) *isExact = bResult; return (ME_GetParagraph(cursor.pRun)->member.para.nCharOfs + cursor.pRun->member.run.nCharOfs + cursor.nOffset); }
void ME_MouseMove(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; /* FIXME: do something with the return value of ME_FindPixelPos */ ME_FindPixelPos(editor, x, y, &tmp_cursor, &editor->bCaretAtEnd); if (tmp_cursor.pRun == editor->pCursors[0].pRun && tmp_cursor.nOffset == editor->pCursors[0].nOffset) return; ME_InvalidateSelection(editor); editor->pCursors[0] = tmp_cursor; HideCaret(editor->hWnd); ME_MoveCaret(editor); ME_InvalidateSelection(editor); ShowCaret(editor->hWnd); ME_SendSelChange(editor); }
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); }
void ME_LButtonDown(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; int is_selection = 0; editor->nUDArrowX = -1; y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; is_selection = ME_IsSelection(editor); if (x >= editor->selofs) { ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd); if (GetKeyState(VK_SHIFT)>=0) { editor->pCursors[1] = editor->pCursors[0]; } else if (!is_selection) { editor->pCursors[1] = tmp_cursor; is_selection = 1; } ME_InvalidateSelection(editor); HideCaret(editor->hWnd); ME_MoveCaret(editor); ShowCaret(editor->hWnd); ME_ClearTempStyle(editor); ME_SendSelChange(editor); } else { ME_DisplayItem *pRow; editor->linesel = 1; editor->sely = y; /* Set pCursors[0] to beginning of line */ ME_FindPixelPos(editor, x, y, &editor->pCursors[1], &editor->bCaretAtEnd); /* Set pCursors[1] to end of line */ pRow = ME_FindItemFwd(editor->pCursors[1].pRun, diStartRowOrParagraphOrEnd); assert(pRow); /* pCursor[0] is the position where the cursor will be drawn, * pCursor[1] is the other end of the selection range * pCursor[2] and [3] are backups of [0] and [1] so I * don't have to look them up again */ if (pRow->type == diStartRow) { /* FIXME WTF was I thinking about here ? */ ME_DisplayItem *pRun = ME_FindItemFwd(pRow, diRun); assert(pRun); editor->pCursors[0].pRun = pRun; editor->pCursors[0].nOffset = 0; editor->bCaretAtEnd = 1; } else { editor->pCursors[0].pRun = ME_FindItemBack(pRow, diRun); assert(editor->pCursors[0].pRun && editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA); editor->pCursors[0].nOffset = 0; editor->bCaretAtEnd = 0; } editor->pCursors[2] = editor->pCursors[0]; editor->pCursors[3] = editor->pCursors[1]; ME_InvalidateSelection(editor); HideCaret(editor->hWnd); ME_MoveCaret(editor); ShowCaret(editor->hWnd); ME_ClearTempStyle(editor); ME_SendSelChange(editor); } }