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.

121 lines
3.4 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 <draw_frame.h>
  29. STATUS_POPUP::STATUS_POPUP( EDA_DRAW_FRAME* aParent ) :
  30. wxPopupWindow( aParent ),
  31. m_frame( aParent ),
  32. m_expireTimer( this )
  33. {
  34. m_panel = new wxPanel( this, wxID_ANY );
  35. m_panel->SetBackgroundColour( *wxLIGHT_GREY );
  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 ), NULL, 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 forwared 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 popups don't get put through the wxWidgets event system on OSX,
  50. // 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. if( m_frame->IsGalCanvasActive() )
  54. m_frame->GetGalCanvas()->OnEvent( aEvent );
  55. else
  56. m_frame->ProcessEvent( aEvent );
  57. }
  58. void STATUS_POPUP::Popup( wxWindow* )
  59. {
  60. Show( true );
  61. Raise();
  62. }
  63. void STATUS_POPUP::Move( const wxPoint& aWhere )
  64. {
  65. SetPosition( aWhere );
  66. }
  67. void STATUS_POPUP::Expire( int aMsecs )
  68. {
  69. m_expireTimer.StartOnce( aMsecs );
  70. }
  71. void STATUS_POPUP::updateSize()
  72. {
  73. m_topSizer->Fit( m_panel );
  74. SetClientSize( m_panel->GetSize() );
  75. }
  76. void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
  77. {
  78. Hide();
  79. }
  80. STATUS_TEXT_POPUP::STATUS_TEXT_POPUP( EDA_DRAW_FRAME* aParent ) :
  81. STATUS_POPUP( aParent )
  82. {
  83. m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
  84. m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
  85. m_topSizer->Add( m_statusLine, 1, wxALL | wxEXPAND, 5 );
  86. }
  87. void STATUS_TEXT_POPUP::SetText( const wxString& aText )
  88. {
  89. m_statusLine->SetLabel( aText );
  90. updateSize();
  91. }
  92. void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
  93. {
  94. m_statusLine->SetForegroundColour( aColor );
  95. }