forked from keizi666/charu3
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyTreeDialog.cpp
1386 lines (1285 loc) · 47.4 KB
/
MyTreeDialog.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
/*----------------------------------------------------------
MyTreeDialogクラス
2002/11/16 (c)Keizi
----------------------------------------------------------*/
#include "stdafx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <list>
#include <vector>
#include "MyTreeDialog.h"
#include "EditDialog.h"
#include "SearchDialog.h"
#include "commonDialog.h"
#include "Charu3.h"
#include "color.h"
#include "log.h"
namespace {
//---------------------------------------------------
//関数名 DrawLline(CDC* pDC, CPoint* point, COLORREF color)
//機能 線を描く
//---------------------------------------------------
void DrawLline(CDC* pDC, CPoint* point, COLORREF color)
{
CPen pen(PS_SOLID, 1, color);
CPen* old_pen = pDC->SelectObject(&pen);
pDC->MoveTo(point[0]);
pDC->LineTo(point[1]);
pDC->LineTo(point[2]);
pDC->SelectObject(old_pen);
}
//---------------------------------------------------
//関数名 DrawFrame(CDC* pDC, CRect& rect, COLORREF color)
//機能 枠を描く
//---------------------------------------------------
void DrawFrame(CDC* pDC, CRect& rect, COLORREF color)
{
CPoint point[3];
COLORREF colRD[3] = {};
COLORREF colLU[3] = {};
colRD[1] = colLU[0] = Color::MultiplyBrightness(color, 1.2);
colRD[2] = colLU[1] = color;
colRD[0] = colLU[2] = Color::MultiplyBrightness(color, 0.8);
for (int i = 1; i <= 3; i++) {
point[0].x = rect.left + i;
point[0].y = rect.bottom - i;
point[1].x = rect.right - i;
point[1].y = rect.bottom - i;
point[2].x = rect.right - i;
point[2].y = rect.top + i - 1;
DrawLline(pDC, point, colRD[i - 1]);
}
for (int i = 0; i <= 2; i++) {
point[0].x = rect.left + i;
point[0].y = rect.bottom - i - 1;
point[1].x = rect.left + i;
point[1].y = rect.top + i;
point[2].x = rect.right - i;
point[2].y = rect.top + i;
DrawLline(pDC, point, colLU[i]);
}
}
} // anonymous namespace
//---------------------------------------------------
//関数名 CMyTreeDialog
//機能 コンストラクタ
//---------------------------------------------------
CMyTreeDialog::CMyTreeDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyTreeDialog::IDD, pParent)
, m_pTreeCtrl(nullptr)
, m_isInitOK(false)
, m_bCheckbox(false)
, m_isModal(true)
, m_isAltDown(false)
, m_selectedDataPtr(nullptr)
, m_dataPtrDbClick(nullptr)
, m_hBookedItemToCopy(nullptr)
, m_hDLL(nullptr)
, m_pExStyle(nullptr)
, m_cFont(nullptr)
, m_colFrame(0xff9900)
, m_bFind(false)
, m_findDialog(nullptr)
, m_dwStartTime(0)
, m_strQuickKey("")
, m_hQuickItem(nullptr)
{
//{{AFX_DATA_INIT(CMyTreeDialog)
//}}AFX_DATA_INIT
m_brBack.m_hObject = NULL;
}
//---------------------------------------------------
//関数名 DoDataExchange(CDataExchange* pDX)
//機能 データエクスチェンジ
//---------------------------------------------------
void CMyTreeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyTreeDialog)
if (GetDlgItem(IDC_MY_TREE))
DDX_Control(pDX, IDC_MY_TREE, *m_pTreeCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyTreeDialog, CDialog)
//{{AFX_MSG_MAP(CMyTreeDialog)
ON_COMMAND(IDML_EDIT, OnEdit)
ON_COMMAND(IDML_DELETE, OnDelete)
ON_COMMAND(IDML_RENAME, OnRename)
ON_COMMAND(IDML_ICON_KEY, OnIconKey)
ON_COMMAND(IDML_ICON_DATE, OnIconDate)
ON_COMMAND(IDML_ICON_EXE, OnIconExe)
ON_COMMAND(IDML_ICON_RELATE, OnIconRelate)
ON_COMMAND(IDML_ICON_SELECT, OnIconSelect)
ON_COMMAND(IDML_ICON_CLIP, OnIconClip)
ON_COMMAND(IDML_ICON_PLUGIN, OnIconPlugin)
ON_COMMAND(IDML_ICON_KEYMACRO, OnIconKeymacro)
ON_COMMAND(IDML_MAKE_ONETIME, OnMakeOnetime)
ON_COMMAND(IDML_MAKE_PERMANENT, OnMakePermanent)
ON_COMMAND(IDML_FOLDER_CLEAR, OnFolderClear)
ON_COMMAND(IDML_NEW_DATA, OnNewData)
ON_COMMAND(IDML_NEW_FOLDER, OnNewFolder)
ON_COMMAND(IDML_RESELECT_ICONS, OnReselectIcons)
ON_COMMAND(IDML_CLEANUP_ONETIME, OnCleanupAllOnetime)
ON_COMMAND(IDML_MAKE_PERMANENT_ALL, OnMakeAllOnetimePermanent)
ON_COMMAND(IDML_CLOSE_ALL, OnCloseAll)
ON_COMMAND(IDML_LIST_SERCH, OnListSearch)
ON_COMMAND(IDML_CHECK_ITEM, OnCheckItem)
ON_COMMAND(IDML_COPY_DATA, OnCopyData)
ON_COMMAND(IDML_DATA_PASTE, OnDataPaste)
ON_COMMAND(IDML_IMPORT, OnImport)
ON_COMMAND(IDML_EXPORT, OnExport)
ON_COMMAND(IDML_OPTION, OnOption)
ON_NOTIFY(NM_RCLICK, IDC_MY_TREE, OnRclickMyTree)
ON_NOTIFY(NM_CLICK, IDC_MY_TREE, OnClickMyTree)
ON_NOTIFY(NM_KILLFOCUS, IDC_MY_TREE, OnKillFocusMyTree)
ON_NOTIFY(NM_SETFOCUS, IDC_MY_TREE, OnSetFocusMyTree)
ON_NOTIFY(TVN_KEYDOWN, IDC_MY_TREE, OnKeydownMyTree)
ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_MY_TREE, OnBeginlabeleditMyTree)
ON_NOTIFY(TVN_ENDLABELEDIT, IDC_MY_TREE, OnEndlabeleditMyTree)
ON_WM_SIZE()
ON_WM_SHOWWINDOW()
ON_WM_NCPAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//---------------------------------------------------
//関数名 OnInitDialog()
//機能 ダイアログの初期化
//---------------------------------------------------
BOOL CMyTreeDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_pTreeCtrl->ModifyStyle(NULL, TVS_SHOWSELALWAYS);
m_toolTip.Create(this, TTS_ALWAYSTIP);
m_toolTip.SetMaxTipWidth(400);
m_toolTip.Activate(TRUE);
m_toolTip.AddTool(m_pTreeCtrl, _T(""));
m_hDLL = ::LoadLibrary(_T("user32"));
m_pExStyle = m_hDLL != 0 ? (PFUNC)::GetProcAddress(m_hDLL, "SetLayeredWindowAttributes") : NULL;
m_PopupMenu.LoadMenu(MAKEINTRESOURCE(IDR_LISTMENU));//メニュークラスにメニューを読む
if (!m_findDialog) {
m_findDialog = new CSearchDialog(this);
}
return TRUE;
}
//---------------------------------------------------
//関数名 PopupMenu(CPoint point)
//機能 ポップアップメニューを出す
//---------------------------------------------------
void CMyTreeDialog::PopupMenu(CPoint point)
{
if (m_isModal || !m_isInitOK) return;
CPoint HitPoint = point;
ScreenToClient(&HitPoint);
HTREEITEM hTreeItem = m_pTreeCtrl->HitTest(HitPoint);
m_PopupMenu.EnableMenuItem(IDML_EDIT, hTreeItem ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_DELETE, hTreeItem ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_RENAME, hTreeItem ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_CHECK_ITEM, m_bCheckbox ? MF_GRAYED : MF_ENABLED);
m_PopupMenu.EnableMenuItem(IDML_COPY_DATA, hTreeItem ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_DATA_PASTE, m_hBookedItemToCopy ? MF_ENABLED : MF_GRAYED);
bool isData = false;
bool isFolder = false;
if (hTreeItem) {
m_pTreeCtrl->SelectItem(hTreeItem);
STRING_DATA* dataPtr = m_pTreeCtrl->getDataPtr(hTreeItem);
isData = (dataPtr->m_cKind & KIND_DATA_ALL) != 0;
isFolder = (dataPtr->m_cKind & KIND_FOLDER_ALL) != 0;
m_PopupMenu.EnableMenuItem(IDML_MAKE_PERMANENT, !isData || (dataPtr->m_cKind & KIND_LOCK) ? MF_GRAYED : MF_ENABLED);
m_PopupMenu.EnableMenuItem(IDML_MAKE_ONETIME, !isData || (dataPtr->m_cKind & KIND_ONETIME) ? MF_GRAYED : MF_ENABLED);
}
else {
m_PopupMenu.EnableMenuItem(IDML_MAKE_PERMANENT, MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_MAKE_ONETIME, MF_GRAYED);
}
m_PopupMenu.EnableMenuItem(IDML_ICON_KEY, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_DATE, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_EXE, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_RELATE, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_SELECT, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_CLIP, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_PLUGIN, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_ICON_KEYMACRO, isData ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.EnableMenuItem(IDML_FOLDER_CLEAR, isFolder ? MF_ENABLED : MF_GRAYED);
m_PopupMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this);
}
//---------------------------------------------------
//関数名 showWindowPos(POINT pos,int nCmdShow)
//機能 ウィンドウを移動して表示
//---------------------------------------------------
BOOL CMyTreeDialog::ShowWindowPos(POINT pos, POINT size, int nCmdShow, bool keepSelection, HTREEITEM hOpenItem)
{
m_pTreeCtrl->OnWindowPosChanging(NULL);
m_toolTip.SetDelayTime(theApp.m_ini.m_nToolTipDelay);
m_toolTip.SetDelayTime(TTDT_AUTOPOP, theApp.m_ini.m_nToolTipTime);
m_pTreeCtrl->SetBkColor(COLORREF(Color::Swap_RGB_BGR(theApp.m_ini.m_nBackgroundColor)));
m_pTreeCtrl->SetTextColor(COLORREF(Color::Swap_RGB_BGR(theApp.m_ini.m_nTextColor)));
m_pTreeCtrl->SetInsertMarkColor(COLORREF(Color::Swap_RGB_BGR(theApp.m_ini.m_nBorderColor)));
m_pTreeCtrl->ModifyStyle(NULL, TVS_TRACKSELECT, NULL);
if (theApp.m_ini.m_bSingleExpand) {
m_pTreeCtrl->ModifyStyle(NULL, TVS_SINGLEEXPAND, NULL);
}
else {
m_pTreeCtrl->ModifyStyle(TVS_SINGLEEXPAND, NULL, NULL);
}
#if false
// I thought about displaying the pathname of the data above the data tree.But decided not to.
CWnd* cpDataName = GetDlgItem(IDC_DATA_NAME);
if (cpDataName) {
TCHAR buf[MAX_PATH];
TCHAR* pFileName;
GetFullPathName(theApp.m_ini.m_strDataPath.GetString(), MAX_PATH, buf, &pFileName);
cpDataName->SetWindowText(pFileName);
}
#endif
HTREEITEM hSelectItem = m_pTreeCtrl->GetSelectedItem();
if (!keepSelection) {
m_pTreeCtrl->SelectItem(m_pTreeCtrl->GetRootItem());
}
if (!theApp.m_ini.m_bKeepFolders) {
m_pTreeCtrl->closeFolder(m_pTreeCtrl->GetRootItem());
if (keepSelection) {
m_pTreeCtrl->SelectItem(hSelectItem);
}
}
else if (hSelectItem && !hOpenItem) {
RECT rSelItem;
m_pTreeCtrl->GetItemRect(hSelectItem, &rSelItem, NULL);
if (size.y < rSelItem.top || rSelItem.bottom < 0)
m_pTreeCtrl->EnsureVisible(hSelectItem); //EnsureVisibleするとフォルダは開かれる
}
if (hOpenItem) m_pTreeCtrl->Expand(hOpenItem, TVE_EXPAND);
m_colFrame = Color::Swap_RGB_BGR(theApp.m_ini.m_nBorderColor);
if (m_brBack.GetSafeHandle()) {
m_brBack.DeleteObject();
m_brBack.m_hObject = NULL;
}
if (m_brBack.m_hObject == NULL)
m_brBack.CreateSolidBrush(COLORREF(Color::Swap_RGB_BGR(theApp.m_ini.m_nBackgroundColor)));
theApp.BeForeground();
m_pTreeCtrl->SetFocus();
m_selectedDataPtr = nullptr;
m_isInitOK = true;
m_isModal = false;
m_isAltDown = false;
m_dataPtrDbClick = nullptr;
m_pTreeCtrl->m_ltCheckItems.clear();
if (theApp.m_ini.m_nToolTip == 2) m_toolTip.Activate(FALSE);
else m_toolTip.Activate(TRUE);
SetWindowPos(&wndTopMost, pos.x, pos.y, size.x, size.y, NULL);
return ShowWindow(nCmdShow);
}
//---------------------------------------------------
// CMyTreeDialog メッセージ ハンドラ
//---------------------------------------------------
void CMyTreeDialog::OnNcPaint()
{
CDialog::OnNcPaint();
// Set scrollbars
m_pTreeCtrl->setScrollBar();
// Draw border
{
CRect rect;
GetWindowRect(rect);
CRect localRect = rect - rect.TopLeft();
CDC* pDC = GetWindowDC();
DrawFrame(pDC, localRect, m_colFrame);
ReleaseDC(pDC);
}
// Workaround for the problem where the border is overwritten
{
DWMNCRENDERINGPOLICY policy = DWMNCRP_DISABLED;
DwmSetWindowAttribute(m_hWnd, DWMWA_NCRENDERING_POLICY, &policy, sizeof policy);
BOOL allow = FALSE;
DwmSetWindowAttribute(m_hWnd, DWMWA_ALLOW_NCPAINT, &allow, sizeof allow);
// Even with this countermeasure, there are still occasional cases where the
// border is hidden by overwriting. In such cases, I used the workaround of
// calling RedrawWindow there.
}
}
//---------------------------------------------------
//関数名 OnSize(UINT nType, int cx, int cy)
//機能 リサイズ
//---------------------------------------------------
void CMyTreeDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (m_pTreeCtrl->m_hWnd) {
m_pTreeCtrl->SetWindowPos(&wndTop, 0, 0, cx, cy, SWP_NOMOVE);
m_pTreeCtrl->setScrollBar();
}
}
//---------------------------------------------------
//関数名 DestroyWindow()
//機能 ウィンド破棄時処理
//---------------------------------------------------
BOOL CMyTreeDialog::DestroyWindow()
{
m_toolTip.DelTool(m_pTreeCtrl);
if (m_findDialog) {
delete m_findDialog;
m_findDialog = nullptr;
}
return CDialog::DestroyWindow();
}
//---------------------------------------------------
//関数名 OnKeydownMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 キー押下処理
//---------------------------------------------------
void CMyTreeDialog::OnKeydownMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
*pResult = 0;
}
//---------------------------------------------------
//関数名 OnRclickMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 右ボタン押下処理
//---------------------------------------------------
void CMyTreeDialog::OnRclickMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_isModal || m_pTreeCtrl->IsDragging()) return;
POINT point;
::GetCursorPos(&point);
PopupMenu(point);
*pResult = 0;
}
//---------------------------------------------------
//関数名 OnClickMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 左ボタン押下処理
//---------------------------------------------------
void CMyTreeDialog::OnClickMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
RECT TreeRect, ItemRect;
POINT pCursolPos;
HTREEITEM hClickItem;
UINT Flags = 0;
m_pTreeCtrl->GetWindowRect(&TreeRect);
GetCursorPos(&pCursolPos);
pCursolPos.x -= TreeRect.left;
pCursolPos.y -= TreeRect.top;
hClickItem = m_pTreeCtrl->HitTest(pCursolPos, &Flags);
if (hClickItem) {
if (m_pTreeCtrl->GetItemRect(hClickItem, &ItemRect, true)) {
if (TVHT_ONITEMICON & Flags) {
// Clicking on the icon of the one-time data item in the data
// tree view changes it to permanent data.
STRING_DATA* pData = m_pTreeCtrl->getDataPtr(hClickItem);
if (pData->m_cKind & KIND_ONETIME) {
pData->m_cKind = KIND_LOCK;
m_pTreeCtrl->UpdateItem(hClickItem);
}
}
if (TVHT_ONITEMSTATEICON & Flags) {
// Clicked on checkbox
m_pTreeCtrl->ToggleItemCheck(hClickItem);
// The process above includes toggling the check, but MFC will
// also toggle the check for this item, so reverse the toggle
// once here.
m_pTreeCtrl->SetCheck(hClickItem, !m_pTreeCtrl->GetCheck(hClickItem));
}
}
m_pTreeCtrl->SelectItem(hClickItem);
// Enter if m_bSingleEnter
if (theApp.m_ini.m_bSingleEnter && !m_pTreeCtrl->IsDragging() && (TVHT_ONITEMSTATEICON & Flags) == 0) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
Determine(GetClickedItem());
}
}
*pResult = 0;
}
//---------------------------------------------------
//関数名 OnKillFocusMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 ツリーのフォーカスが外れたら隠す
//---------------------------------------------------
void CMyTreeDialog::OnKillFocusMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_isInitOK && !m_isModal && !m_bFind) {
Cancel();
}
else {
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
*pResult = 0;
}
void CMyTreeDialog::OnSetFocusMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
//---------------------------------------------------
//関数名 OnShowWindow(BOOL bShow, UINT nStatus)
//機能 ウィンドウ表示時処理
//---------------------------------------------------
void CMyTreeDialog::OnShowWindow(BOOL bShow, UINT nStatus)
{
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
if (bShow) {
//半透明処理
LONG lExStyle = ::GetWindowLong(this->m_hWnd, GWL_EXSTYLE);
if (m_pExStyle && theApp.m_ini.m_nOpacity < 100) {
SetWindowLong(this->m_hWnd, GWL_EXSTYLE, lExStyle | 0x80000);
int nTansparent = 255 * theApp.m_ini.m_nOpacity / 100;
m_pExStyle(this->m_hWnd, 0, nTansparent, 2);
}
else {
SetWindowLong(this->m_hWnd, GWL_EXSTYLE, lExStyle & 0xfff7ffff);
}
m_cFont = new CFont;
if (m_cFont) {
m_cFont->CreatePointFont(theApp.m_ini.m_nFontSize, theApp.m_ini.m_strFontName);
m_pTreeCtrl->SetFont(m_cFont, TRUE);
}
}
else {
if (m_cFont) {
RECT rect;
GetWindowRect(&rect);
theApp.m_ini.m_treeviewSize.x = rect.right - rect.left;
theApp.m_ini.m_treeviewSize.y = rect.bottom - rect.top;
delete m_cFont;
m_cFont = nullptr;
}
}
CDialog::OnShowWindow(bShow, nStatus);
}
//---------------------------------------------------
//関数名 OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
//機能 背景色を変える
//---------------------------------------------------
HBRUSH CMyTreeDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (m_brBack.GetSafeHandle()) hbr = m_brBack;
return hbr;
}
//---------------------------------------------------
//関数名 OnBeginlabeleditMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 ラベル編集開始
//---------------------------------------------------
void CMyTreeDialog::OnBeginlabeleditMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
m_isModal = true;
*pResult = 0;
}
//---------------------------------------------------
//関数名 OnEndlabeleditMyTree(NMHDR* pNMHDR, LRESULT* pResult)
//機能 ラベル編集終了
//---------------------------------------------------
void CMyTreeDialog::OnEndlabeleditMyTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
//変更をツリーに反映
m_pTreeCtrl->SetFocus();
TV_ITEM* item = &(pTVDispInfo->item);
if (item->pszText && *(item->pszText)) {
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
STRING_DATA* pData = m_pTreeCtrl->getDataPtr(hTreeItem);
pData->m_strTitle = item->pszText;
m_pTreeCtrl->UpdateItem(hTreeItem);
}
m_isModal = false;
*pResult = 0;
}
STRING_DATA* CMyTreeDialog::GetClickedItem()
{
HTREEITEM hTreeItem;
hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) {
STRING_DATA* dataPtr = m_pTreeCtrl->getDataPtr(hTreeItem);
if (!(dataPtr->m_cKind & KIND_FOLDER_ALL)) {
return dataPtr;
}
}
return nullptr;
}
//---------------------------------------------------
//関数名 PreTranslateMessage(MSG* pMsg)
//機能 メッセージ前処理
//---------------------------------------------------
BOOL CMyTreeDialog::PreTranslateMessage(MSG* pMsg)
{
m_toolTip.RelayEvent(pMsg);
switch (pMsg->message) {
case WM_TREE_CLOSE:
Cancel();
return TRUE;
case WM_LBUTTONDBLCLK:
if (!m_pTreeCtrl->IsDragging()) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
m_dataPtrDbClick = GetClickedItem();
}
break;
case WM_LBUTTONUP:
if (!m_pTreeCtrl->IsDragging()) {
if (m_dataPtrDbClick != nullptr) {
Determine(m_dataPtrDbClick);
return TRUE;
}
}
break;
case WM_FIND_CLOSE:
if (m_bFind) {
GetFindParam();
m_findDialog->DestroyWindow();
m_bFind = false;
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
break;
case WM_FIND_ONCE:
if (m_bFind) {
GetFindParam();
FindNext(false);
m_findDialog->DestroyWindow();
m_bFind = false;
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
break;
case WM_FIND_NEXT:
if (m_bFind) {
GetFindParam();
FindNext(false);
}
break;
case WM_FIND_PREV:
if (m_bFind) {
GetFindParam();
FindNext(true);
}
break;
case WM_TIPS_CHANGE:
{
HTREEITEM hTarget = (HTREEITEM)pMsg->wParam;
if (hTarget) {
SetTipText(m_pTreeCtrl->getDataPtr(hTarget));
}
else {
m_toolTip.Activate(FALSE);
}
}
break;
}
if (WM_SYSKEYDOWN == pMsg->message) m_isAltDown = true;
else if (((WM_SYSKEYUP == pMsg->message && m_isAltDown) || (WM_KEYDOWN == pMsg->message && pMsg->wParam == VK_APPS)) && !theApp.isCloseKey() && !m_pTreeCtrl->IsDragging()) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
m_isAltDown = false;
CPoint point;
ZeroMemory(&point, sizeof(point));
RECT rSelItem;
HTREEITEM hSelectItem = m_pTreeCtrl->GetSelectedItem();//選択位置を取得
if (hSelectItem) {
m_pTreeCtrl->GetItemRect(hSelectItem, &rSelItem, NULL);
point.x = 0;
point.y = rSelItem.bottom - 5;
}
ClientToScreen(&point);
PopupMenu(point);
// return true;
}
if (WM_KEYDOWN == pMsg->message) {
if (!m_pTreeCtrl->IsDragging()) {
MSG msg;
ZeroMemory(&msg, sizeof(msg));
msg.message = WM_LBUTTONDOWN;
msg.hwnd = this->m_hWnd;
m_toolTip.RelayEvent(&msg);
::PostMessage(m_pTreeCtrl->m_hWnd, WM_MOUSEMOVE, 0, 0);
::SetCursor(NULL);
}
//ESCで閉じる
if (VK_ESCAPE == pMsg->wParam && !m_isModal && !m_pTreeCtrl->IsDragging()) {
Cancel();
return TRUE;
}
//ラベル編集中なら編集終了
else if (VK_RETURN == pMsg->wParam && m_isModal) {
m_pTreeCtrl->SetFocus();
return TRUE;
}
//リターンキーを押したら決定
else if (VK_RETURN == pMsg->wParam && !m_pTreeCtrl->IsDragging()) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
//データ取得
HTREEITEM hTreeItem;
hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) {
STRING_DATA* dataPtr = m_pTreeCtrl->getDataPtr(hTreeItem);
//フォルダか確認
if (!(dataPtr->m_cKind & KIND_FOLDER_ALL) || (m_pTreeCtrl->GetStyle() & TVS_CHECKBOXES && m_pTreeCtrl->GetCheck(hTreeItem))) {
Determine(dataPtr);//データを決定
}
else
m_pTreeCtrl->Expand(hTreeItem, TVE_TOGGLE);
return TRUE;
}
}
//スペースキー
else if (VK_SPACE == pMsg->wParam && !m_isModal) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) {
bool goBackwards = ::GetKeyState(VK_SHIFT) < 0;
if (::GetKeyState(VK_CONTROL) < 0) {
m_pTreeCtrl->ToggleItemCheck(m_pTreeCtrl->GetSelectedItem());
if (goBackwards) {
hTreeItem = m_pTreeCtrl->GetPrevVisibleItem(hTreeItem);
}
else {
HTREEITEM currentItem = hTreeItem;
hTreeItem = m_pTreeCtrl->GetNextSiblingItem(currentItem); // Skip children
if (!hTreeItem) {
hTreeItem = m_pTreeCtrl->GetNextVisibleItem(currentItem);
}
}
std::list<HTREEITEM>::iterator it;
for (it = m_pTreeCtrl->m_ltCheckItems.begin(); it != m_pTreeCtrl->m_ltCheckItems.end(); it++) {
if (m_pTreeCtrl->GetItemState(*it, TVIF_HANDLE)) {
STRING_DATA* data = m_pTreeCtrl->getDataPtr(*it);
LOG(_T("[] %s"), data->m_strTitle.GetString());
}
}
}
else {
if (goBackwards) {
hTreeItem = m_pTreeCtrl->GetPrevVisibleItem(hTreeItem);
if (!hTreeItem) {
hTreeItem = m_pTreeCtrl->GetLastVisibleItem();
}
}
else {
hTreeItem = m_pTreeCtrl->GetNextVisibleItem(hTreeItem);
if (!hTreeItem) {
hTreeItem = m_pTreeCtrl->GetRootItem();
}
}
}
if (hTreeItem) {
m_pTreeCtrl->SelectItem(hTreeItem);
}
}
else {//選択されてなかったら0番目を選択
m_pTreeCtrl->Select(m_pTreeCtrl->GetRootItem(), TVGN_FIRSTVISIBLE);
}
return true;
}
//デリートキー(データ削除)
else if (VK_DELETE == pMsg->wParam && !m_pTreeCtrl->IsDragging() && !m_isModal) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
OnDelete();
}
//F1キー 内容表示
else if (VK_F1 == pMsg->wParam && !m_pTreeCtrl->IsDragging()) {
CPoint point;
ZeroMemory(&point, sizeof(point));
RECT rSelItem;
HTREEITEM hSelectItem = m_pTreeCtrl->GetSelectedItem();//選択位置を取得
if (hSelectItem) {
m_pTreeCtrl->GetItemRect(hSelectItem, &rSelItem, true);
point.x = rSelItem.left + ((rSelItem.right - rSelItem.left) / 2);
point.y = rSelItem.top + ((rSelItem.bottom - rSelItem.top) / 2);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
msg.message = WM_MOUSEMOVE;
msg.wParam = NULL;
msg.lParam = point.y;
msg.lParam = (msg.lParam << 16) + point.x;
msg.hwnd = m_pTreeCtrl->m_hWnd;
::PostMessage(msg.hwnd, msg.message, msg.wParam, msg.lParam);
ClientToScreen(&point);
::SetCursorPos(point.x, point.y);
}
}
// F2 : Rename
else if (VK_F2 == pMsg->wParam && !m_pTreeCtrl->IsDragging()) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
if (m_pTreeCtrl->GetSelectedItem())
m_pTreeCtrl->EditLabel(m_pTreeCtrl->GetSelectedItem());
}
// F3 : Find Next
else if (VK_F3 == pMsg->wParam && !m_pTreeCtrl->IsDragging() && !m_isModal) {
if (m_bFind) {
GetFindParam();
}
FindNext(::GetKeyState(VK_SHIFT) < 0);
}
// Ctrl+F : Open Find dialog
else if (::GetKeyState(VK_CONTROL) < 0 && pMsg->wParam == 'F' && !m_pTreeCtrl->IsDragging() && !m_isModal) {
OnListSearch();
return true;
}
//TABキーでチェック
else if (VK_TAB == pMsg->wParam && !m_pTreeCtrl->IsDragging() && !m_isModal) {
m_pTreeCtrl->ToggleItemCheck(m_pTreeCtrl->GetSelectedItem());
return true;
}
//上下
else if (VK_DOWN == pMsg->wParam || VK_UP == pMsg->wParam && !m_isModal) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem(), hTreeItemTmp;
if (hTreeItem != NULL && ::GetKeyState(VK_SHIFT) < 0) {//選択されていて、SHIFTを押してる
do {
hTreeItemTmp = hTreeItem;
if (VK_DOWN == pMsg->wParam) hTreeItem = m_pTreeCtrl->GetNextVisibleItem(hTreeItem);
else hTreeItem = m_pTreeCtrl->GetPrevVisibleItem(hTreeItem);
if (m_pTreeCtrl->GetChildItem(hTreeItem)) break;
} while (hTreeItem);
if (hTreeItem) {
m_pTreeCtrl->SelectItem(hTreeItem);
return true;
}
}
}
//左
else if (VK_LEFT == pMsg->wParam && !m_isModal) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) KillTimer(CHARU_QUICK_TIMER);
if (::GetKeyState(VK_SHIFT) < 0) {
if (::GetKeyState(VK_CONTROL) < 0) {
m_pTreeCtrl->closeFolder(m_pTreeCtrl->GetRootItem()); // Ctrl+Shift+Left: collapse all
}
else {
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) {
hTreeItem = m_pTreeCtrl->searchMyRoots(hTreeItem);
if (hTreeItem) {
m_pTreeCtrl->SelectItem(hTreeItem); // Shift+Left: collapse parent
}
}
}
}
}
// "select by typing"
else if (!m_isModal && !m_pTreeCtrl->IsDragging()) {
if (SelectByTyping((UINT)pMsg->wParam)) return TRUE;
}
}
// "select by typing" 確定処理
else if (WM_TIMER == pMsg->message && CHARU_QUICK_TIMER == pMsg->wParam && !m_pTreeCtrl->IsDragging()) {
BOOL retval = FALSE;
if (m_hQuickItem) {
STRING_DATA* dataPtr = m_pTreeCtrl->getDataPtr(m_hQuickItem);
if (dataPtr->m_cKind & KIND_DATA_ALL) {
if (theApp.m_ini.m_bSelectByTypingAutoPaste) {
Determine(dataPtr);
}
}
else if (dataPtr->m_cKind & KIND_FOLDER_ALL) {
if (theApp.m_ini.m_bSelectByTypingAutoExpand) {
m_pTreeCtrl->Expand(m_hQuickItem, TVE_EXPAND);
}
}
retval = TRUE;
}
this->KillTimer(CHARU_QUICK_TIMER);
return retval;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CMyTreeDialog::Close(WPARAM wparam)
{
if (m_bFind) {
m_findDialog->DestroyWindow();
m_bFind = false;
}
::PostMessage(theApp.GetAppWnd(), WM_TREE_CLOSE, wparam, NULL);
KillTimer(CHARU_QUICK_TIMER);
m_isInitOK = false;
}
void CMyTreeDialog::Determine(STRING_DATA* dataPtr)
{
if (dataPtr) {
m_selectedDataPtr = dataPtr;
Close(IDOK);
}
}
//---------------------------------------------------
//関数名 OnEdit()
//機能 選択項目を編集
//---------------------------------------------------
void CMyTreeDialog::OnEdit()
{
if (m_isModal) return;
m_isModal = true;
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
CEditDialog dlgEdit(this, m_pTreeCtrl->getDataPtr(hTreeItem), false);
if (dlgEdit.DoModal() == IDOK) {
m_pTreeCtrl->UpdateItem(hTreeItem);
}
m_isModal = false;
}
//---------------------------------------------------
//関数名 OnDelete()
//機能 選択項目を削除
//---------------------------------------------------
void CMyTreeDialog::OnDelete()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (!hTreeItem) {
return;
}
if (m_isModal) {
return;
}
m_isModal = true;
STRING_DATA* data = m_pTreeCtrl->getDataPtr(hTreeItem);
CString strMessage;
strMessage.Format(APP_MES_DELETE_OK, data->m_strTitle);
int nRet = AfxMessageBox(strMessage, MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL);
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
if (nRet == IDYES) {
if ((data->m_cKind & KIND_FOLDER_ALL) && m_pTreeCtrl->ItemHasChildren(hTreeItem)) {
(void)strMessage.LoadString(APP_MES_DELETE_FOLDER);
nRet = AfxMessageBox(strMessage, MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL);
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
}
if (nRet == IDYES) {
m_pTreeCtrl->DeleteData(hTreeItem);
}
m_pTreeCtrl->SetFocus();
m_isModal = false;
}
//---------------------------------------------------
//関数名 OnRename()
//機能 選択項目の名前の変更
//---------------------------------------------------
void CMyTreeDialog::OnRename()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (!hTreeItem) return;
m_pTreeCtrl->EditLabel(hTreeItem);
}
//---------------------------------------------------
//関数名 OnIcon~
//機能 データアイコンを変更
//---------------------------------------------------
//クリップボードマクロ
void CMyTreeDialog::OnIconClip()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_CLIP);
}
//日付マクロ
void CMyTreeDialog::OnIconDate()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_DATE);
}
//シェルマクロ
void CMyTreeDialog::OnIconExe()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_EXE);
}
//普通項目
void CMyTreeDialog::OnIconKey()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, 0);
}
//キーボードマクロ
void CMyTreeDialog::OnIconKeymacro()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_KEY);
}
//プラグイン
void CMyTreeDialog::OnIconPlugin()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_PLUG);
}
//関連付け実行マクロ
void CMyTreeDialog::OnIconRelate()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_RELATE);
}
//選択テキストマクロ
void CMyTreeDialog::OnIconSelect()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) m_pTreeCtrl->changeIcon(hTreeItem, KIND_SELECT);
}
//---------------------------------------------------
//関数名 OnMakeOnetime()
//機能 ワンタイムデータに変更
//---------------------------------------------------
void CMyTreeDialog::OnMakeOnetime()
{
HTREEITEM hTreeItem = m_pTreeCtrl->GetSelectedItem();
if (hTreeItem) {
STRING_DATA* pData = m_pTreeCtrl->getDataPtr(hTreeItem);
pData->m_cKind = KIND_ONETIME;
m_pTreeCtrl->UpdateItem(hTreeItem);
}
}
//---------------------------------------------------
//関数名 OnMakePermanent()
//機能 恒久データに変更
//---------------------------------------------------
void CMyTreeDialog::OnMakePermanent()