2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - Operations on rows of text (rows are recreated during
|
|
|
|
* wrapping and are used for displaying the document, they don't keep any
|
|
|
|
* true document content; delete all rows, rewrap all paragraphs and
|
|
|
|
* you get them back).
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
ME_Row *row_next( ME_Row *row )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
2020-10-26 09:46:39 +01:00
|
|
|
item = ME_FindItemFwd( row_get_di( row ), diStartRowOrParagraphOrEnd );
|
|
|
|
if (!item || item->type != diStartRow) return NULL;
|
2020-10-26 09:46:38 +01:00
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
2020-11-09 09:45:04 +01:00
|
|
|
ME_Row *row_next_all_paras( ME_Row *row )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( row_get_di( row ), diStartRow );
|
|
|
|
if (!item) return NULL;
|
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Row *row_prev_all_paras( ME_Row *row )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
item = ME_FindItemBack( row_get_di( row ), diStartRow );
|
|
|
|
if (!item) return NULL;
|
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
ME_Run *row_first_run( ME_Row *row )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( row_get_di( row ), diRunOrStartRow );
|
|
|
|
assert( item->type == diRun );
|
|
|
|
return &item->member.run;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Run *row_next_run( ME_Row *row, ME_Run *run )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
assert( row == &ME_FindItemBack( run_get_di( run ), diStartRow )->member.row );
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( run_get_di( run ), diRunOrStartRow );
|
|
|
|
if (!item || item->type == diStartRow) return NULL;
|
|
|
|
return &item->member.run;
|
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:40 +01:00
|
|
|
ME_Row *row_from_cursor( ME_Cursor *cursor )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
item = ME_FindItemBack( run_get_di( cursor->run ), diStartRow );
|
2020-10-26 09:46:40 +01:00
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
|
|
|
void row_first_cursor( ME_Row *row, ME_Cursor *cursor )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( row_get_di( row ), diRun );
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->run = &item->member.run;
|
|
|
|
cursor->para = cursor->run->para;
|
2020-10-26 09:46:40 +01:00
|
|
|
cursor->nOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void row_end_cursor( ME_Row *row, ME_Cursor *cursor, BOOL include_eop )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item, *run;
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( row_get_di( row ), diStartRowOrParagraphOrEnd );
|
|
|
|
run = ME_FindItemBack( item, diRun );
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->run = &run->member.run;
|
|
|
|
cursor->para = cursor->run->para;
|
|
|
|
cursor->nOffset = (item->type == diStartRow || include_eop) ? cursor->run->len : 0;
|
2020-10-26 09:46:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-09 09:45:04 +01:00
|
|
|
ME_Paragraph *row_para( ME_Row *row )
|
|
|
|
{
|
|
|
|
ME_Cursor cursor;
|
|
|
|
|
|
|
|
row_first_cursor( row, &cursor );
|
|
|
|
return cursor.para;
|
|
|
|
}
|
|
|
|
|
2020-11-02 09:23:17 +01:00
|
|
|
ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num )
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2020-11-02 09:23:17 +01:00
|
|
|
ME_Paragraph *para = editor_first_para( editor );
|
|
|
|
ME_Row *row;
|
|
|
|
int count = 0;
|
2009-02-06 07:10:06 +01:00
|
|
|
|
2020-11-02 09:23:17 +01:00
|
|
|
while (para_next( para ) && count + para->nRows <= row_num)
|
|
|
|
{
|
|
|
|
count += para->nRows;
|
|
|
|
para = para_next( para );
|
|
|
|
}
|
|
|
|
if (!para_next( para )) return NULL;
|
|
|
|
|
|
|
|
for (row = para_first_row( para ); row && count < row_num; count++)
|
|
|
|
row = row_next( row );
|
|
|
|
|
|
|
|
return row;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
2005-07-06 13:12:10 +02:00
|
|
|
|
|
|
|
|
2020-11-03 09:44:43 +01:00
|
|
|
int row_number_from_char_ofs( ME_TextEditor *editor, int ofs )
|
2005-07-06 13:12:10 +02:00
|
|
|
{
|
2020-11-03 09:44:43 +01:00
|
|
|
ME_Paragraph *para = editor_first_para( editor );
|
|
|
|
ME_Row *row;
|
|
|
|
ME_Cursor cursor;
|
|
|
|
int row_num = 0;
|
|
|
|
|
|
|
|
while (para_next( para ) && para_next( para )->nCharOfs <= ofs)
|
|
|
|
{
|
|
|
|
row_num += para->nRows;
|
|
|
|
para = para_next( para );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (para_next( para ))
|
2005-07-06 13:12:10 +02:00
|
|
|
{
|
2020-11-03 09:44:43 +01:00
|
|
|
for (row = para_first_row( para ); row; row = row_next( row ))
|
|
|
|
{
|
|
|
|
row_end_cursor( row, &cursor, TRUE );
|
|
|
|
if (ME_GetCursorOfs( &cursor ) > ofs ) break;
|
|
|
|
row_num++;
|
|
|
|
}
|
2005-07-06 13:12:10 +02:00
|
|
|
}
|
2020-11-03 09:44:43 +01:00
|
|
|
|
|
|
|
return row_num;
|
2005-07-06 13:12:10 +02:00
|
|
|
}
|