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

📄 itemproprvfrm.pas

📁 richviewaction 1.58 需要richview 1.9.46
💻 PAS
📖 第 1 页 / 共 3 页
字号:

{*******************************************************}
{                                                       }
{       RichViewActions                                 }
{       Object (image, break, table) properties         }
{       dialog                                          }
{                                                       }
{       Copyright (c) Sergey Tkachenko                  }
{       svt@trichview.com                               }
{       http://www.trichview.com                        }
{                                                       }
{*******************************************************}

unit ItemPropRVFrm;

interface

{$I RV_Defs.inc}
{$I RichViewActions.inc}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, BaseRVFrm, ComCtrls, StdCtrls, ImgList, ExtCtrls, RVSpinEdit,
  {$IFDEF USERVKSDEVTE}
  te_controls, te_extctrls,
  {$ENDIF}
  {$IFDEF USERVTNT}
  TntComCtrls, TntStdCtrls,
  {$ENDIF}
  RVColorCombo, CRVData, RVItem, RVEdit, RVFuncs, RVStyle, ExtDlgs,
  RVOfficeRadioBtn, Buttons, RVTable, RVALocalize;

type
  TfrmRVItemProp = class(TfrmRVBase)
    btnOk: TButton;
    btnCancel: TButton;
    pc: TPageControl;
    tsImage: TTabSheet;
    Panel1: TPanel;
    tsImgLayout: TTabSheet;
    gbVAlign: TGroupBox;
    lblAlignTo: TLabel;
    cmbAlignTo: TComboBox;
    lblVShift: TLabel;
    seVShift: TRVSpinEdit;
    cmbVShiftType: TComboBox;
    gbSize: TGroupBox;
    seWidth: TRVSpinEdit;
    cmbWType: TComboBox;
    seHeight: TRVSpinEdit;
    cmbHType: TComboBox;
    img: TImage;
    btnChangeImage: TButton;
    gbTransp: TGroupBox;
    lblTrColor: TLabel;
    cmbColor: TRVColorCombo;
    cbTransp: TCheckBox;
    lblPreview: TLabel;
    tsBreak: TTabSheet;
    lblWidth: TLabel;
    lblHeight: TLabel;
    lblDefSize: TLabel;
    gbBreak: TGroupBox;
    lblBreakColor: TLabel;
    lblBreakWidth: TLabel;
    cmbBreakColor: TRVColorCombo;
    cmbWidth: TComboBox;
    tsTable: TTabSheet;
    gbTableSize: TGroupBox;
    seTableWidth: TRVSpinEdit;
    cmbTWType: TComboBox;
    ImageList1: TImageList;
    lblTableColor: TLabel;
    cmbTableColor: TRVColorCombo;
    lblCellPadding: TLabel;
    seCellPadding: TRVSpinEdit;
    seCellSpacing: TRVSpinEdit;
    lblCellSpacing: TLabel;
    btnSpacing: TButton;
    tsCells: TTabSheet;
    gbCellBorder: TGroupBox;
    lblCellBorderColor: TLabel;
    lblCellBorderLightColor: TLabel;
    cmbCellBorderColor: TRVColorCombo;
    cmbCellBorderLightColor: TRVColorCombo;
    btnTop: TSpeedButton;
    btnLeft: TSpeedButton;
    btnRight: TSpeedButton;
    btnBottom: TSpeedButton;
    lblVS: TLabel;
    gbCells: TGroupBox;
    seCellBestWidth: TRVSpinEdit;
    cmbCellBWType: TComboBox;
    seCellBestHeight: TRVSpinEdit;
    rgCellVAlign: TRVOfficeRadioGroup;
    Bevel2: TBevel;
    btnTableBorder: TButton;
    btnCellBorder: TButton;
    lblTableWidth: TLabel;
    lblCellColor: TLabel;
    cmbCellColor: TRVColorCombo;
    tsRows: TTabSheet;
    rgRowVAlign: TRVOfficeRadioGroup;
    cbCellWidth: TCheckBox;
    cbCellHeight: TCheckBox;
    lblPixels: TLabel;
    gbTablePrint: TGroupBox;
    cbNoSplit: TCheckBox;
    lblHeadingRows: TLabel;
    seHRC: TRVSpinEdit;
    lblHeadingRowsTip: TLabel;
    btnTableBack: TButton;
    btnCellBack: TButton;
    gbWeb: TGroupBox;
    lblAlt: TLabel;
    txtAlt: TEdit;
    gbSpacing: TGroupBox;
    lblSpacing: TLabel;
    seSpacing: TRVSpinEdit;
    procedure FormActivate(Sender: TObject);
    procedure cmbColorColorChange(Sender: TObject);
    procedure cmbVShiftTypeClick(Sender: TObject);
    procedure cmbWTypeClick(Sender: TObject);
    procedure cmbHTypeClick(Sender: TObject);
    procedure btnChangeImageClick(Sender: TObject);
    procedure cmbWidthDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure cmbBreakColorColorChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure seTableWidthChange(Sender: TObject);
    procedure btnSpacingClick(Sender: TObject);
    procedure seCellSpacingChange(Sender: TObject);
    procedure btnTableBorderClick(Sender: TObject);
    procedure btnCellBordersClick(Sender: TObject);
    procedure cmbCellBorderColorColorChange(Sender: TObject);
    procedure cmbCellBorderLightColorColorChange(Sender: TObject);
    procedure seCellBestWidthChange(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnTopClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnTableBackClick(Sender: TObject);
    procedure btnCellBackClick(Sender: TObject);
  private
    { Private declarations }
    CellHSpacing, CellVSpacing, BorderHSpacing, BorderVSpacing: Integer;
    BorderStyle: TRVTableBorderStyle;
    BorderColorD, BorderColorL: TColor;
    CellBorderStyle: TRVTableBorderStyle;
    CellBorderColorD, CellBorderColorL: TColor;
    BorderWidth, CellBorderWidth: Integer;
    FDefCellColorD, FDefCellColorL: Boolean;
    TableBackgroundImage: TGraphic;
    TableBackgroundStyle: TRVItemBackgroundStyle;
    TableBackgroundChanged: Boolean;
    CellBackgroundImage: TGraphic;
    CellBackgroundStyle: TRVItemBackgroundStyle;
    CellBackgroundChanged: Boolean;
    procedure UpdateCellBorders;
  protected
    _gbTransp, _gbSize, _gbCellBorder,
    _cbTransp, _cbCellWidth, _cbCellHeight, _cbNoSplit,
    _cmbAlignTo, _cmbVShiftType, _cmbWType, _cmbHType, _cmbWidth, _cmbTWType,
    _cmbCellBWType,
    _tsImage, _tsImgLayout, _tsBreak, _tsTable, _tsCells, _tsRows,
    _lblDefSize, _lblCellBorderColor, _lblCellBorderLightColor, _txtAlt: TControl;
    _pc : TWinControl;
    {$IFDEF RVASKINNED}
    procedure OnCreateThemedControl(OldControl, NewControl: TControl); override;
    function IsThemeAllowedFor(Component: TComponent): Boolean; override;
    {$ENDIF}
    {$IFDEF USERVKSDEVTE}
    procedure tecmbWidthDrawItem(Control: TWinControl; Canvas: TCanvas; Index: Integer;
    Rect: TRect; State: TOwnerDrawState);
    {$ENDIF}
  public
    { Public declarations }
    ColorDialog: TColorDialog;
    Filter, BackgroundFilter: String;
    function SetItem(rve: TCustomRichViewEdit): Boolean;
    procedure SetTable(table: TRVTableItemInfo; TableOnly: Boolean);
    procedure GetItem(rve: TCustomRichViewEdit);
    procedure GetTable(rve: TCustomRichViewEdit; table: TRVTableItemInfo);
    procedure Localize; override;
  end;


implementation
uses RichViewActions, SpacingRVFrm, TableBrdrRVFrm, TableBackRVFrm;
{$R *.dfm}

{ TfrmRVItemProp }

function TfrmRVItemProp.SetItem(rve: TCustomRichViewEdit): Boolean;
var item: TCustomRVItemInfo;
    v: Integer;
begin
  Result := False;
  item := rve.GetCurrentItem;
  {........................................}
  if item is TRVGraphicItemInfo then begin
    Result := True;
    HelpContext := 90800;
    _pc.HandleNeeded;
    HideTabSheet(_tsBreak);
    HideTabSheet(_tsTable);
    HideTabSheet(_tsCells);
    HideTabSheet(_tsRows);
    SetPageControlActivePage(_pc, _tsImage);
    img.Picture.Graphic := TRVGraphicItemInfo(item).Image;
    if TRVGraphicItemInfo(item).Image is TBitmap then begin
      SetCheckBoxChecked(_cbTransp, TBitmap(TRVGraphicItemInfo(item).Image).Transparent);
      if TBitmap(TRVGraphicItemInfo(item).Image).TransparentMode = tmAuto then
        cmbColor.ChosenColor := cmbColor.AutoColor
      else
        cmbColor.ChosenColor := TBitmap(TRVGraphicItemInfo(item).Image).TransparentColor;
      end
    else
      _gbTransp.Visible := False;
    img.Stretch := (img.Picture.Graphic.Width>img.Width) or (img.Picture.Graphic.Height>img.Height);
    SetXBoxItemIndex(_cmbAlignTo, ord(TRVGraphicItemInfo(item).VAlign));

    seVShift.Value := TRVGraphicItemInfo(item).VShift;
    if TRVGraphicItemInfo(item).VShiftAbs then
      SetXBoxItemIndex(_cmbVShiftType, 1)
    else
      SetXBoxItemIndex(_cmbVShiftType, 0);
    SetXBoxItemIndex(_cmbWType, 1);
    SetXBoxItemIndex(_cmbHType, 1);
    if TRVGraphicItemInfo(item).ImageWidth<>0 then
      seWidth.Value := TRVGraphicItemInfo(item).ImageWidth;
    if TRVGraphicItemInfo(item).ImageHeight<>0 then
      seHeight.Value := TRVGraphicItemInfo(item).ImageHeight;
    SetControlCaption(_lblDefSize, Format(RVA_GetS(rvam_ip_DefaultSize), [img.Picture.Graphic.Width, img.Picture.Graphic.Height]));
    _gbSize.Visible := not (img.Picture.Graphic is TIcon);
    seSpacing.Value := TRVGraphicItemInfo(item).Spacing;
    SetControlCaption(_txtAlt, TRVGraphicItemInfo(item).Alt);
  end;
  {........................................}
  if item is TRVBreakItemInfo then begin
    Result := True;
    HelpContext := 90900;
    _pc.HandleNeeded;
    HideTabSheet(_tsImage);
    HideTabSheet(_tsImgLayout);
    HideTabSheet(_tsTable);
    HideTabSheet(_tsCells);
    HideTabSheet(_tsRows);
    SetPageControlActivePage(_pc, _tsBreak);
    cmbBreakColor.ChosenColor := TRVBreakItemInfo(item).Color;
    v := TRVBreakItemInfo(item).LineWidth-1;
    if (v<0) then
      v := 0;
    if (v>=GetXBoxItemCount(_cmbWidth)) then
      v := GetXBoxItemCount(_cmbWidth)-1;
    SetXBoxItemIndex(_cmbWidth, v);
  end;
  {........................................}
  if item is TRVTableItemInfo then begin
    Result := True;
    SetTable(TRVTableItemInfo(item), False);
  end;
end;

procedure TfrmRVItemProp.GetItem(rve: TCustomRichViewEdit);
var gr: TGraphic;
    Data: Integer;
begin
  rve := rve.TopLevelEditor;
  rve.BeginUndoGroup(rvutModifyItem);
  rve.SetUndoGroupMode(True);
  try
    {........................................}
    if rve.GetCurrentItem is TRVGraphicItemInfo then begin
      gr := RV_CreateGraphics(TGraphicClass(img.Picture.Graphic.ClassType));
      gr.Assign(img.Picture.Graphic);
      if gr is TBitmap then begin
         TBitmap(gr).Transparent := GetCheckBoxChecked(_cbTransp);
         if cmbColor.ChosenColor=cmbColor.AutoColor then
           TBitmap(gr).TransparentMode := tmAuto
         else begin
           TBitmap(gr).TransparentMode := tmFixed;
           TBitmap(gr).TransparentColor := cmbColor.ChosenColor;
         end;
      end;
      rve.SetCurrentPictureInfo(rve.GetCurrentItemText, gr,
        TRVVAlign(GetXBoxItemIndex(_cmbAlignTo)), rve.GetCurrentTag);
      rve.BeginCurrentItemModify(Data);
      if not seWidth.Indeterminate then
        if GetXBoxItemIndex(_cmbWType)=1 then
          rve.SetCurrentItemExtraIntProperty(rvepImageWidth, seWidth.AsInteger, False)
        else
          rve.SetCurrentItemExtraIntProperty(rvepImageWidth, Round(seWidth.AsInteger*gr.Width/100) , False)
      else
        rve.SetCurrentItemExtraIntProperty(rvepImageWidth, 0 , False);
      if not seHeight.Indeterminate then
        if GetXBoxItemIndex(_cmbHType)=1 then
          rve.SetCurrentItemExtraIntProperty(rvepImageHeight, seHeight.AsInteger, False)
        else
          rve.SetCurrentItemExtraIntProperty(rvepImageHeight, Round(seHeight.AsInteger*gr.Height/100) , False)
      else
        rve.SetCurrentItemExtraIntProperty(rvepImageHeight, 0 , False);
      if GetXBoxItemIndex(_cmbVShiftType)=0 then
        rve.SetCurrentItemExtraIntProperty(rvepVShiftAbs, 0, False)
      else
        rve.SetCurrentItemExtraIntProperty(rvepVShiftAbs, 1, False);
      rve.SetCurrentItemExtraIntProperty(rvepVShift, seVShift.AsInteger, False);
      if not seSpacing.Indeterminate then
        rve.SetCurrentItemExtraIntProperty(rvepSpacing, seSpacing.AsInteger, False);
      rve.SetCurrentItemExtraStrProperty(rvespAlt, GetEditText(_txtAlt), False);
      rve.EndCurrentItemModify(Data);
      rve.Change;
      end
    {........................................}
    else if rve.GetCurrentItem is TRVBreakItemInfo then begin
      rve.SetCurrentBreakInfo(GetXBoxItemIndex(_cmbWidth)+1, rvbsLine,
        cmbBreakColor.ChosenColor, rve.GetCurrentTag);
      end
    else if rve.GetCurrentItem is TRVTableItemInfo then begin
      GetTable(rve, TRVTableItemInfo(rve.GetCurrentItem));
    end;
  finally
    rve.SetUndoGroupMode(False);
  end;
end;

procedure TfrmRVItemProp.FormActivate(Sender: TObject);
begin
  inherited;
  cmbColor.ColorDialog := ColorDialog;
  cmbBreakColor.ColorDialog := ColorDialog;
  cmbTableColor.ColorDialog := ColorDialog;
  cmbCellColor.ColorDialog := ColorDialog;
end;


procedure TfrmRVItemProp.cmbColorColorChange(Sender: TObject);
begin
  if Visible then
    SetCheckBoxChecked(_cbTransp, True);
end;

procedure TfrmRVItemProp.cmbVShiftTypeClick(Sender: TObject);
begin
  if not Visible or (img.Picture.Graphic.Height=0) then
    exit;
  if GetXBoxItemIndex(_cmbVShiftType)=0 then
    // convert to percents
    seVShift.Value := Round (seVShift.Value * 100 / img.Picture.Graphic.Height)
  else
    // convert to pixels
    seVShift.Value := Round (seVShift.Value * img.Picture.Graphic.Height / 100);
end;

procedure TfrmRVItemProp.cmbWTypeClick(Sender: TObject);
begin
  if not Visible or (img.Picture.Graphic.Width=0) or seWidth.Indeterminate then
    exit;
  if GetXBoxItemIndex(_cmbWType)=0 then
    // convert to percents
    seWidth.Value := Round (seWidth.Value * 100 / img.Picture.Graphic.Width)
  else
    // convert to pixels
    seWidth.Value := Round (seWidth.Value * img.Picture.Graphic.Width / 100);
end;

procedure TfrmRVItemProp.cmbHTypeClick(Sender: TObject);
begin
  if not Visible or (img.Picture.Graphic.Height=0) or seHeight.Indeterminate then
    exit;
  if GetXBoxItemIndex(_cmbHType)=0 then
    // convert to percents
    seHeight.Value := Round (seHeight.Value * 100 / img.Picture.Graphic.Height)
  else
    // convert to pixels
    seHeight.Value := Round (seHeight.Value * img.Picture.Graphic.Height / 100);
end;

procedure TfrmRVItemProp.btnChangeImageClick(Sender: TObject);
var opd: TOpenPictureDialog;
begin
  opd := TOpenPictureDialog.Create(Self);

⌨️ 快捷键说明

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