infobar.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/infobar.h
  3. // Purpose: interface of wxInfoBar
  4. // Author: Vadim Zeitlin
  5. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. An info bar is a transient window shown at top or bottom of its parent
  10. window to display non-critical information to the user.
  11. This class provides another way to show messages to the user, intermediate
  12. between message boxes and status bar messages. The message boxes are modal
  13. and thus interrupt the users work flow and should be used sparingly for
  14. this reason. However status bar messages are often too easy not to notice
  15. at all. An info bar provides a way to present the messages which has a much
  16. higher chance to be noticed by the user but without being annoying.
  17. Info bar may show an icon (on the left), text message and, optionally,
  18. buttons allowing the user to react to the information presented. It always
  19. has a close button at the right allowing the user to dismiss it so it isn't
  20. necessary to provide a button just to close it.
  21. wxInfoBar calls its parent wxWindow::Layout() method and assumes that it
  22. will change the parent layout appropriately depending on whether the info
  23. bar itself is shown or hidden. Usually this is achieved by simply using a
  24. sizer for the parent window layout and adding wxInfoBar to this sizer as
  25. one of the items. Considering the usual placement of the info bars,
  26. normally this sizer should be a vertical wxBoxSizer and the bar its first
  27. or last element so the simplest possible example of using this class would
  28. be:
  29. @code
  30. class MyFrame : public wxFrame
  31. {
  32. ...
  33. wxInfoBar *m_infoBar;
  34. };
  35. MyFrame::MyFrame()
  36. {
  37. ...
  38. m_infoBar = new wxInfoBar(this);
  39. wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
  40. sizer->Add(m_infoBar, wxSizerFlags().Expand());
  41. ... add other frame controls to the sizer ...
  42. SetSizer(sizer);
  43. }
  44. void MyFrame::SomeMethod()
  45. {
  46. m_infoBar->ShowMessage("Something happened", wxICON_INFORMATION);
  47. }
  48. @endcode
  49. See the dialogs sample for more sophisticated examples.
  50. Currently this class is implemented generically (i.e. in the same
  51. platform-independent way for all ports) and also natively in wxGTK but the
  52. native implementation requires a recent -- as of this writing -- GTK+ 2.18
  53. version.
  54. @library{wxcore}
  55. @category{miscwnd}
  56. @see wxStatusBar, wxMessageDialog
  57. @since 2.9.1
  58. */
  59. class wxInfoBar : public wxControl
  60. {
  61. public:
  62. /**
  63. Default constructor.
  64. Use Create() for the objects created using this constructor.
  65. */
  66. wxInfoBar();
  67. /**
  68. Constructor creating the info bar window.
  69. @see Create()
  70. */
  71. wxInfoBar(wxWindow *parent, wxWindowID winid = wxID_ANY);
  72. /**
  73. Create the info bar window.
  74. Notice that unlike most of the other wxWindow-derived classes,
  75. wxInfoBar is created hidden and is only shown when ShowMessage() is
  76. called. This is more convenient as usually the info bar is created to
  77. be shown at some later time and not immediately and so creating it
  78. hidden avoids the need to call Hide() explicitly from the code using
  79. it.
  80. This should be only called if the object was created using its default
  81. constructor.
  82. @param parent
  83. A valid parent window pointer.
  84. @param winid
  85. The id of the info bar window, usually unused as currently no
  86. events are generated by this class.
  87. */
  88. bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY);
  89. /**
  90. Add a button to be shown in the info bar.
  91. The button added by this method will be shown to the right of the text
  92. (in LTR layout), with each successive button being added to the right
  93. of the previous one. If any buttons are added to the info bar using
  94. this method, the default "Close" button is not shown as it is assumed
  95. that the extra buttons already allow the user to close it.
  96. Clicking the button will generate a normal EVT_COMMAND_BUTTON_CLICKED
  97. event which can be handled as usual. The default handler in wxInfoBar
  98. itself closes the window whenever a button in it is clicked so if you
  99. wish the info bar to be hidden when the button is clicked, simply call
  100. @c event.Skip() in the button handler to let the base class handler do
  101. it (calling Dismiss() explicitly works too, of course). On the other
  102. hand, if you don't skip the event, the info bar will remain opened so
  103. make sure to do it for at least some buttons to allow the user to close
  104. it.
  105. Notice that the generic wxInfoBar implementation handles the button
  106. events itself and so they are not propagated to the info bar parent and
  107. you need to either inherit from wxInfoBar and handle them in your
  108. derived class or use wxEvtHandler::Connect(), as is done in the dialogs
  109. sample, to handle the button events in the parent frame.
  110. @param btnid
  111. Id of the button. It will be used in the button message clicking
  112. this button will generate.
  113. @param label
  114. The label of the button. It may only be empty if @a btnid is one of
  115. the stock ids in which case the corresponding stock label (see
  116. wxGetStockLabel()) will be used.
  117. */
  118. void AddButton(wxWindowID btnid, const wxString& label = wxString());
  119. /**
  120. Hide the info bar window.
  121. This method hides the window and lays out the parent window to account
  122. for its disappearance (unlike a simple Hide()).
  123. */
  124. virtual void Dismiss();
  125. /**
  126. Remove a button previously added by AddButton().
  127. @param btnid
  128. Id of the button to remove. If more than one button with the same
  129. id is used in the info bar (which is in any case not recommended),
  130. the last, i.e. most recently added, button with this id is removed.
  131. */
  132. void RemoveButton(wxWindowID btnid);
  133. /**
  134. Show a message in the bar.
  135. If the bar is currently hidden, it will be shown. Otherwise its message
  136. will be updated in place.
  137. @param msg
  138. The text of the message.
  139. @param flags
  140. One of wxICON_NONE, wxICON_INFORMATION (default), wxICON_QUESTION,
  141. wxICON_WARNING or wxICON_ERROR values. These flags have the same
  142. meaning as in wxMessageDialog for the generic version, i.e. show
  143. (or not, in case of wxICON_NONE) the corresponding icon in the bar
  144. but can be interpreted by the native versions. For example, the
  145. GTK+ native implementation doesn't show icons at all but uses this
  146. parameter to select the appropriate background colour for the
  147. notification.
  148. */
  149. void ShowMessage(const wxString& msg, int flags = wxICON_NONE);
  150. /**
  151. @name Generic version customization methods.
  152. All these methods exist in the generic version of the class only.
  153. The generic version uses wxWindow::ShowWithEffect() function to
  154. progressively show it on the platforms which support it (currently only
  155. wxMSW). The methods here allow to change the default effect used (or
  156. disable it entirely) and change its duration.
  157. */
  158. //@{
  159. /**
  160. Set the effects to use when showing and hiding the bar.
  161. Either or both of the parameters can be set to wxSHOW_EFFECT_NONE to
  162. disable using effects entirely.
  163. By default, the info bar uses wxSHOW_EFFECT_SLIDE_TO_BOTTOM effect for
  164. showing itself and wxSHOW_EFFECT_SLIDE_TO_TOP for hiding if it is the
  165. first element of the containing sizer and reverse effects if it's the
  166. last one. If it is neither the first nor the last element, no effect is
  167. used to avoid the use of an inappropriate one and this function must be
  168. called if an effect is desired.
  169. @param showEffect
  170. The effect to use when showing the bar.
  171. @param hideEffect
  172. The effect to use when hiding the bar.
  173. */
  174. void SetShowHideEffects(wxShowEffect showEffect, wxShowEffect hideEffect);
  175. /// Return the effect currently used for showing the bar.
  176. wxShowEffect GetShowEffect() const;
  177. /// Return the effect currently used for hiding the bar.
  178. wxShowEffect GetHideEffect() const;
  179. /**
  180. Set the duration of the animation used when showing or hiding the bar.
  181. By default, 500ms duration is used.
  182. @param duration
  183. Duration of the animation, in milliseconds.
  184. */
  185. void SetEffectDuration(int duration);
  186. /// Return the effect animation duration currently used.
  187. int GetEffectDuration() const;
  188. /**
  189. Overridden base class methods changes the font of the text message.
  190. wxInfoBar overrides this method to use the font passed to it for its
  191. text message part. By default a larger and bold version of the standard
  192. font is used.
  193. This method is generic-only.
  194. */
  195. virtual bool SetFont(const wxFont& font);
  196. //@}
  197. };