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