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 | 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 |
|
---|
26 | Exports
|
---|
27 | TCustomOutline,'User','CustomOutline.bmp';
|
---|
28 |
|
---|
29 | Implementation
|
---|
30 |
|
---|
31 | Uses
|
---|
32 | PmStdDlg, PmWin;
|
---|
33 |
|
---|
34 | constructor TCustomOutline.Create( Owner: TComponent );
|
---|
35 | begin
|
---|
36 | inherited Create( Owner );
|
---|
37 | FShowMovementCount:= 0;
|
---|
38 | end;
|
---|
39 |
|
---|
40 | procedure TCustomOutline.ItemFocus( INdex: longint );
|
---|
41 | begin
|
---|
42 | if FShowMovementCount > 0 then
|
---|
43 | begin
|
---|
44 | dec( FShowMovementCount );
|
---|
45 | exit;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | Inherited ItemFocus( Index );
|
---|
49 |
|
---|
50 | end;
|
---|
51 |
|
---|
52 | Procedure TCustomOutline.SetAndShowSelectedItem( NodeIndex: longint );
|
---|
53 | var
|
---|
54 | Node: TOutlineNode;
|
---|
55 | TempNode: TOutlineNode;
|
---|
56 | Begin
|
---|
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;
|
---|
99 | End;
|
---|
100 |
|
---|
101 | Procedure TCustomOutline.ParentNotification(Var Msg:TMessage);
|
---|
102 | Var
|
---|
103 | RecordCore:POutlineRecord;
|
---|
104 | Begin
|
---|
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 );
|
---|
116 | end;
|
---|
117 |
|
---|
118 | Initialization
|
---|
119 | {Register classes}
|
---|
120 | RegisterClasses([TCustomOutline]);
|
---|
121 | End.
|
---|
122 |
|
---|