📄 rxrichedit(unicode).pas
字号:
Next: PRichConversionFormat;
end;
TRxCustomRichEdit = class(TCustomMemo)
private
FHideScrollBars: Boolean;
FSelectionBar: Boolean;
FAutoURLDetect: Boolean;
FWordSelection: Boolean;
FPlainText: Boolean;
FSelAttributes: TRxTextAttributes;
FDefAttributes: TRxTextAttributes;
FWordAttributes: TRxTextAttributes;
FParagraph: TRxParaAttributes;
FOldParaAlignment: TParaAlignment;
FScreenLogPixels: Integer;
FUndoLimit: Integer;
FRichEditStrings: TWideStrings;
FMemStream: TMemoryStream;
FHideSelection: Boolean;
FLangOptions: TRichLangOptions;
FModified: Boolean;
FLinesUpdating: Boolean;
FPageRect: TRect;
FClickRange: TCharRange;
FClickBtn: TMouseButton;
FFindDialog: TFindDialog;
FReplaceDialog: TReplaceDialog;
FLastFind: TFindDialog;
FAllowObjects: Boolean;
FCallback: TObject;
FRichEditOle: IUnknown;
FPopupVerbMenu: TPopupMenu;
FTitle: string;
FAutoVerbMenu: Boolean;
{$IFDEF RX_D3}
FAllowInPlace: Boolean;
{$ENDIF}
FDefaultConverter: TConversionClass;
FOnSelChange: TNotifyEvent;
FOnResizeRequest: TRichEditResizeEvent;
FOnProtectChange: TRichEditProtectChange;
FOnProtectChangeEx: TRichEditProtectChangeEx;
FOnSaveClipboard: TRichEditSaveClipboard;
FOnURLClick: TRichEditURLClickEvent;
FOnTextNotFound: TRichEditFindErrorEvent;
{$IFDEF RX_D3}
FOnCloseFindDialog: TRichEditFindCloseEvent;
{$ENDIF}
//FDefWndProcW: TFNWndProc;
__Wide: Boolean; {added by junjiao.wang}
__FCP: Word;
__DefWndProcW: TFNWndProc;
__DefWndProcA: TFNWndProc;
function GetAutoURLDetect: Boolean;
function GetWordSelection: Boolean;
function GetLangOptions: TRichLangOptions;
function GetCanRedo: Boolean;
function GetCanPaste: Boolean;
{$IFNDEF RX_V110}
function GetCanUndo: Boolean;
{$ENDIF}
function GetRedoName: TUndoName;
function GetUndoName: TUndoName;
function GetStreamFormat: TRichStreamFormat;
function GetStreamMode: TRichStreamModes;
function GetSelectionType: TRichSelectionType;
procedure PopupVerbClick(Sender: TObject);
procedure ObjectPropsClick(Sender: TObject);
procedure CloseObjects;
procedure UpdateHostNames;
procedure SetAllowObjects(Value: Boolean);
procedure SetStreamFormat(Value: TRichStreamFormat);
procedure SetStreamMode(Value: TRichStreamModes);
procedure SetAutoURLDetect(Value: Boolean);
procedure SetWordSelection(Value: Boolean);
procedure SetHideScrollBars(Value: Boolean);
procedure SetHideSelection(Value: Boolean);
procedure SetTitle(const Value: string);
procedure SetLangOptions(Value: TRichLangOptions);
procedure SetRichEditStrings(Value: TWideStrings);
procedure SetDefAttributes(Value: TRxTextAttributes);
procedure SetSelAttributes(Value: TRxTextAttributes);
procedure SetWordAttributes(Value: TRxTextAttributes);
procedure SetSelectionBar(Value: Boolean);
procedure SetUndoLimit(Value: Integer);
procedure UpdateTextModes(Plain: Boolean);
procedure AdjustFindDialogPosition(Dialog: TFindDialog);
procedure SetupFindDialog(Dialog: TFindDialog; const SearchStr,
ReplaceStr: string);
function FindEditText(Dialog: TFindDialog; AdjustPos, Events: Boolean): Boolean;
function GetCanFindNext: Boolean;
procedure FindDialogFind(Sender: TObject);
procedure ReplaceDialogReplace(Sender: TObject);
{$IFDEF RX_D3}
procedure FindDialogClose(Sender: TObject);
procedure SetUIActive(Active: Boolean);
procedure CMDocWindowActivate(var Message: TMessage); message CM_DOCWINDOWACTIVATE;
procedure CMUIDeactivate(var Message: TMessage); message CM_UIDEACTIVATE;
{$ENDIF}
{$IFDEF RX_D4}
procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
{$ENDIF}
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
procedure EMReplaceSel(var Message: TMessage); message EM_REPLACESEL;
procedure EMGetSelText(var Message: TMessage); message EM_GETSELTEXT;
procedure EMGetTextRange(var Message: TMessage); message EM_GETTEXTRANGE;
procedure WMDestroy(var Msg: TWMDestroy); message WM_DESTROY;
procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMSetCursor(var Message: TWMSetCursor); message WM_SETCURSOR;
procedure WMSetFont(var Message: TWMSetFont); message WM_SETFONT;
procedure WMSetText(var Message: TMessage); message WM_SETTEXT;
{$IFDEF RX_D5}
procedure WMRButtonUp(var Message: TMessage); message WM_RBUTTONUP;
{$ENDIF}
//procedure EMStreamIn(var Message: TMessage); message EM_STREAMIN;
//procedure EMStreamOut(var Message: TMessage); message EM_STREAMOUT;
function PerformReally(Msg: Cardinal; WParam, LParam: Longint): Longint;
procedure LoadRTFProperty(Reader:TStream);
procedure SaveRTFProperty(Writer:TStream);
protected
// procedure DefineProperties(Filer:TFiler); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
function GetPopupMenu: TPopupMenu; override;
procedure TextNotFound(Dialog: TFindDialog); virtual;
procedure RequestSize(const Rect: TRect); virtual;
procedure SelectionChange; dynamic;
function ProtectChange(const Message: TMessage; StartPos,
EndPos: Integer): Boolean; dynamic;
function SaveClipboard(NumObj, NumChars: Integer): Boolean; dynamic;
procedure URLClick(const URLText: string; Button: TMouseButton); dynamic;
procedure SetPlainText(Value: Boolean); virtual;
{$IFDEF RX_D3}
procedure CloseFindDialog(Dialog: TFindDialog); virtual;
procedure DoSetMaxLength(Value: Integer); override;
function GetSelLength: Integer; override;
procedure WideSetText(Value: WideString);
function WideGetText: WideString;
procedure AnsiSetText(Value: string);
function AnsiGetText: string;
procedure SetRTFSelText(Value: String);
function GetRTFSelText: String;
procedure InsertFromFile(const FileName: String);
function GetSelStart: Integer; override;
//function GetSelText: string; override;{this is used to SelText}
{As non-virtual member in the base class, SetSelText can't be overrided }
{So I bet Assigning something to SelText might cause trouble.}
{comments by wang junjiao 2001.2}
//procedure SetSelText(const Value: string); override;
function WideGetSelText: WideString;
procedure WideSetSelText(Value: WideString);
function AnsiGetSelText: string;
procedure AnsiSetSelText(Value: string);
procedure SetSelLength(Value: Integer); override;
procedure SetSelStart(Value: Integer); override;
property AllowInPlace: Boolean read FAllowInPlace write FAllowInPlace default True;
{$ENDIF}
property AllowObjects: Boolean read FAllowObjects write SetAllowObjects default True;
property AutoURLDetect: Boolean read GetAutoURLDetect write SetAutoURLDetect default True;
property AutoVerbMenu: Boolean read FAutoVerbMenu write FAutoVerbMenu default True;
property HideSelection: Boolean read FHideSelection write SetHideSelection default True;
property HideScrollBars: Boolean read FHideScrollBars
write SetHideScrollBars default True;
property Title: string read FTitle write SetTitle;
property LangOptions: TRichLangOptions read GetLangOptions write SetLangOptions default [rlAutoFont];
property SelectionBar: Boolean read FSelectionBar write SetSelectionBar default True;
property StreamFormat: TRichStreamFormat read GetStreamFormat write SetStreamFormat default sfDefault;
property StreamMode: TRichStreamModes read GetStreamMode write SetStreamMode default [];
property UndoLimit: Integer read FUndoLimit write SetUndoLimit default 100;
property WordSelection: Boolean read GetWordSelection write SetWordSelection default True;
property ScrollBars default ssBoth;
property TabStop default True;
property OnSaveClipboard: TRichEditSaveClipboard read FOnSaveClipboard
write FOnSaveClipboard;
property OnSelectionChange: TNotifyEvent read FOnSelChange write FOnSelChange;
property OnProtectChange: TRichEditProtectChange read FOnProtectChange
write FOnProtectChange; { obsolete }
property OnProtectChangeEx: TRichEditProtectChangeEx read FOnProtectChangeEx
write FOnProtectChangeEx;
property OnResizeRequest: TRichEditResizeEvent read FOnResizeRequest
write FOnResizeRequest;
property OnURLClick: TRichEditURLClickEvent read FOnURLClick write FOnURLClick;
property OnTextNotFound: TRichEditFindErrorEvent read FOnTextNotFound write FOnTextNotFound;
{$IFDEF RX_D3}
property OnCloseFindDialog: TRichEditFindCloseEvent read FOnCloseFindDialog
write FOnCloseFindDialog;
{$ENDIF}
public
procedure ShowEditor;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear; {$IFDEF RX_D3} override; {$ENDIF}
procedure SetSelection(StartPos, EndPos: Longint; ScrollCaret: Boolean);
function GetSelection: TCharRange;
function GetTextRange(StartPos, EndPos: Longint): WideString;
function LineFromChar(CharIndex: Integer): Integer;
function GetLineIndex(LineNo: Integer): Integer;
function GetLineLength(CharIndex: Integer): Integer;
function WordAtCursor: string;
function _WordAtCursor: WideString;
function FindText(const SearchStr: string;
StartPos, Length: Integer; Options: TRichSearchTypes): Integer;
//function WideGetSelTextBuf(Buffer: PWideChar; BufSize: Integer): Integer;
function GetCaretPos: TPoint; override;
function GetCharPos(CharIndex: Integer): TPoint;
function InsertObjectDialog: Boolean;
function ObjectPropertiesDialog: Boolean;
function PasteSpecialDialog: Boolean;
function FindDialog(const SearchStr: string): TFindDialog;
function ReplaceDialog(const SearchStr, ReplaceStr: string): TReplaceDialog;
function FindNext: Boolean;
procedure Print(const Caption: string); virtual;
class procedure RegisterConversionFormat(const AExtension: string;
APlainText: Boolean; AConversionClass: TConversionClass);
procedure ClearUndo;
procedure Redo;
procedure StopGroupTyping;
property CanFindNext: Boolean read GetCanFindNext;
property CanRedo: Boolean read GetCanRedo;
property CanPaste: Boolean read GetCanPaste;
{$IFNDEF RX_V110}
procedure Undo;
property CanUndo: Boolean read GetCanUndo;
property CaretPos: TPoint read GetCaretPos;
{$ENDIF}
property RedoName: TUndoName read GetRedoName;
property UndoName: TUndoName read GetUndoName;
property DefaultConverter: TConversionClass read FDefaultConverter
write FDefaultConverter;
property DefAttributes: TRxTextAttributes read FDefAttributes write SetDefAttributes;
property SelAttributes: TRxTextAttributes read FSelAttributes write SetSelAttributes;
property WordAttributes: TRxTextAttributes read FWordAttributes write SetWordAttributes;
property PageRect: TRect read FPageRect write FPageRect;
property Paragraph: TRxParaAttributes read FParagraph;
property SelectionType: TRichSelectionType read GetSelectionType;
//property SelText: string read GetSelText write SetSelText;
//Since we can not override SetSelText, EMReplaceSel & EMGetSelText are hooked.
//So i'd guess SelText might work , but i'm not very sure this.
//comments by wang junjiao 2001.2
property WideSelText: WideString read WideGetSelText write WideSetSelText;
property WideText: WideString read WideGetText write WideSetText;
property AnsiSelText: string read AnsiGetSelText write AnsiSetSelText;
property AnsiText: string read AnsiGetText write AnsiSetText;
property RTFSelText: String read GetRTFSelText write SetRTFSelText;
published
property Lines: TWideStrings read FRichEditStrings write SetRichEditStrings stored True;
property PlainText: Boolean read FPlainText write SetPlainText default False;
end;
//-----------------------------------------------------------------------------
{TRxRichEdit}
TRxRichEdit = class(TRxCustomRichEdit)
public
published
property Align;
property Alignment;
property AutoURLDetect;
property AutoVerbMenu;
property AllowObjects;
{$IFDEF RX_D3}
property AllowInPlace;
{$ENDIF}
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property BorderWidth;
property DragKind;
{$ENDIF}
property BorderStyle;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HideScrollBars;
property Title;
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$IFDEF RX_D4}
property Constraints;
property Lines;
property ParentBiDiMode;
{$ENDIF}
property LangOptions;
//property Lines;
property MaxLength;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PlainText;
property PopupMenu;
property ReadOnly;
property ScrollBars;
property SelectionBar;
property ShowHint;
property StreamFormat;
property StreamMode;
property TabOrder;
property TabStop;
property UndoLimit;
property Visible;
property WantTabs;
property WantReturns;
property WordSelection;
property WordWrap;
property OnChange;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
{$IFDEF RX_D4}
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
{$ENDIF}
property OnProtectChange; { obsolete }
property OnProtectChangeEx;
property OnResizeRequest;
property OnSaveClipboard;
property OnSelectionChange;
property OnStartDrag;
property OnTextNotFound;
{$IFDEF RX_D3}
property OnCloseFindDialog;
{$ENDIF}
property OnURLClick;
end;
var
RichEditVersion: TRichEditVersion;
procedure Register;
implementation
uses RTFProperty,dsgnintf,Printers, ComStrs,OleConst, OleDlg {$IFDEF RX_D3}, OleCtnrs {$ENDIF}
{,MaxMin};
var
IsWinNT: Boolean;
//-----------------------------------------------------------------------------
{ unicode tools } {added by junjiao.wang, They come form TRichEdit98}
function CharToWide(const S: String; CodePage: Word): WideString;
var
L: Integer;
begin
if S='' then
Result:= ''
else
begin
L:= MultiByteToWideChar(CodePage, 0, PChar(@S[1]), -1, nil, 0);
SetLength(Result, L-1);
MultiByteToWideChar(CodePage, 0, PChar(@S[1]), -1, PWideChar(@Result[1]), L-1);
end;
end;
function WideToChar(const WS: WideString; CodePage: Word): String;
var
L: Integer;
begin
if WS='' then
Result:= ''
else
begin
L:= WideCharToMultiByte(CodePage, 0, @WS[1], -1, nil, 0, nil, nil);
SetLength(Result, L-1);
WideCharToMultiByte(CodePage, 0, @WS[1], -1, @Result[1], L-1, nil, nil);
end;
end;
//-----------------------------------------------------------------------------
{ TWideStrings }
destructor TWideStrings.Destroy;
begin
//StringsAdapter := nil;
inherited Destroy;
end;
function TWideStrings.Add(const S: string): Integer;
begin
Result := WideAdd(CharToWide(S, __cp));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -