From 24e71cb379ceef4643ac8ecea45da78508bc626a Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Sat, 26 Apr 2008 05:43:41 +0000 Subject: [PATCH] Add support for Mac dock icon bouncing. I used a cross-platform enum so that we can (ideally) craft a cross-platform API for 3.0. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53370 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 11 +++++++++++ include/wx/mac/carbon/app.h | 3 +++ src/mac/carbon/app.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 644f4485ee..148e9c2fbc 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2316,6 +2316,17 @@ enum wxUpdateUI wxUPDATE_UI_FROMIDLE = 0x0002 /* Invoked from On(Internal)Idle */ }; +/* ---------------------------------------------------------------------------- */ +/* Notification Event flags - used for dock icon bouncing, etc. */ +/* ---------------------------------------------------------------------------- */ + +enum wxNotificationOptions +{ + wxNOTIFY_NONE = 0x0000, + wxNOTIFY_ONCE = 0x0001, + wxNOTIFY_REPEAT = 0x0002 +}; + /* ---------------------------------------------------------------------------- */ /* miscellaneous */ /* ---------------------------------------------------------------------------- */ diff --git a/include/wx/mac/carbon/app.h b/include/wx/mac/carbon/app.h index c6e85e926a..778e504b8a 100644 --- a/include/wx/mac/carbon/app.h +++ b/include/wx/mac/carbon/app.h @@ -74,6 +74,8 @@ public: WXEVENTHANDLERREF MacGetCurrentEventHandlerCallRef() { return m_macCurrentEventHandlerCallRef ; } void MacSetCurrentEvent( WXEVENTREF event , WXEVENTHANDLERCALLREF handler ) { m_macCurrentEvent = event ; m_macCurrentEventHandlerCallRef = handler ; } + + void MacRequestUserAttention(wxNotificationOptions options); // adding a CFType object to be released only at the end of the current event cycle (increases the // refcount of the object passed), needed in case we are in the middle of an event concering an object @@ -101,6 +103,7 @@ public: static long s_macPreferencesMenuItemId ; static long s_macExitMenuItemId ; static wxString s_macHelpMenuTitleName ; + static void* s_macNotificationRecord ; WXEVENTREF MacGetCurrentEvent() { return m_macCurrentEvent ; } void MacHandleOneEvent( WXEVENTREF ev ) ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 1b8f575369..4976f8fd1b 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -98,6 +98,8 @@ wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ; bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin +void* wxApp::s_macNotificationRecord = NULL; + //---------------------------------------------------------------------- // Core Apple Event Support //---------------------------------------------------------------------- @@ -300,7 +302,18 @@ void wxApp::MacPrintFile(const wxString & fileName ) #endif //docview } - +void wxApp::MacRequestUserAttention(wxNotificationOptions options) +{ + NMRec nmRec = {0}; + nmRec.qType = nmType; + nmRec.nmMark = 1; + NMInstall(&nmRec); + + if (options == wxNOTIFY_ONCE) + NMRemove (&nmRec); + else // save the reference and remove it on app activation + wxApp::s_macNotificationRecord = &nmRec; +} void wxApp::MacNewFile() { @@ -613,8 +626,17 @@ static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef hand switch ( GetEventKind( event ) ) { case kEventAppActivated : - if ( wxTheApp ) + if ( wxTheApp ) { wxTheApp->SetActive( true , NULL ) ; + // If MacRequestUserAttention is set to repeat, then we need + // to shut down the notification upon app activation. This + // should happen automatically, but let's add the handler + // just in case. + if (wxApp::s_macNotificationRecord) { + NMRemove((NMRec*)wxApp::s_macNotificationRecord); + wxApp::s_macNotificationRecord = NULL; + } + } result = noErr ; break ;