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
110void KISTATUSBAR::onNotificationsIconClick( wxCommandEvent& aEvent )
111{
112 wxPoint pos = m_notificationsButton->GetScreenPosition();
113
114 wxRect r;
115 GetFieldRect( m_normalFieldsCount + 3, r );
116 pos.x += r.GetWidth();
117
118 Pgm().GetNotificationsManager().ShowList( this, pos );
119}
120
121
122void KISTATUSBAR::onBackgroundProgressClick( wxMouseEvent& aEvent )
123{
124 wxPoint pos = m_backgroundProgressBar->GetScreenPosition();
125
126 wxRect r;
127 GetFieldRect( m_normalFieldsCount + 1, r );
128 pos.x += r.GetWidth();
129
130 Pgm().GetBackgroundJobMonitor().ShowList( this, pos );
131}
132
133void KISTATUSBAR::onSize( wxSizeEvent& aEvent )
134{
135 wxRect r;
136 GetFieldRect( m_normalFieldsCount + FIELD_OFFSET_BGJOB_TEXT, r );
137 int x = r.GetLeft();
138 int y = r.GetTop();
139
140 m_backgroundTxt->SetPosition( { x, y } );
141
143 x = r.GetLeft();
144 y = r.GetTop();
145 int w = r.GetWidth();
146 int h = r.GetHeight();
147 constexpr int b = 5;
148
149 auto buttonSize = m_backgroundStopButton->GetEffectiveMinSize();
150 m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } );
151 m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h );
152
153 m_backgroundProgressBar->SetPosition( { x, y } );
154 m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - b, h );
155
157 x = r.GetLeft();
158 y = r.GetTop();
159 h = r.GetHeight();
160 buttonSize = m_notificationsButton->GetEffectiveMinSize();
161 m_notificationsButton->SetPosition( { x, y } );
162 m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h );
163}
164
165
167{
169
170 if( aCancellable )
172 else
174}
175
176
178{
181}
182
183
185{
186 m_backgroundProgressBar->SetValue( aAmount );
187}
188
189
191{
192 m_backgroundProgressBar->SetRange( aAmount );
193}
194
195
196void KISTATUSBAR::SetBackgroundStatusText( const wxString& aTxt )
197{
198 m_backgroundTxt->SetLabel( aTxt );
199}
200
201
203{
204 wxString cnt = "";
205 if( aCount > 0 )
206 {
207 cnt = wxString::Format( "%d", aCount );
208 }
209
211
212 // force a repaint or it wont until it gets activity
213 Refresh();
214}
215
216#include <widgets/ui_common.h>
217void KISTATUSBAR::SetEllipsedTextField( const wxString& aText, int aFieldId )
218{
219 wxRect fieldRect;
220 int width = -1;
221 wxString etext = aText;
222
223 // Only GetFieldRect() returns the current size for variable size fields
224 // Other methods return -1 for the width of these fields.
225 if( GetFieldRect( aFieldId, fieldRect ) )
226 width = fieldRect.GetWidth();
227
228 if( width > 20 )
229 {
230 wxClientDC dc( this );
231 // Gives a margin to the text to be sure it is not clamped at its end
232 int margin = KIUI::GetTextSize( wxT( "XX" ), this ).x;
233 etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
234 }
235
236 SetStatusText( etext, aFieldId );
237}
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:97
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:98
void SetBackgroundProgress(int aAmount)
Sets the current progress of the progress bar.
wxGauge * m_backgroundProgressBar
Definition: kistatusbar.h:94
wxButton * m_backgroundStopButton
Definition: kistatusbar.h:95
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:96
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:1059
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.