1 // PropertyAdvancedDlg.cpp: 实现文件
2 //
3
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "PropertyAdvancedDlg.h"
7 #include "AudioTag.h"
8
9
10 // CPropertyAdvancedDlg 对话框
11
IMPLEMENT_DYNAMIC(CPropertyAdvancedDlg,CTabDlg)12 IMPLEMENT_DYNAMIC(CPropertyAdvancedDlg, CTabDlg)
13
14 CPropertyAdvancedDlg::CPropertyAdvancedDlg(vector<SongInfo>& all_song_info, int& index, CWnd* pParent /*= nullptr*/)
15 : CTabDlg(IDD_PROPERTY_ADVANCED_DIALOG, pParent), m_all_song_info{ all_song_info }, m_index{ index }, m_batch_edit{ false }
16 {
17
18 }
19
CPropertyAdvancedDlg(vector<SongInfo> & all_song_info,CWnd * pParent)20 CPropertyAdvancedDlg::CPropertyAdvancedDlg(vector<SongInfo>& all_song_info, CWnd* pParent /*= nullptr*/)
21 : CTabDlg(IDD_PROPERTY_ADVANCED_DIALOG, pParent), m_all_song_info{ all_song_info }, m_index{ m_no_use }, m_batch_edit{ true }
22 {
23
24 }
25
~CPropertyAdvancedDlg()26 CPropertyAdvancedDlg::~CPropertyAdvancedDlg()
27 {
28 }
29
AdjustColumnWidth()30 void CPropertyAdvancedDlg::AdjustColumnWidth()
31 {
32 CRect rect;
33 m_list_ctrl.GetWindowRect(rect);
34 int width0 = theApp.DPI(160);
35 int width1 = rect.Width() - width0 - theApp.DPI(20) - 1;
36 m_list_ctrl.SetColumnWidth(0, width0);
37 m_list_ctrl.SetColumnWidth(1, width1);
38 }
39
SaveModified()40 int CPropertyAdvancedDlg::SaveModified()
41 {
42 return 0;
43 }
44
PagePrevious()45 void CPropertyAdvancedDlg::PagePrevious()
46 {
47 m_index--;
48 if (m_index < 0) m_index = static_cast<int>(m_all_song_info.size()) - 1;
49 if (m_index < 0) m_index = 0;
50 ShowInfo();
51 }
52
PageNext()53 void CPropertyAdvancedDlg::PageNext()
54 {
55 m_index++;
56 if (m_index >= static_cast<int>(m_all_song_info.size())) m_index = 0;
57 ShowInfo();
58 }
59
OnTabEntered()60 void CPropertyAdvancedDlg::OnTabEntered()
61 {
62 ShowInfo();
63 CWnd* pParent = GetParentWindow();
64 if (pParent != nullptr)
65 pParent->SendMessage(WM_PROPERTY_DIALOG_MODIFIED, false); //设置“保存到文件”按钮不可用
66 }
67
CurrentSong()68 const SongInfo& CPropertyAdvancedDlg::CurrentSong()
69 {
70 if (m_index >= 0 && m_index < static_cast<int>(m_all_song_info.size()) && !m_batch_edit)
71 {
72 return m_all_song_info[m_index];
73 }
74 else
75 {
76 static SongInfo song;
77 return song;
78 }
79 }
80
ShowInfo()81 void CPropertyAdvancedDlg::ShowInfo()
82 {
83 EnableWindow(!m_batch_edit);
84 m_list_ctrl.DeleteAllItems();
85 if (!m_batch_edit) //批量编辑(多选)模式下不支持显示高级标签信息
86 {
87 SongInfo cur_song = CurrentSong();
88 CAudioTag audio_tag(cur_song);
89 std::map<wstring, wstring> property_map;
90 audio_tag.GetAudioTagPropertyMap(property_map);
91
92 int index{};
93 for (const auto& prop : property_map)
94 {
95 m_list_ctrl.InsertItem(index, prop.first.c_str());
96 m_list_ctrl.SetItemText(index, 1, prop.second.c_str());
97 index++;
98 }
99 }
100 }
101
DoDataExchange(CDataExchange * pDX)102 void CPropertyAdvancedDlg::DoDataExchange(CDataExchange* pDX)
103 {
104 CTabDlg::DoDataExchange(pDX);
105 DDX_Control(pDX, IDC_LIST1, m_list_ctrl);
106 }
107
108
BEGIN_MESSAGE_MAP(CPropertyAdvancedDlg,CTabDlg)109 BEGIN_MESSAGE_MAP(CPropertyAdvancedDlg, CTabDlg)
110 ON_COMMAND(ID_COPY_TEXT, &CPropertyAdvancedDlg::OnCopyText)
111 ON_NOTIFY(NM_RCLICK, IDC_LIST1, &CPropertyAdvancedDlg::OnNMRClickList1)
112 ON_WM_INITMENU()
113 ON_COMMAND(ID_COPY_ALL_TEXT, &CPropertyAdvancedDlg::OnCopyAllText)
114 END_MESSAGE_MAP()
115
116
117 // CPropertyAdvancedDlg 消息处理程序
118
119
120 BOOL CPropertyAdvancedDlg::OnInitDialog()
121 {
122 CTabDlg::OnInitDialog();
123
124 // TODO: 在此添加额外的初始化
125
126 //初始化列表
127 m_list_ctrl.SetExtendedStyle(m_list_ctrl.GetExtendedStyle() | LVS_EX_GRIDLINES);
128 m_list_ctrl.InsertColumn(0, theApp.m_str_table.LoadText(L"TXT_ITEM").c_str(), LVCFMT_LEFT, theApp.DPI(100));
129 m_list_ctrl.InsertColumn(1, theApp.m_str_table.LoadText(L"TXT_VALUE").c_str(), LVCFMT_LEFT, theApp.DPI(200));
130
131 return TRUE; // return TRUE unless you set the focus to a control
132 // 异常: OCX 属性页应返回 FALSE
133 }
134
135
OnCopyText()136 void CPropertyAdvancedDlg::OnCopyText()
137 {
138 // TODO: 在此添加命令处理程序代码
139 if (!CCommon::CopyStringToClipboard(m_selected_string))
140 MessageBox(theApp.m_str_table.LoadText(L"MSG_COPY_CLIPBOARD_FAILED").c_str(), NULL, MB_ICONWARNING);
141 }
142
143
OnNMRClickList1(NMHDR * pNMHDR,LRESULT * pResult)144 void CPropertyAdvancedDlg::OnNMRClickList1(NMHDR *pNMHDR, LRESULT *pResult)
145 {
146 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
147 // TODO: 在此添加控件通知处理程序代码
148 m_selected_string = m_list_ctrl.GetItemText(pNMItemActivate->iItem, pNMItemActivate->iSubItem);
149 m_item_selected = pNMItemActivate->iItem;
150
151 //弹出右键菜单
152 CMenu* pMenu = theApp.m_menu_mgr.GetMenu(MenuMgr::PropertyAdvMenu);
153 ASSERT(pMenu != nullptr);
154 if (pMenu != nullptr)
155 {
156 m_list_ctrl.ShowPopupMenu(pMenu, pNMItemActivate->iItem, this);
157 }
158
159 *pResult = 0;
160 }
161
162
OnInitMenu(CMenu * pMenu)163 void CPropertyAdvancedDlg::OnInitMenu(CMenu* pMenu)
164 {
165 CTabDlg::OnInitMenu(pMenu);
166
167 // TODO: 在此处添加消息处理程序代码
168 bool select_valid{ m_item_selected >= 0 && m_item_selected < m_list_ctrl.GetItemCount() };
169 pMenu->EnableMenuItem(ID_COPY_TEXT, MF_BYCOMMAND | (select_valid ? MF_ENABLED : MF_GRAYED));
170 }
171
172
OnCopyAllText()173 void CPropertyAdvancedDlg::OnCopyAllText()
174 {
175 // TODO: 在此添加命令处理程序代码
176 CCommon::CopyStringToClipboard(m_list_ctrl.GetAllText());
177 }
178