📄 easygrid.pas
字号:
// *****************************************************************************
//
// Note: This free package of source code can only be used for reference and
// learning purpose, you can distribute it freely, but please do not use
// it for profit sake.
//
// Special thanks to: RICHBBS (www.delphibbs.com)
//
// Huang Qian, Feb 2002
// Wuhan University
//
// *****************************************************************************
// 修改人: liuzhigang
// Email : lzg_0625@yahoo.com.cn
// 地址 : 四川.成都 (德阳)
//
//
// 修改人:韦明
//Email : ming_cn@163.com, ming_cn75@hotmail.com
//地址 :广西.南宁
//修改时间:2007.01
//*****************************************************************************
unit EasyGrid;
{$R *.RES}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,StdCtrls,
Mask, Menus, Dialogs, ClipBrd, Printers,DB,DBConsts,Variants,DBCtrls,DBGrids,
PreviewForm, CellProp,CellField,Preview,PageSetup;
const
MaxCustomExtents = MaxListSize;
MaxShortInt = High(ShortInt);
CellFixedPartSize = 76; // Cell 固定部分(非 string 类型部分)大小
ReservedSpace = 4096;
crExcel = 1001;
crZoomIn = 1002;
crZoomOut = 1003;
SegmentFlagValue = $FF;
resourcestring
VersionInfo = 'Discovery EasyGrid Version 1.0' + #26;
PrintJobName = 'EasyGrid 软件打印任务';
PleaseInputCorrectData = '请输入正确格式的数据。';
NoPrinterInstalled = '本机没有安装打印机。';
NoMoreThan256Columns = '网格列数不能超过256。';
InvalidNumber = '内容不合法,请写入正确的数值。';
InvalidDate = '内容不合法,请写入正确的日期。';
InvalidTime = '内容不合法,请写入正确的时间。';
CannotCutReadOnlyCells = '不能对含有只读单元格的区域进行剪切操作。';
CannotPasteCells = '无法粘贴信息,可能是由于以下原因,请更正后再次尝试。'+#13+#10+#13+#10+
'* 目标区域和现有的合并单元格冲突。'+#13+#10+
'* 目标区域含有只读的单元格。'+#13+#10+
'* 目标区域超过了表格的最大边界。';
CannotChangeMergedCells = '不能对合并单元格作部分改动。';
CannotOverlayReadOnlyCells = '不能覆盖目标区域内的只读单元格。';
MergedCellsMustBeSameSize = '此操作要求合并单元格都具有相同大小。';
CannotRemoveRightMostCells = '为了防止数据丢失,表格中最右侧的非空白单元格不能被移去。'+#13+#10+#13+#10+
'请清除该非空白单元格的内容,或将数据移到新的位置后再尝试。';
CannotRemoveBottomMostCells = '为了防止数据丢失,表格中最底部的非空白单元格不能被移去。'+#13+#10+#13+#10+
'请清除该非空白单元格的内容,或将数据移到新的位置后再尝试。';
DoYouWantDeleteMergedCells = '此操作将会导致一些合并单元格被拆散,是否继续?';
DiscardMultipleCellValues = '选定区域包含多重数值。合并到一个单元格后只能保留最左上角的数据。';
DoYouWantReplace = '是否替换目标区域的单元格内容?';
TitleTooBig = '标题区过大,请重新调整参数后再次尝试。';
BadFileInfo = '无法打开文件, 该文件可能已经损坏。';
NotAEasyGridFile = '该文件不是一个合法的报表文件。';
var
CF_EASYGRID: Word; // 剪贴板注册格式
type
EInvalidGridOperation = class(Exception);
{ Internal grid types }
TGetExtentsFunc = function(Index: Longint): Integer of object;
// EasyGrid 的参数
TEasyGridAxisDrawInfo = record
EffectiveLineWidth: Integer; // 行(列)线宽
TitleBoundary: Integer; // (行列)标题栏边界(像素单位)
FixedBoundary: Integer; // 固定(行列)边界(像素单位)
GridBoundary: Integer; // 有网格的部分的行(列)边界(像素单位)
GridExtent: Integer; // Grid 客户区大小(像素单位)
LastFullVisibleCell: Longint;// 最后一个完整可视Cell(Cell单位)
FullVisBoundary: Integer; // 最后一个完整可视Cell边界(像素单位)
FixedCellCount: Integer; // 固定行(列)个数
FirstGridCell: Integer; // 第一个非固定Cell号
GridCellCount: Integer; // 一行(列)Cell个数
GetExtent: TGetExtentsFunc; // 求某行(列)某数值(通用函数)
end;
// 水平与垂直参数
TEasyGridDrawInfo = record
Horz, Vert: TEasyGridAxisDrawInfo;
end;
TCustomEasyGrid = class;
// 数据格式
TDataStyle = (dsText,dsNumber,dsDate,dsTime,dsFormula);
//绑定的控件
TBindType = (bcNone,bcFieldLabel,bcField,bcPicture,bcCtrl);
{TFieldCtrl = (fcDBEdit,fcDBLookupComboBox,fcDBComboBox,
fcDBDateTime,fcDBCheckBox,fcDBLookupEditBtn);}
TEditStyle = (esSimple, esPickList,esLookup,esLookupForm);
PPointer = ^Pointer;
// EasyGrid 的状态
TEasyGridState = (gsNormal, gsSelecting, gsRowSizing, gsColSizing,
gsMoving, gsCopying, gsFilling);
// EasyGrid 的可选项
TEasyGridOption = (goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect, goDrawFocusSelected, goRowSizing, goColSizing, goEditing,
goTabs, goRowSelect, goAlwaysShowEditor, goThumbTracking,goCancelOnExit);
TEasyGridOptions = set of TEasyGridOption;
TEasyGridDrawState = set of (gdSelected, gdFocused, gdFixed, gdTitled);
TEasyGridScrollDirection = set of (sdLeft, sdRight, sdUp, sdDown);
// Cell 属性名
TPropertyName = (pnDataStyle, pnAlignMode, pnCellLock,pnReadOnly,pnAutoWordBreak,
pnShowForeText, pnDrawTop, pnDrawLeft, pnDrawRight, pnDrawBottom,
pnAllowNegative, pnTrailingZero, pnZeroNull, pnThousandSep, pnMaxLength,
pnIntLength, pnDecLength, pnLineWidth, pnPenStyle, pnNumber, pnColor,
pnFontSize, pnFontColor, pnFontStyle, pnFontName,
pnForeText, pnBackText,pnFeildName,pnDispName);
// 填充方式
TFillStyle = (fsNone, fsHorzFill, fsVertFill);
// 划线方式
TLineStyle = (lsSolid, lsDashed);
// 对齐方式
TAlignMode = (taTopLeft, taTop, taTopRight,
taLeft, taCenter, taRight,
taBottomLeft, taBottom, taBottomRight);
// 弹出菜单的标识
TMenuItemTag = (mtCut, mtCopy, mtPaste,
mtInsertCellRight, mtInsertCellDown, mtInsertRow, mtInsertCol,
mtDeleteCellRight, mtDeleteCellDown, mtDeleteRow, mtDeleteCol,
mtClearCells, mtSetCellProp,mtSetCellField,
mtSetCellNull,mtSetCellPicture,mtSetCellCtrl);
TIntArray = array[0..MaxCustomExtents] of Integer;
PIntArray = ^TIntArray;
TCharArray = array of Char;
PCharArray = ^TCharArray;
TDynaIntArray = array of Integer;
PDynaIntArray = ^TDynaIntArray;
// 网格数据结构
TCellInfo = record
// *************************************************************************
BindType : TBindType; // 关联类型
EditStyle : TEditStyle; // 编辑风格
TmpNull : Boolean; //
DataStyle : TDataStyle; // 数据格式
AlignMode : TAlignMode; // 对齐方式
Merge : TRect; // 合并区坐标(Grid 坐标)
CellLock:Boolean; // 单元格锁定,不能得到焦点。
ReadOnly : Boolean; // 单元格是否可编辑
AutoWordBreak : Boolean; // 文字自动折行
ShowForeText : Boolean; // 显示控制(Default True)
DrawTop : Boolean; // 画顶线
DrawLeft : Boolean; // 画左线
DrawBottom : Boolean; // 画底线
DrawRight : Boolean; // 画右线
AllowNegative : Boolean; // 是否允许输入负数
TrailingZero : Boolean; // 是否在小数后面补 0
ZeroNull : Boolean; // 输入数值 0 时是否当作空串处理
ThousandSep : Boolean; // 是否有千分号
MaxLength : Integer; // 最大编辑长度
IntLength : Integer; // 整数部分最大长度
DecLength : Integer; // 小数部分最大长度
LineWidth : Integer; // 线宽
PenStyle : TPenStyle; // 线形
Number : Integer; // 存储数值
Color : TColor; // 填充的颜色
FontSize: Integer; // 字体大小
FontColor: TColor; // 字体颜色
FontStyle: TFontStyles; // 字体风格
// 以上数据共计 76 个字节(考虑到 Delphi 的四字节对齐方式)
// *************************************************************************
FontName : string; // 字体名字
ForeText : string; // 前台 Text
BackText : string; // 后台 Text
///--------------Add By liuzhigang In 2004.07.30-------------------
FieldName: String;
DispField: String;
end;
PCellInfo = ^TCellInfo;
// 用 TList 管理的一列单元格信息
TColCellInfoList = class(TList)
public
constructor Create(AGrid:TCustomEasyGrid;ACol,ARowCount:Integer);
procedure Clear; override;
end;
// 用 TList 管理的所有单元格信息(用一个 TList 把所有的列串起来)
TCells = class(TList)
private
FGrid : TCustomEasyGrid;
public
constructor Create(AGrid:TCustomEasyGrid;AColCount,ARowCount:Integer);
procedure Clear; override;
end;
TGridCoord = record
X: Longint;
Y: Longint;
end;
TGridRect = record
case Integer of
0: (Left, Top, Right, Bottom: Longint);
1: (TopLeft, BottomRight: TGridCoord);
end;
PGridRect = ^TGridRect;
// EasyGrid 页面信息
TEasyGridDetailPageInfo = record
MonoColored: Boolean; // 单色/彩色打印
HorzCenter, VertCenter: Boolean; // 水平、垂直居中
HorzSplit: Boolean; // 横向/纵向分页
PrintGridLine: Boolean; // 是否打印网格线
PrintColTitle, PrintRowTitle: Boolean; // 是否打印行号列标
PrintFixedCols, PrintFixedRows: Boolean; // 是否在每页打印固定行列
PrintConjunction: Boolean; // 是否打印承接词(如: 承前页、过次页)
TopConjunctionText, BottomConjunctionText: string[10]; // 承接词内容
Reserved: array [0..255] of Char; // 保留空间
end;
// 网格的全部打印信息
TEasyGridPageInfo = class(TObject)
public
DetailPageInfo: TEasyGridDetailPageInfo;
CommonPageInfo: TCommonPageInfo;
constructor Create;
destructor Destroy; override;
procedure LoadFromStream(AFileStream: TStream);
procedure SaveToStream(AFileStream: TStream);
procedure LoadFromFile(FileName: string);
procedure SaveToFile(FileName: string);
end;
TPageSectionDrawInfo = record
StartPos: TPoint;
Size: TSize;
Range: TGridRect;
Included: Boolean;
end;
TPageDrawInfo = record
Index: Integer;
SplitCoord: TPoint;
Section: array[1..9] of TPageSectionDrawInfo;
TopConjunction, BottomConjunction: TPageSectionDrawInfo;
end;
TPageDrawInfoList = array of TPageDrawInfo;
PPageDrawInfoList = ^TPageDrawInfoList;
TSelectCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
var CanSelect: Boolean) of object;
TDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
Rect: TRect; State: TEasyGridDrawState) of object;
TGetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; var Value: string) of object;
TSetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; const Value: string) of object;
TSetCellTextEvent = procedure (Sender: TObject; ACol, ARow: Longint; var Value: string) of object;
TBeforeSetCellPropEvent = procedure (Sender: TObject; Range: TRect; var CanSetCellProp: Boolean) of object;
TAfterSetCellPropEvent = procedure (Sender: TObject; Range: TRect) of object;
TInsertColEvent = procedure (Sender: TObject; InsertRect: TRect) of object;
TInsertRowEvent = procedure (Sender: TObject; InsertRect: TRect) of object;
TDeleteColEvent = procedure (Sender: TObject; DeleteRect: TRect) of object;
TDeleteRowEvent = procedure (Sender: TObject; DeleteRect: TRect) of object;
TInsertCellRightEvent = procedure (Sender: TObject; InsertRect: TRect) of object;
TInsertCellDownEvent = procedure (Sender: TObject; InsertRect: TRect) of object;
TDeleteCellRightEvent = procedure (Sender: TObject; DeleteRect: TRect) of object;
TDeleteCellDownEvent = procedure (Sender: TObject; DeleteRect: TRect) of object;
TPasteCellsEvent = procedure (Sender: TObject; SrcTopLeft, SrcSize: TPoint; DestRect: TRect) of object;
TCutCellsEvent = procedure (Sender: TObject; DestRect: TRect) of object;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -