KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kistatusbar.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) 2023 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <wx/button.h>
26#include <wx/statusbr.h>
27#include <wx/gauge.h>
28#include <wx/stattext.h>
29#include <array>
30#include <widgets/kistatusbar.h>
32#include <pgm_base.h>
35#include <bitmaps.h>
36#include <wx/dcclient.h>
37
38#define FIELD_OFFSET_BGJOB_TEXT 0
39#define FIELD_OFFSET_BGJOB_GAUGE 1
40#define FIELD_OFFSET_BGJOB_CANCEL 2
41#define FIELD_OFFSET_NOTIFICATION_BUTTON 3
42
43
44KISTATUSBAR::KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ) :
45 wxStatusBar( parent, id ),
46 m_normalFieldsCount( aNumberFields )
47{
48#ifdef __WXOSX__
49 // we need +1 extra field on OSX to offset from the rounded corner on the right
50 // OSX doesn't use resize grippers like the other platforms and the statusbar field
51 // includes the rounded part
52 const int ExtraFields = 5;
53#else
54 const int ExtraFields = 4;
55#endif
56 SetFieldsCount( aNumberFields + ExtraFields );
57
58 int* widths = new int[aNumberFields + ExtraFields];
59
60 for( int i = 0; i < aNumberFields; i++ )
61 widths[i] = -1;
62
63 widths[aNumberFields + FIELD_OFFSET_BGJOB_TEXT] = -1; // background status text field
64 // (variable size)
65 widths[aNumberFields + FIELD_OFFSET_BGJOB_GAUGE] = 75; // background progress button
66 widths[aNumberFields + FIELD_OFFSET_BGJOB_CANCEL] = 20; // background stop button
67 widths[aNumberFields + FIELD_OFFSET_NOTIFICATION_BUTTON] = 20; // notifications button
68#ifdef __WXOSX__
69 // offset from the right edge
70 widths[aNumberFields + ExtraFields - 1] = 10;
71#endif
72
73 SetStatusWidths( aNumberFields + ExtraFields, widths );
74 delete[] widths;
75
76
77 int* styles = new int[aNumberFields + ExtraFields];
78
79 for( int i = 0; i < aNumberFields + ExtraFields; i++ )
80 styles[i] = wxSB_FLAT;
81
82 SetStatusStyles( aNumberFields + ExtraFields, styles );
83 delete[] styles;
84
85 m_backgroundTxt = new wxStaticText( this, wxID_ANY, wxT( "" ) );
86
87 m_backgroundProgressBar = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize,
88 wxGA_HORIZONTAL | wxGA_SMOOTH );
89
90 m_backgroundStopButton = new wxButton( this, wxID_ANY, "X", wxDefaultPosition, wxDefaultSize,
91 wxBU_EXACTFIT );
92
93 m_notificationsButton = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
94 wxDefaultSize, wxBU_EXACTFIT );
95
97 m_notificationsButton->SetBitmap( KiBitmapBundle( BITMAPS::notifications ) );
100
102
103 Bind( wxEVT_SIZE, &KISTATUSBAR::onSize, this );
105
107 Layout();
108}
109
110
112{
113 m_notificationsButton->Unbind( wxEVT_BUTTON, &KISTATUSBAR::onNotificationsIconClick, this );
114 Unbind( wxEVT_SIZE, &KISTATUSBAR::onSize, this );
116 this );
117}
118
119
120void KISTATUSBAR::onNotificationsIconClick( wxCommandEvent& aEvent )
121{
122 wxPoint pos = m_notificationsButton->GetScreenPosition();
123
124 wxRect r;
125 GetFieldRect( m_normalFieldsCount + 3, r );
126 pos.x += r.GetWidth();
127
128 Pgm().GetNotificationsManager().ShowList( this, pos );
129}
130
131
132void KISTATUSBAR::onBackgroundProgressClick( wxMouseEvent& aEvent )
133{
134 wxPoint pos = m_backgroundProgressBar->GetScreenPosition();
135
136 wxRect r;
137 GetFieldRect( m_normalFieldsCount + 1, r );
138 pos.x += r.GetWidth();
139
140 Pgm().GetBackgroundJobMonitor().ShowList( this, pos );
141}
142
143void KISTATUSBAR::onSize( wxSizeEvent& aEvent )
144{
145 wxRect r;
146 GetFieldRect( m_normalFieldsCount + FIELD_OFFSET_BGJOB_TEXT, r );
147 int x = r.GetLeft();
148 int y = r.GetTop();
149
150 m_backgroundTxt->SetPosition( { x, y } );
151
153 x = r.GetLeft();
154 y = r.GetTop();
155 int w = r.GetWidth();
156 int h = r.GetHeight();
157 constexpr int b = 5;
158
159 auto buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
160 m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
161 m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
162
163 m_backgroundProgressBar->SetPosition( { x, y } );
164 m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - b, h );
165
167 x = r.GetLeft();
168 y = r.GetTop();
169 h = r.GetHeight();
170 buttonSize = m_notificationsButton->GetEffectiveMinSize();
171 m_notificationsButton->SetPosition( { x, y } );
172 m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
173}
174
175
177{
179
180 if( aCancellable )
182 else
184}
185
186
188{
191}
192
193
195{
196 m_backgroundProgressBar->SetValue( aAmount );
197}
198
199
201{
202 m_backgroundProgressBar->SetRange( aAmount );
203}
204
205
206void KISTATUSBAR::SetBackgroundStatusText( const wxString& aTxt )
207{
208 m_backgroundTxt->SetLabel( aTxt );
209}
210
211
213{
214 wxString cnt = "";
215
216 if( aCount > 0 )
217 {
218 cnt = wxString::Format( "%d", aCount );
219 }
220
222
223 // force a repaint or it wont until it gets activity
224 Refresh();
225}
226
227#include <widgets/ui_common.h>
228void KISTATUSBAR::SetEllipsedTextField( const wxString& aText, int aFieldId )
229{
230 wxRect fieldRect;
231 int width = -1;
232 wxString etext = aText;
233
234 // Only GetFieldRect() returns the current size for variable size fields
235 // Other methods return -1 for the width of these fields.
236 if( GetFieldRect( aFieldId, fieldRect ) )
237 width = fieldRect.GetWidth();
238
239 if( width > 20 )
240 {
241 wxClientDC dc( this );
242
243 // Gives a margin to the text to be sure it is not clamped at its end
244 int margin = KIUI::GetTextSize( wxT( "XX" ), this ).x;
245 etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
246 }
247
248 SetStatusText( etext, aFieldId );
249}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the background job list.
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void SetBadgeText(const wxString &aText)
void SetBitmapCentered(bool aCentered=true)
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
void SetShowBadge(bool aShowBadge)
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
BITMAP_BUTTON * m_notificationsButton
Definition: kistatusbar.h:100
void SetBackgroundStatusText(const wxString &aTxt)
Set the status text that displays next to the progress bar.
void onBackgroundProgressClick(wxMouseEvent &aEvent)
void onSize(wxSizeEvent &aEvent)
int m_normalFieldsCount
Definition: kistatusbar.h:101
void SetBackgroundProgress(int aAmount)
Set the current progress of the progress bar.
wxGauge * m_backgroundProgressBar
Definition: kistatusbar.h:97
wxButton * m_backgroundStopButton
Definition: kistatusbar.h:98
void SetEllipsedTextField(const wxString &aText, int aFieldId)
Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size to the field size.
void HideBackgroundProgressBar()
Hide the background progress bar.
void onNotificationsIconClick(wxCommandEvent &aEvent)
void SetBackgroundProgressMax(int aAmount)
Set the max progress of the progress bar.
KISTATUSBAR(int aNumberFields, wxWindow *parent, wxWindowID id)
Definition: kistatusbar.cpp:44
wxStaticText * m_backgroundTxt
Definition: kistatusbar.h:99
void ShowBackgroundProgressBar(bool aCancellable=false)
Show the background progress bar.
void SetNotificationCount(int aCount)
Set the notification count on the notifications button.
void ShowList(wxWindow *aParent, wxPoint aPos)
Show the notification list.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition: pgm_base.h:129
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition: pgm_base.h:134
#define FIELD_OFFSET_BGJOB_TEXT
Definition: kistatusbar.cpp:38
#define FIELD_OFFSET_BGJOB_GAUGE
Definition: kistatusbar.cpp:39
#define FIELD_OFFSET_NOTIFICATION_BUTTON
Definition: kistatusbar.cpp:41
#define FIELD_OFFSET_BGJOB_CANCEL
Definition: kistatusbar.cpp:40
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:77
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.