-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTree.pas
228 lines (194 loc) · 5.02 KB
/
Tree.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
unit Tree;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, JvExComCtrls, JvComCtrls, ConfigType, smapi, ImgList;
type
TTreeForm = class(TForm)
Tree: TJvTreeView;
Glyphs: TImageList;
procedure TreeKeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure TreeDblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TreeCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
private
{ Private declarations }
public
curmsg: longint;
Area: TArea;
{ Public declarations }
end;
var
TreeForm: TTreeForm;
implementation
{$R *.dfm}
uses Main, Log, View, Language, Setup;
procedure TTreeForm.TreeKeyPress(Sender: TObject; var Key: Char);
begin
if Key=#27 then begin
TreeForm.Close;
MainForm.SetFocus;
end;
if key=#13 then TreeDblClick(Self);
end;
procedure TTreeForm.FormShow(Sender: TObject);
const MAXIDX=65535;
var z:longint;
rootmsg: longint;
root,sel:TTreeNode;
sorted: boolean;
numbers,indexes:array[0..MAXIDX] of longint;
dnum,nm: longint;
procedure swapnumandidx(i1,i2:longint);
var t:longint;
begin
t:=numbers[i1];
numbers[i1]:=numbers[i2];
numbers[i2]:=t;
t:=indexes[i1];
indexes[i1]:=indexes[i2];
indexes[i2]:=t;
end;
procedure AddCh(r: TTreeNode; n:longint);
// r - óçåë äåðåâà, n - íîìåð ñîîáùåíèÿ ÏÎ ÑרÒÓ (ÍÅ UMsgID)
var tn: TTreeNode;
i: byte;
z: longint;
pm: PMsgHandle;
xm: TXMSG;
subj: string[80];
function isRead(xm:TXMSG):boolean;
begin
result:=(xm.attr and MSGREAD)>0;
end;
function isLocal(xm:TXMSG):boolean;
begin
result:=(xm.attr and MSGLOCAL)>0;
end;
function isSent(xm:TXMSG):boolean;
begin
result:=(xm.attr and MSGSENT)>0;
end;
function isForMe(xm:TXMSG):boolean;
begin
result:=(SetupForm.Users.Items.IndexOf(xm._to)>=0)
end;
begin
pm:=MsgOpenMsg(Area.msga,MOPEN_READ,n);
if pm=nil then Exit;
MsgReadMsg(pm,@xm,0,0,nil,0,nil);
MsgCloseMsg(pm);
subj:=OemToAnsiString(xm.subj);
if length(subj)>20 then subj:=Copy(subj,1,20)+'...';
tn:=TreeForm.Tree.Items.AddChild(r,IntToStr(n)+' '+
OemToAnsiString(xm.from)+' "'+subj+'"');
if (not isRead(xm)) and (not isLocal(xm)) then
begin
if isForMe(xm) then tn.StateIndex:=3 else tn.StateIndex:=2
end
else
if (isLocal(xm)) and (not isSent(xm)) then tn.StateIndex:=4
else tn.StateIndex:=0;
if n=curmsg then sel:=tn;
if Area.BaseType=btSquish then begin
for i:=0 to MAX_REPLY-1 do begin
z:=xm.replies[i];
if z=0 then continue;
z:=MsgUidToMsgn(Area.msga,z,UID_EXACT);
if (z=0) or (z=n) or (z>Area.msga.num_msg) then continue;
AddCh(tn,z);
end
end
else if Area.BaseType=btJam then begin
z:=xm.replies[0];
if z>0 then begin
z:=MsgUidToMsgn(Area.msga,z,UID_EXACT);
if (z>0) and (z<>n) and (z<=Area.msga.num_msg)
then AddCh(tn,z);
end;
z:=xm.replies[MAX_REPLY-1];
if z>0 then begin
z:=MsgUidToMsgn(Area.msga,z,UID_EXACT);
if (z>0) and (z<>n) and (z<=Area.msga.num_msg)
then AddCh(r,z);
end;
end;
end;
var xm:TXMSG;
pm:PMsgHandle;
begin
try
if not Area.Open then begin
LogEvent('Unexpected messagebase error - unable to open '+Area.Path);
TreeForm.Close;
Exit;
end;
rootmsg:=curmsg;
pm:=MsgOpenMsg(Area.msga,MOPEN_READ,rootmsg);
if pm=nil then Exit;
MsgReadMsg(pm,@xm,0,0,nil,0,nil);
MsgCloseMsg(pm);
while xm.replyto>0 do begin
rootmsg:=MsgUidToMsgn(Area.msga,xm.replyto,UID_EXACT);
if rootmsg=0 then begin
ShowMessage(lang.errnoroot);
Exit;
end;
pm:=MsgOpenMsg(Area.msga,MOPEN_READ,rootmsg);
if pm=nil then Exit;
MsgReadMsg(pm,@xm,0,0,nil,0,nil);
MsgCloseMsg(pm);
end;
root:=nil;
sel:=nil;
AddCh(root,rootmsg);
if SetupForm.TreeFullExpand.Checked then begin
Tree.FullExpand;
Tree.ShowButtons:=false;
end
else begin
Tree.FullCollapse;
if sel<>nil then begin
if sel.AbsoluteIndex<>0 then sel.Parent.Expand(false);
sel.Expand(true);
end;
Tree.ShowButtons:=true;
end;
Tree.Select(sel);
if sel<>nil then begin
if sel.Parent<>nil then sel.Parent.MakeVisible;
sel.MakeVisible;
end;
except
on E: Exception do LogEvent('TTreeForm.FormShow encountered an exception: '+E.Message);
end;
end;
procedure TTreeForm.TreeDblClick(Sender: TObject);
var nm:longint;
vf:TViewForm;
begin
if (Pos(' ',Tree.Selected.Text)=0) or (Tree.Selected.Text[1]='(') then Exit;
nm:=strtoint(Copy(Tree.Selected.Text,1,Pos(' ',Tree.Selected.Text)-1))-1;
vf:=MainForm.PageList.ActivePage.Components[0] as TViewForm;
if vf<>nil then begin
vf.MsgList.Selected:=vf.MsgList.Items.Item[nm];
vf.MsgList.Selected.MakeVisible(false);
if vf.MsgList.ItemIndex<vf.MsgList.Items.Count-1 then
vf.MsgList.Items[vf.MsgList.Selected.Index+1].MakeVisible(false);
TreeForm.Close;
vf.Timer1.Enabled:=true;
end;
end;
procedure TTreeForm.FormCreate(Sender: TObject);
begin
Caption:=lang.ltree;
end;
procedure TTreeForm.TreeCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
begin
if SetupForm.TreeFullExpand.Checked then
AllowCollapse:=false;
end;
end.