forked from CobaltFusion/DebugViewPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourcesDlg.cpp
More file actions
148 lines (128 loc) · 4.03 KB
/
Copy pathSourcesDlg.cpp
File metadata and controls
148 lines (128 loc) · 4.03 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
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/algorithm/string.hpp>
#include <utility>
#include <atlstr.h>
#include "Win32/Utilities.h"
#include "CobaltFusion/Str.h"
#include "CobaltFusion/AtlWinExt.h"
#include "CobaltFusion/fusionassert.h"
#include "DebugViewppLib/LogFilter.h"
#include "DebugViewppLib/LogSource.h"
#include "resource.h"
#include "SourceDlg.h"
#include "SourcesDlg.h"
namespace fusion {
namespace debugviewpp {
BEGIN_MSG_MAP2(CSourcesDlg)
MSG_WM_INITDIALOG(OnInitDialog)
NOTIFY_CODE_HANDLER_EX(PIN_CLICK, OnClickItem)
COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER_EX(IDOK, OnOk)
COMMAND_ID_HANDLER_EX(IDADD, OnAdd)
REFLECT_NOTIFICATIONS()
CHAIN_MSG_MAP(CDialogResize<CSourcesDlg>)
END_MSG_MAP()
CSourcesDlg::CSourcesDlg(std::vector<SourceInfo> sourceInfos) :
m_sourceInfos(std::move(sourceInfos))
{
}
void CSourcesDlg::OnException()
{
FUSION_REPORT_EXCEPTION("Unknown Exception");
}
void CSourcesDlg::OnException(const std::exception& ex)
{
FUSION_REPORT_EXCEPTION(ex.what());
}
void CSourcesDlg::UpdateGrid()
{
m_grid.DeleteAllItems();
for (auto& sourceInfo : m_sourceInfos)
{
int item = m_grid.GetItemCount();
m_grid.InsertItem(item, PropCreateCheckButton(L"", sourceInfo.enabled));
m_grid.SetSubItem(item, 1, PropCreateReadOnlyItem(L"", sourceInfo.description.c_str()));
m_grid.SetSubItem(item, 2, PropCreateReadOnlyItem(L"", WStr(SourceTypeToString(sourceInfo.type))));
if (sourceInfo.type == SourceType::System)
{
m_grid.SetSubItem(item, 3, PropCreateReadOnlyItem(L"", L""));
}
else
{
m_grid.SetSubItem(item, 3, PropCreateReadOnlyItem(L"", L"x"));
}
}
}
BOOL CSourcesDlg::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
{
m_grid.SubclassWindow(GetDlgItem(IDC_SOURCES_GRID));
m_grid.InsertColumn(0, L"", LVCFMT_LEFT, 32, 0);
m_grid.InsertColumn(1, L"Source description", LVCFMT_LEFT, 280, 0);
m_grid.InsertColumn(2, L"Type", LVCFMT_LEFT, 100, 0);
m_grid.InsertColumn(3, L"", LVCFMT_LEFT, 16, 0);
m_grid.SetExtendedGridStyle(PGS_EX_SINGLECLICKEDIT);
UpdateGrid();
CenterWindow(GetParent());
DlgResize_Init();
return TRUE;
}
LRESULT CSourcesDlg::OnClickItem(NMHDR* pnmh)
{
auto& nmhdr = *reinterpret_cast<NMPROPERTYITEM*>(pnmh);
int iItem = -1;
int iSubItem = -1;
if ((m_grid.FindProperty(nmhdr.prop, iItem, iSubItem) != 0) && iSubItem == 3)
{
if (GetSourceType(iItem) != SourceType::System)
{
m_grid.DeleteItem(iItem);
m_sourceInfos.erase(m_sourceInfos.begin() + iItem);
return TRUE;
}
}
return FALSE;
}
bool CSourcesDlg::GetSourceEnable(int iItem) const
{
CComVariant val;
GetGridItem<CPropertyCheckButtonItem>(m_grid, iItem, 0).GetValue(&val);
return val.boolVal != VARIANT_FALSE;
}
std::wstring CSourcesDlg::GetSourceText(int iItem) const
{
return GetGridItemText(m_grid, iItem, 1);
}
SourceType::type CSourcesDlg::GetSourceType(int iItem) const
{
return StringToSourceType(Str(GetGridItemText(m_grid, iItem, 2)));
}
void CSourcesDlg::OnCancel(UINT /*uNotifyCode*/, int nID, CWindow /*wndCtl*/)
{
m_sourceInfos.clear();
EndDialog(nID);
}
void CSourcesDlg::OnOk(UINT /*uNotifyCode*/, int nID, CWindow /*wndCtl*/)
{
EndDialog(nID);
}
void CSourcesDlg::OnAdd(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wndCtl*/)
{
CSourceDlg dlg(L"UDP port 2020", SourceType::Udp, L"192.168.1.1", 2020);
if (dlg.DoModal() != IDOK)
{
return;
}
auto info = SourceInfo(dlg.GetName(), dlg.GetSourceType(), dlg.GetAddress(), dlg.GetPort());
info.enabled = true;
m_sourceInfos.push_back(info);
UpdateGrid();
}
std::vector<SourceInfo> CSourcesDlg::GetSourceInfos()
{
return m_sourceInfos;
}
} // namespace debugviewpp
} // namespace fusion