IProgressDialog::SetAnimation is not supported any more on Windows >= Vista
[TortoiseGit.git] / src / Utils / MiscUI / SysProgressDlg.h
blob5296b64dc266a7406629b4d81a9e7361c0befe0c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2011, 2015 - 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 nullptr-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 nullptr-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 void FormatNonPathLine(DWORD dwLine, CString FormatText, ...);
69 #endif
70 /**
71 * Sets a message to be displayed if the user clicks the cancel button.
72 * \param szMessage pointer to a nullptr-terminated string that contains the message.
73 * \remark Even though the user clicks Cancel, the application cannot immediately
74 * call Stop() to close the dialog box. The application
75 * must wait until the next time it calls HasUserCancelled() to
76 * discover that the user has canceled the operation. Since this delay might be
77 * significant, the progress dialog box provides the user with immediate feedback
78 * by clearing text lines 1 and 2 and displaying the cancel message on line 3.
79 * The message is intended to let the user know that the delay is normal and that
80 * the progress dialog box will be closed shortly. It is typically is set to
81 * something like "Please wait while ...".
83 void SetCancelMsg ( LPCTSTR szMessage );
84 #ifdef _MFC_VER
85 void SetCancelMsg ( UINT idMessage );
86 #endif
88 /**
89 * Specifies that the progress dialog should have a line indicating the time remaining to complete.
90 * \param bCalculate false to deactivate the time remaining line.
92 void SetTime ( bool bTime = true );
94 /**
95 * Specifies if the progress bar should be shown or not.
97 void SetShowProgressBar ( bool bShow = true );
99 /**
100 * Resets the progress dialog box timer to zero.
101 * \remark the timer is used to estimate the remaining time. It is started when your
102 * application calls ShowModal() or ShowModeless(). Unless your application will
103 * start immediately, it should call ResetTimer() just before starting the operation.
104 * This practice ensures that the time estimates will be as accurate as possible.
105 * This method should not be called after the first call to UpdateProgress().
107 void ResetTimer();
110 * Shows the progress dialog box modal.
112 #ifdef _MFC_VER
113 HRESULT ShowModal ( CWnd* pwndParent, BOOL immediately = true );
114 #endif
115 HRESULT ShowModal ( HWND hWndParent, BOOL immediately = true );
117 * Shows the progress dialog box modeless.
119 #ifdef _MFC_VER
120 HRESULT ShowModeless ( CWnd* pwndParent, BOOL immediately = true );
121 #endif
122 HRESULT ShowModeless ( HWND hWndParent, BOOL immediately = true );
125 * Stops the progress dialog box and removes it from the screen.
127 void Stop();
130 * Updates the progress dialog box with the current state of the operation.
131 * \param dwProgress Application-defined value that indicates what proportion of the operation has been completed at the time the method was called
132 * \param dwMax Application-defined value that specifies what value dwCompleted will have when the operation is complete
134 void SetProgress ( DWORD dwProgress, DWORD dwMax );
136 * Updates the progress dialog box with the current state of the operation.
137 * \param u64Progress Application-defined value that indicates what proportion of the operation has been completed at the time the method was called
138 * \param u64ProgressMax Application-defined value that specifies what value dwCompleted will have when the operation is complete
140 void SetProgress64 ( ULONGLONG u64Progress, ULONGLONG u64ProgressMax );
143 * Checks whether the user has canceled the operation.
145 bool HasUserCancelled();
148 * Checks whether this object was created successfully. If the return value is false then
149 * you MUST NOT use the current instance of this class.
151 bool IsValid() const { return m_pIDlg != nullptr; }
154 * Checks whether the window is shown.
156 bool IsVisible() const { return m_isVisible; }
159 * After a call to Stop() to hide the progress dialog,
160 * call EnsureValid() to recreate the dialog and fill in the
161 * data again.
163 bool EnsureValid();
165 protected:
166 ATL::CComPtr<IProgressDialog> m_pIDlg;
167 bool m_isVisible;
168 DWORD m_dwDlgFlags;
169 HWND m_hWndProgDlg;
170 HWND m_hWndParent;
171 HWND m_hWndFocus;