home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D8 / TVFM.ZIP / DRAGDROP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  2.7 KB  |  115 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit DragDrop;  { Drag and drop support objects }
  9.  
  10. {$X+,V-}
  11.  
  12. interface
  13.  
  14. uses Dos, Objects, Drivers, Views, Dialogs, App;
  15.  
  16. type
  17.  
  18.   { TListViewer that supports grabbing an item with the mouse }
  19.   PDDList = ^TDDList;
  20.   TDDList = object(TListViewer)
  21.     procedure HandleEvent(var Event: TEvent); virtual;
  22.     procedure PickUpItem(Item: Integer; Where: TPoint); virtual;
  23.   end;
  24.  
  25.   { Moving view while item is dragged }
  26.  
  27.   PMover = ^TMover;
  28.   TMover = object(TView)
  29.     Dir: PathStr;
  30.     Items: PCollection;
  31.     constructor Init(Where: TPoint; const ADir: PathStr; AItems: PCollection);
  32.     procedure Draw; virtual;
  33.   end;
  34.  
  35.  
  36. implementation
  37.  
  38. { TDDList }
  39.  
  40. procedure TDDList.PickUpItem(Item: Integer; Where: TPoint);
  41. begin
  42. end;
  43.  
  44. procedure TDDList.HandleEvent(var Event: TEvent);
  45. var
  46.   Mouse: TPoint;
  47.   NewItem, OldItem: Integer;
  48.  
  49. function HasMoved(const P1, P2: TPoint): Boolean;
  50. begin
  51.   HasMoved := (P1.X <> P2.X) or (P1.Y <> P2.Y);
  52. end;
  53.  
  54. begin
  55.   if (Event.What = evMouseDown) and (Event.Buttons = mbLeftButton) then
  56.   begin
  57.     TView.HandleEvent(Event);
  58.     if Event.What = evNothing then Exit;
  59.     OldItem := Focused;
  60.     MakeLocal(Event.Where, Mouse);
  61.     NewItem := Mouse.Y + TopItem;
  62.     if NewItem <> OldItem then
  63.     begin
  64.       if NewItem < 0 then NewItem := 0
  65.       else if (NewItem >= Range) and (Range > 0) then NewItem := Range - 1;
  66.       if Range <> 0 then FocusItem(NewItem);
  67.       DrawView;
  68.     end;
  69.  
  70.     { possibly a drag/drop operation }
  71.     if (Mouse.X > 1) and (Mouse.X <= 13) then
  72.     begin
  73.       if MouseEvent(Event, evMouseMove) and (Event.Buttons = mbLeftButton) then
  74.       begin
  75.         MakeLocal(Event.Where, Event.Where);
  76.         if HasMoved(Event.Where, Mouse) then
  77.         begin
  78.           MakeGlobal(Event.Where, Mouse);
  79.           PickUpItem(Focused, Mouse);
  80.           ClearEvent(Event);
  81.         end;
  82.       end;
  83.     end;
  84.  
  85.     if Event.Double and (Range > Focused) then SelectItem(Focused);
  86.     ClearEvent(Event);
  87.   end;
  88.   inherited HandleEvent(Event);
  89. end;
  90.  
  91.  
  92. { TMover }
  93.  
  94. constructor TMover.Init(Where: TPoint; const ADir: PathStr;
  95.   AItems: PCollection);
  96. var
  97.   R: TRect;
  98.   YSize: Integer;
  99. begin
  100.   YSize := AItems^.Count;
  101.   if YSize > 3 then YSize := 3;
  102.   R.Assign(Where.X, Where.Y, Where.X + 12, Where.Y + YSize);
  103.   inherited Init(R);
  104.   SetState(sfShadow, True);
  105.   Dir := ADir;
  106.   Items := AItems;
  107. end;
  108.  
  109. procedure TMover.Draw;
  110. begin
  111.   Abstract;
  112. end;
  113.  
  114. end.
  115.