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