notifmsg.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/notifmsg.h
  3. // Purpose: class allowing to show notification messages to the user
  4. // Author: Vadim Zeitlin
  5. // Created: 2007-11-19
  6. // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_NOTIFMSG_H_
  10. #define _WX_NOTIFMSG_H_
  11. #include "wx/event.h"
  12. #if wxUSE_NOTIFICATION_MESSAGE
  13. // ----------------------------------------------------------------------------
  14. // wxNotificationMessage: allows to show the user a message non intrusively
  15. // ----------------------------------------------------------------------------
  16. // notice that this class is not a window and so doesn't derive from wxWindow
  17. class WXDLLIMPEXP_ADV wxNotificationMessageBase : public wxEvtHandler
  18. {
  19. public:
  20. // ctors and initializers
  21. // ----------------------
  22. // default ctor, use setters below to initialize it later
  23. wxNotificationMessageBase()
  24. {
  25. m_parent = NULL;
  26. m_flags = wxICON_INFORMATION;
  27. }
  28. // create a notification object with the given title and message (the
  29. // latter may be empty in which case only the title will be shown)
  30. wxNotificationMessageBase(const wxString& title,
  31. const wxString& message = wxEmptyString,
  32. wxWindow *parent = NULL,
  33. int flags = wxICON_INFORMATION)
  34. : m_title(title),
  35. m_message(message),
  36. m_parent(parent)
  37. {
  38. SetFlags(flags);
  39. }
  40. // note that the setters must be called before Show()
  41. // set the title: short string, markup not allowed
  42. void SetTitle(const wxString& title) { m_title = title; }
  43. // set the text of the message: this is a longer string than the title and
  44. // some platforms allow simple HTML-like markup in it
  45. void SetMessage(const wxString& message) { m_message = message; }
  46. // set the parent for this notification: we'll be associated with the top
  47. // level parent of this window or, if this method is not called, with the
  48. // main application window by default
  49. void SetParent(wxWindow *parent) { m_parent = parent; }
  50. // this method can currently be used to choose a standard icon to use: the
  51. // parameter may be one of wxICON_INFORMATION, wxICON_WARNING or
  52. // wxICON_ERROR only (but not wxICON_QUESTION)
  53. void SetFlags(int flags)
  54. {
  55. wxASSERT_MSG( flags == wxICON_INFORMATION ||
  56. flags == wxICON_WARNING || flags == wxICON_ERROR,
  57. "Invalid icon flags specified" );
  58. m_flags = flags;
  59. }
  60. // showing and hiding
  61. // ------------------
  62. // possible values for Show() timeout
  63. enum
  64. {
  65. Timeout_Auto = -1, // notification will be hidden automatically
  66. Timeout_Never = 0 // notification will never time out
  67. };
  68. // show the notification to the user and hides it after timeout seconds
  69. // pass (special values Timeout_Auto and Timeout_Never can be used)
  70. //
  71. // returns false if an error occurred
  72. virtual bool Show(int timeout = Timeout_Auto) = 0;
  73. // hide the notification, returns true if it was hidden or false if it
  74. // couldn't be done (e.g. on some systems automatically hidden
  75. // notifications can't be hidden manually)
  76. virtual bool Close() = 0;
  77. protected:
  78. // accessors for the derived classes
  79. const wxString& GetTitle() const { return m_title; }
  80. const wxString& GetMessage() const { return m_message; }
  81. wxWindow *GetParent() const { return m_parent; }
  82. int GetFlags() const { return m_flags; }
  83. // return the concatenation of title and message separated by a new line,
  84. // this is suitable for simple implementation which have no support for
  85. // separate title and message parts of the notification
  86. wxString GetFullMessage() const
  87. {
  88. wxString text(m_title);
  89. if ( !m_message.empty() )
  90. {
  91. text << "\n\n" << m_message;
  92. }
  93. return text;
  94. }
  95. private:
  96. wxString m_title,
  97. m_message;
  98. wxWindow *m_parent;
  99. int m_flags;
  100. wxDECLARE_NO_COPY_CLASS(wxNotificationMessageBase);
  101. };
  102. /*
  103. TODO: Implement under OS X using notification centre (10.8+) or
  104. Growl (http://growl.info/) for the previous versions.
  105. */
  106. #if defined(__WXGTK__) && wxUSE_LIBNOTIFY
  107. #include "wx/gtk/notifmsg.h"
  108. #elif defined(__WXGTK__) && (wxUSE_LIBHILDON || wxUSE_LIBHILDON2)
  109. #include "wx/gtk/hildon/notifmsg.h"
  110. #elif defined(__WXMSW__) && wxUSE_TASKBARICON && wxUSE_TASKBARICON_BALLOONS
  111. #include "wx/msw/notifmsg.h"
  112. #else
  113. #include "wx/generic/notifmsg.h"
  114. class wxNotificationMessage : public wxGenericNotificationMessage
  115. {
  116. public:
  117. wxNotificationMessage() { }
  118. wxNotificationMessage(const wxString& title,
  119. const wxString& message = wxEmptyString,
  120. wxWindow *parent = NULL,
  121. int flags = wxICON_INFORMATION)
  122. : wxGenericNotificationMessage(title, message, parent, flags)
  123. {
  124. }
  125. };
  126. #endif
  127. #endif // wxUSE_NOTIFICATION_MESSAGE
  128. #endif // _WX_NOTIFMSG_H_