2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // GoToDlg.cpp : implementation file
34 IMPLEMENT_DYNAMIC(CGoToDlg
, CDialog
)
35 CGoToDlg::CGoToDlg(int time
, float fps
, CWnd
* pParent
/*=NULL*/)
36 : CDialog(CGoToDlg::IDD
, pParent
)
44 CString str
= AfxGetApp()->GetProfileString(ResStr(IDS_R_SETTINGS
), _T("fps"), _T("0"));
45 if(_stscanf(str
, _T("%f"), &m_fps
) != 1) m_fps
= 0;
53 void CGoToDlg::DoDataExchange(CDataExchange
* pDX
)
55 CDialog::DoDataExchange(pDX
);
56 DDX_Text(pDX
, IDC_EDIT1
, m_timestr
);
57 DDX_Text(pDX
, IDC_EDIT2
, m_framestr
);
58 DDX_Control(pDX
, IDC_EDIT1
, m_timeedit
);
59 DDX_Control(pDX
, IDC_EDIT2
, m_frameedit
);
62 BOOL
CGoToDlg::OnInitDialog()
64 CDialog::OnInitDialog();
68 m_timestr
.Format(_T("%02d:%02d:%02d.%03d"),
69 (m_time
/(1000*60*60))%60, (m_time
/(1000*60))%60, (m_time
/1000)%60, m_time
%1000);
73 m_framestr
.Format(_T("%d, %.3f"), (int)(m_fps
*m_time
/1000), m_fps
);
78 switch(AfxGetApp()->GetProfileInt(ResStr(IDS_R_SETTINGS
), _T("gotoluf"), 0))
81 case 0: m_timeedit
.SetFocus(); m_timeedit
.SetSel(0, 0); break;
82 case 1: m_frameedit
.SetFocus(); m_frameedit
.SetSel(0, m_framestr
.Find(',')); break;
89 // return TRUE; // return TRUE unless you set the focus to a control
90 // EXCEPTION: OCX Property Pages should return FALSE
94 BEGIN_MESSAGE_MAP(CGoToDlg
, CDialog
)
95 ON_BN_CLICKED(IDC_OK1
, OnBnClickedOk1
)
96 ON_BN_CLICKED(IDC_OK2
, OnBnClickedOk2
)
100 // CGoToDlg message handlers
102 void CGoToDlg::OnBnClickedOk1()
107 hh
= mm
= ss
= ms
= 0;
111 REParseError status
= re
.Parse(_T("{\\z}"), FALSE
);
112 if(REPARSE_ERROR_OK
== status
)
114 CAtlREMatchContext
<> mc
;
115 const CAtlREMatchContext
<>::RECHAR
* s
= m_timestr
.GetBuffer();
116 const CAtlREMatchContext
<>::RECHAR
* e
= NULL
;
117 while(s
&& re
.Match(s
, &mc
, &e
))
119 const CAtlREMatchContext
<>::RECHAR
* szStart
= 0;
120 const CAtlREMatchContext
<>::RECHAR
* szEnd
= 0;
121 mc
.GetMatch(0, &szStart
, &szEnd
);
123 if(hh
!= 0 || hh
> 59 || mm
> 59 || ss
> 59)
125 AfxMessageBox(_T("Error parsing entered time!"));
132 ms
= _tcstol(szStart
, (TCHAR
**)&szStart
, 10);
137 m_time
= ((hh
*60+mm
)*60+ss
)*1000+ms
;
139 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS
), _T("gotoluf"), 0);
146 void CGoToDlg::OnBnClickedOk2()
155 REParseError status
= re
.Parse(_T("{\\z}[^0-9\\.]+{[0-9\\.]+}"), FALSE
);
156 if(REPARSE_ERROR_OK
== status
)
158 CAtlREMatchContext
<> mc
;
159 const CAtlREMatchContext
<>::RECHAR
* s
= m_framestr
.GetBuffer();
160 const CAtlREMatchContext
<>::RECHAR
* e
= NULL
;
161 if(re
.Match(s
, &mc
, &e
))
163 const CAtlREMatchContext
<>::RECHAR
* szStart
= 0;
164 const CAtlREMatchContext
<>::RECHAR
* szEnd
= 0;
166 mc
.GetMatch(0, &szStart
, &szEnd
);
167 frame
= _tcstol(szStart
, (TCHAR
**)&szStart
, 10);
169 mc
.GetMatch(1, &szStart
, &szEnd
);
170 if(_stscanf(szStart
, _T("%f"), &fps
) != 1) fps
= 0;
171 else AfxGetApp()->WriteProfileString(ResStr(IDS_R_SETTINGS
), _T("fps"), szStart
);
175 AfxMessageBox(_T("Error parsing entered text!"));
181 AfxMessageBox(_T("Error parsing entered frame-rate!"));
185 m_time
= (int)(1000.0*frame
/fps
) + 1;
187 AfxGetApp()->WriteProfileInt(ResStr(IDS_R_SETTINGS
), _T("gotoluf"), 1);
193 BOOL
CGoToDlg::PreTranslateMessage(MSG
* pMsg
)
195 if(pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== VK_RETURN
)
197 if(*GetFocus() == m_timeedit
) OnBnClickedOk1();
198 else if(*GetFocus() == m_frameedit
) OnBnClickedOk2();
203 return __super::PreTranslateMessage(pMsg
);