KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kistatusbar_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/app.h>
23#include <wx/time.h>
24
25
27const std::type_info* KISTATUSBAR_POPUP::s_lastDismissedType = nullptr;
28
29
31 wxPopupTransientWindow( aParent, wxBORDER_SIMPLE | wxPU_CONTAINS_CONTROLS )
32{
33 SetSize( FromDIP( wxSize( 300, 150 ) ) );
34
35 Bind( wxEVT_CHAR_HOOK, &KISTATUSBAR_POPUP::onCharHook, this );
36}
37
38
39void KISTATUSBAR_POPUP::PopupAt( const wxPoint& aCorner )
40{
41 Move( aCorner - GetSize() );
42 Popup();
43}
44
45
46bool KISTATUSBAR_POPUP::IsDismissingClick( const std::type_info& aPopupType )
47{
48 if( !s_lastDismissedType || *s_lastDismissedType != aPopupType )
49 return false;
50
51 if( wxGetLocalTimeMillis().GetValue() - s_lastDismissed >= 300 )
52 return false;
53
55 return true;
56}
57
58
60{
61 s_lastDismissed = wxGetLocalTimeMillis().GetValue();
62 s_lastDismissedType = &typeid( *this );
63
64 // Dismissal can repeat before the deferred delete runs, as MSW deactivation does after Escape
65 if( !wxTheApp->IsScheduledForDestruction( this ) )
66 Destroy();
67}
68
69
70void KISTATUSBAR_POPUP::onCharHook( wxKeyEvent& aEvent )
71{
72 if( aEvent.GetKeyCode() == WXK_ESCAPE )
73 DismissAndNotify();
74 else
75 aEvent.Skip();
76}
KISTATUSBAR_POPUP(wxWindow *aParent)
void OnDismiss() override
void PopupAt(const wxPoint &aCorner)
Show the popup with its bottom-right corner at aCorner, in screen coordinates.
void onCharHook(wxKeyEvent &aEvent)
static const std::type_info * s_lastDismissedType
static long long s_lastDismissed
static bool IsDismissingClick(const std::type_info &aPopupType)
Return true, once, for a click that arrives just after a popup of type aPopupType was dismissed.