📄 paint.c
字号:
break;
case diStartRow:
assert(para);
nMargWidth = (pno==0?para->nFirstMargin:para->nLeftMargin);
xs = c->rcView.left+nMargWidth;
xe = c->rcView.right-para->nRightMargin;
y += height;
rcPara.top = y;
rcPara.bottom = y+p->member.row.nHeight;
visible = RectVisible(c->hDC, &rcPara);
if (visible) {
HBRUSH hbr;
hbr = CreateSolidBrush(ME_GetBackColor(c->editor));
/* left margin */
rc.left = c->rcView.left;
rc.right = c->rcView.left+nMargWidth;
rc.top = y;
rc.bottom = y+p->member.row.nHeight;
FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
/* right margin */
rc.left = xe;
rc.right = c->rcView.right;
FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
rc.left = c->rcView.left+nMargWidth;
rc.right = xe;
FillRect(c->hDC, &rc, hbr);
DeleteObject(hbr);
}
if (me_debug)
{
const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
WCHAR buf[128];
POINT pt = c->pt;
wsprintfW(buf, wszRowDebug, no);
pt.y = 12+y;
ME_DebugWrite(c->hDC, &pt, buf);
}
height = p->member.row.nHeight;
baseline = p->member.row.nBaseline;
pno++;
break;
case diRun:
assert(para);
run = &p->member.run;
if (visible && me_debug) {
rc.left = c->rcView.left+run->pt.x;
rc.right = c->rcView.left+run->pt.x+run->nWidth;
rc.top = c->pt.y+run->pt.y;
rc.bottom = c->pt.y+run->pt.y+height;
TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
if (run->nFlags & MERF_SKIPPED)
DrawFocusRect(c->hDC, &rc);
else
FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
}
if (visible)
ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, ¶graph->member.para);
if (me_debug)
{
/* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
WCHAR buf[2560];
POINT pt;
pt.x = run->pt.x;
pt.y = c->pt.y + run->pt.y;
wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
ME_DebugWrite(c->hDC, &pt, buf);
}
/* c->pt.x += p->member.run.nWidth; */
break;
default:
break;
}
no++;
}
SetTextAlign(c->hDC, align);
}
void ME_ScrollAbs(ME_TextEditor *editor, int absY)
{
ME_Scroll(editor, absY, 1);
}
void ME_ScrollUp(ME_TextEditor *editor, int cy)
{
ME_Scroll(editor, cy, 2);
}
void ME_ScrollDown(ME_TextEditor *editor, int cy)
{
ME_Scroll(editor, cy, 3);
}
void ME_Scroll(ME_TextEditor *editor, int value, int type)
{
SCROLLINFO si;
int nOrigPos, nNewPos, nActualScroll;
nOrigPos = ME_GetYScrollPos(editor);
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS;
switch (type)
{
case 1:
/*Scroll absolutly*/
si.nPos = value;
break;
case 2:
/* Scroll up - towards the beginning of the document */
si.nPos = nOrigPos - value;
break;
case 3:
/* Scroll down - towards the end of the document */
si.nPos = nOrigPos + value;
break;
default:
FIXME("ME_Scroll called incorrectly\n");
si.nPos = 0;
}
nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw);
nActualScroll = nOrigPos - nNewPos;
if (editor->bRedraw)
{
if (abs(nActualScroll) > editor->sizeWindow.cy)
InvalidateRect(editor->hWnd, NULL, TRUE);
else
ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE);
ME_Repaint(editor);
}
ME_UpdateScrollBar(editor);
}
void ME_UpdateScrollBar(ME_TextEditor *editor)
{
/* Note that this is the only funciton that should ever call SetScrolLInfo
* with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
* be used at all. */
HWND hWnd;
SCROLLINFO si;
BOOL bScrollBarWasVisible,bScrollBarWillBeVisible;
if (ME_WrapMarkedParagraphs(editor))
FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
hWnd = editor->hWnd;
si.cbSize = sizeof(si);
bScrollBarWasVisible = ME_GetYScrollVisible(editor);
bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy;
if (bScrollBarWasVisible != bScrollBarWillBeVisible)
{
ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
ME_MarkAllForWrapping(editor);
ME_WrapMarkedParagraphs(editor);
}
si.fMask = SIF_PAGE | SIF_RANGE;
if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL)
si.fMask |= SIF_DISABLENOSCROLL;
si.nMin = 0;
si.nMax = editor->nTotalLength;
si.nPage = editor->sizeWindow.cy;
TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
}
int ME_GetYScrollPos(ME_TextEditor *editor)
{
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
GetScrollInfo(editor->hWnd, SB_VERT, &si);
return si.nPos;
}
BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
{ /* Returns true if the scrollbar is visible */
SCROLLBARINFO sbi;
sbi.cbSize = sizeof(sbi);
GetScrollBarInfo(editor->hWnd, OBJID_VSCROLL, &sbi);
return ((sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0);
}
void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
{
ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
int y, yrel, yheight, yold;
assert(pRow);
assert(pPara);
y = pPara->member.para.nYPos+pRow->member.row.nYPos;
yheight = pRow->member.row.nHeight;
yold = ME_GetYScrollPos(editor);
yrel = y - yold;
if (y < yold)
ME_ScrollAbs(editor,y);
else if (yrel + yheight > editor->sizeWindow.cy)
ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy);
}
void
ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
{
RECT rc;
int x, y, height;
ME_Cursor tmp;
ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
rc.left = 0;
rc.top = y;
rc.bottom = y + height;
rc.right = editor->rcFormat.right;
InvalidateRect(editor->hWnd, &rc, FALSE);
}
void
ME_InvalidateSelection(ME_TextEditor *editor)
{
ME_DisplayItem *para1, *para2;
int nStart, nEnd;
int len = ME_GetTextLength(editor);
ME_GetSelection(editor, &nStart, &nEnd);
/* if both old and new selection are 0-char (= caret only), then
there's no (inverted) area to be repainted, neither old nor new */
if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
return;
ME_WrapMarkedParagraphs(editor);
ME_GetSelectionParas(editor, ¶1, ¶2);
assert(para1->type == diParagraph);
assert(para2->type == diParagraph);
/* last selection markers aren't always updated, which means
they can point past the end of the document */
if (editor->nLastSelStart > len)
editor->nLastSelEnd = len;
if (editor->nLastSelEnd > len)
editor->nLastSelEnd = len;
/* if the start part of selection is being expanded or contracted... */
if (nStart < editor->nLastSelStart) {
ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
} else
if (nStart > editor->nLastSelStart) {
ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
}
/* if the end part of selection is being contracted or expanded... */
if (nEnd < editor->nLastSelEnd) {
ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
} else
if (nEnd > editor->nLastSelEnd) {
ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
}
ME_InvalidateMarkedParagraphs(editor);
/* remember the last invalidated position */
ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
assert(editor->pLastSelStartPara->type == diParagraph);
assert(editor->pLastSelEndPara->type == diParagraph);
}
void
ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
{
editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
}
BOOL
ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
{
/* TODO: Zoom images and objects */
if (numerator != 0)
{
if (denominator == 0)
return FALSE;
if (1.0 / 64.0 > (float)numerator / (float)denominator
|| (float)numerator / (float)denominator > 64.0)
return FALSE;
}
editor->nZoomNumerator = numerator;
editor->nZoomDenominator = denominator;
ME_RewrapRepaint(editor);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -