GoToDlg.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // GoToDlg.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "GoToDlg.h"
00028 
00029 #include <atlrx.h>
00030 
00031 
00032 // CGoToDlg dialog
00033 
00034 IMPLEMENT_DYNAMIC(CGoToDlg, CDialog)
00035 CGoToDlg::CGoToDlg(int time, float fps, CWnd* pParent /*=NULL*/)
00036         : CDialog(CGoToDlg::IDD, pParent)
00037         , m_timestr(_T(""))
00038         , m_framestr(_T(""))
00039         , m_time(time)
00040         , m_fps(fps)
00041 {
00042         if(m_fps == 0)
00043         {
00044                 CString str = AfxGetApp()->GetProfileString(ResStr(IDS_R_SETTINGS), _T("fps"), _T("0"));
00045                 if(_stscanf(str, _T("%f"), &m_fps) != 1) m_fps = 0;
00046         }
00047 }
00048 
00049 CGoToDlg::~CGoToDlg()
00050 {
00051 }
00052 
00053 void CGoToDlg::DoDataExchange(CDataExchange* pDX)
00054 {
00055         CDialog::DoDataExchange(pDX);
00056         DDX_Text(pDX, IDC_EDIT1, m_timestr);
00057         DDX_Text(pDX, IDC_EDIT4, m_framestr);
00058         DDX_Control(pDX, IDC_EDIT1, m_timeedit);
00059         DDX_Control(pDX, IDC_EDIT4, m_frameedit);
00060 }
00061 
00062 BOOL CGoToDlg::OnInitDialog()
00063 {
00064         CDialog::OnInitDialog();
00065 
00066         if(m_time >= 0)
00067         {
00068                 m_timestr.Format(_T("%02d:%02d:%02d.%03d"), 
00069                         (m_time/(1000*60*60))%60, (m_time/(1000*60))%60, (m_time/1000)%60, m_time%1000);
00070 
00071                 if(m_fps > 0)
00072                 {
00073                         m_framestr.Format(_T("%d, %.3f"), (int)(m_fps*m_time/1000), m_fps);
00074                 }
00075 
00076                 UpdateData(FALSE);
00077 
00078                 switch(AfxGetApp()->GetProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 0))
00079                 {
00080                 default:
00081                 case 0: m_timeedit.SetFocus(); m_timeedit.SetSel(0, 0); break;
00082                 case 1: m_frameedit.SetFocus(); m_frameedit.SetSel(0, m_framestr.Find(',')); break;
00083                 }
00084 
00085         }
00086 
00087         return FALSE;
00088 
00089 //      return TRUE;  // return TRUE unless you set the focus to a control
00090         // EXCEPTION: OCX Property Pages should return FALSE
00091 }
00092 
00093 
00094 BEGIN_MESSAGE_MAP(CGoToDlg, CDialog)
00095         ON_BN_CLICKED(IDOK, OnBnClickedOk)
00096         ON_BN_CLICKED(IDOK2, OnBnClickedOk2)
00097 END_MESSAGE_MAP()
00098 
00099 
00100 // CGoToDlg message handlers
00101 
00102 void CGoToDlg::OnBnClickedOk()
00103 {
00104         UpdateData();
00105 
00106         int hh, mm, ss, ms;
00107         hh = mm = ss = ms = 0;
00108 
00109         CAtlRegExp<> re;
00110 
00111         REParseError status = re.Parse(_T("{\\z}"), FALSE);
00112         if(REPARSE_ERROR_OK == status)
00113         {
00114                 CAtlREMatchContext<> mc;
00115                 const CAtlREMatchContext<>::RECHAR* s = m_timestr.GetBuffer();
00116                 const CAtlREMatchContext<>::RECHAR* e = NULL;
00117                 while(s && re.Match(s, &mc, &e))
00118                 {
00119                         const CAtlREMatchContext<>::RECHAR* szStart = 0;
00120                         const CAtlREMatchContext<>::RECHAR* szEnd = 0;
00121                         mc.GetMatch(0, &szStart, &szEnd);
00122 
00123                         if(hh != 0 || hh > 59 || mm > 59 || ss > 59)
00124                         {
00125                                 AfxMessageBox(_T("Error parsing entered time!"));
00126                                 return;
00127                         }
00128 
00129                         hh = mm;
00130                         mm = ss;
00131                         ss = ms;
00132                         ms = _tcstol(szStart, (TCHAR**)&szStart, 10);
00133 
00134                         s = e;
00135                 }
00136 
00137                 m_time = ((hh*60+mm)*60+ss)*1000+ms;
00138 
00139                 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 0);
00140 
00141                 OnOK();
00142         }
00143 }
00144 
00145 
00146 void CGoToDlg::OnBnClickedOk2()
00147 {
00148         UpdateData();
00149 
00150         int frame = 0;
00151         float fps = 0;
00152 
00153         CAtlRegExp<> re;
00154 
00155         REParseError status = re.Parse(_T("{\\z}[^0-9\\.]+{[0-9\\.]+}"), FALSE);
00156         if(REPARSE_ERROR_OK == status)
00157         {
00158                 CAtlREMatchContext<> mc;
00159                 const CAtlREMatchContext<>::RECHAR* s = m_framestr.GetBuffer();
00160                 const CAtlREMatchContext<>::RECHAR* e = NULL;
00161                 if(re.Match(s, &mc, &e))
00162                 {
00163                         const CAtlREMatchContext<>::RECHAR* szStart = 0;
00164                         const CAtlREMatchContext<>::RECHAR* szEnd = 0;
00165 
00166                         mc.GetMatch(0, &szStart, &szEnd);
00167                         frame = _tcstol(szStart, (TCHAR**)&szStart, 10);
00168 
00169                         mc.GetMatch(1, &szStart, &szEnd);
00170                         if(_stscanf(szStart, _T("%f"), &fps) != 1) fps = 0;
00171                         else AfxGetApp()->WriteProfileString(ResStr(IDS_R_SETTINGS), _T("fps"), szStart);
00172                 }
00173                 else
00174                 {
00175                         AfxMessageBox(_T("Error parsing entered text!"));
00176                         return;
00177                 }
00178 
00179                 if(fps == 0)
00180                 {
00181                         AfxMessageBox(_T("Error parsing entered frame-rate!"));
00182                         return;
00183                 }
00184 
00185                 m_time = (int)(1000.0*frame/fps) + 1;
00186 
00187                 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS), _T("gotoluf"), 1);
00188 
00189                 OnOK();
00190         }
00191 }
00192 
00193 BOOL CGoToDlg::PreTranslateMessage(MSG* pMsg)
00194 {
00195         if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
00196         {
00197                 if(*GetFocus() == m_timeedit) OnBnClickedOk();
00198                 else if(*GetFocus() == m_frameedit) OnBnClickedOk2();
00199 
00200                 return TRUE;
00201         }
00202 
00203         return CDialog::PreTranslateMessage(pMsg);
00204 }

Generated on Tue Dec 13 14:46:50 2005 for guliverkli by  doxygen 1.4.5