/****************************************************************************** * ME_UpdateRunFlags * * Determine some of run attributes given its content (style, text content). * Some flags cannot be determined by this function (MERF_GRAPHICS, * MERF_ENDPARA) */ void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) { assert(run->nCharOfs >= 0); if (RUN_IS_HIDDEN(run) || run->nFlags & MERF_TABLESTART) run->nFlags |= MERF_HIDDEN; else run->nFlags &= ~MERF_HIDDEN; if (run_is_splittable( run )) run->nFlags |= MERF_SPLITTABLE; else run->nFlags &= ~MERF_SPLITTABLE; if (!(run->nFlags & MERF_NOTEXT)) { if (run_is_entirely_ws( run )) run->nFlags |= MERF_WHITESPACE | MERF_STARTWHITE | MERF_ENDWHITE; else { run->nFlags &= ~MERF_WHITESPACE; if (ME_IsWSpace( *get_text( run, 0 ) )) run->nFlags |= MERF_STARTWHITE; else run->nFlags &= ~MERF_STARTWHITE; if (ME_IsWSpace( *get_text( run, run->len - 1 ) )) run->nFlags |= MERF_ENDWHITE; else run->nFlags &= ~MERF_ENDWHITE; } } else run->nFlags &= ~(MERF_WHITESPACE | MERF_STARTWHITE | MERF_ENDWHITE); }
static BOOL ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) { ME_DisplayItem *pRun = pCursor->pRun; if (nRelOfs == -1) { if (!pCursor->nOffset) { do { pRun = ME_FindItemBack(pRun, diRunOrParagraph); assert(pRun); switch (pRun->type) { case diRun: break; case diParagraph: if (pRun->member.para.prev_para->type == diTextStart) return FALSE; pRun = ME_FindItemBack(pRun, diRunOrParagraph); /* every paragraph ought to have at least one run */ assert(pRun && pRun->type == diRun); assert(pRun->member.run.nFlags & MERF_ENDPARA); break; default: assert(pRun->type != diRun && pRun->type != diParagraph); return FALSE; } } while (RUN_IS_HIDDEN(&pRun->member.run) || pRun->member.run.nFlags & MERF_HIDDEN); pCursor->pRun = pRun; if (pRun->member.run.nFlags & MERF_ENDPARA) pCursor->nOffset = 0; else pCursor->nOffset = pRun->member.run.strText->nLen; } if (pCursor->nOffset) pCursor->nOffset = ME_StrRelPos2(pCursor->pRun->member.run.strText, pCursor->nOffset, nRelOfs); return TRUE; } else { if (!(pRun->member.run.nFlags & MERF_ENDPARA)) { int new_ofs = ME_StrRelPos2(pRun->member.run.strText, pCursor->nOffset, nRelOfs); if (new_ofs < pRun->member.run.strText->nLen) { pCursor->nOffset = new_ofs; return TRUE; } } do { pRun = ME_FindItemFwd(pRun, diRun); } while (pRun && (RUN_IS_HIDDEN(&pRun->member.run) || pRun->member.run.nFlags & MERF_HIDDEN)); if (pRun) { pCursor->pRun = pRun; pCursor->nOffset = 0; return TRUE; } } return FALSE; }