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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
/* ========================================================================
Custom Status List
__________________
Custom Status List plugin for Miranda-IM (www.miranda-im.org)
Follower of Custom Status History List by HANAX
Copyright © 2006-2008 HANAX
Copyright © 2007-2009 jarvis
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.
DESCRIPTION:
Offers List of your Custom Statuses.
============================================================================
// ====[ INCLUDES AND DEFINITIONS ]======================================== */
#ifndef __CSLIST_H
#define __CSLIST_H 1
#define WINVER 0x501
#define _WIN32_WINNT 0x501
#define _WIN32_IE 0x600
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <newpluginapi.h>
#include <m_database.h>
#include <m_system_cpp.h>
#include <m_langpack.h>
#include <m_clistint.h>
#include <m_icolib.h>
#include <m_protosvc.h>
#include <m_xstatus.h>
#include <m_options.h>
#include <m_hotkeys.h>
#include <m_variables.h>
#include <win2k.h>
#include "resource.h"
#include "version.h"
// ====[ BASIC DEFINITIONS ]==================================================
#define MODULENAME LPGEN("Custom Status List")
#define MODNAME "CSList"
// ====[ LIMITS ]=============================================================
#define EXTRASTATUS_TITLE_LIMIT 64 // limit of chars for extra status title
#define EXTRASTATUS_MESSAGE_LIMIT 2048 // limit of chars for extra status message
// ====[ DEFAULT DB VALUES ]==================================================
#define DEFAULT_ICQ_XSTATUS_ENABLED 1
#define DEFAULT_PLUGIN_SHOW_RELNOTES 0
#define DEFAULT_PLUGIN_SHOW_NONSTANDARD_XSTATUSES 1
#define DEFAULT_PLUGIN_CONFIRM_ITEMS_DELETION 1
#define DEFAULT_PLUGIN_DELETE_AFTER_IMPORT 0
#define DEFAULT_ITEMS_COUNT 0
#define DEFAULT_ITEM_ICON 0
#define DEFAULT_ITEM_IS_FAVOURITE 0
#define DEFAULT_ALLOW_EXTRA_ICONS 1
#define DEFAULT_REMEMBER_WINDOW_POSITION 1
// ====[ FUNCTION MACROS ]====================================================
// set which row is selected (cannot be only focused, but fully selected - second param ;))
#define ListView_GetSelectedItemMacro( hwnd ) ListView_GetNextItem( hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED );
#ifndef ListView_SetSelectionMark
#define ListView_SetSelectionMark( x, y ) 0
#endif
#define getByte(setting, error) db_get_b(NULL, MODNAME, setting, error)
#define setByte(setting, value) db_set_b(NULL, MODNAME, setting, value)
#define getWord(setting, error) db_get_w(NULL, MODNAME, setting, error)
#define setWord(setting, value) db_set_w(NULL, MODNAME, setting, value)
#define getDword(setting, error) db_get_dw(NULL, MODNAME, setting, error)
#define setDword(setting, value) db_set_dw(NULL, MODNAME, setting, value)
#define getTString(setting, dest) db_get_ts(NULL, MODNAME, setting, dest)
#define setTString(setting, value) db_set_ts(NULL, MODNAME, setting, value)
#define deleteSetting(setting) db_unset(NULL, MODNAME, setting)
// --
typedef void (__cdecl *pForAllProtosFunc)( char*, void *);
// ====[ STRUCTURES ]=========================================================
struct StatusItem // list item structure
{
int m_iIcon;
TCHAR m_tszTitle[EXTRASTATUS_TITLE_LIMIT];
TCHAR m_tszMessage[EXTRASTATUS_MESSAGE_LIMIT];
BOOL m_bFavourite;
StatusItem()
{
m_iIcon = 0;
lstrcpy(m_tszTitle, _T(""));
lstrcpy(m_tszMessage, _T(""));
m_bFavourite = FALSE;
}
StatusItem( const StatusItem& p )
{
m_iIcon = p.m_iIcon;
lstrcpy( m_tszTitle, p.m_tszTitle );
lstrcpy( m_tszMessage, p.m_tszMessage );
m_bFavourite = p.m_bFavourite;
}
~StatusItem()
{
}
};
static struct CSForm { // icons + buttons
int idc;
TCHAR* ptszTitle;
TCHAR* ptszDescr;
char * pszIconIcoLib;
int iconNoIcoLib;
HANDLE hIcoLibItem;
} forms[] = {
{ -1, LPGENT("Main Menu"), LPGENT("Main Icon"), "icon", IDI_CSLIST },
{ IDC_ADD, LPGENT("Add new item"), LPGENT("Add"), "add", IDI_ADD },
{ IDC_MODIFY, LPGENT("Modify selected item"), LPGENT("Modify"), "modify", IDI_MODIFY },
{ IDC_REMOVE, LPGENT("Delete selected item"), LPGENT("Remove"), "remove", IDI_REMOVE },
{ IDC_FAVOURITE, LPGENT("Set/unset current item as favorite"), LPGENT("Favorite"), "favourite", IDI_FAVOURITE },
{ IDC_UNDO, LPGENT("Undo changes"), LPGENT("Undo changes"), "undo", IDI_UNDO },
{ IDC_IMPORT, LPGENT("Import statuses from database"), LPGENT("Import"), "import", IDI_IMPORT },
{ IDC_FILTER, LPGENT("Filter list"), LPGENT("Filter"), "filter", IDI_FILTER },
{ IDCLOSE, LPGENT("Close without changing custom status"), LPGENT("No change"), "nochng", IDI_CLOSE },
{ IDC_CANCEL, LPGENT("Clear custom status (reset to None) and close"), LPGENT("Clear"), "clear", IDI_UNSET },
{ IDOK, LPGENT("Set custom status to selected one and close"), LPGENT("Set"), "apply", IDI_APPLY }
};
// ====[ MY BITCHY LIST IMPLEMENTATION x)) ]==================================
// TODO: Optimize it all x))
template< class T > struct ListItem
{
T* m_item;
ListItem* m_next;
ListItem()
{
m_item = NULL;
m_next = NULL;
}
~ListItem()
{
delete m_item;
}
ListItem( StatusItem* si )
{
m_item = si;
m_next = NULL;
}
ListItem( const ListItem& p )
{
m_item = p.item;
m_next = NULL;
}
};
template< class T > struct List
{
private:
ListItem< T >* m_items;
unsigned int m_count;
public:
typedef int ( *compareFunc )( const T* p1, const T* p2 );
compareFunc m_compare;
List( compareFunc compFnc )
{
m_items = NULL;
m_count = 0;
m_compare = compFnc;
}
~List()
{
destroy();
}
ListItem< T >* getListHead()
{
return m_items;
}
unsigned int getCount()
{
return m_count;
}
int add( T* csi )
{
int position = 0;
ListItem< T >* item = new ListItem< T >( csi );
if ( m_items == NULL )
m_items = item;
else
{
ListItem< T >* help = item;
item->m_next = m_items;
while ( help->m_next != NULL )
{
int cmp = m_compare( item->m_item, help->m_next->m_item );
if ( cmp == 1 )
help = help->m_next;
else if ( cmp == 0 )
{
delete item;
return -1;
}
else
break;
position++;
}
if ( help != item )
{
item->m_next = help->m_next;
help->m_next = item;
}
else m_items = item;
}
m_count++;
return position;
}
int remove(const unsigned int item)
{
int position = 0;
if (item >= m_count)
return -1;
ListItem< T >* help = m_items;
ListItem< T >* removed;
if ( item == 0 )
{
m_items = m_items->m_next;
removed = help;
}
else
{
for ( unsigned int i = 0; i < item - 1; i++ )
{
help = help->m_next;
position++;
}
removed = help->m_next;
help->m_next = help->m_next->m_next;
}
delete removed;
m_count--;
return position;
}
T* get( const unsigned int item )
{
ListItem< T >* help = m_items;
for ( unsigned int i = 0; i < item; i++ )
help = help->m_next;
return help->m_item;
}
T* operator[]( const unsigned int item )
{
return get( item );
}
void destroy()
{
while ( m_count > 0 )
remove( 0 );
}
};
// ====[ CLASSING -- FUNNY STUFF :) ]=========================================
struct CSWindow;
struct CSAMWindow;
struct CSListView
{
HWND m_handle;
CSWindow* m_parent;
CSListView( HWND, CSWindow* );
void addItem( StatusItem* item, int itemNumber );
void initItems( ListItem< StatusItem >* items );
void reinitItems( ListItem< StatusItem >* items );
void removeItems();
int getPositionInList();
void setFullFocusedSelection( int selection );
};
struct CSItemsList
{
List< StatusItem > *m_list;
static int compareItems( const StatusItem* p1, const StatusItem* p2 );
void loadItems(char *protoName);
void saveItems(char *protoName);
CSItemsList(char *protoName);
~CSItemsList();
};
struct CSWindow
{
HWND m_handle;
BOOL m_bExtraIcons;
CSItemsList* m_itemslist;
CSListView* m_listview;
CSAMWindow* m_addModifyDlg;
HIMAGELIST m_icons;
int m_statusCount;
BOOL m_bSomethingChanged;
TCHAR* m_filterString;
char * m_protoName;
CSWindow(char *protoName);
~CSWindow();
void initIcons();
void deinitIcons();
void initButtons();
void loadWindowPosition();
BOOL toggleButtons();
void toggleEmptyListMessage();
void toggleFilter();
BOOL itemPassedFilter( ListItem< StatusItem >* li );
void __inline saveWindowPosition( HWND hwnd )
{
if (getByte("RememberWindowPosition", DEFAULT_REMEMBER_WINDOW_POSITION) == TRUE)
Utils_SaveWindowPosition(hwnd, NULL, MODNAME, "Position");
}
};
struct CSAMWindow
{
WORD m_action;
StatusItem* m_item;
CSWindow* m_parent;
BOOL m_bChanged;
HWND m_handle;
HWND m_hCombo;
HWND m_hMessage;
CSAMWindow( WORD action, CSWindow* parent );
~CSAMWindow();
void exec();
void setCombo();
void fillDialog();
void checkFieldLimit( WORD action, WORD item );
void checkItemValidity();
};
// service functions
INT_PTR __cdecl showList(WPARAM, LPARAM, LPARAM);
// protocols enumeration related functions
void addProtoStatusMenuItem(char *protoName);
// other functions
void IitIcoLib();
void RegisterHotkeys(char buf[200], TCHAR* accName, int Number);
void SetStatus(WORD code, StatusItem* item, char *protoName);
// ====[ PROCEDURES ]=========================================================
INT_PTR CALLBACK CSWindowProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
INT_PTR CALLBACK CSAMWindowProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
INT_PTR CALLBACK CSRNWindowProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
INT_PTR CALLBACK CSOptionsProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
#endif /* __CSLIST_H */
|