mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-30 19:26:05 +00:00
Krzysztof Foltman <[email protected]> - removed trailing spaces from some files - tab support - indent support - PageUp key support. - Support for "normal" scroll bar functionality (line and page scrolling). - made string operations consistent wrt whitespace handling (which should greatly improve stability of the wrap code and eliminate regressions of the most recent versions) - completely new scrollbar handling (much more reliable) and related redraw fixes - Page Down handler (no Page Up yet, fixing wrap/redraw/scrollbar bugs was of higher priority) - RTF reader doesn't use RichEdit messages anymore (which saves on unnecessary repaints) - added unicode character support to RTF import (like: \u12345 ?) - small fixes - fixed whitespace identification bug - removed drawing of paragraph marks - improved stub implementations for IRichEditOle - Unknown destinations are now correctly skipped (so loading an RTF file generated by, for example, OpenOffice doesn't produce lots of garbage anymore). - Format stack for RTF groups (so that RTF reader can correctly read what RTF writer wrote :) ) - EM_STREAMIN can now deal with undo in a reasonable manner (no multiple undo actions in one EM_STREAMIN). - Related changes to undo code (umIgnore mode is now handled correctly). - Numerous improvements in the RTF reader: it reads some character attributes now (you will have proper small print in license agreements now). - Fixed a memory overwrite bug in conversion from CHARFORMAT2A to CHARFORMAT2W. - Optimized repaint of the area below the text. - ME_JoinRuns didn't mark the paragraph for rewrapping, fixed. - Removed PostQuitMessage(0) from WM_DESTROY handler (duh!). - Use of EM_GETOLEINTERFACE is reported with FIXME instead of TRACE (any app using this message is likely to encounter major problems). - WM_COPY (and WM_CUT) can now put both Unicode and RTF format (thanks to Phil Krylov's RTF generator code). - New message implemented - WM_PASTE. - RTF reader: rtfPlain implemented (kind of). - RTF writer: rewritten main loop (the old one crashed in some circumstances when SFF_SELECTION was used). - The meaning of the rewrap flag got inverted (MEPF_REWRAP instead of MEPF_WRAPPED) for consistency. - Major code cleanups in rewrap/repaint code, leading to "smarter" behaviour wrt repainting selections. - Old font management replaced by the cache-based one, which keeps maximum of 10 HFONTs at once, instead of one per a couple of runs. - EM_CANPASTE implemented - updated TODO list (including list of (un)implemented messages) - fixed WM_PASTE (the previous version might not close the clipboard if it didn't contain a usable format) - scrollbar operations (like clicking on arrows) should update scrollbar's current position Gerald Pfeifer <[email protected]> - Make ME_ArrowLeft() return a value in every case. Phil Krylov <[email protected]> - Make RTF reader fall back to simple text if a correct RTF header is not detected. This should fix some installers. - Made RTF reader and writer handle codepages mostly similar to the original riched20.dll. - Fixed support for RTF documents using ANSI charset and added support for multibyte charsets, so that BIG5 and UTF-8 RTF documents are working now. - Replaced slow and outdated character set handling in RTF reader by Unicode/codepages support. Added charset->codepage conversion. - Implemented hash table lookup for RTF keywords in RTF reader. - Added "generator" RTF destination handling. - Initial implementation of EM_STREAMOUT and RTF writer. - Fixed \u keyword to output signed 16-bit values. Also fixed CP_SYMBOL conversion and the detection of the default font's codepage. - Improved RTF export. Mike McCormack <[email protected]> - Remove casts and unused code. Hannu Valtonen <[email protected]> - Added mousewheel support. Vincent Beron <[email protected]> - Use "" for Windows includes in dlls, instead of <>. Jakob Eriksson <[email protected]> - Get rid of HeapAlloc casts. Jason Edmeades <[email protected]> - Correct memory allocation macro. svn path=/trunk/; revision=15014
275 lines
7.6 KiB
C
275 lines
7.6 KiB
C
/*
|
|
* RichEdit - functions dealing with editor object
|
|
*
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "editor.h"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
void ME_EmptyUndoStack(ME_TextEditor *editor)
|
|
{
|
|
ME_DisplayItem *p, *pNext;
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
return;
|
|
|
|
TRACE("Emptying undo stack\n");
|
|
|
|
p = editor->pUndoStack;
|
|
editor->pUndoStack = NULL;
|
|
while(p) {
|
|
pNext = p->next;
|
|
ME_DestroyDisplayItem(p);
|
|
p = pNext;
|
|
}
|
|
p = editor->pRedoStack;
|
|
editor->pRedoStack = NULL;
|
|
while(p) {
|
|
pNext = p->next;
|
|
ME_DestroyDisplayItem(p);
|
|
p = pNext;
|
|
}
|
|
}
|
|
|
|
ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayItem *pdi) {
|
|
if (editor->nUndoMode == umIgnore)
|
|
return NULL;
|
|
else
|
|
{
|
|
ME_DisplayItem *pItem = (ME_DisplayItem *)ALLOC_OBJ(ME_UndoItem);
|
|
switch(type)
|
|
{
|
|
case diUndoEndTransaction:
|
|
break;
|
|
case diUndoSetParagraphFormat:
|
|
assert(pdi);
|
|
CopyMemory(&pItem->member.para, &pdi->member.para, sizeof(ME_Paragraph));
|
|
pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
|
|
CopyMemory(pItem->member.para.pFmt, pdi->member.para.pFmt, sizeof(PARAFORMAT2));
|
|
break;
|
|
case diUndoInsertRun:
|
|
assert(pdi);
|
|
CopyMemory(&pItem->member.run, &pdi->member.run, sizeof(ME_Run));
|
|
pItem->member.run.strText = ME_StrDup(pItem->member.run.strText);
|
|
ME_AddRefStyle(pItem->member.run.style);
|
|
break;
|
|
case diUndoSetCharFormat:
|
|
case diUndoSetDefaultCharFormat:
|
|
break;
|
|
case diUndoDeleteRun:
|
|
case diUndoJoinParagraphs:
|
|
break;
|
|
case diUndoSplitParagraph:
|
|
pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
|
|
pItem->member.para.pFmt->cbSize = sizeof(PARAFORMAT2);
|
|
pItem->member.para.pFmt->dwMask = 0;
|
|
|
|
break;
|
|
default:
|
|
assert(0 == "AddUndoItem, unsupported item type");
|
|
return NULL;
|
|
}
|
|
pItem->type = type;
|
|
pItem->prev = NULL;
|
|
if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo)
|
|
{
|
|
if (editor->nUndoMode == umAddToUndo)
|
|
TRACE("Pushing id=%s to undo stack, deleting redo stack\n", ME_GetDITypeName(type));
|
|
else
|
|
TRACE("Pushing id=%s to undo stack\n", ME_GetDITypeName(type));
|
|
pItem->next = editor->pUndoStack;
|
|
if (editor->pUndoStack)
|
|
editor->pUndoStack->prev = pItem;
|
|
editor->pUndoStack = pItem;
|
|
/* any new operation (not redo) clears the redo stack */
|
|
if (editor->nUndoMode == umAddToUndo) {
|
|
ME_DisplayItem *p = editor->pRedoStack;
|
|
while(p)
|
|
{
|
|
ME_DisplayItem *pp = p->next;
|
|
ME_DestroyDisplayItem(p);
|
|
p = pp;
|
|
}
|
|
editor->pRedoStack = NULL;
|
|
}
|
|
}
|
|
else if (editor->nUndoMode == umAddToRedo)
|
|
{
|
|
TRACE("Pushing id=%s to redo stack\n", ME_GetDITypeName(type));
|
|
pItem->next = editor->pRedoStack;
|
|
if (editor->pRedoStack)
|
|
editor->pRedoStack->prev = pItem;
|
|
editor->pRedoStack = pItem;
|
|
}
|
|
else
|
|
assert(0);
|
|
return (ME_UndoItem *)pItem;
|
|
}
|
|
}
|
|
|
|
void ME_CommitUndo(ME_TextEditor *editor) {
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
return;
|
|
|
|
assert(editor->nUndoMode == umAddToUndo);
|
|
|
|
/* no transactions, no need to commit */
|
|
if (!editor->pUndoStack)
|
|
return;
|
|
|
|
/* no need to commit empty transactions */
|
|
if (editor->pUndoStack->type == diUndoEndTransaction)
|
|
return;
|
|
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
|
ME_SendSelChange(editor);
|
|
editor->nModifyStep++;
|
|
}
|
|
|
|
void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
|
|
{
|
|
ME_UndoItem *pUItem = (ME_UndoItem *)pItem;
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
return;
|
|
TRACE("Playing undo/redo item, id=%s\n", ME_GetDITypeName(pItem->type));
|
|
|
|
switch(pItem->type)
|
|
{
|
|
case diUndoEndTransaction:
|
|
assert(0);
|
|
case diUndoSetParagraphFormat:
|
|
{
|
|
ME_Cursor tmp;
|
|
ME_CursorFromCharOfs(editor, pItem->member.para.nCharOfs, &tmp);
|
|
ME_SetParaFormat(editor, ME_FindItemBack(tmp.pRun, diParagraph), pItem->member.para.pFmt);
|
|
break;
|
|
}
|
|
case diUndoSetCharFormat:
|
|
{
|
|
ME_SetCharFormat(editor, pUItem->nStart, pUItem->nLen, &pItem->member.ustyle->fmt);
|
|
break;
|
|
}
|
|
case diUndoSetDefaultCharFormat:
|
|
{
|
|
ME_SetDefaultCharFormat(editor, &pItem->member.ustyle->fmt);
|
|
break;
|
|
}
|
|
case diUndoInsertRun:
|
|
{
|
|
ME_InsertRun(editor, pItem->member.run.nCharOfs, pItem);
|
|
break;
|
|
}
|
|
case diUndoDeleteRun:
|
|
{
|
|
ME_InternalDeleteText(editor, pUItem->nStart, pUItem->nLen);
|
|
break;
|
|
}
|
|
case diUndoJoinParagraphs:
|
|
{
|
|
ME_Cursor tmp;
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
|
|
/* the only thing that's needed is paragraph offset, so no need to split runs */
|
|
ME_JoinParagraphs(editor, ME_GetParagraph(tmp.pRun));
|
|
break;
|
|
}
|
|
case diUndoSplitParagraph:
|
|
{
|
|
ME_Cursor tmp;
|
|
ME_DisplayItem *new_para;
|
|
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
|
|
if (tmp.nOffset)
|
|
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
|
|
new_para = ME_SplitParagraph(editor, tmp.pRun, tmp.pRun->member.run.style);
|
|
assert(pItem->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
|
CopyMemory(new_para->member.para.pFmt, pItem->member.para.pFmt, sizeof(PARAFORMAT2));
|
|
break;
|
|
}
|
|
default:
|
|
assert(0 == "PlayUndoItem, unexpected type");
|
|
}
|
|
}
|
|
|
|
void ME_Undo(ME_TextEditor *editor) {
|
|
ME_DisplayItem *p;
|
|
ME_UndoMode nMode = editor->nUndoMode;
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
return;
|
|
assert(nMode == umAddToUndo || nMode == umIgnore);
|
|
|
|
/* no undo items ? */
|
|
if (!editor->pUndoStack)
|
|
return;
|
|
|
|
/* watch out for uncommited transactions ! */
|
|
assert(editor->pUndoStack->type == diUndoEndTransaction);
|
|
|
|
editor->nUndoMode = umAddToRedo;
|
|
p = editor->pUndoStack->next;
|
|
ME_DestroyDisplayItem(editor->pUndoStack);
|
|
do {
|
|
ME_DisplayItem *pp = p;
|
|
ME_PlayUndoItem(editor, p);
|
|
p = p->next;
|
|
ME_DestroyDisplayItem(pp);
|
|
} while(p && p->type != diUndoEndTransaction);
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
|
editor->pUndoStack = p;
|
|
if (p)
|
|
p->prev = NULL;
|
|
editor->nUndoMode = nMode;
|
|
editor->nModifyStep--;
|
|
ME_UpdateRepaint(editor);
|
|
}
|
|
|
|
void ME_Redo(ME_TextEditor *editor) {
|
|
ME_DisplayItem *p;
|
|
ME_UndoMode nMode = editor->nUndoMode;
|
|
|
|
assert(nMode == umAddToUndo || nMode == umIgnore);
|
|
|
|
if (editor->nUndoMode == umIgnore)
|
|
return;
|
|
/* no redo items ? */
|
|
if (!editor->pRedoStack)
|
|
return;
|
|
|
|
/* watch out for uncommited transactions ! */
|
|
assert(editor->pRedoStack->type == diUndoEndTransaction);
|
|
|
|
editor->nUndoMode = umAddBackToUndo;
|
|
p = editor->pRedoStack->next;
|
|
ME_DestroyDisplayItem(editor->pRedoStack);
|
|
do {
|
|
ME_DisplayItem *pp = p;
|
|
ME_PlayUndoItem(editor, p);
|
|
p = p->next;
|
|
ME_DestroyDisplayItem(pp);
|
|
} while(p && p->type != diUndoEndTransaction);
|
|
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
|
|
editor->pRedoStack = p;
|
|
if (p)
|
|
p->prev = NULL;
|
|
editor->nUndoMode = nMode;
|
|
editor->nModifyStep++;
|
|
ME_UpdateRepaint(editor);
|
|
}
|