2007-11-23 20:56:13 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/notifmsg.h
|
|
|
|
// Purpose: class allowing to show notification messages to the user
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2007-11-19
|
2019-04-22 08:12:05 -04:00
|
|
|
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
|
2007-11-23 20:56:13 -05:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_NOTIFMSG_H_
|
|
|
|
#define _WX_NOTIFMSG_H_
|
|
|
|
|
|
|
|
#include "wx/event.h"
|
|
|
|
|
|
|
|
#if wxUSE_NOTIFICATION_MESSAGE
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxNotificationMessage: allows to show the user a message non intrusively
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// notice that this class is not a window and so doesn't derive from wxWindow
|
|
|
|
|
2018-08-27 10:34:34 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxNotificationMessageBase : public wxEvtHandler
|
2007-11-23 20:56:13 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors and initializers
|
|
|
|
// ----------------------
|
|
|
|
|
|
|
|
// default ctor, use setters below to initialize it later
|
2007-12-02 12:02:30 -05:00
|
|
|
wxNotificationMessageBase()
|
|
|
|
{
|
2015-09-09 16:59:21 -04:00
|
|
|
Init();
|
2007-12-02 12:02:30 -05:00
|
|
|
}
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
// create a notification object with the given title and message (the
|
|
|
|
// latter may be empty in which case only the title will be shown)
|
|
|
|
wxNotificationMessageBase(const wxString& title,
|
2008-10-13 04:51:45 -04:00
|
|
|
const wxString& message = wxEmptyString,
|
2007-12-02 12:02:30 -05:00
|
|
|
wxWindow *parent = NULL,
|
|
|
|
int flags = wxICON_INFORMATION)
|
2007-11-23 20:56:13 -05:00
|
|
|
{
|
2015-09-09 16:59:21 -04:00
|
|
|
Init();
|
|
|
|
Create(title, message, parent, flags);
|
2007-11-23 20:56:13 -05:00
|
|
|
}
|
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
virtual ~wxNotificationMessageBase();
|
|
|
|
|
2007-11-23 20:56:13 -05:00
|
|
|
// note that the setters must be called before Show()
|
|
|
|
|
|
|
|
// set the title: short string, markup not allowed
|
2015-09-09 16:59:21 -04:00
|
|
|
void SetTitle(const wxString& title);
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
// set the text of the message: this is a longer string than the title and
|
|
|
|
// some platforms allow simple HTML-like markup in it
|
2015-09-09 16:59:21 -04:00
|
|
|
void SetMessage(const wxString& message);
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
// set the parent for this notification: we'll be associated with the top
|
|
|
|
// level parent of this window or, if this method is not called, with the
|
|
|
|
// main application window by default
|
2015-09-09 16:59:21 -04:00
|
|
|
void SetParent(wxWindow *parent);
|
2007-11-23 20:56:13 -05:00
|
|
|
|
2007-12-02 12:02:30 -05:00
|
|
|
// this method can currently be used to choose a standard icon to use: the
|
|
|
|
// parameter may be one of wxICON_INFORMATION, wxICON_WARNING or
|
|
|
|
// wxICON_ERROR only (but not wxICON_QUESTION)
|
2015-09-09 16:59:21 -04:00
|
|
|
void SetFlags(int flags);
|
2007-12-02 12:02:30 -05:00
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
// set a custom icon to use instead of the system provided specified via SetFlags
|
|
|
|
virtual void SetIcon(const wxIcon& icon);
|
2007-12-02 12:02:30 -05:00
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
// Add a button to the notification, returns false if the platform does not support
|
|
|
|
// actions in notifications
|
|
|
|
virtual bool AddAction(wxWindowID actionid, const wxString &label = wxString());
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
// showing and hiding
|
|
|
|
// ------------------
|
|
|
|
|
|
|
|
// possible values for Show() timeout
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Timeout_Auto = -1, // notification will be hidden automatically
|
|
|
|
Timeout_Never = 0 // notification will never time out
|
|
|
|
};
|
|
|
|
|
|
|
|
// show the notification to the user and hides it after timeout seconds
|
|
|
|
// pass (special values Timeout_Auto and Timeout_Never can be used)
|
|
|
|
//
|
|
|
|
// returns false if an error occurred
|
2015-09-09 16:59:21 -04:00
|
|
|
bool Show(int timeout = Timeout_Auto);
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
// hide the notification, returns true if it was hidden or false if it
|
|
|
|
// couldn't be done (e.g. on some systems automatically hidden
|
|
|
|
// notifications can't be hidden manually)
|
2015-09-09 16:59:21 -04:00
|
|
|
bool Close();
|
2007-11-23 20:56:13 -05:00
|
|
|
|
|
|
|
protected:
|
2015-09-09 16:59:21 -04:00
|
|
|
// Common part of all ctors.
|
|
|
|
void Create(const wxString& title = wxEmptyString,
|
|
|
|
const wxString& message = wxEmptyString,
|
|
|
|
wxWindow *parent = NULL,
|
|
|
|
int flags = wxICON_INFORMATION)
|
2007-11-23 20:56:13 -05:00
|
|
|
{
|
2015-09-09 16:59:21 -04:00
|
|
|
SetTitle(title);
|
|
|
|
SetMessage(message);
|
|
|
|
SetParent(parent);
|
|
|
|
SetFlags(flags);
|
2007-11-23 20:56:13 -05:00
|
|
|
}
|
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
class wxNotificationMessageImpl* m_impl;
|
2007-11-23 20:56:13 -05:00
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
private:
|
2007-11-23 20:56:13 -05:00
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_impl = NULL;
|
|
|
|
}
|
2007-12-02 12:02:30 -05:00
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxNotificationMessageBase);
|
2007-11-23 20:56:13 -05:00
|
|
|
};
|
|
|
|
|
2018-08-27 10:34:34 -04:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_NOTIFICATION_MESSAGE_CLICK, wxCommandEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_NOTIFICATION_MESSAGE_DISMISSED, wxCommandEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_NOTIFICATION_MESSAGE_ACTION, wxCommandEvent );
|
2015-09-09 16:59:21 -04:00
|
|
|
|
|
|
|
#if (defined(__WXGTK__) && wxUSE_LIBNOTIFY) || \
|
|
|
|
(defined(__WXMSW__) && wxUSE_TASKBARICON && wxUSE_TASKBARICON_BALLOONS) || \
|
|
|
|
(defined(__WXOSX_COCOA__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8))
|
|
|
|
#define wxHAS_NATIVE_NOTIFICATION_MESSAGE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxNotificationMessage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef wxHAS_NATIVE_NOTIFICATION_MESSAGE
|
|
|
|
|
|
|
|
#if defined(__WXMSW__)
|
2018-08-27 10:34:34 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxTaskBarIcon;
|
2015-09-09 16:59:21 -04:00
|
|
|
#endif // defined(__WXMSW__)
|
|
|
|
|
2007-11-23 20:56:13 -05:00
|
|
|
#else
|
2015-09-09 16:59:21 -04:00
|
|
|
#include "wx/generic/notifmsg.h"
|
|
|
|
#endif // wxHAS_NATIVE_NOTIFICATION_MESSAGE
|
2007-12-02 12:02:30 -05:00
|
|
|
|
2018-08-27 10:34:34 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxNotificationMessage : public
|
2015-09-09 16:59:21 -04:00
|
|
|
#ifdef wxHAS_NATIVE_NOTIFICATION_MESSAGE
|
|
|
|
wxNotificationMessageBase
|
|
|
|
#else
|
|
|
|
wxGenericNotificationMessage
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxNotificationMessage() { Init(); }
|
|
|
|
wxNotificationMessage(const wxString& title,
|
|
|
|
const wxString& message = wxString(),
|
|
|
|
wxWindow *parent = NULL,
|
|
|
|
int flags = wxICON_INFORMATION)
|
2007-12-02 12:02:30 -05:00
|
|
|
{
|
2015-09-09 16:59:21 -04:00
|
|
|
Init();
|
|
|
|
Create(title, message, parent, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__WXMSW__) && defined(wxHAS_NATIVE_NOTIFICATION_MESSAGE)
|
2015-09-14 14:20:00 -04:00
|
|
|
static bool MSWUseToasts(
|
|
|
|
const wxString& shortcutPath = wxString(),
|
|
|
|
const wxString& appId = wxString());
|
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
// returns the task bar icon which was used previously (may be NULL)
|
|
|
|
static wxTaskBarIcon *UseTaskBarIcon(wxTaskBarIcon *icon);
|
2015-09-14 14:20:00 -04:00
|
|
|
|
|
|
|
#endif // defined(__WXMSW__) && defined(wxHAS_NATIVE_NOTIFICATION_MESSAGE)
|
2007-11-23 20:56:13 -05:00
|
|
|
|
2015-09-09 16:59:21 -04:00
|
|
|
private:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxNotificationMessage);
|
|
|
|
};
|
|
|
|
|
2007-11-23 20:56:13 -05:00
|
|
|
#endif // wxUSE_NOTIFICATION_MESSAGE
|
|
|
|
|
|
|
|
#endif // _WX_NOTIFMSG_H_
|
|
|
|
|