2008-08-05 16:10:47 +00:00
|
|
|
/*
|
|
|
|
* RichEdit functions dealing with on tables
|
|
|
|
*
|
|
|
|
* Copyright 2008 by Dylan Smith
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The implementation of tables differs greatly between version 3.0
|
|
|
|
* (in riched20.dll) and version 4.1 (in msftedit.dll) of richedit controls.
|
2008-08-07 16:31:41 +00:00
|
|
|
* Currently Wine is not distinguishing between version 3.0 and version 4.1,
|
|
|
|
* so v4.1 is assumed unless v1.0 is being emulated (i.e. riched32.dll is used).
|
|
|
|
* If this lack of distinction causes a bug in a Windows application, then Wine
|
|
|
|
* will need to start making this distinction.
|
2008-08-05 16:10:47 +00:00
|
|
|
*
|
|
|
|
* Richedit version 1.0 - 3.0:
|
|
|
|
* Tables are implemented in these versions using tabs at the end of cells,
|
|
|
|
* and tab stops to position the cells. The paragraph format flag PFE_TABLE
|
2008-09-01 15:01:17 +00:00
|
|
|
* will indicate that the paragraph is a table row. Note that in this
|
2008-08-05 16:10:47 +00:00
|
|
|
* implementation there is one paragraph per table row.
|
2008-08-07 16:31:41 +00:00
|
|
|
*
|
|
|
|
* Richedit version 4.1:
|
|
|
|
* Tables are implemented such that cells can contain multiple paragraphs,
|
2014-02-07 21:42:49 +00:00
|
|
|
* each with its own paragraph format, and cells may even contain tables
|
2008-08-07 16:31:41 +00:00
|
|
|
* nested within the cell.
|
|
|
|
*
|
2008-09-01 15:01:17 +00:00
|
|
|
* There is also a paragraph at the start of each table row that contains
|
2008-08-07 16:31:41 +00:00
|
|
|
* the rows paragraph format (e.g. to change the row alignment to row), and a
|
|
|
|
* paragraph at the end of the table row with the PFE_TABLEROWDELIMITER flag
|
|
|
|
* set. The paragraphs at the start and end of the table row should always be
|
|
|
|
* empty, but should have a length of 2.
|
|
|
|
*
|
|
|
|
* Wine implements this using display items (ME_DisplayItem) with a type of
|
|
|
|
* diCell. These cell display items store the cell properties, and are
|
|
|
|
* inserted into the editors linked list before each cell, and at the end of
|
|
|
|
* the last cell. The cell display item for a cell comes before the paragraphs
|
|
|
|
* for the cell, but the last cell display item refers to no cell, so it is
|
|
|
|
* just a delimiter.
|
2008-08-05 16:10:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
2008-08-13 03:15:29 +00:00
|
|
|
#include "rtf.h"
|
2008-08-05 16:10:47 +00:00
|
|
|
|
2020-10-21 09:05:56 +00:00
|
|
|
static ME_Paragraph* table_insert_end_para( ME_TextEditor *editor, ME_Cursor *cursor,
|
|
|
|
const WCHAR *eol_str, int eol_len, int para_flags )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-21 09:05:56 +00:00
|
|
|
ME_Style *style = style_get_insert_style( editor, cursor );
|
|
|
|
ME_Paragraph *para;
|
2020-10-14 10:17:14 +00:00
|
|
|
|
2020-10-21 09:05:56 +00:00
|
|
|
if (cursor->nOffset) run_split( editor, cursor );
|
2008-08-07 16:31:41 +00:00
|
|
|
|
2020-11-06 08:32:24 +00:00
|
|
|
para = para_split( editor, cursor->run, style, eol_str, eol_len, para_flags );
|
2020-10-21 09:05:56 +00:00
|
|
|
ME_ReleaseStyle( style );
|
2020-11-06 08:32:24 +00:00
|
|
|
cursor->para = para;
|
|
|
|
cursor->run = para_first_run( para );
|
2020-10-21 09:05:56 +00:00
|
|
|
return para;
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:46 +00:00
|
|
|
ME_Paragraph* table_insert_row_start( ME_TextEditor *editor, ME_Cursor *cursor )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-21 09:05:56 +00:00
|
|
|
ME_Paragraph *para;
|
|
|
|
|
2020-11-15 22:11:14 +00:00
|
|
|
para = table_insert_end_para( editor, cursor, L"\r\n", 2, MEPF_ROWSTART );
|
2020-10-22 11:46:46 +00:00
|
|
|
return para_prev( para );
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:46 +00:00
|
|
|
ME_Paragraph* table_insert_row_start_at_para( ME_TextEditor *editor, ME_Paragraph *para )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-22 11:46:46 +00:00
|
|
|
ME_Paragraph *prev_para, *end_para, *start_row;
|
|
|
|
ME_Cursor cursor;
|
2008-08-07 16:31:41 +00:00
|
|
|
|
2020-11-06 08:32:24 +00:00
|
|
|
cursor.para = para;
|
|
|
|
cursor.run = para_first_run( para );
|
2020-10-22 11:46:46 +00:00
|
|
|
cursor.nOffset = 0;
|
|
|
|
|
|
|
|
start_row = table_insert_row_start( editor, &cursor );
|
|
|
|
|
2020-11-06 08:32:24 +00:00
|
|
|
end_para = para_next( editor->pCursors[0].para );
|
2020-10-22 11:46:46 +00:00
|
|
|
prev_para = para_next( start_row );
|
|
|
|
para = para_next( prev_para );
|
|
|
|
|
|
|
|
while (para != end_para)
|
|
|
|
{
|
2020-11-06 08:32:22 +00:00
|
|
|
para->cell = para_cell( prev_para );
|
2020-10-22 11:46:46 +00:00
|
|
|
para->nFlags |= MEPF_CELL;
|
|
|
|
para->nFlags &= ~(MEPF_ROWSTART | MEPF_ROWEND);
|
|
|
|
para->fmt.dwMask |= PFM_TABLE | PFM_TABLEROWDELIMITER;
|
|
|
|
para->fmt.wEffects |= PFE_TABLE;
|
|
|
|
para->fmt.wEffects &= ~PFE_TABLEROWDELIMITER;
|
|
|
|
prev_para = para;
|
|
|
|
para = para_next( para );
|
|
|
|
}
|
|
|
|
return start_row;
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inserts a diCell and starts a new paragraph for the next cell.
|
|
|
|
*
|
|
|
|
* Returns the first paragraph of the new cell. */
|
2020-10-22 11:46:47 +00:00
|
|
|
ME_Paragraph* table_insert_cell( ME_TextEditor *editor, ME_Cursor *cursor )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-21 09:05:56 +00:00
|
|
|
WCHAR tab = '\t';
|
|
|
|
|
2020-10-22 11:46:47 +00:00
|
|
|
return table_insert_end_para( editor, editor->pCursors, &tab, 1, MEPF_CELL );
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:47 +00:00
|
|
|
ME_Paragraph* table_insert_row_end( ME_TextEditor *editor, ME_Cursor *cursor )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-21 09:05:56 +00:00
|
|
|
ME_Paragraph *para;
|
|
|
|
|
2020-11-15 22:11:14 +00:00
|
|
|
para = table_insert_end_para( editor, cursor, L"\r\n", 2, MEPF_ROWEND );
|
2020-10-22 11:46:47 +00:00
|
|
|
return para_prev( para );
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 11:59:22 +00:00
|
|
|
ME_Paragraph* table_row_end( ME_Paragraph *para )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-11-06 08:32:20 +00:00
|
|
|
ME_Cell *cell;
|
|
|
|
|
2020-10-09 11:59:22 +00:00
|
|
|
if (para->nFlags & MEPF_ROWEND) return para;
|
|
|
|
if (para->nFlags & MEPF_ROWSTART) para = para_next( para );
|
2020-11-06 08:32:20 +00:00
|
|
|
cell = para_cell( para );
|
|
|
|
while (cell_next( cell ))
|
|
|
|
cell = cell_next( cell );
|
2008-08-07 16:31:41 +00:00
|
|
|
|
2020-11-06 08:32:20 +00:00
|
|
|
para = &ME_FindItemFwd( cell_get_di( cell ), diParagraph )->member.para;
|
2020-10-09 11:59:22 +00:00
|
|
|
assert( para && para->nFlags & MEPF_ROWEND );
|
2008-08-07 16:31:41 +00:00
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2020-10-09 11:59:22 +00:00
|
|
|
ME_Paragraph* table_row_start( ME_Paragraph *para )
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-11-06 08:32:20 +00:00
|
|
|
ME_Cell *cell;
|
|
|
|
|
2020-10-09 11:59:22 +00:00
|
|
|
if (para->nFlags & MEPF_ROWSTART) return para;
|
|
|
|
if (para->nFlags & MEPF_ROWEND) para = para_prev( para );
|
2020-11-06 08:32:20 +00:00
|
|
|
cell = para_cell( para );
|
|
|
|
|
|
|
|
while (cell_prev( cell ))
|
|
|
|
cell = cell_prev( cell );
|
2008-08-07 16:31:41 +00:00
|
|
|
|
2020-11-06 08:32:20 +00:00
|
|
|
para = &ME_FindItemBack( cell_get_di( cell ), diParagraph )->member.para;
|
2020-10-09 11:59:22 +00:00
|
|
|
assert( para && para->nFlags & MEPF_ROWSTART );
|
2008-08-07 16:31:41 +00:00
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2020-10-09 11:59:22 +00:00
|
|
|
ME_Paragraph* table_outer_para( ME_Paragraph *para )
|
2012-05-18 04:30:03 +00:00
|
|
|
{
|
2020-10-09 11:59:22 +00:00
|
|
|
if (para->nFlags & MEPF_ROWEND) para = para_prev( para );
|
2020-11-06 08:32:20 +00:00
|
|
|
while (para_cell( para ))
|
2012-05-18 04:30:03 +00:00
|
|
|
{
|
2020-10-09 11:59:22 +00:00
|
|
|
para = table_row_start( para );
|
2020-11-06 08:32:20 +00:00
|
|
|
if (!para_cell( para )) break;
|
|
|
|
para = &ME_FindItemBack( cell_get_di( para_cell( para ) ), diParagraph )->member.para;
|
2012-05-18 04:30:03 +00:00
|
|
|
}
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:48 +00:00
|
|
|
ME_Cell *table_row_first_cell( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
if (!para_in_table( para )) return NULL;
|
|
|
|
|
|
|
|
para = para_next( table_row_start( para ) );
|
|
|
|
return para_cell( para );
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:50 +00:00
|
|
|
ME_Cell *table_row_end_cell( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
if (!para_in_table( para )) return NULL;
|
|
|
|
|
|
|
|
para = para_prev( table_row_end( para ));
|
|
|
|
return cell_next( para_cell( para ) );
|
|
|
|
}
|
|
|
|
|
2020-11-06 08:32:21 +00:00
|
|
|
ME_Cell *cell_create( void )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_MakeDI( diCell );
|
|
|
|
return &item->member.cell;
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:48 +00:00
|
|
|
ME_Cell *cell_next( ME_Cell *cell )
|
|
|
|
{
|
2020-11-06 08:32:22 +00:00
|
|
|
return cell->next_cell;
|
2020-10-22 11:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ME_Cell *cell_prev( ME_Cell *cell )
|
|
|
|
{
|
2020-11-06 08:32:22 +00:00
|
|
|
return cell->prev_cell;
|
2020-10-22 11:46:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 11:46:50 +00:00
|
|
|
ME_Paragraph *cell_first_para( ME_Cell *cell )
|
|
|
|
{
|
|
|
|
return &ME_FindItemFwd( cell_get_di( cell ), diParagraph )->member.para;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Paragraph *cell_end_para( ME_Cell *cell )
|
|
|
|
{
|
|
|
|
ME_Cell *next = cell_next( cell );
|
|
|
|
|
|
|
|
if (!next) return cell_first_para( cell ); /* End of row */
|
|
|
|
|
|
|
|
return &ME_FindItemBack( cell_get_di( next ), diParagraph )->member.para;
|
|
|
|
}
|
|
|
|
|
2008-08-05 16:10:51 +00:00
|
|
|
/* Table rows should either be deleted completely or not at all. */
|
2020-10-29 10:49:11 +00:00
|
|
|
void table_protect_partial_deletion( ME_TextEditor *editor, ME_Cursor *c, int *num_chars )
|
2008-08-05 16:10:51 +00:00
|
|
|
{
|
2020-10-29 10:49:11 +00:00
|
|
|
int start_ofs = ME_GetCursorOfs( c );
|
2009-08-13 12:44:18 +00:00
|
|
|
ME_Cursor c2 = *c;
|
2020-11-06 08:32:24 +00:00
|
|
|
ME_Paragraph *this_para = c->para, *end_para;
|
2009-08-13 12:44:18 +00:00
|
|
|
|
2020-10-29 10:49:11 +00:00
|
|
|
ME_MoveCursorChars( editor, &c2, *num_chars, FALSE );
|
2020-11-06 08:32:24 +00:00
|
|
|
end_para = c2.para;
|
|
|
|
if (c2.run->nFlags & MERF_ENDPARA)
|
2020-10-29 10:49:11 +00:00
|
|
|
{
|
2008-08-05 16:10:51 +00:00
|
|
|
/* End offset might be in the middle of the end paragraph run.
|
|
|
|
* If this is the case, then we need to use the next paragraph as the last
|
|
|
|
* paragraphs.
|
|
|
|
*/
|
2020-11-06 08:32:24 +00:00
|
|
|
int remaining = start_ofs + *num_chars - c2.run->nCharOfs - end_para->nCharOfs;
|
2008-08-05 16:10:51 +00:00
|
|
|
if (remaining)
|
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
assert( remaining < c2.run->len );
|
2020-10-29 10:49:11 +00:00
|
|
|
end_para = para_next( end_para );
|
2008-08-05 16:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
if (para_cell( this_para ) != para_cell( end_para ) ||
|
|
|
|
((this_para->nFlags | end_para->nFlags) & (MEPF_ROWSTART | MEPF_ROWEND)))
|
2008-08-05 16:10:51 +00:00
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
while (this_para != end_para)
|
2008-08-05 16:10:51 +00:00
|
|
|
{
|
2020-10-29 10:49:11 +00:00
|
|
|
ME_Paragraph *next_para = para_next( this_para );
|
|
|
|
BOOL truancate_del = FALSE;
|
|
|
|
if (this_para->nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
/* The following while loop assumes that next_para is MEPF_ROWSTART,
|
2020-10-29 10:49:11 +00:00
|
|
|
* so moving back one paragraph lets it be processed as the start
|
2008-08-07 16:31:41 +00:00
|
|
|
* of the row. */
|
|
|
|
next_para = this_para;
|
2020-10-29 10:49:11 +00:00
|
|
|
this_para = para_prev( this_para );
|
|
|
|
}
|
|
|
|
else if (para_cell( next_para) != para_cell( this_para ) || this_para->nFlags & MEPF_ROWEND)
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
|
|
|
/* Start of the deletion from after the start of the table row. */
|
2020-10-29 10:49:11 +00:00
|
|
|
truancate_del = TRUE;
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
while (!truancate_del && next_para->nFlags & MEPF_ROWSTART)
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-29 10:49:11 +00:00
|
|
|
next_para = para_next( table_row_end( next_para ) );
|
|
|
|
if (next_para->nCharOfs > start_ofs + *num_chars)
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
|
|
|
/* End of deletion is not past the end of the table row. */
|
2020-10-29 10:49:11 +00:00
|
|
|
next_para = para_next( this_para );
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Delete the end paragraph preceding the table row if the
|
|
|
|
* preceding table row will be empty. */
|
2020-10-29 10:49:11 +00:00
|
|
|
if (this_para->nCharOfs >= start_ofs) next_para = para_next( next_para );
|
|
|
|
truancate_del = TRUE;
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
else this_para = para_prev( next_para );
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
if (truancate_del)
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-29 10:49:11 +00:00
|
|
|
ME_Run *end_run = para_end_run( para_prev( next_para ) );
|
|
|
|
int new_chars = next_para->nCharOfs - start_ofs - end_run->len;
|
|
|
|
new_chars = max( new_chars, 0 );
|
|
|
|
assert( new_chars <= *num_chars);
|
|
|
|
*num_chars = new_chars;
|
2008-08-07 16:31:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
this_para = next_para;
|
2008-08-05 16:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
|
|
|
ME_Run *run;
|
|
|
|
int chars_to_boundary;
|
2008-08-07 16:31:41 +00:00
|
|
|
|
2020-10-29 10:49:11 +00:00
|
|
|
if ((this_para->nCharOfs != start_ofs || this_para == end_para) && para_in_table( this_para ))
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
run = c->run;
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Find the next tab or end paragraph to use as a delete boundary */
|
2020-10-29 10:49:11 +00:00
|
|
|
while (!(run->nFlags & (MERF_TAB | MERF_ENDPARA)))
|
|
|
|
run = run_next( run );
|
2020-11-06 08:32:24 +00:00
|
|
|
chars_to_boundary = run->nCharOfs - c->run->nCharOfs - c->nOffset;
|
2020-10-29 10:49:11 +00:00
|
|
|
*num_chars = min( *num_chars, chars_to_boundary );
|
|
|
|
}
|
|
|
|
else if (para_in_table( end_para ))
|
2008-08-05 16:10:51 +00:00
|
|
|
{
|
2008-08-28 19:24:07 +00:00
|
|
|
/* The deletion starts from before the row, so don't join it with
|
|
|
|
* previous non-empty paragraphs. */
|
2020-10-29 10:49:11 +00:00
|
|
|
ME_Paragraph *cur_para;
|
|
|
|
run = NULL;
|
|
|
|
if (start_ofs > this_para->nCharOfs)
|
|
|
|
{
|
|
|
|
cur_para = para_prev( end_para );
|
|
|
|
run = para_end_run( cur_para );
|
2009-08-12 13:06:00 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
if (!run)
|
|
|
|
{
|
|
|
|
cur_para = end_para;
|
|
|
|
run = para_first_run( end_para );
|
2009-08-12 13:06:00 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
if (run)
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-29 10:49:11 +00:00
|
|
|
chars_to_boundary = cur_para->nCharOfs + run->nCharOfs - start_ofs;
|
|
|
|
if (chars_to_boundary >= 0) *num_chars = min( *num_chars, chars_to_boundary );
|
2008-08-07 16:31:41 +00:00
|
|
|
}
|
2008-08-05 16:10:51 +00:00
|
|
|
}
|
2020-10-29 10:49:11 +00:00
|
|
|
if (*num_chars < 0) *num_chars = 0;
|
2008-08-05 16:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 09:05:55 +00:00
|
|
|
ME_Paragraph* table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row )
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
|
|
|
WCHAR endl = '\r', tab = '\t';
|
2020-10-21 09:05:55 +00:00
|
|
|
ME_Run *run;
|
2008-08-05 16:10:47 +00:00
|
|
|
int i;
|
|
|
|
|
2020-10-21 09:05:55 +00:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
2020-10-29 10:49:12 +00:00
|
|
|
ME_Cell *new_cell, *cell;
|
|
|
|
ME_Paragraph *para, *prev_table_end, *new_row_start;
|
2020-10-21 09:05:55 +00:00
|
|
|
|
2020-10-29 10:49:12 +00:00
|
|
|
cell = table_row_first_cell( table_row );
|
2020-10-21 09:05:55 +00:00
|
|
|
prev_table_end = table_row_end( table_row );
|
|
|
|
para = para_next( prev_table_end );
|
|
|
|
run = para_first_run( para );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = para;
|
|
|
|
editor->pCursors[0].run = run;
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2020-10-29 10:49:12 +00:00
|
|
|
new_row_start = table_insert_row_start( editor, editor->pCursors );
|
|
|
|
new_cell = table_row_first_cell( new_row_start );
|
2009-02-09 17:01:35 +00:00
|
|
|
/* Copy cell properties */
|
2020-10-29 10:49:12 +00:00
|
|
|
new_cell->nRightBoundary = cell->nRightBoundary;
|
|
|
|
new_cell->border = cell->border;
|
|
|
|
while (cell_next( cell ))
|
2020-10-21 09:05:55 +00:00
|
|
|
{
|
2020-10-29 10:49:12 +00:00
|
|
|
cell = cell_next( cell );
|
2020-10-22 11:46:47 +00:00
|
|
|
para = table_insert_cell( editor, editor->pCursors );
|
2020-10-29 10:49:12 +00:00
|
|
|
new_cell = para_cell( para );
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Copy cell properties */
|
2020-10-29 10:49:12 +00:00
|
|
|
new_cell->nRightBoundary = cell->nRightBoundary;
|
|
|
|
new_cell->border = cell->border;
|
2008-08-07 16:31:41 +00:00
|
|
|
};
|
2020-10-22 11:46:47 +00:00
|
|
|
para = table_insert_row_end( editor, editor->pCursors );
|
2020-10-21 09:05:55 +00:00
|
|
|
para->fmt = prev_table_end->fmt;
|
2008-08-07 16:31:41 +00:00
|
|
|
/* return the table row start for the inserted paragraph */
|
2020-10-29 10:49:12 +00:00
|
|
|
return new_row_start;
|
2020-10-21 09:05:55 +00:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
|
|
|
run = para_end_run( table_row );
|
2020-10-29 10:49:12 +00:00
|
|
|
assert( para_in_table( table_row ) );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = table_row;
|
|
|
|
editor->pCursors[0].run = run;
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2020-10-21 09:05:55 +00:00
|
|
|
ME_InsertTextFromCursor( editor, 0, &endl, 1, run->style );
|
2020-11-06 08:32:24 +00:00
|
|
|
run = editor->pCursors[0].run;
|
2020-10-29 10:49:12 +00:00
|
|
|
for (i = 0; i < table_row->fmt.cTabCount; i++)
|
|
|
|
ME_InsertTextFromCursor( editor, 0, &tab, 1, run->style );
|
2020-10-21 09:05:55 +00:00
|
|
|
|
|
|
|
return para_next( table_row );
|
2008-08-05 16:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Selects the next table cell or appends a new table row if at end of table */
|
2020-10-29 10:49:13 +00:00
|
|
|
static void table_select_next_cell_or_append( ME_TextEditor *editor, ME_Run *run )
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
ME_Paragraph *para = run->para;
|
|
|
|
ME_Cell *cell;
|
2008-08-05 16:10:47 +00:00
|
|
|
int i;
|
|
|
|
|
2020-10-29 10:49:13 +00:00
|
|
|
assert( para_in_table( para ) );
|
2020-10-21 09:05:55 +00:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Get the initial cell */
|
2020-10-29 10:49:13 +00:00
|
|
|
if (para->nFlags & MEPF_ROWSTART) cell = para_cell( para_next( para ) );
|
|
|
|
else if (para->nFlags & MEPF_ROWEND) cell = para_cell( para_prev( para ) );
|
|
|
|
else cell = para_cell( para );
|
2020-10-21 09:05:55 +00:00
|
|
|
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Get the next cell. */
|
2020-10-29 10:49:13 +00:00
|
|
|
if (cell_next( cell ) && cell_next( cell_next( cell ) ))
|
|
|
|
cell = cell_next( cell );
|
|
|
|
else
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
para = para_next( table_row_end( para ) );
|
|
|
|
if (para->nFlags & MEPF_ROWSTART) cell = para_cell( para_next( para ) );
|
2020-10-21 09:05:55 +00:00
|
|
|
else
|
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Insert row */
|
2020-10-21 09:05:55 +00:00
|
|
|
para = para_prev( para );
|
|
|
|
para = table_append_row( editor, table_row_start( para ) );
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Put cursor at the start of the new table row */
|
2020-10-21 09:05:55 +00:00
|
|
|
para = para_next( para );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = para;
|
|
|
|
editor->pCursors[0].run = para_first_run( para );
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Select cell */
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[1].para = cell_first_para( cell );
|
|
|
|
editor->pCursors[1].run = para_first_run( editor->pCursors[1].para );
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[1].nOffset = 0;
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = cell_end_para( cell );
|
|
|
|
editor->pCursors[0].run = para_end_run( editor->pCursors[0].para );
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
2020-10-21 09:05:55 +00:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
if (run->nFlags & MERF_ENDPARA && para_in_table( para_next( para ) ))
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
run = run_next_all_paras( run );
|
2008-08-07 16:31:41 +00:00
|
|
|
assert(run);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
while (!(run->nFlags & MERF_TAB))
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
if (!run_next( run ))
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
para = para_next( run->para );
|
2020-10-21 09:05:55 +00:00
|
|
|
if (para_in_table( para ))
|
2008-08-07 16:31:41 +00:00
|
|
|
{
|
2020-10-29 10:49:13 +00:00
|
|
|
run = para_first_run( para );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = para;
|
|
|
|
editor->pCursors[0].run = run;
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
i = 1;
|
2020-10-21 09:05:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Insert table row */
|
2020-10-21 09:05:55 +00:00
|
|
|
para = table_append_row( editor, para_prev( para ) );
|
2008-08-07 16:31:41 +00:00
|
|
|
/* Put cursor at the start of the new table row */
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = para;
|
|
|
|
editor->pCursors[0].run = para_first_run( para );
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
return;
|
|
|
|
}
|
2008-08-05 16:10:47 +00:00
|
|
|
}
|
2020-10-29 10:49:13 +00:00
|
|
|
else run = run_next( run );
|
2008-08-05 16:10:47 +00:00
|
|
|
}
|
2020-10-29 10:49:13 +00:00
|
|
|
if (i == 0) run = run_next_all_paras( run );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[i].run = run;
|
|
|
|
editor->pCursors[i].para = run->para;
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[i].nOffset = 0;
|
2008-08-05 16:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-29 10:49:13 +00:00
|
|
|
void table_handle_tab( ME_TextEditor *editor, BOOL selected_row )
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
|
|
|
/* FIXME: Shift tab should move to the previous cell. */
|
|
|
|
ME_Cursor fromCursor, toCursor;
|
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
{
|
|
|
|
int from, to;
|
2009-08-12 13:05:42 +00:00
|
|
|
from = ME_GetCursorOfs(&editor->pCursors[0]);
|
|
|
|
to = ME_GetCursorOfs(&editor->pCursors[1]);
|
2008-08-05 16:10:47 +00:00
|
|
|
if (from <= to)
|
|
|
|
{
|
|
|
|
fromCursor = editor->pCursors[0];
|
|
|
|
toCursor = editor->pCursors[1];
|
2020-10-29 10:49:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-05 16:10:47 +00:00
|
|
|
fromCursor = editor->pCursors[1];
|
|
|
|
toCursor = editor->pCursors[0];
|
|
|
|
}
|
|
|
|
}
|
2008-08-07 16:31:41 +00:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
if (!para_in_table( toCursor.para ))
|
2008-08-05 16:10:47 +00:00
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0] = toCursor;
|
|
|
|
editor->pCursors[1] = toCursor;
|
|
|
|
}
|
2020-11-06 08:32:24 +00:00
|
|
|
else table_select_next_cell_or_append( editor, toCursor.run );
|
2020-10-29 10:49:13 +00:00
|
|
|
}
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
if (!para_in_table( fromCursor.para ))
|
2020-10-29 10:49:13 +00:00
|
|
|
{
|
2008-08-07 16:31:41 +00:00
|
|
|
editor->pCursors[0] = fromCursor;
|
|
|
|
editor->pCursors[1] = fromCursor;
|
|
|
|
/* FIXME: For some reason the caret is shown at the start of the
|
2020-10-23 09:25:06 +00:00
|
|
|
* previous paragraph in v1.0 to v3.0 */
|
2020-10-29 10:49:13 +00:00
|
|
|
}
|
2020-11-06 08:32:24 +00:00
|
|
|
else if ((selected_row || !para_in_table( toCursor.para )))
|
|
|
|
table_select_next_cell_or_append( editor, fromCursor.run );
|
2020-10-29 10:49:13 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
ME_Run *run = run_prev( toCursor.run );
|
2020-10-29 10:49:13 +00:00
|
|
|
|
|
|
|
if (ME_IsSelection(editor) && !toCursor.nOffset && run && run->nFlags & MERF_TAB)
|
|
|
|
table_select_next_cell_or_append( editor, run );
|
|
|
|
else
|
2020-11-06 08:32:24 +00:00
|
|
|
table_select_next_cell_or_append( editor, toCursor.run );
|
2008-08-05 16:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
ME_Repaint(editor);
|
2019-04-03 13:23:04 +00:00
|
|
|
update_caret(editor);
|
2008-08-05 16:10:47 +00:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
2008-08-13 03:15:29 +00:00
|
|
|
|
2008-09-11 16:45:36 +00:00
|
|
|
/* Make sure the cursor is not in the hidden table row start paragraph
|
|
|
|
* without a selection. */
|
2020-10-29 10:49:14 +00:00
|
|
|
void table_move_from_row_start( ME_TextEditor *editor )
|
2008-09-11 16:45:36 +00:00
|
|
|
{
|
2020-11-06 08:32:24 +00:00
|
|
|
ME_Paragraph *para = editor->pCursors[0].para;
|
2020-10-29 10:49:14 +00:00
|
|
|
|
2020-11-06 08:32:24 +00:00
|
|
|
if (para == editor->pCursors[1].para && para->nFlags & MEPF_ROWSTART)
|
2020-10-29 10:49:14 +00:00
|
|
|
{
|
2008-09-11 16:45:36 +00:00
|
|
|
/* The cursors should not be at the hidden start row paragraph without
|
|
|
|
* a selection, so the cursor is moved into the first cell. */
|
2020-10-29 10:49:14 +00:00
|
|
|
para = para_next( para );
|
2020-11-06 08:32:24 +00:00
|
|
|
editor->pCursors[0].para = para;
|
|
|
|
editor->pCursors[0].run = para_first_run( para );
|
2008-09-11 16:45:36 +00:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 03:15:29 +00:00
|
|
|
struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor)
|
|
|
|
{
|
2018-02-03 22:59:47 +00:00
|
|
|
RTFTable *tableDef = heap_alloc_zero(sizeof(*tableDef));
|
|
|
|
|
2008-08-13 03:15:29 +00:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
tableDef->gapH = 10;
|
|
|
|
return tableDef;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef)
|
|
|
|
{
|
|
|
|
ZeroMemory(tableDef->cells, sizeof(tableDef->cells));
|
2008-08-13 03:15:36 +00:00
|
|
|
ZeroMemory(tableDef->border, sizeof(tableDef->border));
|
2008-08-13 03:15:29 +00:00
|
|
|
tableDef->numCellsDefined = 0;
|
|
|
|
tableDef->leftEdge = 0;
|
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
tableDef->gapH = 10;
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
tableDef->gapH = 0;
|
|
|
|
}
|