X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3b3dc8019a520ce5e166c8ae9098ba020f8b3f94..0c1cc9483ecba053bc9a0983a4a8d48898e334f2:/src/mac/carbon/taskbar.cpp diff --git a/src/mac/carbon/taskbar.cpp b/src/mac/carbon/taskbar.cpp index ca4d3fe1fe..9bb02f5124 100644 --- a/src/mac/carbon/taskbar.cpp +++ b/src/mac/carbon/taskbar.cpp @@ -11,20 +11,19 @@ #include "wx/wxprec.h" -#ifdef wxHAS_TASK_BAR_ICON +#if wxUSE_TASKBARICON #include "wx/taskbar.h" #ifndef WX_PRECOMP #include "wx/dcmemory.h" #include "wx/menu.h" + #include "wx/toplevel.h" + #include "wx/icon.h" #endif #include "wx/mac/private.h" -#include "wx/icon.h" - - class wxTaskBarIconImpl { public: @@ -133,116 +132,98 @@ wxTaskBarIconImpl::~wxTaskBarIconImpl() // 1) To handle wxTaskBarIcon menu events (see below for why) // 2) To handle events from the dock when it requests a menu //----------------------------------------------------------------------------- -pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, - EventRef inEvent, void *pData ) +pascal OSStatus +wxDockEventHandler(EventHandlerCallRef WXUNUSED(inHandlerCallRef), + EventRef inEvent, + void *pData) { // Get the parameters we want from the event wxDockTaskBarIcon* pTB = (wxDockTaskBarIcon*) pData; const UInt32 eventClass = GetEventClass(inEvent); const UInt32 eventKind = GetEventKind(inEvent); + + OSStatus err = eventNotHandledErr; // Handle wxTaskBar menu events (note that this is a global event handler // so it will actually get called by all commands/menus) - if ((eventClass == kEventClassCommand) && (eventKind == kEventCommandProcess)) + if ((eventClass == kEventClassCommand) && (eventKind == kEventCommandProcess || eventKind == kEventCommandUpdateStatus )) { // if we have no taskbar menu quickly pass it back to wxApp - if (pTB->m_pMenu == NULL) - return eventNotHandledErr; - - // This is the real reason why we need this. Normally menus - // get handled in wxMacAppEventHandler - // - // pascal OSStatus wxMacAppEventHandler(EventHandlerCallRef handler, - // EventRef event, void *data) - // - // However, in the case of a taskbar menu call - // command.menu.menuRef IS NULL! - // Which causes the wxApp handler just to skip it. - MenuRef taskbarMenuRef = MAC_WXHMENU(pTB->m_pMenu->GetHMenu()); - OSStatus err; - - // get the HICommand from the event - HICommand command; - err = GetEventParameter( - inEvent, kEventParamDirectObject, - typeHICommand, NULL, - sizeof(HICommand), NULL, &command ); - if (err == noErr) + if (pTB->m_pMenu != NULL) { - // Obtain the REAL menuRef and the menuItemIndex in the real menuRef - // - // NOTE: menuRef is generally used here for submenus, as - // GetMenuItemRefCon could give an incorrect wxMenuItem if we pass - // just the top level wxTaskBar menu - MenuItemIndex menuItemIndex; - MenuRef menuRef; - - err = GetIndMenuItemWithCommandID( - taskbarMenuRef, - command.commandID, - 1, &menuRef, &menuItemIndex ); - if (err == noErr) + // This is the real reason why we need this. Normally menus + // get handled in wxMacAppEventHandler + // However, in the case of a taskbar menu call + // command.menu.menuRef IS NULL! + // Which causes the wxApp handler just to skip it. + + // get the HICommand from the event + HICommand command; + if (GetEventParameter(inEvent, kEventParamDirectObject, + typeHICommand, NULL,sizeof(HICommand), NULL, &command ) == noErr) { - MenuCommand id = command.commandID; - wxMenuItem *item = NULL; - - if (id != 0) // get the wxMenuItem reference from the MenuRef - GetMenuItemRefCon( menuRef, menuItemIndex, (UInt32*) &item ); - - if (item) + // Obtain the REAL menuRef and the menuItemIndex in the real menuRef + // + // NOTE: menuRef is generally used here for submenus, as + // GetMenuItemRefCon could give an incorrect wxMenuItem if we pass + // just the top level wxTaskBar menu + MenuItemIndex menuItemIndex; + MenuRef menuRef; + MenuRef taskbarMenuRef = MAC_WXHMENU(pTB->m_pMenu->GetHMenu()); + + // the next command is only successful if it was a command from the taskbar menu + // otherwise we pass it on + if (GetIndMenuItemWithCommandID(taskbarMenuRef,command.commandID, + 1, &menuRef, &menuItemIndex ) == noErr) { - // Handle items that are checkable - // FIXME: Doesn't work (at least on 10.2)! - if (item->IsCheckable()) - item->Check( !item->IsChecked() ); - - // send the wxEvent to the wxMenu - item->GetMenu()->SendEvent( id, item->IsCheckable() ? item->IsChecked() : -1 ); - - // successfully handled the event - err = noErr; + wxMenu* itemMenu = wxFindMenuFromMacMenu( menuRef ) ; + int id = wxMacCommandToId( command.commandID ) ; + wxMenuItem *item = NULL; + + if (id != 0) // get the wxMenuItem reference from the MenuRef + GetMenuItemRefCon( menuRef, menuItemIndex, (URefCon*) &item ); + + if (item && itemMenu ) + { + if ( eventKind == kEventCommandProcess ) + err = itemMenu->MacHandleCommandProcess( item, id ); + else if ( eventKind == kEventCommandUpdateStatus ) + err = itemMenu->MacHandleCommandUpdateStatus( item, id ); + } } } } //end if noErr on getting HICommand from event - - // return whether we handled the event or not - return err; } + else if ((eventClass == kEventClassApplication) && (eventKind == kEventAppGetDockTileMenu )) + { + // process the right click events + // NB: This may result in double or even triple-creation of the menus + // We need to do this for 2.4 compat, however + wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN, NULL); + pTB->m_parent->ProcessEvent(downevt); - // We better have a kEventClassApplication/kEventAppGetDockTileMenu combo here, - // otherwise something is truly funky - wxASSERT(eventClass == kEventClassApplication && - eventKind == kEventAppGetDockTileMenu); - - // process the right click events - // NB: This may result in double or even triple-creation of the menus - // We need to do this for 2.4 compat, however - wxTaskBarIconEvent downevt(wxEVT_TASKBAR_RIGHT_DOWN, NULL); - pTB->m_parent->ProcessEvent(downevt); - - wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP, NULL); - pTB->m_parent->ProcessEvent(upevt); + wxTaskBarIconEvent upevt(wxEVT_TASKBAR_RIGHT_UP, NULL); + pTB->m_parent->ProcessEvent(upevt); - // create popup menu - wxMenu* menu = pTB->DoCreatePopupMenu(); + // create popup menu + wxMenu* menu = pTB->DoCreatePopupMenu(); - OSStatus err = eventNotHandledErr; - - if (menu != NULL) - { - // note to self - a MenuRef *is* a MenuHandle - MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); - - // When SetEventParameter is called it will decrement - // the reference count of the menu - we need to make - // sure it stays around in the wxMenu class here - RetainMenu(hMenu); - - // set the actual dock menu - err = SetEventParameter( - inEvent, kEventParamMenuRef, - typeMenuRef, sizeof(MenuRef), &hMenu ); - verify_noerr( err ); + if (menu != NULL) + { + // note to self - a MenuRef *is* a MenuHandle + MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); + + // When SetEventParameter is called it will decrement + // the reference count of the menu - we need to make + // sure it stays around in the wxMenu class here + CFRetain(hMenu); + + // set the actual dock menu + err = SetEventParameter( + inEvent, kEventParamMenuRef, + typeMenuRef, sizeof(MenuRef), &hMenu ); + verify_noerr( err ); + } } return err; @@ -291,7 +272,7 @@ wxMenu * wxDeepCopyMenu( wxMenu *menu ) new wxMenuItem( m_pMenu, // parent menu theItem->GetId(), // id - theItem->GetText(), // text label + theItem->GetItemLabel(), // text label theItem->GetHelp(), // status bar help string theItem->GetKind(), // menu flags - checkable, separator, etc. wxDeepCopyMenu(theItem->GetSubMenu()) )); // submenu @@ -318,6 +299,7 @@ wxDockTaskBarIcon::wxDockTaskBarIcon(wxTaskBarIcon* parent) EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand }, + { kEventClassCommand, kEventCommandUpdateStatus }, { kEventClassApplication, kEventAppGetDockTileMenu } }; @@ -389,7 +371,7 @@ bool wxDockTaskBarIcon::IsIconInstalled() const // // Sets the icon for the dock CGImage functions and SetApplicationDockTileImage //----------------------------------------------------------------------------- -bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) +bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& WXUNUSED(tooltip)) { // convert the wxIcon into a wxBitmap so we can perform some // wxBitmap operations with it @@ -398,7 +380,7 @@ bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) // get the CGImageRef for the wxBitmap: // OSX builds only, but then the dock only exists in OSX - CGImageRef pImage = (CGImageRef) bmp.CGImageCreate(); + CGImageRef pImage = (CGImageRef) bmp.CreateCGImage(); wxASSERT( pImage != NULL ); // actually set the dock image @@ -522,4 +504,4 @@ bool wxTaskBarIcon::RemoveIcon() bool wxTaskBarIcon::PopupMenu(wxMenu *menu) { return m_impl->PopupMenu(menu); } -#endif // wxHAS_TASK_BAR_ICON +#endif // wxUSE_TASKBARICON