mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 12:19:49 +00:00
riched20: Move the text to the paragraph level.
This commit is contained in:
parent
b730efc9b4
commit
5168d66be7
8 changed files with 58 additions and 44 deletions
|
@ -382,7 +382,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
|
|||
to the current (deleted) run */
|
||||
add_undo_insert_run( editor, nOfs + nChars, get_text( run, c.nOffset ), nCharsToDelete, run->nFlags, run->style );
|
||||
|
||||
ME_StrDeleteV(run->strText, c.nOffset, nCharsToDelete);
|
||||
ME_StrDeleteV(run->para->text, run->nCharOfs + c.nOffset, nCharsToDelete);
|
||||
run->len -= nCharsToDelete;
|
||||
TRACE("Post deletion string: %s (%d)\n", debugstr_run( run ), run->len);
|
||||
TRACE("Shift value: %d\n", shift);
|
||||
|
|
|
@ -58,12 +58,12 @@ static inline void * __WINE_ALLOC_SIZE(2) heap_realloc( void *ptr, size_t len )
|
|||
|
||||
static inline WCHAR *get_text( const ME_Run *run, int offset )
|
||||
{
|
||||
return run->strText->szData + offset;
|
||||
return run->para->text->szData + run->nCharOfs + offset;
|
||||
}
|
||||
|
||||
static inline const char *debugstr_run( const ME_Run *run )
|
||||
{
|
||||
return debugstr_w( get_text( run, 0 ) );
|
||||
return debugstr_wn( get_text( run, 0 ), run->len );
|
||||
}
|
||||
|
||||
/* style.c */
|
||||
|
@ -102,11 +102,13 @@ ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars) DECLSPEC_HIDDEN;
|
|||
ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) DECLSPEC_HIDDEN;
|
||||
ME_String *ME_StrDup(const ME_String *s) DECLSPEC_HIDDEN;
|
||||
void ME_DestroyString(ME_String *s) DECLSPEC_HIDDEN;
|
||||
void ME_AppendString(ME_String *s1, const ME_String *s2) DECLSPEC_HIDDEN;
|
||||
BOOL ME_AppendString(ME_String *s, const WCHAR *append, int len) DECLSPEC_HIDDEN;
|
||||
ME_String *ME_VSplitString(ME_String *orig, int nVPos) DECLSPEC_HIDDEN;
|
||||
int ME_FindNonWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN;
|
||||
int ME_CallWordBreakProc(ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT code) DECLSPEC_HIDDEN;
|
||||
void ME_StrDeleteV(ME_String *s, int nVChar, int nChars) DECLSPEC_HIDDEN;
|
||||
BOOL ME_InsertString(ME_String *s, int ofs, const WCHAR *insert, int len) DECLSPEC_HIDDEN;
|
||||
|
||||
/* smart helpers for A<->W conversions, they reserve/free memory and call MultiByte<->WideChar functions */
|
||||
LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz) DECLSPEC_HIDDEN;
|
||||
void ME_EndToUnicode(BOOL unicode, LPVOID psz) DECLSPEC_HIDDEN;
|
||||
|
@ -133,7 +135,7 @@ ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_H
|
|||
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
|
||||
|
||||
/* run.c */
|
||||
ME_DisplayItem *ME_MakeRun(ME_Style *s, ME_String *strData, int nFlags) DECLSPEC_HIDDEN;
|
||||
ME_DisplayItem *ME_MakeRun(ME_Style *s, int nFlags) DECLSPEC_HIDDEN;
|
||||
ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor,
|
||||
ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN;
|
||||
void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN;
|
||||
|
@ -330,7 +332,7 @@ BOOL add_undo_delete_run( ME_TextEditor *, int pos, int len ) DECLSPEC_HIDDEN;
|
|||
BOOL add_undo_set_para_fmt( ME_TextEditor *, const ME_Paragraph *para ) DECLSPEC_HIDDEN;
|
||||
BOOL add_undo_set_char_fmt( ME_TextEditor *, int pos, int len, const CHARFORMAT2W *fmt ) DECLSPEC_HIDDEN;
|
||||
BOOL add_undo_join_paras( ME_TextEditor *, int pos ) DECLSPEC_HIDDEN;
|
||||
BOOL add_undo_split_para( ME_TextEditor *, const ME_Paragraph *para, const ME_Run *run, const ME_Cell *cell) DECLSPEC_HIDDEN;
|
||||
BOOL add_undo_split_para( ME_TextEditor *, const ME_Paragraph *para, ME_String *eol_str, const ME_Cell *cell) DECLSPEC_HIDDEN;
|
||||
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN;
|
||||
void ME_ContinueCoalescingTransaction(ME_TextEditor *editor) DECLSPEC_HIDDEN;
|
||||
void ME_CommitCoalescingUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN;
|
||||
|
|
|
@ -141,7 +141,6 @@ struct tagME_DisplayItem;
|
|||
|
||||
typedef struct tagME_Run
|
||||
{
|
||||
ME_String *strText;
|
||||
ME_Style *style;
|
||||
struct tagME_Paragraph *para; /* ptr to the run's paragraph */
|
||||
int nCharOfs; /* relative to para's offset */
|
||||
|
@ -170,6 +169,7 @@ typedef struct tagME_BorderRect
|
|||
typedef struct tagME_Paragraph
|
||||
{
|
||||
PARAFORMAT2 *pFmt;
|
||||
ME_String *text;
|
||||
|
||||
struct tagME_DisplayItem *pCell; /* v4.1 */
|
||||
ME_BorderRect border;
|
||||
|
|
|
@ -143,13 +143,15 @@ void ME_DestroyDisplayItem(ME_DisplayItem *item)
|
|||
{
|
||||
/* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */
|
||||
if (item->type==diParagraph)
|
||||
{
|
||||
FREE_OBJ(item->member.para.pFmt);
|
||||
ME_DestroyString(item->member.para.text);
|
||||
}
|
||||
|
||||
if (item->type==diRun)
|
||||
{
|
||||
if (item->member.run.ole_obj) ME_DeleteReObject(item->member.run.ole_obj);
|
||||
ME_ReleaseStyle(item->member.run.style);
|
||||
ME_DestroyString(item->member.run.strText);
|
||||
}
|
||||
FREE_OBJ(item);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
|
|||
ME_DisplayItem *para = ME_MakeDI(diParagraph);
|
||||
ME_DisplayItem *run;
|
||||
ME_Style *style;
|
||||
ME_String *eol_str;
|
||||
int eol_len;
|
||||
WCHAR cr_lf[] = {'\r','\n',0};
|
||||
|
||||
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
||||
|
@ -64,9 +64,12 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
|
|||
style = ME_MakeStyle(&cf);
|
||||
text->pDefaultStyle = style;
|
||||
|
||||
eol_str = ME_MakeStringN(cr_lf, editor->bEmulateVersion10 ? 2 : 1);
|
||||
run = ME_MakeRun(style, eol_str, MERF_ENDPARA);
|
||||
eol_len = editor->bEmulateVersion10 ? 2 : 1;
|
||||
para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
|
||||
|
||||
run = ME_MakeRun(style, MERF_ENDPARA);
|
||||
run->member.run.nCharOfs = 0;
|
||||
run->member.run.len = eol_len;
|
||||
run->member.run.para = ¶->member.para;
|
||||
|
||||
ME_InsertBefore(text->pLast, para);
|
||||
|
@ -202,7 +205,6 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
|
|||
int ofs, i;
|
||||
ME_DisplayItem *pp;
|
||||
int run_flags = MERF_ENDPARA;
|
||||
ME_String *str;
|
||||
|
||||
if (!editor->bEmulateVersion10) { /* v4.1 */
|
||||
/* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
|
||||
|
@ -219,11 +221,13 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
|
|||
run_para = ME_GetParagraph(run);
|
||||
assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
||||
|
||||
str = ME_MakeStringN( eol_str, eol_len );
|
||||
end_run = ME_MakeRun(style, str, run_flags);
|
||||
ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs;
|
||||
end_run->member.run.para = run->member.run.para;
|
||||
new_para->member.para.text = ME_VSplitString( run_para->member.para.text, run->member.run.nCharOfs );
|
||||
|
||||
end_run = ME_MakeRun(style, run_flags);
|
||||
ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs;
|
||||
end_run->member.run.len = eol_len;
|
||||
end_run->member.run.para = run->member.run.para;
|
||||
ME_AppendString( run_para->member.para.text, eol_str, eol_len );
|
||||
next_para = run_para->member.para.next_para;
|
||||
assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
|
||||
|
||||
|
@ -329,6 +333,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
|||
int end_len;
|
||||
CHARFORMAT2W fmt;
|
||||
ME_Cursor startCur, endCur;
|
||||
ME_String *eol_str;
|
||||
|
||||
assert(tp->type == diParagraph);
|
||||
assert(tp->member.para.next_para);
|
||||
|
@ -344,6 +349,8 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
|||
assert(pRun->member.run.nFlags & MERF_ENDPARA);
|
||||
|
||||
end_len = pRun->member.run.len;
|
||||
eol_str = ME_VSplitString( tp->member.para.text, pRun->member.run.nCharOfs );
|
||||
ME_AppendString( tp->member.para.text, pNext->member.para.text->szData, pNext->member.para.text->nLen );
|
||||
|
||||
/* null char format operation to store the original char format for the ENDPARA run */
|
||||
ME_InitCharFormat2W(&fmt);
|
||||
|
@ -371,7 +378,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
|||
}
|
||||
}
|
||||
|
||||
add_undo_split_para( editor, &pNext->member.para, &pRun->member.run, pCell ? &pCell->member.cell : NULL );
|
||||
add_undo_split_para( editor, &pNext->member.para, eol_str, pCell ? &pCell->member.cell : NULL );
|
||||
|
||||
if (pCell)
|
||||
{
|
||||
|
|
|
@ -230,7 +230,6 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
|
|||
}
|
||||
}
|
||||
|
||||
ME_AppendString(p->member.run.strText, pNext->member.run.strText);
|
||||
p->member.run.len += pNext->member.run.len;
|
||||
ME_Remove(pNext);
|
||||
ME_DestroyDisplayItem(pNext);
|
||||
|
@ -307,11 +306,11 @@ ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor)
|
|||
assert(!(run->member.run.nFlags & MERF_NONTEXT));
|
||||
|
||||
new_run = ME_MakeRun(run->member.run.style,
|
||||
ME_VSplitString(run->member.run.strText, nOffset),
|
||||
run->member.run.nFlags & MERF_SPLITMASK);
|
||||
run->member.run.len = nOffset;
|
||||
new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset;
|
||||
new_run->member.run.len = run->member.run.len - nOffset;
|
||||
new_run->member.run.para = run->member.run.para;
|
||||
run->member.run.len = nOffset;
|
||||
cursor->pRun = new_run;
|
||||
cursor->nOffset = 0;
|
||||
|
||||
|
@ -335,15 +334,14 @@ ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor)
|
|||
*
|
||||
* A helper function to create run structures quickly.
|
||||
*/
|
||||
ME_DisplayItem *ME_MakeRun(ME_Style *s, ME_String *strData, int nFlags)
|
||||
ME_DisplayItem *ME_MakeRun(ME_Style *s, int nFlags)
|
||||
{
|
||||
ME_DisplayItem *item = ME_MakeDI(diRun);
|
||||
item->member.run.style = s;
|
||||
item->member.run.ole_obj = NULL;
|
||||
item->member.run.strText = strData;
|
||||
item->member.run.nFlags = nFlags;
|
||||
item->member.run.nCharOfs = -1;
|
||||
item->member.run.len = strData->nLen;
|
||||
item->member.run.len = 0;
|
||||
item->member.run.para = NULL;
|
||||
ME_AddRefStyle(s);
|
||||
return item;
|
||||
|
@ -368,9 +366,11 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
|
|||
add_undo_delete_run( editor, cursor->pPara->member.para.nCharOfs +
|
||||
cursor->pRun->member.run.nCharOfs, len );
|
||||
|
||||
pDI = ME_MakeRun(style, ME_MakeStringN(str, len), flags);
|
||||
pDI = ME_MakeRun(style, flags);
|
||||
pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs;
|
||||
pDI->member.run.len = len;
|
||||
pDI->member.run.para = cursor->pRun->member.run.para;
|
||||
ME_InsertString( pDI->member.run.para->text, pDI->member.run.nCharOfs, str, len );
|
||||
ME_InsertBefore(cursor->pRun, pDI);
|
||||
TRACE("Shift length:%d\n", len);
|
||||
ME_PropagateCharOffset(cursor->pRun, len);
|
||||
|
|
|
@ -71,25 +71,28 @@ void ME_DestroyString(ME_String *s)
|
|||
FREE_OBJ(s);
|
||||
}
|
||||
|
||||
void ME_AppendString(ME_String *s1, const ME_String *s2)
|
||||
BOOL ME_InsertString(ME_String *s, int ofs, const WCHAR *insert, int len)
|
||||
{
|
||||
if (s1->nLen+s2->nLen+1 <= s1->nBuffer)
|
||||
{
|
||||
memcpy(s1->szData + s1->nLen, s2->szData, s2->nLen * sizeof(WCHAR));
|
||||
s1->nLen += s2->nLen;
|
||||
s1->szData[s1->nLen] = 0;
|
||||
} else {
|
||||
WCHAR *buf;
|
||||
s1->nBuffer = ME_GetOptimalBuffer(s1->nLen+s2->nLen+1);
|
||||
DWORD new_len = s->nLen + len + 1;
|
||||
assert( ofs <= s->nLen );
|
||||
|
||||
buf = ALLOC_N_OBJ(WCHAR, s1->nBuffer);
|
||||
memcpy(buf, s1->szData, s1->nLen * sizeof(WCHAR));
|
||||
memcpy(buf + s1->nLen, s2->szData, s2->nLen * sizeof(WCHAR));
|
||||
FREE_OBJ(s1->szData);
|
||||
s1->szData = buf;
|
||||
s1->nLen += s2->nLen;
|
||||
s1->szData[s1->nLen] = 0;
|
||||
}
|
||||
if( new_len > s->nBuffer )
|
||||
{
|
||||
s->nBuffer = ME_GetOptimalBuffer( new_len );
|
||||
s->szData = heap_realloc( s->szData, s->nBuffer * sizeof(WCHAR) );
|
||||
if (!s->szData) return FALSE;
|
||||
}
|
||||
|
||||
memmove( s->szData + ofs + len, s->szData + ofs, (s->nLen - ofs + 1) * sizeof(WCHAR) );
|
||||
memcpy( s->szData + ofs, insert, len * sizeof(WCHAR) );
|
||||
s->nLen += len;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL ME_AppendString(ME_String *s, const WCHAR *append, int len)
|
||||
{
|
||||
return ME_InsertString( s, s->nLen, append, len );
|
||||
}
|
||||
|
||||
ME_String *ME_VSplitString(ME_String *orig, int charidx)
|
||||
|
|
|
@ -182,13 +182,13 @@ BOOL add_undo_join_paras( ME_TextEditor *editor, int pos )
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL add_undo_split_para( ME_TextEditor *editor, const ME_Paragraph *para, const ME_Run *run, const ME_Cell *cell )
|
||||
BOOL add_undo_split_para( ME_TextEditor *editor, const ME_Paragraph *para, ME_String *eol_str, const ME_Cell *cell )
|
||||
{
|
||||
struct undo_item *undo = add_undo( editor, undo_split_para );
|
||||
if (!undo) return FALSE;
|
||||
|
||||
undo->u.split_para.pos = para->nCharOfs - run->len;
|
||||
undo->u.split_para.eol_str = ME_StrDup( run->strText );
|
||||
undo->u.split_para.pos = para->nCharOfs - eol_str->nLen;
|
||||
undo->u.split_para.eol_str = eol_str;
|
||||
undo->u.split_para.fmt = *para->pFmt;
|
||||
undo->u.split_para.border = para->border;
|
||||
undo->u.split_para.flags = para->prev_para->member.para.nFlags & ~MEPF_CELL;
|
||||
|
|
Loading…
Reference in a new issue