home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / MENUPROP.PAS < prev    next >
Pascal/Delphi Source File  |  1996-09-14  |  3KB  |  126 lines

  1. unit Menuprop;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  6.   StdCtrls, Menus, Grids, Outline, TabNotBk;
  7.  
  8. type
  9.   TBtnBottomDlg = class(TForm)
  10.     OKBtn: TBitBtn;
  11.     CancelBtn: TBitBtn;
  12.     HelpBtn: TBitBtn;
  13.     TabbedNotebook1: TTabbedNotebook;
  14.     Outline: TOutline;
  15.     OutlineMenu: TPopupMenu;
  16.     AddItem: TMenuItem;
  17.     InsertItem: TMenuItem;
  18.     EditItem: TMenuItem;
  19.     DeleteItem: TMenuItem;
  20.     ExpandItem: TMenuItem;
  21.     CollapseItem: TMenuItem;
  22.     N1: TMenuItem;
  23.     Convert: TMenuItem;
  24.     procedure OutlineDragDrop(Sender, Source: TObject; X, Y: Integer);
  25.     procedure OutlineDragOver(Sender, Source: TObject; X, Y: Integer;
  26.       State: TDragState; var Accept: Boolean);
  27.     procedure OutlineEndDrag(Sender, Target: TObject; X, Y: Integer);
  28.     procedure OutlineMouseDown(Sender: TObject; Button: TMouseButton;
  29.       Shift: TShiftState; X, Y: Integer);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.   end;
  35.  
  36. var
  37.   BtnBottomDlg: TBtnBottomDlg;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TBtnBottomDlg.OutlineDragDrop(Sender, Source: TObject; X,
  44.   Y: Integer);
  45. const
  46.   MoveOp: array[Boolean] of TAttachMode = (oaInsert, oaAddChild);
  47. var
  48.   dest : Longint;
  49.   i : Integer;
  50. begin
  51.   EraseDropFocus;
  52.   dest := Outline.GetItem(X, Y);
  53.  
  54.   if Source is TMultiGrid then
  55.     with (TMultiGrid(Source).Owner as TIconWindow).CompileSelection(False) do
  56.       for i := 0 to Count-1 do
  57.         with  TDirItem(Items[i]) do
  58.           AddOutlineNode(dest, GetTitle, GetStartInfo, oaAddChild)
  59.  
  60.   else with Outline do begin
  61.     BeginUpdate;
  62.     Items[DragItem].MoveTo(dest, MoveOp[MakeChild]);
  63.     EndUpdate;
  64.   end;
  65.   StartChanged := True;
  66. end;
  67.  
  68. procedure TBtnBottomDlg.OutlineDragOver(Sender, Source: TObject; X,
  69.   Y: Integer; State: TDragState; var Accept: Boolean);
  70. var i: Integer;
  71. begin
  72.   Accept := ((Sender = Source) or
  73.              (Source is TMultiGrid) and (Source <> SysWindow.Grid))
  74.             and (Outline.GetItem(X, Y) > 0);
  75.  
  76.   with Outline do begin
  77.     if not Accept or (State = dsDragLeave) then
  78.       EraseDropFocus
  79.     else begin
  80.       i := Y div ItemHeight;
  81.       if i <> DropFocus then begin
  82.         EraseDropFocus;
  83.         Canvas.DrawFocusRect(Bounds(0, i * ItemHeight, Width, ItemHeight));
  84.         DropFocus := i;
  85.       end;
  86.     end;
  87.   end;
  88. end;
  89.  
  90. procedure TBtnBottomDlg.OutlineEndDrag(Sender, Target: TObject; X,
  91.   Y: Integer);
  92. begin
  93.   ClipCursor(nil);
  94. end;
  95.  
  96. procedure TBtnBottomDlg.OutlineMouseDown(Sender: TObject;
  97.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  98. begin
  99.   var
  100.   r : TRect;
  101.   i : Longint;
  102.   p : TPoint;
  103. begin
  104.   if ssDouble in Shift then exit
  105.   else if Button = mbRight then with Outline do begin
  106.     i := GetItem(X, Y);
  107.     if i > 0 then SelectedItem := i;
  108.     GetCursorPos(p);
  109.     OutlineMenu.Popup(p.X, p.Y);
  110.   end
  111.   else with Outline do begin
  112.     DragItem := GetItem(X, Y);
  113.     if DragItem > 0 then begin
  114.       MakeChild := ssAlt in Shift;
  115.       with ClientRect do begin
  116.         r.TopLeft := ClientToScreen(TopLeft);
  117.         r.BottomRight := ClientToScreen(Bottomright);
  118.         ClipCursor(@r);
  119.       end;
  120.       BeginDrag(False);
  121.     end;
  122.   end
  123. end;
  124.  
  125. end.
  126.