source: trunk/Components/CustomOutline.pas@ 91

Last change on this file since 91 was 15, checked in by RBRi, 19 years ago

+ components stuff

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1Unit CustomOutline;
2// A minor enhancement to TOutline to remember which node was
3// right clicked
4// And also, has a SetAndShowSelectedItem method
5Interface
6
7Uses
8 Classes, Forms, OutLine;
9
10{Declare new class}
11Type
12 TCustomOutline=Class(TOutline)
13 Protected
14 FPopupNode: TOutlineNode;
15 FShowMovementCount: integer;
16 Procedure ParentNotification(Var Msg:TMessage);Override;
17 procedure ItemFocus( INdex: longint ); override;
18
19 Public
20 Procedure SetAndShowSelectedItem( NodeIndex: longint );
21 Property PopupNode: TOutlineNode read FPopupNode;
22 constructor Create( Owner: TComponent ); override;
23
24 End;
25
26Exports
27 TCustomOutline,'User','CustomOutline.bmp';
28
29Implementation
30
31Uses
32 PmStdDlg, PmWin;
33
34constructor TCustomOutline.Create( Owner: TComponent );
35begin
36 inherited Create( Owner );
37 FShowMovementCount:= 0;
38end;
39
40procedure TCustomOutline.ItemFocus( INdex: longint );
41begin
42 if FShowMovementCount > 0 then
43 begin
44 dec( FShowMovementCount );
45 exit;
46 end;
47
48 Inherited ItemFocus( Index );
49
50end;
51
52Procedure TCustomOutline.SetAndShowSelectedItem( NodeIndex: longint );
53var
54 Node: TOutlineNode;
55 TempNode: TOutlineNode;
56Begin
57 Node:= Items[ NodeIndex ];
58 TempNode:= NOde;
59 while TempNode.Parent <> nil do
60 begin
61 if not TempNode.Expanded then
62 TempNode.Expand;
63 TempNode:= TempNode.Parent;
64 end;
65
66 FShowMovementCount:= 2; // 1 to move to correct item. 1 to move up. 1 to move back.
67 SelectedNode:= Node;
68 // The only way I can find to actually show the selected node
69 // if its off screen!!!
70 // Send a cursor up + cursor down key stroke
71 if NodeIndex>1 then
72 begin
73 SendMsg( Handle,
74 WM_CHAR,
75 MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
76 MPFROM2SHORT( 0, VK_UP ) );
77 SendMsg( Handle,
78 WM_CHAR,
79 MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
80 MPFROM2SHORT( 0, VK_DOWN ) );
81 end
82 else
83 begin
84 // selecting root node - send down then up
85 if ItemCount>1 then
86 begin
87 SendMsg( Handle,
88 WM_CHAR,
89 MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
90 MPFROM2SHORT( 0, VK_DOWN ) );
91 SendMsg( Handle,
92 WM_CHAR,
93 MPFROM2SHORT( KC_VIRTUALKEY, 0 ),
94 MPFROM2SHORT( 0, VK_UP ) );
95 end;
96 end;
97 // Expand the selected node
98 SelectedNode.Expand;
99End;
100
101Procedure TCustomOutline.ParentNotification(Var Msg:TMessage);
102Var
103 RecordCore:POutlineRecord;
104Begin
105 Case Msg.Param1Hi Of
106 CN_CONTEXTMENU:
107 Begin
108 If Designed Then Exit;
109
110 RecordCore := Pointer(Msg.Param2);
111 If RecordCore = Nil Then Exit;
112 FPopupNode := RecordCore^.Node;
113 end;
114 end; // case
115 Inherited ParentNotification( Msg );
116end;
117
118Initialization
119 {Register classes}
120 RegisterClasses([TCustomOutline]);
121End.
122
Note: See TracBrowser for help on using the repository browser.