forked from HemulGM/IMJabber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IM.Roster.pas
136 lines (120 loc) · 3.94 KB
/
IM.Roster.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
unit IM.Roster;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids,
HGM.Controls.VirtualTable, IM.Classes, HGM.Button, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TFormRosterList = class(TForm)
TableExRoster: TTableEx;
PanelTop: TPanel;
Label1: TLabel;
PanelTopSearch: TPanel;
PanelSearch: TPanel;
EditSearch: TEdit;
ButtonFlatSearchClear: TButtonFlat;
ButtonFlat1: TButtonFlat;
Shape1: TShape;
PanelBottom: TPanel;
Shape2: TShape;
ButtonFlatOK: TButtonFlat;
ButtonFlatCancel: TButtonFlat;
procedure TableExRosterDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure TableExRosterItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
procedure EditSearchChange(Sender: TObject);
procedure ButtonFlatOKClick(Sender: TObject);
procedure ButtonFlatCancelClick(Sender: TObject);
private
FRosterList: TRosterList;
procedure SetRosterList(const Value: TRosterList);
public
property RosterList: TRosterList read FRosterList write SetRosterList;
class function Execute(Roster: TRosterList; var Index: Integer): Boolean;
end;
var
FormRosterList: TFormRosterList;
implementation
uses
IM.Main, HGM.Common.Utils;
{$R *.dfm}
procedure TFormRosterList.ButtonFlatCancelClick(Sender: TObject);
begin
Close;
end;
procedure TFormRosterList.ButtonFlatOKClick(Sender: TObject);
begin
if FRosterList.CheckedCount < 1 then Exit;
ModalResult := mrOK;
end;
procedure TFormRosterList.EditSearchChange(Sender: TObject);
begin
ButtonFlatSearchClear.Visible := EditSearch.Text <> '';
end;
class function TFormRosterList.Execute(Roster: TRosterList; var Index: Integer): Boolean;
begin
with TFormRosterList.Create(nil) do
begin
//Prepare
RosterList := Roster;
RosterList.AddTable(TableExRoster);
RosterList.UnCheckAll;
RosterList.UpdateTable;
TableExRoster.UpdateMaxColumn;
//Show
Result := ShowModal = mrOk;
//Apply
Index := TableExRoster.ItemIndex;
RosterList.UnAssignTable(TableExRoster);
//Final
Free;
end;
end;
procedure TFormRosterList.SetRosterList(const Value: TRosterList);
begin
FRosterList := Value;
end;
procedure TFormRosterList.TableExRosterDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if not FRosterList.IndexIn(ARow) then
Exit;
with TableExRoster.Canvas do
begin
case ACol of
0:
begin
Rect.Inflate(-4, -4);
if Assigned(FRosterList[ARow].Avatar) then
Draw(Rect.Left, Rect.Top, FRosterList[ARow].Avatar);
if FRosterList.Checked[ARow] then
FormMain.ImageList16.Draw(TableExRoster.Canvas, Rect.Right - 15, Rect.Bottom - 15, 0, True)
else
FormMain.ImageList16.Draw(TableExRoster.Canvas, Rect.Right - 15, Rect.Bottom - 15, 1, True);
end;
1:
begin
Font.Name := 'Segoe UI';
Font.Color := clWhite;
if FRosterList[ARow].Name.IsEmpty then
TextOut(Rect.Left, Rect.Top + 3, FRosterList[ARow].JID)
else
TextOut(Rect.Left, Rect.Top + 3, FRosterList[ARow].Name);
Font.Color := $00CFCFCF;
if FRosterList[ARow].LastMessage.Unread then
begin
TextOut(Rect.Left, Rect.Top + 22, FRosterList[ARow].LastMessage.Body);
FormMain.ImageListStatuses.Draw(TableExRoster.Canvas, Rect.Right - 20, Rect.Top + 2, 7, True);
end
else
begin
TextOut(Rect.Left, Rect.Top + 22, FRosterList[ARow].GetDisplayStatus);
end;
end;
end;
end;
end;
procedure TFormRosterList.TableExRosterItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
begin
FRosterList.Checked[Index] := not FRosterList.Checked[Index];
TableExRoster.ItemIndex := -1;
end;
end.