📄 tpaint.c
字号:
RECT rc, rcbox;
int cx, x, y, tabwidth;
UINT align;
LPSTR chp, tabp;
DWORD fcol, bkcol;
HFONT hfont;
TEXTMETRIC tm;
HBRUSH hbr;
/* init pointers to cell text and properties */
pline = &ptab->pdata[line];
cd = &pline->pdata[cell];
ppos = &ptab->pcellpos[cell];
/* clip all output to this rectangle */
rc.top = pline->linepos.clipstart;
rc.bottom = pline->linepos.clipend;
rc.left = ppos->clipstart;
rc.right = ppos->clipend;
/* check cell properties and colours */
if (cd->props.valid & P_ALIGN) {
align = cd->props.alignment;
} else {
align = P_LEFT;
}
if (cd->props.valid & P_FONT) {
hfont = SelectObject(hdc, cd->props.hFont);
GetTextMetrics(hdc, &tm);
tabwidth = tm.tmAveCharWidth * 8;
} else {
tabwidth = ptab->avewidth * 8;
}
/* set colours if not default */
if (cd->props.valid & P_FCOLOUR) {
fcol = SetTextColor(hdc, cd->props.forecolour);
}
if (cd->props.valid & P_BCOLOUR) {
/* there is a non-default background colour.
* create a brush and fill the entire cell with it
*/
hbr = CreateSolidBrush(cd->props.backcolour);
FillRect(hdc, &rc, hbr);
DeleteObject(hbr);
/* also set colour as background colour for the text */
bkcol = SetBkColor(hdc, cd->props.backcolour);
}
/* calc offset of text within cell for right-align or centering */
if (align == P_LEFT) {
cx = ptab->avewidth/2;
} else {
if (cd->ptext == NULL) {
cx = 0;
} else {
cx = LOWORD(GetTextExtent(hdc, cd->ptext,
lstrlen(cd->ptext)));
}
if (align == P_CENTRE) {
cx = (ppos->size - cx) / 2;
} else {
cx = ppos->size - cx - (ptab->avewidth/2);
}
}
cx += ppos->start;
/* expand tabs on output */
x = 0;
y = pline->linepos.start;
for (chp = cd->ptext;
((chp != NULL) && ((tabp = strchr(chp, '\t')) != NULL)); ) {
/* perform output upto tab char */
ExtTextOut(hdc, x+cx, y, ETO_CLIPPED, &rc, chp, tabp-chp, NULL);
/* advance past the tab */
x += LOWORD(GetTextExtent(hdc, chp, tabp - chp));
x = ( (x + tabwidth) / tabwidth) * tabwidth;
chp = ++tabp;
}
/*no more tabs - output rest of string */
if (chp != NULL) {
ExtTextOut(hdc, x+cx, y, ETO_CLIPPED, &rc,
chp, lstrlen(chp), NULL);
}
/* reset colours to original if not default */
if (cd->props.valid & P_FCOLOUR) {
SetTextColor(hdc, fcol);
}
if (cd->props.valid & P_BCOLOUR) {
SetBkColor(hdc, bkcol);
}
if (cd->props.valid & P_FONT) {
SelectObject(hdc, hfont);
}
/* now box cell if marked */
if (cd->props.valid & P_BOX) {
if (cd->props.box != 0) {
rcbox.top = pline->linepos.start;
rcbox.bottom = rcbox.top + pline->linepos.size;
rcbox.left = ppos->start;
rcbox.right = ppos->start + ppos->size;
gtab_boxcell(hwnd, hdc, &rcbox, &rc, cd->props.box);
}
}
}
/***************************************************************************
* Function: gtab_paint
*
* Purpose:
*
* Fetch and paint the specified line
*/
void
gtab_paint(HWND hwnd, HDC hdc, lpTable ptab, int line)
{
lpCellPos ppos;
int i;
gtab_updateline(hwnd, ptab, line);
for (i = 0; i < ptab->hdr.ncols; i++) {
ppos = &ptab->pcellpos[i];
if (ppos->clipstart < ppos->clipend) {
gtab_paintcell(hwnd, hdc, ptab, line, i);
}
}
}
/***************************************************************************
* Function: gtab_vsep
*
* Purpose:
*
*/
void
gtab_vsep(HWND hwnd, lpTable ptab, HDC hdc)
{
int x;
RECT rc;
if (ptab->hdr.fixedcols < 1) {
return;
}
x = ptab->pcellpos[ptab->hdr.fixedcols - 1].clipend+1;
GetClientRect(hwnd, &rc);
MoveToEx(hdc, x, rc.top, NULL);
LineTo(hdc, x, rc.bottom);
}
/***************************************************************************
* Function: gtab_hsep
*
* Purpose:
*/
void
gtab_hsep(HWND hwnd, lpTable ptab, HDC hdc)
{
int y;
RECT rc;
if (ptab->hdr.fixedrows < 1) {
return;
}
y = ptab->rowheight * ptab->hdr.fixedrows;
GetClientRect(hwnd, &rc);
MoveToEx(hdc, rc.left, y-1, NULL);
LineTo(hdc, rc.right, y-1);
}
/***************************************************************************
* Function: gtab_drawverline
*
* Purpose:
*
* Draw in (inverting) the dotted selection lines for tracking a col width
*/
void
gtab_drawvertline(HWND hwnd, lpTable ptab)
{
RECT rc;
HDC hdc;
HPEN hpen;
hdc = GetDC(hwnd);
SetROP2(hdc, R2_XORPEN);
hpen = SelectObject(hdc, hpenDotted);
GetClientRect(hwnd, &rc);
MoveToEx(hdc, ptab->trackline1, rc.top, NULL);
LineTo(hdc, ptab->trackline1, rc.bottom);
if (ptab->trackline2 != -1) {
MoveToEx(hdc, ptab->trackline2, rc.top, NULL);
LineTo(hdc, ptab->trackline2, rc.bottom);
}
SelectObject(hdc, hpen);
ReleaseDC(hwnd, hdc);
}
/***************************************************************************
* Function: gtab_invertsel
*
* Purpose:
*
* Mark the selected line, if visible, in the style chosen by the
* client app. This can be TM_SOLID, meaning an inversion of
* the whole selected area or TM_FOCUS, meaning, inversion of the first
* cell, and then a dotted focus rectangle for the rest.
*
* This function inverts either style, and so will turn the selection
* both on and off.
*/
void
gtab_invertsel(HWND hwnd, lpTable ptab, HDC hdc_in)
{
HDC hdc;
int line;
RECT rc;
int lastcell;
/* is row visible on screen ? */
line = gtab_rowtoline(hwnd, ptab, ptab->select.startrow);
if (line < 0) {
return;
}
/* selection mode includes a flag TM_FOCUS indicating we should
* use a focus rect instead of the traditional inversion for
* selections in this table. This interferes with multiple backgrnd
* colours less. However we still do inversion for fixedcols.
*/
lastcell = (int)(ptab->select.startcell + ptab->select.ncells - 1);
rc.top = ptab->pdata[line].linepos.clipstart;
rc.bottom = ptab->pdata[line].linepos.clipend;
/*
* invert the whole area for TM_SOLID or just the first
* cell for TM_FOCUS
*/
rc.left = ptab->pcellpos[ptab->select.startcell].clipstart;
if (ptab->hdr.selectmode & TM_FOCUS) {
rc.right = ptab->pcellpos[ptab->select.startcell].clipend;
}else {
rc.right = ptab->pcellpos[lastcell].clipend;
}
if (hdc_in == NULL) {
hdc = GetDC(hwnd);
} else {
hdc = hdc_in;
}
InvertRect(hdc, &rc);
/*
* draw focus rectangle around remaining cells on this line, if there
* are any
*/
if (ptab->hdr.selectmode & TM_FOCUS) {
if (ptab->select.ncells > 1) {
rc.left = ptab->pcellpos[ptab->select.startcell+1].clipstart;
rc.right = ptab->pcellpos[lastcell].clipend;
DrawFocusRect(hdc, &rc);
}
}
if (hdc_in == NULL) {
ReleaseDC(hwnd, hdc);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -