home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
dos
/
prg
/
pas
/
ktools
/
source
/
swagread.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-11-17
|
8KB
|
329 lines
Program SwagRead;
{ lecture de fichiers SWAG; utilisation de l'objet TSwagFile et des
unités de fenêtrage }
{ KB mai-juin 1994 }
{.$DEFINE debug}
{$IFDEF debug}
{$A+,B-,D+,E-,F-,I+,L+,N-,R+,S+,V-,W+,X+}
{$ELSE}
{$A+,B-,D-,E-,F-,I+,L-,N-,R-,S-,V-,W+,X+}
{$ENDIF}
Uses Dos,
UMem,UDrivers,
OTableau,OFSwag,
OGenView,OTxtView,ODialWin,OHelpWin;
Const
cmInit=$200;
cmAbout=$201;
cmHelp=$202;
Type
PSwagSelWin=^TSwagSelWin;
TSwagSelWin=object(TSelWin)
SwagFile:PSwagFile;
Constructor Init(SwagFileName:PathStr);
Destructor Done; virtual;
Function GetErrorMsg:String; virtual;
Function NombreItems:Integer; virtual;
Function Ligne(n:Integer):String; virtual;
Procedure HandleEvent(Var Event:TEvent); virtual;
end;
PSwagTextWin=^TSwagTextWin;
TSwagTextWin=object(TWindow)
Data : PStrTab;
L1,C1:Integer;
Constructor Init(f:PSwagFile;num:Integer);
Destructor Done;virtual;
Procedure DrawInterior;virtual;
Procedure Bouger(dx,dy:Integer);
Procedure HandleEvent(Var Event:TEvent);virtual;
End;
PSwagApp=^TSwagApp;
TSwagApp=object(TTextApp)
Constructor Init;
Procedure InitStatusLine;virtual;
Procedure MakeSelWin(SwagFileName:PathStr);
Procedure HandleEvent(Var Event:TEvent);virtual;
End;
Var MonApp:PSwagApp;
{ objet TSwagSelWin }
Constructor TSwagSelWin.Init(SwagFileName:PathStr);
Var D:DirStr;
N:NameStr;
E:NameStr;
Begin
FSplit(SwagFileName,D,N,E);
TSelWin.Init(1,2,27,20,N+E);
SwagFile:=New(PSwagFile,Init(SwagFileName));
Ident:='SWAGSEL';
PalOffSet:=pCyan;
if not SwagFile^.IsValid
then ErrorFlag:=erInitFile;
End;
Destructor TSwagSelWin.Done;
Begin
dispose(SwagFile,Done);
TSelWin.Done;
End;
Function TSwagSelWin.GetErrorMsg:String;
Begin
if ErrorFlag=erInitFile
then GetErrorMsg:=SwagFile^.GetErrorMsg
else GetErrorMsg:=TSelWin.GetErrorMsg;
End;
Function TSwagSelWin.NombreItems:Integer;
Begin
NombreItems:=SwagFile^.MsgTab.NombreItems;
End;
Function TSwagSelWin.Ligne(n:Integer):String;
Var S:String;
MR:TMsgRec;
Begin
if (n<1) or (n>NombreItems)
then S:=''
else begin
SwagFile^.MsgTab.Lire(MR,n);
S:=MR.Sujet;
end;
Ligne:=S;
End;
Procedure TSwagSelWin.HandleEvent(Var Event:TEvent);
Var E:TEvent;
W:PSwagTextWin;
Begin
TSelWin.HandleEvent(Event);
if ExitCode=exOk
then begin
ExitCode:=0;
W:=New(PSwagTextWin,Init(SwagFile,Choix));
if not W^.IsValid
then begin
Message(W^.GetErrorMsg);
dispose(W,Done);
end
else begin
Application^.Insert(W);
W^.Show;
end;
end;
End;
{ objet TSwagTextWin }
Constructor TSwagTextWin.Init(f:PSwagFile;num:Integer);
Var MR:TMsgRec;
Begin
TWindow.Init(1,2,78,21,'');
Ident:='SWAGTEXT';
L1:=1;
C1:=1;
f^.MsgTab.Lire(MR,num);
Titre:=MR.Sujet;
while Titre[length(Titre)]=' ' do dec(Titre[0]);
Titre:=' '+Titre+' ';
Data:=f^.ReadMsg(num);
End;
Destructor TSwagTextWin.Done;
Begin
if Data<>nil
then dispose(Data,Done);
TWindow.Done;
End;
Procedure TSwagTextWin.DrawInterior;
Var S:String;
i:Byte;
Begin
For i:=1 to Hauteur do
begin
if L1+i-1>Data^.NombreItems
then S:=''
else S:=Data^.Ligne(L1+i-1);
if C1>1
then if length(S)>C1
then begin
move(S[C1],S[1],length(S)-C1+1);
S[0]:=chr(length(S)-C1+1);
end
else S:='';
Ajuste(S,largeur);
Ecrire(S,1,i,0);
end;
End;
Procedure TSwagTextWin.Bouger(dx,dy:Integer);
Begin
C1:=C1+dx;
if C1<1
then C1:=1
else if C1>255
then C1:=255;
L1:=L1+dy;
if L1<1
then L1:=1
else if L1>Data^.NombreItems
then L1:=Data^.NombreItems;
End;
Procedure TSwagTextWin.HandleEvent(Var Event:TEvent);
Begin
TWindow.HandleEvent(Event);
case Event.What of
evMouseAuto:
begin
if Event.LButton and SurCadre(Event.Where)
then begin
if Event.Where.Y>Origin.Y+hauteur div 2
then Bouger(0,1)
else Bouger(0,-1);
end
else exit;
end;
evKeyDown:
case Event.KeyCode of
CsUp: Bouger(0,-1);
PgUp: Bouger(0,-Hauteur);
CsDn: Bouger(0,1);
PgDn: Bouger(0,Hauteur);
CPgUp: L1:=1;
CPgDn: L1:=Data^.NombreItems-Hauteur;
CsLf: Bouger(-1,0);
CsRg: Bouger(1,0);
Home: C1:=1;
else exit;
end;
else exit;
end;
Event.What:=evNothing;
DrawInterior;
End;
{ objet TSwagApp }
Constructor TSwagApp.Init;
Begin
TTextApp.Init;
Titre:='Visualisateur de fichiers SWAG (K.B. 1994)';
if paramcount>0
then SetCommand(cmInit);
End;
Procedure TSwagApp.InitStatusLine;
Begin
TTextApp.InitStatusLine;
StatusLine^.AjouterItem('F1 Aide',F1);
StatusLine^.AjouterItem('F2 Fichier',F2);
StatusLine^.AjouterItem('AltX Quitter',AltX);
End;
Procedure TSwagApp.MakeSelWin(SwagFileName:PathStr);
Var SelWin : PSwagSelWin;
Begin
if SwagFileName=''
then exit;
Patience('Chargement en cours ...');
SelWin:=New(PSWagSelWin,Init(SwagFileName));
FinPatience;
if SelWin^.IsValid
then begin
Insert(SelWin);
SelWin^.Show;
end
else begin
Message(SelWin^.GetErrorMsg);
dispose(SelWin,Done);
end;
End;
Procedure TSwagApp.HandleEvent(Var Event:TEvent);
Var S:String;
H:PHelpWin;
CurWin:PGenView;
Begin
TTextApp.HandleEvent(Event);
case Event.What of
evCommand:
case Event.Command of
cmInit: MakeSelWin(ParamStr(1));
cmAbout:
Message(chr(13)+
' S W A G R E A D '+chr(13)+
' Kostrzewa Bruno '+chr(13)+
' (novembre 1994) '+chr(13));
cmHelp:
begin
H:=New(PHelpWin,Init(AppPath+'SWAGREAD.HLP'));
if not H^.IsValid
then Message(H^.GetErrorMsg)
else begin
H^.Ident:='AIDE';
Insert(H);
H^.Exec;
end;
dispose(H,Done);
end;
else exit;
end;
evKeyDown:
case Event.KeyCode of
AltS:
begin
CurWin:=FindSelect;
if (CurWin<>nil) and (CurWin^.Ident='SWAGTEXT')
then begin
WinRead(S,' Sauver sous ');
if S<>''
then begin
Patience('Sauvegarde en cours...');
PSwagTextWin(CurWin)^.Data^.Save(S);
FinPatience;
end;
end
else Message('Rien à sauver ! ');
end;
F1: SetCommand(cmHelp);
F2: begin
S:=GetFile('*.SWG');
if S<>''
then begin
ClearDeskTop;
MakeSelWin(S);
end;
end;
F3: SetCommand(cmAbout);
else exit;
end;
else exit;
end;
Event.What:=evNothing;
End;
BEGIN
{$ifdef debug}
initmem;
{$endif}
MonApp:=New(PSwagApp,Init);
MonApp^.Exec;
dispose(MonApp,Done);
{$ifdef debug}
diagmem;
{$endif}
END.
{ Fin du fichier SWAGREAD.PAS }