📄 skingrids.pas
字号:
#9, #27: Key := #0;
#13:
begin
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..#255:
if not Grid.CanEditModify then Key := #0;
end;
if Key <> #0 then inherited KeyPress(Key);
end;
procedure TspSkinInplaceEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
Grid.KeyUp(Key, Shift);
end;
procedure TspSkinInplaceEdit.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 ((GetMessageTime - FClickTime) < GetDoubleClickTime) then
Message.Msg := WM_LBUTTONDBLCLK;
FClickTime := 0;
end;
end;
inherited WndProc(Message);
end;
procedure TspSkinInplaceEdit.Deselect;
begin
SendMessage(Handle, EM_SETSEL, $7FFFFFFF, Longint($FFFFFFFF));
end;
procedure TspSkinInplaceEdit.Invalidate;
var
Cur: TRect;
begin
if not Transparent
then
begin
ValidateRect(Handle, nil);
InvalidateRect(Handle, nil, True);
Windows.GetClientRect(Handle, Cur);
MapWindowPoints(Handle, Grid.Handle, Cur, 2);
ValidateRect(Grid.Handle, @Cur);
InvalidateRect(Grid.Handle, @Cur, False);
end
else
inherited;
end;
procedure TspSkinInplaceEdit.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 TspSkinInplaceEdit.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 TspSkinInplaceEdit.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,
SWP_SHOWWINDOW or SWP_NOREDRAW);
BoundsChanged;
if Redraw then Invalidate;
if Grid.Focused then
Windows.SetFocus(Handle);
end;
end;
procedure TspSkinInplaceEdit.BoundsChanged;
var
R: TRect;
begin
R := Rect(2, 2, Width - 2, Height);
SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@R));
SendMessage(Handle, EM_SCROLLCARET, 0, 0);
end;
procedure TspSkinInplaceEdit.UpdateLoc(const Loc: TRect);
begin
InternalMove(Loc, False);
end;
function TspSkinInplaceEdit.Visible: Boolean;
begin
Result := IsWindowVisible(Handle);
end;
procedure TspSkinInplaceEdit.Move(const Loc: TRect);
begin
InternalMove(Loc, True);
end;
procedure TspSkinInplaceEdit.SetFocus;
begin
if IsWindowVisible(Handle) then
Windows.SetFocus(Handle);
end;
procedure TspSkinInplaceEdit.UpdateContents;
begin
Text := '';
EditMask := Grid.GetEditMask(Grid.Col, Grid.Row);
Text := Grid.GetEditText(Grid.Col, Grid.Row);
MaxLength := Grid.GetEditLimit;
end;
{ TspSkinCustomGrid }
constructor TspSkinCustomGrid.Create(AOwner: TComponent);
const
GridStyle = [csCaptureMouse, csOpaque, csDoubleClicks];
begin
inherited Create(AOwner);
FUseSkinCellHeight := True;
FUseSkinFont := True;
FHScrollBar := nil;
FVScrollBar := nil;
FTransparent := False;
Ctl3D := False;
if NewStyleControls then
ControlStyle := GridStyle else
ControlStyle := GridStyle + [csFramed];
FCanEditModify := True;
FInCheckScrollBars := False;
FColCount := 5;
FRowCount := 5;
FFixedCols := 1;
FFixedRows := 1;
FGridLineWidth := 1;
FOptions := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect];
DesignOptionsBoost := [goColSizing, goRowSizing];
FFixedColor := clBtnFace;
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);
Picture := nil;
BGPicture := nil;
Initialize;
FSkinDataName := 'grid';
FGridLineColor := clWindowText;
end;
destructor TspSkinCustomGrid.Destroy;
begin
FHScrollBar := nil;
FVScrollBar := nil;
FInplaceEdit.Free;
inherited Destroy;
FreeMem(FColWidths);
FreeMem(FRowHeights);
FreeMem(FTabStops);
end;
procedure TspSkinCustomGrid.OnVScrollBarPageUp(Sender: TObject);
begin
SendMessage(Handle, WM_VSCROLL,
MakeWParam(SB_PAGEUP, 0), 0);
end;
procedure TspSkinCustomGrid.OnVScrollBarPageDown(Sender: TObject);
begin
SendMessage(Handle, WM_VSCROLL,
MakeWParam(SB_PAGEDOWN, 0), 0);
end;
procedure TspSkinCustomGrid.OnHScrollBarPageUp(Sender: TObject);
begin
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_PAGEUP, 0), 0);
end;
procedure TspSkinCustomGrid.OnHScrollBarPageDown(Sender: TObject);
begin
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_PAGEDOWN, 0), 0);
end;
procedure TspSkinCustomGrid.OnVScrollBarUpButtonClick(Sender: TObject);
begin
SendMessage(Handle, WM_VSCROLL,
MakeWParam(SB_LINEDOWN, VScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.OnVScrollBarDownButtonClick(Sender: TObject);
begin
SendMessage(Handle, WM_VSCROLL,
MakeWParam(SB_LINEUP, VScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.OnHScrollBarUpButtonClick(Sender: TObject);
begin
FHScrollBar.Position := FHScrollBar.Position + FHScrollBar.SmallChange;
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_THUMBPOSITION, FHScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.OnHScrollBarDownButtonClick(Sender: TObject);
begin
FHScrollBar.Position := FHScrollBar.Position - FHScrollBar.SmallChange;
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_THUMBPOSITION, FHScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.CMVisibleChanged;
begin
inherited;
if FVScrollBar <> nil then FVScrollBar.Visible := Self.Visible;
if FHScrollBar <> nil then FHScrollBar.Visible := Self.Visible;
end;
procedure TspSkinCustomGrid.SetGridLineColor;
begin
FGridLineColor := Value;
if FIndex = -1 then RePaint;
end;
procedure TspSkinCustomGrid.Notification;
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FHScrollBar)
then FHScrollBar := nil;
if (Operation = opRemove) and (AComponent = FVScrollBar)
then FVScrollBar := nil;
end;
procedure TspSkinCustomGrid.SetHScrollBar;
begin
FHScrollBar := Value;
if FHScrollBar <> nil then
begin
FHScrollBar.Enabled := True;
FHScrollBar.Visible := False;
FHScrollBar.OnLastChange := OnHScrollBarChange;
FHScrollBar.OnUpButtonClick := OnHScrollBarUpButtonClick;
FHScrollBar.OnDownButtonClick := OnHScrollBarDownButtonClick;
FHScrollBar.OnPageUp := OnHScrollBarPageUp;
FHScrollBar.OnPageDown := OnHScrollBarPageDown;
end;
UpdateScrollRange;
end;
procedure TspSkinCustomGrid.SetVScrollBar;
begin
FVScrollBar := Value;
if FVScrollBar <> nil then
begin
FVScrollBar.Enabled := True;
FVScrollBar.Visible := False;
if goThumbTracking in Options
then
FVScrollBar.OnChange := OnVScrollBarChange
else
FVScrollBar.OnLastChange := OnVScrollBarChange;
FVScrollBar.OnUpButtonClick := OnVScrollBarUpButtonClick;
FVScrollBar.OnDownButtonClick := OnVScrollBarDownButtonClick;
FVScrollBar.OnPageUp := OnVScrollBarPageUp;
FVScrollBar.OnPageDown := OnVScrollBarPageDown;
end;
UpdateScrollRange;
end;
procedure TspSkinCustomGrid.OnVScrollBarChange(Sender: TObject);
begin
SendMessage(Handle, WM_VSCROLL,
MakeWParam(SB_THUMBPOSITION, FVScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.OnHScrollBarChange(Sender: TObject);
begin
SendMessage(Handle, WM_HSCROLL,
MakeWParam(SB_THUMBPOSITION, FHScrollBar.Position), 0);
end;
procedure TspSkinCustomGrid.SetParentImage;
begin
if FTransparent
then
begin
ParentImage.Width := Width;
ParentImage.Height := Height;
GetParentImage(Self, ParentImage.Canvas);
end;
end;
procedure TspSkinCustomGrid.SetTransparent;
begin
if FTransparent <> Value
then
begin
FTransparent := Value;
Invalidate;
end;
end;
function TspSkinCustomGrid.GetNewTextRect;
var
SR1, SR2, R: TRect;
OX, OY: Integer;
begin
if FIndex < 0
then
begin
Result := CellR;
Exit;
end
else
begin
R := CellR;
if gdFixed in AState
then
begin
SR1 := FixedCellRect;
SR2 := FixedCellTextRect;
end
else
begin
SR1 := SelectCellRect;
SR2 := CellTextRect;
end;
if not IsNullRect(SR2)
then
begin
if not UseSkinCellHeight
then
OY := RectHeight(R) - RectHeight(FixedCellRect)
else
OY := 0;
OX := RectWidth(CellR) - RectWidth(SR1);
Inc(R.Left, SR2.Left);
Inc(R.Top, SR2.Top);
R.Right := R.Left + RectWidth(SR2) + OX;
R.Bottom := R.Top + RectHeight(SR2) + OY;
end;
Result := R;
end
end;
procedure TspSkinCustomGrid.ChangeSkinData;
var
i, Old: Integer;
begin
GetSkinData;
if CursorIndex <> -1
then
Cursor := FSD.StartCursorIndex + CursorIndex
else
Cursor := crDefault;
if FIndex > -1
then
begin
Old := DefaultRowHeight;
i := SelectCellRect.Bottom - SelectCellRect.Top;
if (i <> Old) and FUseSkinCellHeight
then
DefaultRowHeight := i
else
Invalidate;
end
else
Invalidate;
end;
procedure TspSkinCustomGrid.GetSkinData;
begin
BGPicture := nil;
Picture := nil;
FIndex := -1;
inherited;
if FIndex > -1
then
if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinGridControl
then
with TspDataSkinGridControl(FSD.CtrlList.Items[FIndex]) do
begin
//
if (PictureIndex <> -1) and (PictureIndex < FSD.FActivePictures.Count)
then
Picture := TBitMap(FSD.FActivePictures.Items[PictureIndex])
else
Picture := nil;
//
Self.FixedCellRect := FixedCellRect;
Self.SelectCellRect := SelectCellRect;
Self.FocusCellRect := FocusCellRect;
Self.FixedCellLeftOffset := FixedCellLeftOffset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -