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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
/*
Miranda NG: the free IM client for Microsoft* Windows*
Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
Copyright (c) 2000-09 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 "global.h"
typedef struct _MSGPOPUPDATA
{
POPUPACTION pa[3];
HWND hDialog;
}
MSGPOPUPDATA, *LPMSGPOPUPDATA;
/**
* This helper function moves and resizes a dialog box's control element.
*
* @param hDlg - the dialog box's window handle
* @param idCtrl - the identication number of the control to move
* @param dx -´number of pixels to horizontal move the control
* @param dy - number of pixels to vertical move the control
* @param dw - number of pixels to horizontal resize the control
* @param dh - number of pixels to vertical resize the control
*
* @return nothing
**/
static FORCEINLINE VOID MoveCtrl(HWND hDlg, INT idCtrl, INT dx, INT dy, INT dw, INT dh)
{
RECT ws;
HWND hCtrl = GetDlgItem(hDlg, idCtrl);
GetWindowRect(hCtrl, &ws);
OffsetRect(&ws, dx, dy);
MoveWindow(hCtrl, ws.left, ws.top, ws.right - ws.left + dw, ws.bottom - ws.top + dh, FALSE);
}
/**
* This function loads the icon to display for the current message.
*
* @param pMsgBox - pointer to a MSGBOX structure, with information about the message to display.
*
* @retval HICON - The function returns an icon to display with the message.
* @retval NULL - There is no icon for the message.
**/
HICON MsgLoadIcon(LPMSGBOX pMsgBox)
{
HICON hIcon;
// load the desired status icon
switch (pMsgBox->uType & MB_ICONMASK)
{
// custom icon defined by caller function
case MB_ICON_OTHER:
{
hIcon = pMsgBox->hiMsg;
}
break;
// default windows icons
case MB_ICON_ERROR:
case MB_ICON_QUESTION:
case MB_ICON_WARNING:
case MB_ICON_INFO:
{
LPCTSTR ico[] = { 0, IDI_ERROR, IDI_QUESTION, IDI_WARNING, IDI_INFORMATION };
hIcon = LoadIcon(NULL, ico[MB_ICON_INDEX(pMsgBox->uType)]);
}
break;
// no icon
default:
{
hIcon = NULL;
}
}
return hIcon;
}
/**
* This function fills a given POPUPACTION structure with the data of a given message id,
* which is normally used by the message box. This is required to let the user interact
* with a popup in the same way as with a normal message dialog box.
*
* @param pa - reference to a POPUPACTION structure to fill
* @param id - the message id
* @param result - This parameter is passed to the POPUPACTION structure as is.
*
* @return nothing
**/
void MakePopupAction(POPUPACTION &pa, INT id)
{
pa.cbSize = sizeof(POPUPACTION);
pa.flags = PAF_ENABLED;
pa.wParam = MAKEWORD(id, BN_CLICKED);
pa.lParam = 0;
switch (id) {
case IDOK:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_OK);
lstrcpyA(pa.lpzTitle, MODNAME"/Ok");
break;
case IDCLOSE:
case IDCANCEL:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_CANCEL);
lstrcpyA(pa.lpzTitle, MODNAME"/Cancel");
break;
case IDABORT:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_CANCEL);
lstrcpyA(pa.lpzTitle, MODNAME"/Abort");
break;
case IDRETRY:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_UPDATE);
lstrcpyA(pa.lpzTitle, MODNAME"/Retry");
break;
case IDIGNORE:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_OK);
lstrcpyA(pa.lpzTitle, MODNAME"/Ignore");
break;
case IDYES:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_OK);
lstrcpyA(pa.lpzTitle, MODNAME"/Yes");
break;
case IDNO:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_CANCEL);
lstrcpyA(pa.lpzTitle, MODNAME"/No");
break;
case IDHELP:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_CANCEL);
lstrcpyA(pa.lpzTitle, MODNAME"/Help");
break;
case IDALL:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_OK);
lstrcpyA(pa.lpzTitle, MODNAME"/All");
break;
case IDNONE:
pa.lchIcon = IcoLib_GetIcon(ICO_PLUG_CANCEL);
lstrcpyA(pa.lpzTitle, MODNAME"/None");
}
}
/**
* This is the message procedure for my nice looking message box
*
* @param hDlg - window handle
* @param uMsg - message to handle
* @param wParam - message specific parameter
* @param lParam - message specific parameter
*
* @return TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL
**/
INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static INT retOk = IDOK;
static INT retAll = IDALL;
static INT retNon = IDNONE;
static INT retCancel = IDCANCEL;
switch (uMsg)
{
case WM_INITDIALOG:
{
LPMSGBOX pMsgBox = (LPMSGBOX)lParam;
if (PtrIsValid(pMsgBox))
{
INT icoWidth = 0;
INT InfoBarHeight = 0;
HFONT hNormalFont;
hNormalFont = (HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0);
if (pMsgBox->uType & MB_INFOBAR)
{
LOGFONT lf;
// set bold font for name in description area
GetObject(hNormalFont, sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
hNormalFont = CreateFontIndirect(&lf);
// set infobar's textfont
SendDlgItemMessage(hDlg, TXT_NAME, WM_SETFONT, (WPARAM)hNormalFont, 0);
// set infobar's logo icon
SendDlgItemMessage(hDlg, ICO_DLGLOGO, STM_SETIMAGE, IMAGE_ICON,
(LPARAM)((pMsgBox->hiLogo) ? pMsgBox->hiLogo : IcoLib_GetIcon(ICO_DLG_DETAILS)));
// anable headerbar
ShowWindow(GetDlgItem(hDlg, TXT_NAME), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, ICO_DLGLOGO), SW_SHOW);
}
else
{
RECT rc;
GetClientRect(GetDlgItem(hDlg, TXT_NAME), &rc);
InfoBarHeight = rc.bottom;
if (pMsgBox->hiLogo)
{
SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)pMsgBox->hiLogo);
}
}
// draw the desired status icon
HICON hIcon = MsgLoadIcon(pMsgBox);
if (hIcon)
{
SendDlgItemMessage(hDlg, ICO_MSGDLG, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
}
else
{
RECT ws;
GetWindowRect(GetDlgItem(hDlg, ICO_MSGDLG), &ws);
icoWidth = ws.right - ws.left;
ShowWindow(GetDlgItem(hDlg, ICO_MSGDLG), SW_HIDE);
}
// resize the messagebox and reorganize the buttons
if (HDC hDC = GetDC(hDlg))
{
POINT mpt = {0,0};
RECT ws = {0,0,0,0};
INT txtWidth,
txtHeight,
needX, needY;
RECT rcDlg;
SIZE ts;
LPTSTR h, rs;
SelectObject(hDC, hNormalFont);
for (rs = h = pMsgBox->ptszMsg, txtHeight = 0, txtWidth = 0; h; h++)
{
if (*h == '\n' || *h == '\0')
{
GetTextExtentPoint32(hDC, rs, h - rs, &ts);
if (ts.cx > txtWidth)
{
txtWidth = ts.cx;
}
txtHeight += ts.cy;
if (*h == '\0')
{
break;
}
rs = h + 1;
}
}
ReleaseDC(hDlg, hDC);
// calc new dialog size
GetWindowRect(hDlg, &rcDlg);
GetWindowRect(GetDlgItem(hDlg, TXT_MESSAGE), &ws);
needX = txtWidth - (ws.right - ws.left) - icoWidth;
needY = max(0, txtHeight - (ws.bottom - ws.top) + 5);
rcDlg.left -= needX/2; rcDlg.right += needX/2;
rcDlg.top -= (needY-InfoBarHeight)/2; rcDlg.bottom += (needY-InfoBarHeight)/2;
// resize dialog window
MoveWindow(hDlg,
rcDlg.left, rcDlg.top,
rcDlg.right - rcDlg.left,
rcDlg.bottom - rcDlg.top,
FALSE);
ClientToScreen(hDlg, &mpt);
MoveCtrl(hDlg, STATIC_WHITERECT, -mpt.x, -mpt.y, needX, needY - InfoBarHeight);
MoveCtrl(hDlg, TXT_NAME, -mpt.x, -mpt.y, needX, 0);
MoveCtrl(hDlg, ICO_DLGLOGO, -mpt.x + needX, -mpt.y, 0, 0);
MoveCtrl(hDlg, ICO_MSGDLG, -mpt.x, -mpt.y - InfoBarHeight, 0, 0);
MoveCtrl(hDlg, TXT_MESSAGE, -mpt.x - icoWidth, -mpt.y - InfoBarHeight, needX, needY);
MoveCtrl(hDlg, STATIC_LINE2, -mpt.x, -mpt.y + needY - InfoBarHeight, needX, 0);
//
// Do pushbutton positioning
//
{
RECT rcOk, rcAll, rcNone, rcCancel;
LONG okWidth, caWidth, allWidth, noneWidth, dlgMid;
// get button rectangles
GetWindowRect(GetDlgItem(hDlg, IDOK), &rcOk);
OffsetRect(&rcOk, -mpt.x, -mpt.y + needY - InfoBarHeight);
GetWindowRect(GetDlgItem(hDlg, IDALL), &rcAll);
OffsetRect(&rcAll, -mpt.x, -mpt.y + needY - InfoBarHeight);
GetWindowRect(GetDlgItem(hDlg, IDNONE), &rcNone);
OffsetRect(&rcNone, -mpt.x, -mpt.y + needY - InfoBarHeight);
GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &rcCancel);
OffsetRect(&rcCancel, -mpt.x, -mpt.y + needY - InfoBarHeight);
okWidth = rcOk.right - rcOk.left;
allWidth = rcAll.right - rcAll.left;
noneWidth = rcNone.right - rcNone.left;
caWidth = rcCancel.right - rcCancel.left;
dlgMid = (rcDlg.right - rcDlg.left) / 2;
// load button configuration
switch (MB_TYPE(pMsgBox->uType))
{
case MB_OK:
{
rcOk.left = dlgMid - (okWidth / 2);
rcOk.right = rcOk.left + okWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
}
break;
case MB_OKCANCEL:
{
retOk = IDRETRY;
SetDlgItemText(hDlg, IDOK, LPGENT("OK"));
retCancel = IDCANCEL;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
rcOk.left = dlgMid - okWidth - 10;
rcOk.right = rcOk.left + okWidth;
rcCancel.left = dlgMid + 10;
rcCancel.right = rcCancel.left + caWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
case MB_RETRYCANCEL:
{
retOk = IDRETRY;
SetDlgItemText(hDlg, IDOK, LPGENT("Retry"));
retCancel = IDCANCEL;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
rcOk.left = dlgMid - okWidth - 10;
rcOk.right = rcOk.left + okWidth;
rcCancel.left = dlgMid + 10;
rcCancel.right = rcCancel.left + caWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
case MB_YESNO:
{
retOk = IDYES;
SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
retCancel = IDNO;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("No"));
rcOk.left = dlgMid - okWidth - 10;
rcOk.right = rcOk.left + okWidth;
rcCancel.left = dlgMid + 10;
rcCancel.right = rcCancel.left + caWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
case MB_ABORTRETRYIGNORE:
{
retOk = IDABORT;
SetDlgItemText(hDlg, IDOK, LPGENT("Abort"));
retAll = IDABORT;
SetDlgItemText(hDlg, IDALL, LPGENT("Retry"));
retCancel = IDCANCEL;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("Ignore"));
rcAll.left = dlgMid - (allWidth / 2);
rcAll.right = rcAll.left + allWidth;
rcOk.left = rcAll.left - okWidth - 5;
rcOk.right = rcOk.left + okWidth;
rcCancel.left = rcAll.right + 5;
rcCancel.right = rcCancel.left + caWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
case MB_YESNOCANCEL:
{
retOk = IDYES;
SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
retAll = IDNO;
SetDlgItemText(hDlg, IDALL, LPGENT("No"));
retCancel = IDCANCEL;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel"));
rcAll.left = dlgMid - (allWidth / 2);
rcAll.right = rcAll.left + allWidth;
rcOk.left = rcAll.left - okWidth - 5;
rcOk.right = rcOk.left + okWidth;
rcCancel.left = rcAll.right + 5;
rcCancel.right = rcCancel.left + caWidth;
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
case MB_YESALLNO:
{
retOk = IDYES;
SetDlgItemText(hDlg, IDOK, LPGENT("Yes"));
retAll = IDALL;
SetDlgItemText(hDlg, IDALL, LPGENT("All"));
//retNon = IDNONE;
SetDlgItemText(hDlg, IDNONE, LPGENT("None"));
retCancel = IDNO;
SetDlgItemText(hDlg, IDCANCEL, LPGENT("No"));
rcCancel.right = rcDlg.right - rcDlg.left - 10;
rcCancel.left = rcCancel.right - caWidth;
rcNone.right = rcCancel.left - 5;
rcNone.left = rcNone.right - noneWidth;
rcAll.right = rcNone.left - 5;
rcAll.left = rcAll.right - allWidth;
rcOk.right = rcAll.left - 5;
rcOk.left = rcOk.right - okWidth;
// show buttons
ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDNONE), SW_SHOW);
ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
}
break;
default:
{
rcOk.left = dlgMid - (okWidth / 2);
rcOk.right = rcOk.left + okWidth;
}
}
// move ok button
MoveWindow(GetDlgItem(hDlg, IDOK),
rcOk.left, rcOk.top,
rcOk.right - rcOk.left, rcOk.bottom - rcOk.top,
FALSE);
// move all button
MoveWindow(GetDlgItem(hDlg, IDALL),
rcAll.left, rcAll.top,
rcAll.right - rcAll.left, rcAll.bottom - rcAll.top,
FALSE);
// move none button
MoveWindow(GetDlgItem(hDlg, IDNONE),
rcNone.left, rcNone.top,
rcNone.right - rcNone.left, rcNone.bottom - rcNone.top,
FALSE);
// move cancel button
MoveWindow(GetDlgItem(hDlg, IDCANCEL),
rcCancel.left, rcCancel.top,
rcCancel.right - rcCancel.left, rcCancel.bottom - rcCancel.top,
FALSE);
} // end* Do pushbutton positioning
} // end* resize the messagebox and reorganize the buttons
TranslateDialogDefault(hDlg);
// set text's
SetWindowText(hDlg, pMsgBox->ptszTitle);
SetDlgItemText(hDlg, TXT_NAME, pMsgBox->ptszInfoText);
SetDlgItemText(hDlg, TXT_MESSAGE, pMsgBox->ptszMsg);
return TRUE;
} // end* PtrIsValid(pMsgBox)
} // end* WM_INITDIALOG:
break;
case WM_CTLCOLORSTATIC:
{
switch (GetWindowLongPtr((HWND)lParam, GWL_ID))
{
case STATIC_WHITERECT:
case ICO_DLGLOGO:
case ICO_MSGDLG:
case TXT_MESSAGE:
case TXT_NAME:
{
SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
return GetSysColor(COLOR_WINDOW);
}
}
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hDlg, retOk);
break;
case IDCANCEL:
EndDialog(hDlg, retCancel);
break;
case IDALL:
EndDialog(hDlg, retAll);
break;
case IDNONE:
EndDialog(hDlg, retNon);
}
}
break;
case WM_DESTROY:
{
DeleteObject((HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0));
}
break;
}
return FALSE;
}
/**
* Dummi modal MsgBox for popup,
* this set call function in wait stait and do not freece miranda main thread
* the window is outside the desktop
*/
INT_PTR CALLBACK MsgBoxPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
{
MoveWindow(hDlg,-10,-10,0,0,FALSE);
LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)mir_alloc(sizeof(MSGPOPUPDATA));
if (pmpd) {
POPUPDATAT_V2 pd = { 0 };
pd.cbSize = sizeof(pd);
pd.lchContact = NULL; //(HANDLE)wParam;
// icon
LPMSGBOX pMsgBox = (LPMSGBOX)lParam;
pd.lchIcon = MsgLoadIcon(pMsgBox);
mir_tcsncpy(pd.lptzContactName, pMsgBox->ptszTitle, SIZEOF(pd.lptzContactName));
mir_tcsncpy(pd.lptzText, pMsgBox->ptszMsg, SIZEOF(pd.lptzText));
// CALLBAC Proc
pd.PluginWindowProc = PopupProc;
pd.PluginData = pmpd;
pd.iSeconds = -1;
pd.hNotification = NULL;
pd.lpActions = pmpd->pa;
// set color of popup
switch (pMsgBox->uType & MB_ICONMASK) {
case MB_ICON_ERROR:
pd.colorBack = RGB(200, 10, 0);
pd.colorText = RGB(255, 255, 255);
break;
case MB_ICON_WARNING:
pd.colorBack = RGB(200, 100, 0);
pd.colorText = RGB(255, 255, 255);
break;
default:
if (pMsgBox->uType & MB_CUSTOMCOLOR) {
pd.colorBack = pMsgBox->colorBack;
pd.colorText = pMsgBox->colorText;
}
}
// handle for MakePopupAction
pmpd->hDialog = hDlg;
// active buttons
switch (MB_TYPE(pMsgBox->uType)) {
case MB_OK:
MakePopupAction(pmpd->pa[pd.actionCount++], IDOK);
break;
case MB_OKCANCEL:
MakePopupAction(pmpd->pa[pd.actionCount++], IDOK);
MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL);
break;
case MB_RETRYCANCEL:
MakePopupAction(pmpd->pa[pd.actionCount++], IDRETRY);
MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL);
break;
case MB_YESNO:
MakePopupAction(pmpd->pa[pd.actionCount++], IDYES);
MakePopupAction(pmpd->pa[pd.actionCount++], IDNO);
break;
case MB_ABORTRETRYIGNORE:
MakePopupAction(pmpd->pa[pd.actionCount++], IDABORT);
MakePopupAction(pmpd->pa[pd.actionCount++], IDRETRY);
MakePopupAction(pmpd->pa[pd.actionCount++], IDIGNORE);
break;
case MB_YESNOCANCEL:
MakePopupAction(pmpd->pa[pd.actionCount++], IDYES);
MakePopupAction(pmpd->pa[pd.actionCount++], IDNO);
MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL);
break;
case MB_YESALLNO:
MakePopupAction(pmpd->pa[pd.actionCount++], IDYES);
MakePopupAction(pmpd->pa[pd.actionCount++], IDALL);
MakePopupAction(pmpd->pa[pd.actionCount++], IDNO);
break;
}
// create popup
CallService(MS_POPUP_ADDPOPUPT, (WPARAM) &pd, APF_NEWDATA);
if (MB_TYPE(pMsgBox->uType) == MB_OK)
EndDialog(hDlg, IDOK);
}
break;
}
}
return FALSE;
}
/**
* This is the message procedure for popup
*
* @param hDlg - window handle
* @param uMsg - message to handle
* @param wParam - message specific parameter
* @param lParam - message specific parameter
*
* @return TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL
**/
LRESULT CALLBACK PopupProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case UM_POPUPACTION:
if (HIWORD(wParam) == BN_CLICKED) {
LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg);
if (pmpd) {
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
case IDABORT:
case IDRETRY:
case IDIGNORE:
case IDYES:
case IDNO:
case IDALL:
case IDNONE:
if (IsWindow(pmpd->hDialog))
EndDialog(pmpd->hDialog, LOWORD(wParam));
break;
default:
if (IsWindow(pmpd->hDialog))
EndDialog(pmpd->hDialog, IDCANCEL);
}
}
PUDeletePopup(hDlg);
}
break;
case UM_FREEPLUGINDATA:
LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg);
if (pmpd > 0)
mir_freeAndNil(pmpd);
return TRUE; //TRUE or FALSE is the same, it gets ignored.
}
return DefWindowProc(hDlg, uMsg, wParam, lParam);
}
/**
* This is the service function for external plugins to use the nice messagebox
*
* @param wParam - MCONTACT hContact which can display an avatar for popups
* @param lParam - MSGBOX structure holding parameters
*
* @return The function returns the ID of the clicked button (IDOK, IDCANCEL, ...)
* or -1 on error.
**/
INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam)
{
INT rc = -1;
LPMSGBOX pMsgBox = (LPMSGBOX)lParam;
// check input
if (PtrIsValid(pMsgBox) && pMsgBox->cbSize == sizeof(MSGBOX))
{
// Shall the MessageBox displayed as popup?
if (!(pMsgBox->uType & (MB_INFOBAR|MB_NOPOPUP)) && // message box can be a popup?
ServiceExists(MS_POPUP_ADDPOPUPT) && // popups exist?
myGlobals.PopupActionsExist == 1 && // popup support ext stuct?
(db_get_dw(NULL, "Popup","Actions", 0) & 1) && // popup++ actions on?
db_get_b(NULL, MODNAME, SET_POPUPMSGBOX, DEFVAL_POPUPMSGBOX) // user likes popups?
)
{
rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MSGBOXDUMMI), pMsgBox->hParent, MsgBoxPop, lParam);
}
else
{
rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MSGBOX), pMsgBox->hParent, MsgBoxProc, lParam);
}
}
return rc;
}
/**
* name: MsgBox
* desc: calls a messagebox
* param:
**/
INT_PTR MsgBox(HWND hParent, UINT uType, LPTSTR pszTitle, LPTSTR pszInfo, LPTSTR pszFormat, ...)
{
MSGBOX mb = {0};
TCHAR tszMsg[MAX_SECONDLINE];
va_list vl;
va_start(vl, pszFormat);
mir_vsntprintf(tszMsg, SIZEOF(tszMsg), TranslateTS(pszFormat), vl);
va_end(vl);
mb.cbSize = sizeof(MSGBOX);
mb.hParent = hParent;
mb.hiLogo = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLUG_MAIN));
mb.hiMsg = NULL;
mb.ptszTitle = TranslateTS(pszTitle);
mb.ptszInfoText = TranslateTS(pszInfo);
mb.ptszMsg = tszMsg;
mb.uType = uType;
return MsgBoxService(NULL, (LPARAM)&mb);
}
/**
* name: MsgErr
* desc: calls a messagebox
* param:
**/
INT_PTR MsgErr(HWND hParent, LPCTSTR pszFormat, ...)
{
if(!pszFormat) return -1;
MSGBOX mb = {0};
TCHAR tszTitle[MAX_SECONDLINE];
TCHAR tszMsg[MAX_SECONDLINE];
va_list vl;
mir_sntprintf(tszTitle, SIZEOF(tszMsg),_T("%s - %s") ,_T(MODNAME), TranslateT("Error"));
va_start(vl, pszFormat);
mir_vsntprintf(tszMsg, SIZEOF(tszMsg), TranslateTS(pszFormat), vl);
va_end(vl);
mb.cbSize = sizeof(MSGBOX);
mb.hParent = hParent;
mb.hiLogo = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLUG_MAIN));
mb.hiMsg = NULL;
mb.ptszTitle = tszTitle;
mb.ptszMsg = tszMsg;
mb.uType = MB_OK|MB_ICON_ERROR;
return MsgBoxService(NULL, (LPARAM)&mb);
}
|