与之前的键盘上下键一样的封装逻辑,这里就不复重了。
改变是:绘制缓冲区字符串时,要加上列的偏移量:
void EditView::drawText(HDC hdc){
int OFFSET = 0;
HFONT hFont = CreateFontIndirect(&logFont);
SelectObject(hdc, hFont);
//-----------------------
int firstRowIndex = lpEditViewAdapter->firstVisibleRowIndex;
int rowCount = lpEditViewAdapter->visibleRowCount;
int columnIndex = lpEditViewAdapter->firstVisibleColumnIndex;
TCHAR * textBuffer = NULL;
RECT textRect;
int incHeight = getCharHeight();
int i = 0;
int j = 0;
VIEW_RECT viewRect = getArea();
// initial RECT of draw text in editor area.
textRect.left = viewRect.left;
textRect.right = viewRect.right - 1;
textRect.top = viewRect.top;
textRect.bottom = textRect.top + incHeight;
OFFSET = lpEditViewAdapter->firstVisibleColumnIndex;
for (i = firstRowIndex, j = 0; i <= firstRowIndex + rowCount; i++, j++){
// move to row
textBuffer = lpEditViewAdapter->editTextBuffer[0] + j * GOLBAL_MEM_COLUMN_MAX + OFFSET;
// move to first visible column
textBuffer += columnIndex;
// draw text on screen
DrawText(hdc, textBuffer, lstrlen(textBuffer), &textRect, DT_LEFT);
// refresh vertical parameter of RECT.
textRect.top = incHeight * (j+1);
textRect.bottom = textRect.top + incHeight;
}// end for
//-----------------------
DeleteObject(hFont);
}
最右的边界检测没有做,等以后再作为BUG微调:
下一步,就是绑定滚动条以及滚动条的UI。