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 (C) 2023 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 doesnt 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 for( int i = 0; i < aNumberFields + ExtraFields; i++ )
79 styles[i] = wxSB_FLAT;
80
81 SetStatusStyles( aNumberFields + ExtraFields, styles );
82 delete[] styles;
83
84 m_backgroundTxt = new wxStaticText( this, wxID_ANY, wxT( "" ) );
85
86 m_backgroundProgressBar = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize,
87 wxGA_HORIZONTAL | wxGA_SMOOTH );
88
89 m_backgroundStopButton = new wxButton( this, wxID_ANY, "X", wxDefaultPosition, wxDefaultSize,
90 wxBU_EXACTFIT );
91
92 m_notificationsButton = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
93 wxDefaultSize, wxBU_EXACTFIT );
94
96 m_notificationsButton->SetBitmap( KiBitmapBundle( BITMAPS::notifications ) );
99
101
102 Bind( wxEVT_SIZE, &KISTATUSBAR::onSize, this );
104
106 Layout();
107}
108
109
111{
112 m_notificationsButton->Unbind( wxEVT_BUTTON, &KISTATUSBAR::onNotificationsIconClick, this );
113 Unbind( wxEVT_SIZE, &KISTATUSBAR::onSize, this );
115 this );
116}
117
118
119void KISTATUSBAR::onNotificationsIconClick( wxCommandEvent& aEvent )
120{
121 wxPoint pos = m_notificationsButton->GetScreenPosition();
122
123 wxRect r;
124 GetFieldRect( m_normalFieldsCount + 3, r );
125 pos.x += r.GetWidth();
126
127 Pgm().GetNotificationsManager().ShowList( this, pos );
128}
129
130
131void KISTATUSBAR::onBackgroundProgressClick( wxMouseEvent& aEvent )
132{
133 wxPoint pos = m_backgroundProgressBar->GetScreenPosition();
134
135 wxRect r;
136 GetFieldRect( m_normalFieldsCount + 1, r );
137 pos.x += r.GetWidth();
138
139 Pgm().GetBackgroundJobMonitor().ShowList( this, pos );
140}
141
142void KISTATUSBAR::onSize( wxSizeEvent& aEvent )
143{
144 wxRect r;
145 GetFieldRect( m_normalFieldsCount + FIELD_OFFSET_BGJOB_TEXT, r );
146 int x = r.GetLeft();
147 int y = r.GetTop();
148
149 m_backgroundTxt->SetPosition( { x, y } );
150
152 x = r.GetLeft();
153 y = r.GetTop();
154 int w = r.GetWidth();
155 int h = r.GetHeight();
156 constexpr int b = 5;
157
158 auto buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
159 m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
160 m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
161
162 m_backgroundProgressBar->SetPosition( { x, y } );
163 m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - b, h );
164
166 x = r.GetLeft();
167 y = r.GetTop();
168 h = r.GetHeight();
169 buttonSize = m_notificationsButton->GetEffectiveMinSize();
170 m_notificationsButton->SetPosition( { x, y } );
171 m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
172}
173
174
176{
178
179 if( aCancellable )
181 else
183}
184
185
187{
190}
191
192
194{
195 m_backgroundProgressBar->SetValue( aAmount );
196}
197
198
200{
201 m_backgroundProgressBar->SetRange( aAmount );
202}
203
204
205void KISTATUSBAR::SetBackgroundStatusText( const wxString& aTxt )
206{
207 m_backgroundTxt->SetLabel( aTxt );
208}
209
210
212{
213 wxString cnt = "";
214 if( aCount > 0 )
215 {
216 cnt = wxString::Format( "%d", aCount );
217 }
218
220
221 // force a repaint or it wont until it gets activity
222 Refresh();
223}
224
225#include <widgets/ui_common.h>
226void KISTATUSBAR::SetEllipsedTextField( const wxString& aText, int aFieldId )
227{
228 wxRect fieldRect;
229 int width = -1;
230 wxString etext = aText;
231
232 // Only GetFieldRect() returns the current size for variable size fields
233 // Other methods return -1 for the width of these fields.
234 if( GetFieldRect( aFieldId, fieldRect ) )
235 width = fieldRect.GetWidth();
236
237 if( width > 20 )
238 {
239 wxClientDC dc( this );
240 // Gives a margin to the text to be sure it is not clamped at its end
241 int margin = KIUI::GetTextSize( wxT( "XX" ), this ).x;
242 etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
243 }
244
245 SetStatusText( etext, aFieldId );
246}
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:98
void SetBackgroundStatusText(const wxString &aTxt)
Sets the status text that displays next to the progress bar.
void onBackgroundProgressClick(wxMouseEvent &aEvent)
void onSize(wxSizeEvent &aEvent)
int m_normalFieldsCount
Definition: kistatusbar.h:99
void SetBackgroundProgress(int aAmount)
Sets the current progress of the progress bar.
wxGauge * m_backgroundProgressBar
Definition: kistatusbar.h:95
wxButton * m_backgroundStopButton
Definition: kistatusbar.h:96
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 (un...
void HideBackgroundProgressBar()
Hides the background progress bar.
void onNotificationsIconClick(wxCommandEvent &aEvent)
void SetBackgroundProgressMax(int aAmount)
Sets the maX progress of the progress bar.
KISTATUSBAR(int aNumberFields, wxWindow *parent, wxWindowID id)
Definition: kistatusbar.cpp:44
wxStaticText * m_backgroundTxt
Definition: kistatusbar.h:97
void ShowBackgroundProgressBar(bool aCancellable=false)
Shows the background progress bar.
void SetNotificationCount(int aCount)
Sets the notification count on the notifications button A value of 0 will hide the count.
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the notification list.
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition: pgm_base.h:146
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition: pgm_base.h:148
#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:1060
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.