KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_progress_reporters.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef WX_PROGRESS_REPORTERS_H
24#define WX_PROGRESS_REPORTERS_H
25
26#include <wx/progdlg.h>
27#include <wx/gauge.h>
28#include <wx/appprogress.h>
29
30#include <core/throttle.h>
32
33#define PR_NO_ABORT 0
34#define PR_CAN_ABORT wxPD_CAN_ABORT
35
36
37#if defined( _WIN32 ) && wxCHECK_VERSION( 3, 3, 0 )
38// In order to get a dark mode compatible progress dialog on Windows with wx 3.3
39#define WX_PROGRESS_REPORTER_BASE wxGenericProgressDialog
40#else
41#define WX_PROGRESS_REPORTER_BASE wxProgressDialog
42#endif
43
51{
52public:
68 WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases, int aCanAbort,
69 bool aReserveSpaceForMessage = true );
71
75 void SetTitle( const wxString& aTitle ) override
76 {
77 WX_PROGRESS_REPORTER_BASE::SetTitle( aTitle );
78 }
79
81 static bool shouldRefresh( int aProgress, int aMaxProgress, int aPhase, int aNumPhases,
82 THROTTLE& aThrottle )
83 {
84 bool finalTick = aMaxProgress > 0 && aProgress >= aMaxProgress && aPhase + 1 >= aNumPhases;
85
86 return finalTick || aThrottle.Ready();
87 }
88
89private:
90 bool updateUI() override;
91
92private:
93 wxAppProgressIndicator m_appProgressIndicator;
95
96 // Rate-limit expensive dialog repaint and event draining.
98 std::atomic_bool m_lastUpdateResult;
99};
100
101
103{
104public:
112 GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases );
113
114private:
115 bool updateUI() override;
116};
117
118#endif
GAUGE_PROGRESS_REPORTER(wxWindow *aParent, int aNumPhases)
Rate-limiter that fires at most once per interval.
Definition throttle.h:31
bool Ready()
Definition throttle.h:44
std::atomic_bool m_lastUpdateResult
void SetTitle(const wxString &aTitle) override
Change the title displayed on the window caption.
wxAppProgressIndicator m_appProgressIndicator
WX_PROGRESS_REPORTER(wxWindow *aParent, const wxString &aTitle, int aNumPhases, int aCanAbort, bool aReserveSpaceForMessage=true)
The PROGRESS_REPORTER will stay on top of aParent.
static bool shouldRefresh(int aProgress, int aMaxProgress, int aPhase, int aNumPhases, THROTTLE &aThrottle)
#define WX_PROGRESS_REPORTER_BASE