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
229
230
231
232
233
234
235
236
237
238
239
|
/*
Miranda IM: the free IM client for Microsoft* Windows*
Copyright 2000-2006 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "commonheaders.h"
#include "clc.h"
static int GetHwnd(WPARAM wParam, LPARAM lParam)
{
return (int)cli.hwndContactList;
}
static int GetHwndTree(WPARAM wParam,LPARAM lParam)
{
return (int)cli.hwndContactTree;
}
static int CluiProtocolStatusChanged(WPARAM wParam, LPARAM lParam)
{
cli.pfnCluiProtocolStatusChanged( wParam, (const char*)lParam );
return 0;
}
int SortList(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int GroupAdded(WPARAM wParam, LPARAM lParam)
{
//CLC does this automatically unless it's a new group
if (lParam) {
HANDLE hItem;
TCHAR szFocusClass[64];
HWND hwndFocus = GetFocus();
GetClassName(hwndFocus, szFocusClass, SIZEOF(szFocusClass));
if (!lstrcmp(szFocusClass, CLISTCONTROL_CLASS)) {
hItem = (HANDLE) SendMessage(hwndFocus, CLM_FINDGROUP, wParam, 0);
if (hItem)
SendMessage(hwndFocus, CLM_EDITLABEL, (WPARAM) hItem, 0);
}
}
return 0;
}
static int ContactSetIcon(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int ContactDeleted(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int ContactAdded(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int ListBeginRebuild(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int ListEndRebuild(WPARAM wParam, LPARAM lParam)
{
int rebuild = 0;
//CLC does this automatically, but we need to force it if hideoffline or hideempty has changed
if ((DBGetContactSettingByte(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT) == 0) != ((GetWindowLong(cli.hwndContactTree, GWL_STYLE) & CLS_HIDEOFFLINE) == 0)) {
if (DBGetContactSettingByte(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT))
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) | CLS_HIDEOFFLINE);
else
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) & ~CLS_HIDEOFFLINE);
rebuild = 1;
}
if ((DBGetContactSettingByte(NULL, "CList", "HideEmptyGroups", SETTING_HIDEEMPTYGROUPS_DEFAULT) == 0) != ((GetWindowLong(cli.hwndContactTree, GWL_STYLE) & CLS_HIDEEMPTYGROUPS) == 0)) {
if (DBGetContactSettingByte(NULL, "CList", "HideEmptyGroups", SETTING_HIDEEMPTYGROUPS_DEFAULT))
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) | CLS_HIDEEMPTYGROUPS);
else
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) & ~CLS_HIDEEMPTYGROUPS);
rebuild = 1;
}
if ((DBGetContactSettingByte(NULL, "CList", "UseGroups", SETTING_USEGROUPS_DEFAULT) == 0) != ((GetWindowLong(cli.hwndContactTree, GWL_STYLE) & CLS_USEGROUPS) == 0)) {
if (DBGetContactSettingByte(NULL, "CList", "UseGroups", SETTING_USEGROUPS_DEFAULT))
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) | CLS_USEGROUPS);
else
SetWindowLong(cli.hwndContactTree, GWL_STYLE, GetWindowLong(cli.hwndContactTree, GWL_STYLE) & ~CLS_USEGROUPS);
rebuild = 1;
}
if (rebuild)
SendMessage(cli.hwndContactTree, CLM_AUTOREBUILD, 0, 0);
return 0;
}
static int ContactRenamed(WPARAM wParam, LPARAM lParam)
{
//unnecessary: CLC does this automatically
return 0;
}
static int GetCaps(WPARAM wParam, LPARAM lParam)
{
switch (wParam) {
case CLUICAPS_FLAGS1:
return CLUIF_HIDEEMPTYGROUPS | CLUIF_DISABLEGROUPS | CLUIF_HASONTOPOPTION | CLUIF_HASAUTOHIDEOPTION;
}
return 0;
}
int LoadCluiServices(void)
{
CreateServiceFunction(MS_CLUI_GETHWND, GetHwnd);
CreateServiceFunction(MS_CLUI_GETHWNDTREE,GetHwndTree);
CreateServiceFunction(MS_CLUI_PROTOCOLSTATUSCHANGED, CluiProtocolStatusChanged);
CreateServiceFunction(MS_CLUI_GROUPADDED, GroupAdded);
CreateServiceFunction(MS_CLUI_CONTACTSETICON, ContactSetIcon);
CreateServiceFunction(MS_CLUI_CONTACTADDED, ContactAdded);
CreateServiceFunction(MS_CLUI_CONTACTDELETED, ContactDeleted);
CreateServiceFunction(MS_CLUI_CONTACTRENAMED, ContactRenamed);
CreateServiceFunction(MS_CLUI_LISTBEGINREBUILD, ListBeginRebuild);
CreateServiceFunction(MS_CLUI_LISTENDREBUILD, ListEndRebuild);
CreateServiceFunction(MS_CLUI_SORTLIST, SortList);
CreateServiceFunction(MS_CLUI_GETCAPS, GetCaps);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// default protocol status notification handler
int fnCluiProtocolStatusChanged(int parStatus, const char* szProto)
{
int protoCount, i;
PROTOCOLDESCRIPTOR **proto;
int *partWidths, partCount;
int borders[3];
int status;
int flags = 0;
SendMessage(cli.hwndStatus, SB_GETBORDERS, 0, (LPARAM) & borders);
CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM) & protoCount, (LPARAM) & proto);
if (protoCount == 0)
return 0;
partWidths = (int *) mir_alloc(protoCount * sizeof(int));
if (DBGetContactSettingByte(NULL, "CLUI", "EqualSections", 0)) {
RECT rc;
int part;
GetClientRect(cli.hwndStatus, &rc);
rc.right -= borders[0] * 2 + (DBGetContactSettingByte(NULL, "CLUI", "ShowGrip", 1) ? GetSystemMetrics(SM_CXVSCROLL) : 0);
for (partCount = 0, i = protoCount - 1; i >= 0; i--)
if (proto[i]->type == PROTOTYPE_PROTOCOL && CallProtoService(proto[i]->szName, PS_GETCAPS, PFLAGNUM_2, 0) != 0)
partCount++;
for (part = 0, i = 0; i < protoCount; i++) {
if (proto[i]->type != PROTOTYPE_PROTOCOL)
continue;
partWidths[part] = (part + 1) * rc.right / partCount - (borders[2] >> 1);
part++;
}
}
else {
char *modeDescr;
HDC hdc;
SIZE textSize;
BYTE showOpts = DBGetContactSettingByte(NULL, "CLUI", "SBarShow", 1);
int x;
char szName[32];
hdc = GetDC(NULL);
SelectObject(hdc, (HFONT) SendMessage(cli.hwndStatus, WM_GETFONT, 0, 0));
for (partCount = 0, i = protoCount - 1; i >= 0; i--) { //count down since built in ones tend to go at the end
if (proto[i]->type != PROTOTYPE_PROTOCOL || CallProtoService(proto[i]->szName, PS_GETCAPS, PFLAGNUM_2, 0) == 0)
continue;
x = 2;
if (showOpts & 1)
x += g_IconWidth;
if (showOpts & 2) {
CallProtoService(proto[i]->szName, PS_GETNAME, SIZEOF(szName), (LPARAM) szName);
if (showOpts & 4 && lstrlenA(szName) < SIZEOF(szName) - 1)
lstrcatA(szName, " ");
GetTextExtentPoint32A(hdc, szName, lstrlenA(szName), &textSize);
x += textSize.cx;
x += GetSystemMetrics(SM_CXBORDER) * 4; // The SB panel doesnt allocate enough room
}
if (showOpts & 4) {
modeDescr = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, CallProtoService(proto[i]->szName, PS_GETSTATUS, 0, 0), 0);
GetTextExtentPoint32A(hdc, modeDescr, lstrlenA(modeDescr), &textSize);
x += textSize.cx;
x += GetSystemMetrics(SM_CXBORDER) * 4; // The SB panel doesnt allocate enough room
}
partWidths[partCount] = (partCount ? partWidths[partCount - 1] : 0) + x + 2;
partCount++;
}
ReleaseDC(NULL, hdc);
}
if (partCount == 0) {
mir_free(partWidths);
return 0;
}
partWidths[partCount - 1] = -1;
SendMessage(cli.hwndStatus, SB_SETMINHEIGHT, g_IconHeight, 0);
SendMessage(cli.hwndStatus, SB_SETPARTS, partCount, (LPARAM) partWidths);
mir_free(partWidths);
flags = SBT_OWNERDRAW;
if (DBGetContactSettingByte(NULL, "CLUI", "SBarBevel", 1) == 0)
flags |= SBT_NOBORDERS;
for (partCount = 0, i = protoCount - 1; i >= 0; i--) { //count down since built in ones tend to go at the end
// okay, so it was a bug ;)
if (proto[i]->type != PROTOTYPE_PROTOCOL || (CallProtoService(proto[i]->szName, PS_GETCAPS, PFLAGNUM_2, 0) == 0))
continue;
status = CallProtoService(proto[i]->szName, PS_GETSTATUS, 0, 0);
SendMessage(cli.hwndStatus, SB_SETTEXT, partCount | flags, (LPARAM) proto[i]->szName);
partCount++;
}
return 0;
}
|