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.

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