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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
25
26#include <wx/settings.h>
27#include <math/vector2wx.h>
28#include <status_popup.h>
29#include <eda_draw_frame.h>
30#include <bitmaps.h>
31
32STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
33 wxPopupWindow( aParent ),
34 m_expireTimer( this )
35{
36 SetDoubleBuffered( true );
37
38 m_panel = new wxPanel( this, wxID_ANY );
39 m_topSizer = new wxBoxSizer( wxHORIZONTAL );
40 m_panel->SetSizer( m_topSizer );
41 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
42
43 Connect( m_expireTimer.GetId(), 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( ToWxPoint( aWhere ) );
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 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
119 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
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}
138
139
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.
void onExpire(wxTimerEvent &aEvent)
Expire timer even handler.
void Expire(int aMsecs)
Hide the popup after a specified time.
virtual void PopupFor(int aMsecs)
wxBoxSizer * m_topSizer
wxTimer m_expireTimer
STATUS_POPUP(wxWindow *aParent)
Transient mouse following popup window implementation.
wxPanel * m_panel
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
void onCharHook(wxKeyEvent &aEvent)
void SetTextColor(const wxColour &aColor)
Change text color.
void SetText(const wxString &aText)
Display a text.
wxStaticText * m_statusLine
STATUS_TEXT_POPUP(wxWindow *aParent)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
wxPoint ToWxPoint(const VECTOR2I &aSize)
Definition vector2wx.h:46