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

📄 bsskingrids.pas

📁 BusinessSkinForm的控件包与实例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
end;

function LongMulDiv(Mult1, Mult2, Div1: Longint): Longint; stdcall;
  external 'kernel32.dll' name 'MulDiv';

type
  TSelection = record
    StartPos, EndPos: Integer;
  end;

constructor TbsSkinTransparentMaskEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csOpaque];
  FTransparent := False;
  FDown := False;
end;

procedure TbsSkinTransparentMaskEdit.SetTransparent;
begin
  if FTransparent <> Value
  then
    begin
      FTransparent := Value;
      ReCreateWnd;
    end;
end;

procedure TbsSkinTransparentMaskEdit.InvalidateEdit;
var
  R: TRect;
begin
  if Parent = nil then Exit;
  R := ClientRect;
  R.TopLeft := Parent.ScreenToClient(ClientToScreen(R.TopLeft));
  R.BottomRight := Parent.ScreenToClient(ClientToScreen(R.BottomRight));
  InvalidateRect(Parent.Handle, @R, true);
  RedrawWindow(Handle, nil, 0, RDW_FRAME + RDW_INVALIDATE);
end;

procedure TbsSkinTransparentMaskEdit.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  if FTransparent
  then
    with Params do
      ExStyle := ExStyle or WS_EX_TRANSPARENT
  else
    inherited;
end;

procedure TbsSkinTransparentMaskEdit.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);
begin
  if FTransparent
  then
    with Message do
    begin
      SetBkMode(ChildDC, Windows.Transparent);
      SetTextColor(ChildDC, Font.Color);
      Result := GetStockObject(HOLLOW_BRUSH);
    end
  else
    inherited;
end;

procedure TbsSkinTransparentMaskEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  if FTransparent then Invalidate else inherited;
end;

procedure TbsSkinTransparentMaskEdit.DoExit;
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.DoEnter;
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMKeyDown(var Message: TWMKeyDown);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMSetText(var Message:TWMSetText);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMMove(var Message: TMessage);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMCut(var Message: TMessage);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMPaste(var Message: TMessage);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMClear(var Message: TMessage);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMUndo(var Message: TMessage);
begin
  inherited;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMLButtonDown(var Message: TWMKeyDown);
begin
  inherited;
  FDown := True;
  if FTransparent then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMMOUSEMOVE;
begin
  inherited;
  if FDown then Invalidate;
end;

procedure TbsSkinTransparentMaskEdit.WMLButtonUp;
begin
  inherited;
  FDown := False;
end;

procedure TbsSkinTransparentMaskEdit.Invalidate;
begin
  if FTransparent then InvalidateEdit else inherited;
end;

constructor TbsSkinInplaceEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ParentCtl3D := False;
  Ctl3D := False;
  TabStop := False;
  BorderStyle := bsNone;
  FSysPopupMenu := nil;
end;

destructor TbsSkinInplaceEdit.Destroy;
begin
  if FSysPopupMenu <> nil then FSysPopupMenu.Free;
  inherited;
end;

procedure TbsSkinInplaceEdit.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 TbsSkinInplaceEdit.WMAFTERDISPATCH;
begin
  if FSysPopupMenu <> nil
  then
    begin
      FSysPopupMenu.Free;
      FSysPopupMenu := nil;
    end;
end;

procedure TbsSkinInplaceEdit.DoUndo;
begin
  Undo;
end;

procedure TbsSkinInplaceEdit.DoCut;
begin
  CutToClipboard;
end;

procedure TbsSkinInplaceEdit.DoCopy;
begin
  CopyToClipboard;
end;

procedure TbsSkinInplaceEdit.DoPaste;
begin
  PasteFromClipboard;
end;

procedure TbsSkinInplaceEdit.DoDelete;
begin
  ClearSelection;
end;

procedure TbsSkinInplaceEdit.DoSelectAll;
begin
  SelectAll;
end;

procedure TbsSkinInplaceEdit.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 := TbsSkinPopupMenu.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 := BS_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 := BS_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 := BS_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 := BS_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 := BS_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 := BS_Edit_SelectAll;
    Enabled := not IsFullSelected;
    OnClick := DoSelectAll;
  end;
  FSysPopupMenu.Items.Add(Item);
end;

procedure TbsSkinInplaceEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  if not Transparent then inherited;
end;

procedure TbsSkinInplaceEdit.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style or ES_MULTILINE;
end;

procedure TbsSkinInplaceEdit.SetGrid(Value: TbsSkinCustomGrid);
begin
  FGrid := Value;
end;

procedure TbsSkinInplaceEdit.CMShowingChanged(var Message: TMessage);
begin
end;

procedure TbsSkinInplaceEdit.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  inherited;
  if goTabs in Grid.Options then
    Message.Result := Message.Result or DLGC_WANTTAB;
end;

procedure TbsSkinInplaceEdit.WMPaste(var Message);
begin
  if not EditCanModify then Exit;
  inherited
end;

procedure TbsSkinInplaceEdit.WMClear(var Message);
begin
  if not EditCanModify then Exit;
  inherited;
end;

procedure TbsSkinInplaceEdit.WMCut(var Message);
begin
  if not EditCanModify then Exit;
  inherited;
end;

procedure TbsSkinInplaceEdit.DblClick;
begin
  Grid.DblClick;
end;

function TbsSkinInplaceEdit.EditCanModify: Boolean;
begin
  Result := Grid.CanEditModify;
end;

procedure TbsSkinInplaceEdit.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;

⌨️ 快捷键说明

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