⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skingrids.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 5 页
字号:

destructor TspSkinCustomGrid.Destroy;
begin
  FHScrollBar := nil;
  FVScrollBar := nil;
  FInplaceEdit.Free;
  inherited Destroy;
  FreeMem(FColWidths);
  FreeMem(FRowHeights);
  FreeMem(FTabStops);
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;
  end;
  UpdateScrollRange;
end;

procedure TspSkinCustomGrid.SetVScrollBar;
begin
  FVScrollBar := Value;
  if FVScrollBar <> nil then
  begin
    FVScrollBar.Enabled := True;
    FVScrollBar.Visible := False;
    FVScrollBar.OnLastChange := OnVScrollBarChange;
    FVScrollBar.OnUpButtonClick := OnVScrollBarUpButtonClick;
    FVScrollBar.OnDownButtonClick := OnVScrollBarDownButtonClick;
  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: 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
          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);
        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
      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;
        Self.FixedCellRightOffset := FixedCellRightOffset;
        Self.FixedCellTextRect := FixedCellTextRect;
        Self.CellLeftOffset := CellLeftOffset;
        Self.CellRightOffset := CellRightOffset;
        Self.CellTextRect := CellTextRect;
        Self.LinesColor := LinesColor;
        Self.BGColor := BGColor;
        Self.BGPictureIndex := BGPictureIndex;
        //
        if (BGPictureIndex <> -1) and (BGPictureIndex < FSD.FActivePictures.Count)
        then
          BGPicture := TBitMap(FSD.FActivePictures.Items[BGPictureIndex])
        else
          BGPicture := nil;
        //
        Self.FontName := FontName;
        Self.FontStyle := FontStyle;
        Self.FontHeight := FontHeight;
        Self.FontColor := FontColor;
        Self.SelectFontColor := SelectFontColor;
        Self.FocusFontColor := FocusFontColor;
        Self.FixedFontName := FixedFontName;
        Self.FixedFontStyle := FixedFontStyle;
        Self.FixedFontHeight := FixedFontHeight;
        Self.FixedFontColor := FixedFontColor;

        if IsNullRect(Self.SelectCellRect)
        then
          Self.SelectCellRect := Self.FocusCellRect; 
        if IsNullRect(Self.FocusCellRect)
        then
          Self.FocusCellRect := Self.SelectCellRect;

        if IsNullRect(Self.FixedCellRect)
        then
          begin
            FIndex := -1;
            BGPicture := nil;
            Picture := nil;
          end;
          
      end;
end;

procedure TspSkinCustomGrid.PaintWallPaper;
var
  X, Y, XCnt, YCnt: Integer;
begin
  if (BGPicture.Width <> 0) and(BGPicture.Height <> 0) then
  begin
    XCnt := Width div BGPicture.Width;
    YCnt := Height div BGPicture.Height;
    for X := 0 to XCnt do
    for Y := 0 to YCnt do
      C.Draw(X * BGPicture.Width, Y * BGPicture.Height,
                            BGPicture);
  end;
end;

procedure TspSkinCustomGrid.AdjustSize(Index, Amount: Longint; Rows: Boolean);
var
  NewCur: TGridCoord;
  OldRows, OldCols: Longint;
  MovementX, MovementY: Longint;
  MoveRect: TGridRect;
  ScrollArea: TRect;
  AbsAmount: Longint;

  function DoSizeAdjust(var Count: Longint; var Extents: Pointer;
    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, PIntArray(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);
  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
    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
    ScrollWindow(Handle, MovementX, MovementY, @ScrollArea, @ScrollArea);
    UpdateWindow(Handle);
  end;
  SizeChanged(OldCols, OldRows);
  if (NewCur.X <> FCurrent.X) or (NewCur.Y <> FCurrent.Y) then
    MoveCurrent(NewCur.X, NewCur.Y, True, True);
end;

function TspSkinCustomGrid.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 TspSkinCustomGrid.DoExit;
begin
  inherited DoExit;
  if not (goAlwaysShowEditor in Options) then HideEditor;
end;

function TspSkinCustomGrid.CellRect(ACol, ARow: Longint): TRect;
begin
  Result := BoxRect(ACol, ARow, ACol, ARow);
end;

function TspSkinCustomGrid.CanEditAcceptKey(Key: Char): Boolean;
begin
  Result := True;
end;

function TspSkinCustomGrid.CanGridAcceptKey(Key: Word; Shift: TShiftState): Boolean;
begin
  Result := True;
end;

function TspSkinCustomGrid.CanEditModify: Boolean;
begin
  Result := FCanEditModify;
end;

function TspSkinCustomGrid.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 TspSkinCustomGrid.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 TspSkinCustomGrid.GetEditMask(ACol, ARow: Longint): string;
begin
  Result := '';
end;

function TspSkinCustomGrid.GetEditText(ACol, ARow: Longint): string;
begin
  Result := '';
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -