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

📄 rm_editorcellprop.pas

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

unit RM_EditorCellProp;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, ExtCtrls, RM_Common, RM_Class, RM_Ctrls, RM_DsgCtrls, Buttons;

type

  TRMFrameMsg = record
    FrameVisible: Boolean;
    FrameStyle: TPenStyle;
    FrameWidth: Double;
    FrameColor: TColor;
    FrameDouble: Boolean;
  end;

  TRMCellPropForm = class(TForm)
    PageCtlCellProp: TPageControl;
    TabSheetCellType: TTabSheet;
    TabSheetAlign: TTabSheet;
    TabSheetFont: TTabSheet;
    BtnOk: TButton;
    BtnCancel: TButton;
    LabelAlign: TLabel;
    BevelAlign: TBevel;
    LabelFontName: TLabel;
    LabelHAlign: TLabel;
    LabelVAlign: TLabel;
    cmbHAlign: TComboBox;
    cmbVAlign: TComboBox;
    LabelControl: TLabel;
    BevelControl: TBevel;
    ChkBoxAutoWordBreak: TCheckBox;
    LabelFontStyle: TLabel;
    LabelFontSize: TLabel;
    lstFontName: TListBox;
    lstFontStyle: TListBox;
    lstFontSize: TListBox;
    LabelFontColor: TLabel;
    GbxFontPreview: TGroupBox;
    PanelFontPreview2: TPanel;
    PanelFontPreview1: TPanel;
    LabelIntro1: TLabel;
    PanelFontColor: TPanel;
    BtnSetFontColor: TButton;
    EditFontSize: TEdit;
    ColorDialogCellProp: TColorDialog;
    lstFormatFolder: TListBox;
    Label1: TLabel;
    edtFormatDec: TEdit;
    edtForamtStr: TEdit;
    Label2: TLabel;
    edtFormatSpl: TEdit;
    lstFormatType: TListBox;
    Label3: TLabel;
    TabSheet1: TTabSheet;
    btnBorderTop: TSpeedButton;
    btnBorderHInternal: TSpeedButton;
    btnBorderBottom: TSpeedButton;
    btnBorderLeft: TSpeedButton;
    btnBorderVInternal: TSpeedButton;
    btnBorderRight: TSpeedButton;
    btnBorderAll: TSpeedButton;
    btnBorderInside: TSpeedButton;
    btnBorderFrame: TSpeedButton;
    btnBorderNoFrame: TSpeedButton;
    BorderPanel: TPanel;
    BordersBox: TPaintBox;
    EDLeftStyle: TComboBox;
    chkDoubleLeft: TCheckBox;
    Label4: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure lstFontStyleClick(Sender: TObject);
    procedure lstFontSizeClick(Sender: TObject);
    procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
    procedure lstFontNameClick(Sender: TObject);
    procedure BtnSetFontColorClick(Sender: TObject);
    procedure cmbHAlignClick(Sender: TObject);
    procedure cmbVAlignClick(Sender: TObject);
    procedure lstFormatFolderClick(Sender: TObject);
    procedure lstFormatTypeClick(Sender: TObject);
    procedure edtFormatSplEnter(Sender: TObject);
    procedure EditFontSizeKeyPress(Sender: TObject; var Key: Char);
    procedure lstFontNameDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure FormDestroy(Sender: TObject);
    procedure btnBorderFrameClick(Sender: TObject);
    procedure btnBorderNoFrameClick(Sender: TObject);
    procedure EDLeftStyleDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure btnBorderInsideClick(Sender: TObject);
    procedure btnBorderAllClick(Sender: TObject);
    procedure btnBorderTopClick(Sender: TObject);
    procedure BordersBoxPaint(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    FCellRange: TRect;
    FDisplayFormat: TRMFormat;
    FDisplayFormatStr: string;
    FTrueTypeBMP: TBitmap;
    FDeviceBMP: TBitmap;
    FBusy: Boolean;

    FCmbFrameWidth: TComboBox;
    FBtnFrameColor: TRMColorPickerButton;
    FFrameMsgs: array[1..6] of TRMFrameMsg;
    FFrameButtons: array[1..6] of TSpeedButton;
    FFrameChanged: Boolean;

    procedure Localize;
    procedure GetFirstCellProp;
    procedure SetControlState;
    procedure ShowFormatPanels;
    procedure ShowBorderSample;
    procedure SetFrameMsg(aMsgs: array of Integer);
  public
    ParentGrid: Pointer;
  end;

implementation

{$R *.DFM}

uses RM_Grid, RM_Const, RM_Const1, RM_Utils;

const
  CategCount = 5;

type
  THackMemoView = class(TRMCustomMemoView)
  end;

function EnumFontsProc(var EnumLogFont: TEnumLogFont; var TextMetric: TNewTextMetric;
  FontType: Integer; Data: LPARAM): Integer; export; stdcall;
var
  FaceName: string;
begin
  FaceName := StrPas(EnumLogFont.elfLogFont.lfFaceName);
  with TListBox(Data) do
  begin
    if (Items.IndexOf(FaceName) < 0) and
      (FontType and TRUETYPE_FONTTYPE = TRUETYPE_FONTTYPE) then
    begin
      Items.AddObject(FaceName, TObject(FontType));
    end;
  end;
  Result := 1;
end;

procedure TRMCellPropForm.Localize;
var
  i, liOffset: Integer;
begin
  Font.Name := RMLoadStr(SRMDefaultFontName);
  Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
  Font.Charset := StrToInt(RMLoadStr(SCharset));

  RMSetStrProp(TabSheetCellType, 'Caption', rmRes + 675);
  RMSetStrProp(Label1, 'Caption', rmRes + 422);
  RMSetStrProp(Label2, 'Caption', rmRes + 423);
  RMSetStrProp(Label3, 'Caption', rmRes + 424);

  RMSetStrProp(TabSheetAlign, 'Caption', rmRes + 676);
  cmbHAlign.Items.Clear;
  cmbHAlign.Items.Add(RMLoadStr(rmRes + 107));
  cmbHAlign.Items.Add(RMLoadStr(rmRes + 109));
  cmbHAlign.Items.Add(RMLoadStr(rmRes + 108));
  cmbHAlign.Items.Add(RMLoadStr(rmRes + 114));
  cmbVAlign.Items.Clear;
  cmbVAlign.Items.Add(RMLoadStr(rmRes + 112));
  cmbVAlign.Items.Add(RMLoadStr(rmRes + 111));
  cmbVAlign.Items.Add(RMLoadStr(rmRes + 113));
  RMSetStrProp(LabelHAlign, 'Caption', rmRes + 678);
  RMSetStrProp(LabelVAlign, 'Caption', rmRes + 679);
  RMSetStrProp(LabelAlign, 'Caption', rmRes + 680);
  RMSetStrProp(LabelControl, 'Caption', rmRes + 681);
  RMSetStrProp(ChkBoxAutoWordBreak, 'Caption', rmRes + 682);

  RMSetStrProp(TabSheetFont, 'Caption', rmRes + 522);
  RMSetStrProp(LabelFontName, 'Caption', rmRes + 522);
  RMSetStrProp(LabelFontStyle, 'Caption', rmRes + 683);
  RMSetStrProp(LabelFontSize, 'Caption', rmRes + 684);
  RMSetStrProp(LabelFontColor, 'Caption', rmRes + 685);
  RMSetStrProp(GbxFontPreview, 'Caption', rmRes + 196);
  if RMIsChineseGB then
    liOffset := 0
  else
    liOffset := 13;
  for i := Low(RMDefaultFontSizeStr) + liOffset to High(RMDefaultFontSizeStr) do
    lstFontSize.Items.Add(RMDefaultFontSizeStr[i]);
  lstFontStyle.Items.Clear;
  lstFontStyle.Items.Add(RMLoadStr(rmRes + 686));
  lstFontStyle.Items.Add(RMLoadStr(rmRes + 687));
  lstFontStyle.Items.Add(RMLoadStr(rmRes + 688));
  lstFontStyle.Items.Add(RMLoadStr(rmRes + 689));

  RMSetStrProp(TabSheet1, 'Caption', rmRes + 677);
  RMSetStrProp(chkDoubleLeft, 'Caption', rmRes + 864);
  RMSetStrProp(Label4, 'Caption', rmRes + 865);

	RMSetStrProp(Self, 'Caption', rmRes + 929);
  btnOk.Caption := RMLoadStr(SOK);
  btnCancel.Caption := RMLoadStr(SCancel);
end;

procedure TRMCellPropForm.GetFirstCellProp;
var
  i, j: Integer;
  liFound: Boolean;
  liCell: TRMCellInfo;
  t: TRMView;
begin
  liFound := False; t := nil;
  for i := FCellRange.Top to FCellRange.Bottom do
  begin
    j := FCellRange.Left;
    liFound := False;
    while j <= FCellRange.Right do
    begin
      liCell := TRMGridEx(ParentGrid).Cells[j, i];
      if liCell.StartRow = i then
      begin
        if liCell.View is TRMCustomMemoView then
        begin
          t := liCell.View;
          FDisplayFormat := THackMemoView(liCell.View).FormatFlag;
          FDisplayFormatStr := TRMCustomMemoView(liCell.View).DisplayFormat;
          liFound := True;
          Break;
        end;
      end;
      j := liCell.EndCol + 1;
    end;

    if liFound then
      Break;
  end;

  // Format
  lstFormatFolder.Items.Clear;
  for i := 0 to CategCount - 1 do
    lstFormatFolder.Items.Add(RMLoadStr(SCateg1 + i));
  lstFormatFolder.ItemIndex := FDisplayFormat.FormatIndex1;
  if lstFormatFolder.ItemIndex < 0 then lstFormatFolder.ItemIndex := 0;
  lstFormatFolderClick(nil);
  lstFormatType.ItemIndex := FDisplayFormat.FormatIndex2;
  if lstFormatType.ItemIndex < 0 then lstFormatType.ItemIndex := 0;
  lstFormatTypeClick(nil);

  // Layout
  if liFound then
  begin
    cmbHAlign.ItemIndex := Byte(TRMCustomMemoView(t).HAlign);
    cmbVAlign.ItemIndex := Byte(TRMCustomMemoView(t).VAlign);
    ChkBoxAutoWordBreak.Checked := THackMemoView(t).Wordwrap;
  end
  else
  begin
    cmbHAlign.ItemIndex := 0;
    cmbVAlign.ItemIndex := 0;
    ChkBoxAutoWordBreak.Checked := False;
  end;

  // Font
  if liFound then
  begin
    lstFontName.ItemIndex := lstFontName.Items.IndexOf(TRMCustomMemoView(t).Font.Name);
    if TRMCustomMemoView(t).Font.Style = [] then
      lstFontStyle.ItemIndex := 0
    else if TRMCustomMemoView(t).Font.Style = [fsItalic] then
      lstFontStyle.ItemIndex := 1
    else if TRMCustomMemoView(t).Font.Style = [fsBold] then
      lstFontStyle.ItemIndex := 2
    else if TRMCustomMemoView(t).Font.Style = [fsBold, fsItalic] then
      lstFontStyle.ItemIndex := 3
    else
      lstFontStyle.ItemIndex := 0;

    PanelFontColor.Color := TRMCustomMemoView(t).Font.Color;
    lstFontStyle.ItemIndex := 0;
    RMSetFontSize1(TListBox(lstFontSize), TRMCustomMemoView(t).Font.Size);
    PanelFontPreview1.Font.Assign(TRMCustomMemoView(t).Font);
  end
  else
  begin
    lstFontName.ItemIndex := 0;
    PanelFontColor.Color := clBlack;
    lstFontStyle.ItemIndex := 0;
    lstFontSize.ItemIndex := 0;
    PanelFontPreview1.Font.Name := lstFontName.Items[0];
    PanelFontPreview1.Font.Color := clBlack;
    PanelFontPreview1.Font.Style := [];
    PanelFontPreview1.Font.Size := RMGetFontSize1(lstFontSize.ItemIndex, lstFontSize.Items[lstFontSize.ItemIndex]);
  end;

  // Frame
  FFrameChanged := False;
  for i := 1 to 6 do
  begin
    FFrameMsgs[i].FrameStyle := psSolid;
    FFrameMsgs[i].FrameWidth := 1;
    FFrameMsgs[i].FrameColor := clBlack;
    FFrameMsgs[i].FrameDouble := False;
    FFrameMsgs[i].FrameVisible := False;
  end;
  FFrameButtons[1] := btnBorderTop;
  FFrameButtons[2] := btnBorderHInternal;
  FFrameButtons[3] := btnBorderBottom;
  FFrameButtons[4] := btnBorderLeft;
  FFrameButtons[5] := btnBorderVInternal;
  FFrameButtons[6] := btnBorderRight;

  FCmbFrameWidth.Text := '1';
  EDLeftStyle.ItemIndex := 0;
end;

procedure TRMCellPropForm.SetControlState;
var
  i, j: Integer;
  liCell: TRMCellInfo;

  procedure _SetOneCell;
  begin
    // Format;
    if liCell.View is TRMCustomMemoView then
    begin
      THackMemoView(liCell.View).FormatFlag := FDisplayFormat;
      THackMemoView(liCell.View).FDisplayFormat := FDisplayFormatStr;
    end;

    // Layout
    liCell.HAlign := TRMHAlign(cmbHAlign.ItemIndex);
    liCell.VAlign := TRMVAlign(cmbVAlign.ItemIndex);
    if liCell.View is TRMCustomMemoView then
    begin
      THackMemoView(liCell.View).Wordwrap := ChkBoxAutoWordBreak.Checked;
    end;

    // Font
    liCell.Font.Assign(PanelFontPreview1.Font);

    // Border
    if FFrameChanged then
    begin
      if liCell.StartRow = FCellRange.Top then
      begin
        liCell.View.TopFrame.Visible := FFrameMsgs[1].FrameVisible;
        liCell.View.TopFrame.Color := FFrameMsgs[1].FrameColor;
        liCell.View.TopFrame.mmWidth := RMToMMThousandths(FFrameMsgs[1].FrameWidth, rmutScreenPixels);
        liCell.View.TopFrame.Style := FFrameMsgs[1].FrameStyle;
        liCell.View.TopFrame.DoubleFrame := FFrameMsgs[1].FrameDouble;
      end
      else
      begin
        liCell.View.TopFrame.Visible := FFrameMsgs[2].FrameVisible;
        liCell.View.TopFrame.Color := FFrameMsgs[2].FrameColor;
        liCell.View.TopFrame.mmWidth := RMToMMThousandths(FFrameMsgs[2].FrameWidth, rmutScreenPixels);
        liCell.View.TopFrame.Style := FFrameMsgs[2].FrameStyle;
        liCell.View.TopFrame.DoubleFrame := FFrameMsgs[2].FrameDouble;
      end;

      if liCell.EndRow = FCellRange.Bottom then
      begin
        liCell.View.BottomFrame.Visible := FFrameMsgs[3].FrameVisible;
        liCell.View.BottomFrame.Color := FFrameMsgs[3].FrameColor;
        liCell.View.BottomFrame.mmWidth := RMToMMThousandths(FFrameMsgs[3].FrameWidth, rmutScreenPixels);
        liCell.View.BottomFrame.Style := FFrameMsgs[3].FrameStyle;
        liCell.View.BottomFrame.DoubleFrame := FFrameMsgs[3].FrameDouble;
      end
      else
      begin
        liCell.View.BottomFrame.Visible := FFrameMsgs[2].FrameVisible;
        liCell.View.BottomFrame.Color := FFrameMsgs[2].FrameColor;
        liCell.View.BottomFrame.mmWidth := RMToMMThousandths(FFrameMsgs[2].FrameWidth, rmutScreenPixels);
        liCell.View.BottomFrame.Style := FFrameMsgs[2].FrameStyle;
        liCell.View.BottomFrame.DoubleFrame := FFrameMsgs[2].FrameDouble;
      end;

      if liCell.StartCol = FCellRange.Left then
      begin
        liCell.View.LeftFrame.Visible := FFrameMsgs[4].FrameVisible;
        liCell.View.LeftFrame.Color := FFrameMsgs[4].FrameColor;
        liCell.View.LeftFrame.mmWidth := RMToMMThousandths(FFrameMsgs[4].FrameWidth, rmutScreenPixels);
        liCell.View.LeftFrame.Style := FFrameMsgs[4].FrameStyle;
        liCell.View.LeftFrame.DoubleFrame := FFrameMsgs[4].FrameDouble;
      end
      else
      begin
        liCell.View.LeftFrame.Visible := FFrameMsgs[5].FrameVisible;
        liCell.View.LeftFrame.Color := FFrameMsgs[5].FrameColor;
        liCell.View.LeftFrame.mmWidth := RMToMMThousandths(FFrameMsgs[5].FrameWidth, rmutScreenPixels);
        liCell.View.LeftFrame.Style := FFrameMsgs[5].FrameStyle;
        liCell.View.LeftFrame.DoubleFrame := FFrameMsgs[5].FrameDouble;
      end;

      if liCell.EndCol = FCellRange.Right then
      begin
        liCell.View.RightFrame.Visible := FFrameMsgs[6].FrameVisible;
        liCell.View.RightFrame.Color := FFrameMsgs[6].FrameColor;
        liCell.View.RightFrame.mmWidth := RMToMMThousandths(FFrameMsgs[6].FrameWidth, rmutScreenPixels);
        liCell.View.RightFrame.Style := FFrameMsgs[6].FrameStyle;
        liCell.View.RightFrame.DoubleFrame := FFrameMsgs[6].FrameDouble;
      end
      else
      begin
        liCell.View.RightFrame.Visible := FFrameMsgs[5].FrameVisible;
        liCell.View.RightFrame.Color := FFrameMsgs[5].FrameColor;
        liCell.View.RightFrame.mmWidth := RMToMMThousandths(FFrameMsgs[5].FrameWidth, rmutScreenPixels);
        liCell.View.RightFrame.Style := FFrameMsgs[5].FrameStyle;
        liCell.View.RightFrame.DoubleFrame := FFrameMsgs[5].FrameDouble;
      end;
    end;
  end;

begin
  // Format
  FDisplayFormat.FormatIndex1 := lstFormatFolder.ItemIndex;
  FDisplayFormat.FormatIndex2 := lstFormatType.ItemIndex;
  FDisplayFormat.FormatPercent := StrToIntDef(edtFormatDec.Text, 0);
  if edtFormatSpl.Text <> '' then

⌨️ 快捷键说明

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