xref: /MusicPlayer2/MusicPlayer2/PropertyDlg.cpp (revision ccb67e1690268e6e20dcb5784a156f1b466f70db)
1 // PropertyDlg.cpp: 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "Player.h"
7 #include "PropertyDlg.h"
8 
9 
10 // CPropertyDlg 对话框
11 
IMPLEMENT_DYNAMIC(CPropertyDlg,CBaseDialog)12 IMPLEMENT_DYNAMIC(CPropertyDlg, CBaseDialog)
13 
14 CPropertyDlg::CPropertyDlg(vector<SongInfo>& all_song_info, int index, bool read_only, int tab_index, bool show_out_album_cover, CWnd* pParent /*=nullptr*/)
15     : CBaseDialog(IDD_PROPERTY_PARENT_DIALOG, pParent), m_read_only{ read_only }, m_index{ index }, m_song_num{ static_cast<int>(all_song_info.size()) }, m_tab_index{ tab_index },
16     m_property_dlg(all_song_info, m_index, this, read_only),
17     m_album_cover_dlg(all_song_info, m_index, show_out_album_cover, read_only, this),
18     m_advanced_dlg(all_song_info, m_index),
19     m_batch_edit{ false }
20 {
21 
22 }
23 
CPropertyDlg(vector<SongInfo> & all_song_info,CWnd * pParent)24 CPropertyDlg::CPropertyDlg(vector<SongInfo>& all_song_info, CWnd* pParent /*= nullptr*/)
25     : CBaseDialog(IDD_PROPERTY_PARENT_DIALOG, pParent), m_song_num{ static_cast<int>(all_song_info.size()) },
26     m_property_dlg(all_song_info, this),
27     m_album_cover_dlg(all_song_info, this),
28     m_advanced_dlg(all_song_info),
29     m_batch_edit{ true }
30 {
31 
32 }
33 
~CPropertyDlg()34 CPropertyDlg::~CPropertyDlg()
35 {
36 }
37 
GetListRefresh() const38 bool CPropertyDlg::GetListRefresh() const
39 {
40     return m_property_dlg.GetListRefresh();
41 }
42 
GetModified() const43 bool CPropertyDlg::GetModified() const
44 {
45     return m_modified;
46 }
47 
ShowPageNum()48 void CPropertyDlg::ShowPageNum()
49 {
50     //显示页数
51     CString item_info;
52     item_info.Format(_T("%d/%d"), m_index + 1, m_song_num);
53     SetDlgItemText(IDC_ITEM_STATIC, item_info);
54 
55 }
56 
GetDialogName() const57 CString CPropertyDlg::GetDialogName() const
58 {
59     return _T("PropertyDlg");
60 }
61 
InitializeControls()62 bool CPropertyDlg::InitializeControls()
63 {
64     wstring temp;
65     temp = theApp.m_str_table.LoadText(L"TITLE_PROPERTY_PARENT");
66     SetWindowTextW(temp.c_str());
67     // IDC_TAB1
68     temp = theApp.m_str_table.LoadText(L"TXT_PROPERTY_PARENT_PREVIOUS");
69     SetDlgItemTextW(IDC_PREVIOUS_BUTTON, temp.c_str());
70     temp = theApp.m_str_table.LoadText(L"TXT_PROPERTY_PARENT_NEXT");
71     SetDlgItemTextW(IDC_NEXT_BUTTON, temp.c_str());
72     // IDC_ITEM_STATIC
73     temp = theApp.m_str_table.LoadText(L"TXT_PROPERTY_PARENT_SAVE_TO_FILE");
74     SetDlgItemTextW(IDC_SAVE_TO_FILE_BUTTON, temp.c_str());
75     temp = theApp.m_str_table.LoadText(L"TXT_CLOSE");
76     SetDlgItemTextW(IDCANCEL, temp.c_str());
77 
78     RepositionTextBasedControls({
79         { CtrlTextInfo::L2, IDC_PREVIOUS_BUTTON, CtrlTextInfo::W32 },
80         { CtrlTextInfo::L1, IDC_NEXT_BUTTON, CtrlTextInfo::W32 },
81         { CtrlTextInfo::C0, IDC_ITEM_STATIC },
82         { CtrlTextInfo::R1, IDC_SAVE_TO_FILE_BUTTON, CtrlTextInfo::W32 },
83         { CtrlTextInfo::R2, IDCANCEL, CtrlTextInfo::W32 }
84         });
85     return true;
86 }
87 
DoDataExchange(CDataExchange * pDX)88 void CPropertyDlg::DoDataExchange(CDataExchange* pDX)
89 {
90     CBaseDialog::DoDataExchange(pDX);
91     DDX_Control(pDX, IDC_TAB1, m_tab_ctrl);
92     DDX_Control(pDX, IDC_SAVE_TO_FILE_BUTTON, m_save_btn);
93     DDX_Control(pDX, IDC_PREVIOUS_BUTTON, m_previous_btn);
94     DDX_Control(pDX, IDC_NEXT_BUTTON, m_next_btn);
95 }
96 
97 
BEGIN_MESSAGE_MAP(CPropertyDlg,CBaseDialog)98 BEGIN_MESSAGE_MAP(CPropertyDlg, CBaseDialog)
99     ON_BN_CLICKED(IDC_SAVE_TO_FILE_BUTTON, &CPropertyDlg::OnBnClickedSaveToFileButton)
100     ON_BN_CLICKED(IDC_PREVIOUS_BUTTON, &CPropertyDlg::OnBnClickedPreviousButton)
101     ON_BN_CLICKED(IDC_NEXT_BUTTON, &CPropertyDlg::OnBnClickedNextButton)
102     ON_MESSAGE(WM_PROPERTY_DIALOG_MODIFIED, &CPropertyDlg::OnPropertyDialogModified)
103     ON_WM_MOUSEWHEEL()
104 END_MESSAGE_MAP()
105 
106 
107 // CPropertyDlg 消息处理程序
108 
109 
110 BOOL CPropertyDlg::OnInitDialog()
111 {
112     CBaseDialog::OnInitDialog();
113 
114     // TODO:  在此添加额外的初始化
115 
116     SetIcon(IconMgr::IconType::IT_Info, FALSE);
117     SetButtonIcon(IDC_PREVIOUS_BUTTON, IconMgr::IconType::IT_Triangle_Left);
118     SetButtonIcon(IDC_NEXT_BUTTON, IconMgr::IconType::IT_Triangle_Right);
119     SetButtonIcon(IDC_SAVE_TO_FILE_BUTTON, IconMgr::IconType::IT_Save);
120 
121     //创建子对话框
122     m_property_dlg.Create(IDD_PROPERTY_DIALOG);
123     m_album_cover_dlg.Create(IDD_PROPERTY_ALBUM_COVER_DIALOG);
124     if (!m_batch_edit)      //批量编辑时不添加“高级标签信息”标签
125         m_advanced_dlg.Create(IDD_PROPERTY_ADVANCED_DIALOG);
126 
127     //添加对话框
128     m_tab_ctrl.AddWindow(&m_property_dlg, theApp.m_str_table.LoadText(L"TITLE_PROPERTY_DLG").c_str(), IconMgr::IconType::IT_File_Relate);
129     m_tab_ctrl.AddWindow(&m_album_cover_dlg, theApp.m_str_table.LoadText(L"TITLE_COVER_PROPERTY").c_str(), IconMgr::IconType::IT_Album_Cover);
130     if (!m_batch_edit)
131         m_tab_ctrl.AddWindow(&m_advanced_dlg, theApp.m_str_table.LoadText(L"TITLE_ADVANCED_PROPERTY").c_str(), IconMgr::IconType::IT_Tag);
132 
133     m_tab_ctrl.SetItemSize(CSize(theApp.DPI(60), theApp.DPI(24)));
134     m_tab_ctrl.AdjustTabWindowSize();
135 
136     m_album_cover_dlg.AdjustColumnWidth();
137     if (!m_batch_edit)
138         m_advanced_dlg.AdjustColumnWidth();
139 
140     m_tab_ctrl.SetCurTab(m_tab_index);
141 
142     ShowPageNum();
143 
144     if (m_read_only)
145     {
146         CWnd* pBtn = GetDlgItem(IDC_SAVE_TO_FILE_BUTTON);
147         if (pBtn != nullptr)
148             pBtn->ShowWindow(SW_HIDE);
149     }
150 
151     if (m_batch_edit)
152     {
153         SetWindowText(theApp.m_str_table.LoadTextFormat(L"TITLE_PROPERTY_PARENT_BATCH", { m_song_num }).c_str());
154         ShowDlgCtrl(IDC_PREVIOUS_BUTTON, false);
155         ShowDlgCtrl(IDC_NEXT_BUTTON, false);
156         ShowDlgCtrl(IDC_ITEM_STATIC, false);
157     }
158 
159     return TRUE;  // return TRUE unless you set the focus to a control
160                   // 异常: OCX 属性页应返回 FALSE
161 }
162 
163 
OnBnClickedSaveToFileButton()164 void CPropertyDlg::OnBnClickedSaveToFileButton()
165 {
166     // TODO: 在此添加控件通知处理程序代码
167     IPropertyTabDlg* cur_tab = dynamic_cast<IPropertyTabDlg*>(m_tab_ctrl.GetCurrentTab());
168     if (cur_tab != nullptr)
169     {
170         CPlayer::ReOpen reopen(true);   // ReOpen需要在IsLockSuccess失败时撤销操作所以改在这里,但这里判断是否为修改当前播放有点困难所以总是先关闭
171         if (reopen.IsLockSuccess())
172         {
173             int saved_num = cur_tab->SaveModified();
174             m_modified = true;
175             if (m_batch_edit)
176             {
177                 wstring info = theApp.m_str_table.LoadTextFormat(L"MSG_PROPERTY_PARENT_TAG_BATCH_EDIT_SAVE_INFO", { saved_num });
178                 MessageBox(info.c_str(), NULL, MB_ICONINFORMATION | MB_OK);
179             }
180             else
181             {
182                 if (saved_num == 0)
183                 {
184                     const wstring& info = theApp.m_str_table.LoadText(L"MSG_FILE_WRITE_FAILED");
185                     MessageBox(info.c_str(), NULL, MB_ICONWARNING | MB_OK);
186                 }
187             }
188         }
189         else
190         {
191             const wstring& info = theApp.m_str_table.LoadText(L"MSG_WAIT_AND_RETRY");
192             MessageBox(info.c_str(), NULL, MB_ICONINFORMATION | MB_OK);
193         }
194     }
195 }
196 
197 
OnBnClickedPreviousButton()198 void CPropertyDlg::OnBnClickedPreviousButton()
199 {
200     // TODO: 在此添加控件通知处理程序代码
201     if (!m_batch_edit)
202     {
203         IPropertyTabDlg* cur_tab = dynamic_cast<IPropertyTabDlg*>(m_tab_ctrl.GetCurrentTab());
204         if (cur_tab != nullptr)
205         {
206             cur_tab->PagePrevious();
207             ShowPageNum();
208         }
209     }
210 }
211 
212 
OnBnClickedNextButton()213 void CPropertyDlg::OnBnClickedNextButton()
214 {
215     // TODO: 在此添加控件通知处理程序代码
216     if (!m_batch_edit)
217     {
218         IPropertyTabDlg* cur_tab = dynamic_cast<IPropertyTabDlg*>(m_tab_ctrl.GetCurrentTab());
219         if (cur_tab != nullptr)
220         {
221             cur_tab->PageNext();
222             ShowPageNum();
223         }
224     }
225 }
226 
227 
OnPropertyDialogModified(WPARAM wParam,LPARAM lParam)228 afx_msg LRESULT CPropertyDlg::OnPropertyDialogModified(WPARAM wParam, LPARAM lParam)
229 {
230     CWnd* pBtn = GetDlgItem(IDC_SAVE_TO_FILE_BUTTON);
231     if (pBtn != nullptr)
232         pBtn->EnableWindow((BOOL)wParam);
233     return 0;
234 }
235 
236 
OnMouseWheel(UINT nFlags,short zDelta,CPoint pt)237 BOOL CPropertyDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
238 {
239     // TODO: 在此添加消息处理程序代码和/或调用默认值
240     if (zDelta > 0)
241     {
242         OnBnClickedPreviousButton();
243     }
244     if (zDelta < 0)
245     {
246         OnBnClickedNextButton();
247     }
248 
249     return CBaseDialog::OnMouseWheel(nFlags, zDelta, pt);
250 }
251 
252 
PreTranslateMessage(MSG * pMsg)253 BOOL CPropertyDlg::PreTranslateMessage(MSG* pMsg)
254 {
255     // TODO: 在此添加专用代码和/或调用基类
256     if (pMsg->message == WM_KEYDOWN)
257     {
258         if (pMsg->wParam == VK_UP)
259         {
260             OnBnClickedPreviousButton();
261             return TRUE;
262         }
263         if (pMsg->wParam == VK_DOWN)
264         {
265             OnBnClickedNextButton();
266             return TRUE;
267         }
268     }
269 
270     return CBaseDialog::PreTranslateMessage(pMsg);
271 }
272