You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RnQ/RnQ/Nodes.pas

218 lines
5.0 KiB
Plaintext

{
This file is part of R&Q.
Under same license
}
unit Nodes;
{$I RnQConfig.inc}
interface
uses
Winapi.Windows, System.Classes,
ICQCommon, ICQContacts;
{$I PubRTTI.inc}
type
TDivisor = (d_online, d_offline, d_contacts, d_nil, d_recent);
PNode = ^TNode;
TNode = class
public
kind: Integer;
contact: TICQContact;
divisor: TDivisor;
groupId: Integer;
textOfs: Integer;
outboxRect: TRect;
order: Integer;
parent: TNode;
constructor Create(divisor_: TDivisor); overload;
constructor Create(groupId_: Integer; divisor_: TDivisor); overload;
constructor Create(divisor_: TDivisor; contact_: TICQContact); overload;
destructor Destroy; override;
procedure SetExpanded(val: Boolean; recur: Boolean = False);
function isVisible: Boolean;
function ChildrenCount: Integer;
function firstChild: TNode;
function level: Integer;
function next: TNode;
function prev: TNode;
end;
function GetContactNode(const UID: TUID): TNode;
function GetGroupNode(Divisor: TDivisor; GroupID: Integer): TNode;
function GetFirstGroupNode(GroupID: Integer): TNode;
// function GetNode(Kind: Integer; Divisor: TDivisor; GroupID: Integer = 0; UID: TUID = ''): TNode;
const
divsWithGroups = [d_online, d_contacts, d_offline, d_recent];
divisor2str: array [TDivisor] of AnsiString = ('online', 'offline', 'contacts', 'not in list', 'recent');
divisor2ShowStr: array [TDivisor] of string = ('Online', 'Offline', 'Contacts', 'Not in list', 'Recently went offline');
NODE_ROOT = 0;
NODE_DIV = 1;
NODE_GROUP = 2;
NODE_CONTACT = 3;
var
divs: array [TDivisor] of TNode;
contactsPool: TList;
implementation
uses
GlobalLib, GroupsLib,
ICQConsts,
mainDlg;
function GetContactNode(const UID: TUID): TNode;
var
Contact: TICQContact;
begin
Result := nil;
Contact := Account.AccProto.GetContact(UID);
if Assigned(Contact) then
Result := TCE(Contact.data^).Node;
end;
function GetGroupNode(Divisor: TDivisor; GroupID: Integer): TNode;
var
Group: TGroup;
begin
Result := nil;
Group := groups.Get(GroupID);
if Group.ID > 0 then
if Assigned(Group.Node[Divisor]) then
Result := Group.Node[Divisor];
end;
function GetFirstGroupNode(GroupID: Integer): TNode;
var
Divisor: TDivisor;
Group: TGroup;
begin
Result := nil;
Group := groups.Get(GroupID);
if Group.ID > 0 then
for Divisor := Low(TDivisor) to High(TDivisor) do
if Assigned(Group.Node[Divisor]) then
begin
Result := Group.Node[Divisor];
Break;
end;
end;
//function GetNode(Kind: Integer; Divisor: TDivisor; GroupID: Integer = 0; UID: TUID = ''): TNode;
//var
// Group: TGroup;
// Contact: TICQContact;
//begin
// Result := nil;
// if Kind = NODE_DIV then
// Result := divs[Divisor]
// else if Kind = NODE_GROUP then
// Result := GetGroupNode(Divisor, GroupID)
// else if Kind = NODE_CONTACT then
// Result := GetContactNode(UID);
//end;
constructor TNode.Create(divisor_: TDivisor);
begin
inherited Create;
kind := NODE_DIV;
divisor := divisor_;
end; // Create
constructor TNode.Create(groupId_: Integer; divisor_: TDivisor);
begin
inherited Create;
kind := NODE_GROUP;
groupId := groupId_;
divisor := divisor_;
end; // Create
constructor TNode.Create(divisor_: TDivisor; contact_: TICQContact);
begin
inherited Create;
kind := NODE_CONTACT;
contact := contact_;
groupId := contact_.group;
divisor := divisor_;
TCE(contact_.data^).Node := Self;
contactsPool.add(self);
end; // Create
destructor TNode.Destroy;
begin
case kind of
NODE_CONTACT:
begin
contactsPool.remove(Self);
TCE(contact.data^).Node := nil;
end;
NODE_GROUP:
groups.SetNode(groupId, divisor, nil);
NODE_DIV:
divs[divisor] := nil;
end;
inherited;
end; // Destroy
function TNode.ChildrenCount: Integer;
begin
case kind of
NODE_GROUP:
Result := Account.AccProto.readList(LT_ROSTER).GetCount(groupId, Integer(divisor));
NODE_DIV:
Result := groups.GetCount(divisor);
else
Result := 0
end;
end;
function TNode.FirstChild: TNode;
begin
Result := nil; {!!!}
end;
function TNode.Next: TNode;
begin
Result := nil; {!!!}
end;
function TNode.Prev: TNode;
begin
Result := nil; {!!!}
end;
function TNode.Level: Integer;
begin
Result := 0; {!!!}
end;
function TNode.IsVisible: Boolean;
//var
// n, root: PVirtualNode;
begin
Result := True;
{!!!}
// n := treenode;
//
// Result := vsVisible in n.states;
// repeat
// n := n.parent;
// if n <> root then
// Result := (vsVisible in n.states) and (vsExpanded in n.states);
// until not Result or (n = root);
end; // IsVisible
procedure TNode.SetExpanded(val: Boolean; recur: Boolean = False);
begin
if kind = NODE_GROUP then
RnQmain.CLBox.SetGroupState(Self, val);
end; // SetExpanded
end.