📄 unit1.pas
字号:
begin
RichViewEdit1.PasteRVF;
end;
{ Edit|Paste As|Ole ---------------------------------------------------}
procedure TForm1.mitPasteAsOleClick(Sender: TObject);
var oc: TOleContainer;
begin
oc := TOleContainer.Create(nil);
if oc.CanPaste then begin
oc.Visible := False;
oc.BorderStyle := bsNone;
oc.Parent := RichViewEdit1;
oc.SizeMode := smAutoSize;
oc.Paste;
RichViewEdit1.InsertControl('', oc,rvvaBaseline);
oc.OnResize := OnOleResize;
oc.OnActivate := OnOleActivate;
oc.OnDeactivate := OnOleDeactivate;
oc.Visible := True;
end
else
oc.Free;
end;
{-----------------------------------------------------------------------}
procedure TForm1.CloseOleContainer;
begin
if ActiveOleContainer<>nil then begin
ActiveOleContainer.Close;
ActiveOleContainer := nil;
end;
end;
{-----------------------------------------------------------------------}
procedure TForm1.OnOleResize(Sender: TObject);
begin
RichViewEdit1.AdjustControlPlacement2(TControl(Sender));
end;
{-----------------------------------------------------------------------}
procedure TForm1.OnOleActivate(Sender: TObject);
begin
if ActiveOleContainer<>Sender then
CloseOleContainer;
ActiveOleContainer := TOleContainer(Sender);
RichViewEdit1.AdjustControlPlacement2(TControl(Sender));
end;
{-----------------------------------------------------------------------}
procedure TForm1.OnOleDeactivate(Sender: TObject);
begin
RichViewEdit1.AdjustControlPlacement2(TControl(Sender));
end;
{-----------------------------------------------------------------------}
procedure TForm1.RichViewEdit1Click(Sender: TObject);
begin
CloseOleContainer;
end;
{-----------------------------------------------------------------------}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CloseOleContainer;
end;
{-----------------------------------------------------------------------}
procedure TForm1.RichViewEdit1ControlAction(Sender: TCustomRichView;
ControlAction: TRVControlAction; ItemNo: Integer; var ctrl: TControl);
begin
if ControlAction=rvcaAfterRVFLoad then begin
if ctrl is TOleContainer then begin
TOleContainer(ctrl).OnResize := OnOleResize;
TOleContainer(ctrl).OnActivate := OnOleActivate;
TOleContainer(ctrl).OnDeactivate := OnOleDeactivate;
end
else if ctrl is TButton then
TButton(ctrl).OnClick := OnControlClick
else if ctrl is TEdit then
TEdit(ctrl).OnClick := OnControlClick
end;
if ctrl<>ActiveOleContainer then
exit;
if ControlAction in [rvcaMoveToUndoList, rvcaDestroy, rvcaBeforeRVFSave] then
CloseOleContainer;
end;
{ Edit|Delete ---------------------------------------------------------}
procedure TForm1.mitDeleteClick(Sender: TObject);
begin
// Shortcut to this item is Ctrl+Del
// If you make it Del, you will be unable to use del key in editor
RichViewEdit1.DeleteSelection;
end;
{ Edit|Select All -----------------------------------------------------}
procedure TForm1.mitSelectAllClick(Sender: TObject);
begin
{ warning: SelectAll moves caret to the end of the text }
RichViewEdit1.SelectAll;
RichViewEdit1.SetFocus;
RichViewEdit1.Invalidate;
end;
{ Another clipboard-related action ------------------------------------}
procedure TForm1.RichViewEdit1Select(Sender: TObject);
begin
mitCopy.Enabled := RichViewEdit1.SelectionExists;
mitCut.Enabled := mitCopy.Enabled;
mitDelete.Enabled := mitCopy.Enabled;
end;
{ Edit| Insert Page Break----------------------------------------------}
procedure TForm1.mitInsertPageBreakClick(Sender: TObject);
begin
RichViewEdit1.InsertPageBreak;
end;
{ Edit| Remove Page Break----------------------------------------------}
procedure TForm1.mitRemovePageBreakClick(Sender: TObject);
begin
RichViewEdit1.RemoveCurrentPageBreak;
end;
{----------------------------------------------------------------------}
{ This demo understands both tag modes:
1. rvoTagsArePChars is in Options (tags are strings)
2. rvoTagsArePChars is not in Options (tags are integers).
So this demo uses two simple universal functions below for convering
tag to String and String to tag.
}
function GetTagStr(Tag: Integer): String;
begin
if (rvoTagsArePChars in Form1.RichViewEdit1.Options) then
if Tag = 0 then
Result := ''
else
Result := PChar(Tag)
else
Result := IntToStr(Tag);
end;
function MakeTag(TagStr: String): Integer;
begin
if (TagStr<>'') and (rvoTagsArePChars in Form1.RichViewEdit1.Options) then
Result := Integer(StrNew(PChar(TagStr)))
else
Result := StrToIntDef(TagStr,0);
end;
{ Edit|Checkpoint... --------------------------------------------------}
procedure TForm1.mitEditCheckpointClick(Sender: TObject);
var CpNo, Tag: Integer;
Name: String;
CheckPointData: TCheckPointData;
RaiseEvent: Boolean;
begin
CheckPointData := RichViewEdit1.GetCurrentCheckpoint;
if CheckPointData<>nil then begin
RichViewEdit1.GetCheckpointInfo(CheckPointData,Tag,Name,RaiseEvent);
CpNo := RichViewEdit1.GetCheckpointNo(CheckPointData);
frmCp.lblStatus.Caption := 'Editing checkpoint #'+IntToStr(CpNo);
frmCp.txtName.Text := Name;
frmCp.txtTag.Text := GetTagStr(Tag);
frmCp.btnOk.Caption := 'OK';
frmCp.btnDelete.Enabled := True;
end
else begin
frmCp.lblStatus.Caption := 'Checkpoint does not exist';
frmCp.txtName.Text := '';
frmCp.txtTag.Text := GetTagStr(0);
frmCp.btnOk.Caption := 'Add';
frmCp.btnDelete.Enabled := False;
end;
case frmCP.ShowModal of
mrOk: { add new checkpoint or modify existed one }
RichViewEdit1.SetCurrentCheckpointInfo(MakeTag(frmCp.txtTag.Text),
frmCp.txtName.Text,False);
mrYes: { delete checkpoint }
RichViewEdit1.RemoveCurrentCheckpoint;
end;
end;
{ Edit|Search... -------------------------------------}
procedure TForm1.mitSearchClick(Sender: TObject);
begin
FindDialog1.Execute;
end;
{-----------------------------------------------------------------------}
procedure TForm1.FindDialog1Find(Sender: TObject);
begin
if not RichViewEdit1.SearchText(FindDialog1.FindText,
GetRVESearchOptions(FindDialog1.Options)) then
Application.MessageBox('Can''t find', 'Search complete', MB_OK or MB_ICONEXCLAMATION);
end;
{ Edit|Select Current Word -------------------------------------}
procedure TForm1.mitSelectCurrentWordClick(Sender: TObject);
begin
RichViewEdit1.SelectCurrentWord;
// now you can do something with current word:
// translate or spell check, for example...
end;
{ Edit|Current Item Properties... -------------------------------------}
procedure TForm1.mitEditPropsClick(Sender: TObject);
var s: String;
Tag, Index: Integer;
VAlign: TRVVAlign;
ImageList: TCustomImageList;
gr: TGraphic;
ctrl: TControl;
BreakColor: TColor;
BreakStyle: TRVBreakStyle; // <- not implemented
BreakWidth: Byte;
begin
frmProp.PageControl1.Visible := True;
frmProp.tsBullet.TabVisible := False;
frmProp.tsHotSpot.TabVisible := False;
frmProp.tsPicture.TabVisible := False;
frmProp.tsText.TabVisible := False;
frmProp.tsComponent.TabVisible := False;
frmProp.tsBreak.TabVisible := False;
frmProp.txtName.Enabled := True;
case RichViewEdit1.CurItemStyle of
rvsBullet:
begin
RichViewEdit1.GetCurrentBulletInfo(s, Index, ImageList, Tag);
frmProp.tsBullet.TabVisible := True;
frmProp.rgBullet.ItemIndex := Index;
frmProp.txtName.Text := s;
frmProp.txtTag.Text := GetTagStr(Tag);
end;
rvsHotspot:
begin
// you can use GetCurrentBulletInfo or GetCurrentHotspotInfo
// to receive info about hotspot in caret position.
// in this demo we need not HotImageIndex, because here
// HotImageIndex = ImageIndex+2
// and so we can use GetCurrentBulletInfo
RichViewEdit1.GetCurrentBulletInfo(s, Index, ImageList, Tag);
frmProp.tsHotspot.TabVisible := True;
frmProp.rgHotspot.ItemIndex := Index-3;
frmProp.txtName.Text := s;
frmProp.txtTag.Text := GetTagStr(Tag);
end;
rvsPicture, rvsHotPicture:
begin
RichViewEdit1.GetCurrentPictureInfo(s, gr, VAlign, Tag);
frmProp.tsPicture.TabVisible := True;
frmProp.Image1.Picture.Graphic := gr;
frmProp.txtName.Text := s;
frmProp.txtTag.Text := GetTagStr(Tag);
frmProp.rgPicVAlign.ItemIndex := Integer(VAlign);
end;
rvsComponent:
begin
RichViewEdit1.GetCurrentControlInfo(s, ctrl, VAlign, Tag);
frmProp.tsComponent.TabVisible := True;
frmProp.txtWidth.Text := IntToStr(ctrl.Width);
frmProp.txtHeight.Text := IntToStr(ctrl.Height);
frmProp.txtName.Text := s;
frmProp.lblComponent.Caption := ctrl.ClassName;
frmProp.txtTag.Text := GetTagStr(Tag);
frmProp.rgCtrlVAlign.ItemIndex := Integer(VAlign);
end;
rvsBreak:
begin
frmProp.tsBreak.TabVisible := True;
RichViewEdit1.GetCurrentBreakInfo(BreakWidth, BreakStyle, BreakColor, Tag);
frmProp.txtBreakWidth.Text := IntToStr(BreakWidth);
case BreakColor of
clNone:
frmProp.rgBreakColor.ItemIndex := 0;
clRed:
frmProp.rgBreakColor.ItemIndex := 1;
clGreen:
frmProp.rgBreakColor.ItemIndex := 2;
clBlue:
frmProp.rgBreakColor.ItemIndex := 3;
end;
frmProp.txtName.Text := '(not available for breaks)';
frmProp.txtName.Enabled := False;
frmProp.txtTag.Text := GetTagStr(Tag);
end;
rvsTable:
begin
frmProp.txtName.Text := RichViewEdit1.GetCurrentItemText;
frmProp.txtTag.Text := GetTagStr(RichViewEdit1.GetCurrentTag);
frmProp.PageControl1.Visible := False;
end;
else
begin
frmProp.lblText.Caption := RichViewEdit1.GetCurrentItemTextA;
frmProp.txtTag.Text := GetTagStr(RichViewEdit1.GetCurrentTag);
frmProp.tsText.TabVisible := True;
frmProp.txtName.Text := '(not available for text)';
frmProp.txtName.Enabled := False;
end;
end;
if frmProp.ShowModal=mrOk then
case RichViewEdit1.CurItemStyle of
rvsBullet:
begin
RichViewEdit1.SetCurrentBulletInfo(
frmProp.txtName.Text,
frmProp.rgBullet.ItemIndex,
nil,
MakeTag(frmProp.txtTag.Text));
end;
rvsHotspot:
begin
RichViewEdit1.SetCurrentHotspotInfo(
frmProp.txtName.Text,
frmProp.rgHotspot.ItemIndex+3,
frmProp.rgHotspot.ItemIndex+3+2,
nil,
MakeTag(frmProp.txtTag.Text));
end;
rvsPicture, rvsHotPicture:
begin
{ first we need to create a copy of image ...}
gr := TGraphic(frmProp.Image1.Picture.Graphic.ClassType.Create);
gr.Assign(frmProp.Image1.Picture.Graphic);
RichViewEdit1.SetCurrentPictureInfo(
frmProp.txtName.Text,
gr,
TRVVAlign(frmProp.rgPicVAlign.ItemIndex),
MakeTag(frmProp.txtTag.Text));
end;
rvsComponent:
begin
// we wish these setting to be undone as one action,
// so we use BeginUndoGroup, SetUndoGroupMode(True), settings, SetUndoGroupMode(False)
RichViewEdit1.BeginUndoGroup(rvutModifyItem);
// you can use BeginUndoCustomGroup instead of BeginUndoGroup
// example:
// RichViewEdit1.BeginUndoCustomGroup('modifying control');
// In this case undo type will be rvutCustom
// (look at TForm1.UpdateUndoMenu in this file)
RichViewEdit1.SetUndoGroupMode(True);
RichViewEdit1.SetCurrentControlInfo(
frmProp.txtName.Text,
TRVVAlign(frmProp.rgCtrlVAlign.ItemIndex),
MakeTag(frmProp.txtTag.Text));
RichViewEdit1.ResizeCurrentControl(
StrToIntDef(frmProp.txtWidth.Text, ctrl.Width),
StrToIntDef(frmProp.txtHeight.Text, ctrl.Height));
RichViewEdit1.SetUndoGroupMode(False);
end;
rvsBreak:
begin
case frmProp.rgBreakColor.ItemIndex of
-1,0:
BreakColor := clNone;
1:
BreakColor := clRed;
2:
BreakColor := clGreen;
3:
BreakColor := clBlue;
end;
BreakWidth := StrToIntDef(frmProp.txtBreakWidth.Text,1);
RichViewEdit1.SetCurrentBreakInfo(BreakWidth,BreakStyle,BreakColor,
MakeTag(frmProp.txtTag.Text));
end;
rvsTable:
begin
RichViewEdit1.BeginUndoGroup(rvutModifyItem);
RichViewEdit1.SetUndoGroupMode(True);
RichViewEdit1.SetCurrentItemText(frmProp.txtName.Text);
RichViewEdit1.SetCurrentTag(MakeTag(frmProp.txtTag.Text));
RichViewEdit1.SetUndoGroupMode(False);
end;
else
begin
RichViewEdit1.SetCurrentTag(MakeTag(frmProp.txtTag.Text));
end;
end;
end;
{======================================================================}
{ Main menu : "Misc" }
{======================================================================}
{ Misc | Go to checkpoint ... -----------------------------------------}
procedure TForm1.mitCheckPointListClick(Sender: TObject);
var X,Y,Tag: Integer;
Name: String;
CheckpointData: TCheckpointData;
RaiseEvent: Boolean;
s: String;
begin
frmList.lst.Items.Clear;
CheckpointData := RichViewEdit1.GetFirstCheckPoint;
while CheckpointData<>nil do begin
RichViewEdit1.GetCheckpointInfo(CheckpointData,Tag,Name,RaiseEvent);
RichViewEdit1.GetCheckpointXY(CheckpointData,X,Y);
s := Format('(X:%d,Y:%d) Name:"%s" Tag:"%s"', [X,Y,Name,GetTagStr(Tag)]);
frmList.lst.Items.Add(s);
CheckpointData := RichViewEdit1.GetNextCheckpoint(CheckpointData);
end;
if frmList.ShowModal=mrOk then
with RichViewEdit1 do
ScrollTo(GetCheckPointY(frmList.lst.ItemIndex));
end;
{ Misc | Read-Only -----------------------------------------------------}
procedure TForm1.mitReadOnlyClick(Sender: TObject);
begin
RichViewEdit1.ReadOnly := not RichViewEdit1.ReadOnly;
mitReadOnly.Checked := RichViewEdit1.ReadOnly;
end;
{ Misc | Background submenu popups ------------------------------------}
procedure TForm1.mpdBackgroundClick(Sender: TObject);
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -