📄 crctrls.pas
字号:
for I := 0 to Cell.FCellsList.Count - 1 do
TempCellList.Add(Cell.FCellsList[I]);
Cell.RemoveAllOwnedCell();
for I := 0 to TempCellList.Count - 1 do
begin
FCellsList.Add(TempCellList[I]);
TReportCell(TempCellList[I]).OwnerCell := Self;
end;
finally
TempCellList.Free;
end;
// CalcMinCellHeight;
end;
procedure TReportCell.RemoveAllOwnedCell;
var
I: Integer;
Cell: TReportCell;
begin
for I := 0 to FCellsList.Count - 1 do
begin
Cell := FCellsList[I];
Cell.SetOwnerCell(nil);
Cell.CalcMinCellHeight;
end;
FCellsList.Clear;
// CalcMinCellHeight;
end;
function TReportCell.IsCellOwned(Cell: TReportCell): Boolean;
begin
if FCellsList.IndexOf(Cell) >= 0 then
Result := True
else
Result := False;
end;
procedure TReportCell.SetCellLeft(CellLeft: Integer);
begin
if CellLeft = FCellLeft then
Exit;
FCellLeft := CellLeft;
CalcCellRect;
end;
procedure TReportCell.SetCellWidth(CellWidth: Integer);
begin
if CellWidth = FCellWidth then
Exit;
if CellWidth > 10 then
begin
FCellWidth := CellWidth;
CalcMinCellHeight;
CalcCellRect;
end
else
begin
FCellWidth := 10;
CalcMinCellHeight;
CalcCellRect;
end;
end;
function TReportCell.GetCellHeight: Integer;
begin
if FOwnerLine = nil then
Result := 0
else
begin
if FDragCellHeight > FMinCellHeight then
Result := FDragCellHeight
else
Result := FMinCellHeight;
end;
end;
function TReportCell.GetCellTop: Integer;
begin
if FOwnerLine = nil then
Result := 0
else
Result := FOwnerLine.LineTop;
end;
procedure TReportCell.SetLeftLine(LeftLine: Boolean);
begin
if LeftLine = FLeftLine then
Exit;
FLeftLine := LeftLine;
CalcMinCellHeight;
CalcCellRect;
// InvalidateRect here because Cell;s Rect no change
end;
procedure TReportCell.SetLeftLineWidth(LeftLineWidth: Integer);
begin
if LeftLineWidth = FLeftLineWidth then
Exit;
FLeftLineWidth := LeftLineWidth;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetTopLine(TopLine: Boolean);
begin
if TopLine = FTopLine then
Exit;
FTopLine := TopLine;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetTopLineWidth(TopLineWidth: Integer);
begin
if TopLineWidth = FTopLineWidth then
Exit;
FTopLineWidth := TopLineWidth;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetRightLine(RightLine: Boolean);
begin
if RightLine = FRightLine then
Exit;
FRightLine := RightLine;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetRightLineWidth(RightLineWidth: Integer);
begin
if RightLineWidth = FRightLineWidth then
Exit;
FRightLineWidth := RightLineWidth;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetBottomLine(BottomLine: Boolean);
begin
if BottomLine = FBottomLine then
Exit;
FBottomLine := BottomLine;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetBottomLineWidth(BottomLineWidth: Integer);
begin
if BottomLineWidth = FBottomLineWidth then
Exit;
FBottomLineWidth := BottomLineWidth;
CalcMinCellHeight;
CalcCellRect;
end;
procedure TReportCell.SetCellText(CellText: string);
begin
if CellText = FCellText then
Exit;
FCellText := CellText;
CalcMinCellHeight;
end;
procedure TReportCell.SetLogFont(NewFont: TLOGFONT);
begin
FLogFont := NewFont;
CalcMinCellHeight;
end;
procedure TReportCell.SetBackGroundColor(BkColor: COLORREF);
begin
if BkColor = FBackGroundColor then
Exit;
FBackGroundColor := BkColor;
// InvalidateRect
end;
procedure TReportCell.SetTextColor(TextColor: COLORREF);
begin
if TextColor = FTextColor then
Exit;
FTextColor := TextColor;
// InvalidateRect
end;
// 开始噩梦,噩梦中我把屏幕上的象素点一个一个干掉
procedure TReportCell.CalcMinCellHeight;
var
hTempFont, hPrevFont: HFONT;
hTempDC: HDC;
TempString: string;
TempRect: TRect;
Format: UINT;
I: Integer;
BottomCell, ThisCell: TReportCell;
TotalHeight, Height, Top: Integer;
TempSize: TSize;
begin
// 计算CELL的最小高度
if FCellWidth <= FLeftMargin * 2 then
begin
FMinCellHeight := 16 + 2 + FTopLineWidth + FBottomLineWidth;
Exit;
end;
// 隶属与某CELL时
if FOwnerCell <> nil then
begin
// 取得最下的单元格
FMinCellHeight := 16 + 2 + FTopLineWidth + FBottomLineWidth;
BottomCell := nil;
Height := 0;
Top := 0;
for I := 0 to FOwnerCell.FCellsList.Count - 1 do
begin
ThisCell := FOwnerCell.FCellsList[i];
ThisCell.FMinCellHeight := 16 + 2 + ThisCell.TopLineWidth + ThisCell.BottomLineWidth;
ThisCell.OwnerLine.CalcLineHeight;
Height := Height + ThisCell.OwnerLineHeight;
if ThisCell.CellTop > Top then
begin
BottomCell := ThisCell;
Top := ThisCell.CellTop;
end;
end;
if BottomCell <> Self then
begin
FMinCellHeight := 16 + 2 + FTopLineWidth + FBottomLineWidth;
Exit;
end
else
begin
TotalHeight := Height + FOwnerCell.OwnerLineHeight;
if FOwnerCell.RequiredCellHeight > TotalHeight then
FMinCellHeight := FOwnerCell.RequiredCellHeight - TotalHeight + OwnerLineHeight
else
FMinCellHeight := 16 + 2 + FTopLineWidth + FBottomLineWidth;
Exit;
end;
end;
// 此处取得窗口的指针用于计算大小
if (Length(FCellText) <= 0) then
TempString := '汉'
else
TempString := FCellText;
hTempFont := CreateFontIndirect(FLogFont);
hTempDC := GetDC(0);
try
hPrevFont := SelectObject(hTempDC, hTempFont);
SetRect(TempRect, 0, 0, 0, 0);
TempRect.left := FCellLeft + FLeftMargin;
TempRect.top := GetCellTop + 2;
TempRect.right := FCellLeft + FCellWidth - FLeftMargin;
TempRect.bottom := 65535;
Format := DT_EDITCONTROL or DT_WORDBREAK;
case FHorzAlign of
0:
Format := Format or DT_LEFT;
1:
Format := Format or DT_CENTER;
2:
Format := Format or DT_RIGHT;
else
Format := Format or DT_LEFT;
end;
Format := Format or DT_CALCRECT;
DrawText(hTempDC, PChar(TempString), Length(TempString), TempRect, Format);
// DrawText(hTempDC, PChar(TempString), -1, TempRect, Format);
// 补偿文字最后的回车带来的误差
if Length(TempString) >= 2 then
begin
if (TempString[Length(TempString)] = Chr(10)) and
(TempString[Length(TempString) - 1] = Chr(13)) then
begin
GetTextExtentPoint(hTempDC, 'A', 1, TempSize);
TempRect.Bottom := TempRect.Bottom + TempSize.cy;
end;
end;
SelectObject(hTempDc, hPrevFont);
finally
DeleteObject(hTempFont);
ReleaseDC(0, hTempDC);
end;
if (FCellsList.Count > 0) then
begin
if TempRect.Bottom - TempRect.Top <= 0 then
FRequiredCellHeight := 16
else
FRequiredCellHeight := TempRect.Bottom - TempRect.Top;
FRequiredCellHeight := FRequiredCellHeight + 2;
FRequiredCellHeight := FRequiredCellHeight + FTopLineWidth + FBottomLineWidth;
FMinCellHeight := 16 + 2 + FTopLineWidth + FBottomLineWidth;
OwnerLine.CalcLineHeight;
for I := 0 to FCellsList.Count - 1 do
TReportCell(FCellsList[I]).CalcMinCellHeight;
end
else
begin
if TempRect.Bottom - TempRect.Top <= 0 then
FMinCellHeight := 16
else
FMinCellHeight := TempRect.Bottom - TempRect.Top;
FMinCellHeight := FMinCellHeight + 2;
FMinCellHeight := FMinCellHeight + FTopLineWidth + FBottomLineWidth;
end;
end;
procedure TReportCell.CalcCellRect;
var
TempRect: TRect;
TotalHeight: Integer;
I: Integer;
begin
// Calc CellRect & TextRect here
// 如果CELL的大小或者文本框的大小改变,自动的置窗口的失效区
if FCellsList.Count <= 0 then
begin
// 计算CELL的矩形
FCellRect.left := FCellLeft;
FCellRect.top := CellTop;
FCellRect.right := FCellRect.left + FCellWidth;
FCellRect.bottom := FCellRect.top + OwnerLineHeight;
{ if scale <> 100 then //1999.1.23
begin
FCellrect.Left :=FCellrect.Left * 100 div Scale;
FCellrect.top :=FCellrect.top * 100 div Scale;
FCellrect.right :=FCellrect.right * 100 div Scale;
FCellrect.bottom :=FCellrect.bottom * 100 div Scale;
end;
}
// 计算文本框的矩形
TempRect := FCellRect;
TempRect.left := TempRect.Left + FLeftMargin + 1;
TempRect.top := TempRect.top + FTopLineWidth + 1;
TempRect.right := TempRect.right - FLeftMargin - 1;
TempRect.bottom := TempRect.top + FMinCellHeight - 2 - FTopLineWidth - FBottomLineWidth;
case FVertAlign of
TEXT_ALIGN_VCENTER:
begin
TempRect.Top := TempRect.Top + trunc((OwnerLineHeight - FMinCellHeight) / 2 + 0.5);
TempRect.Bottom := TempRect.Bottom + trunc((OwnerLineHeight - FMinCellHeight) / 2 + 0.5);
end;
TEXT_ALIGN_BOTTOM:
begin
TempRect.Top := TempRect.Top + OwnerLineHeight - FMinCellHeight;
TempRect.Bottom := TempRect.Bottom + OwnerLineHeight - FMinCellHeight;
end;
end;
{ if Scale <> 100 then
begin
temprect.top := temprect.top * 100 div Scale;
temprect.bottom :=temprect.Bottom * 100 div Scale;
temprect.Left := temprect.left * 100 div Scale;
temprect.Right := temprect.Right * 100 div Scale;
end;
}
FTextRect := TempRect;
end
else
begin
TotalHeight := OwnerLineHeight;
for I := 0 to FCellsList.Count - 1 do
TotalHeight := TotalHeight + TReportCell(FCellsList[I]).OwnerLineHeight;
FCellRect.left := FCellLeft;
FCellRect.top := CellTop;
FCellRect.right := FCellRect.left + FCellWidth;
FCellRect.bottom := FCellRect.top + TotalHeight;
// 计算文本框的矩形
TempRect := FCellRect;
TempRect.left := TempRect.Left + FLeftMargin + 1;
TempRect.top := TempRect.top + FTopLineWidth + 1;
TempRect.right := TempRect.right - FLeftMargin;
TempRect.bottom := TempRect.top + FRequiredCellHeight - 2 - FTopLineWidth - FBottomLineWidth;
case FVertAlign of
TEXT_ALIGN_VCENTER:
begin
TempRect.Top := TempRect.Top + trunc((FCellRect.Bottom - FCellRect.Top - FRequiredCellHeight) / 2 + 0.5);
TempRect.Bottom := TempRect.Bottom + trunc((FCellRect.Bottom - FCellRect.Top - FRequiredCellHeight) / 2 + 0.5);
end;
TEXT_ALIGN_BOTTOM:
begin
TempRect.Top := TempRect.Top + FCellRect.Bottom - FCellRect.Top - FRequiredCellHeight;
TempRect.Bottom := TempRect.Bottom + FCellRect.Bottom - FCellRect.Top - FRequiredCellHeight;
end;
end;
{
if Scale <> 100 then
begin
temprect.top := temprect.top * 100 div Scale;
temprect.bottom :=temprect.Bottom * 100 div Scale;
temprect.Left := temprect.left * 100 div Scale;
temprect.Right := temprect.Right * 100 div Scale;
end;
}
FTextRect := TempRect;
end;
end;
procedure TReportCell.PaintCell(hPaintDC: HDC; bPrint: Boolean);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -