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

📄 rm_propinsp.pas

📁 这是一个功能强大
💻 PAS
📖 第 1 页 / 共 5 页
字号:
end;

function TELCustomPropsPage.DoMouseWheelDown(Shift: TShiftState;
  MousePos: TPoint): Boolean;
begin
  Result := True;
  if TopRow < RowCount - VisibleRowCount then
    TopRow := TopRow + 1;
end;

function TELCustomPropsPage.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
  Result := True;
  if TopRow > FixedRows then
    TopRow := TopRow - 1;
end;

procedure TELCustomPropsPage.CreateHandle;
begin
  inherited;
  UpdateScrollBar;
  ShowEditor;
  UpdateColWidths;
end;

function TELCustomPropsPage.GetEditStyle(ACol, ARow: Integer): TEditStyle;
var
  LItem: TELPropsPageItem;
begin
  LItem := ItemByRow(ARow);
  if LItem <> nil then
    Result := LItem.EditStyle
  else
    Result := esSimple;
end;

procedure TELCustomPropsPage.MouseMove(Shift: TShiftState; X, Y: Integer);
var
  LGridCoord: TGridCoord;
begin
  if not (ppsMovingSplitter in FState) then
  begin
    inherited;
    if MouseCapture then
    begin
      LGridCoord := MouseCoord(X, Y);
      if (LGridCoord.Y <> -1) then
        Row := LGridCoord.Y
      else
        if Y < 0 then
        begin
          if Row > 0 then
            Row := Row - 1;
        end
        else
        begin
          if Row < RowCount - 1 then
            Row := Row + 1;
        end

    end;
  end;

  if ppsMovingSplitter in FState then
    Splitter := X - FSplitterOffset;

  if FCellHints = True then
    DoHint(X, Y);
end;

function TELCustomPropsPage.IsOnSplitter(AX: Integer): Boolean;
begin
  Result := (AX >= ColWidths[0] - 4) and (AX <= ColWidths[0]);
end;

procedure TELCustomPropsPage.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  LGridCoord: TGridCoord;
  LCellRect: TRect;
  LItem: TELPropsPageItem;
begin
  if ssLeft in Shift then
  begin
    if IsOnSplitter(X) then
    begin
      Include(FState, ppsMovingSplitter);
      FSplitterOffset := X - ColWidths[0];
    end
    else
    begin
      inherited;
      LGridCoord := MouseCoord(X, Y);
      if (LGridCoord.X = 0) and (LGridCoord.Y <> -1) then
      begin
        LCellRect := CellRect(LGridCoord.X, LGridCoord.Y);
        LItem := ItemByRow(LGridCoord.Y);
        if (LItem <> nil) and LItem.CanExpand and LItem.IsOnExpandButton(X) then
        begin
          Row := LGridCoord.Y;
          if LItem.Expanded then
            LItem.Collapse
          else
            LItem.Expand;
        end
        else
          if (LGridCoord.Y < TopRow + VisibleRowCount) then
            Row := LGridCoord.Y;
      end;
    end;
  end;
end;

procedure TELCustomPropsPage.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  LForm: TCustomForm;
begin
  if ppsMovingSplitter in FState then
    if csDesigning in ComponentState then
    begin
      LForm := GetParentForm(Self);
      if (LForm <> nil) and (LForm.Designer <> nil) then
        LForm.Designer.Modified;
    end
    else
      inherited;
  Exclude(FState, ppsMovingSplitter);
end;

procedure TELCustomPropsPage.UpdateColWidths;
begin
  ColWidths[1] := Width - ColWidths[0];
end;

procedure TELCustomPropsPage.UpdateScrollBar;
var
  LSI: TScrollInfo;
begin
  if HandleAllocated then
  begin
    LSI.cbSize := SizeOf(LSI);
    LSI.fMask := SIF_ALL;
    GetScrollInfo(Self.Handle, SB_VERT, LSI);
    LSI.nPage := VisibleRowCount;
    LSI.nMin := 0;
    LSI.nMax := RowCount - 1;
    LSI.nPos := TopRow;
    SetScrollInfo(Self.Handle, SB_VERT, LSI, True);
  end;
end;

procedure TELCustomPropsPage.WMVScroll(var Message: TWMVScroll);
var
  LTopRow: Integer;
  LSI: TScrollInfo;
begin
  LTopRow := TopRow;
  with Message do
    case ScrollCode of
      SB_LINEUP: LTopRow := LTopRow - 1;
      SB_LINEDOWN: LTopRow := LTopRow + 1;
      SB_PAGEUP: LTopRow := LTopRow - VisibleRowCount;
      SB_PAGEDOWN: LTopRow := LTopRow + VisibleRowCount;
      SB_THUMBPOSITION, SB_THUMBTRACK:
        begin
          LSI.cbSize := SizeOf(LSI);
          LSI.fMask := SIF_ALL;
          GetScrollInfo(Self.Handle, SB_VERT, LSI);
          LTopRow := LSI.nTrackPos;
        end;
      SB_BOTTOM: LTopRow := RowCount - 1;
      SB_TOP: LTopRow := 0;
    end;
  if LTopRow < 0 then
    LTopRow := 0;
  if LTopRow > RowCount - VisibleRowCount then
    LTopRow := RowCount - VisibleRowCount;
  TopRow := LTopRow;
  UpdateScrollBar;
  Message.Result := 0;
end;

procedure TELCustomPropsPage.TopLeftChanged;
begin
  inherited;
  UpdateScrollBar;
end;

procedure TELCustomPropsPage.SizeChanged(OldColCount, OldRowCount: Integer);
begin
  inherited;
  AdjustTopRow;
  UpdateScrollBar;
  ShowEditor;
end;

procedure TELCustomPropsPage.WMSize(var Message: TWMSize);
begin
  inherited;
  AdjustTopRow;
  UpdateScrollBar;
  Splitter := Splitter; // Include UpdateColWidths;
  ShowEditor;
end;

procedure TELCustomPropsPage.AdjustTopRow;
var
  LI: Integer;
begin
  if HandleAllocated then
  begin
    LI := ClientHeight div DefaultRowHeight;
    if RowCount - TopRow < LI then
    begin
      LI := RowCount - LI;
      if LI < 0 then
        LI := 0;
      TopRow := LI;
    end;
  end;
end;

destructor TELCustomPropsPage.Destroy;
begin
  Include(FState, ppsDestroying);
  FItems.Free;
  FBitmap.Free;
  FCellBitmap.Free;
//  if FBrush <> 0 then
//    DeleteObject(FBrush);
  inherited;
end;

procedure TELCustomPropsPage.ItemsChange;

  procedure _FillRows(AList: TELObjectList);
  var
    LI: Integer;
  begin
    for LI := 0 to AList.Count - 1 do
    begin
      SetLength(FRows, Length(FRows) + 1);
      FRows[High(FRows)] := TELPropsPageItem(AList[LI]);
      TELPropsPageItem(AList[LI]).FRow := High(FRows);
      if TELPropsPageItem(AList[LI]).Expanded then
        _FillRows(TELObjectList(AList[LI]));
    end;
  end;

var
  LI: Integer;
  LActiveItem: TELPropsPageItem;

begin
  if (FUpdateCount <= 0) and not (ppsDestroying in FState) then
  begin
    LActiveItem := ActiveItem;
    for LI := 0 to High(FRows) do
      if FRows[LI] <> nil then
        FRows[LI].FRow := -1;
    SetLength(FRows, 0);
    _FillRows(Items);
    RowCount := Length(FRows);
    while LActiveItem <> nil do
    begin
      if LActiveItem.FRow <> -1 then
      begin
        if Row <> LActiveItem.FRow then
          Row := LActiveItem.FRow;
        Break;
      end;
      LActiveItem := LActiveItem.Parent;
    end;
    Invalidate;
    LActiveItem := ActiveItem;
    if InplaceEditor <> nil then
    begin
      if LActiveItem <> nil then
      begin
        if (TELPropsPageInplaceEdit(InplaceEditor).ReadOnlyStyle <> LActiveItem.ReadOnly) or
          (TELPropsPageInplaceEdit(InplaceEditor).EditStyle <> LActiveItem.EditStyle) then
          InvalidateEditor;
        InplaceEditor.Text := LActiveItem.DisplayValue;
      end
      else
      begin
        if not TELPropsPageInplaceEdit(InplaceEditor).ReadOnlyStyle or
          (TELPropsPageInplaceEdit(InplaceEditor).EditStyle <> esSimple) then
          InvalidateEditor;
        InplaceEditor.Text := '';
      end;
      FEditText := InplaceEditor.Text;
    end;
    Update;
  end
  else
    Include(FState, ppsChanged);
end;

function TELCustomPropsPage.GetActiveItem: TELPropsPageItem;
var
  LItem: TELPropsPageItem;
begin
  LItem := ItemByRow(Row);
  if LItem <> nil then
    Result := LItem
  else
    Result := nil;
end;

procedure TELCustomPropsPage.WMLButtonDblClk(var Message: TWMLButtonDblClk);
var
  LGridCoord: TGridCoord;
  LCellRect: TRect;
  LItem: TELPropsPageItem;
begin
  inherited;
  LGridCoord := MouseCoord(Message.XPos, Message.YPos);
  if (LGridCoord.X = 0) and (LGridCoord.Y <> -1) then
  begin
    LCellRect := CellRect(LGridCoord.X, LGridCoord.Y);
    LItem := ItemByRow(LGridCoord.Y);
    if (LItem <> nil) and not LItem.IsOnExpandButton(Message.XPos) then
      if LItem.Expanded then
        LItem.Collapse
      else
        LItem.Expand;
  end;
end;

function TELCustomPropsPage.CreateItem(AParent: TELPropsPageItem): TELPropsPageItem;
begin
  Result := TELPropsPageItem.Create(Self, AParent);
end;

function TELCustomPropsPage.CanEditModify: Boolean;
begin
  Result := (ActiveItem <> nil) and not ActiveItem.ReadOnly;
end;

function TELCustomPropsPage.GetEditText(ACol, ARow: Integer): string;
var
  LItem: TELPropsPageItem;
begin
  LItem := ItemByRow(ARow);
  if (ACol = 1) and (LItem <> nil) then
    Result := LItem.DisplayValue;
  FEditText := Result;
end;

procedure TELCustomPropsPage.SetEditText(ACol, ARow: Integer; const Value: string);
var
  LItem: TELPropsPageItem;
begin
  if not (ppsUpdatingEditorContent in FState) then
  begin
    LItem := ItemByRow(ARow);
    if (ACol = 1) and (LItem <> nil) and LItem.AutoUpdate then
      LItem.DisplayValue := Value;
    FEditText := Value;
  end;
end;

function TELCustomPropsPage.ItemByRow(ARow: Integer): TELPropsPageItem;
begin
  if (ARow >= 0) and (ARow <= High(FRows)) then
    Result := FRows[ARow]
  else
    Result := nil;
end;

procedure TELCustomPropsPage.UpdateData(ARow: Integer);
var
  LItem: TELPropsPageItem;
begin
  LItem := ItemByRow(ARow);
  if LItem <> nil then
  try
    LItem.DisplayValue := FEditText;
    FEditText := LItem.DisplayValue;
  finally
    if (InplaceEditor <> nil) then
      TELPropsPageInplaceEdit(InplaceEditor).UpdateContents;
  end;
end;

procedure TELCustomPropsPage.CMExit(var Message: TMessage);
begin
  UpdateData(Row);
  inherited;
end;

procedure TELCustomPropsPage.BeginUpdate;
begin
  Inc(FUpdateCount);
end;

procedure TELCustomPropsPage.EndUpdate;
begin
  Dec(FUpdateCount);
  if (FUpdateCount <= 0) and (ppsChanged in FState) then
  begin
    ItemsChange;
    Exclude(FState, ppsChanged);
  end;
end;

// whf add
procedure TELCustomPropsPage.ClosePopup;
begin
  if (InplaceEditor <> nil) and (InplaceEdit

⌨️ 快捷键说明

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