KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <math/vector2wx.h>
32#include <status_popup.h>
33#include <eda_draw_frame.h>
34
35STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
36 wxPopupWindow( aParent ),
37 m_expireTimer( this )
38{
39 m_panel = new wxPanel( this, wxID_ANY );
40 m_topSizer = new wxBoxSizer( wxVERTICAL );
41 m_panel->SetSizer( m_topSizer );
42 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
43
44 Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), nullptr, this );
45
46#ifdef __WXOSX_MAC__
47 // Key events from popups don't get put through the wxWidgets event system on OSX,
48 // so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
49 // the canvas / frame.
50 Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( STATUS_POPUP::onCharHook ), nullptr, this );
51#endif
52}
53
54
55void STATUS_POPUP::onCharHook( wxKeyEvent& aEvent )
56{
57 // Key events from the status popup don't get put through the wxWidgets event system on
58 // OSX, so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
59 // the canvas / frame.
60 aEvent.SetEventType( wxEVT_CHAR );
61
62 EDA_DRAW_FRAME* frame = dynamic_cast<EDA_DRAW_FRAME*>( GetParent() );
63
64 if( frame )
65 frame->GetCanvas()->OnEvent( aEvent );
66 else
67 GetParent()->GetEventHandler()->ProcessEvent( aEvent );
68}
69
70
71void STATUS_POPUP::Popup( wxWindow* )
72{
73 Show( true );
74 Raise();
75}
76
77
78void STATUS_POPUP::PopupFor( int aMsecs )
79{
80 Popup();
81 Expire( aMsecs );
82}
83
84
85void STATUS_POPUP::Move( const VECTOR2I& aWhere )
86{
87 SetPosition( ToWxPoint( aWhere ) );
88}
89
90
91void STATUS_POPUP::Move( const wxPoint& aWhere )
92{
93 SetPosition( aWhere );
94}
95
96
97void STATUS_POPUP::Expire( int aMsecs )
98{
99 m_expireTimer.StartOnce( aMsecs );
100}
101
102
104{
105 m_topSizer->Fit( m_panel );
106 SetClientSize( m_panel->GetSize() );
107}
108
109
110void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
111{
112 Hide();
113}
114
115
117 STATUS_POPUP( aParent )
118{
119 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
120 m_panel->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
121
122 m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
123 m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
124}
125
126
127void STATUS_TEXT_POPUP::SetText( const wxString& aText )
128{
129 m_statusLine->SetLabel( aText );
130 updateSize();
131}
132
133
134void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
135{
136 m_statusLine->SetForegroundColour( aColor );
137}
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)
wxPoint ToWxPoint(const VECTOR2I &aSize)
Definition: vector2wx.h:50