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
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
|
/*
Scriver
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 "stdafx.h"
#define TIMERID_FLASHWND 1
#define SB_CHAR_WIDTH 40
#define SB_SENDING_WIDTH 25
#define SB_UNICODE_WIDTH 18
#define TIMEOUT_FLASHWND 900
static void DrawTab(ParentWindowData *dat, HWND hwnd, WPARAM wParam, LPARAM lParam);
/////////////////////////////////////////////////////////////////////////////////////////
int ParentWindowData::GetChildCount()
{
return TabCtrl_GetItemCount(m_hwndTabs);
}
void ParentWindowData::GetChildWindowRect(RECT *rcChild)
{
RECT rc, rcStatus, rcTabs;
GetClientRect(m_hwnd, &rc);
GetClientRect(m_hwndTabs, &rcTabs);
TabCtrl_AdjustRect(m_hwndTabs, FALSE, &rcTabs);
rcStatus.top = rcStatus.bottom = 0;
if (flags2.bShowStatusBar)
GetWindowRect(m_hwndStatus, &rcStatus);
rcChild->left = 0;
rcChild->right = rc.right;
if (flags2.bTabsAtBottom) {
rcChild->top = 2;
if ((flags2.bUseTabs && !(flags2.bHideOneTab)) || (m_iChildrenCount > 1))
rcChild->bottom = rcTabs.bottom + 4;
else
rcChild->bottom = rc.bottom - rc.top - (rcStatus.bottom - rcStatus.top);
}
else {
if ((flags2.bUseTabs && !(flags2.bHideOneTab)) || (m_iChildrenCount > 1))
rcChild->top = rcTabs.top;
else
rcChild->top = 2;
rcChild->bottom = rc.bottom - rc.top - (rcStatus.bottom - rcStatus.top);
}
}
int ParentWindowData::GetTabFromHWND(HWND child)
{
int l = TabCtrl_GetItemCount(m_hwndTabs);
for (int i = 0; i < l; i++) {
TCITEM tci = { 0 };
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(m_hwndTabs, i, &tci);
CMsgDialog *pDlg = (CMsgDialog *)tci.lParam;
if (pDlg->GetHwnd() == child)
return i;
}
return -1;
}
static CMsgDialog* GetChildFromTab(HWND m_hwndTabs, int tabId)
{
TCITEM tci = { 0 };
tci.mask = TCIF_PARAM;
if (TabCtrl_GetItem(m_hwndTabs, tabId, &tci))
return (CMsgDialog *)tci.lParam;
return nullptr;
}
CMsgDialog* ParentWindowData::GetChildFromHWND(HWND hwnd)
{
int l = TabCtrl_GetItemCount(m_hwndTabs);
for (int i = 0; i < l; i++) {
TCITEM tci = { 0 };
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(m_hwndTabs, i, &tci);
CMsgDialog *pDlg = (CMsgDialog *)tci.lParam;
if (pDlg->GetHwnd() == hwnd)
return pDlg;
}
return nullptr;
}
static void GetMinimunWindowSize(ParentWindowData *dat, SIZE *size)
{
MINMAXINFO mmi;
RECT rc, rcWindow;
int minW = 216, minH = 80;
GetWindowRect(dat->m_hwnd, &rcWindow);
dat->GetChildWindowRect(&rc);
for (int i = 0; i < dat->m_iChildrenCount; i++) {
CMsgDialog * pDlg = GetChildFromTab(dat->m_hwndTabs, i);
SendMessage(pDlg->GetHwnd(), WM_GETMINMAXINFO, 0, (LPARAM)&mmi);
if (i == 0 || mmi.ptMinTrackSize.x > minW) minW = mmi.ptMinTrackSize.x;
if (i == 0 || mmi.ptMinTrackSize.y > minH) minH = mmi.ptMinTrackSize.y;
}
if (dat->bMinimized) {
size->cx = minW;
size->cy = minH;
}
else {
size->cx = minW + (rcWindow.right - rcWindow.left) - (rc.right - rc.left);
size->cy = minH + (rcWindow.bottom - rcWindow.top) - (rc.bottom - rc.top);
}
}
static void SetupStatusBar(ParentWindowData *dat)
{
int statusIconNum = GetStatusIconsCount(dat->m_hContact);
int statwidths[4];
RECT rc;
GetClientRect(dat->m_hwnd, &rc);
statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_UNICODE_WIDTH - 2 * (statusIconNum > 0) - statusIconNum * (GetSystemMetrics(SM_CXSMICON) + 2);
statwidths[1] = rc.right - rc.left - SB_UNICODE_WIDTH - 2 * (statusIconNum > 0) - statusIconNum * (GetSystemMetrics(SM_CXSMICON) + 2);
statwidths[2] = rc.right - rc.left - SB_UNICODE_WIDTH;
statwidths[3] = -1;
SendMessage(dat->m_hwndStatus, SB_SETPARTS, 4, (LPARAM)statwidths);
SendMessage(dat->m_hwndStatus, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW) | 2, 0);
SendMessage(dat->m_hwndStatus, SB_SETTEXT, (WPARAM)(SBT_NOBORDERS) | 3, 0);
}
static int AddOrReplaceIcon(HIMAGELIST hList, int prevIndex, HICON hIcon)
{
int usageIdx = -1;
for (int i = 0; i < g_dat.tabIconListUsageSize; i++) {
if (!g_dat.tabIconListUsage[i].used && usageIdx == -1)
usageIdx = i;
if (g_dat.tabIconListUsage[i].index == prevIndex) {
usageIdx = i;
break;
}
}
if (usageIdx == -1) {
usageIdx = g_dat.tabIconListUsageSize;
g_dat.tabIconListUsage = (ImageListUsageEntry*)mir_realloc(g_dat.tabIconListUsage, sizeof(ImageListUsageEntry)* (g_dat.tabIconListUsageSize + 1));
g_dat.tabIconListUsageSize++;
}
else prevIndex = g_dat.tabIconListUsage[usageIdx].index;
g_dat.tabIconListUsage[usageIdx].used = 1;
g_dat.tabIconListUsage[usageIdx].index = ImageList_ReplaceIcon(hList, prevIndex, hIcon);
return g_dat.tabIconListUsage[usageIdx].index;
}
static void ReleaseIcon(int index)
{
for (int i = 0; i < g_dat.tabIconListUsageSize; i++)
if (g_dat.tabIconListUsage[i].index == index)
g_dat.tabIconListUsage[i].used = 0;
}
void ParentWindowData::ActivateChild(CMsgDialog *pDlg)
{
if (pDlg == nullptr)
return;
RECT rcChild;
GetChildWindowRect(&rcChild);
SetWindowPos(pDlg->GetHwnd(), HWND_TOP, rcChild.left, rcChild.top, rcChild.right - rcChild.left, rcChild.bottom - rcChild.top, 0);
int i = GetTabFromHWND(pDlg->GetHwnd());
if (i == -1)
return;
m_hContact = pDlg->m_hContact;
if (pDlg->GetHwnd() != m_hwndActive) {
HWND hwndPrev = m_hwndActive;
m_hwndActive = pDlg->GetHwnd();
SetupStatusBar(this);
pDlg->UpdateStatusBar();
pDlg->UpdateTitle();
SendMessage(m_hwndActive, WM_SIZE, 0, 0);
ShowWindow(m_hwndActive, SW_SHOWNOACTIVATE);
pDlg->m_pLog->ScrollToBottom();
if (hwndPrev != nullptr)
ShowWindow(hwndPrev, SW_HIDE);
}
else SendMessage(m_hwnd, WM_SIZE, 0, 0);
TabCtrl_SetCurSel(m_hwndTabs, i);
SendMessage(m_hwndActive, DM_ACTIVATE, WA_ACTIVE, 0);
}
void ParentWindowData::ActivateChildByIndex(int index)
{
int l = TabCtrl_GetItemCount(m_hwndTabs);
if (index < l) {
CMsgDialog *pDlg = GetChildFromTab(m_hwndTabs, index);
if (pDlg != nullptr)
ActivateChild(pDlg);
}
SetFocus(m_hwndActive);
}
void ParentWindowData::ActivateNextChild(HWND child)
{
int i = GetTabFromHWND(child);
int l = TabCtrl_GetItemCount(m_hwndTabs);
i = (i + 1) % l;
ActivateChild(GetChildFromTab(m_hwndTabs, i));
SetFocus(m_hwndActive);
}
void ParentWindowData::ActivatePrevChild(HWND child)
{
int i = GetTabFromHWND(child);
int l = TabCtrl_GetItemCount(m_hwndTabs);
i = (i + l - 1) % l;
ActivateChild(GetChildFromTab(m_hwndTabs, i));
SetFocus(m_hwndActive);
}
void ParentWindowData::AddChild(CMsgDialog *pDlg)
{
TCITEM tci;
tci.mask = TCIF_PARAM | TCIF_IMAGE | TCIF_TEXT;
tci.lParam = (LPARAM)pDlg;
tci.iImage = -1;
tci.pszText = L"";
TabCtrl_InsertItem(m_hwndTabs, m_iChildrenCount, &tci);
m_iChildrenCount++;
SetWindowPos(pDlg->GetHwnd(), HWND_TOP, childRect.left, childRect.top, childRect.right - childRect.left, childRect.bottom - childRect.top, SWP_HIDEWINDOW);
SendMessage(m_hwnd, WM_SIZE, 0, 0);
EnableThemeDialogTexture(pDlg->GetHwnd(), ETDT_ENABLETAB);
}
void ParentWindowData::CloseOtherChilden(CMsgDialog *pChildDlg)
{
ActivateChild(pChildDlg);
for (int i = m_iChildrenCount - 1; i >= 0; i--) {
CMsgDialog *pDlg = GetChildFromTab(m_hwndTabs, i);
if (pDlg != nullptr && pDlg != pChildDlg)
pDlg->Close();
}
ActivateChild(pChildDlg);
}
void ParentWindowData::MessageSend(const SendQueue::Item &msg)
{
for (int i = 0; i < m_iChildrenCount; i++) {
CMsgDialog *pDlg = GetChildFromTab(m_hwndTabs, i);
if (pDlg != nullptr)
pDlg->MessageSend(msg);
}
}
void ParentWindowData::PopupWindow(CMsgDialog *pDlg, bool bIncoming)
{
EnableWindow(m_hwnd, TRUE);
if (bIncoming) { /* incoming message */
if (g_dat.flags.bStayMinimized) {
if (!IsWindowVisible(m_hwnd))
ShowWindow(m_hwnd, SW_SHOWMINNOACTIVE);
if (m_iChildrenCount == 1 || (g_dat.flags2.bSwitchToActive && (IsIconic(m_hwnd) || GetForegroundWindow() != m_hwnd)))
ActivateChild(pDlg);
}
else {
ShowWindow(m_hwnd, IsIconic(m_hwnd) ? SW_SHOWNORMAL : SW_SHOWNA);
if (m_iChildrenCount == 1 || (g_dat.flags2.bSwitchToActive && (IsIconic(m_hwnd) || GetForegroundWindow() != m_hwnd)))
ActivateChild(pDlg);
SetWindowPos(m_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}
else { /* outgoing message */
ShowWindow(m_hwnd, IsIconic(m_hwnd) ? SW_SHOWNORMAL : SW_SHOW);
SetForegroundWindow(m_hwnd);
SetFocus(pDlg->GetHwnd());
}
}
void ParentWindowData::RemoveChild(HWND child)
{
int tab = GetTabFromHWND(child);
if (tab >= 0) {
TCITEM tci;
tci.mask = TCIF_PARAM | TCIF_IMAGE;
TabCtrl_GetItem(m_hwndTabs, tab, &tci);
TabCtrl_DeleteItem(m_hwndTabs, tab);
m_iChildrenCount--;
if (child == m_hwndActive) {
if (tab == TabCtrl_GetItemCount(m_hwndTabs)) tab--;
if (tab >= 0)
ActivateChild(GetChildFromTab(m_hwndTabs, tab));
else
m_hwndActive = nullptr;
}
ReleaseIcon(tci.iImage);
}
if (m_iChildrenCount != 0)
SetFocus(m_hwndActive);
else
PostMessage(m_hwnd, WM_CLOSE, 0, 0);
}
void ParentWindowData::SetContainerWindowStyle()
{
ShowWindow(m_hwndStatus, (flags2.bShowStatusBar) ? SW_SHOW : SW_HIDE);
uint32_t ws = GetWindowLongPtr(m_hwnd, GWL_STYLE) & ~(WS_CAPTION);
if (flags2.bShowTitleBar)
ws |= WS_CAPTION;
SetWindowLongPtr(m_hwnd, GWL_STYLE, ws);
ws = GetWindowLongPtr(m_hwnd, GWL_EXSTYLE)& ~WS_EX_LAYERED;
ws |= flags2.bUseTransparency ? WS_EX_LAYERED : 0;
SetWindowLongPtr(m_hwnd, GWL_EXSTYLE, ws);
if (flags2.bUseTransparency)
SetLayeredWindowAttributes(m_hwnd, RGB(255, 255, 255), (uint8_t)(255 - g_dat.inactiveAlpha), LWA_ALPHA);
ws = GetWindowLongPtr(m_hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM | 0x2000);
if (flags2.bTabsAtBottom)
ws |= TCS_BOTTOM;
ws |= 0x2000;
if (flags2.bTabCloseButton)
TabCtrl_SetPadding(m_hwndTabs, GetSystemMetrics(SM_CXEDGE) + 12, GetSystemMetrics(SM_CYEDGE) + 1);
else
TabCtrl_SetPadding(m_hwndTabs, GetSystemMetrics(SM_CXEDGE) + 4, GetSystemMetrics(SM_CYEDGE) + 1);
SetWindowLongPtr(m_hwndTabs, GWL_STYLE, ws);
RECT rc;
GetWindowRect(m_hwnd, &rc);
SetWindowPos(m_hwnd, nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
}
void ParentWindowData::StartFlashing()
{
if ((GetActiveWindow() != m_hwnd || GetForegroundWindow() != m_hwnd)) {
nFlash = 0;
SetTimer(m_hwnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr);
}
}
void ParentWindowData::ToggleInfoBar()
{
flags2.bShowInfoBar = !flags2.bShowInfoBar;
for (int i = 0; i < m_iChildrenCount; i++) {
CMsgDialog *pDlg = GetChildFromTab(m_hwndTabs, i);
if (pDlg)
pDlg->SetDialogToType();
}
SendMessage(m_hwnd, WM_SIZE, 0, 0);
}
void ParentWindowData::ToggleStatusBar()
{
flags2.bShowStatusBar = !flags2.bShowStatusBar;
ShowWindow(m_hwndStatus, (flags2.bShowStatusBar) ? SW_SHOW : SW_HIDE);
SendMessage(m_hwnd, WM_SIZE, 0, 0);
}
void ParentWindowData::ToggleTitleBar()
{
flags2.bShowTitleBar = !flags2.bShowTitleBar;
uint32_t ws = GetWindowLongPtr(m_hwnd, GWL_STYLE) & ~(WS_CAPTION);
if (flags2.bShowTitleBar)
ws |= WS_CAPTION;
SetWindowLongPtr(m_hwnd, GWL_STYLE, ws);
RECT rc;
GetWindowRect(m_hwnd, &rc);
SetWindowPos(m_hwnd, nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
RedrawWindow(m_hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
void ParentWindowData::ToggleToolBar()
{
flags2.bShowToolBar = !flags2.bShowToolBar;
for (int i = 0; i < m_iChildrenCount; i++) {
CMsgDialog *pDlg = GetChildFromTab(m_hwndTabs, i);
if (pDlg)
pDlg->SetDialogToType();
}
SendMessage(m_hwnd, WM_SIZE, 0, 0);
}
void ParentWindowData::UpdateStatusBar(const StatusBarData &sbd, HWND hwnd)
{
if (m_hwndActive == hwnd) {
if (sbd.iFlags & SBDF_TEXT)
SendMessage(m_hwndStatus, SB_SETTEXT, sbd.iItem, (LPARAM)sbd.pszText);
if (sbd.iFlags & SBDF_ICON)
SendMessage(m_hwndStatus, SB_SETICON, sbd.iItem, (LPARAM)sbd.hIcon);
}
RedrawWindow(m_hwndStatus, nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
}
void ParentWindowData::UpdateTabControl(const TabControlData &tcd, HWND hwnd)
{
int tabId = GetTabFromHWND(hwnd);
if (tabId < 0)
return;
wchar_t *ptszTemp = nullptr;
TCITEM tci;
tci.mask = 0;
if (tcd.iFlags & TCDF_TEXT) {
tci.mask |= TCIF_TEXT;
tci.pszText = tcd.pszText;
if (g_dat.flags2.bLimitNames) {
wchar_t *ltext = limitText(tcd.pszText, g_dat.limitNamesLength);
if (ltext != tcd.pszText)
tci.pszText = ptszTemp = ltext;
}
}
if (tcd.iFlags & TCDF_ICON) {
int iconIdx = -1;
if (tcd.hIcon != nullptr) {
TCITEM tci2;
tci2.mask = TCIF_IMAGE;
TabCtrl_GetItem(m_hwndTabs, tabId, &tci2);
iconIdx = AddOrReplaceIcon(g_dat.hTabIconList, tci2.iImage, tcd.hIcon);
}
tci.mask |= TCIF_IMAGE;
tci.iImage = iconIdx;
}
TabCtrl_SetItem(m_hwndTabs, tabId, &tci);
mir_free(ptszTemp);
}
void ParentWindowData::UpdateTitleBar(const TitleBarData &tbd, HWND hwnd)
{
if (m_hwndActive != hwnd)
return;
if (tbd.iFlags & TBDF_TEXT) {
wchar_t oldtitle[256];
GetWindowText(m_hwnd, oldtitle, _countof(oldtitle));
if (mir_wstrcmp(tbd.pszText, oldtitle))
SetWindowText(m_hwnd, tbd.pszText);
}
if (tbd.iFlags & TBDF_ICON) {
SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)tbd.hIcon);
if (tbd.hIconBig != nullptr)
SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)tbd.hIconBig);
if (pTaskbarInterface)
pTaskbarInterface->SetOverlayIcon(m_hwnd, tbd.hIconNot, L"");
}
}
/////////////////////////////////////////////////////////////////////////////////////////
static LRESULT CALLBACK TabCtrlProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
TabCtrlData *dat = (TabCtrlData*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
TCHITTESTINFO thinfo;
int tabId;
switch (msg) {
case EM_SUBCLASSED:
dat = (TabCtrlData*)mir_alloc(sizeof(TabCtrlData));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);
dat->bDragging = FALSE;
dat->bDragged = FALSE;
dat->srcTab = -1;
dat->destTab = -1;
return 0;
case WM_MBUTTONDOWN:
thinfo.pt.x = LOWORD(lParam);
thinfo.pt.y = HIWORD(lParam);
tabId = TabCtrl_HitTest(hwnd, &thinfo);
if (tabId >= 0) {
TCITEM tci;
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(hwnd, tabId, &tci);
CMsgDialog *pDlg = (CMsgDialog *)tci.lParam;
if (pDlg != nullptr) {
SendMessage(pDlg->GetHwnd(), WM_CLOSE, 0, 0);
dat->srcTab = -1;
}
}
return 0;
case WM_LBUTTONDBLCLK:
thinfo.pt.x = LOWORD(lParam);
thinfo.pt.y = HIWORD(lParam);
tabId = TabCtrl_HitTest(hwnd, &thinfo);
if (tabId >= 0 && tabId == dat->srcTab) {
GetChildFromTab(hwnd, tabId)->Close();
dat->srcTab = -1;
}
dat->destTab = -1;
break;
case WM_LBUTTONDOWN:
if (!dat->bDragging) {
thinfo.pt.x = LOWORD(lParam);
thinfo.pt.y = HIWORD(lParam);
dat->srcTab = TabCtrl_HitTest(hwnd, &thinfo);
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
if (dat->srcTab >= 0) {
dat->bDragging = TRUE;
dat->bDragged = FALSE;
dat->clickLParam = lParam;
dat->clickWParam = wParam;
dat->lastClickTime = ft.dwLowDateTime;
dat->mouseLBDownPos.x = thinfo.pt.x;
dat->mouseLBDownPos.y = thinfo.pt.y;
SetCapture(hwnd);
}
return 0;
}
break;
case WM_CAPTURECHANGED:
case WM_LBUTTONUP:
if (dat->bDragging) {
thinfo.pt.x = LOWORD(lParam);
thinfo.pt.y = HIWORD(lParam);
if (dat->bDragged) {
ImageList_DragLeave(GetDesktopWindow());
ImageList_EndDrag();
ImageList_Destroy(dat->hDragImageList);
SetCursor(LoadCursor(nullptr, IDC_ARROW));
dat->destTab = TabCtrl_HitTest(hwnd, &thinfo);
if (thinfo.flags != TCHT_NOWHERE && dat->destTab != dat->srcTab) {
NMHDR nmh;
wchar_t sBuffer[501];
TCITEM item;
int curSel;
curSel = TabCtrl_GetCurSel(hwnd);
item.mask = TCIF_IMAGE | TCIF_PARAM | TCIF_TEXT;
item.pszText = sBuffer;
item.cchTextMax = _countof(sBuffer);
TabCtrl_GetItem(hwnd, dat->srcTab, &item);
sBuffer[_countof(sBuffer) - 1] = '\0';
if (curSel == dat->srcTab)
curSel = dat->destTab;
else if (curSel > dat->srcTab && curSel <= dat->destTab)
curSel--;
else if (curSel < dat->srcTab && curSel >= dat->destTab)
curSel++;
TabCtrl_DeleteItem(hwnd, dat->srcTab);
TabCtrl_InsertItem(hwnd, dat->destTab, &item);
TabCtrl_SetCurSel(hwnd, curSel);
dat->destTab = -1;
nmh.hwndFrom = hwnd;
nmh.idFrom = GetDlgCtrlID(hwnd);
nmh.code = TCN_SELCHANGE;
SendMessage(GetParent(hwnd), WM_NOTIFY, nmh.idFrom, (LPARAM)&nmh);
UpdateWindow(hwnd);
}
else if (thinfo.flags == TCHT_NOWHERE) {
dat->destTab = -1;
TCITEM tci;
tci.mask = TCIF_PARAM;
TabCtrl_GetItem(hwnd, dat->srcTab, &tci);
CMsgDialog *pDlg = (CMsgDialog*)tci.lParam;
if (pDlg != nullptr)
pDlg->Reattach(GetParent(hwnd));
}
else {
dat->destTab = -1;
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
}
}
else if (dat->srcTab >= 0 && g_dat.flags2.bTabCloseButton) {
int atTop = (GetWindowLongPtr(hwnd, GWL_STYLE) & TCS_BOTTOM) == 0;
RECT rect;
TabCtrl_GetItemRect(hwnd, dat->srcTab, &rect);
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
IMAGEINFO info;
ImageList_GetImageInfo(g_dat.hTabIconList, 0, &info);
rect.left = rect.right - (info.rcImage.right - info.rcImage.left) - 6;
if (!atTop)
rect.top = rect.bottom - (info.rcImage.bottom - info.rcImage.top);
if (pt.x >= rect.left && pt.x < rect.left + (info.rcImage.right - info.rcImage.left) && pt.y >= rect.top && pt.y < rect.top + (info.rcImage.bottom - info.rcImage.top)) {
HBITMAP hOldBitmap, hBmp;
HDC hdc = GetDC(nullptr);
HDC hdcMem = CreateCompatibleDC(hdc);
pt.x -= rect.left;
pt.y -= rect.top;
hBmp = CreateCompatibleBitmap(hdc, info.rcImage.right - info.rcImage.left + 1, info.rcImage.bottom - info.rcImage.top + 1);
hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBmp);
SetPixel(hdcMem, pt.x, pt.y, 0x000000);
ImageList_DrawEx(g_dat.hTabIconList, 0, hdcMem, 0, 0, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
COLORREF color1 = GetPixel(hdcMem, pt.x, pt.y);
SetPixel(hdcMem, pt.x, pt.y, 0xFFFFFF);
ImageList_DrawEx(g_dat.hTabIconList, 0, hdcMem, 0, 0, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
COLORREF color2 = GetPixel(hdcMem, pt.x, pt.y);
SelectObject(hdcMem, hOldBitmap);
DeleteDC(hdcMem);
DeleteObject(hBmp);
ReleaseDC(nullptr, hdc);
if (color1 != 0x000000 || color2 != 0xFFFFFF) {
GetChildFromTab(hwnd, dat->srcTab)->Close();
dat->srcTab = -1;
}
}
else SendMessage(hwnd, WM_LBUTTONDOWN, dat->clickWParam, dat->clickLParam);
}
else SendMessage(hwnd, WM_LBUTTONDOWN, dat->clickWParam, dat->clickLParam);
dat->bDragged = dat->bDragging = FALSE;
dat->destTab = -1;
ReleaseCapture();
}
break;
case WM_MOUSEMOVE:
if (wParam & MK_LBUTTON) {
if (dat->bDragging) {
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
thinfo.pt.x = LOWORD(lParam);
thinfo.pt.y = HIWORD(lParam);
if (!dat->bDragged) {
if ((abs(thinfo.pt.x - dat->mouseLBDownPos.x) < 3 && abs(thinfo.pt.y - dat->mouseLBDownPos.y) < 3)
|| (ft.dwLowDateTime - dat->lastClickTime) < 10 * 1000 * 150)
break;
}
if (!dat->bDragged) {
POINT pt;
RECT rect;
RECT rect2;
HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 254));
GetCursorPos(&pt);
TabCtrl_GetItemRect(hwnd, dat->srcTab, &rect);
rect.right -= rect.left - 1;
rect.bottom -= rect.top - 1;
rect2.left = 0; rect2.right = rect.right; rect2.top = 0; rect2.bottom = rect.bottom;
dat->hDragImageList = ImageList_Create(rect.right, rect.bottom, ILC_COLOR | ILC_MASK, 0, 1);
HDC hDC = GetDC(hwnd);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
FillRect(hMemDC, &rect2, hBrush);
SetWindowOrgEx(hMemDC, rect.left, rect.top, nullptr);
SendMessage(hwnd, WM_PRINTCLIENT, (WPARAM)hMemDC, PRF_CLIENT);
SelectObject(hMemDC, hOldBitmap);
ImageList_AddMasked(dat->hDragImageList, hBitmap, RGB(255, 0, 254));
DeleteObject(hBitmap);
DeleteObject(hBrush);
ReleaseDC(hwnd, hDC);
DeleteDC(hMemDC);
ImageList_BeginDrag(dat->hDragImageList, 0, dat->mouseLBDownPos.x - rect.left, dat->mouseLBDownPos.y - rect.top);
ImageList_DragEnter(GetDesktopWindow(), pt.x, pt.y);
SetCursor(hDragCursor);
dat->mouseLBDownPos.x = thinfo.pt.x;
dat->mouseLBDownPos.y = thinfo.pt.y;
}
else {
POINT pt;
GetCursorPos(&pt);
thinfo.pt = pt;
ScreenToClient(hwnd, &thinfo.pt);
int newDest = TabCtrl_HitTest(hwnd, &thinfo);
if (thinfo.flags == TCHT_NOWHERE)
newDest = -1;
if (newDest != dat->destTab) {
dat->destTab = newDest;
ImageList_DragLeave(GetDesktopWindow());
RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
ImageList_DragEnter(GetDesktopWindow(), pt.x, pt.y);
}
else ImageList_DragMove(pt.x, pt.y);
}
dat->bDragged = TRUE;
return 0;
}
}
break;
case EM_UNSUBCLASSED:
mir_free(dat);
return 0;
}
return mir_callNextSubclass(hwnd, TabCtrlProc, msg, wParam, lParam);
}
__forceinline void SubclassTabCtrl(HWND hwnd)
{
mir_subclassWindow(hwnd, TabCtrlProc);
SendMessage(hwnd, EM_SUBCLASSED, 0, 0);
}
__forceinline void UnsubclassTabCtrl(HWND hwnd)
{
SendMessage(hwnd, EM_UNSUBCLASSED, 0, 0);
}
/////////////////////////////////////////////////////////////////////////////////////////
struct NewMessageWindowLParam
{
MCONTACT hContact;
BOOL isChat;
};
static INT_PTR CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
ParentWindowData *dat = (ParentWindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (!dat && msg != WM_INITDIALOG)
return FALSE;
switch (msg) {
case WM_INITDIALOG:
{
int savePerContact = g_plugin.bSavePerContact && !g_dat.flags2.bUseTabs;
NewMessageWindowLParam *newData = (NewMessageWindowLParam *)lParam;
dat = (ParentWindowData *)mir_alloc(sizeof(ParentWindowData));
dat->m_hContact = newData->hContact;
dat->nFlash = 0;
dat->nFlashMax = g_plugin.iFlashCount;
dat->m_iChildrenCount = 0;
dat->m_hwnd = hwndDlg;
dat->mouseLBDown = 0;
dat->windowWasCascaded = 0;
dat->bMinimized = 0;
dat->bVMaximized = 0;
dat->iSplitterX = g_plugin.getDword("splitterx", -1);
dat->iSplitterY = g_plugin.getDword("splittery", -1);
dat->flags2 = g_dat.flags2;
dat->m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hwndDlg, nullptr, g_plugin.getInst(), nullptr);
dat->isChat = newData->isChat;
SendMessage(dat->m_hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0);
SetupStatusBar(dat);
dat->m_hwndTabs = GetDlgItem(hwndDlg, IDC_TABS);
dat->m_hwndActive = nullptr;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
if (g_dat.hTabIconList != nullptr)
TabCtrl_SetImageList(dat->m_hwndTabs, g_dat.hTabIconList);
dat->next = nullptr;
if (!newData->isChat) {
dat->prev = g_dat.lastParent;
g_dat.lastParent = dat;
}
else {
dat->prev = g_dat.lastChatParent;
g_dat.lastChatParent = dat;
}
if (dat->prev != nullptr)
dat->prev->next = dat;
WindowList_Add(g_dat.hParentWindowList, hwndDlg, (UINT_PTR)hwndDlg);
SubclassTabCtrl(dat->m_hwndTabs);
dat->SetContainerWindowStyle();
MCONTACT hSContact = savePerContact ? dat->m_hContact : 0;
dat->bTopmost = g_plugin.bTopmost;
if (Utils_RestoreWindowPosition(hwndDlg, hSContact, SRMM_MODULE, (newData->isChat && !savePerContact) ? "chat" : "", RWPF_HIDDEN))
SetWindowPos(hwndDlg, nullptr, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_HIDEWINDOW);
if (!savePerContact && g_plugin.bCascade)
WindowList_Broadcast(g_dat.hParentWindowList, DM_CASCADENEWWINDOW, (WPARAM)hwndDlg, (LPARAM)&dat->windowWasCascaded);
PostMessage(hwndDlg, WM_SIZE, 0, 0);
HMENU hMenu = GetSystemMenu(hwndDlg, FALSE);
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
if (dat->bTopmost) {
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED | MF_CHECKED | MF_STRING, IDM_TOPMOST, TranslateT("Always on top"));
SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
else InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED | MF_UNCHECKED | MF_STRING, IDM_TOPMOST, TranslateT("Always on top"));
}
return TRUE;
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi = (MINMAXINFO *)lParam;
if (dat->bVMaximized) {
MONITORINFO mi;
HMONITOR hMonitor;
WINDOWPLACEMENT wp;
RECT rcDesktop;
wp.length = sizeof(wp);
GetWindowPlacement(hwndDlg, &wp);
hMonitor = MonitorFromRect(&wp.rcNormalPosition, MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
rcDesktop = mi.rcWork;
mmi->ptMaxSize.x = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
mmi->ptMaxSize.y = rcDesktop.bottom - rcDesktop.top;
mmi->ptMaxPosition.x = wp.rcNormalPosition.left;
if (IsIconic(hwndDlg))
mmi->ptMaxPosition.y = rcDesktop.top;
else
mmi->ptMaxPosition.y = 0;
}
SIZE size;
GetMinimunWindowSize(dat, &size);
mmi->ptMinTrackSize.x = size.cx;
mmi->ptMinTrackSize.y = size.cy;
}
return FALSE;
case WM_SIZE:
if (wParam == SIZE_MINIMIZED)
dat->bMinimized = 1;
if (IsIconic(hwndDlg))
MoveWindow(dat->m_hwndActive, dat->childRect.left, dat->childRect.top, dat->childRect.right - dat->childRect.left, dat->childRect.bottom - dat->childRect.top, TRUE);
else {
RECT rcStatus, rcChild, rcWindow, rc;
SIZE size;
dat->bMinimized = 0;
GetClientRect(hwndDlg, &rc);
GetWindowRect(hwndDlg, &rcWindow);
rcStatus.top = rcStatus.bottom = 0;
if (dat->flags2.bShowStatusBar) {
GetWindowRect(dat->m_hwndStatus, &rcStatus);
SetupStatusBar(dat);
}
MoveWindow(dat->m_hwndTabs, 0, 2, (rc.right - rc.left), (rc.bottom - rc.top) - (rcStatus.bottom - rcStatus.top) - 2, FALSE);
RedrawWindow(dat->m_hwndTabs, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE);
GetMinimunWindowSize(dat, &size);
if ((rcWindow.bottom - rcWindow.top) < size.cy || (rcWindow.right - rcWindow.left) < size.cx) {
if ((rcWindow.bottom - rcWindow.top) < size.cy)
rcWindow.bottom = rcWindow.top + size.cy;
if ((rcWindow.right - rcWindow.left) < size.cx)
rcWindow.right = rcWindow.left + size.cx;
MoveWindow(hwndDlg, rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, TRUE);
}
dat->GetChildWindowRect(&rcChild);
dat->childRect = rcChild;
MoveWindow(dat->m_hwndActive, rcChild.left, rcChild.top, rcChild.right - rcChild.left, rcChild.bottom - rcChild.top, TRUE);
RedrawWindow(GetDlgItem(dat->m_hwndActive, IDC_SRMM_LOG), nullptr, nullptr, RDW_INVALIDATE);
if (dat->flags2.bShowStatusBar) {
SendMessage(dat->m_hwndStatus, WM_SIZE, 0, 0);
RedrawWindow(dat->m_hwndStatus, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
}
}
return FALSE;
case WM_SETFOCUS:
if (dat->m_hwndActive != nullptr)
SetFocus(dat->m_hwndActive);
return TRUE;
case WM_CLOSE:
if (g_dat.flags2.bHideContainer && dat->m_iChildrenCount > 0)
ShowWindow(hwndDlg, SW_HIDE);
else
DestroyWindow(hwndDlg);
return TRUE;
case WM_MEASUREITEM:
return Menu_MeasureItem(lParam);
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
if (dat && dat->m_hwndActive && dis->hwndItem == dat->m_hwndStatus) {
CMsgDialog *pDlg = dat->GetChildFromHWND(dat->m_hwndActive);
if (pDlg != nullptr)
DrawStatusIcons(pDlg->m_hContact, dis->hDC, dis->rcItem, 2);
return TRUE;
}
if (dis->hwndItem == dat->m_hwndTabs) {
DrawTab(dat, dat->m_hwndTabs, wParam, lParam);
return TRUE;
}
}
return Menu_DrawItem(lParam);
case WM_COMMAND:
if (Clist_MenuProcessCommand(LOWORD(wParam), MPCF_CONTACTMENU, dat->m_hContact))
break;
if (LOWORD(wParam) == IDCANCEL)
return TRUE;
break;
case WM_NOTIFY:
{
NMHDR *pNMHDR = (NMHDR*)lParam;
if (pNMHDR->hwndFrom == dat->m_hwndTabs) {
switch (pNMHDR->code) {
case TCN_SELCHANGE:
{
TCITEM tci = { 0 };
int iSel = TabCtrl_GetCurSel(dat->m_hwndTabs);
tci.mask = TCIF_PARAM;
if (TabCtrl_GetItem(dat->m_hwndTabs, iSel, &tci)) {
CMsgDialog *pDlg = (CMsgDialog *)tci.lParam;
dat->ActivateChild(pDlg);
SetFocus(dat->m_hwndActive);
}
}
break;
case NM_RCLICK:
TCHITTESTINFO thinfo;
GetCursorPos(&thinfo.pt);
int x = thinfo.pt.x;
int y = thinfo.pt.y;
ScreenToClient(dat->m_hwndTabs, &thinfo.pt);
int tabId = TabCtrl_HitTest(dat->m_hwndTabs, &thinfo);
if (tabId != -1) {
CMsgDialog *pDlg = GetChildFromTab(dat->m_hwndTabs, tabId);
HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXT));
HMENU hSubMenu = GetSubMenu(hMenu, 1);
TranslateMenu(hSubMenu);
HMENU hUserMenu = (HMENU)SendMessage(pDlg->GetHwnd(), DM_GETCONTEXTMENU, 0, 0);
if (hUserMenu != nullptr) {
InsertMenu(hSubMenu, 0, MF_POPUP | MF_BYPOSITION, (UINT_PTR)hUserMenu, TranslateT("User menu"));
InsertMenu(hSubMenu, 1, MF_SEPARATOR | MF_BYPOSITION, 0, nullptr);
}
BOOL menuResult = TrackPopupMenu(hSubMenu, TPM_RETURNCMD, x, y, 0, hwndDlg, nullptr);
switch (menuResult) {
case IDM_CLOSETAB:
SendMessage(pDlg->GetHwnd(), WM_CLOSE, 0, 0);
break;
case IDM_CLOSEOTHERTABS:
dat->CloseOtherChilden(pDlg);
break;
default:
Clist_MenuProcessCommand(LOWORD(menuResult), MPCF_CONTACTMENU, pDlg->m_hContact);
}
if (hUserMenu != nullptr)
DestroyMenu(hUserMenu);
DestroyMenu(hMenu);
}
}
break;
}
else if (pNMHDR->hwndFrom == dat->m_hwndStatus) {
switch (pNMHDR->code) {
case NM_CLICK:
RECT rc;
NMMOUSE *nm = (NMMOUSE*)lParam;
SendMessage(dat->m_hwndStatus, SB_GETRECT, SendMessage(dat->m_hwndStatus, SB_GETPARTS, 0, 0) - 2, (LPARAM)&rc);
if (nm->pt.x >= rc.left) {
CMsgDialog *pDlg = dat->GetChildFromHWND(dat->m_hwndActive);
if (pDlg != nullptr)
CheckStatusIconClick(pDlg->m_hContact, dat->m_hwndStatus, nm->pt, rc, 2, 0);
}
return TRUE;
}
}
}
break;
case WM_DROPFILES:
SendMessage(dat->m_hwndActive, WM_DROPFILES, wParam, lParam);
break;
case WM_TIMER:
if (wParam == TIMERID_FLASHWND) {
if (dat->nFlash < 2 * dat->nFlashMax) {
FlashWindow(hwndDlg, TRUE);
dat->nFlash++;
}
else {
KillTimer(hwndDlg, TIMERID_FLASHWND);
FlashWindow(hwndDlg, FALSE);
}
}
break;
case WM_CONTEXTMENU:
if (dat->m_hwndStatus && dat->m_hwndStatus == (HWND)wParam) {
POINT pt, pt2;
GetCursorPos(&pt);
pt2 = pt;
ScreenToClient(dat->m_hwndStatus, &pt);
RECT rc;
SendMessage(dat->m_hwndStatus, SB_GETRECT, SendMessage(dat->m_hwndStatus, SB_GETPARTS, 0, 0) - 2, (LPARAM)&rc);
if (pt.x >= rc.left) {
CMsgDialog *pDlg = dat->GetChildFromHWND(dat->m_hwndActive);
if (pDlg != nullptr)
CheckStatusIconClick(pDlg->m_hContact, dat->m_hwndStatus, pt, rc, 2, MBCF_RIGHTBUTTON);
break;
}
else SendMessage(dat->m_hwndActive, WM_CONTEXTMENU, (WPARAM)hwndDlg, 0);
}
break;
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE) {
uint32_t ws = GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
ws |= dat->flags2.bUseTransparency ? WS_EX_LAYERED : 0;
SetWindowLongPtr(hwndDlg, GWL_EXSTYLE, ws);
if (dat->flags2.bUseTransparency)
SetLayeredWindowAttributes(hwndDlg, RGB(255, 255, 255), (uint8_t)(255 - g_dat.inactiveAlpha), LWA_ALPHA);
break;
}
if (dat->m_hwndActive != nullptr) {
dat->ActivateChild(dat->GetChildFromHWND(dat->m_hwndActive));
g_dat.hFocusWnd = dat->m_hwndActive;
PostMessage(dat->m_hwndActive, DM_SETFOCUS, 0, msg);
}
if (KillTimer(hwndDlg, TIMERID_FLASHWND)) {
FlashWindow(hwndDlg, FALSE);
dat->nFlash = 0;
}
{
uint32_t ws = GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
ws |= dat->flags2.bUseTransparency ? WS_EX_LAYERED : 0;
SetWindowLongPtr(hwndDlg, GWL_EXSTYLE, ws);
}
if (dat->flags2.bUseTransparency)
SetLayeredWindowAttributes(hwndDlg, RGB(255, 255, 255), (uint8_t)(255 - g_dat.activeAlpha), LWA_ALPHA);
break;
case WM_LBUTTONDOWN:
if (!IsZoomed(hwndDlg)) {
POINT pt;
GetCursorPos(&pt);
return SendMessage(hwndDlg, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, MAKELPARAM(pt.x, pt.y));
}
break;
case WM_MOVING:
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000)) {
int snapPixels = 10;
RECT *pRect = (RECT *)lParam;
HMONITOR hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST);
SIZE szSize = { pRect->right - pRect->left, pRect->bottom - pRect->top };
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
POINT pt;
GetCursorPos(&pt);
RECT rcDesktop = mi.rcWork;
pRect->left = pt.x - dat->mouseLBDownPos.x;
pRect->top = pt.y - dat->mouseLBDownPos.y;
pRect->right = pRect->left + szSize.cx;
pRect->bottom = pRect->top + szSize.cy;
if (pRect->top < rcDesktop.top + snapPixels && pRect->top > rcDesktop.top - snapPixels) {
pRect->top = rcDesktop.top;
pRect->bottom = rcDesktop.top + szSize.cy;
}
if (pRect->left < rcDesktop.left + snapPixels && pRect->left > rcDesktop.left - snapPixels) {
pRect->left = rcDesktop.left;
pRect->right = rcDesktop.left + szSize.cx;
}
if (pRect->right < rcDesktop.right + snapPixels && pRect->right > rcDesktop.right - snapPixels) {
pRect->right = rcDesktop.right;
pRect->left = rcDesktop.right - szSize.cx;
}
if (pRect->bottom < rcDesktop.bottom + snapPixels && pRect->bottom > rcDesktop.bottom - snapPixels) {
pRect->bottom = rcDesktop.bottom;
pRect->top = rcDesktop.bottom - szSize.cy;
}
}
break;
case WM_SYSCOMMAND:
if ((wParam & 0xFFF0) == SC_MAXIMIZE) {
if (GetKeyState(VK_CONTROL) & 0x8000)
dat->bVMaximized = 1;
else
dat->bVMaximized = 0;
}
else if ((wParam & 0xFFF0) == SC_MOVE) {
RECT rc;
GetWindowRect(hwndDlg, &rc);
dat->mouseLBDownPos.x = LOWORD(lParam) - rc.left;
dat->mouseLBDownPos.y = HIWORD(lParam) - rc.top;
}
else if (wParam == IDM_TOPMOST) {
HMENU hMenu = GetSystemMenu(hwndDlg, FALSE);
if (dat->bTopmost) {
CheckMenuItem(hMenu, IDM_TOPMOST, MF_BYCOMMAND | MF_UNCHECKED);
SetWindowPos(hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
dat->bTopmost = false;
}
else {
CheckMenuItem(hMenu, IDM_TOPMOST, MF_BYCOMMAND | MF_CHECKED);
SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
dat->bTopmost = true;
}
}
break;
case WM_DESTROY:
for (int i = dat->m_iChildrenCount; i >= 0; i--) {
TCITEM tci;
tci.mask = TCIF_PARAM | TCIF_IMAGE;
if (TabCtrl_GetItem(dat->m_hwndTabs, i, &tci)) {
ReleaseIcon(tci.iImage);
TabCtrl_DeleteItem(dat->m_hwndTabs, i);
}
}
g_plugin.setDword("splitterx", dat->iSplitterX);
g_plugin.setDword("splittery", dat->iSplitterY);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
WindowList_Remove(g_dat.hParentWindowList, hwndDlg);
{
int savePerContact = g_plugin.bSavePerContact && !dat->flags2.bUseTabs;
MCONTACT hContact = (savePerContact) ? dat->m_hContact : 0;
Utils_SaveWindowPosition(hwndDlg, hContact, SRMM_MODULE, (!savePerContact && dat->isChat) ? "chat" : "");
g_plugin.bTopmost = dat->bTopmost;
}
if (g_dat.lastParent == dat)
g_dat.lastParent = dat->prev;
if (g_dat.lastChatParent == dat)
g_dat.lastChatParent = dat->prev;
if (dat->prev != nullptr)
dat->prev->next = dat->next;
if (dat->next != nullptr)
dat->next->prev = dat->prev;
UnsubclassTabCtrl(dat->m_hwndTabs);
mir_free(dat);
break;
case DM_OPTIONSAPPLIED:
dat->flags2 = g_dat.flags2;
dat->SetContainerWindowStyle();
SendMessage(hwndDlg, WM_SIZE, 0, 0);
break;
case DM_STATUSICONCHANGE:
SendMessage(dat->m_hwndStatus, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW) | 2, 0);
SetupStatusBar(dat);
RedrawWindow(dat->m_hwndStatus, nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
break;
case DM_CASCADENEWWINDOW:
if ((HWND)wParam != hwndDlg) {
RECT rcThis, rcNew;
GetWindowRect(hwndDlg, &rcThis);
GetWindowRect((HWND)wParam, &rcNew);
if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) {
int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
SetWindowPos((HWND)wParam, nullptr, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
*(int *)lParam = 1;
}
}
break;
}
return FALSE;
}
static void DrawTab(ParentWindowData *dat, HWND hwnd, WPARAM, LPARAM lParam)
{
LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)lParam;
int iTabIndex = lpDIS->itemID;
if (iTabIndex < 0)
return;
TabCtrlData *tcdat = (TabCtrlData*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
int tstate = 0;
wchar_t szLabel[1024];
TCITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE;
tci.pszText = szLabel;
tci.cchTextMax = _countof(szLabel);
tci.dwStateMask = TCIS_HIGHLIGHTED;
if (!TabCtrl_GetItem(hwnd, iTabIndex, &tci))
return;
IMAGEINFO info;
RECT rIcon = lpDIS->rcItem;
RECT rect = lpDIS->rcItem;
RECT rectTab = lpDIS->rcItem;
int bSelected = lpDIS->itemState & ODS_SELECTED;
int atTop = (GetWindowLongPtr(hwnd, GWL_STYLE) & TCS_BOTTOM) == 0;
UINT dwFormat;
HANDLE hTheme = nullptr;
if (!IsAppThemed())
FillRect(lpDIS->hDC, &rect, GetSysColorBrush(COLOR_BTNFACE));
else {
if (lpDIS->itemState & ODS_SELECTED)
tstate = TTIS_SELECTED;
else if (lpDIS->itemState & ODS_FOCUS)
tstate = TTIS_FOCUSED;
else if (lpDIS->itemState & ODS_HOTLIGHT)
tstate = TTIS_HOT;
else
tstate = TTIS_NORMAL;
if (!bSelected)
InflateRect(&rectTab, 1, 1);
hTheme = OpenThemeData(hwnd, L"TAB");
if (IsThemeBackgroundPartiallyTransparent(hTheme, TABP_TABITEM, tstate))
DrawThemeParentBackground(hwnd, lpDIS->hDC, &rectTab);
DrawThemeBackground(hTheme, lpDIS->hDC, TABP_TABITEM, tstate, &rectTab, nullptr);
}
if (atTop) {
dwFormat = DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOPREFIX | DT_NOCLIP;
rIcon.top = rect.top + GetSystemMetrics(SM_CYEDGE);
if (tci.iImage >= 0) {
rIcon.left = rect.left + GetSystemMetrics(SM_CXEDGE) + (bSelected ? 6 : 2);
ImageList_GetImageInfo(g_dat.hTabIconList, tci.iImage, &info);
ImageList_DrawEx(g_dat.hTabIconList, tci.iImage, lpDIS->hDC, rIcon.left, rIcon.top, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
rect.left = rIcon.left + (info.rcImage.right - info.rcImage.left);
}
if (dat->flags2.bTabCloseButton) {
ImageList_GetImageInfo(g_dat.hTabIconList, 0, &info);
rIcon.left = rect.right - GetSystemMetrics(SM_CXEDGE) - (bSelected ? 6 : 2) - (info.rcImage.right - info.rcImage.left);
ImageList_DrawEx(g_dat.hTabIconList, 0, lpDIS->hDC, rIcon.left, rIcon.top, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
rect.right = rIcon.left - 1;
}
rect.top += GetSystemMetrics(SM_CYEDGE) + 2;
}
else {
dwFormat = DT_SINGLELINE | DT_BOTTOM | DT_CENTER | DT_NOPREFIX | DT_NOCLIP;
rIcon.left = rect.left + GetSystemMetrics(SM_CXEDGE) + (bSelected ? 6 : 2);
if (tci.iImage >= 0) {
ImageList_GetImageInfo(g_dat.hTabIconList, tci.iImage, &info);
rIcon.top = rect.bottom - (info.rcImage.bottom - info.rcImage.top) - 1;
ImageList_DrawEx(g_dat.hTabIconList, tci.iImage, lpDIS->hDC, rIcon.left, rIcon.top, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
rect.left = rIcon.left + (info.rcImage.right - info.rcImage.left);
}
if (dat->flags2.bTabCloseButton) {
ImageList_GetImageInfo(g_dat.hTabIconList, 0, &info);
rIcon.top = rect.bottom - (info.rcImage.bottom - info.rcImage.top) - 2;
rIcon.left = rect.right - GetSystemMetrics(SM_CXEDGE) - (bSelected ? 6 : 2) - (info.rcImage.right - info.rcImage.left);
ImageList_DrawEx(g_dat.hTabIconList, 0, lpDIS->hDC, rIcon.left, rIcon.top, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
rect.right = rIcon.left - 1;
}
rect.bottom -= GetSystemMetrics(SM_CYEDGE) + 2;
}
if (hTheme)
DrawThemeText(hTheme, lpDIS->hDC, TABP_TABITEM, tstate, szLabel, -1, dwFormat, 0, &rect);
else
DrawText(lpDIS->hDC, szLabel, -1, &rect, dwFormat);
if (tcdat->bDragged && iTabIndex == tcdat->destTab && iTabIndex != tcdat->srcTab) {
RECT hlRect = lpDIS->rcItem;
if (bSelected) {
hlRect.bottom -= GetSystemMetrics(SM_CYEDGE);
hlRect.top += GetSystemMetrics(SM_CYEDGE);
hlRect.left += GetSystemMetrics(SM_CXEDGE);
hlRect.right -= GetSystemMetrics(SM_CXEDGE);
}
else {
if (atTop) {
hlRect.top += GetSystemMetrics(SM_CYEDGE);
hlRect.bottom += GetSystemMetrics(SM_CYEDGE);
}
else {
hlRect.top -= GetSystemMetrics(SM_CYEDGE);
hlRect.bottom -= GetSystemMetrics(SM_CYEDGE);
}
}
FrameRect(lpDIS->hDC, &hlRect, GetSysColorBrush(COLOR_HIGHLIGHT));
hlRect.left++;
hlRect.top++;
hlRect.right--;
hlRect.bottom--;
FrameRect(lpDIS->hDC, &hlRect, GetSysColorBrush(COLOR_HIGHLIGHT));
}
if (hTheme)
CloseThemeData(hTheme);
}
HWND GetParentWindow(MCONTACT hContact, bool bChat)
{
NewMessageWindowLParam newData = { 0 };
newData.hContact = hContact;
newData.isChat = bChat;
if (g_dat.flags2.bUseTabs) {
if (!bChat || !g_dat.flags2.bSeparateChats) {
if (g_dat.lastParent != nullptr) {
int tabsNum = g_dat.lastParent->GetChildCount();
if (!g_dat.flags2.bLimitTabs || tabsNum < g_dat.limitTabsNum)
return g_dat.lastParent->m_hwnd;
}
}
else {
if (g_dat.lastChatParent != nullptr) {
int tabsNum = g_dat.lastChatParent->GetChildCount();
if (!g_dat.flags2.bLimitChatTabs || tabsNum < g_dat.limitChatsTabsNum)
return g_dat.lastChatParent->m_hwnd;
}
}
}
if (!g_dat.flags2.bSeparateChats)
newData.isChat = false;
return CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MSGWIN), nullptr, DlgProcParentWindow, (LPARAM)&newData);
}
|