📄 rm_grid.pas
字号:
function CalcMaxRange(aDestRect: TRect): TRect; // 计算新的选择范围
property GridHeight: Integer read GetGridHeight;
property GridWidth: Integer read GetGridWidth;
property HitTest: TPoint read FHitTest;
property LeftCol: Longint read GetLeftCol write SetLeftCol;
property TopRow: Longint read GetTopRow write SetTopRow;
property ParentColor default False;
property VisibleColCount: Integer read GetVisibleColCount;
property VisibleRowCount: Integer read GetVisibleRowCount;
property InLoadSaveMode: Boolean read FInLoadSaveMode write FInLoadSaveMode;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure CreateViewsName;
function GetCellInfo(ACol, Arow: Integer): TRMCellinfo;
procedure InvalidateGrid;
procedure InvalidateRect(ARect: TRect);
procedure InvalidateCell(ACol, ARow: Longint);
function MouseCoord(X, Y: Integer): TPoint;
procedure MergeCell(aFirstCol, aFirstRow, aEndCol, aEndRow: Integer);
procedure MergeSelection;
procedure SplitCell(aFirstCol, aFirstRow, aEndCol, aEndRow: Integer);
procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longint);
function GetCellRect(ACell: TRMCellInfo): TRect;
procedure FreeEditor;
procedure InsertColumn(aCol: Integer; aCreateName: Boolean);
procedure InsertRow(aRow: Integer; aCreateName: Boolean);
procedure DeleteColumn(aCol: Integer; aRefresh: Boolean); virtual;
procedure DeleteRow(ARow: Integer; aRefresh: Boolean); virtual;
procedure InsertCellRight(aInsertRect: TRect); // 向右插入一个网格
procedure InsertCellDown(aInsertRect: TRect); // 向下插入一个网格
procedure DeleteCellRight(aDeleteRect: TRect); // 向右删除一个网格
procedure DeleteCellDown(aDeleteRect: TRect); // 向下删除一个网格
procedure CopyCells(aDestCopyRect: TRect); // 拷贝一个范围内的 Cells 内容到剪贴板中
procedure CutCells(aDestCutRect: TRect); // 拷贝一个范围内的 Cells 内容到剪贴板中并清除 Cells 内容
procedure PasteCells(aDestPasteCoord: TPoint); // 从剪贴板中粘贴 Cells 内容到一个范围内
function CanCut: Boolean;
function CanCopy: Boolean;
function CanPaste: Boolean;
procedure LoadFromFile(aFileName: string);
procedure SaveToFile(aFileName: string);
procedure LoadFromStream(aStream: TStream);
procedure SaveToStream(aStream: TStream);
property InplaceEditor: TRMInplaceEdit read FInplaceEdit;
property AutoCreateName: Boolean read FAutoCreateName write FAutoCreateName;
property HeaderClick: Boolean read FHeaderClick write FHeaderClick;
property Selection: TRect read GetSelection write SetSelection;
property Cells[ACol, ARow: Integer]: TRMCellInfo read GetCell;
property Merges[ACol, ARow: Integer]: TRect read GetMerges;
property ColWidths[Index: Longint]: Integer read GetColWidths write SetColWidths;
property mmColWidths[Index: Longint]: Integer read GetmmColWidths write SetmmColWidths;
property RowHeights[Index: Longint]: Integer read GetRowHeights write SetRowHeights;
property mmRowHeights[Index: Longint]: Integer read GetmmRowHeights write SetmmRowHeights;
property Col: Longint read GetCol write SetCol;
property Row: Longint read GetRow write SetRow;
property AutoDraw: Boolean read FAutoDraw write FAutoDraw;
property DrawPicture: Boolean read FDrawPicture write FDrawPicture;
property ParentReport: TRMReport read FParentReport write SetParentReport;
property ParentPage: TRMReportPage read FParentPage write FParentPage;
property ScrollBars: TScrollStyle read FScrollBars write FScrollBars;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property OnAfterInsertRow: TRMAfterInsertRowEvent read FOnAfterInsertRow write FOnAfterInsertRow;
property OnAfterDeleteRow: TRMAfterDeleteRowEvent read FOnAfterDeleteRow write FOnAfterDeleteRow;
property OnAfterChangeRowCount: TRMAfterChangeRowCountEvent read FOnAfterChangeRowCount write FOnAfterChangeRowCount;
property OnBeginSizingCell: TNotifyEvent read FOnBeginSizingCell write FOnBeginSizingCell;
property OnBeforeChangeCell: TRMBeforeChangeCellEvent read FOnBeforeChangeCell write FOnBeforeChangeCell;
property OnDropDownField: TRMDropDownFieldEvent read FOnDropDownField write FOnDropDownField;
property OnDropDownFieldClick: TRMDropDownFieldClickEvent read FOnDropDownFieldClick write FOnDropDownFieldClick;
property CurrentCol: Integer read FCurrentCol write FCurrentCol;
property CurrentRow: Integer read FCurrentRow write FCurrentRow;
property ComAdapter: IUnknown read GetComAdapter write FComAdapter;
published
property FixedCols: Integer read FFixedCols write FFixedCols;
property FixedRows: Integer read FFixedRows write FFixedRows;
property ColCount: Longint read FColCount write SetColCount;
property RowCount: Longint read FRowCount write SetRowCount;
property DefaultDrawing: Boolean read FDefaultDrawing;
property Options: TRMGridOptions read FOptions;
property DefaultColWidth: Integer read GetDefaultColWidth write SetDefaultColWidth;
property DefaultRowHeight: Integer read GetDefaultRowHeight write SetDefaultRowHeight;
property FixedColor: TColor read FFixedColor write SetFixedColor;
property Color default clWindow;
property TabStop default True;
property PopupMenu;
property Font;
property OnSelectCell: TRMSelectCellEvent read FOnSelectCell write FOnSelectCell;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnRowHeaderClick: TRMFRowHeaderClickEvent read FOnRowHeaderClick write FOnRowHeaderClick;
property OnRowHeaderDblClick: TNotifyEvent read FOnRowHeaderDblClick write FOnRowHeaderDblClick;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnEnter;
end;
var
CF_RMGridCopyFormat: Word;
implementation
uses Math, Consts, RM_Utils, RM_Const, RM_Const1;
type
THackView = class(TRMView);
THackMemoView = class(TRMCustomMemoView);
THackPage = class(TRMCustomPage);
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{ TRMCellInfo }
constructor TRMCellInfo.Create;
begin
inherited Create;
FFont := TFont.Create;
FView := RMCreateObject(rmgtMemo, '');
// FView.TopFrame.Visible := True;
// FView.LeftFrame.Visible := True;
// FView.BottomFrame.Visible := True;
// FView.RightFrame.Visible := True;
end;
destructor TRMCellInfo.Destroy;
begin
FFont.Free;
FView.Free;
inherited Destroy;
end;
function TRMCellInfo.CanEdit: Boolean;
begin
Result := FView is TRMCustomMemoView;
end;
procedure TRMCellInfo.Assign(Source: TPersistent);
begin
if Source is TRMCellInfo then
begin
FStartCol := TRMCellInfo(Source).StartCol;
FStartRow := TRMCellInfo(Source).StartRow;
FEndCol := TRMCellInfo(Source).EndCol;
FEndRow := TRMCellInfo(Source).EndRow;
FMutilCell := TRMCellInfo(Source).MutilCell;
FFont.Assign(TRMCellInfo(Source).Font);
FAutoWordBreak := TRMCellInfo(Source).FAutoWordBreak;
FHorizAlign := TRMCellInfo(Source).FHorizAlign;
FVertAlign := TRMCellInfo(Source).FVertAlign;
ReCreateView(TRMCellInfo(Source).FView.ObjectType, TRMCellInfo(Source).FView.ClassName);
FView.Assign(TRMCellInfo(Source).FView);
ParentReport := TRMCellInfo(Source).ParentReport;
end;
end;
procedure TRMCellInfo.AssignFromCell(Source: TRMCellInfo);
begin
FStartCol := Source.StartCol;
FStartRow := Source.StartRow;
FEndCol := Source.EndCol;
FEndRow := Source.EndRow;
FMutilCell := Source.MutilCell;
end;
procedure TRMCellInfo.ReCreateView(aObjectType: Byte; const aClassName: string);
var
t: TRMView;
begin
if (FView.ObjectType <> rmgtAddIn) and (FView.ObjectType = aObjectType) then Exit;
if (FView.ObjectType = rmgtAddIn) and (AnsiCompareText(FView.ClassName, aClassName) = 0) then Exit;
t := RMCreateObject(aObjectType, aClassName);
t.LeftFrame.Assign(FView.LeftFrame);
t.RightFrame.Assign(FView.RightFrame);
t.TopFrame.Assign(FView.TopFrame);
t.BottomFrame.Assign(View.BottomFrame);
t.FillColor := FView.FillColor;
t.Restrictions := FView.Restrictions;
if (t is TRMCustomMemoView) and (FView is TRMCustomMemoView) then
begin
TRMCustomMemoView(t).Font.Assign(TRMCustomMemoView(FView).Font);
TRMCustomMemoView(t).GapLeft := TRMCustomMemoView(FView).GapLeft;
TRMCustomMemoView(t).GapTop := TRMCustomMemoView(FView).GapTop;
TRMCustomMemoView(t).LineSpacing := TRMCustomMemoView(FView).LineSpacing;
TRMCustomMemoView(t).CharacterSpacing := TRMCustomMemoView(FView).CharacterSpacing;
THackView(t).FFlags := THackView(FView).FFlags;
TRMCustomMemoView(t).HAlign := TRMCustomMemoView(FView).HAlign;
TRMCustomMemoView(t).VAlign := TRMCustomMemoView(FView).VAlign;
THackMemoView(t).FDisplayFormat := TRMCustomMemoView(FView).DisplayFormat;
THackMemoView(t).FormatFlag := THackMemoView(FView).FormatFlag;
t.Memo.Assign(FView.Memo);
end;
FView.Free;
FView := t;
ParentReport := ParentReport;
end;
function TRMCellInfo.GetText: string;
var
i: Integer;
begin
if View is TRMCustomMemoView then
begin
Result := '';
for i := 0 to FView.Memo.Count - 1 do
begin
if i > 0 then
Result := Result + #13#10;
Result := Result + FView.Memo[i];
end;
end
else
Result := THackView(View).GetViewCommon;
end;
procedure TRMCellInfo.SetText(const Value: string);
begin
if View is TRMCustomMemoView then
TRMCustomMemoView(View).Memo.Text := Value;
end;
function TRMCellInfo.GetFillColor: TColor;
begin
Result := FView.FillColor;
end;
procedure TRMCellInfo.SetFillColor(Value: TColor);
begin
FView.FillColor := Value;
end;
function TRMCellInfo.GetFont: TFont;
begin
if View is TRMCustomMemoView then
Result := TRMCustomMemoView(View).Font
else
Result := FFont;
end;
procedure TRMCellInfo.SetFont(Value: TFont);
begin
if View is TRMCustomMemoView then
TRMCustomMemoView(View).Font.Assign(Value);
FFont.Assign(Value);
end;
function TRMCellInfo.GetAutoWordBreak: Boolean;
begin
if View is TRMCustomMemoView then
Result := THackMemoView(View).Wordwrap
else
Result := FAutowordBreak;
end;
procedure TRMCellInfo.SetAutowordBreak(Value: Boolean);
begin
FAutowordBreak := Value;
if View is TRMCustomMemoView then
THackMemoView(View).Wordwrap := Value;
end;
function TRMCellInfo.GetHorizAlign: TRMHAlign;
begin
if View is TRMCustomMemoView then
Result := TRMCustomMemoView(View).HAlign
else
Result := FHorizAlign;
end;
procedure TRMCellInfo.SetHorizAlign(Value: TRMHAlign);
begin
FHorizAlign := Value;
if View is TRMCustomMemoView then
TRMCustomMemoView(View).HAlign := Value;
end;
function TRMCellInfo.GetVertAlign: TRMVAlign;
begin
if View is TRMCustomMemoView then
Result := TRMCustomMemoView(View).VAlign
else
Result := FVertAlign;
end;
procedure TRMCellInfo.SetVertAlign(Value: TRMVAlign);
begin
FVertAlign := Value;
if View is TRMCustomMemoView then
TRMCustomMemoView(View).VAlign := Value;
end;
procedure TRMCellInfo.SetParentReport(Value: TRMReport);
begin
FParentReport := Value;
if FView <> nil then
THackView(FView).ParentReport := Value;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
constructor TRMRowCell.Create(ARow, AColCount: Integer; AGrid: TRMGridEx);
var
i: Integer;
liCellInfo: TRMCellInfo;
begin
inherited Create;
FList := TList.Create;
for i := 0 to AColCount - 1 do
begin
liCellInfo := TRMCellInfo.Create;
AGrid.InitCell(AGrid, liCellInfo, i, ARow);
FList.Add(liCellInfo);
liCellInfo.ParentReport := aGrid.ParentReport;
end;
end;
destructor TRMRowCell.Destroy;
begin
Clear;
FList.Free;
inherited Destroy;
end;
procedure TRMRowCell.Clear;
begin
while FList.Count > 0 do
begin
TRMCellInfo(FList[0]).Free;
FList.Delete(0);
end;
end;
procedure TRMRowCell.Add(ARow, ACol: Integer; AGrid: TRMGridEx);
var
liCellInfo: TRMCellInfo;
begin
liCellInfo := TRMCellInfo.Create;
AGrid.InitCell(AGrid, liCellInfo, ACol, ARow);
FList.Add(liCellInfo);
liCellInfo.ParentReport := aGrid.ParentReport;
end;
procedure TRMRowCell.Delete(Index: Integer);
begin
TRMCellInfo(FList[Index]).Free;
FList.Delete(Index);
end;
function TRMRowCell.GetItem(Index: Integer): TRMCellInfo;
begin
Result := TRMCellInfo(FList[Index]);
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
constructor TRMCells.Create(AColCount, ARowCount: Integer; AGrid: TRMGridEx);
var
i: Integer;
liRowCell: TRMRowCell;
begin
inherited Create;
FList := TList.Create;
FGrid := AGrid;
for i := 0 to ARowCount - 1 do
begin
liRowCell := TRMRowCell.Create(i, AColCount, AGrid);
FList.Add(liRowCell);
end;
end;
destructor TRMCells.Destroy;
begin
Clear;
FList.Free;
inherited Destroy;
end;
procedure TRMCells.Clear;
begin
while FList.Count > 0 do
begin
TRMRowCell(FList[0]).Free;
FList.Delete(0);
end;
end;
function TRMCells.GetItem(Index: Integer): TRMRowCell;
begin
Result := TRMRowCell(FList[Index]);
end;
procedure TRMCells.Insert(AIndex: Integer);
var
liRowCell: TRMRowCell;
begin
liRowCell := TRMRowCell.Create(AIndex, FGrid.ColCount, FGrid);
FList.Insert(AIndex, liRowCell);
end;
procedure TRMCells.Add(AIndex: Integer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -