00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PnSPresetsDlg.h"
00028
00029
00030
00031
00032 IMPLEMENT_DYNAMIC(CPnSPresetsDlg, CCmdUIDialog)
00033 CPnSPresetsDlg::CPnSPresetsDlg(CWnd* pParent )
00034 : CCmdUIDialog(CPnSPresetsDlg::IDD, pParent)
00035 , m_label(_T(""))
00036 {
00037 }
00038
00039 CPnSPresetsDlg::~CPnSPresetsDlg()
00040 {
00041 }
00042
00043 void CPnSPresetsDlg::DoDataExchange(CDataExchange* pDX)
00044 {
00045 __super::DoDataExchange(pDX);
00046 DDX_Control(pDX, IDC_EDIT2, m_PosX);
00047 DDX_Control(pDX, IDC_EDIT3, m_PosY);
00048 DDX_Control(pDX, IDC_EDIT4, m_ZoomX);
00049 DDX_Control(pDX, IDC_EDIT5, m_ZoomY);
00050 DDX_Text(pDX, IDC_EDIT1, m_label);
00051 DDX_Control(pDX, IDC_LIST1, m_list);
00052 }
00053
00054 BOOL CPnSPresetsDlg::OnInitDialog()
00055 {
00056 __super::OnInitDialog();
00057
00058 for(int i = 0, j = m_pnspresets.GetCount(); i < j; i++)
00059 {
00060 CString label;
00061 double PosX, PosY, ZoomX, ZoomY;
00062 StringToParams(m_pnspresets[i], label, PosX, PosY, ZoomX, ZoomY);
00063
00064 m_list.AddString(label);
00065
00066 if(i == 0)
00067 {
00068 m_list.SetCurSel(0);
00069 OnLbnSelchangeList1();
00070 }
00071 }
00072
00073 return TRUE;
00074
00075 }
00076
00077
00078 void CPnSPresetsDlg::StringToParams(CString str, CString& label, double& PosX, double& PosY, double& ZoomX, double& ZoomY)
00079 {
00080 int i = 0, j = 0;
00081
00082 for(CString token = str.Tokenize(_T(","), i); !token.IsEmpty(); token = str.Tokenize(_T(","), i), j++)
00083 {
00084 if(j == 0)
00085 {
00086 label = token;
00087 }
00088 else
00089 {
00090 float f = 0;
00091 if(_stscanf(token, _T("%f"), &f) != 1) continue;
00092
00093 switch(j)
00094 {
00095 case 1: PosX = f; break;
00096 case 2: PosY = f; break;
00097 case 3: ZoomX = f; break;
00098 case 4: ZoomY = f; break;
00099 default: break;
00100 }
00101 }
00102 }
00103 }
00104
00105 CString CPnSPresetsDlg::ParamsToString(CString label, double PosX, double PosY, double ZoomX, double ZoomY)
00106 {
00107 CString str;
00108 str.Format(_T("%s,%.3f,%.3f,%.3f,%.3f"), label, PosX, PosY, ZoomX, ZoomY);
00109 return(str);
00110 }
00111
00112 BEGIN_MESSAGE_MAP(CPnSPresetsDlg, CCmdUIDialog)
00113 ON_LBN_SELCHANGE(IDC_LIST1, OnLbnSelchangeList1)
00114 ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
00115 ON_UPDATE_COMMAND_UI(IDC_BUTTON2, OnUpdateButton2)
00116 ON_BN_CLICKED(IDC_BUTTON6, OnBnClickedButton6)
00117 ON_UPDATE_COMMAND_UI(IDC_BUTTON6, OnUpdateButton6)
00118 ON_BN_CLICKED(IDC_BUTTON9, OnBnClickedButton9)
00119 ON_UPDATE_COMMAND_UI(IDC_BUTTON9, OnUpdateButton9)
00120 ON_BN_CLICKED(IDC_BUTTON10, OnBnClickedButton10)
00121 ON_UPDATE_COMMAND_UI(IDC_BUTTON10, OnUpdateButton10)
00122 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
00123 ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
00124 END_MESSAGE_MAP()
00125
00126
00127
00128 void CPnSPresetsDlg::OnLbnSelchangeList1()
00129 {
00130 int i = m_list.GetCurSel();
00131 if(i >= 0 && i < m_pnspresets.GetCount())
00132 {
00133 double PosX, PosY, ZoomX, ZoomY;
00134 StringToParams(m_pnspresets[i], m_label, PosX, PosY, ZoomX, ZoomY);
00135 m_PosX = PosX; m_PosY = PosY;
00136 m_ZoomX = ZoomX; m_ZoomY = ZoomY;
00137 }
00138 else
00139 {
00140 m_label.Empty();
00141 m_PosX.SetWindowText(_T(""));
00142 m_PosY.SetWindowText(_T(""));
00143 m_ZoomX.SetWindowText(_T(""));
00144 m_ZoomY.SetWindowText(_T(""));
00145 }
00146
00147 UpdateData(FALSE);
00148 }
00149
00150 void CPnSPresetsDlg::OnBnClickedButton2()
00151 {
00152 m_pnspresets.Add(_T("New,0.5,0.5,1.0,1.0"));
00153 m_list.SetCurSel(m_list.AddString(_T("New")));
00154 OnLbnSelchangeList1();
00155 }
00156
00157 void CPnSPresetsDlg::OnUpdateButton2(CCmdUI* pCmdUI)
00158 {
00159 CString str;
00160 int len = m_list.GetCount();
00161 if(len > 0) m_list.GetText(len-1, str);
00162 pCmdUI->Enable(str != _T("New"));
00163 }
00164
00165 void CPnSPresetsDlg::OnBnClickedButton6()
00166 {
00167 int i = m_list.GetCurSel();
00168 m_list.DeleteString(i);
00169 m_pnspresets.RemoveAt(i);
00170 if(i == m_list.GetCount()) i--;
00171 m_list.SetCurSel(i);
00172 OnLbnSelchangeList1();
00173 }
00174
00175 void CPnSPresetsDlg::OnUpdateButton6(CCmdUI* pCmdUI)
00176 {
00177 pCmdUI->Enable(m_list.GetCurSel() >= 0);
00178 }
00179
00180 void CPnSPresetsDlg::OnBnClickedButton9()
00181 {
00182 int i = m_list.GetCurSel();
00183 CString str, str2;
00184 m_list.GetText(i, str);
00185 str2 = m_pnspresets.GetAt(i);
00186 m_list.DeleteString(i);
00187 m_pnspresets.RemoveAt(i);
00188 i--;
00189 m_list.InsertString(i, str);
00190 m_pnspresets.InsertAt(i, str2);
00191 m_list.SetCurSel(i);
00192 }
00193
00194 void CPnSPresetsDlg::OnUpdateButton9(CCmdUI* pCmdUI)
00195 {
00196 pCmdUI->Enable(m_list.GetCurSel() > 0 && m_list.GetCurSel() < m_list.GetCount());
00197 }
00198
00199 void CPnSPresetsDlg::OnBnClickedButton10()
00200 {
00201 int i = m_list.GetCurSel();
00202 CString str, str2;
00203 m_list.GetText(i, str);
00204 str2 = m_pnspresets.GetAt(i);
00205 m_list.DeleteString(i);
00206 m_pnspresets.RemoveAt(i);
00207 i++;
00208 m_list.InsertString(i, str);
00209 m_pnspresets.InsertAt(i, str2);
00210 m_list.SetCurSel(i);
00211 }
00212
00213 void CPnSPresetsDlg::OnUpdateButton10(CCmdUI* pCmdUI)
00214 {
00215 pCmdUI->Enable(m_list.GetCurSel() >= 0 && m_list.GetCurSel() < m_list.GetCount()-1);
00216 }
00217
00218 void CPnSPresetsDlg::OnBnClickedButton1()
00219 {
00220 int i = m_list.GetCurSel();
00221 UpdateData();
00222 if(m_label.Remove(',') > 0)
00223 UpdateData(FALSE);
00224 m_pnspresets[i] = ParamsToString(m_label, m_PosX, m_PosY, m_ZoomX, m_ZoomY);
00225 m_list.DeleteString(i);
00226 m_list.InsertString(i, m_label);
00227 m_list.SetCurSel(i);
00228 }
00229
00230 void CPnSPresetsDlg::OnUpdateButton1(CCmdUI* pCmdUI)
00231 {
00232 UpdateData();
00233 pCmdUI->Enable(m_list.GetCurSel() >= 0
00234 && !m_label.IsEmpty() && m_label.Find(',') < 0
00235 && m_PosX >= 0 && m_PosX <= 1
00236 && m_PosY >= 0 && m_PosY <= 1
00237 && m_ZoomX >= 0.2 && m_ZoomX <= 3.0
00238 && m_ZoomY >= 0.2 && m_ZoomY <= 3.0);
00239 }
00240
00241 void CPnSPresetsDlg::OnOK()
00242 {
00243 if(m_list.GetCurSel() >= 0)
00244 OnBnClickedButton1();
00245
00246 __super::OnOK();
00247 }