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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
#include "common.h"
#define OLD_TBBUTTON_SIZE (offsetof(TTBButton, pszTooltipUp))
pfnCustomProc g_CustomProc = NULL;
LPARAM g_CustomProcParam = 0;
TTBCtrl *g_ctrl = NULL;
INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam);
HWND hwndContactList = 0;
int nextButtonId = 200;
HANDLE hTTBModuleLoaded;
static WNDPROC buttonWndProc;
mir_cs csButtonsHook;
int sortfunc(const TopButtonInt *a, const TopButtonInt *b)
{
return a->arrangedpos - b->arrangedpos;
}
LIST<TopButtonInt> Buttons(8, sortfunc);
TopButtonInt *idtopos(int id, int *pPos)
{
for (int i = 0; i < Buttons.getCount(); i++)
if (Buttons[i]->id == id) {
if (pPos)
*pPos = i;
return Buttons[i];
}
if (pPos)
*pPos = -1;
return NULL;
}
//----- Service buttons -----
void InsertSBut(int i)
{
TTBButton ttb = {0};
ttb.cbSize = sizeof(ttb);
ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_RUN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_RUN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISSBUTTON | TTBBF_INTERNAL;
ttb.wParamDown = i;
TTBAddButton((WPARAM)&ttb, 0);
}
void LoadAllSButs()
{
//must be locked
int cnt = db_get_b(0, TTB_OPTDIR, "ServiceCnt", 0);
if (cnt > 0) {
for (int i = 1; i <= cnt; i++)
InsertSBut(i);
}
}
//----- Launch buttons -----
INT_PTR LaunchService(WPARAM, LPARAM lParam)
{
PROCESS_INFORMATION pi;
STARTUPINFO si = {0};
si.cb = sizeof(si);
if (CreateProcess(NULL, Buttons[lParam]->ptszProgram, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
return 0;
}
void InsertLBut(int i)
{
TTBButton ttb = {0};
ttb.cbSize = sizeof(ttb);
ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_RUN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISLBUTTON | TTBBF_INTERNAL;
ttb.name = LPGEN("Default");
ttb.program = _T("Execute Path");
ttb.wParamDown = i;
TTBAddButton((WPARAM)&ttb, 0);
}
void LoadAllLButs()
{
//must be locked
int cnt = db_get_b(0, TTB_OPTDIR, "LaunchCnt", 0);
for (int i = 0; i < cnt; i++)
InsertLBut(i);
}
//----- Separators -----
void InsertSeparator(int i)
{
TTBButton ttb = {0};
ttb.cbSize = sizeof(ttb);
ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISSEPARATOR | TTBBF_INTERNAL;
ttb.wParamDown = i;
TTBAddButton((WPARAM)&ttb, 0);
}
void LoadAllSeparators()
{
//must be locked
int cnt = db_get_b(0, TTB_OPTDIR, "SepCnt", 0);
for (int i = 0; i < cnt; i++)
InsertSeparator(i);
}
int SaveAllButtonsOptions()
{
int SeparatorCnt = 0;
int LaunchCnt = 0;
{
mir_cslock lck(csButtonsHook);
for (int i = 0; i < Buttons.getCount(); i++)
Buttons[i]->SaveSettings(&SeparatorCnt, &LaunchCnt);
}
db_set_b(0, TTB_OPTDIR, "SepCnt", SeparatorCnt);
db_set_b(0, TTB_OPTDIR, "LaunchCnt", LaunchCnt);
return 0;
}
static bool nameexists(const char *name)
{
if (name == NULL)
return false;
for (int i = 0; i < Buttons.getCount(); i++)
if (!mir_strcmp(Buttons[i]->pszName, name))
return true;
return false;
}
static void Icon2button(TTBButton *but, HANDLE &hIcoLib, HICON &hIcon, bool bIsUp)
{
HANDLE hSrc = bIsUp ? but->hIconHandleUp : but->hIconHandleDn;
if (hSrc == NULL) {
hIcoLib = NULL, hIcon = NULL;
return;
}
hIcoLib = IcoLib_IsManaged((HICON)hSrc);
if (!hIcoLib) {
char buf[256];
mir_snprintf(buf, "toptoolbar_%s%s", but->name, bIsUp ? (but->hIconDn ? "%s_up" : "%s") : "%s_dn");
SKINICONDESC sid = { 0 };
sid.section.a = "Toolbar";
sid.pszName = buf;
sid.defaultFile.a = NULL;
mir_snprintf(buf, "%s%s", but->name, bIsUp ? "" : " (pressed)");
sid.description.a = buf;
sid.hDefaultIcon = bIsUp ? but->hIconUp : but->hIconDn;
hIcoLib = IcoLib_AddIcon(&sid);
}
hIcon = IcoLib_GetIconByHandle(hIcoLib);
}
TopButtonInt *CreateButton(TTBButton *but)
{
TopButtonInt *b = new TopButtonInt;
b->id = nextButtonId++;
b->dwFlags = but->dwFlags;
b->wParamUp = but->wParamUp;
b->lParamUp = but->lParamUp;
b->wParamDown = but->wParamDown;
b->lParamDown = but->lParamDown;
if (!(b->dwFlags & TTBBF_ISSEPARATOR)) {
b->bPushed = (but->dwFlags & TTBBF_PUSHED) ? TRUE : FALSE;
if (but->dwFlags & TTBBF_ISLBUTTON) {
b->ptszProgram = mir_tstrdup(but->program);
b->pszService = mir_strdup(TTB_LAUNCHSERVICE);
}
else {
b->ptszProgram = NULL;
b->pszService = mir_strdup(but->pszService);
}
b->pszName = mir_strdup(but->name);
Icon2button(but, b->hIconHandleUp, b->hIconUp, true);
Icon2button(but, b->hIconHandleDn, b->hIconDn, false);
if (but->cbSize > OLD_TBBUTTON_SIZE) {
b->ptszTooltipUp = mir_a2t(but->pszTooltipUp);
b->ptszTooltipDn = mir_a2t(but->pszTooltipDn);
}
}
return b;
}
int ArrangeButtons()
{
mir_cslock lck(csButtonsHook);
RECT rcClient;
GetClientRect(g_ctrl->hWnd, &rcClient);
int nBarSize = rcClient.right - rcClient.left;
if (nBarSize == 0)
return 0;
int nLineCount = 0;
int i, ypos = 1, xpos = g_ctrl->nButtonSpace, nextX = 0, y = 0;
int newheight = g_ctrl->nButtonHeight + 1, nButtonCount = 0;
for (i = 0; i < Buttons.getCount(); i++)
if (Buttons[i]->hwnd)
nButtonCount++;
if (nButtonCount == 0)
return 0;
HDWP hdwp = BeginDeferWindowPos(nButtonCount);
bool bWasButttonBefore;
int nUsedWidth, iFirstButtonId = 0, iLastButtonId = 0;
do {
nLineCount++;
bWasButttonBefore = false;
nUsedWidth = 0;
for (i = iFirstButtonId; i < Buttons.getCount(); i++) {
TopButtonInt *b = Buttons[i];
if (b->hwnd == NULL)
continue;
int width = 0;
if (b->isVisible())
width = b->isSep() ? SEPWIDTH + 2 : g_ctrl->nButtonWidth + (bWasButttonBefore ? g_ctrl->nButtonSpace : 0);
if (nUsedWidth + width > nBarSize)
break;
nUsedWidth += width;
iLastButtonId = i + 1;
bWasButttonBefore = !b->isSep();
}
int nFreeSpace = nBarSize - nUsedWidth;
for (i = iFirstButtonId; i < iLastButtonId; i++) {
TopButtonInt *b = Buttons[i];
if (b->hwnd == NULL)
continue;
bool bOldVisible = IsWindowVisible(b->hwnd) != 0;
if (bOldVisible != b->isVisible())
g_ctrl->bOrderChanged = TRUE;
if (b->isVisible()) {
if (NULL != b->hwnd) /* Wine fix. */
hdwp = DeferWindowPos(hdwp, b->hwnd, NULL, nextX, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
if (b->isSep())
nextX += SEPWIDTH + 2;
else
nextX += g_ctrl->nButtonWidth + g_ctrl->nButtonSpace;
} else {
if (NULL != Buttons[i]->hwnd) /* Wine fix. */
hdwp = DeferWindowPos(hdwp, Buttons[i]->hwnd, NULL, nextX, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW);
}
}
if (iFirstButtonId == iLastButtonId)
break;
iFirstButtonId = iLastButtonId;
y += g_ctrl->nButtonHeight + g_ctrl->nButtonSpace;
nextX = 0;
if (g_ctrl->bSingleLine)
break;
} while (iFirstButtonId < Buttons.getCount() && y >= 0 && (g_ctrl->bAutoSize || (y + g_ctrl->nButtonHeight <= rcClient.bottom - rcClient.top)));
for (i = iLastButtonId; i < Buttons.getCount(); i++) {
if (NULL != Buttons[i]->hwnd) /* Wine fix. */
hdwp = DeferWindowPos(hdwp, Buttons[i]->hwnd, NULL, nextX, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW);
}
if (hdwp)
EndDeferWindowPos(hdwp);
return (g_ctrl->nButtonHeight + g_ctrl->nButtonSpace) * nLineCount - g_ctrl->nButtonSpace;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Toolbar services
// wparam = (TTBButton*)lpTTBButton
// lparam = hLangpack
INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam)
{
if (wParam == 0)
return -1;
TTBButton *but = (TTBButton *)wParam;
if (but->cbSize != sizeof(TTBButton) && but->cbSize != OLD_TBBUTTON_SIZE)
return -1;
if (!(but->dwFlags & TTBBF_ISLBUTTON) && nameexists(but->name))
return -1;
TopButtonInt *b = CreateButton(but);
b->hLangpack = (int)lParam;
b->LoadSettings();
b->CreateWnd();
if (b->hwnd == NULL) {
delete b;
return -1;
}
mir_cslock lck(csButtonsHook);
Buttons.insert(b);
g_ctrl->bOrderChanged = TRUE;
ArrangeButtons();
AddToOptions(b);
return b->id;
}
// wparam = (HANDLE)hTTButton
// lparam = 0
INT_PTR TTBRemoveButton(WPARAM wParam, LPARAM)
{
mir_cslock lck(csButtonsHook);
int idx;
TopButtonInt *b = idtopos(wParam, &idx);
if (b == NULL)
return -1;
RemoveFromOptions(b->id);
Buttons.remove(idx);
delete b;
g_ctrl->bOrderChanged = TRUE;
ArrangeButtons();
return 0;
}
// wparam = hTTBButton
// lparam = state
INT_PTR TTBSetState(WPARAM wParam, LPARAM lParam)
{
mir_cslock lck(csButtonsHook);
TopButtonInt *b = idtopos(wParam);
if (b == NULL)
return -1;
b->bPushed = (lParam & TTBST_PUSHED) != 0;
b->SetBitmap();
return 0;
}
// wparam = hTTBButton
// lparam = 0
//return = state
INT_PTR TTBGetState(WPARAM wParam, LPARAM lParam)
{
mir_cslock lck(csButtonsHook);
TopButtonInt *b = idtopos(wParam);
if (b == NULL)
return -1;
return ((b->bPushed == TRUE) ? TTBST_PUSHED : 0);
}
INT_PTR TTBGetOptions(WPARAM wParam, LPARAM lParam)
{
mir_cslock lck(csButtonsHook);
TopButtonInt *b = idtopos(wParam);
if (b == NULL)
return -1;
switch (LOWORD(wParam)) {
case TTBO_FLAGS: {
INT_PTR retval = b->dwFlags & (~TTBBF_PUSHED);
if (b->bPushed)
retval |= TTBBF_PUSHED;
return retval;
}
case TTBO_TIPNAME:
return (INT_PTR)b->ptszTooltip;
case TTBO_ALLDATA:
if (lParam) {
lpTTBButton lpTTB = (lpTTBButton)lParam;
if (lpTTB->cbSize != sizeof(TTBButton))
return -1;
lpTTB->dwFlags = b->dwFlags & (~TTBBF_PUSHED);
if (b->bPushed)
lpTTB->dwFlags |= TTBBF_PUSHED;
lpTTB->hIconDn = b->hIconDn;
lpTTB->hIconUp = b->hIconUp;
lpTTB->lParamUp = b->lParamUp;
lpTTB->wParamUp = b->wParamUp;
lpTTB->lParamDown = b->lParamDown;
lpTTB->wParamDown = b->wParamDown;
if (b->dwFlags & TTBBF_ISLBUTTON)
replaceStrT(lpTTB->program, b->ptszProgram);
else
replaceStr(lpTTB->pszService, b->pszService);
return (INT_PTR)lpTTB;
}
else
return -1;
default:
return -1;
}
}
INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam)
{
mir_cslock lck(csButtonsHook);
TopButtonInt *b = idtopos(HIWORD(wParam));
if (b == NULL)
return -1;
switch (LOWORD(wParam)) {
case TTBO_FLAGS: {
if (b->dwFlags == lParam)
return 0;
DWORD retval = b->CheckFlags(lParam);
if (retval & TTBBF_PUSHED)
b->SetBitmap();
if (retval & TTBBF_VISIBLE) {
ArrangeButtons();
b->SaveSettings(0, 0);
}
return 1;
}
case TTBO_TIPNAME:
if (lParam == 0)
return -1;
replaceStrT(b->ptszTooltip, TranslateTS(_A2T((LPCSTR)lParam)));
SendMessage(b->hwnd, BUTTONADDTOOLTIP, (WPARAM)b->ptszTooltip, BATF_UNICODE);
return 1;
case TTBO_ALLDATA:
if (lParam) {
lpTTBButton lpTTB = (lpTTBButton)lParam;
if (lpTTB->cbSize != sizeof(TTBButton))
return 0;
DWORD retval = b->CheckFlags(lpTTB->dwFlags);
bool changed = false;
if (b->hIconUp != lpTTB->hIconUp) {
b->hIconUp = lpTTB->hIconUp;
changed = true;
}
if (b->hIconDn != lpTTB->hIconDn) {
b->hIconDn = lpTTB->hIconDn;
changed = true;
}
if (changed)
b->SetBitmap();
if (retval & TTBBF_VISIBLE) {
ArrangeButtons();
b->SaveSettings(0, 0);
}
if (b->dwFlags & TTBBF_ISLBUTTON)
replaceStrT(b->ptszProgram, lpTTB->program);
else
replaceStr(b->pszService, lpTTB->pszService);
b->lParamUp = lpTTB->lParamUp;
b->wParamUp = lpTTB->wParamUp;
b->lParamDown = lpTTB->lParamDown;
b->wParamDown = lpTTB->wParamDown;
return 1;
}
else
return 0;
default:
return -1;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// Reload all icons from their icolib handles
int OnIconChange(WPARAM, LPARAM)
{
mir_cslock lck(csButtonsHook);
for (int i = 0; i < Buttons.getCount(); i++) {
TopButtonInt *b = Buttons[i];
if (!b->hIconHandleUp && !b->hIconHandleDn)
continue;
if (b->hIconHandleUp) {
IcoLib_ReleaseIcon(b->hIconUp);
b->hIconUp = IcoLib_GetIconByHandle(b->hIconHandleUp);
}
if (b->hIconHandleDn) {
IcoLib_ReleaseIcon(b->hIconDn);
b->hIconDn = IcoLib_GetIconByHandle(b->hIconHandleDn);
}
DestroyWindow(b->hwnd);
b->CreateWnd();
}
if (g_ctrl->hWnd) {
g_ctrl->bOrderChanged = true;
PostMessage(g_ctrl->hWnd, TTB_UPDATEFRAMEVISIBILITY, 0, 0);
}
return 0;
}
static int OnBGChange(WPARAM, LPARAM)
{
LoadBackgroundOptions();
return 0;
}
static INT_PTR TTBSetCustomProc(WPARAM wParam, LPARAM lParam)
{
g_CustomProc = (pfnCustomProc)wParam;
g_CustomProcParam = lParam;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Adds buttons of plugins being loaded. lParam = HINSTANCE
int OnPluginLoad(WPARAM, LPARAM lParam)
{
CallPluginEventHook((HINSTANCE)lParam, hTTBModuleLoaded, 0, 0);
if (g_ctrl->hWnd && g_ctrl->bOrderChanged)
PostMessage(g_ctrl->hWnd, TTB_UPDATEFRAMEVISIBILITY, 0, 0);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Removes buttons of plugins being unloaded. lParam = HINSTANCE
int OnPluginUnload(WPARAM, LPARAM lParam)
{
int hLangpack = CallService(MS_LANGPACK_LOOKUPHANDLE, 0, lParam);
if (hLangpack) {
bool bNeedUpdate = false;
mir_cslock lck(csButtonsHook);
for (int i = Buttons.getCount() - 1; i >= 0; i--)
if (Buttons[i]->hLangpack == hLangpack) {
TTBRemoveButton(Buttons[i]->id, 0);
bNeedUpdate = true;
}
if (bNeedUpdate) {
ArrangeButtons();
if (g_ctrl->hWnd)
PostMessage(g_ctrl->hWnd, TTB_UPDATEFRAMEVISIBILITY, 0, 0);
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
static int OnModulesLoad(WPARAM, LPARAM)
{
LoadAllSeparators();
LoadAllLButs();
ArrangeButtons();
HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);//anonymous event
if (hEvent != 0)
CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)"TTB_ONSTARTUPFIRE");
if (HookEvent(ME_BACKGROUNDCONFIG_CHANGED, OnBGChange)) {
char buf[256];
mir_snprintf(buf, "%s/%s", LPGEN("TopToolBar background"), TTB_OPTDIR);
CallService(MS_BACKGROUNDCONFIG_REGISTER, (WPARAM)buf, 0);
}
return 0;
}
static int OnShutdown(WPARAM, LPARAM)
{
if (g_ctrl) {
if (g_ctrl->hFrame) {
CallService(MS_CLIST_FRAMES_REMOVEFRAME, (WPARAM)g_ctrl->hFrame, 0);
g_ctrl->hFrame = 0;
}
if (g_ctrl->hWnd) {
DestroyWindow(g_ctrl->hWnd);
g_ctrl->hWnd = NULL;
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
static LRESULT CALLBACK TTBButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LRESULT lResult = buttonWndProc(hwnd, msg, wParam, lParam);
if (msg == WM_NCCREATE) {
TopButtonInt *p = (TopButtonInt *)((CREATESTRUCT *)lParam)->lpCreateParams;
if (g_CustomProc)
g_CustomProc((HANDLE)p->id, hwnd, g_CustomProcParam);
}
return lResult;
}
int LoadToolbarModule()
{
if (!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
if (!db_get_b(NULL, TTB_OPTDIR, "WarningDone", 0))
MessageBox(0, TranslateT("Frames service has not been found, so plugin will be disabled.\nTo run it you need to install and / or enable contact list plugin that supports it:\n- Modern contact list\n- Nicer+\nYou can get them at http://wiki.miranda-ng.org/Download"), TranslateT("TopToolBar"), 0);
db_set_b(NULL, TTB_OPTDIR, "WarningDone", 1);
return 1;
}
g_ctrl = (TTBCtrl *)mir_calloc(sizeof(TTBCtrl));
g_ctrl->nButtonHeight = db_get_dw(0, TTB_OPTDIR, "BUTTHEIGHT", DEFBUTTHEIGHT);
g_ctrl->nButtonWidth = db_get_dw(0, TTB_OPTDIR, "BUTTWIDTH", DEFBUTTWIDTH);
g_ctrl->nButtonSpace = db_get_dw(0, TTB_OPTDIR, "BUTTGAP", DEFBUTTGAP);
g_ctrl->nLastHeight = db_get_dw(0, TTB_OPTDIR, "LastHeight", DEFBUTTHEIGHT);
g_ctrl->bFlatButtons = db_get_b(0, TTB_OPTDIR, "UseFlatButton", true);
g_ctrl->bSingleLine = db_get_b(0, TTB_OPTDIR, "SingleLine", true);
g_ctrl->bAutoSize = db_get_b(0, TTB_OPTDIR, "AutoSize", true);
db_unset(NULL, TTB_OPTDIR, "WarningDone");
hBmpSeparator = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SEP));
HookEvent(ME_SYSTEM_MODULELOAD, OnPluginLoad);
HookEvent(ME_SYSTEM_MODULEUNLOAD, OnPluginUnload);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoad);
HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
HookEvent(ME_SKIN2_ICONSCHANGED, OnIconChange);
HookEvent(ME_OPT_INITIALISE, TTBOptInit);
hTTBModuleLoaded = CreateHookableEvent(ME_TTB_MODULELOADED);
CreateServiceFunction("TopToolBar/AddButton", TTBAddButton);
CreateServiceFunction(MS_TTB_REMOVEBUTTON, TTBRemoveButton);
CreateServiceFunction(MS_TTB_SETBUTTONSTATE, TTBSetState);
CreateServiceFunction(MS_TTB_GETBUTTONSTATE, TTBGetState);
CreateServiceFunction(MS_TTB_GETBUTTONOPTIONS, TTBGetOptions);
CreateServiceFunction(MS_TTB_SETBUTTONOPTIONS, TTBSetOptions);
CreateServiceFunction(TTB_LAUNCHSERVICE, LaunchService);
CreateServiceFunction("TopToolBar/SetCustomProc", TTBSetCustomProc);
CreateServiceFunction("TTB_ONSTARTUPFIRE", OnEventFire);
buttonWndProc = (WNDPROC)CallService("Button/GetWindowProc", 0, 0);
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(wc);
wc.lpszClassName = TTB_BUTTON_CLASS;
wc.lpfnWndProc = TTBButtonWndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.cbWndExtra = sizeof(void *);
wc.hbrBackground = 0;
wc.style = CS_GLOBALCLASS;
RegisterClassEx(&wc);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
int UnloadToolbarModule()
{
DestroyHookableEvent(hTTBModuleLoaded);
DeleteObject(hBmpSeparator);
for (int i = 0; i < Buttons.getCount(); i++)
delete Buttons[i];
mir_free(g_ctrl);
return 0;
}
|