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

📄 rvedit.pas

📁 richview1.7 full.source
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    property EditorOptions;
    property ReadOnly;
    property UndoLimit;

    property OnCaretGetOut;
    property OnChange;
    property OnChanging;
    property OnCaretMove;
    property OnCurParaStyleChanged;
    property OnCurTextStyleChanged;
    property OnPaste;
    property OnParaStyleConversion;
    property OnStyleConversion;
    property TabNavigation;
    { Published standard properties }
    property Align;
    {$IFDEF RICHVIEWDEF4}
    property Anchors;
    property Constraints;
    {$ENDIF}
    property Color default clNone;
    property Ctl3D;
    {$IFDEF RICHVIEWDEF4}
    property DragKind;
    {$ENDIF}
    property DragMode;
    property Enabled;
    property HelpContext;
    property ParentCtl3D;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop default True;
    property Visible;
    { Published standard events }
    property OnClick;
    {$IFDEF RICHVIEWDEF5}
    property OnContextPopup;
    {$ENDIF}
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseMove;
    {$IFDEF RICHVIEWDEF4}
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;
    property OnResize;    
    {$ENDIF}
    property OnStartDrag;
    { Published RichView properties }
    property BackgroundBitmap;
    property BackgroundStyle default bsNoBitmap;
    property BiDiMode;
    property BorderStyle default bsSingle;
    property BottomMargin;
    //property CPEventKind stored False;
    property Cursor default crIBeam;
    property Delimiters;
    property DoInPaletteMode;
    property FirstJumpNo;
    property HScrollVisible;
    property LeftMargin;
    property MaxTextWidth;
    property MinTextWidth;
    property Options;
    property RightMargin;
    property RTFOptions;
    property RTFReadProperties;
    property RVFOptions;
    property RVFParaStylesReadMode;
    property RVFTextStylesReadMode;
    {$IFDEF RVFLATSCROLLBARS}
    property ScrollBarColor;
    property ScrollBarStyle;
    {$ENDIF}
    property Style;
    //property TabNavigation;
    property TopMargin;
    property Tracking;
    property UseXPThemes;
    property VScrollVisible;
    {$IFDEF RICHVIEWDEF4}
    property WheelStep;
    {$ENDIF}
    { Published RichView events }
    //property OnCheckpointVisible;
    property OnControlAction;
    property OnCopy;
    {$IFDEF RV_ODHC}
    property OnDocumentHeightChange;
    {$ENDIF}
    property OnItemAction;
    property OnJump;
    property OnHScrolled;    
    property OnHTMLSaveImage;
    property OnPaint;    
    property OnReadHyperlink;    
    property OnRVDblClick;
    property OnRVFImageListNeeded;
    property OnRVFControlNeeded;
    property OnRVFPictureNeeded;
    property OnRVMouseDown;
    property OnRVMouseMove;
    property OnRVMouseUp;
    property OnRVRightClick;
    property OnSaveComponentToFile;
    property OnSaveHTMLExtra;
    property OnSaveRTFExtra;    
    property OnSelect;
    property OnURLNeeded;
    property OnVScrolled;
    { obsolete properties }
    property AllowSelection;
    property SingleClick;
  end;

  TRichViewUnicodeInput = (rvuiStandard, rvuiAlternative);

const RichViewUnicodeInput: TRichViewUnicodeInput = rvuiStandard;

implementation
uses RVERVData, RVUndo, RVStr;
{------------------------------------------------------------------------------}
constructor TCustomRichViewEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  KeyboardScroll   := False;
  Flags            := Flags + [rvflRootEditor] - [rvflUseJumps{, rvflTrim},rvflUseExternalLeading];
  Cursor           := crIBeam;
  EditorOptions    := DEFAULT_RVEDITOROPTIONS;
  UndoLimit        := -1;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.CreateParams(var Params: TCreateParams);
begin
   inherited CreateParams(Params);
   FVDisableNoScroll := True;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.GetDataClass: TRichViewRVDataClass;
begin
   Result := TRVEditRVData;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.BeforeInserting: Boolean;
var StyleNo: Integer;
begin
  Result := False;
  if (RVData.PartialSelectedItem<>nil) or not CanDelete or
    not BeforeChange(False) then begin
    TRVEditRVData(RVData).Beep;
    exit;
  end;
  TRVEditRVData(RVData).BeginUndoSequence(rvutInsert, True);
  SetUndoGroupMode(True);
  StyleNo := CurTextStyleNo;
  TRVEditRVData(RVData).DeleteSelection_;
  TRVEditRVData(RVData).Deselect(nil, True);
  CurTextStyleNo := StyleNo;
  Result := True;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.AfterInserting;
begin
  SetUndoGroupMode(False);
  Refresh;
  Change;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.InsertBreak(Width: Byte; Style: TRVBreakStyle; Color: TColor);
var info: TRVBreakItemInfo;
    s: String;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    TCustomRichViewEdit(InplaceEditor).InsertBreak(Width, Style, Color);
    exit;
  end;
  {$ENDIF}
  if not BeforeInserting then exit;
  try
    info := TRVBreakItemInfo.CreateEx(RVData, Width, Style, Color);
    s := '';
    TRVEditRVData(RVData).InsertSomething(info, s, False, False);
  finally
    AfterInserting;
  end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.InsertBullet(ImageIndex: Integer; ImageList: TCustomImageList);
var info: TRVBulletItemInfo;
    s: String;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    TCustomRichViewEdit(InplaceEditor).InsertBullet(ImageIndex, ImageList);
    exit;
  end;
  {$ENDIF}
  if not BeforeInserting then exit;
  try
    info  := TRVBulletItemInfo.CreateEx(RVData, ImageIndex, ImageList, rvvaBaseline);
    s := '';
    TRVEditRVData(RVData).InsertSomething(info, s, False, False);
  finally
    AfterInserting;
  end;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.InsertItem(const Name: String; Item: TCustomRVItemInfo): Boolean;
var s: String;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    Result := TCustomRichViewEdit(InplaceEditor).InsertItem(Name, Item);
    exit;
  end;
  {$ENDIF}
  if not BeforeInserting then begin
    Item.Free;
    Result := False;
    exit;
  end;
  try
    s := Name;
    Result := TRVEditRVData(RVData).InsertSomething(Item, s, False, False);
  finally
    AfterInserting;
  end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.InsertText(const text: String;  CaretBefore: Boolean {$IFDEF RICHVIEWDEF4}=False{$ENDIF});
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    TCustomRichViewEdit(InplaceEditor).InsertText(text, CaretBefore);
    exit;
  end;
  {$ENDIF}
  if not BeforeInserting then exit;
  try
    TRVEditRVData(RVData).InsertText_(text, True, CaretBefore);
  finally
    SetUndoGroupMode(False);
    Change;
  end;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.InsertTextFromFile(const FileName: String):Boolean;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    Result := TCustomRichViewEdit(InplaceEditor).InsertTextFromFile(FileName);
    exit;
  end;
  {$ENDIF}
  Result := True;
  if not BeforeInserting then exit;
  try
    Result := TRVEditRVData(RVData).InsertTextFromFile(FileName, False, False);
  finally
    SetUndoGroupMode(False);
    Change;
  end;
end;
{------------------------------------------------------------------------------}
{$IFNDEF RVDONOTUSEUNICODE}
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.BeforeUnicode;
begin
  if not Style.TextStyles[CurTextStyleNo].Unicode and
     (Style.DefUnicodeStyle>=0) and
     (Style.DefUnicodeStyle<Style.TextStyles.Count) then
    CurTextStyleNo := Style.DefUnicodeStyle;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.InsertTextFromFileW(const FileName: String):Boolean;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    Result := TCustomRichViewEdit(InplaceEditor).InsertTextFromFileW(FileName);
    exit;
  end;
  {$ENDIF}
  Result := True;
  if not BeforeInserting then exit;
  try
    BeforeUnicode;
    Result := TRVEditRVData(RVData).InsertTextFromFileW(FileName,True);
  finally
    SetUndoGroupMode(False);
    Change;
  end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.InsertTextW_(const text: String);
begin
  if not BeforeInserting then exit;
  try
    BeforeUnicode;
    TRVEditRVData(RVData).InsertTextW_(text,True, False);
  finally
    SetUndoGroupMode(False);
    Change;
  end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.PasteTextW;
var
    mem: Cardinal;
    ptr: Pointer;
    s: String;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    TCustomRichViewEdit(InplaceEditor).PasteTextW;
    exit;
  end;
  {$ENDIF}
  if not BeforeChange(False) then exit;
  if not Clipboard.HasFormat(CF_UNICODETEXT) then exit;
  Clipboard.Open;
  try
    mem := Clipboard.GetAsHandle(CF_UNICODETEXT);
    SetLength(s, GlobalSize(mem));
    ptr := GlobalLock(mem);
    Move(ptr^,PChar(s)^, Length(s));
    GlobalUnlock(mem);
  finally
    Clipboard.Close;
  end;
  if Length(s)=0 then exit;
  ptr := RVU_StrScanW(Pointer(s), 0, Length(s) div 2);
  if ptr<>nil then
    SetLength(s, PChar(ptr)-PChar(s));
  InsertTextW_(s);
end;
function TCustomRichViewEdit.GetCurrentItemTextA: String;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
    Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItemTextA;
    exit;

⌨️ 快捷键说明

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