KiCad PCB EDA Suite
Loading...
Searching...
No Matches
msgpanel.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) 2004 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <widgets/msgpanel.h>
23
24#include <wx/dcscreen.h>
25#include <wx/dcclient.h>
26#include <wx/settings.h>
27#include <wx/toplevel.h>
28
29#include <advanced_config.h>
30#include <kiid.h>
31
32#include <widgets/ui_common.h>
33
34
35BEGIN_EVENT_TABLE( EDA_MSG_PANEL, wxPanel )
36 EVT_DPI_CHANGED( EDA_MSG_PANEL::OnDPIChanged )
37 EVT_SIZE( EDA_MSG_PANEL::OnSize )
38 EVT_PAINT( EDA_MSG_PANEL::OnPaint )
39END_EVENT_TABLE()
40
41
42EDA_MSG_PANEL::EDA_MSG_PANEL( wxWindow* aParent, int aId, const wxPoint& aPosition,
43 const wxSize& aSize, long style, const wxString &name ) :
44 wxPanel( aParent, aId, aPosition, aSize, style, name )
45{
46 SetFont( KIUI::GetStatusFont( this ) );
47 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
48
49 // informs wx not to paint the background itself as we will paint it later in erase()
50 SetBackgroundStyle( wxBG_STYLE_PAINT );
51
52 m_last_x = 0;
53
55
56 InvalidateBestSize();
57}
58
59
63
64
66{
67 wxFont font = KIUI::GetControlFont( this );
68 GetTextExtent( wxT( "W" ), &m_fontSize.x, &m_fontSize.y, 0, 0, &font );
69}
70
71
73{
74 return wxSize( wxDefaultCoord, 2 * m_fontSize.y + 0 );
75}
76
77
79{
80 return wxPanel::DoGetBestClientSize();
81}
82
83
84void EDA_MSG_PANEL::OnDPIChanged( wxDPIChangedEvent& aEvent )
85{
87 InvalidateBestSize();
88
89 aEvent.Skip();
90}
91
92
94{
95 m_last_x = 0;
96
97 for( MSG_PANEL_ITEM& item : m_Items )
98 updateItemPos( item );
99}
100
101
102void EDA_MSG_PANEL::OnSize( wxSizeEvent& aEvent )
103{
104 rebuildItems();
105}
106
107
108void EDA_MSG_PANEL::OnPaint( wxPaintEvent& aEvent )
109{
110 wxPaintDC dc( this );
111
112 erase( &dc );
113
114 dc.SetBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
115 dc.SetBackgroundMode( wxSOLID );
116 dc.SetTextBackground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
117 dc.SetFont( KIUI::GetControlFont( this ) );
118
119 for( const MSG_PANEL_ITEM& item : m_Items )
120 showItem( dc, item );
121
122 aEvent.Skip();
123}
124
125
127{
128 wxString text;
129 wxString upperText = item.GetUpperText();
130 wxString lowerText = item.GetLowerText();
131 wxSize drawSize = GetClientSize();
132
133 text = ( upperText.Len() > lowerText.Len() ) ? upperText : lowerText;
134 text.Append( ' ', item.GetPadding() );
135
136 /* Don't put the first message a window client position 0. Offset by
137 * one 'W' character width. */
138 if( m_last_x == 0 )
140
141 item.m_X = m_last_x;
142
143 item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y;
144 item.m_LowerY = drawSize.y - m_fontSize.y;
145
146 m_last_x += GetTextExtent( text ).x;
147
148 // Add an extra space between texts for a better look:
149 m_last_x += m_fontSize.x;
150}
151
152
153void EDA_MSG_PANEL::AppendMessage( const wxString& aUpperText, const wxString& aLowerText, int aPadding )
154{
155 MSG_PANEL_ITEM item;
156
157 item.m_UpperText = aUpperText;
158 item.m_LowerText = aLowerText;
159
160 updateItemPos( item );
161 m_Items.push_back( item );
162
163 Refresh();
164}
165
166
167void EDA_MSG_PANEL::showItem( wxDC& aDC, const MSG_PANEL_ITEM& aItem )
168{
169 COLOR4D color;
170
171 // Change the text to a disabled color when the window isn't active
172 wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>( wxGetTopLevelParent( this ) );
173
174 if( tlw && !tlw->IsActive() )
175 color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
176 else
177 color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
178
179 aDC.SetTextForeground( color.ToColour() );
180
181 if( !aItem.m_UpperText.IsEmpty() )
182 aDC.DrawText( aItem.m_UpperText, aItem.m_X, aItem.m_UpperY );
183
184 if( !aItem.m_LowerText.IsEmpty() )
185 aDC.DrawText( aItem.m_LowerText, aItem.m_X, aItem.m_LowerY );
186}
187
188
190{
191 m_Items.clear();
192 m_last_x = 0;
193 Refresh();
194}
195
196
197void EDA_MSG_PANEL::erase( wxDC* aDC )
198{
199 wxPen pen;
200 wxBrush brush;
201
202 wxSize size = GetClientSize();
203 wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
204
205 pen.SetColour( color );
206
207 brush.SetColour( color );
208 brush.SetStyle( wxBRUSHSTYLE_SOLID );
209
210 aDC->SetPen( pen );
211 aDC->SetBrush( brush );
212 aDC->DrawRectangle( 0, 0, size.x, size.y );
213}
214
215
216std::optional<wxString> GetMsgPanelDisplayUuid( const KIID& aKiid )
217{
218 const static int showUuids = ADVANCED_CFG::GetCfg().m_MsgPanelShowUuids;
219 std::optional<wxString> uuid;
220
221 if( showUuids > 0 )
222 {
223 uuid = aKiid.AsString();
224
225 if( showUuids == 2 )
226 uuid = uuid->SubString( 0, 7 );
227 }
228
229 return uuid;
230}
const char * name
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A panel to display various information messages.
Definition msgpanel.h:97
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition msgpanel.cpp:153
void OnDPIChanged(wxDPIChangedEvent &aEvent)
Definition msgpanel.cpp:84
wxSize DoGetBestSize() const override
Definition msgpanel.cpp:72
void updateFontSize()
Definition msgpanel.cpp:65
int m_last_x
the last used x coordinate
Definition msgpanel.h:153
EDA_MSG_PANEL(wxWindow *aParent, int aId, const wxPoint &aPosition, const wxSize &aSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxPanelNameStr)
Definition msgpanel.cpp:42
void EraseMsgBox()
Definition msgpanel.cpp:189
void updateItemPos(MSG_PANEL_ITEM &aItem)
Definition msgpanel.cpp:126
wxSize m_fontSize
Definition msgpanel.h:154
void rebuildItems()
Definition msgpanel.cpp:93
wxSize DoGetBestClientSize() const override
Definition msgpanel.cpp:78
void showItem(wxDC &dc, const MSG_PANEL_ITEM &aItem)
Definition msgpanel.cpp:167
std::vector< MSG_PANEL_ITEM > m_Items
Definition msgpanel.h:152
void OnPaint(wxPaintEvent &aEvent)
Definition msgpanel.cpp:108
void erase(wxDC *DC)
Definition msgpanel.cpp:197
void OnSize(wxSizeEvent &aEvent)
Definition msgpanel.cpp:102
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
wxColour ToColour() const
Definition color4d.cpp:221
Definition kiid.h:44
wxString AsString() const
Definition kiid.cpp:242
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:50
const wxString & GetUpperText() const
Definition msgpanel.h:73
const wxString & GetLowerText() const
Definition msgpanel.h:76
int GetPadding() const
Definition msgpanel.h:79
wxString m_UpperText
Definition msgpanel.h:87
wxString m_LowerText
Definition msgpanel.h:88
int m_MsgPanelShowUuids
Show UUIDs of items in the message panel.
std::optional< wxString > GetMsgPanelDisplayUuid(const KIID &aKiid)
Get a formatted UUID string for display in the message panel, according to the current advanced confi...
Definition msgpanel.cpp:216
Message panel definition file.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Functions to provide common constants and other functions to assist in making a consistent UI.