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(&cr
, 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. */
374 if (nOfs
> this_para
->member
.para
.nCharOfs
)
375 pRun
= ME_FindItemBack(end_para
, diRun
);
377 pRun
= ME_FindItemFwd(end_para
, diRun
);
380 nCharsToBoundary
= ME_GetParagraph(pRun
)->member
.para
.nCharOfs
381 + pRun
->member
.run
.nCharOfs
383 if (nCharsToBoundary
>= 0)
384 *nChars
= min(*nChars
, nCharsToBoundary
);
392 ME_DisplayItem
* ME_AppendTableRow(ME_TextEditor
*editor
,
393 ME_DisplayItem
*table_row
)
395 WCHAR endl
= '\r', tab
= '\t';
401 assert(table_row
->type
== diParagraph
);
402 if (!editor
->bEmulateVersion10
) { /* v4.1 */
403 ME_DisplayItem
*insertedCell
, *para
, *cell
, *prevTableEnd
;
404 cell
= ME_FindItemFwd(ME_GetTableRowStart(table_row
), diCell
);
405 prevTableEnd
= ME_GetTableRowEnd(table_row
);
406 para
= prevTableEnd
->member
.para
.next_para
;
407 run
= ME_FindItemFwd(para
, diRun
);
408 editor
->pCursors
[0].pPara
= para
;
409 editor
->pCursors
[0].pRun
= run
;
410 editor
->pCursors
[0].nOffset
= 0;
411 editor
->pCursors
[1] = editor
->pCursors
[0];
412 para
= ME_InsertTableRowStartFromCursor(editor
);
413 insertedCell
= ME_FindItemFwd(para
, diCell
);
414 /* Copy cell properties */
415 insertedCell
->member
.cell
.nRightBoundary
= cell
->member
.cell
.nRightBoundary
;
416 insertedCell
->member
.cell
.border
= cell
->member
.cell
.border
;
417 while (cell
->member
.cell
.next_cell
) {
418 cell
= cell
->member
.cell
.next_cell
;
419 para
= ME_InsertTableCellFromCursor(editor
);
420 insertedCell
= ME_FindItemBack(para
, diCell
);
421 /* Copy cell properties */
422 insertedCell
->member
.cell
.nRightBoundary
= cell
->member
.cell
.nRightBoundary
;
423 insertedCell
->member
.cell
.border
= cell
->member
.cell
.border
;
425 para
= ME_InsertTableRowEndFromCursor(editor
);
426 *para
->member
.para
.pFmt
= *prevTableEnd
->member
.para
.pFmt
;
427 /* return the table row start for the inserted paragraph */
428 return ME_FindItemFwd(cell
, diParagraph
)->member
.para
.next_para
;
429 } else { /* v1.0 - 3.0 */
430 run
= ME_FindItemBack(table_row
->member
.para
.next_para
, diRun
);
431 pFmt
= table_row
->member
.para
.pFmt
;
432 assert(pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
);
433 editor
->pCursors
[0].pPara
= table_row
;
434 editor
->pCursors
[0].pRun
= run
;
435 editor
->pCursors
[0].nOffset
= 0;
436 editor
->pCursors
[1] = editor
->pCursors
[0];
437 ME_InsertTextFromCursor(editor
, 0, &endl
, 1, run
->member
.run
.style
);
438 run
= editor
->pCursors
[0].pRun
;
439 for (i
= 0; i
< pFmt
->cTabCount
; i
++) {
440 ME_InsertTextFromCursor(editor
, 0, &tab
, 1, run
->member
.run
.style
);
442 return table_row
->member
.para
.next_para
;
446 /* Selects the next table cell or appends a new table row if at end of table */
447 static void ME_SelectOrInsertNextCell(ME_TextEditor
*editor
,
450 ME_DisplayItem
*para
= ME_GetParagraph(run
);
453 assert(run
&& run
->type
== diRun
);
454 assert(ME_IsInTable(run
));
455 if (!editor
->bEmulateVersion10
) { /* v4.1 */
456 ME_DisplayItem
*cell
;
457 /* Get the initial cell */
458 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
) {
459 cell
= para
->member
.para
.next_para
->member
.para
.pCell
;
460 } else if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
461 cell
= para
->member
.para
.prev_para
->member
.para
.pCell
;
463 cell
= para
->member
.para
.pCell
;
466 /* Get the next cell. */
467 if (cell
->member
.cell
.next_cell
&&
468 cell
->member
.cell
.next_cell
->member
.cell
.next_cell
)
470 cell
= cell
->member
.cell
.next_cell
;
472 para
= ME_GetTableRowEnd(ME_FindItemFwd(cell
, diParagraph
));
473 para
= para
->member
.para
.next_para
;
475 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
) {
476 cell
= para
->member
.para
.next_para
->member
.para
.pCell
;
479 para
= para
->member
.para
.prev_para
;
480 para
= ME_AppendTableRow(editor
, ME_GetTableRowStart(para
));
481 /* Put cursor at the start of the new table row */
482 para
= para
->member
.para
.next_para
;
483 editor
->pCursors
[0].pPara
= para
;
484 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
485 editor
->pCursors
[0].nOffset
= 0;
486 editor
->pCursors
[1] = editor
->pCursors
[0];
487 ME_WrapMarkedParagraphs(editor
);
492 editor
->pCursors
[1].pRun
= ME_FindItemFwd(cell
, diRun
);
493 editor
->pCursors
[1].pPara
= ME_GetParagraph(editor
->pCursors
[1].pRun
);
494 editor
->pCursors
[1].nOffset
= 0;
495 assert(editor
->pCursors
[0].pRun
);
496 cell
= cell
->member
.cell
.next_cell
;
497 editor
->pCursors
[0].pRun
= ME_FindItemBack(cell
, diRun
);
498 editor
->pCursors
[0].pPara
= ME_GetParagraph(editor
->pCursors
[0].pRun
);
499 editor
->pCursors
[0].nOffset
= 0;
500 assert(editor
->pCursors
[1].pRun
);
501 } else { /* v1.0 - 3.0 */
502 if (run
->member
.run
.nFlags
& MERF_ENDPARA
&&
503 ME_IsInTable(ME_FindItemFwd(run
, diParagraphOrEnd
)))
505 run
= ME_FindItemFwd(run
, diRun
);
508 for (i
= 0; i
< 2; i
++)
510 while (!(run
->member
.run
.nFlags
& MERF_TAB
))
512 run
= ME_FindItemFwd(run
, diRunOrParagraphOrEnd
);
513 if (run
->type
!= diRun
)
516 if (ME_IsInTable(para
))
518 run
= ME_FindItemFwd(para
, diRun
);
520 editor
->pCursors
[0].pPara
= para
;
521 editor
->pCursors
[0].pRun
= run
;
522 editor
->pCursors
[0].nOffset
= 0;
525 /* Insert table row */
526 para
= ME_AppendTableRow(editor
, para
->member
.para
.prev_para
);
527 /* Put cursor at the start of the new table row */
528 editor
->pCursors
[0].pPara
= para
;
529 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
530 editor
->pCursors
[0].nOffset
= 0;
531 editor
->pCursors
[1] = editor
->pCursors
[0];
532 ME_WrapMarkedParagraphs(editor
);
538 run
= ME_FindItemFwd(run
, diRun
);
539 editor
->pCursors
[i
].pRun
= run
;
540 editor
->pCursors
[i
].pPara
= ME_GetParagraph(run
);
541 editor
->pCursors
[i
].nOffset
= 0;
547 void ME_TabPressedInTable(ME_TextEditor
*editor
, BOOL bSelectedRow
)
549 /* FIXME: Shift tab should move to the previous cell. */
550 ME_Cursor fromCursor
, toCursor
;
551 ME_InvalidateSelection(editor
);
554 from
= ME_GetCursorOfs(editor
, 0);
555 to
= ME_GetCursorOfs(editor
, 1);
558 fromCursor
= editor
->pCursors
[0];
559 toCursor
= editor
->pCursors
[1];
561 fromCursor
= editor
->pCursors
[1];
562 toCursor
= editor
->pCursors
[0];
565 if (!editor
->bEmulateVersion10
) /* v4.1 */
567 if (!ME_IsInTable(toCursor
.pRun
))
569 editor
->pCursors
[0] = toCursor
;
570 editor
->pCursors
[1] = toCursor
;
572 ME_SelectOrInsertNextCell(editor
, toCursor
.pRun
);
574 } else { /* v1.0 - 3.0 */
575 if (!ME_IsInTable(fromCursor
.pRun
)) {
576 editor
->pCursors
[0] = fromCursor
;
577 editor
->pCursors
[1] = fromCursor
;
578 /* FIXME: For some reason the caret is shown at the start of the
579 * previous paragraph in v1.0 to v3.0, and bCaretAtEnd only works
580 * within the paragraph for wrapped lines. */
581 if (ME_FindItemBack(fromCursor
.pRun
, diRun
))
582 editor
->bCaretAtEnd
= TRUE
;
583 } else if ((bSelectedRow
|| !ME_IsInTable(toCursor
.pRun
))) {
584 ME_SelectOrInsertNextCell(editor
, fromCursor
.pRun
);
586 if (ME_IsSelection(editor
) && !toCursor
.nOffset
)
589 run
= ME_FindItemBack(toCursor
.pRun
, diRunOrParagraphOrEnd
);
590 if (run
->type
== diRun
&& run
->member
.run
.nFlags
& MERF_TAB
)
591 ME_SelectOrInsertNextCell(editor
, run
);
593 ME_SelectOrInsertNextCell(editor
, toCursor
.pRun
);
595 ME_SelectOrInsertNextCell(editor
, toCursor
.pRun
);
599 ME_InvalidateSelection(editor
);
601 ITextHost_TxShowCaret(editor
->texthost
, FALSE
);
602 ME_ShowCaret(editor
);
603 ME_SendSelChange(editor
);
606 /* Make sure the cursor is not in the hidden table row start paragraph
607 * without a selection. */
608 void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor
*editor
)
610 ME_DisplayItem
*para
= editor
->pCursors
[0].pPara
;
611 if (para
== editor
->pCursors
[1].pPara
&&
612 para
->member
.para
.nFlags
& MEPF_ROWSTART
) {
613 /* The cursors should not be at the hidden start row paragraph without
614 * a selection, so the cursor is moved into the first cell. */
615 para
= para
->member
.para
.next_para
;
616 editor
->pCursors
[0].pPara
= para
;
617 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
618 editor
->pCursors
[0].nOffset
= 0;
619 editor
->pCursors
[1] = editor
->pCursors
[0];
623 struct RTFTable
*ME_MakeTableDef(ME_TextEditor
*editor
)
625 RTFTable
*tableDef
= ALLOC_OBJ(RTFTable
);
626 ZeroMemory(tableDef
, sizeof(RTFTable
));
627 if (!editor
->bEmulateVersion10
) /* v4.1 */
632 void ME_InitTableDef(ME_TextEditor
*editor
, struct RTFTable
*tableDef
)
634 ZeroMemory(tableDef
->cells
, sizeof(tableDef
->cells
));
635 ZeroMemory(tableDef
->border
, sizeof(tableDef
->border
));
636 tableDef
->numCellsDefined
= 0;
637 tableDef
->leftEdge
= 0;
638 if (!editor
->bEmulateVersion10
) /* v4.1 */
640 else /* v1.0 - 3.0 */