Huw Davies : riched20: Use row and para ptrs in the cursor up/down handler.
Alexandre Julliard
julliard at winehq.org
Mon Nov 9 15:11:50 CST 2020
Module: wine
Branch: master
Commit: cb9353bca95a5d1d05decf366ae3230eb0fb9c13
URL: https://source.winehq.org/git/wine.git/?a=commit;h=cb9353bca95a5d1d05decf366ae3230eb0fb9c13
Author: Huw Davies <huw at codeweavers.com>
Date: Mon Nov 9 08:45:05 2020 +0000
riched20: Use row and para ptrs in the cursor up/down handler.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/riched20/caret.c | 130 +++++++++++++++++++++++--------------------------
dlls/riched20/editor.h | 1 -
dlls/riched20/para.c | 4 --
3 files changed, 60 insertions(+), 75 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index f36c00458b8..6417bbde442 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -1196,80 +1196,70 @@ static int ME_GetXForArrow(ME_TextEditor *editor, ME_Cursor *pCursor)
}
-static void
-ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL extend)
+static void cursor_move_line( ME_TextEditor *editor, ME_Cursor *cursor, BOOL up, BOOL extend )
{
- ME_DisplayItem *pRun = run_get_di( pCursor->run );
- ME_Paragraph *old_para = pCursor->para, *new_para;
- ME_DisplayItem *pItem;
- int x = ME_GetXForArrow(editor, pCursor);
+ ME_Paragraph *old_para = cursor->para, *new_para;
+ ME_Row *row = row_from_cursor( cursor );
+ int x = ME_GetXForArrow( editor, cursor );
- if (nRelOfs == -1)
- {
- /* start of this row */
- pItem = ME_FindItemBack(pRun, diStartRow);
- assert(pItem);
- /* start of the previous row */
- pItem = ME_FindItemBack(pItem, diStartRow);
- if (!pItem) /* row not found */
- {
- if (extend)
- ME_SetCursorToStart(editor, pCursor);
- return;
- }
- new_para = &ME_GetParagraph(pItem)->member.para;
- if (old_para->nFlags & MEPF_ROWEND ||
- (para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
- {
- /* Brought out of a cell */
- new_para = para_prev( table_row_start( old_para ));
- if (!new_para) return; /* At the top, so don't go anywhere. */
- pItem = ME_FindItemFwd( para_get_di( new_para ), diStartRow);
- }
- if (new_para->nFlags & MEPF_ROWEND)
- {
- /* Brought into a table row */
- ME_Cell *cell = table_row_end_cell( new_para );
- while (x < cell->pt.x && cell_prev( cell ))
- cell = cell_prev( cell );
- if (cell_next( cell )) /* else - we are still at the end of the row */
- pItem = ME_FindItemBack( cell_get_di( cell_next( cell ) ), diStartRow );
- }
- }
- else
- {
- /* start of the next row */
- pItem = ME_FindItemFwd(pRun, diStartRow);
- if (!pItem) /* row not found */
- {
- if (extend)
- ME_SetCursorToEnd(editor, pCursor, TRUE);
- return;
- }
- new_para = &ME_GetParagraph(pItem)->member.para;
- if (old_para->nFlags & MEPF_ROWSTART ||
- (para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
+ if (up)
{
- /* Brought out of a cell */
- new_para = para_next( table_row_end( old_para ) );
- if (!para_next( new_para )) return; /* At the bottom, so don't go anywhere. */
- pItem = ME_FindItemFwd( para_get_di( new_para ), diStartRow );
+ /* start of the previous row */
+ row = row_prev_all_paras( row );
+ if (!row)
+ {
+ if (extend) ME_SetCursorToStart( editor, cursor );
+ return;
+ }
+ new_para = row_para( row );
+ if (old_para->nFlags & MEPF_ROWEND ||
+ (para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
+ {
+ /* Brought out of a cell */
+ new_para = para_prev( table_row_start( old_para ));
+ if (!new_para) return; /* At the top, so don't go anywhere. */
+ row = para_first_row( new_para );
+ }
+ if (new_para->nFlags & MEPF_ROWEND)
+ {
+ /* Brought into a table row */
+ ME_Cell *cell = table_row_end_cell( new_para );
+ while (x < cell->pt.x && cell_prev( cell ))
+ cell = cell_prev( cell );
+ if (cell_next( cell )) /* else - we are still at the end of the row */
+ row = para_end_row( cell_end_para( cell ) );
+ }
}
- if (new_para->nFlags & MEPF_ROWSTART)
+ else
{
- /* Brought into a table row */
- ME_Cell *cell = table_row_first_cell( new_para );
- while (cell_next( cell ) && x >= cell_next( cell )->pt.x)
- cell = cell_next( cell );
- pItem = ME_FindItemFwd( cell_get_di( cell ), diStartRow );
+ /* start of the next row */
+ row = row_next_all_paras( row );
+ if (!row)
+ {
+ if (extend) ME_SetCursorToEnd( editor, cursor, TRUE );
+ return;
+ }
+ new_para = row_para( row );
+ if (old_para->nFlags & MEPF_ROWSTART ||
+ (para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
+ {
+ /* Brought out of a cell */
+ new_para = para_next( table_row_end( old_para ) );
+ if (!para_next( new_para )) return; /* At the bottom, so don't go anywhere. */
+ row = para_first_row( new_para );
+ }
+ if (new_para->nFlags & MEPF_ROWSTART)
+ {
+ /* Brought into a table row */
+ ME_Cell *cell = table_row_first_cell( new_para );
+ while (cell_next( cell ) && x >= cell_next( cell )->pt.x)
+ cell = cell_next( cell );
+ row = para_first_row( cell_first_para( cell ) );
+ }
}
- }
- if (!pItem)
- {
- /* row not found - ignore */
- return;
- }
- row_cursor( editor, &pItem->member.row, x, pCursor );
+ if (!row) return;
+
+ row_cursor( editor, row, x, cursor );
}
static void ME_ArrowPageUp( ME_TextEditor *editor, ME_Cursor *cursor )
@@ -1434,10 +1424,10 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
success = ME_MoveCursorChars(editor, &tmp_curs, +1, extend);
break;
case VK_UP:
- ME_MoveCursorLines(editor, &tmp_curs, -1, extend);
+ cursor_move_line( editor, &tmp_curs, TRUE, extend );
break;
case VK_DOWN:
- ME_MoveCursorLines(editor, &tmp_curs, +1, extend);
+ cursor_move_line( editor, &tmp_curs, FALSE, extend );
break;
case VK_PRIOR:
ME_ArrowPageUp(editor, &tmp_curs);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index e7ae7b806be..7a9d445f98f 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -208,7 +208,6 @@ void editor_get_selection_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *fmt ) DE
void editor_mark_rewrap_all( ME_TextEditor *editor ) DECLSPEC_HIDDEN;
void editor_set_default_para_fmt(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
BOOL editor_set_selection_para_fmt( ME_TextEditor *editor, const PARAFORMAT2 *fmt ) DECLSPEC_HIDDEN;
-ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run) DECLSPEC_HIDDEN;
void ME_MakeFirstParagraph(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_DumpParaStyle(ME_Paragraph *s) DECLSPEC_HIDDEN;
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 1a53ba46a27..c0f2a7b5471 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -794,10 +794,6 @@ ME_Paragraph *para_join( ME_TextEditor *editor, ME_Paragraph *para, BOOL use_fir
return para;
}
-ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *item) {
- return ME_FindItemBackOrHere(item, diParagraph);
-}
-
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048])
{
char *p;
More information about the wine-cvs
mailing list