int ME_GetCharBack(const ME_String *s, int nPos) { int nVPos = ME_StrVLen(s); assert(nPos < ME_StrLen(s)); if (nPos) nVPos = ME_StrRelPos2(s, nVPos, -nPos); if (nVPos < s->nLen) return s->szData[nVPos]; return -1; }
void ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, int *x, int *y, int *height) { ME_DisplayItem *pCursorRun = pCursor->pRun; ME_DisplayItem *pSizeRun = pCursor->pRun; assert(height && x && y); assert(!(ME_GetParagraph(pCursorRun)->member.para.nFlags & MEPF_REWRAP)); assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); if (pCursorRun->type == diRun) { ME_DisplayItem *row = ME_FindItemBack(pCursorRun, diStartRowOrParagraph); if (row) { HDC hDC = GetDC(editor->hWnd); ME_Context c; ME_DisplayItem *run = pCursorRun; ME_DisplayItem *para = NULL; SIZE sz = {0, 0}; ME_InitContext(&c, editor, hDC); if (!pCursor->nOffset) { ME_DisplayItem *prev = ME_FindItemBack(pCursorRun, diRunOrParagraph); assert(prev); if (prev->type == diRun) pSizeRun = prev; } assert(row->type == diStartRow); /* paragraph -> run without start row ?*/ para = ME_FindItemBack(row, diParagraph); assert(para); assert(para->type == diParagraph); if (editor->bCaretAtEnd && !pCursor->nOffset && run == ME_FindItemFwd(row, diRun)) { ME_DisplayItem *tmp = ME_FindItemBack(row, diRunOrParagraph); assert(tmp); if (tmp->type == diRun) { row = ME_FindItemBack(tmp, diStartRow); pSizeRun = run = tmp; assert(run); assert(run->type == diRun); sz = ME_GetRunSize(&c, ¶->member.para, &run->member.run, ME_StrLen(run->member.run.strText), row->member.row.nLMargin); } } if (pCursor->nOffset) { sz = ME_GetRunSize(&c, ¶->member.para, &run->member.run, pCursor->nOffset, row->member.row.nLMargin); } *height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent; *x = c.rcView.left + run->member.run.pt.x + sz.cx - editor->horz_si.nPos; *y = c.rcView.top + para->member.para.pt.y + row->member.row.nBaseline + run->member.run.pt.y - pSizeRun->member.run.nAscent - editor->vert_si.nPos; ME_DestroyContext(&c, editor->hWnd); return; } } *height = 10; /* FIXME use global font */ *x = 0; *y = 0; }