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  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <status_popup.h>
30 #include <eda_draw_frame.h>
31 
32 STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
33  wxPopupWindow( aParent ),
34  m_expireTimer( this )
35 {
36  m_panel = new wxPanel( this, wxID_ANY );
37  m_topSizer = new wxBoxSizer( wxVERTICAL );
38  m_panel->SetSizer( m_topSizer );
39  m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
40 
41  Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), NULL, this );
42 
43 #ifdef __WXOSX_MAC__
44  // Key events from popups don't get put through the wxWidgets event system on OSX,
45  // so we have to fall back to the CHAR_HOOK to forwared hotkeys from the popup to
46  // the canvas / frame.
47  Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( STATUS_POPUP::onCharHook ), nullptr, this );
48 #endif
49 }
50 
51 
52 void STATUS_POPUP::onCharHook( wxKeyEvent& aEvent )
53 {
54  // Key events from the status popup don't get put through the wxWidgets event system on
55  // OSX, so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
56  // the canvas / frame.
57  aEvent.SetEventType( wxEVT_CHAR );
58 
59  EDA_DRAW_FRAME* frame = dynamic_cast<EDA_DRAW_FRAME*>( GetParent() );
60 
61  if( frame )
62  frame->GetCanvas()->OnEvent( aEvent );
63  else
64  GetParent()->GetEventHandler()->ProcessEvent( aEvent );
65 }
66 
67 
68 void STATUS_POPUP::Popup( wxWindow* )
69 {
70  Show( true );
71  Raise();
72 }
73 
74 
75 void STATUS_POPUP::PopupFor( int aMsecs )
76 {
77  Popup();
78  Expire( aMsecs );
79 }
80 
81 
82 void STATUS_POPUP::Move( const VECTOR2I& aWhere )
83 {
84  SetPosition( wxPoint( aWhere.x, aWhere.y ) );
85 }
86 
87 
88 void STATUS_POPUP::Move( const wxPoint& aWhere )
89 {
90  SetPosition( aWhere );
91 }
92 
93 
94 void STATUS_POPUP::Expire( int aMsecs )
95 {
96  m_expireTimer.StartOnce( aMsecs );
97 }
98 
99 
101 {
102  m_topSizer->Fit( m_panel );
103  SetClientSize( m_panel->GetSize() );
104 }
105 
106 
107 void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
108 {
109  Hide();
110 }
111 
112 
114  STATUS_POPUP( aParent )
115 {
116  m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
117  m_panel->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
118 
119  m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
120  m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
121 }
122 
123 
124 void STATUS_TEXT_POPUP::SetText( const wxString& aText )
125 {
126  m_statusLine->SetLabel( aText );
127  updateSize();
128 }
129 
130 
131 void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
132 {
133  m_statusLine->SetForegroundColour( aColor );
134 }
void onExpire(wxTimerEvent &aEvent)
Expire timer even handler
void SetTextColor(const wxColour &aColor)
Change text color.
STATUS_POPUP(wxWindow *aParent)
Transient mouse following popup window implementation.
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
The base class for create windows for drawing purpose.
wxPanel * m_panel
Definition: status_popup.h:68
void onCharHook(wxKeyEvent &aEvent)
#define NULL
wxStaticText * m_statusLine
Definition: status_popup.h:98
wxTimer m_expireTimer
Definition: status_popup.h:70
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
STATUS_POPUP.
Definition: status_popup.h:42
void Expire(int aMsecs)
Hides the popup after a specified time.
virtual void PopupFor(int aMsecs)
wxBoxSizer * m_topSizer
Definition: status_popup.h:69
STATUS_TEXT_POPUP(wxWindow *aParent)
void SetText(const wxString &aText)
Display a text.