Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * RichEdit - functions dealing with editor object |
| 3 | * |
| 4 | * Copyright 2004 by Krzysztof Foltman |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "editor.h" |
| 22 | |
| 23 | WINE_DEFAULT_DEBUG_CHANNEL(richedit); |
| 24 | |
| 25 | void ME_EmptyUndoStack(ME_TextEditor *editor) |
| 26 | { |
| 27 | ME_DisplayItem *p, *pNext; |
| 28 | |
Krzysztof Foltman | 898068f | 2005-03-11 10:24:56 +0000 | [diff] [blame] | 29 | if (editor->nUndoMode == umIgnore) |
| 30 | return; |
| 31 | |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 32 | TRACE("Emptying undo stack\n"); |
| 33 | |
| 34 | p = editor->pUndoStack; |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 35 | editor->pUndoStack = editor->pUndoStackBottom = NULL; |
| 36 | editor->nUndoStackSize = 0; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 37 | while(p) { |
| 38 | pNext = p->next; |
| 39 | ME_DestroyDisplayItem(p); |
| 40 | p = pNext; |
| 41 | } |
| 42 | p = editor->pRedoStack; |
| 43 | editor->pRedoStack = NULL; |
| 44 | while(p) { |
| 45 | pNext = p->next; |
| 46 | ME_DestroyDisplayItem(p); |
| 47 | p = pNext; |
| 48 | } |
| 49 | } |
| 50 | |
Andrew Talbot | b150ea6 | 2007-08-16 21:57:12 +0100 | [diff] [blame] | 51 | ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi) { |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 52 | if (editor->nUndoMode == umIgnore) |
| 53 | return NULL; |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 54 | else if (editor->nUndoLimit == 0) |
| 55 | return NULL; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 56 | else |
| 57 | { |
Michael Stefaniuc | d1a7e41 | 2009-01-30 10:40:02 +0100 | [diff] [blame] | 58 | ME_DisplayItem *pItem = ALLOC_OBJ(ME_UndoItem); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 59 | switch(type) |
| 60 | { |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 61 | case diUndoPotentialEndTransaction: |
| 62 | /* only should be added for manually typed chars, not undos or redos */ |
| 63 | assert(editor->nUndoMode == umAddToUndo); |
| 64 | /* intentional fall-through to next case */ |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 65 | case diUndoEndTransaction: |
| 66 | break; |
| 67 | case diUndoSetParagraphFormat: |
| 68 | assert(pdi); |
Eric Pouech | 34a4f92 | 2008-03-16 21:47:01 +0100 | [diff] [blame] | 69 | pItem->member.para = pdi->member.para; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 70 | pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); |
Eric Pouech | 34a4f92 | 2008-03-16 21:47:01 +0100 | [diff] [blame] | 71 | *pItem->member.para.pFmt = *pdi->member.para.pFmt; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 72 | break; |
| 73 | case diUndoInsertRun: |
| 74 | assert(pdi); |
Eric Pouech | 34a4f92 | 2008-03-16 21:47:01 +0100 | [diff] [blame] | 75 | pItem->member.run = pdi->member.run; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 76 | pItem->member.run.strText = ME_StrDup(pItem->member.run.strText); |
| 77 | ME_AddRefStyle(pItem->member.run.style); |
Eric Pouech | 00de775 | 2008-01-27 19:01:41 +0100 | [diff] [blame] | 78 | if (pdi->member.run.ole_obj) |
| 79 | { |
| 80 | pItem->member.run.ole_obj = ALLOC_OBJ(*pItem->member.run.ole_obj); |
| 81 | ME_CopyReObject(pItem->member.run.ole_obj, pdi->member.run.ole_obj); |
| 82 | } |
| 83 | else pItem->member.run.ole_obj = NULL; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 84 | break; |
| 85 | case diUndoSetCharFormat: |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 86 | break; |
| 87 | case diUndoDeleteRun: |
| 88 | case diUndoJoinParagraphs: |
| 89 | break; |
| 90 | case diUndoSplitParagraph: |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 91 | { |
| 92 | ME_DisplayItem *prev_para = pdi->member.para.prev_para; |
Dylan Smith | 4e56a3c | 2008-08-04 19:19:01 -0400 | [diff] [blame] | 93 | assert(pdi->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 94 | pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 95 | pItem->member.para.pFmt->cbSize = sizeof(PARAFORMAT2); |
| 96 | pItem->member.para.pFmt->dwMask = 0; |
Dylan Smith | 4e56a3c | 2008-08-04 19:19:01 -0400 | [diff] [blame] | 97 | *pItem->member.para.pFmt = *pdi->member.para.pFmt; |
Dylan Smith | 3df7871 | 2008-09-30 17:11:19 -0400 | [diff] [blame] | 98 | pItem->member.para.border = pdi->member.para.border; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 99 | pItem->member.para.nFlags = prev_para->member.para.nFlags & ~MEPF_CELL; |
| 100 | pItem->member.para.pCell = NULL; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 101 | break; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 102 | } |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 103 | default: |
| 104 | assert(0 == "AddUndoItem, unsupported item type"); |
| 105 | return NULL; |
| 106 | } |
| 107 | pItem->type = type; |
| 108 | pItem->prev = NULL; |
| 109 | if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo) |
| 110 | { |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 111 | if (editor->pUndoStack |
| 112 | && editor->pUndoStack->type == diUndoPotentialEndTransaction) |
| 113 | { |
| 114 | editor->pUndoStack->type = diUndoEndTransaction; |
| 115 | } |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 116 | if (editor->nUndoMode == umAddToUndo) |
| 117 | TRACE("Pushing id=%s to undo stack, deleting redo stack\n", ME_GetDITypeName(type)); |
| 118 | else |
| 119 | TRACE("Pushing id=%s to undo stack\n", ME_GetDITypeName(type)); |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 120 | |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 121 | pItem->next = editor->pUndoStack; |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 122 | if (type == diUndoEndTransaction || type == diUndoPotentialEndTransaction) |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 123 | editor->nUndoStackSize++; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 124 | if (editor->pUndoStack) |
| 125 | editor->pUndoStack->prev = pItem; |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 126 | else |
| 127 | editor->pUndoStackBottom = pItem; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 128 | editor->pUndoStack = pItem; |
Matt Finnicum | a379ac9 | 2006-05-15 14:00:15 -0400 | [diff] [blame] | 129 | |
| 130 | if (editor->nUndoStackSize > editor->nUndoLimit) |
| 131 | { /* remove oldest undo from stack */ |
| 132 | ME_DisplayItem *p = editor->pUndoStackBottom; |
| 133 | while (p->type !=diUndoEndTransaction) |
| 134 | p = p->prev; /*find new stack bottom */ |
| 135 | editor->pUndoStackBottom = p->prev; |
| 136 | editor->pUndoStackBottom->next = NULL; |
| 137 | do |
| 138 | { |
| 139 | ME_DisplayItem *pp = p->next; |
| 140 | ME_DestroyDisplayItem(p); |
| 141 | p = pp; |
| 142 | } while (p); |
| 143 | editor->nUndoStackSize--; |
| 144 | } |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 145 | /* any new operation (not redo) clears the redo stack */ |
| 146 | if (editor->nUndoMode == umAddToUndo) { |
| 147 | ME_DisplayItem *p = editor->pRedoStack; |
| 148 | while(p) |
| 149 | { |
| 150 | ME_DisplayItem *pp = p->next; |
| 151 | ME_DestroyDisplayItem(p); |
| 152 | p = pp; |
| 153 | } |
| 154 | editor->pRedoStack = NULL; |
| 155 | } |
| 156 | } |
| 157 | else if (editor->nUndoMode == umAddToRedo) |
| 158 | { |
| 159 | TRACE("Pushing id=%s to redo stack\n", ME_GetDITypeName(type)); |
| 160 | pItem->next = editor->pRedoStack; |
| 161 | if (editor->pRedoStack) |
| 162 | editor->pRedoStack->prev = pItem; |
| 163 | editor->pRedoStack = pItem; |
| 164 | } |
| 165 | else |
| 166 | assert(0); |
| 167 | return (ME_UndoItem *)pItem; |
| 168 | } |
| 169 | } |
| 170 | |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 171 | /** |
| 172 | * Commits preceding changes into a transaction that can be undone together. |
| 173 | * |
| 174 | * This should be called after all the changes occur associated with an event |
| 175 | * so that the group of changes can be undone atomically as a transaction. |
| 176 | * |
| 177 | * This will have no effect the undo mode is set to ignore changes, or if no |
| 178 | * changes preceded calling this function before the last time it was called. |
| 179 | * |
| 180 | * This can also be used to conclude a coalescing transaction (used for grouping |
| 181 | * typed characters). |
| 182 | */ |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 183 | void ME_CommitUndo(ME_TextEditor *editor) { |
Krzysztof Foltman | 898068f | 2005-03-11 10:24:56 +0000 | [diff] [blame] | 184 | if (editor->nUndoMode == umIgnore) |
| 185 | return; |
| 186 | |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 187 | assert(editor->nUndoMode == umAddToUndo); |
| 188 | |
| 189 | /* no transactions, no need to commit */ |
| 190 | if (!editor->pUndoStack) |
| 191 | return; |
| 192 | |
| 193 | /* no need to commit empty transactions */ |
| 194 | if (editor->pUndoStack->type == diUndoEndTransaction) |
| 195 | return; |
| 196 | |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 197 | if (editor->pUndoStack->type == diUndoPotentialEndTransaction) |
| 198 | { |
| 199 | /* Previous transaction was as a result of characters typed, |
| 200 | * so the end of this transaction is confirmed. */ |
| 201 | editor->pUndoStack->type = diUndoEndTransaction; |
| 202 | return; |
| 203 | } |
| 204 | |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 205 | ME_AddUndoItem(editor, diUndoEndTransaction, NULL); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 208 | /** |
Frédéric Delanoy | 7e30960 | 2011-08-02 22:20:32 +0200 | [diff] [blame] | 209 | * Groups subsequent changes with previous ones for an undo if coalescing. |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 210 | * |
| 211 | * Has no effect if the previous changes were followed by a ME_CommitUndo. This |
| 212 | * function will only have an affect if the previous changes were followed by |
| 213 | * a call to ME_CommitCoalescingUndo, which allows the transaction to be |
| 214 | * continued. |
| 215 | * |
| 216 | * This allows multiple consecutively typed characters to be grouped together |
| 217 | * to be undone by a single undo operation. |
| 218 | */ |
| 219 | void ME_ContinueCoalescingTransaction(ME_TextEditor *editor) |
| 220 | { |
| 221 | ME_DisplayItem* p; |
| 222 | |
| 223 | if (editor->nUndoMode == umIgnore) |
| 224 | return; |
| 225 | |
| 226 | assert(editor->nUndoMode == umAddToUndo); |
| 227 | |
| 228 | p = editor->pUndoStack; |
| 229 | |
| 230 | if (p && p->type == diUndoPotentialEndTransaction) { |
| 231 | assert(p->next); /* EndTransactions shouldn't be at bottom of undo stack */ |
| 232 | editor->pUndoStack = p->next; |
| 233 | editor->pUndoStack->prev = NULL; |
| 234 | editor->nUndoStackSize--; |
| 235 | ME_DestroyDisplayItem(p); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Commits preceding changes into a undo transaction that can be expanded. |
| 241 | * |
| 242 | * This function allows the transaction to be reopened with |
| 243 | * ME_ContinueCoalescingTransaction in order to continue the transaction. If an |
| 244 | * undo item is added to the undo stack as a result of a change without the |
| 245 | * transaction being reopened, then the transaction will be ended, and the |
| 246 | * changes will become a part of the next transaction. |
| 247 | * |
| 248 | * This is used to allow typed characters to be grouped together since each |
| 249 | * typed character results in a single event, and each event adding undo items |
| 250 | * must be committed. Using this function as opposed to ME_CommitUndo allows |
| 251 | * multiple events to be grouped, and undone together. |
| 252 | */ |
| 253 | void ME_CommitCoalescingUndo(ME_TextEditor *editor) |
| 254 | { |
| 255 | if (editor->nUndoMode == umIgnore) |
| 256 | return; |
| 257 | |
| 258 | assert(editor->nUndoMode == umAddToUndo); |
| 259 | |
| 260 | /* no transactions, no need to commit */ |
| 261 | if (!editor->pUndoStack) |
| 262 | return; |
| 263 | |
| 264 | /* no need to commit empty transactions */ |
| 265 | if (editor->pUndoStack->type == diUndoEndTransaction) |
| 266 | return; |
| 267 | if (editor->pUndoStack->type == diUndoPotentialEndTransaction) |
| 268 | return; |
| 269 | |
| 270 | ME_AddUndoItem(editor, diUndoPotentialEndTransaction, NULL); |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Andrew Talbot | 166b3a6 | 2007-01-23 21:00:27 +0000 | [diff] [blame] | 273 | static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 274 | { |
| 275 | ME_UndoItem *pUItem = (ME_UndoItem *)pItem; |
| 276 | |
Krzysztof Foltman | 898068f | 2005-03-11 10:24:56 +0000 | [diff] [blame] | 277 | if (editor->nUndoMode == umIgnore) |
| 278 | return; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 279 | TRACE("Playing undo/redo item, id=%s\n", ME_GetDITypeName(pItem->type)); |
| 280 | |
| 281 | switch(pItem->type) |
| 282 | { |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 283 | case diUndoPotentialEndTransaction: |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 284 | case diUndoEndTransaction: |
| 285 | assert(0); |
| 286 | case diUndoSetParagraphFormat: |
| 287 | { |
| 288 | ME_Cursor tmp; |
Dylan Smith | 4e56a3c | 2008-08-04 19:19:01 -0400 | [diff] [blame] | 289 | ME_DisplayItem *para; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 290 | ME_CursorFromCharOfs(editor, pItem->member.para.nCharOfs, &tmp); |
Dylan Smith | 4e56a3c | 2008-08-04 19:19:01 -0400 | [diff] [blame] | 291 | para = ME_FindItemBack(tmp.pRun, diParagraph); |
| 292 | ME_AddUndoItem(editor, diUndoSetParagraphFormat, para); |
| 293 | *para->member.para.pFmt = *pItem->member.para.pFmt; |
Dylan Smith | 3df7871 | 2008-09-30 17:11:19 -0400 | [diff] [blame] | 294 | para->member.para.border = pItem->member.para.border; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | case diUndoSetCharFormat: |
| 298 | { |
Dylan Smith | 2da0d8e | 2009-08-12 09:06:13 -0400 | [diff] [blame] | 299 | ME_Cursor start, end; |
| 300 | ME_CursorFromCharOfs(editor, pUItem->nStart, &start); |
Dylan Smith | 27c28ab | 2009-08-13 08:43:57 -0400 | [diff] [blame] | 301 | end = start; |
| 302 | ME_MoveCursorChars(editor, &end, pUItem->nLen); |
Dylan Smith | 2da0d8e | 2009-08-12 09:06:13 -0400 | [diff] [blame] | 303 | ME_SetCharFormat(editor, &start, &end, &pItem->member.ustyle->fmt); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 304 | break; |
| 305 | } |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 306 | case diUndoInsertRun: |
| 307 | { |
Dylan Smith | 8f0dfab | 2009-08-13 08:44:13 -0400 | [diff] [blame] | 308 | ME_Cursor tmp; |
| 309 | ME_CursorFromCharOfs(editor, pItem->member.run.nCharOfs, &tmp); |
| 310 | ME_InsertRunAtCursor(editor, &tmp, pItem->member.run.style, |
| 311 | pItem->member.run.strText->szData, |
| 312 | pItem->member.run.strText->nLen, |
| 313 | pItem->member.run.nFlags); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | case diUndoDeleteRun: |
| 317 | { |
Dylan Smith | bd47042 | 2009-08-13 08:44:18 -0400 | [diff] [blame] | 318 | ME_Cursor tmp; |
| 319 | ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); |
| 320 | ME_InternalDeleteText(editor, &tmp, pUItem->nLen, TRUE); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
| 323 | case diUndoJoinParagraphs: |
| 324 | { |
| 325 | ME_Cursor tmp; |
| 326 | ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); |
| 327 | /* the only thing that's needed is paragraph offset, so no need to split runs */ |
Dylan Smith | ecb6c21 | 2009-02-09 12:01:35 -0500 | [diff] [blame] | 328 | ME_JoinParagraphs(editor, tmp.pPara, TRUE); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | case diUndoSplitParagraph: |
| 332 | { |
| 333 | ME_Cursor tmp; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 334 | ME_DisplayItem *this_para, *new_para; |
| 335 | BOOL bFixRowStart; |
| 336 | int paraFlags = pItem->member.para.nFlags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 337 | ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); |
| 338 | if (tmp.nOffset) |
Dylan Smith | 8b8e4f8 | 2010-07-29 14:07:40 -0400 | [diff] [blame] | 339 | ME_SplitRunSimple(editor, &tmp); |
Dylan Smith | 5d74f58 | 2009-01-28 01:34:56 -0500 | [diff] [blame] | 340 | assert(pUItem->eol_str); |
Dylan Smith | ecb6c21 | 2009-02-09 12:01:35 -0500 | [diff] [blame] | 341 | this_para = tmp.pPara; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 342 | bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART; |
| 343 | if (bFixRowStart) |
| 344 | { |
| 345 | /* Re-insert the paragraph before the table, making sure the nFlag value |
| 346 | * is correct. */ |
| 347 | this_para->member.para.nFlags &= ~MEPF_ROWSTART; |
| 348 | } |
Alex VillacĂs Lasso | d47f661 | 2008-04-26 13:29:53 -0500 | [diff] [blame] | 349 | new_para = ME_SplitParagraph(editor, tmp.pRun, tmp.pRun->member.run.style, |
Dylan Smith | 5d74f58 | 2009-01-28 01:34:56 -0500 | [diff] [blame] | 350 | pUItem->eol_str, paraFlags); |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 351 | if (bFixRowStart) |
| 352 | new_para->member.para.nFlags |= MEPF_ROWSTART; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 353 | assert(pItem->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); |
Eric Pouech | 34a4f92 | 2008-03-16 21:47:01 +0100 | [diff] [blame] | 354 | *new_para->member.para.pFmt = *pItem->member.para.pFmt; |
Dylan Smith | 3df7871 | 2008-09-30 17:11:19 -0400 | [diff] [blame] | 355 | new_para->member.para.border = pItem->member.para.border; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 356 | if (pItem->member.para.pCell) |
| 357 | { |
| 358 | ME_DisplayItem *pItemCell, *pCell; |
| 359 | pItemCell = pItem->member.para.pCell; |
| 360 | pCell = new_para->member.para.pCell; |
| 361 | pCell->member.cell.nRightBoundary = pItemCell->member.cell.nRightBoundary; |
Dylan Smith | 3df7871 | 2008-09-30 17:11:19 -0400 | [diff] [blame] | 362 | pCell->member.cell.border = pItemCell->member.cell.border; |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 363 | } |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | default: |
| 367 | assert(0 == "PlayUndoItem, unexpected type"); |
| 368 | } |
| 369 | } |
| 370 | |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 371 | BOOL ME_Undo(ME_TextEditor *editor) { |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 372 | ME_DisplayItem *p; |
| 373 | ME_UndoMode nMode = editor->nUndoMode; |
| 374 | |
Krzysztof Foltman | 898068f | 2005-03-11 10:24:56 +0000 | [diff] [blame] | 375 | if (editor->nUndoMode == umIgnore) |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 376 | return FALSE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 377 | assert(nMode == umAddToUndo || nMode == umIgnore); |
| 378 | |
| 379 | /* no undo items ? */ |
| 380 | if (!editor->pUndoStack) |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 381 | return FALSE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 382 | |
Austin English | 313a85f | 2008-04-10 21:17:14 -0500 | [diff] [blame] | 383 | /* watch out for uncommitted transactions ! */ |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 384 | assert(editor->pUndoStack->type == diUndoEndTransaction |
| 385 | || editor->pUndoStack->type == diUndoPotentialEndTransaction); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 386 | |
| 387 | editor->nUndoMode = umAddToRedo; |
| 388 | p = editor->pUndoStack->next; |
| 389 | ME_DestroyDisplayItem(editor->pUndoStack); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 390 | editor->pUndoStack = p; |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 391 | do { |
| 392 | p->prev = NULL; |
| 393 | ME_PlayUndoItem(editor, p); |
| 394 | editor->pUndoStack = p->next; |
| 395 | ME_DestroyDisplayItem(p); |
| 396 | p = editor->pUndoStack; |
| 397 | } while(p && p->type != diUndoEndTransaction); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 398 | if (p) |
| 399 | p->prev = NULL; |
Dylan Smith | 88a3a8a | 2008-09-11 12:45:36 -0400 | [diff] [blame] | 400 | ME_MoveCursorFromTableRowStartParagraph(editor); |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 401 | ME_AddUndoItem(editor, diUndoEndTransaction, NULL); |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 402 | ME_CheckTablesForCorruption(editor); |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 403 | editor->nUndoStackSize--; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 404 | editor->nUndoMode = nMode; |
Dylan Smith | dfa80b3 | 2010-07-28 21:17:40 -0400 | [diff] [blame] | 405 | ME_UpdateRepaint(editor, FALSE); |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 406 | return TRUE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 409 | BOOL ME_Redo(ME_TextEditor *editor) { |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 410 | ME_DisplayItem *p; |
| 411 | ME_UndoMode nMode = editor->nUndoMode; |
| 412 | |
| 413 | assert(nMode == umAddToUndo || nMode == umIgnore); |
| 414 | |
Krzysztof Foltman | 898068f | 2005-03-11 10:24:56 +0000 | [diff] [blame] | 415 | if (editor->nUndoMode == umIgnore) |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 416 | return FALSE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 417 | /* no redo items ? */ |
| 418 | if (!editor->pRedoStack) |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 419 | return FALSE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 420 | |
Austin English | 313a85f | 2008-04-10 21:17:14 -0500 | [diff] [blame] | 421 | /* watch out for uncommitted transactions ! */ |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 422 | assert(editor->pRedoStack->type == diUndoEndTransaction); |
| 423 | |
| 424 | editor->nUndoMode = umAddBackToUndo; |
| 425 | p = editor->pRedoStack->next; |
| 426 | ME_DestroyDisplayItem(editor->pRedoStack); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 427 | editor->pRedoStack = p; |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 428 | do { |
| 429 | p->prev = NULL; |
| 430 | ME_PlayUndoItem(editor, p); |
| 431 | editor->pRedoStack = p->next; |
| 432 | ME_DestroyDisplayItem(p); |
| 433 | p = editor->pRedoStack; |
| 434 | } while(p && p->type != diUndoEndTransaction); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 435 | if (p) |
| 436 | p->prev = NULL; |
Dylan Smith | 88a3a8a | 2008-09-11 12:45:36 -0400 | [diff] [blame] | 437 | ME_MoveCursorFromTableRowStartParagraph(editor); |
Dylan Smith | ebded16 | 2008-07-06 15:27:40 -0400 | [diff] [blame] | 438 | ME_AddUndoItem(editor, diUndoEndTransaction, NULL); |
Dylan Smith | 300db37 | 2008-08-07 12:31:41 -0400 | [diff] [blame] | 439 | ME_CheckTablesForCorruption(editor); |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 440 | editor->nUndoMode = nMode; |
Dylan Smith | dfa80b3 | 2010-07-28 21:17:40 -0400 | [diff] [blame] | 441 | ME_UpdateRepaint(editor, FALSE); |
Dylan Smith | d1f1346 | 2008-06-25 10:29:19 -0400 | [diff] [blame] | 442 | return TRUE; |
Krzysztof Foltman | d488f3f | 2005-03-05 11:19:14 +0000 | [diff] [blame] | 443 | } |