home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Pascal / Turbo Pascal 7.1 Final CD-RiP / EXAMPLES / TVFM / TRASH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-05  |  2.7 KB  |  112 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit Trash;
  9.  
  10. {$X+,V-}
  11.  
  12. interface
  13.  
  14. uses Drivers, Objects, Views, App, Globals, Tools, Equ, MsgBox;
  15.  
  16. type
  17.  
  18.   { Trash can object }
  19.   PTrashCan = ^TTrashCan;
  20.   TTrashCan = object(TView)
  21.     procedure Draw; virtual;
  22.     procedure HandleEvent(var Event: TEvent); virtual;
  23.     function GetPalette: PPalette; virtual;
  24.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  25.   end;
  26.  
  27.  
  28. implementation
  29.  
  30. const
  31.   CTrashCan : string[Length(CGrayWindow)] = CGrayWindow;
  32.  
  33. { TTrashCan }
  34.  
  35. function TTrashCan.GetPalette: PPalette;
  36. begin
  37.    GetPalette := @CTrashCan;
  38. end;
  39.  
  40. procedure TTrashCan.Draw;
  41. var
  42.   B: TDrawBuffer;
  43.   C: Word;
  44. begin
  45.   if State and sfDragging <> 0 then C := 3
  46.   else if State and sfSelected = 0 then C := 1
  47.   else C := 2;
  48.   C := GetColor(C);
  49.   MoveStr(B, #209#209#216#209#209, C);
  50.   WriteLine(0, 0, Size.X, 1, B);
  51.   MoveStr(B, 'Trash', C);
  52.   WriteLine(0, 1, Size.X, 1, B);
  53.   MoveStr(B, #192#193#193#193#217, C);
  54.   WriteLine(0, 2, Size.X, 1, B);
  55. end;
  56.  
  57. procedure TTrashCan.HandleEvent(var Event:TEvent);
  58. var
  59.   Mover: PFileMover;
  60.   Where: TPoint;
  61.   SaveConfirm: Boolean;
  62.   Extent: TRect;
  63.   Msg: String;
  64.  
  65.   procedure DeleteFile(F: PFileRec); far;
  66.   begin
  67.     SafeDelete(Mover^.Dir + '\' + F^.Name + F^.Ext);
  68.   end;
  69.  
  70. begin
  71.   inherited HandleEvent(Event);
  72.  
  73.   if (Event.What = evBroadcast) and (Event.Command = cmItemDropped) then
  74.   begin
  75.     Mover := Event.InfoPtr;
  76.     Desktop^.MakeGlobal(Mover^.Origin, Where);
  77.     if MouseInView(Where) then
  78.     begin
  79.       ClearEvent(Event);
  80.       if Mover^.Items^.Count = 1 then Msg := RezStrings^.Get(sDelSingle)
  81.       else Msg := RezStrings^.Get(sDelMult);
  82.       if MessageBox(Msg, nil, mfConfirmation +
  83.         mfYesButton + mfNoButton) = cmYes then
  84.       begin
  85.         SaveConfirm := ConfirmDelete;
  86.         ConfirmDelete := False;
  87.         Mover^.Items^.ForEach(@DeleteFile);
  88.         ConfirmDelete := SaveConfirm;
  89.         InvalidateDir(Mover^.Dir);
  90.       end;
  91.     end;
  92.   end;
  93.  
  94.   if Event.What = evMouseDown then
  95.   begin
  96.     Owner^.GetExtent(Extent);
  97.     DragView(Event, dmDragMove, Extent, Size, Size);
  98.   end;
  99.  
  100. end;
  101.  
  102. procedure TTrashCan.SetState(AState: Word; Enable: Boolean);
  103. begin
  104.   inherited SetState(AState, Enable);
  105.   if AState and sfSelected <> 0 then
  106.     SetCmdState([cmNext, cmPrev], Enable);
  107.   if AState and (sfSelected + sfFocused) <> 0 then
  108.     DrawView;
  109. end;
  110.  
  111. end.
  112.