-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrm.cpp
More file actions
3563 lines (3194 loc) · 88.2 KB
/
Copy pathMainFrm.cpp
File metadata and controls
3563 lines (3194 loc) · 88.2 KB
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
// MainFrm.cpp : implmentation of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "No5IrcObj.h"
#include "CMyScriptSite.h"
#include "MainFrm.h"
#include "aboutdlg.h"
#include "View.h"
#include "ChildFrm.h"
#include "usermsgs.h"
#include "COptionsDlg.h"
#include "CFileSender.h"
#include "CScriptsView.h"
#include "MarqueeOptions.h"
class CMarqueeView : public CWindowImpl<CMarqueeView>
{
public:
BEGIN_MSG_MAP()
END_MSG_MAP()
};
static BOOL CALLBACK EnumChildGetDataByName(HWND hWnd, LPARAM lParam);
static BOOL CALLBACK EnumChildActivate(HWND hWnd, LPARAM lParam);
static BOOL CALLBACK EnumViews(HWND hWnd, LPARAM lParam);
static int CALLBACK CompareLVItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
LRESULT CMyTabbedChildWindow::OnLVDoubleClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_frame.OnLVDoubleClick(idCtrl, pnmh, bHandled);
}
LRESULT CMyTabbedChildWindow::OnTVDoubleClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_frame.OnTVDoubleClick(idCtrl, pnmh, bHandled);
}
LRESULT CMyTabbedChildWindow::OnColumnClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_frame.OnColumnClick(idCtrl, pnmh, bHandled);
}
LRESULT CMyTabbedChildWindow::OnTVRightClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_frame.OnTVRightClick(idCtrl, pnmh, bHandled);
}
LRESULT CMyTabbedChildWindow::OnTVGetInfoTip(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_frame.OnTVGetInfoTip(idCtrl, pnmh, bHandled);
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if (_baseClass::PreTranslateMessage(pMsg))
return TRUE;
HWND hWnd = MDIGetActive();
if(hWnd != NULL)
return (BOOL)::SendMessage(hWnd, WM_FORWARDMSG, 0, (LPARAM)pMsg);
return FALSE;
}
BOOL CMainFrame::OnIdle()
{
UIUpdateToolBar();
return FALSE;
}
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CRect rcClient;
// create command bar window
HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
// attach menu
m_CmdBar.AttachMenu(GetMenu());
// load command bar images
m_CmdBar.LoadImages(IDR_MAINFRAME);
// remove old menu
SetMenu(NULL);
TCHAR szPath[_MAX_PATH];
GetModuleFileName(0, szPath, _MAX_PATH);
m_path.SetPath(szPath, FALSE, FALSE);
m_path = m_path.GetLocation();
BOOL res = m_path.ExistLocation();
ATLASSERT(res);
res = LoadUserSettings();
ATLASSERT(res);
if (!res) {
MessageBox(_T("failed to load settings"), m_path);
}
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
// marquee
CreateMarquee(0);
//AddSimpleReBarBandCtrl(m_hWndToolBar, m_marquee[0], IDC_BAND_MARQUEE,
// NULL, // title
// TRUE, // new row
// 0, // cx
// FALSE); // full width always
//m_marquee[0].AddItem(_T("Welcome to NO5 IRC"));
//AddSimpleReBarBandCtrl(m_hWndToolBar, m_axwnd, IDC_BAND_MARQUEE,
// NULL, // title
// TRUE, // new row
// 0, // cx
// FALSE); // full width always
//m_marquee[0].AddItem(_T("Welcome to NO5 IRC"));
CreateSimpleStatusBar();
CreateMDIClient();
m_CmdBar.SetMDIClient(m_hWndMDIClient);
UIAddToolBar(hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
UISetCheck(ID_VIEW_MARQUEE, 1);
UISetCheck(ID_VIEW_DARKMODE, m_bDarkMode?1:0,TRUE);
m_splitter.Create(m_hWnd, 0, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 0);
m_vsplitter.Create(m_splitter, 0, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 0);
m_hWndClient = m_splitter;
//m_hWndClient = NULL;
// left pane
//m_tab.ModifyTabStyles(0, CTCS_CLOSEBUTTON); // tem que ser antes do Create
m_tab.Create(m_vsplitter, 0, 0, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0);
// botttom
m_bottom.Create(m_splitter,rcDefault,(LPCTSTR)0,0);
m_bottom.m_status = m_hWndStatusBar;
m_bottom.AddTab(m_ftMonitor.CreateListView(m_bottom),_T("Transfers"));
if (m_bDarkMode) {
m_bottom.m_client.SetTextBkColor(0);
m_bottom.m_client.SetTextColor(0xffffff);
}
m_output.Create(m_bottom, 0, NULL, WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE| ES_WANTRETURN| WS_VSCROLL, 0,(UINT)0U, NULL);
m_output.SetFont(m_font);
m_bottom.AddTab(m_output, _T("output"));
//
CreateTreeView();
CreateListView();
CreateImageList();
m_tab.GetTabCtrl().SetCurSel(1);
//
m_splitter.SetSplitterPanes(m_vsplitter, m_bottom);
m_vsplitter.SetSplitterPanes(m_tab, m_hWndMDIClient);
m_vsplitter.SetSplitterPosPct(40);
UpdateLayout(TRUE);
GetClientRect(&rcClient);
m_splitter.SetSplitterPos(rcClient.Height() - m_bottom.GetDesiredHeight());
//SetTabOwnerParent(m_hWnd);
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
pLoop->AddIdleHandler(&m_bottom);
pLoop->AddIdleHandler(&m_ChannelsView);
pLoop->AddMessageFilter(&m_ChannelsView);
pLoop->AddMessageFilter(&m_bottom);
CreateFontOptions(&m_pfo);
CString file = m_path;
file += _T("no5irc.ini");
m_pfo->Read(file);
CreateIrcObj();
CreateScriptSite();
m_FormsPath = (CString)m_path + _T("Forms\\");
CComQIPtr<IDispatch> sp;
HRESULT hr = m_pIrc->QueryInterface(&sp);
m_pScriptView = new CScriptView(sp);
m_pScriptView->m_editor = m_editor;
m_pScriptView->Create(m_tab, rcDefault);
m_tab.AddTab(m_pScriptView->m_hWnd, _T("scripts"));
//
m_FormList.Create(m_tab);
m_tab.AddTab(m_FormList, _T("Forms"));
return 0;
}
LRESULT CMainFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
m_CmdBar.AttachMenu(NULL);
BOOL res = SaveUserSettings();
ATLASSERT(res);
// unregister message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);
pLoop->RemoveIdleHandler(&m_bottom);
pLoop->RemoveMessageFilter(&m_bottom);
pLoop->RemoveMessageFilter(&m_ChannelsView);
pLoop->RemoveIdleHandler(&m_ChannelsView);
CString file = m_path;
file += _T("no5irc.ini");
m_pfo->Write(file);
DestroyFontOptions(&m_pfo);
bHandled = FALSE;
return 1;
}
LRESULT CMainFrame::OnChildDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
BOOL bClose = TRUE;
ViewData* p = (ViewData*)lParam;
if (p->type == VIEW_CHANNEL) {
if (m_sock.IsConnected()) {
if (m_bInChannel && p->name[0] == '#') {
LeaveChannel(p->name, _T("NO5 IRC for Windows at https://fioresoft.net"));
// deletes the channel tree node
m_tv.DeleteItem(p->name, TRUE, TRUE);
}
}
}
else if (p->type == ViewType::VIEW_DCCCHAT) {
IDCCChat* pChat = m_Chats.GetValueAt(m_Chats.FindKey(p->name));
if (pChat) {
pChat->Close();
}
}
if (p->type == VIEW_SERVER && m_sock.IsConnected()) {
int res = MessageBox(_T("Disconnect from server?"), L"", MB_OKCANCEL);
if (res == IDCANCEL)
bClose = FALSE;
else {
m_sock.Shutdown();
}
}
return (LRESULT)bClose;
}
LRESULT CMainFrame::OnMDIActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CWindow wnd = (HWND)lParam;
ViewData* p = NULL;
p = (ViewData*)wnd.SendMessage(WM_CHILDGETDATA);
ATLASSERT(p && (!p->name.IsEmpty()) && p->pView);
m_NameOrChannel = p->name;
if (p->type == VIEW_CHANNEL) {
m_bInChannel = true;
m_bNoColors = p->m_bNoColors;
if (m_bNoColors) {
// disable formatting elements
m_bottom.DisableFormat();
}
else {
m_bottom.EnableFormat();
}
}
else
m_bInChannel = false;
return 0;
}
LRESULT CMainFrame::OnChannelsFileOpen(UINT, WPARAM, LPARAM, BOOL&)
{
CString file = m_server + _T(".txt");
file = (CString)m_path + file;
CFileDialog dlg(TRUE, _T("txt"), file, OFN_NOCHANGEDIR | OFN_NONETWORKBUTTON | OFN_EXPLORER,
_T("text files\0*.txt\0\0\0\0"));
if (IDOK == dlg.DoModal()) {
CWinFile wf;
TCHAR buf[MAX_PATH] = { 0 };
CString ext;
DWORD written = 0;
CString text;
CDataBuffer<TCHAR> db;
file = dlg.m_szFileName;
ext = file.Right(3);
if (wf.Create(dlg.m_szFileName, OPEN_ALWAYS)) {
if (!ext.CompareNoCase(_T("txt"))) {
CString channel;
CString users;
CString topic;
CString line;
CSimpleArray<CString> lines;
CDataBuffer<TCHAR> db;
BOOL res = wf.ReadLines(lines);
//BOOL res = wf.ReadAll(db);
ATLASSERT(res);
if (res) {
for (int i = 0; i < lines.GetSize(); i++) {
int index = lines[i].Find(' ', 0);
if (index > 0) {
StringCopyN(channel, lines[i], 0, index);
int index2 = lines[i].Find(':', index);
if (index2 > index) {
StringCopyN(users, lines[i], index, index2 - index);
StringCopyN(topic, lines[i], index2, lines[i].GetLength() - index2 + 1);
int insert = m_lv.InsertItem(LVIF_TEXT, 0, channel, 0, 0, 0, 0);
m_lv.SetItemText(insert, 1, users);
m_lv.SetItemText(insert, 2, topic);
}
}
}
}
}
}
}
return 0;
}
LRESULT CMainFrame::OnChannelsFileSave(UINT, WPARAM, LPARAM, BOOL&)
{
CString file = m_server + _T(".txt");
file = (CString)m_path + file;
CFileDialog dlg(FALSE, _T("txt"),file, OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
_T("text files\0*.txt\0\0\0\0"));
if (IDOK == dlg.DoModal()) {
CWinFile wf;
TCHAR buf[MAX_PATH] = { 0 };
CString ext;
DWORD written = 0;
CString text;
CDataBuffer<TCHAR> db;
file = dlg.m_szFileName;
ext = file.Right(3);
if (wf.Create(dlg.m_szFileName, CREATE_ALWAYS)) {
if (!ext.CompareNoCase(_T("txt"))) {
const int count = m_lv.GetItemCount();
CString channel;
CString users;
CString topic;
CString line;
BOOL res;
for (int i = 0; i < count; i++) {
m_lv.GetItemText(i, 0, channel);
m_lv.GetItemText(i, 1, users);
m_lv.GetItemText(i, 2, topic);
line = channel + ' ' + users + topic + _T("\r\n");
//db.Add<LPCWSTR>(line);
res = wf.WriteString(line, &written);
ATLASSERT(res);
}
//res = wf.Write(db);
// ATLASSERT(res);
//ATLASSERT(written == db.GetDataLen());
}
}
}
return 0;
}
LRESULT CMainFrame::OnChannelsFileUpdate(UINT, WPARAM, LPARAM, BOOL&)
{
ListChannels();
return 0;
}
LRESULT CMainFrame::OnFontChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
CView* p = GetActiveView();
if (p) {
LPCTSTR font = LPCTSTR(lParam);
p->SetTextFontName(font, SCF_ALL);
}
CRect rc;
GetClientRect(&rc);
UpdateLayout(TRUE);
m_splitter.SetSplitterPos(rc.Height() - m_bottom.GetDesiredHeight());
return 0;
}
LRESULT CMainFrame::OnFontSizeChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
CView* p = GetActiveView();
if (p) {
int size = int(lParam);
p->SetTextHeight(size, SCF_ALL);
}
CRect rc;
GetClientRect(&rc);
UpdateLayout(TRUE);
m_splitter.SetSplitterPos(rc.Height() - m_bottom.GetDesiredHeight());
return 0;
}
struct EnumNameData
{
LPCTSTR partial;
CStringArray* pres;
};
BOOL EnumFindName(CNo5TreeItem& item, LPARAM lParam)
{
CString name;
EnumNameData* p = (EnumNameData*)lParam;
item.GetText(name);
LPCTSTR found = StrStrI((LPCTSTR)name, (LPCTSTR)(p->partial));
if (found != NULL && found == (LPCTSTR)name) {
p->pres->Add(name);
}
return FALSE;
}
LRESULT CMainFrame::OnFindUser(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
ViewData* p = GetViewData();
LRESULT res = 0;
if (p && p->type == ViewType::VIEW_CHANNEL) {
CNo5TreeItem item = m_tv.FindItem(p->name, FALSE, TRUE);
if (!item.IsNull()) {
EnumNameData nd;
nd.partial = (LPCTSTR)wParam;
nd.pres = (CStringArray*)lParam;
item = item.GetChild();
if (!item.IsNull()) {
item.EnumSiblings(&EnumFindName, (LPARAM)&nd, TRUE, TRUE);
res = nd.pres->GetSize();
}
}
}
return res;
}
LRESULT CMainFrame::OnGetUsers(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
ViewData* p = GetViewDataByName((LPCTSTR)wParam);
CSimpleArray<CComBSTR>* names = (CSimpleArray<CComBSTR>*)lParam;
ATLASSERT(p);
if (p && p->type == ViewType::VIEW_CHANNEL) {
CNo5TreeItem item = m_tv.FindItem(p->name, FALSE, TRUE);
if (!item.IsNull()) {
CComBSTR _name;
CString name;
item = item.GetChild();
while (item) {
m_tv.GetItemText(item, name);
_name = name;
names->Add(_name);
item = item.GetNextSibling();
}
}
}
return 0;
}
LRESULT CMainFrame::OnTimerMsg(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
OnTimer((long)wParam);
return 0;
}
LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PostMessage(WM_CLOSE);
return 0;
}
LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
OnLogin();
CreateViewIfNoExist(m_server, VIEW_SERVER);
return 0;
}
LRESULT CMainFrame::OnTabSelChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
NMCTC2ITEMS* pData = (LPNMCTC2ITEMS)pnmh;
pData->iItem2; // new item selected
ATLTRACE(_T("item %d selected\n"), pData->iItem2);
return 0;
}
LRESULT CMainFrame::OnTabSelChanging(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
NMCTC2ITEMS* pData = (LPNMCTC2ITEMS)pnmh;
pData->iItem2; // new item selected
ATLTRACE(_T("item %d selected\n"), pData->iItem2);
return 0;
}
LRESULT CMainFrame::OnTabClose(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static BOOL bVisible = TRUE; // initially visible
bVisible = !bVisible;
CReBarCtrl rebar = m_hWndToolBar;
int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1); // toolbar is 2nd added band
rebar.ShowBand(nBandIndex, bVisible);
UISetCheck(ID_VIEW_TOOLBAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewMarquee(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static BOOL bVisible = TRUE; // initially visible
bVisible = !bVisible;
CReBarCtrl rebar = m_hWndToolBar;
int nBandIndex = rebar.IdToIndex(IDC_BAND_MARQUEE); // toolbar is 2nd added band
rebar.ShowBand(nBandIndex, bVisible);
UISetCheck(ID_VIEW_MARQUEE, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewOptions(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CPropertySheet ps(_T("Options"),1,m_hWnd);
COptionsDlgPage pp;
CFontOptionsDlgPage fop(m_pfo);
pp.m_bAllowCTCP = m_bAllowCTCP ? true : false;
pp.m_userinfo = m_userinfo;
pp.m_bPingPong = m_bPingPong;
pp.Create();
fop.Create();
BOOL res = ps.AddPage(&pp.m_psp);
ATLASSERT(res);
res = ps.AddPage(&fop.m_psp);
if (res) {
int res = ps.DoModal(m_hWnd);
if (res == IDOK) {
m_bAllowCTCP = pp.m_bAllowCTCP ? TRUE : FALSE;
m_userinfo = pp.m_userinfo;
m_bPingPong = pp.m_bPingPong;
}
}
return 0;
}
LRESULT CMainFrame::OnViewDarkMode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_bDarkMode = !m_bDarkMode;
UISetCheck(ID_VIEW_DARKMODE, m_bDarkMode?1:0,TRUE);
CView* pView = GetActiveView();
/*int aElements[] = { COLOR_WINDOW, COLOR_WINDOWTEXT };
const int count = sizeof(aElements) / sizeof(aElements[0]);
COLORREF aColors[] = { 0,RGB(255,255,255)};
COLORREF aNormalColors[] = {GetSysColor(COLOR_WINDOW),GetSysColor(COLOR_WINDOWTEXT)};*/
if (m_bDarkMode) {
/*m_marquee[0].SetBackColor(0);
m_marquee[0].SetTextColor(0xffffff);*/
if (pView) {
pView->SetTextBkColor(0,SCF_ALL);
pView->SetTextColor(0xffffff,SCF_ALL);
//SetClassLongPtr(pView->m_hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)AtlGetStockBrush(BLACK_BRUSH));
}
//SetSysColors(count, aElements, aColors);
m_tv.SetBkColor(0);
m_tv.SetTextColor(0xffffff);
m_lv.SetBkColor(0);
m_lv.SetTextBkColor(0);
m_lv.SetTextColor(0xffffff);
m_bottom.m_client.SetTextBkColor(0, SCF_ALL);
m_bottom.m_client.SetTextColor(0xffffff, SCF_ALL);
}
else {
//m_marquee[0].SetBackColor(mo[0].back);
//m_marquee[0].SetTextColor(mo[0].fore);
if (pView) {
pView->SetTextBkColor(0xffffff, SCF_ALL);
pView->SetTextColor(0,SCF_ALL);
SetClassLongPtr(pView->m_hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)GetSysColorBrush(COLOR_WINDOW));
}
//SetSysColors(count, aElements, aNormalColors);
m_tv.SetBkColor(-1);
m_tv.SetTextColor(-1);
m_lv.SetBkColor(-1);
m_lv.SetTextBkColor(-1);
m_lv.SetTextColor(-1);
//
m_bottom.m_client.SetTextBkColor(0xffffff, SCF_ALL);
m_bottom.m_client.SetTextColor(0, SCF_ALL);
}
UpdateLayout(FALSE);
return 0;
}
LRESULT CMainFrame::OnMarqueeChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
/*mo[0].fore = m_marquee[0].GetTextColor();
mo[0].back = m_marquee[0].GetBackColor();
mo[0].Elapse = m_marquee[0].GetElapse();*/
return 0;
}
LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
LRESULT CMainFrame::OnWindowCascade(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDICascade();
return 0;
}
LRESULT CMainFrame::OnWindowTile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDITile();
return 0;
}
LRESULT CMainFrame::OnWindowArrangeIcons(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
MDIIconArrange();
return 0;
}
LRESULT CMainFrame::OnFilePrint(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//ShellExecute(GetActiveView()->m_hWnd, _T("PRINT"), NULL, NULL, NULL, 0);
// hwnd is the HWND of the rich edit control.
// hdc is the HDC of the printer. This value can be obtained for the
// default printer as follows:
PRINTDLG pd = { sizeof(pd) };
pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
if (PrintDlg(&pd))
{
HDC hdc = pd.hDC;
PrintRTF(GetActiveView()->m_hWnd, hdc);
}
return 0;
}
LRESULT CMainFrame::OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
//CShellFileSaveDialog dlg;
CFileDialog dlg(FALSE, _T("txt"), _T("dump.txt"), OFN_CREATEPROMPT | OFN_NOCHANGEDIR | OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
_T("text files\0*.txt\0rich text\0*.rtf\0\0\0"));
if (IDOK == dlg.DoModal()) {
CWinFile wf;
CString file;
TCHAR buf[MAX_PATH] = { 0 };
CString ext;
DWORD written = 0;
CView* pView = GetActiveView();
CString text;
if (!pView)
return 0;
file = dlg.m_szFileName;
ext = file.Right(3);
if (wf.Create(dlg.m_szFileName, CREATE_ALWAYS)) {
if (!ext.CompareNoCase(_T("txt"))) {
if (pView->GetWindowText(text)) {
if (wf.Write(text.GetBuffer(), pView->GetWindowTextLength() * sizeof(TCHAR), &written)) {
MessageBox(_T("ok"));
}
}
}
else if (!ext.CompareNoCase(_T("rtf"))) {
written = pView->StreamOutFile(wf);
}
}
}
return 0;
}
LRESULT CMainFrame::OnLVDoubleClick(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
NMITEMACTIVATE* pItem = (NMITEMACTIVATE*)(LPNMHDR)(pnmh);
int iItem = pItem->iItem;
TCHAR buf[81] = { 0 };
LVITEM item = { 0 };
item.iItem = iItem;
item.pszText = buf;
item.cchTextMax = 80;
item.mask = LVIF_TEXT;
m_lv.SendMessage(LVM_GETITEMTEXT, (WPARAM)iItem, (LPARAM)&item);
JoinChannel(item.pszText);
//m_tv.DeleteAllItems();
m_NameOrChannel = item.pszText;
CreateChannel(item.pszText);
bHandled = TRUE;
return 0;
}
LRESULT CMainFrame::OnTVDoubleClick(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
CNo5TreeItem item = m_tv.GetSelectedItem();
CString name;
CString _name;
CNo5TreeItem parent;
if (m_sock.IsConnected()) {
if (parent = item.GetParent()) {
parent = parent.GetParent();
if (parent) {
item.GetText(name);
_name = name;
CView* pView = CreatePrivateChannel(_name);
}
}
}
return 0;
}
LRESULT CMainFrame::OnTVRightClick(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
CNo5TreeItem item = m_tv.GetSelectedItem();
CString name;
CNo5TreeItem parent;
if (parent = item.GetParent()) {
parent = parent.GetParent();
if (parent) {
item.GetText(name);
CMenuHandle menu;
CPoint pt;
GetCursorPos(&pt);
menu.LoadMenu(IDR_MENU1);
menu.Attach(menu.GetSubMenu(0));
UINT id = menu.TrackPopupMenu(TPM_CENTERALIGN | TPM_VCENTERALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_HORNEGANIMATION | \
TPM_VERNEGANIMATION, pt.x, pt.y, m_hWnd);
switch (id) {
case ID_USER_SENDVERSIONREQUEST:
RequestVersion(name);
break;
case ID_USER_SENDPINGREQUEST:
RequestPing(name);
break;
case ID_USER_SENDUSERINFOREQUEST:
RequestUserinfo(name);
break;
case ID_USER_SENDTIMEREQUEST:
RequestTime(name);
break;
case ID_USER_WHOIS:
WhoIs(name);
break;
case ID_USER_WHO:
Who(name);
break;
case ID_USER_SENDFILE:
UserSendFile(name);
break;
case ID_USER_CHAT:
UserSendChat(name);
break;
default:
break;
}
}
}
return 0;
}
LRESULT CMainFrame::OnTVGetInfoTip(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMTVGETINFOTIP pit = (LPNMTVGETINFOTIP)pnmh;
CNo5TreeItem ti(pit->hItem, &m_tv);
int img = ti.GetImageIndex();
CString tt;
CString name;
ti.GetText(name);
CNo5TreeItem parent = ti.GetParent();
if (parent)
parent = parent.GetParent();
if (!parent)
return 0;
switch(img){
// founder
case 0:
tt = name + _T("\r\nFounder");
break;
case 1:
// protected
tt = name + _T("\r\nProtected");
break;
case 2:
tt = name + _T("\r\nOperator");
break;
case 3:
tt = name + _T("\r\nHalf OP");
break;
case 4:
tt = name + _T("\r\nVoice");
break;
case 5:
tt = name + _T("\r\nNormal user");
break;
default:
break;
}
::StringCchCopyN(pit->pszText, pit->cchTextMax, tt, tt.GetLength());
return 0;
}
void CMainFrame::CreateView(LPCTSTR name, ViewType type)
{
CChildFrame* pChild = new CChildFrame(name, type, *this);
pChild->CreateEx(m_hWndMDIClient);
pChild->SetTitle(name, true);
pChild->m_view.SetAutoURLDetect();
pChild->m_view.SetEventMask(ENM_LINK);
pChild->m_view.SetIndent(150);
if (m_bDarkMode) {
pChild->m_view.SetTextBkColor(0, SCF_ALL);
pChild->m_view.SetTextColor(0xffffff, SCF_ALL);
}
}
CView* CMainFrame::GetActiveView()
{
ViewData* p = GetViewData();
CView* res = NULL;
if (p) {
res = p->pView;
ATLASSERT(res);
ATLASSERT(res->IsWindow());
}
return res;
}
void CMainFrame::CreateTreeView()
{
m_tv.Create(m_tab, 0, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT| TVS_INFOTIP,
0, IDC_TREEVIEW);
m_tab.AddTab(m_tv, _T("Users"));
ATLASSERT(m_tv.IsWindow());
/*NO5TL::CNo5TreeItem root = m_tv.InsertItem(_T("root"), NULL, TVI_ROOT);
m_tv.InsertItem(_T("child"), root, TVI_SORT);
m_tv.InsertItem(_T("child 2"), root, TVI_SORT);
NO5TL::CNo5TreeItem item;
item = m_tv.FindItem(_T("child"), TRUE, TRUE);
if (item) {
m_tv.InsertItem(_T("grandchild"), item, TVI_SORT);
}*/
if (m_bDarkMode) {
m_tv.SetBkColor(0);
m_tv.SetTextColor(0xffffff);
}
}
void CMainFrame::CreateListView()
{
m_ChannelsView.CreateEx(m_tab, rcDefault, WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 0);
m_lv.Create(m_ChannelsView, 0, 0, LVS_REPORT | LVS_SINGLESEL | LVS_SORTASCENDING | LVS_SHOWSELALWAYS| WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
0,IDC_LISTVIEW);
LVCOLUMN col = { 0 };
CClientDC dc(m_hWnd);
CSize sz;
//m_lv.SetFont(m_font);
dc.GetTextExtent(_T(" CHANNEL "), strlen(" CHANNEL "), &sz);
m_lv.InsertColumn(0, _T("channel"), LVCFMT_LEFT, sz.cx);
dc.GetTextExtent(_T(" users "), strlen("users "), &sz);
m_lv.InsertColumn(1, _T("users"), LVCFMT_LEFT, sz.cx);
dc.GetTextExtent(_T(" topic "), strlen("topic "),
&sz);
m_lv.InsertColumn(2, _T("topic"), LVCFMT_LEFT, sz.cx);
m_ChannelsView.m_hWndClient = m_lv;
m_tab.AddTab(m_ChannelsView, _T("channels"));
if (m_bDarkMode) {
m_lv.SetBkColor(0);
m_lv.SetTextColor(0xffffff);
}
}
void CMainFrame::CreateImageList()
{
BOOL res = m_il.Create(18, 18, ILC_COLOR32, 6, 1);
ATLASSERT(res);
if (res) {
CClientDC dc(m_hWnd);
CIconHandle icon;
HBITMAP hbmp;
UINT imgs[] = { IDI_ICON2,IDI_ICON3,IDI_ICON4,IDI_ICON6,IDI_ICON8,IDI_ICON5};
const int count = sizeof(imgs) / sizeof(imgs[0]);
for (int i = 0; i < count; i++) {
icon.LoadIcon(imgs[i],18,18, LR_LOADTRANSPARENT);
ATLASSERT(!icon.IsNull());
m_il.AddIcon(icon.Detach());
}
m_tv.SetImageList(m_il);
}
}
BOOL CMainFrame::PrintRTF(HWND hwnd, HDC hdc)
{
DOCINFO di = { sizeof(di) };
if (!StartDoc(hdc, &di))
{
return FALSE;
}
int cxPhysOffset = GetDeviceCaps(hdc, PHYSICALOFFSETX);
int cyPhysOffset = GetDeviceCaps(hdc, PHYSICALOFFSETY);
int cxPhys = GetDeviceCaps(hdc, PHYSICALWIDTH);
int cyPhys = GetDeviceCaps(hdc, PHYSICALHEIGHT);
// Create "print preview".
SendMessage(hwnd, EM_SETTARGETDEVICE, (WPARAM)hdc, cxPhys / 2);
FORMATRANGE fr;
fr.hdc = hdc;
fr.hdcTarget = hdc;
// Set page rect to physical page size in twips.
fr.rcPage.top = 0;
fr.rcPage.left = 0;
fr.rcPage.right = MulDiv(cxPhys, 1440, GetDeviceCaps(hdc, LOGPIXELSX));
fr.rcPage.bottom = MulDiv(cyPhys, 1440, GetDeviceCaps(hdc, LOGPIXELSY));
// Set the rendering rectangle to the pintable area of the page.
fr.rc.left = cxPhysOffset;
fr.rc.right = cxPhysOffset + cxPhys;
fr.rc.top = cyPhysOffset;
fr.rc.bottom = cyPhysOffset + cyPhys;
SendMessage(hwnd, EM_SETSEL, 0, (LPARAM)-1); // Select the entire contents.
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&fr.chrg); // Get the selection into a CHARRANGE.
BOOL fSuccess = TRUE;
// Use GDI to print successive pages.
while (fr.chrg.cpMin < fr.chrg.cpMax&& fSuccess)
{
fSuccess = StartPage(hdc) > 0;
if (!fSuccess) break;
int cpMin = SendMessage(hwnd, EM_FORMATRANGE, TRUE, (LPARAM)&fr);
if (cpMin <= fr.chrg.cpMin)
{
fSuccess = FALSE;
break;
}