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

📄 wzgrid.pas

📁 delphi控件的使用
💻 PAS
📖 第 1 页 / 共 4 页
字号:
        end;
        FActiveList := FPickList;}
      end;
  else
//    FActiveList := nil;
  end;
  with TWzGrid(Grid) do
    Self.ReadOnly := Columns[SelectedIndex].ReadOnly;
  Repaint;
end;

procedure TWzInplaceEdit.UpdateContents;
var
  Column: TColumn;
  NewStyle: TEditStyle;
begin
  with TWzGrid(Grid) do Column := Columns[SelectedIndex];
  NewStyle := esSimple;
//  NewStyle := esEllipsis;
{  case Column.ButtonStyle of
   cbsEllipsis : NewStyle := esEllipsis;
   cbsAuto : if  Assigned(Column.Picklist)
             and (Column.PickList.Count > 0)
             and not Column.Readonly then
               NewStyle := esPickList;
   end;
}  EditStyle := NewStyle;

  //SetImeMode( Column.ImeMode );
  //ImeMode := Column.ImeMode;
  //SetImeStatus( ImeMode );

  inherited UpdateContents;
end;

procedure TWzInplaceEdit.BoundsChanged;
var
  R: TRect;
begin
  SetRect(R, 2, 2, Width - 2, Height);
//if FEditStyle <> esSimple then Dec(R.Right, FButtonWidth);
  SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@R));
  SendMessage(Handle, EM_SCROLLCARET, 0, 0);
end;



//********************************
// TWzGrid
//********************************
constructor TWzGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//  inherited DefaultDrawing := False;

  FOptions := [dgEditing, dgTitles, dgIndicator, dgColumnResize,
               dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit,
               dgColumnMove,dgRowMove];

  inherited Options := [goFixedHorzLine, goFixedVertLine, goHorzLine,
                        goVertLine, goColSizing, goColMoving, goTabs, goEditing,
                        goColMoving,goRowMoving];

  FIndicatorOffset := 1;
  inherited ColCount := 2;
  inherited RowCount := 2;
  FSaveCellExtents := False;

  FLineName := TStringList.Create;

  FColumns := CreateColumns;
  Color := clWindow;
  ParentColor := False;
  FColumns.Add;
  FDefaultDrawing := True;
  HideEditor;
end;

destructor TWzGrid.Destroy;
begin
  FColumns.Free;
  FColumns := nil;
{  DataList.Free;
  DataList := nil;}
  FLineName.Free;
{  FIndicators.Free;
  FTitleFont.Free;
  FTitleFont := nil;}
  inherited Destroy;
//  ReleaseBitmap;
end;

procedure TWzGrid.ColExit;
begin
  if Assigned(FOnColExit) then FOnColExit(Self);
end;

function  TWzGrid.CanEditShow: Boolean;
var be1 : Boolean;
    be2 : Boolean;
    be3 : Boolean;
    be5 : Boolean;
begin

{  be1 := ([goRowSelect, goEditing] * Options = [goEditing]);
  be2 := TCustomGrid.FEditorMode ;
  be3 := not (csDesigning in ComponentState);}
  be4 := HandleAllocated;
  be4 := IsActiveControl(Self);
//  be5 := ((goAlwaysShowEditor in Options) or IsActiveControl);

  Result := (LayoutLock = 0) and inherited CanEditShow;
  be4 := Result;

//  Result := True;
end;

procedure TWzGrid.ColWidthsChanged;
var
  I,W : Integer;
begin
  inherited ColWidthsChanged;
  if {(FColumns.State = csCustomized) and }AcquireLayoutLock then begin
    try
      Canvas.Font := Font;
      W := Canvas.TextWidth( '0' );
      for I := FIndicatorOffset to ColCount - 1 do
        FColumns[I - FIndicatorOffset].Width := ( ColWidths[I] + W div 2 - 4 ) div W;
    finally
      EndLayout;
    end
  end;
end;

procedure TWzGrid.ColEnter;
begin
  if Assigned(FOnColEnter) then FOnColEnter(Self);
end;

function  TWzGrid.CanEditModify: Boolean;
begin
  Result := False;
  if not ReadOnly then
  with Columns[SelectedIndex] do
    if not ReadOnly then begin
      Result := True;
    end;
end;

function TWzGrid.GetSelectedIndex: Integer;
begin
  Result := RawToDataColumn(Col);
end;

function  TWzGrid.RawToDataColumn(ACol: Integer): Integer;
begin
  Result := ACol - FIndicatorOffset;
end;

procedure TWzGrid.SetSelectedIndex(Value: Integer);
begin
  MoveCol(DataToRawColumn(Value), 0);
end;

procedure TWzGrid.MoveCol(RawCol, Direction: Integer);
var
  OldCol: Integer;
begin
//  FDatalink.UpdateData;
try
  BeginLayout;
  if RawCol >= ColCount then RawCol := ColCount - 1;
  if RawCol < FIndicatorOffset then RawCol := FIndicatorOffset;
  if Direction <> 0 then begin
    while (RawCol < ColCount) and (RawCol >= FIndicatorOffset) and
      (ColWidths[RawCol] <= 0) do
      Inc(RawCol, Direction);
    if (RawCol >= ColCount) or (RawCol < FIndicatorOffset) then Exit;
  end;
  OldCol := Col;
  if RawCol <> OldCol then begin
    if not FInColExit then begin
      FInColExit := True;
      try
        ColExit;
      finally
        FInColExit := False;
      end;
      if Col <> OldCol then Exit;
    end;
    if not (dgAlwaysShowEditor in Options) then HideEditor;
    Col := RawCol;
    ColEnter;
  end;
finally
  EndLayout;
end;
end;

procedure TWzGrid.CMExit(var Message: TMessage);
var ChkMode : boolean;
begin
  try
//    if Assigned( OnRowExit ) then OnRowExit( Self );
    {if not ChkRecord( TRUE ) then begin
      SetFocus;
      Abort;
    end;}

    MoveCol( FIndicatorOffset,0 );
//    Row := FTitleOffset;//MoveRow( FTitleOffset );
//    if FExitReset then Row := FTitleOffset;//MoveRow( FTitleOffset );
  except
    SetFocus;
    Abort;
  end;
  inherited;
end;

procedure TWzGrid.HideEdit;
begin
  HideEditor;
end;

procedure  TWzGrid.DefaultDrawColumnCell(const Rect: TRect;
      Value: string; Column: TColumn; State: TGridDrawState);
begin
  WriteText(Canvas, Rect, 2, 2, Value, Column.Alignment);
end;

function  TWzGrid.GetSlRow : integer;
begin
  Result := Row-FTitleOffset;
end;

procedure TWzGrid.SetSlRow( Value : integer );
begin
//  MoveRow( Value + FTitleOffset );
end;

function  TWzGrid.CreateColumns: TWzGridColumns;
begin
  Result := TWzGridColumns.Create(Self, TColumn);
end;

procedure TWzGrid.SetColumns(Value: TWzGridColumns);
begin
  Columns.Assign(Value);
end;

function  TWzGrid.CreateEditor: TInplaceEdit;
begin
  Result := TWzInplaceEdit.Create(Self);
end;

procedure TWzGrid.KeyDown(var Key: Word; Shift: TShiftState);

  procedure Tab( ToForward : boolean );
  var OrgCol, ACol, OrgRow, ARow : integer;
  begin
    ACol := Col;
    ARow := Row;
    while True do begin
      if ToForward then Inc(ACol) else Dec(ACol);

      if ACol >= ColCount then begin
        ACol := FIndicatorOffset;
        Inc(ARow);
      end;

      if TabStops[ACol] then begin
        MoveCol(ACol, 0);
        Break;
      end;
    end;
    if ARow >= RowCount then begin
      if Assigned( OnGoNext ) then OnGoNext( Self );
      SelectNextCtrl(Self,True);
      exit;
    end;
    Col := ACol;
    Row := ARow;
  end;

begin
  case Key of
  VK_RETURN
    : begin
      if EditorMode = True then Tab( True );
      if Columns[RawToDataColumn(Col)].AutoSelect then
        ShowEditor
      else begin
        EditorMode := TRUE;
        InplaceEditor.SelStart := 0;
        InplaceEditor.SelLength:= 1;
      end;
//      InplaceEditor.SelStart := 0;
//      InplaceEditor.SelLength:= 1;
      end;
  end;
//inherited KeyDown(Key, Shift);
end;

procedure TWzGrid.LayoutChanged;
begin
  if AcquireLayoutLock then EndLayout;
end;

procedure TWzGrid.CMDeferLayout(var Message);
begin
  if AcquireLayoutLock then
    EndLayout
  else
    DeferLayout;
end;

procedure TWzGrid.SetLineName(Value: TStrings);
begin
  BeginLayout;
  FLineName.Assign(Value);
  EndLayout;
end;

procedure TWzGrid.DeferLayout;
var
  M: TMsg;
begin
  if not PeekMessage(M, Handle, cm_DeferLayout, cm_DeferLayout, pm_NoRemove) then
    PostMessage(Handle, cm_DeferLayout, 0, 0);
  CancelLayout;
end;

procedure TWzGrid.CancelLayout;
begin
  if FLayoutLock > 0 then begin
    if FLayoutLock = 1 then Columns.EndUpdate;
    Dec(FLayoutLock);
    EndUpdate;
  end;
end;

procedure TWzGrid.BeginLayout;
begin
  BeginUpdate;
  if (FLayoutLock = 0) then Columns.BeginUpdate;
  Inc(FLayoutLock);
end;

procedure TWzGrid.EndLayout;
begin
  if FLayoutLock > 0 then begin
    try
      try
        if FLayoutLock = 1 then
          InternalLayout;
      finally
        if FLayoutLock = 1 then
          FColumns.EndUpdate;
      end;
    finally
      Dec(FLayoutLock);
      EndUpdate;
    end;
  end;
end;

procedure TWzGrid.BeginUpdate;
begin
  Inc(FUpdateLock);
end;

procedure TWzGrid.EndUpdate;
begin
  if FUpdateLock > 0 then Dec(FUpdateLock);
end;

procedure TWzGrid.InternalLayout;
var
  I, J, K: Integer;
  Column: TColumn;
  SeenPassthrough: Boolean;
  RestoreCanvas: Boolean;
  M: TMsg;
begin
  if (csLoading in ComponentState) then Exit;

  if HandleAllocated then
    PeekMessage(M, Handle, cm_DeferLayout, cm_DeferLayout, pm_Remove or pm_NoYield);

  FIndicatorOffset:= 0;
  if dgIndicator in Options then Inc( FIndicatorOffset );

  ColCount := FColumns.Count + FIndicatorOffset;
  inherited FixedCols := FIndicatorOffset;

  FTitleOffset := 0;
  if dgTitles in Options then FTitleOffset := 1;

  RestoreCanvas := not HandleAllocated;
  if RestoreCanvas then
    Canvas.Handle := GetDC(0);
  try
    Canvas.Font := Font;
    K := Canvas.TextHeight('Wg') + 3;
    if dgRowLines in Options then
      Inc(K, GridLineWidth);
    DefaultRowHeight := K;
{    if dgTitles in Options then begin
      K := 0;
      for I := 0 to FColumns.Count-1 do begin
        Canvas.Font := FColumns[I].Title.Font;

        J := Canvas.TextHeight('Wg') + 4;
        if J > K then K := J;
      end;
      if K = 0 then begin
        Canvas.Font.Assign( FTitleFont );
        K := Canvas.TextHeight('Wg') + 4;
      end;
      RowHeights[0] := K;
    end;}
    SetColumnAttributes;
  finally

⌨️ 快捷键说明

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