?? gridseh.pas
字號:
function BoxRect(ALeft, ATop, ARight, ABottom: Longint): TRect;
procedure DoExit; override;
function CellRect(ACol, ARow: Longint): TRect;
function CanEditAcceptKey(Key: Char): Boolean; dynamic;
function CanGridAcceptKey(Key: Word; Shift: TShiftState): Boolean; dynamic;
function CanEditModify: Boolean; dynamic;
function CanEditShow: Boolean; virtual;
function CheckCellMouseClick(var Message: TWMLButtonUp): Boolean; virtual;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function PaintLocked: Boolean;
procedure FocusCell(ACol, ARow: Longint; MoveAnchor: Boolean);
procedure FlatChanged; virtual;
function GetEditText(ACol, ARow: Longint): string; dynamic;
procedure SetEditText(ACol, ARow: Longint; const Value: string); dynamic;
function GetEditLimit: Integer; dynamic;
function GetEditMask(ACol, ARow: Longint): string; dynamic;
function GetEditStyle(ACol, ARow: Longint): TEditStyle; dynamic;
function GetGridWidth: Integer;
function GetGridHeight: Integer;
procedure HideEdit;
procedure HideEditor;
procedure ShowEditor;
procedure ShowEditorChar(Ch: Char);
procedure InvalidateEditor;
procedure InvalidateGrid;
procedure MoveColumn(FromIndex, ToIndex: Longint);
procedure ColumnMoved(FromIndex, ToIndex: Longint); dynamic;
procedure MoveRow(FromIndex, ToIndex: Longint);
procedure RowMoved(FromIndex, ToIndex: Longint); dynamic;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); virtual; abstract;
// procedure DrawContraCell(ACol, ARow: Longint; ARect: TRect;
// AState: TGridDrawState); virtual; abstract;
procedure DefineProperties(Filer: TFiler); override;
procedure MoveColRow(ACol, ARow: Longint; MoveAnchor, Show: Boolean);
function SelectCell(ACol, ARow: Longint): Boolean; virtual;
procedure SizeChanged(OldColCount, OldRowCount: Longint); dynamic;
function Sizing(X, Y: Integer): Boolean;
procedure ScrollData(DX, DY: Integer);
procedure InvalidateCell(ACol, ARow: Longint);
procedure InvalidateCol(ACol: Longint);
procedure InvalidateRow(ARow: Longint);
procedure TopLeftChanged; dynamic;
procedure TimedScroll(Direction: TGridScrollDirection); dynamic;
procedure Paint; override;
procedure DrawLines(DrawInfo: TGridDrawInfoEh; DoHorz, DoVert: Boolean;
Col, Row: Longint; const CellBounds: array of Integer; OnColor, OffColor: TColor;
Canvas: TCanvas; DrawLinesInfo: TDrawLinesInfoEh);
procedure DrawContraInfo(DrawInfo: TGridDrawInfoEh);
procedure DrawPolyPolyline(PointsList: TPointArray; StrokeList: TDWORDArray; VCount: Integer);
procedure DrawPolyline(Points: array of TPoint);
procedure ColWidthsChanged; dynamic;
procedure RowHeightsChanged; dynamic;
procedure DeleteColumn(ACol: Longint); virtual;
procedure DeleteRow(ARow: Longint); virtual;
procedure UpdateDesigner;
procedure UnlockPaint;
procedure UpdateFixedLineColor; virtual;
procedure DrawEdgeEh(ACanvas: TCanvas; qrc: TRect; IsDown, IsSelected,
NeedLeft, NeedRight: Boolean);
function CreateGridLineColors: TGridLineColorsEh; virtual;
procedure SetContraSize(NewContraColCount, NewContraRowCount: Integer); virtual;
// procedure ScrollMoveTopLeft(ALeft, ATop: Longint);
procedure SmoothOffsetData(DX, DY: Integer);
function BeginColumnDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
function BeginRowDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
function CheckColumnDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
function CheckRowDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
function EndColumnDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
function EndRowDrag(var Origin, Destination: Integer;
const MousePt: TPoint): Boolean; dynamic;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Col: Longint read FCurrent.X write SetCol;
property Color default clWindow;
property ColCount: Longint read FColCount write SetColCount default 5;
property ColWidths[Index: Longint]: Integer read GetColWidths write SetColWidths;
property DefaultColWidth: Integer read FDefaultColWidth write SetDefaultColWidth default 64;
property DefaultDrawing: Boolean read FDefaultDrawing write FDefaultDrawing default True;
property DefaultRowHeight: Integer read FDefaultRowHeight write SetDefaultRowHeight default 24;
property EditorMode: Boolean read FEditorMode write SetEditorMode;
property FixedColor: TColor read FFixedColor write SetFixedColor default clBtnFace;
property FixedCols: Integer read FFixedCols write SetFixedCols default 1;
property FixedRows: Integer read FFixedRows write SetFixedRows default 1;
property GridHeight: Integer read GetGridHeight;
property GridLineWidth: Integer read FGridLineWidth write SetGridLineWidth default 1;
property GridWidth: Integer read GetGridWidth;
property HitTest: TPoint read FHitTest;
property InplaceEditor: TInplaceEdit read FInplaceEdit;
property LeftCol: Longint read FTopLeft.X write SetLeftCol;
property Options: TGridOptions read FOptions write SetOptions
default [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect];
property ParentColor default False;
property Row: Longint read FCurrent.Y write SetRow;
property RowCount: Longint read FRowCount write SetRowCount default 5;
property RowHeights[Index: Longint]: Integer read GetRowHeights write SetRowHeights;
property ScrollBars: TScrollStyle read FScrollBars write SetScrollBars default ssBoth;
property Selection: TGridRect read GetSelection write SetSelection;
property TabStops[Index: Longint]: Boolean read GetTabStops write SetTabStops;
property TopRow: Longint read FTopLeft.Y write SetTopRow;
property VisibleColCount: Integer read GetVisibleColCount;
property VisibleRowCount: Integer read GetVisibleRowCount;
property ContraRowCount: Longint read FContraRowCount write SetContraRowCount default 0;
property ContraColCount: Longint read FContraColCount write SetContraColCount default 0;
property FullRowCount: Longint read GetFullRowCount;
property FullColCount: Longint read GetFullColCount;
property FrozenColCount: Longint read FFrozenColCount write SetFrozenColCount;
property FrozenRowCount: Longint read FFrozenRowCount write SetFrozenRowCount;
property GridLineColors: TGridLineColorsEh read FGridLineColors;
property OnCellMouseClick: TGridEhCellMouseEvent read FOnCellMouseClick write FOnCellMouseClick;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function MouseCoord(X, Y: Integer): TGridCoord;
procedure DefaultCellMouseClick(Cell: TGridCoord; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
property Flat: Boolean read FFlat write SetFlat;
published
property TabStop default True;
end;
{ TCustomDrawGrid }
{ A grid relies on the OnDrawCell event to display the cells.
CellRect
This method returns control relative screen coordinates of the cell or
an empty rectangle if the cell is not visible.
EditorMode
Setting to true shows the editor, as if the F2 key was pressed, when
goEditing is turned on and goAlwaysShowEditor is turned off.
MouseToCell
Takes control relative screen X, Y location and fills in the column and
row that contain that point.
OnColumnMoved
Called when the user request to move a column with the mouse when
the goColMoving option is on.
OnDrawCell
This event is passed the same information as the DrawCell method
discussed above.
OnGetEditMask
Called to retrieve edit mask in the inplace editor when goEditing is
turned on.
OnGetEditText
Called to retrieve text to edit when goEditing is turned on.
OnRowMoved
Called when the user request to move a row with the mouse when
the goRowMoving option is on.
OnSetEditText
Called when goEditing is turned on to reflect changes to the text
made by the editor.
OnTopLeftChanged
Invoked when TopRow or LeftCol change. }
TGetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; var Value: string) of object;
TSetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; const Value: string) of object;
TMovedEvent = procedure (Sender: TObject; FromIndex, ToIndex: Longint) of object;
TCustomDrawGridEh = class(TCustomGridEh)
private
FOnColumnMoved: TMovedEvent;
FOnDrawCell: TDrawCellEvent;
FOnGetEditMask: TGetEditEvent;
FOnGetEditText: TGetEditEvent;
FOnRowMoved: TMovedEvent;
FOnSelectCell: TSelectCellEvent;
FOnSetEditText: TSetEditEvent;
FOnTopLeftChanged: TNotifyEvent;
protected
procedure ColumnMoved(FromIndex, ToIndex: Longint); override;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); override;
// procedure DrawContraCell(ACol, ARow: Longint; ARect: TRect;
// AState: TGridDrawState); override;
function GetEditMask(ACol, ARow: Longint): string; override;
function GetEditText(ACol, ARow: Longint): string; override;
procedure RowMoved(FromIndex, ToIndex: Longint); override;
function SelectCell(ACol, ARow: Longint): Boolean; override;
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
procedure TopLeftChanged; override;
property OnColumnMoved: TMovedEvent read FOnColumnMoved write FOnColumnMoved;
property OnDrawCell: TDrawCellEvent read FOnDrawCell write FOnDrawCell;
property OnGetEditMask: TGetEditEvent read FOnGetEditMask write FOnGetEditMask;
property OnGetEditText: TGetEditEvent read FOnGetEditText write FOnGetEditText;
property OnRowMoved: TMovedEvent read FOnRowMoved write FOnRowMoved;
property OnSelectCell: TSelectCellEvent read FOnSelectCell write FOnSelectCell;
property OnSetEditText: TSetEditEvent read FOnSetEditText write FOnSetEditText;
property OnTopLeftChanged: TNotifyEvent read FOnTopLeftChanged write FOnTopLeftChanged;
public
function CellRect(ACol, ARow: Longint): TRect;
procedure MouseToCell(X, Y: Integer; var ACol, ARow: Longint);
property Canvas;
property Col;
property ColWidths;
property EditorMode;
property GridHeight;
property GridWidth;
property LeftCol;
property Selection;
property Row;
property RowHeights;
property TabStops;
property TopRow;
property ContraRowCount;
property ContraColCount;
property FullRowCount;
property FullColCount;
property FrozenColCount;
property FrozenRowCount;
property Flat;
end;
{ TDrawGrid }
TDrawGridEh = class(TCustomDrawGridEh)
published
property Align;
property Anchors;
property BiDiMode;
property BorderStyle;
property Color;
property ColCount;
property Constraints;
property Ctl3D;
property DefaultColWidth;
property DefaultRowHeight;
property DefaultDrawing;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FixedColor;
property FixedCols;
property RowCount;
property FixedRows;
property Font;
property GridLineWidth;
property Options;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ScrollBars;
property ShowHint;
property TabOrder;
property Visible;
property VisibleColCount;
property VisibleRowCount;
property OnClick;
property OnColumnMoved;
// property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawCell;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetEditMask;
property OnGetEditText;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnRowMoved;
property OnSelectCell;
property OnSetEditText;
property OnStartDock;
property OnStartDrag;
property OnTopLeftChanged;
end;
function GridCoord(X, Y: Longint): TGridCoord;
implementation
uses Math, Consts{, RTLConsts, Themes};
function GridCoord(X, Y: Longint): TGridCoord;
begin
Result.X := X;
Result.Y := Y;
end;
procedure InvalidOp(const id: string);
begin
raise EInvalidGridOperationEh.Create(id);
end;
function GridRect(Coord1, Coord2: TGridCoord): TGridRect;
begin
with Result do
begin
Left := Coord2.X;
if Coord1.X < Coord2.X then Left := Coord1.X;
Right := Coord1.X;
if Coord1.X < Coord2.X then Right := Coord2.X;
Top := Coord2.Y;
if Coord1.Y < Coord2.Y then Top := Coord1.Y;
Bottom := Coord1.Y;
if Coord1.Y < Coord2.Y then Bottom := Coord2.Y;
end;
end;
function PointInGridRect(Col, Row: Longint; const Rect: TGridRect): Boolean;
begin
Result := (Col >= Rect.Left) and (Col <= Rect.Right) and (Row >= Rect.Top)
and (Row <= Rect.Bottom);
end;
type
TXorRects = array[0..3] of TRect;
procedure XorRects(const R1, R2: TRect; var XorRects: TXorRects);
var
Intersect, Union: TRect;
function PtInRect(X, Y: Integer; const Rect: TRect): Boolean;
begin
with Rect do Result := (X >= Left) and (X <= Right) and (Y >= Top) and
(Y <= Bottom);
end;
function Includes(const P1: TPoint; P2: TPoint): Boolean;
begin
with P1 do
Result := PtInRect(X, Y, R1) or PtInRect(X, Y, R2);
end;
function Build(var R: TRect; const P1, P2, P3: TPoint): Boolean;
begin
Build := True;
with R do
if Includes(P1, R.TopLeft) then
begin
Left := P1.X;
Top := P1.Y;
if Includes(P3, R.BottomRight) then
begin
Right := P3.X;
Bottom := P3.Y;
end else
begin
Right := P2.X;
Bottom := P2.Y;
end
end
else if Includes(P2, R.TopLeft) then
begin
Left := P2.X;
Top := P2.Y;
Bottom := P3.Y;
Right := P3.X;
end
else
Build := False;
end;
begin
XorRects[0] := EmptyRect;
XorRects[1] := EmptyRect;
XorRects[2] := EmptyRect;
XorRects[3] := EmptyRect;
// FillChar(XorRects, SizeOf(XorRects), 0);
if not Bool(IntersectRect(Intersect, R1, R2)) then
begin
{ Don't intersect so its simple }
XorRects[0] := R1;
XorRects[1] := R2;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -