📄 cnreport.cpp
字号:
hClientDC = GetDC(Handle);
hInvertPen = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
hPrevPen = SelectObject(hClientDC, hInvertPen);
PrevDrawMode = SetROP2(hClientDC, R2_NOTXORPEN);
// 置横向标志
if (abs(RectCell.Bottom - point.y) <= 3 )
bHorz = True;
else
bHorz = False;
// 计算上下左右边界
ThisLine = ThisCell->OwnerLine;
RectBorder.Top = ThisLine->LineTop + 5;
RectBorder.Bottom = Height - 10;
RectBorder.Right = ClientRect.Right;
NextCell = NULL;
for (I = 0 ; I < ThisLine->FCells->Count; I++)
{
TempCell = ((TCNReportCell *)ThisLine->FCells->Items[I]);
if (ThisCell == TempCell )
{
RectBorder.Left = ThisCell->CellLeft + 10;
if (I < ThisLine->FCells->Count - 1 )
{
NextCell = (TCNReportCell *)ThisLine->FCells->Items[I + 1];
RectBorder.Right = NextCell->CellLeft + NextCell->CellWidth - 10;
}
else
RectBorder.Right = ClientRect.Right - 10;
}
}
if ( !bHorz )
{
// 若无选中的CELL,或者要改变宽度的CELL和NEXTCELL不在选中区中
bSelectFlag = False;
if (FSelectCells->Count <= 0 )
bSelectFlag = True;
if (NextCell == NULL )
{
if(( !IsCellSelected(ThisCell)) && (!IsCellSelected(NextCell)) )
bSelectFlag = True;
}
else
if((!IsCellSelected(ThisCell)) && (!IsCellSelected(NextCell)) &&
(!IsCellSelected(NextCell->OwnerCell)))
bSelectFlag = True;
if (bSelectFlag )
{
for (I = 0 ; I < FLineList->Count; I++)
{
TempLine = (TCNReportLine *)FLineList->Items[I];
for (J = 0 ; J < TempLine->FCells->Count; J ++)
{
TempCell = (TCNReportCell *)TempLine->FCells->Items[J];
// 若该CELL的右边等于选中的CELL的右边,将该CELL和NEXTCELL加入到两个LIST中去
if (TempCell->CellRect.Right == ThisCell->CellRect.Right)
{
ThisCellsList->Add(TempCell);
if (TempCell->CellLeft + 10 > RectBorder.Left)
RectBorder.Left = TempCell->CellLeft + 10;
if (J < TempLine->FCells->Count - 1)
{
TempNextCell = (TCNReportCell *)TempLine->FCells->Items[J + 1];
if (TempNextCell->CellRect.Right - 10 < RectBorder.Right)
RectBorder.Right = TempNextCell->CellRect.Right - 10;
}
}
}
}
}
else
{
for (I = 0; I < FLineList->Count; I++)
{
TempLine = (TCNReportLine *)FLineList->Items[I];
TempNextCell = NULL;
for (J = 0 ; J < TempLine->FCells->Count; J ++)
{
TempCell = (TCNReportCell *)TempLine->FCells->Items[J];
// 若该CELL的右边等于选中的CELL的右边,将该CEL加入到LIST中去
// 前提是CELL或NEXTCELL在选中区内
if((TempCell->CellRect.Right) == (ThisCell->CellRect.Right))
{
if (J < TempLine->FCells->Count - 1 )
TempNextCell = (TCNReportCell *)TempLine->FCells->Items[J + 1];
if( (!IsCellSelected(TempNextCell)) && (!IsCellSelected(TempCell)))
break;
if (TempNextCell != NULL )
{
if (TempNextCell->CellRect.Right - 10 < RectBorder.Right)
RectBorder.Right = TempNextCell->CellRect.Right - 10;
}
ThisCellsList->Add(TempCell);
if (TempCell->CellLeft + 10 > RectBorder.Left )
RectBorder.Left = TempCell->CellLeft + 10;
break;
}
}
}
}
}
// 画第一条线
if (bHorz)
{
FMousePoint.y = trunc(FMousePoint.y / 5 * 5 + 0.5);
if (FMousePoint.y < RectBorder.Top )
FMousePoint.y = RectBorder.Top;
if (FMousePoint.y > RectBorder.Bottom)
FMousePoint.y = RectBorder.Bottom;
MoveToEx(hClientDC, 0, FMousePoint.y, NULL);
LineTo(hClientDC, RectClient.Right, FMousePoint.y);
::SetCursor(LoadCursor(0, IDC_SIZENS));
}
else
{
FMousePoint.x = trunc(FMousePoint.x / 5 * 5 + 0.5);
if (FMousePoint.x < RectBorder.Left )
FMousePoint.x = RectBorder.Left;
if (FMousePoint.x > RectBorder.Right)
FMousePoint.x = RectBorder.Right;
MoveToEx(hClientDC, FMousePoint.x, 0, NULL);
LineTo(hClientDC, FMousePoint.x, RectClient.Bottom);
::SetCursor(LoadCursor(0, IDC_SIZEWE));
};
::SetCapture(Handle);
// 取得鼠标输入,进入第二个消息循环
while (::GetCapture() == Handle )
{
if (!GetMessage(&TempMsg, Handle, 0, 0) )
{
PostQuitMessage(TempMsg.wParam);
break;
}
switch(TempMsg.message)
{
case WM_LBUTTONUP:
ReleaseCapture();
break;
case WM_MOUSEMOVE:
if( bHorz )
{
MoveToEx(hClientDC, 0, FMousePoint.y, NULL);
LineTo(hClientDC, RectClient.Right, FMousePoint.y);
FMousePoint = TempMsg.pt;
::ScreenToClient(Handle, &FMousePoint);
// 边界检查
FMousePoint.y = trunc(FMousePoint.y / 5 * 5 + 0.5);
if (FMousePoint.y < RectBorder.Top )
FMousePoint.y = RectBorder.Top;
if (FMousePoint.y > RectBorder.Bottom)
FMousePoint.y = RectBorder.Bottom;
MoveToEx(hClientDC, 0, FMousePoint.y, NULL);
LineTo(hClientDC, RectClient.Right, FMousePoint.y);
}
else
{
MoveToEx(hClientDC, FMousePoint.x, 0, NULL);
LineTo(hClientDC, FMousePoint.x, RectClient.Bottom);
FMousePoint = TempMsg.pt;
::ScreenToClient(Handle, &FMousePoint);
// 边界检查
FMousePoint.x = trunc(FMousePoint.x / 5 * 5 + 0.5);
if (FMousePoint.x < RectBorder.Left )
FMousePoint.x = RectBorder.Left;
if (FMousePoint.x > RectBorder.Right )
FMousePoint.x = RectBorder.Right;
MoveToEx(hClientDC, FMousePoint.x, 0, NULL);
LineTo(hClientDC, FMousePoint.x, RectClient.Bottom);
}
break;
case WM_SETCURSOR: break;
default:
DispatchMessage(&TempMsg);
}
}
if (::GetCapture() == Handle )
ReleaseCapture();
if ( bHorz )
{
// 将反显的线去掉
MoveToEx(hClientDC, 0, FMousePoint.y, NULL);
LineTo(hClientDC, RectClient.Right, FMousePoint.y);
// 改变行高
// 改变行高
if (ThisCell->FCellsList->Count <= 0 )
{
// 不跨越其他CELL时
BottomCell = ThisCell;
}
else
{
// 跨越其他CELL时,取得最下一行的CELL
BottomCell = NULL;
Top = 0;
for (I = 0 ; I < ThisCell->FCellsList->Count; I++)
{
if ( ((TCNReportCell *)ThisCell->FCellsList->Items[I])->CellTop > Top )
{
BottomCell = (TCNReportCell *)ThisCell->FCellsList->Items[I];
Top = BottomCell->CellTop;
}
}
}
BottomCell->CalcMinCellHeight();
BottomCell->OwnerLine->LineHeight = FMousePoint.y - BottomCell->OwnerLine->LineTop;
UpdateLines();
}
else
{
// 将反显的线去掉
MoveToEx(hClientDC, FMousePoint.x, 0, NULL);
LineTo(hClientDC, FMousePoint.x, RectClient.Bottom);
// 在此处判断对CELL宽度的设定是否有效
DragBottom = ThisCellsList->Count;
for (I = 0 ; I < DragBottom ; I ++)
{
for (J = 0 ; J < ((TCNReportCell *)ThisCellsList->Items[I])->FCellsList->Count; J++)
{
ThisCellsList->Add( ((TCNReportCell *)ThisCellsList->Items[I])->FCellsList->Items[J]);
}
}
// 取得NEXTCELL
if (ThisCellsList->Count > 0 )
{
ThisCell = ((TCNReportCell *)ThisCellsList->Items[0]);
if (ThisCell->CellIndex < ThisCell->OwnerLine->FCells->Count - 1 )
NextCell =((TCNReportCell *)ThisCell->OwnerLine->FCells->Items[ThisCell->CellIndex + 1]);
// 右边的CELL不为空且隶属与某一CELL
if (NextCell != NULL )
{
if( NextCell->OwnerCell != NULL )
{
SelectObject(hClientDC, hPrevPen);
DeleteObject(hInvertPen);
SetROP2(hClientDC, PrevDrawMode);
::ReleaseDC(Handle, hClientDC);
return;
}
}
DragBottom = 0;
for (I = 0 ; I < ThisCellsList->Count ; I++)
{
if ( ((TCNReportCell *)ThisCellsList->Items[I])->CellRect.Bottom > DragBottom )
DragBottom = ((TCNReportCell *)ThisCellsList->Items[I])->CellRect.Bottom;
}
for (I = 0 ; I < ThisCellsList->Count ; I++)
{
ThisCell = ((TCNReportCell *)ThisCellsList->Items[I]);
if (ThisCell->CellIndex < ThisCell->OwnerLine->FCells->Count - 1 )
NextCell = ((TCNReportCell *)ThisCell->OwnerLine->FCells->Items[ThisCell->CellIndex + 1]);
if (NextCell != NULL )
{
if (NextCell->CellRect.Bottom > DragBottom )
{
SelectObject(hClientDC, hPrevPen);
DeleteObject(hInvertPen);
SetROP2(hClientDC, PrevDrawMode);
ReleaseDC(Handle, hClientDC);
return;
}
}
}
}
for (I = 0 ; I < ThisCellsList->Count; I++)
{
ThisCell = ((TCNReportCell *)ThisCellsList->Items[I]);
NextCell = NULL;
if (ThisCell->CellIndex < ThisCell->OwnerLine->FCells->Count - 1 )
NextCell = ((TCNReportCell *)ThisCell->OwnerLine->FCel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -