📄 rm_jvrichedit.pas
字号:
PFE_TABLECELL = $4000; { that para is part of a table }
PFA_JUSTIFY = 4; { New paragraph-alignment option 2.0 (*) }
const
SF_UNICODE = $0010; { Unicode file of some kind }
type
TFindTextExA = record
chrg: TCharRange;
lpstrText: PAnsiChar;
chrgText: TCharRange;
end;
TObjectPositions = packed record
NMHdr: TNMHdr;
cObjectCount: Longint;
pcpPositions: PLongint;
end;
TENLink = record
NMHdr: TNMHdr;
Msg: UINT;
WParam: WParam;
LParam: LParam;
chrg: TCharRange;
end;
TENOleOpFailed = packed record
NMHdr: TNMHdr;
iob: Longint;
lOper: Longint;
hr: HRESULT;
end;
const
{ flags for the GETTEXTLENGTHEX data structure }
GTL_DEFAULT = 0; { do the default (return # of chars) }
GTL_USECRLF = 1; { compute answer using CRLFs for paragraphs }
GTL_PRECISE = 2; { compute a precise answer }
GTL_CLOSE = 4; { fast computation of a "close" answer }
GTL_NUMCHARS = 8; { return the number of characters }
GTL_NUMBYTES = 16; { return the number of _bytes_ }
type
{ EM_GETTEXTLENGTHEX info; this struct is passed in the wparam of the msg }
TGetTextLengthEx = record
Flags: DWORD; { flags (see GTL_XXX defines) }
codepage: UINT; { code page for translation }
end;
const
OLEOP_DOVERB = 1;
{$ENDIF COMPILER3_UP}
const
FT_DOWN = 1;
type
PENLink = ^TENLink;
PENOleOpFailed = ^TENOleOpFailed;
TFindTextEx = TFindTextExA;
TTextRangeA = record
chrg: TCharRange;
lpstrText: PAnsiChar;
end;
TTextRangeW = record
chrg: TCharRange;
lpstrText: PWideChar;
end;
TTextRange = TTextRangeA;
{$IFDEF COMPILER3_UP}
function ResStr(const Ident: string): string;
begin
Result := Ident;
end;
{$ELSE}
function ResStr(Ident: Cardinal): string;
begin
Result := LoadStr(Ident);
end;
{$ENDIF}
const
AttrFlags: array[TJvAttributeType] of Word =
(0, SCF_SELECTION, SCF_WORD or SCF_SELECTION);
//=== TJvTextAttributes ======================================================
constructor TJvTextAttributes.Create(AOwner: TJvCustomRichEdit;
AttributeType: TJvAttributeType);
begin
inherited Create;
FRichEdit := AOwner;
FType := AttributeType;
end;
procedure TJvTextAttributes.InitFormat(var Format: TJvCharFormat2);
begin
FillChar(Format, SizeOf(Format), 0);
if RichEditVersion >= 2 then
Format.cbSize := SizeOf(Format)
else
Format.cbSize := SizeOf(TCharFormat);
end;
function TJvTextAttributes.GetConsistentAttributes: TJvConsistentAttributes;
var
Format: TJvCharFormat2;
begin
Result := [];
if FRichEdit.HandleAllocated and (FType <> atDefaultText) then
begin
InitFormat(Format);
SendMessage(FRichEdit.Handle, EM_GETCHARFORMAT,
AttrFlags[FType], LParam(@Format));
with Format do
begin
if (dwMask and CFM_BOLD) <> 0 then
Include(Result, caBold);
if (dwMask and CFM_COLOR) <> 0 then
Include(Result, caColor);
if (dwMask and CFM_FACE) <> 0 then
Include(Result, caFace);
if (dwMask and CFM_ITALIC) <> 0 then
Include(Result, caItalic);
if (dwMask and CFM_SIZE) <> 0 then
Include(Result, caSize);
if (dwMask and CFM_STRIKEOUT) <> 0 then
Include(Result, caStrikeOut);
if (dwMask and CFM_UNDERLINE) <> 0 then
Include(Result, caUnderline);
if (dwMask and CFM_PROTECTED) <> 0 then
Include(Result, caProtected);
if (dwMask and CFM_OFFSET) <> 0 then
Include(Result, caOffset);
if (dwMask and CFM_HIDDEN) <> 0 then
Include(Result, caHidden);
if RichEditVersion >= 2 then
begin
if (dwMask and CFM_LINK) <> 0 then
Include(Result, caLink);
if (dwMask and CFM_BACKCOLOR) <> 0 then
Include(Result, caBackColor);
if (dwMask and CFM_DISABLED) <> 0 then
Include(Result, caDisabled);
if (dwMask and CFM_WEIGHT) <> 0 then
Include(Result, caWeight);
if (dwMask and CFM_SUBSCRIPT) <> 0 then
Include(Result, caSubscript);
if (dwMask and CFM_REVAUTHOR) <> 0 then
Include(Result, caRevAuthor);
end;
end;
end;
end;
procedure TJvTextAttributes.GetAttributes(var Format: TJvCharFormat2);
begin
InitFormat(Format);
if FRichEdit.HandleAllocated then
SendMessage(FRichEdit.Handle, EM_GETCHARFORMAT, AttrFlags[FType],
LParam(@Format));
end;
procedure TJvTextAttributes.SetAttributes(var Format: TJvCharFormat2);
begin
if FRichEdit.HandleAllocated then
SendMessage(FRichEdit.Handle, EM_SETCHARFORMAT, AttrFlags[FType],
LParam(@Format));
end;
{$IFNDEF COMPILER2}
function TJvTextAttributes.GetCharset: TFontCharset;
var
Format: TJvCharFormat2;
begin
GetAttributes(Format);
Result := Format.bCharset;
end;
procedure TJvTextAttributes.SetCharset(Value: TFontCharset);
var
Format: TJvCharFormat2;
begin
InitFormat(Format);
with Format do
begin
dwMask := CFM_CHARSET;
bCharSet := Value;
end;
SetAttributes(Format);
end;
{$ENDIF}
function TJvTextAttributes.GetProtected: Boolean;
var
Format: TJvCharFormat2;
begin
GetAttributes(Format);
with Format do
Result := (dwEffects and CFE_PROTECTED) <> 0;
end;
procedure TJvTextAttributes.SetProtected(Value: Boolean);
var
Format: TJvCharFormat2;
begin
InitFormat(Format);
with Format do
begin
dwMask := CFM_PROTECTED;
if Value then
dwEffects := CFE_PROTECTED;
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetLink: Boolean;
var
Format: TJvCharFormat2;
begin
Result := False;
if RichEditVersion < 2 then
Exit;
GetAttributes(Format);
with Format do
Result := (dwEffects and CFE_LINK) <> 0;
end;
procedure TJvTextAttributes.SetLink(Value: Boolean);
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
Exit;
InitFormat(Format);
with Format do
begin
dwMask := CFM_LINK;
if Value then
dwEffects := CFE_LINK;
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetRevAuthorIndex: Byte;
var
Format: TJvCharFormat2;
begin
GetAttributes(Format);
Result := Format.bRevAuthor;
end;
procedure TJvTextAttributes.SetRevAuthorIndex(Value: Byte);
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
Exit;
InitFormat(Format);
with Format do
begin
dwMask := CFM_REVAUTHOR;
bRevAuthor := Value;
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetHidden: Boolean;
var
Format: TJvCharFormat2;
begin
Result := False;
if RichEditVersion < 2 then
Exit;
GetAttributes(Format);
Result := Format.dwEffects and CFE_HIDDEN <> 0;
end;
procedure TJvTextAttributes.SetHidden(Value: Boolean);
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
Exit;
InitFormat(Format);
with Format do
begin
dwMask := CFM_HIDDEN;
if Value then
dwEffects := CFE_HIDDEN;
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetDisabled: Boolean;
var
Format: TJvCharFormat2;
begin
Result := False;
if RichEditVersion < 2 then
Exit;
GetAttributes(Format);
Result := Format.dwEffects and CFE_DISABLED <> 0;
end;
procedure TJvTextAttributes.SetDisabled(Value: Boolean);
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
Exit;
InitFormat(Format);
with Format do
begin
dwMask := CFM_DISABLED;
if Value then
dwEffects := CFE_DISABLED;
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetColor: TColor;
var
Format: TJvCharFormat2;
begin
GetAttributes(Format);
with Format do
if (dwEffects and CFE_AUTOCOLOR) <> 0 then
Result := clWindowText
else
Result := crTextColor;
end;
procedure TJvTextAttributes.SetColor(Value: TColor);
var
Format: TJvCharFormat2;
begin
InitFormat(Format);
with Format do
begin
dwMask := CFM_COLOR;
if (Value = clWindowText) or (Value = clDefault) then
dwEffects := CFE_AUTOCOLOR
else
crTextColor := ColorToRGB(Value);
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetBackColor: TColor;
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
begin
Result := clWindow;
Exit;
end;
GetAttributes(Format);
with Format do
if (dwEffects and CFE_AUTOBACKCOLOR) <> 0 then
Result := clWindow
else
Result := crBackColor;
end;
procedure TJvTextAttributes.SetBackColor(Value: TColor);
var
Format: TJvCharFormat2;
begin
if RichEditVersion < 2 then
Exit;
InitFormat(Format);
with Format do
begin
dwMask := CFM_BACKCOLOR;
if (Value = clWindow) or (Value = clDefault) then
dwEffects := CFE_AUTOBACKCOLOR
else
crBackColor := ColorToRGB(Value);
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetName: TFontName;
var
Format: TJvCharFormat2;
begin
GetAttributes(Format);
Result := Format.szFaceName;
end;
procedure TJvTextAttributes.SetName(Value: TFontName);
var
Format: TJvCharFormat2;
begin
InitFormat(Format);
with Format do
begin
dwMask := CFM_FACE;
StrPLCopy(szFaceName, Value, SizeOf(szFaceName));
end;
SetAttributes(Format);
end;
function TJvTextAttributes.GetStyle: TFontStyles;
var
Format: TJvCharFormat2;
begin
Result := [];
GetAttributes(Format);
with Format do
begin
if (dwEffects and CFE_BOLD) <> 0 then
Include(Result, fsBold);
if (dwEffects and CFE_ITALIC) <> 0 then
Include(Result, fsItalic);
if (dwEffects and CFE_UNDERLINE) <> 0 then
Include(Result, fsUnderline);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -