KiCad PCB EDA Suite
status_popup.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) 2014-2015 CERN
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
30#include <wx/settings.h>
31#include <status_popup.h>
32#include <eda_draw_frame.h>
33
34STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
35 wxPopupWindow( aParent ),
36 m_expireTimer( this )
37{
38 m_panel = new wxPanel( this, wxID_ANY );
39 m_topSizer = new wxBoxSizer( wxVERTICAL );
40 m_panel->SetSizer( m_topSizer );
41 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
42
43 Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), nullptr, this );
44
45#ifdef __WXOSX_MAC__
46 // Key events from popups don't get put through the wxWidgets event system on OSX,
47 // so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
48 // the canvas / frame.
49 Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( STATUS_POPUP::onCharHook ), nullptr, this );
50#endif
51}
52
53
54void STATUS_POPUP::onCharHook( wxKeyEvent& aEvent )
55{
56 // Key events from the status popup don't get put through the wxWidgets event system on
57 // OSX, so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
58 // the canvas / frame.
59 aEvent.SetEventType( wxEVT_CHAR );
60
61 EDA_DRAW_FRAME* frame = dynamic_cast<EDA_DRAW_FRAME*>( GetParent() );
62
63 if( frame )
64 frame->GetCanvas()->OnEvent( aEvent );
65 else
66 GetParent()->GetEventHandler()->ProcessEvent( aEvent );
67}
68
69
70void STATUS_POPUP::Popup( wxWindow* )
71{
72 Show( true );
73 Raise();
74}
75
76
77void STATUS_POPUP::PopupFor( int aMsecs )
78{
79 Popup();
80 Expire( aMsecs );
81}
82
83
84void STATUS_POPUP::Move( const VECTOR2I& aWhere )
85{
86 SetPosition( wxPoint( aWhere.x, aWhere.y ) );
87}
88
89
90void STATUS_POPUP::Move( const wxPoint& aWhere )
91{
92 SetPosition( aWhere );
93}
94
95
96void STATUS_POPUP::Expire( int aMsecs )
97{
98 m_expireTimer.StartOnce( aMsecs );
99}
100
101
103{
104 m_topSizer->Fit( m_panel );
105 SetClientSize( m_panel->GetSize() );
106}
107
108
109void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
110{
111 Hide();
112}
113
114
116 STATUS_POPUP( aParent )
117{
118 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
119 m_panel->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
120
121 m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
122 m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
123}
124
125
126void STATUS_TEXT_POPUP::SetText( const wxString& aText )
127{
128 m_statusLine->SetLabel( aText );
129 updateSize();
130}
131
132
133void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
134{
135 m_statusLine->SetForegroundColour( aColor );
136}
The base class for create windows for drawing purpose.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
A tiny, headerless popup window used to display useful status (e.g.
Definition: status_popup.h:45
void onExpire(wxTimerEvent &aEvent)
void Expire(int aMsecs)
Hide the popup after a specified time.
virtual void PopupFor(int aMsecs)
wxBoxSizer * m_topSizer
Definition: status_popup.h:74
wxTimer m_expireTimer
Definition: status_popup.h:75
STATUS_POPUP(wxWindow *aParent)
Transient mouse following popup window implementation.
wxPanel * m_panel
Definition: status_popup.h:73
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
void onCharHook(wxKeyEvent &aEvent)
Expire timer even handler.
void SetTextColor(const wxColour &aColor)
Change text color.
void SetText(const wxString &aText)
Display a text.
wxStaticText * m_statusLine
Definition: status_popup.h:103
STATUS_TEXT_POPUP(wxWindow *aParent)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)