void ME_SendSelChange(ME_TextEditor *editor) { SELCHANGE sc; if (!(editor->nEventMask & ENM_SELCHANGE)) return; sc.nmhdr.hwndFrom = NULL; sc.nmhdr.idFrom = 0; sc.nmhdr.code = EN_SELCHANGE; ME_GetSelectionOfs(editor, &sc.chrg.cpMin, &sc.chrg.cpMax); sc.seltyp = SEL_EMPTY; if (sc.chrg.cpMin != sc.chrg.cpMax) sc.seltyp |= SEL_TEXT; if (sc.chrg.cpMin < sc.chrg.cpMax+1) /* what were RICHEDIT authors thinking ? */ sc.seltyp |= SEL_MULTICHAR; TRACE("cpMin=%d cpMax=%d seltyp=%d (%s %s)\n", sc.chrg.cpMin, sc.chrg.cpMax, sc.seltyp, (sc.seltyp & SEL_TEXT) ? "SEL_TEXT" : "", (sc.seltyp & SEL_MULTICHAR) ? "SEL_MULTICHAR" : ""); if (sc.chrg.cpMin != editor->notified_cr.cpMin || sc.chrg.cpMax != editor->notified_cr.cpMax) { ME_ClearTempStyle(editor); editor->notified_cr = sc.chrg; ITextHost_TxNotify(editor->texthost, sc.nmhdr.code, &sc); } }
void ME_SendSelChange(ME_TextEditor *editor) { SELCHANGE sc; if (!(editor->nEventMask & ENM_SELCHANGE)) return; sc.nmhdr.code = EN_SELCHANGE; ME_GetSelection(editor, &sc.chrg.cpMin, &sc.chrg.cpMax); sc.seltyp = SEL_EMPTY; if (sc.chrg.cpMin != sc.chrg.cpMax) sc.seltyp |= SEL_TEXT; if (sc.chrg.cpMin < sc.chrg.cpMax+1) /* wth were RICHEDIT authors thinking ? */ sc.seltyp |= SEL_MULTICHAR; TRACE("cpMin=%d cpMax=%d seltyp=%d (%s %s)\n", sc.chrg.cpMin, sc.chrg.cpMax, sc.seltyp, (sc.seltyp & SEL_TEXT) ? "SEL_TEXT" : "", (sc.seltyp & SEL_MULTICHAR) ? "SEL_MULTICHAR" : ""); if (sc.chrg.cpMin != editor->notified_cr.cpMin || sc.chrg.cpMax != editor->notified_cr.cpMax) { ME_ClearTempStyle(editor); editor->notified_cr = sc.chrg; SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, sc.nmhdr.idFrom, (LPARAM)&sc); } }
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_SendSelChange(ME_TextEditor *editor) { SELCHANGE sc; ME_ClearTempStyle(editor); if (!(editor->nEventMask & ENM_SELCHANGE)) return; sc.nmhdr.hwndFrom = editor->hWnd; sc.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); sc.nmhdr.code = EN_SELCHANGE; SendMessageW(editor->hWnd, EM_EXGETSEL, 0, (LPARAM)&sc.chrg); sc.seltyp = SEL_EMPTY; if (sc.chrg.cpMin != sc.chrg.cpMax) sc.seltyp |= SEL_TEXT; if (sc.chrg.cpMin < sc.chrg.cpMax+1) /* wth were RICHEDIT authors thinking ? */ sc.seltyp |= SEL_MULTICHAR; SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, sc.nmhdr.idFrom, (LPARAM)&sc); }
int ME_SetSelection(ME_TextEditor *editor, int from, int to) { int selectionEnd = 0; const int len = ME_GetTextLength(editor); /* all negative values are effectively the same */ if (from < 0) from = -1; if (to < 0) to = -1; /* select all */ if (from == 0 && to == -1) { editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); editor->pCursors[1].nOffset = 0; editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); editor->pCursors[0].nOffset = 0; ME_InvalidateSelection(editor); ME_ClearTempStyle(editor); return len + 1; } /* if both values are equal and also out of bound, that means to */ /* put the selection at the end of the text */ if ((from == to) && (to < 0 || to > len)) { selectionEnd = 1; } else { /* if from is negative and to is positive then selection is */ /* deselected and caret moved to end of the current selection */ if (from < 0) { int start, end; ME_GetSelection(editor, &start, &end); editor->pCursors[1] = editor->pCursors[0]; ME_Repaint(editor); ME_ClearTempStyle(editor); return end; } /* adjust to if it's a negative value */ if (to < 0) to = len + 1; /* flip from and to if they are reversed */ if (from>to) { int tmp = from; from = to; to = tmp; } /* after fiddling with the values, we find from > len && to > len */ if (from > len) selectionEnd = 1; /* special case with to too big */ else if (to > len) to = len + 1; } if (selectionEnd) { editor->pCursors[1].pRun = editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); editor->pCursors[1].nOffset = editor->pCursors[0].nOffset = 0; ME_InvalidateSelection(editor); ME_ClearTempStyle(editor); return len; } ME_RunOfsFromCharOfs(editor, from, &editor->pCursors[1].pRun, &editor->pCursors[1].nOffset); ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset); return to; }
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); } }
int ME_SetSelection(ME_TextEditor *editor, int from, int to) { int selectionEnd = 0; const int len = ME_GetTextLength(editor); /* all negative values are effectively the same */ if (from < 0) from = -1; if (to < 0) to = -1; /* select all */ if (from == 0 && to == -1) { ME_SetCursorToStart(editor, &editor->pCursors[1]); ME_SetCursorToEnd(editor, &editor->pCursors[0]); ME_InvalidateSelection(editor); ME_ClearTempStyle(editor); return len + 1; } /* if both values are equal and also out of bound, that means to */ /* put the selection at the end of the text */ if ((from == to) && (to < 0 || to > len)) { selectionEnd = 1; } else { /* if from is negative and to is positive then selection is */ /* deselected and caret moved to end of the current selection */ if (from < 0) { int start, end; ME_GetSelectionOfs(editor, &start, &end); if (start != end) { editor->pCursors[1] = editor->pCursors[0]; ME_Repaint(editor); } ME_ClearTempStyle(editor); return end; } /* adjust to if it's a negative value */ if (to < 0) to = len + 1; /* flip from and to if they are reversed */ if (from>to) { int tmp = from; from = to; to = tmp; } /* after fiddling with the values, we find from > len && to > len */ if (from > len) selectionEnd = 1; /* special case with to too big */ else if (to > len) to = len + 1; } if (selectionEnd) { ME_SetCursorToEnd(editor, &editor->pCursors[0]); editor->pCursors[1] = editor->pCursors[0]; ME_InvalidateSelection(editor); ME_ClearTempStyle(editor); return len; } ME_CursorFromCharOfs(editor, from, &editor->pCursors[1]); editor->pCursors[0] = editor->pCursors[1]; ME_MoveCursorChars(editor, &editor->pCursors[0], to - from); /* Selection is not allowed in the middle of an end paragraph run. */ if (editor->pCursors[1].pRun->member.run.nFlags & MERF_ENDPARA) editor->pCursors[1].nOffset = 0; if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA) editor->pCursors[0].nOffset = 0; return to; }