📄 gridseh.pas
字号:
end
else
begin
UnionRect(Union, R1, R2);
if Build(XorRects[0],
Point(Union.Left, Union.Top),
Point(Union.Left, Intersect.Top),
Point(Union.Left, Intersect.Bottom)) then
XorRects[0].Right := Intersect.Left;
if Build(XorRects[1],
Point(Intersect.Left, Union.Top),
Point(Intersect.Right, Union.Top),
Point(Union.Right, Union.Top)) then
XorRects[1].Bottom := Intersect.Top;
if Build(XorRects[2],
Point(Union.Right, Intersect.Top),
Point(Union.Right, Intersect.Bottom),
Point(Union.Right, Union.Bottom)) then
XorRects[2].Left := Intersect.Right;
if Build(XorRects[3],
Point(Union.Left, Union.Bottom),
Point(Intersect.Left, Union.Bottom),
Point(Intersect.Right, Union.Bottom)) then
XorRects[3].Top := Intersect.Bottom;
end;
end;
procedure ModifyExtents(var Extents: TIntegerArray; Index, Amount: Longint; Default: Integer);
// Adds or deletes itmes in Extents from 'Index' with 'Amount'.
var
LongSize, OldSize: LongInt;
NewSize: Integer;
I: Integer;
begin
if Amount <> 0 then
begin
if Length(Extents) = 0 then OldSize := 0
else OldSize := Extents[0];
if (Index < 0) or (OldSize < Index) then InvalidOp(SIndexOutOfRange);
LongSize := OldSize + Amount;
if LongSize < 0 then InvalidOp(STooManyDeleted)
else if LongSize >= MaxListSize - 1 then InvalidOp(SGridTooLarge);
NewSize := Cardinal(LongSize);
if NewSize > 0 then Inc(NewSize);
SetLength(Extents, NewSize);
if Length(Extents) <> 0 then
begin
I := Index + 1;
while I < NewSize do
begin
Extents[I] := Default;
Inc(I);
end;
Extents[0] := NewSize-1;
end;
end;
end;
procedure UpdateExtents(var Extents: TIntegerArray; NewSize: Longint;
Default: Integer);
var
OldSize: Integer;
begin
OldSize := 0;
if Length(Extents) <> 0 then OldSize := Extents[0];
ModifyExtents(Extents, OldSize, NewSize - OldSize, Default);
end;
procedure MoveExtent(var Extents: TIntegerArray; FromIndex, ToIndex: Longint);
var
Extent, I: Integer;
begin
if Length(Extents) <> 0 then
begin
Extent := Extents[FromIndex];
if FromIndex < ToIndex then
for I := FromIndex + 1 to ToIndex do
Extents[I - 1] := Extents[I]
else if FromIndex > ToIndex then
for I := FromIndex - 1 downto ToIndex do
Extents[I + 1] := Extents[I];
Extents[ToIndex] := Extent;
end;
end;
function CompareExtents(E1, E2: TIntegerArray): Boolean;
var
I: Integer;
begin
Result := False;
if Length(E1) <> 0 then
begin
if Length(E2) <> 0 then
begin
for I := 0 to E1[0] do
if E1[I] <> E2[I] then Exit;
Result := True;
end
end
else Result := Length(E2) = 0;
end;
{procedure KillMessage(Wnd: HWnd; Msg: Integer);
// Delete the requested message from the queue, but throw back
// any WM_QUIT msgs that PeekMessage may also return
var
M: TMsg;
begin
M.Message := 0;
if PeekMessage(M, Wnd, Msg, Msg, pm_Remove) and (M.Message = WM_QUIT) then
PostQuitMessage(M.wparam);
end;
}
type
TSelection = record
StartPos, EndPos: Integer;
end;
constructor TInplaceEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ParentCtl3D := False;
Ctl3D := False;
TabStop := False;
BorderStyle := bsNone;
DoubleBuffered := False;
end;
procedure TInplaceEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or ES_MULTILINE;
end;
procedure TInplaceEdit.SetGrid(Value: TCustomGridEh);
begin
FGrid := Value;
end;
procedure TInplaceEdit.CMShowingChanged(var Message: TMessage);
begin
{ Ignore showing using the Visible property }
end;
procedure TInplaceEdit.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
inherited;
if goTabs in Grid.Options then
Message.Result := Message.Result or DLGC_WANTTAB;
end;
procedure TInplaceEdit.WMPaste(var Message: TMessage);
begin
if not EditCanModify then Exit;
inherited
end;
procedure TInplaceEdit.WMClear(var Message: TMessage);
begin
if not EditCanModify then Exit;
inherited;
end;
procedure TInplaceEdit.WMCut(var Message: TMessage);
begin
if not EditCanModify then Exit;
inherited;
end;
procedure TInplaceEdit.DblClick;
begin
{$IFDEF CIL}
// Grid.DblClick;
{$ELSE}
Grid.DblClick;
{$ENDIF}
end;
function TInplaceEdit.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean;
begin
{$IFDEF CIL}
// Result := Grid.DoMouseWheel(Shift, WheelDelta, MousePos);
{$ELSE}
Result := Grid.DoMouseWheel(Shift, WheelDelta, MousePos);
{$ENDIF}
end;
function TInplaceEdit.EditCanModify: Boolean;
begin
Result := Grid.CanEditModify;
end;
procedure TInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
procedure SendToParent;
begin
Grid.KeyDown(Key, Shift);
Key := 0;
end;
procedure ParentEvent;
var
GridKeyDown: TKeyEvent;
begin
{$IFDEF CIL}
// GridKeyDown := Grid.OnKeyDown;
{$ELSE}
GridKeyDown := Grid.OnKeyDown;
{$ENDIF}
if Assigned(GridKeyDown) then GridKeyDown(Grid, Key, Shift);
end;
function ForwardMovement: Boolean;
begin
Result := goAlwaysShowEditor in Grid.Options;
end;
function Ctrl: Boolean;
begin
Result := ssCtrl in Shift;
end;
function Selection: TSelection;
begin
// SendMessage(Handle, EM_GETSEL, Longint(@Result.StartPos), Longint(@Result.EndPos));
MessageSendGetSel(Handle, Result.StartPos, Result.EndPos);
end;
function CaretPos: Integer;
var
P: TPoint;
begin
Windows.GetCaretPos(P);
Result := SendMessage(Handle, EM_CHARFROMPOS, 0, MakeLong(P.X, P.Y));
end;
function RightSide: Boolean;
begin
with Selection do
Result := (CaretPos = GetTextLen) and
((StartPos = 0) or (EndPos = StartPos)) and (EndPos = GetTextLen);
end;
function LeftSide: Boolean;
begin
with Selection do
Result := (CaretPos = 0) and (StartPos = 0) and
((EndPos = 0) or (EndPos = GetTextLen));
end;
begin
case Key of
VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT, VK_ESCAPE: SendToParent;
VK_INSERT:
if Shift = [] then SendToParent
else if (Shift = [ssShift]) and not Grid.CanEditModify then Key := 0;
VK_LEFT: if ForwardMovement and (Ctrl or LeftSide) then SendToParent;
VK_RIGHT: if ForwardMovement and (Ctrl or RightSide) then SendToParent;
VK_HOME: if ForwardMovement and (Ctrl or LeftSide) then SendToParent;
VK_END: if ForwardMovement and (Ctrl or RightSide) then SendToParent;
VK_F2:
begin
ParentEvent;
if Key = VK_F2 then
begin
Deselect;
Exit;
end;
end;
VK_TAB: if not (ssAlt in Shift) then SendToParent;
VK_DELETE:
if Ctrl then
SendToParent
else
if not Grid.CanEditModify then Key := 0;
end;
if Key <> 0 then
begin
ParentEvent;
inherited KeyDown(Key, Shift);
end;
end;
procedure TInplaceEdit.KeyPress(var Key: Char);
var
Selection: TSelection;
begin
Grid.KeyPress(Key);
if (Key >= #32) and not Grid.CanEditAcceptKey(Key) then
begin
Key := #0;
MessageBeep(0);
end;
case Key of
#9, #27: Key := #0;
#13:
begin
MessageSendGetSel(Handle, Selection.StartPos, Selection.EndPos);
// SendMessage(Handle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
if (Selection.StartPos = 0) and (Selection.EndPos = GetTextLen) then
Deselect else
SelectAll;
Key := #0;
end;
^H, ^V, ^X, #32..High(Char):
if not Grid.CanEditModify then Key := #0;
end;
if Key <> #0 then inherited KeyPress(Key);
end;
procedure TInplaceEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
{$IFDEF CIL}
// Grid.KeyUp(Key, Shift);
{$ELSE}
Grid.KeyUp(Key, Shift);
{$ENDIF}
end;
procedure TInplaceEdit.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_SETFOCUS:
begin
if (GetParentForm(Self) = nil) or GetParentForm(Self).SetFocusedControl(Grid) then
Dispatch(Message);
Exit;
end;
WM_LBUTTONDOWN:
begin
if UINT(GetMessageTime - FClickTime) < GetDoubleClickTime then
Message.Msg := WM_LBUTTONDBLCLK;
FClickTime := 0;
end;
end;
inherited WndProc(Message);
end;
procedure TInplaceEdit.Deselect;
begin
SendMessage(Handle, EM_SETSEL, $7FFFFFFF, Longint($FFFFFFFF));
end;
procedure TInplaceEdit.Invalidate;
var
Cur: TRect;
begin
ValidateRect(Handle, nil);
InvalidateRect(Handle, nil, True);
Windows.GetClientRect(Handle, Cur);
MapWindowPoints(Handle, Grid.Handle, Cur, 2);
WindowsValidateRect(Grid.Handle, Cur);
WindowsInvalidateRect(Grid.Handle, Cur, False);
end;
procedure TInplaceEdit.Hide;
begin
if HandleAllocated and IsWindowVisible(Handle) then
begin
Invalidate;
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_HIDEWINDOW or SWP_NOZORDER or
SWP_NOREDRAW);
if Focused then Windows.SetFocus(Grid.Handle);
end;
end;
function TInplaceEdit.PosEqual(const Rect: TRect): Boolean;
var
Cur: TRect;
begin
GetWindowRect(Handle, Cur);
MapWindowPoints(HWND_DESKTOP, Grid.Handle, Cur, 2);
Result := EqualRect(Rect, Cur);
end;
procedure TInplaceEdit.InternalMove(const Loc: TRect; Redraw: Boolean);
begin
if IsRectEmpty(Loc) then Hide
else
begin
CreateHandle;
Redraw := Redraw or not IsWindowVisible(Handle);
Invalidate;
with Loc do
SetWindowPos(Handle, HWND_TOP, Left, Top, Right - Left, Bottom - Top,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -