cxlookupgrid.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 2,076 行 · 第 1/5 页
PAS
2,076 行
Include(ARowViewInfo.Borders, bRight);
end
else
Include(ACellViewInfo.Borders, bRight);
end;
end;
if (GridLines in [glBoth, glHorizontal]) or
((GridLines = glVertical) and (ARowIndex = (RowCount - 1)) and ExistEmptyArea) then
begin
Inc(ARowViewInfo.Bounds.Bottom, GetGridLineWidth);
Include(ARowViewInfo.Borders, bBottom);
end;
RowsRect.Bottom := ARowViewInfo.Bounds.Bottom;
ATop := RowsRect.Bottom;
CalculateCells(ARowViewInfo);
end;
var
I, ATop: Integer;
begin
FRows.Clear;
SetRectEmpty(RowsRect);
SetRectEmpty(VisibleRowsRect);
PartialVisibleRowCount := 0;
VisibleRowCount := 0;
if (HeadersRect.Right - HeadersRect.Left) > 0 then
begin
FRowMinHeight := CalcRowMinHeight;
RowsRect := Rect(HeadersRect.Left, HeadersRect.Bottom, HeadersRect.Right, HeadersRect.Bottom);
VisibleRowsRect := RowsRect;
ATop := RowsRect.Top;
if TopRowIndexCalculation = ticBackward then
begin
for I := TopRowIndex downto 0 do
begin
CalcCells(I, ATop);
Inc(PartialVisibleRowCount);
if RowsRect.Bottom <= ClientBounds.Bottom then
begin
Inc(VisibleRowCount);
VisibleRowsRect.Bottom := RowsRect.Bottom;
end
else
Break;
end;
end
else
begin
for I := TopRowIndex to RowCount - 1 do
begin
CalcCells(I, ATop);
Inc(PartialVisibleRowCount);
if RowsRect.Bottom <= ClientBounds.Bottom then
begin
Inc(VisibleRowCount);
VisibleRowsRect.Bottom := RowsRect.Bottom;
end
else
Break;
end;
end;
if (PartialVisibleRowCount > 0) and (VisibleRowCount = 0) then
VisibleRowCount := 1;
end;
end;
procedure TcxLookupGridViewInfo.Calculate;
begin
BorderSize := FGrid.GetBorderSize;
CalcColumns;
CalcRows;
CalcEmptyAreas;
end;
function TcxLookupGridViewInfo.CheckTopRowIndex(ANewTopIndex: Integer): Integer;
begin
TopRowIndexCalculation := ticForward;
try
FInternalTopRowIndex := ANewTopIndex;
Calculate;
if not IsRectEmpty(EmptyRectBottom) then
begin
TopRowIndexCalculation := ticBackward;
try
FInternalTopRowIndex := ANewTopIndex + VisibleRowCount - 1;
if FInternalTopRowIndex > (RowCount - 1) then
FInternalTopRowIndex := RowCount - 1;
Calculate;
ANewTopIndex := FInternalTopRowIndex - VisibleRowCount + 1;
finally
TopRowIndexCalculation := ticNone;
end;
end;
finally
TopRowIndexCalculation := ticNone;
end;
Result := ANewTopIndex;
end;
function TcxLookupGridViewInfo.AddRow(ARowIndex: Integer; const AInitBounds: TRect): TcxLookupGridRowViewInfo;
begin
Result := TcxLookupGridRowViewInfo.Create;
FRows.Add(Result);
Result.RowIndex := ARowIndex;
Result.RecordIndex := Grid.FDataController.GetRowInfo(ARowIndex).RecordIndex;
Result.IsFocused := ARowIndex = Grid.FocusedRowIndex;
Result.Bounds := AInitBounds;
end;
function TcxLookupGridViewInfo.CalcCellMinHeight(AIndex: Integer): Integer;
var
AEditViewData: TcxCustomEditViewData;
begin
AEditViewData := CreateEditViewData(Columns[AIndex], Grid.Columns[AIndex]);
try
Result := 2 * cxGridEditOffset +
AEditViewData.GetEditSize(Canvas, Null, DefaultcxEditSizeProperties).cy;
finally
DestroyEditViewData(Columns[AIndex], Grid.Columns[AIndex]);
end;
end;
function TcxLookupGridViewInfo.CalcRowMinHeight: Integer;
var
I, ACellHeight: Integer;
begin
Result := 0;
for I := 0 to Grid.Columns.Count - 1 do
begin
ACellHeight := CalcCellMinHeight(I);
if ACellHeight > Result then
Result := ACellHeight;
end;
end;
procedure TcxLookupGridViewInfo.CalculateCells(ARowViewInfo: TcxLookupGridRowViewInfo);
procedure CalcCell(ACellViewInfo: TcxLookupGridCellViewInfo);
var
AColor, AFontColor: TColor;
ADisplayValue: Variant;
AEditViewData: TcxCustomEditViewData;
AEditViewInfo: TcxCustomEditViewInfo;
ARect: TRect;
ASelected: Boolean;
begin
// Style
ASelected := Grid.DataController.IsRowSelected(ARowViewInfo.RowIndex);
CalcCellColors(ASelected and ARowViewInfo.IsFocused,
ASelected and ACellViewInfo.IsFocused, AColor, AFontColor);
with Columns[ACellViewInfo.Index].Style do
begin
StyleData.Color := AColor;
StyleData.FontColor := AFontColor;
end;
// Calculate
AEditViewInfo := ACellViewInfo.CreateEditViewInfo(Grid.Columns[ACellViewInfo.Index].Properties);
AEditViewData := CreateEditViewData(Columns[ACellViewInfo.Index], Grid.Columns[ACellViewInfo.Index]);
try
// Value
if Grid.Columns[ACellViewInfo.Index].Properties.GetEditValueSource(False) = evsValue then
ADisplayValue := Grid.FDataController.Values[ARowViewInfo.RecordIndex, ACellViewInfo.Index]
else
ADisplayValue := Grid.FDataController.DisplayTexts[ARowViewInfo.RecordIndex, ACellViewInfo.Index];
// Calculate
ARect := ACellViewInfo.ContentBounds;
InflateRect(ARect, -cxGridEditOffset, -cxGridEditOffset);
AEditViewData.EditValueToDrawValue(Canvas, ADisplayValue, AEditViewInfo);
AEditViewData.Calculate(Canvas, ARect, Point(-1, -1), cxmbNone, [], AEditViewInfo, False);
finally
DestroyEditViewData(Columns[ACellViewInfo.Index], Grid.Columns[ACellViewInfo.Index]);
end;
end;
var
I: Integer;
begin
for I := 0 to ARowViewInfo.Count - 1 do
CalcCell(ARowViewInfo[I]);
end;
function TcxLookupGridViewInfo.GetCellHeight(ARowIndex, AColumnIndex: Integer): Integer;
begin
Result := FRowMinHeight;
end;
function TcxLookupGridViewInfo.GetContentColor: TColor;
begin
Result := Grid.Color;
end;
function TcxLookupGridViewInfo.GetContentFont: TFont;
begin
Result := Grid.Font;
end;
function TcxLookupGridViewInfo.GetContentFontColor: TColor;
begin
Result := GetContentFont.Color;
end;
procedure TcxLookupGridViewInfo.CreateEditStyle(AColumnViewInfo: TcxLookupGridColumnViewInfo;
AColumn: TcxLookupGridColumn);
begin
AColumnViewInfo.CreateEditStyle(AColumn.Properties);
with AColumnViewInfo.Style do
StyleData.Font := AColumn.GetContentFont;
end;
function TcxLookupGridViewInfo.CreateEditViewData(AColumnViewInfo: TcxLookupGridColumnViewInfo;
AColumn: TcxLookupGridColumn): TcxCustomEditViewData;
begin
with AColumn.Properties do
begin
LockUpdate(True);
try
IDefaultValuesProvider := AColumn.DefaultValuesProvider;
finally
LockUpdate(False);
end;
end;
Result := AColumnViewInfo.CreateEditViewData(AColumn.Properties);
end;
procedure TcxLookupGridViewInfo.DestroyEditViewData(AColumnViewInfo: TcxLookupGridColumnViewInfo;
AColumn: TcxLookupGridColumn);
begin
AColumnViewInfo.DestroyEditViewData;
with AColumn.Properties do
begin
LockUpdate(True);
try
IDefaultValuesProvider := nil;
finally
LockUpdate(False);
end;
end;
end;
function TcxLookupGridViewInfo.GetGridColor: TColor;
begin
Result := clBtnFace; // TODO: style
end;
function TcxLookupGridViewInfo.GetGridLineWidth: Integer;
begin
Result := 1;
end;
function TcxLookupGridViewInfo.GetHeaderColor: TColor;
begin
Result := Grid.Painter.LFPainterClass.DefaultHeaderColor;
end;
function TcxLookupGridViewInfo.GetHeaderFont: TFont;
begin
Result := Grid.Font; // TODO: style
end;
function TcxLookupGridViewInfo.GetHeaderFontColor: TColor;
begin
Result := Grid.Painter.LFPainterClass.DefaultHeaderTextColor;
end;
function TcxLookupGridViewInfo.GetSelectedColor: TColor;
begin
Result := Grid.Painter.LFPainterClass.DefaultSelectionColor; // clHighlight;
end;
function TcxLookupGridViewInfo.GetSelectedFontColor: TColor;
begin
Result := Grid.Painter.LFPainterClass.DefaultSelectionTextColor; // clHighlightText;
end;
function TcxLookupGridViewInfo.GetHeaderHeight: Integer;
begin
Result := Grid.Painter.LFPainterClass.HeaderHeight(Canvas.FontHeight(GetHeaderFont));
end;
function TcxLookupGridViewInfo.GetBounds: TRect;
begin
Result := FGrid.Bounds;
end;
function TcxLookupGridViewInfo.GetCanvas: TcxCanvas;
begin
Result := FGrid.Painter.Canvas;
end;
function TcxLookupGridViewInfo.GetClientBounds: TRect;
begin
Result := FGrid.ClientBounds;
end;
function TcxLookupGridViewInfo.GetEmptyAreaColor: TColor;
begin
Result := FGrid.Color;
end;
function TcxLookupGridViewInfo.GetGridLines: TcxGridLines;
begin
Result := FGrid.Options.GridLines;
end;
function TcxLookupGridViewInfo.GetRowCount: Integer;
begin
Result := Grid.RowCount;
end;
function TcxLookupGridViewInfo.GetRowHeight: Integer;
begin
// TODO: RowAutoHeight
Result := FRowMinHeight;
if (Grid.Options.GridLines in [glBoth, glHorizontal]) then
Inc(Result, GetGridLineWidth);
end;
function TcxLookupGridViewInfo.GetTopRowIndex: Integer;
begin
if TopRowIndexCalculation <> ticNone then
Result := FInternalTopRowIndex
else
Result := Grid.TopRowIndex;
end;
{ TcxLookupGridPainter }
constructor TcxLookupGridPainter.Create(AGrid: TcxCustomLookupGrid);
begin
inherited Create;
FGrid := AGrid;
end;
destructor TcxLookupGridPainter.Destroy;
begin
FreeAndNil(FCanvas);
inherited Destroy;
end;
procedure TcxLookupGridPainter.Invalidate;
begin
Grid.Invalidate;
end;
procedure TcxLookupGridPainter.Paint;
begin
DrawBorder;
DrawContent;
end;
procedure TcxLookupGridPainter.DrawBorder;
begin
with ViewInfo do
if BorderSize <> 0 then
begin
LFPainterClass.DrawBorder(Canvas, Bounds);
Canvas.IntersectClipRect(ClientBounds);
end;
end;
procedure TcxLookupGridPainter.DrawContent;
begin
DrawHeaders;
DrawEmptyArea;
DrawRows;
end;
procedure TcxLookupGridPainter.DrawCell(ACellViewInfo: TcxLookupGridCellViewInfo);
begin
ACellViewInfo.EditViewInfo.Paint(Canvas);
Canvas.FrameRect(ACellViewInfo.ContentBounds, ACellViewInfo.EditViewInfo.BackgroundColor,
cxGridEditOffset);
Canvas.FrameRect(ACellViewInfo.Bounds, ViewInfo.GetGridColor,
ViewInfo.GetGridLineWidth, ACellViewInfo.Borders);
end;
procedure TcxLookupGridPainter.DrawEmptyArea;
begin
with ViewInfo do
if not IsRectEmpty(EmptyRectBottom) or not IsRectEmpty(EmptyRectRight) then
begin
Canvas.Brush.Color := EmptyAreaColor;
if not IsRectEmpty(EmptyRectBottom) then
Canvas.FillRect(EmptyRectBottom);
if not IsRectEmpty(EmptyRectRight) then
Canvas.FillRect(EmptyRectRight);
end;
end;
procedure TcxLookupGridPainter.DrawHeaders;
var
R, ASortRect, ATextRect: TRect;
ASortOrder: TcxDataSortOrder;
I: Integer;
begin
with ViewInfo do
if not IsRectEmpty(HeadersRect) then
begin
for I := 0 to Columns.Count - 1 do
begin
R := Columns[I].Bounds;
ATextRect := LFPainterClass.HeaderContentBounds(R, Columns[I].Borders);
InflateRect(ATextRect, -cxHeaderTextOffset, -cxHeaderTextOffset);
ASortOrder := Columns[I].SortOrder;
if ASortOrder <> soNone then
begin
ASortRect := Rect(ATextRect.Right - LFPainterClass.SortingMarkAreaSize.X, ATextRect.Top,
ATextRect.Right, ATextRect.Bottom);
ATextRect.Right := ASortRect.Left;
if ATextRect.Right < ATextRect.Left then
ATextRect.Right := ATextRect.Left;
end;
LFPainterClass.DrawHeader(Canvas, R, ATextRect, Columns[I].Neighbors, Columns[I].Borders,
cxbsNormal, Columns[I].Alignment, vaCenter, False, True, Columns[I].Text,
GetHeaderFont, GetHeaderFontColor, GetHeaderColor);
if ASortOrder <> soNone then
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?