Commit b47e5d0d authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Pass a row ptr to the cursor from row function.

parent 20971961
...@@ -903,40 +903,39 @@ static ME_Paragraph *pixel_pos_in_table_row( int x, int y, ME_Paragraph *para ) ...@@ -903,40 +903,39 @@ static ME_Paragraph *pixel_pos_in_table_row( int x, int y, ME_Paragraph *para )
return para; return para;
} }
static BOOL row_cursor( ME_TextEditor *editor, ME_Row *row, int x,
static BOOL cursor_from_row( ME_TextEditor *editor, ME_DisplayItem *pRow, ME_Cursor *cursor )
int x, ME_Cursor *cursor )
{ {
ME_DisplayItem *pNext, *pLastRun; ME_Run *run, *last;
ME_Row *row = &pRow->member.row; BOOL exact = TRUE;
BOOL exact = TRUE;
if (x < row->pt.x) if (x < row->pt.x)
{
x = row->pt.x;
exact = FALSE;
}
pNext = ME_FindItemFwd(pRow, diRunOrStartRow);
assert(pNext->type == diRun);
cursor->nOffset = 0;
do {
int run_x = pNext->member.run.pt.x;
int width = pNext->member.run.nWidth;
if (x >= run_x && x < run_x+width)
{ {
cursor->nOffset = ME_CharFromPoint(editor, x-run_x, &pNext->member.run, TRUE, TRUE); x = row->pt.x;
cursor->pRun = pNext; exact = FALSE;
cursor->pPara = ME_GetParagraph( cursor->pRun );
return exact;
} }
pLastRun = pNext;
pNext = ME_FindItemFwd(pNext, diRunOrStartRow);
} while(pNext && pNext->type == diRun);
cursor->pRun = pLastRun; run = row_first_run( row );
cursor->pPara = ME_GetParagraph( cursor->pRun ); assert( run );
return FALSE; cursor->nOffset = 0;
do
{
if (x >= run->pt.x && x < run->pt.x + run->nWidth)
{
cursor->nOffset = ME_CharFromPoint( editor, x - run->pt.x, run, TRUE, TRUE );
cursor->pRun = run_get_di( run );
cursor->pPara = para_get_di( run->para );
return exact;
}
last = run;
run = row_next_run( row, run );
} while (run);
run = last;
cursor->pRun = run_get_di( run );
cursor->pPara = para_get_di( run->para );
return FALSE;
} }
/* Finds the run and offset from the pixel position. /* Finds the run and offset from the pixel position.
...@@ -995,8 +994,7 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y, ...@@ -995,8 +994,7 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
row = ME_FindItemBack( para_get_di( para ), diStartRow); row = ME_FindItemBack( para_get_di( para ), diStartRow);
} }
if (row) return row_cursor( editor, &row->member.row, x, result ) && isExact;
if (row) return cursor_from_row( editor, row, x, result ) && isExact;
ME_SetCursorToEnd(editor, result, TRUE); ME_SetCursorToEnd(editor, result, TRUE);
return FALSE; return FALSE;
...@@ -1279,7 +1277,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL ...@@ -1279,7 +1277,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL
/* row not found - ignore */ /* row not found - ignore */
return; return;
} }
cursor_from_row( editor, pItem, x, pCursor ); row_cursor( editor, &pItem->member.row, x, pCursor );
assert(pCursor->pRun); assert(pCursor->pRun);
assert(pCursor->pRun->type == diRun); assert(pCursor->pRun->type == diRun);
} }
...@@ -1329,7 +1327,7 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) ...@@ -1329,7 +1327,7 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor)
pLast = p; pLast = p;
} while(1); } while(1);
cursor_from_row( editor, pLast, x, pCursor ); row_cursor( editor, &pLast->member.row, x, pCursor );
} }
assert(pCursor->pRun); assert(pCursor->pRun);
assert(pCursor->pRun->type == diRun); assert(pCursor->pRun->type == diRun);
...@@ -1383,7 +1381,7 @@ static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor) ...@@ -1383,7 +1381,7 @@ static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor)
pLast = p; pLast = p;
} while(1); } while(1);
cursor_from_row( editor, pLast, x, pCursor ); row_cursor( editor, &pLast->member.row, x, pCursor );
} }
assert(pCursor->pRun); assert(pCursor->pRun);
assert(pCursor->pRun->type == diRun); assert(pCursor->pRun->type == diRun);
......
...@@ -111,10 +111,17 @@ int ME_ReverseFindNonWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN ...@@ -111,10 +111,17 @@ int ME_ReverseFindNonWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN
int ME_ReverseFindWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN; int ME_ReverseFindWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN;
/* row.c */ /* row.c */
ME_Run *row_first_run( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Row *row_next( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN; ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN;
/* ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item); */ /* ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item); */
ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_HIDDEN; ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_HIDDEN;
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN; int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
static inline ME_DisplayItem *row_get_di( ME_Row *row )
{
return (ME_DisplayItem *)((ptrdiff_t)row - offsetof(ME_DisplayItem, member));
}
/* run.c */ /* run.c */
void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) DECLSPEC_HIDDEN; void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
......
...@@ -24,6 +24,35 @@ ...@@ -24,6 +24,35 @@
#include "editor.h" #include "editor.h"
ME_Row *row_next( ME_Row *row )
{
ME_DisplayItem *item;
item = ME_FindItemFwd( row_get_di( row ), diStartRow );
if (!item) return NULL;
return &item->member.row;
}
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;
}
/* I'm sure these functions would simplify some code in caret ops etc, /* I'm sure these functions would simplify some code in caret ops etc,
* I just didn't remember them when I wrote that code * I just didn't remember them when I wrote that code
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment