KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_progress_reporters.cpp
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#include <thread>
26
27
28WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle,
29 int aNumPhases, int aCanAbort,
30 bool aReserveSpaceForMessage ) :
31 PROGRESS_REPORTER_BASE( aNumPhases ),
33 ( aReserveSpaceForMessage ? wxString( ' ', 80 ) : wxString( wxT( "" ) ) ),
34 1, aParent,
35 // wxPD_APP_MODAL | // Don't use; messes up OSX when called from
36 // quasi-modal dialog
37 wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin
38 // up another event loop on completion which
39 // causes all sorts of grief
40 aCanAbort | wxPD_ELAPSED_TIME ),
41 m_appProgressIndicator( aParent ),
43{
44 // wxAppProgressIndicator doesn't like value > max, ever. However there are some risks
45 // with multithreaded setting of those values making a mess
46 // the cop out is just to set the progress to "indeterminate"
48}
49
50
54
55
57{
58 int cur = CurrentProgress();
59
60 if( cur < 0 || cur > 1000 )
61 cur = 0;
62
63 SetRange( 1000 );
64
65 wxString message;
66
67 {
68 std::lock_guard<std::mutex> guard( m_mutex );
69 message = m_rptMessage;
70 }
71
72 // Perhaps the window size is too small if the new message to display is bigger
73 // than the previous message. in this case, resize the WX_PROGRESS_REPORTER window
74 // GetTextExtent has probably bugs in wxWidgets < 3.1.6, so calling it only when
75 // the message has changed is mandatory
77 {
78 int newWidth = GetTextExtent( m_rptMessage ).x;
79
80 if( newWidth > m_messageWidth )
81 {
82 m_messageWidth = newWidth;
83 Fit();
84 }
85
86 m_messageChanged = false;
87 }
88
89 // Allowing interaction with other windows has unintended consequences
90 wxWindowDisabler ed( this );
91
92 // Returns false when cancelled (if it's a cancellable dialog)
93 bool diag = WX_PROGRESS_REPORTER_BASE::Update( cur, message );
94
96
97 return diag;
98}
99
100
101GAUGE_PROGRESS_REPORTER::GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases ) :
102 PROGRESS_REPORTER_BASE( aNumPhases ),
103 wxGauge( aParent, wxID_ANY, 1000, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL,
104 wxDefaultValidator, wxGaugeNameStr )
105{
106}
107
108
110{
111 int cur = CurrentProgress();
112
113 if( cur < 0 || cur > 1000 )
114 cur = 0;
115
116 wxGauge::SetValue( cur );
117
118 DrainPendingEvents( wxEVT_CATEGORY_UI );
119
120 return true; // No cancel button on a wxGauge
121}
GAUGE_PROGRESS_REPORTER(wxWindow *aParent, int aNumPhases)
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.
void DrainPendingEvents(long aCategories=wxEVT_CATEGORY_TIMER)
Drain pending events of the given categories from the active event loop.
#define WX_PROGRESS_REPORTER_BASE