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

📄 rm_gridview.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  LVersion := 0;
  inherited SaveToStream(Stream);
  FGrid.SaveToStream(Stream);
end;

class function TRMGridView.CanPlaceOnGridView: Boolean;
begin
  Result := False;
end;

procedure TRMGridView.OnGridDblClickEvent(Sender: TObject);
var
  liCell: TRMCellInfo;
begin
  liCell := FGrid.GetCellInfo(FGrid.Selection.Left, FGrid.Selection.Top);
  RMMemoEditor(liCell.View);
end;

procedure TRMGridView.OnItemMergeClick(Sender: TObject);
begin
  FGrid.MergeSelection;
  RMDesigner.Modified := True;
end;

procedure TRMGridView.OnItemRevertClick(Sender: TObject);
begin
  FGrid.SplitCell(FGrid.Selection);
  RMDesigner.Modified := True;
end;

procedure TRMGridView.OnItemInsertRowClick(Sender: TObject);
begin
  FGrid.InsertRow(FGrid.Row);
  RMDesigner.Modified := True;
end;

procedure TRMGridView.OnItemInsertColClick(Sender: TObject);
begin
  FGrid.InsertColumn(FGrid.Col);
  RMDesigner.Modified := True;
end;

procedure TRMGridView.OnItemDeleteRowClick(Sender: TObject);
begin
  FGrid.DeleteRow(FGrid.Row);
  RMDesigner.Modified := True;
end;

procedure TRMGridView.OnItemDeleteColClick(Sender: TObject);
begin
  FGrid.DeleteColumn(FGrid.Col);
  RMDesigner.Modified := True;
end;

procedure TRMGridView.ShowEditor;
var
  tmp: TRMGridViewForm;
  i, liCol, liRow: Integer;
  liCell: TRMCellInfo;
begin
  SaveDesigner := RMDesigner;
  tmp := TRMGridViewForm.Create(nil);
  try
    FGrid1 := tmp.FGrid;
    tmp.FGrid.ColCount := FGrid.ColCount;
    tmp.FGrid.RowCount := FGrid.RowCount;
    tmp.FGrid.FixedColor := FGrid.FixedColor;
    tmp.FGrid.Font.Assign(FGrid.Font);
    tmp.FGrid.DefaultRowHeight := FGrid.DefaultRowHeight;
    tmp.FGrid.DefaultColWidth := FGrid.DefaultColWidth;
    for i := 1 to FGrid.ColCount - 1 do
      tmp.FGrid.ColWidths[i] := FGrid.ColWidths[i];
    for i := 1 to FGrid.RowCount - 1 do
      tmp.FGrid.RowHeights[i] := FGrid.RowHeights[i];
    for liCol := 1 to FGrid.ColCount - 1 do
    begin
      for liRow := 1 to FGrid.RowCount - 1 do
      begin
        liCell := tmp.FGrid.Cells[liCol, liRow];
        liCell.Assign(FGrid.Cells[liCol, liRow]);
      end;
    end;

    tmp.FGridView := Self;
    if tmp.ShowModal = mrOK then
    begin
      FGrid.ColCount := tmp.FGrid.ColCount;
      FGrid.RowCount := tmp.FGrid.RowCount;
      FGrid.FixedColor := tmp.FGrid.FixedColor;
      FGrid.Font.Assign(tmp.FGrid.font);
      for i := 1 to tmp.FGrid.ColCount - 1 do
        FGrid.ColWidths[i] := tmp.FGrid.ColWidths[i];
      for i := 1 to tmp.FGrid.RowCount - 1 do
        FGrid.RowHeights[i] := tmp.Fgrid.RowHeights[i];
      for liCol := 1 to tmp.FGrid.ColCount - 1 do
      begin
        for liRow := 1 to tmp.FGrid.RowCount - 1 do
        begin
          liCell := FGrid.Cells[liCol, liRow];
          liCell.Assign(tmp.FGrid.Cells[liCol, liRow]);
        end;
      end;
      SaveDesigner.Modified := True;
    end;
  finally
    FGrid1 := FGrid;
    RMDesigner := SaveDesigner;
    tmp.Free;
  end;
end;


{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{ TRMGridViewForm }

function Objects: TList;
begin
  Result := RMDesigner.Page.Objects;
end;

procedure TRMGridViewForm.Localize;
begin
  Font.Name := RMLoadStr(SRMDefaultFontName);
  Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
  Font.Charset := StrToInt(RMLoadStr(SCharset));

  RMSetStrProp(MenuFile, 'Caption', rmRes + 154);
  RMSetStrProp(MenuFileNew, 'Caption', rmRes + 155);
  RMSetStrProp(MenuFileOpen, 'Caption', rmRes + 156);
  RMSetStrProp(MenuFileSave, 'Caption', rmRes + 157);
  RMSetStrProp(MenuFileSaveas, 'Caption', rmRes + 188);
  RMSetStrProp(MenuFilePreview, 'Caption', rmRes + 161);
  RMSetStrProp(MenuFileExit, 'Caption', rmRes + 162);

  RMSetStrProp(MenuEdit, 'Caption', rmRes + 163);
  RMSetStrProp(MenuEditInsertColumn, 'Caption', rmRes + 801);
  RMSetStrProp(MenuEditInsertRow, 'Caption', rmRes + 802);
  RMSetStrProp(MenuEditDeleteColumn, 'Caption', rmRes + 803);
  RMSetStrProp(MenuEditDeleteRow, 'Caption', rmRes + 804);
  RMSetStrProp(MenuEditMerge, 'Caption', rmRes + 805);
  RMSetStrProp(MenuEditReverse, 'Caption', rmRes + 806);

  RMSetStrProp(MenuCell, 'Caption', rmRes + 807);
  RMSetStrProp(MenuCellProperty, 'Caption', rmRes + 211);

  RMSetStrProp(itmMergeCells, 'Caption', rmRes + 805);
  RMSetStrProp(itmSplitCells, 'Caption', rmRes + 806);
  RMSetStrProp(itmInsert, 'Caption', rmRes + 702);
  RMSetStrProp(itmInsertLeftColumn, 'Caption', rmRes + 808);
  RMSetStrProp(itmInsertRightColumn, 'Caption', rmRes + 809);
  RMSetStrProp(itmInsertTopRow, 'Caption', rmRes + 810);
  RMSetStrProp(itmInsertBottomRow, 'Caption', rmRes + 811);
  RMSetStrProp(itmDelete, 'Caption', rmRes + 350);
  RMSetStrProp(itmDeleteColumn, 'Caption', rmRes + 812);
  RMSetStrProp(itmDeleteRow, 'Caption', rmRes + 813);
  RMSetStrProp(itmCellType, 'Caption', rmRes + 814);
  RMSetStrProp(itmFrameType, 'Caption', rmRes + 214);
  RMSetStrProp(itmEdit, 'Caption', rmRes + 153);
  RMSetStrProp(itmMemoView, 'Caption', rmRes + 133);
  RMSetStrProp(itmCalcMemoView, 'Caption', rmRes + 197);
  RMSetStrProp(itmPictureView, 'Caption', rmRes + 135);

  RMSetStrProp(btnFrameLeft, 'Hint', rmRes + 123);
  RMSetStrProp(btnFrameRight, 'Hint', rmRes + 125);
  RMSetStrProp(btnFrameTop, 'Hint', rmRes + 122);
  RMSetStrProp(btnFrameBottom, 'Hint', rmRes + 124);
  RMSetStrProp(btnNoBorder, 'Hint', rmRes + 127);
  RMSetStrProp(btnSetBorder, 'Hint', rmRes + 126);

  RMSetStrProp(btnBold, 'Hint', rmRes + 115);
  RMSetStrProp(btnItalic, 'Hint', rmRes + 116);
  RMSetStrProp(btnUnderline, 'Hint', rmRes + 117);
  RMSetStrProp(btnLeft, 'Hint', rmRes + 107);
  RMSetStrProp(btnCenter, 'Hint', rmRes + 109);
  RMSetStrProp(btnRight, 'Hint', rmRes + 108);
  RMSetStrProp(btnSpaceEqual, 'Hint', rmRes + 114);
  RMSetStrProp(btnTop, 'Hint', rmRes + 112);
  RMSetStrProp(btnVCenter, 'Hint', rmRes + 114);
  RMSetStrProp(btnBottom, 'Hint', rmRes + 113);
  RMSetStrProp(btnMerge, 'Hint', rmRes + 805);
  RMSetStrProp(btnSplit, 'Hint', rmRes + 806);

  btnOk.Hint := RMLoadStr(SOK);
  btnCancel.Hint := RMLoadStr(SCancel);
end;

function TRMGridViewForm.GetDesignerPage: TWinControl;
begin
  Result := nil;
end;

function TRMGridViewForm.GetModified: Boolean;
begin
  Result := False;
end;

procedure TRMGridViewForm.SetModified(Value: Boolean);
begin
end;

procedure TRMGridViewForm.RedrawPage;
begin
end;

procedure TRMGridViewForm.SelectObject(ObjName: string);
begin
end;

procedure TRMGridViewForm.RegisterObject(ButtonBmp: TBitmap; const ButtonHint: string; ButtonTag: Integer; IsControl: Boolean);
begin
end;

procedure TRMGridViewForm.RegisterTool(MenuCaption: string; ButtonBmp: TBitmap; OnClick: TNotifyEvent);
begin
end;

procedure TRMGridViewForm.BeforeChange;
begin
  if FNowView is TRMMemoView then
  begin
    TRMMemoView(FNowView).Font.Assign(FNowCellInfo.Font);
  end;
end;

procedure TRMGridViewForm.AfterChange;
begin
  if FNowView is TRMMemoView then
  begin
    FNowCellInfo.Text := FNowView.Memo.Text;
    FNowCellInfo.Font.Assign(TRMMemoView(FNowView).Font);
    FNowCellInfo.AutoWordBreak := TRMMemoView(FNowView).PWordWrap;
  end;
  FillInspFields;
  FInspForm.ItemsChanged;
end;

function TRMGridViewForm.InsertDBField: string;
begin
  Result := SaveDesigner.InsertDBField;
end;

function TRMGridViewForm.InsertExpression: string;
begin
  Result := SaveDesigner.InsertExpression;
end;

procedure TRMGridViewForm.GetCellState(aCell: TRMCellInfo);
begin
  btnFrameLeft.Down := aCell.View.LeftFrame.Visible;
  btnFrameRight.Down := aCell.View.RightFrame.Visible;
  btnFrameTop.Down := aCell.View.TopFrame.Visible;
  btnFrameBottom.Down := aCell.View.BottomFrame.Visible;

  if FcmbFont.ItemIndex <> FcmbFont.Items.IndexOf(aCell.Font.Name) then
    FcmbFont.ItemIndex := FcmbFont.Items.IndexOf(aCell.Font.Name);
  RMSetFontSize(TComboBox(FCmbFontSize), aCell.Font.Size);
  btnBold.down := fsBold in aCell.Font.Style;
  btnItalic.down := fsItalic in aCell.Font.Style;
  btnUnderline.down := fsUnderline in aCell.Font.Style;
  case aCell.HorizAlign of
    rmtaLeftJustify: btnLeft.Down := True;
    rmtaRightJustify: btnRight.Down := True;
    rmtaCenterJustify: btnCenter.Down := True;
    rmtaEuqalJustify: btnSpaceEqual.Down := True;
  end;
  case aCell.VertAlign of
    rmtlTop: btnTop.Down := True;
    rmtlCenter: btnVCenter.Down := True;
    rmtlBottom: btnBottom.Down := True;
  end;
end;

procedure TRMGridViewForm.OnGridDblClickEvent(Sender: TObject);
var
  liCell: TRMCellInfo;
begin
  liCell := FGrid.GetCellInfo(FGrid.Selection.Left, FGrid.Selection.Top);
  liCell.View.ShowEditor;
end;

procedure TRMGridViewForm.OnGridClick(Sender: TObject);
var
  liSelection: TRect;
  liCol, liRow: Integer;
  liCell: TRMCellInfo;
begin
  if FBusy then
    Exit;
  FBusy := True;
  try
    liSelection := FGrid.Selection;
    FNowCellInfo := FGrid.Cells[liSelection.Left, liSelection.Top];
//  StatusBar1.Panels[0].Text := Format('StartCol:%d StartRow:%d EndCol:%d EndRow:%d',
//  	[FGrid.Cells[ACol, ARow].StartCol, FGrid.Cells[ACol, ARow].StartRow, FGrid.Cells[ACol, ARow].EndCol, FGrid.Cells[ACol, ARow].EndRow]);
//	StatusBar1.Panels[1].Text := Format('Col:%d Row:%d', [FGrid.Col, FGrid.Row]);

    FNowView := FNowCellInfo.View;
    FNowView.Selected := True;

    Page.Objects.Clear;
    for liCol := liSelection.Left to liSelection.Right do
    begin
      for liRow := liSelection.Top to liSelection.Bottom do
      begin
        liCell := FGrid.Cells[liCol, liRow];
        if (liCell.StartCol = liCol) and (liCell.StartRow = liRow) then
        begin
          liCell.View.Selected := True;
          Page.Objects.Add(liCell.View);
        end;
      end;
    end;

    GetCellState(FNowCellInfo);
    FillInspFields;
    if not FInspBusy then
      FInspForm.ItemsChanged;
  finally
    FBusy := False;
  end;
end;

procedure TRMGridViewForm.FormCreate(Sender: TObject);
var
  i: Integer;
  liOffset: Integer;
  MenuItem: TMenuItem;
begin
  Localize;
  Page := TRMPage.Create(RMPrinter.DefaultPaper, 0, 0, -1, poPortrait);
  RMDesigner := Self;
  FFileName := '';

  FAddinObjects := TStringList.Create;

  FGrid := TRMGridEx.Create(Self);
  FGrid.Parent := Self;
  FGrid.Align := alClient;
  FGrid.PopupMenu := SelectionMenu;
  FGrid.OnDblClick := OnGridDblClickEvent;
  FGrid.OnClick := OnGridClick;

  FcmbFontSize := TComboBox.Create(FormattingBar);
  with FcmbFontSize do
  begin
    Parent := FormattingBar;
    Height := 21;
    Width := 50;
    DropDownCount := 12;
    if RMIsChineseGB then
      liOffset := 0
    else
      liOffset := 13;
    for i := Low(RMDefaultFontSizeStr) + liOffset to High(RMDefaultFontSizeStr) do
      Items.Add(RMDefaultFontSizeStr[i]);
    OnChange := OnFontSizeChange;
  end;

  FcmbFont := TRMFontComboBox.Create(FormattingBar);
  with FcmbFont do
  begin
    Parent := FormattingBar;
    Height := 21;
    Width := 120;
    OnChange := OnFontNameChange;
  end;

  FAddinObjects.Clear;
  for i := 0 to RMAddInsCount - 1 do
  begin
    if not RMAddIns(i).IsControl then
    begin
      if not RMAddIns(i).ClassRef.CanPlaceOnGridView then
//      if not TRMView(RMAddIns(i).ClassRef.NewInstance).CanPlaceOnGridView then
        Continue;
      MenuItem := TMenuItem.Create(itmCellType);
      MenuItem.RadioItem := True;
      MenuItem.Tag := gtAddin;
      MenuItem.Caption := RMAddIns(i).ButtonHint;
      MenuItem.OnClick := itmMemoViewClick;
      FAddinObjects.Add(RMAddIns(i).ClassRef.ClassName);
      itmCellType.Add(MenuItem);
    end;
  end;
end;

procedure TRMGridViewForm.FormDestroy(Sender: TObject);
begin
  SaveState;

  FInspForm.Free;
  FAddinObjects.Free;
  FGrid.Free;

  Page.Objects.Clear;
  Page.Free;
end;

procedure TRMGridViewForm.btnMergeClick(Sender: TObject);
begin
  FModify := True;
  FGrid.MergeSelection;
end;

procedure TRMGridViewForm.btnSplitClick(Sender: TObject);
begin
  FModify := True;
  FGrid.SplitCell(FGrid.Selection);
end;

procedure TRMGridViewForm.btnOKClick(Sender: TObject);
begin
  ModalResult := mrOK;
end;

procedure TRMGridViewForm.btnCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TRMGridViewForm.FormShow(Sender: TObject);
begin
  FInspBusy := True;

  FInspForm := TRMInspForm.Create(Self);
  with FInspForm do
  begin
{$IFNDEF USE_TB2K}
    Parent := Self;
{$ENDIF}
    ClearProperties;
    AddProperty('', 0, [RMdtString], nil, Null, nil);
    OnModify := Self.OnModify;
    OnGetObjects := InspGetObjects;
  end;

  FGrid.CreateViewsName;
  OnGridClick(nil);

  RestoreState;
  FInspBusy := False;

  FillInspFields;
  if not FInspBusy then
    FInspForm.ItemsChanged;
end;

procedure TRMGridViewForm.OnFontNameChange(Sender: TObject);
var
  liCol, liRow: Integer;
begin
  FModify := True;
  for liCol := FGrid.Selection.Left to FGrid.Selection.Right do
  begin
    for liRow := FGrid.Selection.Top to FGrid.Selection.Bottom do
      FGrid.Cells[liCol, liRow].Font.Name := FcmbFont.Text;
  end;
  FGrid.InvalidateGrid;
end;

procedure TRMGridViewForm.OnFontSizeChange(Sender: TObject);
var
  liCol, liRow: Integer;
  liFontSize: Integer;
begin
  FModify := True;
  liFontSize := RMGetFontSize(TComboBox(FCmbFontSize));
  for liCol := FGrid.Selection.Left to FGrid.Selection.Right do
  begin
    for liRow := FGrid.Selection.Top to FGrid.Selection.Bottom do
      FGrid.Cells[liCol, liRow].Font.Size := liFontSize;
  end;
  FGrid.InvalidateGrid;
end;

procedure TRMGridViewForm.btnFrameLeftClick(Sender: TObject);
var
  liCol, liRow: Integer;
  liCell: TRMCellInfo;
begin
  FModify := True;
  for liCol := FGrid.Selection.Left to FGrid.Selection.Right do
  begin
    for liRow := FGrid.Selection.Top to FGrid.Selection.Bottom do
    begin
      liCell := FGrid.Cells[liCol, liRow];
      case TToolButton(Sender).Tag of
        1: liCell.View.LeftFrame.Visible := btnFrameLeft.Down;
        2: liCell.View.RightFrame.Visible := btnFrameRight.Down;
        3: liCell.View.TopFrame.Visible := btnFrameTop.Down;
        4: liCell.View.BottomFrame.Visible := btnFrameBottom.Down;
        5: liCell.View.Prop['FrameTyp'] := 0;
        6: liCell.View.Prop['FrameTyp'] := 15;
        9:
          begin
            if btnBias1Border.Down then
              liCell.View.LeftRightFrame := 4
            else

⌨️ 快捷键说明

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