home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 17
/
CD_ASCQ_17_101194.iso
/
vrac
/
ptgenr2.zip
/
SAMPLE.ARJ
/
PREAPP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-20
|
9KB
|
345 lines
{ Created : 1991-09-05
Functions and procedures used by the PtGen created application
$Author: Berend_de_Boer $
$Date: 93/05/20 23:00:55 $
$Revision: 1.1 $
Last changes :
93-02-01 Made completely TV2.0 aware
93-03-06 Renamed to PREAPP.PAS
Internationalized by making use of string resources
}
{$I DEFINES.DEF}
{$F+,O+,X+,R-,Q-,S-,V-,D+}
unit PreApp;
interface
uses Objects, Drivers, Views, Menus,
{$IFDEF Editor}
Editors,
{$ENDIF}
{$IFDEF TVTool} {* you can only compile PreApp when TVTool *}
TVApp, {* is defined in DEFINES.DEF when you have *}
{$ENDIF} {* the TVTool pack of Richard Hansen *}
App;
{$IFDEF Editor}
const
hcEditor = 2700;
{$ENDIF}
type
PPreAppStatusLine = ^TPreAppStatusLine;
TPreAppStatusLine = object(TStatusLine)
function Hint(AHelpCtx : word) : string; virtual;
end;
PPreApp = ^TPreApp;
{$IFDEF TVTool}
TPreApp = object(TbxApplication)
{$ELSE}
TPreApp = object(TApplication)
{$ENDIF}
{$IFDEF Editor}
constructor Init;
{$ENDIF}
{$IFDEF BufferedPrinter}
procedure Idle; virtual;
{$ENDIF}
{$IFDEF Help}
procedure GetEvent(var Event: TEvent); virtual;
{$IFNDEF TVTool}
function GetPalette: PPalette; virtual;
{$ENDIF TVTool}
{$ENDIF Help}
procedure OutOfMemory; virtual;
end;
{$IFDEF Help}
var
HFileName : FNameStr;
{$ENDIF}
{$IFDEF Editor}
var
ClipWindow : PEditWindow;
function OpenEditor(FileName: FNameStr; Visible: Boolean) : PEditWindow;
{$ENDIF}
implementation
uses Dialogs,
{$IFDEF Editor}
StdDlg,
{$ENDIF}
{$IFDEF Help}
HelpFile,
{$ENDIF}
{$IFDEF BufferedPrinter}
BufPrinter,
{$ENDIF}
Dos, BBFile, BBUtil, BBDlg, BBStrRes;
{$I STRINGS.INC}
function TPreAppStatusLine.Hint(AHelpCtx : word) : string;
begin
Hint := Strings^.Get(AHelpCtx);
end;
{$IFDEF Editor}
function CreateFindDialog: PDialog;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 38, 12);
D := New(PDialog, Init(R, rsGet(seFind)));
with D^ do
begin
Options := Options or ofCentered;
R.Assign(3, 3, 32, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 2, 15, 3);
Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
R.Assign(32, 3, 35, 4);
Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
R.Assign(3, 5, 35, 7);
Insert(New(PCheckBoxes, Init(R,
NewSItem(rsGet(seCase),
NewSItem(rsGet(seWholeWords), nil)))));
R.Assign(14, 9, 24, 11);
Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
Inc(R.A.X, 12); Inc(R.B.X, 12);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
SelectNext(False);
end;
CreateFindDialog := D;
end;
function CreateReplaceDialog: PDialog;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 40, 16);
D := New(PDialog, Init(R, rsGet(seReplace)));
with D^ do
begin
Options := Options or ofCentered;
R.Assign(3, 3, 34, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 2, 15, 3);
Insert(New(PLabel, Init(R, rsGet(seTextToFind), Control)));
R.Assign(34, 3, 37, 4);
Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
R.Assign(3, 6, 34, 7);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 5, 12, 6);
Insert(New(PLabel, Init(R, rsGet(seNewText), Control)));
R.Assign(34, 6, 37, 7);
Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
R.Assign(3, 8, 37, 12);
Insert(New(PCheckBoxes, Init(R,
NewSItem(rsGet(seCase),
NewSItem(rsGet(seWholeWords),
NewSItem(rsGet(sePromptOnReplace),
NewSItem(rsGet(seReplaceAll), nil)))))));
R.Assign(17, 13, 27, 15);
Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
R.Assign(28, 13, 38, 15);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
SelectNext(False);
end;
CreateReplaceDialog := D;
end;
function DoEditDialog(Dialog: Integer; Info: Pointer): Word; far;
var
R: TRect;
T: TPoint;
begin
case Dialog of
edOutOfMemory:
DoEditDialog := MessageBox(rsGet(sMemory),
nil, mfError + mfOkButton, hcNoContext);
edReadError:
DoEditDialog := MessageBox(rsGet(seErrReading),
@Info, mfError + mfOkButton, hcNoContext);
edWriteError:
DoEditDialog := MessageBox(rsGet(seErrWriting),
@Info, mfError + mfOkButton, hcNoContext);
edCreateError:
DoEditDialog := MessageBox(rsGet(seErrCreating),
@Info, mfError + mfOkButton, hcNoContext);
edSaveModify:
DoEditDialog := MessageBox(rsGet(seSave),
@Info, mfInformation + mfYesNoCancel, hcNoContext);
edSaveUntitled:
DoEditDialog := MessageBox(rsGet(seSaveUntitled),
nil, mfInformation + mfYesNoCancel, hcNoContext);
edSaveAs:
DoEditDialog := ExecDialog(New(PFileDialog, Init('*.*',
rsGet(seSaveAs), rsGet(sName), fdOkButton, 101)), Info);
edFind:
DoEditDialog := ExecDialog(CreateFindDialog, Info);
edSearchFailed:
DoEditDialog := MessageBox(rsGet(seStringNotFound),
nil, mfError + mfOkButton, hcNoContext);
edReplace:
DoEditDialog := ExecDialog(CreateReplaceDialog, Info);
edReplacePrompt:
begin
{ Avoid placing the dialog on the same line as the cursor }
R.Assign(0, 1, 40, 8);
R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
Desktop^.MakeGlobal(R.B, T);
Inc(T.Y);
if TPoint(Info).Y <= T.Y then
R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
DoEditDialog := MessageBoxRect(R, rsGet(seReplaceThis),
nil, mfYesNoCancel + mfInformation, hcNoContext);
end;
end;
end;
function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
var
P: PView;
R: TRect;
begin
DeskTop^.GetExtent(R);
P := Application^.ValidView(New(PEditWindow,
Init(R, FileName, wnNoNumber)));
P^.HelpCtx := hcEditor;
if not Visible then P^.Hide;
DeskTop^.Insert(P);
OpenEditor := PEditWindow(P);
end;
constructor TPreApp.Init;
var
R: TRect;
begin
inherited Init;
DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
cmUndo, cmFind, cmReplace, cmSearchAgain]);
EditorDialog := DoEditDialog;
ClipWindow := OpenEditor('', False);
if ClipWindow <> nil then
begin
Clipboard := ClipWindow^.Editor;
Clipboard^.CanUndo := False;
end;
end;
{$ENDIF}
{$IFDEF Help}
procedure TPreApp.GetEvent(var Event: TEvent);
var
W: PWindow;
HFile: PHelpFile;
HelpStrm: PBufStream;
D : DirStr;
N : NameStr;
E : ExtStr;
FileName : string;
const
HelpInUse: Boolean = False;
begin
inherited GetEvent(Event);
case Event.What of
evCommand : if (Event.Command = cmHelp) and not HelpInUse then begin
HelpInUse := TRUE;
FSplit(ParamStr(0), D,N,E);
FileName := FSearch(HFileName, D+';'+GetEnv('PTGINPUT')+';'+GetEnv('PATH'));
if FileName = ''
then PrintError(rsGet1(sHelpFileNotFound, longint(@HFileName)), hcNoContext)
else begin
HelpStrm := New(PBufStream, Init(FileName, stOpenRead, 1024));
HFile := New(PHelpFile, Init(HelpStrm));
if HelpStrm^.Status <> stOk
then begin
PrintError(rsGet1(word(HelpStrm^.Status), longint(@HFileName)), hcNoContext);
Dispose(HFile, Done);
end
else begin
W := New(PHelpWindow,Init(HFile, GetHelpCtx));
if ValidView(W) <> nil then begin
ExecView(W);
Dispose(W, Done);
end;
ClearEvent(Event);
end;
end;
HelpInUse := FALSE;
end;
{$IFNDEF TVToool}
(*
evKeyDown : HideMouse;
evMouseMove, evMouseUp, evMouseDown : ShowMouse;
*)
{$ENDIF}
end; { of case }
end;
{$IFNDEF TVTool}
function TPreApp.GetPalette: PPalette;
const
CNewColor = CAppColor + CHelpColor;
CNewBlackWhite = CAppBlackWhite + CHelpBlackWhite;
CNewMonochrome = CAppMonochrome + CHelpMonochrome;
P: array[apColor..apMonochrome] of string[Length(CNewColor)] =
(CNewColor, CNewBlackWhite, CNewMonochrome);
begin
GetPalette := @P[AppPalette];
end;
{$ENDIF TVTool}
{$ENDIF Help}
{$IFDEF BufferedPrinter}
procedure TPreApp.Idle;
begin
inherited Idle;
if StandardPrinter <> nil then StandardPrinter^.PrintFromBuffer;
end;
{$ENDIF}
procedure TPreApp.OutOfMemory;
begin
PrintError(rsGet(sMemory), hcNoContext);
end;
end. { of unit PreApp }