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.

243 lines
7.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
  5. * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef INFOBAR_H_
  21. #define INFOBAR_H_
  22. #include <wx/event.h>
  23. #include <wx/infobar.h>
  24. #include <wx/wx.h>
  25. class wxAuiManager;
  26. enum
  27. {
  28. /// ID for the close button on the frame's infobar
  29. ID_CLOSE_INFOBAR = 2000,
  30. };
  31. wxDECLARE_EVENT( KIEVT_SHOW_INFOBAR, wxCommandEvent );
  32. wxDECLARE_EVENT( KIEVT_DISMISS_INFOBAR, wxCommandEvent );
  33. /**
  34. * A modified version of the wxInfoBar class that allows us to:
  35. * * Show the close button along with the other buttons
  36. * * Remove all user-provided buttons at once
  37. * * Allow automaticly hiding the infobar after a time period
  38. * * Show/hide using events
  39. * * Place it inside an AUI manager
  40. *
  41. * This inherits from the generic infobar because the native infobar
  42. * on GTK doesn't include the icon on the left and it looks worse.
  43. *
  44. * There are 2 events associated with the infobar:
  45. *
  46. * KIEVT_SHOW_INFOBAR:
  47. * An event that tells the infobar to show a message.
  48. *
  49. * The message text is contained inside the string component,
  50. * and the message flag is contained inside the int component.
  51. *
  52. * Sample event creation code:
  53. * wxCommandEvent* evt = new wxCommandEvent( KIEVT_SHOW_INFOBAR );
  54. * evt->SetString( "A message to show" );
  55. * evt->SetInt( wxICON_WARNING );
  56. *
  57. * KIEVT_DISMISS_INFOBAR:
  58. * An event that tells the infobar to hide itself.
  59. */
  60. class WX_INFOBAR : public wxInfoBarGeneric
  61. {
  62. public:
  63. /**
  64. * Construct an infobar that can exist inside an AUI managed frame.
  65. *
  66. * @param aParent is the parent
  67. * @param aMgr is the AUI manager that this infobar is added to
  68. * @param aWinId is the ID for this infobar object
  69. */
  70. WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr = nullptr, wxWindowID aWinid = wxID_ANY );
  71. ~WX_INFOBAR();
  72. /**
  73. * Set the time period to show the infobar.
  74. *
  75. * This only applies for the next showing of the infobar,
  76. * so it must be reset every time. A value of 0 disables
  77. * the automatic hiding (this is the default).
  78. *
  79. * @param aTime is the time in milliseconds to show the infobar
  80. */
  81. void SetShowTime( int aTime );
  82. /**
  83. * Add the default close button to the infobar on the right side.
  84. *
  85. * @param aTooltip is the tooltip to give the close button
  86. */
  87. void AddCloseButton( const wxString& aTooltip = _( "Hide this message." ) );
  88. /**
  89. * Add an already created button to the infobar.
  90. * New buttons are added in the right-most position.
  91. *
  92. * @param aButton is the button to add
  93. */
  94. void AddButton( wxButton* aButton );
  95. /**
  96. * Add a button with the provided ID and text.
  97. * The new button is created on the right-most positon.
  98. *
  99. * @param aId is the ID to assign to the button
  100. * @param aLabel is the text for the button
  101. */
  102. void AddButton( wxWindowID aId, const wxString& aLabel = wxEmptyString ) override;
  103. /**
  104. * Remove all the buttons that have been added by the user.
  105. */
  106. void RemoveAllButtons();
  107. /**
  108. * Show the infobar with the provided message and icon for a specific period
  109. * of time.
  110. *
  111. * @param aMessage is the message to display
  112. * @param aTime is the amount of time in milliseconds to show the infobar
  113. * @param aFlags is the flag containing the icon to display on the left side of the infobar
  114. */
  115. void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );
  116. /**
  117. * Show the info bar with the provided message and icon.
  118. *
  119. * @param aMessage is the message to display
  120. * @param aFlags is the flag containing the icon to display on the left side of the infobar
  121. */
  122. void ShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION ) override;
  123. /**
  124. * Dismisses the infobar and updates the containing layout and AUI manager
  125. * (if one is provided).
  126. */
  127. void Dismiss() override;
  128. /**
  129. * Send the infobar an event telling it to show a message.
  130. *
  131. * @param aMessage is the message to display
  132. * @param aFlags is the flag containing the icon to display on the left side of the infobar
  133. */
  134. void QueueShowMessage( const wxString& aMessage, int aFlags = wxICON_INFORMATION );
  135. /**
  136. * Send the infobar an event telling it to hide itself.
  137. */
  138. void QueueDismiss();
  139. protected:
  140. /**
  141. * Event handler for showing the infobar using a wxCommandEvent of the type
  142. * KIEVT_SHOW_INFOBAR. The message is stored inside the string field, and the
  143. * icon flag is stored inside the int field.
  144. */
  145. void OnShowInfoBar( wxCommandEvent& aEvent );
  146. /**
  147. * Event handler for dismissing the infobar using a wxCommandEvent of the type
  148. * KIEVT_DISMISS_INFOBAR.
  149. */
  150. void OnDismissInfoBar( wxCommandEvent& aEvent );
  151. /**
  152. * Event handler for the close button.
  153. * This is bound to ID_CLOSE_INFOBAR on the infobar.
  154. */
  155. void OnCloseButton( wxCommandEvent& aEvent );
  156. /**
  157. * Event handler for the automatic closing timer.
  158. */
  159. void OnTimer( wxTimerEvent& aEvent );
  160. /**
  161. * Update the AUI pane to show or hide this infobar.
  162. *
  163. * @param aShow is true to show the pane
  164. */
  165. void UpdateAuiLayout( bool aShow );
  166. int m_showTime; ///< The time to show the infobar. 0 = don't auto hide
  167. bool m_updateLock; ///< True if this infobar requested the UI update
  168. wxTimer* m_showTimer; ///< The timer counting the autoclose period
  169. wxAuiManager* m_auiManager; ///< The AUI manager that contains this infobar
  170. DECLARE_EVENT_TABLE()
  171. };
  172. /**
  173. * A wxPanel derived class that hold an infobar and another control.
  174. * The infobar is located at the top of the panel, and the other control
  175. * is located below it.
  176. *
  177. * This allows the infobar to be controlled nicely by an AUI manager,
  178. * since adding the infobar on its own to the AUI manager produces
  179. * artifacts when showing/hiding it due to the AUI pane layout.
  180. *
  181. * Note that this implementation currently has issues on Windows with
  182. * event processing inside the GAL canvas, see:
  183. * https://gitlab.com/kicad/code/kicad/-/issues/4501
  184. *
  185. */
  186. class EDA_INFOBAR_PANEL : public wxPanel
  187. {
  188. public:
  189. EDA_INFOBAR_PANEL( wxWindow* aParent, wxWindowID aId = wxID_ANY,
  190. const wxPoint& aPos = wxDefaultPosition,
  191. const wxSize& aSize = wxSize( -1,-1 ),
  192. long aStyle = wxTAB_TRAVERSAL,
  193. const wxString& aName = wxEmptyString );
  194. /**
  195. * Add the given infobar object to the panel
  196. *
  197. * @param aInfoBar is the infobar to add
  198. */
  199. void AddInfoBar( WX_INFOBAR* aInfoBar );
  200. /**
  201. * Add the other item to the panel.
  202. * This item will expand to fill up the vertical space left.
  203. *
  204. * @param aOtherItem is the item to add
  205. */
  206. void AddOtherItem( wxWindow* aOtherItem );
  207. protected:
  208. // The sizer containing the infobar and the other object
  209. wxFlexGridSizer* m_mainSizer;
  210. };
  211. #endif // INFOBAR_H_