📄 wpbuff.pas
字号:
// Copyright (c) 1995-2002, Eminent Domain Software. All rights reserved.
// WPTools buffer manager for EDSSpell component
unit WPBuff;
{$I WPINC.INC}
interface
uses
Classes, Controls, Graphics, SysUtils, Forms, StdCtrls,
Windows,
AbsBuff, MemoUtil, SpellGbl
{$IFDEF WPTOOLS5}
,WPRTEDefs, WPRTEPaint, WPCTRMemo
{$ELSE}
,WPWinCtr, WPDefs, WPRich
{$ENDIF}
; //JZ
type
// WPTools Editor Buffer Manager
TWPBuf = class(TPCharBuffer)
private
WeModified: Boolean;
// position of cursor
FSaveSelStart: integer;
// length of selection
FSaveSelLength: integer;
protected
public
// creates the buffer manager component
constructor Create(AOwner: TComponent); override;
// saves the state of the buffer manager and/or parent control
procedure SaveState; override;
// restore the state of the buffer manager and/or parent control
procedure RestoreState; override;
// returns TRUE if parent had been modified
function IsModified: Boolean; override;
// sets parents modified flag
procedure SetModified(NowModified: Boolean); override;
// gets the current y location of the highlighted word (absolute screen)
function GetYPos: integer; override;
// highlights the current word using BeginPos & EndPos
procedure SetSelectedText; override;
// unselect text
procedure UnSelectText; override;
// returns the next word in the buffer
function GetNextWord: string; override;
// returns the current word
function GetCurrentWord(AControl: TControl): string; override;
// updates the buffer from the parent component, if any
procedure UpdateBuffer; override;
// moves back to the beginning of the current word
procedure MoveBackOneWord; override;
// replaces the current word with the word provided
procedure ReplaceWord(WithWord: string); override;
end; { TWPBuf }
implementation
// The WPTools Editor Buffer Manager
// creates the buffer manager component
constructor TWPBuf.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
WeModified := FALSE;
end; { TWPBuf.Create }
// saves the state of the buffer manager and/or parent control
procedure TWPBuf.SaveState;
begin
with ParentControl as TWPCustomRtfEdit do
begin
FSaveSelStart := SelStart;
FSaveSelLength := SelLength;
end; { with }
end; { TWPBuf.SaveState }
// restore the state of the buffer manager and/or parent control
procedure TWPBuf.RestoreState;
begin
with ParentControl as TWPCustomRtfEdit do
begin
SelStart := FSaveSelStart;
SelLength := FSaveSelLength;
end; { with }
end; { TWPBuf.RestoreState }
// returns TRUE if ParentControl had been modified
function TWPBuf.IsModified: Boolean;
begin
Result := WeModified;
end; { TWPBuf.IsModified }
// sets ParentControls modified flag
procedure TWPBuf.SetModified(NowModified: Boolean);
begin
WeModified := NowModified;
end; { TWPBuf.SetModified }
// gets the current y location of the highlighted word (absolute screen)
function TWPBuf.GetYPos: integer;
{ code provided by Julian Ziersch }
var
{$IFDEF WPTOOLS5}
r : TRect;
{$ELSE}
p: TPoint;
{$ENDIF}
begin
Result := 0;
with ParentControl as TWPCustomRtfEdit do
begin
{$IFDEF WPTOOLS5}
Result := Spell_TopPosition;
{$ELSE}
p.x := 0;
p.y := 0;
if memo.block_e_lin <> nil then
p.y := memo.TwipToScreen(memo.block_e_lin^.y_start
+ memo.block_e_lin^.height - memo.Top_Offset);
p := ClientToScreen(p);
Result := p.y;
{$ENDIF}
end; { with }
end; { TWPBuf.GetYPos }
// highlights the current word using FBeginPos & FEndPos
procedure TWPBuf.SetSelectedText;
begin
{$IFDEF WPTOOLS5}
with ParentControl as TWPCustomRtfEdit do
Spell_SelectWord;
{$ELSE}
with ParentControl as TWPCustomRichText do //JZ TWPCustomRtfEdit do
Spell_SelectWord;
{$ENDIF}
end; { TWPBuf.SetSelectedText }
// unselect text
procedure TWPBuf.UnSelectText;
begin
with ParentControl as TWPCustomRtfEdit do
SelLength := 0;
end; { TCEBuffer.UnSelectText }
// returns the next word in the buffer
function TWPBuf.GetNextWord: string;
var
i: byte;
Buffer: array[0..256] of Char;
begin
{$IFDEF WPTOOLS5}
with ParentControl as TWPCustomRtfEdit do
{$ELSE}
with ParentControl as TWPCustomRichText do //JZ TWPCustomRtfEdit do
{$ENDIF}
begin
Result := Spell_GetNextWord;
if (Result <> '') then
begin
// modified by Julian Ziersch
StrPLCopy(Buffer, Result, 255);
ANSItoOEM(Buffer, Buffer);
Result := StrPas(Buffer);
end;
AllNumbers := TRUE;
i := 1;
while (i <= Length(Result)) and AllNumbers do
begin
AllNumbers := AllNumbers and (Result[i] in NumberSet);
Inc(i);
end; { while }
end; { if... }
end; { TWPBuf.GetNextWord }
// returns the current word
function TWPBuf.GetCurrentWord(AControl: TControl): string;
begin
ParentControl := AControl;
{$IFDEF WPTOOLS5}
with ParentControl as TWPCustomRtfEdit do
{$ELSE}
with ParentControl as TWPCustomRichText do //JZ TWPCustomRtfEdit do
{$ENDIF}
begin
if (CPPosition > 0) and (
{$IFDEF WPTOOLS5}CPChar{$ELSE}Char(CPChar^){$ENDIF}
in ValidChars) then
// current character is valid
// check to see if previous character is valid
MoveBackOneWord;
Spell_FromCursorPos;
end; { with }
Result := GetNextWord;
end; { TWPBuf.GetCurrentWord }
// updates the buffer from the ParentControl component, if any
procedure TWPBuf.UpdateBuffer;
begin
{do nothing}
end; { TWPBuf.UpdateBuffer }
// moves back to the beginning of the current word
procedure TWPBuf.MoveBackOneWord;
begin
with ParentControl as TWPCustomRtfEdit do
while (CPPosition > 0) and (
{$IFDEF WPTOOLS5}CPChar{$ELSE}Char(CPChar^){$ENDIF}
in ValidChars) do
CPPosition := CPPosition - 1;
end; { TWPBuf.MoveBackOneWord }
// replaces the current word with the word provided
procedure TWPBuf.ReplaceWord(WithWord: string);
{$IFDEF WPTOOLS5}
begin
( ParentControl as TWPCustomRtfEdit).InputString(WithWord);
WeModified := TRUE;
end;
{$ELSE}
var
InsertAttr: TAttr;
InsertWord: string[255];
begin
InsertWord := WithWord + #0;
with ParentControl as TWPCustomRtfEdit do
begin
InsertAttr := Attr;
ClearSelection;
InsertTextAtCP(@InsertWord[1], @InsertAttr);
Refresh;
end; { with }
WeModified := TRUE;
end; { TWPBuf.ReplaceWord }
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -