home *** CD-ROM | disk | FTP | other *** search
- {*
- *
- * Copyright (c) 1992 by Richard W. Hansen
- *
- * This source code will compile.
- * Unpacked source is available to registered users.
- *
- *}
- UNIT TvDialog;{$X+}{$V-}{$I TVDEFS.INC}INTERFACE USES Dos,TvColl,TvConst,TvString,TvType,TvViews,{$IFDEF TVSCROLL}TvScroll,
- {$ENDIF}App,Dialogs,Drivers,Memory,MsgBox,Objects,StdDlg,Views;CONST C3DButton=#37#41#38#39#40#42;
- C3DDialog=CDialog+#72#73#74#75#76#77#78#79#80#81#82#83#84#85#86#87;C3DOutline=#43#44;C3DListViewer=#48#48#49#50#51;
- BarChar:Char='▒';BarFillChar:Char='█';ButtonSelect:FrameArray='╔╗╚╝║║══';ButtonNormal1:FrameArray='┌┐└┘││──';
- ButtonNormal2:FrameArray='┌╖╘╝│║─═';ButtonPress:FrameArray='┌┐└┘││──';BorderNormal:FrameArray='╔╗╚╝║║══';
- Buttons:Array[0..3]of String[8]=('~Y~es','~N~o','O~K~','~C~ancel');Commands:Array[0..3]of Word=(cmYes,cmNo,cmOK,cmCancel);
- Titles:Array[0..3]of String[11]=('Warning','Error','Information','Confirm');mfMessageLine=$1000;mfPauseButton=$2000;
- mfPauseCancel=mfPauseButton+mfCancelButton;mfOKPauseCancel=mfOKCancel+mfPauseButton;TYPE PSearchRec=^TSearchRec;
- DriveLetters='A'..'Z';DriveSet=Set of DriveLetters;TYPE PRunDialog=^TRunDialog;TRunDialog=Object(TDialog)Msg:PStaticText;
- RunState:Word;pfFlags:Word;BtnRow:Byte;SButton:PButton;CButton:PButton;Constructor Init(var Bounds:TRect;ATitle:TTitleStr;
- AMessage:String;AOptions:Word;ButtonRow:Byte);Function Execute:Word;Virtual;Procedure HandleEvent(var Event:TEvent);Virtual;
- Procedure Process;Virtual;Procedure ChangeMessage(AMessage:String);end;PPercentDialog=^TPercentDialog;
- TPercentDialog=Object(TRunDialog)Total:LongInt;Count:LongInt;Step:Word;Pct:PStaticText;Bar:PStaticText;
- Constructor Init(ATitle:TTitleStr;AMessage:String;ATotal:LongInt;AOptions:Word );Procedure Increment;
- Procedure IncrementBy(AStep:Word);end;PPrintDialog=^TPrintDialog;TPrintDialog=Object(TRunDialog)
- Constructor Init(ATitle:TTitleStr;AMessage:String;AOptions:Word );end;PMessageDialog=^TMessageDialog;
- TMessageDialog=Object(TDialog)SList:TUnsortedStringCollection;DOptions:Word;Constructor Init(AOptions:Word);
- Procedure AddMessage(St:String);Function Process:Word;Destructor Done;Virtual;end;{$IFDEF NEW_FILE_DIALOG}
- PNewFileCollection=^TNewFileCollection;TNewFileCollection=object(TFileCollection)
- Function Compare(Key1,Key2:Pointer):Integer;Virtual;end;PNewFileList=^TNewFileList;TNewFileList=object(TFileList)
- Constructor Init(var Bounds:TRect;AWildCard:PathStr;AScrollBar:PScrollBar);Procedure HandleEvent(var Event:TEvent);Virtual;
- Procedure FocusItem(Item:Integer);Virtual;Procedure ReadDirectory(AWildCard:PathStr);Virtual;end;PDriveList=^TDriveList;
- TDriveList=object(TNewFileList)Constructor Init(var Bounds:TRect;AScrollBar:PScrollBar);
- Procedure GetDrives(var Drives:DriveSet);Procedure ReadDirectory(AWildCard:PathStr);Virtual;
- Function GetKey(var S:String):Pointer;Virtual;end;PNewFileInputLine=^TNewFileInputLine;
- TNewFileInputLine=object(TFileInputLine)Procedure HandleEvent(var Event:TEvent);Virtual;end;
- PNewFileInfoPane=^TNewFileInfoPane;TNewFileInfoPane=object(TFileInfoPane)Procedure Draw;Virtual;end;
- PDirectoryInfoPane=^TDirectoryInfoPane;TDirectoryInfoPane=object(TView)Constructor Init(var Bounds:TRect);
- Function GetPalette:PPalette;Virtual;Procedure HandleEvent(var Event:TEvent);Virtual;Procedure Draw;Virtual;end;
- PNewFileDialog=^TNewFileDialog;TNewFileDialog=object(TFileDialog)DriveList:PDriveList;Constructor Init(AWildCard:TWildStr;
- ATitle:String;InputName:String;AOptions:Word;HistoryId:Byte);end;{$ENDIF}PLinkedInputLine=^TLinkedInputLine;
- TLinkedInputLine=Object(TInputLine)LinkEvent:Word;Constructor Init(var Bounds:TRect;AMaxLen:Integer;EventCode:Word);
- Procedure HandleEvent(var Event:TEvent);Virtual;end;PLinkedListBox=^TLinkedListBox;TLinkedListBox=object(TListBox)
- LinkEvent:Word;Constructor Init(var Bounds:TRect;ANumCols:Word;AScrollBar:PScrollBar;EventCode:Word);
- Procedure FocusItem(Item:Integer);virtual;end;P3DButton=^T3DButton;T3DButton=Object(TButton)Down:Boolean;
- Constructor Init(var Bounds:TRect;ATitle:TTitleStr;ACommand:Word;AFlags:Word);Procedure Draw;Virtual;
- Procedure HandleEvent(var Event:TEvent);Virtual;Procedure DrawTitle(ATitle:TTitleStr;Color:Word;Row:Word);
- Function GetPalette:PPalette;Virtual;Procedure GetFrame(var F:FrameArray);Virtual;end;PToolButton=^TToolButton;
- TToolButton=Object(T3DButton)Procedure GetFrame(var F:FrameArray);Virtual;end;P3DDialog=^T3DDialog;T3DDialog=Object(TDialog)
- Procedure InitFrame;Virtual;Function GetPalette:PPalette;Virtual;end;P3DOutline=^T3DOutline;T3DOutline=Object(TView)
- Constructor Init(var Bounds:TRect);Procedure Draw;Virtual;Function GetPalette:PPalette;Virtual;
- Procedure GetFrame(var F:FrameArray);Virtual;end;PToolBar=^TToolBar;TToolBar=Object(T3DDialog)IsVertical:Boolean;LastX:Word;
- LastY:Word;Constructor Init(var Bounds:TRect;Vertical:Boolean);Procedure AddTool(ATitle:TTitleStr;ACommand:Word);
- Procedure SizeLimits(var Min,Max:TPoint);Virtual;Procedure InitFrame;Virtual;end;P3DListViewer=^T3DListViewer;
- T3DListViewer=Object(TView)Function GetPalette:PPalette;Virtual;end;IMPLEMENTATION
- Function T3DListViewer.GetPalette:PPalette;Const P:String[Length(C3DListViewer)]=C3DListViewer;begin GetPalette:=@P;end;
- Constructor T3DOutline.Init(var Bounds:TRect);var R:TRect;begin R:=Bounds;R.Grow(1,1);TView.Init(R);end;
- Function T3DOutline.GetPalette:PPalette;Const P:String[Length(C3DOutline)]=C3DOutline;begin GetPalette:=@P;end;
- Procedure T3DOutline.GetFrame(var F:FrameArray);begin F:=BorderNormal;end;Procedure T3DOutline.Draw;var Chars:FrameArray;
- CBorder:Word;X:Word;Y:Word;B:TDrawBuffer;begin GetFrame(Chars);CBorder:=GetColor($0102);X:=Size.X-1;
- MoveChar(B,Chars[7],WordRec(CBorder).Lo,Size.X);WordRec(B[X]).Hi:=WordRec(CBorder).Hi;WordRec(B[0]).Lo:=Byte(Chars[1]);
- WordRec(B[X]).Lo:=Byte(Chars[2]);WriteLine(0,0,Size.X,1,B);MoveChar(B,Chars[8],WordRec(CBorder).Hi,Size.X);
- WordRec(B[0]).Hi:=WordRec(CBorder).Lo;WordRec(B[0]).Lo:=Byte(Chars[3]);WordRec(B[X]).Lo:=Byte(Chars[4]);
- WriteLine(0,Size.Y-1,Size.X,1,B);for Y:=1 to Size.Y-2 do begin WriteChar(0,Y,Chars[5],2,1);WriteChar(X,Y,Chars[6],1,1);end;
- end;Procedure T3DDialog.InitFrame;var R:TRect;begin GetExtent(R);Frame:=New(P3DFrame,Init(R));end;
- Function T3DDialog.GetPalette:PPalette;Const P:String[Length(C3DDialog)]=C3DDialog;begin GetPalette:=@P;end;
- Constructor TToolBar.Init(var Bounds:TRect;Vertical:Boolean);var R:TRect;P:PView;begin TDialog.Init(Bounds,'');
- IsVertical:=Vertical;SetState(sfShadow,False);Options:=Options and not ofTileable and not ofSelectable or ofFirstClick;
- Flags:=Flags and not wfClose;GetExtent(R);if(Frame<>nil)then begin LastX:=1;LastY:=1;R.Grow(-1,-1);end else begin LastX:=0;
- LastY:=0;end;P:=New(PView,Init(R));P^.SetState(sfDisabled,True);P^.Options:=P^.Options and not ofSelectable;
- P^.GrowMode:=P^.GrowMode or gfGrowHiX OR gfGrowHiY;Insert(P);end;Procedure TToolBar.AddTool(ATitle:TTitleStr;ACommand:Word);
- var R:TRect;B:TRect;Len:Word;Cols:Word;Rows:Word;MPos:Word;DX:Word;DY:Word;Width:Word;Height:Word;Btn:PToolButton;begin
- MPos:=Pos(^M,ATitle);if(MPos=0)then begin Rows:=3;Cols:=CStrLen(ATitle);end else begin Rows:=4;
- Cols:=CStrLen(Copy(ATitle,1,MPos-1));Len:=CStrLen(Copy(ATitle,MPos+1,Length(ATitle)));if(Len>Cols)then Cols:=Len;end;
- Cols:=Cols+2;R.A.X:=LastX;R.A.Y:=LastY;R.B.X:=R.A.X+Cols;R.B.Y:=R.A.Y+Rows;Width:=Size.X;Height:=Size.Y;if(Frame<>nil)then
- begin Dec(Width);Dec(Height);end;if(R.B.Y>Height)then DY:=R.B.Y-Height else DY:=0;if(R.B.X>Width)then DX:=R.B.X-Width else
- DX:=0;GetBounds(B);if(DY<>0)then begin B.B.Y:=B.B.Y+DY;if(B.B.Y>Desktop^.Size.Y)then EXIT;end;if(DX<>0)then begin
- B.B.X:=B.B.X+DX;if(B.B.X>Desktop^.Size.X)then EXIT;end;if(DX<>0)or(DY<>0)then if(State and sfVisible<>0)then ChangeBounds(B)
- else SetBounds(B);Btn:=New(PToolButton,Init(R,ATitle,ACommand,0));Insert(Btn);if IsVertical then LastY:=R.B.Y else
- LastX:=R.B.X;end;Procedure TToolBar.SizeLimits(var Min,Max:TPoint);begin Min:=Size;Max:=Size;end;
- Procedure TToolBar.InitFrame;begin Frame:=nil;end;Constructor T3DButton.Init(var Bounds:TRect;ATitle:TTitleStr;ACommand:Word;
- AFlags:Word);begin TButton.Init(Bounds,ATitle,ACommand,AFlags);Down:=False;end;Procedure T3DButton.Draw;var Chars:FrameArray;
- Y:Word;X:Word;CBorder:Word;CText:Word;B:TDrawBuffer;begin GetFrame(Chars);if(State and sfDisabled<>0)then
- CText:=GetColor($0404)else if(State and sfSelected=0)and AmDefault then CText:=GetColor($0506)else CText:=GetColor($0503);
- if Down then CBorder:=GetColor($0201)else CBorder:=GetColor($0102);X:=Size.X-1;
- MoveChar(B,Chars[7],WordRec(CBorder).Hi,Size.X);WordRec(B[X]).Hi:=WordRec(CBorder).Lo;WordRec(B[0]).Lo:=Byte(Chars[1]);
- WordRec(B[X]).Lo:=Byte(Chars[2]);WriteLine(0,0,Size.X,1,B);MoveChar(B,Chars[8],WordRec(CBorder).Lo,Size.X);
- WordRec(B[0]).Hi:=WordRec(CBorder).Hi;WordRec(B[0]).Lo:=Byte(Chars[3]);WordRec(B[X]).Lo:=Byte(Chars[4]);
- WriteLine(0,Size.Y-1,Size.X,1,B);MoveChar(B,' ',WordRec(CBorder).Hi,Size.X);WordRec(B[0]).Lo:=Byte(Chars[5]);
- WordRec(B[X]).Lo:=Byte(Chars[6]);WordRec(B[X]).Hi:=WordRec(CBorder).Lo;for Y:=1 to Size.Y-2 do WriteLine(0,Y,Size.X,1,B);
- X:=Pos(^M,Title^);if(X=0)then Y:=Size.Y div 2 else Y:=(Size.Y-1)div 2;if(X=0)then DrawTitle(Title^,CText,Y)else begin
- DrawTitle(Copy(Title^,1,X-1),CText,Y);DrawTitle(Copy(Title^,X+1,Length(Title^)),CText,Y+1);end;end;
- Procedure T3DButton.DrawTitle(ATitle:TTitleStr;Color:Word;Row:Word);var X:Word;L:Word;B:TDrawBuffer;begin L:=Size.X-2;
- if(Flags and bfLeftJust<>0)then X:=0 else X:=(L-CStrLen(ATitle))div 2;MoveChar(B,' ',WordRec(Color).Lo,L);
- MoveCStr(B[X],ATitle,Color);WriteLine(1,Row,L,1,B);end;Procedure T3DButton.HandleEvent(var Event:TEvent);var R:TRect;
- P:TPoint;begin GetExtent(R);if(Event.What=evMouseDown)then begin MakeLocal(Event.Where,P);if not R.Contains(P)then
- ClearEvent(Event);TView.HandleEvent(Event);if(Event.What=evMouseDown)then begin Down:=False;Repeat MakeLocal(Event.Where,P);
- if(Down<>R.Contains(P))then begin Down:=not Down;Draw;end;Until not MouseEvent(Event,evMouseMove);if Down then begin
- Down:=False;Press;Draw;end;ClearEvent(Event);end;end;TButton.HandleEvent(Event);end;Function T3DButton.GetPalette:PPalette;
- Const P:String[Length(C3DButton)]=C3DButton;begin GetPalette:=@P;end;Procedure T3DButton.GetFrame(var F:FrameArray);begin
- if Down then F:=ButtonPress else if(State and sfSelected<>0)then F:=ButtonSelect else F:=ButtonNormal1;end;
- Procedure TToolButton.GetFrame(var F:FrameArray);begin if Down then F:=ButtonPress else F:=ButtonNormal1;end;
- Constructor TLinkedListBox.Init(var Bounds:TRect;ANumCols:Word;AScrollBar:PScrollBar;EventCode:Word);begin
- TListBox.Init(Bounds,ANumCols,AScrollBar);LinkEvent:=EventCode;end;Procedure TLinkedListBox.FocusItem(Item:Integer);begin
- TListBox.FocusItem(Item);Message(Owner,evBroadcast,LinkEvent,List^.At(Item));end;
- Constructor TLinkedInputLine.Init(var Bounds:TRect;AMaxLen:Integer;EventCode:Word);begin TInputLine.Init(Bounds,AMaxLen);
- LinkEvent:=EventCode;EventMask:=EventMask or evBroadcast;end;Procedure TLinkedInputLine.HandleEvent(var Event:TEvent);begin
- TInputLine.HandleEvent(Event);if(Event.What=evBroadcast)and(Event.Command=LinkEvent)and (State and sfSelected=0)then begin
- Data^:=PString(Event.InfoPtr)^;DrawView;end;end;Constructor TRunDialog.Init(var Bounds:TRect;ATitle:TTitleStr;
- AMessage:String;AOptions:Word;ButtonRow:Byte);var R:TRect;begin TDialog.Init(Bounds,ATitle);pfFlags:=AOptions;
- Flags:=Flags AND NOT wfClose;BtnRow:=ButtonRow;RunState:=0;if((pfFlags AND mfMessageLine)<>0)then begin R.Assign(2,1,42,2);
- Msg:=New(PStaticText,Init(R,AMessage));Insert(Msg);end;if((pfFlags AND mfOKCancel)=mfOKCancel)then begin
- R.Assign(11,BtnRow,20,BtnRow+2);SButton:=New(PButton,Init(R,'Start',cmStartJob,bfDefault));Insert(SButton);
- R.Assign(24,BtnRow,34,BtnRow+2);CButton:=New(PButton,Init(R,'Cancel',cmCancelJob,bfNormal));Insert(CButton);end
- else if((pfFlags AND mfOKButton)<>0)then begin R.Assign(17,BtnRow,26,BtnRow+2);
- SButton:=New(PButton,Init(R,'Start',cmStartJob,bfDefault));Insert(SButton);CButton:=nil;end
- else if((pfFlags AND mfCancelButton)<>0)then begin R.Assign(16,BtnRow,26,BtnRow+2);
- CButton:=New(PButton,Init(R,'Cancel',cmCancelJob,bfDefault));Insert(CButton);SButton:=nil;end;SelectNext(False);end;
- Function TRunDialog.Execute:Word;var Event:TEvent;begin if((pfFlags AND mfOKButton)=0)then RunState:=cmStartJob;Repeat
- GetEvent(Event);HandleEvent(Event);Process;Until(RunState>cmContinueJob);Execute:=RunState;end;
- Procedure TRunDialog.HandleEvent(var Event:TEvent);var R:TRect;Procedure DisposeButton(Button:PButton);begin
- if(Button<>nil)then begin Delete(Button);Dispose(Button,Done);end;end;begin TWindow.HandleEvent(Event);Case Event.What of
- evKeyDown:Case Event.KeyCode of kbEsc:begin Event.What:=evCommand;Event.Command:=cmCancelJob;Event.InfoPtr:=nil;
- PutEvent(Event);ClearEvent(Event);end;kbEnter:begin Event.What:=evBroadcast;Event.Command:=cmDefault;Event.InfoPtr:=nil;
- PutEvent(Event);ClearEvent(Event);end;end;evCommand:Case Event.Command of cmCancelJob,cmJobComplete,
- cmPauseJob,cmContinueJob,cmStartJob:begin Case Event.Command of cmContinueJob,cmStartJob:begin Lock;DisposeButton(SButton);
- DisposeButton(CButton);if((pfFlags AND mfPauseCancel)=mfPauseCancel)then begin R.Assign(11,BtnRow,20,BtnRow+2);
- SButton:=New(PButton,Init(R,'Pause',cmPauseJob,bfDefault));SButton^.State:=SButton^.State or sfActive;Insert(SButton);
- R.Assign(24,BtnRow,34,BtnRow+2);CButton:=New(PButton,Init(R,'Cancel',cmCancelJob,bfNormal));Insert(CButton);
- CButton^.State:=CButton^.State or sfActive;end else if((pfFlags AND mfPauseButton)<>0)then begin
- R.Assign(17,BtnRow,26,BtnRow+2);SButton:=New(PButton,Init(R,'Pause',cmPauseJob,bfDefault));Insert(SButton);CButton:=nil;
- SButton^.State:=SButton^.State or sfActive;end else if((pfFlags AND mfCancelButton)<>0)then begin
- R.Assign(16,BtnRow,26,BtnRow+2);CButton:=New(PButton,Init(R,'Cancel',cmCancelJob,bfDefault));Insert(CButton);SButton:=nil;
- CButton^.State:=CButton^.State or sfActive;end;SelectNext(False);DrawView;Unlock;end;cmPauseJob:begin Lock;
- DisposeButton(SButton);DisposeButton(CButton);if((pfFlags AND mfPauseCancel)=mfPauseCancel)then begin
- R.Assign(10,BtnRow,22,BtnRow+2);SButton:=New(PButton,Init(R,'Continue',cmContinueJob,bfDefault));Insert(SButton);
- R.Assign(25,BtnRow,35,BtnRow+2);CButton:=New(PButton,Init(R,'Cancel',cmCancelJob,bfNormal));Insert(CButton);
- SButton^.State:=SButton^.State or sfActive;CButton^.State:=CButton^.State or sfActive;end else begin
- R.Assign(15,BtnRow,27,BtnRow+2);SButton:=New(PButton,Init(R,'Continue',cmContinueJob,bfDefault));Insert(SButton);
- CButton:=nil;SButton^.State:=SButton^.State or sfActive;end;SelectNext(False);DrawView;Unlock;end;end;
- RunState:=Event.Command;ClearEvent(Event);end;end;end;end;Procedure TRunDialog.Process;begin end;
- Procedure TRunDialog.ChangeMessage(AMessage:String);begin if(Msg<>nil)then begin DisposeStr(Msg^.Text);
- Msg^.Text:=NewStr(AMessage);Msg^.DrawView;end;end;Constructor TPercentDialog.Init(ATitle:TTitleStr;AMessage:String;
- ATotal:LongInt;AOptions:Word );var R:TRect;begin R.Assign(0,0,44,10);TRunDialog.Init(R,ATitle,AMessage,AOptions,7);
- Options:=Options OR ofCentered;Total:=ATotal;Step:=Total DIV 25;if(Total MOD 25<>0)then Inc(Step);R.Assign(9,3,36,4);
- Insert(New(PStaticText,Init(R,'┌─────────────────────────┐')));R.Assign(9,4,36,5);
- Insert(New(PStaticText,Init(R,'│ │')));R.Assign(9,5,36,6);
- Insert(New(PStaticText,Init(R,'└─────────────────────────┘')));R.Assign(20,2,25,3);Pct:=New(PStaticText,Init(R,'0% '));
- Insert(Pct);R.Assign(10,4,35,5);Bar:=New(PStaticText,Init(R,Chars(25,BarChar)));Insert(Bar);end;
- Procedure TPercentDialog.Increment;begin IncrementBy(1);end;Procedure TPercentDialog.IncrementBy(AStep:Word);var Percent:Real;
- X:Word;N:String[3];begin if(Count<Total)then begin Count:=Count+AStep;if(Count>=Total)then begin
- FillChar(Bar^.Text^[1],25,BarFillChar);Bar^.DrawView;Pct^.Text^:='100%';Pct^.DrawView;end else if((Count MOD Step)=0)then
- begin Percent:=(Count/Total)*100;X:=Round(Percent/4);FillChar(Bar^.Text^[1],X,BarFillChar);Bar^.DrawView;Str(Percent:3:0,N);
- Pct^.Text^:=N+'%';Pct^.DrawView;end;end;end;Constructor TPrintDialog.Init(ATitle:TTitleStr;AMessage:String;AOptions:Word );
- var R:TRect;begin R.Assign(0,0,44,7);TRunDialog.Init(R,ATitle,AMessage,AOptions,4);Options:=Options OR ofCentered;end;
- {$IFDEF NEW_FILE_DIALOG}Function TNewFileCollection.Compare(Key1,Key2:Pointer):Integer;begin
- if PSearchRec(Key1)^.Name=PSearchRec(Key2)^.Name then Compare:=0 else if PSearchRec(Key1)^.Name='..'then Compare:=-1
- else if PSearchRec(Key2)^.Name='..'then Compare:=1 else if(PSearchRec(Key1)^.Attr and VolumeID<>0)and
- (PSearchRec(Key2)^.Attr and VolumeID=0)then Compare:=1 else if(PSearchRec(Key2)^.Attr and VolumeID<>0)and
- (PSearchRec(Key1)^.Attr and VolumeID=0)then Compare:=-1 else if PSearchRec(Key1)^.Name>PSearchRec(Key2)^.Name then Compare:=1
- else Compare:=-1;end;Constructor TNewFileList.Init(var Bounds:TRect;AWildCard:PathStr;AScrollBar:PScrollBar);begin
- TSortedListBox.Init(Bounds,1,AScrollBar);end;Procedure TNewFileList.HandleEvent(var Event:TEvent);var E:TEvent;begin
- if(Event.What=evBroadcast)and(Event.Command=cmReceivedFocus)and (Event.InfoPtr=@Self)then begin FocusItem(Focused)end else
- begin if(Event.What=evMouseDown)and(Event.Double)then Message(Owner,evBroadcast,cmRecordHistory,nil);
- TFileList.HandleEvent(Event);end;end;Procedure TNewFileList.FocusItem(Item:Integer);begin if(List^.Count>0)then
- TFileList.FocusItem(Item);end;Procedure TNewFileList.ReadDirectory(AWildCard:PathStr);var S:SearchRec;P:PSearchRec;
- Event:TEvent;FileList:PNewFileCollection;Dir:DirStr;Name:NameStr;Ext:ExtStr;begin
- PNewFileDialog(Owner)^.DriveList^.ReadDirectory(AWildCard);AWildCard:=FExpand(AWildCard);FSplit(AWildCard,Dir,Name,Ext);
- FileList:=New(PNewFileCollection,Init(5,5));FindFirst(AWildCard,ReadOnly+Archive,S);P:=@P;while(P<>nil)and(DosError=0)do begin
- if(S.Attr and Directory=0)then begin P:=MemAlloc(SizeOf(P^));if(P<>nil)then begin Move(S.Attr,P^,SizeOf(P^));
- FileList^.Insert(P);end;end;FindNext(S);end;if(P=nil)then MessageBox('Too many files.',nil,mfOkButton+mfWarning);
- NewList(FileList);if(List^.Count>0)then begin Event.What:=evBroadcast;Event.Command:=cmFileFocused;
- Event.InfoPtr:=List^.At(0);Owner^.HandleEvent(Event);end;end;Constructor TDriveList.Init(var Bounds:TRect;
- AScrollBar:PScrollBar);begin TSortedListBox.Init(Bounds,1,AScrollBar);end;
- Procedure TDriveList.GetDrives(var Drives:DriveSet);var DriveMap:LongInt;begin
- ASM
- mov ah,19h
- int 21h
- push ax
-
- mov bx,1
- xor cx,cx
- xor dl,dl
- mov word ptr [DriveMap], 0
- mov word ptr [DriveMap+2], 0
-
- @1: mov ah,0Eh
- int 21h
- mov ah,19h
- int 21h
- cmp al,dl
- jne @2
- or word ptr [DriveMap],bx
- or word ptr [DriveMap+2],cx
-
- @2: shl bx,1
- rcl cx,1
- inc dl
- cmp dl,26
- jb @1
-
- mov ah,0Eh
- pop dx
- int 21h
-
- shl word ptr [DriveMap],1
- rcl word ptr [DriveMap+2],1
- end;Drives:=DriveSet(DriveMap);end;Function TDriveList.GetKey(var S:String):Pointer;const SR:TSearchRec=();
- Procedure UpStr(var S:String);var I:Byte;begin for I:=1 to Length(S)do S[I]:=UpCase(S[I]);end;begin SR.Attr:=Directory;
- SR.Name:=S;UpStr(SR.Name);GetKey:=@SR;end;Procedure TDriveList.ReadDirectory(AWildCard:PathStr);var C:Char;Drives:DriveSet;
- S:SearchRec;P:PSearchRec;FileList:PNewFileCollection;Dir:DirStr;Name:NameStr;Ext:ExtStr;begin P:=@P;
- FileList:=New(PNewFileCollection,Init(5,5));AWildCard:=FExpand(AWildCard);FSplit(AWildCard,Dir,Name,Ext);
- AWildCard:=Dir+'*.*';FindFirst(AWildCard,Directory,S);while(P<>nil)and(DosError=0)do begin
- if(S.Attr and Directory<>0)and(S.Name[1]<>'.')then begin P:=MemAlloc(SizeOf(P^));if(P<>nil)then begin
- Move(S.Attr,P^,SizeOf(P^));FileList^.Insert(PObject(P));end;end;FindNext(S);end;if Length(Dir)>4 then begin
- P:=MemAlloc(SizeOf(P^));if(P<>nil)then begin FindFirst(AWildCard,Directory,S);FindNext(S);if(DosError=0)and(S.Name='..')then
- begin Move(S.Attr,P^,SizeOf(P^))end else begin P^.Name:='..';P^.Size:=0;P^.Time:=$210000;P^.Attr:=Directory;end;
- FileList^.Insert(PObject(P));end;end;GetDrives(Drives);for C:='A'to'Z'do if(C in Drives)then begin P:=MemAlloc(SizeOf(P^));
- if(P<>nil)then begin P^.Name:=C+':';P^.Size:=0;P^.Time:=$210000;P^.Attr:=Directory OR VolumeID;
- FileList^.AtInsert(FileList^.Count,PObject(P));end;end;if(P=nil)then
- MessageBox('Too many directories.',nil,mfOkButton+mfWarning);NewList(FileList);end;Procedure TNewFileInfoPane.Draw;var
- Color:Word;Params:array[0..7]of LongInt;Time:DateTime;D:String[5];FmtId:String[60];Str:String[60];B:TDrawBuffer;const
- sDirectoryLine='%-12s %-9s %02d/%02d/%4d %02d:%02d%cm';sFileLine='%-12s %-9d %02d/%02d/%4d %02d:%02d%cm';begin
- Color:=GetColor($01);MoveChar(B,' ',Color,Size.X);Params[0]:=LongInt(@S.Name);if((S.Attr and Directory)<>0)then begin
- FmtId:=sDirectoryLine;D:='<Dir>';Params[1]:=LongInt(@D);end else begin FmtId:=sFileLine;Params[1]:=S.Size;end;
- UnpackTime(S.Time,Time);Params[2]:=Time.Month;Params[3]:=Time.Day;Params[4]:=Time.Year;if(Time.Hour>=12)then
- Params[7]:=Byte('p')else Params[7]:=Byte('a');Time.Hour:=Time.Hour mod 12;if(Time.Hour=0)then Time.Hour:=12;
- Params[5]:=Time.Hour;Params[6]:=Time.Min;FormatStr(Str,FmtId,Params);MoveStr(B[1],Str,Color);WriteLine(0,0,Size.X,1,B);end;
- Constructor TDirectoryInfoPane.Init(var Bounds:TRect);begin TView.Init(Bounds);EventMask:=EventMask or evBroadcast;end;
- Function TDirectoryInfoPane.GetPalette:PPalette;const P:String[Length(CInfoPane)]=CInfoPane;begin GetPalette:=@P;end;
- Procedure TDirectoryInfoPane.HandleEvent(var Event:TEvent);begin TView.HandleEvent(Event);
- if(Event.What=evBroadcast)and(Event.Command=cmFileFocused)then DrawView;end;Procedure TDirectoryInfoPane.Draw;var
- B:TDrawBuffer;Color:Word;Path:PathStr;begin Path:=FExpand(PNewFileDialog(Owner)^.Directory^);Color:=GetColor($01);
- MoveChar(B,' ',Color,Size.X);MoveStr(B[1],Path,Color);WriteLine(0,0,Size.X,1,B);end;
- Procedure TNewFileInputLine.HandleEvent(var Event:TEvent);begin TInputLine.HandleEvent(Event);
- if(Event.What=evBroadcast)and(Event.Command=cmFileFocused)and (State and sfSelected=0)then begin
- if(PSearchRec(Event.InfoPtr)^.Attr and Directory<>0)then Data^:=PSearchRec(Event.InfoPtr)^.Name+'\'+
- PFileDialog(Owner)^.WildCard else Data^:=FExpand(PNewFileDialog(Owner)^.Directory^)+PSearchRec(Event.InfoPtr)^.Name;DrawView;
- end;end;Constructor TNewFileDialog.Init(AWildCard:TWildStr;ATitle:String;InputName:String;AOptions:Word;HistoryId:Byte);var
- Control:PView;R:TRect;S:String;Opt:Word;ACurDir:PathStr;begin R.Assign(0,0,49,18);TDialog.Init(R,ATitle);
- Options:=Options or ofCentered;WildCard:=AWildCard;R.Assign(2,2,31,3);FileName:=New(PNewFileInputLine,Init(R,79));
- FileName^.Data^:=WildCard;Insert(FileName);R.Assign(2,1,3+CStrLen(InputName),2);
- Control:=New(PLabel,Init(R,InputName,FileName));Insert(Control);R.Assign(31,2,34,3);
- Control:=New(PHistory,Init(R,FileName,HistoryId));Insert(Control);R.Assign(16,6,17,16);Control:=New(PScrollBar,Init(R));
- Insert(Control);R.Assign(2,6,16,16);FileList:=New(PNewFileList,Init(R,WildCard,PScrollBar(Control)));Insert(FileList);
- R.Assign(2,5,8,6);Control:=New(PLabel,Init(R,'~F~iles',FileList));Insert(Control);R.Assign(32,6,33,16);
- Control:=New(PScrollBar,Init(R));Insert(Control);R.Assign(18,6,32,16);DriveList:=New(PDriveList,Init(R,PScrollBar(Control)));
- Insert(DriveList);R.Assign(18,5,30,6);Control:=New(PLabel,Init(R,'~D~irectories',DriveList));Insert(Control);
- R.Assign(35,2,46,4);Opt:=bfDefault;if AOptions and fdOpenButton<>0 then begin
- Insert(New(PButton,Init(R,'~O~pen',cmFileOpen,Opt)));Opt:=bfNormal;Inc(R.A.Y,3);Inc(R.B.Y,3);end;
- if AOptions and fdOkButton<>0 then begin Insert(New(PButton,Init(R,'O~K~',cmFileOpen,Opt)));Opt:=bfNormal;
- Inc(R.A.Y,3);Inc(R.B.Y,3);end;if AOptions and fdReplaceButton<>0 then begin
- Insert(New(PButton,Init(R,'~R~eplace',cmFileReplace,Opt)));Opt:=bfNormal;Inc(R.A.Y,3);Inc(R.B.Y,3);end;
- if AOptions and fdClearButton<>0 then begin Insert(New(PButton,Init(R,'~C~lear',cmFileClear,Opt)));Opt:=bfNormal;
- Inc(R.A.Y,3);Inc(R.B.Y,3);end;Insert(New(PButton,Init(R,'Cancel',cmCancel,bfNormal)));Inc(R.A.Y,3);Inc(R.B.Y,3);
- if AOptions and fdHelpButton<>0 then begin Insert(New(PButton,Init(R,'Help',cmHelp,bfNormal)));Inc(R.A.Y,3);Inc(R.B.Y,3);end;
- R.Assign(2,4,31,5);Control:=New(PDirectoryInfoPane,Init(R));Insert(Control);R.Assign(3,3,12,4);
- Control:=New(PStaticText,Init(R,'Directory'));Insert(Control);R.Assign(2,Size.Y-2,Size.X-2,Size.Y-1);
- Control:=New(PNewFileInfoPane,Init(R));Insert(Control);SelectNext(False);if((AOptions and fdNoLoadDir)=0)then ReadDirectory;
- end;{$ENDIF}Constructor TMessageDialog.Init(AOptions:Word);var R:TRect;S:String[13];begin R.Assign(0,0,4,4);
- TDialog.Init(R,Titles[AOptions AND$3]);Options:=Options+ofCentered;DOptions:=AOptions;Desktop^.GetExtent(R);
- SList.Init(R.B.Y-5,0);end;Procedure TMessageDialog.AddMessage(St:String);var P:PString;begin GetMem(P,Length(St)+1);
- if(P<>nil)then begin P^:=St;SList.Insert(P);end;end;Function TMessageDialog.Process:Word;var P:Pointer;X,Y:Byte;I:Byte;
- Count:Byte;Rem:Integer;Spc:Integer;R:TRect;begin Desktop^.GetExtent(R);X:=0;for i:=0 to SList.Count-1 do begin P:=SList.At(i);
- if(Byte(P^)>R.B.X)then Byte(P^):=R.B.X;if(Byte(P^)>X)then X:=Byte(P^);end;Count:=0;for i:=0 to 3 do
- if(DOptions AND($0100 shl i)<>0)then Inc(Count);if((Count*11+1)>X)then X:=Count*11+1;X:=X+2;Y:=SList.Count+2;
- if(ButtonCount>0)then Y:=Y+3;R.Assign(0,0,X,Y);ChangeBounds(R);if(Count>0)then begin Rem:=Size.X-(Count*9);
- Spc:=Rem DIV(Count+1);X:=Spc+(Rem MOD Count)shr 1;for i:=0 to 3 do if(DOptions AND($0100 shl i)<>0)then begin
- R.Assign(X,Size.Y-3,X+10,Size.Y-1);Insert(New(PButton,Init(R,Buttons[i],Commands[i],bfNormal)));Inc(X,Spc+8);end;
- SelectNext(False);end;for i:=0 to SList.Count-1 do begin R.Assign(1,i+1,Size.X-1,i+2);
- Insert(New(PStaticText,Init(R,PString(SList.At(i))^)));end;Process:=DeskTop^.ExecView(@Self);end;
- Destructor TMessageDialog.Done;begin SList.Done;end;END.
-