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.

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