📄 skingrids.pas
字号:
SetBkMode(ChildDC, Windows.Transparent);
SetTextColor(ChildDC, Font.Color);
Result := GetStockObject(HOLLOW_BRUSH);
end
else
inherited;
end;
procedure TspSkinTransparentMaskEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
if FTransparent then Invalidate else inherited;
end;
procedure TspSkinTransparentMaskEdit.DoExit;
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.DoEnter;
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMKeyDown(var Message: TWMKeyDown);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMSetText(var Message:TWMSetText);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMMove(var Message: TMessage);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMCut(var Message: TMessage);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMPaste(var Message: TMessage);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMClear(var Message: TMessage);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMUndo(var Message: TMessage);
begin
inherited;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMLButtonDown(var Message: TWMKeyDown);
begin
inherited;
FDown := True;
if FTransparent then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMMOUSEMOVE;
begin
inherited;
if FDown then Invalidate;
end;
procedure TspSkinTransparentMaskEdit.WMLButtonUp;
begin
inherited;
FDown := False;
end;
procedure TspSkinTransparentMaskEdit.Invalidate;
begin
if FTransparent then InvalidateEdit else inherited;
end;
constructor TspSkinInplaceEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ParentCtl3D := False;
Ctl3D := False;
TabStop := False;
BorderStyle := bsNone;
FSysPopupMenu := nil;
end;
destructor TspSkinInplaceEdit.Destroy;
begin
if FSysPopupMenu <> nil then FSysPopupMenu.Free;
inherited;
end;
procedure TspSkinInplaceEdit.WMCONTEXTMENU;
var
X, Y: Integer;
P: TPoint;
begin
if PopupMenu <> nil
then
inherited
else
begin
CreateSysPopupMenu;
X := Message.XPos;
Y := Message.YPos;
if (X < 0) or (Y < 0)
then
begin
X := Width div 2;
Y := Height div 2;
P := Point(0, 0);
P := ClientToScreen(P);
X := X + P.X;
Y := Y + P.Y;
end;
if FSysPopupMenu <> nil
then
FSysPopupMenu.Popup2(Self, X, Y)
end;
end;
procedure TspSkinInplaceEdit.WMAFTERDISPATCH;
begin
if FSysPopupMenu <> nil
then
begin
FSysPopupMenu.Free;
FSysPopupMenu := nil;
end;
end;
procedure TspSkinInplaceEdit.DoUndo;
begin
Undo;
end;
procedure TspSkinInplaceEdit.DoCut;
begin
CutToClipboard;
end;
procedure TspSkinInplaceEdit.DoCopy;
begin
CopyToClipboard;
end;
procedure TspSkinInplaceEdit.DoPaste;
begin
PasteFromClipboard;
end;
procedure TspSkinInplaceEdit.DoDelete;
begin
ClearSelection;
end;
procedure TspSkinInplaceEdit.DoSelectAll;
begin
SelectAll;
end;
procedure TspSkinInplaceEdit.CreateSysPopupMenu;
function IsSelected: Boolean;
var
i, j: Integer;
begin
GetSel(i, j);
Result := (i < j);
end;
function IsFullSelected: Boolean;
var
i, j: Integer;
begin
GetSel(i, j);
Result := (i = 0) and (j = Length(Text));
end;
var
Item: TMenuItem;
begin
if FSysPopupMenu <> nil then FSysPopupMenu.Free;
FSysPopupMenu := TspSkinPopupMenu.Create(Self);
FSysPopupMenu.ComponentForm := TForm(GetParentForm(Self));
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_UNDO')
else
Caption := SP_Edit_Undo;
OnClick := DoUndo;
Enabled := Self.CanUndo;
end;
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
Item.Caption := '-';
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_CUT')
else
Caption := SP_Edit_Cut;
Enabled := IsSelected and not Self.ReadOnly;
OnClick := DoCut;
end;
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_COPY')
else
Caption := SP_Edit_Copy;
Enabled := IsSelected;
OnClick := DoCopy;
end;
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_PASTE')
else
Caption := SP_Edit_Paste;
Enabled := (ClipBoard.AsText <> '') and not ReadOnly;
OnClick := DoPaste;
end;
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_DELETE')
else
Caption := SP_Edit_Delete;
Enabled := IsSelected and not Self.ReadOnly;
OnClick := DoDelete;
end;
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
Item.Caption := '-';
FSysPopupMenu.Items.Add(Item);
Item := TMenuItem.Create(FSysPopupMenu);
with Item do
begin
if (FGrid.SkinData <> nil) and (FGrid.SkinData.ResourceStrData <> nil)
then
Caption := FGrid.SkinData.ResourceStrData.GetResStr('EDIT_SELECTALL')
else
Caption := SP_Edit_SelectAll;
Enabled := not IsFullSelected;
OnClick := DoSelectAll;
end;
FSysPopupMenu.Items.Add(Item);
end;
procedure TspSkinInplaceEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
if not Transparent then inherited;
end;
procedure TspSkinInplaceEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or ES_MULTILINE;
end;
procedure TspSkinInplaceEdit.SetGrid(Value: TspSkinCustomGrid);
begin
FGrid := Value;
end;
procedure TspSkinInplaceEdit.CMShowingChanged(var Message: TMessage);
begin
end;
procedure TspSkinInplaceEdit.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
inherited;
if goTabs in Grid.Options then
Message.Result := Message.Result or DLGC_WANTTAB;
end;
procedure TspSkinInplaceEdit.WMPaste(var Message);
begin
if not EditCanModify then Exit;
inherited
end;
procedure TspSkinInplaceEdit.WMClear(var Message);
begin
if not EditCanModify then Exit;
inherited;
end;
procedure TspSkinInplaceEdit.WMCut(var Message);
begin
if not EditCanModify then Exit;
inherited;
end;
procedure TspSkinInplaceEdit.DblClick;
begin
Grid.DblClick;
end;
function TspSkinInplaceEdit.EditCanModify: Boolean;
begin
Result := Grid.CanEditModify;
end;
procedure TspSkinInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
procedure SendToParent;
begin
Grid.KeyDown(Key, Shift);
Key := 0;
end;
procedure ParentEvent;
var
GridKeyDown: TKeyEvent;
begin
GridKeyDown := Grid.OnKeyDown;
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));
end;
function RightSide: Boolean;
begin
with Selection do
Result := ((StartPos = 0) or (EndPos = StartPos)) and
(EndPos = GetTextLen);
end;
function LeftSide: Boolean;
begin
with Selection do
Result := (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;
end;
if (Key = VK_DELETE) and not Grid.CanEditModify then Key := 0;
if Key <> 0 then
begin
ParentEvent;
inherited KeyDown(Key, Shift);
end;
end;
procedure TspSkinInplaceEdit.KeyPress(var Key: Char);
var
Selection: TSelection;
begin
Grid.KeyPress(Key);
if (Key in [#32..#255]) and not Grid.CanEditAcceptKey(Key) then
begin
Key := #0;
MessageBeep(0);
end;
case Key of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -