1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2006,2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "ProgressDlg.h"
\r
22 CProgressDlg::CProgressDlg() :
\r
24 m_bValid(false), //not valid by default
\r
26 m_dwDlgFlags(PROGDLG_NORMAL)
\r
31 CProgressDlg::~CProgressDlg()
\r
35 if (m_isVisible) //still visible, so stop first before destroying
\r
36 m_pIDlg->StopProgressDialog();
\r
42 bool CProgressDlg::EnsureValid()
\r
48 hr = CoCreateInstance (CLSID_ProgressDialog, NULL, CLSCTX_INPROC_SERVER,
\r
49 IID_IProgressDialog, (void**)&m_pIDlg);
\r
52 m_bValid = true; //instance successfully created
\r
56 void CProgressDlg::SetTitle(LPCTSTR szTitle)
\r
61 m_pIDlg->SetTitle(T2COLE(szTitle));
\r
64 void CProgressDlg::SetTitle ( UINT idTitle)
\r
66 SetTitle(CString(MAKEINTRESOURCE(idTitle)));
\r
69 void CProgressDlg::SetLine(DWORD dwLine, LPCTSTR szText, bool bCompactPath /* = false */)
\r
74 m_pIDlg->SetLine(dwLine, T2COLE(szText), bCompactPath, NULL);
\r
79 void CProgressDlg::SetCancelMsg ( UINT idMessage )
\r
81 SetCancelMsg(CString(MAKEINTRESOURCE(idMessage)));
\r
85 void CProgressDlg::SetCancelMsg(LPCTSTR szMessage)
\r
90 m_pIDlg->SetCancelMsg(T2COLE(szMessage), NULL);
\r
94 void CProgressDlg::SetAnimation(HINSTANCE hinst, UINT uRsrcID)
\r
98 m_pIDlg->SetAnimation(hinst, uRsrcID);
\r
102 void CProgressDlg::SetAnimation(UINT uRsrcID)
\r
106 m_pIDlg->SetAnimation(AfxGetResourceHandle(), uRsrcID);
\r
110 void CProgressDlg::SetTime(bool bTime /* = true */)
\r
112 m_dwDlgFlags &= ~(PROGDLG_NOTIME | PROGDLG_AUTOTIME);
\r
115 m_dwDlgFlags |= PROGDLG_AUTOTIME;
\r
117 m_dwDlgFlags |= PROGDLG_NOTIME;
\r
120 void CProgressDlg::SetShowProgressBar(bool bShow /* = true */)
\r
123 m_dwDlgFlags &= ~PROGDLG_NOPROGRESSBAR;
\r
125 m_dwDlgFlags |= PROGDLG_NOPROGRESSBAR;
\r
128 HRESULT CProgressDlg::ShowModal (CWnd* pwndParent)
\r
131 return ShowModal(pwndParent->GetSafeHwnd());
\r
134 HRESULT CProgressDlg::ShowModeless(CWnd* pwndParent)
\r
137 return ShowModeless(pwndParent->GetSafeHwnd());
\r
140 void CProgressDlg::FormatPathLine ( DWORD dwLine, UINT idFormatText, ...)
\r
143 va_start(args, idFormatText);
\r
146 sText.FormatV(CString(MAKEINTRESOURCE(idFormatText)), args);
\r
147 SetLine(dwLine, sText, true);
\r
152 void CProgressDlg::FormatNonPathLine(DWORD dwLine, UINT idFormatText, ...)
\r
155 va_start(args, idFormatText);
\r
158 sText.FormatV(CString(MAKEINTRESOURCE(idFormatText)), args);
\r
159 SetLine(dwLine, sText, false);
\r
165 HRESULT CProgressDlg::ShowModal (HWND hWndParent)
\r
172 hr = m_pIDlg->StartProgressDialog(hWndParent,
\r
174 m_dwDlgFlags | PROGDLG_MODAL,
\r
179 m_isVisible = true;
\r
186 HRESULT CProgressDlg::ShowModeless(HWND hWndParent)
\r
189 HRESULT hr = E_FAIL;
\r
193 hr = m_pIDlg->StartProgressDialog(hWndParent, NULL, m_dwDlgFlags, NULL);
\r
197 m_isVisible = true;
\r
199 // The progress window can be remarkably slow to display, particularly
\r
200 // if its parent is blocked.
\r
201 // This process finds the hwnd for the progress window and gives it a kick...
\r
202 IOleWindow *pOleWindow;
\r
203 HRESULT hr=m_pIDlg->QueryInterface(IID_IOleWindow,(LPVOID *)&pOleWindow);
\r
208 hr=pOleWindow->GetWindow(&hDlgWnd);
\r
211 ShowWindow(hDlgWnd, SW_NORMAL);
\r
213 pOleWindow->Release();
\r
220 void CProgressDlg::SetProgress(DWORD dwProgress, DWORD dwMax)
\r
224 m_pIDlg->SetProgress(dwProgress, dwMax);
\r
229 void CProgressDlg::SetProgress64(ULONGLONG u64Progress, ULONGLONG u64ProgressMax)
\r
233 m_pIDlg->SetProgress64(u64Progress, u64ProgressMax);
\r
238 bool CProgressDlg::HasUserCancelled()
\r
242 return (0 != m_pIDlg->HasUserCancelled());
\r
247 void CProgressDlg::Stop()
\r
249 if ((m_isVisible)&&(m_bValid))
\r
251 m_pIDlg->StopProgressDialog();
\r
252 //Sometimes the progress dialog sticks around after stopping it,
\r
253 //until the mouse pointer is moved over it or some other triggers.
\r
254 //This process finds the hwnd of the progress dialog and hides it
\r
256 IOleWindow *pOleWindow;
\r
257 HRESULT hr=m_pIDlg->QueryInterface(IID_IOleWindow,(LPVOID *)&pOleWindow);
\r
262 hr=pOleWindow->GetWindow(&hDlgWnd);
\r
265 ShowWindow(hDlgWnd, SW_HIDE);
\r
267 pOleWindow->Release();
\r
269 m_isVisible = false;
\r
270 m_pIDlg->Release();
\r
275 void CProgressDlg::ResetTimer()
\r
279 m_pIDlg->Timer(PDTIMER_RESET, NULL);
\r