synced (Sys)ProgressDlg with TortoiseSVN
[TortoiseGit.git] / src / Utils / MiscUI / SysProgressDlg.h
blobb962112b8173c674c784c23949cc94e73ad946b6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
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 this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 /**
22 * \ingroup Utils
23 * A wrapper class for the IProgressDialog interface. Thats
24 * the dialog used by the shell/IE to show progress in e.g.
25 * copying, downloading, ...
27 * \remark you need to call AfxOleInit() before using this class, preferably in
28 * your app's InitInistance() method.
30 class CSysProgressDlg
32 public:
33 CSysProgressDlg();
34 ~CSysProgressDlg();
36 /**
37 * sets the title of the progress dialog box.
38 * \param szTitle pointer to a NULL-terminated string that contains the dialog box title
40 void SetTitle ( LPCTSTR szTitle );
41 /**
42 * sets the title of the progress dialog box to a string resource value.
44 void SetTitle ( UINT idTitle);
46 /**
47 * Displays a message.
48 * \param dwLine line number on which the text is to be displayed. There are three lines possible, two lines if SetCalculateTime() is set to true.
49 * \param szText NULL-terminated string that contains the line text.
50 * \param bCompactPath set to true if you want the text to be compacted (if it is a path) to fit on the line.
52 * \remark This call should be made *after* the dialog has been shown - this allows
53 * the system to measure the space available for the text, and do path compaction properly
55 void SetLine ( DWORD dwLine, LPCTSTR szText, bool bCompactPath = false );
57 #ifdef _MFC_VER
58 /**
59 * Wrappers around set line, to do a CString::Format type operation
60 * See SetLine for more details
62 * \remark These calls should be made *after* the dialog has been shown - this allows
63 * the system to measure the space available for the text, and do path compaction properly
65 void FormatPathLine ( DWORD dwLine, UINT idFormatText, ...);
66 void FormatPathLine ( DWORD dwLine, CString FormatText, ...);
67 void FormatNonPathLine ( DWORD dwLine, UINT idFormatText, ...);
68 #endif
69 /**
70 * Sets a message to be displayed if the user clicks the cancel button.
71 * \param szMessage pointer to a NULL-terminated string that contains the message.
72 * \remark Even though the user clicks Cancel, the application cannot immediately
73 * call Stop() to close the dialog box. The application
74 * must wait until the next time it calls HasUserCancelled() to
75 * discover that the user has canceled the operation. Since this delay might be
76 * significant, the progress dialog box provides the user with immediate feedback
77 * by clearing text lines 1 and 2 and displaying the cancel message on line 3.
78 * The message is intended to let the user know that the delay is normal and that
79 * the progress dialog box will be closed shortly. It is typically is set to
80 * something like "Please wait while ...".
82 void SetCancelMsg ( LPCTSTR szMessage );
83 #ifdef _MFC_VER
84 void SetCancelMsg ( UINT idMessage );
85 /**
86 * Specifies an AVI-clip that will run in the dialog box.
87 * \param uRsrcID AVI resource identifier. To create this value use the MAKEINTRESOURCE macro.
89 void SetAnimation ( UINT uRsrcID );
90 #endif
91 /**
92 * Specifies an AVI-clip that will run in the dialog box.
93 * \param hinst instance handle to the module from which the avi resource should be loaded.
94 * \param uRsrcID AVI resource identifier. To create this value use the MAKEINTRESOURCE macro.
96 void SetAnimation ( HINSTANCE hinst, UINT uRsrcID );
98 /**
99 * Specifies that the progress dialog should have a line indicating the time remaining to complete.
100 * \param bCalculate false to deactivate the time remaining line.
102 void SetTime ( bool bTime = true );
105 * Specifies if the progress bar should be shown or not.
107 void SetShowProgressBar ( bool bShow = true );
110 * Resets the progress dialog box timer to zero.
111 * \remark the timer is used to estimate the remaining time. It is started when your
112 * application calls ShowModal() or ShowModeless(). Unless your application will
113 * start immediately, it should call ResetTimer() just before starting the operation.
114 * This practice ensures that the time estimates will be as accurate as possible.
115 * This method should not be called after the first call to UpdateProgress().
117 void ResetTimer();
120 * Shows the progress dialog box modal.
122 #ifdef _MFC_VER
123 HRESULT ShowModal ( CWnd* pwndParent, BOOL immediately = true );
124 #endif
125 HRESULT ShowModal ( HWND hWndParent, BOOL immediately = true );
127 * Shows the progress dialog box modeless.
129 #ifdef _MFC_VER
130 HRESULT ShowModeless ( CWnd* pwndParent, BOOL immediately = true );
131 #endif
132 HRESULT ShowModeless ( HWND hWndParent, BOOL immediately = true );
135 * Stops the progress dialog box and removes it from the screen.
137 void Stop();
140 * Updates the progress dialog box with the current state of the operation.
141 * \param dwProgress Application-defined value that indicates what proportion of the operation has been completed at the time the method was called
142 * \param dwMax Application-defined value that specifies what value dwCompleted will have when the operation is complete
144 void SetProgress ( DWORD dwProgress, DWORD dwMax );
146 * Updates the progress dialog box with the current state of the operation.
147 * \param u64Progress Application-defined value that indicates what proportion of the operation has been completed at the time the method was called
148 * \param u64ProgressMax Application-defined value that specifies what value dwCompleted will have when the operation is complete
150 void SetProgress64 ( ULONGLONG u64Progress, ULONGLONG u64ProgressMax );
153 * Checks whether the user has canceled the operation.
155 bool HasUserCancelled();
158 * Checks whether this object was created successfully. If the return value is false then
159 * you MUST NOT use the current instance of this class.
161 bool IsValid() const { return m_pIDlg != 0; }
164 * Checks whether the window is shown.
166 bool IsVisible() const { return m_isVisible; }
169 * After a call to Stop() to hide the progress dialog,
170 * call EnsureValid() to recreate the dialog and fill in the
171 * data again.
173 bool EnsureValid();
175 private:
176 static LRESULT CSysProgressDlg::fnSubclass(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
178 protected:
179 ATL::CComPtr<IProgressDialog> m_pIDlg;
180 bool m_isVisible;
181 DWORD m_dwDlgFlags;
182 HWND m_hWndProgDlg;
183 HWND m_hWndParent;
184 WNDPROC m_OrigProc;