home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
program8
/
spellwnd.pa$
/
spellwnd.pas
Wrap
Pascal/Delphi Source File
|
1993-07-23
|
22KB
|
742 lines
{*******************************************************}
{ }
{ Turbo Pascal for Windows }
{ Standard windows unit for ObjectWindows }
{ }
{ Copyright (c) 1991 Borland International }
{ }
{=======================================================}
{ Modifications to allows Spell Checker }
{ SpelMate DLL to be accesses. }
{ Copyright (c) 1993 Aciran Software systems }
{*******************************************************}
unit SpellWnds;
{$R SpellWNDS.RES}
interface
uses WinTypes, WinProcs, WinDos, Objects, OWindows, ODialogs,
OMemory, OStdDlgs, Strings,Win31;
const
cm_spell = 101;
MaxWordLen = 20;
{create function prototypes}
type
TSpelmateInit = function :integer;
TSpellCheck = function (AWord:Pchar):BOOL;
TSuggestWord = function(AWord:PChar):PChar;
TDisplayAtTop = procedure;
{create a new edit type so we can get a handle direct to its text buffer
for faster scanning}
type
PNewEdit = ^TNewEdit;
TNewEdit = object(TEdit)
function GetHandle:word;
end;
type
{ TSearchRec }
TSearchRec = record
SearchText: array[0..80] of Char;
CaseSensitive: Bool;
ReplaceText: array[0..80] of Char;
ReplaceAll: Bool;
PromptOnReplace: Bool;
IsReplace: Boolean;
end;
{ TEditWindow }
PEditWindow = ^TEditWindow;
TEditWindow = object(TWindow)
Editor: PNewEdit;
SearchRec: TSearchRec;
constructor Init(AParent: PWindowsObject; ATitle: PChar);
constructor Load(var S: TStream);
procedure Store(var S: TStream);
procedure WMSize(var Msg: TMessage);
virtual wm_First + wm_Size;
procedure WMSetFocus(var Msg: TMessage);
virtual wm_First + wm_SetFocus;
procedure CMEditFind(var Msg: TMessage);
virtual cm_First + cm_EditFind;
procedure CMEditFindNext(var Msg: TMessage);
virtual cm_First + cm_EditFindNext;
procedure CMEditReplace(var Msg: TMessage);
virtual cm_First + cm_EditReplace;
procedure CMSpell(var Msg: TMessage); {Spell check option added}
virtual cm_First + cm_Spell;
private
procedure DoSearch;
end;
{ TFileWindow }
PFileWindow = ^TFileWindow;
TFileWindow = object(TEditWindow)
FileName: PChar;
IsNewFile: Boolean;
constructor Init(AParent: PWindowsObject; ATitle, AFileName: PChar);
destructor Done; virtual;
constructor Load(var S: TStream);
procedure Store(var S: TStream);
function CanClear: Boolean; virtual;
function CanClose: Boolean; virtual;
procedure NewFile;
procedure Open;
procedure Read;
procedure SetFileName(AFileName: PChar);
procedure ReplaceWith(AFileName: PChar);
function Save: Boolean;
function SaveAs: Boolean;
procedure SetupWindow; virtual;
procedure Write;
procedure CMFileNew(var Msg: TMessage);
virtual cm_First + cm_FileNew;
procedure CMFileOpen(var Msg: TMessage);
virtual cm_First + cm_FileOpen;
procedure CMFileSave(var Msg: TMessage);
virtual cm_First + cm_FileSave;
procedure CMFileSaveAs(var Msg: TMessage);
virtual cm_First + cm_FileSaveAs;
end;
const
REditWindow: TStreamRec = (
ObjType: 80;
VmtLink: Ofs(TypeOf(TEditWindow)^);
Load: @TEditWindow.Load;
Store: @TEditWindow.Store);
const
RFileWindow: TStreamRec = (
ObjType: 81;
VmtLink: Ofs(TypeOf(TFileWindow)^);
Load: @TFileWindow.Load;
Store: @TFileWindow.Store);
procedure RegisterStdWnds;
implementation
{make instances of the functions from our prototypes}
var
SpelmateInit : TSpelmateInit;
SpellCheck : TSpellCheck;
SuggestWord : TSuggestWord;
DisplayAtTop : TDisplayAtTop;
{ TSearchDialog }
const
sd_Search = MakeIntResource($7F10);
sd_Replace = MakeIntResource($7F11);
sd_BCSearch = MakeIntResource($7F12);
sd_BCReplace = MakeIntResource($7F13);
id_SearchText = 100;
id_CaseSensitive = 101;
id_ReplaceText = 102;
id_ReplaceAll = 103;
id_PromptOnReplace = 104;
type
PSearchDialog = ^TSearchDialog;
TSearchDialog = object(TDialog)
constructor Init(AParent: PWindowsObject; Template: PChar;
var SearchRec: TSearchRec);
end;
constructor TSearchDialog.Init(AParent: PWindowsObject; Template: PChar;
var SearchRec: TSearchRec);
var
C: PWindowsObject;
begin
TDialog.Init(AParent, Template);
C := New(PEdit, InitResource(@Self, id_SearchText,
SizeOf(SearchRec.SearchText)));
C := New(PCheckBox, InitResource(@Self, id_CaseSensitive));
if (Template = sd_Replace) or (Template = sd_BCReplace) then
begin
C := New(PEdit, InitResource(@Self, id_ReplaceText,
SizeOf(SearchRec.ReplaceText)));
C := New(PCheckBox, InitResource(@Self, id_ReplaceAll));
C := New(PCheckBox, InitResource(@Self, id_PromptOnReplace));
end;
TransferBuffer := @SearchRec;
end;
function TNewEdit.GetHandle;
begin
GetHandle := SendMessage(HWindow,EM_GETHANDLE,0,LongInt(0));
end;
{ TEditWindow }
{ Constructor for a TEditWindow. Initializes its data fields using passed
parameters and default values. Constructs its child edit control. }
constructor TEditWindow.Init(AParent: PWindowsObject; ATitle: PChar);
begin
TWindow.Init(AParent, ATitle);
{NOTE: we use our new edit type here}
Editor := New(PNewEdit, Init(@Self, 200, nil, 0, 0, 0, 0, 0, True));
with Editor^.Attr do
Style := Style or es_NoHideSel;
FillChar(SearchRec, SizeOf(SearchRec), #0);
end;
{ Load a TEditWindow from the given stream }
constructor TEditWindow.Load(var S: TStream);
begin
TWindow.Load(S);
GetChildPtr(S, Editor);
end;
{ Store a TEditWindow to the given stream }
procedure TEditWindow.Store(var S: TStream);
begin
TWindow.Store(S);
PutChildPtr(S, Editor);
end;
{ Responds to an incoming wm_Size message by resizing the child edit
control according to the size of the TEditWindow's client area. }
procedure TEditWindow.WMSize(var Msg: TMessage);
begin
TWindow.WMSize(Msg);
SetWindowPos(Editor^.HWindow, 0, -1, -1, Msg.LParamLo+2, Msg.LParamHi+2,
swp_NoZOrder);
end;
{ Responds to an incoming wm_SetFocus message by setting the focus to the
child edit control. }
procedure TEditWindow.WMSetFocus(var Msg: TMessage);
begin
SetFocus(Editor^.HWindow);
end;
procedure TEditWindow.DoSearch;
var
S: array[0..80] of Char;
P: Pointer;
Rslt: Integer;
begin
Rslt := 0;
with SearchRec do
repeat
Rslt := Editor^.Search(-1, SearchText, CaseSensitive);
if Rslt = -1 then
begin
if not IsReplace or not ReplaceAll then
begin
P := @SearchText;
WVSPrintF(S, '"%0.60s" not found.', P);
MessageBox(HWindow, S, 'Find error', mb_OK + mb_IconExclamation);
end;
end
else
if IsReplace then
if not PromptOnReplace then Editor^.Insert(ReplaceText)
else
begin
Rslt := MessageBox(HWindow, 'Replace this occurrence?',
'Search/Replace', mb_YesNoCancel + mb_IconQuestion);
if Rslt = id_Yes then Editor^.Insert(ReplaceText)
else if Rslt = id_Cancel then Exit;
end;
until (Rslt = -1) or not ReplaceAll or not IsReplace;
end;
procedure TEditWindow.CMEditFind(var Msg: TMessage);
var
Dialog: PChar;
begin
if BWCCClassNames then
Dialog := sd_BCSearch
else
Dialog := sd_Search;
if Application^.ExecDialog(New(PSearchDialog, Init(@Self,
Dialog, SearchRec))) = id_OK then
begin
SearchRec.IsReplace := False;
DoSearch;
end;
end;
procedure TEditWindow.CMEditFindNext(var Msg: TMessage);
begin
DoSearch;
end;
procedure TEditWindow.CMEditReplace(var Msg: TMessage);
var
Dialog: PChar;
begin
if BWCCClassName