RVEdit.pas
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:161k
- {*******************************************************}
- { }
- { RichView }
- { TRichViewEdit: document editor. }
- { (registered on "RichView" page of }
- { the Component Palette) }
- { }
- { Copyright (c) Sergey Tkachenko }
- { svt@trichview.com }
- { http://www.trichview.com }
- { }
- {*******************************************************}
- unit RVEdit;
- interface
- {$I RV_Defs.inc}
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, RichEdit,
- {$IFDEF RVUSEIME}
- Imm,
- {$ENDIF}
- {$IFNDEF RVDONOTUSELISTS}
- RVMarker,
- {$ENDIF}
- {$IFDEF RICHVIEWDEF4}
- ImgList,
- {$ENDIF}
- {$IFNDEF RVDONOTUSEDRAGDROP}
- ActiveX, ShlObj, RVDragDrop,
- {$ENDIF}
- RVScroll, RVStyle, RVItem, RichView, DLines, Clipbrd, RVFuncs, RVUni,
- CRVData, CRVFData, RVRVData,
- RVRTFErr;
- const
- WM_RVUNDOFROMINPLACE = WM_USER+13;
- WM_RVREDOFROMINPLACE = WM_USER+14;
- {$IFNDEF RICHVIEWCBDEF3}
- EM_REDO = WM_USER + 84;
- EM_CANREDO = WM_USER + 85;
- {$ENDIF}
- type
- { Options for TCustomRichViewEdit.SearchText }
- TRVESearchOption = (
- rvseoMatchCase, // match case
- rvseoDown, // search from top to bottom
- rvseoWholeWord); // match whole words
- TRVESearchOptions = set of TRVESearchOption;
- { Values for TCustomRichViewEdit.EditorOptions }
- TRVEditorOption = (
- rvoClearTagOnStyleApp, // ApplyTextStyle and ApplyStyleConversion clear tags
- rvoCtrlJumps, // When user holds Ctrl key, switching to hypertext mode
- rvoDoNotWantReturns, // Ignore Enter keys
- rvoDoNotWantShiftReturns, // Ignore Shift+Enter keys
- rvoWantTabs, // Do not ignore Tab keys
- rvoAutoSwitchLang, // Process WM_INPUTLANGCHANGE. For non-Unicode text,
- // switch to style with the proper charset (new
- // styles can be added to the collection!)
- rvoHideReadOnlyCaret, // Hide caret when ReadOnly is True
- rvoNoImageResize, // Disallow resizing images
- rvoNoCaretHighlightJumps); // Disallow highlighting hyperlinks at caret position
- TRVEditorOptions = set of TRVEditorOption;
- { Drag&drop formats }
- TRVDragDropFormat = (
- rvddRVF, // RVF ('RichView Format')
- rvddRTF, // RTF ('Rich Text Format')
- rvddText, // ANSI text (CF_TEXT)
- rvddUnicodeText, // Unicode text (CF_UNICODETEXT)
- rvddBitmap, // Bitmap (CF_DIB or CF_BITMAP)
- rvddMetafile, // Metafile (CF_ENHMETAFILE);
- rvddURL, // 'UniformResourceLocator'
- rvddFiles); // list of files (CF_HDROP)
- TRVDragDropFormats = set of TRVDragDropFormat;
- { Drag&drop effects }
- TRVDropFileAction = (
- rvdfNone, // Files were ignored
- rvdfInsert, // Files were Inserted
- rvdfLink); // Link to files were created
- { Types of undo/redo operations }
- TRVUndoType = (
- rvutNone, // n/a
- rvutDelete, // deleting
- rvutInsert, // inserting
- rvutPara, // applying paragraph styles
- rvutMiscTyping, // editing (such as Backspace)
- rvutInsertPageBreak, // insert page-break
- rvutRemovePageBreak, // remove page-break
- rvutTyping, // text typing
- rvutTag, // changing tags
- rvutStyleNo, // applying text styles
- rvutAddCheckpoint, // adding checkpoints
- rvutRemoveCheckpoint, // removing checkpoints
- rvutModifyCheckpoint, // editing checkpoints
- rvutModifyItem, // chaning item properties
- rvutList, // applying/removing/editing paragraph lists
- rvutCustom); // custom (see TCustomRichViewEdit.BeginUndoCustomGroup)
- { Values for Direction parameter of TCustomRichViewEdit.OnCaretGetOut event }
- TRVGetOutDirection = (
- rvdLeft, // Left at the beginning of doc
- rvdUp, // Up at the beginning of doc
- rvdRight, // Right at the end of doc
- rvdDown, // Down at the end of doc
- rvdTop, // Ctrl+Home
- rvdBottom); // Ctrl+End
- { for OnOle*** events }
- TRVOleDropEffect = (rvdeNone, rvdeCopy, rvdeMove, rvdeLink);
- TRVOleDropEffects = set of TRVOleDropEffect;
- type
- TCustomRichViewEdit = class;
- { ------------- Types for events of TCustomRichViewEdit -------------------- }
- { OnStyleConversion & OnParaStyleConversion. Occurs when calling
- ApplyStyleConversion or ApplyParaStyleConversion.
- Parameters:
- [in] StyleNo: current text/para style index;
- [in] UserData: value passed to ApplyStyleConversion/ApplyParaStyleConversion;
- [in] AppliedToText: false if the event is called to change current text style
- (not used in OnParaStyleConversion)
- [out] NewStyleNo: set it to text/para style index }
- TRVStyleConversionEvent = procedure (Sender: TCustomRichViewEdit;
- StyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer) of object;
- { Internal procedure for the same }
- TRVStyleConversionEvent_ = procedure (Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean) of object;
- { OnPaste. Occurs when pasting from the Clipboard.
- Allows to paste in your formats or forbid default pasting.
- Parameters:
- [out] DoDefault: set it to false to prevent default pasting. }
- TRVPasteEvent = procedure (Sender: TCustomRichViewEdit;
- var DoDefault: Boolean) of object;
- { OnCaretGetOut. Occurs when user presses arrow keys at the beginning/end of
- document in "outside" direction.
- Parameters:
- [in] Direction: see TRVGetOutDirection type }
- TRVOnCaretGetOutEvent = procedure (Sender: TCustomRichViewEdit;
- Direction: TRVGetOutDirection) of object;
- { OnChanging. Occurs before editing operations.
- Parameters:
- [out] CanEdit: set to false to disallow the operation. }
- TRVChangingEvent = procedure (Sender: TCustomRichViewEdit;
- var CanEdit: Boolean) of object;
- { OnDropFiles. Occurs when dropping files in CF_HDROP format, for example from
- Windows Explorer (rvddFiles must be in AcceptDragDropFormats.
- Parameters:
- [in] Files: a list of file names.
- [out] FileAction: if you inserted files, set to rvdfInserted. If you
- inserted hyperlinks to files, set to rvdfLinked. Ignored if DoDefault is True.
- [out] DoDefault: set to False if you want to allow default processing for
- dropped files. }
- TRVDropFilesEvent = procedure (Sender: TCustomRichViewEdit;
- Files: TStrings; var FileAction: TRVDropFileAction; var DoDefault: Boolean) of object;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- TRVOleDragEnterEvent = procedure (Sender: TCustomRichView; const DataObject: IDataObject;
- Shift: TShiftState;
- X, Y: Integer; PossibleDropEffects: TRVOleDropEffects;
- var DropEffect: TRVOleDropEffect) of object;
- TRVOleDragOverEvent = procedure (Sender: TCustomRichView; Shift: TShiftState;
- X, Y: Integer; PossibleDropEffects: TRVOleDropEffects;
- var DropEffect: TRVOleDropEffect) of object;
- TRVOleDropEvent = procedure (Sender: TCustomRichView; const DataObject: IDataObject;
- Shift: TShiftState; X, Y: Integer; PossibleDropEffects: TRVOleDropEffects;
- var DropEffect: TRVOleDropEffect; var DoDefault: Boolean) of object;
- {$ENDIF}
- { ---------------------------------------------------------------------------
- TCustomRichViewEdit: ancestor class for TRichViewEdit and TDBRichViewEdit
- components.
- }
- TCustomRichViewEdit = class(TCustomRichView)
- private
- { Storing properties }
- FModified: Boolean;
- FReadOnly : Boolean;
- FEditorOptions: TRVEditorOptions;
- FAcceptDragDropFormats: TRVDragDropFormats;
- { Events }
- FOnCurParaStyleChanged, FOnCurTextStyleChanged, FOnChange,
- FOnCaretMove: TNotifyEvent;
- FOnChanging: TRVChangingEvent;
- FOnStyleConversion, FOnParaStyleConversion: TRVStyleConversionEvent;
- FOnPaste: TRVPasteEvent;
- {$IFDEF RVONCUT}
- FOnCut: TNotifyEvent;
- {$ENDIF}
- FOnCaretGetOut: TRVOnCaretGetOutEvent;
- FOnDropFiles: TRVDropFilesEvent;
- { Other fields }
- {$IFNDEF RVDONOTUSEDRAGDROP}
- FDropTarget: TRVDropTarget; // object implemeting IDropTarget
- FOnOleDragEnter: TRVOleDragEnterEvent;
- FOnOleDrop: TRVOleDropEvent;
- FOnOleDragOver: TRVOleDragOverEvent;
- FOnOleDragLeave: TNotifyEvent;
- {$ENDIF}
- procedure CheckItemClass(ItemNo: Integer; RequiredClass: TCustomRVItemInfoClass);
- procedure WMInputLangChange(var Message: TMessage); message WM_INPUTLANGCHANGE;
- procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
- procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
- procedure WMCut(var Message: TWMCut); message WM_CUT;
- procedure WMPaste(var Message: TWMpaste); message WM_PASTE;
- procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
- procedure WMSysChar(var Message: TWMSysChar); message WM_SYSCHAR;
- procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
- procedure WMChar(var Message: TWMChar); message WM_CHAR;
- procedure WMUndoFromInplace(var Message: TMessage); message WM_RVUNDOFROMINPLACE;
- procedure WMRedoFromInplace(var Message: TMessage); message WM_RVREDOFROMINPLACE;
- procedure WMClear(var Message: TMessage); message WM_CLEAR;
- procedure WMUndo(var Message: TMessage); message WM_UNDO;
- procedure EMUndo(var Message: TMessage); message EM_UNDO;
- procedure EMRedo(var Message: TMessage); message EM_REDO;
- procedure EMCanUndo(var Message: TMessage); message EM_CANUNDO;
- procedure EMCanRedo(var Message: TMessage); message EM_CANREDO;
- procedure EMCanPaste(var Message: TMessage); message EM_CANPASTE;
- procedure WMCreate(var Message: TMessage); message WM_CREATE;
- procedure WMDestroy(var Message: TMessage); message WM_DESTROY;
- {$IFDEF RVUSEIME}
- procedure WMImeStartComposition(var Message: TMessage); message WM_IME_STARTCOMPOSITION;
- procedure WMImeComposition(var Message: TMessage); message WM_IME_COMPOSITION;
- {$ENDIF}
- procedure SetCurParaStyleNo(const Value: Integer);
- procedure SetCurTextStyleNo(const Value: Integer);
- function GetCurParaStyleNo: Integer;
- function GetCurTextStyleNo: Integer;
- function GetCurItemStyle: Integer;
- function GetCurItemNo: Integer;
- function GetOffsetInCurItem: Integer;
- procedure ApplyTextStyleConversionProc(Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- {$IFNDEF RVDONOTUSESTYLETEMPLATES}
- procedure ApplyParaStyleTemplateConversionProc(Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- procedure ApplyTextStyleTemplateConversionProc(Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- {$ENDIF}
- procedure ApplyUserParaStyleConversionProc(Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- procedure ApplyUserTextStyleConversionProc(Sender: TCustomRichViewEdit;
- StyleNo, ParaStyleNo, UserData: Integer; AppliedToText: Boolean;
- var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- function GetUndoLimit: Integer;
- procedure SetUndoLimit(const Value: Integer);
- function IsUndoShortcut(Shift: TShiftState; Key: Word): Boolean;
- function IsRedoShortcut(Shift: TShiftState; Key: Word): Boolean;
- {$IFNDEF RVDONOTUSEUNICODE}
- procedure InsertTextW_(const text: String);
- {$ENDIF}
- procedure SetTabNavigation(const Value: TRVTabNavigationType);
- function GetTopLevelEditor: TCustomRichViewEdit;
- function GetRootEditor: TCustomRichViewEdit;
- function DoChanging: Boolean;
- function GetActualCurTextStyleNo: Integer;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- procedure RefreshAll;
- {$ENDIF}
- protected
- { Init & info }
- procedure CreateParams(var Params: TCreateParams); override;
- function GetDataClass: TRichViewRVDataClass; override;
- procedure SetReadOnly(const Value: Boolean); virtual;
- function GetReadOnly: Boolean; virtual;
- { Keyboard }
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- procedure KeyUp(var Key: Word; Shift: TShiftState); override;
- procedure KeyPress(var Key: Char); override;
- procedure OnEnterPress(Shift: Boolean);
- procedure OnBackSpacePress(Ctrl: Boolean);
- procedure OnDeletePress(Ctrl: Boolean);
- { Scrolling }
- procedure AfterVScroll; override;
- procedure AfterHScroll; override;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- { Ole drag&drop: IDropTarget related }
- function OleDragEnter(X,Y: Integer): Boolean; override;
- procedure CallOleDragEnterEvent(const DataObj: IDataObject;
- KeyState: Integer; pt: TPoint; PossibleEffects: Integer;
- var Effect: Integer); override;
- procedure OleDragLeave; override;
- function OleDragOver(X, Y: Integer): Boolean; override;
- procedure CallOleDragOverEvent(KeyState: Integer; pt: TPoint;
- PossibleEffects: Integer; var Effect: Integer); override;
- function OleDrop(const DataObj: IDataObject; FMove: Boolean;
- KeyState: Integer; pt: TPoint; PossibleEffects: Integer): Integer; override;
- procedure ReleaseOleDropTargetObject; override;
- function GetAcceptableRVFormat: Word;
- function OleCanAcceptFormat(Format: Word): Boolean; override;
- {$ENDIF}
- procedure AdjustPopupMenuPos(var pt: TPoint); override;
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function GetBasePathFromHTMLInClipboard: String;
- {$ENDIF}
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- procedure SetSmartPopupTarget; override;
- {$ENDIF}
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property OnCaretMove: TNotifyEvent read FOnCaretMove write FOnCaretMove;
- property OnChanging: TRVChangingEvent read FOnChanging write FOnChanging;
- property OnPaste: TRVPasteEvent read FOnPaste write FOnPaste;
- {$IFDEF RVONCUT}
- property OnCut: TNotifyEvent read FOnCut write FOnCut;
- {$ENDIF}
- property TabNavigation read GetTabNavigation write SetTabNavigation default rvtnNone;
- property AcceptDragDropFormats: TRVDragDropFormats read FAcceptDragDropFormats
- write FAcceptDragDropFormats default [rvddRVF, rvddRTF, rvddText, rvddUnicodeText,
- rvddBitmap, rvddMetafile, rvddFiles];
- public
- LockCount: Integer;
- FCurStyleConversion: TRVStyleConversionEvent_;
- { Constructor - destructor }
- constructor Create(AOwner: TComponent); override;
- { For internal use }
- procedure SetFReadOnly(Value: Boolean);
- function BeforeInserting: Boolean;
- procedure AfterInserting;
- procedure CurParaStyleChange; dynamic;
- procedure CurTextStyleChange; dynamic;
- function BeforeChange(FromOutside: Boolean): Boolean; virtual;
- procedure DoChange(ClearRedo: Boolean); dynamic;
- procedure Selecting; dynamic;
- procedure AfterCaretMove;
- procedure AssignEvents(Source: TCustomRichView);
- {$IFNDEF RVDONOTUSEUNICODE}
- procedure BeforeUnicode;
- {$ENDIF}
- { Inserting in the caret position (can be undone/redone) }
- {$IFNDEF RVDONOTUSEUNICODE}
- {$IFDEF RICHVIEWCBDEF3}
- procedure InsertTextW(const text: WideString; CaretBefore: Boolean {$IFDEF RICHVIEWDEF4}=False{$ENDIF});
- function InsertStringWTag(const s: WideString; Tag: Integer): Boolean;
- {$ENDIF}
- {$ENDIF}
- function InsertItem(const Name: String; Item: TCustomRVItemInfo): Boolean;
- procedure InsertText(const text: String; CaretBefore: Boolean
- {$IFDEF RICHVIEWDEF4}=False{$ENDIF});
- function InsertStringTag(const s: String; Tag: Integer): Boolean;
- {$IFNDEF RVDONOTUSETABS}
- function InsertTab: Boolean;
- {$ENDIF}
- function InsertControl(const Name: String; ctrl: TControl;
- VAlign: TRVVAlign): Boolean;
- function InsertPicture(const Name: String; gr: TGraphic;
- VAlign: TRVVAlign): Boolean;
- function InsertHotPicture(const Name: String; gr: TGraphic;
- VAlign: TRVVAlign): Boolean;
- function InsertBreak(Width: Byte; Style: TRVBreakStyle;
- Color: TColor): Boolean;
- function InsertBullet(ImageIndex: Integer;
- ImageList: TCustomImageList): Boolean;
- function InsertHotspot(ImageIndex, HotImageIndex: Integer;
- ImageList: TCustomImageList): Boolean;
- { Inserting in the caret position from files and streams
- (can be undone/redone) }
- function InsertRVFFromStreamEd(Stream: TStream):Boolean;
- function InsertRVFFromFileEd(const FileName: String):Boolean;
- function InsertTextFromFile(const FileName: String):Boolean;
- function InsertOEMTextFromFile(const FileName: String):Boolean;
- {$IFNDEF RVDONOTUSEUNICODE}
- function InsertTextFromFileW(const FileName: String):Boolean;
- {$ENDIF}
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function InsertRTFFromStreamEd(Stream: TStream): Boolean;
- function InsertRTFFromFileEd(const FileName: String): Boolean;
- {$ENDIF}
- { Page breaks (can be undone/redone) }
- procedure InsertPageBreak;
- procedure RemoveCurrentPageBreak;
- { Operations specific to some item types (can be undone/redone) }
- procedure ConvertToPicture(ItemNo: Integer);
- procedure ConvertToHotPicture(ItemNo: Integer);
- { Operations on selection (can be undone/redone) }
- function CanDelete: Boolean;
- procedure DeleteSelection;dynamic;
- procedure CutDef;
- procedure ApplyParaStyle(ParaStyleNo: Integer);
- procedure ApplyTextStyle(TextStyleNo: Integer);
- procedure ApplyStyleConversion(UserData: Integer);
- procedure ApplyParaStyleConversion(UserData: Integer);
- {$IFNDEF RVDONOTUSESTYLETEMPLATES}
- procedure ApplyParaStyleTemplate(TemplateNo: Integer);
- procedure ApplyTextStyleTemplate(TemplateNo: Integer; ToWholeParagraphs: Boolean);
- procedure ApplyStyleTemplate(TemplateNo: Integer);
- {$ENDIF}
- { Can paste ? }
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function CanPasteRTF: Boolean;
- {$ENDIF}
- function CanPaste: Boolean; dynamic;
- function CanPasteRVF: Boolean;
- { Pasting from the Clipboard (can be undone/redone) }
- procedure Paste; dynamic;
- procedure PasteBitmap(TextAsName: Boolean);
- procedure PasteMetafile(TextAsName: Boolean);
- procedure PasteText;
- procedure PasteRVF;
- {$IFNDEF RVDONOTUSERTFIMPORT}
- function PasteRTF: Boolean;
- {$ENDIF}
- {$IFNDEF RVDONOTUSEUNICODE}
- procedure PasteTextW;
- {$ENDIF}
- { Get info about item in the position of caret - general properties }
- function GetCurrentTag: Integer;
- function GetCurrentItemText: String;
- function GetCurrentItem: TCustomRVItemInfo;
- function GetCurrentItemEx(RequiredClass: TCustomRVItemInfoClass;
- var ItemRichViewEdit: TCustomRichViewEdit;
- var Item: TCustomRVItemInfo): Boolean;
- {$IFNDEF RVDONOTUSEUNICODE}
- function GetCurrentItemTextA: String;
- {$IFDEF RICHVIEWCBDEF3}
- function GetCurrentItemTextW: WideString;
- {$ENDIF}
- {$ENDIF}
- { Get info about item in the position of caret - for specific item types }
- procedure GetCurrentBreakInfo(var AWidth: Byte;
- var AStyle: TRVBreakStyle; var AColor: TColor; var ATag: Integer);
- procedure GetCurrentBulletInfo(var AName: String;
- var AImageIndex: Integer; var AImageList: TCustomImageList;
- var ATag: Integer);
- procedure GetCurrentHotspotInfo(var AName: String;
- var AImageIndex, AHotImageIndex: Integer; var AImageList: TCustomImageList;
- var ATag: Integer);
- procedure GetCurrentPictureInfo(var AName: String; var Agr: TGraphic;
- var AVAlign: TRVVAlign; var ATag: Integer);
- procedure GetCurrentControlInfo(var AName: String; var Actrl: TControl;
- var AVAlign: TRVVAlign; var ATag: Integer);
- procedure GetCurrentTextInfo(var AText: String; var ATag: Integer);
- { Set info for item - general properties (can be undone/redone) }
- procedure SetItemTextEd(ItemNo: Integer; const s: String);
- procedure SetItemTagEd(ItemNo: Integer; ATag: Integer);
- procedure ResizeControl(ItemNo, NewWidth, NewHeight: Integer);
- {$IFNDEF RVDONOTUSEUNICODE}
- procedure SetItemTextEdA(ItemNo: Integer; const s: String);
- {$IFDEF RICHVIEWCBDEF3}
- procedure SetItemTextEdW(ItemNo: Integer; const s: WideString);
- {$ENDIF}
- {$ENDIF}
- { Set info for item in the position of caret - general properties
- (can be undone/redone) }
- procedure SetCurrentItemText(const s: String);
- procedure SetCurrentTag(ATag: Integer);
- {$IFNDEF RVDONOTUSEUNICODE}
- procedure SetCurrentItemTextA(const s: String);
- {$IFDEF RICHVIEWCBDEF3}
- procedure SetCurrentItemTextW(const s: WideString);
- {$ENDIF}
- {$ENDIF}
- { Set info for item - for specific item types
- (can be undone/redone) }
- procedure SetBreakInfoEd(ItemNo: Integer; AWidth: Byte;
- AStyle: TRVBreakStyle; AColor: TColor; ATag: Integer);
- procedure SetBulletInfoEd(ItemNo: Integer; const AName: String;
- AImageIndex: Integer; AImageList: TCustomImageList; ATag: Integer);
- procedure SetHotspotInfoEd(ItemNo: Integer; const AName: String;
- AImageIndex, AHotImageIndex: Integer; AImageList: TCustomImageList;
- ATag: Integer);
- procedure SetPictureInfoEd(ItemNo: Integer; const AName: String;
- Agr: TGraphic; AVAlign: TRVVAlign; ATag: Integer);
- procedure SetControlInfoEd(ItemNo: Integer; const AName: String;
- AVAlign: TRVVAlign; ATag: Integer);
- { Set info for item in the position of caret - for specific item types
- (can be undone/redone) }
- procedure SetCurrentBreakInfo(AWidth: Byte; AStyle: TRVBreakStyle;
- AColor: TColor; ATag: Integer);
- procedure SetCurrentBulletInfo(const AName: String; AImageIndex: Integer;
- AImageList: TCustomImageList; ATag: Integer);
- procedure SetCurrentHotspotInfo(const AName: String;
- AImageIndex, AHotImageIndex: Integer; AImageList: TCustomImageList;
- ATag: Integer);
- procedure SetCurrentPictureInfo(const AName: String; Agr: TGraphic;
- AVAlign: TRVVAlign; ATag: Integer);
- procedure SetCurrentControlInfo(const AName: String; AVAlign: TRVVAlign;
- ATag: Integer);
- procedure ResizeCurrentControl(NewWidth, NewHeight: Integer);
- { Item operations: misc. }
- procedure AdjustControlPlacement(ItemNo: Integer);
- procedure AdjustControlPlacement2(Control: TControl);
- procedure BeginItemModify(ItemNo: Integer; var ModifyData: Integer);
- procedure EndItemModify(ItemNo: Integer; ModifyData: Integer);
- procedure BeginCurrentItemModify(var ModifyData: Integer);
- procedure EndCurrentItemModify(ModifyData: Integer);
- { Extra item properties (changing can be undone/redone) }
- function GetCurrentItemExtraIntProperty(Prop: TRVExtraItemProperty;
- var Value: Integer): Boolean;
- procedure SetItemExtraIntPropertyEd(ItemNo: Integer;
- Prop: TRVExtraItemProperty; Value: Integer; AutoReformat: Boolean);
- procedure SetCurrentItemExtraIntProperty(Prop: TRVExtraItemProperty;
- Value: Integer; AutoReformat: Boolean);
- function GetCurrentItemExtraStrProperty(Prop: TRVExtraItemStrProperty;
- var Value: String): Boolean;
- procedure SetItemExtraStrPropertyEd(ItemNo: Integer;
- Prop: TRVExtraItemStrProperty; const Value: String; AutoReformat: Boolean);
- procedure SetCurrentItemExtraStrProperty(Prop: TRVExtraItemStrProperty;
- const Value: String; AutoReformat: Boolean);
- { Checkpoints (changing can be undone/redone) }
- function GetCurrentCheckpoint: TCheckpointData;
- procedure SetCheckpointInfoEd(ItemNo: Integer; ATag: Integer;
- const AName: String; ARaiseEvent: Boolean);
- procedure RemoveCheckpointEd(ItemNo: Integer);
- procedure SetCurrentCheckpointInfo(ATag: Integer; const AName: String;
- ARaiseEvent: Boolean);
- procedure RemoveCurrentCheckpoint;
- { Selecting }
- function SearchText(s: String; SrchOptions: TRVESearchOptions): Boolean;
- procedure SelectCurrentWord;
- procedure SelectCurrentLine;
- { Changing }
- function CanChange: Boolean;
- procedure Change;
- procedure BeginUpdate;
- procedure EndUpdate;
- { Undo and redo }
- procedure Undo; dynamic;
- procedure Redo; dynamic;
- function UndoAction: TRVUndoType;
- function RedoAction: TRVUndoType;
- function UndoName: String;
- function RedoName: String;
- procedure ClearUndo;
- procedure SetUndoGroupMode(GroupUndo: Boolean);
- procedure BeginUndoGroup(UndoType: TRVUndoType);
- procedure BeginUndoCustomGroup(const Name: String);
- { Lists }
- {$IFNDEF RVDONOTUSELISTS}
- procedure ApplyListStyle(AListNo, AListLevel, AStartFrom: Integer;
- AUseStartFrom, ARecursive: Boolean);
- procedure RemoveLists(ARecursive: Boolean);
- procedure ChangeListLevels(LevelDelta: Integer);
- {$ENDIF}
- { Live spelling }
- {$IFNDEF RVDONOTUSELIVESPELL}
- function GetCurrentMisspelling(SelectIt: Boolean;
- var Word: String; var StyleNo: Integer): Boolean;
- {$ENDIF}
- procedure GetCurrentLineCol(var Line, Column: Integer);
- property Modified: Boolean read FModified write FModified;
- property CurItemNo: Integer read GetCurItemNo;
- property CurItemStyle: Integer read GetCurItemStyle;
- property CurParaStyleNo: Integer read GetCurParaStyleNo write SetCurParaStyleNo;
- property CurTextStyleNo: Integer read GetCurTextStyleNo write SetCurTextStyleNo;
- property ActualCurTextStyleNo: Integer read GetActualCurTextStyleNo write SetCurTextStyleNo;
- property OffsetInCurItem: Integer read GetOffsetInCurItem;
- property EditorOptions: TRVEditorOptions read FEditorOptions write FEditorOptions default [rvoWantTabs, rvoCtrlJumps];
- property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
- property UndoLimit: Integer read GetUndoLimit write SetUndoLimit default -1;
- property TopLevelEditor: TCustomRichViewEdit read GetTopLevelEditor;
- property RootEditor: TCustomRichViewEdit read GetRootEditor;
- property OnCaretGetOut: TRVOnCaretGetOutEvent read FOnCaretGetOut write FOnCaretGetOut;
- property OnDropFiles: TRVDropFilesEvent read FOnDropFiles write FOnDropFiles;
- property OnParaStyleConversion: TRVStyleConversionEvent read FOnParaStyleConversion write FOnParaStyleConversion;
- property OnStyleConversion: TRVStyleConversionEvent read FOnStyleConversion write FOnStyleConversion;
- property OnCurParaStyleChanged: TNotifyEvent read FOnCurParaStyleChanged write FOnCurParaStyleChanged;
- property OnCurTextStyleChanged: TNotifyEvent read FOnCurTextStyleChanged write FOnCurTextStyleChanged;
- property OnMouseMove;
- property OnDragOver;
- property OnDragDrop;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- property OnOleDragEnter: TRVOleDragEnterEvent read FOnOleDragEnter write FOnOleDragEnter;
- property OnOleDragOver: TRVOleDragOverEvent read FOnOleDragOver write FOnOleDragOver;
- property OnOleDrop: TRVOleDropEvent read FOnOleDrop write FOnOleDrop;
- property OnOleDragLeave: TNotifyEvent read FOnOleDragLeave write FOnOleDragLeave;
- {$ENDIF}
- end;
- { ---------------------------------------------------------------------------
- TRichViewEdit component: editor.
- TRichViewEdit publishes properties of TCustomRichViewEdit.
- }
- TRichViewEdit = class (TCustomRichViewEdit)
- published
- { Published declarations: new for TRichViewEdit }
- property AcceptDragDropFormats;
- property EditorOptions;
- property ReadOnly;
- property UndoLimit;
- property OnCaretGetOut;
- property OnChange;
- property OnChanging;
- property OnCaretMove;
- property OnCurParaStyleChanged;
- property OnCurTextStyleChanged;
- {$IFDEF RVONCUT}
- property OnCut;
- {$ENDIF}
- property OnDropFiles;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- property OnOleDragEnter;
- property OnOleDragLeave;
- property OnOleDragOver;
- property OnOleDrop;
- {$ENDIF}
- property OnParaStyleConversion;
- property OnPaste;
- 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 ParentShowHint;
- 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 }
- {$IFNDEF RVDONOTUSEANIMATION}
- property AnimationMode;
- {$ENDIF}
- 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 DocProperties;
- property DoInPaletteMode;
- property FirstJumpNo;
- property HScrollVisible;
- property LeftMargin;
- {$IFNDEF RVDONOTUSELIVESPELL}
- property LiveSpellingMode default rvlspOnChange;
- {$ENDIF}
- property MaxTextWidth;
- property MinTextWidth;
- property Options;
- property RightMargin;
- property RTFOptions;
- property RTFReadProperties;
- property RVFOptions;
- property RVFParaStylesReadMode;
- property RVFTextStylesReadMode;
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- property SmartPopupProperties;
- {$ENDIF}
- {$IFDEF RVFLATSCROLLBARS}
- property ScrollBarColor;
- property ScrollBarStyle;
- {$ENDIF}
- property Style;
- //property TabNavigation;
- property TopMargin;
- property Tracking;
- property UseXPThemes;
- {$IFDEF RICHVIEWDEF3}
- property VAlign;
- {$ENDIF}
- property VScrollVisible;
- {$IFDEF RICHVIEWDEF4}
- property WheelStep;
- {$ENDIF}
- { Published RichView events }
- //property OnCheckpointVisible;
- property OnControlAction;
- property OnCopy;
- {$IFDEF RV_ODHC}
- property OnDocumentHeightChange;
- {$ENDIF}
- property OnImportPicture;
- property OnItemAction;
- property OnItemHint;
- property OnJump;
- property OnHScrolled;
- property OnHTMLSaveImage;
- property OnPaint;
- property OnProgress;
- property OnReadHyperlink;
- property OnRVDblClick;
- property OnRVFImageListNeeded;
- property OnRVFControlNeeded;
- property OnRVFPictureNeeded;
- property OnRVMouseDown;
- property OnRVMouseMove;
- property OnRVMouseUp;
- property OnRVRightClick;
- property OnSaveComponentToFile;
- property OnSaveHTMLExtra;
- property OnSaveImage2;
- property OnSaveItemToFile;
- property OnSaveRTFExtra;
- property OnSelect;
- {$IFNDEF RVDONOTUSESMARTPOPUP}
- property OnSmartPopupClick;
- {$ENDIF}
- {$IFNDEF RVDONOTUSELIVESPELL}
- property OnSpellingCheck;
- {$IFDEF RVLIVESPELLEXEVENT}
- property OnSpellingCheckEx;
- {$ENDIF}
- {$ENDIF}
- property OnVScrolled;
- property OnWriteHyperlink;
- { obsolete properties }
- property AllowSelection;
- property SingleClick;
- property OnURLNeeded;
- 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 := [rvoWantTabs, rvoCtrlJumps];
- UndoLimit := -1;
- AcceptDragDropFormats := [rvddRVF, rvddRTF, rvddText, rvddUnicodeText,
- rvddBitmap, rvddMetafile, rvddFiles];
- {$IFNDEF RVDONOTUSELIVESPELL}
- LiveSpellingMode := rvlspOnChange;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- FVDisableNoScroll := True;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetDataClass: TRichViewRVDataClass;
- begin
- Result := TRVEditRVData;
- end;
- {------------------------------------------------------------------------------}
- { Processing message: WM_CREATE.
- Registering itself as a drag&drop target. }
- procedure TCustomRichViewEdit.WMCreate(var Message: TMessage);
- begin
- inherited;
- {$IFNDEF RVDONOTUSEDRAGDROP}
- if not (csDesigning in ComponentState) then begin
- if FDropTarget=nil then
- FDropTarget := TRVDropTarget.Create(Self);
- FDropTarget.RegisterDragDropForOwner;
- end;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- { Processing message: WM_DESTROY.
- Unregistering itself as a drag&drop target. }
- procedure TCustomRichViewEdit.WMDestroy(var Message: TMessage);
- begin
- {$IFNDEF RVDONOTUSEDRAGDROP}
- if not (csDesigning in ComponentState) and Assigned(FDropTarget) then
- FDropTarget.UnRegisterDragDropForOwner;
- {$ENDIF}
- inherited;
- 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;
- Exclude(RVData.State, rvstDoNotClearCurTag);
- exit;
- end;
- TRVEditRVData(RVData).BeginUndoSequence(rvutInsert, True);
- SetUndoGroupMode(True);
- StyleNo := ActualCurTextStyleNo;
- TRVEditRVData(RVData).AssignCurTag;
- TRVEditRVData(RVData).DeleteSelection_;
- TRVEditRVData(RVData).Deselect(nil, True);
- CurTextStyleNo := StyleNo;
- Result := True;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.AfterInserting;
- begin
- SetUndoGroupMode(False);
- Refresh;
- Change;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertBreak(Width: Byte; Style: TRVBreakStyle;
- Color: TColor): Boolean;
- var info: TRVBreakItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertBreak(Width, Style, Color);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVBreakItemInfo.CreateEx(RVData, Width, Style, Color);
- s := '';
- Result := TRVEditRVData(RVData).InsertSomething(info, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertBullet(ImageIndex: Integer;
- ImageList: TCustomImageList): Boolean;
- var info: TRVBulletItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertBullet(ImageIndex, ImageList);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVBulletItemInfo.CreateEx(RVData, ImageIndex, ImageList, rvvaBaseline);
- s := '';
- Result := 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}
- Include(RVData.State, rvstDoNotClearCurTag);
- if not BeforeInserting then exit;
- try
- TRVEditRVData(RVData).InsertText_(text, True, CaretBefore);
- finally
- SetUndoGroupMode(False);
- Exclude(RVData.State, rvstDoNotClearCurTag);
- 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;
- Include(RVData.State, rvstDoNotClearCurTag);
- if not BeforeInserting then exit;
- try
- Result := TRVEditRVData(RVData).InsertTextFromFile(FileName, False, False);
- finally
- SetUndoGroupMode(False);
- Exclude(RVData.State, rvstDoNotClearCurTag);
- 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;
- Include(RVData.State, rvstDoNotClearCurTag);
- if not BeforeInserting then exit;
- try
- BeforeUnicode;
- Result := TRVEditRVData(RVData).InsertTextFromFileW(FileName,True);
- finally
- SetUndoGroupMode(False);
- Exclude(RVData.State, rvstDoNotClearCurTag);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.InsertTextW_(const text: String);
- begin
- Include(RVData.State, rvstDoNotClearCurTag);
- if not BeforeInserting then exit;
- try
- BeforeUnicode;
- TRVEditRVData(RVData).InsertTextW_(text,True, False);
- finally
- SetUndoGroupMode(False);
- Exclude(RVData.State, rvstDoNotClearCurTag);
- 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;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- Result := GetItemTextA(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetItemTextEdA(ItemNo: Integer;
- const s: String);
- begin
- SetItemTextEd(ItemNo, RVData.GetTextInItemFormatA(ItemNo, s));
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentItemTextA(const s: String);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentItemTextA(s);
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- SetItemTextEdA(CurItemNo, s);
- end;
- {------------------------------------------------------------------------------}
- {$IFDEF RICHVIEWCBDEF3}
- function TCustomRichViewEdit.GetCurrentItemTextW: WideString;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentItemTextW;
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- Result := GetItemTextW(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetItemTextEdW(ItemNo: Integer;
- const s: WideString);
- begin
- SetItemTextEd(ItemNo, RVData.GetTextInItemFormatW(ItemNo, s));
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentItemTextW(const s: WideString);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentItemTextW(s);
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- SetItemTextEdW(CurItemNo, s);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.InsertTextW(const text: WideString; CaretBefore: Boolean {$IFDEF RICHVIEWDEF4}=False{$ENDIF});
- var s: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).InsertTextW(text, CaretBefore);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- BeforeUnicode;
- s := RVU_GetRawUnicode(text);
- TRVEditRVData(RVData).InsertTextW_(s,True, CaretBefore);
- finally
- SetUndoGroupMode(False);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertStringWTag(const s: WideString;
- Tag: Integer): Boolean;
- var info: TRVTextItemInfo;
- s2: String;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertStringWTag(s, Tag);
- exit;
- end;
- {$ENDIF}
- Result := False;
- if not BeforeInserting then exit;
- try
- BeforeUnicode;
- info := RichViewTextItemClass.Create(RVData);
- info.StyleNo := ActualCurTextStyleNo;
- info.Tag := Tag;
- info.ItemOptions := info.ItemOptions+[rvioUnicode];
- s2 := RVU_GetRawUnicode(s);
- s2 := RV_ReplaceTabsW(s2, Style.SpacesInTab);
- {$IFNDEF RVDONOTUSEUNICODE}
- if not Style.TextStyles[info.GetActualStyleNo(Style)].Unicode then begin
- s2 := RVU_UnicodeToAnsi(RVData.GetStyleCodePage(
- info.GetActualStyleNo(Style)), s2);
- info.ItemOptions := info.ItemOptions-[rvioUnicode];
- end;
- {$ENDIF}
- Result := TRVEditRVData(RVData).InsertSomething(info, s2, False, False);
- finally
- AfterInserting;
- end;
- end;
- {$ENDIF}
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertOEMTextFromFile(const FileName: String):Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertOEMTextFromFile(FileName);
- exit;
- end;
- {$ENDIF}
- Result := True;
- if not BeforeInserting then exit;
- try
- Result := TRVEditRVData(RVData).InsertTextFromFile(FileName, True, True);
- finally
- SetUndoGroupMode(False);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertStringTag(const s: String; Tag: Integer): Boolean;
- var info: TRVTextItemInfo;
- s2: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertStringTag(s, Tag);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := RichViewTextItemClass.Create(RVData);
- info.StyleNo := ActualCurTextStyleNo;
- info.Tag := Tag;
- s2 := RV_ReplaceTabsA(s, Style.SpacesInTab);
- {$IFNDEF RVDONOTUSEUNICODE}
- if Style.TextStyles[info.GetActualStyleNo(Style)].Unicode then begin
- s2 := RVU_AnsiToUnicode(RVData.GetStyleCodePage(
- info.GetActualStyleNo(Style)), s);
- info.ItemOptions := info.ItemOptions+[rvioUnicode];
- end;
- {$ENDIF}
- Result := TRVEditRVData(RVData).InsertSomething(info, s2, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSETABS}
- function TCustomRichViewEdit.InsertTab: Boolean;
- var Item: TRVTabItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertTab;
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- Item := TRVTabItemInfo.Create(RVData);
- Item.StyleNo := rvsTab;
- Item.TextStyleNo := ActualCurTextStyleNo;
- s := '';
- Result := TRVEditRVData(RVData).InsertSomething(Item, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertControl(const Name: String; ctrl: TControl;
- VAlign: TRVVAlign): Boolean;
- var info: TRVControlItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertControl(Name, ctrl, VAlign);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVControlItemInfo.CreateEx(RVData, ctrl, VAlign);
- ctrl.Visible := False;
- ctrl.Parent := Self;
- s := Name;
- Result := TRVEditRVData(RVData).InsertSomething(info, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertHotspot(ImageIndex, HotImageIndex: Integer;
- ImageList: TCustomImageList): Boolean;
- var info: TRVHotspotItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertHotspot(ImageIndex, HotImageIndex, ImageList);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVHotspotItemInfo.CreateEx(RVData, ImageIndex, HotImageIndex, ImageList, rvvaBaseline);
- s := '';
- Result := TRVEditRVData(RVData).InsertSomething(info, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertPicture(const Name: String; gr: TGraphic;
- VAlign: TRVVAlign): Boolean;
- var info: TRVGraphicItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertPicture(Name, gr, VAlign);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVGraphicItemInfo.CreateEx(RVData, gr, VAlign);
- info.UpdatePaletteInfo(DoInPaletteMode, False, RVPalette, PRVLogPalette);
- s := Name;
- Result := TRVEditRVData(RVData).InsertSomething(info, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertHotPicture(const Name: String; gr: TGraphic;
- VAlign: TRVVAlign): Boolean;
- var info: TRVHotGraphicItemInfo;
- s: String;
- begin
- Result := False;
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertHotPicture(Name, gr, VAlign);
- exit;
- end;
- {$ENDIF}
- if not BeforeInserting then exit;
- try
- info := TRVHotGraphicItemInfo.CreateEx(RVData, gr, VAlign);
- info.UpdatePaletteInfo(DoInPaletteMode, False, RVPalette, PRVLogPalette);
- s := Name;
- Result := TRVEditRVData(RVData).InsertSomething(info, s, False, False);
- finally
- AfterInserting;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.CanDelete: Boolean;
- begin
- Result := TRVEditRVData(GetTopLevelEditor.RVData).CanDelete;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.DeleteSelection;
- //var Selected: Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).DeleteSelection;
- exit;
- end;
- {$ENDIF}
- {
- if not BeforeChange(False) then exit;
- Selected := RVData.SelectionExists(False, True);
- TRVEditRVData(RVData).DeleteSelection_;
- if Selected then
- Invalidate;
- }
- if RVData.SelectionExists(False, True) and BeforeChange(False) then begin
- TRVEditRVData(RVData).DeleteSelection_;
- Invalidate;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurItemNo: Integer;
- begin
- Result := TRVEditRVData(RVData).GetCurItemNo;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetOffsetInCurItem: Integer;
- begin
- Result := TRVEditRVData(RVData).GetOffsetInCurItem;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurItemStyle: Integer;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurItemStyle;
- exit;
- end;
- {$ENDIF}
- TRVEditRVData(RVData).PrepareForEdit;
- Result := GetItemStyle(GetCurItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMKillFocus(var Message: TWMKillFocus);
- var PRVData: TCustomRVData;
- begin
- inherited;
- if (csDestroying in ComponentState) or (rvstNoKillFocusEvents in RVData.GetAbsoluteRootData.State) then exit;
- TRVEditRVData(RVData).ClearJumpsCoords;
- if not ReadOnly then begin
- PRVData := RVData.GetAbsoluteParentData;
- if (PRVData<>nil) and (PRVData is TRVEditRVData) then begin
- TRVEditRVData(PRVData).ClearJumps;
- TRVEditRVData(PRVData).Flags := TRVEditRVData(PRVData).Flags - [rvflUseJumps];
- TRVEditRVData(PRVData).State := TRVEditRVData(PRVData).State - [rvstDrawHover];
- end;
- end;
- GenerateMouseMove;
- if (Style<>nil) and (not TRVEditRVData(RVData).NotFormatted) then begin
- HideCaret(Handle);
- DestroyCaret;
- // Invalidate;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMInputLangChange(var Message: TMessage);
- {$IFDEF RICHVIEWCBDEF3}
- var NewStyleNo : integer;
- {$ENDIF}
- begin
- {$IFDEF RICHVIEWCBDEF3}
- if (Style=nil) or (ItemCount=0) or
- not (rvoAutoSwitchLang in EditorOptions)
- {$IFNDEF RVDONOTUSEUNICODE}
- or Style.TextStyles[CurTextStyleNo].Unicode
- {$ENDIF}
- then
- exit;
- NewStyleNo := Style.TextStyles.FindStyleWithCharset(CurTextStyleNo, Message.WParam);
- if NewStyleNo=-1 then begin
- Style.TextStyles.Add;
- NewStyleNo := Style.TextStyles.Count-1;
- Style.TextStyles[NewStyleNo].Assign(Style.TextStyles[CurTextStyleNo]);
- Style.TextStyles[NewStyleNo].Standard := False;
- Style.TextStyles[NewStyleNo].Charset := Message.WParam;
- end;
- CurTextStyleNo:=NewStyleNo;
- Message.Result := 1;
- {$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMSetFocus(var Message: TWMSetFocus);
- begin
- inherited;
- if {TRVEditRVData(RVData).NotFormatted} True then begin
- TRVEditRVData(RVData).PrepareForEdit;
- if (Style<>nil) and (not TRVEditRVData(RVData).NotFormatted) then begin
- TRVEditRVData(RVData).ChangeCaret(True,False,True,False);
- Invalidate;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMGetDlgCode(var Message: TWMGetDlgCode);
- begin
- Message.Result := DLGC_WANTARROWS or DLGC_WANTCHARS;
- if not (rvoDoNotWantReturns in EditorOptions) then
- Message.Result := Message.Result or DLGC_WANTALLKEYS;
- if rvoWantTabs in EditorOptions then
- Message.Result := Message.Result or DLGC_WANTTAB;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EMRedo(var Message: TMessage);
- begin
- Message.Result := Integer(RedoAction<>rvutNone);
- if Message.Result<>0 then
- Redo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMClear(var Message: TMessage);
- begin
- DeleteSelection;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMUndo(var Message: TMessage);
- begin
- Message.Result := Integer(UndoAction<>rvutNone);
- Undo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EMUndo(var Message: TMessage);
- begin
- Message.Result := Integer(UndoAction<>rvutNone);
- Undo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EMCanRedo(var Message: TMessage);
- begin
- Message.Result := Integer(RedoAction<>rvutNone);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.EMCanUndo(var Message: TMessage);
- begin
- Message.Result := Integer(UndoAction<>rvutNone);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CurParaStyleChange;
- begin
- if (Style<>nil) and not (csDestroying in ComponentState) and
- Assigned(FOnCurParaStyleChanged) then
- FOnCurParaStyleChanged(GetRootEditor);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.CurTextStyleChange;
- begin
- if (Style<>nil) and not (csDestroying in ComponentState) and
- Assigned(FOnCurTextStyleChanged) then
- FOnCurTextStyleChanged(GetRootEditor);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurParaStyleNo(const Value: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurParaStyleNo(Value);
- exit;
- end;
- {$ENDIF}
- if (TRVEditRVData(RVData).FCurParaStyleNo <> Value) or
- (rvstForceStyleChangeEvent in RVData.State) then begin
- TRVEditRVData(RVData).FCurParaStyleNo := Value;
- CurParaStyleChange;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurTextStyleNo(const Value: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurTextStyleNo(Value);
- exit;
- end;
- {$ENDIF}
- if (TRVEditRVData(RVData).FCurTextStyleNo <> Value) or
- (rvstForceStyleChangeEvent in RVData.State)
- then begin
- Exclude(RVData.State, rvstForceStyleChangeEvent);
- TRVEditRVData(RVData).FCurTextStyleNo := Value;
- CurTextStyleChange;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurParaStyleNo: Integer;
- begin
- Result := TRVEditRVData(GetTopLevelEditor.RVData).FCurParaStyleNo;
- {$IFDEF RVDEBUG}{$I Debugk.inc}{$ENDIF}
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurTextStyleNo: Integer;
- begin
- Result := RVData.GetActualStyle2(
- TRVEditRVData(GetTopLevelEditor.RVData).FCurTextStyleNo,
- TRVEditRVData(GetTopLevelEditor.RVData).FCurParaStyleNo);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetActualCurTextStyleNo: Integer;
- begin
- Result := TRVEditRVData(GetTopLevelEditor.RVData).FCurTextStyleNo;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.KeyUp(var Key: Word; Shift: TShiftState);
- begin
- if Key=VK_CONTROL then begin
- TRVEditRVData(RVdata).ClearJumpsCoords;
- GenerateMouseMove;
- end;
- inherited KeyUp(Key, Shift);
- end;
- {-----------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMSysChar(var Message: TWMSysChar);
- begin
- if (Message.CharCode = VK_BACK) and (UndoLimit<>0) then
- Message.Result := 0
- else
- inherited;
- end;
- {-----------------------------------------------------------------------}
- {
- function IsLeadByte(ch: Char; CodePage: TRVCodePage): Boolean;
- var cpinfo: TCPInfo;
- i: Integer;
- begin
- Result := False;
- GetCPInfo(CodePage, cpinfo);
- if cpinfo.MaxCharSize=1 then
- exit;
- for i := 0 to MAX_LEADBYTES div 2-1 do begin
- if (cpinfo.LeadByte[i*2]=0) and (cpinfo.LeadByte[i*2+1]=0) then
- break;
- if ch in [chr(cpinfo.LeadByte[i*2])..chr(cpinfo.LeadByte[i*2+1])] then begin
- Result := True;
- break;
- end;
- end;
- end;
- }
- {-----------------------------------------------------------------------}
- {$IFDEF VER93} // C++Builder 1
- function ToUnicode(wVirtKey, wScanCode: UINT; const KeyState: TKeyboardState;
- var pwszBuff; cchBuff: Integer; wFlags: UINT): Integer; stdcall;
- external user32 name 'ToUnicode';
- {$ENDIF}
- procedure TCustomRichViewEdit.WMKeyDown(var Message: TWMKeyDown);
- {$IFNDEF RVDONOTUSEUNICODE}
- var KeyState: TKeyboardState;
- s: String;
- Len: Integer;
- CodePage: TRVCodePage;
- ansis: String;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- CodePage := RVU_GetKeyboardCodePage;
- RVData.State := RVData.State-[rvstIgnoreNextChar];
- Len := 0;
- if RVNT and (CodePage=0) then
- BeforeUnicode;
- if ((RichViewUnicodeInput=rvuiAlternative) or (CodePage=0)) and RVNT and
- Style.TextStyles[CurTextStyleNo].Unicode then begin
- // Manual translation of key codes to Unicode
- if Message.CharCode in [ord('A')..ord('Z'),ord('0')..ord('9'),187..192,219..221] then begin
- if Style.TextStyles[CurTextStyleNo].Unicode then begin
- SetLength(s,10);
- if GetKeyboardState(KeyState)
- and not (((KeyState[VK_CONTROL] and $80)<>0) and ((KeyState[VK_MENU] and $80)=0)) then begin
- Len := ToUnicode(Message.CharCode, Message.KeyData, KeyState, PChar(s)^, 5, 0);
- if Len>0 then begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).DeleteSelection_;
- SetLength(s, Len*2);
- if Len=1 then begin
- if CodePage=0 then
- CodePage := Style.DefCodePage;
- ansis := RVU_UnicodeToAnsi(CodePage, s);
- if ansis='' then
- ansis := '?';
- TRVEditRVData(RVData).InsertTextTyping(s, ansis[1]);
- end
- else
- InsertTextW_(s);
- end;
- end;
- end;
- end;
- end;
- if Len<=0 then
- inherited
- else begin
- Message.CharCode := 0;
- Message.Result := 0;
- RVData.State := RVData.State+[rvstIgnoreNextChar];
- end;
- {$ELSE}
- inherited;
- {$ENDIF}
- end;
- {-----------------------------------------------------------------------}
- procedure TCustomRichViewEdit.KeyDown(var Key: Word; Shift: TShiftState);
- var selchanged : ByteBool;
- {........................................................}
- procedure GetOut(Direction: TRVGetOutDirection);
- begin
- if Assigned(FOnCaretGetOut) then
- FOnCaretGetOut(Self, Direction);
- end;
- begin
- TRVEditRVData(RVData).PrepareForEdit;
- if (Key=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then
- Key := 0;
- if IsUndoShortcut(Shift, Key) then begin
- Undo;
- Key := 0;
- end
- else if IsRedoShortcut(Shift, Key) then begin
- Redo;
- Key := 0;
- end;
- if Key = 0 then
- exit;
- inherited KeyDown(Key, Shift);
- if Key = 0 then
- exit;
- if (Key=VK_ESCAPE) and TRVEditRVData(RVData).CancelResize then
- exit;
- if (Key=VK_UP) and (ssCtrl in Shift) then begin
- GetRootEditor.VScrollPos := GetRootEditor.VScrollPos-1;
- exit;
- end;
- if (Key=VK_DOWN) and (ssCtrl in Shift) then begin
- GetRootEditor.VScrollPos := GetRootEditor.VScrollPos+1;
- exit;
- end;
- // Step 1 of 3. Working with selection
- selchanged := False;
- case Key of
- VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN,
- VK_HOME, VK_END, VK_PRIOR, VK_NEXT:
- begin
- {$IFNDEF RVDONOTUSELIVESPELL}
- LiveSpellingCheckCurrentItem(RVData, CurItemNo);
- {$ENDIF}
- // if cursor movement key, then handle selection
- if ssShift in Shift then begin
- TRVEditRVData(RVData).StartShiftMoving;
- selchanged := True;
- end
- else begin
- selchanged := SelectionExists;
- if selchanged then Deselect;
- end
- end;
- VK_MENU, VK_SHIFT,
- VK_F1..VK_F24, VK_SCROLL, VK_NUMLOCK, VK_PAUSE, VK_CAPITAL, VK_ESCAPE,
- VK_SNAPSHOT, VK_LWIN, VK_RWIN, VK_APPS, VK_LSHIFT..{VK_LAUNCH_APP2}$B7,
- VK_PROCESSKEY, VK_ATTN..$FF:
- begin
- // Do nothing
- end;
- VK_CONTROL:
- begin
- if (rvoCtrlJumps in EditorOptions) and not (rvflUseJumps in Flags) then begin
- TRVEditRVData(RVData).BuildJumpsCoords(False);
- GenerateMouseMove;
- end;
- end;
- VK_BACK, VK_DELETE:
- begin
- // if selection exists then delete it and forbid further actions
- selchanged := SelectionExists;
- if selchanged then begin
- if IsCutShortcut(Shift, Key) then
- SendMessage(Handle, WM_CUT, 0, 0)
- else begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).DeleteSelection_;
- Key := 0;
- Refresh;
- end;
- Exit;
- end;
- end;
- else
- begin
- if IsCopyShortcut(Shift,Key) then begin
- //SendMessage(Handle, WM_COPY, 0, 0); handled by RichView
- Key := 0;
- exit;
- end;
- if IsCutShortcut(Shift, Key) then begin
- SendMessage(Handle, WM_CUT, 0, 0);
- exit;
- end;
- if IsPasteShortcut(Shift, Key) then begin
- SendMessage(Handle, WM_PASTE, 0, 0);
- exit;
- end;
- if not (ssAlt in Shift) and not (ssCtrl in Shift) and (Key<>VK_INSERT) then begin
- // Just delete selection, if it exists
- selchanged := SelectionExists;
- if selchanged then begin
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).DeleteSelection_;
- end;
- end;
- end;
- end;
- // Step 2 of 3. Processing the key
- case Key of
- VK_RETURN:
- begin
- if not ((ssShift in Shift) and (rvoDoNotWantShiftReturns in EditorOptions)) then
- OnEnterPress(ssShift in Shift);
- Key := 0;
- exit;
- end;
- VK_BACK:
- begin
- OnBackSpacePress(ssCtrl in Shift);
- Key := 0;
- exit;
- end;
- VK_DELETE:
- begin
- OnDeletePress(ssCtrl in Shift);
- {$IFDEF RVDEBUG}{$I Debugj.inc}{$ENDIF}
- Key := 0;
- exit;
- end;
- VK_HOME:
- if TRVEditRVData(RVData).OnHomePress(ssCtrl in Shift) then
- GetOut(rvdTop);
- VK_END:
- if TRVEditRVData(RVData).OnEndPress(ssCtrl in Shift) then
- GetOut(rvdBottom);
- VK_LEFT:
- if BiDiMode=rvbdRightToLeft then begin
- if TRVEditRVData(RVData).OnRightPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdRight);
- end
- else begin
- if TRVEditRVData(RVData).OnLeftPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdLeft);
- end;
- VK_RIGHT:
- if BiDiMode=rvbdRightToLeft then begin
- if TRVEditRVData(RVData).OnLeftPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdLeft);
- end
- else begin
- if TRVEditRVData(RVData).OnRightPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdRight);
- end;
- VK_UP:
- if TRVEditRVData(RVData).OnUpPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdUp);
- VK_DOWN:
- if TRVEditRVData(RVData).OnDownPress(ssShift in Shift, ssCtrl in Shift) then
- GetOut(rvdDown);
- VK_PRIOR:
- TRVEditRVData(RVData).OnPgUpPress;
- VK_NEXT:
- TRVEditRVData(RVData).OnPgDownPress;
- VK_TAB:
- begin
- if ssCtrl in Shift then
- PostMessage(Handle, WM_CHAR, VK_TAB, 0)
- end;
- else
- begin
- if selchanged then
- Invalidate;
- exit;
- end;
- end;
- // Step 3 of 3: Processing selection (if key is arrow-moving key)
- if ssShift in Shift then
- TRVEditRVData(RVData).EndShiftMoving;
- if selchanged then begin
- RVData.DoOnSelection(True);
- Invalidate;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyParaStyle(ParaStyleNo: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyParaStyle(ParaStyleNo);
- exit;
- end;
- {$ENDIF}
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True);
- TRVEditRVData(RVData).ApplyParaStyle(ParaStyleNo, rvscParaStyle);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyTextStyleConversionProc(
- Sender: TCustomRichViewEdit; StyleNo, ParaStyleNo, UserData: Integer;
- AppliedToText: Boolean; var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- begin
- if not (AppliedToText and (rvprStyleProtect in Style.TextStyles[StyleNo].Protection)) then
- NewStyleNo := UserData;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSESTYLETEMPLATES}
- procedure TCustomRichViewEdit.ApplyParaStyleTemplateConversionProc(
- Sender: TCustomRichViewEdit; StyleNo, ParaStyleNo, UserData: Integer;
- AppliedToText: Boolean; var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- var ParaStyle: TParaInfo;
- begin
- if rvpaoStyleProtect in Style.ParaStyles[StyleNo].Options then
- exit;
- ParaStyle := TParaInfo.Create(nil);
- try
- ParaStyle.Assign(Style.ParaStyles[StyleNo]);
- if UserData>=0 then
- Style.StyleTemplates[UserData].ApplyToParaStyle(ParaStyle, True)
- else
- Style.StyleTemplates.ClearParaFormat(ParaStyle);
- NewStyleNo := Style.ParaStyles.FindSuchStyle(StyleNo, ParaStyle, RVAllParaInfoProperties);
- if NewStyleNo<0 then begin
- NewStyleNo := Style.ParaStyles.Count;
- Style.ParaStyles.Add.Assign(ParaStyle);
- Style.ParaStyles[NewStyleNo].Standard := False;
- end;
- finally
- ParaStyle.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyTextStyleTemplateConversionProc(
- Sender: TCustomRichViewEdit; StyleNo, ParaStyleNo, UserData: Integer;
- AppliedToText: Boolean; var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- var TextStyle: TFontInfo;
- begin
- if rvprStyleProtect in Style.TextStyles[StyleNo].Protection then
- exit;
- TextStyle := TFontInfo.Create(nil);
- try
- TextStyle.Assign(Style.TextStyles[StyleNo]);
- if UserData>=0 then
- Style.StyleTemplates[UserData].ApplyToTextStyle(TextStyle,
- Style.ParaStyles[ParaStyleNo], not ToWholeParagraphs)
- else
- Style.StyleTemplates.ClearTextFormat(TextStyle, Style.ParaStyles[ParaStyleNo]);
- NewStyleNo := Style.TextStyles.FindSuchStyle(StyleNo, TextStyle, RVAllFontInfoProperties);
- if NewStyleNo<0 then begin
- NewStyleNo := Style.TextStyles.Count;
- Style.TextStyles.Add.Assign(TextStyle);
- Style.TextStyles[NewStyleNo].Standard := False;
- end;
- finally
- TextStyle.Free;
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyUserParaStyleConversionProc(
- Sender: TCustomRichViewEdit; StyleNo, ParaStyleNo, UserData: Integer;
- AppliedToText: Boolean; var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- begin
- FOnParaStyleConversion(Sender, StyleNo, UserData, AppliedToText, NewStyleNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyUserTextStyleConversionProc(
- Sender: TCustomRichViewEdit; StyleNo, ParaStyleNo, UserData: Integer;
- AppliedToText: Boolean; var NewStyleNo: Integer; ToWholeParagraphs: Boolean);
- begin
- FOnStyleConversion(Sender, StyleNo, UserData, AppliedToText, NewStyleNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyStyleConversion(UserData: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyStyleConversion(UserData);
- exit;
- end;
- {$ENDIF}
- if RVData.SelectionExists(False, True) and not BeforeChange(False) then
- exit;
- if Assigned(FOnStyleConversion) then begin
- FCurStyleConversion := ApplyUserTextStyleConversionProc;
- TRVEditRVData(RVData).ApplyStyleConversion_(UserData,
- rvscTextStyleConversion, False);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyParaStyleConversion(UserData: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyParaStyleConversion(UserData);
- exit;
- end;
- {$ENDIF}
- if Assigned(FOnParaStyleConversion) and BeforeChange(False) then begin
- TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True);
- FCurStyleConversion := ApplyUserParaStyleConversionProc;
- TRVEditRVData(RVData).ApplyParaStyle(UserData, rvscParaStyleConversion);
- end;
- end;
- {------------------------------------------------------------------------------}
- {$IFNDEF RVDONOTUSESTYLETEMPLATES}
- procedure TCustomRichViewEdit.ApplyStyleTemplate(TemplateNo: Integer);
- var ToWholeParagraphs: Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyStyleTemplate(TemplateNo);
- exit;
- end;
- {$ENDIF}
- ToWholeParagraphs := not RVData.SelectionExists(True, False) or RVData.IsMultiParagraphSelection;
- if BeforeChange(False) then begin
- if ToWholeParagraphs then
- TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True)
- else
- TRVEditRVData(RVData).BeginUndoSequence(rvutStyleNo, True);
- TRVEditRVData(RVData).SetUndoGroupMode(True);
- try
- if ToWholeParagraphs then begin
- FCurStyleConversion := ApplyParaStyleTemplateConversionProc;
- TRVEditRVData(RVData).ApplyParaStyle(TemplateNo, rvscParaStyleTemplate);
- end;
- FCurStyleConversion := ApplyTextStyleTemplateConversionProc;
- TRVEditRVData(RVData).ApplyStyleConversion_(TemplateNo,
- rvscTextStyleTemplate, ToWholeParagraphs);
- finally
- TRVEditRVData(RVData).SetUndoGroupMode(False);
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyParaStyleTemplate(TemplateNo: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyParaStyleTemplate(TemplateNo);
- exit;
- end;
- {$ENDIF}
- if BeforeChange(False) then begin
- TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True);
- FCurStyleConversion := ApplyParaStyleTemplateConversionProc;
- TRVEditRVData(RVData).ApplyParaStyle(TemplateNo, rvscParaStyleTemplate);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyTextStyleTemplate(TemplateNo: Integer;
- ToWholeParagraphs: Boolean);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyTextStyleTemplate(TemplateNo,
- ToWholeParagraphs);
- exit;
- end;
- {$ENDIF}
- if BeforeChange(False) then begin
- TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True);
- FCurStyleConversion := ApplyTextStyleTemplateConversionProc;
- TRVEditRVData(RVData).ApplyStyleConversion_(TemplateNo,
- rvscTextStyleTemplate, ToWholeParagraphs);
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.ApplyTextStyle(TextStyleNo: Integer);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).ApplyTextStyle(TextStyleNo);
- exit;
- end;
- {$ENDIF}
- if BeforeChange(False) then begin
- FCurStyleConversion := ApplyTextStyleConversionProc;
- TRVEditRVData(RVData).ApplyStyleConversion_(TextStyleNo, rvscTextStyle, False);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.OnBackSpacePress(Ctrl: Boolean);
- begin
- //if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).OnBackSpacePress_(Ctrl, False, False);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.OnDeletePress(Ctrl: Boolean);
- begin
- //if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).OnDeletePress_(Ctrl, False);
- Change;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.OnEnterPress(Shift: Boolean);
- begin
- if not BeforeChange(False) then exit;
- if TRVEditRVData(RVData).OnEnterPress_(Shift, False) then begin
- Refresh;
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertRVFFromStreamEd(Stream: TStream):Boolean;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).InsertRVFFromStreamEd(Stream);
- exit;
- end;
- {$ENDIF}
- Result := True;
- if not BeforeChange(False) then exit;
- if (RVData.PartialSelectedItem<>nil)or not CanDelete then begin
- TRVEditRVData(RVData).Beep;
- exit;
- end;
- TRVEditRVData(RVData).BeginUndoSequence(rvutInsert, True);
- SetUndoGroupMode(True);
- try
- TRVEditRVData(RVData).DeleteSelection_;
- Result := TRVEditRVData(RVData).InsertRVFFromStreamEd_(Stream);
- finally
- SetUndoGroupMode(False);
- Change;
- end;
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.InsertRVFFromFileEd(const FileName: String):Boolean;
- var Stream: TFileStream;
- begin
- try
- Stream := TFileStream.Create(FileName, fmOpenRead);
- try
- Result := InsertRVFFromStreamEd(Stream);
- finally
- Stream.Free;
- end;
- except
- Result := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.WMChar(var Message: TWMChar);
- {$IFNDEF RVDONOTUSEUNICODE}
- var s: String;
- {$ENDIF}
- begin
- {$IFNDEF RVDONOTUSEUNICODE}
- if rvstIgnoreNextChar in RVData.State then
- exit;
- if Message.CharCode>$FF then begin
- BeforeUnicode;
- SetLength(s,2);
- s[1] := chr(Message.CharCode and $00FF);
- s[2] := chr((Message.CharCode and $FF00) shr 8);
- s := RVU_AnsiToUnicode(RVU_GetKeyboardCodePage, s);
- if Length(s)>0 then
- if (Length(s)=2) and Style.TextStyles[CurTextStyleNo].Unicode then
- TRVEditRVData(RVData).InsertTextTyping(s, '?')
- else
- InsertTextW_(s);
- exit;
- end;
- {$ENDIF}
- inherited;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.KeyPress(var Key: Char);
- var s: String;
- i: Integer;
- r: Boolean;
- begin
- if rvstIgnoreNextChar in RVData.State then
- exit;
- if (ord(Key)=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then begin
- Key := #0;
- TRVEditRVData(RVData).Beep;
- exit;
- end;
- if ((Key < #32) or (Key=#127)) and (ord(Key)<>VK_TAB) then exit;
- Include(RVData.State, rvstKeyPress);
- try
- r := BeforeChange(False);
- finally
- Exclude(RVData.State, rvstKeyPress);
- end;
- if not r then
- exit;
- inherited KeyPress(Key);
- if Key=#0 then
- exit;
- DeleteSelection;
- if ord(Key)=VK_TAB then begin
- if Style.SpacesInTab>0 then begin
- SetLength(s, Style.SpacesInTab);
- for i := 1 to Style.SpacesInTab do
- s[i] := ' ';
- InsertText(s, False);
- end
- {$IFNDEF RVDONOTUSETABS}
- else
- InsertTab
- {$ENDIF}
- ;
- exit;
- end;
- TRVEditRVData(RVData).KeyPress(Key);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCheckpointInfoEd(ItemNo: Integer; ATag: Integer; const AName: String;
- ARaiseEvent: Boolean);
- var cp: TRVCPInfo;
- begin
- if not BeforeChange(False) then exit;
- cp := TCustomRVItemInfo(RVData.Items.Objects[ItemNo]).Checkpoint;
- if cp<>nil then begin
- TRVEditRVData(RVData).BeginUndoSequence(rvutModifyCheckpoint, True);
- if ATag=cp.Tag then
- ATag := RV_CopyTag(ATag, rvoTagsArePChars in Options);
- TRVEditRVData(RVData).Do_DeleteCP(ItemNo);
- end
- else
- TRVEditRVData(RVData).BeginUndoSequence(rvutAddCheckpoint, True);
- cp := TRVCPInfo.Create;
- cp.Name := AName;
- cp.Tag := ATag;
- cp.RaiseEvent := ARaiseEvent;
- TRVEditRVData(RVData).Do_AddCP(ItemNo, cp);
- Change;
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.RemoveCheckpointEd(ItemNo: Integer);
- begin
- if TCustomRVItemInfo(RVData.Items.Objects[ItemNo]).Checkpoint=nil then exit;
- if not BeforeChange(False) then exit;
- TRVEditRVData(RVData).BeginUndoSequence(rvutRemoveCheckpoint, True);
- TRVEditRVData(RVData).Do_DeleteCP(ItemNo);
- Change;
- Invalidate;
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.SetCurrentCheckpointInfo(ATag: Integer; const AName: String;
- ARaiseEvent: Boolean);
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- TCustomRichViewEdit(InplaceEditor).SetCurrentCheckpointInfo(ATag, AName, ARaiseEvent);
- exit;
- end;
- {$ENDIF}
- SetCheckpointInfoEd(CurItemNo, ATag, AName, ARaiseEvent);
- end;
- {------------------------------------------------------------------------------}
- function TCustomRichViewEdit.GetCurrentCheckpoint: TCheckpointData;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}
- if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
- Result := TCustomRichViewEdit(InplaceEditor).GetCurrentCheckpoint;
- exit;
- end;
- {$ENDIF}
- Result := GetItemCheckpoint(CurItemNo);
- end;
- {------------------------------------------------------------------------------}
- procedure TCustomRichViewEdit.RemoveCurrentCheckpoint;
- begin
- {$IFNDEF RVDONOTUSEINPLACE}