📄 cnreport.cpp
字号:
}
else return False;
}
void __fastcall TCNReportControl::SetCellLines(bool bLeftLine, bool bTopLine, bool bRightLine, bool bBottomLine, int nLeftLineWidth, int nTopLineWidth, int nRightLineWidth, int nBottomLineWidth)
{
int I;
TRect CellRect;
for (I = 0 ; I < FSelectCells->Count; I++)
{
((TCNReportCell *)FSelectCells->Items[I])->LeftLine = bLeftLine;
((TCNReportCell *)FSelectCells->Items[I])->LeftLineWidth = nLeftLineWidth;
((TCNReportCell *)FSelectCells->Items[I])->TopLine = bTopLine;
((TCNReportCell *)FSelectCells->Items[I])->TopLineWidth = nTopLineWidth;
((TCNReportCell *)FSelectCells->Items[I])->RightLine = bRightLine;
((TCNReportCell *)FSelectCells->Items[I])->RightLineWidth = nRightLineWidth;
((TCNReportCell *)FSelectCells->Items[I])->BottomLine = bBottomLine;
((TCNReportCell *)FSelectCells->Items[I])->BottomLineWidth = nBottomLineWidth;
CellRect = ((TCNReportCell *)FSelectCells->Items[I])->CellRect;
CellRect.Left = CellRect.left - 1;
CellRect.Top = CellRect.top - 1;
CellRect.Right = CellRect.Right + 1;
CellRect.Bottom= CellRect.Bottom + 1;
InvalidateRect(Handle, &CellRect, false);
}
UpdateLines();
}
void __fastcall TCNReportControl::SetCellDiagonal(unsigned NewDiagonal)
{
for (int I = 0 ; I < FSelectCells->Count; I++)
{
((TCNReportCell *)FSelectCells->Items[I])->Diagonal = NewDiagonal;
InvalidateRect(Handle, &(((TCNReportCell *)FSelectCells->Items[I])->CellRect), False);
}
}
void __fastcall TCNReportControl::SetCellColor(unsigned NewTextColor, unsigned NewBackColor)
{
for(int I = 0 ; I < FSelectCells->Count; I++)
{
((TCNReportCell *)FSelectCells->Items[I])->TextColor = NewTextColor;
((TCNReportCell *)FSelectCells->Items[I])->BkColor = NewBackColor;
InvalidateRect(Handle, &(((TCNReportCell *)FSelectCells->Items[I])->CellRect), False);
}
}
void __fastcall TCNReportControl::SetCellFont(const tagLOGFONTA &CellFont)
{
TRect CellRect;
for ( int I = 0 ; I < FSelectCells->Count; I++)
{
((TCNReportCell *)FSelectCells->Items[I])->LogFont = CellFont;
CellRect = ((TCNReportCell *)FSelectCells->Items[I])->CellRect;
CellRect.Left = CellRect.left - 1;
CellRect.Top = CellRect.top - 1;
CellRect.Right = CellRect.Right + 1;
CellRect.Bottom = CellRect.Bottom + 1;
InvalidateRect(Handle, &CellRect, false);
}
UpdateLines();
}
void __fastcall TCNReportControl::SetCellAlign(int NewHorzAlign, int NewVertAlign)
{
for (int I = 0; I < FSelectCells->Count; I++)
{
((TCNReportCell *)FSelectCells->Items[I])->HorzAlign = NewHorzAlign;
((TCNReportCell *)FSelectCells->Items[I])->VertAlign = NewVertAlign;
InvalidateRect(Handle, &(((TCNReportCell *)FSelectCells->Items[I])->CellRect), False);
}
UpdateLines();
}
void __fastcall TCNReportControl::SetMargin(int nLeftMargin, int nTopMargin, int nRightMargin, int nBottomMargin)
{
TRect RectClient;
int nPixelsPerInch;
HDC hTempDC;
// 将毫米数转化为象素点
if((FLeftMargin1 != nLeftMargin) ||
(FTopMargin1 != nTopMargin) ||
(FRightMargin1 != nRightMargin) ||
(FBottomMargin1!= nBottomMargin) )
{
hTempDC = GetDC(Handle);
nPixelsPerInch = GetDeviceCaps(hTempDC, LOGPIXELSX);
ReleaseDC(Handle, hTempDC);
FLeftMargin1 = nLeftMargin;
FTopMargin1 = nTopMargin;
FRightMargin1 = nRightMargin;
FBottomMargin1 = nBottomMargin;
FLeftMargin = trunc(nLeftMargin * nPixelsPerInch / 25 + 0.5);
FTopMargin = trunc(nTopMargin * nPixelsPerInch / 25 + 0.5);
FRightMargin = trunc(nRightMargin * nPixelsPerInch / 25 + 0.5);
FBottomMargin= trunc(nBottomMargin * nPixelsPerInch / 25 + 0.5);
UpdateLines();
RectClient = ClientRect;
InvalidateRect(Handle, &RectClient, False);
}
}
TRect __fastcall TCNReportControl::GetMargin()
{
TRect Result;
Result.Left = FLeftMargin1;
Result.Top = FTopMargin1;
Result.Right = FRightMargin1;
Result.Bottom = FBottomMargin1;
return Result;
}
TFont* __fastcall TCNReportControl::GetcellFont(void)
{
int i;
TFont *AFont,*Result;
try{
AFont = new TFont;
i = 0;
if (FSelectCells->Count > 0 )
{
AFont->Handle = CreateFontIndirect(&(((TCNReportCell *)FSelectCells->Items[i])->LogFont));
Result = AFont;
}
else Result = NULL;
}
__finally{
delete AFont;
};
return Result;
}
void __fastcall TCNReportControl::UpdateLines(void)
{
TRect PrevRect, TempRect;
int I, J;
TCNReportLine *ThisLine;
TCNReportCell *ThisCell;
// 首先计算合并后的单元格
for (I = 0 ; I < FLineList->Count; I++)
{
ThisLine = ((TCNReportLine *)FLineList->Items[I]);
for ( J = 0 ; J < ThisLine->FCells->Count; J++)
{
ThisCell = ((TCNReportCell *)ThisLine->FCells->Items[J]);
if (ThisCell->FCellsList->Count > 0)
ThisCell->CalcMinCellHeight();
}
}
// 计算每行的高度
for (I = 0 ; I < FLineList->Count; I++)
{
ThisLine = ((TCNReportLine *)FLineList->Items[I]);
ThisLine->CalcLineHeight();
}
for (I = 0; I < FLineList->Count; I++)
{
ThisLine = ((TCNReportLine *)FLineList->Items[I]);
ThisLine->Index = I;
if (I == 0 )
ThisLine->LineTop = FTopMargin;
if (I > 0 )
ThisLine->LineTop = ((TCNReportLine *)FLineList->Items[I - 1])->LineTop + ((TCNReportLine *)FLineList->Items[I - 1])->LineHeight;
PrevRect = ThisLine->PrevLineRect;
TempRect = ThisLine->LineRect;
if((PrevRect.Left != TempRect.Left) || (PrevRect.Top != TempRect.Top) ||
(PrevRect.Right != TempRect.Right) || (PrevRect.Bottom != TempRect.Bottom) &&
(TempRect.Top <= ClientRect.Bottom))
{
for (J = 0; J < ThisLine->FCells->Count; J++)
{
ThisCell = ((TCNReportCell *)ThisLine->FCells->Items[J]);
if (ThisCell->OwnerCell != NULL)
InvalidateRect(Handle, &(ThisCell->OwnerCell->CellRect), False);
}
PrevRect.Right = PrevRect.Right + 1;
PrevRect.Bottom = PrevRect.Bottom + 1;
TempRect.Right = TempRect.Right + 1;
TempRect.Bottom = TempRect.Bottom + 1;
InvalidateRect(Handle, &PrevRect, False);
InvalidateRect(Handle, &TempRect, False);
}
}
}
bool __fastcall TCNReportControl::AddSelectedCell(TCNReportCell* Cell)
{
HDC hClientDC;
if (IsCellSelected(Cell) || (Cell == NULL) )
{
return False;
}
else
{
FSelectCells->Add(Cell);
celldisp = Cell;
FcellFont_d = Cell->FLogFont; //取选中单元格的字体类型 1999.1.23
cellline_d = Cell; //用于保存选中单元格的属性 1999.1.25
hClientDC = GetDC(Handle);
InvertRect(hClientDC, &(Cell->CellRect));
ReleaseDC(Handle, hClientDC);
return True;
}
}
bool __fastcall TCNReportControl::RemoveSelectedCell(TCNReportCell* Cell)
{
HDC hClientDC;
if (!IsCellSelected(Cell))
{
return False;
}
else
{
hClientDC = GetDC(Handle);
InvertRect(hClientDC, &(Cell->CellRect));
ReleaseDC(Handle, hClientDC);
FSelectCells->Remove(Cell);
return True;
}
}
void __fastcall TCNReportControl::RemoveAllSelectedCell(void)
{
TCNReportCell *ThisCell;
HDC hClientDC;
hClientDC = GetDC(Handle);
while (FSelectCells->Count > 0 )
{
ThisCell = ((TCNReportCell *)FSelectCells->First());
InvertRect(hClientDC, &(ThisCell->CellRect));
FSelectCells->Remove(ThisCell);
}
ReleaseDC(Handle, hClientDC);
}
bool __fastcall TCNReportControl::IsCellSelected(TCNReportCell* Cell)
{
if (Cell == NULL) return False;
if (FSelectCells->IndexOf(Cell) >= 0 ) return True;
return False;
}
TCNReportCell* __fastcall TCNReportControl::CellFromPoint(const TPoint &point)
{
int I, J;
TCNReportLine *ThisLine;
TCNReportCell *ThisCell;
TCNReportCell *Result = NULL;
for (I = 0; I < FLineList->Count; I++)
{
ThisLine = ((TCNReportLine *)FLineList->Items[I]);
if ((point.y >= ThisLine->LineTop) && (point.y <= (ThisLine->LineTop + ThisLine->LineHeight)) )
{
for (J = 0; J < ThisLine->FCells->Count; J++)
{
ThisCell = ((TCNReportCell *)ThisLine->FCells->Items[J]);
if (PtInRect(&(ThisCell->CellRect), point) )
{
if (ThisCell->OwnerCell != NULL)
Result = ThisCell->OwnerCell;
else
Result = ThisCell;
break;
}
}
}
}
return Result;
}
void __fastcall TCNReportControl::StartMouseDrag(const TPoint &point)
{
TCNReportCell *TempCell, *TempNextCell, *ThisCell, *NextCell;
TList *ThisCellsList;
TRect TempRect, RectBorder, RectCell, RectClient;
HDC hClientDC;
HPEN hInvertPen, hPrevPen;
int PrevDrawMode, PrevCellWidth, Distance;
int I, J;
bool bHorz, bSelectFlag;
TCNReportLine *ThisLine, *TempLine;
MSG TempMsg;
TCNReportCell *BottomCell;
int Top;
int DragBottom;
ThisCell = CellFromPoint(point);
RectCell = ThisCell->CellRect;
FMousePoint = point;
::GetClientRect(Handle, &RectClient);
ThisCellsList = new TList;
// 设置线形和绘制模式
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -