?? gridseh.pas
字號:
SWP_SHOWWINDOW or SWP_NOREDRAW);
BoundsChanged;
if Redraw then Invalidate;
if Grid.Focused then
Windows.SetFocus(Handle);
end;
end;
procedure TInplaceEdit.BoundsChanged;
var
R: TRect;
begin
R := Rect(2, 2, Width - 2, Height);
// SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@R));
SendStructMessage(Handle, EM_SETRECTNP, 0, R);
SendMessage(Handle, EM_SCROLLCARET, 0, 0);
end;
procedure TInplaceEdit.UpdateLoc(const Loc: TRect);
begin
InternalMove(Loc, False);
end;
function TInplaceEdit.Visible: Boolean;
begin
Result := IsWindowVisible(Handle);
end;
procedure TInplaceEdit.Move(const Loc: TRect);
begin
InternalMove(Loc, True);
end;
procedure TInplaceEdit.SetFocus;
begin
if IsWindowVisible(Handle) then
Windows.SetFocus(Handle);
end;
procedure TInplaceEdit.UpdateContents;
begin
Text := '';
EditMask := Grid.GetEditMask(Grid.Col, Grid.Row);
Text := Grid.GetEditText(Grid.Col, Grid.Row);
MaxLength := Grid.GetEditLimit;
end;
{ TCustomGridEh }
constructor TCustomGridEh.Create(AOwner: TComponent);
const
GridStyle = [csCaptureMouse, csOpaque, csDoubleClicks];
begin
inherited Create(AOwner);
if NewStyleControls then
ControlStyle := GridStyle
else
ControlStyle := GridStyle + [csFramed];
{$IFDEF EH_LIB_7}
ControlStyle := ControlStyle + [csNeedsBorderPaint];
{$ENDIF}
FCanEditModify := True;
FColCount := 5;
FRowCount := 5;
FFixedCols := 1;
FFixedRows := 1;
FGridLineWidth := 1;
FOptions := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect];
DesignOptionsBoost := [goColSizing, goRowSizing];
FFixedColor := clBtnFace;
FScrollBars := ssBoth;
FBorderStyle := bsSingle;
FDefaultColWidth := 64;
FDefaultRowHeight := 24;
FDefaultDrawing := True;
FSaveCellExtents := True;
FEditorMode := False;
Color := clWindow;
ParentColor := False;
TabStop := True;
SetBounds(Left, Top, FColCount * FDefaultColWidth,
FRowCount * FDefaultRowHeight);
Initialize;
FFixedLineColor := clBlack;
FGridLineColors := CreateGridLineColors;
FMouseDownCell := MouseCoord(-1, -1);
end;
destructor TCustomGridEh.Destroy;
begin
FreeAndNil(FInplaceEdit);
inherited Destroy;
// FreeMem(FColWidths);
// FreeMem(FRowHeights);
// FreeMem(FTabStops);
FreeAndNil(FGridLineColors);
end;
procedure TCustomGridEh.AdjustSize(Index, Amount: Longint; Rows: Boolean);
// Adds or deletes rows or columns from 'Index' with 'Amount'.
var
NewCur: TGridCoord;
OldRows, OldCols, TabColColunt, TabNewCur: Longint;
MovementX, MovementY: Longint;
MoveRect: TGridRect;
ScrollArea: TRect;
AbsAmount: Longint;
function DoSizeAdjust(var Count: Longint; var Extents: TIntegerArray;
DefaultExtent: Integer; var Current: Longint): Longint;
var
I: Integer;
NewCount: Longint;
begin
NewCount := Count + Amount;
if NewCount < Index then InvalidOp(STooManyDeleted);
if (Amount < 0) and Assigned(Extents) then
begin
Result := 0;
for I := Index to Index - Amount - 1 do
Inc(Result, Extents[I]);
end
else
Result := Amount * DefaultExtent;
if Extents <> nil then
ModifyExtents(Extents, Index, Amount, DefaultExtent);
Count := NewCount;
if Current >= Index then
if (Amount < 0) and (Current < Index - Amount) then Current := Index
else Inc(Current, Amount);
if Current >= Count then
Current := Count - 1;
end;
begin
if Amount = 0 then Exit;
NewCur := FCurrent;
OldCols := ColCount;
OldRows := RowCount;
MoveRect.Left := FixedCols;
MoveRect.Right := ColCount - 1;
MoveRect.Top := FixedRows;
MoveRect.Bottom := RowCount - 1;
MovementX := 0;
MovementY := 0;
AbsAmount := Amount;
if AbsAmount < 0 then AbsAmount := -AbsAmount;
if Rows then
begin
MovementY := DoSizeAdjust(FRowCount, FRowHeights, DefaultRowHeight, NewCur.Y);
MoveRect.Top := Index;
if Index + AbsAmount <= TopRow then MoveRect.Bottom := TopRow - 1;
end
else
begin
TabColColunt := FColCount;
TabNewCur := NewCur.X;
DoSizeAdjust(TabColColunt, FTabStops, Integer(True), TabNewCur);
MovementX := DoSizeAdjust(FColCount, FColWidths, DefaultColWidth, NewCur.X);
MoveRect.Left := Index;
if Index + AbsAmount <= LeftCol then MoveRect.Right := LeftCol - 1;
end;
GridRectToScreenRect(MoveRect, ScrollArea, True);
if not IsRectEmpty(ScrollArea) then
begin
WindowsScrollWindow(Handle, MovementX, MovementY, ScrollArea, ScrollArea);
UpdateWindow(Handle);
end;
if (ContraRowCount > 0) or (ContraColCount > 0) then Invalidate;
SizeChanged(OldCols, OldRows);
if (NewCur.X <> FCurrent.X) or (NewCur.Y <> FCurrent.Y) then
MoveCurrent(NewCur.X, NewCur.Y, True, True);
UpdateScrollRange;
end;
procedure TCustomGridEh.SetContraSize(NewContraColCount, NewContraRowCount: Integer);
var
OldContraColCount, OldContraRowCount: Integer;
begin
OldContraColCount := FContraColCount;
OldContraRowCount := FContraRowCount;
FContraColCount := NewContraColCount;
FContraRowCount := NewContraRowCount;
try
if Length(FColWidths) <> 0 then
UpdateExtents(FColWidths, FullColCount, DefaultColWidth);
if Length(FTabStops) <> 0 then
UpdateExtents(FTabStops, FullColCount, Integer(True));
if Length(FRowHeights) <> 0 then
UpdateExtents(FRowHeights, FullRowCount, DefaultRowHeight);
except
FContraColCount := OldContraColCount;
FContraRowCount := OldContraRowCount;
end;
Invalidate;
UpdateScrollRange;
end;
function TCustomGridEh.BoxRect(ALeft, ATop, ARight, ABottom: Longint): TRect;
var
GridRect: TGridRect;
begin
GridRect.Left := ALeft;
GridRect.Right := ARight;
GridRect.Top := ATop;
GridRect.Bottom := ABottom;
GridRectToScreenRect(GridRect, Result, False);
end;
procedure TCustomGridEh.DoExit;
begin
inherited DoExit;
if not (goAlwaysShowEditor in Options) then HideEditor;
end;
function TCustomGridEh.CellRect(ACol, ARow: Longint): TRect;
begin
Result := BoxRect(ACol, ARow, ACol, ARow);
end;
function TCustomGridEh.CanEditAcceptKey(Key: Char): Boolean;
begin
Result := True;
end;
function TCustomGridEh.CanGridAcceptKey(Key: Word; Shift: TShiftState): Boolean;
begin
Result := True;
end;
function TCustomGridEh.CanEditModify: Boolean;
begin
Result := FCanEditModify;
end;
function TCustomGridEh.CanEditShow: Boolean;
begin
Result := ([goRowSelect, goEditing] * Options = [goEditing]) and
FEditorMode and not (csDesigning in ComponentState) and HandleAllocated and
((goAlwaysShowEditor in Options) or IsActiveControl);
end;
function TCustomGridEh.IsActiveControl: Boolean;
var
H: Hwnd;
ParentForm: TCustomForm;
begin
Result := False;
ParentForm := GetParentForm(Self);
if Assigned(ParentForm) then
begin
if (ParentForm.ActiveControl = Self) then
Result := True
end
else
begin
H := GetFocus;
while IsWindow(H) and (Result = False) do
begin
if H = WindowHandle then
Result := True
else
H := GetParent(H);
end;
end;
end;
function TCustomGridEh.GetEditMask(ACol, ARow: Longint): string;
begin
Result := '';
end;
function TCustomGridEh.GetEditText(ACol, ARow: Longint): string;
begin
Result := '';
end;
procedure TCustomGridEh.SetEditText(ACol, ARow: Longint; const Value: string);
begin
end;
function TCustomGridEh.GetEditLimit: Integer;
begin
Result := 0;
end;
function TCustomGridEh.GetEditStyle(ACol, ARow: Longint): TEditStyle;
begin
Result := esSimple;
end;
procedure TCustomGridEh.HideEditor;
begin
FEditorMode := False;
HideEdit;
end;
procedure TCustomGridEh.ShowEditor;
begin
FEditorMode := True;
UpdateEdit;
end;
procedure TCustomGridEh.ShowEditorChar(Ch: Char);
begin
ShowEditor;
if FInplaceEdit <> nil then
PostMessage(FInplaceEdit.Handle, WM_CHAR, Ord(Ch), 0);
end;
procedure TCustomGridEh.InvalidateEditor;
begin
FInplaceCol := -1;
FInplaceRow := -1;
UpdateEdit;
end;
procedure TCustomGridEh.ReadColWidths(Reader: TReader);
var
I: Integer;
begin
with Reader do
begin
ReadListBegin;
for I := 0 to ColCount - 1 do ColWidths[I] := ReadInteger;
ReadListEnd;
end;
end;
procedure TCustomGridEh.ReadRowHeights(Reader: TReader);
var
I: Integer;
begin
with Reader do
begin
ReadListBegin;
for I := 0 to RowCount - 1 do RowHeights[I] := ReadInteger;
ReadListEnd;
end;
end;
procedure TCustomGridEh.WriteColWidths(Writer: TWriter);
var
I: Integer;
begin
with Writer do
begin
WriteListBegin;
for I := 0 to ColCount - 1 do WriteInteger(ColWidths[I]);
WriteListEnd;
end;
end;
procedure TCustomGridEh.WriteRowHeights(Writer: TWriter);
var
I: Integer;
begin
with Writer do
begin
WriteListBegin;
for I := 0 to RowCount - 1 do WriteInteger(RowHeights[I]);
WriteListEnd;
end;
end;
procedure TCustomGridEh.DefineProperties(Filer: TFiler);
function DoColWidths: Boolean;
begin
if Filer.Ancestor <> nil then
Result := not CompareExtents(TCustomGridEh(Filer.Ancestor).FColWidths, FColWidths)
else
Result := Length(FColWidths) <> 0;
end;
function DoRowHeights: Boolean;
begin
if Filer.Ancestor <> nil then
Result := not CompareExtents(TCustomGridEh(Filer.Ancestor).FRowHeights, FRowHeights)
else
Result := Length(FRowHeights) <> 0;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -