This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_cntlist.cpp
1469 lines (1302 loc) · 49.8 KB
/
ui_cntlist.cpp
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
/*
Konnekt UI
Obs³uga listy kontaktów.
*/
#include "stdafx.h"
#pragma hdrstop
#include "include\win_listview.h"
#include "include\preg.h"
#include "include\fontpicker.h"
#include "ui_main.h"
#include "ui_actions.h"
#include "ui_msgcontrol.h"
#include "ui_cntlist.h"
#include "ui_cntlistfilter.h"
#include "ui_window.h"
#include "ui_dialogs.h"
#include "ui_history.h"
#include "ui_ui.h"
#define CLINFO_MARGIN 4
cCntList cntList;
cCntListWindow * cntListWnd = 0;
cCntListTip * cntTip = 0;
void sUICnt::close () {
if (hwndMsg) DestroyWindow(hwndMsg);
if (hwndInfo) DestroyWindow(hwndInfo);
hwndMsg = hwndInfo = 0;
}
void sUICnt::MsgGetHandles() {
}
int sUICnt::MsgUpdate(bool getHandles) {
if (!hwndMsg) return 0;
ActionStatus(Act[IMIG_MSGTB](IMIA_MSG_INFO).act(this->ID),-1,0,this->GetStatusIcon(false));
SendMessage(hwndMsg , MYWM_REFRESH , 0 , 0);
return 1;
}
void sUICnt::setStatus(int status , string info) {
if (this->hwndMsg && status!=-1 && GETINT(CFG_UIMSGSHOWSTATUS) && _msgControl) {
this->_msgControl->statusInsert(status & ST_MASK , info);
}
}
int sUICnt::GetStatusIcon(bool sameStatus) {
int icon = GETCNTI(this->ID , CNT_STATUS_ICON);
if (this->status & ST_COMPOSING)
icon = UIIcon(IT_STATUS , 0 , ST_COMPOSING , 0);
if (!icon) {
if (this->net == NET_NONE)
icon = IDI_NET_NONE;
else
icon = sameStatus
?UIIcon(IT_STATUS,0,this->status & CNTM_STATUS,0)
:UIIcon(IT_STATUS,this->net,this->status & CNTM_STATUS,0);
}
// Sprawdzamy czy ikonka w ogole istnieje, a jak nie to bierzemy sobie inna...
if (!Ico.find(icon))
icon=UIIcon(IT_STATUS,0,this->status & CNTM_STATUS,0);
return icon;
}
void sUICnt::cfgSet() {
// Kolorki
if (!this->hwndMsg) return;
// LOGFONTEX lfeBg = StrToLogFont(GETSTR(CFG_UIF_MSG)); //tlo
LOGFONTEX lfe = StrToLogFont(GETSTR(CFG_UIF_MSGSEND)); //czcionka
//HWND hwnd = GetDlgItem(this->hwndMsg , IDC_EDIT);
/* SetProp(hwnd , "Color" , (HANDLE)lfe.color);
SetProp(hwnd , "BGColor" , (HANDLE)lfe.bgColor);
SendMessage(hwnd , WM_SETFONT , (WPARAM)fontMsgSend , 1);*/
}
void sUICnt::MsgSend() {
// Szykujemy obiekt wiadomoœci...
CStdString buff;
cMessage m;
m.id=0;
m.net=GETCNTI(this->ID , CNT_NET);
m.type=MT_MESSAGE;
m.fromUid="";
char UIDbuff [500];
m.toUid=(char *)GETCNTC(this->ID , CNT_UID , UIDbuff , 500);
m.ext="";
m.flag = MF_SEND;
m.notify = 0;
m.action = NOACTION;
m.time = cTime64(true);
// Wczytujemy treϾ
sUIAction sendAct = sUIAction(IMIG_MSGWND , Konnekt::UI::ACT::msg_ctrlsend , this->ID);
Konnekt::UI::Notify::_getMessage gm (0,0);
Act(sendAct).setCnt(this->ID);
gm._size = Act(sendAct).call(Konnekt::UI::Notify::getMessageSize , 0 , 0);
if (!gm._size) gm._size = 65000;
gm._size ++;
gm._message = &m;
m.body = buff.GetBuffer(gm._size);
Act(sendAct).call(&gm);
buff.ReleaseBuffer();
// Czyscimy
cPreg Preg;
buff = Preg.replace("/(^[\\r\\n ]+)/g" , "" , buff);
buff = Preg.replace("/([\\r\\n ]+)$/g" , "" , buff);
if (buff.empty()) {
cMessage m;
m.net = this->net;
m.type = MT_QUICKEVENT;
m.fromUid = (char*)GETCNTC(this->ID , CNT_UID);
m.toUid = "";
m.body = "Wpisz wiadomoϾ!";
m.ext = "";
m.flag = MF_HANDLEDBYUI;
m.action = NOACTION;
m.notify = 0;
ICMessage(IMC_NEWMESSAGE , (int)&m,0);
return;
}
if (msgHistory.size()<2 || msgHistory[1].body!=buff || msgHistory[1].flag!=m.flag || msgHistory[1].type!=m.type) {
this->msgHistory.insert(msgHistory.begin()+1 , cMsgHistoryEntry(buff , m.ext , m.type , m.flag)); // wrzucamy nowy "wpis"
// czyscimy jak jest ich za duzo...
if (msgHistory.size()>MSGSENDHISTORY_LIMIT)
msgHistory.erase(msgHistory.begin()+MSGSENDHISTORY_LIMIT , msgHistory.end());
}
msgHistoryPos = 0;
ActionStatus(sUIAction(IMIG_MSGTB , IMIA_MSG_SEND , this->ID) , ACTS_DISABLED);
SetProp(hwndMsg , "SENDING" , (void*)1);
m.body = (char*)buff.c_str(); //wrzucamy najaktualniejsza wersje
IMessage(IMC_NEWMESSAGE , 0 , 0 , (int)&m);
int session = (int)GetProp(hwndMsg , "MsgSession");
hist_add(&m , HISTDIR_MSG , this , 0 , session);
if (!session) SetProp(hwndMsg , "MsgSession" , (void*)1);
// sTime64 * st = (sTime64*)(&m.time);
if (!(m.flag & MF_HIDE)) {
this->_msgControl->msgInsert(&m);
}
SetDlgItemText(hwndMsg , Act(sendAct).index , "");
sMESSAGESELECT mSel;
mSel.id = m.id;
if (mSel.id) ICMessage(IMC_MESSAGEQUEUE , (int)&mSel);
SetProp(hwndMsg , "SENDING" , 0);
ActionStatus(sUIAction(IMIG_MSGTB , IMIA_MSG_SEND , this->ID) , 0);
}
void sUICnt::MsgWndOpen(bool queue , bool autoPopup) {
using namespace Konnekt::UI;
CFG::enMsgPopup popup = autoPopup ? (CFG::enMsgPopup) GETINT(CFG_UIMSGPOPUP) : CFG::mpFocused;
if (!hwndMsg) {
//msgStatus = status & ST_MASK;
hwndMsg=CreateDialogParam(Ctrl->hDll() , MAKEINTRESOURCE(IDD_MSG)
, 0/*hwndTop*/ , (DLGPROC)MsgDialogProc , (long)this);
cfgSet();
onSizeMsg(hwndMsg , 0,0);
}
if (popup == CFG::mpFocused) {
if (IsIconic(hwndMsg)) OpenIcon(hwndMsg);
SetForegroundWindow(hwndMsg);
SetActiveWindow(hwndMsg);
SetWindowPos(hwndMsg , HWND_TOP , 0 , 0 , 0 , 0 , SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetFocus(GetDlgItem(hwndMsg , Act(sUIAction(IMIG_MSGWND , Konnekt::UI::ACT::msg_ctrlsend , this->ID)).index));
} else
ShowWindow(hwndMsg, popup == CFG::mpBackground ? SW_SHOWNOACTIVATE : popup == CFG::mpMinimized ? SW_SHOWMINNOACTIVE : SW_SHOW);
if (queue) ICMessage(IMC_MESSAGEQUEUE , (int)&sMESSAGESELECT(net , GETCNTC(this->ID,CNT_UID) , -1 , 0 , MF_SEND));
}
void sUICnt::MsgWndClose(){
this->hwndMsg = 0;
delete this->_msgControl;
_msgControl = 0;
/*
sUIActionNotify_destroyWindow dw;
Act(sUIAction(IMIG_MSGWND , Konnekt::UI::ACT::msg_ctrlsend , this->ID)).call(&dw);
*/
}
void sUICnt::InfoWndOpen(bool newUser) {
if (!hwndInfo) {
hwndInfo=CreateDialogParam(Ctrl->hDll() , MAKEINTRESOURCE(IDD_INFO)
, /*hwndTop*/ 0 , (DLGPROC)InfoDialogProc , (long)this);
if (newUser) {SetProp(hwndInfo , "NEWContact" , (void*)1);}
SendMessage(hwndInfo , MYWM_REFRESH , 0 , 0 );
ShowWindow(hwndInfo, SW_SHOW);
}
else SetForegroundWindow(hwndInfo);
}
bool sUICnt::haveMsgHistory(bool next) {
if (next)
return (this->msgHistoryPos > 0);
else
return (this->msgHistoryPos < (int)this->msgHistory.size()-1);
}
void sUICnt::useMsgHistory(bool next) {
if (!haveMsgHistory(next)) return;
cUIAction & sendAct = Act(sUIAction(IMIG_MSGWND , UI::ACT::msg_ctrlsend , this->ID));
sendAct.setCnt(this->ID);
int length = sendAct.call(UI::Notify::getMessageSize , 0 , 0);
UI::Notify::_getSelection gs;
sendAct.call(&gs);
if (!next) { // Poprzedni
// Trzeba zapamiêtaæ aktualnego...
if (this->msgHistoryPos==0) {
cMessage m;
UI::Notify::_getMessage gm (&m,0);
gm._size = length + 1;
cMsgHistoryEntry & mhe = this->msgHistory[0];
m.body = mhe.body.GetBuffer(gm._size);
sendAct.call(&gm);
mhe.body.ReleaseBuffer();
mhe.ext = m.ext;
mhe.flag = m.flag;
mhe.type = m.type;
}
++this->msgHistoryPos;
} else { // Nastêpny
--this->msgHistoryPos;
}
cMessage m;
cMsgHistoryEntry & mhe = this->msgHistory[this->msgHistoryPos];
m.body = (char*) mhe.body.c_str();
m.ext = (char*) mhe.ext.c_str();
m.type = mhe.type;
m.flag = mhe.flag;
UI::Notify::_insertMsg im(&m , 0 , false);
sendAct.call(&im);
}
void sUICnt::clearMsgHistory() {
this->msgHistory.clear();
this->msgHistoryPos=0;
this->msgHistory.push_front(cMsgHistoryEntry("" , "" , MT_MESSAGE , MF_SEND));
}
void cUICnts::closeAll() {
/* for (Cnt_it_t Cnt_it = Cnt.begin(); Cnt_it != Cnt.end(); Cnt_it++) {
if (Cnt_it->second) {
Cnt_it->second->close();
delete Cnt_it->second;
}
Cnt_it->second=0;
}
*/
while (Cnt.size()) {
Cnt_it_t Cnt_it = Cnt.begin();
sUICnt * temp = Cnt_it->second;
if (temp)
temp->close();
Cnt.erase(Cnt_it);
if (temp)
delete temp;
}
}
bool cUICnts::exists(int id) {
if (!DT_ISROWID(id)) id = Ctrl->DTgetID(DTCNT , id);
return (Cnt.find(id)!=Cnt.end());
}
sUICnt & cUICnts::operator [] (int n) {
if (!DT_ISROWID(n)) n = Ctrl->DTgetID(DTCNT , n);
return *Cnt[n];
}
cUICnts::~cUICnts() {
//closeAll();
}
int cUICnts::compare(sUICnt * a, sUICnt * b) {
#define COMPARE(A , B) { \
if ((##A) != (##B)) {\
if ((##A)) return 1; \
else if ((##B)) return -1;}\
}
COMPARE(a->status & ST_NOTINLIST , b->status & ST_NOTINLIST);
COMPARE(a->status & ST_IGNORED , b->status & ST_IGNORED);
if (a->net != b->net)
if (a->net == NET_NONE) return 1;
else if (b->net == NET_NONE) return -1;
// COMPARE(status & CNTM_STATUS == ST_OFFLINE);
if ((a->status & CNTM_STATUS)/0x20 != (b->status & CNTM_STATUS)/0x20) {
return ((a->status & CNTM_STATUS)/0x20 > (b->status & CNTM_STATUS)/0x20)?-1:1;
}
if ((a->status & CNTM_STATUS) < ST_SEMIONLINE && GETINT(CFG_UISORTACTIVE)) {COMPARE(!a->active , !b->active);}
#undef COMPARE
// const char * c1 = GETCNTC(a->ID , CNT_DISPLAY);
// const char * c2 = GETCNTC(b->ID , CNT_DISPLAY);
// const char * c1 = "Przyk³ad";
// const char * c2 = "Dupek";
return _stricoll(a->display.c_str() , b->display.c_str());
// return stricmp(GETCNTC(a->ID , CNT_DISPLAY) , GETCNTC(b->ID , CNT_DISPLAY));
}
void cUICnts::sort() {
// std::sort(Cnt.begin()+1 , Cnt.end() , &compare );
}
void cUICnts::cfgSet() {
for (Cnt_it_t it=this->Cnt.begin(); it != Cnt.end(); it++)
it->second->cfgSet();
imPrepare();
}
void cUICnts::checkActivity(bool force) {
static int lastCheck = time(0);
if (force || time(0)-lastCheck > 600) {
for (Cnt_it_t it=this->Cnt.begin(); it!=Cnt.end(); it++)
it->second->checkActivity();
this->sort();
}
}
void cUICnts::imPrepare ()
{
int c=IMessage(IMC_CNT_COUNT);
// if (c>Cnt.size()) {
// for (int i = 0; i<Cnt.size() - c; i++) imAdd(-1);
// }
// Cnt.resize(c);
for (int i=0;i<c;i++) {
int ID = Ctrl->DTgetID(DTCNT , i);
if (ID == -1) continue;
if (Cnt.find(ID)==Cnt.end()) {imAdd(ID);Cnt[ID]->hidden=false;}
if (i) Cnt[ID]->imRefresh();
else Cnt[ID]->user = 1;
}
}
void cUICnts::imAdd (int id , bool hidden) {
if ((id = Ctrl->DTgetID(DTCNT , id))==-1) return;
if (!this->exists(id)) {
Cnt[id]=new sUICnt;
Cnt[id]->hidden = hidden;
Cnt[id]->ID = (Ctrl->DTgetPos(DTCNT , id))?id : 0;
Cnt[id]->imRefresh();
} else if (!Cnt[id]->hidden) return;
UI::CntList::filters.ApplyToCnt(Cnt[id]);
}
void cUICnts::imRemove (int id , bool massive=false) {
if ((id = Ctrl->DTgetID(DTCNT , id))==-1) return;
cntList.removeCnt(Cnt[id]);
Cnt[id]->close();
delete Cnt[id];
Cnt.erase(id);
// for (Cnt_it=Cnt.begin(); Cnt_it!=Cnt.end(); Cnt_it++) {
// if ((*Cnt_it)->pos > pos) (*Cnt_it)->pos--; // zmniejsza wszystkie pozycje o jeden
// }
}
void sUICnt::ApplyFilters() {
Konnekt::UI::CntList::filters.ApplyToCnt(this);
}
CStdString sUICnt::getDisplayFormatted() {
char * format = (char*)GETSTR(CFG_UICL_DISPLAY_FORMAT);
if (!*format) { // standardowa obs³uga
format = (char*)GETCNTC(this->ID,CNT_DISPLAY);
if (!*format)
return GETCNTC(this->ID, CNT_UID);
return format;
}
// formatujemy linijkami... bierzemy pierwsz¹ nie pust¹...
format = strdup(format);
format = removeChar(format, '\r');
char * line = format;
CStdString result;
while (((int)line > 1) && result.empty()) {
char * newline = strchr(line, '\n');
if (newline) *newline = 0;
result = formatTitle(line, this->ID, FT_DISPLAY);
line = newline+1;
}
free(format);
return result;
}
void sUICnt::imRefresh () {
int id=ID;
net=GETCNTI(id,CNT_NET);
// Cnt[id]->UID=GETCNTC(pos,CNT_UID);
status=GETCNTI(id,CNT_STATUS);
display=getDisplayFormatted();
MsgUpdate();
checkActivity();
if (cntTip->docked && cntTip->cnt==Ctrl->DTgetPos(DTCNT , this->ID))
cntTip->refresh();
ApplyFilters();
}
void sUICnt::checkActivity() {
if (active && Ctrl->DTgetInt64(DTCNT , this->ID , CNT_LASTACTIVITY) < _time64(0)-1200)
active=false;
}
int cUICnts::findBy(int val , char by) {
for (Cnt_it_t Cnt_it = Cnt.begin(); Cnt_it != Cnt.end(); Cnt_it++) {
switch(by) {
case 1: if (Cnt_it->second->hwndInfo==(void*)val) break;
case 2: if (Cnt_it->second->hwndMsg==(void*)val) break;
}
}
return -1;
}
void cCntListWindow::callDefaultAction() {
// if (>1) return 0;
int selStart = SendMessage(hwndList , LVM_GETSELECTIONMARK , 0 , 0);
int selCount = ListView_GetSelectedCount(this->_hwnd);
if (selStart < 0) return;
sUICnt * pCnt = (sUICnt*)ListView_GetItemData(this->_hwnd , selStart);
sUIAction act;
if (!pCnt) return;
if (selCount == 1 && pCnt->action.id) {
act = pCnt->action;
} else {/* Ustalamy defaultowa akcje */
act.parent = act.id = 0;
Act[IMIG_CNT].setCnt(selCount > 1 ? -1 : pCnt->ID , true);
cUIAction * action = Act[IMIG_CNT].getDefaultAction();
if (action) act = action->act();
}
if (!Act.exists(act)) {/*IMLOG("NO_PARENT!");*/return;}
Act(act).setCnt(selCount > 1 ? -1 : pCnt->ID);
Act(act).call(ACTN_ACTION,0,0);
}
INT_PTR CALLBACK cCntListWindow::ListControlProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
cCntListWindow * clw = (cCntListWindow *)GetProp(hwnd , "cCntListWindow");
if (!clw) return 0;
TRACKMOUSEEVENT tme;
RECT rc;
static bool cursorInList = false;
static bool canShow = false;
switch (message)
{
case WM_ERASEBKGND: {
// HDC DC = GetDC(hwnd);
HDC DC = (HDC)wParam;
GetChildRect(hwnd , &rc);
rc.left=rc.top=0;
int last , count;
last=ListView_GetTopIndex(hwnd)+ListView_GetCountPerPage(hwnd);
count=ListView_GetItemCount(hwnd);
HBRUSH hbr = CreateSolidBrush(clw->parent->_lfItem.bgColor);
if (clw->parent->_flickerFree && count) {
if (last >= count) {
RECT rc2;
ListView_GetItemRect(hwnd , count-1 , &rc2 , LVIR_BOUNDS);
rc.top=rc2.bottom;
FillRect(DC , &rc , hbr);
}
rc.top=0;
rc.bottom = 5;
FillRect(DC , &rc , hbr); // Czyscimy gorna ramke
} else { // calosc
FillRect(DC , &rc , hbr);
}
DeleteObject(hbr);
// FloodFill(DC , 0 , 0 , GetSysColor(COLOR_HIGHLIGHT));
// ReleaseDC(hwnd , DC);
return 1;}
case WM_MOUSEMOVE:
if (!cursorInList) {
cursorInList = true;
// IMLOG("SETTING HOVER");
tme.cbSize = sizeof (tme);
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.hwndTrack = hwnd;
tme.dwHoverTime = GETINT(CFG_UITIPDELAY);
_TrackMouseEvent(&tme);
}
if (canShow && clw->tip && !clw->tip->docked) clw->tip->show(-2 , hwnd);
break;
case WM_MOUSELEAVE:
cursorInList = false;
// GetCursorPos(&pt);
// GetWindowRect(hwndListTip , &rc);
// rc.right-=30;
// pt.x++;pt.y++;
// IMLOG("PT %d %d , RC %d %d %d %d" , pt.x , pt.y , rc.left , rc.top , rc.right , rc.bottom);
// if (PtInRect(&rc , pt)) {
// ListControlProc(hwnd , WM_MOUSEMOVE , 0 , 0);
// return 0;
// }
// IMLOG("LEAVE");
if (clw->tip && !clw->tip->docked) clw->tip->show(-1);
canShow = false;
break;
case WM_MOUSEHOVER:
// IMLOG("HOVER");
canShow = true;
tme.cbSize = sizeof (tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
_TrackMouseEvent(&tme);
// ListTipShow(-3);
if (clw->tip && !clw->tip->docked) clw->tip->show(-2,hwnd);
return 0;
case WM_LBUTTONDOWN: case WM_RBUTTONDOWN:
clw->lookupLast = 0;
clw->lookupString = "";
canShow = false;
cursorInList = false;
if (clw->tip && !clw->tip->docked) clw->tip->show(-1);
break;
case WM_CONTEXTMENU:
if (wParam == (unsigned int)clw->_hwnd) {
POINT pt;
int cnt;
if (lParam != -1) {
pt.x=LOWORD(lParam);pt.y=HIWORD(lParam);
ScreenToClient(clw->_hwnd , &pt);
cnt = ListView_ItemFromPoint(hwndList , pt);
if (cnt<0) return 0;
if (!ListView_GetItemState(clw->_hwnd , cnt , LVIS_SELECTED)) {
ListView_Deselect(clw->_hwnd);
ListView_SetItemState(clw->_hwnd , cnt , LVIS_SELECTED , LVIS_SELECTED);
ListView_SetSelectionMark(clw->_hwnd , cnt);
}
} else {
cnt = ListView_GetSelectionMark(clw->_hwnd);
if (cnt<0) return 0;
ListView_GetItemPosition(clw->_hwnd , cnt , &pt);
pt.x += 20;
pt.y += 16;
}
ClientToScreen(clw->_hwnd , &pt);
if (ListView_GetSelectedCount(clw->_hwnd)>1) Act[IMIG_CNT].setCnt(-1 , true);
else Act[IMIG_CNT].setCnt(((sUICnt *)ListView_GetItemData(clw->_hwnd , cnt))->ID);
UIPopupMenu(Act[IMIG_CNT],TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD,
pt.x,pt.y,0,GetParent(clw->_hwnd) , 0);
}
return 0;
case WM_ACTIVATE:
clw->lookupString = "";
clw->lookupLast = 0;
break;
case WM_KEYUP:
if (wParam > 0x20 && wParam <=0x2F) {clw->lookupString = "";clw->lookupLast=0;}
if (wParam == VK_DELETE) {
if (ListView_GetSelectedCount(clw->_hwnd)<1) return 0;
// Act[IMIG_CNT].setCnt(((sUICnt *)ListView_GetItemData(clw->_hwnd , ListView_GetSelectionMark(clw->_hwnd)))->ID);
Act[IMIG_CNT].setCnt(-1);
Act(IMIG_CNT , IMIA_CNT_DEL).call(ACTN_ACTION,0,0);
SetActiveWindow(clw->_hwnd);
} else if (wParam == VK_RETURN) {
if (!SendMessage(clw->_hwnd , LVM_GETEDITCONTROL , 0 , 0))
clw->callDefaultAction();
}
break;
case WM_CHAR: {
if (wParam == VK_SPACE) {clw->lookupLast++;}
else {clw->lookupString += (char)wParam;}
// Przeszukiwanie po liscie
int c=ListView_GetItemCount(clw->_hwnd);
if (clw->lookupLast > c) clw->lookupLast = 0;
int i=clw->lookupLast;
bool found = false;
do {
sUICnt * cnt = (sUICnt *)ListView_GetItemData(clw->_hwnd , i);
if (!cnt) break;
if (!strnicmp(clw->lookupString , cnt->display.c_str() , clw->lookupString.size())) {
ListView_SetCurSel(clw->_hwnd , i);
ListView_SetItemState(clw->_hwnd , i , LVIS_FOCUSED , LVIS_FOCUSED);
clw->lookupLast = i;
found = true;
break;
}
i++;
if (i>=c) i=0;
} while (i!=clw->lookupLast); // Dopoki nie dojedzie do poczatku
if (!found) {
int t = clw->lookupString.size();
clw->lookupLast = 0;
clw->lookupString = "";
if (t>1) ListControlProc(hwnd , message , wParam , lParam);
}
return 0;}
}
return CallWindowProc((WNDPROC)clw->_oldwndproc , hwnd , message , wParam , lParam);
}
// ---------------------------------------------------------------------------
int CALLBACK sortList_compare(LPARAM p1, LPARAM p2, LPARAM lParam) {
return Cnt.compare((sUICnt*)p1 , (sUICnt*)p2);
}
int dragdropList(HWND hwnd, UINT message , WPARAM wParam , LPARAM lParam )
{
static bool dragging = false;
static int dragIndex = -1;
static HIMAGELIST dragImage;
static int dropIndex = -1;
POINT pt;
if (!hwnd) return dragging?1:0;
switch (message)
{
case WM_NOTIFY:
NMHDR * nm;nm=(NMHDR*)lParam;
switch (nm->code) {
case LVN_BEGINDRAG:
dragIndex = ((NM_LISTVIEW *)lParam)->iItem;
pt.x = 0;
pt.y = 0;
ImageList_BeginDrag(Ico.iml[0] , Ico[IDI_NET_NONE].index[0], pt.x , pt.y);
GetCursorPos(&pt);
ImageList_DragEnter(
GetDesktopWindow(), pt.x , pt.y);
dragging = true;
SetCapture(hwndMain);
}
break;
case WM_LBUTTONUP:
ReleaseCapture();
ImageList_DragLeave(hwndMain);
ImageList_EndDrag();
if (dropIndex>=0) {
int c = ListView_GetItemCount(cntListWnd->_hwnd);
TCITEM tci;
*TLS().buff = 0;
if (dropIndex) {
tci.mask = TCIF_TEXT;
tci.pszText = TLS().buff;
tci.cchTextMax = MAX_STRING;
TabCtrl_GetItem(hwndGroups , dropIndex , &tci);
}
for (int i = 0; i<c ; i++) {
if (ListView_GetItemState(cntListWnd->_hwnd , i , LVIS_SELECTED)) {
sUICnt * cnt = (sUICnt *)ListView_GetItemData(cntListWnd->_hwnd , i);
if (!cnt) continue;
SETCNTC(cnt->ID , CNT_GROUP , TLS().buff);
sIMessage_CntChanged cc(IMC_CNT_CHANGED , cnt->ID);
cc._changed.group = 1;
IMessage(&cc);
}
}
ICMessage(IMI_REFRESH_LST , 1);
}
// ImageList_Destroy(dragImage);
dragging = false;
break;
case WM_MOUSEMOVE:
GetCursorPos(&pt);
ImageList_DragMove(pt.x , pt.y - 14);
ScreenToClient(hwndGroups , &pt);
TCHITTESTINFO tchti;
tchti.pt = pt;
dropIndex = TabCtrl_HitTest(hwndGroups , &tchti);
if (tchti.flags & (TCHT_ONITEMLABEL | TCHT_ONITEMICON)) SetCursor(LoadCursor(0 , IDC_ARROW));
else SetCursor(LoadCursor(0 , IDC_NO));
break;
}
return 0;
}
void fillGroups() {
deque <string> items;
TabCtrl_DeleteAllItems(hwndGroups);
char * grps2 = strdup(GETSTR(CFG_GROUPS)) , * grp = grps2 , * grps = grps2;
unsigned int i = 0;
TCITEM tci;
tci.mask = TCIF_IMAGE | TCIF_TEXT;
while ((grps = strchr(grps , '\n'))!=0) {
*grps = 0;
grps++;
if (*grp) {
items.push_back(grp);
}
grp = grps;
}
sort(items.begin() , items.end() , strcompare);
for (i = 0; i < items.size() ; i++) {
tci.pszText = (char *)items[i].c_str();
tci.iImage = -1;
TabCtrl_InsertItem(hwndGroups , i , &tci);
if (!stricmp(GETSTR(CFG_CURGROUP) , items[i].c_str()))
TabCtrl_SetCurSel(hwndGroups , i);
}
if (i) {
tci.pszText = (char*)GETSTR(CFG_UIALLGROUPSDESC);
tci.iImage = Ico[UIIcon(IT_STATUS , NET_NONE , 0 , 0)].index[0];
TabCtrl_InsertItem(hwndGroups , 0 , &tci);
if (!*GETSTR(CFG_CURGROUP))
TabCtrl_SetCurSel(hwndGroups , 0);
}
free(grps2);
}
void selectGroups() {
int pos = TabCtrl_GetCurSel(hwndGroups);
char * ch = "";
if (pos > 0) {
TCITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = TLS().buff;
tci.cchTextMax = MAX_STRING;
TabCtrl_GetItem(hwndGroups , pos , &tci);
if (ICMessage(IMC_GRP_FIND , (int)TLS().buff))
ch = TLS().buff;
}
SETSTR(CFG_CURGROUP , ch);
cntList.refill();
ListView_SetColumnWidth(hwndList , 0 , LVSCW_AUTOSIZE_USEHEADER);
}
// -------------------------------------------------------
void cCntList::registerWnd(class cCntListWindow * wnd) {
_wnd.push_back(wnd);
}
void cCntList::unregisterWnd(class cCntListWindow * wnd){
_wnd.erase(find(_wnd.begin(), _wnd.end() , wnd));
}
bool cCntList::running(){
return _wnd.size()>0;
}
void cCntList::refresh(bool sort){
for (_wnd_it_t it=_wnd.begin(); it!=_wnd.end(); it++) {
(*it)->refresh(sort);
}
}
void cCntList::refill(){
for (_wnd_it_t it=_wnd.begin(); it!=_wnd.end(); it++) {
(*it)->refill();
}
}
void cCntList::removeCnt(sUICnt * cnt){
for (_wnd_it_t it=_wnd.begin(); it!=_wnd.end(); it++) {
(*it)->removeCnt(cnt);
}
}
void cCntList::addCnt(sUICnt * cnt){
for (_wnd_it_t it=_wnd.begin(); it!=_wnd.end(); it++) {
(*it)->addCnt(cnt);
}
}
void cCntList::cfgSet() {
_right = GETINT(CFG_UICL_ICONSONRIGHT) != 0;
_iconson = GETINT(CFG_UICL_ICONSON) != 0;
_icons = GETINT(CFG_UICL_ICONS);
_offset = GETINT(CFG_UICL_ICONSOFFSET) != 0;
_samestatus = GETINT(CFG_UISAMECNTSTATUS) != 0;
_flickerFree = GETINT(CFG_UICL_BUFFEREDPAINT) != 0;
_info = (UI::CFG::enCntListInfo)GETINT(CFG_UICL_INFO);
_infoFormat = GETSTR(CFG_UICL_INFO_FORMAT);
_lfItem = StrToLogFont(GETSTR(CFG_UIF_CLIST));
_lfItemSel = StrToLogFont(GETSTR(CFG_UIF_CLISTSEL));
_lfItemInfo = StrToLogFont(GETSTR(CFG_UIF_CLISTINFO));
if (_hfItem) DeleteObject(_hfItem);
_hfItem = CreateFontIndirect(&_lfItem.lf);
if (_hfItemOnline) DeleteObject(_hfItemOnline);
LOGFONT lf = _lfItem.lf;
if (GETINT(CFG_UIONLINEBOLD))
lf.lfWeight = FW_BOLD;
_hfItemOnline = CreateFontIndirect(&lf);
if (_hfItemSel) DeleteObject(_hfItemSel);
_hfItemSel = CreateFontIndirect(&_lfItemSel.lf);
if (_hfItemInfo) DeleteObject(_hfItemInfo);
_hfItemInfo = CreateFontIndirect(&_lfItemInfo.lf);
for (_wnd_it_t it=_wnd.begin(); it!=_wnd.end(); it++) {
(*it)->cfgSet();
}
}
// ----------------------
cCntListWindow::cCntListWindow(cCntList * owner , int x , int y , int w , int h , HWND parent , HMENU id) {
this->parent = owner;
_hwnd = CreateWindowEx(0,"SysListView32", "",
WS_VISIBLE | WS_CHILD | WS_VSCROLL |
LVS_REPORT | LVS_SHOWSELALWAYS | LVS_EDITLABELS
| LVS_OWNERDRAWFIXED | LVS_NOCOLUMNHEADER
,x, y, w, h , parent, id, 0, NULL);
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.iSubItem = 0;
lvc.pszText = "Kontakty";
lvc.cx = LVSCW_AUTOSIZE_USEHEADER;
ListView_InsertColumn(_hwnd, 0, &lvc);
ListView_SetColumnWidth(_hwnd , 0 , LVSCW_AUTOSIZE_USEHEADER);
ListView_SetImageList(_hwnd , LVSIL_SMALL , Ico.iml[0]);
SetProp(_hwnd , "cCntListWindow" , (HANDLE)this);
_oldwndproc = (WNDPROC)SetWindowLong(_hwnd , GWL_WNDPROC , (long)ListControlProc);
this->parent->registerWnd(this);
}
cCntListWindow::~cCntListWindow() {
this->parent->unregisterWnd(this);
DestroyWindow(_hwnd);
}
void cCntListWindow::cfgSet() {
SendMessage(_hwnd, WM_SETFONT , (WPARAM)this->parent->_hfItem , 1);
RECT rc;
GetClientRect(_hwnd , &rc);
WINDOWPOS wp;
wp.hwnd = _hwnd;
wp.cx = rc.right;
wp.cy = rc.bottom;
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(_hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );
ListView_SetBkColor(_hwnd , parent->_lfItem.bgColor);
}
void cCntListWindow::sort() {
int s = GetTickCount();
ListView_SortItems(_hwnd , sortList_compare , 0);
// IMLOG("* sortList.time = %d ms" , GetTickCount() - s);
}
int cCntListWindow::find(sUICnt * cnt) { // podaje pozycjê danego kontaktu na liœcie
LVFINDINFO vfi;
vfi.flags = LVFI_PARAM;
vfi.lParam = (LPARAM)cnt;
return ListView_FindItem(_hwnd , -1 , &vfi);
}
void cCntListWindow::refresh(bool sort){ // Odœwie¿a listê
if (sort) this->sort();
else
RedrawWindow(_hwnd,0,0,RDW_UPDATENOW|RDW_VALIDATE|RDW_INVALIDATE);
}
void cCntListWindow::refill() { // Wype³nia na nowo
if (!_hwnd) return;
SendMessage(_hwnd , WM_SETREDRAW , 0,0);
// SendMessage(_hwnd , LVM_DELETEALLITEMS, 0,0);
IMLOG("*fillList Start");
for (int i=0;i<Cnt.size();i++) {
Konnekt::UI::CntList::filters.ApplyToCnt(&Cnt[i]);
// if (ICMessage(IMC_CNT_INGROUP , i) && !Cnt[i].hidden)
// addCnt(&Cnt[i]);
}
IMLOG("*fillList End");
sort();
SendMessage(_hwnd , LVM_SETCOLUMNWIDTH , 0 , MAKELPARAM(LVSCW_AUTOSIZE_USEHEADER , 0));
// onSizeMain(0,0);
SendMessage(_hwnd , WM_SETREDRAW , 1,0);
}
void cCntListWindow::removeCnt(sUICnt * cnt) {
if (!cnt->onList)
return;
int pos = this->find(cnt);
cnt->onList = false;
if (pos > -1) ListView_DeleteItem(_hwnd , pos);
}
int cCntListWindow::addCnt(sUICnt * cnt) {
if (cnt->onList)
return 0;
LVITEM lvi;
lvi.mask = LVIF_PARAM | LVIF_TEXT;
lvi.iItem = 0xFFFF;
lvi.iSubItem = 0;
lvi.lParam = (LPARAM)cnt;
lvi.pszText = "";
cnt->onList = true;
return ListView_InsertItem(_hwnd , &lvi);
}
void cCntListWindow::measureListItem(MEASUREITEMSTRUCT * mis) {
mis->itemHeight=abs(parent->_lfItem.lf.lfHeight) + 2 + (parent->_lfItem.lf.lfHeight<0?4:0);
mis->itemHeight = max(mis->itemHeight , 20);
if (this->parent->_info != UI::CFG::clinfoInline && this->parent->_info != UI::CFG::clinfoOff) {
CStdString format = GETSTR(CFG_UICL_INFO_FORMAT);
format += "j_^M|";
HDC hdc = GetDC(this->_hwnd);
SelectObject(hdc , this->parent->_hfItemInfo);
RECT rt = Rect(0,0,1000,100);
this->parent->_infoHeight = DrawText(hdc, format, -1, &rt, DT_LEFT | DT_NOPREFIX | DT_CALCRECT) + (2 * CLINFO_MARGIN);
mis->itemHeight += this->parent->_infoHeight;
ReleaseDC(_hwnd, hdc);
} else {
this->parent->_infoHeight = 0;
}
mis->itemWidth=30;
}
void cCntListWindow::drawListItem(DRAWITEMSTRUCT * dis) {
sUICnt * pCnt;
bool notify=false;
HBRUSH hBrush;
RECT rc;
if (!dis->itemData) return;
pCnt=(sUICnt *)dis->itemData;
// Poszerzamy "trochê" nasz item
GetClientRect(dis->hwndItem , &rc);
//dis->rcItem.left = 0;
dis->rcItem.right = rc.right;
HDC origDC;
RECT rcItem;
HBITMAP memBmp;
RECT rcName; // fragment z nazw¹
RECT rcInfo; // fragment z opisem
// FlickerFree
if (this->parent->_flickerFree) {
origDC = dis->hDC; // Zapisujemy oryginalne DC...
rcItem = dis->rcItem; // zapisujemy oryginalne wspolrzedne
dis->hDC = CreateCompatibleDC(origDC);
memBmp = CreateCompatibleBitmap(origDC , dis->rcItem.right - dis->rcItem.left , dis->rcItem.bottom - dis->rcItem.top);
HGDIOBJ old = SelectObject(dis->hDC , memBmp);
if (old) DeleteObject(old);
// Ustawiam sobie Clipping...
/* HRGN memRgn = CreateRectRgn(0,0,1000,1000);
test = GetRandomRgn(origDC , memRgn , SYSRGN);
OffsetRgn(memRgn , 0 , -dis->rcItem.top);
SelectObject(dis->hDC , memRgn);
GetUpdateRgn
*/
dis->rcItem.bottom = dis->rcItem.bottom - dis->rcItem.top;
dis->rcItem.top = 0;
}
// Wczytujemy kilka przydatnych wartoœci dla pewnoœci...
pCnt->status = GETCNTI(pCnt->ID , CNT_STATUS);
rcName = rcInfo = dis->rcItem;
rcName.bottom = rcInfo.top = (rcName.bottom - this->parent->_infoHeight);
bool selected = dis->itemState & ODS_SELECTED;
// Robimy tlo...
if (selected) {
SelectObject(dis->hDC , parent->_hfItemSel);
hBrush = CreateSolidBrush(parent->_lfItemSel.bgColor);