void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor) { ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); WCHAR space = ' '; /* FIXME no no no */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle, MERF_ENDROW); ME_ReleaseStyle(pStyle); }
/* FIXME this is temporary, just to have something to test how bad graphics handler is */ void ME_InsertGraphicsFromCursor(ME_TextEditor *editor, int nCursor) { ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); WCHAR space = ' '; /* FIXME no no no */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle, MERF_GRAPHICS); ME_SendSelChange(editor); }
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor) { ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); ME_DisplayItem *di; WCHAR space = ' '; /* FIXME no no no */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle, MERF_ENDROW); ME_SendSelChange(editor); }
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor) { ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); ME_DisplayItem *di; WCHAR space = ' '; /* FIXME no no no */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle, MERF_GRAPHICS); di->member.run.ole_obj = ALLOC_OBJ(*reo); ME_CopyReObject(di->member.run.ole_obj, reo); ME_SendSelChange(editor); }
void ME_InsertTableCellFromCursor(ME_TextEditor *editor, int nCursor) { WCHAR tab = '\t'; ME_DisplayItem *p, *run; ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); p = ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, pStyle, MERF_CELL); run = p; while ((run = ME_FindItemBack(run, diRunOrParagraph))->type == diRun) { if (run->member.run.nFlags & MERF_CELL) { assert(run->member.run.pCell->next); p->member.run.pCell = run->member.run.pCell->next; return; } } assert(run->type == diParagraph); assert(run->member.para.bTable); assert(run->member.para.pCells); p->member.run.pCell = run->member.para.pCells; }
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style) { const WCHAR *pos; ME_Cursor *p = NULL; int oldLen; /* FIXME really HERE ? */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); /* FIXME: is this too slow? */ /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */ oldLen = ME_GetTextLength(editor); /* text operations set modified state */ editor->nModifyStep = 1; assert(style); assert(nCursor>=0 && nCursor<editor->nCursors); if (len == -1) len = lstrlenW(str); /* grow the text limit to fit our text */ if(editor->nTextLimit < oldLen +len) editor->nTextLimit = oldLen + len; while (len) { pos = str; /* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */ while(pos-str < len && *pos != '\r' && *pos != '\n' && *pos != '\t') pos++; if (pos-str < len && *pos == '\t') { /* handle tabs */ WCHAR tab = '\t'; if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB); pos++; if(pos-str <= len) { len -= pos - str; str = pos; continue; } } /* handle special \r\r\n sequence (richedit 2.x and higher only) */ if (!editor->bEmulateVersion10 && pos-str < len-2 && pos[0] == '\r' && pos[1] == '\r' && pos[2] == '\n') { WCHAR space = ' '; if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0); pos+=3; if(pos-str <= len) { len -= pos - str; str = pos; continue; } } if (pos-str < len) { /* handle EOLs */ ME_DisplayItem *tp, *end_run; ME_Style *tmp_style; int numCR, numLF; if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); p = &editor->pCursors[nCursor]; if (p->nOffset) { ME_SplitRunSimple(editor, p->pRun, p->nOffset); p = &editor->pCursors[nCursor]; } tmp_style = ME_GetInsertStyle(editor, nCursor); /* ME_SplitParagraph increases style refcount */ /* Encode and fill number of CR and LF according to emulation mode */ if (editor->bEmulateVersion10) { const WCHAR * tpos; /* We have to find out how many consecutive \r are there, and if there is a \n terminating the run of \r's. */ numCR = 0; numLF = 0; tpos = pos; while (tpos-str < len && *tpos == '\r') { tpos++; numCR++; } if (tpos-str >= len) { /* Reached end of text without finding anything but '\r' */ if (tpos != pos) { pos++; } numCR = 1; numLF = 0; } else if (*tpos == '\n') { /* The entire run of \r's plus the one \n is one single line break */ pos = tpos + 1; numLF = 1; } else { /* Found some other content past the run of \r's */ pos++; numCR = 1; numLF = 0; } } else { if(pos-str < len && *pos =='\r') pos++; if(pos-str < len && *pos =='\n') pos++; numCR = 1; numLF = 0; } tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, numCR, numLF, 0); p->pRun = ME_FindItemFwd(tp, diRun); end_run = ME_FindItemBack(tp, diRun); ME_ReleaseStyle(end_run->member.run.style); end_run->member.run.style = tmp_style; p->nOffset = 0; if(pos-str <= len) { len -= pos - str; str = pos; continue; } } ME_InternalInsertTextFromCursor(editor, nCursor, str, len, style, 0); len = 0; } }
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style) { const WCHAR *pos; ME_Cursor *p = NULL; int oldLen; /* FIXME really HERE ? */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); /* FIXME: is this too slow? */ /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */ oldLen = ME_GetTextLength(editor); /* text operations set modified state */ editor->nModifyStep = 1; assert(style); assert(nCursor>=0 && nCursor<editor->nCursors); if (len == -1) len = lstrlenW(str); /* grow the text limit to fit our text */ if(editor->nTextLimit < oldLen +len) editor->nTextLimit = oldLen + len; pos = str; while (len) { /* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */ while(pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t') pos++; if (pos != str) { /* handle text */ ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); } else if (*pos == '\t') { /* handle tabs */ WCHAR tab = '\t'; ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB); pos++; } else { /* handle EOLs */ ME_DisplayItem *tp, *end_run, *run, *prev; ME_Style *tmp_style; int eol_len = 0; /* Find number of CR and LF in end of paragraph run */ if (*pos =='\r') { if (len > 1 && pos[1] == '\n') eol_len = 2; else if (len > 2 && pos[1] == '\r' && pos[2] == '\n') eol_len = 3; else eol_len = 1; } else { assert(*pos == '\n'); eol_len = 1; } pos += eol_len; if (!editor->bEmulateVersion10 && eol_len == 3) { /* handle special \r\r\n sequence (richedit 2.x and higher only) */ WCHAR space = ' '; ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0); } else { const WCHAR cr = '\r', *eol_str = str; if (!editor->bEmulateVersion10) { eol_str = &cr; eol_len = 1; } p = &editor->pCursors[nCursor]; if (p->nOffset == p->pRun->member.run.len) { run = ME_FindItemFwd( p->pRun, diRun ); if (!run) run = p->pRun; } else { if (p->nOffset) ME_SplitRunSimple(editor, p); run = p->pRun; } tmp_style = ME_GetInsertStyle(editor, nCursor); /* ME_SplitParagraph increases style refcount */ tp = ME_SplitParagraph(editor, run, run->member.run.style, eol_str, eol_len, 0); end_run = ME_FindItemBack(tp, diRun); ME_ReleaseStyle(end_run->member.run.style); end_run->member.run.style = tmp_style; /* Move any cursors that were at the end of the previous run to the beginning of the new para */ prev = ME_FindItemBack( end_run, diRun ); if (prev) { int i; for (i = 0; i < editor->nCursors; i++) { if (editor->pCursors[i].pRun == prev && editor->pCursors[i].nOffset == prev->member.run.len) { editor->pCursors[i].pPara = tp; editor->pCursors[i].pRun = run; editor->pCursors[i].nOffset = 0; } } } } } len -= pos - str; str = pos; } }
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style) { const WCHAR *pos; ME_Cursor *p = NULL; /* FIXME: is this too slow? */ /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */ int freeSpace = editor->nTextLimit - ME_GetTextLength(editor); /* text operations set modified state */ editor->nModifyStep = 1; assert(style); /* FIXME really HERE ? */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); assert(nCursor>=0 && nCursor<editor->nCursors); if (len == -1) len = lstrlenW(str); len = min(len, freeSpace); while (len) { pos = str; /* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */ while(pos-str < len && *pos != '\r' && *pos != '\n' && *pos != '\t') pos++; if (pos-str < len && *pos == '\t') { /* handle tabs */ WCHAR tab = '\t'; if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB); pos++; if(pos-str <= len) { len -= pos - str; str = pos; continue; } } if (pos-str < len) { /* handle EOLs */ ME_DisplayItem *tp, *end_run; ME_Style *tmp_style; if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); p = &editor->pCursors[nCursor]; if (p->nOffset) { ME_SplitRunSimple(editor, p->pRun, p->nOffset); p = &editor->pCursors[nCursor]; } tmp_style = ME_GetInsertStyle(editor, nCursor); /* ME_SplitParagraph increases style refcount */ tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style); p->pRun = ME_FindItemFwd(tp, diRun); end_run = ME_FindItemBack(tp, diRun); ME_ReleaseStyle(end_run->member.run.style); end_run->member.run.style = tmp_style; p->nOffset = 0; if(pos-str < len && *pos =='\r') pos++; if(pos-str < len && *pos =='\n') pos++; if(pos-str <= len) { len -= pos - str; str = pos; continue; } } ME_InternalInsertTextFromCursor(editor, nCursor, str, len, style, 0); len = 0; } }