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 <draw_frame.h>
31 
33  wxPopupWindow( aParent ),
34  m_frame( aParent ),
35  m_expireTimer( this )
36 {
37  m_panel = new wxPanel( this, wxID_ANY );
38  m_panel->SetBackgroundColour( *wxLIGHT_GREY );
39 
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 ), NULL, 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 forwared 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 
55 void STATUS_POPUP::onCharHook( wxKeyEvent& aEvent )
56 {
57  // Key events from popups don't get put through the wxWidgets event system on OSX,
58  // 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  if( m_frame->IsGalCanvasActive() )
63  m_frame->GetGalCanvas()->OnEvent( aEvent );
64  else
65  m_frame->ProcessEvent( aEvent );
66 }
67 
68 
69 void STATUS_POPUP::Popup( wxWindow* )
70 {
71  Show( true );
72  Raise();
73 }
74 
75 
76 void STATUS_POPUP::Move( const wxPoint& aWhere )
77 {
78  SetPosition( aWhere );
79 }
80 
81 
82 void STATUS_POPUP::Expire( int aMsecs )
83 {
84  m_expireTimer.StartOnce( aMsecs );
85 }
86 
87 
89 {
90  m_topSizer->Fit( m_panel );
91  SetClientSize( m_panel->GetSize() );
92 }
93 
94 
95 void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
96 {
97  Hide();
98 }
99 
100 
102  STATUS_POPUP( aParent )
103 {
104  m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
105 
106  m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
107  m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
108 }
109 
110 
111 void STATUS_TEXT_POPUP::SetText( const wxString& aText )
112 {
113  m_statusLine->SetLabel( aText );
114  updateSize();
115 }
116 
117 
118 void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
119 {
120  m_statusLine->SetForegroundColour( aColor );
121 }
EDA_DRAW_FRAME * m_frame
Definition: status_popup.h:65
void onExpire(wxTimerEvent &aEvent)
Expire timer even handler
void SetTextColor(const wxColour &aColor)
Change text color.
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.
STATUS_TEXT_POPUP(EDA_DRAW_FRAME *aParent)
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
wxPanel * m_panel
Definition: status_popup.h:66
void onCharHook(wxKeyEvent &aEvent)
wxStaticText * m_statusLine
Definition: status_popup.h:96
wxTimer m_expireTimer
Definition: status_popup.h:68
void updateSize()
virtual void Popup(wxWindow *aFocus=nullptr)
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:914
virtual void Move(const wxPoint &aWhere)
Class STATUS_POPUP.
Definition: status_popup.h:41
void Expire(int aMsecs)
Hides the popup after a specified time.
wxBoxSizer * m_topSizer
Definition: status_popup.h:67
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:921
STATUS_POPUP(EDA_DRAW_FRAME *aParent)
Transient mouse following popup window implementation.
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
void SetText(const wxString &aText)
Display a text.