📄 rm_jvrichedit.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvRichEd.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributor(s):
Polaris Software
Last Modified: 2002-07-04
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
{$I RM_JVCL.INC}
unit RM_JvRichEdit;
{.$DEFINE RICHEDIT_VER_10}
{$R-}
{$I RM.INC}
interface
uses
Windows,
{$IFDEF COMPILER3_UP}
ActiveX, ComObj,
{$ELSE}
Ole2, OleAuto,
{$ENDIF}
CommCtrl, Messages, SysUtils, Classes, Controls, Forms, Graphics, StdCtrls,
Dialogs, RichEdit, Menus, ComCtrls
{$IFDEF TntUnicode}
, TntClasses, TntSysUtils, TntStdCtrls, TntWindows, TntControls,
ActiveIMM_TLB, TntWideStrings
{$ENDIF};
type
TRichEditVersion = 1..3;
// {$IFNDEF COMPILER3_UP}
TJvCharFormat2A = record
cbSize: UINT;
dwMask: DWORD;
dwEffects: DWORD;
yHeight: Longint;
yOffset: Longint;
crTextColor: TColorRef;
bCharSet: Byte;
bPitchAndFamily: Byte;
szFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
{ new fields in version 2.0 }
wWeight: Word; { Font weight (LOGFONT value) }
sSpacing: SmallInt; { Amount to space between letters }
crBackColor: TColorRef; { Background color }
lid: LCID; { Locale ID }
dwReserved: DWORD; { Reserved. Must be 0 }
sStyle: SmallInt; { Style handle }
wKerning: Word; { Twip size above which to kern char pair }
bUnderlineType: Byte; { Underline type }
bAnimation: Byte; { Animated text like marching ants }
bRevAuthor: Byte; { Revision author index }
bReserved1: Byte;
end;
TJvCharFormat2 = TJvCharFormat2A;
TJvParaFormat2 = record
cbSize: UINT;
dwMask: DWORD;
wNumbering: Word;
wReserved: Word;
dxStartIndent: Longint;
dxRightIndent: Longint;
dxOffset: Longint;
wAlignment: Word;
cTabCount: SmallInt;
rgxTabs: array[0..MAX_TAB_STOPS - 1] of Longint;
{ new fields in version 2.0 }
dySpaceBefore: Longint; { Vertical spacing before paragraph }
dySpaceAfter: Longint; { Vertical spacing after paragraph }
dyLineSpacing: Longint; { Line spacing depending on Rule }
sStyle: SmallInt; { Style handle }
bLineSpacingRule: Byte; { Rule for line spacing (see tom.doc) }
bCRC: Byte; { Reserved for CRC for rapid searching }
wShadingWeight: Word; { Shading in hundredths of a per cent }
wShadingStyle: Word; { Nibble 0: style, 1: cfpat, 2: cbpat }
wNumberingStart: Word; { Starting value for numbering }
wNumberingStyle: Word; { Alignment, roman/arabic, (), ), ., etc.}
wNumberingTab: Word; { Space bet 1st indent and 1st-line text }
wBorderSpace: Word; { Space between border and text (twips) }
wBorderWidth: Word; { Border pen width (twips) }
wBorders: Word; { Byte 0: bits specify which borders }
{ Nibble 2: border style, 3: color index }
end;
// {$ENDIF COMPILER3_UP}
// Polaris
//{$IFDEF COMPILER5_UP}
// TJvCharFormat2 = TJvCharFormat2A;
//{$ENDIF}
type
TJvCustomRichEdit = class;
TJvAttributeType = (atDefaultText, atSelected, atWord);
TJvConsistentAttribute = (caBold, caColor, caFace, caItalic, caSize,
caStrikeOut, caUnderline, caProtected, caOffset, caHidden, caLink,
caBackColor, caDisabled, caWeight, caSubscript, caRevAuthor);
TJvConsistentAttributes = set of TJvConsistentAttribute;
TSubscriptStyle = (ssNone, ssSubscript, ssSuperscript);
TUnderlineType = (utNone, utSolid, utWord, utDouble, utDotted, utWave);
TJvTextAttributes = class(TPersistent)
private
FRichEdit: TJvCustomRichEdit;
FType: TJvAttributeType;
procedure AssignFont(Font: TFont);
procedure GetAttributes(var Format: TJvCharFormat2);
{$IFNDEF COMPILER2}
function GetCharset: TFontCharset;
procedure SetCharset(Value: TFontCharset);
{$ENDIF}
function GetSubscriptStyle: TSubscriptStyle;
procedure SetSubscriptStyle(Value: TSubscriptStyle);
function GetBackColor: TColor;
function GetColor: TColor;
function GetConsistentAttributes: TJvConsistentAttributes;
function GetHeight: Integer;
function GetHidden: Boolean;
function GetDisabled: Boolean;
function GetLink: Boolean;
function GetName: TFontName;
function GetOffset: Integer;
function GetPitch: TFontPitch;
function GetProtected: Boolean;
function GetRevAuthorIndex: Byte;
function GetSize: Integer;
function GetStyle: TFontStyles;
function GetUnderlineType: TUnderlineType;
procedure SetAttributes(var Format: TJvCharFormat2);
procedure SetBackColor(Value: TColor);
procedure SetColor(Value: TColor);
procedure SetDisabled(Value: Boolean);
procedure SetHeight(Value: Integer);
procedure SetHidden(Value: Boolean);
procedure SetLink(Value: Boolean);
procedure SetName(Value: TFontName);
procedure SetOffset(Value: Integer);
procedure SetPitch(Value: TFontPitch);
procedure SetProtected(Value: Boolean);
procedure SetRevAuthorIndex(Value: Byte);
procedure SetSize(Value: Integer);
procedure SetStyle(Value: TFontStyles);
procedure SetUnderlineType(Value: TUnderlineType);
protected
procedure InitFormat(var Format: TJvCharFormat2);
procedure AssignTo(Dest: TPersistent); override;
public
constructor Create(AOwner: TJvCustomRichEdit; AttributeType: TJvAttributeType);
procedure Assign(Source: TPersistent); override;
{$IFNDEF COMPILER2}
property Charset: TFontCharset read GetCharset write SetCharset;
{$ENDIF}
property BackColor: TColor read GetBackColor write SetBackColor;
property Color: TColor read GetColor write SetColor;
property ConsistentAttributes: TJvConsistentAttributes read GetConsistentAttributes;
property Disabled: Boolean read GetDisabled write SetDisabled;
property Hidden: Boolean read GetHidden write SetHidden;
property Link: Boolean read GetLink write SetLink;
property Name: TFontName read GetName write SetName;
property Offset: Integer read GetOffset write SetOffset;
property Pitch: TFontPitch read GetPitch write SetPitch;
property Protected: Boolean read GetProtected write SetProtected;
property RevAuthorIndex: Byte read GetRevAuthorIndex write SetRevAuthorIndex;
property SubscriptStyle: TSubscriptStyle read GetSubscriptStyle write SetSubscriptStyle;
property Size: Integer read GetSize write SetSize;
property Style: TFontStyles read GetStyle write SetStyle;
property Height: Integer read GetHeight write SetHeight;
property UnderlineType: TUnderlineType read GetUnderlineType write SetUnderlineType;
end;
TJvNumbering = (nsNone, nsBullet, nsArabicNumbers, nsLoCaseLetter,
nsUpCaseLetter, nsLoCaseRoman, nsUpCaseRoman);
TJvNumberingStyle = (nsParenthesis, nsPeriod, nsEnclosed, nsSimple);
TParaAlignment = (paLeftJustify, paRightJustify, paCenter, paJustify);
TLineSpacingRule = (lsSingle, lsOneAndHalf, lsDouble, lsSpecifiedOrMore,
lsSpecified, lsMultiple);
THeadingStyle = 0..9;
TParaTableStyle = (tsNone, tsTableRow, tsTableCellEnd, tsTableCell);
TJvParaAttributes = class(TPersistent)
private
FRichEdit: TJvCustomRichEdit;
procedure GetAttributes(var Paragraph: TJvParaFormat2);
function GetAlignment: TParaAlignment;
function GetFirstIndent: Longint;
function GetHeadingStyle: THeadingStyle;
function GetLeftIndent: Longint;
function GetRightIndent: Longint;
function GetSpaceAfter: Longint;
function GetSpaceBefore: Longint;
function GetLineSpacing: Longint;
function GetLineSpacingRule: TLineSpacingRule;
function GetNumbering: TJvNumbering;
function GetNumberingStyle: TJvNumberingStyle;
function GetNumberingTab: Word;
function GetTab(Index: Byte): Longint;
function GetTabCount: Integer;
function GetTableStyle: TParaTableStyle;
procedure SetAlignment(Value: TParaAlignment);
procedure SetAttributes(var Paragraph: TJvParaFormat2);
procedure SetFirstIndent(Value: Longint);
procedure SetHeadingStyle(Value: THeadingStyle);
procedure SetLeftIndent(Value: Longint);
procedure SetRightIndent(Value: Longint);
procedure SetSpaceAfter(Value: Longint);
procedure SetSpaceBefore(Value: Longint);
procedure SetLineSpacing(Value: Longint);
procedure SetLineSpacingRule(Value: TLineSpacingRule);
procedure SetNumbering(Value: TJvNumbering);
procedure SetNumberingStyle(Value: TJvNumberingStyle);
procedure SetNumberingTab(Value: Word);
procedure SetTab(Index: Byte; Value: Longint);
procedure SetTabCount(Value: Integer);
procedure SetTableStyle(Value: TParaTableStyle);
protected
procedure InitPara(var Paragraph: TJvParaFormat2);
procedure AssignTo(Dest: TPersistent); override;
public
constructor Create(AOwner: TJvCustomRichEdit);
procedure Assign(Source: TPersistent); override;
property Alignment: TParaAlignment read GetAlignment write SetAlignment;
property FirstIndent: Longint read GetFirstIndent write SetFirstIndent;
property HeadingStyle: THeadingStyle read GetHeadingStyle write SetHeadingStyle;
property LeftIndent: Longint read GetLeftIndent write SetLeftIndent;
property LineSpacing: Longint read GetLineSpacing write SetLineSpacing;
property LineSpacingRule: TLineSpacingRule read GetLineSpacingRule write SetLineSpacingRule;
property Numbering: TJvNumbering read GetNumbering write SetNumbering;
property NumberingStyle: TJvNumberingStyle read GetNumberingStyle write SetNumberingStyle;
property NumberingTab: Word read GetNumberingTab write SetNumberingTab;
property RightIndent: Longint read GetRightIndent write SetRightIndent;
property SpaceAfter: Longint read GetSpaceAfter write SetSpaceAfter;
property SpaceBefore: Longint read GetSpaceBefore write SetSpaceBefore;
property Tab[Index: Byte]: Longint read GetTab write SetTab;
property TabCount: Integer read GetTabCount write SetTabCount;
property TableStyle: TParaTableStyle read GetTableStyle write SetTableStyle;
end;
TJvOEMConversion = class(TConversion)
public
function ConvertReadStream(Stream: TStream; Buffer: PChar; BufSize: Integer): Integer; override;
function ConvertWriteStream(Stream: TStream; Buffer: PChar; BufSize: Integer): Integer; override;
end;
TUndoName = (unUnknown, unTyping, unDelete, unDragDrop, unCut, unPaste);
TRichSearchType = (stWholeWord, stMatchCase, stBackward, stSetSelection);
TRichSearchTypes = set of TRichSearchType;
TRichSelection = (stText, stObject, stMultiChar, stMultiObject);
TRichSelectionType = set of TRichSelection;
TRichLangOption = (rlAutoKeyboard, rlAutoFont, rlImeCancelComplete,
rlImeAlwaysSendNotify);
TRichLangOptions = set of TRichLangOption;
TRichStreamFormat = (sfDefault, sfRichText, sfPlainText);
TRichStreamMode = (smSelection, smPlainRtf, smNoObjects, smUnicode);
TRichStreamModes = set of TRichStreamMode;
TRichEditURLClickEvent = procedure(Sender: TObject; const URLText: string;
Button: TMouseButton) of object;
TRichEditProtectChangeEx = procedure(Sender: TObject; const Msg: TMessage;
StartPos, EndPos: Integer; var AllowChange: Boolean) of object;
TRichEditFindErrorEvent = procedure(Sender: TObject; const FindText: string) of object;
{$IFDEF COMPILER3_UP}
TRichEditFindCloseEvent = procedure(Sender: TObject; Dialog: TFindDialog) of object;
{$ENDIF}
PRichConversionFormat = ^TRichConversionFormat;
TRichConversionFormat = record
ConversionClass: TConversionClass;
Extension: string;
PlainText: Boolean;
Next: PRichConversionFormat;
end;
TJvCustomRichEdit = class(TCustomMemo)
private
FHideScrollBars: Boolean;
FSelectionBar: Boolean;
FAutoURLDetect: Boolean;
FWordSelection: Boolean;
FPlainText: Boolean;
FSelAttributes: TJvTextAttributes;
FDefAttributes: TJvTextAttributes;
FWordAttributes: TJvTextAttributes;
FParagraph: TJvParaAttributes;
FOldParaAlignment: TParaAlignment;
FScreenLogPixels: Integer;
FUndoLimit: Integer;
FRichEditStrings: TStrings;
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 COMPILER3_UP}
FAllowInPlace: Boolean;
{$ENDIF}
FDefaultJvConverter: TConversionClass;
FOnSelChange: TNotifyEvent;
FOnResizeRequest: TRichEditResizeEvent;
FOnProtectChange: TRichEditProtectChange;
FOnProtectChangeEx: TRichEditProtectChangeEx;
FOnSaveClipboard: TRichEditSaveClipboard;
FOnURLClick: TRichEditURLClickEvent;
FOnTextNotFound: TRichEditFindErrorEvent;
{$IFDEF COMPILER3_UP}
FOnCloseFindDialog: TRichEditFindCloseEvent;
{$ENDIF}
function GetAutoURLDetect: Boolean;
function GetWordSelection: Boolean;
function GetLangOptions: TRichLangOptions;
function GetCanRedo: Boolean;
function GetCanPaste: Boolean;
{$IFNDEF COMPILER35_UP}
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: TStrings);
procedure SetDefAttributes(Value: TJvTextAttributes);
procedure SetSelAttributes(Value: TJvTextAttributes);
procedure SetWordAttributes(Value: TJvTextAttributes);
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 COMPILER3_UP}
procedure FindDialogClose(Sender: TObject);
procedure SetUIActive(Active: Boolean);
procedure CMDocWindowActivate(var Msg: TMessage); message CM_DOCWINDOWACTIVATE;
procedure CMUIDeactivate(var Msg: TMessage); message CM_UIDEACTIVATE;
{$ENDIF}
{$IFDEF COMPILER4_UP}
procedure CMBiDiModeChanged(var Msg: TMessage); message CM_BIDIMODECHANGED;
{$ENDIF}
procedure CMColorChanged(var Msg: TMessage); message CM_COLORCHANGED;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
procedure EMReplaceSel(var Msg: TMessage); message EM_REPLACESEL;
procedure WMDestroy(var Msg: TWMDestroy); message WM_DESTROY;
procedure WMMouseMove(var Msg: TMessage); message WM_MOUSEMOVE;
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
procedure WMSetFont(var Msg: TWMSetFont); message WM_SETFONT;
{$IFDEF COMPILER5_UP}
procedure WMRButtonUp(var Msg: TMessage); message WM_RBUTTONUP;
{$ENDIF}
protected
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 Msg: 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 COMPILER3_UP}
procedure CloseFindDialog(Dialog: TFindDialog); virtual;
procedure DoSetMaxLength(Value: Integer); override;
function GetSelLength: Integer; override;
function GetSelStart: Integer; override;
function GetSelText: string; override;
procedure SetSelLength(Value: Integer); override;
procedure SetSelStart(Value: Integer); override;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -