xref: /MusicPlayer2/MusicPlayer2/OptionsDlg.cpp (revision 443d2d2511be730d1b1dd3181942b7fa6539aa1a)
1 // OptionsDlg.cpp : 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "OptionsDlg.h"
7 
8 
9 // COptionsDlg 对话框
10 
11 IMPLEMENT_DYNAMIC(COptionsDlg, CBaseDialog)
12 
13 COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/)
14 	: CBaseDialog(IDD_OPTIONS_DIALOG, pParent)
15 {
16 
17 }
18 
19 COptionsDlg::~COptionsDlg()
20 {
21 }
22 
23 CString COptionsDlg::GetDialogName() const
24 {
25     return _T("OptionsDlg");
26 }
27 
28 bool COptionsDlg::InitializeControls()
29 {
30     wstring temp;
31     temp = theApp.m_str_table.LoadText(L"TITLE_OPT");
32     SetWindowTextW(temp.c_str());
33     temp = theApp.m_str_table.LoadText(L"TXT_APPLY");
34     SetDlgItemTextW(IDC_APPLY_BUTTON, temp.c_str());
35 
36     RepositionTextBasedControls({
37         { CtrlTextInfo::R1, IDOK, CtrlTextInfo::W32 },
38         { CtrlTextInfo::R2, IDCANCEL, CtrlTextInfo::W32 },
39         { CtrlTextInfo::R3, IDC_APPLY_BUTTON, CtrlTextInfo::W32 }
40         });
41     return true;
42 }
43 
44 void COptionsDlg::DoDataExchange(CDataExchange* pDX)
45 {
46 	CBaseDialog::DoDataExchange(pDX);
47 	DDX_Control(pDX, IDC_OPTIONS_TAB, m_tab);
48 }
49 
50 
51 BEGIN_MESSAGE_MAP(COptionsDlg, CBaseDialog)
52 	ON_BN_CLICKED(IDC_APPLY_BUTTON, &COptionsDlg::OnBnClickedApplyButton)
53 	ON_WM_DESTROY()
54     ON_WM_GETMINMAXINFO()
55     ON_WM_SIZE()
56 END_MESSAGE_MAP()
57 
58 
59 // COptionsDlg 消息处理程序
60 
61 
62 BOOL COptionsDlg::OnInitDialog()
63 {
64 	CBaseDialog::OnInitDialog();
65 
66 	// TODO:  在此添加额外的初始化
67 
68     SetIcon(theApp.m_icon_set.setting.GetIcon(true), FALSE);
69 
70 	//创建子对话框
71 	m_tab1_dlg.Create(IDD_LYRIC_SETTING_DIALOG);
72 	m_tab2_dlg.Create(IDD_APPEREANCE_SETTING_DLG);
73 	m_tab3_dlg.Create(IDD_DATA_SETTINGS_DIALOG);
74 	m_tab4_dlg.Create(IDD_PLAY_SETTING_DIALOG);
75 	m_media_lib_dlg.Create(IDD_MEDIA_LIB_SETTING_DIALOG);
76 	m_tab5_dlg.Create(IDD_HOT_KEY_SETTINGS_DIALOG);
77 
78 	//保存子对话框
79 	m_tab_vect.push_back(&m_tab1_dlg);
80 	m_tab_vect.push_back(&m_tab2_dlg);
81 	m_tab_vect.push_back(&m_tab3_dlg);
82 	m_tab_vect.push_back(&m_tab4_dlg);
83 	m_tab_vect.push_back(&m_media_lib_dlg);
84 	m_tab_vect.push_back(&m_tab5_dlg);
85 
86 	//获取子对话框的初始高度
87 	for (const auto* pDlg : m_tab_vect)
88 	{
89 		CRect rect;
90 		pDlg->GetWindowRect(rect);
91 		m_tab_height.push_back(rect.Height());
92 	}
93 
94 	//添加对话框
95 	m_tab.AddWindow(&m_tab1_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_LRC").c_str());
96 	m_tab.AddWindow(&m_tab2_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_APC").c_str());
97 	m_tab.AddWindow(&m_tab3_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_DATA").c_str());
98 	m_tab.AddWindow(&m_tab4_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_PLAY").c_str());
99 	m_tab.AddWindow(&m_media_lib_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_MEDIA_LIB").c_str());
100 	m_tab.AddWindow(&m_tab5_dlg, theApp.m_str_table.LoadText(L"TITLE_OPT_HOT_KEY").c_str());
101 
102     //为每个标签添加图标
103     CImageList ImageList;
104     ImageList.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
105     ImageList.Add(theApp.m_icon_set.lyric.GetIcon(true));
106     ImageList.Add(theApp.m_icon_set.skin.GetIcon(true));
107     ImageList.Add(theApp.m_icon_set.setting.GetIcon(true));
108     ImageList.Add(theApp.m_icon_set.play_new.GetIcon(true));
109     ImageList.Add(theApp.m_icon_set.media_lib.GetIcon(true));
110     ImageList.Add(theApp.m_icon_set.hot_key);
111     m_tab.SetImageList(&ImageList);
112     ImageList.Detach();
113 
114     m_tab.SetItemSize(CSize(theApp.DPI(60), theApp.DPI(24)));
115     m_tab.AdjustTabWindowSize();
116 
117 	//为每个子窗口设置滚动信息
118 	for (size_t i = 0; i < m_tab_vect.size(); i++)
119 	{
120 		m_tab_vect[i]->SetScrollbarInfo(m_tab.m_tab_rect.Height(), m_tab_height[i]);
121 	}
122 
123     if (m_tab_selected < 0 || m_tab_selected >= m_tab.GetItemCount())
124         m_tab_selected = 0;
125 	m_tab.SetCurTab(m_tab_selected);
126 
127 	return TRUE;  // return TRUE unless you set the focus to a control
128 				  // 异常: OCX 属性页应返回 FALSE
129 }
130 
131 void COptionsDlg::OnOK()
132 {
133 	// TODO: 在此添加专用代码和/或调用基类
134     for (const auto& tab : m_tab_vect)
135     {
136         tab->GetDataFromUi();
137     }
138 
139 	CBaseDialog::OnOK();
140 }
141 
142 
143 void COptionsDlg::OnBnClickedApplyButton()
144 {
145 	// TODO: 在此添加控件通知处理程序代码
146     for (const auto& tab : m_tab_vect)
147     {
148         tab->GetDataFromUi();
149     }
150 
151 	::SendMessage(theApp.m_pMainWnd->GetSafeHwnd(), WM_SETTINGS_APPLIED, (WPARAM)this, 0);
152 
153     for (const auto& tab : m_tab_vect)
154     {
155         tab->ApplyDataToUi();
156     }
157 }
158 
159 
160 void COptionsDlg::OnDestroy()
161 {
162 	CBaseDialog::OnDestroy();
163 
164 	// TODO: 在此处添加消息处理程序代码
165 	m_tab_selected = m_tab.GetCurSel();
166 }
167 
168 
169 void COptionsDlg::OnSize(UINT nType, int cx, int cy)
170 {
171     CBaseDialog::OnSize(nType, cx, cy);
172     if (nType != SIZE_MINIMIZED)
173     {
174         //为每个子窗口设置滚动信息
175         for (size_t i = 0; i < m_tab_vect.size(); i++)
176         {
177             m_tab_vect[i]->ResetScroll();
178             m_tab_vect[i]->SetScrollbarInfo(m_tab.m_tab_rect.Height(), m_tab_height[i]);
179         }
180 
181     }
182 
183     // TODO: 在此处添加消息处理程序代码
184 }
185