home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / outlines.zip / CustomOutline.pas < prev    next >
Pascal/Delphi Source File  |  1999-09-30  |  2KB  |  88 lines

  1. Unit CustomOutline;
  2. // A minor enhancement to TOutline to remember which node was
  3. // right clicked
  4. // And also, has a SetAndShowSelectedItem method
  5. Interface
  6.  
  7. Uses
  8.   Classes, Forms, OutLine;
  9.  
  10. {Declare new class}
  11. Type
  12.   TCustomOutline=Class(TOutline)
  13.     Protected
  14.     FPopupNode: TOutlineNode;
  15.     Procedure ParentNotification(Var Msg:TMessage);Override;
  16.  
  17.     Public
  18.     Procedure SetAndShowSelectedItem( NodeIndex: longint );
  19.     Property PopupNode: TOutlineNode read FPopupNode;
  20.   End;
  21.  
  22. Exports
  23.   TCustomOutline,'User','CustomOutline.bmp';
  24.  
  25. Implementation
  26.  
  27. Uses
  28.   PmStdDlg, PmWin;
  29.  
  30. Procedure TCustomOutline.SetAndShowSelectedItem( NodeIndex: longint );
  31. Begin
  32.   SelectedItem:= NodeIndex;
  33.   // The only way I can find to actually show the selected node
  34.   // if its off screen!!!
  35.   // Send a cursor up + cursor down key stroke
  36.   if NodeIndex>1 then
  37.   begin
  38.     SendMsg( Handle,
  39.              WM_CHAR,
  40.              MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
  41.              MPFROM2SHORT( 0, VK_UP ) );
  42.     SendMsg( Handle,
  43.              WM_CHAR,
  44.              MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
  45.              MPFROM2SHORT( 0, VK_DOWN ) );
  46.   end
  47.   else
  48.   begin
  49.     // selecting root node
  50.     if ItemCount>1 then
  51.     begin
  52.       SendMsg( Handle,
  53.                WM_CHAR,
  54.                MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
  55.                MPFROM2SHORT( 0, VK_DOWN ) );
  56.       SendMsg( Handle,
  57.                WM_CHAR,
  58.                MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
  59.                MPFROM2SHORT( 0, VK_UP ) );
  60.     end;
  61.   end;
  62.   // Expand the selected node
  63.   SelectedNode.Expand;
  64. End;
  65.  
  66. Procedure TCustomOutline.ParentNotification(Var Msg:TMessage);
  67. Var
  68.   RecordCore:POutlineRecord;
  69. Begin
  70.   Case Msg.Param1Hi Of
  71.     CN_CONTEXTMENU:
  72.     Begin
  73.       If Designed Then Exit;
  74.  
  75.       RecordCore := Pointer(Msg.Param2);
  76.       If RecordCore = Nil Then Exit;
  77.       FPopupNode := RecordCore^.Node;
  78.     end;
  79.   end; // case
  80.   Inherited ParentNotification( Msg );
  81. end;
  82.  
  83. Initialization
  84.   {Register classes}
  85.   RegisterClasses([TCustomOutline]);
  86. End.
  87.  
  88.