You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.7 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  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 (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  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, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * Transient mouse following popup window implementation.
  27. */
  28. #include <wx/settings.h>
  29. #include <status_popup.h>
  30. #include <eda_draw_frame.h>
  31. STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
  32. wxPopupWindow( aParent ),
  33. m_expireTimer( this )
  34. {
  35. m_panel = new wxPanel( this, wxID_ANY );
  36. m_topSizer = new wxBoxSizer( wxVERTICAL );
  37. m_panel->SetSizer( m_topSizer );
  38. m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
  39. Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), nullptr, this );
  40. #ifdef __WXOSX_MAC__
  41. // Key events from popups don't get put through the wxWidgets event system on OSX,
  42. // so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
  43. // the canvas / frame.
  44. Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( STATUS_POPUP::onCharHook ), nullptr, this );
  45. #endif
  46. }
  47. void STATUS_POPUP::onCharHook( wxKeyEvent& aEvent )
  48. {
  49. // Key events from the status popup don't get put through the wxWidgets event system on
  50. // OSX, so we have to fall back to the CHAR_HOOK to forward hotkeys from the popup to
  51. // the canvas / frame.
  52. aEvent.SetEventType( wxEVT_CHAR );
  53. EDA_DRAW_FRAME* frame = dynamic_cast<EDA_DRAW_FRAME*>( GetParent() );
  54. if( frame )
  55. frame->GetCanvas()->OnEvent( aEvent );
  56. else
  57. GetParent()->GetEventHandler()->ProcessEvent( aEvent );
  58. }
  59. void STATUS_POPUP::Popup( wxWindow* )
  60. {
  61. Show( true );
  62. Raise();
  63. }
  64. void STATUS_POPUP::PopupFor( int aMsecs )
  65. {
  66. Popup();
  67. Expire( aMsecs );
  68. }
  69. void STATUS_POPUP::Move( const VECTOR2I& aWhere )
  70. {
  71. SetPosition( wxPoint( aWhere.x, aWhere.y ) );
  72. }
  73. void STATUS_POPUP::Move( const wxPoint& aWhere )
  74. {
  75. SetPosition( aWhere );
  76. }
  77. void STATUS_POPUP::Expire( int aMsecs )
  78. {
  79. m_expireTimer.StartOnce( aMsecs );
  80. }
  81. void STATUS_POPUP::updateSize()
  82. {
  83. m_topSizer->Fit( m_panel );
  84. SetClientSize( m_panel->GetSize() );
  85. }
  86. void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
  87. {
  88. Hide();
  89. }
  90. STATUS_TEXT_POPUP::STATUS_TEXT_POPUP( wxWindow* aParent ) :
  91. STATUS_POPUP( aParent )
  92. {
  93. m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
  94. m_panel->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
  95. m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
  96. m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
  97. }
  98. void STATUS_TEXT_POPUP::SetText( const wxString& aText )
  99. {
  100. m_statusLine->SetLabel( aText );
  101. updateSize();
  102. }
  103. void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
  104. {
  105. m_statusLine->SetForegroundColour( aColor );
  106. }