X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6433692716880ca5d7441356d9a65ec4e616cb93..88932ec82d048d006cdc81bd309f5e59aee799ac:/src/msw/notifmsg.cpp diff --git a/src/msw/notifmsg.cpp b/src/msw/notifmsg.cpp index dbbc098ad2..b1a91d86d6 100644 --- a/src/msw/notifmsg.cpp +++ b/src/msw/notifmsg.cpp @@ -23,13 +23,19 @@ #pragma hdrstop #endif -#if wxUSE_NOTIFICATION_MESSAGE && wxUSE_TASKBARICON +// we can only use the native implementation if we have a working +// wxTaskBarIcon::ShowBalloon() method +#if wxUSE_NOTIFICATION_MESSAGE && \ + wxUSE_TASKBARICON && wxUSE_TASKBARICON_BALLOONS + +#include "wx/notifmsg.h" #ifndef WX_PRECOMP + #include "wx/toplevel.h" + #include "wx/app.h" #include "wx/string.h" #endif // WX_PRECOMP -#include "wx/notifmsg.h" #include "wx/generic/notifmsg.h" #include "wx/taskbar.h" @@ -52,7 +58,7 @@ public: virtual bool DoClose() = 0; private: - DECLARE_NO_COPY_CLASS(wxNotifMsgImpl) + wxDECLARE_NO_COPY_CLASS(wxNotifMsgImpl); }; // implementation which is simply a bridge to wxGenericNotificationMessage @@ -128,11 +134,6 @@ public: // can't close automatic notification [currently] virtual bool DoClose() { return false; } - -private: - // custom event handler connected to m_icon which will receive the icon - // close event and delete it and itself when it happens - wxEvtHandler * const m_iconEvtHandler; }; // implementation for manually closed notifications @@ -178,7 +179,7 @@ private: wxTaskBarIcon * const m_icon; - DECLARE_NO_COPY_CLASS(wxNotificationIconEvtHandler) + wxDECLARE_NO_COPY_CLASS(wxNotificationIconEvtHandler); }; // ============================================================================ @@ -274,7 +275,7 @@ void wxBalloonNotifMsgImpl::SetUpIcon(wxWindow *win) if ( !icon.IsOk() ) { // we really must have some icon - icon = wxIcon(_T("wxICON_AAA")); + icon = wxIcon(wxT("wxICON_AAA")); } m_icon->SetIcon(icon); @@ -287,6 +288,23 @@ wxBalloonNotifMsgImpl::DoShow(const wxString& title, int timeout, int flags) { + if ( !m_icon->IsIconInstalled() ) + { + // If we failed to install the icon (which does happen sometimes, + // although only in unusual circumstances, e.g. it happens regularly, + // albeit not constantly, if we're used soon after resume from suspend + // under Windows 7), we should not call ShowBalloon() because it would + // just assert and return and we must delete the icon ourselves because + // otherwise its associated wxTaskBarIconWindow would remain alive + // forever because we're not going to receive a notification about icon + // disappearance from the system if we failed to install it in the + // first place. + delete m_icon; + m_icon = NULL; + + return false; + } + timeout *= 1000; // Windows expresses timeout in milliseconds return m_icon->ShowBalloon(title, message, timeout, flags); @@ -311,11 +329,11 @@ wxManualNotifMsgImpl::~wxManualNotifMsgImpl() bool wxManualNotifMsgImpl::DoShow(const wxString& title, const wxString& message, - int timeout, + int WXUNUSED_UNLESS_DEBUG(timeout), int flags) { wxASSERT_MSG( timeout == wxNotificationMessage::Timeout_Never, - _T("shouldn't be used") ); + wxT("shouldn't be used") ); // base class creates the icon for us initially but we could have destroyed // it in DoClose(), recreate it if this was the case @@ -350,9 +368,14 @@ bool wxManualNotifMsgImpl::DoClose() // ---------------------------------------------------------------------------- wxAutoNotifMsgImpl::wxAutoNotifMsgImpl(wxWindow *win) - : wxBalloonNotifMsgImpl(win), - m_iconEvtHandler(new wxNotificationIconEvtHandler(m_icon)) + : wxBalloonNotifMsgImpl(win) { + if ( m_ownsIcon ) + { + // This object will self-destruct and also delete the icon when the + // notification is hidden. + new wxNotificationIconEvtHandler(m_icon); + } } bool @@ -362,7 +385,7 @@ wxAutoNotifMsgImpl::DoShow(const wxString& title, int flags) { wxASSERT_MSG( timeout != wxNotificationMessage::Timeout_Never, - _T("shouldn't be used") ); + wxT("shouldn't be used") ); if ( timeout == wxNotificationMessage::Timeout_Auto ) { @@ -377,6 +400,9 @@ wxAutoNotifMsgImpl::DoShow(const wxString& title, // wxNotificationMessage // ---------------------------------------------------------------------------- +/* static */ +bool wxNotificationMessage::ms_alwaysUseGeneric = false; + /* static */ wxTaskBarIcon *wxNotificationMessage::UseTaskBarIcon(wxTaskBarIcon *icon) { @@ -387,7 +413,7 @@ bool wxNotificationMessage::Show(int timeout) { if ( !m_impl ) { - if ( wxTheApp->GetShell32Version() >= 500 ) + if ( !ms_alwaysUseGeneric && wxTheApp->GetShell32Version() >= 500 ) { if ( timeout == Timeout_Never ) m_impl = new wxManualNotifMsgImpl(GetParent());