2 * RichEdit functions dealing with on tables
4 * Copyright 2008 by Dylan Smith
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.
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.
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * The implementation of tables differs greatly between version 3.0
23 * (in riched20.dll) and version 4.1 (in msftedit.dll) of richedit controls.
24 * Currently Wine is not distinguishing between version 3.0 and version 4.1,
25 * so v4.1 is assumed unless v1.0 is being emulated (i.e. riched32.dll is used).
26 * If this lack of distinction causes a bug in a Windows application, then Wine
27 * will need to start making this distinction.
29 * Richedit version 1.0 - 3.0:
30 * Tables are implemented in these versions using tabs at the end of cells,
31 * and tab stops to position the cells. The paragraph format flag PFE_TABLE
32 * will indicate that the paragraph is a table row. Note that in this
33 * implementation there is one paragraph per table row.
35 * Richedit version 4.1:
36 * Tables are implemented such that cells can contain multiple paragraphs,
37 * each with it's own paragraph format, and cells may even contain tables
38 * nested within the cell.
40 * There is also a paragraph at the start of each table row that contains
41 * the rows paragraph format (e.g. to change the row alignment to row), and a
42 * paragraph at the end of the table row with the PFE_TABLEROWDELIMITER flag
43 * set. The paragraphs at the start and end of the table row should always be
44 * empty, but should have a length of 2.
46 * Wine implements this using display items (ME_DisplayItem) with a type of
47 * diCell. These cell display items store the cell properties, and are
48 * inserted into the editors linked list before each cell, and at the end of
49 * the last cell. The cell display item for a cell comes before the paragraphs
50 * for the cell, but the last cell display item refers to no cell, so it is
57 WINE_DEFAULT_DEBUG_CHANNEL(richedit_lists);
59 static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
64 ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
66 ME_Cursor* cursor = &editor->pCursors[nCursor];
67 if (cursor->nOffset) {
68 ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
69 cursor = &editor->pCursors[nCursor];
72 tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags);
73 ME_ReleaseStyle(pStyle);
75 cursor->pRun = ME_FindItemFwd(tp, diRun);
79 ME_DisplayItem* ME_InsertTableRowStartFromCursor(ME_TextEditor *editor)
82 WCHAR cr_lf[] = {'\r', '\n', 0};
83 ME_String *eol_str = ME_MakeStringN(cr_lf, 2);
84 para = ME_InsertEndParaFromCursor(editor, 0, eol_str, MEPF_ROWSTART);
85 return para->member.para.prev_para;
88 ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
91 ME_DisplayItem *prev_para, *end_para;
92 ME_Cursor savedCursor = editor->pCursors[0];
93 ME_DisplayItem *startRowPara;
94 editor->pCursors[0].pPara = para;
95 editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
96 editor->pCursors[0].nOffset = 0;
97 editor->pCursors[1] = editor->pCursors[0];
98 startRowPara = ME_InsertTableRowStartFromCursor(editor);
99 savedCursor.pPara = ME_GetParagraph(savedCursor.pRun);
100 editor->pCursors[0] = savedCursor;
101 editor->pCursors[1] = editor->pCursors[0];
103 end_para = editor->pCursors[0].pPara->member.para.next_para;
104 prev_para = startRowPara->member.para.next_para;
105 para = prev_para->member.para.next_para;
106 while (para != end_para)
108 para->member.para.pCell = prev_para->member.para.pCell;
109 para->member.para.nFlags |= MEPF_CELL;
110 para->member.para.nFlags &= ~(MEPF_ROWSTART|MEPF_ROWEND);
111 para->member.para.pFmt->dwMask |= PFM_TABLE|PFM_TABLEROWDELIMITER;
112 para->member.para.pFmt->wEffects |= PFE_TABLE;
113 para->member.para.pFmt->wEffects &= ~PFE_TABLEROWDELIMITER;
115 para = para->member.para.next_para;
120 /* Inserts a diCell and starts a new paragraph for the next cell.
122 * Returns the first paragraph of the new cell. */
123 ME_DisplayItem* ME_InsertTableCellFromCursor(ME_TextEditor *editor)
125 ME_DisplayItem *para;
127 ME_String *eol_str = ME_MakeStringN(&tab, 1);
128 para = ME_InsertEndParaFromCursor(editor, 0, eol_str, MEPF_CELL);
132 ME_DisplayItem* ME_InsertTableRowEndFromCursor(ME_TextEditor *editor)
134 ME_DisplayItem *para;
135 WCHAR cr_lf[] = {'\r', '\n', 0};
136 ME_String *eol_str = ME_MakeStringN(cr_lf, 2);
137 para = ME_InsertEndParaFromCursor(editor, 0, eol_str, MEPF_ROWEND);
138 return para->member.para.prev_para;
141 ME_DisplayItem* ME_GetTableRowEnd(ME_DisplayItem *para)
143 ME_DisplayItem *cell;
145 if (para->member.para.nFlags & MEPF_ROWEND)
147 if (para->member.para.nFlags & MEPF_ROWSTART)
148 para = para->member.para.next_para;
149 cell = para->member.para.pCell;
150 assert(cell && cell->type == diCell);
151 while (cell->member.cell.next_cell)
152 cell = cell->member.cell.next_cell;
154 para = ME_FindItemFwd(cell, diParagraph);
155 assert(para && para->member.para.nFlags & MEPF_ROWEND);
159 ME_DisplayItem* ME_GetTableRowStart(ME_DisplayItem *para)
161 ME_DisplayItem *cell;
163 if (para->member.para.nFlags & MEPF_ROWSTART)
165 if (para->member.para.nFlags & MEPF_ROWEND)
166 para = para->member.para.prev_para;
167 cell = para->member.para.pCell;
168 assert(cell && cell->type == diCell);
169 while (cell->member.cell.prev_cell)
170 cell = cell->member.cell.prev_cell;
172 para = ME_FindItemBack(cell, diParagraph);
173 assert(para && para->member.para.nFlags & MEPF_ROWSTART);
177 /* Make a bunch of assertions to make sure tables haven't been corrupted.
179 * These invariants may not hold true in the middle of streaming in rich text
180 * or during an undo and redo of streaming in rich text. It should be safe to
181 * call this method after an event is processed.
183 void ME_CheckTablesForCorruption(ME_TextEditor *editor)
185 if(TRACE_ON(richedit_lists))
188 ME_DumpDocument(editor->pBuffer);
192 ME_DisplayItem *p, *pPrev;
193 pPrev = editor->pBuffer->pFirst;
195 if (!editor->bEmulateVersion10) /* v4.1 */
197 while (p->type == diParagraph)
199 assert(p->member.para.pFmt->dwMask & PFM_TABLE);
200 assert(p->member.para.pFmt->dwMask & PFM_TABLEROWDELIMITER);
201 if (p->member.para.pCell)
203 assert(p->member.para.nFlags & MEPF_CELL);
204 assert(p->member.para.pFmt->wEffects & PFE_TABLE);
206 if (p->member.para.pCell != pPrev->member.para.pCell)
208 /* There must be a diCell in between the paragraphs if pCell changes. */
209 ME_DisplayItem *pCell = ME_FindItemBack(p, diCell);
211 assert(ME_FindItemBack(p, diRun) == ME_FindItemBack(pCell, diRun));
213 if (p->member.para.nFlags & MEPF_ROWEND)
215 /* ROWEND must come after a cell. */
216 assert(pPrev->member.para.pCell);
217 assert(p->member.para.pCell
218 == pPrev->member.para.pCell->member.cell.parent_cell);
219 assert(p->member.para.pFmt->wEffects & PFE_TABLEROWDELIMITER);
221 else if (p->member.para.pCell)
223 assert(!(p->member.para.pFmt->wEffects & PFE_TABLEROWDELIMITER));
224 assert(pPrev->member.para.pCell ||
225 pPrev->member.para.nFlags & MEPF_ROWSTART);
226 if (pPrev->member.para.pCell &&
227 !(pPrev->member.para.nFlags & MEPF_ROWSTART))
229 assert(p->member.para.pCell->member.cell.parent_cell
230 == pPrev->member.para.pCell->member.cell.parent_cell);
231 if (pPrev->member.para.pCell != p->member.para.pCell)
232 assert(pPrev->member.para.pCell
233 == p->member.para.pCell->member.cell.prev_cell);
236 else if (!(p->member.para.nFlags & MEPF_ROWSTART))
238 assert(!(p->member.para.pFmt->wEffects & PFE_TABLEROWDELIMITER));
239 /* ROWSTART must be followed by a cell. */
240 assert(!(p->member.para.nFlags & MEPF_CELL));
241 /* ROWSTART must be followed by a cell. */
242 assert(!(pPrev->member.para.nFlags & MEPF_ROWSTART));
245 p = p->member.para.next_para;
247 } else { /* v1.0 - 3.0 */
248 while (p->type == diParagraph)
250 assert(!(p->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL)));
251 assert(p->member.para.pFmt->dwMask & PFM_TABLE);
252 assert(!(p->member.para.pFmt->wEffects & PFM_TABLEROWDELIMITER));
253 assert(!p->member.para.pCell);
254 p = p->member.para.next_para;
258 assert(p->type == diTextEnd);
259 assert(!pPrev->member.para.pCell);
264 BOOL ME_IsInTable(ME_DisplayItem *pItem)
269 if (pItem->type == diRun)
270 pItem = ME_GetParagraph(pItem);
271 if (pItem->type != diParagraph)
273 pFmt = pItem->member.para.pFmt;
274 return pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE;
277 /* Table rows should either be deleted completely or not at all. */
278 void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars)
281 ME_DisplayItem *this_para, *end_para;
282 ME_CursorFromCharOfs(editor, nOfs, &c);
284 ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2);
286 if (c2.pRun->member.run.nFlags & MERF_ENDPARA) {
287 /* End offset might be in the middle of the end paragraph run.
288 * If this is the case, then we need to use the next paragraph as the last
291 int remaining = nOfs + *nChars - c2.pRun->member.run.nCharOfs
292 - end_para->member.para.nCharOfs;
295 assert(remaining < c2.pRun->member.run.strText->nLen);
296 end_para = end_para->member.para.next_para;
299 if (!editor->bEmulateVersion10) { /* v4.1 */
300 if (this_para->member.para.pCell != end_para->member.para.pCell ||
301 ((this_para->member.para.nFlags|end_para->member.para.nFlags)
302 & (MEPF_ROWSTART|MEPF_ROWEND)))
304 while (this_para != end_para)
306 ME_DisplayItem *next_para = this_para->member.para.next_para;
307 BOOL bTruancateDeletion = FALSE;
308 if (this_para->member.para.nFlags & MEPF_ROWSTART) {
309 /* The following while loop assumes that next_para is MEPF_ROWSTART,
310 * so moving back one paragraph let's it be processed as the start
312 next_para = this_para;
313 this_para = this_para->member.para.prev_para;
314 } else if (next_para->member.para.pCell != this_para->member.para.pCell
315 || this_para->member.para.nFlags & MEPF_ROWEND)
317 /* Start of the deletion from after the start of the table row. */
318 bTruancateDeletion = TRUE;
320 while (!bTruancateDeletion &&
321 next_para->member.para.nFlags & MEPF_ROWSTART)
323 next_para = ME_GetTableRowEnd(next_para)->member.para.next_para;
324 if (next_para->member.para.nCharOfs > nOfs + *nChars)
326 /* End of deletion is not past the end of the table row. */
327 next_para = this_para->member.para.next_para;
328 /* Delete the end paragraph preceding the table row if the
329 * preceding table row will be empty. */
330 if (this_para->member.para.nCharOfs >= nOfs)
332 next_para = next_para->member.para.next_para;
334 bTruancateDeletion = TRUE;
336 this_para = next_para->member.para.prev_para;
339 if (bTruancateDeletion)
341 ME_Run *end_run = &ME_FindItemBack(next_para, diRun)->member.run;
342 int nCharsNew = (next_para->member.para.nCharOfs - nOfs
343 - end_run->strText->nLen);
344 nCharsNew = max(nCharsNew, 0);
345 assert(nCharsNew <= *nChars);
349 this_para = next_para;
352 } else { /* v1.0 - 3.0 */
353 ME_DisplayItem *pRun;
354 int nCharsToBoundary;
356 if ((this_para->member.para.nCharOfs != nOfs || this_para == end_para) &&
357 this_para->member.para.pFmt->dwMask & PFM_TABLE &&
358 this_para->member.para.pFmt->wEffects & PFE_TABLE)
361 /* Find the next tab or end paragraph to use as a delete boundary */
362 while (!(pRun->member.run.nFlags & (MERF_TAB|MERF_ENDPARA)))
363 pRun = ME_FindItemFwd(pRun, diRun);
364 nCharsToBoundary = pRun->member.run.nCharOfs
365 - c.pRun->member.run.nCharOfs
367 *nChars = min(*nChars, nCharsToBoundary);
368 } else if (end_para->member.para.pFmt->dwMask & PFM_TABLE &&
369 end_para->member.para.pFmt->wEffects & PFE_TABLE)
371 /* The deletion starts from before the row, so don't join it with
372 * previous non-empty paragraphs. */
373 ME_DisplayItem *curPara;
375 if (nOfs > this_para->member.para.nCharOfs) {
376 pRun = ME_FindItemBack(end_para, diRun);
377 curPara = end_para->member.para.prev_para;
380 pRun = ME_FindItemFwd(end_para, diRun);
385 nCharsToBoundary = curPara->member.para.nCharOfs
386 + pRun->member.run.nCharOfs
388 if (nCharsToBoundary >= 0)
389 *nChars = min(*nChars, nCharsToBoundary);
397 ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
398 ME_DisplayItem *table_row)
400 WCHAR endl = '\r', tab = '\t';
406 assert(table_row->type == diParagraph);
407 if (!editor->bEmulateVersion10) { /* v4.1 */
408 ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd;
409 cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell);
410 prevTableEnd = ME_GetTableRowEnd(table_row);
411 para = prevTableEnd->member.para.next_para;
412 run = ME_FindItemFwd(para, diRun);
413 editor->pCursors[0].pPara = para;
414 editor->pCursors[0].pRun = run;
415 editor->pCursors[0].nOffset = 0;
416 editor->pCursors[1] = editor->pCursors[0];
417 para = ME_InsertTableRowStartFromCursor(editor);
418 insertedCell = ME_FindItemFwd(para, diCell);
419 /* Copy cell properties */
420 insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
421 insertedCell->member.cell.border = cell->member.cell.border;
422 while (cell->member.cell.next_cell) {
423 cell = cell->member.cell.next_cell;
424 para = ME_InsertTableCellFromCursor(editor);
425 insertedCell = ME_FindItemBack(para, diCell);
426 /* Copy cell properties */
427 insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
428 insertedCell->member.cell.border = cell->member.cell.border;
430 para = ME_InsertTableRowEndFromCursor(editor);
431 *para->member.para.pFmt = *prevTableEnd->member.para.pFmt;
432 /* return the table row start for the inserted paragraph */
433 return ME_FindItemFwd(cell, diParagraph)->member.para.next_para;
434 } else { /* v1.0 - 3.0 */
435 run = ME_FindItemBack(table_row->member.para.next_para, diRun);
436 pFmt = table_row->member.para.pFmt;
437 assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE);
438 editor->pCursors[0].pPara = table_row;
439 editor->pCursors[0].pRun = run;
440 editor->pCursors[0].nOffset = 0;
441 editor->pCursors[1] = editor->pCursors[0];
442 ME_InsertTextFromCursor(editor, 0, &endl, 1, run->member.run.style);
443 run = editor->pCursors[0].pRun;
444 for (i = 0; i < pFmt->cTabCount; i++) {
445 ME_InsertTextFromCursor(editor, 0, &tab, 1, run->member.run.style);
447 return table_row->member.para.next_para;
451 /* Selects the next table cell or appends a new table row if at end of table */
452 static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
455 ME_DisplayItem *para = ME_GetParagraph(run);
458 assert(run && run->type == diRun);
459 assert(ME_IsInTable(run));
460 if (!editor->bEmulateVersion10) { /* v4.1 */
461 ME_DisplayItem *cell;
462 /* Get the initial cell */
463 if (para->member.para.nFlags & MEPF_ROWSTART) {
464 cell = para->member.para.next_para->member.para.pCell;
465 } else if (para->member.para.nFlags & MEPF_ROWEND) {
466 cell = para->member.para.prev_para->member.para.pCell;
468 cell = para->member.para.pCell;
471 /* Get the next cell. */
472 if (cell->member.cell.next_cell &&
473 cell->member.cell.next_cell->member.cell.next_cell)
475 cell = cell->member.cell.next_cell;
477 para = ME_GetTableRowEnd(ME_FindItemFwd(cell, diParagraph));
478 para = para->member.para.next_para;
480 if (para->member.para.nFlags & MEPF_ROWSTART) {
481 cell = para->member.para.next_para->member.para.pCell;
484 para = para->member.para.prev_para;
485 para = ME_AppendTableRow(editor, ME_GetTableRowStart(para));
486 /* Put cursor at the start of the new table row */
487 para = para->member.para.next_para;
488 editor->pCursors[0].pPara = para;
489 editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
490 editor->pCursors[0].nOffset = 0;
491 editor->pCursors[1] = editor->pCursors[0];
492 ME_WrapMarkedParagraphs(editor);
497 editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun);
498 editor->pCursors[1].pPara = ME_GetParagraph(editor->pCursors[1].pRun);
499 editor->pCursors[1].nOffset = 0;
500 assert(editor->pCursors[0].pRun);
501 cell = cell->member.cell.next_cell;
502 editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun);
503 editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun);
504 editor->pCursors[0].nOffset = 0;
505 assert(editor->pCursors[1].pRun);
506 } else { /* v1.0 - 3.0 */
507 if (run->member.run.nFlags & MERF_ENDPARA &&
508 ME_IsInTable(ME_FindItemFwd(run, diParagraphOrEnd)))
510 run = ME_FindItemFwd(run, diRun);
513 for (i = 0; i < 2; i++)
515 while (!(run->member.run.nFlags & MERF_TAB))
517 run = ME_FindItemFwd(run, diRunOrParagraphOrEnd);
518 if (run->type != diRun)
521 if (ME_IsInTable(para))
523 run = ME_FindItemFwd(para, diRun);
525 editor->pCursors[0].pPara = para;
526 editor->pCursors[0].pRun = run;
527 editor->pCursors[0].nOffset = 0;
530 /* Insert table row */
531 para = ME_AppendTableRow(editor, para->member.para.prev_para);
532 /* Put cursor at the start of the new table row */
533 editor->pCursors[0].pPara = para;
534 editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
535 editor->pCursors[0].nOffset = 0;
536 editor->pCursors[1] = editor->pCursors[0];
537 ME_WrapMarkedParagraphs(editor);
543 run = ME_FindItemFwd(run, diRun);
544 editor->pCursors[i].pRun = run;
545 editor->pCursors[i].pPara = ME_GetParagraph(run);
546 editor->pCursors[i].nOffset = 0;
552 void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
554 /* FIXME: Shift tab should move to the previous cell. */
555 ME_Cursor fromCursor, toCursor;
556 ME_InvalidateSelection(editor);
559 from = ME_GetCursorOfs(&editor->pCursors[0]);
560 to = ME_GetCursorOfs(&editor->pCursors[1]);
563 fromCursor = editor->pCursors[0];
564 toCursor = editor->pCursors[1];
566 fromCursor = editor->pCursors[1];
567 toCursor = editor->pCursors[0];
570 if (!editor->bEmulateVersion10) /* v4.1 */
572 if (!ME_IsInTable(toCursor.pRun))
574 editor->pCursors[0] = toCursor;
575 editor->pCursors[1] = toCursor;
577 ME_SelectOrInsertNextCell(editor, toCursor.pRun);
579 } else { /* v1.0 - 3.0 */
580 if (!ME_IsInTable(fromCursor.pRun)) {
581 editor->pCursors[0] = fromCursor;
582 editor->pCursors[1] = fromCursor;
583 /* FIXME: For some reason the caret is shown at the start of the
584 * previous paragraph in v1.0 to v3.0, and bCaretAtEnd only works
585 * within the paragraph for wrapped lines. */
586 if (ME_FindItemBack(fromCursor.pRun, diRun))
587 editor->bCaretAtEnd = TRUE;
588 } else if ((bSelectedRow || !ME_IsInTable(toCursor.pRun))) {
589 ME_SelectOrInsertNextCell(editor, fromCursor.pRun);
591 if (ME_IsSelection(editor) && !toCursor.nOffset)
594 run = ME_FindItemBack(toCursor.pRun, diRunOrParagraphOrEnd);
595 if (run->type == diRun && run->member.run.nFlags & MERF_TAB)
596 ME_SelectOrInsertNextCell(editor, run);
598 ME_SelectOrInsertNextCell(editor, toCursor.pRun);
600 ME_SelectOrInsertNextCell(editor, toCursor.pRun);
604 ME_InvalidateSelection(editor);
606 ITextHost_TxShowCaret(editor->texthost, FALSE);
607 ME_ShowCaret(editor);
608 ME_SendSelChange(editor);
611 /* Make sure the cursor is not in the hidden table row start paragraph
612 * without a selection. */
613 void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor)
615 ME_DisplayItem *para = editor->pCursors[0].pPara;
616 if (para == editor->pCursors[1].pPara &&
617 para->member.para.nFlags & MEPF_ROWSTART) {
618 /* The cursors should not be at the hidden start row paragraph without
619 * a selection, so the cursor is moved into the first cell. */
620 para = para->member.para.next_para;
621 editor->pCursors[0].pPara = para;
622 editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
623 editor->pCursors[0].nOffset = 0;
624 editor->pCursors[1] = editor->pCursors[0];
628 struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor)
630 RTFTable *tableDef = ALLOC_OBJ(RTFTable);
631 ZeroMemory(tableDef, sizeof(RTFTable));
632 if (!editor->bEmulateVersion10) /* v4.1 */
637 void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef)
639 ZeroMemory(tableDef->cells, sizeof(tableDef->cells));
640 ZeroMemory(tableDef->border, sizeof(tableDef->border));
641 tableDef->numCellsDefined = 0;
642 tableDef->leftEdge = 0;
643 if (!editor->bEmulateVersion10) /* v4.1 */
645 else /* v1.0 - 3.0 */