aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp')
-rw-r--r--Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp b/Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp
new file mode 100644
index 00000000..7fc12ce3
--- /dev/null
+++ b/Src/external_dependencies/openmpt-trunk/mptrack/ProgressDialog.cpp
@@ -0,0 +1,120 @@
+/*
+ * ProgressDialog.cpp
+ * ------------------
+ * Purpose: An abortable, progress-indicating dialog, e.g. for showing conversion progress.
+ * Notes : (currently none)
+ * Authors: OpenMPT Devs
+ * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
+ */
+
+
+#include "stdafx.h"
+#include "resource.h"
+#include "ProgressDialog.h"
+#include "Mptrack.h"
+
+OPENMPT_NAMESPACE_BEGIN
+
+BEGIN_MESSAGE_MAP(CProgressDialog, CDialog)
+ ON_COMMAND(IDC_BUTTON1, &CProgressDialog::Run)
+END_MESSAGE_MAP()
+
+CProgressDialog::CProgressDialog(CWnd *parent, UINT resourceID)
+ : CDialog{resourceID <= 0 ? IDD_PROGRESS : resourceID, parent}
+ , m_customDialog{resourceID > 0}
+{ }
+
+CProgressDialog::~CProgressDialog()
+{
+ if(m_taskBarList)
+ {
+ m_taskBarList->SetProgressState(*theApp.m_pMainWnd, TBPF_NOPROGRESS);
+ m_taskBarList->Release();
+ }
+
+ if(IsWindow(m_hWnd))
+ {
+ // This should only happen if this dialog gets destroyed as part of stack unwinding
+ EndDialog(IDCANCEL);
+ DestroyWindow();
+ }
+}
+
+BOOL CProgressDialog::OnInitDialog()
+{
+ CDialog::OnInitDialog();
+ if(!m_customDialog)
+ PostMessage(WM_COMMAND, IDC_BUTTON1);
+ return TRUE;
+}
+
+
+void CProgressDialog::SetTitle(const TCHAR *title)
+{
+ SetWindowText(title);
+}
+
+
+
+void CProgressDialog::SetAbortText(const TCHAR *abort)
+{
+ SetDlgItemText(IDCANCEL, abort);
+}
+
+
+void CProgressDialog::SetText(const TCHAR *text)
+{
+ SetDlgItemText(IDC_TEXT1, text);
+}
+
+
+void CProgressDialog::SetRange(uint64 min, uint64 max)
+{
+ MPT_ASSERT(min <= max);
+ m_min = min;
+ m_max = max;
+ m_shift = 0;
+ // Is the range too big for 32-bit values?
+ while(max > int32_max)
+ {
+ m_shift++;
+ max >>= 1;
+ }
+ ::SendMessage(::GetDlgItem(m_hWnd, IDC_PROGRESS1), PBM_SETRANGE32, static_cast<uint32>(m_min >> m_shift), static_cast<uint32>(m_max >> m_shift));
+}
+
+
+void CProgressDialog::SetProgress(uint64 progress)
+{
+ ::SendMessage(::GetDlgItem(m_hWnd, IDC_PROGRESS1), PBM_SETPOS, static_cast<uint32>(progress >> m_shift), 0);
+ if(m_taskBarList != nullptr)
+ {
+ m_taskBarList->SetProgressValue(*theApp.m_pMainWnd, progress - m_min, m_max - m_min);
+ }
+}
+
+
+void CProgressDialog::EnableTaskbarProgress()
+{
+ if(CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_ITaskbarList3, (void**)&m_taskBarList) != S_OK)
+ {
+ return;
+ }
+ if(m_taskBarList != nullptr)
+ {
+ m_taskBarList->SetProgressState(*theApp.m_pMainWnd, TBPF_NORMAL);
+ }
+}
+
+
+void CProgressDialog::ProcessMessages()
+{
+ MSG msg;
+ while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+ }
+}
+
+OPENMPT_NAMESPACE_END