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

📄 jvginspectorgrid.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:

//=== { TJvgInspectorGrid } ==================================================

constructor TJvgInspectorGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FItems := TJvgGridItems.Create(TJvgGridItem);
  DefaultDrawing := False;
  DefaultRowHeight := 16; //Canvas.TextHeight('Th');
  ColCount := 2;
  FItems.OnUpdate := ItemsUpdate;
  Options := Options + [goEditing, goAlwaysShowEditor];
  CaptionTextAlignment := taLeftJustify;
end;

destructor TJvgInspectorGrid.Destroy;
begin
  FItems.Free;
  inherited Destroy;
end;

procedure TJvgInspectorGrid.DrawButton(ARow: Integer; Expanded: Boolean);
var
  R: TRect;
begin
  with Canvas do
  begin
    R := Bounds(2, (DefaultRowHeight + 1) * ARow + (DefaultRowHeight shr 1) - 3, 7, 7);
    FillRect(R);
    Pen.Color := clBlack;
    MoveTo(R.Left + 1, R.Top + 3);
    LineTo(R.Right - 1, R.Top + 3);
    if not Expanded then
    begin
      MoveTo(R.Left + 3, R.Top + 1);
      LineTo(R.Left + 3, R.Bottom - 1);
    end;
  end;
end;

procedure TJvgInspectorGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState);
var
  Item: TJvgGridItem;
begin
  inherited DrawCell(ACol, ARow, ARect, AState);
  //  if Items.Count <= ARow then Exit;
  if ACol = 1 then
    InvalidateCol(0);

  Item := RowToItem(ARow);
  if Assigned(Item) and (Item.Values.Count > 1) and (Item.Sequence = 0) then
    DrawButton(ARow, Item.Expanded);
end;

procedure TJvgInspectorGrid.GetCellGradientParams(Sender: TObject; ACol,
  ARow: Integer; var CellRect: TRect; var Gradient: TJvgGradient);
begin
  inherited GetCellGradientParams(Sender, ACol, ARow, CellRect, Gradient);
end;

procedure TJvgInspectorGrid.GetCellStyle(Sender: TObject; var ACol, ARow: Integer;
  var Style: TglGridCellStyle);
var
  //  ItemNo: Integer;
  Item: TJvgGridItem;
begin
  with Style do
  begin
    // inherited;
    // ItemNo := 0;
    BevelInner := bvNone;
    BevelOuter := bvSpace;
    BevelBold := False;

    Item := RowToItem(Row);
    if Item = nil then
      Exit;

    if ACol = 0 then
      BackgrColor := IIF(ARow = Row, clBtnShadow, DecColor(ColorToRGB(clBtnShadow), 20))
    else
      BackgrColor := clBtnFace;

    if not Hottracking then
    begin
      FontColor := IIF(ACol = 0, clWhite, clBlack);
      if (ACol = 0) and (ARow = Item.Row) then
        FontColor := clYellow;
    end;
    Interspace := IIF(ACol = 0, 13, 3);

    Item := RowToItem(ARow);
    if Item <> nil then
      if Item.HasChanged and (Item.IsChanged(Item.Sequence) or (Item.Sequence = 0)) then
        FontStyle := [fsBold]
      else
        FontStyle := [];
  end;

end;

{function TJvgInspectorGrid.GetEditText(ACol, ARow: Longint): string;
var
  I: Integer;
begin
  inherited GetEditText(ACol, ARow);
  for I := 0 to Items.Count-1 do
    Items[I].Selected := False;
  Items[ARow].Selected := True;
end;}

procedure TJvgInspectorGrid.ItemsUpdate(Sender: TObject);
var
  I, J: Integer;
begin
  SendMessage(handle, WM_SETREDRAW, 0, 0);

  RowCount := 1;
  for I := 0 to Items.Count - 1 do
  begin
    Items[I].Row := RowCount - 1;
    Cells[0, RowCount - 1] := Items[I].Caption;
    if Items[I].Values.Count = 1 then
    begin
      Cells[1, RowCount - 1] := Items[I].Values[0];
      if ColCount > 2 then
        Cells[2, RowCount - 1] := Items[I].OriginalValues[0];
    end
    else
    if Items[I].Values.Count > 1 then
    begin
      if ColCount > 2 then
        Cells[2, RowCount - 1] := '';
      Cells[1, RowCount - 1] := Items[I].GetValue;
      if Items[I].Expanded then
        for J := 0 to Items[I].Values.Count - 1 do
        begin
          RowCount := RowCount + 1;
          Cells[0, RowCount - 1] := '';
          Cells[1, RowCount - 1] := Items[I].Values[J];
          if ColCount > 2 then
            Cells[2, RowCount - 1] := Items[I].OriginalValues[J];
        end;
    end
    else
      Cells[1, RowCount - 1] := '';
    RowCount := RowCount + 1;
  end;
  RowCount := RowCount - 1;

  SendMessage(handle, WM_SETREDRAW, 1, 0);
  Invalidate; //Rect(Handle, nil, False);
end;

procedure TJvgInspectorGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
type
  PClass = ^TClass;
var
  GridCoord: TGridCoord;
  Item: TJvgGridItem;
begin
  //...inherit grandfather
{  ClassOld := PClass(Self)^;
  PClass(Self)^ := Self.ClassParent.ClassParent;
  Self.MouseDown(Button, Shift, X, Y);
  PClass(Self)^ := ClassOld;}
  inherited MouseDown(Button, Shift, X, Y);

  GridCoord := MouseCoord(X, Y);
  if GridCoord.X = 0 then
  begin
    Item := RowToItem(GridCoord.Y);
    if Item = nil then
      Exit;
    if Item.Sequence = 0 then
      Item.Expanded := not Item.Expanded;
    Row := GridCoord.Y;
  end;
end;

function TJvgInspectorGrid.RowToItem(ARow: Integer): TJvgGridItem;
var
  I, Index: Integer;
begin
  Index := 0;
  //  I := 0;
  Result := nil;
  if Items.Count = 0 then
    Exit;
  for I := 0 to ARow - 1 do
  begin
    if Items[I].Expanded then
      Inc(Index, Items[I].Values.Count);
    Inc(Index);
    if Index > ARow then
      Break;
  end;

  Result := Items[I];
  Result.Sequence := ARow - ItemToRow(Result);
end;

function TJvgInspectorGrid.ItemToRow(Item: TJvgGridItem): Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := 0 to Item.Index - 1 do
  begin
    if Items[I].Expanded then
      Inc(Result, Items[I].Values.Count);
    Inc(Result);
  end;
end;

function TJvgInspectorGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
  Result := True;
  if Assigned(OnSelectCell) then
    OnSelectCell(Self, ACol, ARow, Result);
  // if Items.FShowMultiValues and (Items[ARow].Values.Count > 1) then
 //   Result := False;
end;

function TJvgInspectorGrid.CanEditModify: Boolean;
var
  Item: TJvgGridItem;
begin
  Result := False;
  // (rom) deactivated  Result is already false
  //if (Col <> 1) or not (goEditing in Options) then
  //  Result := False;
  Item := RowToItem(Row);
  if Item <> nil then
    Result := not (Items.FShowMultiValues and (Item.Values.Count > 1) and (Item.Row = Row));
end;

procedure TJvgInspectorGrid.SetEditText(ACol, ARow: Integer; const Value: string);
var
  Item: TJvgGridItem;
begin
  inherited SetEditText(ACol, ARow, Value);
  if Assigned(OnSetEditText) then
    OnSetEditText(Self, ACol, ARow, Value);
  Item := RowToItem(ARow);
  if Item = nil then
    Exit;
  //  if Value <> Item.Values[Item.Sequence] then Item.Changed := True;// Values.Data :=
  Item.SetValue(Item.Sequence, Value);

  if Item.Sequence > 0 then
    Cells[1, Item.Row] := Item.GetValue;
  //  Item.Changed := Item.Changed or ;
    //Cells[1, ARow] := Value;
end;

procedure TJvgInspectorGrid.KeyPress(var Key: Char);
var
  Item: TJvgGridItem;
  I, OldRow: Integer;
begin
  inherited;
  Item := RowToItem(Row);
  if Item = nil then
    Exit;
  OldRow := Row;
  case Key of
    '+':
      if (Item.Values.Count > 0) and not Item.Expanded then
        Item.Expanded := True;
    '-':
      if (Item.Values.Count > 0) and Item.Expanded and (Row = ItemToRow(Item)) then
        Item.Expanded := False;
    '*':
      for I := 0 to Items.Count - 1 do
        Items[I].Expanded := True;
  end;
  Row := OldRow;
end;

procedure TJvgInspectorGrid.UndoAll;
var
  I: Integer;
begin
  for I := 0 to Items.Count - 1 do
    Items[I].UndoAll;
end;

procedure TJvgInspectorGrid.UndoCurent;
begin
  RowToItem(Row).UndoAll;
end;

procedure TJvgInspectorGrid.WMSize(var Msg: TWMSize);
var
  I, FreeClientWidth: Integer;
begin
  inherited;
  FreeClientWidth := Width;
  I := GetScrollPos(handle, SB_VERT);
  if I <> 0 then
    Dec(FreeClientWidth, GetSystemMetrics(SM_CXHSCROLL) + 2);
  ColWidths[1] := FreeClientWidth - ColWidths[0];
end;

function TJvgInspectorGrid.GetEditMask(ACol, ARow: Integer): string;
var
  Item: TJvgGridItem;
begin
  Item := RowToItem(ARow);
  if Item = nil then
    Exit;
  if CanEditModify then
    Result := Item.EditMask
  else
    Result := '';
  if Assigned(OnGetEditMask) then
    OnGetEditMask(Self, ACol, ARow, Result);
end;

{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
initialization
  RegisterUnitVersion(HInstance, UnitVersioning);

finalization
  UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}

end.

⌨️ 快捷键说明

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