00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "DlgSounds.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CDlgSounds::CDlgSounds(CWnd* pParent )
00017 : CDialog(CDlgSounds::IDD, pParent)
00018 {
00019
00020
00021
00022 }
00023
00024 void CDlgSounds::DoDataExchange(CDataExchange* pDX)
00025 {
00026 CDialog::DoDataExchange(pDX);
00027
00028 DDX_Control(pDX, IDC_SOUNDS, m_wndSnds);
00029
00030 }
00031
00032 BEGIN_MESSAGE_MAP(CDlgSounds, CDialog)
00033
00034 ON_WM_CONTEXTMENU()
00035 ON_WM_HELPINFO()
00036 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00037 ON_NOTIFY(NM_CLICK, IDC_SOUNDS, OnClickSounds)
00038 ON_NOTIFY(NM_DBLCLK, IDC_SOUNDS, OnDblclkSounds)
00039 ON_BN_CLICKED(IDC_SETSOUND, OnSetsound)
00040 ON_BN_CLICKED(IDC_REMOVE, OnRemove)
00041 ON_BN_CLICKED(IDC_TEST, OnTest)
00042
00043 END_MESSAGE_MAP()
00044
00045 BOOL CDlgSounds::OnInitDialog()
00046 {
00047 CDialog::OnInitDialog();
00048
00049 CRect rc;
00050 m_wndSnds.GetClientRect (&rc);
00051
00052 m_wndSnds.InsertColumn (0, LS (L_EVENT), LVCFMT_LEFT, rc.right / 2);
00053 m_wndSnds.InsertColumn (1, LS (L_SOUND), LVCFMT_LEFT, rc.right / 2 - 1);
00054
00055 m_wndSnds.InsertItem (0, LS (L_DOWNLOADADDED));
00056 m_wndSnds.SetItemText (0, 1, SndFile (_App.Snd_DownloadAdded ()));
00057
00058 m_wndSnds.InsertItem (1, LS (L_DOWNLOADCOMPLETE));
00059 m_wndSnds.SetItemText (1, 1, SndFile (_App.Snd_DownloadComplete ()));
00060
00061 m_wndSnds.InsertItem (2, LS (L_DOWNLOADFAILED));
00062 m_wndSnds.SetItemText (2, 1, SndFile (_App.Snd_DownloadFailed ()));
00063
00064 m_wndSnds.InsertItem (3, LS (L_DIALINGSUCCEDED));
00065 m_wndSnds.SetItemText (3, 1, SndFile (_App.Snd_DialingOK ()));
00066
00067 m_wndSnds.InsertItem (4, LS (L_DIALINGFAILED));
00068 m_wndSnds.SetItemText (4, 1, SndFile (_App.Snd_DialingFailed ()));
00069
00070 m_wndSnds.InsertItem (5, LS (L_NOACTIVEDOWNLOADS));
00071 m_wndSnds.SetItemText (5, 1, SndFile (_App.Snd_NoActiveDownloads ()));
00072
00073 ApplyLanguage ();
00074 UpdateEnabled ();
00075
00076 return TRUE;
00077 }
00078
00079 void CDlgSounds::OnContextMenu(CWnd* , CPoint point)
00080 {
00081 PrepareCHMgr (point);
00082 _CHMgr.ShowMenu ();
00083 }
00084
00085 BOOL CDlgSounds::OnHelpInfo(HELPINFO* pHelpInfo)
00086 {
00087 RECT rc;
00088
00089 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00090 if (pItem == NULL)
00091 return TRUE;
00092
00093 pItem->GetWindowRect (&rc);
00094 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00095 {
00096 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00097 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00098 }
00099
00100 PrepareCHMgr (pHelpInfo->MousePos);
00101
00102 _CHMgr.OnWT ();
00103 return TRUE;
00104 }
00105
00106 void CDlgSounds::OnWhatisthis()
00107 {
00108 _CHMgr.OnWT ();
00109 }
00110
00111 void CDlgSounds::ApplyLanguage()
00112 {
00113 fsDlgLngInfo lnginfo [] = {
00114 fsDlgLngInfo (IDC_SETSOUND, L_SETSOUND),
00115 fsDlgLngInfo (IDC_REMOVE, L_REMOVE),
00116 fsDlgLngInfo (IDC_TEST, L_TEST),
00117 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00118 };
00119
00120 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_CUSTOMIZESOUNDS);
00121 }
00122
00123 void CDlgSounds::PrepareCHMgr(CPoint point)
00124 {
00125 LPCSTR pszSoundsHere = LS (L_SNDEVENTSHERE);
00126
00127 CPoint pt = point;
00128 m_wndSnds.ScreenToClient (&pt);
00129 switch (m_wndSnds.HitTest (pt))
00130 {
00131 case 0:
00132 pszSoundsHere = LS (L_DLADDEDHERE);
00133 break;
00134
00135 case 1:
00136 pszSoundsHere = LS (L_DLCOMPLETEDHERE);
00137 break;
00138
00139 case 2:
00140 pszSoundsHere = LS (L_DLFAILEDHERE);
00141 break;
00142
00143 case 3:
00144 pszSoundsHere = LS (L_DIALOKHERE);
00145 break;
00146
00147 case 4:
00148 pszSoundsHere = LS (L_DIALFAILEDHERE);
00149 break;
00150
00151 case 5:
00152 pszSoundsHere = LS (L_NOACTIVEDOWNLOADSSNDHERE);
00153 break;
00154 }
00155
00156 fsCtrlContextHelp aCH1 [] = {
00157 fsCtrlContextHelp (IDC_SOUNDS, pszSoundsHere),
00158 fsCtrlContextHelp (IDC_SETSOUND, LS (L_SETSOUNDHERE)),
00159 fsCtrlContextHelp (IDC_REMOVE, LS (L_REMOVESOUNDHERE)),
00160 fsCtrlContextHelp (IDC_TEST, LS (L_TESTSOUNDHERE)),
00161 fsCtrlContextHelp (IDCANCEL, LS (L_DONTACCEPTCHANGES)),
00162 fsCtrlContextHelp (IDOK, LS (L_ACCEPTCHANGES)),
00163 };
00164
00165 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00166 CopyMemory (aCH, aCH1, sizeof (aCH));
00167
00168 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00169 }
00170
00171 CString CDlgSounds::SndFile(CString strSndFile)
00172 {
00173 if (strSndFile == "")
00174 strSndFile = LS (L_NOSOUND);
00175 return strSndFile;
00176 }
00177
00178 void CDlgSounds::UpdateEnabled()
00179 {
00180 int cSel = 0;
00181 BOOL bNoSound = TRUE;
00182
00183 cSel = m_wndSnds.GetSelectedCount ();
00184
00185 if (cSel)
00186 {
00187 POSITION pos = m_wndSnds.GetFirstSelectedItemPosition ();
00188 while (pos)
00189 {
00190 int i = m_wndSnds.GetNextSelectedItem (pos);
00191 CString str = m_wndSnds.GetItemText (i, 1);
00192 if (str != LS (L_NOSOUND))
00193 bNoSound = FALSE;
00194 }
00195 }
00196
00197 GetDlgItem (IDC_SETSOUND)->EnableWindow (cSel == 1);
00198 GetDlgItem (IDC_REMOVE)->EnableWindow (cSel && bNoSound == FALSE);
00199 GetDlgItem (IDC_TEST)->EnableWindow (cSel == 1 && bNoSound == FALSE);
00200 }
00201
00202 void CDlgSounds::OnClickSounds(NMHDR* , LRESULT* pResult)
00203 {
00204 UpdateEnabled ();
00205 *pResult = 0;
00206 }
00207
00208 void CDlgSounds::OnDblclkSounds(NMHDR* , LRESULT* pResult)
00209 {
00210 if (m_wndSnds.GetSelectedCount () == 0)
00211 return;
00212
00213 OnSetsound ();
00214
00215 *pResult = 0;
00216 }
00217
00218 void CDlgSounds::OnSetsound()
00219 {
00220 LOG ("setsnd: building filter" << nl);
00221
00222 CString strFilter;
00223 strFilter.Format ("%s (*.wav)|*.wav||", LS (L_SOUNDFILES));
00224
00225 LOG ("setsnd: getting snd file" << nl);
00226
00227 CString strFile = GetSndFile (GetCurSelSnd ());
00228
00229 LOG ("setsnd: building dlg" << nl);
00230
00231 CFileDialog dlg (TRUE, "wav", strFile, OFN_HIDEREADONLY|OFN_NOCHANGEDIR, strFilter, this);
00232
00233 LOG ("setsnd: do modal" << nl);
00234
00235 if (_DlgMgr.DoModal (&dlg) == IDCANCEL)
00236 {
00237 LOG ("setsnd: domodal canceled" << nl);
00238 return;
00239 }
00240
00241 LOG ("setsnd: domodal: ok." << nl);
00242
00243 m_wndSnds.SetItemText (GetCurSelSnd (), 1, dlg.GetPathName ());
00244
00245 LOG ("setsnd: updating" << nl);
00246 UpdateEnabled ();
00247 LOG ("setsnd: exit" << nl);
00248 }
00249
00250 void CDlgSounds::OnRemove()
00251 {
00252 POSITION pos = m_wndSnds.GetFirstSelectedItemPosition ();
00253 while (pos)
00254 {
00255 int i = m_wndSnds.GetNextSelectedItem (pos);
00256 m_wndSnds.SetItemText (i, 1, LS (L_NOSOUND));
00257 }
00258
00259 UpdateEnabled ();
00260 }
00261
00262 void CDlgSounds::OnTest()
00263 {
00264 _Snds.PlaySnd (GetSndFile (GetCurSelSnd ()));
00265 }
00266
00267 void CDlgSounds::OnOK()
00268 {
00269 _App.Snd_DownloadAdded (GetSndFile (0));
00270 _App.Snd_DownloadComplete (GetSndFile (1));
00271 _App.Snd_DownloadFailed (GetSndFile (2));
00272 _App.Snd_DialingOK (GetSndFile (3));
00273 _App.Snd_DialingFailed (GetSndFile (4));
00274 _App.Snd_NoActiveDownloads (GetSndFile (5));
00275
00276 _Snds.ReadSettings ();
00277
00278 CDialog::OnOK();
00279 }
00280
00281 CString CDlgSounds::GetSndFile(int iItem)
00282 {
00283 if (iItem == -1)
00284 return "";
00285
00286 CString str = m_wndSnds.GetItemText (iItem, 1);
00287 if (str == LS (L_NOSOUND))
00288 str = "";
00289
00290 return str;
00291 }
00292
00293 int CDlgSounds::GetCurSelSnd()
00294 {
00295 POSITION pos = m_wndSnds.GetFirstSelectedItemPosition ();
00296 if (pos == NULL)
00297 return -1;
00298
00299 return m_wndSnds.GetNextSelectedItem (pos);
00300 }