1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/notifmsg.h
// Purpose: class allowing to show notification messages to the user
// Author: Vadim Zeitlin
// Created: 2007-11-19
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
// 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
class WXDLLIMPEXP_CORE wxNotificationMessageBase : public wxEvtHandler
{
public:
// ctors and initializers
// ----------------------
// default ctor, use setters below to initialize it later
wxNotificationMessageBase()
{
Init();
}
// 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,
const wxString& message = wxEmptyString,
wxWindow *parent = NULL,
int flags = wxICON_INFORMATION)
{
Init();
Create(title, message, parent, flags);
}
virtual ~wxNotificationMessageBase();
// note that the setters must be called before Show()
// set the title: short string, markup not allowed
void SetTitle(const wxString& title);
// set the text of the message: this is a longer string than the title and
// some platforms allow simple HTML-like markup in it
void SetMessage(const wxString& message);
// 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
void SetParent(wxWindow *parent);
// 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)
void SetFlags(int flags);
// set a custom icon to use instead of the system provided specified via SetFlags
virtual void SetIcon(const wxIcon& icon);
// 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());
// 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
bool Show(int timeout = Timeout_Auto);
// 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)
bool Close();
protected:
// Common part of all ctors.
void Create(const wxString& title = wxEmptyString,
const wxString& message = wxEmptyString,
wxWindow *parent = NULL,
int flags = wxICON_INFORMATION)
{
SetTitle(title);
SetMessage(message);
SetParent(parent);
SetFlags(flags);
}
class wxNotificationMessageImpl* m_impl;
private:
void Init()
{
m_impl = NULL;
}
wxDECLARE_NO_COPY_CLASS(wxNotificationMessageBase);
};
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 );
#if (defined(__WXGTK__) && wxUSE_LIBNOTIFY) || \
(defined(__WXMSW__) && wxUSE_TASKBARICON && wxUSE_TASKBARICON_BALLOONS) || \
defined(__WXOSX_COCOA__)
#define wxHAS_NATIVE_NOTIFICATION_MESSAGE
#endif
// ----------------------------------------------------------------------------
// wxNotificationMessage
// ----------------------------------------------------------------------------
#ifdef wxHAS_NATIVE_NOTIFICATION_MESSAGE
#if defined(__WXMSW__)
class WXDLLIMPEXP_FWD_CORE wxTaskBarIcon;
#endif // defined(__WXMSW__)
#else
#include "wx/generic/notifmsg.h"
#endif // wxHAS_NATIVE_NOTIFICATION_MESSAGE
class WXDLLIMPEXP_CORE wxNotificationMessage : public
#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)
{
Init();
Create(title, message, parent, flags);
}
#if defined(__WXMSW__) && defined(wxHAS_NATIVE_NOTIFICATION_MESSAGE)
static bool MSWUseToasts(
const wxString& shortcutPath = wxString(),
const wxString& appId = wxString());
// returns the task bar icon which was used previously (may be NULL)
static wxTaskBarIcon *UseTaskBarIcon(wxTaskBarIcon *icon);
#endif // defined(__WXMSW__) && defined(wxHAS_NATIVE_NOTIFICATION_MESSAGE)
private:
// common part of all ctors
void Init();
wxDECLARE_NO_COPY_CLASS(wxNotificationMessage);
};
#endif // wxUSE_NOTIFICATION_MESSAGE
#endif // _WX_NOTIFMSG_H_
|